Core/Spells Handle auras 328 & 396 (SPELL_AURA_TRIGGER_SPELL_ON_POWER_*)
Port From (https://github.com/TrinityCore/TrinityCore/commit/56e9560661adca81fc1e9a297cb6823cf7a6cb22)
This commit is contained in:
@@ -13,7 +13,7 @@
|
|||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Framework.Constants
|
namespace Framework.Constants
|
||||||
{
|
{
|
||||||
@@ -576,4 +576,10 @@ namespace Framework.Constants
|
|||||||
Level4 = 3,
|
Level4 = 3,
|
||||||
TauntImmune = 4
|
TauntImmune = 4
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum AuraTriggerOnPowerChangeDirection
|
||||||
|
{
|
||||||
|
Gain = 0,
|
||||||
|
Loss = 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -171,6 +171,11 @@ public static class MathFunctions
|
|||||||
return (ulong)(value * pct / 100.0f);
|
return (ulong)(value * pct / 100.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static float GetPctOf(float value, float max)
|
||||||
|
{
|
||||||
|
return value / max * 100.0f;
|
||||||
|
}
|
||||||
|
|
||||||
public static int RoundToInterval(ref int num, dynamic floor, dynamic ceil)
|
public static int RoundToInterval(ref int num, dynamic floor, dynamic ceil)
|
||||||
{
|
{
|
||||||
return num = (int)Math.Min(Math.Max(num, floor), ceil);
|
return num = (int)Math.Min(Math.Max(num, floor), ceil);
|
||||||
|
|||||||
@@ -603,6 +603,7 @@ namespace Game.Entities
|
|||||||
if (maxPower < val)
|
if (maxPower < val)
|
||||||
val = maxPower;
|
val = maxPower;
|
||||||
|
|
||||||
|
int oldPower = m_unitData.Power[(int)powerIndex];
|
||||||
SetUpdateFieldValue(ref m_values.ModifyValue(m_unitData).ModifyValue(m_unitData.Power, (int)powerIndex), val);
|
SetUpdateFieldValue(ref m_values.ModifyValue(m_unitData).ModifyValue(m_unitData.Power, (int)powerIndex), val);
|
||||||
|
|
||||||
if (IsInWorld)
|
if (IsInWorld)
|
||||||
@@ -613,6 +614,8 @@ namespace Game.Entities
|
|||||||
SendMessageToSet(packet, IsTypeId(TypeId.Player));
|
SendMessageToSet(packet, IsTypeId(TypeId.Player));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TriggerOnPowerChangeAuras(powerType, oldPower, val);
|
||||||
|
|
||||||
// group update
|
// group update
|
||||||
if (IsTypeId(TypeId.Player))
|
if (IsTypeId(TypeId.Player))
|
||||||
{
|
{
|
||||||
@@ -658,6 +661,48 @@ namespace Game.Entities
|
|||||||
public virtual uint GetPowerIndex(PowerType powerType) { return 0; }
|
public virtual uint GetPowerIndex(PowerType powerType) { return 0; }
|
||||||
public float GetPowerPct(PowerType powerType) { return GetMaxPower(powerType) != 0 ? 100.0f* GetPower(powerType) / GetMaxPower(powerType) : 0.0f; }
|
public float GetPowerPct(PowerType powerType) { return GetMaxPower(powerType) != 0 ? 100.0f* GetPower(powerType) / GetMaxPower(powerType) : 0.0f; }
|
||||||
|
|
||||||
|
void TriggerOnPowerChangeAuras(PowerType power, int oldVal, int newVal)
|
||||||
|
{
|
||||||
|
var effects = GetAuraEffectsByType(AuraType.TriggerSpellOnPowerPct);
|
||||||
|
var effectsAmount = GetAuraEffectsByType(AuraType.TriggerSpellOnPowerAmount);
|
||||||
|
effects.AddRange(effectsAmount);
|
||||||
|
|
||||||
|
foreach (AuraEffect effect in effects)
|
||||||
|
{
|
||||||
|
if (effect.GetMiscValue() == (int)power)
|
||||||
|
{
|
||||||
|
uint effectAmount = (uint)effect.GetAmount();
|
||||||
|
uint triggerSpell = effect.GetSpellEffectInfo().TriggerSpell;
|
||||||
|
|
||||||
|
float oldValueCheck = oldVal;
|
||||||
|
float newValueCheck = newVal;
|
||||||
|
|
||||||
|
if (effect.GetAuraType() == AuraType.TriggerSpellOnPowerPct)
|
||||||
|
{
|
||||||
|
int maxPower = GetMaxPower(power);
|
||||||
|
oldValueCheck = MathFunctions.GetPctOf(oldVal, maxPower);
|
||||||
|
newValueCheck = MathFunctions.GetPctOf(newVal, maxPower);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ((AuraTriggerOnPowerChangeDirection)effect.GetMiscValueB())
|
||||||
|
{
|
||||||
|
case AuraTriggerOnPowerChangeDirection.Gain:
|
||||||
|
if (oldValueCheck >= effect.GetAmount() || newValueCheck < effectAmount)
|
||||||
|
continue;
|
||||||
|
break;
|
||||||
|
case AuraTriggerOnPowerChangeDirection.Loss:
|
||||||
|
if (oldValueCheck <= effect.GetAmount() || newValueCheck > effectAmount)
|
||||||
|
continue;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
CastSpell(this, triggerSpell, true, null, effect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void ApplyResilience(Unit victim, ref uint damage)
|
public void ApplyResilience(Unit victim, ref uint damage)
|
||||||
{
|
{
|
||||||
// player mounted on multi-passenger mount is also classified as vehicle
|
// player mounted on multi-passenger mount is also classified as vehicle
|
||||||
|
|||||||
@@ -4698,6 +4698,64 @@ namespace Game.Spells
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[AuraEffectHandler(AuraType.TriggerSpellOnPowerPct)]
|
||||||
|
void HandleTriggerSpellOnPowerPercent(AuraApplication aurApp, AuraEffectHandleModes mode, bool apply)
|
||||||
|
{
|
||||||
|
if (!mode.HasAnyFlag(AuraEffectHandleModes.Real) || !apply)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Unit target = aurApp.GetTarget();
|
||||||
|
|
||||||
|
int effectAmount = GetAmount();
|
||||||
|
uint triggerSpell = GetSpellEffectInfo().TriggerSpell;
|
||||||
|
float powerAmountPct = MathFunctions.GetPctOf(target.GetPower((PowerType)GetMiscValue()), target.GetMaxPower((PowerType)GetMiscValue()));
|
||||||
|
|
||||||
|
switch ((AuraTriggerOnPowerChangeDirection)GetMiscValueB())
|
||||||
|
{
|
||||||
|
case AuraTriggerOnPowerChangeDirection.Gain:
|
||||||
|
if (powerAmountPct < effectAmount)
|
||||||
|
return;
|
||||||
|
break;
|
||||||
|
case AuraTriggerOnPowerChangeDirection.Loss:
|
||||||
|
if (powerAmountPct > effectAmount)
|
||||||
|
return;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
target.CastSpell(target, triggerSpell, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
[AuraEffectHandler(AuraType.TriggerSpellOnPowerAmount)]
|
||||||
|
void HandleTriggerSpellOnPowerAmount(AuraApplication aurApp, AuraEffectHandleModes mode, bool apply)
|
||||||
|
{
|
||||||
|
if (!mode.HasAnyFlag(AuraEffectHandleModes.Real) || !apply)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Unit target = aurApp.GetTarget();
|
||||||
|
|
||||||
|
int effectAmount = GetAmount();
|
||||||
|
uint triggerSpell = GetSpellEffectInfo().TriggerSpell;
|
||||||
|
float powerAmount = target.GetPower((PowerType)GetMiscValue());
|
||||||
|
|
||||||
|
switch ((AuraTriggerOnPowerChangeDirection)GetMiscValueB())
|
||||||
|
{
|
||||||
|
case AuraTriggerOnPowerChangeDirection.Gain:
|
||||||
|
if (powerAmount < effectAmount)
|
||||||
|
return;
|
||||||
|
break;
|
||||||
|
case AuraTriggerOnPowerChangeDirection.Loss:
|
||||||
|
if (powerAmount > effectAmount)
|
||||||
|
return;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
target.CastSpell(target, triggerSpell, true);
|
||||||
|
}
|
||||||
|
|
||||||
[AuraEffectHandler(AuraType.OpenStable)]
|
[AuraEffectHandler(AuraType.OpenStable)]
|
||||||
void HandleAuraOpenStable(AuraApplication aurApp, AuraEffectHandleModes mode, bool apply)
|
void HandleAuraOpenStable(AuraApplication aurApp, AuraEffectHandleModes mode, bool apply)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user