Support overriding attacks through script hooks.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
@@ -84,17 +84,19 @@ void TurnHandler::ExecuteChoice(const ArbUt::BorrowedPtr<BaseTurnChoice>& choice
|
||||
|
||||
void TurnHandler::ExecuteAttackChoice(const ArbUt::BorrowedPtr<AttackTurnChoice>& choice) {
|
||||
auto battle = choice->GetUser()->GetBattle();
|
||||
auto attackName = choice->GetAttack()->GetAttack()->GetName();
|
||||
auto attackData = choice->GetAttack()->GetAttack();
|
||||
auto attackName = attackData->GetName();
|
||||
HOOK(ChangeAttack, choice, choice.GetRaw(), &attackName);
|
||||
if (attackName != choice->GetAttack()->GetAttack()->GetName()) {
|
||||
// TODO: Change attack
|
||||
attackData = battle.GetValue()->GetLibrary()->GetAttackLibrary()->Get(attackName);
|
||||
}
|
||||
|
||||
auto targetType = choice->GetAttack()->GetAttack()->GetTarget();
|
||||
auto targetType = attackData->GetTarget();
|
||||
ArbUt::List<ArbUt::OptionalBorrowedPtr<Creature>> targets;
|
||||
Ensure(battle.HasValue());
|
||||
try_creature(targets = TargetResolver::ResolveTargets(choice->GetTarget(), targetType, battle.GetValue());
|
||||
, "Exception during target determination");
|
||||
// HOOK: override targets
|
||||
|
||||
u8 numberHits = 1;
|
||||
HOOK(ModifyNumberOfHits, choice, choice, &numberHits);
|
||||
@@ -102,15 +104,14 @@ void TurnHandler::ExecuteAttackChoice(const ArbUt::BorrowedPtr<AttackTurnChoice>
|
||||
return;
|
||||
}
|
||||
|
||||
auto attackScoped = ArbUt::ScopedPtr<ExecutingAttack>(
|
||||
new ExecutingAttack(targets, numberHits, choice->GetUser(), choice->GetAttack(), choice->GetAttackScript()));
|
||||
auto attackScoped = ArbUt::ScopedPtr<ExecutingAttack>(new ExecutingAttack(
|
||||
targets, numberHits, choice->GetUser(), choice->GetAttack(), attackData, choice->GetAttackScript()));
|
||||
bool prevented = false;
|
||||
HOOK(PreventAttack, attackScoped, attackScoped, &prevented);
|
||||
if (prevented) {
|
||||
return;
|
||||
}
|
||||
|
||||
// HOOK: override targets
|
||||
if (!choice->GetAttack()->TryUse(1)) {
|
||||
return;
|
||||
}
|
||||
@@ -119,7 +120,6 @@ void TurnHandler::ExecuteAttackChoice(const ArbUt::BorrowedPtr<AttackTurnChoice>
|
||||
battle.GetValue()->TriggerEventListener<AttackUseEvent>(attack);
|
||||
battle.GetValue()->RegisterHistoryElement<AttackUseHistory>(attack);
|
||||
|
||||
// HOOK: check if attack fails
|
||||
bool fail = false;
|
||||
HOOK(FailAttack, attack, attack, &fail);
|
||||
if (fail) {
|
||||
@@ -173,8 +173,7 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, const ArbUt::Bo
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& learnedAttack = attack->GetAttack();
|
||||
const auto& attackData = learnedAttack->GetAttack();
|
||||
const auto& attackData = attack->GetUseAttack();
|
||||
|
||||
const auto& library = battle.GetValue()->GetLibrary();
|
||||
const auto& dmgLibrary = library->GetDamageLibrary();
|
||||
|
||||
Reference in New Issue
Block a user