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. *