void GameEventMgr::DespawnEvent(uint32 id) { Log.Success("GameEvent","Started despawning event %u", id); // creatures for(std::map<uint32, std::list<uint32>>::iterator mitr = m_creaturespawns[id].begin(); mitr != m_creaturespawns[id].end(); mitr++) { for(std::list<uint32>::iterator gitr = mitr->second.begin(); gitr != mitr->second.end(); gitr++) { // find creature with current guid(*gitr) and despawn it MapMgr *mgr = sInstanceMgr.GetMapMgr(mitr->first); Creature *crt = mgr->GetCreature(*gitr); if(crt == NULL) { Log.Success("GameEvent","Failed to despawn creature with guid %u for event %u", *gitr, id); } else { // we don't need to delete waypoints as they are stored in m_custom_waypoint_map // and they are deleted automatically when creature is deleted crt->Despawn(0,0); Log.Success("GameEvent","creature with guid %u despawned from map %u for event %u", *gitr, mitr->first, id); } } mitr->second.clear(); } // gameobjects for(std::map<uint32, std::list<uint32>>::iterator mitr = m_gameobjectspawns[id].begin(); mitr != m_gameobjectspawns[id].end(); mitr++) { for(std::list<uint32>::iterator gitr = mitr->second.begin(); gitr != mitr->second.end(); gitr++) { // find gameobject with current guid(*gitr) and despawn it MapMgr *mgr = sInstanceMgr.GetMapMgr(mitr->first); GameObject *go = mgr->GetGameObject(*gitr); if(go == NULL) { Log.Success("GameEvent","Failed to despawn gameobject with guid %u for event %u", *gitr, id); } else { go->Despawn(0,0); Log.Success("GameEvent","gameobject with guid %u despawned from map %u for event %u", *gitr, mitr->first, id); } } mitr->second.clear(); } Log.Success("GameEvent","event %u despawned.", id); }
void LuaEngineMgr::Restart(ScriptMgr* sMgr) { Log.Notice("LuaEngineMgr", "Restarting Engine."); CREATE_L_PTR; g_engine->getcoLock().Acquire(); Unload(); m_engine->LoadScripts(); for(UnitBindingMap::iterator itr = m_unitBinding.begin(); itr != m_unitBinding.end(); ++itr) { typedef multimap<uint32, LuaCreature*> CMAP; CMAP & cMap = g_luaMgr.getLuCreatureMap(); CMAP::iterator it = cMap.find(itr->first); CMAP::iterator itend = cMap.upper_bound(itr->first); if(it == cMap.end()) { sMgr->register_creature_script(itr->first, CreateLuaCreature); cMap.insert(make_pair(itr->first, (LuaCreature*)NULL)); } else { for(; it != itend; ++it) { if(it->second != NULL) it->second->m_binding = &itr->second; } } } for(GameObjectBindingMap::iterator itr = m_gameobjectBinding.begin(); itr != m_gameobjectBinding.end(); ++itr) { typedef multimap<uint32, LuaGameObject*> GMAP; GMAP & gMap = g_luaMgr.getLuGameObjectMap(); GMAP::iterator it = gMap.find(itr->first); GMAP::iterator itend = gMap.upper_bound(itr->first); if(it == gMap.end()) { sMgr->register_gameobject_script(itr->first, CreateLuaGameObject); gMap.insert(make_pair(itr->first, (LuaGameObject*)NULL)); } else { for(; it != itend; ++it) { if(it->second != NULL) it->second->m_binding = &itr->second; } } } for(QuestBindingMap::iterator itr = m_questBinding.begin(); itr != m_questBinding.end(); ++itr) { typedef HM_NAMESPACE::hash_map<uint32, LuaQuest*> QMAP; QMAP & qMap = g_luaMgr.getLuQuestMap(); QMAP::iterator it = qMap.find(itr->first); if(it == qMap.end()) { sMgr->register_quest_script(itr->first, CreateLuaQuestScript(itr->first)); qMap.insert(make_pair(itr->first, (LuaQuest*)NULL)); } else { LuaQuest* q_interface = it->second; if(q_interface != NULL) q_interface->m_binding = &itr->second; } } for(InstanceBindingMap::iterator itr = m_instanceBinding.begin(); itr != m_instanceBinding.end(); ++itr) { typedef HM_NAMESPACE::hash_map<uint32, LuaInstance*> IMAP; IMAP & iMap = g_luaMgr.getLuInstanceMap(); IMAP::iterator it = iMap.find(itr->first); if(it == iMap.end()) { sMgr->register_mapmanager_script(itr->first, CreateLuaInstance); iMap.insert(make_pair(itr->first, (LuaInstance*)NULL)); } else { if(it->second != NULL) it->second->m_binding = &itr->second; } } for(GossipUnitScriptsBindingMap::iterator itr = this->m_unit_gossipBinding.begin(); itr != m_unit_gossipBinding.end(); ++itr) { typedef HM_NAMESPACE::hash_map<uint32, LuaGossip*> GMAP; GMAP & gMap = g_luaMgr.getUnitGossipInterfaceMap(); GMAP::iterator it = gMap.find(itr->first); if(it == gMap.end()) { GossipScript* gs = CreateLuaUnitGossipScript(itr->first); if(gs != NULL) { sMgr->register_gossip_script(itr->first, gs); gMap.insert(make_pair(itr->first, (LuaGossip*)NULL)); } } else { LuaGossip* u_gossip = it->second; if(u_gossip != NULL) u_gossip->m_unit_gossip_binding = &itr->second; } } for(GossipItemScriptsBindingMap::iterator itr = this->m_item_gossipBinding.begin(); itr != m_item_gossipBinding.end(); ++itr) { typedef HM_NAMESPACE::hash_map<uint32, LuaGossip*> GMAP; GMAP & gMap = g_luaMgr.getItemGossipInterfaceMap(); GMAP::iterator it = gMap.find(itr->first); if(it == gMap.end()) { GossipScript* gs = CreateLuaItemGossipScript(itr->first); if(gs != NULL) { sMgr->register_item_gossip_script(itr->first, gs); gMap.insert(make_pair(itr->first, (LuaGossip*)NULL)); } } else { LuaGossip* i_gossip = it->second; if(i_gossip != NULL) i_gossip->m_item_gossip_binding = &itr->second; } } for(GossipGOScriptsBindingMap::iterator itr = this->m_go_gossipBinding.begin(); itr != m_go_gossipBinding.end(); ++itr) { typedef HM_NAMESPACE::hash_map<uint32, LuaGossip*> GMAP; GMAP & gMap = g_luaMgr.getGameObjectGossipInterfaceMap(); GMAP::iterator it = gMap.find(itr->first); if(it == gMap.end()) { GossipScript* gs = CreateLuaGOGossipScript(itr->first); if(gs != NULL) { sMgr->register_go_gossip_script(itr->first, gs); gMap.insert(make_pair(itr->first, (LuaGossip*)NULL)); } } else { LuaGossip* g_gossip = it->second; if(g_gossip != NULL) g_gossip->m_go_gossip_binding = &itr->second; } } /* BIG SERV HOOK CHUNK EEK */ RegisterHook(SERVER_HOOK_EVENT_ON_NEW_CHARACTER, Lua_HookOnNewCharacter); RegisterHook(SERVER_HOOK_EVENT_ON_KILL_PLAYER, Lua_HookOnKillPlayer); RegisterHook(SERVER_HOOK_EVENT_ON_FIRST_ENTER_WORLD, Lua_HookOnFirstEnterWorld); RegisterHook(SERVER_HOOK_EVENT_ON_ENTER_WORLD, Lua_HookOnEnterWorld); RegisterHook(SERVER_HOOK_EVENT_ON_GUILD_JOIN, Lua_HookOnGuildJoin); RegisterHook(SERVER_HOOK_EVENT_ON_DEATH, Lua_HookOnDeath); RegisterHook(SERVER_HOOK_EVENT_ON_REPOP, Lua_HookOnRepop); RegisterHook(SERVER_HOOK_EVENT_ON_EMOTE, Lua_HookOnEmote); RegisterHook(SERVER_HOOK_EVENT_ON_ENTER_COMBAT, Lua_HookOnEnterCombat); RegisterHook(SERVER_HOOK_EVENT_ON_CAST_SPELL, Lua_HookOnCastSpell); RegisterHook(SERVER_HOOK_EVENT_ON_TICK, Lua_HookOnTick); RegisterHook(SERVER_HOOK_EVENT_ON_LOGOUT_REQUEST, Lua_HookOnLogoutRequest); RegisterHook(SERVER_HOOK_EVENT_ON_LOGOUT, Lua_HookOnLogout); RegisterHook(SERVER_HOOK_EVENT_ON_QUEST_ACCEPT, Lua_HookOnQuestAccept); RegisterHook(SERVER_HOOK_EVENT_ON_ZONE, Lua_HookOnZone); RegisterHook(SERVER_HOOK_EVENT_ON_CHAT, Lua_HookOnChat); RegisterHook(SERVER_HOOK_EVENT_ON_LOOT, Lua_HookOnLoot); RegisterHook(SERVER_HOOK_EVENT_ON_GUILD_CREATE, Lua_HookOnGuildCreate); RegisterHook(SERVER_HOOK_EVENT_ON_FULL_LOGIN, Lua_HookOnEnterWorld2); RegisterHook(SERVER_HOOK_EVENT_ON_CHARACTER_CREATE, Lua_HookOnCharacterCreate); RegisterHook(SERVER_HOOK_EVENT_ON_QUEST_CANCELLED, Lua_HookOnQuestCancelled); RegisterHook(SERVER_HOOK_EVENT_ON_QUEST_FINISHED, Lua_HookOnQuestFinished); RegisterHook(SERVER_HOOK_EVENT_ON_HONORABLE_KILL, Lua_HookOnHonorableKill); RegisterHook(SERVER_HOOK_EVENT_ON_ARENA_FINISH, Lua_HookOnArenaFinish); RegisterHook(SERVER_HOOK_EVENT_ON_OBJECTLOOT, Lua_HookOnObjectLoot); RegisterHook(SERVER_HOOK_EVENT_ON_AREATRIGGER, Lua_HookOnAreaTrigger); RegisterHook(SERVER_HOOK_EVENT_ON_POST_LEVELUP, Lua_HookOnPostLevelUp); RegisterHook(SERVER_HOOK_EVENT_ON_PRE_DIE, Lua_HookOnPreUnitDie); RegisterHook(SERVER_HOOK_EVENT_ON_ADVANCE_SKILLLINE, Lua_HookOnAdvanceSkillLine); RegisterHook(SERVER_HOOK_EVENT_ON_DUEL_FINISHED, Lua_HookOnDuelFinished); RegisterHook(SERVER_HOOK_EVENT_ON_AURA_REMOVE, Lua_HookOnAuraRemove); RegisterHook(SERVER_HOOK_EVENT_ON_RESURRECT, Lua_HookOnResurrect); for(std::map<uint32, uint16>::iterator itr = m_luaDummySpells.begin(); itr != m_luaDummySpells.end(); ++itr) { if(find(g_luaMgr.HookInfo.dummyHooks.begin(), g_luaMgr.HookInfo.dummyHooks.end(), itr->first) == g_luaMgr.HookInfo.dummyHooks.end()) { sMgr->register_dummy_spell(itr->first, &Lua_HookOnDummySpell); g_luaMgr.HookInfo.dummyHooks.push_back(itr->first); } } RELEASE_LOCK g_engine->getcoLock().Release(); //hyper: do OnSpawns for spawned creatures. vector<uint32> temp = OnLoadInfo; OnLoadInfo.clear(); for(vector<uint32>::iterator itr = temp.begin(); itr != temp.end(); itr += 3) { //*itr = mapid; *(itr+1) = iid; *(itr+2) = lowguid MapMgr* mgr = NULL; if(*(itr + 1) == 0) //no instance mgr = sInstanceMgr.GetMapMgr(*itr); else { Instance* inst = sInstanceMgr.GetInstanceByIds(*itr, *(itr + 1)); if(inst != NULL) mgr = inst->m_mapMgr; } if(mgr != NULL) { Creature* unit = mgr->GetCreature(*(itr + 2)); if(unit != NULL && unit->IsInWorld() && unit->GetScript() != NULL) unit->GetScript()->OnLoad(); } } temp.clear(); Log.Notice("LuaEngineMgr", "Done restarting engine."); }