Register Heal Method in AngelScript.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-02-13 15:15:07 +01:00
parent 6032610de6
commit b83cefce11
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
3 changed files with 27 additions and 1 deletions

View File

@ -44,7 +44,7 @@ class PkmnLibConan(ConanFile):
self.options["AngelScript"].link_std_statically = True
def requirements(self):
self.requires("CreatureLib/2dcb197191f8e26a106c032f09476073cce0f2df@creaturelib/master")
self.requires("CreatureLib/8d4860f5534b105c35e2b2a640163461076f321d@creaturelib/master")
if self.options.script_handler == "angelscript":
self.requires("AngelScript/2.34@AngelScript/Deukhoofd")
else:

View File

@ -129,9 +129,15 @@ void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
r = engine->RegisterObjectMethod("Pokemon", "bool HasType(uint8 type) const",
asMETHOD(PkmnLib::Battling::Pokemon, HasType), asCALL_THISCALL);
assert(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "uint32 get_MaxHealth() const property",
asMETHOD(PkmnLib::Battling::Pokemon, GetMaxHealth), asCALL_THISCALL);
assert(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "void Damage(uint32 type, DamageSource source)",
asMETHOD(PkmnLib::Battling::Pokemon, Damage), asCALL_THISCALL);
assert(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "void Heal(uint32 type)",
asMETHOD(PkmnLib::Battling::Pokemon, Heal), asCALL_THISCALL);
assert(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "void OverrideActiveAbility(const string &in ability)",
asMETHOD(PkmnLib::Battling::Pokemon, OverrideActiveTalent), asCALL_THISCALL);
assert(r >= 0);

View File

@ -21,6 +21,7 @@ class testScript1 {
bool testType(Pokemon@ p, uint index, uint8 type){ return p.GetTypes()[index] == type; }
bool testHasType(Pokemon@ p, uint8 type){ return p.HasType(type); }
void testDamage(Pokemon@ p, uint32 damage, DamageSource source){ p.Damage(damage, source); }
void testHeal(Pokemon@ p, uint32 amount){ p.Heal(amount); }
bool testMove(Pokemon@ p, uint index, LearnedMove@ move){ return p.GetMoves()[index] is move; }
}
@ -292,6 +293,25 @@ TEST_CASE("Validate Pokemon Damage in Script") {
delete mon;
}
TEST_CASE("Validate Pokemon Heal in Script") {
auto mainLib = TestLibrary::GetLibrary();
auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies3", 30)
.WithForme("default")
->WithGender(CreatureLib::Library::Gender::Male)
->Build();
mon->Damage(50, CreatureLib::Battling::DamageSource::AttackDamage);
auto data = GetScript(mainLib, "testHeal");
data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon));
data.Context->SetArgDWord(1, 30);
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
REQUIRE(mon->GetCurrentHealth() == mon->GetBoostedStat(PkmnLib::Library::Statistic::HealthPoints) - 20);
delete mon;
}
TEST_CASE("Validate Pokemon GetMoves in Script") {
auto mainLib = TestLibrary::GetLibrary();