Furter rework on script hooks, simplifying required logic.

This commit is contained in:
2019-11-10 14:32:05 +01:00
parent f72fd5f905
commit 3488784409
18 changed files with 79 additions and 37 deletions

View File

@@ -24,6 +24,10 @@ namespace CreatureLib::Battling{
[[nodiscard]] bool HasNext() const{
return _current < _queue.size();
}
std::vector<const BaseTurnChoice*>& GetInnerQueue(){
return _queue;
}
};
}

View File

@@ -7,6 +7,9 @@ using namespace CreatureLib::Battling;
void TurnHandler::RunTurn(Battle* battle, ChoiceQueue* queue) {
//HOOK: On Before Turn hook for all choices
for (auto choice: queue->GetInnerQueue()){
HOOK(OnBeforeTurn, choice, choice);
}
while (queue->HasNext()){
if (!battle->HasRecalledSlots()){
return;
@@ -83,25 +86,25 @@ void TurnHandler::ExecuteAttackChoice(const AttackTurnChoice *choice) {
void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature *target, const ExecutingAttack::TargetData &targetData) {
auto user = attack->GetUser();
std::array<ScriptSource*, 1> targetSources = {target};
std::array<ScriptSource*, 1> userSources = {user};
ScriptSource* targetSource = target;
ScriptSource* userSource = attack;
bool fail = false;
HOOK(FailIncomingAttack, targetSources, attack, target, fail);
HOOK(FailIncomingAttack, targetSource, attack, target, fail);
if (fail){
//TODO: Fail handling.
return;
}
bool invulnerable = fail;
HOOK(IsInvulnerable, targetSources, attack, target, invulnerable);
HOOK(IsInvulnerable, targetSource, attack, target, invulnerable);
if (invulnerable){
//TODO: We should probably do something when a target is invulnerable.
return;
}
if (!targetData.IsHit()){
HOOK(OnAttackMiss, targetSources, attack, target);
HOOK(OnAttackMiss, targetSource, attack, target);
return;
}
@@ -122,15 +125,14 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature *targe
auto hit = targetData.GetHit(hitIndex);
auto hitType = hit.GetType();
HOOK(ChangeAttackType, targetSources, attack, target, hitIndex, hitType);
HOOK(ChangeAttackType, targetSource, 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(OnStatusMove, attackSource, attack, target, hitIndex);
HOOK(OnStatusMove, userSource, attack, target, hitIndex);
}
else{
auto damage = hit.GetDamage();
@@ -142,15 +144,15 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature *targe
target->Damage(damage, DamageSource::AttackDamage);
bool preventSecondary = false;
HOOK(PreventSecondaryEffects, targetSources, attack, target, hitIndex, preventSecondary);
HOOK(PreventSecondaryEffects, targetSource, attack, target, hitIndex, preventSecondary);
if (!preventSecondary){
HOOK(OnSecondaryEffect, attackSource, attack, target, hitIndex);
HOOK(OnSecondaryEffect, userSource, attack, target, hitIndex);
}
}
}
}
if (!user->IsFainted()){
HOOK(OnAfterHits, userSources, attack, target);
HOOK(OnAfterHits, userSource, attack, target);
}
}