From: Daniel Karbach Date: Tue, 12 Feb 2013 07:07:14 +0000 (+0100) Subject: put stat increments in level ladder X-Git-Url: http://git.localhorst.tv/?p=l2e.git;a=commitdiff_plain;h=b9e715649b41cb69ea1b2d2a588522541eb87b46 put stat increments in level ladder --- diff --git a/src/battle/states/VictoryState.cpp b/src/battle/states/VictoryState.cpp index 64318e0..e2cc99f 100644 --- a/src/battle/states/VictoryState.cpp +++ b/src/battle/states/VictoryState.cpp @@ -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: diff --git a/src/common/Capsule.cpp b/src/common/Capsule.cpp index de2ea56..3bfdde7 100644 --- a/src/common/Capsule.cpp +++ b/src/common/Capsule.cpp @@ -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 &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)); diff --git a/src/common/Capsule.h b/src/common/Capsule.h index 1e2a631..60d70d2 100644 --- a/src/common/Capsule.h +++ b/src/common/Capsule.h @@ -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 @@ -120,7 +121,7 @@ private: int level; int experience; - int *levelLadder; + LevelUp *levelLadder; int numLevels; Class *classes; diff --git a/src/common/Hero.cpp b/src/common/Hero.cpp index beeab83..7958156 100644 --- a/src/common/Hero.cpp +++ b/src/common/Hero.cpp @@ -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 &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)); diff --git a/src/common/Hero.h b/src/common/Hero.h index 1b4c8d1..a0f1da4 100644 --- a/src/common/Hero.h +++ b/src/common/Hero.h @@ -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 index 0000000..0b8f85c --- /dev/null +++ b/src/common/LevelUp.cpp @@ -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 index 0000000..9637eee --- /dev/null +++ b/src/common/LevelUp.h @@ -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 diff --git a/src/common/Stats.cpp b/src/common/Stats.cpp index c15ca1a..59e4a81 100644 --- a/src/common/Stats.cpp +++ b/src/common/Stats.cpp @@ -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) { diff --git a/src/common/Stats.h b/src/common/Stats.h index f07528a..f2eed68 100644 --- a/src/common/Stats.h +++ b/src/common/Stats.h @@ -1,6 +1,11 @@ #ifndef COMMON_STATS_H_ #define COMMON_STATS_H_ +namespace loader { + class TypeDescription; +} + +#include #include 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; } } diff --git a/src/common/Upgrade.h b/src/common/Upgrade.h index 0a5c079..97f5238 100644 --- a/src/common/Upgrade.h +++ b/src/common/Upgrade.h @@ -16,7 +16,7 @@ public: AGILITY, INTELLIGENCE, GUT, - MAGIC_RSISTANCE, + MAGIC_RESISTANCE, LEVEL_NEXT, }; diff --git a/src/main.cpp b/src/main.cpp index d790928..f0811de 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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(); diff --git a/test-data/test.l2s b/test-data/test.l2s index 83baa77..7b187aa 100644 --- a/test-data/test.l2s +++ b/test-data/test.l2s @@ -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 {