From 90406e03285e19b35115fa9ba74e702a62e1a850 Mon Sep 17 00:00:00 2001 From: Kinglykrab <89047260+Kinglykrab@users.noreply.github.com> Date: Wed, 28 Sep 2022 04:02:42 -0400 Subject: [PATCH] [Quest API] Add Merchant Events to Perl/Lua. (#2452) - Add EVENT_ALT_CURRENCY_MERCHANT_BUY to Perl/Lua. - Add EVENT_ALT_CURRENCY_MERCHANT_SELL to Perl/Lua. - Add EVENT_MERCHANT_BUY to Perl/Lua. - Add EVENT_MERCHANT_SELL to Perl/Lua. This will allow server operators to track or do specific stuff based on if a person buys X item from Y NPC or whatever. --- zone/client_packet.cpp | 41 ++++++++++++++++++++++++++++++++++++++ zone/embparser.cpp | 28 +++++++++++++++++++++++++- zone/event_codes.h | 4 ++++ zone/lua_general.cpp | 6 +++++- zone/lua_parser.cpp | 10 +++++++++- zone/lua_parser_events.cpp | 36 +++++++++++++++++++++++++++++++++ zone/lua_parser_events.h | 4 ++++ 7 files changed, 126 insertions(+), 3 deletions(-) diff --git a/zone/client_packet.cpp b/zone/client_packet.cpp index 089e24127..bd5fc3d03 100644 --- a/zone/client_packet.cpp +++ b/zone/client_packet.cpp @@ -2575,6 +2575,16 @@ void Client::Handle_OP_AltCurrencyPurchase(const EQApplicationPacket *app) QServ->PlayerLogEvent(Player_Log_Alternate_Currency_Transactions, CharacterID(), event_desc); } + const auto& export_string = fmt::format( + "{} {} {} {} {}", + alt_cur_id, + tar->GetNPCTypeID(), + tar->MerchantType, + item->ID, + cost + ); + parse->EventPlayer(EVENT_ALT_CURRENCY_MERCHANT_BUY, this, export_string, 0); + AddAlternateCurrencyValue(alt_cur_id, -((int32)cost)); int16 charges = 1; if (item->MaxCharges != 0) @@ -2730,6 +2740,16 @@ void Client::Handle_OP_AltCurrencySell(const EQApplicationPacket *app) QServ->PlayerLogEvent(Player_Log_Alternate_Currency_Transactions, CharacterID(), event_desc); } + const auto& export_string = fmt::format( + "{} {} {} {} {}", + alt_cur_id, + tar->GetNPCTypeID(), + tar->MerchantType, + item->ID, + cost + ); + parse->EventPlayer(EVENT_ALT_CURRENCY_MERCHANT_SELL, this, export_string, 0); + FastQueuePacket(&outapp); AddAlternateCurrencyValue(alt_cur_id, cost); Save(1); @@ -13222,6 +13242,16 @@ void Client::Handle_OP_ShopPlayerBuy(const EQApplicationPacket *app) if (RuleB(EventLog, RecordBuyFromMerchant)) LogMerchant(this, tmp, mpo->quantity, mpo->price, item, true); + const auto& export_string = fmt::format( + "{} {} {} {} {}", + tmp->GetNPCTypeID(), + tmp->CastToNPC()->MerchantType, + item_id, + mpo->quantity, + mpo->price + ); + parse->EventPlayer(EVENT_MERCHANT_BUY, this, export_string, 0); + if ((RuleB(Character, EnableDiscoveredItems))) { if (!GetGM() && !IsDiscovered(item_id)) @@ -13379,6 +13409,17 @@ void Client::Handle_OP_ShopPlayerSell(const EQApplicationPacket *app) } // end QS code + const auto& export_string = fmt::format( + "{} {} {} {} {}", + vendor->GetNPCTypeID(), + vendor->CastToNPC()->MerchantType, + itemid, + mp->quantity, + price + ); + parse->EventPlayer(EVENT_MERCHANT_SELL, this, export_string, 0); + + // Now remove the item from the player, this happens regardless of outcome DeleteItemInInventory( mp->itemslot, diff --git a/zone/embparser.cpp b/zone/embparser.cpp index 69e55cfeb..d90b960b7 100644 --- a/zone/embparser.cpp +++ b/zone/embparser.cpp @@ -154,7 +154,11 @@ const char *QuestEventSubroutines[_LargestEventID] = { "EVENT_EQUIP_ITEM_CLIENT", "EVENT_UNEQUIP_ITEM_CLIENT", "EVENT_SKILL_UP", - "EVENT_LANGUAGE_SKILL_UP" + "EVENT_LANGUAGE_SKILL_UP", + "EVENT_ALT_CURRENCY_MERCHANT_BUY", + "EVENT_ALT_CURRENCY_MERCHANT_SELL", + "EVENT_MERCHANT_BUY", + "EVENT_MERCHANT_SELL" }; PerlembParser::PerlembParser() : perl(nullptr) @@ -1708,6 +1712,28 @@ void PerlembParser::ExportEventVariables( break; } + case EVENT_ALT_CURRENCY_MERCHANT_BUY: + case EVENT_ALT_CURRENCY_MERCHANT_SELL: { + Seperator sep(data); + ExportVar(package_name.c_str(), "currency_id", sep.arg[0]); + ExportVar(package_name.c_str(), "npc_id", sep.arg[1]); + ExportVar(package_name.c_str(), "merchant_id", sep.arg[2]); + ExportVar(package_name.c_str(), "item_id", sep.arg[3]); + ExportVar(package_name.c_str(), "item_cost", sep.arg[4]); + break; + } + + case EVENT_MERCHANT_BUY: + case EVENT_MERCHANT_SELL: { + Seperator sep(data); + ExportVar(package_name.c_str(), "npc_id", sep.arg[0]); + ExportVar(package_name.c_str(), "merchant_id", sep.arg[1]); + ExportVar(package_name.c_str(), "item_id", sep.arg[2]); + ExportVar(package_name.c_str(), "item_quantity", sep.arg[3]); + ExportVar(package_name.c_str(), "item_cost", sep.arg[4]); + break; + } + default: { break; } diff --git a/zone/event_codes.h b/zone/event_codes.h index 9044a9bf4..012caa9a2 100644 --- a/zone/event_codes.h +++ b/zone/event_codes.h @@ -98,6 +98,10 @@ typedef enum { EVENT_UNEQUIP_ITEM_CLIENT, EVENT_SKILL_UP, EVENT_LANGUAGE_SKILL_UP, + EVENT_ALT_CURRENCY_MERCHANT_BUY, + EVENT_ALT_CURRENCY_MERCHANT_SELL, + EVENT_MERCHANT_BUY, + EVENT_MERCHANT_SELL, _LargestEventID } QuestEventID; diff --git a/zone/lua_general.cpp b/zone/lua_general.cpp index fda3c5beb..dd91b183e 100644 --- a/zone/lua_general.cpp +++ b/zone/lua_general.cpp @@ -4283,7 +4283,11 @@ luabind::scope lua_register_events() { luabind::value("equip_item_client", static_cast(EVENT_EQUIP_ITEM_CLIENT)), luabind::value("unequip_item_client", static_cast(EVENT_UNEQUIP_ITEM_CLIENT)), luabind::value("skill_up", static_cast(EVENT_SKILL_UP)), - luabind::value("language_skill_up", static_cast(EVENT_LANGUAGE_SKILL_UP)) + luabind::value("language_skill_up", static_cast(EVENT_LANGUAGE_SKILL_UP)), + luabind::value("alt_currency_merchant_buy", static_cast(EVENT_ALT_CURRENCY_MERCHANT_BUY)), + luabind::value("alt_currency_merchant_sell", static_cast(EVENT_ALT_CURRENCY_MERCHANT_SELL)), + luabind::value("merchant_buy", static_cast(EVENT_MERCHANT_BUY)), + luabind::value("merchant_sell", static_cast(EVENT_MERCHANT_SELL)) ]; } diff --git a/zone/lua_parser.cpp b/zone/lua_parser.cpp index 4ae02a326..cbbb69ece 100644 --- a/zone/lua_parser.cpp +++ b/zone/lua_parser.cpp @@ -140,7 +140,11 @@ const char *LuaEvents[_LargestEventID] = { "event_equip_item_client", "event_unequip_item_client", "event_skill_up", - "event_language_skill_up" + "event_language_skill_up", + "event_alt_currency_merchant_buy", + "event_alt_currency_merchant_sell", + "event_merchant_buy", + "event_merchant_sell" }; extern Zone *zone; @@ -236,6 +240,10 @@ LuaParser::LuaParser() { PlayerArgumentDispatch[EVENT_UNEQUIP_ITEM_CLIENT] = handle_player_equip_item; PlayerArgumentDispatch[EVENT_SKILL_UP] = handle_player_skill_up; PlayerArgumentDispatch[EVENT_LANGUAGE_SKILL_UP] = handle_player_skill_up; + PlayerArgumentDispatch[EVENT_ALT_CURRENCY_MERCHANT_BUY] = handle_player_alt_currency_merchant; + PlayerArgumentDispatch[EVENT_ALT_CURRENCY_MERCHANT_SELL] = handle_player_alt_currency_merchant; + PlayerArgumentDispatch[EVENT_MERCHANT_BUY] = handle_player_merchant; + PlayerArgumentDispatch[EVENT_MERCHANT_SELL] = handle_player_merchant; ItemArgumentDispatch[EVENT_ITEM_CLICK] = handle_item_click; ItemArgumentDispatch[EVENT_ITEM_CLICK_CAST] = handle_item_click; diff --git a/zone/lua_parser_events.cpp b/zone/lua_parser_events.cpp index c5ecf824c..9396d116c 100644 --- a/zone/lua_parser_events.cpp +++ b/zone/lua_parser_events.cpp @@ -855,4 +855,40 @@ void handle_player_language_skill_up(QuestInterface* parse, lua_State* L, Client lua_setfield(L, -2, "skill_max"); } +void handle_player_alt_currency_merchant(QuestInterface* parse, lua_State* L, Client* client, std::string data, uint32 extra_data, std::vector* extra_pointers) { + Seperator sep(data.c_str()); + lua_pushinteger(L, std::stoi(sep.arg[0])); + lua_setfield(L, -2, "currency_id"); + + lua_pushinteger(L, std::stoi(sep.arg[1])); + lua_setfield(L, -2, "npc_id"); + + lua_pushinteger(L, std::stoi(sep.arg[2])); + lua_setfield(L, -2, "merchant_id"); + + lua_pushinteger(L, std::stoi(sep.arg[3])); + lua_setfield(L, -2, "item_id"); + + lua_pushinteger(L, std::stoi(sep.arg[4])); + lua_setfield(L, -2, "item_cost"); +} + +void handle_player_merchant(QuestInterface* parse, lua_State* L, Client* client, std::string data, uint32 extra_data, std::vector* extra_pointers) { + Seperator sep(data.c_str()); + lua_pushinteger(L, std::stoi(sep.arg[0])); + lua_setfield(L, -2, "npc_id"); + + lua_pushinteger(L, std::stoi(sep.arg[1])); + lua_setfield(L, -2, "merchant_id"); + + lua_pushinteger(L, std::stoi(sep.arg[2])); + lua_setfield(L, -2, "item_id"); + + lua_pushinteger(L, std::stoi(sep.arg[3])); + lua_setfield(L, -2, "item_quantity"); + + lua_pushinteger(L, std::stoi(sep.arg[4])); + lua_setfield(L, -2, "item_cost"); +} + #endif diff --git a/zone/lua_parser_events.h b/zone/lua_parser_events.h index 0b0c3fc69..d70050a20 100644 --- a/zone/lua_parser_events.h +++ b/zone/lua_parser_events.h @@ -119,6 +119,10 @@ void handle_player_skill_up(QuestInterface* parse, lua_State* L, Client* client, std::vector* extra_pointers); void handle_player_language_skill_up(QuestInterface* parse, lua_State* L, Client* client, std::string data, uint32 extra_data, std::vector* extra_pointers); +void handle_player_alt_currency_merchant(QuestInterface* parse, lua_State* L, Client* client, std::string data, uint32 extra_data, + std::vector* extra_pointers); +void handle_player_merchant(QuestInterface* parse, lua_State* L, Client* client, std::string data, uint32 extra_data, + std::vector* extra_pointers); //Item void handle_item_click(QuestInterface *parse, lua_State* L, Client* client, EQ::ItemInstance* item, Mob *mob, std::string data, uint32 extra_data,