Initial work on item use handling
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -79,7 +79,7 @@ void TurnHandler::ExecuteChoice(const ArbUt::BorrowedPtr<BaseTurnChoice>& choice
|
||||
case TurnChoiceKind::Switch: return ExecuteSwitchChoice(choice.ForceAs<SwitchTurnChoice>());
|
||||
case TurnChoiceKind::Flee: return ExecuteFleeChoice(choice.ForceAs<FleeTurnChoice>());
|
||||
|
||||
case TurnChoiceKind::Item: NOT_IMPLEMENTED;
|
||||
case TurnChoiceKind::Item: return ExecuteItemChoice(choice.ForceAs<ItemTurnChoice>());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -361,3 +361,29 @@ void TurnHandler::ExecuteFleeChoice(const ArbUt::BorrowedPtr<FleeTurnChoice>& ch
|
||||
battle.GetValue()->ValidateBattleState();
|
||||
}
|
||||
}
|
||||
void TurnHandler::ExecuteItemChoice(const ArbUt::BorrowedPtr<ItemTurnChoice>& choice) {
|
||||
auto user = choice->GetUser();
|
||||
auto battle = user->GetBattle();
|
||||
if (!battle.HasValue()) {
|
||||
return;
|
||||
}
|
||||
auto* script = battle.GetValue()->GetLibrary()->GetScriptResolver()->LoadItemScript(choice->GetItem());
|
||||
auto targetIndex = choice->GetTarget();
|
||||
ArbUt::OptionalBorrowedPtr<Creature> target = nullptr;
|
||||
if (targetIndex.has_value()) {
|
||||
target = battle.GetValue()->GetCreature(targetIndex.value());
|
||||
}
|
||||
auto isCreatureUseItem = script->IsCreatureUseItem();
|
||||
if (isCreatureUseItem && !target.HasValue()) {
|
||||
target = choice->GetUser();
|
||||
}
|
||||
|
||||
if (isCreatureUseItem) {
|
||||
if (!script->IsUseValidForCreature(target.GetValue())) {
|
||||
return;
|
||||
}
|
||||
script->OnCreatureUse(target.GetValue(), true);
|
||||
} else {
|
||||
script->OnUse(battle.GetValue());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user