*always remove UNIT_FLAG_OOC_NOT_ATTACKABLE if crature enters combat and reset on leave combat

-Please post feedback if it breaks any script!

--HG--
branch : trunk
This commit is contained in:
Rat
2010-03-18 00:01:39 +01:00
parent 4f948651df
commit 2b096c478a
+8 -1
View File
@@ -11439,9 +11439,12 @@ void Unit::SetInCombatState(bool PvP, Unit* enemy)
this->ToCreature()->SetHomePosition(GetPositionX(), GetPositionY(), GetPositionZ(), GetOrientation()); this->ToCreature()->SetHomePosition(GetPositionX(), GetPositionY(), GetPositionZ(), GetOrientation());
if (enemy) if (enemy)
{ {
if (IsAIEnabled) if (IsAIEnabled)
{
this->ToCreature()->AI()->EnterCombat(enemy); this->ToCreature()->AI()->EnterCombat(enemy);
RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_OOC_NOT_ATTACKABLE);//always remove Out of Combat Non Attackable flag if we enter combat and AI is enabled
}
if (this->ToCreature()->GetFormation()) if (this->ToCreature()->GetFormation())
this->ToCreature()->GetFormation()->MemberAttackStart(this->ToCreature(), enemy); this->ToCreature()->GetFormation()->MemberAttackStart(this->ToCreature(), enemy);
} }
@@ -11469,6 +11472,10 @@ 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)
{ {
Creature* creature = this->ToCreature();
if (creature->GetCreatureInfo() && creature->GetCreatureInfo()->unit_flags & UNIT_FLAG_OOC_NOT_ATTACKABLE)
SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_OOC_NOT_ATTACKABLE);//re-apply Out of Combat Non Attackable flag if we leave combat, can be overriden in scripts in EnterEvadeMode()
clearUnitState(UNIT_STAT_ATTACK_PLAYER); clearUnitState(UNIT_STAT_ATTACK_PLAYER);
if (HasFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_TAPPED)) if (HasFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_TAPPED))
SetUInt32Value(UNIT_DYNAMIC_FLAGS, ((Creature*)this)->GetCreatureInfo()->dynamicflags); SetUInt32Value(UNIT_DYNAMIC_FLAGS, ((Creature*)this)->GetCreatureInfo()->dynamicflags);