[8443] Implement use of UNIT_FLAG_OOC_NOT_ATTACKABLE for creature.

Creature with this flag will no longer be attackable by other creatures, and if by any reason it enter combat, flag is removed.

Signed-off-by: NoFantasy <nofantasy@nf.no>
This commit is contained in:
NoFantasy 2009-08-31 16:41:32 +02:00
parent f7963d1791
commit a9dea03e09
3 changed files with 51 additions and 37 deletions

View file

@ -9169,9 +9169,14 @@ void Unit::SetInCombatState(bool PvP, Unit* enemy)
if(isCharmed() || (GetTypeId()!=TYPEID_PLAYER && ((Creature*)this)->isPet())) if(isCharmed() || (GetTypeId()!=TYPEID_PLAYER && ((Creature*)this)->isPet()))
SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PET_IN_COMBAT); SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PET_IN_COMBAT);
if(creatureNotInCombat && ((Creature*)this)->AI()) if (creatureNotInCombat)
{
RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_OOC_NOT_ATTACKABLE);
if (((Creature*)this)->AI())
((Creature*)this)->AI()->EnterCombat(enemy); ((Creature*)this)->AI()->EnterCombat(enemy);
} }
}
void Unit::ClearInCombat() void Unit::ClearInCombat()
{ {
@ -9183,7 +9188,12 @@ void Unit::ClearInCombat()
// Player's state will be cleared in Player::UpdateContestedPvP // Player's state will be cleared in Player::UpdateContestedPvP
if (GetTypeId() != TYPEID_PLAYER) if (GetTypeId() != TYPEID_PLAYER)
{
if (((Creature*)this)->GetCreatureInfo()->unit_flags & UNIT_FLAG_OOC_NOT_ATTACKABLE)
SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_OOC_NOT_ATTACKABLE);
clearUnitState(UNIT_STAT_ATTACK_PLAYER); clearUnitState(UNIT_STAT_ATTACK_PLAYER);
}
else else
((Player*)this)->UpdatePotionCooldown(); ((Player*)this)->UpdatePotionCooldown();
} }
@ -9196,6 +9206,10 @@ bool Unit::isTargetableForAttack() const
if (HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE | UNIT_FLAG_NOT_SELECTABLE)) if (HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE | UNIT_FLAG_NOT_SELECTABLE))
return false; return false;
// to be removed if unit by any reason enter combat
if (HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_OOC_NOT_ATTACKABLE))
return false;
return IsInWorld() && isAlive() && !hasUnitState(UNIT_STAT_DIED)&& !isInFlight() /*&& !isStealth()*/; return IsInWorld() && isAlive() && !hasUnitState(UNIT_STAT_DIED)&& !isInFlight() /*&& !isStealth()*/;
} }

View file

@ -499,7 +499,7 @@ enum UnitFlags
UNIT_FLAG_PREPARATION = 0x00000020, // don't take reagents for spells with SPELL_ATTR_EX5_NO_REAGENT_WHILE_PREP UNIT_FLAG_PREPARATION = 0x00000020, // don't take reagents for spells with SPELL_ATTR_EX5_NO_REAGENT_WHILE_PREP
UNIT_FLAG_UNK_6 = 0x00000040, UNIT_FLAG_UNK_6 = 0x00000040,
UNIT_FLAG_NOT_ATTACKABLE_1 = 0x00000080, // ?? (UNIT_FLAG_PVP_ATTACKABLE | UNIT_FLAG_NOT_ATTACKABLE_1) is NON_PVP_ATTACKABLE UNIT_FLAG_NOT_ATTACKABLE_1 = 0x00000080, // ?? (UNIT_FLAG_PVP_ATTACKABLE | UNIT_FLAG_NOT_ATTACKABLE_1) is NON_PVP_ATTACKABLE
UNIT_FLAG_UNK_8 = 0x00000100, // 2.0.8 UNIT_FLAG_OOC_NOT_ATTACKABLE = 0x00000100, // 2.0.8 - (OOC Out Of Combat) Can not be attacked when not in combat. Removed if unit for some reason enter combat.
UNIT_FLAG_UNK_9 = 0x00000200, // 3.0.3 - makes you unable to attack everything UNIT_FLAG_UNK_9 = 0x00000200, // 3.0.3 - makes you unable to attack everything
UNIT_FLAG_LOOTING = 0x00000400, // loot animation UNIT_FLAG_LOOTING = 0x00000400, // loot animation
UNIT_FLAG_PET_IN_COMBAT = 0x00000800, // in combat?, 2.0.8 UNIT_FLAG_PET_IN_COMBAT = 0x00000800, // in combat?, 2.0.8

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "8442" #define REVISION_NR "8443"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__