[Quest API] Add EVENT_DROP_ITEM_CLIENT to Perl/Lua (#2869)

* [Quest API] Add EVENT_DROP_ITEM_CLIENT to Perl/Lua

- Add `EVENT_DROP_ITEM_CLIENT`, exports `$quantity,` $item_name`, `$item_id`, `$spell_id`, `$slot_id`, and `$item`.

- Add `event_drop_item_client`, exports `e.quantity`, `e.item_name`, `e.item_id`, `e.spell_id`, `e.slot_id`, and `e.item`.

* Update inventory.cpp

* Update inventory.cpp

* Update lua_general.cpp

* Update inventory.cpp
This commit is contained in:
Alex King 2023-02-13 01:15:19 -05:00 committed by GitHub
parent 8c363320d8
commit 4df9661903
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 81 additions and 5 deletions

View File

@ -176,6 +176,7 @@ const char *QuestEventSubroutines[_LargestEventID] = {
"EVENT_ITEM_CLICK_CLIENT",
"EVENT_ITEM_CLICK_CAST_CLIENT",
"EVENT_DESTROY_ITEM_CLIENT",
"EVENT_DROP_ITEM_CLIENT",
// Add new events before these or Lua crashes
"EVENT_SPELL_EFFECT_BOT",
"EVENT_SPELL_EFFECT_BUFF_TIC_BOT"
@ -1883,6 +1884,19 @@ void PerlembParser::ExportEventVariables(
break;
}
case EVENT_DROP_ITEM_CLIENT: {
if (extra_pointers && extra_pointers->size() == 1) {
EQ::ItemInstance* item_instance = std::any_cast<EQ::ItemInstance*>(extra_pointers->at(0));
ExportVar(package_name.c_str(), "quantity", item_instance->IsStackable() ? item_instance->GetCharges() : 1);
ExportVar(package_name.c_str(), "item_name", item_instance->GetItem()->Name);
ExportVar(package_name.c_str(), "item_id", item_instance->GetItem()->ID);
ExportVar(package_name.c_str(), "spell_id", item_instance->GetItem()->Click.Effect);
ExportVar(package_name.c_str(), "slot_id", extradata);
ExportVar(package_name.c_str(), "item", "QuestItem", item_instance);
}
break;
}
case EVENT_SPAWN_ZONE: {
ExportVar(package_name.c_str(), "spawned_entity_id", mob->GetID());
ExportVar(package_name.c_str(), "spawned_bot_id", mob->IsBot() ? mob->CastToBot()->GetBotID() : 0);

View File

@ -121,6 +121,7 @@ typedef enum {
EVENT_ITEM_CLICK_CLIENT,
EVENT_ITEM_CLICK_CAST_CLIENT,
EVENT_DESTROY_ITEM_CLIENT,
EVENT_DROP_ITEM_CLIENT,
// Add new events before these or Lua crashes
EVENT_SPELL_EFFECT_BOT,
EVENT_SPELL_EFFECT_BUFF_TIC_BOT,

View File

@ -903,6 +903,9 @@ void Client::DropItem(int16 slot_id, bool recurse)
}
}
int i = 0;
if (player_event_logs.IsEventEnabled(PlayerEvent::DROPPED_ITEM)) {
auto e = PlayerEvent::DroppedItemEvent{
.item_id = inst->GetID(),
@ -913,10 +916,22 @@ void Client::DropItem(int16 slot_id, bool recurse)
RecordPlayerEventLog(PlayerEvent::DROPPED_ITEM, e);
}
int i = parse->EventItem(EVENT_DROP_ITEM, this, inst, nullptr, "", slot_id);
if (i != 0) {
LogInventory("Item drop handled by [EVENT_DROP_ITEM]");
safe_delete(inst);
if (parse->ItemHasQuestSub(inst, EVENT_DROP_ITEM)) {
parse->EventItem(EVENT_DROP_ITEM, this, inst, nullptr, "", slot_id);
if (i != 0) {
LogInventory("Item drop handled by [EVENT_DROP_ITEM]");
safe_delete(inst);
}
}
if (parse->PlayerHasQuestSub(EVENT_DROP_ITEM_CLIENT)) {
std::vector<std::any> args = { inst };
i = parse->EventPlayer(EVENT_DROP_ITEM_CLIENT, this, "", slot_id, &args);
if (i != 0) {
LogInventory("Item drop handled by [EVENT_DROP_ITEM_CLIENT]");
safe_delete(inst);
}
}
} else {
// Item doesn't exist in inventory!

View File

@ -4751,7 +4751,8 @@ luabind::scope lua_register_events() {
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("destroy_item_client", static_cast<int>(EVENT_DESTROY_ITEM_CLIENT))
luabind::value("destroy_item_client", static_cast<int>(EVENT_DESTROY_ITEM_CLIENT)),
luabind::value("drop_item_client", static_cast<int>(EVENT_DROP_ITEM_CLIENT))
)];
}

View File

@ -163,6 +163,7 @@ const char *LuaEvents[_LargestEventID] = {
"event_item_click_client",
"event_item_click_cast_client",
"event_destroy_item_client"
"event_drop_item_client"
};
extern Zone *zone;
@ -287,6 +288,7 @@ LuaParser::LuaParser() {
PlayerArgumentDispatch[EVENT_ITEM_CLICK_CLIENT] = handle_player_item_click;
PlayerArgumentDispatch[EVENT_DESTROY_ITEM_CLIENT] = handle_player_destroy_item;
PlayerArgumentDispatch[EVENT_TARGET_CHANGE] = handle_player_target_change;
PlayerArgumentDispatch[EVENT_DROP_ITEM_CLIENT] = handle_player_drop_item;
ItemArgumentDispatch[EVENT_ITEM_CLICK] = handle_item_click;
ItemArgumentDispatch[EVENT_ITEM_CLICK_CAST] = handle_item_click;

View File

@ -1334,6 +1334,40 @@ void handle_player_destroy_item(
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");
}
}
void handle_player_drop_item(
QuestInterface *parse,
lua_State* L,
Client* client,
std::string data,
uint32 extra_data,
std::vector<std::any> *extra_pointers
) {
lua_pushnumber(L, extra_data);
lua_setfield(L, -2, "slot_id");
if (extra_pointers && extra_pointers->size() == 1) {
EQ::ItemInstance* item_inst = std::any_cast<EQ::ItemInstance*>(extra_pointers->at(0));
lua_pushnumber(L, item_inst->IsStackable() ? item_inst->GetCharges() : 1);
lua_setfield(L, -2, "quantity");
lua_pushnumber(L, item_inst->GetItem()->ID);
lua_setfield(L, -2, "item_id");
lua_pushstring(L, item_inst->GetItem()->Name);
lua_setfield(L, -2, "item_name");
lua_pushnumber(L, item_inst->GetItem()->Click.Effect);
lua_setfield(L, -2, "spell_id");
Lua_Item l_item(item_inst->GetItem());
luabind::adl::object l_item_o = luabind::adl::object(L, l_item);
l_item_o.push(L);
lua_setfield(L, -2, "item");

View File

@ -707,6 +707,15 @@ void handle_player_target_change(
std::vector<std::any> *extra_pointers
);
void handle_player_drop_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,