From 48fb510b53b27db97eecb710515fddfdd1af5d63 Mon Sep 17 00:00:00 2001 From: dongresource Date: Thu, 8 Apr 2021 19:25:30 +0200 Subject: [PATCH] Fix playersInView miscount for dead mobs --- src/Chunking.cpp | 12 ++++++++++++ src/Entities.cpp | 10 ---------- src/MobAI.hpp | 3 --- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/Chunking.cpp b/src/Chunking.cpp index 3888d42..6dd3dfd 100644 --- a/src/Chunking.cpp +++ b/src/Chunking.cpp @@ -92,6 +92,12 @@ void Chunking::addEntityToChunks(std::set chnks, const EntityRef& ref) { if (ref.type == EntityType::PLAYER && other->isAlive()) { 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 chnks, const EntityRef& r if (ref.type == EntityType::PLAYER && other->isAlive()) { 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--; } } } diff --git a/src/Entities.cpp b/src/Entities.cpp index 9c286f1..c4881c3 100644 --- a/src/Entities.cpp +++ b/src/Entities.cpp @@ -48,11 +48,6 @@ void BaseNPC::enterIntoViewOf(CNSocket *sock) { sock->sendPacket(pkt, P_FE2CL_NPC_ENTER); } -void Mob::enterIntoViewOf(CNSocket *sock) { - this->BaseNPC::enterIntoViewOf(sock); - playersInView++; -} - void Bus::enterIntoViewOf(CNSocket *sock) { INITSTRUCT(sP_FE2CL_TRANSPORTATION_ENTER, pkt); @@ -102,11 +97,6 @@ void BaseNPC::disappearFromViewOf(CNSocket *sock) { sock->sendPacket(pkt, P_FE2CL_NPC_EXIT); } -void Mob::disappearFromViewOf(CNSocket *sock) { - this->BaseNPC::disappearFromViewOf(sock); - playersInView--; -} - void Bus::disappearFromViewOf(CNSocket *sock) { INITSTRUCT(sP_FE2CL_TRANSPORTATION_EXIT, pkt); pkt.eTT = 3; diff --git a/src/MobAI.hpp b/src/MobAI.hpp index b9798d3..9dc4452 100644 --- a/src/MobAI.hpp +++ b/src/MobAI.hpp @@ -95,9 +95,6 @@ struct Mob : public CombatNPC { auto operator[](std::string s) { return data[s]; } - - virtual void enterIntoViewOf(CNSocket *sock) override; - virtual void disappearFromViewOf(CNSocket *sock) override; }; namespace MobAI {