diff --git a/CreatureMethods.h b/CreatureMethods.h index cdff83c..ec498a6 100644 --- a/CreatureMethods.h +++ b/CreatureMethods.h @@ -324,15 +324,12 @@ namespace LuaCreature uint32 targetType = sEluna->CHECKVAL(L, 2); bool playerOnly = sEluna->CHECKVAL(L, 3, false); uint32 position = sEluna->CHECKVAL(L, 4, 0); - float dist = sEluna->CHECKVAL(L, 5, 0.0f); + float dist = sEluna->CHECKVAL(L, 5, -1.0f); int32 aura = sEluna->CHECKVAL(L, 6, 0); ThreatList const& threatlist = creature->getThreatManager().getThreatList(); if (position >= threatlist.size()) - { - sEluna->Push(L); return 1; - } std::list targetList; for (ThreatList::const_iterator itr = threatlist.begin(); itr != threatlist.end(); ++itr) @@ -352,10 +349,7 @@ namespace LuaCreature } if (position >= targetList.size()) - { - sEluna->Push(L); return 1; - } if (targetType == SELECT_TARGET_NEAREST || targetType == SELECT_TARGET_FARTHEST) targetList.sort(Eluna::ObjectDistanceOrderPred(creature)); @@ -368,7 +362,6 @@ namespace LuaCreature std::list::const_iterator itr = targetList.begin(); std::advance(itr, position); sEluna->Push(L, *itr); - return 1; } case SELECT_TARGET_FARTHEST: case SELECT_TARGET_BOTTOMAGGRO: @@ -376,20 +369,17 @@ namespace LuaCreature std::list::reverse_iterator ritr = targetList.rbegin(); std::advance(ritr, position); sEluna->Push(L, *ritr); - return 1; } case SELECT_TARGET_RANDOM: { std::list::const_iterator itr = targetList.begin(); std::advance(itr, urand(position, targetList.size() - 1)); sEluna->Push(L, *itr); - return 1; } default: luaL_argerror(L, 2, "SelectAggroTarget expected"); } - sEluna->Push(L); return 1; } diff --git a/GameObjectMethods.h b/GameObjectMethods.h index 0cecd60..ada097e 100644 --- a/GameObjectMethods.h +++ b/GameObjectMethods.h @@ -24,36 +24,24 @@ namespace LuaGameObject int IsSpawned(lua_State* L, GameObject* go) { - if (!go || !go->IsInWorld()) - sEluna->Push(L, false); - else - sEluna->Push(L, go->isSpawned()); + sEluna->Push(L, go->isSpawned()); return 1; } int IsTransport(lua_State* L, GameObject* go) { - if (!go || !go->IsInWorld()) - sEluna->Push(L, false); - else - sEluna->Push(L, go->IsTransport()); + sEluna->Push(L, go->IsTransport()); return 1; } int IsActive(lua_State* L, GameObject* go) { - if (!go || !go->IsInWorld()) - sEluna->Push(L, false); - else - sEluna->Push(L, go->isActiveObject()); + sEluna->Push(L, go->isActiveObject()); return 1; } /*int IsDestructible(lua_State* L, GameObject* go) // TODO: Implementation core side { - if (!go || !go->IsInWorld()) - sEluna->Push(L, false); - else sEluna->Push(L, go->IsDestructibleBuilding()); return 1; }*/ @@ -61,27 +49,18 @@ namespace LuaGameObject /* GETTERS */ int GetDisplayId(lua_State* L, GameObject* go) { - if (!go || !go->IsInWorld()) - return 0; - sEluna->Push(L, go->GetDisplayId()); return 1; } int GetGoState(lua_State* L, GameObject* go) { - if (!go || !go->IsInWorld()) - return 0; - sEluna->Push(L, go->GetGoState()); return 1; } int GetLootState(lua_State* L, GameObject* go) { - if (!go || !go->IsInWorld()) - return 0; - sEluna->Push(L, go->getLootState()); return 1; } @@ -89,9 +68,6 @@ namespace LuaGameObject /* SETTERS */ int SetGoState(lua_State* L, GameObject* go) { - if (!go || !go->IsInWorld()) - return 0; - uint32 state = sEluna->CHECKVAL(L, 2, 0); if (state == 0) @@ -106,9 +82,6 @@ namespace LuaGameObject int SetLootState(lua_State* L, GameObject* go) { - if (!go || !go->IsInWorld()) - return 0; - uint32 state = sEluna->CHECKVAL(L, 2, 0); if (state == 0) @@ -132,11 +105,8 @@ namespace LuaGameObject int RemoveFromWorld(lua_State* L, GameObject* go) { - if (!go || !go->IsInWorld()) - return 0; - - bool del = sEluna->CHECKVAL(L, 2, false); - if (del) + bool deldb = sEluna->CHECKVAL(L, 2, false); + if (deldb) go->DeleteFromDB(); go->RemoveFromWorld(); return 0; @@ -153,8 +123,6 @@ namespace LuaGameObject functionRef = sEluna->m_EventMgr.AddEvent(&go->m_Events, functionRef, delay, repeats, go); if (functionRef) sEluna->Push(L, functionRef); - else - sEluna->Push(L); return 1; } @@ -173,9 +141,6 @@ namespace LuaGameObject int UseDoorOrButton(lua_State* L, GameObject* go) { - if (!go || !go->IsInWorld()) - return 0; - uint32 delay = sEluna->CHECKVAL(L, 2, 0); go->UseDoorOrButton(delay); diff --git a/GlobalMethods.h b/GlobalMethods.h index 5486bea..7b0b281 100644 --- a/GlobalMethods.h +++ b/GlobalMethods.h @@ -40,8 +40,6 @@ namespace LuaGlobalFunctions sEluna->Push(L, 2); #elif defined(CATA) sEluna->Push(L, 3); -#else - sEluna->Push(L); #endif return 1; } @@ -118,7 +116,7 @@ namespace LuaGlobalFunctions Map* map = sMapMgr->FindMap(mapID, instanceID); if (!map) - return 0; + return 1; lua_newtable(L); int tbl = lua_gettop(L); @@ -439,7 +437,7 @@ namespace LuaGlobalFunctions { const char* query = sEluna->CHECKVAL(L, 1); if (!query) - return 0; + return 1; QueryResult* result = NULL; #ifdef MANGOS @@ -450,7 +448,7 @@ namespace LuaGlobalFunctions result = new QueryResult(res); #endif if (!result) - return 0; + return 1; sEluna->Push(L, result); return 1; @@ -459,13 +457,16 @@ namespace LuaGlobalFunctions int WorldDBExecute(lua_State* L) { const char* query = sEluna->CHECKVAL(L, 1); - WorldDatabase.Execute(query); + if (query) + WorldDatabase.Execute(query); return 0; } int CharDBQuery(lua_State* L) { const char* query = sEluna->CHECKVAL(L, 1); + if (!query) + return 1; QueryResult* result = NULL; #ifdef MANGOS @@ -476,7 +477,7 @@ namespace LuaGlobalFunctions result = new QueryResult(res); #endif if (!result) - return 0; + return 1; sEluna->Push(L, result); return 1; @@ -485,7 +486,8 @@ namespace LuaGlobalFunctions int CharDBExecute(lua_State* L) { const char* query = sEluna->CHECKVAL(L, 1); - CharacterDatabase.Execute(query); + if (query) + CharacterDatabase.Execute(query); return 0; } @@ -511,7 +513,8 @@ namespace LuaGlobalFunctions int AuthDBExecute(lua_State* L) { const char* query = sEluna->CHECKVAL(L, 1); - LoginDatabase.Execute(query); + if (query) + LoginDatabase.Execute(query); return 0; } @@ -526,8 +529,6 @@ namespace LuaGlobalFunctions functionRef = sEluna->m_EventMgr.AddEvent(&sEluna->m_EventMgr.GlobalEvents, functionRef, delay, repeats); if (functionRef) sEluna->Push(L, functionRef); - else - sEluna->Push(L); return 1; } @@ -569,13 +570,13 @@ namespace LuaGlobalFunctions #if (!defined(TBC) && !defined(CLASSIC)) uint32 phase = sEluna->CHECKVAL(L, 11, PHASEMASK_NORMAL); if (!phase) - return 0; + return 1; #endif #ifdef MANGOS Map* map = sMapMgr->FindMap(mapID, instanceID); if (!map) - return 0; + return 1; if (spawntype == 1) // spawn creature { @@ -583,7 +584,7 @@ namespace LuaGlobalFunctions { CreatureInfo const* cinfo = ObjectMgr::GetCreatureTemplate(entry); if (!cinfo) - return 0; + return 1; #if (defined(TBC) || defined(CLASSIC)) CreatureCreatePos pos(map, x, y, z, o); @@ -594,12 +595,12 @@ namespace LuaGlobalFunctions // used guids from specially reserved range (can be 0 if no free values) uint32 lowguid = sObjectMgr->GenerateStaticCreatureLowGuid(); if (!lowguid) - return 0; + return 1; if (!pCreature->Create(lowguid, pos, cinfo)) { delete pCreature; - return 0; + return 1; } #ifdef TBC @@ -626,7 +627,7 @@ namespace LuaGlobalFunctions { CreatureInfo const* cinfo = ObjectMgr::GetCreatureTemplate(entry); if (!cinfo) - return 0; + return 1; TemporarySummon* pCreature = new TemporarySummon(ObjectGuid(uint64(0))); #if (defined(TBC) || defined(CLASSIC)) @@ -638,7 +639,7 @@ namespace LuaGlobalFunctions if (!pCreature->Create(map->GenerateLocalLowGuid(cinfo->GetHighGuid()), pos, cinfo, TEAM_NONE)) { delete pCreature; - return NULL; + return 1; } pCreature->SetRespawnCoord(pos); @@ -665,12 +666,12 @@ namespace LuaGlobalFunctions { const GameObjectInfo* gInfo = ObjectMgr::GetGameObjectInfo(entry); if (!gInfo) - return 0; + return 1; // used guids from specially reserved range (can be 0 if no free values) uint32 db_lowGUID = sObjectMgr->GenerateStaticGameObjectLowGuid(); if (!db_lowGUID) - return 0; + return 1; GameObject* pGameObj = new GameObject; #if (defined(TBC) || defined(CLASSIC)) @@ -680,7 +681,7 @@ namespace LuaGlobalFunctions #endif { delete pGameObj; - return 0; + return 1; } if (durorresptime) @@ -699,7 +700,7 @@ namespace LuaGlobalFunctions if (!pGameObj->LoadFromDB(db_lowGUID, map)) { delete pGameObj; - return false; + return 1; } // DEBUG_LOG(GetMangosString(LANG_GAMEOBJECT_CURRENT), gInfo->name, db_lowGUID, x, y, z, o); @@ -721,7 +722,7 @@ namespace LuaGlobalFunctions #endif { delete pGameObj; - return NULL; + return 1; } pGameObj->SetRespawnTime(durorresptime / IN_MILLISECONDS); @@ -735,7 +736,7 @@ namespace LuaGlobalFunctions #else Map* map = sMapMgr->FindMap(mapID, instanceID); if (!map) - return 0; + return 1; Position pos = { x, y, z, o }; @@ -747,7 +748,7 @@ namespace LuaGlobalFunctions if (!creature->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_UNIT), map, phase, entry, x, y, z, o)) { delete creature; - return 0; + return 1; } creature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), phase); @@ -756,7 +757,7 @@ namespace LuaGlobalFunctions if (!creature->LoadCreatureFromDB(db_lowguid, map)) { delete creature; - return 0; + return 1; } sObjectMgr->AddCreatureToGrid(db_lowguid, sObjectMgr->GetCreatureData(db_lowguid)); @@ -766,7 +767,7 @@ namespace LuaGlobalFunctions { TempSummon* creature = map->SummonCreature(entry, pos, NULL, durorresptime); if (!creature) - return 0; + return 1; if (durorresptime) creature->SetTempSummonType(TEMPSUMMON_TIMED_OR_DEAD_DESPAWN); @@ -783,10 +784,10 @@ namespace LuaGlobalFunctions { const GameObjectTemplate* objectInfo = sObjectMgr->GetGameObjectTemplate(entry); if (!objectInfo) - return 0; + return 1; if (objectInfo->displayId && !sGameObjectDisplayInfoStore.LookupEntry(objectInfo->displayId)) - return 0; + return 1; GameObject* object = new GameObject; uint32 lowguid = sObjectMgr->GenerateLowGuid(HIGHGUID_GAMEOBJECT); @@ -794,7 +795,7 @@ namespace LuaGlobalFunctions if (!object->Create(lowguid, objectInfo->entry, map, phase, x, y, z, o, 0.0f, 0.0f, 0.0f, 0.0f, 0, GO_STATE_READY)) { delete object; - return 0; + return 1; } if (durorresptime) @@ -809,7 +810,7 @@ namespace LuaGlobalFunctions if (!object->LoadGameObjectFromDB(lowguid, map)) { delete object; - return false; + return 1; } sObjectMgr->AddGameobjectToGrid(lowguid, sObjectMgr->GetGOData(lowguid)); @@ -820,7 +821,7 @@ namespace LuaGlobalFunctions return 1; } #endif - return 0; + return 1; } // CreatePacket(opcode, size) diff --git a/HookMgr.cpp b/HookMgr.cpp index 3785c60..519fc92 100644 --- a/HookMgr.cpp +++ b/HookMgr.cpp @@ -257,17 +257,6 @@ public: sEluna->ServerEventBindings.EndCall(); } - void OnMotdChange(std::string& newMotd) override - { - if (!sEluna->ServerEventBindings.HasEvents(WORLD_EVENT_ON_MOTD_CHANGE)) - return; - ELUNA_GUARD(); - sEluna->ServerEventBindings.BeginCall(WORLD_EVENT_ON_MOTD_CHANGE); - sEluna->Push(sEluna->L, newMotd); - sEluna->ServerEventBindings.ExecuteCall(); - sEluna->ServerEventBindings.EndCall(); - } - void OnShutdownInitiate(ShutdownExitCode code, ShutdownMask mask) override { if (!sEluna->ServerEventBindings.HasEvents(WORLD_EVENT_ON_SHUTDOWN_INIT)) @@ -592,41 +581,6 @@ void HookMgr::OnQuestAbandon(Player* pPlayer, uint32 questId) sEluna->PlayerEventBindings.EndCall(); } -void HookMgr::OnGmTicketCreate(Player* pPlayer, std::string& ticketText) -{ - if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_GM_TICKET_CREATE)) - return; - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_GM_TICKET_CREATE); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, ticketText); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); -} - -void HookMgr::OnGmTicketUpdate(Player* pPlayer, std::string& ticketText) -{ - if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_GM_TICKET_UPDATE)) - return; - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_GM_TICKET_UPDATE); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, ticketText); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); -} - -void HookMgr::OnGmTicketDelete(Player* pPlayer) -{ - if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_GM_TICKET_DELETE)) - return; - ELUNA_GUARD(); - sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_GM_TICKET_DELETE); - sEluna->Push(sEluna->L, pPlayer); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); -} - void HookMgr::OnEquip(Player* pPlayer, Item* pItem, uint8 bag, uint8 slot) { if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_EQUIP)) @@ -1565,21 +1519,6 @@ bool HookMgr::OnQuestAccept(Player* pPlayer, Creature* pCreature, Quest const* p return true; } -bool HookMgr::OnQuestSelect(Player* pPlayer, Creature* pCreature, Quest const* pQuest) -{ - int bind = sEluna->CreatureEventBindings.GetBind(pCreature->GetEntry(), CREATURE_EVENT_ON_QUEST_SELECT); - if (!bind) - return false; - ELUNA_GUARD(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_QUEST_SELECT); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pCreature); - sEluna->Push(sEluna->L, pQuest); - sEluna->ExecuteCall(4, 0); - return true; -} - bool HookMgr::OnQuestComplete(Player* pPlayer, Creature* pCreature, Quest const* pQuest) { int bind = sEluna->CreatureEventBindings.GetBind(pCreature->GetEntry(), CREATURE_EVENT_ON_QUEST_COMPLETE); @@ -1892,7 +1831,7 @@ struct ElunaCreatureAI : ScriptedAI // Enables use of MoveInLineOfSight bool IsVisible(Unit* who) const override { - return me->IsWithinLOSInMap(who); + return true } #endif diff --git a/HookMgr.h b/HookMgr.h index d3ecf50..929f50c 100644 --- a/HookMgr.h +++ b/HookMgr.h @@ -104,7 +104,7 @@ enum ServerEvents // World // Not implemented on mangos WORLD_EVENT_ON_OPEN_STATE_CHANGE = 8, // (event, open) WORLD_EVENT_ON_CONFIG_LOAD = 9, // (event, reload) - WORLD_EVENT_ON_MOTD_CHANGE = 10, // (event, newMOTD) + // UNUSED = 10, // (event) WORLD_EVENT_ON_SHUTDOWN_INIT = 11, // (event, code, mask) WORLD_EVENT_ON_SHUTDOWN_CANCEL = 12, // (event) WORLD_EVENT_ON_UPDATE = 13, // (event, diff) @@ -183,10 +183,10 @@ enum PlayerEvents PLAYER_EVENT_ON_REPOP = 35, // (event, player) PLAYER_EVENT_ON_RESURRECT = 36, // (event, player) PLAYER_EVENT_ON_LOOT_MONEY = 37, // (event, player, amount) - PLAYER_EVENT_ON_QUEST_ABANDON = 38, // (event, player, questId) // Not on TC - PLAYER_EVENT_ON_GM_TICKET_CREATE = 39, // (event, player, ticketText) // Not on TC - PLAYER_EVENT_ON_GM_TICKET_UPDATE = 40, // (event, player, ticketText) // Not on TC - PLAYER_EVENT_ON_GM_TICKET_DELETE = 41, // (event, player) // Not on TC + PLAYER_EVENT_ON_QUEST_ABANDON = 38, // (event, player, questId) + // UNUSED = 39, // (event, player) + // UNUSED = 40, // (event, player) + // UNUSED = 41, // (event, player) PLAYER_EVENT_ON_COMMAND = 42, // (event, player, command) - Can return false PLAYER_EVENT_COUNT @@ -267,12 +267,12 @@ enum CreatureEvents CREATURE_EVENT_ON_REACH_HOME = 24, // (event, creature) // UNUSED = 25, // (event, creature) CREATURE_EVENT_ON_CORPSE_REMOVED = 26, // (event, creature, respawndelay) - CREATURE_EVENT_ON_MOVE_IN_LOS = 27, // (event, creature, unit) + CREATURE_EVENT_ON_MOVE_IN_LOS = 27, // (event, creature, unit) // Doesnt actually check LOS // UNUSED = 28, // (event, creature) // UNUSED = 29, // (event, creature) CREATURE_EVENT_ON_DUMMY_EFFECT = 30, // (event, caster, spellid, effindex, creature) CREATURE_EVENT_ON_QUEST_ACCEPT = 31, // (event, player, creature, quest) - CREATURE_EVENT_ON_QUEST_SELECT = 32, // (event, player, creature, quest) + // UNUSED = 32, // (event, creature) CREATURE_EVENT_ON_QUEST_COMPLETE = 33, // (event, player, creature, quest) CREATURE_EVENT_ON_QUEST_REWARD = 34, // (event, player, creature, quest, opt) CREATURE_EVENT_ON_DIALOG_STATUS = 35, // (event, player, creature) @@ -339,9 +339,6 @@ public: void OnRepop(Player* pPlayer); void OnResurrect(Player* pPlayer); void OnQuestAbandon(Player* pPlayer, uint32 questId); - void OnGmTicketCreate(Player* pPlayer, std::string& ticketText); - void OnGmTicketUpdate(Player* pPlayer, std::string& ticketText); - void OnGmTicketDelete(Player* pPlayer); InventoryResult OnCanUseItem(const Player* pPlayer, uint32 itemEntry); void OnEngineRestart(); bool OnAddonMessage(Player* sender, uint32 type, std::string& msg, Player* receiver, Guild* guild, Group* group, Channel* channel); @@ -360,7 +357,6 @@ public: bool OnGossipSelect(Player* pPlayer, Creature* pCreature, uint32 sender, uint32 action); bool OnGossipSelectCode(Player* pPlayer, Creature* pCreature, uint32 sender, uint32 action, const char* code); bool OnQuestAccept(Player* pPlayer, Creature* pCreature, Quest const* pQuest); - bool OnQuestSelect(Player* pPlayer, Creature* pCreature, Quest const* pQuest); bool OnQuestComplete(Player* pPlayer, Creature* pCreature, Quest const* pQuest); bool OnQuestReward(Player* pPlayer, Creature* pCreature, Quest const* pQuest); uint32 GetDialogStatus(Player* pPlayer, Creature* pCreature); diff --git a/ItemMethods.h b/ItemMethods.h index 678d18b..ae1800c 100644 --- a/ItemMethods.h +++ b/ItemMethods.h @@ -136,12 +136,13 @@ namespace LuaItem return 1; } + /* int IsRefundExpired(lua_State* L, Item* item)// TODO: Implement core support { - /*sEluna->Push(L, item->IsRefundExpired()); - return 1;*/ - return 0; // Temp till supported + sEluna->Push(L, item->IsRefundExpired()); + return 1; } + */ /* GETTERS */ int GetItemLink(lua_State* L, Item* item) @@ -271,7 +272,7 @@ namespace LuaItem uint32 enchant_slot = sEluna->CHECKVAL(L, 2); if (enchant_slot >= MAX_INSPECTED_ENCHANTMENT_SLOT) - return 0; + return luaL_argerror(L, 2, "valid EnchantmentSlot expected"); sEluna->Push(L, item->GetEnchantmentId(EnchantmentSlot(enchant_slot))); return 1; diff --git a/LuaEngine.h b/LuaEngine.h index d1fb72c..dd128e6 100644 --- a/LuaEngine.h +++ b/LuaEngine.h @@ -122,6 +122,8 @@ enum SelectAggroTarget #define Opcodes OpcodesList #endif #else +#undef UNORDERED_MAP +#define UNORDERED_MAP std::unordered_map #ifndef CATA typedef uint64 ObjectGuid; #endif @@ -268,7 +270,18 @@ public: ElunaRegister* l = static_cast*>(lua_touserdata(L, lua_upvalueindex(1))); if (!obj) return 0; - return l->mfunc(L, obj); + int args = lua_gettop(L); + int expected = l->mfunc(L, obj); + args = lua_gettop(L) - args; + if (args <= 0 || args > expected) + { + if (args < 0 || args > expected) // Assert instead? + ELUNA_LOG_ERROR("[Eluna]: %s returned unexpected amount of arguments %i out of %i. Report to devs", l->name, args, expected); + return expected; + } + for (; args < expected; ++args) + lua_pushnil(L); + return expected; } static int tostringT(lua_State* L) @@ -455,11 +468,11 @@ class Eluna { public: friend class ScriptMgr; - friend class ACE_Singleton; + // friend class ACE_Singleton; lua_State* L; EventMgr m_EventMgr; - ACE_Recursive_Thread_Mutex lock; + // ACE_Recursive_Thread_Mutex lock; Eluna() { @@ -511,7 +524,7 @@ public: struct EntryBind { typedef std::map ElunaBindingMap; - typedef std::map ElunaEntryMap; + typedef UNORDERED_MAP ElunaEntryMap; ~EntryBind() { @@ -697,46 +710,7 @@ template<> Corpse* Eluna::CHECKOBJ(lua_State* L, int narg, bool error); #define sEluna ACE_Singleton::instance() #endif -/* -class FakeLock -{ -public: -static bool locked; -FakeLock() -{ -if (locked) -printf("ELUNA_GUARD CREATE\n"); -locked = true; -} -~FakeLock() -{ -if (!locked) -printf("ELUNA_GUARD DELETE\n"); -locked = false; -} -}; -class FakeRecursiveLock -{ -public: -static uint32 locked; -FakeRecursiveLock() -{ -++locked; -if (locked > 1) -printf("GUARD LOCK %u\n", locked); -} -~FakeRecursiveLock() -{ -if (!locked) -printf("GUARD FAULTY\n"); -else if (locked > 1) -printf("GUARD RELE %u\n", locked); ---locked; -} -}; -*/ -#define ELUNA_GUARD() \ - ACE_Guard< ACE_Recursive_Thread_Mutex > ELUNA_GUARD_OBJECT(sEluna->lock); +#define ELUNA_GUARD() // ACE_Guard< ACE_Recursive_Thread_Mutex > ELUNA_GUARD_OBJECT(sEluna->lock); class LuaTaxiMgr { diff --git a/LuaFunctions.cpp b/LuaFunctions.cpp index 4d954ff..11f9237 100644 --- a/LuaFunctions.cpp +++ b/LuaFunctions.cpp @@ -956,9 +956,6 @@ ElunaRegister QuestMethods[] = #endif { "IsRepeatable", &LuaQuest::IsRepeatable }, // :IsRepeatable() - Returns true or false if the quest is repeatable - // Setters - { "SetFlag", &LuaQuest::SetFlag }, // :SetFlag(flag) - Sets the flag of the quest by the specified flag - { NULL, NULL }, }; diff --git a/MapMethods.h b/MapMethods.h index a038dc2..2517a84 100644 --- a/MapMethods.h +++ b/MapMethods.h @@ -71,9 +71,8 @@ namespace LuaMap uint32 phasemask = sEluna->CHECKVAL(L, 4, 1); float z = map->GetHeight(phasemask, x, y, MAX_HEIGHT); #endif - if (z == INVALID_HEIGHT) - return 0; - sEluna->Push(L, z); + if (z != INVALID_HEIGHT) + sEluna->Push(L, z); return 1; } diff --git a/PlayerMethods.h b/PlayerMethods.h index 65795c4..2a41dfc 100644 --- a/PlayerMethods.h +++ b/PlayerMethods.h @@ -21,10 +21,9 @@ namespace LuaPlayer { uint32 talentId = sEluna->CHECKVAL(L, 2); uint8 spec = sEluna->CHECKVAL(L, 3); - if (spec >= MAX_TALENT_SPECS) - sEluna->Push(L, false); - else - sEluna->Push(L, player->HasTalent(talentId, spec)); + if (spec < MAX_TALENT_SPECS) + return 1; + sEluna->Push(L, player->HasTalent(talentId, spec)); return 1; } @@ -87,8 +86,6 @@ namespace LuaPlayer CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id); if (titleInfo) sEluna->Push(L, player->HasTitle(titleInfo)); - else - sEluna->Push(L, false); return 1; } #endif @@ -724,7 +721,7 @@ namespace LuaPlayer int GetGuildName(lua_State* L, Player* player) { if (!player->GetGuildId()) - return 0; + return 1; sEluna->Push(L, sGuildMgr->GetGuildNameById(player->GetGuildId())); return 1; } @@ -808,7 +805,7 @@ namespace LuaPlayer { uint8 slot = sEluna->CHECKVAL(L, 2); if (slot >= EQUIPMENT_SLOT_END) - return 0; + return 1; Item* item = player->GetItemByPos(INVENTORY_SLOT_BAG_0, slot); sEluna->Push(L, item); @@ -953,8 +950,6 @@ namespace LuaPlayer std::string accName; if (sAccountMgr->GetName(player->GetSession()->GetAccountId(), accName)) sEluna->Push(L, accName); - else - return 0; return 1; } @@ -1474,9 +1469,8 @@ namespace LuaPlayer int SendListInventory(lua_State* L, Player* player) { WorldObject* obj = sEluna->CHECKOBJ(L, 2); - uint32 entry = sEluna->CHECKVAL(L, 3, 0); - player->GetSession()->SendListInventory(obj->GET_GUID()), entry; + player->GetSession()->SendListInventory(obj->GET_GUID()); return 0; } @@ -1802,20 +1796,20 @@ namespace LuaPlayer uint32 slot = sEluna->CHECKVAL(L, 3); if (slot >= INVENTORY_SLOT_BAG_END) - return 0; + return 1; if (!item) { uint32 entry = sEluna->CHECKVAL(L, 2); item = Item::CreateItem(entry, 1, player); if (!item) - return 0; + return 1; InventoryResult result = player->CanEquipItem(slot, dest, item, false); if (result != EQUIP_ERR_OK) { delete item; - return 0; + return 1; } player->ItemAddedQuestCheck(entry, 1); #if (!defined(TBC) && !defined(CLASSIC)) @@ -1826,7 +1820,7 @@ namespace LuaPlayer { InventoryResult result = player->CanEquipItem(slot, dest, item, false); if (result != EQUIP_ERR_OK) - return 0; + return 1; player->RemoveItem(item->GetBagSlot(), item->GetSlot(), true); } @@ -1905,7 +1899,7 @@ namespace LuaPlayer }; static const uint32 skillsSize = sizeof(skillsArray) / sizeof(*skillsArray); - for (int i = 0; i < skillsSize; ++i) + for (uint32 i = 0; i < skillsSize; ++i) { if (player->HasSkill(skillsArray[i])) player->UpdateSkill(skillsArray[i], step); diff --git a/QueryMethods.h b/QueryMethods.h index cb7d1c9..c93ed9f 100644 --- a/QueryMethods.h +++ b/QueryMethods.h @@ -18,12 +18,11 @@ namespace LuaQuery int IsNull(lua_State* L, QueryResult* result) { uint32 col = sEluna->CHECKVAL(L, 2); - if (!result || col >= RESULT->GetFieldCount()) - sEluna->Push(L, true); - else #ifdef MANGOS + if (col < RESULT->GetFieldCount()) sEluna->Push(L, RESULT->Fetch()[col].IsNULL()); #else + if (col < RESULT->GetFieldCount()) sEluna->Push(L, RESULT->Fetch()[col].IsNull()); #endif return 1; @@ -32,33 +31,23 @@ namespace LuaQuery /* GETTERS */ int GetColumnCount(lua_State* L, QueryResult* result) { - if (!result) - sEluna->Push(L, 0); - else - sEluna->Push(L, RESULT->GetFieldCount()); + sEluna->Push(L, RESULT->GetFieldCount()); return 1; } int GetRowCount(lua_State* L, QueryResult* result) { - if (!result) - sEluna->Push(L, 0); + if (RESULT->GetRowCount() > (uint32)-1) + sEluna->Push(L, (uint32)-1); else - { - if (RESULT->GetRowCount() > (uint32)-1) - sEluna->Push(L, (uint32)-1); - else - sEluna->Push(L, RESULT->GetRowCount()); - } + sEluna->Push(L, RESULT->GetRowCount()); return 1; } int GetBool(lua_State* L, QueryResult* result) { uint32 col = sEluna->CHECKVAL(L, 2); - if (!result || col >= RESULT->GetFieldCount()) - sEluna->Push(L, false); - else + if (col < RESULT->GetFieldCount()) sEluna->Push(L, RESULT->Fetch()[col].GetBool()); return 1; } @@ -66,9 +55,7 @@ namespace LuaQuery int GetUInt8(lua_State* L, QueryResult* result) { uint32 col = sEluna->CHECKVAL(L, 2); - if (!result || col >= RESULT->GetFieldCount()) - sEluna->Push(L, 0); - else + if (col < RESULT->GetFieldCount()) sEluna->Push(L, RESULT->Fetch()[col].GetUInt8()); return 1; } @@ -76,9 +63,7 @@ namespace LuaQuery int GetUInt16(lua_State* L, QueryResult* result) { uint32 col = sEluna->CHECKVAL(L, 2); - if (!result || col >= RESULT->GetFieldCount()) - sEluna->Push(L, 0); - else + if (col < RESULT->GetFieldCount()) sEluna->Push(L, RESULT->Fetch()[col].GetUInt16()); return 1; } @@ -86,9 +71,7 @@ namespace LuaQuery int GetUInt32(lua_State* L, QueryResult* result) { uint32 col = sEluna->CHECKVAL(L, 2); - if (!result || col >= RESULT->GetFieldCount()) - sEluna->Push(L, 0); - else + if (col < RESULT->GetFieldCount()) sEluna->Push(L, RESULT->Fetch()[col].GetUInt32()); return 1; } @@ -96,9 +79,7 @@ namespace LuaQuery int GetUInt64(lua_State* L, QueryResult* result) { uint32 col = sEluna->CHECKVAL(L, 2); - if (!result || col >= RESULT->GetFieldCount()) - sEluna->Push(L, 0); - else + if (col < RESULT->GetFieldCount()) sEluna->Push(L, RESULT->Fetch()[col].GetUInt64()); return 1; } @@ -106,9 +87,7 @@ namespace LuaQuery int GetInt8(lua_State* L, QueryResult* result) { uint32 col = sEluna->CHECKVAL(L, 2); - if (!result || col >= RESULT->GetFieldCount()) - sEluna->Push(L, 0); - else + if (col < RESULT->GetFieldCount()) sEluna->Push(L, RESULT->Fetch()[col].GetInt8()); return 1; } @@ -116,9 +95,7 @@ namespace LuaQuery int GetInt16(lua_State* L, QueryResult* result) { uint32 col = sEluna->CHECKVAL(L, 2); - if (!result || col >= RESULT->GetFieldCount()) - sEluna->Push(L, 0); - else + if (col < RESULT->GetFieldCount()) sEluna->Push(L, RESULT->Fetch()[col].GetInt16()); return 1; } @@ -126,9 +103,7 @@ namespace LuaQuery int GetInt32(lua_State* L, QueryResult* result) { uint32 col = sEluna->CHECKVAL(L, 2); - if (!result || col >= RESULT->GetFieldCount()) - sEluna->Push(L, 0); - else + if (col < RESULT->GetFieldCount()) sEluna->Push(L, RESULT->Fetch()[col].GetInt32()); return 1; } @@ -136,9 +111,7 @@ namespace LuaQuery int GetInt64(lua_State* L, QueryResult* result) { uint32 col = sEluna->CHECKVAL(L, 2); - if (!result || col >= RESULT->GetFieldCount()) - sEluna->Push(L, 0); - else + if (col < RESULT->GetFieldCount()) sEluna->Push(L, RESULT->Fetch()[col].GetInt64()); return 1; } @@ -146,9 +119,7 @@ namespace LuaQuery int GetFloat(lua_State* L, QueryResult* result) { uint32 col = sEluna->CHECKVAL(L, 2); - if (!result || col >= RESULT->GetFieldCount()) - sEluna->Push(L, 0.0f); - else + if (col < RESULT->GetFieldCount()) sEluna->Push(L, RESULT->Fetch()[col].GetFloat()); return 1; } @@ -156,9 +127,7 @@ namespace LuaQuery int GetDouble(lua_State* L, QueryResult* result) { uint32 col = sEluna->CHECKVAL(L, 2); - if (!result || col >= RESULT->GetFieldCount()) - sEluna->Push(L, 0.0); - else + if (col < RESULT->GetFieldCount()) sEluna->Push(L, RESULT->Fetch()[col].GetDouble()); return 1; } @@ -166,9 +135,7 @@ namespace LuaQuery int GetString(lua_State* L, QueryResult* result) { uint32 col = sEluna->CHECKVAL(L, 2); - if (!result || col >= RESULT->GetFieldCount()) - sEluna->Push(L, ""); - else + if (col < RESULT->GetFieldCount()) sEluna->Push(L, RESULT->Fetch()[col].GetString()); return 1; } @@ -176,10 +143,7 @@ namespace LuaQuery /* OTHER */ int NextRow(lua_State* L, QueryResult* result) { - if (!result) - sEluna->Push(L, false); - else - sEluna->Push(L, RESULT->NextRow()); + sEluna->Push(L, RESULT->NextRow()); return 1; } }; diff --git a/QuestMethods.h b/QuestMethods.h index 44753eb..94bdfad 100644 --- a/QuestMethods.h +++ b/QuestMethods.h @@ -93,13 +93,5 @@ namespace LuaQuest sEluna->Push(L, quest->GetMaxLevel()); return 1; }*/ - - /* SETTERS */ - int SetFlag(lua_State* L, Quest* quest) - { - uint32 flag = sEluna->CHECKVAL(L, 2); - quest->SetSpecialFlag((QuestSpecialFlags)flag); - return 0; - } }; #endif diff --git a/SpellMethods.h b/SpellMethods.h index 7351ec0..d87a644 100644 --- a/SpellMethods.h +++ b/SpellMethods.h @@ -55,12 +55,12 @@ namespace LuaSpell { #ifdef MANGOS if (!(spell->m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)) - return 0; + return 3; float x, y, z; spell->m_targets.getDestination(x, y, z); #else if (!spell->m_targets.HasDst()) - return 0; + return 3; float x, y, z; spell->m_targets.GetDstPos()->GetPosition(x, y, z); #endif @@ -81,8 +81,6 @@ namespace LuaSpell sEluna->Push(sEluna->L, target); else if (Unit* target = spell->m_targets.getUnitTarget()) sEluna->Push(sEluna->L, target); - else - sEluna->Push(sEluna->L); #else if (GameObject* target = spell->m_targets.GetGOTarget()) sEluna->Push(L, target); @@ -94,8 +92,6 @@ namespace LuaSpell sEluna->Push(L, target); else if (WorldObject* target = spell->m_targets.GetObjectTarget()) sEluna->Push(L, target); - else - sEluna->Push(L); #endif return 1; } diff --git a/UnitMethods.h b/UnitMethods.h index 764115d..576d458 100644 --- a/UnitMethods.h +++ b/UnitMethods.h @@ -503,7 +503,7 @@ namespace LuaUnit uint32 stat = sEluna->CHECKVAL(L, 2); if (stat >= MAX_STATS) - return 0; + return 1; sEluna->Push(L, unit->GetStat((Stats)stat)); return 1; @@ -514,7 +514,7 @@ namespace LuaUnit uint32 spellschool = sEluna->CHECKVAL(L, 2); if (spellschool >= MAX_SPELL_SCHOOL) - return 0; + return 1; sEluna->Push(L, unit->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + spellschool)); return 1; @@ -1260,12 +1260,12 @@ namespace LuaUnit return 0; } - static void PrepareMove(Unit* unit) - { - unit->GetMotionMaster()->MovementExpired(); // Chase - unit->StopMoving(); // Some - unit->GetMotionMaster()->Clear(); // all - } + // static void PrepareMove(Unit* unit) + // { + // unit->GetMotionMaster()->MovementExpired(); // Chase + // unit->StopMoving(); // Some + // unit->GetMotionMaster()->Clear(); // all + // } int MoveStop(lua_State* L, Unit* unit) { @@ -1479,11 +1479,11 @@ namespace LuaUnit Unit* target = sEluna->CHECKOBJ(L, 3); SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellId); if (!spellInfo) - return 0; + return 1; #ifdef MANGOS if (!IsSpellAppliesAura(spellInfo) && !IsSpellHaveEffect(spellInfo, SPELL_EFFECT_PERSISTENT_AREA_AURA)) - return 0; + return 1; SpellAuraHolder* holder = CreateSpellAuraHolder(spellInfo, target, unit); @@ -1559,8 +1559,6 @@ namespace LuaUnit functionRef = sEluna->m_EventMgr.AddEvent(&unit->m_Events, functionRef, delay, repeats, unit); if (functionRef) sEluna->Push(L, functionRef); - else - sEluna->Push(L); return 1; } @@ -1675,13 +1673,13 @@ namespace LuaUnit SummonPropertiesEntry const* properties = sSummonPropertiesStore.LookupEntry(61); if (!properties) - return 0; + return 1; Position pos; pos.Relocate(x,y,z,o); TempSummon* summon = unit->GetMap()->SummonCreature(entry, pos, properties, desp, unit); if (!summon) - return 0; + return 1; if (summon->HasUnitTypeMask(UNIT_MASK_GUARDIAN)) ((Guardian*)summon)->InitStatsForLevel(unit->getLevel()); diff --git a/WorldObjectMethods.h b/WorldObjectMethods.h index d0967f5..2c00a92 100644 --- a/WorldObjectMethods.h +++ b/WorldObjectMethods.h @@ -283,7 +283,7 @@ namespace LuaWorldObject return 1; } - return 0; + return 1; } int GetWorldObject(lua_State* L, WorldObject* obj) @@ -302,7 +302,6 @@ namespace LuaWorldObject #endif case HIGHGUID_UNIT: case HIGHGUID_PET: sEluna->Push(L, obj->GetMap()->GetAnyTypeCreature(ObjectGuid(guid))); break; - default: return 0; } #else switch (GUID_HIPART(guid)) @@ -314,7 +313,6 @@ namespace LuaWorldObject case HIGHGUID_VEHICLE: case HIGHGUID_UNIT: sEluna->Push(L, sObjectAccessor->GetCreature(*obj, ObjectGuid(guid))); break; case HIGHGUID_PET: sEluna->Push(L, sObjectAccessor->GetPet(*obj, ObjectGuid(guid))); break; - default: return 0; } #endif return 1;