From 7ed94d3e7a65d55f74cb4857efc6dadb781cede1 Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Mon, 7 Apr 2014 01:48:45 +0300 Subject: [PATCH] Update eluna --- GroupMethods.h | 13 +++++++++++++ LuaEngine.cpp | 20 ++++++++++---------- LuaFunctions.cpp | 2 +- ObjectMethods.h | 9 --------- PlayerMethods.h | 36 ++++++++++++++++-------------------- UnitMethods.h | 27 +++++++++------------------ 6 files changed, 49 insertions(+), 58 deletions(-) diff --git a/GroupMethods.h b/GroupMethods.h index 39c5c31..0708394 100644 --- a/GroupMethods.h +++ b/GroupMethods.h @@ -222,6 +222,19 @@ namespace LuaGroup return 0; } + int SetTargetIcon(lua_State* L, Group* group) + { + uint8 icon = sEluna->CHECKVAL(L, 2); + uint64 target = sEluna->CHECKVAL(L, 3); + uint64 setter = sEluna->CHECKVAL(L, 4, 0); + + if (icon >= TARGETICONCOUNT) + return luaL_argerror(L, 2, "valid target icon expected"); + + group->SetTargetIcon(icon, setter, target); + return 0; + } + /*int ConvertToLFG(lua_State* L, Group* group) // TODO: Implementation { group->ConvertToLFG(); diff --git a/LuaEngine.cpp b/LuaEngine.cpp index 9f04e4d..2476655 100644 --- a/LuaEngine.cpp +++ b/LuaEngine.cpp @@ -423,7 +423,7 @@ template<> float Eluna::CHECKVAL(lua_State* L, int narg) } template<> float Eluna::CHECKVAL(lua_State* L, int narg, float def) { - if (lua_isnoneornil(L, narg) || lua_isnumber(L, narg)) + if (lua_isnoneornil(L, narg) || !lua_isnumber(L, narg)) return def; return luaL_optnumber(L, narg, def); } @@ -433,7 +433,7 @@ template<> double Eluna::CHECKVAL(lua_State* L, int narg) } template<> double Eluna::CHECKVAL(lua_State* L, int narg, double def) { - if (lua_isnoneornil(L, narg) || lua_isnumber(L, narg)) + if (lua_isnoneornil(L, narg) || !lua_isnumber(L, narg)) return def; return luaL_optnumber(L, narg, def); } @@ -443,7 +443,7 @@ template<> int8 Eluna::CHECKVAL(lua_State* L, int narg) } template<> int8 Eluna::CHECKVAL(lua_State* L, int narg, int8 def) { - if (lua_isnoneornil(L, narg) || lua_isnumber(L, narg)) + if (lua_isnoneornil(L, narg) || !lua_isnumber(L, narg)) return def; return luaL_optint(L, narg, def); } @@ -453,7 +453,7 @@ template<> uint8 Eluna::CHECKVAL(lua_State* L, int narg) } template<> uint8 Eluna::CHECKVAL(lua_State* L, int narg, uint8 def) { - if (lua_isnoneornil(L, narg) || lua_isnumber(L, narg)) + if (lua_isnoneornil(L, narg) || !lua_isnumber(L, narg)) return def; return luaL_optunsigned(L, narg, def); } @@ -463,7 +463,7 @@ template<> int16 Eluna::CHECKVAL(lua_State* L, int narg) } template<> int16 Eluna::CHECKVAL(lua_State* L, int narg, int16 def) { - if (lua_isnoneornil(L, narg) || lua_isnumber(L, narg)) + if (lua_isnoneornil(L, narg) || !lua_isnumber(L, narg)) return def; return luaL_optint(L, narg, def); } @@ -473,7 +473,7 @@ template<> uint16 Eluna::CHECKVAL(lua_State* L, int narg) } template<> uint16 Eluna::CHECKVAL(lua_State* L, int narg, uint16 def) { - if (lua_isnoneornil(L, narg) || lua_isnumber(L, narg)) + if (lua_isnoneornil(L, narg) || !lua_isnumber(L, narg)) return def; return luaL_optunsigned(L, narg, def); } @@ -483,7 +483,7 @@ template<> uint32 Eluna::CHECKVAL(lua_State* L, int narg) } template<> uint32 Eluna::CHECKVAL(lua_State* L, int narg, uint32 def) { - if (lua_isnoneornil(L, narg) || lua_isnumber(L, narg)) + if (lua_isnoneornil(L, narg) || !lua_isnumber(L, narg)) return def; return luaL_optunsigned(L, narg, def); } @@ -493,7 +493,7 @@ template<> int32 Eluna::CHECKVAL(lua_State* L, int narg) } template<> int32 Eluna::CHECKVAL(lua_State* L, int narg, int32 def) { - if (lua_isnoneornil(L, narg) || lua_isnumber(L, narg)) + if (lua_isnoneornil(L, narg) || !lua_isnumber(L, narg)) return def; return luaL_optlong(L, narg, def); } @@ -503,7 +503,7 @@ template<> const char* Eluna::CHECKVAL(lua_State* L, int narg) } template<> const char* Eluna::CHECKVAL(lua_State* L, int narg, const char* def) { - if (lua_isnoneornil(L, narg) || !lua_isstring(L, narg) || lua_isnumber(L, narg)) + if (lua_isnoneornil(L, narg) || !lua_isstring(L, narg)) return def; return luaL_optstring(L, narg, def); } @@ -513,7 +513,7 @@ template<> std::string Eluna::CHECKVAL(lua_State* L, int narg) } template<> std::string Eluna::CHECKVAL(lua_State* L, int narg, std::string def) { - if (lua_isnoneornil(L, narg) || !lua_isstring(L, narg) || lua_isnumber(L, narg)) + if (lua_isnoneornil(L, narg) || !lua_isstring(L, narg)) return def; return luaL_optstring(L, narg, def.c_str()); } diff --git a/LuaFunctions.cpp b/LuaFunctions.cpp index 6bf9222..8fac5c0 100644 --- a/LuaFunctions.cpp +++ b/LuaFunctions.cpp @@ -144,7 +144,6 @@ ElunaRegister ObjectMethods[] = { "RemoveFlag", &LuaObject::RemoveFlag }, // :RemoveFlag(index, flag) { "RemoveUInt64Value", &LuaObject::RemoveUInt64Value }, // :RemoveUInt64Value(index, value) { "AddUInt64Value", &LuaObject::AddUInt64Value }, // :AddUInt64Value(index, value) - { "ApplyModUInt64Value", &LuaObject::ApplyModUInt64Value }, // :ApplyModUInt64Value(index, value, apply) { NULL, NULL }, }; @@ -980,6 +979,7 @@ ElunaRegister GroupMethods[] = // Setters { "SetLeader", &LuaGroup::ChangeLeader }, // :SetLeader(Player) - Sets the player as the new leader { "SetMembersGroup", &LuaGroup::ChangeMembersGroup }, // :ChangeMembersGroup(player, subGroup) - Changes the member's subgroup + { "SetTargetIcon", &LuaGroup::SetTargetIcon }, // :SetTargetIcon(icon, targetguid[, setterguid]) - Sets target's icon for group. target 0 to clear. // Boolean { "IsLeader", &LuaGroup::IsLeader }, // :IsLeader(GUID) diff --git a/ObjectMethods.h b/ObjectMethods.h index 8d3b2c9..dc5b633 100644 --- a/ObjectMethods.h +++ b/ObjectMethods.h @@ -241,14 +241,5 @@ namespace LuaObject obj->AddUInt64Value(index, value); return 0; } - - int ApplyModUInt64Value(lua_State* L, Object* obj) - { - uint16 index = sEluna->CHECKVAL(L, 2); - int32 value = sEluna->CHECKVAL(L, 3); - bool apply = sEluna->CHECKVAL(L, 4); - obj->ApplyModUInt64Value(index, value, apply); - return 0; - } }; #endif diff --git a/PlayerMethods.h b/PlayerMethods.h index ef60974..480e199 100644 --- a/PlayerMethods.h +++ b/PlayerMethods.h @@ -2028,17 +2028,17 @@ namespace LuaPlayer int SendAreaTriggerMessage(lua_State* L, Player* player) { - const char* msg = sEluna->CHECKVAL(L, 2); - if (std::string(msg).length() > 0) - player->GetSession()->SendAreaTriggerMessage(msg); + std::string msg = sEluna->CHECKVAL(L, 2); + if (msg.length() > 0) + player->GetSession()->SendAreaTriggerMessage(msg.c_str()); return 0; } int SendNotification(lua_State* L, Player* player) { - const char* msg = sEluna->CHECKVAL(L, 2); - if (std::string(msg).length() > 0) - player->GetSession()->SendNotification(msg); + std::string msg = sEluna->CHECKVAL(L, 2); + if (msg.length() > 0) + player->GetSession()->SendNotification(msg.c_str()); return 0; } @@ -2069,20 +2069,16 @@ namespace LuaPlayer std::string fullmsg = prefix + "\t" + message; - // Needs a custom built packet since TC doesnt send guid - WorldPacket* data = new WorldPacket(); - uint32 messageLength = (uint32)strlen(fullmsg.c_str()) + 1; - data->Initialize(SMSG_MESSAGECHAT, 100); - *data << (uint8)channel; - *data << LANG_ADDON; - *data << player->GetGUID(); - *data << uint32(0); - *data << player->GetGUID(); - *data << messageLength; - *data << fullmsg; - *data << uint8(0); - player->GetSession()->SendPacket(data); - + WorldPacket data(SMSG_MESSAGECHAT, 100); + data << uint8(channel); + data << int32(LANG_ADDON); + data << uint64(player->GetGUID()); + data << uint32(0); + data << uint64(receiver->GetGUID()); + data << uint32(fullmsg.length() + 1); + data << fullmsg; + data << uint8(0); + receiver->GetSession()->SendPacket(&data); return 0; } diff --git a/UnitMethods.h b/UnitMethods.h index f97c799..841184d 100644 --- a/UnitMethods.h +++ b/UnitMethods.h @@ -1242,26 +1242,17 @@ namespace LuaUnit { uint8 type = sEluna->CHECKVAL(L, 2); uint32 lang = sEluna->CHECKVAL(L, 3); - const char* msg = sEluna->CHECKVAL(L, 4); + std::string msg = sEluna->CHECKVAL(L, 4); Player* target = sEluna->CHECKOBJ(L, 5); - if (type == CHAT_MSG_CHANNEL) - return 0; - WorldPacket* data = new WorldPacket(); - uint32 messageLength = (uint32)strlen(msg) + 1; - data->Initialize(SMSG_MESSAGECHAT, 100); - *data << (uint8)type; - *data << lang; - *data << unit->GetGUIDLow(); - *data << uint32(0); - *data << unit->GetGUIDLow(); - *data << messageLength; - *data << msg; - if (unit->ToPlayer() && type != CHAT_MSG_WHISPER_INFORM && type != CHAT_MSG_DND && type != CHAT_MSG_AFK) - *data << uint8(unit->ToPlayer()->GetChatTag()); - else - *data << uint8(0); - target->GetSession()->SendPacket(data); + if (type >= MAX_CHAT_MSG_TYPE) + return luaL_argerror(L, 2, "valid ChatMsg expected"); + if (lang >= LANGUAGES_COUNT) + return luaL_argerror(L, 3, "valid Language expected"); + + WorldPacket data; + ChatHandler::BuildChatPacket(data, ChatMsg(type), Language(lang), unit, target, msg); + target->GetSession()->SendPacket(&data); return 0; }