mirror of
https://github.com/mangosfour/server.git
synced 2025-12-12 10:37:03 +00:00
[9603] Implement use of UNIT_FLAG_PASSIVE for creature.
Add function to check creatures own ability to initiate an attack in MoveInLineOfSight. Signed-off-by: NoFantasy <nofantasy@nf.no>
This commit is contained in:
parent
a27ff3e79d
commit
bfecdc3ded
6 changed files with 21 additions and 5 deletions
|
|
@ -47,9 +47,8 @@ AggressorAI::MoveInLineOfSight(Unit *u)
|
||||||
if( !m_creature->canFly() && m_creature->GetDistanceZ(u) > CREATURE_Z_ATTACK_RANGE )
|
if( !m_creature->canFly() && m_creature->GetDistanceZ(u) > CREATURE_Z_ATTACK_RANGE )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!m_creature->hasUnitState(UNIT_STAT_STUNNED | UNIT_STAT_DIED) && u->isTargetableForAttack() &&
|
if (m_creature->CanInitiateAttack() && u->isTargetableForAttack() &&
|
||||||
( m_creature->IsHostileTo( u ) /*|| u->getVictim() && m_creature->IsFriendlyTo( u->getVictim() )*/ ) &&
|
m_creature->IsHostileTo(u) && u->isInAccessablePlaceFor(m_creature))
|
||||||
u->isInAccessablePlaceFor(m_creature))
|
|
||||||
{
|
{
|
||||||
float attackRadius = m_creature->GetAttackDistance(u);
|
float attackRadius = m_creature->GetAttackDistance(u);
|
||||||
if(m_creature->IsWithinDistInMap(u, attackRadius) && m_creature->IsWithinLOSInMap(u) )
|
if(m_creature->IsWithinDistInMap(u, attackRadius) && m_creature->IsWithinLOSInMap(u) )
|
||||||
|
|
|
||||||
|
|
@ -1634,6 +1634,20 @@ bool Creature::CanAssistTo(const Unit* u, const Unit* enemy, bool checkfaction /
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Creature::CanInitiateAttack()
|
||||||
|
{
|
||||||
|
if (hasUnitState(UNIT_STAT_STUNNED | UNIT_STAT_DIED))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE | UNIT_FLAG_NOT_SELECTABLE))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (isPassiveToHostile())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void Creature::SaveRespawnTime()
|
void Creature::SaveRespawnTime()
|
||||||
{
|
{
|
||||||
if(isPet() || !m_DBTableGuid)
|
if(isPet() || !m_DBTableGuid)
|
||||||
|
|
|
||||||
|
|
@ -556,6 +556,7 @@ class MANGOS_DLL_SPEC Creature : public Unit
|
||||||
void SetNoSearchAssistance(bool val) { m_AlreadySearchedAssistance = val; }
|
void SetNoSearchAssistance(bool val) { m_AlreadySearchedAssistance = val; }
|
||||||
bool HasSearchedAssistance() { return m_AlreadySearchedAssistance; }
|
bool HasSearchedAssistance() { return m_AlreadySearchedAssistance; }
|
||||||
bool CanAssistTo(const Unit* u, const Unit* enemy, bool checkfaction = true) const;
|
bool CanAssistTo(const Unit* u, const Unit* enemy, bool checkfaction = true) const;
|
||||||
|
bool CanInitiateAttack();
|
||||||
|
|
||||||
MovementGeneratorType GetDefaultMovementType() const { return m_defaultMovementType; }
|
MovementGeneratorType GetDefaultMovementType() const { return m_defaultMovementType; }
|
||||||
void SetDefaultMovementType(MovementGeneratorType mgt) { m_defaultMovementType = mgt; }
|
void SetDefaultMovementType(MovementGeneratorType mgt) { m_defaultMovementType = mgt; }
|
||||||
|
|
|
||||||
|
|
@ -1022,7 +1022,7 @@ void CreatureEventAI::MoveInLineOfSight(Unit *who)
|
||||||
if (m_creature->isCivilian() || m_creature->IsNeutralToAll())
|
if (m_creature->isCivilian() || m_creature->IsNeutralToAll())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!m_creature->hasUnitState(UNIT_STAT_STUNNED | UNIT_STAT_DIED) && who->isTargetableForAttack() &&
|
if (m_creature->CanInitiateAttack() && who->isTargetableForAttack() &&
|
||||||
m_creature->IsHostileTo(who) && who->isInAccessablePlaceFor(m_creature))
|
m_creature->IsHostileTo(who) && who->isInAccessablePlaceFor(m_creature))
|
||||||
{
|
{
|
||||||
if (!m_creature->canFly() && m_creature->GetDistanceZ(who) > CREATURE_Z_ATTACK_RANGE)
|
if (!m_creature->canFly() && m_creature->GetDistanceZ(who) > CREATURE_Z_ATTACK_RANGE)
|
||||||
|
|
|
||||||
|
|
@ -1342,6 +1342,8 @@ class MANGOS_DLL_SPEC Unit : public WorldObject
|
||||||
void RemoveSpellbyDamageTaken(AuraType auraType, uint32 damage);
|
void RemoveSpellbyDamageTaken(AuraType auraType, uint32 damage);
|
||||||
|
|
||||||
bool isTargetableForAttack(bool inversAlive = false) const;
|
bool isTargetableForAttack(bool inversAlive = false) const;
|
||||||
|
bool isPassiveToHostile() { return HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PASSIVE); }
|
||||||
|
|
||||||
virtual bool IsInWater() const;
|
virtual bool IsInWater() const;
|
||||||
virtual bool IsUnderWater() const;
|
virtual bool IsUnderWater() const;
|
||||||
bool isInAccessablePlaceFor(Creature const* c) const;
|
bool isInAccessablePlaceFor(Creature const* c) const;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#ifndef __REVISION_NR_H__
|
#ifndef __REVISION_NR_H__
|
||||||
#define __REVISION_NR_H__
|
#define __REVISION_NR_H__
|
||||||
#define REVISION_NR "9602"
|
#define REVISION_NR "9603"
|
||||||
#endif // __REVISION_NR_H__
|
#endif // __REVISION_NR_H__
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue