diff --git a/apps/openmw/mwmp/DedicatedPlayer.cpp b/apps/openmw/mwmp/DedicatedPlayer.cpp index 23aa76e5d..d887e7645 100644 --- a/apps/openmw/mwmp/DedicatedPlayer.cpp +++ b/apps/openmw/mwmp/DedicatedPlayer.cpp @@ -484,6 +484,41 @@ void DedicatedPlayer::resurrect() getPtr().getClass().getCreatureStats(getPtr()).setHealth(health); } +void DedicatedPlayer::addSpellsActive() +{ + MWMechanics::ActiveSpells& activeSpells = getPtr().getClass().getCreatureStats(getPtr()).getActiveSpells(); + + for (const auto& activeSpell : spellsActiveChanges.activeSpells) + { + // Only add spells that are ensured to exist + if (MWBase::Environment::get().getWorld()->getStore().get().search(activeSpell.id)) + { + activeSpells.addSpell(activeSpell.id, false, activeSpell.params.mEffects, activeSpell.params.mDisplayName, 1); + } + else + LOG_APPEND(TimedLog::LOG_INFO, "- Ignored addition of invalid spell %s", activeSpell.id.c_str()); + } +} + +void DedicatedPlayer::removeSpellsActive() +{ + MWMechanics::ActiveSpells& activeSpells = getPtr().getClass().getCreatureStats(getPtr()).getActiveSpells(); + + for (const auto& activeSpell : spellsActiveChanges.activeSpells) + { + activeSpells.removeEffects(activeSpell.id); + } +} + +void DedicatedPlayer::setSpellsActive() +{ + MWMechanics::ActiveSpells& activeSpells = getPtr().getClass().getCreatureStats(getPtr()).getActiveSpells(); + activeSpells.clear(); + + // Proceed by adding spells active + addSpellsActive(); +} + void DedicatedPlayer::updateMarker() { if (!markerEnabled) diff --git a/apps/openmw/mwmp/DedicatedPlayer.hpp b/apps/openmw/mwmp/DedicatedPlayer.hpp index f9359a8b2..679e021f9 100644 --- a/apps/openmw/mwmp/DedicatedPlayer.hpp +++ b/apps/openmw/mwmp/DedicatedPlayer.hpp @@ -49,6 +49,10 @@ namespace mwmp void die(); void resurrect(); + void addSpellsActive(); + void removeSpellsActive(); + void setSpellsActive(); + void updateMarker(); void removeMarker(); void enableMarker(); diff --git a/apps/openmw/mwmp/processors/player/ProcessorPlayerSpellsActive.hpp b/apps/openmw/mwmp/processors/player/ProcessorPlayerSpellsActive.hpp index 95752831b..a33b6d10d 100644 --- a/apps/openmw/mwmp/processors/player/ProcessorPlayerSpellsActive.hpp +++ b/apps/openmw/mwmp/processors/player/ProcessorPlayerSpellsActive.hpp @@ -16,24 +16,42 @@ namespace mwmp virtual void Do(PlayerPacket &packet, BasePlayer *player) { - if (!isLocal()) return; + LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "Received ID_PLAYER_SPELLS_ACTIVE from server"); - LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "Received ID_PLAYER_SPELLS_ACTIVE about LocalPlayer from server"); + if (isLocal()) + { + LOG_APPEND(TimedLog::LOG_INFO, "- Packet was about me"); - if (isRequest()) - static_cast(player)->sendSpellsActive(); + if (isRequest()) + static_cast(player)->sendSpellsActive(); + else + { + LocalPlayer& localPlayer = static_cast(*player); + + int spellsActiveAction = localPlayer.spellsActiveChanges.action; + + if (spellsActiveAction == SpellsActiveChanges::ADD) + localPlayer.addSpellsActive(); + else if (spellsActiveAction == SpellsActiveChanges::REMOVE) + localPlayer.removeSpellsActive(); + else // SpellsActiveChanges::SET + localPlayer.setSpellsActive(); + } + } else { - LocalPlayer &localPlayer = static_cast(*player); - - int spellsActiveAction = localPlayer.spellsActiveChanges.action; + LOG_APPEND(TimedLog::LOG_INFO, "- Packet was about %s", player->npc.mName.c_str()); + + DedicatedPlayer& dedicatedPlayer = static_cast(*player); + + int spellsActiveAction = dedicatedPlayer.spellsActiveChanges.action; if (spellsActiveAction == SpellsActiveChanges::ADD) - localPlayer.addSpellsActive(); + dedicatedPlayer.addSpellsActive(); else if (spellsActiveAction == SpellsActiveChanges::REMOVE) - localPlayer.removeSpellsActive(); + dedicatedPlayer.removeSpellsActive(); else // SpellsActiveChanges::SET - localPlayer.setSpellsActive(); + dedicatedPlayer.setSpellsActive(); } } };