From 88e788a36081be1c55794409786a40ffa6dae328 Mon Sep 17 00:00:00 2001 From: Niam5 Date: Mon, 2 Sep 2024 15:28:16 -0700 Subject: [PATCH] Add stat modifier unit methods for VMaNGOS Co-Authored-By: Foe --- methods/VMangos/UnitMethods.h | 71 +++++++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 3 deletions(-) diff --git a/methods/VMangos/UnitMethods.h b/methods/VMangos/UnitMethods.h index 64f7c84c71..6680a0734f 100644 --- a/methods/VMangos/UnitMethods.h +++ b/methods/VMangos/UnitMethods.h @@ -2394,6 +2394,71 @@ namespace LuaUnit return 1; }*/ + /** + * Returns whether or not the [Unit] can have stat modifiers applied. + * + * @return bool canModifyStats + */ + int CanModifyStats(Eluna* E, Unit* unit) + { + E->Push(unit->CanModifyStats()); + return 1; + } + + /** + * Modifies a flat amount of a specific stat of the [Unit] + * + *
+    * enum UnitModifierFlatType
+    * {
+    *      BASE_VALUE = 0,
+    *      TOTAL_VALUE = 1
+    * };
+    * 
+ * + * @param uint32 statType : The stat to modify + * @param [UnitModifierFlatType] modType : The type of modifier to apply + * @param float value : The value to apply to the stat + * @param bool apply = true : True applies a positive modifier, false applies a negative + */ + int AddFlatStatModifier(Eluna* E, Unit* unit) + { + uint32 statType = E->CHECKVAL(2); + uint8 modType = E->CHECKVAL(3); + float value = E->CHECKVAL(4); + bool apply = E->CHECKVAL(5, true); + UnitModifierType type = (modType == 0) ? BASE_VALUE : TOTAL_VALUE; + + unit->HandleStatModifier(UnitMods(UNIT_MOD_STAT_START + statType), (UnitModifierType)type, value, apply); + return 0; + } + + /** + * Modifies a percentage amount of a specific stat of the [Unit] + * + *
+    * enum UnitModifierPctType
+    * {
+    *      BASE_PCT = 0,
+    *      TOTAL_PCT = 1
+    * };
+    * 
+ * + * @param uint32 statType : The stat to modify + * @param [UnitModifierPctType] modType : The type of modifier to apply + * @param float value : The value to apply to the stat + */ + int AddPctStatModifier(Eluna* E, Unit* unit) + { + uint32 statType = E->CHECKVAL(2); + uint8 modType = E->CHECKVAL(3); + float value = E->CHECKVAL(4); + UnitModifierType type = (modType == 0) ? BASE_PCT : TOTAL_PCT; + + unit->HandleStatModifier(UnitMods(UNIT_MOD_STAT_START + statType), (UnitModifierType)type, value, true); + return 0; + } + ElunaRegister UnitMethods[] = { // Getters @@ -2504,6 +2569,7 @@ namespace LuaUnit { "HasAura", &LuaUnit::HasAura }, { "IsCasting", &LuaUnit::IsCasting }, { "IsStandState", &LuaUnit::IsStandState }, + { "CanModifyStats", &LuaUnit::CanModifyStats }, // Other { "AddAura", &LuaUnit::AddAura }, @@ -2546,6 +2612,8 @@ namespace LuaUnit { "DealDamage", &LuaUnit::DealDamage }, { "DealHeal", &LuaUnit::DealHeal }, { "AddThreat", &LuaUnit::AddThreat }, + { "AddFlatStatModifier", &LuaUnit::AddFlatStatModifier }, + { "AddPctStatModifier", &LuaUnit::AddPctStatModifier }, // Not used in VMaNGOS { "GetVehicleKit", METHOD_REG_NONE }, @@ -2572,9 +2640,6 @@ namespace LuaUnit { "DisableMelee", METHOD_REG_NONE }, // not implemented { "SummonGuardian", METHOD_REG_NONE }, // not implemented { "SetImmuneTo", METHOD_REG_NONE }, // not implemented - { "CanModifyStats", METHOD_REG_NONE }, // not implemented - { "AddFlatStatModifier", METHOD_REG_NONE }, // not implemented - { "AddPctStatModifier", METHOD_REG_NONE } // not implemented }; }; #endif