]> git.localhorst.tv Git - l2e.git/blobdiff - src/battle/states/PerformAttacks.cpp
added complex attack and spell animations
[l2e.git] / src / battle / states / PerformAttacks.cpp
index c34e1144cdc6e4e54de9ca9ec1b6130bb6dafbd6..93a09ef77d8baa79726a59149880a1518364451f 100644 (file)
@@ -17,9 +17,9 @@
 #include "../../common/Spell.h"
 #include "../../geometry/operators.h"
 #include "../../geometry/Point.h"
+#include "../../graphics/Animation.h"
 #include "../../graphics/Font.h"
 #include "../../graphics/Frame.h"
-#include "../../graphics/SimpleAnimation.h"
 
 #include <cstring>
 
@@ -27,13 +27,11 @@ using app::Application;
 using app::Input;
 using geometry::Point;
 using geometry::Vector;
-using graphics::SimpleAnimation;
 
 namespace battle {
 
 void PerformAttacks::EnterState(Application &c, SDL_Surface *screen) {
        ctrl = &c;
-       // TODO: push battle animation if enemy is faster
 }
 
 void PerformAttacks::ExitState(Application &c, SDL_Surface *screen) {
@@ -69,7 +67,12 @@ void PerformAttacks::HandleEvents(const Input &input) {
                                }
                        } else {
                                if (cursor == 0) {
-                                       battle->HeroAnimationAt(battle->NumHeroes() - 1).Stop();
+                                       if (battle->HeroAt(battle->NumHeroes() - 1).AttackAnimation()) {
+                                               battle->HeroAt(battle->NumHeroes() - 1).AttackAnimation()->Stop();
+                                       }
+                                       if (battle->HeroAt(battle->NumHeroes() - 1).SpellAnimation()) {
+                                               battle->HeroAt(battle->NumHeroes() - 1).SpellAnimation()->Stop();
+                                       }
                                }
                                titleBarText = battle->MonsterAt(cursor).Name();
                        }
@@ -80,31 +83,27 @@ void PerformAttacks::HandleEvents(const Input &input) {
 
                                switch (ac.GetType()) {
                                        case AttackChoice::SWORD:
-                                               battle->HeroAnimationAt(cursor) = SimpleAnimation(
-                                                               battle->HeroAt(cursor).Sprite(),
-                                                               battle->HeroAt(cursor).AttackFrameTime(),
-                                                               battle->HeroAt(cursor).AttackFrames(), 2);
+                                               if (battle->HeroAt(cursor).AttackAnimation()) {
+                                                       battle->HeroAt(cursor).AttackAnimation()->Start(*this);
+                                               }
                                                break;
                                        case AttackChoice::MAGIC:
-                                               battle->HeroAnimationAt(cursor) = SimpleAnimation(
-                                                               battle->HeroAt(cursor).Sprite(),
-                                                               battle->HeroAt(cursor).SpellFrameTime(),
-                                                               battle->HeroAt(cursor).SpellFrames(), 3);
+                                               if (battle->HeroAt(cursor).SpellAnimation()) {
+                                                       battle->HeroAt(cursor).SpellAnimation()->Start(*this);
+                                               }
                                                break;
                                        case AttackChoice::DEFEND:
                                                break;
                                        case AttackChoice::IKARI:
                                                if (ac.GetItem()->HasIkari()) {
                                                        if (ac.GetItem()->GetIkari()->IsMagical()) {
-                                                               battle->HeroAnimationAt(cursor) = SimpleAnimation(
-                                                                               battle->HeroAt(cursor).Sprite(),
-                                                                               battle->HeroAt(cursor).SpellFrameTime(),
-                                                                               battle->HeroAt(cursor).SpellFrames(), 3);
+                                                               if (battle->HeroAt(cursor).SpellAnimation()) {
+                                                                       battle->HeroAt(cursor).SpellAnimation()->Start(*this);
+                                                               }
                                                        } else {
-                                                               battle->HeroAnimationAt(cursor) = SimpleAnimation(
-                                                                               battle->HeroAt(cursor).Sprite(),
-                                                                               battle->HeroAt(cursor).AttackFrameTime(),
-                                                                               battle->HeroAt(cursor).AttackFrames(), 2);
+                                                               if (battle->HeroAt(cursor).AttackAnimation()) {
+                                                                       battle->HeroAt(cursor).AttackAnimation()->Start(*this);
+                                                               }
                                                        }
                                                }
                                                break;
@@ -113,7 +112,6 @@ void PerformAttacks::HandleEvents(const Input &input) {
                                        case AttackChoice::UNDECIDED:
                                                break;
                                }
-                               battle->HeroAnimationAt(cursor).Start(*this);
 
                                ++cursor;
                                if (cursor == battle->NumHeroes()) {
@@ -122,7 +120,12 @@ void PerformAttacks::HandleEvents(const Input &input) {
                                }
                        } else {
                                if (cursor > 0) {
-                                       battle->HeroAnimationAt(cursor - 1).Stop();
+                                       if (battle->HeroAt(cursor - 1).AttackAnimation()) {
+                                               battle->HeroAt(cursor - 1).AttackAnimation()->Stop();
+                                       }
+                                       if (battle->HeroAt(cursor - 1).SpellAnimation()) {
+                                               battle->HeroAt(cursor - 1).SpellAnimation()->Stop();
+                                       }
                                }
                                switch (ac.GetType()) {
                                        case AttackChoice::SWORD: