Update to latest Arbutils, include stacktrace.
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:
@@ -122,24 +122,24 @@ void TurnHandler::ExecuteAttackChoice(const ArbUt::BorrowedPtr<AttackTurnChoice>
|
||||
}
|
||||
|
||||
void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, const ArbUt::BorrowedPtr<Creature>& target) {
|
||||
auto user = attack->GetUser();
|
||||
AssertNotNull(attack)
|
||||
auto& user = attack->GetUser();
|
||||
AssertNotNull(user)
|
||||
AssertNotNull(target)
|
||||
if (user->GetBattle()->HasEnded())
|
||||
auto& battle = user->GetBattle();
|
||||
AssertNotNull(battle)
|
||||
if (battle->HasEnded())
|
||||
return;
|
||||
|
||||
const auto& targetSource = target;
|
||||
auto userSource = attack;
|
||||
|
||||
bool fail = false;
|
||||
HOOK(FailIncomingAttack, targetSource, attack, target.GetRaw(), &fail);
|
||||
HOOK(FailIncomingAttack, target, attack, target.GetRaw(), &fail);
|
||||
if (fail) {
|
||||
// TODO: Fail handling.
|
||||
return;
|
||||
}
|
||||
|
||||
bool invulnerable = false;
|
||||
HOOK(IsInvulnerable, targetSource, attack, target.GetRaw(), &invulnerable);
|
||||
HOOK(IsInvulnerable, target, attack, target.GetRaw(), &invulnerable);
|
||||
if (invulnerable) {
|
||||
// TODO: We should probably do something when a target is invulnerable.
|
||||
return;
|
||||
@@ -147,18 +147,28 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, const ArbUt::Bo
|
||||
|
||||
auto numberOfHits = attack->GetNumberOfHits();
|
||||
if (numberOfHits == 0) {
|
||||
HOOK(OnAttackMiss, targetSource, attack, target.GetRaw());
|
||||
user->GetBattle()->TriggerEventListener<MissEvent>(user);
|
||||
HOOK(OnAttackMiss, target, attack, target.GetRaw());
|
||||
battle->TriggerEventListener<MissEvent>(user);
|
||||
return;
|
||||
}
|
||||
|
||||
auto attackData = attack->GetAttack()->GetAttack();
|
||||
auto library = user->GetBattle()->GetLibrary();
|
||||
auto& learnedAttack = attack->GetAttack();
|
||||
AssertNotNull(learnedAttack);
|
||||
auto& attackData = learnedAttack->GetAttack();
|
||||
AssertNotNull(attackData);
|
||||
|
||||
auto& library = battle->GetLibrary();
|
||||
AssertNotNull(library)
|
||||
auto& dmgLibrary = library->GetDamageLibrary();
|
||||
auto hitIterator = attack->GetTargetIteratorBegin(target.GetRaw());
|
||||
auto& typeLibrary = library->GetTypeLibrary();
|
||||
auto& miscLibrary = library->GetMiscLibrary();
|
||||
AssertNotNull(dmgLibrary)
|
||||
AssertNotNull(typeLibrary)
|
||||
AssertNotNull(miscLibrary)
|
||||
|
||||
auto hitIterator = attack->GetTargetIteratorBegin(target);
|
||||
for (uint8_t hitIndex = 0; hitIndex < numberOfHits; hitIndex++) {
|
||||
if (user->GetBattle()->HasEnded())
|
||||
if (battle->HasEnded())
|
||||
return;
|
||||
if (user->IsFainted()) {
|
||||
break;
|
||||
@@ -167,28 +177,34 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, const ArbUt::Bo
|
||||
break;
|
||||
}
|
||||
auto& hit = hitIterator[hitIndex];
|
||||
uint8_t hitType = attack->GetAttack()->GetAttack()->GetType();
|
||||
HOOK(ChangeAttackType, targetSource, attack, target.GetRaw(), hitIndex, &hitType);
|
||||
uint8_t hitType = attackData->GetType();
|
||||
HOOK(ChangeAttackType, target, attack, target.GetRaw(), hitIndex, &hitType);
|
||||
hit.SetType(hitType);
|
||||
auto effectiveness = library->GetTypeLibrary()->GetEffectiveness(hitType, target->GetTypes());
|
||||
auto effectiveness = typeLibrary->GetEffectiveness(hitType, target->GetTypes());
|
||||
HOOK(ChangeEffectiveness, attack, attack, target.GetRaw(), hitIndex, &effectiveness)
|
||||
hit.SetEffectiveness(effectiveness);
|
||||
hit.SetCritical(library->GetMiscLibrary()->IsCritical(attack, target.GetRaw(), hitIndex));
|
||||
hit.SetCritical(miscLibrary->IsCritical(attack, target.GetRaw(), hitIndex));
|
||||
hit.SetBasePower(dmgLibrary->GetBasePower(attack, target.GetRaw(), hitIndex, hit));
|
||||
hit.SetDamage(dmgLibrary->GetDamage(attack, target.GetRaw(), hitIndex, hit));
|
||||
|
||||
if (attackData->GetCategory() == Library::AttackCategory::Status) {
|
||||
if (attackData->HasSecondaryEffect()) {
|
||||
auto& effect = attackData->GetSecondaryEffect();
|
||||
bool hasSecondaryEffect;
|
||||
if (effect->GetChance() == -1) {
|
||||
hasSecondaryEffect = true;
|
||||
} else {
|
||||
hasSecondaryEffect =
|
||||
user->GetBattle()->GetRandom()->EffectChance(effect->GetChance(), attack, target.GetRaw());
|
||||
}
|
||||
if (hasSecondaryEffect) {
|
||||
HOOK(OnSecondaryEffect, userSource, attack, target.GetRaw(), hitIndex);
|
||||
try {
|
||||
auto& effect = attackData->GetSecondaryEffect();
|
||||
bool hasSecondaryEffect;
|
||||
if (effect->GetChance() == -1) {
|
||||
hasSecondaryEffect = true;
|
||||
} else {
|
||||
hasSecondaryEffect =
|
||||
battle->GetRandom()->EffectChance(effect->GetChance(), attack, target.GetRaw());
|
||||
}
|
||||
if (hasSecondaryEffect) {
|
||||
HOOK(OnSecondaryEffect, user, attack, target.GetRaw(), hitIndex);
|
||||
}
|
||||
} catch (const CreatureException& e) {
|
||||
throw e;
|
||||
} catch (const std::exception& e) {
|
||||
THROW_CREATURE("Exception during status attack effect handling: " << e.what() << ".");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -202,18 +218,26 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, const ArbUt::Bo
|
||||
|
||||
if (attackData->HasSecondaryEffect() && !user->IsFainted()) {
|
||||
bool preventSecondary = false;
|
||||
HOOK(PreventSecondaryEffects, targetSource, attack, target.GetRaw(), hitIndex, &preventSecondary);
|
||||
HOOK(PreventSecondaryEffects, target, attack, target.GetRaw(), hitIndex, &preventSecondary);
|
||||
if (!preventSecondary) {
|
||||
auto& effect = attackData->GetSecondaryEffect();
|
||||
bool hasSecondaryEffect;
|
||||
if (effect->GetChance() == -1) {
|
||||
hasSecondaryEffect = true;
|
||||
} else {
|
||||
hasSecondaryEffect = user->GetBattle()->GetRandom()->EffectChance(effect->GetChance(),
|
||||
attack, target.GetRaw());
|
||||
}
|
||||
if (hasSecondaryEffect) {
|
||||
HOOK(OnSecondaryEffect, userSource, attack, target.GetRaw(), hitIndex);
|
||||
try {
|
||||
auto& effect = attackData->GetSecondaryEffect();
|
||||
bool hasSecondaryEffect;
|
||||
if (effect->GetChance() == -1) {
|
||||
hasSecondaryEffect = true;
|
||||
} else {
|
||||
auto random = battle->GetRandom();
|
||||
AssertNotNull(random);
|
||||
hasSecondaryEffect = random->EffectChance(effect->GetChance(), attack, target.GetRaw());
|
||||
}
|
||||
if (hasSecondaryEffect) {
|
||||
HOOK(OnSecondaryEffect, user, attack, target.GetRaw(), hitIndex);
|
||||
}
|
||||
} catch (const CreatureException& e) {
|
||||
throw e;
|
||||
} catch (const std::exception& e) {
|
||||
THROW_CREATURE("Exception during offensive attack secondary effect handling: " << e.what()
|
||||
<< ".");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -222,7 +246,7 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, const ArbUt::Bo
|
||||
}
|
||||
|
||||
if (!user->IsFainted()) {
|
||||
HOOK(OnAfterHits, userSource, attack, target.GetRaw());
|
||||
HOOK(OnAfterHits, user, attack, target.GetRaw());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user