]> git.localhorst.tv Git - l2e.git/blobdiff - src/battle/states/SelectIkari.cpp
removed redundant BattleState::ActiveHeroAttackChoice()
[l2e.git] / src / battle / states / SelectIkari.cpp
index 85b61c79d24443dc02be1396e07e7c81b39e06cc..d66f8b5458dff6fccd822a38d278e6b61ea5a776 100644 (file)
@@ -8,15 +8,19 @@
 #include "SelectIkari.h"
 
 #include "SelectAttackType.h"
+#include "SelectTarget.h"
 #include "../BattleState.h"
 #include "../../app/Application.h"
 #include "../../app/Input.h"
+#include "../../common/Ikari.h"
+#include "../../common/Item.h"
 #include "../../geometry/Point.h"
 #include "../../geometry/operators.h"
 #include "../../graphics/Frame.h"
 
 using app::Application;
 using app::Input;
+using common::Ikari;
 using geometry::Point;
 using geometry::Vector;
 using graphics::Frame;
@@ -32,7 +36,11 @@ void SelectIkari::ExitState(Application &c, SDL_Surface *screen) {
 }
 
 void SelectIkari::ResumeState(Application &ctrl, SDL_Surface *screen) {
-
+       if (battle->ActiveHero().GetAttackChoice().Selection().HasSelected()) {
+               battle->ActiveHero().GetAttackChoice().SetType(AttackChoice::IKARI);
+               battle->ActiveHero().GetAttackChoice().SetItem(battle->GetIkariMenu().Selected());
+               ctrl.PopState();
+       }
 }
 
 void SelectIkari::PauseState(Application &ctrl, SDL_Surface *screen) {
@@ -45,13 +53,31 @@ void SelectIkari::Resize(int width, int height) {
 }
 
 
-void SelectIkari::HandleInput(const Input &input) {
+void SelectIkari::HandleEvents(const Input &input) {
        if (input.JustPressed(Input::ACTION_A)) {
-               // TODO: switch to target select
-               if (battle->GetIkariMenu().SelectedIsEnabled()) {
-                       battle->SetAttackType(AttackChoice::IKARI);
-                       battle->NextHero();
-                       ctrl->PopState();
+               if (battle->GetIkariMenu().SelectedIsEnabled() && battle->GetIkariMenu().Selected()->HasIkari()) {
+                       AttackChoice &ac(battle->ActiveHero().GetAttackChoice());
+                       const Ikari *ikari(battle->GetIkariMenu().Selected()->GetIkari());
+                       ac.Selection().Reset();
+                       if (ikari->GetTargetingMode().TargetsAlly()) {
+                               ac.Selection().SelectHeroes();
+                       } else {
+                               ac.Selection().SelectEnemies();
+                       }
+                       if (ikari->GetTargetingMode().TargetsAll()) {
+                               ac.SetType(AttackChoice::MAGIC);
+                               // TODO: remove item from inventory
+                               ac.SetItem(battle->GetIkariMenu().Selected());
+                               battle->NextHero();
+                               ctrl->PopState();
+                       } else {
+                               if (ikari->GetTargetingMode().TargetsSingle()) {
+                                       ac.Selection().SetSingle();
+                               } else {
+                                       ac.Selection().SetMultiple();
+                               }
+                               ctrl->PushState(new SelectTarget(battle, parent, &ac.Selection(), ikari->IsMagical() ? battle->Res().magicTargetCursor : battle->Res().weaponTargetCursor));
+                       }
                }
        }
        if (input.JustPressed(Input::ACTION_B)) {
@@ -86,7 +112,7 @@ void SelectIkari::Render(SDL_Surface *screen) {
 void SelectIkari::RenderFrame(SDL_Surface *screen, const Vector<int> &offset) {
        const Frame *frame(battle->Res().selectFrame);
        Point<int> position(frame->BorderWidth(), frame->BorderHeight());
-       int width(battle->BackgroundWidth() - 2 * frame->BorderWidth());
+       int width(battle->Width() - 2 * frame->BorderWidth());
        int height(battle->Res().normalFont->CharHeight() * 13);
        frame->Draw(screen, position + offset, width, height);
 }