From e23af08838544586260e6684fc60db0773bf2784 Mon Sep 17 00:00:00 2001 From: gsemaj Date: Tue, 12 Apr 2022 23:44:12 -0400 Subject: [PATCH] (WIP) Add src param to transition + certain hooks Should all hooks have src? I think not --- src/Abilities.cpp | 6 +++--- src/Combat.cpp | 8 ++++---- src/Entities.hpp | 6 +++--- src/MobAI.cpp | 12 ++++++------ src/MobAI.hpp | 4 ++-- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Abilities.cpp b/src/Abilities.cpp index 988947b..f7730e3 100644 --- a/src/Abilities.cpp +++ b/src/Abilities.cpp @@ -449,7 +449,7 @@ bool doDamageNDebuff(Mob* mob, sSkillResult_Damage_N_Debuff* respdata, int i, in respdata[i].iConditionBitFlag = plr->iConditionBitFlag; if (plr->HP <= 0) { - mob->transition(AIState::RETREAT); + mob->transition(AIState::RETREAT, mob->target); } return true; @@ -523,7 +523,7 @@ bool doDamage(Mob* mob, sSkillResult_Damage* respdata, int i, int32_t targetID, respdata[i].iHP = plr->HP -= damage; if (plr->HP <= 0) { - mob->transition(AIState::RETREAT); + mob->transition(AIState::RETREAT, mob->target); } return true; @@ -575,7 +575,7 @@ bool doLeech(Mob* mob, sSkillResult_Heal_HP* healdata, int i, int32_t targetID, damagedata->iHP = plr->HP -= damage; if (plr->HP <= 0) { - mob->transition(AIState::RETREAT); + mob->transition(AIState::RETREAT, mob->target); } return true; diff --git a/src/Combat.cpp b/src/Combat.cpp index 9588dde..9109a87 100644 --- a/src/Combat.cpp +++ b/src/Combat.cpp @@ -128,7 +128,7 @@ void CombatNPC::step(time_t currTime) { } } -void CombatNPC::transition(AIState newState) { +void CombatNPC::transition(AIState newState, EntityRef src) { state = newState; switch (newState) { case AIState::INACTIVE: @@ -138,13 +138,13 @@ void CombatNPC::transition(AIState newState) { onRoamStart(); break; case AIState::COMBAT: - onCombatStart(); + onCombatStart(src); break; case AIState::RETREAT: onRetreat(); break; case AIState::DEAD: - onDeath(); + onDeath(src); break; } } @@ -312,7 +312,7 @@ void Combat::npcAttackPc(Mob *mob, time_t currTime) { PlayerManager::sendToViewable(mob->target, respbuf, P_FE2CL_NPC_ATTACK_PCs); if (plr->HP <= 0) { - mob->transition(AIState::RETREAT); + mob->transition(AIState::RETREAT, mob->target); } } diff --git a/src/Entities.hpp b/src/Entities.hpp index cbfeb32..638b7d8 100644 --- a/src/Entities.hpp +++ b/src/Entities.hpp @@ -157,12 +157,12 @@ struct CombatNPC : public BaseNPC, public ICombatant { virtual void retreatStep(time_t currTime) {} virtual void deadStep(time_t currTime) {} - virtual void transition(AIState newState); + virtual void transition(AIState newState, EntityRef src); virtual void onInactive() {} // no-ops by default virtual void onRoamStart() {} - virtual void onCombatStart() {} + virtual void onCombatStart(EntityRef src) {} virtual void onRetreat() {} - virtual void onDeath() {} + virtual void onDeath(EntityRef src) {} }; // Mob is in MobAI.hpp, Player is in Player.hpp diff --git a/src/MobAI.cpp b/src/MobAI.cpp index 0e9675b..ffc8bb2 100644 --- a/src/MobAI.cpp +++ b/src/MobAI.cpp @@ -267,7 +267,7 @@ static void dealCorruption(Mob *mob, std::vector targetData, int skillID, i if (plr->HP <= 0) { if (!MobAI::aggroCheck(mob, getTime())) - mob->transition(AIState::RETREAT); + mob->transition(AIState::RETREAT, mob->target); } } @@ -496,7 +496,7 @@ void Mob::combatStep(time_t currTime) { // lose aggro if the player lost connection if (PlayerManager::players.find(target) == PlayerManager::players.end()) { if (!MobAI::aggroCheck(this, getTime())) - transition(AIState::RETREAT); + transition(AIState::RETREAT, target); return; } @@ -506,7 +506,7 @@ void Mob::combatStep(time_t currTime) { if (plr->HP <= 0 || (plr->iSpecialState & CN_SPECIAL_STATE_FLAG__INVULNERABLE)) { if (!MobAI::aggroCheck(this, getTime())) - transition(AIState::RETREAT); + transition(AIState::RETREAT, target); return; } @@ -611,7 +611,7 @@ void Mob::combatStep(time_t currTime) { int xyDistance = hypot(plr->x - roamX, plr->y - roamY); distance = hypot(xyDistance, plr->z - roamZ); if (distance >= data["m_iCombatRange"]) { - transition(AIState::RETREAT); + transition(AIState::RETREAT, target); } } @@ -763,7 +763,7 @@ void Mob::onRoamStart() { // stub } -void Mob::onCombatStart() { +void Mob::onCombatStart(EntityRef src) { // stub } @@ -774,6 +774,6 @@ void Mob::onRetreat() { MobAI::groupRetreat(this); } -void Mob::onDeath() { +void Mob::onDeath(EntityRef src) { // stub } diff --git a/src/MobAI.hpp b/src/MobAI.hpp index 86721e6..7ad9353 100644 --- a/src/MobAI.hpp +++ b/src/MobAI.hpp @@ -78,9 +78,9 @@ struct Mob : public CombatNPC { virtual void onInactive() override; virtual void onRoamStart() override; - virtual void onCombatStart() override; + virtual void onCombatStart(EntityRef src) override; virtual void onRetreat() override; - virtual void onDeath() override; + virtual void onDeath(EntityRef src) override; auto operator[](std::string s) { return data[s];