[Server] Remove Actors from a Cell's ActorList when they change cells

0.6.1
David Cernat 8 years ago
parent a77bd6652f
commit 83ba4b62b1

@ -127,6 +127,32 @@ mwmp::BaseActor *Cell::getActor(int refNumIndex, int mpNum)
return 0;
}
void Cell::removeActors(const mwmp::BaseActorList *newActorList)
{
for (std::vector<mwmp::BaseActor>::iterator it = cellActorList.baseActors.begin(); it != cellActorList.baseActors.end();)
{
int refNumIndex = (*it).refNumIndex;
int mpNum = (*it).mpNum;
bool foundActor = false;
for (unsigned int i = 0; i < newActorList->count; i++)
{
mwmp::BaseActor newActor = newActorList->baseActors.at(i);
if (newActor.refNumIndex == refNumIndex && newActor.mpNum == mpNum)
{
it = cellActorList.baseActors.erase(it);
foundActor = true;
break;
}
}
if (!foundActor)
it++;
}
}
mwmp::BaseActorList *Cell::getActorList()
{
return &cellActorList;

@ -33,6 +33,7 @@ public:
void readActorList(unsigned char packetID, const mwmp::BaseActorList *newActorList);
bool containsActor(int refNumIndex, int mpNum);
mwmp::BaseActor *getActor(int refNumIndex, int mpNum);
void removeActors(const mwmp::BaseActorList *newActorList);
mwmp::BaseActorList *getActorList();
TPlayers getPlayers() const;

@ -15,10 +15,17 @@ namespace mwmp
void Do(ActorPacket &packet, Player &player, BaseActorList &actorList) override
{
// Send this to everyone
packet.Send(true);
Cell *serverCell = CellController::get()->getCell(&actorList.cell);
Script::Call<Script::CallbackIdentity("OnActorCellChange")>(player.getId(), actorList.cell.getDescription().c_str());
if (serverCell != nullptr)
{
serverCell->removeActors(&actorList);
Script::Call<Script::CallbackIdentity("OnActorCellChange")>(player.getId(), actorList.cell.getDescription().c_str());
// Send this to everyone
packet.Send(true);
}
}
};
}

Loading…
Cancel
Save