Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Quest API] Add EVENT_DESTROY_ITEM_CLIENT to Perl/Lua. #2871

Merged
merged 3 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions zone/embparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ const char *QuestEventSubroutines[_LargestEventID] = {
"EVENT_DAMAGE_TAKEN",
"EVENT_ITEM_CLICK_CLIENT",
"EVENT_ITEM_CLICK_CAST_CLIENT",
"EVENT_DESTROY_ITEM_CLIENT",
// Add new events before these or Lua crashes
"EVENT_SPELL_EFFECT_BOT",
"EVENT_SPELL_EFFECT_BUFF_TIC_BOT"
Expand Down Expand Up @@ -2133,6 +2134,17 @@ void PerlembParser::ExportEventVariables(
break;
}

case EVENT_DESTROY_ITEM_CLIENT: {
if (extra_pointers && extra_pointers->size() == 1) {
EQ::ItemInstance* inst = std::any_cast<EQ::ItemInstance*>(extra_pointers->at(0));
ExportVar(package_name.c_str(), "item_id", inst->GetID());
ExportVar(package_name.c_str(), "item_name", inst->GetItem()->Name);
ExportVar(package_name.c_str(), "quantity", inst->IsStackable() ? inst->GetCharges() : 1);
ExportVar(package_name.c_str(), "item", "QuestItem", inst);
}
break;
}

default: {
break;
}
Expand Down
1 change: 1 addition & 0 deletions zone/event_codes.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ typedef enum {
EVENT_DAMAGE_TAKEN,
EVENT_ITEM_CLICK_CLIENT,
EVENT_ITEM_CLICK_CAST_CLIENT,
EVENT_DESTROY_ITEM_CLIENT,
// Add new events before these or Lua crashes
EVENT_SPELL_EFFECT_BOT,
EVENT_SPELL_EFFECT_BUFF_TIC_BOT,
Expand Down
35 changes: 31 additions & 4 deletions zone/inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,16 @@ void Client::SendCursorBuffer()
LogInventory("([{}]) Duplicate lore items are not allowed - destroying item [{}](id:[{}]) on cursor",
GetName(), test_item->Name, test_item->ID);
MessageString(Chat::Loot, 290);
parse->EventItem(EVENT_DESTROY_ITEM, this, test_inst, nullptr, "", 0);

if (parse->ItemHasQuestSub(test_inst, EVENT_DESTROY_ITEM)) {
parse->EventItem(EVENT_DESTROY_ITEM, this, test_inst, nullptr, "", 0);
}

if (parse->PlayerHasQuestSub(EVENT_DESTROY_ITEM_CLIENT)) {
std::vector<std::any> args = { test_inst };
parse->EventPlayer(EVENT_DESTROY_ITEM_CLIENT, this, "", 0, &args);
}

DeleteItemInInventory(EQ::invslot::slotCursor);
SendCursorBuffer();
}
Expand Down Expand Up @@ -1861,7 +1870,16 @@ bool Client::SwapItem(MoveItem_Struct* move_in) {
LogInventory("([{}]) Duplicate lore items are not allowed - destroying item [{}](id:[{}]) on cursor",
GetName(), test_item->Name, test_item->ID);
MessageString(Chat::Loot, 290);
parse->EventItem(EVENT_DESTROY_ITEM, this, test_inst, nullptr, "", 0);

if (parse->ItemHasQuestSub(test_inst, EVENT_DESTROY_ITEM)) {
parse->EventItem(EVENT_DESTROY_ITEM, this, test_inst, nullptr, "", 0);
}

if (parse->PlayerHasQuestSub(EVENT_DESTROY_ITEM_CLIENT)) {
std::vector<std::any> args = { test_inst };
parse->EventPlayer(EVENT_DESTROY_ITEM_CLIENT, this, "", 0, &args);
}

DeleteItemInInventory(EQ::invslot::slotCursor, 0, true);

if (player_event_logs.IsEventEnabled(PlayerEvent::ITEM_DESTROY)) {
Expand All @@ -1886,8 +1904,8 @@ bool Client::SwapItem(MoveItem_Struct* move_in) {
if(RuleB(QueryServ, PlayerLogMoves)) { QSSwapItemAuditor(move_in); } // QS Audit

EQ::ItemInstance *inst = m_inv.GetItem(EQ::invslot::slotCursor);
if(inst) {
parse->EventItem(EVENT_DESTROY_ITEM, this, inst, nullptr, "", 0);

if (inst) {
if (player_event_logs.IsEventEnabled(PlayerEvent::ITEM_DESTROY)) {
auto e = PlayerEvent::DestroyItemEvent{
.item_id = inst->GetItem()->ID,
Expand All @@ -1898,6 +1916,15 @@ bool Client::SwapItem(MoveItem_Struct* move_in) {

RecordPlayerEventLog(PlayerEvent::ITEM_DESTROY, e);
}

if (parse->ItemHasQuestSub(inst, EVENT_DESTROY_ITEM)) {
parse->EventItem(EVENT_DESTROY_ITEM, this, inst, nullptr, "", 0);
}

if (parse->PlayerHasQuestSub(EVENT_DESTROY_ITEM_CLIENT)) {
std::vector<std::any> args = { inst };
parse->EventPlayer(EVENT_DESTROY_ITEM_CLIENT, this, "", 0, &args);
}
}

DeleteItemInInventory(move_in->from_slot);
Expand Down
3 changes: 2 additions & 1 deletion zone/lua_general.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4750,7 +4750,8 @@ luabind::scope lua_register_events() {
luabind::value("damage_given", static_cast<int>(EVENT_DAMAGE_GIVEN)),
luabind::value("damage_taken", static_cast<int>(EVENT_DAMAGE_TAKEN)),
luabind::value("item_click_client", static_cast<int>(EVENT_ITEM_CLICK_CLIENT)),
luabind::value("item_click_cast_client", static_cast<int>(EVENT_ITEM_CLICK_CAST_CLIENT))
luabind::value("item_click_cast_client", static_cast<int>(EVENT_ITEM_CLICK_CAST_CLIENT)),
luabind::value("destroy_item_client", static_cast<int>(EVENT_DESTROY_ITEM_CLIENT))
)];
}

Expand Down
4 changes: 3 additions & 1 deletion zone/lua_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ const char *LuaEvents[_LargestEventID] = {
"event_damage_given",
"event_damage_taken",
"event_item_click_client",
"event_item_click_cast_client"
"event_item_click_cast_client",
"event_destroy_item_client"
};

extern Zone *zone;
Expand Down Expand Up @@ -284,6 +285,7 @@ LuaParser::LuaParser() {
PlayerArgumentDispatch[EVENT_DAMAGE_TAKEN] = handle_player_damage;
PlayerArgumentDispatch[EVENT_ITEM_CLICK_CAST_CLIENT] = handle_player_item_click;
PlayerArgumentDispatch[EVENT_ITEM_CLICK_CLIENT] = handle_player_item_click;
PlayerArgumentDispatch[EVENT_DESTROY_ITEM_CLIENT] = handle_player_destroy_item;

ItemArgumentDispatch[EVENT_ITEM_CLICK] = handle_item_click;
ItemArgumentDispatch[EVENT_ITEM_CLICK_CAST] = handle_item_click;
Expand Down
25 changes: 25 additions & 0 deletions zone/lua_parser_events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,31 @@ void handle_player_item_click(
}
}

void handle_player_destroy_item(
QuestInterface *parse,
lua_State* L,
Client* client,
std::string data,
uint32 extra_data,
std::vector<std::any> *extra_pointers
) {
if (extra_pointers && extra_pointers->size() >= 1) {
lua_pushnumber(L, std::any_cast<EQ::ItemInstance*>(extra_pointers->at(0))->GetID());
lua_setfield(L, -2, "item_id");

lua_pushstring(L, std::any_cast<EQ::ItemInstance*>(extra_pointers->at(0))->GetItem()->Name);
lua_setfield(L, -2, "item_name");

lua_pushnumber(L, std::any_cast<EQ::ItemInstance*>(extra_pointers->at(0))->IsStackable() ? std::any_cast<EQ::ItemInstance*>(extra_pointers->at(0))->GetCharges() : 1);
lua_setfield(L, -2, "quantity");

Lua_ItemInst l_item(std::any_cast<EQ::ItemInstance *>(extra_pointers->at(0)));
luabind::adl::object l_item_o = luabind::adl::object(L, l_item);
l_item_o.push(L);
lua_setfield(L, -2, "item");
}
}

// Item
void handle_item_click(
QuestInterface *parse,
Expand Down
9 changes: 9 additions & 0 deletions zone/lua_parser_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,15 @@ void handle_player_item_click(
std::vector<std::any> *extra_pointers
);

void handle_player_destroy_item(
QuestInterface *parse,
lua_State* L,
Client* client,
std::string data,
uint32 extra_data,
std::vector<std::any> *extra_pointers
);

// Item
void handle_item_click(
QuestInterface *parse,
Expand Down