X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fbattle%2Fstates%2FPerformAttacks.cpp;h=4f7a427c6a404a5fbac1ecc3f29de5c1bba936b7;hb=85ac93ffe31bfeee54aa6167111f1c15f14bc405;hp=c34e1144cdc6e4e54de9ca9ec1b6130bb6dafbd6;hpb=b9fdb4fd361fbc0c8e2c0df9615e6eed540917a1;p=l2e.git diff --git a/src/battle/states/PerformAttacks.cpp b/src/battle/states/PerformAttacks.cpp index c34e114..4f7a427 100644 --- a/src/battle/states/PerformAttacks.cpp +++ b/src/battle/states/PerformAttacks.cpp @@ -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 @@ -27,13 +27,12 @@ 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 + battle->WriteOrder(order); } void PerformAttacks::ExitState(Application &c, SDL_Surface *screen) { @@ -41,7 +40,7 @@ void PerformAttacks::ExitState(Application &c, SDL_Surface *screen) { } void PerformAttacks::ResumeState(Application &ctrl, SDL_Surface *screen) { - fakeMoveTimer = GraphicsTimers().StartCountdown(850); + } void PerformAttacks::PauseState(Application &ctrl, SDL_Surface *screen) { @@ -55,98 +54,72 @@ void PerformAttacks::Resize(int width, int height) { void PerformAttacks::HandleEvents(const Input &input) { - if (fakeMoveTimer.JustHit()) { - if (monsters) { - if (titleBarText) { - titleBarText = 0; - ++cursor; - while (cursor < battle->MaxMonsters() && !battle->MonsterPositionOccupied(cursor)) { - ++cursor; - } - if (cursor >= battle->MaxMonsters()) { - battle->ClearAllAttacks(); - ctrl->PopState(); - } - } else { - if (cursor == 0) { - battle->HeroAnimationAt(battle->NumHeroes() - 1).Stop(); - } - titleBarText = battle->MonsterAt(cursor).Name(); - } + if (titleBarTimer.Running() || (moveAnimation && moveAnimation->Running())) return; + + if (moveAnimation) moveAnimation->Stop(); + titleBarTimer.Clear(); + + ++cursor; + + while (cursor < int(order.size())) { + if (order[cursor].isMonster) { + if (battle->MonsterAt(order[cursor].index).Health() > 0) break; } else { - const AttackChoice &ac(battle->AttackChoiceAt(cursor)); - if (titleBarText) { - titleBarText = 0; - - switch (ac.GetType()) { - case AttackChoice::SWORD: - battle->HeroAnimationAt(cursor) = SimpleAnimation( - battle->HeroAt(cursor).Sprite(), - battle->HeroAt(cursor).AttackFrameTime(), - battle->HeroAt(cursor).AttackFrames(), 2); - break; - case AttackChoice::MAGIC: - battle->HeroAnimationAt(cursor) = SimpleAnimation( - battle->HeroAt(cursor).Sprite(), - battle->HeroAt(cursor).SpellFrameTime(), - battle->HeroAt(cursor).SpellFrames(), 3); - 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); - } else { - battle->HeroAnimationAt(cursor) = SimpleAnimation( - battle->HeroAt(cursor).Sprite(), - battle->HeroAt(cursor).AttackFrameTime(), - battle->HeroAt(cursor).AttackFrames(), 2); - } - } - break; - case AttackChoice::ITEM: - break; - case AttackChoice::UNDECIDED: - break; - } - battle->HeroAnimationAt(cursor).Start(*this); + if (battle->HeroAt(order[cursor].index).Health() > 0) break; + } + ++cursor; + } - ++cursor; - if (cursor == battle->NumHeroes()) { - cursor = 0; - monsters = true; - } - } else { - if (cursor > 0) { - battle->HeroAnimationAt(cursor - 1).Stop(); - } - switch (ac.GetType()) { - case AttackChoice::SWORD: - titleBarText = battle->HeroAt(cursor).HasWeapon() ? battle->HeroAt(cursor).Weapon()->Name() : "Gauntlet"; - break; - case AttackChoice::MAGIC: - titleBarText = ac.GetSpell()->Name(); - break; - case AttackChoice::DEFEND: - titleBarText = "Defends."; - break; - case AttackChoice::IKARI: - titleBarText = ac.GetItem()->HasIkari() ? ac.GetItem()->GetIkari()->Name() : "No Ikari?"; - break; - case AttackChoice::ITEM: - titleBarText = ac.GetItem()->Name(); - break; - case AttackChoice::UNDECIDED: - titleBarText = "WTF???"; - break; + if (cursor >= int(order.size())) { + battle->ClearAllAttacks(); + ctrl->PopState(); + return; + } + + if (order[cursor].isMonster) { + const Monster &monster(battle->MonsterAt(order[cursor].index)); + titleBarText = monster.Name(); + moveAnimation = 0; + } else { + Hero &hero(battle->HeroAt(order[cursor].index)); + const AttackChoice &ac(battle->AttackChoiceAt(order[cursor].index)); + + switch (ac.GetType()) { + case AttackChoice::SWORD: + titleBarText = hero.HasWeapon() ? hero.Weapon()->Name() : "Melee attack!"; + moveAnimation = hero.AttackAnimation(); + break; + case AttackChoice::MAGIC: + titleBarText = ac.GetSpell()->Name(); + moveAnimation = hero.SpellAnimation(); + break; + case AttackChoice::DEFEND: + titleBarText = "Defends."; + moveAnimation = 0; + break; + case AttackChoice::IKARI: + if (ac.GetItem()->HasIkari()) { + titleBarText = ac.GetItem()->GetIkari()->Name(); + if (ac.GetItem()->GetIkari()->IsMagical()) { + moveAnimation = hero.SpellAnimation(); + } else { + moveAnimation = hero.AttackAnimation(); + } } - } + break; + case AttackChoice::ITEM: + titleBarText = ac.GetItem()->Name(); + moveAnimation = 0; + break; + case AttackChoice::UNDECIDED: + titleBarText = "UNDECIDED"; + moveAnimation = 0; + break; } } + + titleBarTimer = GraphicsTimers().StartCountdown(1500); + if (moveAnimation) moveAnimation->Start(*this); } @@ -164,7 +137,7 @@ void PerformAttacks::Render(SDL_Surface *screen) { } void PerformAttacks::RenderTitleBar(SDL_Surface *screen, const Vector &offset) { - if (!titleBarText) return; + if (!titleBarText || !titleBarTimer.Running()) return; int height(battle->Res().titleFrame->BorderHeight() * 2 + battle->Res().titleFont->CharHeight()); battle->Res().titleFrame->Draw(screen, Point(offset.X(), offset.Y()), battle->BackgroundWidth(), height);