Implement held item scripts
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2022-02-19 14:04:43 +01:00
parent c0bdc73606
commit f7c881b4e7
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
12 changed files with 34 additions and 12 deletions

3
.gitignore vendored
View File

@ -1,4 +1,3 @@
/cmake-build-debug/
/cmake-build-release/
/cmake-build-*
/build-release-windows/
/.idea/

3
.gitmodules vendored
View File

@ -1,3 +0,0 @@
[submodule "extern/AngelscriptDebuggerServer"]
path = extern/AngelscriptDebuggerServer
url = https://git.p-epsilon.com/Deukhoofd/AngelscriptDebuggerServer.git

View File

@ -6,7 +6,9 @@ using namespace PkmnLib::Library;
export Item* PkmnLib_Item_Construct(const char* name, CreatureLib::Library::ItemCategory category,
CreatureLib::Library::BattleItemCategory battleCategory, int32_t price,
const char* effectName, CreatureLib::Library::EffectParameter* effectParameters[],
size_t effectParameterCount, const char* flags[], size_t flagsCount,
size_t effectParameterCount, const char* battleTriggerEffectName,
CreatureLib::Library::EffectParameter* battleTriggerEffectParameters[],
size_t battleTriggerEffectParameterCount, const char* flags[], size_t flagsCount,
uint8_t flingPower) {
std::unordered_set<uint32_t> conversedFlags(flagsCount);
for (size_t i = 0; i < flagsCount; i++) {
@ -18,6 +20,11 @@ export Item* PkmnLib_Item_Construct(const char* name, CreatureLib::Library::Item
new CreatureLib::Library::SecondaryEffect(100, effectName,
ArbUt::List<CreatureLib::Library::EffectParameter*>(
effectParameters, effectParameters + effectParameterCount)),
new CreatureLib::Library::SecondaryEffect(
100, battleTriggerEffectName,
ArbUt::List<CreatureLib::Library::EffectParameter*>(
battleTriggerEffectParameters, battleTriggerEffectParameters + battleTriggerEffectParameterCount)),
conversedFlags, flingPower);
};

View File

@ -9,9 +9,10 @@ namespace PkmnLib::Library {
public:
Item(const ArbUt::StringView& name, CreatureLib::Library::ItemCategory category,
CreatureLib::Library::BattleItemCategory battleCategory, int32_t price,
const CreatureLib::Library::SecondaryEffect* effect, const std::unordered_set<uint32_t>& flags,
uint8_t flingPower) noexcept
: CreatureLib::Library::Item(name, category, battleCategory, price, effect, flags),
const CreatureLib::Library::SecondaryEffect* effect,
const CreatureLib::Library::SecondaryEffect* battleTriggerEffect,
const std::unordered_set<uint32_t>& flags, uint8_t flingPower) noexcept
: CreatureLib::Library::Item(name, category, battleCategory, price, battleTriggerEffect, effect, flags),
_flingPower(flingPower) {}
inline uint8_t GetFlingPower() const noexcept { return _flingPower; }

View File

@ -5,8 +5,8 @@
#include <scriptdictionary/scriptdictionary.h>
#include <scripthandle/scripthandle.h>
#include <scripthelper/scripthelper.h>
#include <scriptstdstring/scriptstdstring.h>
#include <scriptmath/scriptmath.h>
#include <scriptstdstring/scriptstdstring.h>
#include "AngelScriptMetadata.hpp"
#include "AngelscriptUserdata.hpp"
#include "ByteCodeHandling/FileByteCodeStream.hpp"
@ -309,6 +309,10 @@ void AngelScriptResolver::RegisterScriptType(asITypeInfo* typeInfo, const ArbUt:
case "Side"_cnc:
_typeDatabase[ScriptCategory::Side].Insert(effectName, new AngelScriptTypeInfo(effectName, typeInfo));
break;
case "ItemBattleTrigger"_cnc:
_typeDatabase[ScriptCategory::ItemBattleTrigger].Insert(effectName,
new AngelScriptTypeInfo(effectName, typeInfo));
break;
case "Weather"_cnc:
_typeDatabase[static_cast<ScriptCategory>(PkmnScriptCategory::Weather)].Insert(
effectName, new AngelScriptTypeInfo(effectName, typeInfo));

View File

@ -136,6 +136,7 @@ public:
case ScriptCategory::Creature: t = _engine->GetTypeInfoByName("Pokemon"); break;
case ScriptCategory::Battle: t = _engine->GetTypeInfoByName("Battle"); break;
case ScriptCategory::Side: t = _engine->GetTypeInfoByName("BattleSide"); break;
case ScriptCategory::ItemBattleTrigger: t = _engine->GetTypeInfoByName("Pokemon"); break;
}
switch (static_cast<PkmnScriptCategory>(category)) {
case PkmnScriptCategory::Weather: t = _engine->GetTypeInfoByName("Battle"); break;

View File

@ -433,3 +433,10 @@ void AngelScriptScript::ModifyDefensiveStatValue(CreatureLib::Battling::Executin
ctx->SetArgAddress(3, modifier);
})
}
void AngelScriptScript::OnAfterHeldItemConsume(CreatureLib::Battling::Creature* creature,
const CreatureLib::Library::Item* item) {
CALL_HOOK(OnAfterHeldItemConsume, {
ctx->SetArgObject(0, (void*)creature);
ctx->SetArgObject(1, (void*)item);
});
}

View File

@ -133,6 +133,8 @@ public:
[[maybe_unused]] u32 oldHealth, [[maybe_unused]] u32 newHealth) override;
void OnFaint(CreatureLib::Battling::Creature* creature, CreatureLib::Battling::DamageSource source) override;
void OnSwitchIn(CreatureLib::Battling::Creature* creature) override;
void OnAfterHeldItemConsume(CreatureLib::Battling::Creature* creature,
const CreatureLib::Library::Item* item) override;
////////////////////
// PkmnLib methods//

View File

@ -190,6 +190,9 @@ public:
SCRIPT_HOOK_FUNCTION(
ModifyDefensiveStatValue,
"void ModifyDefensiveStatValue(ExecutingMove@ attack, Pokemon@ target, uint8 hit, float& defensiveStatValue)");
SCRIPT_HOOK_FUNCTION(
OnAfterHeldItemConsume,
"void OnAfterHeldItemConsume(Pokemon@ target, const Item@ item)");
};
#undef SCRIPT_HOOK_FUNCTION

View File

@ -58,6 +58,7 @@ shared abstract class PkmnScript {
void OnEndTurn(){};
void OnDamage(Pokemon@ pokemon, DamageSource damageSource, uint oldHealth, uint newHealth){};
void OnFaint(Pokemon@ pokemon, DamageSource damageSource){};
void OnAfterHeldItemConsume(Pokemon@ target, const Item@ item){};
// PkmnLib methods
void PreventIncomingCritical(ExecutingMove@ attack, Pokemon@ target, uint8 hit, bool& preventCrit){};

View File

@ -42,7 +42,7 @@ static AngelScriptItemUseScript* GetScript(PkmnLib::Battling::BattleLibrary* mai
auto lib = GetScriptResolver(mainLib);
auto item = CreatureLib::Library::Item(name, CreatureLib::Library::ItemCategory::MiscItem,
CreatureLib::Library::BattleItemCategory::None, 0,
new CreatureLib::Library::SecondaryEffect(100, name, {}), {});
new CreatureLib::Library::SecondaryEffect(100, name, {}), nullptr, {});
auto s = lib->LoadItemScript(&item);
auto script = dynamic_cast<AngelScriptItemUseScript*>(s);

View File

@ -78,6 +78,6 @@ PkmnLib::Library::ItemLibrary* TestLibrary::BuildItemLibrary() {
auto lib = new PkmnLib::Library::ItemLibrary();
lib->Insert("testItem"_cnc.GetHash(),
new PkmnLib::Library::Item("testItem"_cnc, CreatureLib::Library::ItemCategory::MiscItem,
CreatureLib::Library::BattleItemCategory::None, 0, nullptr, {}, 0));
CreatureLib::Library::BattleItemCategory::None, 0, nullptr, nullptr, {}, 0));
return lib;
}