More handling of script hooks.

This commit is contained in:
2019-11-09 12:55:48 +01:00
parent ee14efe22e
commit 658672a246
4 changed files with 44 additions and 34 deletions

View File

@@ -78,23 +78,33 @@ void TurnHandler::ExecuteAttackChoice(const AttackTurnChoice *choice) {
}
void TurnHandler::HandleAttackForTarget(ExecutingAttack &attack, Creature *target, ExecutingAttack::TargetData &targetData) {
//HOOK: Check if attack fails on target
std::array<ScriptSource*, 1> sources = {target};
HOOK(OnIncomingAttackFails, sources, &attack, target);
auto user = attack.GetUser();
//HOOK: Check if target is invulnerable
HOOK(IsInvulnerable, sources, &attack, target);
std::array<ScriptSource*, 1> targetSources = {target};
std::array<ScriptSource*, 1> userSources = {user};
bool fail = false;
HOOK(FailIncomingAttack, targetSources, &attack, target, fail);
if (fail){
//TODO: Fail handling.
return;
}
bool invulnerable = fail;
HOOK(IsInvulnerable, targetSources, &attack, target, invulnerable);
if (invulnerable){
//TODO: We should probably do something when a target is invulnerable.
return;
}
if (!targetData.IsHit()){
//HOOK: On attack miss.
HOOK(OnAttackMiss, sources, &attack, target);
HOOK(OnAttackMiss, targetSources, &attack, target);
return;
}
auto numHits = targetData.GetNumberOfHits();
if (numHits == 0)
return;
auto user = attack.GetUser();
auto attackData = attack.GetAttack()->GetAttack();
auto library = user->GetBattle()->GetLibrary();
auto dmgLibrary = library->GetDamageLibrary();
@@ -108,14 +118,16 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack &attack, Creature *targe
}
auto hit = targetData.GetHit(hitIndex);
//HOOK: Change move type
hit.SetEffectiveness(library->GetTypeLibrary()->GetEffectiveness(hit.GetType(), target->GetTypes()));
auto hitType = hit.GetType();
HOOK(ChangeAttackType, targetSources, &attack, target, hitIndex, hitType);
hit.SetEffectiveness(library->GetTypeLibrary()->GetEffectiveness(hitType, target->GetTypes()));
hit.SetCritical(library->GetCriticalLibrary()->IsCritical(&attack, target, hitIndex));
hit.SetBasePower(dmgLibrary->GetBasePower(&attack, target, hitIndex));
hit.SetDamage(dmgLibrary->GetDamage(&attack, target, hitIndex));
std::array<ScriptSource*, 1> attackSource = {&attack};
if (attackData->GetCategory() == Library::AttackCategory::Status){
//HOOK: Status attack
HOOK(OnStatusMove, attackSource, &attack, target, hitIndex);
}
else{
auto damage = hit.GetDamage();
@@ -125,14 +137,17 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack &attack, Creature *targe
}
if (damage > 0){
target->Damage(damage, DamageSource::AttackDamage);
//HOOK: Prevent secondary effects
//HOOK: On Move Hit
bool preventSecondary = false;
HOOK(PreventSecondaryEffects, targetSources, &attack, target, hitIndex, preventSecondary);
if (!preventSecondary){
//HOOK: On Move Hit
}
}
}
}
if (!user->IsFainted()){
//HOOK: On After Hits
if (!user->IsFainted())
HOOK(OnAfterHits, userSources, attack, target);
}
}