Eluna add new hook (need to think where to place this) and corrected Power functions

This commit is contained in:
Rochet2
2014-07-09 21:18:20 +03:00
parent 965d511d52
commit dc8afa45b2
5 changed files with 72 additions and 127 deletions

View File

@@ -1272,6 +1272,22 @@ void Eluna::OnUpdate(Map* map, uint32 diff)
EVENT_EXECUTE(0);
ENDCALL();
}
void Eluna::OnRemove(Map* map, Creature* creature)
{
EVENT_BEGIN(ServerEventBindings, MAP_EVENT_ON_REMOVE_CREATURE, return);
Push(L, map);
Push(L, creature);
ENTRY_EXECUTE(0);
ENDCALL();
}
void Eluna::OnRemove(Map* map, GameObject* gameobject)
{
EVENT_BEGIN(ServerEventBindings, MAP_EVENT_ON_REMOVE_GAMEOBJECT, return);
Push(L, map);
Push(L, gameobject);
ENTRY_EXECUTE(0);
ENDCALL();
}
// creature
bool Eluna::OnDummyEffect(Unit* pCaster, uint32 spellId, SpellEffIndex effIndex, Creature* pTarget)

View File

@@ -86,6 +86,9 @@ namespace HookMgr
// AddOns
ADDON_EVENT_ON_MESSAGE = 30, // (event, sender, type, prefix, msg, target) - target can be nil/whisper_target/guild/group/channel
MAP_EVENT_ON_REMOVE_CREATURE = 31, // (event, map, creature)
MAP_EVENT_ON_REMOVE_GAMEOBJECT = 32, // (event, map, gameobject)
SERVER_EVENT_COUNT
};

View File

@@ -675,6 +675,8 @@ public:
void OnPlayerEnter(Map* map, Player* player);
void OnPlayerLeave(Map* map, Player* player);
void OnUpdate(Map* map, uint32 diff);
void OnRemove(Map* map, Creature* creature);
void OnRemove(Map* map, GameObject* gameobject);
/* World */
void OnOpenStateChange(bool open);
@@ -1063,13 +1065,9 @@ public:
{
T* obj = Eluna::CHECKOBJ<T>(L, 1); // get self
if (obj)
{
lua_pushfstring(L, "%s: (%p)", tname, obj);
return 1;
}
lua_pushnil(L);
lua_replace(L, 1);
luaL_tolstring(L, 1, NULL);
else
lua_pushstring(L, "nil");
return 1;
}
};

View File

@@ -194,12 +194,12 @@ ElunaRegister<Unit> UnitMethods[] =
{ "GetHealth", &LuaUnit::GetHealth }, // :GetHealth()
{ "GetDisplayId", &LuaUnit::GetDisplayId }, // :GetDisplayId()
{ "GetNativeDisplayId", &LuaUnit::GetNativeDisplayId }, // :GetNativeDisplayId()
{ "GetPower", &LuaUnit::GetPower }, // :GetPower(index) - returns power at index. Index can be omitted
{ "GetMaxPower", &LuaUnit::GetMaxPower }, // :GetMaxPower(index) - returns power at index. Index can be omitted
{ "GetPowerType", &LuaUnit::GetPowerType }, // :GetPowerType() - Returns the power type
{ "GetPower", &LuaUnit::GetPower }, // :GetPower([type]) - returns power for power type. type can be omitted
{ "GetMaxPower", &LuaUnit::GetMaxPower }, // :GetMaxPower([type]) - returns max power for power type. type can be omitted
{ "GetPowerType", &LuaUnit::GetPowerType }, // :GetPowerType() - Returns the power type tye unit uses
{ "GetMaxHealth", &LuaUnit::GetMaxHealth }, // :GetMaxHealth()
{ "GetHealthPct", &LuaUnit::GetHealthPct }, // :GetHealthPct()
{ "GetPowerPct", &LuaUnit::GetPowerPct }, // :GetPowerPct(power_id)
{ "GetPowerPct", &LuaUnit::GetPowerPct }, // :GetPowerPct([type]) - returns power percent for power type. type can be omitted
{ "GetGender", &LuaUnit::GetGender }, // :GetGender() - returns the gender where male = 0 female = 1
{ "GetRace", &LuaUnit::GetRace }, // :GetRace()
{ "GetClass", &LuaUnit::GetClass }, // :GetClass()
@@ -238,8 +238,9 @@ ElunaRegister<Unit> UnitMethods[] =
{ "SetLevel", &LuaUnit::SetLevel }, // :SetLevel(amount)
{ "SetHealth", &LuaUnit::SetHealth }, // :SetHealth(amount)
{ "SetMaxHealth", &LuaUnit::SetMaxHealth }, // :SetMaxHealth(amount)
{ "SetPower", &LuaUnit::SetPower }, // :SetPower(index, amount)
{ "SetMaxPower", &LuaUnit::SetMaxPower }, // :SetMaxPower(index, amount)
{ "SetPower", &LuaUnit::SetPower }, // :SetPower([type,] amount)
{ "SetMaxPower", &LuaUnit::SetMaxPower }, // :SetMaxPower([type,] amount)
{ "SetPowerType", &LuaUnit::SetPowerType }, // :SetPowerType(type)
{ "SetDisplayId", &LuaUnit::SetDisplayId }, // :SetDisplayId(id)
{ "SetNativeDisplayId", &LuaUnit::SetNativeDisplayId }, // :SetNativeDisplayId(id)
{ "SetFacing", &LuaUnit::SetFacing }, // :SetFacing(o) - Sets the Unit facing to arg

View File

@@ -549,81 +549,46 @@ namespace LuaUnit
return 1;
}
Powers PowerSelectorHelper(lua_State* L, Unit* unit, int powerType = -1)
{
if (powerType == -1)
return unit->getPowerType();
if (powerType < 0 || powerType >= int(MAX_POWERS))
luaL_argerror(L, 2, "valid Powers expected");
return (Powers)powerType;
}
int GetPower(lua_State* L, Unit* unit)
{
int type = Eluna::CHECKVAL<int>(L, 2, -1);
if (type == -1)
{
Powers power = PowerSelectorHelper(L, unit, type);
switch (unit->getClass())
{
case 1:
type = POWER_RAGE;
break;
case 4:
type = POWER_ENERGY;
break;
#if (!defined(TBC) && !defined(CLASSIC))
case 6:
type = POWER_RUNIC_POWER;
break;
#endif
case 2:
case 3:
case 5:
case 7:
case 8:
case 9:
case 11:
type = POWER_MANA;
break;
default:
type = POWER_MANA;
}
}
else if (type < 0 || type >= int(MAX_POWERS))
return luaL_argerror(L, 2, "valid Powers expected");
Eluna::Push(L, unit->GetPower((Powers)type));
Eluna::Push(L, unit->GetPower(power));
return 1;
}
int GetMaxPower(lua_State* L, Unit* unit)
{
int type = Eluna::CHECKVAL<int>(L, 2, -1);
if (type == -1)
{
Powers power = PowerSelectorHelper(L, unit, type);
switch (unit->getClass())
Eluna::Push(L, unit->GetMaxPower(power));
return 1;
}
int GetPowerPct(lua_State* L, Unit* unit)
{
case 1:
type = POWER_RAGE;
break;
case 4:
type = POWER_ENERGY;
break;
#if (!defined(TBC) && !defined(CLASSIC))
case 6:
type = POWER_RUNIC_POWER;
break;
int type = Eluna::CHECKVAL<int>(L, 2, -1);
Powers power = PowerSelectorHelper(L, unit, type);
#if (!defined(TRINITY) && defined(WOTLK))
float percent = ((float)unit->GetPower(power) / (float)unit->GetMaxPower(power)) * 100.0f;
#else
float percent = ((float)unit->GetPower(power) / (float)unit->GetMaxPower(power)) * 100.0f;
#endif
case 2:
case 3:
case 5:
case 7:
case 8:
case 9:
case 11:
type = POWER_MANA;
break;
default:
type = POWER_MANA;
}
}
else if (type < 0 || type >= int(MAX_POWERS))
return luaL_argerror(L, 2, "valid Powers expected");
Eluna::Push(L, unit->GetMaxPower((Powers)type));
Eluna::Push(L, percent);
return 1;
}
@@ -653,17 +618,6 @@ namespace LuaUnit
return 1;
}
int GetPowerPct(lua_State* L, Unit* unit)
{
#if (!defined(TRINITY) && defined(WOTLK))
float percent = (unit->GetPower(unit->GetPowerType()) / unit->GetMaxPower(unit->GetPowerType())) * 100;
#else
float percent = (unit->GetPower(unit->getPowerType()) / unit->GetMaxPower(unit->getPowerType())) * 100;
#endif
Eluna::Push(L, percent);
return 1;
}
int GetGender(lua_State* L, Unit* unit)
{
Eluna::Push(L, unit->getGender());
@@ -933,57 +887,30 @@ namespace LuaUnit
int SetPower(lua_State* L, Unit* unit)
{
int type = Eluna::CHECKVAL<int>(L, 2);
int type = Eluna::CHECKVAL<int>(L, 2, -1);
uint32 amt = Eluna::CHECKVAL<uint32>(L, 3);
Powers power = PowerSelectorHelper(L, unit, type);
switch (type)
{
case POWER_MANA:
unit->SetPower(POWER_MANA, amt);
break;
case POWER_RAGE:
unit->SetPower(POWER_RAGE, amt);
break;
case POWER_ENERGY:
unit->SetPower(POWER_ENERGY, amt);
break;
#if (!defined(TBC) && !defined(CLASSIC))
case POWER_RUNIC_POWER:
unit->SetMaxPower(POWER_RUNIC_POWER, amt);
break;
#endif
default:
return luaL_argerror(L, 2, "valid Powers expected");
break;
}
unit->SetPower(power, amt);
return 0;
}
int SetMaxPower(lua_State* L, Unit* unit)
{
int type = Eluna::CHECKVAL<int>(L, 2);
int type = Eluna::CHECKVAL<int>(L, 2, -1);
uint32 amt = Eluna::CHECKVAL<uint32>(L, 3);
Powers power = PowerSelectorHelper(L, unit, type);
switch (type)
{
case POWER_MANA:
unit->SetMaxPower(POWER_MANA, amt);
break;
case POWER_RAGE:
unit->SetMaxPower(POWER_RAGE, amt);
break;
case POWER_ENERGY:
unit->SetMaxPower(POWER_ENERGY, amt);
break;
#if (!defined(TBC) && !defined(CLASSIC))
case POWER_RUNIC_POWER:
unit->SetMaxPower(POWER_RUNIC_POWER, amt);
break;
#endif
default:
return luaL_argerror(L, 2, "valid Powers expected");
break;
unit->SetMaxPower(power, amt);
return 0;
}
int SetPowerType(lua_State* L, Unit* unit)
{
uint32 type = Eluna::CHECKVAL<uint32>(L, 2);
if (type >= int(MAX_POWERS))
return luaL_argerror(L, 2, "valid Powers expected");
unit->setPowerType((Powers)type);
return 0;
}