Fix playersInView miscount for dead mobs

This commit is contained in:
dongresource 2021-04-08 19:25:30 +02:00
parent fd965fbf03
commit 48fb510b53
3 changed files with 12 additions and 13 deletions

View File

@ -92,6 +92,12 @@ void Chunking::addEntityToChunks(std::set<Chunk*> chnks, const EntityRef& ref) {
if (ref.type == EntityType::PLAYER && other->isAlive()) { if (ref.type == EntityType::PLAYER && other->isAlive()) {
other->enterIntoViewOf(ref.sock); other->enterIntoViewOf(ref.sock);
} }
// for mobs, increment playersInView
if (ref.type == EntityType::MOB && otherRef.type == EntityType::PLAYER)
((Mob*)ent)->playersInView++;
if (otherRef.type == EntityType::MOB && ref.type == EntityType::PLAYER)
((Mob*)other)->playersInView++;
} }
} }
} }
@ -118,6 +124,12 @@ void Chunking::removeEntityFromChunks(std::set<Chunk*> chnks, const EntityRef& r
if (ref.type == EntityType::PLAYER && other->isAlive()) { if (ref.type == EntityType::PLAYER && other->isAlive()) {
other->disappearFromViewOf(ref.sock); other->disappearFromViewOf(ref.sock);
} }
// for mobs, decrement playersInView
if (ref.type == EntityType::MOB && otherRef.type == EntityType::PLAYER)
((Mob*)ent)->playersInView--;
if (otherRef.type == EntityType::MOB && ref.type == EntityType::PLAYER)
((Mob*)other)->playersInView--;
} }
} }
} }

View File

@ -48,11 +48,6 @@ void BaseNPC::enterIntoViewOf(CNSocket *sock) {
sock->sendPacket(pkt, P_FE2CL_NPC_ENTER); sock->sendPacket(pkt, P_FE2CL_NPC_ENTER);
} }
void Mob::enterIntoViewOf(CNSocket *sock) {
this->BaseNPC::enterIntoViewOf(sock);
playersInView++;
}
void Bus::enterIntoViewOf(CNSocket *sock) { void Bus::enterIntoViewOf(CNSocket *sock) {
INITSTRUCT(sP_FE2CL_TRANSPORTATION_ENTER, pkt); INITSTRUCT(sP_FE2CL_TRANSPORTATION_ENTER, pkt);
@ -102,11 +97,6 @@ void BaseNPC::disappearFromViewOf(CNSocket *sock) {
sock->sendPacket(pkt, P_FE2CL_NPC_EXIT); sock->sendPacket(pkt, P_FE2CL_NPC_EXIT);
} }
void Mob::disappearFromViewOf(CNSocket *sock) {
this->BaseNPC::disappearFromViewOf(sock);
playersInView--;
}
void Bus::disappearFromViewOf(CNSocket *sock) { void Bus::disappearFromViewOf(CNSocket *sock) {
INITSTRUCT(sP_FE2CL_TRANSPORTATION_EXIT, pkt); INITSTRUCT(sP_FE2CL_TRANSPORTATION_EXIT, pkt);
pkt.eTT = 3; pkt.eTT = 3;

View File

@ -95,9 +95,6 @@ struct Mob : public CombatNPC {
auto operator[](std::string s) { auto operator[](std::string s) {
return data[s]; return data[s];
} }
virtual void enterIntoViewOf(CNSocket *sock) override;
virtual void disappearFromViewOf(CNSocket *sock) override;
}; };
namespace MobAI { namespace MobAI {