From 380d898f405c4a45dac8d31f0d9c26dc58a2f4d6 Mon Sep 17 00:00:00 2001 From: Dave Corley Date: Wed, 27 Sep 2023 11:44:02 -0500 Subject: [PATCH] Feat(scripting): Add script function to set player who cast a spell effect on another --- apps/openmw-mp/Script/Functions/Spells.cpp | 13 +++++++++++++ apps/openmw-mp/Script/Functions/Spells.hpp | 9 +++++++++ 2 files changed, 22 insertions(+) diff --git a/apps/openmw-mp/Script/Functions/Spells.cpp b/apps/openmw-mp/Script/Functions/Spells.cpp index 4fd9c1754..d09de1e8a 100644 --- a/apps/openmw-mp/Script/Functions/Spells.cpp +++ b/apps/openmw-mp/Script/Functions/Spells.cpp @@ -8,6 +8,7 @@ using namespace mwmp; +Player* storedPlayerCaster; std::vector storedActiveEffects; void SpellFunctions::ClearSpellbookChanges(unsigned short pid) noexcept @@ -112,8 +113,15 @@ void SpellFunctions::AddSpellActive(unsigned short pid, const char* spellId, con spell.params.mDisplayName = displayName; spell.params.mEffects = storedActiveEffects; + if (storedPlayerCaster != nullptr) + { + spell.caster.isPlayer = true; + spell.caster.guid = storedPlayerCaster->guid; + } + player->spellsActiveChanges.activeSpells.push_back(spell); + storedPlayerCaster = nullptr; storedActiveEffects.clear(); } @@ -348,6 +356,11 @@ double SpellFunctions::GetCooldownStartHour(unsigned short pid, unsigned int ind return player->cooldownChanges.at(index).startTimestampHour; } +void SpellFunctions::SetSpellsActiveCasterPid(unsigned short casterPid) noexcept +{ + storedPlayerCaster = Players::getPlayer(casterPid); +} + void SpellFunctions::SendSpellbookChanges(unsigned short pid, bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept { Player *player; diff --git a/apps/openmw-mp/Script/Functions/Spells.hpp b/apps/openmw-mp/Script/Functions/Spells.hpp index 869b7e720..3e6f5b69b 100644 --- a/apps/openmw-mp/Script/Functions/Spells.hpp +++ b/apps/openmw-mp/Script/Functions/Spells.hpp @@ -41,6 +41,8 @@ {"GetCooldownStartDay", SpellFunctions::GetCooldownStartDay},\ {"GetCooldownStartHour", SpellFunctions::GetCooldownStartHour},\ \ + {"SetSpellsActiveCasterPid", SpellFunctions::SetSpellsActiveCasterPid},\ + \ {"SendSpellbookChanges", SpellFunctions::SendSpellbookChanges},\ {"SendSpellsActiveChanges", SpellFunctions::SendSpellsActiveChanges},\ {"SendCooldownChanges", SpellFunctions::SendCooldownChanges},\ @@ -353,6 +355,13 @@ public: */ static double GetCooldownStartHour(unsigned short pid, unsigned int index) noexcept; + /** + * \brief Set a player ID as the caster of the next active spell that will be added to a player. + * + * \param casterPid The player ID of the caster. + */ + static void SetSpellsActiveCasterPid(unsigned short casterPid) noexcept; + /** * \brief Send a PlayerSpellbook packet with a player's recorded spellbook changes. *