mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-17 03:20:06 +00:00
Move mob aggro logic into takeDamage
override
God that feels good
This commit is contained in:
parent
4f49bcea87
commit
828f49cd62
@ -44,41 +44,8 @@ void Player::step(time_t currTime) {
|
||||
|
||||
int CombatNPC::takeDamage(EntityRef src, int amt) {
|
||||
|
||||
/* REFACTOR: all of this logic is strongly coupled to mobs.
|
||||
* come back to this when more of it is moved to CombatNPC.
|
||||
* remove this cast when done */
|
||||
Mob* mob = (Mob*)this;
|
||||
|
||||
// cannot kill mobs multiple times; cannot harm retreating mobs
|
||||
if (mob->state != AIState::ROAMING && mob->state != AIState::COMBAT) {
|
||||
return 0; // no damage
|
||||
}
|
||||
|
||||
if (mob->skillStyle >= 0)
|
||||
return 0; // don't hurt a mob casting corruption
|
||||
|
||||
if (mob->state == AIState::ROAMING) {
|
||||
assert(mob->target == nullptr && src.kind == EntityKind::PLAYER); // players only for now
|
||||
mob->transition(AIState::COMBAT, src);
|
||||
|
||||
if (mob->groupLeader != 0)
|
||||
MobAI::followToCombat(mob);
|
||||
}
|
||||
|
||||
hp -= amt;
|
||||
|
||||
// wake up sleeping monster
|
||||
if (mob->cbf & CSB_BIT_MEZ) {
|
||||
mob->cbf &= ~CSB_BIT_MEZ;
|
||||
|
||||
INITSTRUCT(sP_FE2CL_CHAR_TIME_BUFF_TIME_OUT, pkt1);
|
||||
pkt1.eCT = 2;
|
||||
pkt1.iID = mob->id;
|
||||
pkt1.iConditionBitFlag = mob->cbf;
|
||||
NPCManager::sendToViewable(mob, &pkt1, P_FE2CL_CHAR_TIME_BUFF_TIME_OUT, sizeof(sP_FE2CL_CHAR_TIME_BUFF_TIME_OUT));
|
||||
}
|
||||
|
||||
if (mob->hp <= 0)
|
||||
if (hp <= 0)
|
||||
transition(AIState::DEAD, src);
|
||||
|
||||
return amt;
|
||||
|
@ -16,6 +16,52 @@ using namespace MobAI;
|
||||
|
||||
bool MobAI::simulateMobs = settings::SIMULATEMOBS;
|
||||
|
||||
void Mob::step(time_t currTime) {
|
||||
if (playersInView < 0)
|
||||
std::cout << "[WARN] Weird playerview value " << playersInView << std::endl;
|
||||
|
||||
// skip movement and combat if disabled or not in view
|
||||
if ((!MobAI::simulateMobs || playersInView == 0) && state != AIState::DEAD
|
||||
&& state != AIState::RETREAT)
|
||||
return;
|
||||
|
||||
// call superclass step
|
||||
CombatNPC::step(currTime);
|
||||
}
|
||||
|
||||
int Mob::takeDamage(EntityRef src, int amt) {
|
||||
|
||||
// cannot kill mobs multiple times; cannot harm retreating mobs
|
||||
if (state != AIState::ROAMING && state != AIState::COMBAT) {
|
||||
return 0; // no damage
|
||||
}
|
||||
|
||||
if (skillStyle >= 0)
|
||||
return 0; // don't hurt a mob casting corruption
|
||||
|
||||
if (state == AIState::ROAMING) {
|
||||
assert(target == nullptr && src.kind == EntityKind::PLAYER); // TODO: players only for now
|
||||
transition(AIState::COMBAT, src);
|
||||
|
||||
if (groupLeader != 0)
|
||||
MobAI::followToCombat(this);
|
||||
}
|
||||
|
||||
// wake up sleeping monster
|
||||
if (cbf & CSB_BIT_MEZ) {
|
||||
cbf &= ~CSB_BIT_MEZ;
|
||||
|
||||
INITSTRUCT(sP_FE2CL_CHAR_TIME_BUFF_TIME_OUT, pkt1);
|
||||
pkt1.eCT = 2;
|
||||
pkt1.iID = id;
|
||||
pkt1.iConditionBitFlag = cbf;
|
||||
NPCManager::sendToViewable(this, &pkt1, P_FE2CL_CHAR_TIME_BUFF_TIME_OUT, sizeof(sP_FE2CL_CHAR_TIME_BUFF_TIME_OUT));
|
||||
}
|
||||
|
||||
// call superclass takeDamage
|
||||
return CombatNPC::takeDamage(src, amt);
|
||||
}
|
||||
|
||||
/*
|
||||
* Dynamic lerp; distinct from Transport::lerp(). This one doesn't care about height and
|
||||
* only returns the first step, since the rest will need to be recalculated anyway if chasing player.
|
||||
@ -423,19 +469,6 @@ void MobAI::incNextMovement(Mob* mob, time_t currTime) {
|
||||
mob->nextMovement = currTime + delay / 2 + Rand::rand(delay / 2);
|
||||
}
|
||||
|
||||
void Mob::step(time_t currTime) {
|
||||
if (playersInView < 0)
|
||||
std::cout << "[WARN] Weird playerview value " << playersInView << std::endl;
|
||||
|
||||
// skip movement and combat if disabled or not in view
|
||||
if ((!MobAI::simulateMobs || playersInView == 0) && state != AIState::DEAD
|
||||
&& state != AIState::RETREAT)
|
||||
return;
|
||||
|
||||
// call superclass step
|
||||
CombatNPC::step(currTime);
|
||||
}
|
||||
|
||||
void MobAI::deadStep(CombatNPC* npc, time_t currTime) {
|
||||
Mob* self = (Mob*)npc;
|
||||
|
||||
|
@ -96,6 +96,7 @@ struct Mob : public CombatNPC {
|
||||
|
||||
~Mob() {}
|
||||
|
||||
virtual int takeDamage(EntityRef src, int amt) override;
|
||||
virtual void step(time_t currTime) override;
|
||||
|
||||
auto operator[](std::string s) {
|
||||
|
Loading…
Reference in New Issue
Block a user