[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.
This commit is contained in:
Kinglykrab 2022-09-28 04:02:42 -04:00 committed by GitHub
parent e883703b2f
commit 90406e0328
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 126 additions and 3 deletions

View File

@ -2575,6 +2575,16 @@ void Client::Handle_OP_AltCurrencyPurchase(const EQApplicationPacket *app)
QServ->PlayerLogEvent(Player_Log_Alternate_Currency_Transactions, CharacterID(), event_desc); 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)); AddAlternateCurrencyValue(alt_cur_id, -((int32)cost));
int16 charges = 1; int16 charges = 1;
if (item->MaxCharges != 0) 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); 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); FastQueuePacket(&outapp);
AddAlternateCurrencyValue(alt_cur_id, cost); AddAlternateCurrencyValue(alt_cur_id, cost);
Save(1); Save(1);
@ -13222,6 +13242,16 @@ void Client::Handle_OP_ShopPlayerBuy(const EQApplicationPacket *app)
if (RuleB(EventLog, RecordBuyFromMerchant)) if (RuleB(EventLog, RecordBuyFromMerchant))
LogMerchant(this, tmp, mpo->quantity, mpo->price, item, true); 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 ((RuleB(Character, EnableDiscoveredItems)))
{ {
if (!GetGM() && !IsDiscovered(item_id)) if (!GetGM() && !IsDiscovered(item_id))
@ -13379,6 +13409,17 @@ void Client::Handle_OP_ShopPlayerSell(const EQApplicationPacket *app)
} }
// end QS code // 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 // Now remove the item from the player, this happens regardless of outcome
DeleteItemInInventory( DeleteItemInInventory(
mp->itemslot, mp->itemslot,

View File

@ -154,7 +154,11 @@ const char *QuestEventSubroutines[_LargestEventID] = {
"EVENT_EQUIP_ITEM_CLIENT", "EVENT_EQUIP_ITEM_CLIENT",
"EVENT_UNEQUIP_ITEM_CLIENT", "EVENT_UNEQUIP_ITEM_CLIENT",
"EVENT_SKILL_UP", "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) PerlembParser::PerlembParser() : perl(nullptr)
@ -1708,6 +1712,28 @@ void PerlembParser::ExportEventVariables(
break; 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: { default: {
break; break;
} }

View File

@ -98,6 +98,10 @@ typedef enum {
EVENT_UNEQUIP_ITEM_CLIENT, EVENT_UNEQUIP_ITEM_CLIENT,
EVENT_SKILL_UP, 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,
_LargestEventID _LargestEventID
} QuestEventID; } QuestEventID;

View File

@ -4283,7 +4283,11 @@ luabind::scope lua_register_events() {
luabind::value("equip_item_client", static_cast<int>(EVENT_EQUIP_ITEM_CLIENT)), luabind::value("equip_item_client", static_cast<int>(EVENT_EQUIP_ITEM_CLIENT)),
luabind::value("unequip_item_client", static_cast<int>(EVENT_UNEQUIP_ITEM_CLIENT)), luabind::value("unequip_item_client", static_cast<int>(EVENT_UNEQUIP_ITEM_CLIENT)),
luabind::value("skill_up", static_cast<int>(EVENT_SKILL_UP)), luabind::value("skill_up", static_cast<int>(EVENT_SKILL_UP)),
luabind::value("language_skill_up", static_cast<int>(EVENT_LANGUAGE_SKILL_UP)) luabind::value("language_skill_up", static_cast<int>(EVENT_LANGUAGE_SKILL_UP)),
luabind::value("alt_currency_merchant_buy", static_cast<int>(EVENT_ALT_CURRENCY_MERCHANT_BUY)),
luabind::value("alt_currency_merchant_sell", static_cast<int>(EVENT_ALT_CURRENCY_MERCHANT_SELL)),
luabind::value("merchant_buy", static_cast<int>(EVENT_MERCHANT_BUY)),
luabind::value("merchant_sell", static_cast<int>(EVENT_MERCHANT_SELL))
]; ];
} }

View File

@ -140,7 +140,11 @@ const char *LuaEvents[_LargestEventID] = {
"event_equip_item_client", "event_equip_item_client",
"event_unequip_item_client", "event_unequip_item_client",
"event_skill_up", "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; extern Zone *zone;
@ -236,6 +240,10 @@ LuaParser::LuaParser() {
PlayerArgumentDispatch[EVENT_UNEQUIP_ITEM_CLIENT] = handle_player_equip_item; PlayerArgumentDispatch[EVENT_UNEQUIP_ITEM_CLIENT] = handle_player_equip_item;
PlayerArgumentDispatch[EVENT_SKILL_UP] = handle_player_skill_up; PlayerArgumentDispatch[EVENT_SKILL_UP] = handle_player_skill_up;
PlayerArgumentDispatch[EVENT_LANGUAGE_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] = handle_item_click;
ItemArgumentDispatch[EVENT_ITEM_CLICK_CAST] = handle_item_click; ItemArgumentDispatch[EVENT_ITEM_CLICK_CAST] = handle_item_click;

View File

@ -855,4 +855,40 @@ void handle_player_language_skill_up(QuestInterface* parse, lua_State* L, Client
lua_setfield(L, -2, "skill_max"); 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<std::any>* 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<std::any>* 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 #endif

View File

@ -119,6 +119,10 @@ void handle_player_skill_up(QuestInterface* parse, lua_State* L, Client* client,
std::vector<std::any>* extra_pointers); std::vector<std::any>* extra_pointers);
void handle_player_language_skill_up(QuestInterface* parse, lua_State* L, Client* client, std::string data, uint32 extra_data, void handle_player_language_skill_up(QuestInterface* parse, lua_State* L, Client* client, std::string data, uint32 extra_data,
std::vector<std::any>* extra_pointers); std::vector<std::any>* extra_pointers);
void handle_player_alt_currency_merchant(QuestInterface* parse, lua_State* L, Client* client, std::string data, uint32 extra_data,
std::vector<std::any>* extra_pointers);
void handle_player_merchant(QuestInterface* parse, lua_State* L, Client* client, std::string data, uint32 extra_data,
std::vector<std::any>* extra_pointers);
//Item //Item
void handle_item_click(QuestInterface *parse, lua_State* L, Client* client, EQ::ItemInstance* item, Mob *mob, std::string data, uint32 extra_data, void handle_item_click(QuestInterface *parse, lua_State* L, Client* client, EQ::ItemInstance* item, Mob *mob, std::string data, uint32 extra_data,