diff --git a/src/MobManager.cpp b/src/MobManager.cpp index ec267ae..a97d455 100644 --- a/src/MobManager.cpp +++ b/src/MobManager.cpp @@ -147,8 +147,11 @@ void MobManager::npcAttackPc(Mob *mob, time_t currTime) { if (plr->HP <= 0) { mob->target = nullptr; mob->state = MobState::RETREAT; - if (!aggroCheck(mob, currTime)) + if (!aggroCheck(mob, currTime)) { clearDebuff(mob); + if (mob->groupLeader != 0) + groupRetreat(mob); + } } } @@ -513,8 +516,11 @@ void MobManager::combatStep(Mob *mob, time_t currTime) { if (PlayerManager::players.find(mob->target) == PlayerManager::players.end()) { mob->target = nullptr; mob->state = MobState::RETREAT; - if (!aggroCheck(mob, currTime)) + if (!aggroCheck(mob, currTime)) { clearDebuff(mob); + if (mob->groupLeader != 0) + groupRetreat(mob); + } return; } @@ -525,8 +531,11 @@ void MobManager::combatStep(Mob *mob, time_t currTime) { || (plr->iSpecialState & CN_SPECIAL_STATE_FLAG__INVULNERABLE)) { mob->target = nullptr; mob->state = MobState::RETREAT; - if (!aggroCheck(mob, currTime)) + if (!aggroCheck(mob, currTime)) { clearDebuff(mob); + if (mob->groupLeader != 0) + groupRetreat(mob); + } return; } @@ -635,6 +644,8 @@ void MobManager::combatStep(Mob *mob, time_t currTime) { mob->target = nullptr; mob->state = MobState::RETREAT; clearDebuff(mob); + if (mob->groupLeader != 0) + groupRetreat(mob); } } @@ -1470,6 +1481,31 @@ void MobManager::followToCombat(Mob *mob) { } } +void MobManager::groupRetreat(Mob *mob) { + if (Mobs.find(mob->groupLeader) == Mobs.end()) + return; + + Mob* leadMob = Mobs[mob->groupLeader]; + for (int i = 0; i < 4; i++) { + if (leadMob->groupMember[i] == 0) + break; + + if (Mobs.find(leadMob->groupMember[i]) == Mobs.end()) { + std::cout << "[WARN] roamingStep: leader can't find a group member!" << std::endl; + continue; + } + Mob* followerMob = Mobs[leadMob->groupMember[i]]; + + followerMob->target = nullptr; + followerMob->state = MobState::RETREAT; + clearDebuff(followerMob); + } + + leadMob->target = nullptr; + leadMob->state = MobState::RETREAT; + clearDebuff(leadMob); +} + void MobManager::useAbilities(Mob *mob, time_t currTime) { /* * targetData approach @@ -1670,8 +1706,11 @@ void MobManager::dealCorruption(Mob *mob, std::vector targetData, int skill if (plr->HP <= 0) { mob->target = nullptr; mob->state = MobState::RETREAT; - if (!aggroCheck(mob, getTime())) + if (!aggroCheck(mob, getTime())) { clearDebuff(mob); + if (mob->groupLeader != 0) + groupRetreat(mob); + } } } @@ -1726,8 +1765,11 @@ bool doDamageNDebuff(Mob *mob, sSkillResult_Damage_N_Debuff *respdata, int i, in if (plr->HP <= 0) { mob->target = nullptr; mob->state = MobState::RETREAT; - if (!aggroCheck(mob, getTime())) + if (!aggroCheck(mob, getTime())) { clearDebuff(mob); + if (mob->groupLeader != 0) + groupRetreat(mob); + } } return true; @@ -1776,8 +1818,11 @@ bool doDamage(Mob *mob, sSkillResult_Damage *respdata, int i, int32_t targetID, if (plr->HP <= 0) { mob->target = nullptr; mob->state = MobState::RETREAT; - if (!aggroCheck(mob, getTime())) + if (!aggroCheck(mob, getTime())) { clearDebuff(mob); + if (mob->groupLeader != 0) + groupRetreat(mob); + } } return true; @@ -1830,8 +1875,11 @@ bool doLeech(Mob *mob, sSkillResult_Heal_HP *healdata, int i, int32_t targetID, if (plr->HP <= 0) { mob->target = nullptr; mob->state = MobState::RETREAT; - if (!aggroCheck(mob, getTime())) + if (!aggroCheck(mob, getTime())) { clearDebuff(mob); + if (mob->groupLeader != 0) + groupRetreat(mob); + } } return true; diff --git a/src/MobManager.hpp b/src/MobManager.hpp index 01dcbaf..c1fd18d 100644 --- a/src/MobManager.hpp +++ b/src/MobManager.hpp @@ -187,6 +187,7 @@ namespace MobManager { int8_t addBullet(Player* plr, bool isGrenade); void followToCombat(Mob *mob); + void groupRetreat(Mob *mob); void useAbilities(Mob *mob, time_t currTime); void dealCorruption(Mob *mob, std::vector targetData, int skillID, int style); }