(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 69a478b777
commit 45742e90a2
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;
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;

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;
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);
}
}

View File

@ -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

View File

@ -267,7 +267,7 @@ static void dealCorruption(Mob *mob, std::vector<int> 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
}

View File

@ -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];