]> git.localhorst.tv Git - l2e.git/commitdiff
feed victory messages from upgrade
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 8 Feb 2013 16:05:22 +0000 (17:05 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 13 Feb 2013 18:44:17 +0000 (19:44 +0100)
src/battle/Battle.h
src/battle/states/VictoryState.cpp
src/battle/states/VictoryState.h
src/common/Capsule.cpp
src/common/Capsule.h
src/common/Hero.cpp
src/common/Hero.h
test-data/test.l2s

index cd2894fa753dbba0cbc0f39bc4aea765c524df0b..314288c6213dbebd892bd90d85c49558aeddecf1 100644 (file)
@@ -47,7 +47,9 @@ public:
        bool MonsterAlive(int index) const;
        bool CapsuleAlive() const;
 
+       std::vector<Hero>::iterator HeroesBegin() { return heroes.begin(); }
        std::vector<Hero>::const_iterator HeroesBegin() const { return heroes.begin(); }
+       std::vector<Hero>::iterator HeroesEnd() { return heroes.end(); }
        std::vector<Hero>::const_iterator HeroesEnd() const { return heroes.end(); }
        Hero &HeroAt(int index);
        const Hero &HeroAt(int index) const;
index a0b09ceb5b93d7996c71317f88765b80cce45bad..409f0846aa380b4a8153f53a12aaa287f616cda6 100644 (file)
@@ -8,7 +8,6 @@
 #include "../../common/Capsule.h"
 #include "../../common/GameConfig.h"
 #include "../../common/GameState.h"
-#include "../../common/Hero.h"
 #include "../../math/Vector.h"
 #include "../../graphics/Font.h"
 #include "../../graphics/Frame.h"
@@ -43,11 +42,15 @@ void VictoryState::LoadResults() {
 
        lines.push_back("");
 
-       for (std::vector<Hero>::const_iterator
+       vector<common::Hero::UpgradeInfo> upgrade;
+       for (std::vector<Hero>::iterator
                        i(battle->HeroesBegin()), end(battle->HeroesEnd());
                        i != end; ++i) {
                if (i->Health() <= 0) continue;
-               const common::Hero &hero = i->Master();
+               upgrade.clear();
+               common::Hero &hero = i->Master();
+               hero.AddExperience(battle->ExpReward(), upgrade);
+               LoadResults(hero.Name(), upgrade, lines);
                s.str("");
                s << hero.Name() << " next level " << hero.NextLevel();
                lines.push_back(s.str());
@@ -68,6 +71,54 @@ void VictoryState::LoadResults() {
        lines.push_back(s.str());
 }
 
+void VictoryState::LoadResults(
+               const char *who,
+               const vector<common::Hero::UpgradeInfo> &upgrade,
+               vector<string> &lines) {
+       std::stringstream s;
+       for (vector<common::Hero::UpgradeInfo>::const_iterator
+                       i(upgrade.begin()), end(upgrade.end());
+                       i != end; ++i) {
+               s.str("");
+               switch (i->type) {
+                       case common::Hero::UPGRADE_LVL:
+                               s << who << " levels up.";
+                               break;
+                       case common::Hero::UPGRADE_MHP:
+                               s << "Max. HP increases by " << i->amount;
+                               break;
+                       case common::Hero::UPGRADE_MMP:
+                               s << "Max. MP increases by " << i->amount;
+                               break;
+                       case common::Hero::UPGRADE_ATK:
+                               s << "ATK increases by " << i->amount;
+                               break;
+                       case common::Hero::UPGRADE_DFP:
+                               s << "DFP increases by " << i->amount;
+                               break;
+                       case common::Hero::UPGRADE_STR:
+                               s << "STR increases by " << i->amount;
+                               break;
+                       case common::Hero::UPGRADE_AGL:
+                               s << "AGL increases by " << i->amount;
+                               break;
+                       case common::Hero::UPGRADE_INT:
+                               s << "INT increases by " << i->amount;
+                               break;
+                       case common::Hero::UPGRADE_GUT:
+                               s << "GUT increases by " << i->amount;
+                               break;
+                       case common::Hero::UPGRADE_MGR:
+                               s << "MGR increases by " << i->amount;
+                               break;
+                       default:
+                               s << "There's an error in common::Hero::"
+                                               "AddExperience()";
+               }
+               lines.push_back(s.str());
+       }
+}
+
 void VictoryState::OnExitState(SDL_Surface *screen) {
 
 }
index 4dca6e9663373dbc1d275647aff813b04dd6ecbb..41a541e87c4ed78eb9d7401f9972df15ad6ad7df 100644 (file)
@@ -7,6 +7,7 @@ namespace battle {
 }
 
 #include "../../app/State.h"
+#include "../../common/Hero.h"
 #include "../../math/Vector.h"
 
 #include <string>
@@ -41,6 +42,10 @@ private:
 
 private:
        void LoadResults();
+       void LoadResults(
+                       const char *,
+                       const std::vector<common::Hero::UpgradeInfo> &,
+                       std::vector<std::string> &);
        void RenderFrame(SDL_Surface *screen);
        void RenderLines(SDL_Surface *screen);
 
index 6667068c3c8299dc11268faa889d4cba9a383a8e..083931c5c0a6a2835e933b4134aa0a5c1149879d 100644 (file)
@@ -17,6 +17,7 @@ using graphics::Sprite;
 using loader::FieldDescription;
 using loader::Interpreter;
 using loader::TypeDescription;
+using std::vector;
 
 namespace common {
 
@@ -81,6 +82,30 @@ int Capsule::NextLevel() const {
        }
 }
 
+void Capsule::AddExperience(int exp, vector<Hero::UpgradeInfo> &info) {
+       if (level > numLevels) {
+               // don't award any experience if at highest level
+               return;
+       }
+       int remain = exp;
+       while (remain >= NextLevel()) {
+               int added = NextLevel();
+               experience += added;
+               remain -= added;
+               ++level;
+
+               info.push_back(Hero::UpgradeInfo(Hero::UPGRADE_LVL, level));
+
+               // TODO: upgrade attributes and push info
+
+               if (level > numLevels) {
+                       return;
+               }
+       }
+       experience += remain;
+}
+
+
 void Capsule::UpgradeClass() {
        ++maxClass;
        ++curClass;
index 5aa5f344fd6c09711f2c53f07cdc27507026e9f1..a1afc1b2c012ddd1b0647f1ff185ecffdc46e3d3 100644 (file)
@@ -9,9 +9,11 @@ namespace graphics {
        class Sprite;
 }
 
+#include "Hero.h"
 #include "../common/Stats.h"
 #include "../math/Vector.h"
 
+#include <vector>
 #include <SDL.h>
 
 namespace common {
@@ -65,6 +67,8 @@ public:
        int Experience() const { return experience; }
        int NextLevel() const;
 
+       void AddExperience(int, std::vector<Hero::UpgradeInfo> &);
+
        graphics::Sprite *BattleSprite();
        const graphics::Sprite *BattleSprite() const;
        graphics::Animation *MeleeAnimation();
index cca9d43f812eba77b89c039fc10990889c97645c..4e7b5b91068f08e8db5137fb8f97656afae79bd8 100644 (file)
@@ -17,6 +17,7 @@ using loader::Interpreter;
 using loader::TypeDescription;
 using map::Entity;
 using std::memset;
+using std::vector;
 
 
 namespace common {
@@ -69,6 +70,29 @@ int Hero::NextLevel() const {
        }
 }
 
+void Hero::AddExperience(int exp, vector<UpgradeInfo> &info) {
+       if (level > numLevels) {
+               // don't award any experience if at highest level
+               return;
+       }
+       int remain = exp;
+       while (remain >= NextLevel()) {
+               int added = NextLevel();
+               experience += added;
+               remain -= added;
+               ++level;
+
+               info.push_back(UpgradeInfo(UPGRADE_LVL, level));
+
+               // TODO: upgrade attributes and push info
+
+               if (level > numLevels) {
+                       return;
+               }
+       }
+       experience += remain;
+}
+
 
 bool Hero::CanEquip(const Item &item) const {
        return useMask & item.HeroMask();
index aa12b2559cdfe69aa1221847aded744bfbd8549e..2016396a4458d605c58c0d7fc77919c17f407791 100644 (file)
@@ -37,6 +37,19 @@ public:
                EQUIP_COUNT,
        };
 
+       enum UpgradeType {
+               UPGRADE_LVL,
+               UPGRADE_MHP,
+               UPGRADE_MMP,
+               UPGRADE_ATK,
+               UPGRADE_DFP,
+               UPGRADE_STR,
+               UPGRADE_AGL,
+               UPGRADE_INT,
+               UPGRADE_GUT,
+               UPGRADE_MGR,
+       };
+
        const char *Name() const { return name; }
 
        Uint16 MaxHealth() const { return maxHealth; }
@@ -60,6 +73,14 @@ public:
        int Experience() const { return experience; }
        int NextLevel() const;
 
+       struct UpgradeInfo {
+               UpgradeType type;
+               int amount;
+               UpgradeInfo(UpgradeType t, int a = 0)
+               : type(t), amount(a) { }
+       };
+       void AddExperience(int, std::vector<UpgradeInfo> &);
+
        bool CanEquip(const Item &) const;
        bool CanInvoke(const Spell &) const;
 
@@ -100,6 +121,7 @@ private:
        int level;
        int experience;
 
+       // TODO: ladder should contain hp, mp, and stats mods.
        int *levelLadder;
        int numLevels;
 
index 4fd4e9767b0e52e5ad9f2090c9464a4a539427bd..83baa7734895b28370c2cf9a8b4beab59403bce6 100644 (file)
@@ -45,7 +45,7 @@ export Monster lizard {
                gut:  6,
                mgr:  6
        },
-       expReward: 2,
+       expReward: 8,
        goldReward: 5,
        attackAnimation: ComplexAnimation {
                sprite: lizardSprite,