Core/Units: moved health and power ordering predicates from Unit header into CommonPredicates
Port From (https://github.com/TrinityCore/TrinityCore/commit/2f6ed2c203b16a1d1e85f61a8b8e2cf3d1a4e784)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
// Copyright (c) CypherCore <http://github.com/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<WorldObject>
|
||||
{
|
||||
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<WorldObject>
|
||||
{
|
||||
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<WorldObject>
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,10 @@
|
||||
// Copyright (c) CypherCore <http://github.com/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
|
||||
{
|
||||
@@ -25,4 +23,61 @@ namespace Game.Miscellaneous
|
||||
return obj != null && (_victim == obj);
|
||||
}
|
||||
}
|
||||
|
||||
public class PowerPctOrderPred : IComparer<WorldObject>
|
||||
{
|
||||
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<WorldObject>
|
||||
{
|
||||
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<WorldObject>
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user