[Quest API] Add Client Augment Events to Perl/Lua. (#2735)

* [Quest API] Add Client Augment Events to Perl/Lua.

# Perl
- Add `EVENT_AUGMENT_INSERT_CLIENT`.
- Add `EVENT_AUGMENT_REMOVE_CLIENT`.

# Lua
- Add `event_augment_insert_client`.
- Add `event_augment_remove_client`.

# Notes
- Allows operators to use augment insert and augment remove events outside of an item script.
This commit is contained in:
Alex King 2023-01-14 23:23:48 -05:00 committed by GitHub
parent c41f375129
commit a422484307
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 178 additions and 3 deletions

View File

@ -3099,6 +3099,19 @@ void Client::Handle_OP_AugmentItem(const EQApplicationPacket *app)
args.assign(1, tobe_auged);
args.push_back(false);
parse->EventItem(EVENT_AUGMENT_REMOVE, this, old_aug, nullptr, "", in_augment->augment_index, &args);
const auto export_string = fmt::format(
"{} {} {} {} {}",
tobe_auged->GetID(),
item_slot,
aug->GetID(),
in_augment->augment_index,
false
);
args.push_back(aug);
parse->EventPlayer(EVENT_AUGMENT_REMOVE_CLIENT, this, export_string, 0, &args);
}
tobe_auged->PutAugment(in_augment->augment_index, *new_aug);
@ -3112,6 +3125,18 @@ void Client::Handle_OP_AugmentItem(const EQApplicationPacket *app)
args.assign(1, tobe_auged);
parse->EventItem(EVENT_AUGMENT_INSERT, this, aug, nullptr, "", in_augment->augment_index, &args);
args.push_back(aug);
const auto export_string = fmt::format(
"{} {} {} {}",
tobe_auged->GetID(),
item_slot,
aug->GetID(),
in_augment->augment_index
);
parse->EventPlayer(EVENT_AUGMENT_INSERT_CLIENT, this, export_string, 0, &args);
} else {
Message(
Chat::Red,
@ -3165,9 +3190,23 @@ void Client::Handle_OP_AugmentItem(const EQApplicationPacket *app)
std::vector<std::any> args;
args.push_back(aug);
parse->EventItem(EVENT_UNAUGMENT_ITEM, this, tobe_auged, nullptr, "", in_augment->augment_index, &args);
args.assign(1, tobe_auged);
args.push_back(false);
parse->EventItem(EVENT_AUGMENT_REMOVE, this, aug, nullptr, "", in_augment->augment_index, &args);
args.push_back(aug);
const auto export_string = fmt::format(
"{} {} {} {} {}",
tobe_auged->GetID(),
item_slot,
aug->GetID(),
in_augment->augment_index,
false
);
parse->EventPlayer(EVENT_AUGMENT_REMOVE_CLIENT, this, export_string, 0, &args);
} else {
Message(Chat::Red, "Error: Could not find augmentation to remove at index %i. Aborting.", in_augment->augment_index);
return;
@ -3215,9 +3254,23 @@ void Client::Handle_OP_AugmentItem(const EQApplicationPacket *app)
std::vector<std::any> args;
args.push_back(aug);
parse->EventItem(EVENT_UNAUGMENT_ITEM, this, tobe_auged, nullptr, "", in_augment->augment_index, &args);
args.assign(1, tobe_auged);
args.push_back(true);
parse->EventItem(EVENT_AUGMENT_REMOVE, this, aug, nullptr, "", in_augment->augment_index, &args);
args.push_back(aug);
const auto export_string = fmt::format(
"{} {} {} {} {}",
tobe_auged->GetID(),
item_slot,
aug->GetID(),
in_augment->augment_index,
true
);
parse->EventPlayer(EVENT_AUGMENT_REMOVE_CLIENT, this, export_string, 0, &args);
} else {
Message(
Chat::Red,

View File

@ -169,7 +169,10 @@ const char *QuestEventSubroutines[_LargestEventID] = {
"EVENT_DESPAWN",
"EVENT_DESPAWN_ZONE",
"EVENT_BOT_CREATE",
"EVENT_SPELL_EFFECT_BOT", // Add new events before these or Lua crashes
"EVENT_AUGMENT_INSERT_CLIENT",
"EVENT_AUGMENT_REMOVE_CLIENT",
// Add new events before these or Lua crashes
"EVENT_SPELL_EFFECT_BOT",
"EVENT_SPELL_EFFECT_BUFF_TIC_BOT"
};
@ -1943,6 +1946,19 @@ void PerlembParser::ExportEventVariables(
break;
}
case EVENT_AUGMENT_INSERT_CLIENT:
case EVENT_AUGMENT_REMOVE_CLIENT: {
Seperator sep(data);
ExportVar(package_name.c_str(), "item_id", sep.arg[0]);
ExportVar(package_name.c_str(), "item_slot", sep.arg[1]);
ExportVar(package_name.c_str(), "augment_id", sep.arg[2]);
ExportVar(package_name.c_str(), "augment_slot", sep.arg[3]);
if (sep.argnum >= 4) {
ExportVar(package_name.c_str(), "destroyed", sep.arg[4]);
}
break;
}
case EVENT_SKILL_UP: {
Seperator sep(data);
ExportVar(package_name.c_str(), "skill_id", sep.arg[0]);

View File

@ -112,7 +112,10 @@ typedef enum {
EVENT_DESPAWN,
EVENT_DESPAWN_ZONE,
EVENT_BOT_CREATE,
EVENT_SPELL_EFFECT_BOT, // Add new events before these or Lua crashes
EVENT_AUGMENT_INSERT_CLIENT,
EVENT_AUGMENT_REMOVE_CLIENT,
// Add new events before these or Lua crashes
EVENT_SPELL_EFFECT_BOT,
EVENT_SPELL_EFFECT_BUFF_TIC_BOT,
_LargestEventID
} QuestEventID;

View File

@ -4623,7 +4623,9 @@ luabind::scope lua_register_events() {
luabind::value("gm_command", static_cast<int>(EVENT_GM_COMMAND)),
luabind::value("despawn", static_cast<int>(EVENT_DESPAWN)),
luabind::value("despawn_zone", static_cast<int>(EVENT_DESPAWN_ZONE)),
luabind::value("bot_create", static_cast<int>(EVENT_BOT_CREATE))
luabind::value("bot_create", static_cast<int>(EVENT_BOT_CREATE)),
luabind::value("augment_insert_client", static_cast<int>(EVENT_AUGMENT_INSERT_CLIENT)),
luabind::value("augment_remove_client", static_cast<int>(EVENT_AUGMENT_REMOVE_CLIENT))
)];
}

View File

@ -156,6 +156,8 @@ const char *LuaEvents[_LargestEventID] = {
"event_despawn",
"event_despawn_zone",
"event_bot_create",
"event_augment_insert_client",
"event_augment_remove_client",
};
extern Zone *zone;
@ -272,6 +274,8 @@ LuaParser::LuaParser() {
PlayerArgumentDispatch[EVENT_LEVEL_DOWN] = handle_player_level_down;
PlayerArgumentDispatch[EVENT_GM_COMMAND] = handle_player_gm_command;
PlayerArgumentDispatch[EVENT_BOT_CREATE] = handle_player_bot_create;
PlayerArgumentDispatch[EVENT_AUGMENT_INSERT_CLIENT] = handle_player_augment_insert;
PlayerArgumentDispatch[EVENT_AUGMENT_REMOVE_CLIENT] = handle_player_augment_remove;
ItemArgumentDispatch[EVENT_ITEM_CLICK] = handle_item_click;
ItemArgumentDispatch[EVENT_ITEM_CLICK_CAST] = handle_item_click;

View File

@ -1597,6 +1597,73 @@ void handle_player_merchant(
lua_setfield(L, -2, "item_cost");
}
void handle_player_augment_insert(
QuestInterface *parse,
lua_State* L,
Client* client,
std::string data,
uint32 extra_data,
std::vector<std::any> *extra_pointers
) {
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");
Lua_ItemInst l_augment(std::any_cast<EQ::ItemInstance*>(extra_pointers->at(1)));
luabind::adl::object l_augment_o = luabind::adl::object(L, l_augment);
l_augment_o.push(L);
lua_setfield(L, -2, "augment");
Seperator sep(data.c_str());
lua_pushinteger(L, std::stoul(sep.arg[0]));
lua_setfield(L, -2, "item_id");
lua_pushinteger(L, std::stoi(sep.arg[1]));
lua_setfield(L, -2, "item_slot");
lua_pushinteger(L, std::stoul(sep.arg[2]));
lua_setfield(L, -2, "augment_id");
lua_pushinteger(L, std::stoul(sep.arg[3]));
lua_setfield(L, -2, "augment_slot");
}
void handle_player_augment_remove(
QuestInterface *parse,
lua_State* L,
Client* client,
std::string data,
uint32 extra_data,
std::vector<std::any> *extra_pointers
) {
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");
Lua_ItemInst l_augment(std::any_cast<EQ::ItemInstance*>(extra_pointers->at(2)));
luabind::adl::object l_augment_o = luabind::adl::object(L, l_augment);
l_augment_o.push(L);
lua_setfield(L, -2, "augment");
Seperator sep(data.c_str());
lua_pushinteger(L, std::stoul(sep.arg[0]));
lua_setfield(L, -2, "item_id");
lua_pushinteger(L, std::stoi(sep.arg[1]));
lua_setfield(L, -2, "item_slot");
lua_pushinteger(L, std::stoul(sep.arg[2]));
lua_setfield(L, -2, "augment_id");
lua_pushinteger(L, std::stoul(sep.arg[3]));
lua_setfield(L, -2, "augment_slot");
lua_pushboolean(L, Strings::ToBool(sep.arg[4]));
lua_setfield(L, -2, "destroyed");
}
// Bot
#ifdef BOTS

View File

@ -637,6 +637,24 @@ void handle_player_bot_create(
std::vector<std::any> *extra_pointers
);
void handle_player_augment_insert(
QuestInterface *parse,
lua_State* L,
Client* client,
std::string data,
uint32 extra_data,
std::vector<std::any> *extra_pointers
);
void handle_player_augment_remove(
QuestInterface *parse,
lua_State* L,
Client* client,
std::string data,
uint32 extra_data,
std::vector<std::any> *extra_pointers
);
// Item
void handle_item_click(

View File

@ -140,6 +140,18 @@ void Object::HandleAugmentation(Client* user, const AugmentItem_Struct* in_augme
args.assign(1, tobe_auged);
parse->EventItem(EVENT_AUGMENT_INSERT, user, aug, nullptr, "", slot, &args);
args.push_back(aug);
const auto export_string = fmt::format(
"{} {} {} {}",
tobe_auged->GetID(),
-1,
aug->GetID(),
slot
);
parse->EventPlayer(EVENT_AUGMENT_INSERT_CLIENT, user, export_string, 0, &args);
}
item_one_to_push = tobe_auged->Clone();