]> git.localhorst.tv Git - l2e.git/commitdiff
put stat increments in level ladder
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 12 Feb 2013 07:07:14 +0000 (08:07 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 13 Feb 2013 18:44:18 +0000 (19:44 +0100)
12 files changed:
src/battle/states/VictoryState.cpp
src/common/Capsule.cpp
src/common/Capsule.h
src/common/Hero.cpp
src/common/Hero.h
src/common/LevelUp.cpp [new file with mode: 0644]
src/common/LevelUp.h [new file with mode: 0644]
src/common/Stats.cpp
src/common/Stats.h
src/common/Upgrade.h
src/main.cpp
test-data/test.l2s

index 64318e0157d87b50afbdd75334ad22647c8a983f..e2cc99fb27cc3e7799d0dde3728958c4a1f45538 100644 (file)
@@ -33,6 +33,7 @@ void VictoryState::OnEnterState(SDL_Surface *screen) {
 }
 
 void VictoryState::LoadResults() {
+       // TODO: localization
        lines.clear();
 
        std::stringstream s;
@@ -75,7 +76,7 @@ void VictoryState::LoadResult(
                        s << "Max. MP increases by " << u.Amount();
                        break;
                case Upgrade::ATTACK:
-                       s << "ATK increases by " << u.Amount();
+                       s << "ATP increases by " << u.Amount();
                        break;
                case Upgrade::DEFENSE:
                        s << "DFP increases by " << u.Amount();
@@ -92,7 +93,7 @@ void VictoryState::LoadResult(
                case Upgrade::GUT:
                        s << "GUT increases by " << u.Amount();
                        break;
-               case Upgrade::MAGIC_RSISTANCE:
+               case Upgrade::MAGIC_RESISTANCE:
                        s << "MGR increases by " << u.Amount();
                        break;
                case Upgrade::LEVEL_NEXT:
index de2ea56583fd7ff77a0d5375782d0f1f93f907e1..3bfdde7456caa574451a6cf7bd26d5e00ff2ff61 100644 (file)
@@ -1,8 +1,8 @@
 #include "Capsule.h"
 
 #include "Item.h"
+#include "LevelUp.h"
 #include "Spell.h"
-#include "Stats.h"
 #include "Upgrade.h"
 #include "../graphics/Animation.h"
 #include "../graphics/Sprite.h"
@@ -77,7 +77,7 @@ Stats Capsule::GetStats() const {
 int Capsule::NextLevel() const {
        int levelOffset(Level() - 1);
        if (levelOffset < numLevels) {
-               return levelLadder[levelOffset] - Experience();
+               return levelLadder[levelOffset].Experience() - Experience();
        } else {
                return 0;
        }
@@ -92,14 +92,40 @@ void Capsule::AddExperience(int exp, vector<Upgrade> &info) {
        }
        int remain = exp;
        while (remain >= NextLevel()) {
+               const LevelUp &lup = levelLadder[level - 1];
                int added = NextLevel();
                experience += added;
                remain -= added;
                ++level;
+               maxHealth += lup.MaxHealth();
+               stats += lup;
 
                info.push_back(Upgrade(name, Upgrade::LEVEL_UP, level));
 
-               // TODO: upgrade attributes and push info
+               if (lup.MaxHealth() > 0) {
+                       info.push_back(Upgrade(name, Upgrade::MAX_HEALTH, lup.MaxHealth()));
+               }
+               if (lup.Attack() > 0) {
+                       info.push_back(Upgrade(name, Upgrade::ATTACK, lup.Attack()));
+               }
+               if (lup.Defense() > 0) {
+                       info.push_back(Upgrade(name, Upgrade::DEFENSE, lup.Defense()));
+               }
+               if (lup.Strength() > 0) {
+                       info.push_back(Upgrade(name, Upgrade::STRENGTH, lup.Strength()));
+               }
+               if (lup.Agility() > 0) {
+                       info.push_back(Upgrade(name, Upgrade::AGILITY, lup.Agility()));
+               }
+               if (lup.Intelligence() > 0) {
+                       info.push_back(Upgrade(name, Upgrade::INTELLIGENCE, lup.Intelligence()));
+               }
+               if (lup.Gut() > 0) {
+                       info.push_back(Upgrade(name, Upgrade::GUT, lup.Gut()));
+               }
+               if (lup.MagicResistance() > 0) {
+                       info.push_back(Upgrade(name, Upgrade::MAGIC_RESISTANCE, lup.MagicResistance()));
+               }
 
                if (level > numLevels) {
                        info.push_back(Upgrade(
@@ -263,7 +289,7 @@ void Capsule::CreateTypeDescription() {
        td.AddField("level", FieldDescription(((char *)&c.level) - ((char *)&c), Interpreter::NUMBER_ID));
        td.AddField("experience", FieldDescription(((char *)&c.experience) - ((char *)&c), Interpreter::NUMBER_ID));
 
-       td.AddField("ladder", FieldDescription(((char *)&c.levelLadder) - ((char *)&c), Interpreter::NUMBER_ID).SetAggregate());
+       td.AddField("ladder", FieldDescription(((char *)&c.levelLadder) - ((char *)&c), LevelUp::TYPE_ID).SetAggregate());
 
        td.AddField("classes", FieldDescription(((char *)&c.classes) - ((char *)&c), Class::TYPE_ID).SetAggregate());
        td.AddField("class", FieldDescription(((char *)&c.curClass) - ((char *)&c), Interpreter::NUMBER_ID));
index 1e2a6311f07fe1f27ad871a527f24567f575fa21..60d70d2c6b6fd6c2bd01aa4101bc7f170e37d363 100644 (file)
@@ -3,6 +3,7 @@
 
 namespace common {
        class Item;
+       class LevelUp;
        class Upgrade;
 }
 namespace graphics {
@@ -10,7 +11,7 @@ namespace graphics {
        class Sprite;
 }
 
-#include "../common/Stats.h"
+#include "Stats.h"
 #include "../math/Vector.h"
 
 #include <vector>
@@ -120,7 +121,7 @@ private:
        int level;
        int experience;
 
-       int *levelLadder;
+       LevelUp *levelLadder;
        int numLevels;
 
        Class *classes;
index beeab8305844b8a9b2cccb95a98a66d73c8153ee..79581569c4002335402d9e3117069221de5714c8 100644 (file)
@@ -1,6 +1,7 @@
 #include "Hero.h"
 
 #include "Item.h"
+#include "LevelUp.h"
 #include "Spell.h"
 #include "Upgrade.h"
 #include "../graphics/Animation.h"
@@ -65,7 +66,7 @@ void Hero::SubtractHealth(int amount) {
 int Hero::NextLevel() const {
        int levelOffset(Level() - 1);
        if (levelOffset < numLevels) {
-               return levelLadder[levelOffset] - Experience();
+               return levelLadder[levelOffset].Experience() - Experience();
        } else {
                return 0;
        }
@@ -80,14 +81,44 @@ void Hero::AddExperience(int exp, vector<Upgrade> &info) {
        }
        int remain = exp;
        while (remain >= NextLevel()) {
+               const LevelUp &lup = levelLadder[level - 1];
                int added = NextLevel();
                experience += added;
                remain -= added;
                ++level;
+               maxHealth += lup.MaxHealth();
+               maxMana += lup.MaxMagic();
+               stats += lup;
 
                info.push_back(Upgrade(name, Upgrade::LEVEL_UP, level));
 
-               // TODO: upgrade attributes and push info
+               if (lup.MaxHealth() > 0) {
+                       info.push_back(Upgrade(name, Upgrade::MAX_HEALTH, lup.MaxHealth()));
+               }
+               if (lup.MaxMagic() > 0) {
+                       info.push_back(Upgrade(name, Upgrade::MAX_MAGIC, lup.MaxMagic()));
+               }
+               if (lup.Attack() > 0) {
+                       info.push_back(Upgrade(name, Upgrade::ATTACK, lup.Attack()));
+               }
+               if (lup.Defense() > 0) {
+                       info.push_back(Upgrade(name, Upgrade::DEFENSE, lup.Defense()));
+               }
+               if (lup.Strength() > 0) {
+                       info.push_back(Upgrade(name, Upgrade::STRENGTH, lup.Strength()));
+               }
+               if (lup.Agility() > 0) {
+                       info.push_back(Upgrade(name, Upgrade::AGILITY, lup.Agility()));
+               }
+               if (lup.Intelligence() > 0) {
+                       info.push_back(Upgrade(name, Upgrade::INTELLIGENCE, lup.Intelligence()));
+               }
+               if (lup.Gut() > 0) {
+                       info.push_back(Upgrade(name, Upgrade::GUT, lup.Gut()));
+               }
+               if (lup.MagicResistance() > 0) {
+                       info.push_back(Upgrade(name, Upgrade::MAGIC_RESISTANCE, lup.MagicResistance()));
+               }
 
                if (level > numLevels) {
                        info.push_back(Upgrade(
@@ -128,7 +159,7 @@ void Hero::CreateTypeDescription() {
        td.AddField("stats", FieldDescription(((char *)&h.stats) - ((char *)&h), Stats::TYPE_ID));
 
        td.AddField("level", FieldDescription(((char *)&h.level) - ((char *)&h), Interpreter::NUMBER_ID));
-       td.AddField("ladder", FieldDescription(((char *)&h.levelLadder) - ((char *)&h), Interpreter::NUMBER_ID).SetAggregate());
+       td.AddField("ladder", FieldDescription(((char *)&h.levelLadder) - ((char *)&h), LevelUp::TYPE_ID).SetAggregate());
 
        td.AddField("useMask", FieldDescription(((char *)&h.useMask) - ((char *)&h), Interpreter::NUMBER_ID));
 
index 1b4c8d10954c3076007d38730a2a622daf900f3d..a0f1da47fc0af02833cc10f6bb00033d9de89afa 100644 (file)
@@ -3,6 +3,7 @@
 
 namespace common {
        class Item;
+       class LevelUp;
        class Spell;
        class Upgrade;
 }
@@ -116,8 +117,7 @@ private:
        int level;
        int experience;
 
-       // TODO: ladder should contain hp, mp, and stats mods.
-       int *levelLadder;
+       LevelUp *levelLadder;
        int numLevels;
 
        int useMask;
diff --git a/src/common/LevelUp.cpp b/src/common/LevelUp.cpp
new file mode 100644 (file)
index 0000000..0b8f85c
--- /dev/null
@@ -0,0 +1,43 @@
+#include "LevelUp.h"
+
+#include "../loader/Interpreter.h"
+#include "../loader/TypeDescription.h"
+
+using loader::FieldDescription;
+using loader::Interpreter;
+using loader::TypeDescription;
+
+
+namespace common {
+
+LevelUp::LevelUp()
+: Stats()
+, experience(0)
+, maxHealth(0)
+, maxMagic(0) {
+
+}
+
+
+void LevelUp::CreateTypeDescription() {
+       LevelUp l;
+       Stats *s = &l;
+
+       TypeDescription &td(TypeDescription::Create(TYPE_ID, "LevelUp"));
+       td.SetDescription("Describes the requirements and benefits of a levelup.");
+       td.SetConstructor(&Construct);
+       td.SetSize(sizeof(LevelUp));
+       td.AddSupertype(Stats::TYPE_ID, ((char *)s) - ((char *)&l));
+
+       td.AddField("exp", FieldDescription(((char *)&l.experience) - ((char *)&l), Interpreter::NUMBER_ID).SetDescription("reuired experience points"));
+       td.AddField("maxHP", FieldDescription(((char *)&l.maxHealth) - ((char *)&l), Interpreter::NUMBER_ID).SetDescription("increase in maximum health points"));
+       td.AddField("maxMP", FieldDescription(((char *)&l.maxMagic) - ((char *)&l), Interpreter::NUMBER_ID).SetDescription("increas in maximum magic points"));
+
+       AddFields(td, l, ((char *)s) - ((char *)&l));
+}
+
+void LevelUp::Construct(void *data) {
+       new (data) LevelUp;
+}
+
+}
diff --git a/src/common/LevelUp.h b/src/common/LevelUp.h
new file mode 100644 (file)
index 0000000..9637eee
--- /dev/null
@@ -0,0 +1,35 @@
+#ifndef COMMON_LEVELUP_H_
+#define COMMON_LEVELUP_H_
+
+#include "Stats.h"
+
+
+namespace common {
+
+struct LevelUp
+: public Stats {
+
+public:
+       static const int TYPE_ID = 309;
+
+public:
+       LevelUp();
+
+public:
+       int Experience() const { return experience; }
+       int MaxHealth() const { return maxHealth; }
+       int MaxMagic() const { return maxMagic; }
+
+       static void CreateTypeDescription();
+       static void Construct(void *);
+
+private:
+       int experience;
+       int maxHealth;
+       int maxMagic;
+
+};
+
+}
+
+#endif
index c15ca1ac5d4913cefe8458d1e74f2dd4cbd8c7a2..59e4a819ee2acbdeac13c4cf3bd7008898b63eb5 100644 (file)
@@ -40,13 +40,17 @@ void Stats::CreateTypeDescription() {
        td.SetConstructor(&Construct);
        td.SetSize(sizeof(Stats));
 
-       td.AddField("atp", FieldDescription(((char *)&s.attack) - ((char *)&s), Interpreter::NUMBER_ID).SetDescription("attack points"));
-       td.AddField("dfp", FieldDescription(((char *)&s.defense) - ((char *)&s), Interpreter::NUMBER_ID).SetDescription("defense points"));
-       td.AddField("str", FieldDescription(((char *)&s.strength) - ((char *)&s), Interpreter::NUMBER_ID).SetDescription("strength"));
-       td.AddField("agl", FieldDescription(((char *)&s.agility) - ((char *)&s), Interpreter::NUMBER_ID).SetDescription("agility"));
-       td.AddField("int", FieldDescription(((char *)&s.intelligence) - ((char *)&s), Interpreter::NUMBER_ID).SetDescription("intelligence"));
-       td.AddField("gut", FieldDescription(((char *)&s.gut) - ((char *)&s), Interpreter::NUMBER_ID).SetDescription("gut (ikari factor)"));
-       td.AddField("mgr", FieldDescription(((char *)&s.magicResistance) - ((char *)&s), Interpreter::NUMBER_ID).SetDescription("magic resistance"));
+       AddFields(td, s, 0);
+}
+
+void Stats::AddFields(TypeDescription &td, const Stats &s, std::ptrdiff_t offset) {
+       td.AddField("atp", FieldDescription(((char *)&s.attack) - ((char *)&s) - offset, Interpreter::NUMBER_ID).SetDescription("attack points"));
+       td.AddField("dfp", FieldDescription(((char *)&s.defense) - ((char *)&s) - offset, Interpreter::NUMBER_ID).SetDescription("defense points"));
+       td.AddField("str", FieldDescription(((char *)&s.strength) - ((char *)&s) - offset, Interpreter::NUMBER_ID).SetDescription("strength"));
+       td.AddField("agl", FieldDescription(((char *)&s.agility) - ((char *)&s) - offset, Interpreter::NUMBER_ID).SetDescription("agility"));
+       td.AddField("int", FieldDescription(((char *)&s.intelligence) - ((char *)&s) - offset, Interpreter::NUMBER_ID).SetDescription("intelligence"));
+       td.AddField("gut", FieldDescription(((char *)&s.gut) - ((char *)&s) - offset, Interpreter::NUMBER_ID).SetDescription("gut (ikari factor)"));
+       td.AddField("mgr", FieldDescription(((char *)&s.magicResistance) - ((char *)&s) - offset, Interpreter::NUMBER_ID).SetDescription("magic resistance"));
 }
 
 void Stats::Construct(void *data) {
index f07528a2f5db86331cf9cd088eb51d9da66b8cdb..f2eed68089d991ef884838f20e6a645bc172bb2c 100644 (file)
@@ -1,6 +1,11 @@
 #ifndef COMMON_STATS_H_
 #define COMMON_STATS_H_
 
+namespace loader {
+       class TypeDescription;
+}
+
+#include <memory>
 #include <SDL.h>
 
 namespace common {
@@ -34,6 +39,21 @@ public:
        static void CreateTypeDescription();
        static void Construct(void *);
 
+public:
+       Stats &operator +=(const Stats &other) {
+               attack += other.attack;
+               defense += other.defense;
+               strength += other.strength;
+               agility += other.agility;
+               intelligence += other.intelligence;
+               magicResistance += other.magicResistance;
+               gut += other.gut;
+               return *this;
+       }
+
+protected:
+       static void AddFields(loader::TypeDescription &, const Stats &, std::ptrdiff_t offset);
+
 private:
        int attack;
        int defense;
@@ -47,14 +67,9 @@ private:
 
 
 inline Stats operator +(const Stats &lhs, const Stats &rhs) {
-       return Stats(
-                       lhs.Attack() + rhs.Attack(),
-                       lhs.Defense() + rhs.Defense(),
-                       lhs.Strength() + rhs.Strength(),
-                       lhs.Agility() + rhs.Agility(),
-                       lhs.Intelligence() + rhs.Intelligence(),
-                       lhs.Gut() + rhs.Gut(),
-                       lhs.MagicResistance() + rhs.MagicResistance());
+       Stats temp(lhs);
+       temp = rhs;
+       return temp;
 }
 
 }
index 0a5c079e1a91b76bafe4b26d68bcbe3836eb16ce..97f5238552b161c6fc41ba7dfe3e1b6ecd0e671f 100644 (file)
@@ -16,7 +16,7 @@ public:
                AGILITY,
                INTELLIGENCE,
                GUT,
-               MAGIC_RSISTANCE,
+               MAGIC_RESISTANCE,
                LEVEL_NEXT,
        };
 
index d790928dc4fb851c7a96b956a92dbff3fdd5a47e..f0811de23ede1282543681de19c6996aff6223f2 100644 (file)
@@ -15,6 +15,7 @@
 #include "common/Ikari.h"
 #include "common/Inventory.h"
 #include "common/Item.h"
+#include "common/LevelUp.h"
 #include "common/Script.h"
 #include "common/Spell.h"
 #include "common/Stats.h"
@@ -110,6 +111,7 @@ int main(int argc, char **argv) {
                common::Hero::CreateTypeDescription();
                common::Ikari::CreateTypeDescription();
                common::Item::CreateTypeDescription();
+               common::LevelUp::CreateTypeDescription();
                common::Stats::CreateTypeDescription();
                common::Spell::CreateTypeDescription();
                common::TargetingMode::CreateTypeDescription();
index 83baa7734895b28370c2cf9a8b4beab59403bce6..7b187aafbeaf4d62228c57a90afb8fe818818162 100644 (file)
@@ -91,8 +91,9 @@ export Hero maxim {
                gut: 100,
                mgr:  10
        },
-       ladder: [
-               10
+       ladder: [ LevelUp
+               // insensible test data
+               { exp: 10, maxHP: 5, maxMP: 3, atp: 2, str: 1 }
        ],
        useMask: maskMaxim,
        attackAnimation: ComplexAnimation {