Initial work on capturing of Pokemon
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
41
src/Battling/Library/CaptureLibrary.cpp
Normal file
41
src/Battling/Library/CaptureLibrary.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
#include "CaptureLibrary.hpp"
|
||||
#include "../PkmnItemUseScript.hpp"
|
||||
#include "../PkmnScriptHook.hpp"
|
||||
|
||||
namespace PkmnLib::Battling {
|
||||
CaptureLibrary::CaptureResult CaptureLibrary::TryCatch(Pokemon* pokemon, Library::Item* catchItem,
|
||||
ArbUt::Random* random) const {
|
||||
auto hpMax = pokemon->GetMaxHealth();
|
||||
auto hpCurrent = pokemon->GetCurrentHealth();
|
||||
auto rate = pokemon->GetSpecies()->GetCaptureRate();
|
||||
|
||||
u8 bonusBall = 1;
|
||||
auto* itemScript =
|
||||
dynamic_cast<PkmnItemUseScript*>(pokemon->GetLibrary()->GetScriptResolver()->LoadItemScript(catchItem));
|
||||
itemScript->ModifyPokeballCatchBonus(pokemon, &bonusBall);
|
||||
|
||||
u8 bonusStatus = 1;
|
||||
PKMN_HOOK(ModifyCaptureRateBonus, pokemon, pokemon, catchItem, &bonusStatus);
|
||||
|
||||
auto modifiedCatchRate = (((3.0 * hpMax) - (2.0 * hpCurrent)) * rate * bonusBall) / (3.0 * hpMax);
|
||||
modifiedCatchRate *= bonusStatus;
|
||||
|
||||
auto shakeProbability = 65536 / pow((255.0 / modifiedCatchRate), 0.1875);
|
||||
|
||||
u8 shakes = 0;
|
||||
if (modifiedCatchRate >= 255) {
|
||||
shakes = 4;
|
||||
}
|
||||
|
||||
// FIXME: Implement critical capture
|
||||
|
||||
for (; shakes < 4; shakes++) {
|
||||
auto randomNumber = random->GetUnsigned(65536);
|
||||
if (randomNumber >= shakeProbability) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
auto success = shakes == 4;
|
||||
return CaptureResult{.WasCaught = success, .Shakes = shakes, .WasCritical = false};
|
||||
}
|
||||
}
|
||||
20
src/Battling/Library/CaptureLibrary.hpp
Normal file
20
src/Battling/Library/CaptureLibrary.hpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef PKMNLIB_CAPTURELIBRARY_HPP
|
||||
#define PKMNLIB_CAPTURELIBRARY_HPP
|
||||
|
||||
#include <CreatureLib/Defines.hpp>
|
||||
#include "../Pokemon/Pokemon.hpp"
|
||||
namespace PkmnLib::Battling {
|
||||
class CaptureLibrary {
|
||||
public:
|
||||
struct CaptureResult {
|
||||
bool WasCaught;
|
||||
u8 Shakes;
|
||||
bool WasCritical;
|
||||
};
|
||||
|
||||
CaptureResult TryCatch(Pokemon* pokemon, Library::Item* catchItem, ArbUt::Random* random) const;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif // PKMNLIB_CAPTURELIBRARY_HPP
|
||||
16
src/Battling/PkmnItemUseScript.hpp
Normal file
16
src/Battling/PkmnItemUseScript.hpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef PKMNLIB_PKMNITEMUSESCRIPT_HPP
|
||||
#define PKMNLIB_PKMNITEMUSESCRIPT_HPP
|
||||
|
||||
#include <CreatureLib/Battling/ScriptHandling/ItemUseScript.hpp>
|
||||
namespace PkmnLib::Battling {
|
||||
class Pokemon;
|
||||
|
||||
class PkmnItemUseScript : public CreatureLib::Battling::ItemUseScript {
|
||||
public:
|
||||
virtual void ModifyPokeballCatchBonus(Pokemon* pokemon, u8* catchBonus) const {
|
||||
(void)pokemon;
|
||||
(void)catchBonus;
|
||||
}
|
||||
};
|
||||
}
|
||||
#endif // PKMNLIB_PKMNITEMUSESCRIPT_HPP
|
||||
@@ -36,6 +36,8 @@ namespace PkmnLib::Battling {
|
||||
CreatureLib::Battling::Creature* target, u8 hitIndex, float* modifier){};
|
||||
virtual void ModifyDefensiveStatValue(CreatureLib::Battling::ExecutingAttack* attack,
|
||||
CreatureLib::Battling::Creature* target, u8 hitIndex, float* modifier){};
|
||||
virtual void ModifyCaptureRateBonus(CreatureLib::Battling::Creature* pokemon,
|
||||
CreatureLib::Library::Item* catchItem, u8* modifier){};
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user