]> git.localhorst.tv Git - l2e.git/commitdiff
apply damage indicated by attack selection
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 19 Aug 2012 18:01:50 +0000 (20:01 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 19 Aug 2012 18:01:50 +0000 (20:01 +0200)
src/battle/BattleState.cpp
src/battle/BattleState.h
src/battle/Hero.cpp
src/battle/Hero.h
src/battle/Monster.cpp
src/battle/Monster.h
src/battle/TargetSelection.h
src/battle/states/PerformAttacks.cpp

index dcad8b2322d3c12197e3a308438da6556bddc294..be3c9705d712ee8f03f790c3f2989959b571f237 100644 (file)
@@ -213,6 +213,7 @@ void BattleState::ResumeState(Application &ctrl, SDL_Surface *screen) {
                ctrl.PopState(); // quit the battle scene
                return;
        }
+       // TODO: this should not push a state while quitting
        if (AttackSelectionDone()) {
                ctrl.PushState(new PerformAttacks(this));
        } else {
@@ -272,14 +273,14 @@ void BattleState::CalculateDamage() {
        } else {
                TargetSelection &ts(AttackChoiceAt(CurrentAttack().index).Selection());
                if (ts.TargetsEnemies()) {
-                       for (int i(0); i < NumHeroes(); ++i) {
-                               if (ts.IsSelected(i)) {
+                       for (int i(0); i < MaxMonsters(); ++i) {
+                               if (ts.IsSelected(i) && MonsterAt(i).Health() > 0) {
                                        ts.SetBad(i, 15);
                                }
                        }
                } else {
-                       for (int i(0); i < MaxMonsters(); ++i) {
-                               if (ts.IsSelected(i) && MonsterAt(i).Health() > 0) {
+                       for (int i(0); i < NumHeroes(); ++i) {
+                               if (ts.IsSelected(i) && HeroAt(i).Health() > 0) {
                                        ts.SetBad(i, 15);
                                }
                        }
@@ -287,6 +288,25 @@ void BattleState::CalculateDamage() {
        }
 }
 
+void BattleState::ApplyDamage() {
+       if (attackCursor < 0) return;
+       AttackChoice &ac(CurrentAttack().isMonster ? monsterAttacks[CurrentAttack().index] : AttackChoiceAt(CurrentAttack().index));
+       TargetSelection &ts(ac.Selection());
+       if (ts.TargetsEnemies()) {
+               for (int i(0); i < MaxMonsters(); ++i) {
+                       if (ts.IsBad(i)) {
+                               MonsterAt(i).SubtractHealth(ts.GetAmount(i));
+                       }
+               }
+       } else {
+               for (int i(0); i < NumHeroes(); ++i) {
+                       if (ts.IsSelected(i) && MonsterAt(i).Health() > 0) {
+                               HeroAt(i).SubtractHealth(ts.GetAmount(i));
+                       }
+               }
+       }
+}
+
 void BattleState::ClearAllAttacks() {
        attackCursor = -1;
        activeHero = -1;
index 5898a2d4aa93920ffc9a5a20a1d366240d46de5c..45c43f9c70a27387e20cc65b48fb9a39033fc0d9 100644 (file)
@@ -130,6 +130,7 @@ public:
        void NextAttack();
        bool AttacksFinished() const { return attackCursor >= int(attackOrder.size()); }
        void CalculateDamage();
+       void ApplyDamage();
        const Order &CurrentAttack() const { return attackOrder[attackCursor]; };
        void ClearAllAttacks();
 
index 4bfdf0a0cf651e879cb80d7b1bad92e12effd892..ab3b23e9b9c396e023516e539f640501a76ff831 100644 (file)
@@ -45,4 +45,13 @@ Hero::~Hero() {
 
 }
 
+
+void Hero::SubtractHealth(int amount) {
+       if (amount > Health()) {
+               health = 0;
+       } else {
+               health -= amount;
+       }
+}
+
 }
index d5284ae3d9a9f78f5bf3661be526d73ad04d9c94..7abfb68fb35ae5f8a0cd16e243678546cf58074e 100644 (file)
@@ -38,6 +38,7 @@ public:
        Uint16 MaxHealth() const { return maxHealth; }
        Uint16 Health() const { return health; }
        int RelativeHealth(int max) const { return Health() * max / MaxHealth(); }
+       void SubtractHealth(int amount);
 
        Uint16 MaxMana() const { return maxMana; }
        Uint16 Mana() const { return mana; }
index acbe6cf93bdacbd402eb4cff94ee6ce53396bb51..033614231ff0cea9ffec691b5c0dfcf307822901 100644 (file)
@@ -40,4 +40,13 @@ Monster::~Monster() {
 
 }
 
+
+void Monster::SubtractHealth(int amount) {
+       if (amount > Health()) {
+               health = 0;
+       } else {
+               health -= amount;
+       }
+}
+
 }
index f37786a076f3f8618449a7148a2faf8539716ff8..f79eaab3e1fc7e8dc807ed85b10cef677ed73f81 100644 (file)
@@ -28,6 +28,7 @@ public:
        Uint16 MaxHealth() const { return maxHealth; }
        Uint16 Health() const { return health; }
        int RelativeHealth(int max) const { return health * max / maxHealth; }
+       void SubtractHealth(int amount);
 
        Uint16 MaxMana() const { return maxMana; }
        Uint16 Mana() const { return mana; }
index 64500b0b02aca225a117e2005d60f881f63fae11..70c95b52a469ad9f5280aa1ed554ba911c7fbe8a 100644 (file)
@@ -54,6 +54,9 @@ public:
        void SetGood(int index, int amount) { selected[index].type = State::GOOD; selected[index].number = amount; }
        void SetBad(int index, int amount) { selected[index].type = State::BAD; selected[index].number = amount; }
        int GetAmount(int index) const { return selected[index].number; }
+       bool Missed(int index) const { return selected[index].type == State::MISS; }
+       bool IsGood(int index) const { return selected[index].type == State::GOOD; }
+       bool IsBad(int index) const { return selected[index].type == State::BAD; }
 
 private:
        void FindNextEnemy();
index 6baa1dae0fe700d64d70bab13141d7d857179a0c..9a81e00ccc1b062970761497a2287de524f7c5da 100644 (file)
@@ -60,6 +60,7 @@ void PerformAttacks::HandleEvents(const Input &input) {
        CheckAnimations();
        if (HasAnimationsRunning()) return;
        ResetAnimation();
+       battle->ApplyDamage();
        battle->NextAttack();
        if (battle->AttacksFinished()) {
                battle->ClearAllAttacks();