diff options
author | Teleqraph <nyrdeveloper@gmail.com> | 2023-07-20 12:20:15 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-20 12:20:15 +0200 |
commit | 53f9abec14613c0823b1ee5363b3f873cc23ece9 (patch) | |
tree | c7649ad72fc0f5f433104d05c9d20624e8270953 /src | |
parent | 889e88ab8033a78db837e0bb8619d8ce9d64967f (diff) |
Core/Unit: Added helper functions to modify UNIT_FLAG2_CANNOT_TURN (#29160)
Diffstat (limited to 'src')
-rw-r--r-- | src/server/game/Entities/Creature/Creature.cpp | 6 | ||||
-rw-r--r-- | src/server/game/Entities/Unit/Unit.cpp | 8 | ||||
-rw-r--r-- | src/server/game/Entities/Unit/Unit.h | 3 |
3 files changed, 14 insertions, 3 deletions
diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index 450f09b3bec..af3c30ab610 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -3358,7 +3358,7 @@ void Creature::SetSpellFocus(Spell const* focusSpell, WorldObject const* target) _spellFocusInfo.Spell = focusSpell; bool const noTurnDuringCast = spellInfo->HasAttribute(SPELL_ATTR5_AI_DOESNT_FACE_TARGET); - bool const turnDisabled = HasUnitFlag2(UNIT_FLAG2_CANNOT_TURN); + bool const turnDisabled = CannotTurn(); // set target, then force send update packet to players if it changed to provide appropriate facing ObjectGuid newTarget = (target && !noTurnDuringCast && !turnDisabled) ? target->GetGUID() : ObjectGuid::Empty; if (GetTarget() != newTarget) @@ -3404,7 +3404,7 @@ void Creature::ReleaseSpellFocus(Spell const* focusSpell, bool withDelay) if (IsPet()) // player pets do not use delay system { - if (!HasUnitFlag2(UNIT_FLAG2_CANNOT_TURN)) + if (!CannotTurn()) ReacquireSpellFocusTarget(); } else // don't allow re-target right away to prevent visual bugs @@ -3423,7 +3423,7 @@ void Creature::ReacquireSpellFocusTarget() SetUpdateFieldValue(m_values.ModifyValue(&Unit::m_unitData).ModifyValue(&UF::UnitData::Target), _spellFocusInfo.Target); - if (!HasUnitFlag2(UNIT_FLAG2_CANNOT_TURN)) + if (!CannotTurn()) { if (!_spellFocusInfo.Target.IsEmpty()) { diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index b2a2eed635b..db72864c945 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -7968,6 +7968,14 @@ void Unit::SetImmuneToNPC(bool apply, bool keepCombat) RemoveUnitFlag(UNIT_FLAG_IMMUNE_TO_NPC); } +void Unit::SetCannotTurn(bool apply) +{ + if (apply) + SetUnitFlag2(UNIT_FLAG2_CANNOT_TURN); + else + RemoveUnitFlag2(UNIT_FLAG2_CANNOT_TURN); +} + bool Unit::IsThreatened() const { return !m_threatManager.IsThreatListEmpty(); diff --git a/src/server/game/Entities/Unit/Unit.h b/src/server/game/Entities/Unit/Unit.h index e69d01795dd..43955fcd969 100644 --- a/src/server/game/Entities/Unit/Unit.h +++ b/src/server/game/Entities/Unit/Unit.h @@ -1151,6 +1151,9 @@ class TC_GAME_API Unit : public WorldObject void SetImmuneToNPC(bool apply, bool keepCombat); virtual void SetImmuneToNPC(bool apply) { SetImmuneToNPC(apply, false); } + bool CannotTurn() const { return HasUnitFlag2(UNIT_FLAG2_CANNOT_TURN); } + void SetCannotTurn(bool apply); + bool IsInCombat() const { return HasUnitFlag(UNIT_FLAG_IN_COMBAT); } bool IsInCombatWith(Unit const* who) const { return who && m_combatManager.IsInCombatWith(who); } void SetInCombatWith(Unit* enemy, bool addSecondUnitSuppressed = false) { if (enemy) m_combatManager.SetInCombatWith(enemy, addSecondUnitSuppressed); } |