[Client] Reply to ActorList request with list of NPCs

This commit is contained in:
David Cernat 2017-04-05 05:54:25 +03:00
parent 8f18dc87c4
commit ca92be14a5
5 changed files with 45 additions and 0 deletions

View file

@ -842,7 +842,17 @@ void Networking::processWorldPacket(RakNet::Packet *packet)
{
case ID_ACTOR_LIST:
{
MWWorld::CellStore *ptrCellStore = Main::get().getWorldController()->getCell(worldEvent.cell);
if (!ptrCellStore) return;
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Received ID_ACTOR_LIST about %s", worldEvent.cell.getDescription().c_str());
LOG_APPEND(Log::LOG_VERBOSE, "- action: %i", worldEvent.action);
// If we've received a request for information, comply with it
if (worldEvent.action == mwmp::BaseEvent::REQUEST)
worldEvent.sendActors(ptrCellStore);
break;
}
case ID_ACTOR_AUTHORITY:

View file

@ -40,6 +40,31 @@ void WorldEvent::addObject(WorldObject worldObject)
objectChanges.objects.push_back(worldObject);
}
void WorldEvent::sendActors(MWWorld::CellStore* cellStore)
{
mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent();
worldEvent->cell = *cellStore->getCell();
worldEvent->action = BaseEvent::SET;
MWWorld::CellRefList<ESM::NPC> *npcList = cellStore->getNpcs();
for (typename MWWorld::CellRefList<ESM::NPC>::List::iterator listIter(npcList->mList.begin());
listIter != npcList->mList.end(); ++listIter)
{
MWWorld::Ptr npc(&*listIter, 0);
mwmp::WorldObject worldObject;
worldObject.refId = npc.getCellRef().getRefId();
worldObject.refNumIndex = npc.getCellRef().getRefNum().mIndex;
worldObject.mpNum = npc.getCellRef().getMpNum();
worldEvent->addObject(worldObject);
}
mwmp::Main::get().getNetworking()->getWorldPacket(ID_ACTOR_LIST)->setEvent(worldEvent);
mwmp::Main::get().getNetworking()->getWorldPacket(ID_ACTOR_LIST)->Send();
}
void WorldEvent::sendContainers(MWWorld::CellStore* cellStore)
{
mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->resetWorldEvent();

View file

@ -17,6 +17,7 @@ namespace mwmp
void addObject(WorldObject worldObject);
void sendActors(MWWorld::CellStore* cellStore);
void sendContainers(MWWorld::CellStore* cellStore);
void editContainers(MWWorld::CellStore* cellStore);

View file

@ -481,6 +481,12 @@ namespace MWWorld
return searchVisitor.mFound;
}
// Added by tes3mp and used to get all the NPCs in the cell
CellRefList<ESM::NPC> *CellStore::getNpcs()
{
return &mNpcs;
}
// Added by tes3mp and used to get all the containers in the cell
CellRefList<ESM::Container> *CellStore::getContainers()
{

View file

@ -237,6 +237,9 @@ namespace MWWorld
Ptr searchExact (const std::string& id, unsigned int refNumIndex, unsigned int mpNum);
///< Added by tes3mp and used to find an object by both its ID and its reference number
CellRefList<ESM::NPC> *getNpcs();
// Added by tes3mp and used to get all the NPCs in the cell
CellRefList<ESM::Container> *getContainers();
// Added by tes3mp and used to get all the containers in the cell