mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-22 13:16:23 +00:00
fix(Core/Creatures): Critters should start fleeing upon entering comb… (#14253)
This commit is contained in:
@@ -69,30 +69,30 @@ void PossessedAI::KilledUnit(Unit* /*victim*/)
|
||||
// victim->RemoveDynamicFlag(UNIT_DYNFLAG_LOOTABLE);
|
||||
}
|
||||
|
||||
void CritterAI::DamageTaken(Unit*, uint32&, DamageEffectType, SpellSchoolMask)
|
||||
void CritterAI::EnterCombat(Unit* who)
|
||||
{
|
||||
if (!me->HasUnitState(UNIT_STATE_FLEEING))
|
||||
me->SetControlled(true, UNIT_STATE_FLEEING);
|
||||
{
|
||||
me->SetControlled(true, UNIT_STATE_FLEEING, who);
|
||||
}
|
||||
}
|
||||
|
||||
_combatTimer = 1;
|
||||
void CritterAI::MovementInform(uint32 type, uint32 /*id*/)
|
||||
{
|
||||
if (type == TIMED_FLEEING_MOTION_TYPE)
|
||||
{
|
||||
EnterEvadeMode(EVADE_REASON_OTHER);
|
||||
}
|
||||
}
|
||||
|
||||
void CritterAI::EnterEvadeMode(EvadeReason why)
|
||||
{
|
||||
if (me->HasUnitState(UNIT_STATE_FLEEING))
|
||||
me->SetControlled(false, UNIT_STATE_FLEEING);
|
||||
CreatureAI::EnterEvadeMode(why);
|
||||
_combatTimer = 0;
|
||||
}
|
||||
|
||||
void CritterAI::UpdateAI(uint32 diff)
|
||||
{
|
||||
if (me->IsInCombat())
|
||||
{
|
||||
_combatTimer += diff;
|
||||
if (_combatTimer >= 5000)
|
||||
EnterEvadeMode(EVADE_REASON_OTHER);
|
||||
me->SetControlled(false, UNIT_STATE_FLEEING);
|
||||
}
|
||||
|
||||
CreatureAI::EnterEvadeMode(why);
|
||||
}
|
||||
|
||||
int32 CritterAI::Permissible(Creature const* creature)
|
||||
|
||||
@@ -66,16 +66,14 @@ public:
|
||||
class CritterAI : public PassiveAI
|
||||
{
|
||||
public:
|
||||
explicit CritterAI(Creature* c) : PassiveAI(c) { _combatTimer = 0; }
|
||||
explicit CritterAI(Creature* c) : PassiveAI(c) { }
|
||||
|
||||
void DamageTaken(Unit* /*done_by*/, uint32& /*damage*/, DamageEffectType damagetype, SpellSchoolMask damageSchoolMask) override;
|
||||
void EnterCombat(Unit* /*who*/) override;
|
||||
void EnterEvadeMode(EvadeReason why) override;
|
||||
void UpdateAI(uint32) override;
|
||||
void MovementInform(uint32 type, uint32 id) override;
|
||||
void UpdateAI(uint32 /*diff*/) override { }
|
||||
|
||||
static int32 Permissible(Creature const* creature);
|
||||
// Xinef: Added
|
||||
private:
|
||||
uint32 _combatTimer;
|
||||
};
|
||||
|
||||
class TriggerAI : public NullCreatureAI
|
||||
|
||||
@@ -1036,7 +1036,7 @@ void Creature::DoFleeToGetAssistance()
|
||||
if (!creature)
|
||||
//SetFeared(true, GetVictim()->GetGUID(), 0, sWorld->getIntConfig(CONFIG_CREATURE_FAMILY_FLEE_DELAY));
|
||||
//TODO: use 31365
|
||||
SetControlled(true, UNIT_STATE_FLEEING);
|
||||
SetControlled(true, UNIT_STATE_FLEEING, GetVictim());
|
||||
else
|
||||
GetMotionMaster()->MoveSeekAssistance(creature->GetPositionX(), creature->GetPositionY(), creature->GetPositionZ());
|
||||
}
|
||||
|
||||
@@ -18131,7 +18131,7 @@ void Unit::Kill(Unit* killer, Unit* victim, bool durabilityLoss, WeaponAttackTyp
|
||||
}
|
||||
}
|
||||
|
||||
void Unit::SetControlled(bool apply, UnitState state)
|
||||
void Unit::SetControlled(bool apply, UnitState state, Unit* source /*= nullptr*/, bool isFear /*= false*/)
|
||||
{
|
||||
if (apply)
|
||||
{
|
||||
@@ -18164,7 +18164,7 @@ void Unit::SetControlled(bool apply, UnitState state)
|
||||
ClearUnitState(UNIT_STATE_MELEE_ATTACKING);
|
||||
SendMeleeAttackStop();
|
||||
// SendAutoRepeatCancel ?
|
||||
SetFeared(true);
|
||||
SetFeared(true, source, isFear);
|
||||
CastStop(0, false);
|
||||
}
|
||||
break;
|
||||
@@ -18234,7 +18234,21 @@ void Unit::SetControlled(bool apply, UnitState state)
|
||||
if (HasUnitState(UNIT_STATE_CONFUSED) || HasAuraType(SPELL_AURA_MOD_CONFUSE))
|
||||
SetConfused(true);
|
||||
else if (HasUnitState(UNIT_STATE_FLEEING) || HasAuraType(SPELL_AURA_MOD_FEAR))
|
||||
SetFeared(true);
|
||||
{
|
||||
bool isFear = false;
|
||||
if (HasAuraType(SPELL_AURA_MOD_FEAR))
|
||||
{
|
||||
isFear = true;
|
||||
source = ObjectAccessor::GetUnit(*this, GetAuraEffectsByType(SPELL_AURA_MOD_FEAR).front()->GetCasterGUID());
|
||||
}
|
||||
|
||||
if (!source)
|
||||
{
|
||||
source = getAttackerForHelper();
|
||||
}
|
||||
|
||||
SetFeared(true, source, isFear);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18369,19 +18383,12 @@ void Unit::DisableRotate(bool apply)
|
||||
RemoveUnitFlag(UNIT_FLAG_POSSESSED);
|
||||
}
|
||||
|
||||
void Unit::SetFeared(bool apply)
|
||||
void Unit::SetFeared(bool apply, Unit* fearedBy /*= nullptr*/, bool isFear /*= false*/)
|
||||
{
|
||||
if (apply)
|
||||
{
|
||||
SetTarget();
|
||||
|
||||
Unit* caster = nullptr;
|
||||
Unit::AuraEffectList const& fearAuras = GetAuraEffectsByType(SPELL_AURA_MOD_FEAR);
|
||||
if (!fearAuras.empty())
|
||||
caster = ObjectAccessor::GetUnit(*this, fearAuras.front()->GetCasterGUID());
|
||||
if (!caster)
|
||||
caster = getAttackerForHelper();
|
||||
GetMotionMaster()->MoveFleeing(caster, fearAuras.empty() ? sWorld->getIntConfig(CONFIG_CREATURE_FAMILY_FLEE_DELAY) : 0); // caster == nullptr processed in MoveFleeing
|
||||
GetMotionMaster()->MoveFleeing(fearedBy, isFear ? 0 : sWorld->getIntConfig(CONFIG_CREATURE_FAMILY_FLEE_DELAY));
|
||||
|
||||
if (GetTypeId() == TYPEID_PLAYER)
|
||||
{
|
||||
|
||||
@@ -2280,7 +2280,7 @@ public:
|
||||
[[nodiscard]] uint16 GetExtraUnitMovementFlags() const { return m_movementInfo.flags2; }
|
||||
void SetExtraUnitMovementFlags(uint16 f) { m_movementInfo.flags2 = f; }
|
||||
|
||||
void SetControlled(bool apply, UnitState state);
|
||||
void SetControlled(bool apply, UnitState state, Unit* source = nullptr, bool isFear = false);
|
||||
void DisableRotate(bool apply);
|
||||
void DisableSpline();
|
||||
|
||||
@@ -2557,7 +2557,7 @@ private:
|
||||
[[nodiscard]] uint32 GetCombatRatingDamageReduction(CombatRating cr, float rate, float cap, uint32 damage) const;
|
||||
|
||||
protected:
|
||||
void SetFeared(bool apply);
|
||||
void SetFeared(bool apply, Unit* fearedBy = nullptr, bool isFear = false);
|
||||
void SetConfused(bool apply);
|
||||
void SetStunned(bool apply);
|
||||
void SetRooted(bool apply, bool isStun = false);
|
||||
|
||||
@@ -36,6 +36,7 @@ void FleeingMovementGenerator<T>::DoInitialize(T* owner)
|
||||
return;
|
||||
}
|
||||
|
||||
owner->StopMoving();
|
||||
_path = nullptr;
|
||||
owner->SetUnitFlag(UNIT_FLAG_FLEEING);
|
||||
owner->AddUnitState(UNIT_STATE_FLEEING);
|
||||
@@ -233,8 +234,19 @@ void TimedFleeingMovementGenerator::Finalize(Unit* owner)
|
||||
{
|
||||
owner->RemoveUnitFlag(UNIT_FLAG_FLEEING);
|
||||
owner->ClearUnitState(UNIT_STATE_FLEEING | UNIT_STATE_FLEEING_MOVE);
|
||||
if (owner->GetVictim())
|
||||
owner->SetTarget(owner->GetVictim()->GetGUID());
|
||||
|
||||
if (Unit* victim = owner->GetVictim())
|
||||
{
|
||||
owner->SetTarget(victim->GetGUID());
|
||||
}
|
||||
|
||||
if (Creature* ownerCreature = owner->ToCreature())
|
||||
{
|
||||
if (CreatureAI* AI = ownerCreature->AI())
|
||||
{
|
||||
AI->MovementInform(TIMED_FLEEING_MOTION_TYPE, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool TimedFleeingMovementGenerator::Update(Unit* owner, uint32 time_diff)
|
||||
|
||||
@@ -3096,7 +3096,7 @@ void AuraEffect::HandleModFear(AuraApplication const* aurApp, uint8 mode, bool a
|
||||
|
||||
Unit* target = aurApp->GetTarget();
|
||||
|
||||
target->SetControlled(apply, UNIT_STATE_FLEEING);
|
||||
target->SetControlled(apply, UNIT_STATE_FLEEING, GetCaster(), true);
|
||||
}
|
||||
|
||||
void AuraEffect::HandleAuraModStun(AuraApplication const* aurApp, uint8 mode, bool apply) const
|
||||
|
||||
Reference in New Issue
Block a user