From 0b17dc73f1bcf2f074a47fbedd45685e07af6986 Mon Sep 17 00:00:00 2001 From: Russell Kinasz Date: Fri, 5 Jun 2015 12:23:42 -0700 Subject: [PATCH] Update to encounter timers so they can actually work from hooked events --- zone/CMakeLists.txt | 6 ++++-- zone/lua_encounter.cpp | 14 ++++++++++++++ zone/lua_encounter.h | 30 ++++++++++++++++++++++++++++++ zone/lua_general.cpp | 6 ++++++ zone/lua_parser.cpp | 9 ++++++--- zone/lua_parser_events.cpp | 15 +++++++++++---- zone/lua_parser_events.h | 10 +++++----- 7 files changed, 76 insertions(+), 14 deletions(-) create mode 100644 zone/lua_encounter.cpp create mode 100644 zone/lua_encounter.h diff --git a/zone/CMakeLists.txt b/zone/CMakeLists.txt index 2510dcddb..5573e6f4f 100644 --- a/zone/CMakeLists.txt +++ b/zone/CMakeLists.txt @@ -20,7 +20,7 @@ SET(zone_sources embparser_api.cpp embperl.cpp embxs.cpp - encounter.cpp + encounter.cpp entity.cpp exp.cpp fearpath.cpp @@ -36,6 +36,7 @@ SET(zone_sources lua_corpse.cpp lua_client.cpp lua_door.cpp + lua_encounter.cpp lua_entity.cpp lua_entity_list.cpp lua_general.cpp @@ -138,7 +139,7 @@ SET(zone_headers embparser.h embperl.h embxs.h - encounter.h + encounter.h entity.h errmsg.h event_codes.h @@ -150,6 +151,7 @@ SET(zone_headers lua_bit.h lua_client.h lua_corpse.h + lua_encounter.h lua_entity.h lua_entity_list.h lua_general.h diff --git a/zone/lua_encounter.cpp b/zone/lua_encounter.cpp new file mode 100644 index 000000000..a01c846fb --- /dev/null +++ b/zone/lua_encounter.cpp @@ -0,0 +1,14 @@ +#ifdef LUA_EQEMU + +#include "lua.hpp" +#include +#include "lua_encounter.h" +#include "encounter.h" + + +luabind::scope lua_register_encounter() { + return luabind::class_("Encounter") + .def(luabind::constructor<>()); +} + +#endif \ No newline at end of file diff --git a/zone/lua_encounter.h b/zone/lua_encounter.h new file mode 100644 index 000000000..d4ce63bb9 --- /dev/null +++ b/zone/lua_encounter.h @@ -0,0 +1,30 @@ +#ifndef EQEMU_LUA_ENCOUNTER_H +#define EQEMU_LUA_ENCOUNTER_H +#ifdef LUA_EQEMU + +#include "lua_ptr.h" + +class Encounter; + +namespace luabind { + struct scope; + class object; +} + +luabind::scope lua_register_encounter(); + +class Lua_Encounter : public Lua_Ptr +{ + typedef Encounter NativeType; +public: + Lua_Encounter() { SetLuaPtrData(nullptr); } + Lua_Encounter(Encounter *d) { SetLuaPtrData(reinterpret_cast(d)); } + virtual ~Lua_Encounter() { } + + operator Encounter*() { + return reinterpret_cast(GetLuaPtrData()); + } + +}; +#endif +#endif \ No newline at end of file diff --git a/zone/lua_general.cpp b/zone/lua_general.cpp index 139951724..777396daa 100644 --- a/zone/lua_general.cpp +++ b/zone/lua_general.cpp @@ -19,6 +19,7 @@ #include "../common/timer.h" #include "../common/eqemu_logsys.h" #include "encounter.h" +#include "lua_encounter.h" struct Events { }; struct Factions { }; @@ -296,6 +297,10 @@ void lua_set_timer(const char *timer, int time_ms, Lua_Mob mob) { quest_manager.settimerMS(timer, time_ms, mob); } +void lua_set_timer(const char *timer, int time_ms, Lua_Encounter enc) { + quest_manager.settimerMS(timer, time_ms, enc); +} + void lua_stop_timer(const char *timer) { quest_manager.stoptimer(timer); } @@ -1457,6 +1462,7 @@ luabind::scope lua_register_general() { luabind::def("set_timer", (void(*)(const char*, int))&lua_set_timer), luabind::def("set_timer", (void(*)(const char*, int, Lua_ItemInst))&lua_set_timer), luabind::def("set_timer", (void(*)(const char*, int, Lua_Mob))&lua_set_timer), + luabind::def("set_timer", (void(*)(const char*, int, Lua_Encounter))&lua_set_timer), luabind::def("stop_timer", (void(*)(const char*))&lua_stop_timer), luabind::def("stop_timer", (void(*)(const char*, Lua_ItemInst))&lua_stop_timer), luabind::def("stop_timer", (void(*)(const char*, Lua_Mob))&lua_stop_timer), diff --git a/zone/lua_parser.cpp b/zone/lua_parser.cpp index 4b5a1faad..24f25948e 100644 --- a/zone/lua_parser.cpp +++ b/zone/lua_parser.cpp @@ -34,6 +34,7 @@ #include "questmgr.h" #include "zone.h" #include "lua_parser.h" +#include "lua_encounter.h" const char *LuaEvents[_LargestEventID] = { "event_say", @@ -610,10 +611,11 @@ int LuaParser::_EventEncounter(std::string package_name, QuestEventID evt, std:: lua_pushstring(L, encounter_name.c_str()); lua_setfield(L, -2, "name"); - auto arg_function = EncounterArgumentDispatch[evt]; - arg_function(this, L, data, extra_data, extra_pointers); - Encounter *enc = lua_encounters[encounter_name]; + + auto arg_function = EncounterArgumentDispatch[evt]; + arg_function(this, L, enc, data, extra_data, extra_pointers); + quest_manager.StartQuest(enc, nullptr, nullptr, encounter_name); if(lua_pcall(L, 1, 1, 0)) { std::string error = lua_tostring(L, -1); @@ -977,6 +979,7 @@ void LuaParser::MapFunctions(lua_State *L) { lua_register_client_version(), lua_register_appearance(), lua_register_entity(), + lua_register_encounter(), lua_register_mob(), lua_register_special_abilities(), lua_register_npc(), diff --git a/zone/lua_parser_events.cpp b/zone/lua_parser_events.cpp index 5428304a6..840bcb40d 100644 --- a/zone/lua_parser_events.cpp +++ b/zone/lua_parser_events.cpp @@ -22,6 +22,7 @@ #include "lua_door.h" #include "lua_object.h" #include "lua_packet.h" +#include "lua_encounter.h" #include "zone.h" #include "lua_parser_events.h" @@ -704,14 +705,20 @@ void handle_spell_null(QuestInterface *parse, lua_State* L, NPC* npc, Client* cl std::vector *extra_pointers) { } -void handle_encounter_timer(QuestInterface *parse, lua_State* L, std::string data, uint32 extra_data, +void handle_encounter_timer(QuestInterface *parse, lua_State* L, Encounter* encounter, std::string data, uint32 extra_data, std::vector *extra_pointers) { lua_pushstring(L, data.c_str()); lua_setfield(L, -2, "timer"); } -void handle_encounter_load(QuestInterface *parse, lua_State* L, std::string data, uint32 extra_data, +void handle_encounter_load(QuestInterface *parse, lua_State* L, Encounter* encounter, std::string data, uint32 extra_data, std::vector *extra_pointers) { + if (encounter) { + Lua_Encounter l_enc(encounter); + luabind::adl::object l_enc_o = luabind::adl::object(L, l_enc); + l_enc_o.push(L); + lua_setfield(L, -2, "encounter"); + } if (extra_pointers) { std::string *str = EQEmu::any_cast(extra_pointers->at(0)); lua_pushstring(L, str->c_str()); @@ -719,7 +726,7 @@ void handle_encounter_load(QuestInterface *parse, lua_State* L, std::string data } } -void handle_encounter_unload(QuestInterface *parse, lua_State* L, std::string data, uint32 extra_data, +void handle_encounter_unload(QuestInterface *parse, lua_State* L, Encounter* encounter, std::string data, uint32 extra_data, std::vector *extra_pointers) { if (extra_pointers) { std::string *str = EQEmu::any_cast(extra_pointers->at(0)); @@ -728,7 +735,7 @@ void handle_encounter_unload(QuestInterface *parse, lua_State* L, std::string da } } -void handle_encounter_null(QuestInterface *parse, lua_State* L, std::string data, uint32 extra_data, +void handle_encounter_null(QuestInterface *parse, lua_State* L, Encounter* encounter, std::string data, uint32 extra_data, std::vector *extra_pointers) { } diff --git a/zone/lua_parser_events.h b/zone/lua_parser_events.h index 46609fb06..0a2ab5ad9 100644 --- a/zone/lua_parser_events.h +++ b/zone/lua_parser_events.h @@ -6,7 +6,7 @@ typedef void(*NPCArgumentHandler)(QuestInterface*, lua_State*, NPC*, Mob*, std:: typedef void(*PlayerArgumentHandler)(QuestInterface*, lua_State*, Client*, std::string, uint32, std::vector*); typedef void(*ItemArgumentHandler)(QuestInterface*, lua_State*, Client*, ItemInst*, Mob*, std::string, uint32, std::vector*); typedef void(*SpellArgumentHandler)(QuestInterface*, lua_State*, NPC*, Client*, uint32, uint32, std::vector*); -typedef void(*EncounterArgumentHandler)(QuestInterface*, lua_State*, std::string, uint32, std::vector*); +typedef void(*EncounterArgumentHandler)(QuestInterface*, lua_State*, Encounter* encounter, std::string, uint32, std::vector*); //NPC void handle_npc_event_say(QuestInterface *parse, lua_State* L, NPC* npc, Mob *init, std::string data, uint32 extra_data, @@ -130,13 +130,13 @@ void handle_spell_null(QuestInterface *parse, lua_State* L, NPC* npc, Client* cl //Encounter -void handle_encounter_timer(QuestInterface *parse, lua_State* L, std::string data, uint32 extra_data, +void handle_encounter_timer(QuestInterface *parse, lua_State* L, Encounter* encounter, std::string data, uint32 extra_data, std::vector *extra_pointers); -void handle_encounter_load(QuestInterface *parse, lua_State* L, std::string data, uint32 extra_data, +void handle_encounter_load(QuestInterface *parse, lua_State* L, Encounter* encounter, std::string data, uint32 extra_data, std::vector *extra_pointers); -void handle_encounter_unload(QuestInterface *parse, lua_State* L, std::string data, uint32 extra_data, +void handle_encounter_unload(QuestInterface *parse, lua_State* L, Encounter* encounter, std::string data, uint32 extra_data, std::vector *extra_pointers); -void handle_encounter_null(QuestInterface *parse, lua_State* L, std::string data, uint32 extra_data, +void handle_encounter_null(QuestInterface *parse, lua_State* L, Encounter* encounter, std::string data, uint32 extra_data, std::vector *extra_pointers); #endif