From 6d0c0aee7d605e44ee4c13f5639fe0fedd191705 Mon Sep 17 00:00:00 2001 From: KimLS Date: Tue, 4 Jun 2013 23:22:03 -0700 Subject: [PATCH] Last work to make lua parser feature complete, time to start fixing bugs and cleaning up design and maybe adding some features here and there. --- zone/lua_general.cpp | 67 +++++++++++++++++++++++++++++++++++++- zone/lua_parser.cpp | 64 +++++++++--------------------------- zone/lua_parser.h | 1 - zone/lua_parser_events.cpp | 10 ++++++ zone/lua_parser_events.h | 2 ++ 5 files changed, 93 insertions(+), 51 deletions(-) diff --git a/zone/lua_general.cpp b/zone/lua_general.cpp index cac88c2c0..f9c1835f9 100644 --- a/zone/lua_general.cpp +++ b/zone/lua_general.cpp @@ -12,6 +12,7 @@ #include "lua_iteminst.h" #include "lua_client.h" #include "lua_npc.h" +#include "lua_entity_list.h" #include "QuestParserCollection.h" #include "questmgr.h" #include "QGlobals.h" @@ -761,6 +762,62 @@ luabind::object lua_get_qglobals(lua_State *L) { return lua_get_qglobals(L, Lua_NPC(nullptr), Lua_Client(nullptr)); } +Lua_EntityList lua_get_entity_list() { + return Lua_EntityList(&entity_list); +} + +int lua_get_zone_id() { + if(!zone) + return 0; + + return zone->GetZoneID(); +} + +const char *lua_get_zone_long_name() { + if(!zone) + return ""; + + return zone->GetLongName(); +} + +const char *lua_get_zone_short_name() { + if(!zone) + return ""; + + return zone->GetShortName(); +} + +int lua_get_zone_instance_id() { + if(!zone) + return 0; + + return zone->GetInstanceID(); +} + +int lua_get_zone_instance_version() { + if(!zone) + return 0; + + return zone->GetInstanceVersion(); +} + +int lua_get_zone_weather() { + if(!zone) + return 0; + + return zone->zone_weather; +} + +luabind::object lua_get_zone_time(lua_State *L) { + TimeOfDay_Struct eqTime; + zone->zone_time.getEQTimeOfDay(time(0), &eqTime); + + luabind::object ret = luabind::newtable(L); + ret["zone_hour"] = eqTime.hour - 1; + ret["zone_minute"] = eqTime.minute; + ret["zone_time"] = (eqTime.hour - 1) * 100 + eqTime.minute; + return ret; +} luabind::scope lua_register_general() { return luabind::namespace_("eq") @@ -897,7 +954,15 @@ luabind::scope lua_register_general() { luabind::def("get_qglobals", (luabind::object(*)(lua_State*,Lua_Client,Lua_NPC))&lua_get_qglobals), luabind::def("get_qglobals", (luabind::object(*)(lua_State*,Lua_Client))&lua_get_qglobals), luabind::def("get_qglobals", (luabind::object(*)(lua_State*,Lua_NPC))&lua_get_qglobals), - luabind::def("get_qglobals", (luabind::object(*)(lua_State*))&lua_get_qglobals) + luabind::def("get_qglobals", (luabind::object(*)(lua_State*))&lua_get_qglobals), + luabind::def("get_entity_list", &lua_get_entity_list), + luabind::def("get_zone_id", &lua_get_zone_id), + luabind::def("get_zone_long_name", &lua_get_zone_long_name), + luabind::def("get_zone_short_name", &lua_get_zone_short_name), + luabind::def("get_zone_instance_id", &lua_get_zone_instance_id), + luabind::def("get_zone_instance_version", &lua_get_zone_instance_version), + luabind::def("get_zone_weather", &lua_get_zone_weather), + luabind::def("get_zone_time", &lua_get_zone_time) ]; } diff --git a/zone/lua_parser.cpp b/zone/lua_parser.cpp index af812ba52..2857cb160 100644 --- a/zone/lua_parser.cpp +++ b/zone/lua_parser.cpp @@ -157,6 +157,14 @@ LuaParser::LuaParser() { PlayerArgumentDispatch[EVENT_TASK_STAGE_COMPLETE] = handle_player_task_stage_complete; PlayerArgumentDispatch[EVENT_TASK_COMPLETE] = handle_player_task_complete; + ItemArgumentDispatch[EVENT_ITEM_CLICK] = handle_item_click; + ItemArgumentDispatch[EVENT_ITEM_CLICK_CAST] = handle_item_click; + + SpellArgumentDispatch[EVENT_SPELL_EFFECT_NPC] = handle_spell_effect; + SpellArgumentDispatch[EVENT_SPELL_EFFECT_CLIENT] = handle_spell_effect; + SpellArgumentDispatch[EVENT_SPELL_EFFECT_BUFF_TIC_NPC] = handle_spell_effect; + SpellArgumentDispatch[EVENT_SPELL_EFFECT_BUFF_TIC_CLIENT] = handle_spell_effect; + L = nullptr; } @@ -226,7 +234,6 @@ int LuaParser::_EventNPC(std::string package_name, QuestEventID evt, NPC* npc, M auto arg_function = NPCArgumentDispatch[evt]; arg_function(this, L, npc, init, data, extra_data); - ExportZoneVariables(); Client *c = (init && init->IsClient()) ? init->CastToClient() : nullptr; quest_manager.StartQuest(npc, c, nullptr); @@ -317,7 +324,6 @@ int LuaParser::_EventPlayer(std::string package_name, QuestEventID evt, Client * auto arg_function = PlayerArgumentDispatch[evt]; arg_function(this, L, client, data, extra_data); - ExportZoneVariables(); quest_manager.StartQuest(nullptr, client, nullptr); if(lua_pcall(L, 1, 1, 0)) { @@ -412,7 +418,6 @@ int LuaParser::_EventItem(std::string package_name, QuestEventID evt, Client *cl auto arg_function = ItemArgumentDispatch[evt]; arg_function(this, L, client, item, objid, extra_data); - ExportZoneVariables(); quest_manager.StartQuest(nullptr, client, item); if(lua_pcall(L, 1, 1, 0)) { @@ -493,7 +498,6 @@ int LuaParser::_EventSpell(std::string package_name, QuestEventID evt, NPC* npc, auto arg_function = SpellArgumentDispatch[evt]; arg_function(this, L, npc, client, spell_id, extra_data); - ExportZoneVariables(); quest_manager.StartQuest(npc, client, nullptr); if(lua_pcall(L, 1, 1, 0)) { @@ -554,8 +558,6 @@ int LuaParser::_EventEncounter(std::string package_name, QuestEventID evt, std:: lua_pushstring(L, encounter_name.c_str()); lua_setfield(L, -2, "name"); - ExportZoneVariables(); - quest_manager.StartQuest(nullptr, nullptr, nullptr); if(lua_pcall(L, 1, 1, 0)) { std::string error = lua_tostring(L, -1); @@ -728,7 +730,11 @@ void LuaParser::ReloadQuests() { MapFunctions(L); //load init - FILE *f = fopen("quests/global/script_init.lua", "r"); + std::string path = "quests/"; + path += QUEST_GLOBAL_DIRECTORY; + path += "/script_init.lua"; + + FILE *f = fopen(path.c_str(), "r"); if(f) { fclose(f); @@ -740,7 +746,8 @@ void LuaParser::ReloadQuests() { //zone init - always loads after global if(zone) { - std::string zone_script = "quests/" + std::string(zone->GetShortName()); + std::string zone_script = "quests/"; + zone_script += zone->GetShortName(); zone_script += "/script_init.lua"; f = fopen(zone_script.c_str(), "r"); if(f) { @@ -955,45 +962,4 @@ void LuaParser::DispatchEventSpell(QuestEventID evt, NPC* npc, Client *client, u } } -void LuaParser::ExportZoneVariables() { - if(zone == nullptr) { - return; - } - - Lua_EntityList l_entity_list(&entity_list); - luabind::object l_entity_list_o = luabind::object(L, l_entity_list); - l_entity_list_o.push(L); - lua_setfield(L, -2, "entity_list"); - - lua_pushinteger(L, zone->GetZoneID()); - lua_setfield(L, -2, "zone_id"); - - lua_pushstring(L, zone->GetLongName()); - lua_setfield(L, -2, "zone_ln"); - - lua_pushstring(L, zone->GetShortName()); - lua_setfield(L, -2, "zone_sn"); - - lua_pushinteger(L, zone->GetInstanceID()); - lua_setfield(L, -2, "instance_id"); - - lua_pushinteger(L, zone->GetInstanceVersion()); - lua_setfield(L, -2, "instance_version"); - - TimeOfDay_Struct eqTime; - zone->zone_time.getEQTimeOfDay(time(0), &eqTime); - - lua_pushinteger(L, eqTime.hour - 1); - lua_setfield(L, -2, "zone_hour"); - - lua_pushinteger(L, eqTime.minute); - lua_setfield(L, -2, "zone_minute"); - - lua_pushinteger(L, (eqTime.hour - 1) * 100 + eqTime.minute); - lua_setfield(L, -2, "zone_time"); - - lua_pushinteger(L, zone->zone_weather); - lua_setfield(L, -2, "zone_weather"); -} - #endif diff --git a/zone/lua_parser.h b/zone/lua_parser.h index 4219c9e2e..10f0951d9 100644 --- a/zone/lua_parser.h +++ b/zone/lua_parser.h @@ -75,7 +75,6 @@ private: bool HasFunction(std::string function, std::string package_name); void ClearStates(); void MapFunctions(lua_State *L); - void ExportZoneVariables(); std::map vars_; std::map loaded_; diff --git a/zone/lua_parser_events.cpp b/zone/lua_parser_events.cpp index 3a8c80ebe..0b4c99ec2 100644 --- a/zone/lua_parser_events.cpp +++ b/zone/lua_parser_events.cpp @@ -355,9 +355,19 @@ void handle_player_null(QuestInterface *parse, lua_State* L, Client* client, std } //Item +void handle_item_click(QuestInterface *parse, lua_State* L, Client* client, ItemInst* item, uint32 objid, uint32 extra_data) { + lua_pushinteger(L, extra_data); + lua_setfield(L, -2, "slot_id"); +} + void handle_item_null(QuestInterface *parse, lua_State* L, Client* client, ItemInst* item, uint32 objid, uint32 extra_data) { } //Spell +void handle_spell_effect(QuestInterface *parse, lua_State* L, NPC* npc, Client* client, uint32 spell_id, uint32 extra_data) { + lua_pushinteger(L, extra_data); + lua_setfield(L, -2, "caster_id"); +} + void handle_spell_null(QuestInterface *parse, lua_State* L, NPC* npc, Client* client, uint32 spell_id, uint32 extra_data) { } diff --git a/zone/lua_parser_events.h b/zone/lua_parser_events.h index 3d34bf250..4c135dd65 100644 --- a/zone/lua_parser_events.h +++ b/zone/lua_parser_events.h @@ -44,9 +44,11 @@ void handle_player_task_complete(QuestInterface *parse, lua_State* L, Client* cl void handle_player_null(QuestInterface *parse, lua_State* L, Client* client, std::string data, uint32 extra_data); //Item +void handle_item_click(QuestInterface *parse, lua_State* L, Client* client, ItemInst* item, uint32 objid, uint32 extra_data); void handle_item_null(QuestInterface *parse, lua_State* L, Client* client, ItemInst* item, uint32 objid, uint32 extra_data); //Spell +void handle_spell_effect(QuestInterface *parse, lua_State* L, NPC* npc, Client* client, uint32 spell_id, uint32 extra_data); void handle_spell_null(QuestInterface *parse, lua_State* L, NPC* npc, Client* client, uint32 spell_id, uint32 extra_data); #endif