From 12066e1dfede164f5598fff57dba2a63d35df2f9 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Fri, 5 Jun 2020 13:49:12 +0200 Subject: [PATCH] Implements most of the Damage Modifier calculation. --- src/Battling/Library/DamageLibrary.cpp | 18 +++++++++++++++++ src/Battling/PkmnScript.hpp | 6 ++++++ .../AngelScript/AngelScriptScript.cpp | 20 +++++++++++++++++++ .../AngelScript/AngelScriptScript.hpp | 4 ++++ .../AngelScript/AngelScriptTypeInfo.hpp | 6 ++++++ .../TypeRegistry/BasicScriptClass.cpp | 3 +++ 6 files changed, 57 insertions(+) diff --git a/src/Battling/Library/DamageLibrary.cpp b/src/Battling/Library/DamageLibrary.cpp index e202fa2..fb14503 100644 --- a/src/Battling/Library/DamageLibrary.cpp +++ b/src/Battling/Library/DamageLibrary.cpp @@ -1,5 +1,8 @@ #include "DamageLibrary.hpp" +#include +#include "../PkmnScriptHook.hpp" #include "../Pokemon/Pokemon.hpp" + using HitData = const CreatureLib::Battling::ExecutingAttack::HitData; 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, const HitData& hitData) const { 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(); // HOOK: Modify damage modifier. return mod; diff --git a/src/Battling/PkmnScript.hpp b/src/Battling/PkmnScript.hpp index 1de4c68..b81ae94 100644 --- a/src/Battling/PkmnScript.hpp +++ b/src/Battling/PkmnScript.hpp @@ -7,6 +7,12 @@ namespace PkmnLib::Battling { public: virtual void ModifyCriticalStage(CreatureLib::Battling::ExecutingAttack* attack, 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, CreatureLib::Battling::Creature* winningMon, uint32_t* experienceGain){}; virtual void DoesShareExperience(CreatureLib::Battling::Creature* faintedMon, diff --git a/src/ScriptResolving/AngelScript/AngelScriptScript.cpp b/src/ScriptResolving/AngelScript/AngelScriptScript.cpp index c5eb6de..96c91df 100644 --- a/src/ScriptResolving/AngelScript/AngelScriptScript.cpp +++ b/src/ScriptResolving/AngelScript/AngelScriptScript.cpp @@ -273,3 +273,23 @@ void AngelScriptScript::DoesShareExperience(CreatureLib::Battling::Creature* fai 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); + }) +} diff --git a/src/ScriptResolving/AngelScript/AngelScriptScript.hpp b/src/ScriptResolving/AngelScript/AngelScriptScript.hpp index fe7e6b9..3c90e24 100644 --- a/src/ScriptResolving/AngelScript/AngelScriptScript.hpp +++ b/src/ScriptResolving/AngelScript/AngelScriptScript.hpp @@ -107,6 +107,10 @@ public: void ModifyCriticalStage(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target, 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, uint32_t* experienceGain) override; diff --git a/src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp b/src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp index fd69825..367a87c 100644 --- a/src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp +++ b/src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp @@ -130,6 +130,12 @@ public: SCRIPT_HOOK_FUNCTION( ModifyCriticalStage, "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, "void ModifyExperienceGain(Pokemon@ faintedMon, Pokemon@ winningMon, uint32& critStage)"); SCRIPT_HOOK_FUNCTION(DoesShareExperience, diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/BasicScriptClass.cpp b/src/ScriptResolving/AngelScript/TypeRegistry/BasicScriptClass.cpp index fe0a53f..d2ebaa3 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/BasicScriptClass.cpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/BasicScriptClass.cpp @@ -39,6 +39,9 @@ shared abstract class PkmnScript { // PkmnLib methods 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 DoesShareExperience(Pokemon@ faintedMon, Pokemon@ winningMon, bool& shareExperience){}; }