[Server] Add sendToOtherVisitors boolean to SendActorAI()

Additionally, avoid repetition in functions that send Actor packets.
remotes/1728160796594174844/tmp_0.7.0-alpha
David Cernat 7 years ago
parent 25f7a55495
commit 5bb442bbd3

@ -371,8 +371,9 @@ void ActorFunctions::AddActor() noexcept
void ActorFunctions::SendActorList() noexcept
{
mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_LIST)->setActorList(&writeActorList);
mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_LIST)->Send(writeActorList.guid);
mwmp::ActorPacket *actorPacket = mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_LIST);
actorPacket->setActorList(&writeActorList);
actorPacket->Send(writeActorList.guid);
}
void ActorFunctions::SendActorAuthority() noexcept
@ -383,42 +384,58 @@ void ActorFunctions::SendActorAuthority() noexcept
{
serverCell->setAuthority(writeActorList.guid);
mwmp::ActorPacket *authorityPacket = mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_AUTHORITY);
authorityPacket->setActorList(&writeActorList);
authorityPacket->Send(writeActorList.guid);
mwmp::ActorPacket *actorPacket = mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_AUTHORITY);
actorPacket->setActorList(&writeActorList);
actorPacket->Send(writeActorList.guid);
// Also send this to everyone else who has the cell loaded
serverCell->sendToLoaded(authorityPacket, &writeActorList);
serverCell->sendToLoaded(actorPacket, &writeActorList);
}
}
void ActorFunctions::SendActorPosition() noexcept
{
mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_POSITION)->setActorList(&writeActorList);
mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_POSITION)->Send(writeActorList.guid);
mwmp::ActorPacket *actorPacket = mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_POSITION);
actorPacket->setActorList(&writeActorList);
actorPacket->Send(writeActorList.guid);
}
void ActorFunctions::SendActorStatsDynamic() noexcept
{
mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_STATS_DYNAMIC)->setActorList(&writeActorList);
mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_STATS_DYNAMIC)->Send(writeActorList.guid);
mwmp::ActorPacket *actorPacket = mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_STATS_DYNAMIC);
actorPacket->setActorList(&writeActorList);
actorPacket->Send(writeActorList.guid);
}
void ActorFunctions::SendActorEquipment() noexcept
{
mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_EQUIPMENT)->setActorList(&writeActorList);
mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_EQUIPMENT)->Send(writeActorList.guid);
mwmp::ActorPacket *actorPacket = mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_EQUIPMENT);
actorPacket->setActorList(&writeActorList);
actorPacket->Send(writeActorList.guid);
}
void ActorFunctions::SendActorAI() noexcept
void ActorFunctions::SendActorAI(bool sendToOtherVisitors) noexcept
{
mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_AI)->setActorList(&writeActorList);
mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_AI)->Send(writeActorList.guid);
mwmp::ActorPacket *actorPacket = mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_AI);
actorPacket->setActorList(&writeActorList);
actorPacket->Send(writeActorList.guid);
if (sendToOtherVisitors)
{
Cell *serverCell = CellController::get()->getCell(&writeActorList.cell);
if (serverCell != nullptr)
{
// Also send this to everyone else who has the cell loaded
serverCell->sendToLoaded(actorPacket, &writeActorList);
}
}
}
void ActorFunctions::SendActorCellChange() noexcept
{
mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_CELL_CHANGE)->setActorList(&writeActorList);
mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_CELL_CHANGE)->Send(writeActorList.guid);
mwmp::ActorPacket *actorPacket = mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_CELL_CHANGE);
actorPacket->setActorList(&writeActorList);
actorPacket->Send(writeActorList.guid);
}

@ -689,11 +689,12 @@ public:
/**
* \brief Send an ActorAI 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).
*
* \return void
*/
static void SendActorAI() noexcept;
static void SendActorAI(bool sendToOtherVisitors) noexcept;
/**
* \brief Send an ActorCellChange packet.

Loading…
Cancel
Save