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);
|
||||
|
||||
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.
|
||||
|
@ -93,7 +93,7 @@ void TurnHandler::ExecuteAttackChoice(AttackTurnChoice* choice) {
|
|||
}
|
||||
|
||||
void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* target,
|
||||
const ExecutingAttack::TargetData& targetData) {
|
||||
ExecutingAttack::TargetData* targetData) {
|
||||
auto user = attack->GetUser();
|
||||
|
||||
ScriptSource* targetSource = target;
|
||||
|
@ -113,12 +113,12 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* targe
|
|||
return;
|
||||
}
|
||||
|
||||
if (!targetData.IsHit()) {
|
||||
if (!targetData->IsHit()) {
|
||||
HOOK(OnAttackMiss, targetSource, attack, target);
|
||||
return;
|
||||
}
|
||||
|
||||
auto numHits = targetData.GetNumberOfHits();
|
||||
auto numHits = targetData->GetNumberOfHits();
|
||||
if (numHits == 0)
|
||||
return;
|
||||
auto attackData = attack->GetAttack()->GetAttack();
|
||||
|
@ -132,22 +132,22 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* targe
|
|||
// STOP, STOP! HE'S ALREADY DEAD ;_;
|
||||
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);
|
||||
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));
|
||||
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));
|
||||
|
||||
if (attackData->GetCategory() == Library::AttackCategory::Status) {
|
||||
HOOK(OnStatusMove, userSource, attack, target, hitIndex);
|
||||
} else {
|
||||
auto damage = hit.GetDamage();
|
||||
auto damage = hit->GetDamage();
|
||||
if (damage > target->GetCurrentHealth()) {
|
||||
damage = target->GetCurrentHealth();
|
||||
hit.SetDamage(damage);
|
||||
hit->SetDamage(damage);
|
||||
}
|
||||
if (damage > 0) {
|
||||
target->Damage(damage, DamageSource::AttackDamage);
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace CreatureLib::Battling {
|
|||
|
||||
static void ExecuteAttackChoice(AttackTurnChoice* choice);
|
||||
static void HandleAttackForTarget(ExecutingAttack* attack, Creature* target,
|
||||
const ExecutingAttack::TargetData& targetData);
|
||||
ExecutingAttack::TargetData* targetData);
|
||||
|
||||
public:
|
||||
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 {
|
||||
auto levelMod = static_cast<float>(2 * attack->GetUser()->GetLevel());
|
||||
auto hit = attack->GetAttackDataForTarget(target).GetHit(hitIndex);
|
||||
auto bp = hit.GetBasePower();
|
||||
auto bp = hit->GetBasePower();
|
||||
auto statMod = GetStatModifier(attack, target, hitIndex);
|
||||
// HOOK: Modify stat modifier
|
||||
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;
|
||||
}
|
||||
|
||||
auto bypassDefensive = hit.IsCritical() && target->GetStatBoost(defensiveStat) > 0;
|
||||
auto bypassDefensive = hit->IsCritical() && target->GetStatBoost(defensiveStat) > 0;
|
||||
// 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.
|
||||
|
||||
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 mod = 1;
|
||||
auto hit = attack->GetAttackDataForTarget(target).GetHit(hitIndex);
|
||||
mod *= hit.GetEffectiveness();
|
||||
mod *= hit->GetEffectiveness();
|
||||
// HOOK: Modify damage modifier.
|
||||
return mod;
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ namespace CreatureLib::Battling {
|
|||
}
|
||||
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]; }
|
||||
|
||||
|
@ -75,7 +75,7 @@ namespace CreatureLib::Battling {
|
|||
|
||||
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; }
|
||||
|
||||
|
|
|
@ -31,13 +31,13 @@ SpeciesLibrary *TestLibrary::BuildSpeciesLibrary() {
|
|||
|
||||
AttackLibrary *TestLibrary::BuildAttackLibrary() {
|
||||
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, {}));
|
||||
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, {}));
|
||||
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, {}));
|
||||
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, {}));
|
||||
return l;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue