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); EVENT_EXECUTE(0);
ENDCALL(); 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 // creature
bool Eluna::OnDummyEffect(Unit* pCaster, uint32 spellId, SpellEffIndex effIndex, Creature* pTarget) bool Eluna::OnDummyEffect(Unit* pCaster, uint32 spellId, SpellEffIndex effIndex, Creature* pTarget)

View File

@@ -86,6 +86,9 @@ namespace HookMgr
// AddOns // AddOns
ADDON_EVENT_ON_MESSAGE = 30, // (event, sender, type, prefix, msg, target) - target can be nil/whisper_target/guild/group/channel 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 SERVER_EVENT_COUNT
}; };

View File

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

View File

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

View File

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