From eb8535b7b2cd33fd6fbdd669073e0f38adb42a97 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Tue, 7 Dec 2021 13:41:20 -0500 Subject: [PATCH] Core/Creature: couple refactors/renaming Port From (https://github.com/TrinityCore/TrinityCore/commit/c22431936e5bd65474aca4c1fd71e315a20c34cb) --- Source/Game/Entities/Creature/Creature.cs | 97 +++++++++++++---------- 1 file changed, 54 insertions(+), 43 deletions(-) diff --git a/Source/Game/Entities/Creature/Creature.cs b/Source/Game/Entities/Creature/Creature.cs index 4a830345b..139005e3e 100644 --- a/Source/Game/Entities/Creature/Creature.cs +++ b/Source/Game/Entities/Creature/Creature.cs @@ -409,10 +409,9 @@ namespace Game.Entities ApplySpellImmune(0, SpellImmunity.Effect, SpellEffectName.AttackMe, true); } - if (GetMovementTemplate().IsRooted()) - SetControlled(true, UnitState.Root); + LoadTemplateRoot(); + InitializeMovementFlags(); - UpdateMovementFlags(); LoadCreaturesAddon(); LoadTemplateImmunities(); @@ -1565,6 +1564,12 @@ namespace Game.Entities SetHealth((m_deathState == DeathState.Alive || m_deathState == DeathState.JustRespawned) ? curhealth : 0); } + void LoadTemplateRoot() + { + if (GetMovementTemplate().IsRooted()) + SetControlled(true, UnitState.Root); + } + public override bool HasQuest(uint quest_id) { var qr = Global.ObjectMgr.GetCreatureQuestRelationBounds(GetEntry()); @@ -2439,6 +2444,52 @@ namespace Game.Entities bool IsSpawnedOnTransport() { return m_creatureData != null && m_creatureData.spawnPoint.GetMapId() != GetMapId(); } + void InitializeMovementFlags() + { + // It does the same, for now + UpdateMovementFlags(); + } + + public void UpdateMovementFlags() + { + // Do not update movement flags if creature is controlled by a player (charm/vehicle) + if (m_playerMovingMe != null) + return; + + // Creatures with CREATURE_FLAG_EXTRA_NO_MOVE_FLAGS_UPDATE should control MovementFlags in your own scripts + if (GetCreatureTemplate().FlagsExtra.HasAnyFlag(CreatureFlagsExtra.NoMoveFlagsUpdate)) + return; + + // Set the movement flags if the creature is in that mode. (Only fly if actually in air, only swim if in water, etc) + float ground = GetFloorZ(); + + bool canHover = CanHover(); + bool isInAir = (MathFunctions.fuzzyGt(GetPositionZ(), ground + (canHover ? m_unitData.HoverHeight : 0.0f) + MapConst.GroundHeightTolerance) || MathFunctions.fuzzyLt(GetPositionZ(), ground - MapConst.GroundHeightTolerance)); // Can be underground too, prevent the falling + + if (GetMovementTemplate().IsFlightAllowed() && isInAir && !IsFalling()) + { + if (GetMovementTemplate().Flight == CreatureFlightMovementType.CanFly) + SetCanFly(true); + else + SetDisableGravity(true); + + if (!HasAuraType(AuraType.Hover)) + SetHover(false); + } + else + { + SetCanFly(false); + SetDisableGravity(false); + if (IsAlive() && (CanHover() || HasAuraType(AuraType.Hover))) + SetHover(true); + } + + if (!isInAir) + SetFall(false); + + SetSwim(GetMovementTemplate().IsSwimAllowed() && IsInWater()); + } + public CreatureMovementData GetMovementTemplate() { CreatureMovementData movementOverride = Global.ObjectMgr.GetCreatureMovementOverride(m_spawnId); @@ -2794,46 +2845,6 @@ namespace Game.Entities return searcher.GetTarget(); } - public void UpdateMovementFlags() - { - // Do not update movement flags if creature is controlled by a player (charm/vehicle) - if (m_playerMovingMe != null) - return; - - // Creatures with CREATURE_FLAG_EXTRA_NO_MOVE_FLAGS_UPDATE should control MovementFlags in your own scripts - if (GetCreatureTemplate().FlagsExtra.HasAnyFlag(CreatureFlagsExtra.NoMoveFlagsUpdate)) - return; - - // Set the movement flags if the creature is in that mode. (Only fly if actually in air, only swim if in water, etc) - float ground = GetFloorZ(); - - bool canHover = CanHover(); - bool isInAir = (MathFunctions.fuzzyGt(GetPositionZ(), ground + (canHover ? m_unitData.HoverHeight : 0.0f) + MapConst.GroundHeightTolerance) || MathFunctions.fuzzyLt(GetPositionZ(), ground - MapConst.GroundHeightTolerance)); // Can be underground too, prevent the falling - - if (GetMovementTemplate().IsFlightAllowed() && isInAir && !IsFalling()) - { - if (GetMovementTemplate().Flight == CreatureFlightMovementType.CanFly) - SetCanFly(true); - else - SetDisableGravity(true); - - if (!HasAuraType(AuraType.Hover)) - SetHover(false); - } - else - { - SetCanFly(false); - SetDisableGravity(false); - if (IsAlive() && (CanHover() || HasAuraType(AuraType.Hover))) - SetHover(true); - } - - if (!isInAir) - SetFall(false); - - SetSwim(GetMovementTemplate().IsSwimAllowed() && IsInWater()); - } - public override void SetObjectScale(float scale) { base.SetObjectScale(scale);