Skip to content

Commit

Permalink
Add stat modifier unit methods for MaNGOS
Browse files Browse the repository at this point in the history
Co-Authored-By: Foe <[email protected]>
  • Loading branch information
Niam5 and Foereaper committed Sep 2, 2024
1 parent 88e788a commit 9bdef8c
Showing 1 changed file with 68 additions and 3 deletions.
71 changes: 68 additions & 3 deletions methods/Mangos/UnitMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -2423,6 +2423,71 @@ 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]
*
* <pre>
* enum UnitModifierFlatType
* {
* BASE_VALUE = 0,
* TOTAL_VALUE = 1
* };
* </pre>
*
* @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<uint32>(2);
uint8 modType = E->CHECKVAL<uint8>(3);
float value = E->CHECKVAL<float>(4);
bool apply = E->CHECKVAL<bool>(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]
*
* <pre>
* enum UnitModifierPctType
* {
* BASE_PCT = 0,
* TOTAL_PCT = 1
* };
* </pre>
*
* @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<uint32>(2);
uint8 modType = E->CHECKVAL<uint8>(3);
float value = E->CHECKVAL<float>(4);
UnitModifierType type = (modType == 0) ? BASE_PCT : TOTAL_PCT;

unit->HandleStatModifier(UnitMods(UNIT_MOD_STAT_START + statType), (UnitModifierType)type, value, true);
return 0;
}

ElunaRegister<Unit> UnitMethods[] =
{
// Getters
Expand Down Expand Up @@ -2554,6 +2619,7 @@ namespace LuaUnit
#else
{ "IsOnVehicle", METHOD_REG_NONE },
#endif
{ "CanModifyStats", &LuaUnit::CanModifyStats },

// Other
{ "AddAura", &LuaUnit::AddAura },
Expand Down Expand Up @@ -2606,6 +2672,8 @@ namespace LuaUnit
#else
{ "MoveJump", METHOD_REG_NONE },
#endif
{ "AddFlatStatModifier", &LuaUnit::AddFlatStatModifier },
{ "AddPctStatModifier", &LuaUnit::AddPctStatModifier },

// Not implemented mehtods
{ "GetVehicle", METHOD_REG_NONE }, // not implemented
Expand All @@ -2622,9 +2690,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

0 comments on commit 9bdef8c

Please sign in to comment.