mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-22 21:40:05 +00:00
(WIP) Transitions + hook definitions + onRetreat hook implementation
This commit is contained in:
parent
c32e5b2d5e
commit
69a478b777
@ -449,13 +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->target = nullptr;
|
mob->transition(AIState::RETREAT);
|
||||||
mob->state = AIState::RETREAT;
|
|
||||||
if (!MobAI::aggroCheck(mob, getTime())) {
|
|
||||||
MobAI::clearDebuff(mob);
|
|
||||||
if (mob->groupLeader != 0)
|
|
||||||
MobAI::groupRetreat(mob);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -529,13 +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->target = nullptr;
|
mob->transition(AIState::RETREAT);
|
||||||
mob->state = AIState::RETREAT;
|
|
||||||
if (!MobAI::aggroCheck(mob, getTime())) {
|
|
||||||
MobAI::clearDebuff(mob);
|
|
||||||
if (mob->groupLeader != 0)
|
|
||||||
MobAI::groupRetreat(mob);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -587,13 +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->target = nullptr;
|
mob->transition(AIState::RETREAT);
|
||||||
mob->state = AIState::RETREAT;
|
|
||||||
if (!MobAI::aggroCheck(mob, getTime())) {
|
|
||||||
MobAI::clearDebuff(mob);
|
|
||||||
if (mob->groupLeader != 0)
|
|
||||||
MobAI::groupRetreat(mob);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -128,6 +128,27 @@ void CombatNPC::step(time_t currTime) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CombatNPC::transition(AIState newState) {
|
||||||
|
state = newState;
|
||||||
|
switch (newState) {
|
||||||
|
case AIState::INACTIVE:
|
||||||
|
onInactive();
|
||||||
|
break;
|
||||||
|
case AIState::ROAMING:
|
||||||
|
onRoamStart();
|
||||||
|
break;
|
||||||
|
case AIState::COMBAT:
|
||||||
|
onCombatStart();
|
||||||
|
break;
|
||||||
|
case AIState::RETREAT:
|
||||||
|
onRetreat();
|
||||||
|
break;
|
||||||
|
case AIState::DEAD:
|
||||||
|
onDeath();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static std::pair<int,int> getDamage(int attackPower, int defensePower, bool shouldCrit,
|
static std::pair<int,int> getDamage(int attackPower, int defensePower, bool shouldCrit,
|
||||||
bool batteryBoost, int attackerStyle,
|
bool batteryBoost, int attackerStyle,
|
||||||
int defenderStyle, int difficulty) {
|
int defenderStyle, int difficulty) {
|
||||||
@ -291,13 +312,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->target = nullptr;
|
mob->transition(AIState::RETREAT);
|
||||||
mob->state = AIState::RETREAT;
|
|
||||||
if (!MobAI::aggroCheck(mob, currTime)) {
|
|
||||||
MobAI::clearDebuff(mob);
|
|
||||||
if (mob->groupLeader != 0)
|
|
||||||
MobAI::groupRetreat(mob);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,10 +152,17 @@ struct CombatNPC : public BaseNPC, public ICombatant {
|
|||||||
virtual int32_t getID() override;
|
virtual int32_t getID() override;
|
||||||
|
|
||||||
virtual void step(time_t currTime) override;
|
virtual void step(time_t currTime) override;
|
||||||
virtual void roamingStep(time_t currTime) {} // no-op by default
|
virtual void roamingStep(time_t currTime) {} // no-ops by default
|
||||||
virtual void combatStep(time_t currTime) {}
|
virtual void combatStep(time_t currTime) {}
|
||||||
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 onInactive() {} // no-ops by default
|
||||||
|
virtual void onRoamStart() {}
|
||||||
|
virtual void onCombatStart() {}
|
||||||
|
virtual void onRetreat() {}
|
||||||
|
virtual void onDeath() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Mob is in MobAI.hpp, Player is in Player.hpp
|
// Mob is in MobAI.hpp, Player is in Player.hpp
|
||||||
|
@ -266,13 +266,8 @@ static void dealCorruption(Mob *mob, std::vector<int> targetData, int skillID, i
|
|||||||
respdata[i].iConditionBitFlag = plr->iConditionBitFlag;
|
respdata[i].iConditionBitFlag = plr->iConditionBitFlag;
|
||||||
|
|
||||||
if (plr->HP <= 0) {
|
if (plr->HP <= 0) {
|
||||||
mob->target = nullptr;
|
if (!MobAI::aggroCheck(mob, getTime()))
|
||||||
mob->state = AIState::RETREAT;
|
mob->transition(AIState::RETREAT);
|
||||||
if (!aggroCheck(mob, getTime())) {
|
|
||||||
clearDebuff(mob);
|
|
||||||
if (mob->groupLeader != 0)
|
|
||||||
groupRetreat(mob);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -500,13 +495,8 @@ 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()) {
|
||||||
target = nullptr;
|
if (!MobAI::aggroCheck(this, getTime()))
|
||||||
state = AIState::RETREAT;
|
transition(AIState::RETREAT);
|
||||||
if (!aggroCheck(this, currTime)) {
|
|
||||||
clearDebuff(this);
|
|
||||||
if (groupLeader != 0)
|
|
||||||
groupRetreat(this);
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -515,13 +505,8 @@ void Mob::combatStep(time_t currTime) {
|
|||||||
// lose aggro if the player became invulnerable or died
|
// lose aggro if the player became invulnerable or died
|
||||||
if (plr->HP <= 0
|
if (plr->HP <= 0
|
||||||
|| (plr->iSpecialState & CN_SPECIAL_STATE_FLAG__INVULNERABLE)) {
|
|| (plr->iSpecialState & CN_SPECIAL_STATE_FLAG__INVULNERABLE)) {
|
||||||
target = nullptr;
|
if (!MobAI::aggroCheck(this, getTime()))
|
||||||
state = AIState::RETREAT;
|
transition(AIState::RETREAT);
|
||||||
if (!aggroCheck(this, currTime)) {
|
|
||||||
clearDebuff(this);
|
|
||||||
if (groupLeader != 0)
|
|
||||||
groupRetreat(this);
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -626,11 +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"]) {
|
||||||
target = nullptr;
|
transition(AIState::RETREAT);
|
||||||
state = AIState::RETREAT;
|
|
||||||
clearDebuff(this);
|
|
||||||
if (groupLeader != 0)
|
|
||||||
groupRetreat(this);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -773,3 +754,26 @@ void Mob::retreatStep(time_t currTime) {
|
|||||||
clearDebuff(this);
|
clearDebuff(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Mob::onInactive() {
|
||||||
|
// stub
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mob::onRoamStart() {
|
||||||
|
// stub
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mob::onCombatStart() {
|
||||||
|
// stub
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mob::onRetreat() {
|
||||||
|
target = nullptr;
|
||||||
|
MobAI::clearDebuff(this);
|
||||||
|
if (groupLeader != 0)
|
||||||
|
MobAI::groupRetreat(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mob::onDeath() {
|
||||||
|
// stub
|
||||||
|
}
|
||||||
|
@ -76,6 +76,12 @@ struct Mob : public CombatNPC {
|
|||||||
virtual void retreatStep(time_t currTime) override;
|
virtual void retreatStep(time_t currTime) override;
|
||||||
virtual void deadStep(time_t currTime) override;
|
virtual void deadStep(time_t currTime) override;
|
||||||
|
|
||||||
|
virtual void onInactive() override;
|
||||||
|
virtual void onRoamStart() override;
|
||||||
|
virtual void onCombatStart() override;
|
||||||
|
virtual void onRetreat() override;
|
||||||
|
virtual void onDeath() override;
|
||||||
|
|
||||||
auto operator[](std::string s) {
|
auto operator[](std::string s) {
|
||||||
return data[s];
|
return data[s];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user