Pass ExecutingAttack values by reference instead of pointer.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
734d056449
commit
0e874346bb
|
@ -13,7 +13,7 @@ export void CreatureLib_ExecutingAttack_Destruct(ExecutingAttack* p) { delete p;
|
||||||
|
|
||||||
export uint8_t CreatureLib_ExecutingAttack_GetAttackDataForTarget(ExecutingAttack::TargetData*& out, ExecutingAttack* p,
|
export uint8_t CreatureLib_ExecutingAttack_GetAttackDataForTarget(ExecutingAttack::TargetData*& out, ExecutingAttack* p,
|
||||||
Creature* target) {
|
Creature* target) {
|
||||||
Try(out = p->GetAttackDataForTarget(target);)
|
Try(out = &p->GetAttackDataForTarget(target);)
|
||||||
}
|
}
|
||||||
|
|
||||||
export bool CreatureLib_ExecutingAttack_IsCreatureTarget(ExecutingAttack* p, Creature* target) {
|
export bool CreatureLib_ExecutingAttack_IsCreatureTarget(ExecutingAttack* p, Creature* target) {
|
||||||
|
@ -25,7 +25,7 @@ export LearnedAttack* CreatureLib_ExecutingAttack_GetAttack(ExecutingAttack* p)
|
||||||
|
|
||||||
export uint8_t CreatureLib_TargetData_GetHit(ExecutingAttack::HitData*& out, ExecutingAttack::TargetData* p,
|
export uint8_t CreatureLib_TargetData_GetHit(ExecutingAttack::HitData*& out, ExecutingAttack::TargetData* p,
|
||||||
uint8_t hit) {
|
uint8_t hit) {
|
||||||
Try(out = p->GetHit(hit);)
|
Try(out = &p->GetHit(hit);)
|
||||||
}
|
}
|
||||||
export uint8_t CreatureLib_TargetData_GetNumberOfHits(ExecutingAttack::TargetData* p) { return p->GetNumberOfHits(); }
|
export uint8_t CreatureLib_TargetData_GetNumberOfHits(ExecutingAttack::TargetData* p) { return p->GetNumberOfHits(); }
|
||||||
export bool CreatureLib_TargetData_IsHit(ExecutingAttack::TargetData* p) { return p->IsHit(); }
|
export bool CreatureLib_TargetData_IsHit(ExecutingAttack::TargetData* p) { return p->IsHit(); }
|
||||||
|
|
|
@ -91,7 +91,7 @@ void TurnHandler::ExecuteAttackChoice(AttackTurnChoice* choice) {
|
||||||
HOOK(OnBeforeAttack, attack, attack);
|
HOOK(OnBeforeAttack, attack, attack);
|
||||||
|
|
||||||
for (auto& kv : attack->GetTargets()) {
|
for (auto& kv : attack->GetTargets()) {
|
||||||
HandleAttackForTarget(attack, kv.first, &kv.second);
|
HandleAttackForTarget(attack, kv.first, kv.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: We currently delete this, but we probably want to store this in a log, so scripts can look it up.
|
// TODO: We currently delete this, but we probably want to store this in a log, so scripts can look it up.
|
||||||
|
@ -99,7 +99,7 @@ void TurnHandler::ExecuteAttackChoice(AttackTurnChoice* choice) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* target,
|
void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* target,
|
||||||
ExecutingAttack::TargetData* targetData) {
|
ExecutingAttack::TargetData& targetData) {
|
||||||
auto user = attack->GetUser();
|
auto user = attack->GetUser();
|
||||||
AssertNotNull(user)
|
AssertNotNull(user)
|
||||||
AssertNotNull(target)
|
AssertNotNull(target)
|
||||||
|
@ -121,12 +121,12 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* targe
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!targetData->IsHit()) {
|
if (!targetData.IsHit()) {
|
||||||
HOOK(OnAttackMiss, targetSource, attack, target);
|
HOOK(OnAttackMiss, targetSource, attack, target);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto numHits = targetData->GetNumberOfHits();
|
auto numHits = targetData.GetNumberOfHits();
|
||||||
if (numHits == 0)
|
if (numHits == 0)
|
||||||
return;
|
return;
|
||||||
auto attackData = attack->GetAttack()->GetAttack();
|
auto attackData = attack->GetAttack()->GetAttack();
|
||||||
|
@ -140,17 +140,15 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* targe
|
||||||
if (target->IsFainted()) {
|
if (target->IsFainted()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
auto hit = targetData->GetHit(hitIndex);
|
auto& hit = targetData.GetHit(hitIndex);
|
||||||
AssertNotNull(hit)
|
auto hitType = hit.GetType();
|
||||||
|
|
||||||
auto hitType = hit->GetType();
|
|
||||||
HOOK(ChangeAttackType, targetSource, attack, target, hitIndex, &hitType);
|
HOOK(ChangeAttackType, targetSource, attack, target, hitIndex, &hitType);
|
||||||
auto effectiveness = library->GetTypeLibrary()->GetEffectiveness(hitType, target->GetTypes());
|
auto effectiveness = library->GetTypeLibrary()->GetEffectiveness(hitType, target->GetTypes());
|
||||||
HOOK(ChangeEffectiveness, attack, attack, target, hitIndex, &effectiveness)
|
HOOK(ChangeEffectiveness, attack, attack, target, hitIndex, &effectiveness)
|
||||||
hit->SetEffectiveness(effectiveness);
|
hit.SetEffectiveness(effectiveness);
|
||||||
hit->SetCritical(library->GetMiscLibrary()->IsCritical(attack, target, hitIndex));
|
hit.SetCritical(library->GetMiscLibrary()->IsCritical(attack, target, hitIndex));
|
||||||
hit->SetBasePower(dmgLibrary->GetBasePower(attack, target, hitIndex));
|
hit.SetBasePower(dmgLibrary->GetBasePower(attack, target, hitIndex));
|
||||||
hit->SetDamage(dmgLibrary->GetDamage(attack, target, hitIndex));
|
hit.SetDamage(dmgLibrary->GetDamage(attack, target, hitIndex));
|
||||||
|
|
||||||
if (attackData->GetCategory() == Library::AttackCategory::Status) {
|
if (attackData->GetCategory() == Library::AttackCategory::Status) {
|
||||||
if (attackData->HasSecondaryEffect()) {
|
if (attackData->HasSecondaryEffect()) {
|
||||||
|
@ -167,10 +165,10 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* targe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
auto damage = hit->GetDamage();
|
auto damage = hit.GetDamage();
|
||||||
if (damage > target->GetCurrentHealth()) {
|
if (damage > target->GetCurrentHealth()) {
|
||||||
damage = target->GetCurrentHealth();
|
damage = target->GetCurrentHealth();
|
||||||
hit->SetDamage(damage);
|
hit.SetDamage(damage);
|
||||||
}
|
}
|
||||||
if (damage > 0) {
|
if (damage > 0) {
|
||||||
target->Damage(damage, DamageSource::AttackDamage);
|
target->Damage(damage, DamageSource::AttackDamage);
|
||||||
|
|
|
@ -15,7 +15,7 @@ namespace CreatureLib::Battling {
|
||||||
|
|
||||||
static void ExecuteAttackChoice(AttackTurnChoice* choice);
|
static void ExecuteAttackChoice(AttackTurnChoice* choice);
|
||||||
static void HandleAttackForTarget(ExecutingAttack* attack, Creature* target,
|
static void HandleAttackForTarget(ExecutingAttack* attack, Creature* target,
|
||||||
ExecutingAttack::TargetData* targetData);
|
ExecutingAttack::TargetData& targetData);
|
||||||
|
|
||||||
static void ExecuteSwitchChoice(SwitchTurnChoice* choice);
|
static void ExecuteSwitchChoice(SwitchTurnChoice* choice);
|
||||||
static void ExecuteFleeChoice(FleeTurnChoice* choice);
|
static void ExecuteFleeChoice(FleeTurnChoice* choice);
|
||||||
|
|
|
@ -7,8 +7,8 @@ uint32_t DamageLibrary::GetDamage(ExecutingAttack* attack, Creature* target, uin
|
||||||
AssertNotNull(attack)
|
AssertNotNull(attack)
|
||||||
AssertNotNull(target)
|
AssertNotNull(target)
|
||||||
auto levelMod = static_cast<float>(2 * attack->GetUser()->GetLevel()) / 5 + 2;
|
auto levelMod = static_cast<float>(2 * attack->GetUser()->GetLevel()) / 5 + 2;
|
||||||
auto hit = attack->GetAttackDataForTarget(target)->GetHit(hitIndex);
|
auto hit = attack->GetAttackDataForTarget(target).GetHit(hitIndex);
|
||||||
auto bp = hit->GetBasePower();
|
auto bp = hit.GetBasePower();
|
||||||
auto statMod = GetStatModifier(attack, target, hitIndex);
|
auto statMod = GetStatModifier(attack, target, hitIndex);
|
||||||
HOOK(ModifyStatModifier, attack, attack, target, hitIndex, &statMod);
|
HOOK(ModifyStatModifier, attack, attack, target, hitIndex, &statMod);
|
||||||
uint32_t damage = static_cast<uint32_t>((((levelMod * static_cast<float>(bp) * statMod) / 50) + 2) *
|
uint32_t damage = static_cast<uint32_t>((((levelMod * static_cast<float>(bp) * statMod) / 50) + 2) *
|
||||||
|
@ -31,7 +31,7 @@ float DamageLibrary::GetStatModifier(ExecutingAttack* attack, Creature* target,
|
||||||
auto user = attack->GetUser();
|
auto user = attack->GetUser();
|
||||||
AssertNotNull(user)
|
AssertNotNull(user)
|
||||||
HOOK(ChangeDamageStatsUser, attack, attack, target, hitIndex, &user);
|
HOOK(ChangeDamageStatsUser, attack, attack, target, hitIndex, &user);
|
||||||
auto hit = attack->GetAttackDataForTarget(target)->GetHit(hitIndex);
|
auto hit = attack->GetAttackDataForTarget(target).GetHit(hitIndex);
|
||||||
Library::Statistic offensiveStat;
|
Library::Statistic offensiveStat;
|
||||||
Library::Statistic defensiveStat;
|
Library::Statistic defensiveStat;
|
||||||
if (attack->GetAttack()->GetAttack()->GetCategory() == Library::AttackCategory::Physical) {
|
if (attack->GetAttack()->GetAttack()->GetCategory() == Library::AttackCategory::Physical) {
|
||||||
|
@ -42,9 +42,9 @@ float DamageLibrary::GetStatModifier(ExecutingAttack* attack, Creature* target,
|
||||||
defensiveStat = Library::Statistic::MagicalDefense;
|
defensiveStat = Library::Statistic::MagicalDefense;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto bypassDefensive = hit->IsCritical() && target->GetStatBoost(defensiveStat) > 0;
|
auto bypassDefensive = hit.IsCritical() && target->GetStatBoost(defensiveStat) > 0;
|
||||||
HOOK(BypassDefensiveStat, attack, attack, target, hitIndex, &bypassDefensive);
|
HOOK(BypassDefensiveStat, attack, attack, target, hitIndex, &bypassDefensive);
|
||||||
auto bypassOffensive = hit->IsCritical() && user->GetStatBoost(offensiveStat) < 0;
|
auto bypassOffensive = hit.IsCritical() && user->GetStatBoost(offensiveStat) < 0;
|
||||||
HOOK(BypassOffensiveStat, attack, attack, target, hitIndex, &bypassOffensive);
|
HOOK(BypassOffensiveStat, attack, attack, target, hitIndex, &bypassOffensive);
|
||||||
|
|
||||||
float offensiveValue;
|
float offensiveValue;
|
||||||
|
@ -68,9 +68,8 @@ float DamageLibrary::GetDamageModifier(ExecutingAttack* attack, Creature* target
|
||||||
AssertNotNull(attack)
|
AssertNotNull(attack)
|
||||||
AssertNotNull(target)
|
AssertNotNull(target)
|
||||||
float mod = 1;
|
float mod = 1;
|
||||||
auto hit = attack->GetAttackDataForTarget(target)->GetHit(hitIndex);
|
auto hit = attack->GetAttackDataForTarget(target).GetHit(hitIndex);
|
||||||
AssertNotNull(hit)
|
mod *= hit.GetEffectiveness();
|
||||||
mod *= hit->GetEffectiveness();
|
|
||||||
HOOK(ModifyDamageModifier, attack, attack, target, hitIndex, &mod);
|
HOOK(ModifyDamageModifier, attack, attack, target, hitIndex, &mod);
|
||||||
return mod;
|
return mod;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,8 +44,9 @@ namespace CreatureLib::Battling {
|
||||||
public:
|
public:
|
||||||
explicit TargetData(uint8_t numberOfHits) : _hits(numberOfHits) { _hits.Resize(numberOfHits, HitData()); }
|
explicit TargetData(uint8_t numberOfHits) : _hits(numberOfHits) { _hits.Resize(numberOfHits, HitData()); }
|
||||||
TargetData() = default;
|
TargetData() = default;
|
||||||
|
TargetData& operator=(const TargetData&) = delete;
|
||||||
|
|
||||||
HitData* GetHit(uint8_t index) { return &_hits[index]; }
|
HitData& GetHit(uint8_t index) { return _hits[index]; }
|
||||||
|
|
||||||
uint8_t GetNumberOfHits() const noexcept { return _hits.Count(); }
|
uint8_t GetNumberOfHits() const noexcept { return _hits.Count(); }
|
||||||
|
|
||||||
|
@ -71,7 +72,7 @@ namespace CreatureLib::Battling {
|
||||||
|
|
||||||
virtual ~ExecutingAttack() noexcept { delete _script; };
|
virtual ~ExecutingAttack() noexcept { delete _script; };
|
||||||
|
|
||||||
TargetData* GetAttackDataForTarget(Creature* creature) { return &_targets[creature]; }
|
TargetData& GetAttackDataForTarget(Creature* creature) { return _targets[creature]; }
|
||||||
|
|
||||||
bool IsCreatureTarget(Creature* creature) noexcept { return _targets.Has(creature); }
|
bool IsCreatureTarget(Creature* creature) noexcept { return _targets.Has(creature); }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue