]> git.localhorst.tv Git - l2e.git/blobdiff - src/battle/states/PerformAttacks.cpp
added Maxim's melee animation
[l2e.git] / src / battle / states / PerformAttacks.cpp
index dd0e0df1cd0a27de4102081e4b8a6e470e945f01..6c318aaf04138e86c627a94429dcdec23e260911 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "PerformAttacks.h"
 
+#include "../AttackAnimation.h"
 #include "../BattleState.h"
 #include "../Hero.h"
 #include "../Monster.h"
@@ -57,6 +58,7 @@ void PerformAttacks::Resize(int width, int height) {
 
 
 void PerformAttacks::HandleEvents(const Input &input) {
+       if (attackAnimation) attackAnimation->Update();
        CheckNumberAnimation();
        if (HasAnimationsRunning()) return;
        ResetAnimation();
@@ -77,8 +79,19 @@ void PerformAttacks::HandleEvents(const Input &input) {
 
                switch (ac.GetType()) {
                        case AttackChoice::SWORD:
-                               titleBarText = hero.HasWeapon() ? hero.Weapon()->Name() : "Melee attack!";
-                               moveAnimation = hero.AttackAnimation();
+                               if (hero.HasWeapon()) {
+                                       titleBarText = hero.Weapon()->Name();
+                                       moveAnimation = hero.AttackAnimation();
+                               } else {
+                                       titleBarText = "Melee attack!";
+                                       if (hero.MeleeAnimation()) {
+                                               moveAnimation = 0;
+                                               attackAnimation = hero.MeleeAnimation();
+                                       } else {
+                                               moveAnimation = hero.AttackAnimation();
+                                               attackAnimation = 0;
+                                       }
+                               }
                                numberAnimation.push_back(NumberAnimation(15, battle->Res().numberAnimationPrototype, battle->Res().bigNumberSprite));
                                if (ac.Selection().TargetsEnemies()) {
                                        numberPosition.push_back(
@@ -119,11 +132,15 @@ void PerformAttacks::HandleEvents(const Input &input) {
 
        if (titleBarText) titleBarTimer = GraphicsTimers().StartCountdown(1500);
        if (moveAnimation) moveAnimation->Start(*this);
+       if (attackAnimation) attackAnimation->Start(battle, this);
 }
 
 void PerformAttacks::CheckNumberAnimation() {
        if (moveAnimation && moveAnimation->Running()) return;
-       if (!moveAnimation || moveAnimation->JustFinished()) {
+       if (attackAnimation && !attackAnimation->Finished()) return;
+       if (moveAnimation || attackAnimation) {
+               moveAnimation = 0;
+               attackAnimation = 0;
                for (vector<NumberAnimation>::iterator i(numberAnimation.begin()), end(numberAnimation.end()); i != end; ++i) {
                        i->Start(*this);
                }
@@ -145,6 +162,7 @@ bool PerformAttacks::HasAnimationsRunning() const {
 
 void PerformAttacks::ResetAnimation() {
        if (moveAnimation) moveAnimation->Stop();
+       if (attackAnimation) attackAnimation = 0;
        titleBarTimer.Clear();
        numberAnimation.clear();
        numberPosition.clear();
@@ -175,6 +193,7 @@ void PerformAttacks::Render(SDL_Surface *screen) {
        battle->RenderSmallHeroTags(screen, offset);
        RenderTitleBar(screen, offset);
        RenderNumbers(screen, offset);
+       if (attackAnimation) attackAnimation->Render(screen, offset);
 }
 
 void PerformAttacks::RenderTitleBar(SDL_Surface *screen, const Vector<int> &offset) {