aboutsummaryrefslogtreecommitdiff
path: root/src/game/Unit.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/Unit.cpp')
-rw-r--r--src/game/Unit.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp
index a569282bf4a..423345196d1 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);