diff --git a/apps/openmw/mwmechanics/activespells.cpp b/apps/openmw/mwmechanics/activespells.cpp index 46be0a48e..cc6cce290 100644 --- a/apps/openmw/mwmechanics/activespells.cpp +++ b/apps/openmw/mwmechanics/activespells.cpp @@ -229,18 +229,13 @@ namespace MWMechanics { bool isStackingSpell = it == end() || stack; - ESM::ActiveSpells::ActiveSpellParams esmParams; - esmParams.mEffects = effects; - esmParams.mDisplayName = displayName; - esmParams.mCasterActorId = casterActorId; - if (this == &MWMechanics::getPlayer().getClass().getCreatureStats(MWMechanics::getPlayer()).getActiveSpells()) { - mwmp::Main::get().getLocalPlayer()->sendSpellsActiveAddition(id, isStackingSpell, esmParams, params.mTimeStamp); + mwmp::Main::get().getLocalPlayer()->sendSpellsActiveAddition(id, isStackingSpell, params); } else if (mwmp::Main::get().getCellController()->isLocalActor(MechanicsHelper::getCurrentActor())) { - mwmp::Main::get().getCellController()->getLocalActor(MechanicsHelper::getCurrentActor())->sendSpellsActiveAddition(id, isStackingSpell, esmParams, params.mTimeStamp); + mwmp::Main::get().getCellController()->getLocalActor(MechanicsHelper::getCurrentActor())->sendSpellsActiveAddition(id, isStackingSpell, params); } } /* diff --git a/apps/openmw/mwmp/DedicatedActor.cpp b/apps/openmw/mwmp/DedicatedActor.cpp index 06af17f58..c9c068cb6 100644 --- a/apps/openmw/mwmp/DedicatedActor.cpp +++ b/apps/openmw/mwmp/DedicatedActor.cpp @@ -366,9 +366,10 @@ void DedicatedActor::addSpellsActive() for (const auto& activeSpell : spellsActiveChanges.activeSpells) { MWWorld::TimeStamp timestamp = MWWorld::TimeStamp(activeSpell.timestampHour, activeSpell.timestampDay); + int casterActorId = MechanicsHelper::getActorId(activeSpell.caster); // Don't do a check for a spell's existence, because active effects from potions need to be applied here too - activeSpells.addSpell(activeSpell.id, activeSpell.isStackingSpell, activeSpell.params.mEffects, activeSpell.params.mDisplayName, 1, timestamp, false); + activeSpells.addSpell(activeSpell.id, activeSpell.isStackingSpell, activeSpell.params.mEffects, activeSpell.params.mDisplayName, casterActorId, timestamp, false); } reloadPtr(); diff --git a/apps/openmw/mwmp/DedicatedPlayer.cpp b/apps/openmw/mwmp/DedicatedPlayer.cpp index a78ba7428..488b41f15 100644 --- a/apps/openmw/mwmp/DedicatedPlayer.cpp +++ b/apps/openmw/mwmp/DedicatedPlayer.cpp @@ -491,9 +491,10 @@ void DedicatedPlayer::addSpellsActive() for (const auto& activeSpell : spellsActiveChanges.activeSpells) { MWWorld::TimeStamp timestamp = MWWorld::TimeStamp(activeSpell.timestampHour, activeSpell.timestampDay); + int casterActorId = MechanicsHelper::getActorId(activeSpell.caster); // Don't do a check for a spell's existence, because active effects from potions need to be applied here too - activeSpells.addSpell(activeSpell.id, activeSpell.isStackingSpell, activeSpell.params.mEffects, activeSpell.params.mDisplayName, 1, timestamp, false); + activeSpells.addSpell(activeSpell.id, activeSpell.isStackingSpell, activeSpell.params.mEffects, activeSpell.params.mDisplayName, casterActorId, timestamp, false); } } diff --git a/apps/openmw/mwmp/LocalActor.cpp b/apps/openmw/mwmp/LocalActor.cpp index 9132c433f..94a69b5aa 100644 --- a/apps/openmw/mwmp/LocalActor.cpp +++ b/apps/openmw/mwmp/LocalActor.cpp @@ -285,7 +285,7 @@ void LocalActor::sendEquipment() Main::get().getNetworking()->getActorPacket(ID_ACTOR_EQUIPMENT)->Send(); } -void LocalActor::sendSpellsActiveAddition(const std::string id, bool isStackingSpell, ESM::ActiveSpells::ActiveSpellParams params, MWWorld::TimeStamp timestamp) +void LocalActor::sendSpellsActiveAddition(const std::string id, bool isStackingSpell, const MWMechanics::ActiveSpells::ActiveSpellParams& params) { // Skip any bugged spells that somehow have clientside-only dynamic IDs if (id.find("$dynamic") != std::string::npos) @@ -293,12 +293,16 @@ void LocalActor::sendSpellsActiveAddition(const std::string id, bool isStackingS spellsActiveChanges.activeSpells.clear(); + const MWWorld::Ptr& caster = MWBase::Environment::get().getWorld()->searchPtrViaActorId(params.mCasterActorId); + mwmp::ActiveSpell spell; spell.id = id; spell.isStackingSpell = isStackingSpell; - spell.timestampDay = timestamp.getDay(); - spell.timestampHour = timestamp.getHour(); - spell.params = params; + spell.caster = MechanicsHelper::getTarget(caster); + spell.timestampDay = params.mTimeStamp.getDay(); + spell.timestampHour = params.mTimeStamp.getHour(); + spell.params.mEffects = params.mEffects; + spell.params.mDisplayName = params.mDisplayName; spellsActiveChanges.activeSpells.push_back(spell); spellsActiveChanges.action = mwmp::SpellsActiveChanges::ADD; diff --git a/apps/openmw/mwmp/LocalActor.hpp b/apps/openmw/mwmp/LocalActor.hpp index d888d7036..1b474d60e 100644 --- a/apps/openmw/mwmp/LocalActor.hpp +++ b/apps/openmw/mwmp/LocalActor.hpp @@ -3,6 +3,7 @@ #include #include "../mwmechanics/creaturestats.hpp" +#include "../mwmechanics/activespells.hpp" #include "../mwworld/manualref.hpp" #include "../mwworld/timestamp.hpp" @@ -27,7 +28,7 @@ namespace mwmp void updateAttackOrCast(); void sendEquipment(); - void sendSpellsActiveAddition(const std::string id, bool isStackingSpell, ESM::ActiveSpells::ActiveSpellParams params, MWWorld::TimeStamp timestamp); + void sendSpellsActiveAddition(const std::string id, bool isStackingSpell, const MWMechanics::ActiveSpells::ActiveSpellParams& params); void sendSpellsActiveRemoval(const std::string id, bool isStackingSpell, MWWorld::TimeStamp timestamp); void sendDeath(char newDeathState); diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index b123118d0..f344ca1f8 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -719,9 +719,10 @@ void LocalPlayer::addSpellsActive() for (const auto& activeSpell : spellsActiveChanges.activeSpells) { MWWorld::TimeStamp timestamp = MWWorld::TimeStamp(activeSpell.timestampHour, activeSpell.timestampDay); + int casterActorId = MechanicsHelper::getActorId(activeSpell.caster); // Don't do a check for a spell's existence, because active effects from potions need to be applied here too - activeSpells.addSpell(activeSpell.id, activeSpell.isStackingSpell, activeSpell.params.mEffects, activeSpell.params.mDisplayName, 1, timestamp, false); + activeSpells.addSpell(activeSpell.id, activeSpell.isStackingSpell, activeSpell.params.mEffects, activeSpell.params.mDisplayName, casterActorId, timestamp, false); } } @@ -1617,7 +1618,7 @@ void LocalPlayer::sendSpellsActive() getNetworking()->getPlayerPacket(ID_PLAYER_SPELLS_ACTIVE)->Send(); } -void LocalPlayer::sendSpellsActiveAddition(const std::string id, bool isStackingSpell, ESM::ActiveSpells::ActiveSpellParams params, MWWorld::TimeStamp timestamp) +void LocalPlayer::sendSpellsActiveAddition(const std::string id, bool isStackingSpell, const MWMechanics::ActiveSpells::ActiveSpellParams& params) { // Skip any bugged spells that somehow have clientside-only dynamic IDs if (id.find("$dynamic") != std::string::npos) @@ -1625,12 +1626,17 @@ void LocalPlayer::sendSpellsActiveAddition(const std::string id, bool isStacking spellsActiveChanges.activeSpells.clear(); + + MWWorld::Ptr caster = MWBase::Environment::get().getWorld()->searchPtrViaActorId(params.mCasterActorId); + mwmp::ActiveSpell spell; spell.id = id; spell.isStackingSpell = isStackingSpell; - spell.timestampDay = timestamp.getDay(); - spell.timestampHour = timestamp.getHour(); - spell.params = params; + spell.caster = MechanicsHelper::getTarget(caster); + spell.timestampDay = params.mTimeStamp.getDay(); + spell.timestampHour = params.mTimeStamp.getHour(); + spell.params.mEffects = params.mEffects; + spell.params.mDisplayName = params.mDisplayName; spellsActiveChanges.activeSpells.push_back(spell); LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "Sending active spell addition with stacking %s, timestamp %i %f", diff --git a/apps/openmw/mwmp/LocalPlayer.hpp b/apps/openmw/mwmp/LocalPlayer.hpp index 73410f2e1..74a53b01e 100644 --- a/apps/openmw/mwmp/LocalPlayer.hpp +++ b/apps/openmw/mwmp/LocalPlayer.hpp @@ -2,6 +2,7 @@ #define OPENMW_LOCALPLAYER_HPP #include +#include "../mwmechanics/activespells.hpp" #include "../mwworld/ptr.hpp" #include "../mwworld/timestamp.hpp" #include @@ -93,7 +94,7 @@ namespace mwmp void sendSpellbook(); void sendSpellChange(std::string id, unsigned int action); void sendSpellsActive(); - void sendSpellsActiveAddition(const std::string id, bool isStackingSpell, ESM::ActiveSpells::ActiveSpellParams params, MWWorld::TimeStamp timestamp); + void sendSpellsActiveAddition(const std::string id, bool isStackingSpell, const MWMechanics::ActiveSpells::ActiveSpellParams& params); void sendSpellsActiveRemoval(const std::string id, bool isStackingSpell, MWWorld::TimeStamp timestamp); void sendCooldownChange(std::string id, int startTimestampDay, float startTimestampHour); void sendQuickKey(unsigned short slot, int type, const std::string& itemId = ""); diff --git a/components/openmw-mp/Base/BaseStructs.hpp b/components/openmw-mp/Base/BaseStructs.hpp index 42176e5b2..970aeb80c 100644 --- a/components/openmw-mp/Base/BaseStructs.hpp +++ b/components/openmw-mp/Base/BaseStructs.hpp @@ -173,6 +173,7 @@ namespace mwmp bool isStackingSpell; int timestampDay; double timestampHour; + Target caster; ESM::ActiveSpells::ActiveSpellParams params; }; diff --git a/components/openmw-mp/Packets/Actor/PacketActorSpellsActive.cpp b/components/openmw-mp/Packets/Actor/PacketActorSpellsActive.cpp index adbf99bf4..e7cf1b347 100644 --- a/components/openmw-mp/Packets/Actor/PacketActorSpellsActive.cpp +++ b/components/openmw-mp/Packets/Actor/PacketActorSpellsActive.cpp @@ -34,6 +34,19 @@ void PacketActorSpellsActive::Actor(BaseActor &actor, bool send) RW(activeSpell.timestampHour, send); RW(activeSpell.params.mDisplayName, send, true); + RW(activeSpell.caster.isPlayer, send); + + if (activeSpell.caster.isPlayer) + { + RW(activeSpell.caster.guid, send); + } + else + { + RW(activeSpell.caster.refId, send, true); + RW(activeSpell.caster.refNum, send); + RW(activeSpell.caster.mpNum, send); + } + uint32_t effectCount; if (send) diff --git a/components/openmw-mp/Packets/Player/PacketPlayerSpellsActive.cpp b/components/openmw-mp/Packets/Player/PacketPlayerSpellsActive.cpp index 194440711..500af1a0c 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerSpellsActive.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerSpellsActive.cpp @@ -35,6 +35,19 @@ void PacketPlayerSpellsActive::Packet(RakNet::BitStream *newBitstream, bool send RW(activeSpell.timestampHour, send); RW(activeSpell.params.mDisplayName, send, true); + RW(activeSpell.caster.isPlayer, send); + + if (activeSpell.caster.isPlayer) + { + RW(activeSpell.caster.guid, send); + } + else + { + RW(activeSpell.caster.refId, send, true); + RW(activeSpell.caster.refNum, send); + RW(activeSpell.caster.mpNum, send); + } + uint32_t effectCount; if (send)