Skip to content

Commit

Permalink
Add stat modifier unit methods for VMaNGOS
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 89891d4 commit 88e788a
Showing 1 changed file with 68 additions and 3 deletions.
71 changes: 68 additions & 3 deletions methods/VMangos/UnitMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -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]
*
* <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 @@ -2504,6 +2569,7 @@ namespace LuaUnit
{ "HasAura", &LuaUnit::HasAura },
{ "IsCasting", &LuaUnit::IsCasting },
{ "IsStandState", &LuaUnit::IsStandState },
{ "CanModifyStats", &LuaUnit::CanModifyStats },

// Other
{ "AddAura", &LuaUnit::AddAura },
Expand Down Expand Up @@ -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 },
Expand All @@ -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

0 comments on commit 88e788a

Please sign in to comment.