[Quest API] Add EVENT_ITEM_CLICK_CLIENT and EVENT_ITEM_CLICK_CAST_CLIENT to Perl/Lua. (#2810)

* [Quest API] Add EVENT_ITEM_CLICK_CLIENT and EVENT_ITEM_CLICK_CAST_CLIENT to Perl/Lua.

# Perl
- Add `EVENT_ITEM_CLICK_CLIENT`.
- Add `EVENT_ITEM_CLICK_CAST_CLIENT`.
- Both events export `$item_id`, `$item_name`, `$slot_id`, and `$spell_id`.

# Lua
- Add `event_item_click_client`.
- Add `event_item_click_cast_client`.
- Both events export `e.item_id`, `e.item_name`, `e.slot_id`, `e.spell_id`, and `e.item`.

# Notes
- Allows operators to handle item clicks in player scripts instead of item-specific scripts.

* Update lua_parser_events.cpp

* Remove optional bool.
This commit is contained in:
Alex King 2023-01-30 06:01:12 -05:00 committed by GitHub
parent 66896a3121
commit a25952910a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 298 additions and 154 deletions

View File

@ -4168,8 +4168,26 @@ void Client::Handle_OP_CastSpell(const EQApplicationPacket *app)
{ {
if (GetLevel() >= item->Click.Level2) if (GetLevel() >= item->Click.Level2)
{ {
EQ::ItemInstance* p_inst = (EQ::ItemInstance*)inst; auto* p_inst = (EQ::ItemInstance*) inst;
int i = parse->EventItem(EVENT_ITEM_CLICK_CAST, this, p_inst, nullptr, "", castspell->inventoryslot); int i = 0;
if (parse->ItemHasQuestSub(p_inst, EVENT_ITEM_CLICK_CAST)) {
i = parse->EventItem(
EVENT_ITEM_CLICK_CAST,
this,
p_inst,
nullptr,
"",
castspell->inventoryslot
);
}
if (parse->PlayerHasQuestSub(EVENT_ITEM_CLICK_CAST_CLIENT)) {
std::vector<std::any> args;
args.emplace_back(p_inst);
i = parse->EventPlayer(EVENT_ITEM_CLICK_CAST_CLIENT, this, std::to_string(castspell->inventoryslot), 0, &args);
}
if (i == 0) { if (i == 0) {
CastSpell(item->Click.Effect, castspell->target_id, slot, item->CastTime, 0, 0, castspell->inventoryslot); CastSpell(item->Click.Effect, castspell->target_id, slot, item->CastTime, 0, 0, castspell->inventoryslot);
} }
@ -4187,8 +4205,26 @@ void Client::Handle_OP_CastSpell(const EQApplicationPacket *app)
} }
else else
{ {
EQ::ItemInstance* p_inst = (EQ::ItemInstance*)inst; auto* p_inst = (EQ::ItemInstance*) inst;
int i = parse->EventItem(EVENT_ITEM_CLICK_CAST, this, p_inst, nullptr, "", castspell->inventoryslot);
int i = 0;
if (parse->ItemHasQuestSub(p_inst, EVENT_ITEM_CLICK_CAST)) {
i = parse->EventItem(
EVENT_ITEM_CLICK_CAST,
this,
p_inst,
nullptr,
"",
castspell->inventoryslot
);
}
if (parse->PlayerHasQuestSub(EVENT_ITEM_CLICK_CAST_CLIENT)) {
std::vector<std::any> args;
args.emplace_back(p_inst);
i = parse->EventPlayer(EVENT_ITEM_CLICK_CAST_CLIENT, this, std::to_string(castspell->inventoryslot), 0, &args);
}
if (i == 0) { if (i == 0) {
CastSpell(item->Click.Effect, castspell->target_id, slot, item->CastTime, 0, 0, castspell->inventoryslot); CastSpell(item->Click.Effect, castspell->target_id, slot, item->CastTime, 0, 0, castspell->inventoryslot);
@ -8836,9 +8872,18 @@ void Client::Handle_OP_ItemVerifyRequest(const EQApplicationPacket *app)
if (m_inv.SupportsClickCasting(slot_id) || ((item->ItemType == EQ::item::ItemTypePotion || item->PotionBelt) && m_inv.SupportsPotionBeltCasting(slot_id))) // sanity check if (m_inv.SupportsClickCasting(slot_id) || ((item->ItemType == EQ::item::ItemTypePotion || item->PotionBelt) && m_inv.SupportsPotionBeltCasting(slot_id))) // sanity check
{ {
EQ::ItemInstance* p_inst = (EQ::ItemInstance*)inst; auto* p_inst = (EQ::ItemInstance*) inst;
if (parse->ItemHasQuestSub(p_inst, EVENT_ITEM_CLICK)) {
parse->EventItem(EVENT_ITEM_CLICK, this, p_inst, nullptr, "", slot_id); parse->EventItem(EVENT_ITEM_CLICK, this, p_inst, nullptr, "", slot_id);
}
if (parse->PlayerHasQuestSub(EVENT_ITEM_CLICK_CLIENT)) {
std::vector<std::any> args;
args.emplace_back(p_inst);
parse->EventPlayer(EVENT_ITEM_CLICK_CLIENT, this, std::to_string(slot_id), 0, &args);
}
inst = m_inv[slot_id]; inst = m_inv[slot_id];
if (!inst) if (!inst)
{ {
@ -8940,7 +8985,25 @@ void Client::Handle_OP_ItemVerifyRequest(const EQApplicationPacket *app)
} }
} }
int i = parse->EventItem(EVENT_ITEM_CLICK_CAST, this, p_inst, nullptr, "", slot_id); int i = 0;
if (parse->ItemHasQuestSub(p_inst, EVENT_ITEM_CLICK_CAST)) {
i = parse->EventItem(
EVENT_ITEM_CLICK_CAST,
this,
p_inst,
nullptr,
"",
slot_id
);
}
if (parse->PlayerHasQuestSub(EVENT_ITEM_CLICK_CAST_CLIENT)) {
std::vector<std::any> args;
args.emplace_back(p_inst);
i = parse->EventPlayer(EVENT_ITEM_CLICK_CAST_CLIENT, this, std::to_string(slot_id), 0, &args);
}
inst = m_inv[slot_id]; inst = m_inv[slot_id];
if (!inst) if (!inst)
{ {
@ -8989,7 +9052,25 @@ void Client::Handle_OP_ItemVerifyRequest(const EQApplicationPacket *app)
} }
} }
int i = parse->EventItem(EVENT_ITEM_CLICK_CAST, this, clickaug, nullptr, "", slot_id); int i = 0;
if (parse->ItemHasQuestSub(p_inst, EVENT_ITEM_CLICK_CAST)) {
i = parse->EventItem(
EVENT_ITEM_CLICK_CAST,
this,
clickaug,
nullptr,
"",
slot_id
);
}
if (parse->PlayerHasQuestSub(EVENT_ITEM_CLICK_CAST_CLIENT)) {
std::vector<std::any> args;
args.emplace_back(clickaug);
i = parse->EventPlayer(EVENT_ITEM_CLICK_CAST_CLIENT, this, std::to_string(slot_id), 0, &args);
}
inst = m_inv[slot_id]; inst = m_inv[slot_id];
if (!inst) if (!inst)
{ {

View File

@ -173,6 +173,8 @@ const char *QuestEventSubroutines[_LargestEventID] = {
"EVENT_UNEQUIP_ITEM_BOT", "EVENT_UNEQUIP_ITEM_BOT",
"EVENT_DAMAGE_GIVEN", "EVENT_DAMAGE_GIVEN",
"EVENT_DAMAGE_TAKEN", "EVENT_DAMAGE_TAKEN",
"EVENT_ITEM_CLICK_CLIENT",
"EVENT_ITEM_CLICK_CAST_CLIENT",
// Add new events before these or Lua crashes // Add new events before these or Lua crashes
"EVENT_SPELL_EFFECT_BOT", "EVENT_SPELL_EFFECT_BOT",
"EVENT_SPELL_EFFECT_BUFF_TIC_BOT" "EVENT_SPELL_EFFECT_BUFF_TIC_BOT"
@ -1713,6 +1715,20 @@ void PerlembParser::ExportEventVariables(
break; break;
} }
case EVENT_ITEM_CLICK_CAST_CLIENT:
case EVENT_ITEM_CLICK_CLIENT: {
ExportVar(package_name.c_str(), "slot_id", data);
if (extra_pointers && extra_pointers->size() == 1) {
auto* item = std::any_cast<EQ::ItemInstance*>(extra_pointers->at(0));
if (item) {
ExportVar(package_name.c_str(), "item_id", item->GetID());
ExportVar(package_name.c_str(), "item_name", item->GetItem()->Name);
ExportVar(package_name.c_str(), "spell_id", item->GetItem()->Click.Effect);
}
}
break;
}
case EVENT_GROUP_CHANGE: { case EVENT_GROUP_CHANGE: {
if (mob && mob->IsClient()) { if (mob && mob->IsClient()) {
ExportVar(package_name.c_str(), "grouped", mob->IsGrouped()); ExportVar(package_name.c_str(), "grouped", mob->IsGrouped());

View File

@ -118,6 +118,8 @@ typedef enum {
EVENT_UNEQUIP_ITEM_BOT, EVENT_UNEQUIP_ITEM_BOT,
EVENT_DAMAGE_GIVEN, EVENT_DAMAGE_GIVEN,
EVENT_DAMAGE_TAKEN, EVENT_DAMAGE_TAKEN,
EVENT_ITEM_CLICK_CLIENT,
EVENT_ITEM_CLICK_CAST_CLIENT,
// Add new events before these or Lua crashes // Add new events before these or Lua crashes
EVENT_SPELL_EFFECT_BOT, EVENT_SPELL_EFFECT_BOT,
EVENT_SPELL_EFFECT_BUFF_TIC_BOT, EVENT_SPELL_EFFECT_BUFF_TIC_BOT,

View File

@ -4627,7 +4627,11 @@ luabind::scope lua_register_events() {
luabind::value("augment_insert_client", static_cast<int>(EVENT_AUGMENT_INSERT_CLIENT)), luabind::value("augment_insert_client", static_cast<int>(EVENT_AUGMENT_INSERT_CLIENT)),
luabind::value("augment_remove_client", static_cast<int>(EVENT_AUGMENT_REMOVE_CLIENT)), luabind::value("augment_remove_client", static_cast<int>(EVENT_AUGMENT_REMOVE_CLIENT)),
luabind::value("equip_item_bot", static_cast<int>(EVENT_EQUIP_ITEM_BOT)), luabind::value("equip_item_bot", static_cast<int>(EVENT_EQUIP_ITEM_BOT)),
luabind::value("unequip_item_bot", static_cast<int>(EVENT_UNEQUIP_ITEM_BOT)) luabind::value("unequip_item_bot", static_cast<int>(EVENT_UNEQUIP_ITEM_BOT)),
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))
)]; )];
} }

View File

@ -159,7 +159,9 @@ const char *LuaEvents[_LargestEventID] = {
"event_equip_item_bot", "event_equip_item_bot",
"event_unequip_item_bot", "event_unequip_item_bot",
"event_damage_given", "event_damage_given",
"event_damage_taken" "event_damage_taken",
"event_item_click_client",
"event_item_click_cast_client"
}; };
extern Zone *zone; extern Zone *zone;
@ -279,6 +281,8 @@ LuaParser::LuaParser() {
PlayerArgumentDispatch[EVENT_AUGMENT_REMOVE_CLIENT] = handle_player_augment_remove; PlayerArgumentDispatch[EVENT_AUGMENT_REMOVE_CLIENT] = handle_player_augment_remove;
PlayerArgumentDispatch[EVENT_DAMAGE_GIVEN] = handle_player_damage; PlayerArgumentDispatch[EVENT_DAMAGE_GIVEN] = handle_player_damage;
PlayerArgumentDispatch[EVENT_DAMAGE_TAKEN] = handle_player_damage; 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;
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

@ -1235,13 +1235,41 @@ void handle_player_damage(
lua_setfield(L, -2, "special_attack"); lua_setfield(L, -2, "special_attack");
if (extra_pointers && extra_pointers->size() >= 1) { if (extra_pointers && extra_pointers->size() >= 1) {
Lua_Mob l_mob(std::any_cast<Mob*>(extra_pointers->at(1))); Lua_Mob l_mob(std::any_cast<Mob*>(extra_pointers->at(0)));
luabind::adl::object l_mob_o = luabind::adl::object(L, l_mob); luabind::adl::object l_mob_o = luabind::adl::object(L, l_mob);
l_mob_o.push(L); l_mob_o.push(L);
lua_setfield(L, -2, "other"); lua_setfield(L, -2, "other");
} }
} }
void handle_player_item_click(
QuestInterface *parse,
lua_State* L,
Client* client,
const std::string& data,
uint32 extra_data,
std::vector<std::any> *extra_pointers
) {
lua_pushnumber(L, std::stoi(data));
lua_setfield(L, -2, "slot_id");
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))->GetItem()->Click.Effect);
lua_setfield(L, -2, "spell_id");
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 // Item
void handle_item_click( void handle_item_click(
QuestInterface *parse, QuestInterface *parse,

View File

@ -661,6 +661,15 @@ void handle_player_damage(
std::vector<std::any> *extra_pointers std::vector<std::any> *extra_pointers
); );
void handle_player_item_click(
QuestInterface *parse,
lua_State* L,
Client* client,
const std::string& data,
uint32 extra_data,
std::vector<std::any> *extra_pointers
);
// Item // Item
void handle_item_click( void handle_item_click(
QuestInterface *parse, QuestInterface *parse,

View File

@ -103,8 +103,8 @@ void QuestParserCollection::RemoveEncounter(const std::string name) {
} }
} }
bool QuestParserCollection::HasQuestSub(uint32 npcid, QuestEventID evt, bool check_encounters) { bool QuestParserCollection::HasQuestSub(uint32 npcid, QuestEventID evt) {
return HasQuestSubLocal(npcid, evt) || HasQuestSubGlobal(evt) || (check_encounters && NPCHasEncounterSub(npcid, evt)); return HasQuestSubLocal(npcid, evt) || HasQuestSubGlobal(evt) || NPCHasEncounterSub(npcid, evt);
} }
bool QuestParserCollection::NPCHasEncounterSub(uint32 npc_id, QuestEventID evt) { bool QuestParserCollection::NPCHasEncounterSub(uint32 npc_id, QuestEventID evt) {
@ -162,8 +162,8 @@ bool QuestParserCollection::HasQuestSubGlobal(QuestEventID evt) {
return false; return false;
} }
bool QuestParserCollection::PlayerHasQuestSub(QuestEventID evt, bool check_encounters) { bool QuestParserCollection::PlayerHasQuestSub(QuestEventID evt) {
return PlayerHasQuestSubLocal(evt) || PlayerHasQuestSubGlobal(evt) || (check_encounters && PlayerHasEncounterSub(evt)); return PlayerHasQuestSubLocal(evt) || PlayerHasQuestSubGlobal(evt) || PlayerHasEncounterSub(evt);
} }
bool QuestParserCollection::PlayerHasEncounterSub(QuestEventID evt) { bool QuestParserCollection::PlayerHasEncounterSub(QuestEventID evt) {
@ -207,8 +207,8 @@ bool QuestParserCollection::SpellHasEncounterSub(uint32 spell_id, QuestEventID e
return HasEncounterSub(evt, package_name); return HasEncounterSub(evt, package_name);
} }
bool QuestParserCollection::SpellHasQuestSub(uint32 spell_id, QuestEventID evt, bool check_encounters) { bool QuestParserCollection::SpellHasQuestSub(uint32 spell_id, QuestEventID evt) {
if (check_encounters && SpellHasEncounterSub(spell_id, evt)) { if (SpellHasEncounterSub(spell_id, evt)) {
return true; return true;
} }
@ -241,11 +241,11 @@ bool QuestParserCollection::ItemHasEncounterSub(EQ::ItemInstance* item, QuestEve
return false; return false;
} }
bool QuestParserCollection::ItemHasQuestSub(EQ::ItemInstance *itm, QuestEventID evt, bool check_encounters) { bool QuestParserCollection::ItemHasQuestSub(EQ::ItemInstance *itm, QuestEventID evt) {
if (itm == nullptr) if (itm == nullptr)
return false; return false;
if (check_encounters && ItemHasEncounterSub(itm, evt)) { if (ItemHasEncounterSub(itm, evt)) {
return true; return true;
} }

View File

@ -67,10 +67,10 @@ public:
void ReloadQuests(bool reset_timers = true); void ReloadQuests(bool reset_timers = true);
void RemoveEncounter(const std::string name); void RemoveEncounter(const std::string name);
bool HasQuestSub(uint32 npcid, QuestEventID evt, bool check_encounters = false); bool HasQuestSub(uint32 npcid, QuestEventID evt);
bool PlayerHasQuestSub(QuestEventID evt, bool check_encounters = false); bool PlayerHasQuestSub(QuestEventID evt);
bool SpellHasQuestSub(uint32 spell_id, QuestEventID evt, bool check_encounters = false); bool SpellHasQuestSub(uint32 spell_id, QuestEventID evt);
bool ItemHasQuestSub(EQ::ItemInstance *itm, QuestEventID evt, bool check_encounters = false); bool ItemHasQuestSub(EQ::ItemInstance *itm, QuestEventID evt);
bool BotHasQuestSub(QuestEventID evt); bool BotHasQuestSub(QuestEventID evt);
int EventNPC(QuestEventID evt, NPC* npc, Mob *init, const std::string& data, uint32 extra_data, int EventNPC(QuestEventID evt, NPC* npc, Mob *init, const std::string& data, uint32 extra_data,

View File

@ -875,7 +875,7 @@ void Client::FinishTrade(Mob* tradingWith, bool finalizer, void* event_entry, st
} }
bool quest_npc = false; bool quest_npc = false;
if (parse->HasQuestSub(tradingWith->GetNPCTypeID(), EVENT_TRADE, true)) { if (parse->HasQuestSub(tradingWith->GetNPCTypeID(), EVENT_TRADE)) {
// This is a quest NPC // This is a quest NPC
quest_npc = true; quest_npc = true;
} }