]> git.localhorst.tv Git - l2e.git/blobdiff - src/battle/BattleState.cpp
fix monster attack animation frame offsets
[l2e.git] / src / battle / BattleState.cpp
index 84d1a497240da814a105eb64301889b412c7650e..fd4be082847813a5c41b16d1dd1155f54b64a572 100644 (file)
@@ -278,6 +278,10 @@ void BattleState::CalculateAttackOrder() {
 }
 
 void BattleState::NextAttack() {
+       if (Victory() || Defeat()) {
+               attackCursor = attackOrder.size();
+               return;
+       }
        ++attackCursor;
        while (attackCursor < int(attackOrder.size())) {
                if (attackOrder[attackCursor].isMonster) {
@@ -375,15 +379,20 @@ void BattleState::ApplyDamage() {
        TargetSelection &ts(ac.Selection());
        if (ts.TargetsEnemies()) {
                for (int i(0); i < MaxMonsters(); ++i) {
+                       Monster &monster(MonsterAt(i));
                        if (ts.IsBad(i)) {
-                               MonsterAt(i).SubtractHealth(ts.GetAmount(i));
-                               // TODO: collect reward if dead
+                               monster.SubtractHealth(ts.GetAmount(i));
+                               if (monster.Health() == 0) {
+                                       expReward += monster.ExpReward();
+                                       goldReward += monster.GoldReward();
+                               }
                        }
                }
        } else {
                for (int i(0); i < NumHeroes(); ++i) {
+                       Hero &hero(HeroAt(i));
                        if (ts.IsBad(i)) {
-                               HeroAt(i).SubtractHealth(ts.GetAmount(i));
+                               hero.SubtractHealth(ts.GetAmount(i));
                        }
                }
        }
@@ -440,10 +449,8 @@ void BattleState::RenderMonsters(SDL_Surface *screen, const Vector<int> &offset)
        for (vector<Monster>::size_type i(0), end(monsters.size()); i < end; ++i) {
                if (MonsterPositionOccupied(i)) {
                        // TODO: better solution for running animations
-                       if (monsters[i].AttackAnimation() && monsters[i].AttackAnimation()->Running()) {
-                               monsters[i].AttackAnimation()->DrawCenter(screen, monsterPositions[i] + offset);
-                       } else if (monsters[i].SpellAnimation() && monsters[i].SpellAnimation()->Running()) {
-                               monsters[i].SpellAnimation()->DrawCenter(screen, monsterPositions[i] + offset);
+                       if (monsters[i].GetAnimation().Running()) {
+                               monsters[i].GetAnimation().DrawCenter(screen, monsterPositions[i] + offset);
                        } else {
                                monsters[i].Sprite()->DrawCenter(screen, monsterPositions[i] + offset);
                        }
@@ -454,10 +461,8 @@ void BattleState::RenderMonsters(SDL_Surface *screen, const Vector<int> &offset)
 void BattleState::RenderHeroes(SDL_Surface *screen, const Vector<int> &offset) {
        assert(screen);
        for (int i(0); i < numHeroes; ++i) {
-               if (heroes[i].AttackAnimation() && heroes[i].AttackAnimation()->Running()) {
-                       heroes[i].AttackAnimation()->DrawCenter(screen, heroesPositions[i] + offset);
-               } else if (heroes[i].SpellAnimation() && heroes[i].SpellAnimation()->Running()) {
-                       heroes[i].SpellAnimation()->DrawCenter(screen, heroesPositions[i] + offset);
+               if (heroes[i].GetAnimation().Running()) {
+                       heroes[i].GetAnimation().DrawCenter(screen, heroesPositions[i] + offset);
                } else {
                        int row(heroes[i].Health() > 0 ? 0 : 2);
                        heroes[i].Sprite()->DrawCenter(screen, heroesPositions[i] + offset, 1, row);