Skip to content

Commit

Permalink
Add stat modifier unit methods for Trinitycore
Browse files Browse the repository at this point in the history
closes #495
  • Loading branch information
Foereaper committed Sep 1, 2024
1 parent 74bcdc8 commit f45e651
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 3 deletions.
5 changes: 4 additions & 1 deletion methods/CMangos/UnitMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 4 additions & 1 deletion methods/Mangos/UnitMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
66 changes: 66 additions & 0 deletions methods/TrinityCore/UnitMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -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]
*
* <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);

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]
*
* <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);

unit->ApplyStatPctModifier(UnitMods(UNIT_MOD_STAT_START + statType), (UnitModifierPctType)modType, value);
return 0;
}

/*int SummonGuardian(Eluna* E, Unit* unit)
{
uint32 entry = E->CHECKVAL<uint32>(2);
Expand Down Expand Up @@ -2670,6 +2733,7 @@ namespace LuaUnit
{ "IsCasting", &LuaUnit::IsCasting },
{ "IsStandState", &LuaUnit::IsStandState },
{ "IsOnVehicle", &LuaUnit::IsOnVehicle },
{ "CanModifyStats", &LuaUnit::CanModifyStats },

// Other
{ "AddAura", &LuaUnit::AddAura },
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion methods/VMangos/UnitMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f45e651

Please sign in to comment.