diff --git a/apps/openmw-mp/Script/Functions/Actors.cpp b/apps/openmw-mp/Script/Functions/Actors.cpp index 2324a89fc..6cb7a0e5a 100644 --- a/apps/openmw-mp/Script/Functions/Actors.cpp +++ b/apps/openmw-mp/Script/Functions/Actors.cpp @@ -402,32 +402,70 @@ void ActorFunctions::SendActorAuthority() noexcept } } -void ActorFunctions::SendActorPosition() noexcept +void ActorFunctions::SendActorPosition(bool sendToOtherVisitors, bool skipAttachedPlayer) noexcept { mwmp::ActorPacket *actorPacket = mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_POSITION); actorPacket->setActorList(&writeActorList); - actorPacket->Send(writeActorList.guid); + + if (!skipAttachedPlayer) + actorPacket->Send(writeActorList.guid); + + if (sendToOtherVisitors) + { + Cell *serverCell = CellController::get()->getCell(&writeActorList.cell); + + if (serverCell != nullptr) + { + serverCell->sendToLoaded(actorPacket, &writeActorList); + } + } } -void ActorFunctions::SendActorStatsDynamic() noexcept +void ActorFunctions::SendActorStatsDynamic(bool sendToOtherVisitors, bool skipAttachedPlayer) noexcept { mwmp::ActorPacket *actorPacket = mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_STATS_DYNAMIC); actorPacket->setActorList(&writeActorList); - actorPacket->Send(writeActorList.guid); + + if (!skipAttachedPlayer) + actorPacket->Send(writeActorList.guid); + + if (sendToOtherVisitors) + { + Cell *serverCell = CellController::get()->getCell(&writeActorList.cell); + + if (serverCell != nullptr) + { + serverCell->sendToLoaded(actorPacket, &writeActorList); + } + } } -void ActorFunctions::SendActorEquipment() noexcept +void ActorFunctions::SendActorEquipment(bool sendToOtherVisitors, bool skipAttachedPlayer) noexcept { mwmp::ActorPacket *actorPacket = mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_EQUIPMENT); actorPacket->setActorList(&writeActorList); - actorPacket->Send(writeActorList.guid); + + if (!skipAttachedPlayer) + actorPacket->Send(writeActorList.guid); + + if (sendToOtherVisitors) + { + Cell *serverCell = CellController::get()->getCell(&writeActorList.cell); + + if (serverCell != nullptr) + { + serverCell->sendToLoaded(actorPacket, &writeActorList); + } + } } -void ActorFunctions::SendActorAI(bool sendToOtherVisitors) noexcept +void ActorFunctions::SendActorAI(bool sendToOtherVisitors, bool skipAttachedPlayer) noexcept { mwmp::ActorPacket *actorPacket = mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_AI); actorPacket->setActorList(&writeActorList); - actorPacket->Send(writeActorList.guid); + + if (!skipAttachedPlayer) + actorPacket->Send(writeActorList.guid); if (sendToOtherVisitors) { @@ -435,17 +473,28 @@ void ActorFunctions::SendActorAI(bool sendToOtherVisitors) noexcept if (serverCell != nullptr) { - // Also send this to everyone else who has the cell loaded serverCell->sendToLoaded(actorPacket, &writeActorList); } } } -void ActorFunctions::SendActorCellChange() noexcept +void ActorFunctions::SendActorCellChange(bool sendToOtherVisitors, bool skipAttachedPlayer) noexcept { mwmp::ActorPacket *actorPacket = mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_CELL_CHANGE); actorPacket->setActorList(&writeActorList); - actorPacket->Send(writeActorList.guid); + + if (!skipAttachedPlayer) + actorPacket->Send(writeActorList.guid); + + if (sendToOtherVisitors) + { + Cell *serverCell = CellController::get()->getCell(&writeActorList.cell); + + if (serverCell != nullptr) + { + serverCell->sendToLoaded(actorPacket, &writeActorList); + } + } } // All methods below are deprecated versions of methods from above diff --git a/apps/openmw-mp/Script/Functions/Actors.hpp b/apps/openmw-mp/Script/Functions/Actors.hpp index 42552e764..29a089800 100644 --- a/apps/openmw-mp/Script/Functions/Actors.hpp +++ b/apps/openmw-mp/Script/Functions/Actors.hpp @@ -682,48 +682,61 @@ public: /** * \brief Send an ActorPosition packet. * - * It is sent only to the player for whom the current actor list was initialized. + * \param sendToOtherVisitors Whether this packet should be sent to cell visitors other + * than the player attached to the packet (false by default). + * \param skipAttachedPlayer Whether the packet should skip being sent to the player attached + * to the packet (false by default). * * \return void */ - static void SendActorPosition() noexcept; + static void SendActorPosition(bool sendToOtherVisitors, bool skipAttachedPlayer) noexcept; /** * \brief Send an ActorStatsDynamic packet. * - * It is sent only to the player for whom the current actor list was initialized. + * \param sendToOtherVisitors Whether this packet should be sent to cell visitors other + * than the player attached to the packet (false by default). + * \param skipAttachedPlayer Whether the packet should skip being sent to the player attached + * to the packet (false by default). * * \return void */ - static void SendActorStatsDynamic() noexcept; + static void SendActorStatsDynamic(bool sendToOtherVisitors, bool skipAttachedPlayer) noexcept; /** * \brief Send an ActorEquipment packet. * - * It is sent only to the player for whom the current actor list was initialized. + * \param sendToOtherVisitors Whether this packet should be sent to cell visitors other + * than the player attached to the packet (false by default). + * \param skipAttachedPlayer Whether the packet should skip being sent to the player attached + * to the packet (false by default). * * \return void */ - static void SendActorEquipment() noexcept; + static void SendActorEquipment(bool sendToOtherVisitors, bool skipAttachedPlayer) noexcept; /** * \brief Send an ActorAI packet. * * \param sendToOtherVisitors Whether this packet should be sent to cell visitors other * than the player attached to the packet (false by default). - * + * \param skipAttachedPlayer Whether the packet should skip being sent to the player attached + * to the packet (false by default). * \return void */ - static void SendActorAI(bool sendToOtherVisitors) noexcept; + static void SendActorAI(bool sendToOtherVisitors, bool skipAttachedPlayer) noexcept; /** * \brief Send an ActorCellChange packet. * - * It is sent only to the player for whom the current actor list was initialized. + * \param sendToOtherVisitors Whether this packet should be sent to cell visitors other + * than the player attached to the packet (false by default). + * \param skipAttachedPlayer Whether the packet should skip being sent to the player attached + * to the packet (false by default). * * \return void */ - static void SendActorCellChange() noexcept; + static void SendActorCellChange(bool sendToOtherVisitors, bool skipAttachedPlayer) noexcept; // All methods below are deprecated versions of methods from above