From 0cba9fc4c3829318aec20bd2b1c266c3aae97cd7 Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Wed, 19 Jul 2017 19:53:18 +0300 Subject: [PATCH] Change SetPower arguments Add modify power https://github.com/ElunaLuaEngine/Eluna/issues/189 --- LuaFunctions.cpp | 1 + UnitMethods.h | 36 +++++++++++++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/LuaFunctions.cpp b/LuaFunctions.cpp index bfe0616..051a5e0 100644 --- a/LuaFunctions.cpp +++ b/LuaFunctions.cpp @@ -320,6 +320,7 @@ ElunaRegister UnitMethods[] = #endif { "SetWaterWalk", &LuaUnit::SetWaterWalk }, { "SetStandState", &LuaUnit::SetStandState }, + { "ModifyPower", &LuaUnit::ModifyPower }, // Boolean { "IsAlive", &LuaUnit::IsAlive }, diff --git a/UnitMethods.h b/UnitMethods.h index e601378..f4d8d57 100644 --- a/UnitMethods.h +++ b/UnitMethods.h @@ -1556,19 +1556,49 @@ namespace LuaUnit * POWER_HEALTH = 0xFFFFFFFE // (-2 as signed value) * }; * + * @param uint32 amount : new power amount * @param int type = -1 : a valid power type from [Powers] or -1 for the [Unit]'s current power type - * @param uint32 power : new power amount */ int SetPower(lua_State* L, Unit* unit) { - int type = Eluna::CHECKVAL(L, 2, -1); - uint32 amt = Eluna::CHECKVAL(L, 3); + uint32 amt = Eluna::CHECKVAL(L, 2); + int type = Eluna::CHECKVAL(L, 3, -1); Powers power = PowerSelectorHelper(L, unit, type); unit->SetPower(power, amt); return 0; } + /** + * modifies the [Unit]'s power amount for the given power type. + * + * enum Powers + * { + * POWER_MANA = 0, + * POWER_RAGE = 1, + * POWER_FOCUS = 2, + * POWER_ENERGY = 3, + * POWER_HAPPINESS = 4, + * POWER_RUNE = 5, + * POWER_RUNIC_POWER = 6, + * MAX_POWERS = 7, + * POWER_ALL = 127, // default for class? + * POWER_HEALTH = 0xFFFFFFFE // (-2 as signed value) + * }; + * + * @param int32 amount : amount to modify + * @param int type = -1 : a valid power type from [Powers] or -1 for the [Unit]'s current power type + */ + int ModifyPower(lua_State* L, Unit* unit) + { + int32 amt = Eluna::CHECKVAL(L, 2); + int type = Eluna::CHECKVAL(L, 3, -1); + Powers power = PowerSelectorHelper(L, unit, type); + + unit->ModifyPower(power, amt); + return 0; + } + /** * Sets the [Unit]'s max power amount for the given power type. *