forked from mirror/openmw-tes3mp
[Server] Remove Actors from a Cell's ActorList when they change cells
This commit is contained in:
parent
a77bd6652f
commit
83ba4b62b1
3 changed files with 37 additions and 3 deletions
|
@ -127,6 +127,32 @@ mwmp::BaseActor *Cell::getActor(int refNumIndex, int mpNum)
|
||||||
return 0;
|
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()
|
mwmp::BaseActorList *Cell::getActorList()
|
||||||
{
|
{
|
||||||
return &cellActorList;
|
return &cellActorList;
|
||||||
|
|
|
@ -33,6 +33,7 @@ public:
|
||||||
void readActorList(unsigned char packetID, const mwmp::BaseActorList *newActorList);
|
void readActorList(unsigned char packetID, const mwmp::BaseActorList *newActorList);
|
||||||
bool containsActor(int refNumIndex, int mpNum);
|
bool containsActor(int refNumIndex, int mpNum);
|
||||||
mwmp::BaseActor *getActor(int refNumIndex, int mpNum);
|
mwmp::BaseActor *getActor(int refNumIndex, int mpNum);
|
||||||
|
void removeActors(const mwmp::BaseActorList *newActorList);
|
||||||
mwmp::BaseActorList *getActorList();
|
mwmp::BaseActorList *getActorList();
|
||||||
|
|
||||||
TPlayers getPlayers() const;
|
TPlayers getPlayers() const;
|
||||||
|
|
|
@ -15,10 +15,17 @@ namespace mwmp
|
||||||
|
|
||||||
void Do(ActorPacket &packet, Player &player, BaseActorList &actorList) override
|
void Do(ActorPacket &packet, Player &player, BaseActorList &actorList) override
|
||||||
{
|
{
|
||||||
// Send this to everyone
|
Cell *serverCell = CellController::get()->getCell(&actorList.cell);
|
||||||
packet.Send(true);
|
|
||||||
|
|
||||||
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…
Reference in a new issue