]> git.localhorst.tv Git - l2e.git/blobdiff - src/battle/states/SelectItem.cpp
added spell target select
[l2e.git] / src / battle / states / SelectItem.cpp
index 0bdd4b10c3adfba9fe4216e5a8b9e6cc1d582628..96def09e1bed6803972feb3521ca0ffe9af5fed4 100644 (file)
@@ -8,15 +8,18 @@
 #include "SelectItem.h"
 
 #include "SelectAttackType.h"
+#include "SelectTarget.h"
 #include "../BattleState.h"
 #include "../../app/Application.h"
 #include "../../app/Input.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::Item;
 using geometry::Point;
 using geometry::Vector;
 using graphics::Frame;
@@ -32,7 +35,9 @@ void SelectItem::ExitState(Application &c, SDL_Surface *screen) {
 }
 
 void SelectItem::ResumeState(Application &ctrl, SDL_Surface *screen) {
-
+       if (battle->ActiveHeroTargets().HasSelected()) {
+               ctrl.PopState();
+       }
 }
 
 void SelectItem::PauseState(Application &ctrl, SDL_Surface *screen) {
@@ -47,10 +52,28 @@ void SelectItem::Resize(int width, int height) {
 
 void SelectItem::HandleInput(const Input &input) {
        if (input.JustPressed(Input::ACTION_A)) {
-               // TODO: switch to target select
                if (battle->GetItemMenu().SelectedIsEnabled()) {
-                       battle->NextHero();
-                       ctrl->PopState();
+                       const Item *item(battle->GetItemMenu().Selected());
+                       battle->ActiveHeroTargets().Reset();
+                       if (item->GetTargetingMode().TargetsAlly()) {
+                               battle->ActiveHeroTargets().SelectHeroes();
+                       } else {
+                               battle->ActiveHeroTargets().SelectEnemies();
+                       }
+                       if (item->GetTargetingMode().TargetsAll()) {
+                               battle->SetAttackType(AttackChoice::ITEM);
+                               // TODO: remove item from inventory
+                               battle->ActiveHeroAttackChoice().SetItem(item);
+                               battle->NextHero();
+                               ctrl->PopState();
+                       } else {
+                               if (item->GetTargetingMode().TargetsSingle()) {
+                                       battle->ActiveHeroTargets().SetSingle();
+                               } else {
+                                       battle->ActiveHeroTargets().SetMultiple();
+                               }
+                               ctrl->PushState(new SelectTarget(battle, parent, &battle->ActiveHeroTargets(), battle->Res().itemTargetCursor));
+                       }
                }
        }
        if (input.JustPressed(Input::ACTION_B)) {