From 81e7cf5a32d901100c0e85e28a289afacff6bc2d Mon Sep 17 00:00:00 2001 From: Kinglykrab <89047260+Kinglykrab@users.noreply.github.com> Date: Wed, 20 Oct 2021 16:02:12 -0400 Subject: [PATCH] [Quest API] Convert Spell Events to similar formats and exports. (#1618) * [Quest API] Convert Spell Events to similar formats and exports. Export spell ID, caster ID, caster level, tics remaining, and buff slot to Perl/Lua spell events. - Export e.buff_slot, e.caster_id, e.caster_level, e.spell_id, and e.tics_remaining to `event_spell_buff_tic`, `event_spell_effect`, and `event_spell_fade` in Lua. - Export $buff_slot, $caster_id, $caster_level, $spell_id, $tics_remaining to `EVENT_SPELL_EFFECT_BUFF_TIC_CLIENT`, `EVENT_SPELL_EFFECT_BUFF_TIC_NPC`, `EVENT_SPELL_EFFECT_CLIENT`, `EVENT_SPELL_EFFECT_NPC`, and `EVENT_SPELL_FADE` in Perl. * Formatting. * Remove debug variable. --- common/spdat.cpp | 8 ++++ common/spdat.h | 4 ++ zone/client_packet.cpp | 45 ++++++++++++------- zone/embparser.cpp | 60 +++++++++++++------------ zone/embparser.h | 2 +- zone/event_codes.h | 4 +- zone/lua_general.cpp | 2 +- zone/lua_parser.cpp | 26 +++++------ zone/lua_parser.h | 6 +-- zone/lua_parser_events.cpp | 76 +++++++------------------------ zone/lua_parser_events.h | 12 ++--- zone/quest_interface.h | 4 +- zone/quest_parser_collection.cpp | 18 ++++---- zone/quest_parser_collection.h | 4 +- zone/spell_effects.cpp | 77 ++++++++++++++++---------------- 15 files changed, 164 insertions(+), 184 deletions(-) diff --git a/common/spdat.cpp b/common/spdat.cpp index 8721078d7..7c3476505 100644 --- a/common/spdat.cpp +++ b/common/spdat.cpp @@ -833,6 +833,14 @@ bool IsTeleportSpell(uint16 spell_id) return false; } +bool IsTranslocateSpell(uint16 spell_id) +{ + if (IsEffectInSpell(spell_id, SE_Translocate)) + return true; + + return false; +} + bool IsGateSpell(uint16 spell_id) { if (IsEffectInSpell(spell_id, SE_Gate)) diff --git a/common/spdat.h b/common/spdat.h index ebd39eed4..c6c9df888 100644 --- a/common/spdat.h +++ b/common/spdat.h @@ -129,6 +129,8 @@ #define SPELL_SPIRITUAL_ECHO 1248 #define SPELL_BRISTLING_ARMAMENT 1249 #define SPELL_WATON_DESTRUCTION 1250 +#define SPELL_TRANSLOCATE_GROUP 1334 +#define SPELL_TRANSLOCATE 1422 #define SPELL_ACTING_MAGIC_RESIST_I 1900 #define SPELL_ACTING_FIRE_RESIST_I 1901 #define SPELL_ACTING_COLD_RESIST_I 1902 @@ -154,6 +156,7 @@ #define SPELL_ACTING_SPIRIT_II 1922 #define SPELL_RESURRECTION_SICKNESS 756 #define SPELL_RESURRECTION_SICKNESS4 757 +#define SPELL_TELEPORT 3243 #define SPELL_RESURRECTION_SICKNESS2 5249 #define SPELL_REVIVAL_SICKNESS 13087 #define SPELL_RESURRECTION_SICKNESS3 37624 @@ -1472,6 +1475,7 @@ bool IsPartialDeathSaveSpell(uint16 spell_id); bool IsShadowStepSpell(uint16 spell_id); bool IsSuccorSpell(uint16 spell_id); bool IsTeleportSpell(uint16 spell_id); +bool IsTranslocateSpell(uint16 spell_id); bool IsGateSpell(uint16 spell_id); bool IsPlayerIllusionSpell(uint16 spell_id); // seveian 2008-09-23 bool IsLDoNObjectSpell(uint16 spell_id); diff --git a/zone/client_packet.cpp b/zone/client_packet.cpp index 8fec728e8..c925d90db 100644 --- a/zone/client_packet.cpp +++ b/zone/client_packet.cpp @@ -14761,38 +14761,44 @@ void Client::Handle_OP_TradeSkillCombine(const EQApplicationPacket *app) void Client::Handle_OP_Translocate(const EQApplicationPacket *app) { - if (app->size != sizeof(Translocate_Struct)) { LogDebug("Size mismatch in OP_Translocate expected [{}] got [{}]", sizeof(Translocate_Struct), app->size); DumpPacket(app); return; } + Translocate_Struct *its = (Translocate_Struct*)app->pBuffer; - if (!PendingTranslocate) + if (!PendingTranslocate) { return; + } - if ((RuleI(Spells, TranslocateTimeLimit) > 0) && (time(nullptr) > (TranslocateTime + RuleI(Spells, TranslocateTimeLimit)))) { + auto translocate_time_limit = RuleI(Spells, TranslocateTimeLimit); + if ( + translocate_time_limit && + time(nullptr) > (TranslocateTime + translocate_time_limit) + ) { Message(Chat::Red, "You did not accept the Translocate within the required time limit."); PendingTranslocate = false; return; } if (its->Complete == 1) { - - int SpellID = PendingTranslocateData.spell_id; - int i = parse->EventSpell(EVENT_SPELL_EFFECT_TRANSLOCATE_COMPLETE, nullptr, this, SpellID, 0); - - if (i == 0) - { + uint32 spell_id = PendingTranslocateData.spell_id; + bool in_translocate_zone = ( + zone->GetZoneID() == PendingTranslocateData.zone_id && + zone->GetInstanceID() == PendingTranslocateData.instance_id + ); + + if (parse->EventSpell(EVENT_SPELL_EFFECT_TRANSLOCATE_COMPLETE, nullptr, this, spell_id, "", 0) == 0) { // If the spell has a translocate to bind effect, AND we are already in the zone the client // is bound in, use the GoToBind method. If we send OP_Translocate in this case, the client moves itself // to the bind coords it has from the PlayerProfile, but with the X and Y reversed. I suspect they are // reversed in the pp, and since spells like Gate are handled serverside, this has not mattered before. - if (((SpellID == 1422) || (SpellID == 1334) || (SpellID == 3243)) && - (zone->GetZoneID() == PendingTranslocateData.zone_id && - zone->GetInstanceID() == PendingTranslocateData.instance_id)) - { + if ( + IsTranslocateSpell(spell_id) && + in_translocate_zone + ) { PendingTranslocate = false; GoToBind(); return; @@ -14800,9 +14806,16 @@ void Client::Handle_OP_Translocate(const EQApplicationPacket *app) ////Was sending the packet back to initiate client zone... ////but that could be abusable, so lets go through proper channels - MovePC(PendingTranslocateData.zone_id, PendingTranslocateData.instance_id, - PendingTranslocateData.x, PendingTranslocateData.y, - PendingTranslocateData.z, PendingTranslocateData.heading, 0, ZoneSolicited); + MovePC( + PendingTranslocateData.zone_id, + PendingTranslocateData.instance_id, + PendingTranslocateData.x, + PendingTranslocateData.y, + PendingTranslocateData.z, + PendingTranslocateData.heading, + 0, + ZoneSolicited + ); } } diff --git a/zone/embparser.cpp b/zone/embparser.cpp index 43bcebe5c..635a48b4c 100644 --- a/zone/embparser.cpp +++ b/zone/embparser.cpp @@ -253,19 +253,15 @@ int PerlembParser::EventCommon( if (isPlayerQuest || isGlobalPlayerQuest) { return SendCommands(package_name.c_str(), sub_name, 0, mob, mob, nullptr); - } - else if (isItemQuest) { + } else if (isItemQuest) { return SendCommands(package_name.c_str(), sub_name, 0, mob, mob, item_inst); - } - else if (isSpellQuest) { + } else if (isSpellQuest) { if (mob) { return SendCommands(package_name.c_str(), sub_name, 0, mob, mob, nullptr); - } - else { + } else { return SendCommands(package_name.c_str(), sub_name, 0, npcmob, mob, nullptr); } - } - else { + } else { return SendCommands(package_name.c_str(), sub_name, objid, npcmob, mob, nullptr); } } @@ -312,11 +308,11 @@ int PerlembParser::EventItem( } int PerlembParser::EventSpell( - QuestEventID evt, NPC *npc, Client *client, uint32 spell_id, uint32 extra_data, + QuestEventID evt, NPC *npc, Client *client, uint32 spell_id, std::string data, uint32 extra_data, std::vector *extra_pointers ) { - return EventCommon(evt, 0, itoa(spell_id), npc, nullptr, client, extra_data, false, extra_pointers); + return EventCommon(evt, spell_id, data.c_str(), npc, nullptr, client, extra_data, false, extra_pointers); } bool PerlembParser::HasQuestSub(uint32 npcid, QuestEventID evt) @@ -1004,8 +1000,8 @@ void PerlembParser::GetQuestTypes( { if (event == EVENT_SPELL_EFFECT_CLIENT || event == EVENT_SPELL_EFFECT_NPC || - event == EVENT_SPELL_BUFF_TIC_CLIENT || - event == EVENT_SPELL_BUFF_TIC_NPC || + event == EVENT_SPELL_EFFECT_BUFF_TIC_CLIENT || + event == EVENT_SPELL_EFFECT_BUFF_TIC_NPC || event == EVENT_SPELL_FADE || event == EVENT_SPELL_EFFECT_TRANSLOCATE_COMPLETE) { isSpellQuest = true; @@ -1042,31 +1038,31 @@ void PerlembParser::GetQuestPackageName( bool global ) { - if (!isPlayerQuest && !isGlobalPlayerQuest && !isItemQuest && !isSpellQuest) { + if ( + !isPlayerQuest && + !isGlobalPlayerQuest && + !isItemQuest && + !isSpellQuest + ) { if (global) { isGlobalNPC = true; package_name = "qst_global_npc"; - } - else { + } else { package_name = "qst_npc_"; - package_name += itoa(npcmob->GetNPCTypeID()); + package_name += std::to_string(npcmob->GetNPCTypeID()); } - } - else if (isItemQuest) { + } else if (isItemQuest) { // need a valid EQ::ItemInstance pointer check here..unsure how to cancel this process const EQ::ItemData *item = item_inst->GetItem(); package_name = "qst_item_"; - package_name += itoa(item->ID); - } - else if (isPlayerQuest) { + package_name += std::to_string(item->ID); + } else if (isPlayerQuest) { package_name = "qst_player"; - } - else if (isGlobalPlayerQuest) { + } else if (isGlobalPlayerQuest) { package_name = "qst_global_player"; - } - else { + } else { package_name = "qst_spell_"; - package_name += data; + package_name += std::to_string(objid); } } @@ -1525,11 +1521,17 @@ void PerlembParser::ExportEventVariables( break; } + case EVENT_SPELL_EFFECT_BUFF_TIC_CLIENT: + case EVENT_SPELL_EFFECT_BUFF_TIC_NPC: case EVENT_SPELL_EFFECT_CLIENT: case EVENT_SPELL_EFFECT_NPC: - case EVENT_SPELL_BUFF_TIC_CLIENT: - case EVENT_SPELL_BUFF_TIC_NPC: { - ExportVar(package_name.c_str(), "caster_id", extradata); + case EVENT_SPELL_FADE: { + Seperator sep(data); + ExportVar(package_name.c_str(), "spell_id", objid); + ExportVar(package_name.c_str(), "caster_id", sep.arg[0]); + ExportVar(package_name.c_str(), "tics_remaining", sep.arg[1]); + ExportVar(package_name.c_str(), "caster_level", sep.arg[2]); + ExportVar(package_name.c_str(), "buff_slot", sep.arg[3]); break; } diff --git a/zone/embparser.h b/zone/embparser.h index ed7989a99..76d6d9717 100644 --- a/zone/embparser.h +++ b/zone/embparser.h @@ -58,7 +58,7 @@ public: std::vector *extra_pointers); virtual int EventItem(QuestEventID evt, Client *client, EQ::ItemInstance *item, Mob *mob, std::string data, uint32 extra_data, std::vector *extra_pointers); - virtual int EventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, uint32 extra_data, + virtual int EventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, std::string data, uint32 extra_data, std::vector *extra_pointers); virtual bool HasQuestSub(uint32 npcid, QuestEventID evt); diff --git a/zone/event_codes.h b/zone/event_codes.h index 0fd9d94b3..8aebee1a7 100644 --- a/zone/event_codes.h +++ b/zone/event_codes.h @@ -43,8 +43,8 @@ typedef enum { EVENT_HATE_LIST, EVENT_SPELL_EFFECT_CLIENT, EVENT_SPELL_EFFECT_NPC, - EVENT_SPELL_BUFF_TIC_CLIENT, - EVENT_SPELL_BUFF_TIC_NPC, + EVENT_SPELL_EFFECT_BUFF_TIC_CLIENT, + EVENT_SPELL_EFFECT_BUFF_TIC_NPC, EVENT_SPELL_FADE, EVENT_SPELL_EFFECT_TRANSLOCATE_COMPLETE, EVENT_COMBINE_SUCCESS, //PC successfully combined a recipe diff --git a/zone/lua_general.cpp b/zone/lua_general.cpp index 283ed5db8..57a426516 100644 --- a/zone/lua_general.cpp +++ b/zone/lua_general.cpp @@ -4126,7 +4126,7 @@ luabind::scope lua_register_events() { luabind::value("target_change", static_cast(EVENT_TARGET_CHANGE)), luabind::value("hate_list", static_cast(EVENT_HATE_LIST)), luabind::value("spell_effect", static_cast(EVENT_SPELL_EFFECT_CLIENT)), - luabind::value("spell_buff_tic", static_cast(EVENT_SPELL_BUFF_TIC_CLIENT)), + luabind::value("spell_buff_tic", static_cast(EVENT_SPELL_EFFECT_BUFF_TIC_CLIENT)), luabind::value("spell_fade", static_cast(EVENT_SPELL_FADE)), luabind::value("spell_effect_translocate_complete", static_cast(EVENT_SPELL_EFFECT_TRANSLOCATE_COMPLETE)), luabind::value("combine_success ", static_cast(EVENT_COMBINE_SUCCESS )), diff --git a/zone/lua_parser.cpp b/zone/lua_parser.cpp index 093f11c62..a1aee9a41 100644 --- a/zone/lua_parser.cpp +++ b/zone/lua_parser.cpp @@ -241,9 +241,9 @@ LuaParser::LuaParser() { ItemArgumentDispatch[EVENT_AUGMENT_INSERT] = handle_item_augment_insert; ItemArgumentDispatch[EVENT_AUGMENT_REMOVE] = handle_item_augment_remove; - SpellArgumentDispatch[EVENT_SPELL_EFFECT_CLIENT] = handle_spell_effect; - SpellArgumentDispatch[EVENT_SPELL_BUFF_TIC_CLIENT] = handle_spell_tic; - SpellArgumentDispatch[EVENT_SPELL_FADE] = handle_spell_fade; + SpellArgumentDispatch[EVENT_SPELL_EFFECT_CLIENT] = handle_spell_event; + SpellArgumentDispatch[EVENT_SPELL_EFFECT_BUFF_TIC_CLIENT] = handle_spell_event; + SpellArgumentDispatch[EVENT_SPELL_FADE] = handle_spell_event; SpellArgumentDispatch[EVENT_SPELL_EFFECT_TRANSLOCATE_COMPLETE] = handle_translocate_finish; EncounterArgumentDispatch[EVENT_TIMER] = handle_encounter_timer; @@ -535,7 +535,7 @@ int LuaParser::_EventItem(std::string package_name, QuestEventID evt, Client *cl return 0; } -int LuaParser::EventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, uint32 extra_data, +int LuaParser::EventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, std::string data, uint32 extra_data, std::vector *extra_pointers) { evt = ConvertLuaEvent(evt); if(evt >= _LargestEventID) { @@ -548,10 +548,10 @@ int LuaParser::EventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spe return 0; } - return _EventSpell(package_name, evt, npc, client, spell_id, extra_data, extra_pointers); + return _EventSpell(package_name, evt, npc, client, spell_id, data, extra_data, extra_pointers); } -int LuaParser::_EventSpell(std::string package_name, QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, uint32 extra_data, +int LuaParser::_EventSpell(std::string package_name, QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, std::string data, uint32 extra_data, std::vector *extra_pointers, luabind::adl::object *l_func) { const char *sub_name = LuaEvents[evt]; @@ -582,7 +582,7 @@ int LuaParser::_EventSpell(std::string package_name, QuestEventID evt, NPC* npc, lua_setfield(L, -2, "self"); auto arg_function = SpellArgumentDispatch[evt]; - arg_function(this, L, npc, client, spell_id, extra_data, extra_pointers); + arg_function(this, L, npc, client, spell_id, data, extra_data, extra_pointers); quest_manager.StartQuest(npc, client, nullptr); if(lua_pcall(L, 1, 1, 0)) { @@ -1276,7 +1276,7 @@ int LuaParser::DispatchEventItem(QuestEventID evt, Client *client, EQ::ItemInsta return ret; } -int LuaParser::DispatchEventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, uint32 extra_data, +int LuaParser::DispatchEventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, std::string data, uint32 extra_data, std::vector *extra_pointers) { evt = ConvertLuaEvent(evt); if(evt >= _LargestEventID) { @@ -1292,7 +1292,7 @@ int LuaParser::DispatchEventSpell(QuestEventID evt, NPC* npc, Client *client, ui while(riter != iter->second.end()) { if(riter->event_id == evt) { std::string package_name = "encounter_" + riter->encounter_name; - int i = _EventSpell(package_name, evt, npc, client, spell_id, extra_data, extra_pointers, &riter->lua_reference); + int i = _EventSpell(package_name, evt, npc, client, spell_id, data, extra_data, extra_pointers, &riter->lua_reference); if(i != 0) { ret = i; } @@ -1310,7 +1310,7 @@ int LuaParser::DispatchEventSpell(QuestEventID evt, NPC* npc, Client *client, ui while(riter != iter->second.end()) { if(riter->event_id == evt) { std::string package_name = "encounter_" + riter->encounter_name; - int i = _EventSpell(package_name, evt, npc, client, spell_id, extra_data, extra_pointers, &riter->lua_reference); + int i = _EventSpell(package_name, evt, npc, client, spell_id, data, extra_data, extra_pointers, &riter->lua_reference); if(i != 0) ret = i; } @@ -1329,9 +1329,9 @@ QuestEventID LuaParser::ConvertLuaEvent(QuestEventID evt) { case EVENT_SPELL_EFFECT_NPC: return EVENT_SPELL_EFFECT_CLIENT; break; - case EVENT_SPELL_BUFF_TIC_CLIENT: - case EVENT_SPELL_BUFF_TIC_NPC: - return EVENT_SPELL_BUFF_TIC_CLIENT; + case EVENT_SPELL_EFFECT_BUFF_TIC_CLIENT: + case EVENT_SPELL_EFFECT_BUFF_TIC_NPC: + return EVENT_SPELL_EFFECT_BUFF_TIC_CLIENT; break; case EVENT_AGGRO: case EVENT_ATTACK: diff --git a/zone/lua_parser.h b/zone/lua_parser.h index d058daf13..831f22061 100644 --- a/zone/lua_parser.h +++ b/zone/lua_parser.h @@ -46,7 +46,7 @@ public: std::vector *extra_pointers); virtual int EventItem(QuestEventID evt, Client *client, EQ::ItemInstance *item, Mob *mob, std::string data, uint32 extra_data, std::vector *extra_pointers); - virtual int EventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, uint32 extra_data, + virtual int EventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, std::string data, uint32 extra_data, std::vector *extra_pointers); virtual int EventEncounter(QuestEventID evt, std::string encounter_name, std::string data, uint32 extra_data, std::vector *extra_pointers); @@ -80,7 +80,7 @@ public: std::vector *extra_pointers); virtual int DispatchEventItem(QuestEventID evt, Client *client, EQ::ItemInstance *item, Mob *mob, std::string data, uint32 extra_data, std::vector *extra_pointers); - virtual int DispatchEventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, uint32 extra_data, + virtual int DispatchEventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, std::string data, uint32 extra_data, std::vector *extra_pointers); static LuaParser* Instance() { @@ -112,7 +112,7 @@ private: std::vector *extra_pointers, luabind::adl::object *l_func = nullptr); int _EventItem(std::string package_name, QuestEventID evt, Client *client, EQ::ItemInstance *item, Mob *mob, std::string data, uint32 extra_data, std::vector *extra_pointers, luabind::adl::object *l_func = nullptr); - int _EventSpell(std::string package_name, QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, uint32 extra_data, + int _EventSpell(std::string package_name, QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, std::string data, uint32 extra_data, std::vector *extra_pointers, luabind::adl::object *l_func = nullptr); int _EventEncounter(std::string package_name, QuestEventID evt, std::string encounter_name, std::string data, uint32 extra_data, std::vector *extra_pointers); diff --git a/zone/lua_parser_events.cpp b/zone/lua_parser_events.cpp index e7711b36c..9adc0981e 100644 --- a/zone/lua_parser_events.cpp +++ b/zone/lua_parser_events.cpp @@ -702,8 +702,7 @@ void handle_item_null(QuestInterface *parse, lua_State* L, Client* client, EQ::I } //Spell -void handle_spell_effect(QuestInterface *parse, lua_State* L, NPC* npc, Client* client, uint32 spell_id, uint32 extra_data, - std::vector *extra_pointers) { +void handle_spell_event(QuestInterface *parse, lua_State* L, NPC* npc, Client* client, uint32 spell_id, std::string data, uint32 extra_data, std::vector *extra_pointers) { if(npc) { Lua_Mob l_npc(npc); luabind::adl::object l_npc_o = luabind::adl::object(L, l_npc); @@ -720,71 +719,30 @@ void handle_spell_effect(QuestInterface *parse, lua_State* L, NPC* npc, Client* lua_setfield(L, -2, "target"); - lua_pushinteger(L, *EQ::any_cast(extra_pointers->at(0))); - lua_setfield(L, -2, "buff_slot"); + lua_pushinteger(L, spell_id); + lua_setfield(L, -2, "spell_id"); - lua_pushinteger(L, extra_data); + Seperator sep(data.c_str()); + + lua_pushinteger(L, std::stoi(sep.arg[0])); lua_setfield(L, -2, "caster_id"); -} -void handle_spell_tic(QuestInterface *parse, lua_State* L, NPC* npc, Client* client, uint32 spell_id, uint32 extra_data, - std::vector *extra_pointers) { - if(npc) { - Lua_Mob l_npc(npc); - luabind::adl::object l_npc_o = luabind::adl::object(L, l_npc); - l_npc_o.push(L); - } else if(client) { - Lua_Mob l_client(client); - luabind::adl::object l_client_o = luabind::adl::object(L, l_client); - l_client_o.push(L); - } else { - Lua_Mob l_mob(nullptr); - luabind::adl::object l_mob_o = luabind::adl::object(L, l_mob); - l_mob_o.push(L); - } - - lua_setfield(L, -2, "target"); - - lua_pushinteger(L, *EQ::any_cast(extra_pointers->at(0))); + lua_pushinteger(L, std::stoi(sep.arg[1])); lua_setfield(L, -2, "tics_remaining"); - lua_pushinteger(L, *EQ::any_cast(extra_pointers->at(1))); + lua_pushinteger(L, std::stoi(sep.arg[2])); lua_setfield(L, -2, "caster_level"); - lua_pushinteger(L, *EQ::any_cast(extra_pointers->at(2))); + lua_pushinteger(L, std::stoi(sep.arg[3])); lua_setfield(L, -2, "buff_slot"); - - lua_pushinteger(L, extra_data); - lua_setfield(L, -2, "caster_id"); + + Lua_Spell l_spell(spell_id); + luabind::adl::object l_spell_o = luabind::adl::object(L, l_spell); + l_spell_o.push(L); + lua_setfield(L, -2, "spell"); } -void handle_spell_fade(QuestInterface *parse, lua_State* L, NPC* npc, Client* client, uint32 spell_id, uint32 extra_data, - std::vector *extra_pointers) { - if(npc) { - Lua_Mob l_npc(npc); - luabind::adl::object l_npc_o = luabind::adl::object(L, l_npc); - l_npc_o.push(L); - } else if(client) { - Lua_Mob l_client(client); - luabind::adl::object l_client_o = luabind::adl::object(L, l_client); - l_client_o.push(L); - } else { - Lua_Mob l_mob(nullptr); - luabind::adl::object l_mob_o = luabind::adl::object(L, l_mob); - l_mob_o.push(L); - } - - lua_setfield(L, -2, "target"); - - lua_pushinteger(L, extra_data); - lua_setfield(L, -2, "buff_slot"); - - lua_pushinteger(L, *EQ::any_cast(extra_pointers->at(0))); - lua_setfield(L, -2, "caster_id"); -} - -void handle_translocate_finish(QuestInterface *parse, lua_State* L, NPC* npc, Client* client, uint32 spell_id, uint32 extra_data, - std::vector *extra_pointers) { +void handle_translocate_finish(QuestInterface *parse, lua_State* L, NPC* npc, Client* client, uint32 spell_id, std::string data, uint32 extra_data, std::vector *extra_pointers) { if(npc) { Lua_Mob l_npc(npc); luabind::adl::object l_npc_o = luabind::adl::object(L, l_npc); @@ -802,9 +760,7 @@ void handle_translocate_finish(QuestInterface *parse, lua_State* L, NPC* npc, Cl lua_setfield(L, -2, "target"); } -void handle_spell_null(QuestInterface *parse, lua_State* L, NPC* npc, Client* client, uint32 spell_id, uint32 extra_data, - std::vector *extra_pointers) { -} +void handle_spell_null(QuestInterface *parse, lua_State* L, NPC* npc, Client* client, uint32 spell_id, std::string data, uint32 extra_data, std::vector *extra_pointers) { } void handle_encounter_timer(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 1d9d4b22c..5eced1243 100644 --- a/zone/lua_parser_events.h +++ b/zone/lua_parser_events.h @@ -5,7 +5,7 @@ typedef void(*NPCArgumentHandler)(QuestInterface*, lua_State*, NPC*, Mob*, std::string, uint32, std::vector*); typedef void(*PlayerArgumentHandler)(QuestInterface*, lua_State*, Client*, std::string, uint32, std::vector*); typedef void(*ItemArgumentHandler)(QuestInterface*, lua_State*, Client*, EQ::ItemInstance*, Mob*, std::string, uint32, std::vector*); -typedef void(*SpellArgumentHandler)(QuestInterface*, lua_State*, NPC*, Client*, uint32, uint32, std::vector*); +typedef void(*SpellArgumentHandler)(QuestInterface*, lua_State*, NPC*, Client*, uint32, std::string, uint32, std::vector*); typedef void(*EncounterArgumentHandler)(QuestInterface*, lua_State*, Encounter* encounter, std::string, uint32, std::vector*); //NPC @@ -135,15 +135,11 @@ void handle_item_null(QuestInterface *parse, lua_State* L, Client* client, EQ::I std::vector *extra_pointers); //Spell -void handle_spell_effect(QuestInterface *parse, lua_State* L, NPC* npc, Client* client, uint32 spell_id, uint32 extra_data, +void handle_spell_event(QuestInterface *parse, lua_State* L, NPC* npc, Client* client, uint32 spell_id, std::string data, uint32 extra_data, std::vector *extra_pointers); -void handle_spell_tic(QuestInterface *parse, lua_State* L, NPC* npc, Client* client, uint32 spell_id, uint32 extra_data, +void handle_translocate_finish(QuestInterface *parse, lua_State* L, NPC* npc, Client* client, uint32 spell_id, std::string data, uint32 extra_data, std::vector *extra_pointers); -void handle_spell_fade(QuestInterface *parse, lua_State* L, NPC* npc, Client* client, uint32 spell_id, uint32 extra_data, - std::vector *extra_pointers); -void handle_translocate_finish(QuestInterface *parse, lua_State* L, NPC* npc, Client* client, uint32 spell_id, uint32 extra_data, - std::vector *extra_pointers); -void handle_spell_null(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, std::string data, uint32 extra_data, std::vector *extra_pointers); diff --git a/zone/quest_interface.h b/zone/quest_interface.h index d0f121cb6..794251e36 100644 --- a/zone/quest_interface.h +++ b/zone/quest_interface.h @@ -43,7 +43,7 @@ public: std::vector *extra_pointers) { return 0; } virtual int EventItem(QuestEventID evt, Client *client, EQ::ItemInstance *item, Mob *mob, std::string data, uint32 extra_data, std::vector *extra_pointers) { return 0; } - virtual int EventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, uint32 extra_data, + virtual int EventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, std::string data, uint32 extra_data, std::vector *extra_pointers) { return 0; } virtual int EventEncounter(QuestEventID evt, std::string encounter_name, std::string data, uint32 extra_data, std::vector *extra_pointers) { return 0; } @@ -70,7 +70,7 @@ public: std::vector *extra_pointers) { return 0; } virtual int DispatchEventItem(QuestEventID evt, Client *client, EQ::ItemInstance *item, Mob *mob, std::string data, uint32 extra_data, std::vector *extra_pointers) { return 0; } - virtual int DispatchEventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, uint32 extra_data, + virtual int DispatchEventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, std::string data, uint32 extra_data, std::vector *extra_pointers) { return 0; } virtual void AddVar(std::string name, std::string val) { } diff --git a/zone/quest_parser_collection.cpp b/zone/quest_parser_collection.cpp index 625425839..8c5185ad6 100644 --- a/zone/quest_parser_collection.cpp +++ b/zone/quest_parser_collection.cpp @@ -410,21 +410,21 @@ int QuestParserCollection::EventItem(QuestEventID evt, Client *client, EQ::ItemI return 0; } -int QuestParserCollection::EventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, uint32 extra_data, +int QuestParserCollection::EventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, std::string data, uint32 extra_data, std::vector *extra_pointers) { auto iter = _spell_quest_status.find(spell_id); if(iter != _spell_quest_status.end()) { //loaded or failed to load if(iter->second != QuestFailedToLoad) { auto qiter = _interfaces.find(iter->second); - int ret = DispatchEventSpell(evt, npc, client, spell_id, extra_data, extra_pointers); - int i = qiter->second->EventSpell(evt, npc, client, spell_id, extra_data, extra_pointers); + int ret = DispatchEventSpell(evt, npc, client, spell_id, data, extra_data, extra_pointers); + int i = qiter->second->EventSpell(evt, npc, client, spell_id, data, extra_data, extra_pointers); if(i != 0) { ret = i; } return ret; } - return DispatchEventSpell(evt, npc, client, spell_id, extra_data, extra_pointers); + return DispatchEventSpell(evt, npc, client, spell_id, data, extra_data, extra_pointers); } else if (_spell_quest_status[spell_id] != QuestFailedToLoad) { std::string filename; @@ -432,8 +432,8 @@ int QuestParserCollection::EventSpell(QuestEventID evt, NPC* npc, Client *client if (qi) { _spell_quest_status[spell_id] = qi->GetIdentifier(); qi->LoadSpellScript(filename, spell_id); - int ret = DispatchEventSpell(evt, npc, client, spell_id, extra_data, extra_pointers); - int i = qi->EventSpell(evt, npc, client, spell_id, extra_data, extra_pointers); + int ret = DispatchEventSpell(evt, npc, client, spell_id, data, extra_data, extra_pointers); + int i = qi->EventSpell(evt, npc, client, spell_id, data, extra_data, extra_pointers); if (i != 0) { ret = i; } @@ -441,7 +441,7 @@ int QuestParserCollection::EventSpell(QuestEventID evt, NPC* npc, Client *client } else { _spell_quest_status[spell_id] = QuestFailedToLoad; - return DispatchEventSpell(evt, npc, client, spell_id, extra_data, extra_pointers); + return DispatchEventSpell(evt, npc, client, spell_id, data, extra_data, extra_pointers); } } return 0; @@ -1042,12 +1042,12 @@ int QuestParserCollection::DispatchEventItem(QuestEventID evt, Client *client, E return ret; } -int QuestParserCollection::DispatchEventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, uint32 extra_data, +int QuestParserCollection::DispatchEventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, std::string data, uint32 extra_data, std::vector *extra_pointers) { int ret = 0; auto iter = _load_precedence.begin(); while(iter != _load_precedence.end()) { - int i = (*iter)->DispatchEventSpell(evt, npc, client, spell_id, extra_data, extra_pointers); + int i = (*iter)->DispatchEventSpell(evt, npc, client, spell_id, data, extra_data, extra_pointers); if(i != 0) { ret = i; } diff --git a/zone/quest_parser_collection.h b/zone/quest_parser_collection.h index 082b5b6f4..c8ebc2427 100644 --- a/zone/quest_parser_collection.h +++ b/zone/quest_parser_collection.h @@ -78,7 +78,7 @@ public: std::vector *extra_pointers = nullptr); int EventItem(QuestEventID evt, Client *client, EQ::ItemInstance *item, Mob *mob, std::string data, uint32 extra_data, std::vector *extra_pointers = nullptr); - int EventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, uint32 extra_data, + int EventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, std::string data, uint32 extra_data, std::vector *extra_pointers = nullptr); int EventEncounter(QuestEventID evt, std::string encounter_name, std::string data, uint32 extra_data, std::vector *extra_pointers = nullptr); @@ -131,7 +131,7 @@ private: std::vector *extra_pointers); int DispatchEventItem(QuestEventID evt, Client *client, EQ::ItemInstance *item, Mob *mob, std::string data, uint32 extra_data, std::vector *extra_pointers); - int DispatchEventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, uint32 extra_data, + int DispatchEventSpell(QuestEventID evt, NPC* npc, Client *client, uint32 spell_id, std::string data, uint32 extra_data, std::vector *extra_pointers); std::map _interfaces; diff --git a/zone/spell_effects.cpp b/zone/spell_effects.cpp index db2e78ecc..926cfff6d 100644 --- a/zone/spell_effects.cpp +++ b/zone/spell_effects.cpp @@ -161,22 +161,21 @@ bool Mob::SpellEffect(Mob* caster, uint16 spell_id, float partial, int level_ove } } - if(IsNPC()) - { - std::vector args; - args.push_back(&buffslot); - int i = parse->EventSpell(EVENT_SPELL_EFFECT_NPC, CastToNPC(), nullptr, spell_id, caster ? caster->GetID() : 0, &args); - if(i != 0){ + std::string buf = fmt::format( + "{} {} {} {}", + caster->GetID(), + buffs[buffslot].ticsremaining, + caster->GetLevel(), + buffslot + ); + + if (IsClient()) { + if (parse->EventSpell(EVENT_SPELL_EFFECT_CLIENT, nullptr, CastToClient(), spell_id, buf, 0) != 0) { CalcBonuses(); return true; } - } - else if(IsClient()) - { - std::vector args; - args.push_back(&buffslot); - int i = parse->EventSpell(EVENT_SPELL_EFFECT_CLIENT, nullptr, CastToClient(), spell_id, caster ? caster->GetID() : 0, &args); - if(i != 0){ + } else if (IsNPC()) { + if (parse->EventSpell(EVENT_SPELL_EFFECT_NPC, CastToNPC(), nullptr, spell_id, buf, 0) != 0) { CalcBonuses(); return true; } @@ -3750,24 +3749,20 @@ void Mob::DoBuffTic(const Buffs_Struct &buff, int slot, Mob *caster) const SPDat_Spell_Struct &spell = spells[buff.spellid]; - if (IsNPC()) { - std::vector args; - args.push_back(&buff.ticsremaining); - args.push_back(&buff.casterlevel); - args.push_back(&slot); - int i = parse->EventSpell(EVENT_SPELL_BUFF_TIC_NPC, CastToNPC(), nullptr, buff.spellid, - caster ? caster->GetID() : 0, &args); - if (i != 0) { + std::string buf = fmt::format( + "{} {} {} {}", + caster->GetID(), + buffs[slot].ticsremaining, + caster->GetLevel(), + slot + ); + + if (IsClient()) { + if (parse->EventSpell(EVENT_SPELL_EFFECT_BUFF_TIC_CLIENT, nullptr, CastToClient(), buff.spellid, buf, 0) != 0) { return; } - } else { - std::vector args; - args.push_back(&buff.ticsremaining); - args.push_back(&buff.casterlevel); - args.push_back(&slot); - int i = parse->EventSpell(EVENT_SPELL_BUFF_TIC_CLIENT, nullptr, CastToClient(), buff.spellid, - caster ? caster->GetID() : 0, &args); - if (i != 0) { + } else if (IsNPC()) { + if (parse->EventSpell(EVENT_SPELL_EFFECT_BUFF_TIC_NPC, CastToNPC(), nullptr, buff.spellid, buf, 0) != 0) { return; } } @@ -4115,16 +4110,22 @@ void Mob::BuffFadeBySlot(int slot, bool iRecalcBonuses) } } - if(IsClient()) { - std::vector args; - args.push_back(&buffs[slot].casterid); + std::string buf = fmt::format( + "{} {} {} {}", + buffs[slot].casterid, + buffs[slot].ticsremaining, + buffs[slot].casterlevel, + slot + ); - parse->EventSpell(EVENT_SPELL_FADE, nullptr, CastToClient(), buffs[slot].spellid, slot, &args); - } else if(IsNPC()) { - std::vector args; - args.push_back(&buffs[slot].casterid); - - parse->EventSpell(EVENT_SPELL_FADE, CastToNPC(), nullptr, buffs[slot].spellid, slot, &args); + if (IsClient()) { + if (parse->EventSpell(EVENT_SPELL_FADE, nullptr, CastToClient(), buffs[slot].spellid, buf, 0) != 0) { + return; + } + } else if (IsNPC()) { + if (parse->EventSpell(EVENT_SPELL_FADE, CastToNPC(), nullptr, buffs[slot].spellid, buf, 0) != 0) { + return; + } } for (int i=0; i < EFFECT_COUNT; i++)