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
This commit is contained in:
Ovah
2020-08-07 14:51:40 +02:00
committed by GitHub
parent 98b1b20d6b
commit 764f22fc91
5 changed files with 13 additions and 7 deletions

View File

@@ -44,12 +44,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();

View File

@@ -614,6 +614,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();

View File

@@ -91,7 +91,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();

View File

@@ -382,6 +382,7 @@ Unit::Unit(bool isWorldObject) :
_oldFactionId = 0;
_isWalkingBeforeCharm = false;
_instantCast = false;
_isIgnoringCombat = false;
}
////////////////////////////////////////////////////////////

View File

@@ -1686,6 +1686,11 @@ class TC_GAME_API Unit : public WorldObject
float GetCollisionHeight() const override;
// 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;
protected:
explicit Unit (bool isWorldObject);
@@ -1832,6 +1837,8 @@ class TC_GAME_API Unit : public WorldObject
SpellHistory* m_spellHistory;
PositionUpdateInfo _positionUpdateInfo;
bool _isIgnoringCombat;
};
namespace Trinity