Fixes for damage calculations always using a base power of 0.
This commit is contained in:
parent
262279bd2c
commit
7c642f7df5
|
@ -85,7 +85,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.
|
||||||
|
@ -93,7 +93,7 @@ void TurnHandler::ExecuteAttackChoice(AttackTurnChoice* choice) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* target,
|
void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* target,
|
||||||
const ExecutingAttack::TargetData& targetData) {
|
ExecutingAttack::TargetData* targetData) {
|
||||||
auto user = attack->GetUser();
|
auto user = attack->GetUser();
|
||||||
|
|
||||||
ScriptSource* targetSource = target;
|
ScriptSource* targetSource = target;
|
||||||
|
@ -113,12 +113,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();
|
||||||
|
@ -132,22 +132,22 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* targe
|
||||||
// STOP, STOP! HE'S ALREADY DEAD ;_;
|
// STOP, STOP! HE'S ALREADY DEAD ;_;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
auto hit = targetData.GetHit(hitIndex);
|
auto hit = targetData->GetHit(hitIndex);
|
||||||
|
|
||||||
auto hitType = hit.GetType();
|
auto hitType = hit->GetType();
|
||||||
HOOK(ChangeAttackType, targetSource, attack, target, hitIndex, hitType);
|
HOOK(ChangeAttackType, targetSource, attack, target, hitIndex, hitType);
|
||||||
hit.SetEffectiveness(library->GetTypeLibrary()->GetEffectiveness(hitType, target->GetTypes()));
|
hit->SetEffectiveness(library->GetTypeLibrary()->GetEffectiveness(hitType, target->GetTypes()));
|
||||||
hit.SetCritical(library->GetCriticalLibrary()->IsCritical(attack, target, hitIndex));
|
hit->SetCritical(library->GetCriticalLibrary()->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) {
|
||||||
HOOK(OnStatusMove, userSource, attack, target, hitIndex);
|
HOOK(OnStatusMove, userSource, attack, target, hitIndex);
|
||||||
} 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);
|
||||||
|
|
|
@ -13,7 +13,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,
|
||||||
const ExecutingAttack::TargetData& targetData);
|
ExecutingAttack::TargetData* targetData);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void RunTurn(Battle* battle, ChoiceQueue* queue);
|
static void RunTurn(Battle* battle, ChoiceQueue* queue);
|
||||||
|
|
|
@ -4,7 +4,7 @@ using namespace CreatureLib::Battling;
|
||||||
int DamageLibrary::GetDamage(ExecutingAttack* attack, Creature* target, uint8_t hitIndex) const {
|
int DamageLibrary::GetDamage(ExecutingAttack* attack, Creature* target, uint8_t hitIndex) const {
|
||||||
auto levelMod = static_cast<float>(2 * attack->GetUser()->GetLevel());
|
auto levelMod = static_cast<float>(2 * attack->GetUser()->GetLevel());
|
||||||
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: Modify stat modifier
|
// HOOK: Modify stat modifier
|
||||||
int damage = static_cast<int>((((levelMod * static_cast<float>(bp) * statMod) / 50) + 2) *
|
int damage = static_cast<int>((((levelMod * static_cast<float>(bp) * statMod) / 50) + 2) *
|
||||||
|
@ -33,9 +33,9 @@ float DamageLibrary::GetStatModifier(ExecutingAttack* attack, Creature* target,
|
||||||
defensiveStat = Core::Statistic::MagicalDefense;
|
defensiveStat = Core::Statistic::MagicalDefense;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto bypassDefensive = hit.IsCritical() && target->GetStatBoost(defensiveStat) > 0;
|
auto bypassDefensive = hit->IsCritical() && target->GetStatBoost(defensiveStat) > 0;
|
||||||
// HOOK: allow bypassing defensive stat modifiers.
|
// HOOK: allow bypassing defensive stat modifiers.
|
||||||
auto bypassOffensive = hit.IsCritical() && user->GetStatBoost(offensiveStat) < 0;
|
auto bypassOffensive = hit->IsCritical() && user->GetStatBoost(offensiveStat) < 0;
|
||||||
// HOOK: Allow bypassing offensive stat modifiers.
|
// HOOK: Allow bypassing offensive stat modifiers.
|
||||||
|
|
||||||
float offensiveValue;
|
float offensiveValue;
|
||||||
|
@ -58,7 +58,7 @@ float DamageLibrary::GetStatModifier(ExecutingAttack* attack, Creature* target,
|
||||||
float DamageLibrary::GetDamageModifier(ExecutingAttack* attack, Creature* target, uint8_t hitIndex) const {
|
float DamageLibrary::GetDamageModifier(ExecutingAttack* attack, Creature* target, uint8_t hitIndex) const {
|
||||||
float mod = 1;
|
float mod = 1;
|
||||||
auto hit = attack->GetAttackDataForTarget(target).GetHit(hitIndex);
|
auto hit = attack->GetAttackDataForTarget(target).GetHit(hitIndex);
|
||||||
mod *= hit.GetEffectiveness();
|
mod *= hit->GetEffectiveness();
|
||||||
// HOOK: Modify damage modifier.
|
// HOOK: Modify damage modifier.
|
||||||
return mod;
|
return mod;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ namespace CreatureLib::Battling {
|
||||||
}
|
}
|
||||||
TargetData() = default;
|
TargetData() = default;
|
||||||
|
|
||||||
const HitData& GetHit(uint8_t index) const { return _hits[index]; }
|
HitData* GetHit(uint8_t index) { return &_hits[index]; }
|
||||||
|
|
||||||
HitData* GetHitPtr(uint8_t index) { return &_hits[index]; }
|
HitData* GetHitPtr(uint8_t index) { return &_hits[index]; }
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ namespace CreatureLib::Battling {
|
||||||
|
|
||||||
bool IsCreatureTarget(Creature* creature) { return _targets.find(creature) != _targets.end(); }
|
bool IsCreatureTarget(Creature* creature) { return _targets.find(creature) != _targets.end(); }
|
||||||
|
|
||||||
const std::unordered_map<Creature*, TargetData>& GetTargets() { return _targets; }
|
std::unordered_map<Creature*, TargetData>& GetTargets() { return _targets; }
|
||||||
|
|
||||||
Creature* GetUser() { return _user; }
|
Creature* GetUser() { return _user; }
|
||||||
|
|
||||||
|
|
|
@ -31,13 +31,13 @@ SpeciesLibrary *TestLibrary::BuildSpeciesLibrary() {
|
||||||
|
|
||||||
AttackLibrary *TestLibrary::BuildAttackLibrary() {
|
AttackLibrary *TestLibrary::BuildAttackLibrary() {
|
||||||
auto l = new AttackLibrary();
|
auto l = new AttackLibrary();
|
||||||
l->LoadAttack("standard", new AttackData("standard", "normal", AttackCategory::Physical, 50, 100, 30,
|
l->LoadAttack("standard", new AttackData("standard", "normal", AttackCategory::Physical, 20, 100, 30,
|
||||||
AttackTarget::AdjacentOpponent, 0, {}));
|
AttackTarget::AdjacentOpponent, 0, {}));
|
||||||
l->LoadAttack("highPriority", new AttackData("highPriority", "normal", AttackCategory::Physical, 50, 100, 30,
|
l->LoadAttack("highPriority", new AttackData("highPriority", "normal", AttackCategory::Physical, 20, 100, 30,
|
||||||
AttackTarget::AdjacentOpponent, 1, {}));
|
AttackTarget::AdjacentOpponent, 1, {}));
|
||||||
l->LoadAttack("higherPriority", new AttackData("higherPriority", "normal", AttackCategory::Physical, 50, 100, 30,
|
l->LoadAttack("higherPriority", new AttackData("higherPriority", "normal", AttackCategory::Physical, 20, 100, 30,
|
||||||
AttackTarget::AdjacentOpponent, 2, {}));
|
AttackTarget::AdjacentOpponent, 2, {}));
|
||||||
l->LoadAttack("lowPriority", new AttackData("lowPriority", "normal", AttackCategory::Physical, 50, 100, 30,
|
l->LoadAttack("lowPriority", new AttackData("lowPriority", "normal", AttackCategory::Physical, 20, 100, 30,
|
||||||
AttackTarget::AdjacentOpponent, -1, {}));
|
AttackTarget::AdjacentOpponent, -1, {}));
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue