From dab536cb6a9e40978a70a54e9a0b0ff6c453f8ef Mon Sep 17 00:00:00 2001 From: Gent S Date: Sun, 22 Nov 2020 19:14:22 -0500 Subject: [PATCH] Grouped mobs adjustment --- src/MobManager.cpp | 20 +++++++++++++------- src/MobManager.hpp | 3 +++ src/TableData.cpp | 8 +++----- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/MobManager.cpp b/src/MobManager.cpp index 906766b..f1e82b1 100644 --- a/src/MobManager.cpp +++ b/src/MobManager.cpp @@ -456,16 +456,18 @@ void MobManager::deadStep(Mob *mob, time_t currTime) { Mob* leaderMob = Mobs[mob->groupLeader]; mob->appearanceData.iX = leaderMob->appearanceData.iX + mob->offsetX; mob->appearanceData.iY = leaderMob->appearanceData.iY + mob->offsetY; + mob->appearanceData.iZ = leaderMob->appearanceData.iZ; } else { std::cout << "[WARN] deadStep: mob cannot find it's leader!" << std::endl; mob->appearanceData.iX = mob->spawnX; mob->appearanceData.iY = mob->spawnY; + mob->appearanceData.iZ = mob->spawnZ; } } else { mob->appearanceData.iX = mob->spawnX; mob->appearanceData.iY = mob->spawnY; + mob->appearanceData.iZ = mob->spawnZ; } - mob->appearanceData.iZ = mob->spawnZ; INITSTRUCT(sP_FE2CL_NPC_NEW, pkt); @@ -566,8 +568,8 @@ void MobManager::combatStep(Mob *mob, time_t currTime) { int targetX = mob->target->plr->x; int targetY = mob->target->plr->y; if (mob->groupLeader != 0) { - targetX += mob->offsetX*distance/(mob->sightRange+1); - targetY += mob->offsetY*distance/(mob->sightRange+1); + targetX += mob->offsetX*distance/(mob->idleRange + 1); + targetY += mob->offsetY*distance/(mob->idleRange + 1); } auto targ = lerp(mob->appearanceData.iX, mob->appearanceData.iY, targetX, targetY, std::min(distance-(int)mob->data["m_iAtkRange"]+1, speed*2/5)); @@ -625,17 +627,17 @@ void MobManager::roamingStep(Mob *mob, time_t currTime) { if (mob->staticPath) return; - if (mob->nextMovement != 0 && currTime < mob->nextMovement) + if (mob->groupLeader != 0 && mob->groupLeader != mob->appearanceData.iNPC_ID) // don't roam by yourself without group leader return; - incNextMovement(mob, currTime); + /* * mob->nextMovement is also updated whenever the path queue is traversed in * TransportManager::stepNPCPathing() (which ticks at a higher frequency than nextMovement), * so we don't have to check if there's already entries in the queue since we know there won't be. */ - - if (mob->groupLeader != 0 && mob->groupLeader != mob->appearanceData.iNPC_ID) // don't roam by yourself without group leader + if (mob->nextMovement != 0 && currTime < mob->nextMovement) return; + incNextMovement(mob, currTime); int xStart = mob->spawnX - mob->idleRange/2; int yStart = mob->spawnY - mob->idleRange/2; @@ -644,6 +646,10 @@ void MobManager::roamingStep(Mob *mob, time_t currTime) { int farX, farY; int distance; // for short walk detection + /* + * We don't want the mob to just take one step and stop, so we make sure + * it has walked a half-decent distance. + */ do { farX = xStart + rand() % mob->idleRange; farY = yStart + rand() % mob->idleRange; diff --git a/src/MobManager.hpp b/src/MobManager.hpp index e3145bf..744bc8d 100644 --- a/src/MobManager.hpp +++ b/src/MobManager.hpp @@ -76,6 +76,9 @@ struct Mob : public BaseNPC { roamY = spawnY = appearanceData.iY; roamZ = spawnZ = appearanceData.iZ; + offsetX = 0; + offsetY = 0; + appearanceData.iConditionBitFlag = 0; // NOTE: there appear to be discrepancies in the dump diff --git a/src/TableData.cpp b/src/TableData.cpp index a492804..f6367f3 100644 --- a/src/TableData.cpp +++ b/src/TableData.cpp @@ -216,8 +216,8 @@ void TableData::init() { NPCManager::updateNPCPosition(nextId, npc["iX"], npc["iY"], npc["iZ"], instanceID, npc["iAngle"]); // handling groups - if (npc.find("iOffsetX") != npc.end() && MobManager::Mobs.find(nextId) != MobManager::Mobs.end()) { - Mob* currNpc = MobManager::Mobs[nextId]; + if (npc.find("iOffsetX") != npc.end()) { + Mob* currNpc = (Mob*)tmp; if (leaderMob == -1) { if (MobManager::Mobs.find(nextId-1) != MobManager::Mobs.end()) { @@ -231,7 +231,6 @@ void TableData::init() { } else { if (MobManager::Mobs.find(leaderMob) != MobManager::Mobs.end()) { Mob* leadNpc = MobManager::Mobs[leaderMob]; - leaderMob = leaderMob; leadNpc->groupMember[leaderMobFollowers] = nextId; leaderMobFollowers++; currNpc->groupLeader = leaderMob; @@ -240,7 +239,7 @@ void TableData::init() { currNpc->offsetX = (int)npc["iOffsetX"]; currNpc->offsetY = npc.find("iOffsetY") == npc.end() ? 0 : (int)npc["iOffsetY"]; - std::cout << "[INFO] Added group NPC " << nextId << " to ID " << currNpc->groupLeader << std::endl; + std::cout << "[INFO] Added group NPC " << nextId << " to ID " << currNpc->groupLeader << std::endl; // TODO: get rid of this after testing } else { leaderMob = -1; leaderMobFollowers = 0; @@ -674,7 +673,6 @@ void TableData::loadGruntwork(int32_t *nextId) { } else { if (MobManager::Mobs.find(leaderMob) != MobManager::Mobs.end()) { Mob* leadNpc = MobManager::Mobs[leaderMob]; - leaderMob = leaderMob; leadNpc->groupMember[leaderMobFollowers] = id; leaderMobFollowers++; currNpc->groupLeader = leaderMob;