diff --git a/apps/openmw-mp/Script/Functions/Actors.cpp b/apps/openmw-mp/Script/Functions/Actors.cpp index c0ab7739b..d0e57939b 100644 --- a/apps/openmw-mp/Script/Functions/Actors.cpp +++ b/apps/openmw-mp/Script/Functions/Actors.cpp @@ -280,6 +280,36 @@ double ActorFunctions::GetActorSpellsActiveEffectTimeLeft(unsigned int actorInde return readActorList->baseActors.at(actorIndex).spellsActiveChanges.activeSpells.at(spellIndex).params.mEffects.at(effectIndex).mTimeLeft; } +bool ActorFunctions::DoesActorSpellsActiveHavePlayerCaster(unsigned int actorIndex, unsigned int spellIndex) noexcept +{ + return readActorList->baseActors.at(actorIndex).spellsActiveChanges.activeSpells.at(spellIndex).caster.isPlayer; +} + +int ActorFunctions::GetActorSpellsActiveCasterPid(unsigned int actorIndex, unsigned int spellIndex) noexcept +{ + Player* caster = Players::getPlayer(readActorList->baseActors.at(actorIndex).spellsActiveChanges.activeSpells.at(spellIndex).caster.guid); + + if (caster != nullptr) + return caster->getId(); + + return -1; +} + +const char* ActorFunctions::GetActorSpellsActiveCasterRefId(unsigned int actorIndex, unsigned int spellIndex) noexcept +{ + return readActorList->baseActors.at(actorIndex).spellsActiveChanges.activeSpells.at(spellIndex).caster.refId.c_str(); +} + +unsigned int ActorFunctions::GetActorSpellsActiveCasterRefNum(unsigned int actorIndex, unsigned int spellIndex) noexcept +{ + return readActorList->baseActors.at(actorIndex).spellsActiveChanges.activeSpells.at(spellIndex).caster.refNum; +} + +unsigned int ActorFunctions::GetActorSpellsActiveCasterMpNum(unsigned int actorIndex, unsigned int spellIndex) noexcept +{ + return readActorList->baseActors.at(actorIndex).spellsActiveChanges.activeSpells.at(spellIndex).caster.mpNum; +} + bool ActorFunctions::DoesActorHavePosition(unsigned int index) noexcept { return readActorList->baseActors.at(index).hasPositionData; diff --git a/apps/openmw-mp/Script/Functions/Actors.hpp b/apps/openmw-mp/Script/Functions/Actors.hpp index 6e5049d04..80ff88e47 100644 --- a/apps/openmw-mp/Script/Functions/Actors.hpp +++ b/apps/openmw-mp/Script/Functions/Actors.hpp @@ -60,6 +60,12 @@ {"GetActorSpellsActiveEffectDuration", ActorFunctions::GetActorSpellsActiveEffectDuration},\ {"GetActorSpellsActiveEffectTimeLeft", ActorFunctions::GetActorSpellsActiveEffectTimeLeft},\ \ + {"DoesActorSpellsActiveHavePlayerCaster", ActorFunctions::DoesActorSpellsActiveHavePlayerCaster},\ + {"GetActorSpellsActiveCasterPid", ActorFunctions::GetActorSpellsActiveCasterPid},\ + {"GetActorSpellsActiveCasterRefId", ActorFunctions::GetActorSpellsActiveCasterRefId},\ + {"GetActorSpellsActiveCasterRefNum", ActorFunctions::GetActorSpellsActiveCasterRefNum},\ + {"GetActorSpellsActiveCasterMpNum", ActorFunctions::GetActorSpellsActiveCasterMpNum},\ + \ {"DoesActorHavePosition", ActorFunctions::DoesActorHavePosition},\ {"DoesActorHaveStatsDynamic", ActorFunctions::DoesActorHaveStatsDynamic},\ \ @@ -533,6 +539,52 @@ public: */ static double GetActorSpellsActiveEffectTimeLeft(unsigned int actorIndex, unsigned int spellIndex, unsigned int effectIndex) noexcept; + /** + * \brief Check whether the spell at a certain index in an actor's latest spells active changes has a player + * as its caster. + * + * \param actorIndex The index of the actor. + * \param spellIndex The index of the spell. + * \return Whether a player is the caster of the spell. + */ + static bool DoesActorSpellsActiveHavePlayerCaster(unsigned int actorIndex, unsigned int spellIndex) noexcept; + + /** + * \brief Get the player ID of the caster of the spell at a certain index in an actor's latest spells active changes. + * + * \param actorIndex The index of the actor. + * \param spellIndex The index of the spell. + * \return The player ID of the caster. + */ + static int GetActorSpellsActiveCasterPid(unsigned int actorIndex, unsigned int spellIndex) noexcept; + + /** + * \brief Get the refId of the actor caster of the spell at a certain index in an actor's latest spells active changes. + * + * \param actorIndex The index of the actor. + * \param spellIndex The index of the spell. + * \return The refId of the caster. + */ + static const char* GetActorSpellsActiveCasterRefId(unsigned int actorIndex, unsigned int spellIndex) noexcept; + + /** + * \brief Get the refNum of the actor caster of the spell at a certain index in an actor's latest spells active changes. + * + * \param actorIndex The index of the actor. + * \param spellIndex The index of the spell. + * \return The refNum of the caster. + */ + static unsigned int GetActorSpellsActiveCasterRefNum(unsigned int actorIndex, unsigned int spellIndex) noexcept; + + /** + * \brief Get the mpNum of the actor caster of the spell at a certain index in an actor's latest spells active changes. + * + * \param actorIndex The index of the actor. + * \param spellIndex The index of the spell. + * \return The mpNum of the caster. + */ + static unsigned int GetActorSpellsActiveCasterMpNum(unsigned int actorIndex, unsigned int spellIndex) noexcept; + /** * \brief Check whether there is any positional data for the actor at a certain index in * the read actor list.