]> git.localhorst.tv Git - l2e.git/blobdiff - src/battle/states/SelectAttackType.cpp
fixed attack choice reset bug
[l2e.git] / src / battle / states / SelectAttackType.cpp
index 4bac0bbe50cf1d8ebf7a827f042e14588bd304cb..7f366818143ad48c29beeb70ea966b7e85fe085c 100644 (file)
 #include "../BattleState.h"
 #include "../../app/Application.h"
 #include "../../app/Input.h"
+#include "../../common/Item.h"
 #include "../../geometry/operators.h"
 
 #include <stdexcept>
 
 using app::Application;
 using app::Input;
+using common::Item;
 using geometry::Point;
 using geometry::Vector;
 
@@ -69,13 +71,24 @@ void SelectAttackType::HandleEvents(const Input &input) {
                battle->GetAttackTypeMenu().Select(AttackChoice::SWORD);
        }
 
+       Hero &hero(battle->ActiveHero());
+       AttackChoice &ac(hero.GetAttackChoice());
        if (input.JustPressed(Input::ACTION_A)) {
                switch (battle->GetAttackTypeMenu().Selected()) {
                        case AttackChoice::SWORD:
-                               // TODO: detect single/multiple/all attack mode
-                               battle->ActiveHero().GetAttackChoice().Selection().SetSingle();
-                               battle->ActiveHero().GetAttackChoice().Selection().Reset();
-                               ctrl->PushState(new SelectTarget(battle, this, &battle->ActiveHero().GetAttackChoice().Selection(), battle->Res().weaponTargetCursor));
+                               if (hero.HasWeapon()) {
+                                       if (hero.Weapon()->GetTargetingMode().TargetsAll()) {
+                                               ac.SetType(AttackChoice::SWORD);
+                                               battle->NextHero();
+                                               break;
+                                       } else {
+                                               ac.Selection().ReadMode(hero.Weapon()->GetTargetingMode());
+                                       }
+                               } else {
+                                       ac.Selection().SetSingle();
+                               }
+                               ac.Selection().Reset();
+                               ctrl->PushState(new SelectTarget(battle, this, &ac.Selection(), battle->Res().weaponTargetCursor));
                                break;
                        case AttackChoice::MAGIC:
                                if (battle->ActiveHero().CanUseMagic()) {
@@ -83,7 +96,7 @@ void SelectAttackType::HandleEvents(const Input &input) {
                                }
                                break;
                        case AttackChoice::DEFEND:
-                               battle->ActiveHero().GetAttackChoice().SetType(AttackChoice::DEFEND);
+                               ac.SetType(AttackChoice::DEFEND);
                                battle->NextHero();
                                break;
                        case AttackChoice::IKARI:
@@ -96,7 +109,7 @@ void SelectAttackType::HandleEvents(const Input &input) {
                                throw std::logic_error("selected invalid attack type");
                }
        } else if (input.JustPressed(Input::ACTION_B)) {
-               battle->ActiveHero().GetAttackChoice().Reset();
+               ac.Reset();
                battle->PreviousHero();
                if (battle->BeforeFirstHero()) {
                        ctrl->ChangeState(new SelectMoveAction(battle));