diff options
author | Ovah <dreadkiller@gmx.de> | 2020-08-07 14:51:40 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2022-01-26 18:41:41 +0100 |
commit | 2819951dce545438724719836e3a13d3039b8690 (patch) | |
tree | f5231c0aec78ba2a8052a5974dbe01182ee90653 | |
parent | d6c998a1a8f01b05d136667612e8fb350d9fdb59 (diff) |
Core/Units: add new functionality for units to block or enable combat interactions (#25168)
* Core/Units: add new functionality for units to block or enable combat entirely via helper to reflect what CREATURE_DIFFICULTYFLAGS_IGNORE_COMBAT and client AI functions imply
* yeah...
* Nuke Creature::IsCombatDisallowed helper as its unused by now
* no combat extra flag may now be changed on transforms if the transformed entry does not have the flag
(cherry picked from commit 764f22fc9157ad184baa38995ee4e2d821299935)
-rw-r--r-- | src/server/game/Combat/CombatManager.cpp | 9 | ||||
-rw-r--r-- | src/server/game/Entities/Creature/Creature.cpp | 2 | ||||
-rw-r--r-- | src/server/game/Entities/Creature/Creature.h | 1 | ||||
-rw-r--r-- | src/server/game/Entities/Unit/Unit.cpp | 1 | ||||
-rw-r--r-- | src/server/game/Entities/Unit/Unit.h | 7 |
5 files changed, 13 insertions, 7 deletions
diff --git a/src/server/game/Combat/CombatManager.cpp b/src/server/game/Combat/CombatManager.cpp index edf47fdca87..d0401ded76c 100644 --- a/src/server/game/Combat/CombatManager.cpp +++ b/src/server/game/Combat/CombatManager.cpp @@ -43,12 +43,9 @@ return false; if (a->HasUnitState(UNIT_STATE_IN_FLIGHT) || b->HasUnitState(UNIT_STATE_IN_FLIGHT)) return false; - if (Creature const* aCreature = a->ToCreature()) - if (aCreature->IsCombatDisallowed()) - return false; - if (Creature const* bCreature = b->ToCreature()) - if (bCreature->IsCombatDisallowed()) - return false; + // ... both units must not be ignoring combat + if (a->IsIgnoringCombat() || b->IsIgnoringCombat()) + return false; if (a->IsFriendlyTo(b) || b->IsFriendlyTo(a)) return false; Player const* playerA = a->GetCharmerOrOwnerPlayerOrPlayerItself(); diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index c7d92bc46a2..4d17c7a6c0b 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -680,6 +680,8 @@ bool Creature::UpdateEntry(uint32 entry, CreatureData const* data /*= nullptr*/, ApplySpellImmune(0, IMMUNITY_EFFECT, SPELL_EFFECT_ATTACK_ME, true); } + SetIgnoringCombat((cInfo->flags_extra & CREATURE_FLAG_EXTRA_NO_COMBAT) != 0); + LoadTemplateRoot(); InitializeMovementFlags(); diff --git a/src/server/game/Entities/Creature/Creature.h b/src/server/game/Entities/Creature/Creature.h index 8b0dc29f542..1a67853ebf1 100644 --- a/src/server/game/Entities/Creature/Creature.h +++ b/src/server/game/Entities/Creature/Creature.h @@ -105,7 +105,6 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma bool IsCivilian() const { return (GetCreatureTemplate()->flags_extra & CREATURE_FLAG_EXTRA_CIVILIAN) != 0; } bool IsTrigger() const { return (GetCreatureTemplate()->flags_extra & CREATURE_FLAG_EXTRA_TRIGGER) != 0; } bool IsGuard() const { return (GetCreatureTemplate()->flags_extra & CREATURE_FLAG_EXTRA_GUARD) != 0; } - bool IsCombatDisallowed() const { return (GetCreatureTemplate()->flags_extra & CREATURE_FLAG_EXTRA_NO_COMBAT) != 0; } void InitializeMovementFlags(); void UpdateMovementFlags(); diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index 49b3b19be9b..057fd26a731 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -400,6 +400,7 @@ Unit::Unit(bool isWorldObject) : _oldFactionId = 0; _isWalkingBeforeCharm = false; _instantCast = false; + _isIgnoringCombat = false; } //////////////////////////////////////////////////////////// diff --git a/src/server/game/Entities/Unit/Unit.h b/src/server/game/Entities/Unit/Unit.h index 520b6fb1a30..6e255d8e0f6 100644 --- a/src/server/game/Entities/Unit/Unit.h +++ b/src/server/game/Entities/Unit/Unit.h @@ -1849,6 +1849,11 @@ class TC_GAME_API Unit : public WorldObject uint16 GetVirtualItemAppearanceMod(uint32 slot) const; void SetVirtualItem(uint32 slot, uint32 itemId, uint16 appearanceModId = 0, uint16 itemVisual = 0); + // returns if the unit is ignoring any combat interaction + bool IsIgnoringCombat() const { return _isIgnoringCombat; } + // enables/disables combat interaction of this unit. + void SetIgnoringCombat(bool apply) { _isIgnoringCombat = apply; } + std::string GetDebugInfo() const override; UF::UpdateField<UF::UnitData, 0, TYPEID_UNIT> m_unitData; @@ -2017,6 +2022,8 @@ class TC_GAME_API Unit : public WorldObject std::unique_ptr<MovementForces> _movementForces; PositionUpdateInfo _positionUpdateInfo; + + bool _isIgnoringCombat; }; namespace Trinity |