MCPcopy Create free account
hub / github.com/EQEmu/EQEmu / _EventEncounter

Method _EventEncounter

zone/lua_parser.cpp:848–903  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

846}
847
848int LuaParser::_EventEncounter(std::string package_name, QuestEventID evt, std::string encounter_name, std::string data, uint32 extra_data,
849 std::vector<std::any> *extra_pointers) {
850 const char *sub_name = LuaEvents[evt];
851
852 int start = lua_gettop(L);
853
854 try {
855 PushErrorHandler(L);
856 lua_getfield(L, LUA_REGISTRYINDEX, package_name.c_str());
857 lua_getfield(L, -1, sub_name);
858
859 lua_createtable(L, 0, 0);
860 lua_pushstring(L, encounter_name.c_str());
861 lua_setfield(L, -2, "name");
862
863 Encounter *enc = lua_encounters[encounter_name];
864
865 auto arg_function = EncounterArgumentDispatch[evt];
866 arg_function(this, L, enc, data, extra_data, extra_pointers);
867
868 RunningQuest q;
869
870 q.owner = enc;
871 q.encounter = encounter_name;
872
873 quest_manager.StartQuest(q);
874
875 if(lua_pcall(L, 1, 1, start + 1)) {
876 std::string error = lua_tostring(L, -1);
877 AddError(error);
878 quest_manager.EndQuest();
879 lua_pop(L, 3);
880 return 0;
881 }
882 quest_manager.EndQuest();
883
884 if(lua_isnumber(L, -1)) {
885 int ret = static_cast<int>(lua_tointeger(L, -1));
886 lua_pop(L, 3);
887 return ret;
888 }
889
890 lua_pop(L, 3);
891 } catch(std::exception &ex) {
892 AddError(fmt::format("Lua Exception | [{}] for Encounter [{}]: {}", sub_name, encounter_name, ex.what()));
893
894 //Restore our stack to the best of our ability
895 int end = lua_gettop(L);
896 int n = end - start;
897 if(n > 0) {
898 lua_pop(L, n);
899 }
900 }
901
902 return 0;
903}
904
905bool LuaParser::HasQuestSub(uint32 npc_id, QuestEventID evt) {

Callers

nothing calls this directly

Calls 5

PushErrorHandlerFunction · 0.85
StartQuestMethod · 0.80
EndQuestMethod · 0.80
c_strMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected