From aac60cf9a8614abe545625478bc50c87fb3afbc1 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Tue, 6 Feb 2024 10:01:30 -0500 Subject: [PATCH] Core/Units: moved health and power ordering predicates from Unit header into CommonPredicates Port From (https://github.com/TrinityCore/TrinityCore/commit/2f6ed2c203b16a1d1e85f61a8b8e2cf3d1a4e784) --- Source/Game/AI/CoreAI/UnitAI.cs | 1 + Source/Game/Entities/Creature/Creature.cs | 5 +- Source/Game/Entities/Pet.cs | 2 +- Source/Game/Entities/Unit/Comparer.cs | 66 ------------------- Source/Game/Miscellaneous/CommonPredicates.cs | 65 ++++++++++++++++-- Source/Game/Spells/Spell.cs | 1 + Source/Scripts/Spells/Generic.cs | 9 +-- Source/Scripts/Spells/Item.cs | 1 + Source/Scripts/Spells/Paladin.cs | 1 + 9 files changed, 74 insertions(+), 77 deletions(-) delete mode 100644 Source/Game/Entities/Unit/Comparer.cs diff --git a/Source/Game/AI/CoreAI/UnitAI.cs b/Source/Game/AI/CoreAI/UnitAI.cs index 53acc48a7..8de22d3fd 100644 --- a/Source/Game/AI/CoreAI/UnitAI.cs +++ b/Source/Game/AI/CoreAI/UnitAI.cs @@ -4,6 +4,7 @@ using Framework.Constants; using Game.Combat; using Game.Entities; +using Game.Miscellaneous; using Game.Spells; using System; using System.Collections.Generic; diff --git a/Source/Game/Entities/Creature/Creature.cs b/Source/Game/Entities/Creature/Creature.cs index 423f69806..f07f3285f 100644 --- a/Source/Game/Entities/Creature/Creature.cs +++ b/Source/Game/Entities/Creature/Creature.cs @@ -2995,7 +2995,10 @@ namespace Game.Entities return base.GetName(locale); } - public virtual byte GetPetAutoSpellSize() { return 4; } + public virtual int GetPetAutoSpellSize() + { + return SharedConst.MaxSpellCharm; + } public virtual uint GetPetAutoSpellOnPos(byte pos) { diff --git a/Source/Game/Entities/Pet.cs b/Source/Game/Entities/Pet.cs index 2b2963d32..3a12d4ccd 100644 --- a/Source/Game/Entities/Pet.cs +++ b/Source/Game/Entities/Pet.cs @@ -1497,7 +1497,7 @@ namespace Game.Entities public override bool IsLoading() { return m_loading; } - public override byte GetPetAutoSpellSize() { return (byte)m_autospells.Count; } + public override int GetPetAutoSpellSize() { return m_autospells.Count; } public override uint GetPetAutoSpellOnPos(byte pos) { if (pos >= m_autospells.Count) diff --git a/Source/Game/Entities/Unit/Comparer.cs b/Source/Game/Entities/Unit/Comparer.cs deleted file mode 100644 index 23b3c2205..000000000 --- a/Source/Game/Entities/Unit/Comparer.cs +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (c) CypherCore All rights reserved. -// Licensed under the GNU GENERAL PUBLIC LICENSE. See LICENSE file in the project root for full license information. - -using Framework.Constants; -using System; -using System.Collections.Generic; - -namespace Game.Entities -{ - public class PowerPctOrderPred : IComparer - { - public PowerPctOrderPred(PowerType power, bool ascending = true) - { - m_power = power; - m_ascending = ascending; - } - - public int Compare(WorldObject objA, WorldObject objB) - { - Unit a = objA.ToUnit(); - Unit b = objB.ToUnit(); - float rA = a != null ? a.GetPowerPct(m_power) : 0.0f; - float rB = b != null ? b.GetPowerPct(m_power) : 0.0f; - return Convert.ToInt32(m_ascending ? rA < rB : rA > rB); - } - - PowerType m_power; - bool m_ascending; - } - - public class HealthPctOrderPred : IComparer - { - public HealthPctOrderPred(bool ascending = true) - { - m_ascending = ascending; - } - - public int Compare(WorldObject objA, WorldObject objB) - { - Unit a = objA.ToUnit(); - Unit b = objB.ToUnit(); - float rA = a.GetMaxHealth() != 0 ? a.GetHealth() / (float)a.GetMaxHealth() : 0.0f; - float rB = b.GetMaxHealth() != 0 ? b.GetHealth() / (float)b.GetMaxHealth() : 0.0f; - return Convert.ToInt32(m_ascending ? rA < rB : rA > rB); - } - - bool m_ascending; - } - - public class ObjectDistanceOrderPred : IComparer - { - public ObjectDistanceOrderPred(WorldObject pRefObj, bool ascending = true) - { - m_refObj = pRefObj; - m_ascending = ascending; - } - - public int Compare(WorldObject pLeft, WorldObject pRight) - { - return (m_ascending ? m_refObj.GetDistanceOrder(pLeft, pRight) : !m_refObj.GetDistanceOrder(pLeft, pRight)) ? 1 : 0; - } - - WorldObject m_refObj; - bool m_ascending; - } -} diff --git a/Source/Game/Miscellaneous/CommonPredicates.cs b/Source/Game/Miscellaneous/CommonPredicates.cs index 5816f198e..62a8293cb 100644 --- a/Source/Game/Miscellaneous/CommonPredicates.cs +++ b/Source/Game/Miscellaneous/CommonPredicates.cs @@ -1,12 +1,10 @@ // Copyright (c) CypherCore All rights reserved. // Licensed under the GNU GENERAL PUBLIC LICENSE. See LICENSE file in the project root for full license information. +using Framework.Constants; +using Game.Entities; using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Game.Entities; namespace Game.Miscellaneous { @@ -15,7 +13,7 @@ namespace Game.Miscellaneous { WorldObject _victim; - public IsVictimOf(Unit attacker) + public IsVictimOf(Unit attacker) { _victim = attacker?.GetVictim(); } @@ -25,4 +23,61 @@ namespace Game.Miscellaneous return obj != null && (_victim == obj); } } + + public class PowerPctOrderPred : IComparer + { + public PowerPctOrderPred(PowerType power, bool ascending = true) + { + m_power = power; + m_ascending = ascending; + } + + public int Compare(WorldObject objA, WorldObject objB) + { + Unit a = objA.ToUnit(); + Unit b = objB.ToUnit(); + float rA = a != null ? a.GetPowerPct(m_power) : 0.0f; + float rB = b != null ? b.GetPowerPct(m_power) : 0.0f; + return Convert.ToInt32(m_ascending ? rA < rB : rA > rB); + } + + PowerType m_power; + bool m_ascending; + } + + public class HealthPctOrderPred : IComparer + { + public HealthPctOrderPred(bool ascending = true) + { + m_ascending = ascending; + } + + public int Compare(WorldObject objA, WorldObject objB) + { + Unit a = objA.ToUnit(); + Unit b = objB.ToUnit(); + float rA = a.GetMaxHealth() != 0 ? a.GetHealth() / (float)a.GetMaxHealth() : 0.0f; + float rB = b.GetMaxHealth() != 0 ? b.GetHealth() / (float)b.GetMaxHealth() : 0.0f; + return Convert.ToInt32(m_ascending ? rA < rB : rA > rB); + } + + bool m_ascending; + } + + public class ObjectDistanceOrderPred : IComparer + { + public ObjectDistanceOrderPred(WorldObject pRefObj, bool ascending = true) + { + m_refObj = pRefObj; + m_ascending = ascending; + } + + public int Compare(WorldObject pLeft, WorldObject pRight) + { + return (m_ascending ? m_refObj.GetDistanceOrder(pLeft, pRight) : !m_refObj.GetDistanceOrder(pLeft, pRight)) ? 1 : 0; + } + + WorldObject m_refObj; + bool m_ascending; + } } diff --git a/Source/Game/Spells/Spell.cs b/Source/Game/Spells/Spell.cs index 440284b62..c61517759 100644 --- a/Source/Game/Spells/Spell.cs +++ b/Source/Game/Spells/Spell.cs @@ -11,6 +11,7 @@ using Game.DataStorage; using Game.Entities; using Game.Loots; using Game.Maps; +using Game.Miscellaneous; using Game.Movement; using Game.Networking.Packets; using Game.Scripting; diff --git a/Source/Scripts/Spells/Generic.cs b/Source/Scripts/Spells/Generic.cs index 3443d20f3..3d35250c4 100644 --- a/Source/Scripts/Spells/Generic.cs +++ b/Source/Scripts/Spells/Generic.cs @@ -6,6 +6,7 @@ using Framework.Dynamic; using Game.DataStorage; using Game.Entities; using Game.Maps; +using Game.Miscellaneous; using Game.Networking.Packets; using Game.Scripting; using Game.Spells; @@ -76,10 +77,10 @@ namespace Scripts.Spells.Generic uint spellId = SharedConst.GetFirstSchoolInMask(eventInfo.GetSchoolMask()) switch { SpellSchools.Fire => SpellGenAdaptiveWardingFire, - SpellSchools.Nature => SpellGenAdaptiveWardingNature, - SpellSchools.Frost => SpellGenAdaptiveWardingFrost, - SpellSchools.Shadow => SpellGenAdaptiveWardingShadow, - SpellSchools.Arcane => SpellGenAdaptiveWardingArcane, + SpellSchools.Nature => SpellGenAdaptiveWardingNature, + SpellSchools.Frost => SpellGenAdaptiveWardingFrost, + SpellSchools.Shadow => SpellGenAdaptiveWardingShadow, + SpellSchools.Arcane => SpellGenAdaptiveWardingArcane, _ => 0 }; diff --git a/Source/Scripts/Spells/Item.cs b/Source/Scripts/Spells/Item.cs index ca3717a32..4546f25f5 100644 --- a/Source/Scripts/Spells/Item.cs +++ b/Source/Scripts/Spells/Item.cs @@ -7,6 +7,7 @@ using Game.BattleGrounds; using Game.DataStorage; using Game.Entities; using Game.Loots; +using Game.Miscellaneous; using Game.Scripting; using Game.Spells; using System; diff --git a/Source/Scripts/Spells/Paladin.cs b/Source/Scripts/Spells/Paladin.cs index 6bc5166c1..d84277cd8 100644 --- a/Source/Scripts/Spells/Paladin.cs +++ b/Source/Scripts/Spells/Paladin.cs @@ -6,6 +6,7 @@ using Framework.Dynamic; using Game.AI; using Game.DataStorage; using Game.Entities; +using Game.Miscellaneous; using Game.Scripting; using Game.Spells; using System;