From 2b096c478a64ef9448c574f933449f85b228b8dd Mon Sep 17 00:00:00 2001 From: Rat Date: Thu, 18 Mar 2010 00:01:39 +0100 Subject: [PATCH] *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 --- src/game/Unit.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index a569282bf4..423345196d 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -11439,9 +11439,12 @@ void Unit::SetInCombatState(bool PvP, Unit* enemy) this->ToCreature()->SetHomePosition(GetPositionX(), GetPositionY(), GetPositionZ(), GetOrientation()); if (enemy) - { + { if (IsAIEnabled) + { 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()) this->ToCreature()->GetFormation()->MemberAttackStart(this->ToCreature(), enemy); } @@ -11469,6 +11472,10 @@ void Unit::ClearInCombat() // Player's state will be cleared in Player::UpdateContestedPvP 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); if (HasFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_TAPPED)) SetUInt32Value(UNIT_DYNAMIC_FLAGS, ((Creature*)this)->GetCreatureInfo()->dynamicflags);