Core/Creatures: Reworked setting move types in database

Port From (https://github.com/TrinityCore/TrinityCore/commit/f8c03a90661610e289029c78d2055d7b73a5ad98)
This commit is contained in:
hondacrx
2021-08-24 12:23:39 -04:00
parent 89058fec83
commit e4240fcd94
13 changed files with 669 additions and 492 deletions
+28 -19
View File
@@ -416,7 +416,7 @@ namespace Game.Entities
ApplySpellImmune(0, SpellImmunity.Effect, SpellEffectName.AttackMe, true);
}
if (cInfo.InhabitType.HasAnyFlag(InhabitType.Root))
if (GetMovementTemplate().IsRooted())
SetControlled(true, UnitState.Root);
UpdateMovementFlags();
@@ -2311,7 +2311,7 @@ namespace Game.Entities
dist += GetCombatReach() + victim.GetCombatReach();
// to prevent creatures in air ignore attacks because distance is already too high...
if (GetCreatureTemplate().InhabitType.HasAnyFlag(InhabitType.Air))
if (GetMovementTemplate().IsFlightAllowed())
return victim.IsInDist2d(m_homePosition, dist);
else
return victim.IsInDist(m_homePosition, dist);
@@ -2356,7 +2356,7 @@ namespace Game.Entities
//! Check using InhabitType as movement flags are assigned dynamically
//! basing on whether the creature is in air or not
//! Set MovementFlag_Hover. Otherwise do nothing.
if (Convert.ToBoolean(m_unitData.AnimTier & (byte)UnitBytes1Flags.Hover) && !Convert.ToBoolean(GetCreatureTemplate().InhabitType & InhabitType.Air))
if (CanHover())
AddUnitMovementFlag(MovementFlag.Hover);
}
@@ -2463,6 +2463,15 @@ namespace Game.Entities
bool IsSpawnedOnTransport() { return m_creatureData != null && m_creatureData.spawnPoint.GetMapId() != GetMapId(); }
public CreatureMovementData GetMovementTemplate()
{
CreatureMovementData movementOverride = Global.ObjectMgr.GetCreatureMovementOverride(m_spawnId);
if (movementOverride != null)
return movementOverride;
return GetCreatureTemplate().Movement;
}
public void AllLootRemovedFromCorpse()
{
if (loot.loot_type != LootType.Skinning && !IsPet() && GetCreatureTemplate().SkinLootId != 0 && HasLootRecipient())
@@ -2822,25 +2831,31 @@ namespace Game.Entities
// 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 isInAir = (MathFunctions.fuzzyGt(GetPositionZ(), ground + MapConst.GroundHeightTolerance) || MathFunctions.fuzzyLt(GetPositionZ(), ground - MapConst.GroundHeightTolerance)); // Can be underground too, prevent the falling
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 (GetCreatureTemplate().InhabitType.HasAnyFlag(InhabitType.Air) && isInAir && !IsFalling())
if (GetMovementTemplate().IsFlightAllowed() && isInAir && !IsFalling())
{
if (GetCreatureTemplate().InhabitType.HasAnyFlag(InhabitType.Ground))
if (GetMovementTemplate().Flight == CreatureFlightMovementType.CanFly)
SetCanFly(true);
else
SetDisableGravity(true);
if (!HasAuraType(AuraType.Hover))
SetHover(false);
}
else
{
SetCanFly(false);
SetDisableGravity(false);
if (CanHover() || HasAuraType(AuraType.Hover))
SetHover(true);
}
if (!isInAir)
SetFall(false);
SetSwim(GetCreatureTemplate().InhabitType.HasAnyFlag(InhabitType.Water) && IsInWater());
SetSwim(GetMovementTemplate().IsSwimAllowed() && IsInWater());
}
public override void SetObjectScale(float scale)
@@ -3034,18 +3049,12 @@ namespace Game.Entities
{
return GetCreatureTemplate().FlagsExtra.HasAnyFlag(CreatureFlagsExtra.Guard);
}
public bool CanWalk()
{
return GetCreatureTemplate().InhabitType.HasAnyFlag(InhabitType.Ground);
}
public override bool CanSwim()
{
return GetCreatureTemplate().InhabitType.HasAnyFlag(InhabitType.Water);
}
public override bool CanFly()
{
return GetCreatureTemplate().InhabitType.HasAnyFlag(InhabitType.Air);
}
public bool CanWalk() { return GetMovementTemplate().IsGroundAllowed(); }
public override bool CanSwim() { return GetMovementTemplate().IsSwimAllowed() || IsPet();}
public override bool CanFly() { return GetMovementTemplate().IsFlightAllowed(); }
bool CanHover() { return GetMovementTemplate().Ground == CreatureGroundMovementType.Hover; }
public bool IsDungeonBoss() { return (GetCreatureTemplate().FlagsExtra.HasAnyFlag(CreatureFlagsExtra.DungeonBoss)); }
public override bool IsAffectedByDiminishingReturns() { return base.IsAffectedByDiminishingReturns() || GetCreatureTemplate().FlagsExtra.HasAnyFlag(CreatureFlagsExtra.AllDiminish); }
+29 -1
View File
@@ -74,7 +74,7 @@ namespace Game.Entities
public uint MaxGold;
public string AIName;
public uint MovementType;
public InhabitType InhabitType;
public CreatureMovementData Movement;
public float HoverHeight;
public float ModHealth;
public float ModHealthExtra;
@@ -347,6 +347,34 @@ namespace Game.Entities
public CreatureData() : base(SpawnObjectType.Creature) { }
}
public class CreatureMovementData
{
public CreatureGroundMovementType Ground;
public CreatureFlightMovementType Flight;
public bool Swim;
public bool Rooted;
public CreatureMovementData()
{
Ground = CreatureGroundMovementType.Run;
Flight = CreatureFlightMovementType.None;
Swim = true;
Rooted = false;
}
bool IsGroundAllowed() { return Ground != CreatureGroundMovementType.None; }
bool IsSwimAllowed() { return Swim; }
bool IsFlightAllowed() { return Flight != CreatureFlightMovementType.None; }
bool IsRooted() { return Rooted; }
public override string ToString()
{
return $"Ground: {Ground}, Swim: {Swim}, Flight: {Flight} {(Rooted ? ", Rooted" : "")}";
}
}
public class CreatureModelInfo
{
public float BoundingRadius;