(WIP) Add src param to transition + certain hooks

Should all hooks have src? I think not
This commit is contained in:
gsemaj 2022-04-12 23:44:12 -04:00
parent 0b8b92b7f6
commit 589c5a8732
5 changed files with 18 additions and 18 deletions

View File

@ -449,7 +449,7 @@ bool doDamageNDebuff(Mob* mob, sSkillResult_Damage_N_Debuff* respdata, int i, in
respdata[i].iConditionBitFlag = plr->iConditionBitFlag; respdata[i].iConditionBitFlag = plr->iConditionBitFlag;
if (plr->HP <= 0) { if (plr->HP <= 0) {
mob->transition(AIState::RETREAT); mob->transition(AIState::RETREAT, mob->target);
} }
return true; return true;
@ -523,7 +523,7 @@ bool doDamage(Mob* mob, sSkillResult_Damage* respdata, int i, int32_t targetID,
respdata[i].iHP = plr->HP -= damage; respdata[i].iHP = plr->HP -= damage;
if (plr->HP <= 0) { if (plr->HP <= 0) {
mob->transition(AIState::RETREAT); mob->transition(AIState::RETREAT, mob->target);
} }
return true; return true;
@ -575,7 +575,7 @@ bool doLeech(Mob* mob, sSkillResult_Heal_HP* healdata, int i, int32_t targetID,
damagedata->iHP = plr->HP -= damage; damagedata->iHP = plr->HP -= damage;
if (plr->HP <= 0) { if (plr->HP <= 0) {
mob->transition(AIState::RETREAT); mob->transition(AIState::RETREAT, mob->target);
} }
return true; return true;

View File

@ -128,7 +128,7 @@ void CombatNPC::step(time_t currTime) {
} }
} }
void CombatNPC::transition(AIState newState) { void CombatNPC::transition(AIState newState, EntityRef src) {
state = newState; state = newState;
switch (newState) { switch (newState) {
case AIState::INACTIVE: case AIState::INACTIVE:
@ -138,13 +138,13 @@ void CombatNPC::transition(AIState newState) {
onRoamStart(); onRoamStart();
break; break;
case AIState::COMBAT: case AIState::COMBAT:
onCombatStart(); onCombatStart(src);
break; break;
case AIState::RETREAT: case AIState::RETREAT:
onRetreat(); onRetreat();
break; break;
case AIState::DEAD: case AIState::DEAD:
onDeath(); onDeath(src);
break; break;
} }
} }
@ -303,7 +303,7 @@ void Combat::npcAttackPc(Mob *mob, time_t currTime) {
PlayerManager::sendToViewable(mob->target, respbuf, P_FE2CL_NPC_ATTACK_PCs); PlayerManager::sendToViewable(mob->target, respbuf, P_FE2CL_NPC_ATTACK_PCs);
if (plr->HP <= 0) { if (plr->HP <= 0) {
mob->transition(AIState::RETREAT); mob->transition(AIState::RETREAT, mob->target);
} }
} }

View File

@ -157,12 +157,12 @@ struct CombatNPC : public BaseNPC, public ICombatant {
virtual void retreatStep(time_t currTime) {} virtual void retreatStep(time_t currTime) {}
virtual void deadStep(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 onInactive() {} // no-ops by default
virtual void onRoamStart() {} virtual void onRoamStart() {}
virtual void onCombatStart() {} virtual void onCombatStart(EntityRef src) {}
virtual void onRetreat() {} virtual void onRetreat() {}
virtual void onDeath() {} virtual void onDeath(EntityRef src) {}
}; };
// Mob is in MobAI.hpp, Player is in Player.hpp // Mob is in MobAI.hpp, Player is in Player.hpp

View File

@ -267,7 +267,7 @@ static void dealCorruption(Mob *mob, std::vector<int> targetData, int skillID, i
if (plr->HP <= 0) { if (plr->HP <= 0) {
if (!MobAI::aggroCheck(mob, getTime())) 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 // lose aggro if the player lost connection
if (PlayerManager::players.find(target) == PlayerManager::players.end()) { if (PlayerManager::players.find(target) == PlayerManager::players.end()) {
if (!MobAI::aggroCheck(this, getTime())) if (!MobAI::aggroCheck(this, getTime()))
transition(AIState::RETREAT); transition(AIState::RETREAT, target);
return; return;
} }
@ -506,7 +506,7 @@ void Mob::combatStep(time_t currTime) {
if (plr->HP <= 0 if (plr->HP <= 0
|| (plr->iSpecialState & CN_SPECIAL_STATE_FLAG__INVULNERABLE)) { || (plr->iSpecialState & CN_SPECIAL_STATE_FLAG__INVULNERABLE)) {
if (!MobAI::aggroCheck(this, getTime())) if (!MobAI::aggroCheck(this, getTime()))
transition(AIState::RETREAT); transition(AIState::RETREAT, target);
return; return;
} }
@ -611,7 +611,7 @@ void Mob::combatStep(time_t currTime) {
int xyDistance = hypot(plr->x - roamX, plr->y - roamY); int xyDistance = hypot(plr->x - roamX, plr->y - roamY);
distance = hypot(xyDistance, plr->z - roamZ); distance = hypot(xyDistance, plr->z - roamZ);
if (distance >= data["m_iCombatRange"]) { if (distance >= data["m_iCombatRange"]) {
transition(AIState::RETREAT); transition(AIState::RETREAT, target);
} }
} }
@ -763,7 +763,7 @@ void Mob::onRoamStart() {
// stub // stub
} }
void Mob::onCombatStart() { void Mob::onCombatStart(EntityRef src) {
// stub // stub
} }
@ -774,6 +774,6 @@ void Mob::onRetreat() {
MobAI::groupRetreat(this); MobAI::groupRetreat(this);
} }
void Mob::onDeath() { void Mob::onDeath(EntityRef src) {
// stub // stub
} }

View File

@ -78,9 +78,9 @@ struct Mob : public CombatNPC {
virtual void onInactive() override; virtual void onInactive() override;
virtual void onRoamStart() override; virtual void onRoamStart() override;
virtual void onCombatStart() override; virtual void onCombatStart(EntityRef src) override;
virtual void onRetreat() override; virtual void onRetreat() override;
virtual void onDeath() override; virtual void onDeath(EntityRef src) override;
auto operator[](std::string s) { auto operator[](std::string s) {
return data[s]; return data[s];