Implements most of the Damage Modifier calculation.
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Deukhoofd 2020-06-05 13:49:12 +02:00
parent ce54861966
commit 12066e1dfe
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
6 changed files with 57 additions and 0 deletions

View File

@ -1,5 +1,8 @@
#include "DamageLibrary.hpp" #include "DamageLibrary.hpp"
#include <CreatureLib/Battling/Models/Battle.hpp>
#include "../PkmnScriptHook.hpp"
#include "../Pokemon/Pokemon.hpp" #include "../Pokemon/Pokemon.hpp"
using HitData = const CreatureLib::Battling::ExecutingAttack::HitData; using HitData = const CreatureLib::Battling::ExecutingAttack::HitData;
uint32_t PkmnLib::Battling::DamageLibrary::GetDamage(CreatureLib::Battling::ExecutingAttack* attack, uint32_t PkmnLib::Battling::DamageLibrary::GetDamage(CreatureLib::Battling::ExecutingAttack* attack,
@ -63,6 +66,21 @@ float PkmnLib::Battling::DamageLibrary::GetDamageModifier(CreatureLib::Battling:
CreatureLib::Battling::Creature* target, uint8_t hitIndex, CreatureLib::Battling::Creature* target, uint8_t hitIndex,
const HitData& hitData) const { const HitData& hitData) const {
float mod = 1; float mod = 1;
if (attack->GetTargetCount() > 1)
mod *= 0.75;
if (hitData.IsCritical()) {
float critModifier = 1.5;
PKMN_HOOK(OverrideCriticalModifier, attack, attack, target, hitIndex, &critModifier);
mod *= critModifier;
}
float randPercentage = 85 + attack->GetUser()->GetBattle()->GetRandom()->Get(0, 16);
mod *= randPercentage / 100.0;
if (attack->GetUser()->HasType(hitData.GetType())) {
float stabModifier = 1.5;
PKMN_HOOK(OverrideSTABModifier, attack, attack, target, hitIndex, &stabModifier);
mod *= stabModifier;
}
mod *= hitData.GetEffectiveness(); mod *= hitData.GetEffectiveness();
// HOOK: Modify damage modifier. // HOOK: Modify damage modifier.
return mod; return mod;

View File

@ -7,6 +7,12 @@ namespace PkmnLib::Battling {
public: public:
virtual void ModifyCriticalStage(CreatureLib::Battling::ExecutingAttack* attack, virtual void ModifyCriticalStage(CreatureLib::Battling::ExecutingAttack* attack,
CreatureLib::Battling::Creature* target, uint8_t hit, uint8_t* critStage){}; CreatureLib::Battling::Creature* target, uint8_t hit, uint8_t* critStage){};
virtual void OverrideCriticalModifier(CreatureLib::Battling::ExecutingAttack* attack,
CreatureLib::Battling::Creature* target, uint8_t hit,
float* critModifier){};
virtual void OverrideSTABModifier(CreatureLib::Battling::ExecutingAttack* attack,
CreatureLib::Battling::Creature* target, uint8_t hit, float* stabModifier){};
virtual void ModifyExperienceGain(CreatureLib::Battling::Creature* faintedMon, virtual void ModifyExperienceGain(CreatureLib::Battling::Creature* faintedMon,
CreatureLib::Battling::Creature* winningMon, uint32_t* experienceGain){}; CreatureLib::Battling::Creature* winningMon, uint32_t* experienceGain){};
virtual void DoesShareExperience(CreatureLib::Battling::Creature* faintedMon, virtual void DoesShareExperience(CreatureLib::Battling::Creature* faintedMon,

View File

@ -273,3 +273,23 @@ void AngelScriptScript::DoesShareExperience(CreatureLib::Battling::Creature* fai
ctx->SetArgAddress(2, shareExperience); ctx->SetArgAddress(2, shareExperience);
}) })
} }
void AngelScriptScript::OverrideCriticalModifier(CreatureLib::Battling::ExecutingAttack* attack,
CreatureLib::Battling::Creature* target, uint8_t hit,
float* critModifier) {
CALL_HOOK(OverrideCriticalModifier, {
ctx->SetArgObject(0, (void*)attack);
ctx->SetArgObject(1, (void*)target);
ctx->SetArgByte(2, hit);
ctx->SetArgAddress(3, critModifier);
})
}
void AngelScriptScript::OverrideSTABModifier(CreatureLib::Battling::ExecutingAttack* attack,
CreatureLib::Battling::Creature* target, uint8_t hit,
float* stabModifier) {
CALL_HOOK(OverrideSTABModifier, {
ctx->SetArgObject(0, (void*)attack);
ctx->SetArgObject(1, (void*)target);
ctx->SetArgByte(2, hit);
ctx->SetArgAddress(3, stabModifier);
})
}

View File

@ -107,6 +107,10 @@ public:
void ModifyCriticalStage(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target, void ModifyCriticalStage(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
uint8_t hit, uint8_t* critStage) override; uint8_t hit, uint8_t* critStage) override;
void OverrideCriticalModifier(CreatureLib::Battling::ExecutingAttack* attack,
CreatureLib::Battling::Creature* target, uint8_t hit, float* critModifier) override;
void OverrideSTABModifier(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
uint8_t hit, float* stabModifier) override;
void ModifyExperienceGain(CreatureLib::Battling::Creature* faintedMon, CreatureLib::Battling::Creature* winningMon, void ModifyExperienceGain(CreatureLib::Battling::Creature* faintedMon, CreatureLib::Battling::Creature* winningMon,
uint32_t* experienceGain) override; uint32_t* experienceGain) override;

View File

@ -130,6 +130,12 @@ public:
SCRIPT_HOOK_FUNCTION( SCRIPT_HOOK_FUNCTION(
ModifyCriticalStage, ModifyCriticalStage,
"void ModifyCriticalStage(ExecutingMove@ attack, Pokemon@ target, uint8 hit, uint8& critStage)"); "void ModifyCriticalStage(ExecutingMove@ attack, Pokemon@ target, uint8 hit, uint8& critStage)");
SCRIPT_HOOK_FUNCTION(
OverrideCriticalModifier,
"void OverrideCriticalModifier(ExecutingMove@ attack, Pokemon@ target, uint8 hit, float& critModifier)");
SCRIPT_HOOK_FUNCTION(
OverrideSTABModifier,
"void OverrideSTABModifier(ExecutingMove@ attack, Pokemon@ target, uint8 hit, float& stabModifier)");
SCRIPT_HOOK_FUNCTION(ModifyExperienceGain, SCRIPT_HOOK_FUNCTION(ModifyExperienceGain,
"void ModifyExperienceGain(Pokemon@ faintedMon, Pokemon@ winningMon, uint32& critStage)"); "void ModifyExperienceGain(Pokemon@ faintedMon, Pokemon@ winningMon, uint32& critStage)");
SCRIPT_HOOK_FUNCTION(DoesShareExperience, SCRIPT_HOOK_FUNCTION(DoesShareExperience,

View File

@ -39,6 +39,9 @@ shared abstract class PkmnScript {
// PkmnLib methods // PkmnLib methods
void ModifyCriticalStage(ExecutingMove@ attack, Pokemon@ target, uint8 hit, uint8& critStage){}; void ModifyCriticalStage(ExecutingMove@ attack, Pokemon@ target, uint8 hit, uint8& critStage){};
void OverrideCriticalModifier(ExecutingMove@ attack, Pokemon@ target, uint8 hit, float& critModifier){};
void OverrideSTABModifier(ExecutingMove@ attack, Pokemon@ target, uint8 hit, float& stabModifier){};
void ModifyExperienceGain(Pokemon@ faintedMon, Pokemon@ winningMon, uint32& critStage){}; void ModifyExperienceGain(Pokemon@ faintedMon, Pokemon@ winningMon, uint32& critStage){};
void DoesShareExperience(Pokemon@ faintedMon, Pokemon@ winningMon, bool& shareExperience){}; void DoesShareExperience(Pokemon@ faintedMon, Pokemon@ winningMon, bool& shareExperience){};
} }