Core/GuardAI: Guards don't evade if the target casts Vanish and also can detect players with Feign Death.

Core/Scripts: Moved scripts from ScriptedGuardAI to guards.cpp
Core/Creature: Removed custom npcflags UNIT_NPC_FLAG_GUARD (now moved to flag_extras) and UNIT_NPC_FLAG_OUTDOORPVP (not used)

Thanks to Kaelima, Xanadu, Shauren and linencloth.

Signed-off-by: Manuel Carrasco <[email protected]>
This commit is contained in:
Manuel Carrasco
2011-02-10 22:36:35 -03:00
parent 71849e0efe
commit 6b2ffc9039
16 changed files with 337 additions and 398 deletions
+20 -1
View File
@@ -1421,6 +1421,17 @@ bool Creature::isVisibleForInState(WorldObject const* seer) const
return false;
}
bool Creature::canSeeAlways(WorldObject const* obj) const
{
if (Unit::canSeeAlways(obj))
return true;
if (IsAIEnabled && AI()->CanSeeAlways(obj))
return true;
return false;
}
bool Creature::canStartAttack(Unit const* who, bool force) const
{
if (isCivilian())
@@ -1960,10 +1971,18 @@ bool Creature::_IsTargetAcceptable(const Unit *target) const
// if the target cannot be attacked, the target is not acceptable
if (IsFriendlyTo(target)
|| !target->isAttackableByAOE()
|| target->HasUnitState(UNIT_STAT_DIED)
|| (m_vehicle && (IsOnVehicle(target) || m_vehicle->GetBase()->IsOnVehicle(target))))
return false;
if (target->HasUnitState(UNIT_STAT_DIED))
{
// guards can detect fake death
if (isGuard() && target->HasFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FEIGN_DEATH))
return true;
else
return false;
}
const Unit *myVictim = getAttackerForHelper();
const Unit *targetVictim = target->getAttackerForHelper();
+5 -2
View File
@@ -49,7 +49,7 @@ enum CreatureFlagsExtra
CREATURE_FLAG_EXTRA_TRIGGER = 0x00000080, // trigger creature
CREATURE_FLAG_EXTRA_NO_TAUNT = 0x00000100, // creature is immune to taunt auras and effect attack me
CREATURE_FLAG_EXTRA_WORLDEVENT = 0x00004000, // custom flag for world event creatures (left room for merging)
//CREATURE_FLAG_EXTRA_CHARM_AI = 0x00008000, // use ai when charmed
CREATURE_FLAG_EXTRA_GUARD = 0x00008000, // Creature is guard
CREATURE_FLAG_EXTRA_NO_CRIT = 0x00020000, // creature can't do critical strikes
CREATURE_FLAG_EXTRA_NO_SKILLGAIN = 0x00040000, // creature won't increase weapon skills
CREATURE_FLAG_EXTRA_TAUNT_DIMINISH = 0x00080000, // Taunt is a subject to diminishing returns on this creautre
@@ -61,7 +61,8 @@ enum CreatureFlagsExtra
CREATURE_FLAG_EXTRA_NO_PARRY | CREATURE_FLAG_EXTRA_NO_PARRY_HASTEN | CREATURE_FLAG_EXTRA_NO_BLOCK | \
CREATURE_FLAG_EXTRA_NO_CRUSH | CREATURE_FLAG_EXTRA_NO_XP_AT_KILL | CREATURE_FLAG_EXTRA_TRIGGER | \
CREATURE_FLAG_EXTRA_NO_TAUNT | CREATURE_FLAG_EXTRA_WORLDEVENT | CREATURE_FLAG_EXTRA_NO_CRIT | \
CREATURE_FLAG_EXTRA_NO_SKILLGAIN | CREATURE_FLAG_EXTRA_TAUNT_DIMINISH | CREATURE_FLAG_EXTRA_ALL_DIMINISH)
CREATURE_FLAG_EXTRA_NO_SKILLGAIN | CREATURE_FLAG_EXTRA_TAUNT_DIMINISH | CREATURE_FLAG_EXTRA_ALL_DIMINISH | \
CREATURE_FLAG_EXTRA_GUARD)
// GCC have alternative #pragma pack(N) syntax and old gcc version not support pack(push,N), also any gcc version not support it at some platform
#if defined(__GNUC__)
@@ -435,6 +436,7 @@ class Creature : public Unit, public GridObject<Creature>
bool isRacialLeader() const { return GetCreatureInfo()->RacialLeader; }
bool isCivilian() const { return GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_CIVILIAN; }
bool isTrigger() const { return GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_TRIGGER; }
bool isGuard() const { return GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_GUARD; }
bool canWalk() const { return GetCreatureInfo()->InhabitType & INHABIT_GROUND; }
bool canSwim() const { return GetCreatureInfo()->InhabitType & INHABIT_WATER; }
//bool canFly() const { return GetCreatureInfo()->InhabitType & INHABIT_AIR; }
@@ -729,6 +731,7 @@ class Creature : public Unit, public GridObject<Creature>
uint32 guid_transport;
bool isVisibleForInState(WorldObject const* seer) const;
bool canSeeAlways(WorldObject const* obj) const;
private:
//WaypointMovementGenerator vars
uint32 m_waypointID;
+1 -1
View File
@@ -529,7 +529,7 @@ void Object::_BuildValuesUpdate(uint8 updatetype, ByteBuffer * data, UpdateMask
if (index == UNIT_NPC_FLAGS)
{
// remove custom flag before sending
uint32 appendValue = m_uint32Values[ index ] & ~(UNIT_NPC_FLAG_GUARD + UNIT_NPC_FLAG_OUTDOORPVP);
uint32 appendValue = m_uint32Values[ index ];
if (GetTypeId() == TYPEID_UNIT)
{
+11 -1
View File
@@ -11879,9 +11879,19 @@ bool Unit::canAttack(Unit const* target, bool force) const
else if (!IsHostileTo(target))
return false;
if (!target->isAttackableByAOE() || target->HasUnitState(UNIT_STAT_DIED))
if (!target->isAttackableByAOE())
return false;
if (target->HasUnitState(UNIT_STAT_DIED))
{
if (!ToCreature() || !ToCreature()->isGuard())
return false;
// guards can detect fake death
if (!target->HasFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FEIGN_DEATH))
return false;
}
if (m_vehicle)
if (IsOnVehicle(target) || m_vehicle->GetBase()->IsOnVehicle(target))
return false;
+1 -6
View File
@@ -624,8 +624,6 @@ enum NPCFlags
UNIT_NPC_FLAG_GUILD_BANKER = 0x00800000, // cause client to send 997 opcode
UNIT_NPC_FLAG_SPELLCLICK = 0x01000000, // cause client to send 1015 opcode (spell click), dynamic, set at loading and don't must be set in DB
UNIT_NPC_FLAG_PLAYER_VEHICLE = 0x02000000, // players with mounts that have vehicle data should have it set
UNIT_NPC_FLAG_GUARD = 0x10000000, // custom flag for guards
UNIT_NPC_FLAG_OUTDOORPVP = 0x20000000, // custom flag for outdoor pvp creatures
};
enum MovementFlags
@@ -1422,14 +1420,11 @@ class Unit : public WorldObject
return HasFlag(UNIT_NPC_FLAGS,
UNIT_NPC_FLAG_VENDOR | UNIT_NPC_FLAG_TRAINER | UNIT_NPC_FLAG_FLIGHTMASTER |
UNIT_NPC_FLAG_PETITIONER | UNIT_NPC_FLAG_BATTLEMASTER | UNIT_NPC_FLAG_BANKER |
UNIT_NPC_FLAG_INNKEEPER | UNIT_NPC_FLAG_GUARD | UNIT_NPC_FLAG_SPIRITHEALER |
UNIT_NPC_FLAG_INNKEEPER | UNIT_NPC_FLAG_SPIRITHEALER |
UNIT_NPC_FLAG_SPIRITGUIDE | UNIT_NPC_FLAG_TABARDDESIGNER | UNIT_NPC_FLAG_AUCTIONEER);
}
bool isSpiritService() const { return HasFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPIRITHEALER | UNIT_NPC_FLAG_SPIRITGUIDE); }
//Need fix or use this
bool isGuard() const { return HasFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GUARD); }
bool isInFlight() const { return HasUnitState(UNIT_STAT_IN_FLIGHT); }
bool isInCombat() const { return HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IN_COMBAT); }