From f45e65128d410ce5dcf8ea5bacd10f3353b28a55 Mon Sep 17 00:00:00 2001 From: Foereaper Date: Sun, 1 Sep 2024 16:15:14 +0200 Subject: [PATCH] Add stat modifier unit methods for Trinitycore closes #495 --- methods/CMangos/UnitMethods.h | 5 ++- methods/Mangos/UnitMethods.h | 5 ++- methods/TrinityCore/UnitMethods.h | 66 +++++++++++++++++++++++++++++++ methods/VMangos/UnitMethods.h | 5 ++- 4 files changed, 78 insertions(+), 3 deletions(-) diff --git a/methods/CMangos/UnitMethods.h b/methods/CMangos/UnitMethods.h index cc885de581..6c890a9f95 100644 --- a/methods/CMangos/UnitMethods.h +++ b/methods/CMangos/UnitMethods.h @@ -2604,7 +2604,10 @@ namespace LuaUnit { "RemoveBindSightAuras", METHOD_REG_NONE }, // not implemented { "RemoveCharmAuras", METHOD_REG_NONE }, // not implemented { "DisableMelee", METHOD_REG_NONE }, // not implemented - { "SummonGuardian", METHOD_REG_NONE } // not implemented + { "SummonGuardian", METHOD_REG_NONE }, // not implemented + { "CanModifyStats", METHOD_REG_NONE }, // not implemented + { "AddFlatStatModifier", METHOD_REG_NONE }, // not implemented + { "AddPctStatModifier", METHOD_REG_NONE } // not implemented }; }; #endif diff --git a/methods/Mangos/UnitMethods.h b/methods/Mangos/UnitMethods.h index e91cb427e9..1449f6463d 100644 --- a/methods/Mangos/UnitMethods.h +++ b/methods/Mangos/UnitMethods.h @@ -2621,7 +2621,10 @@ namespace LuaUnit { "RemoveCharmAuras", METHOD_REG_NONE }, // not implemented { "DisableMelee", METHOD_REG_NONE }, // not implemented { "SummonGuardian", METHOD_REG_NONE }, // not implemented - { "SetImmuneTo", 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 diff --git a/methods/TrinityCore/UnitMethods.h b/methods/TrinityCore/UnitMethods.h index 379887a9d6..aa2bc0d63d 100644 --- a/methods/TrinityCore/UnitMethods.h +++ b/methods/TrinityCore/UnitMethods.h @@ -2506,6 +2506,69 @@ namespace LuaUnit return 0; } + /** + * 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); + + unit->HandleStatFlatModifier(UnitMods(UNIT_MOD_STAT_START + statType), (UnitModifierFlatType)modType, 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); + + unit->ApplyStatPctModifier(UnitMods(UNIT_MOD_STAT_START + statType), (UnitModifierPctType)modType, value); + return 0; + } + /*int SummonGuardian(Eluna* E, Unit* unit) { uint32 entry = E->CHECKVAL(2); @@ -2670,6 +2733,7 @@ namespace LuaUnit { "IsCasting", &LuaUnit::IsCasting }, { "IsStandState", &LuaUnit::IsStandState }, { "IsOnVehicle", &LuaUnit::IsOnVehicle }, + { "CanModifyStats", &LuaUnit::CanModifyStats }, // Other { "AddAura", &LuaUnit::AddAura }, @@ -2717,6 +2781,8 @@ namespace LuaUnit { "MoveClear", &LuaUnit::MoveClear }, { "DealDamage", &LuaUnit::DealDamage }, { "DealHeal", &LuaUnit::DealHeal }, + { "AddFlatStatModifier", &LuaUnit::AddFlatStatModifier }, + { "AddPctStatModifier", &LuaUnit::AddPctStatModifier }, // Not implemented methods { "SummonGuardian", METHOD_REG_NONE } // not implemented diff --git a/methods/VMangos/UnitMethods.h b/methods/VMangos/UnitMethods.h index 90a56abdb5..64f7c84c71 100644 --- a/methods/VMangos/UnitMethods.h +++ b/methods/VMangos/UnitMethods.h @@ -2571,7 +2571,10 @@ namespace LuaUnit { "RemoveCharmAuras", METHOD_REG_NONE }, // not implemented { "DisableMelee", METHOD_REG_NONE }, // not implemented { "SummonGuardian", METHOD_REG_NONE }, // not implemented - { "SetImmuneTo", 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