[Quest API] Add EVENT_LDON_POINTS_GAIN and EVENT_LDON_POINTS_LOSS to Perl/Lua (#3742)

* [Quest API] Add EVENT_LDON_POINTS_GAIN and EVENT_LDON_POINTS_LOSS to Perl/Lua

- Add `EVENT_LDON_POINTS_GAIN`.
- Add `EVENT_LDON_POINTS_LOSS`.
- Exports `$theme_id` and `$points`.

- Add `event_ldon_points_gain`.
- Add `event_ldon_points_loss`.
- Exports `e.theme_id` and `e.points`.

- Allows operators to track gain/loss of LDoN Points of any theme.

* Update client.cpp
This commit is contained in:
Alex King 2023-12-16 23:31:25 -05:00 committed by GitHub
parent c1b07afae9
commit 8aae59eebe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 116 additions and 37 deletions

View File

@ -1411,126 +1411,163 @@ void Client::SetMaxHP() {
Save();
}
bool Client::UpdateLDoNPoints(uint32 theme_id, int points) {
/* make sure total stays in sync with individual buckets
m_pp.ldon_points_available = m_pp.ldon_points_guk
+m_pp.ldon_points_mir
+m_pp.ldon_points_mmc
+m_pp.ldon_points_ruj
+m_pp.ldon_points_tak; */
if(points < 0) {
if(m_pp.ldon_points_available < (0 - points))
bool Client::UpdateLDoNPoints(uint32 theme_id, int points)
{
if (points < 0) {
if (m_pp.ldon_points_available < (0 - points)) {
return false;
}
}
bool is_loss = false;
switch (theme_id) {
case LDoNThemes::Unused: { // No theme, so distribute evenly across all
int split_points = (points / 5);
int guk_points = (split_points + (points % 5));
int mir_points = split_points;
int mmc_points = split_points;
int ruj_points = split_points;
int tak_points = split_points;
split_points = 0;
if(points < 0) {
if(m_pp.ldon_points_available < (0 - points)) {
if (points < 0) {
if (m_pp.ldon_points_available < (0 - points)) {
return false;
}
if(m_pp.ldon_points_guk < (0 - guk_points)) {
is_loss = true;
if (m_pp.ldon_points_guk < (0 - guk_points)) {
mir_points += (guk_points + m_pp.ldon_points_guk);
guk_points = (0 - m_pp.ldon_points_guk);
}
if(m_pp.ldon_points_mir < (0 - mir_points)) {
if (m_pp.ldon_points_mir < (0 - mir_points)) {
mmc_points += (mir_points + m_pp.ldon_points_mir);
mir_points = (0 - m_pp.ldon_points_mir);
}
if(m_pp.ldon_points_mmc < (0 - mmc_points)) {
if (m_pp.ldon_points_mmc < (0 - mmc_points)) {
ruj_points += (mmc_points + m_pp.ldon_points_mmc);
mmc_points = (0 - m_pp.ldon_points_mmc);
}
if(m_pp.ldon_points_ruj < (0 - ruj_points)) {
if (m_pp.ldon_points_ruj < (0 - ruj_points)) {
tak_points += (ruj_points + m_pp.ldon_points_ruj);
ruj_points = (0 - m_pp.ldon_points_ruj);
}
if(m_pp.ldon_points_tak < (0 - tak_points)) {
if (m_pp.ldon_points_tak < (0 - tak_points)) {
split_points = (tak_points + m_pp.ldon_points_tak);
tak_points = (0 - m_pp.ldon_points_tak);
tak_points = (0 - m_pp.ldon_points_tak);
}
}
m_pp.ldon_points_guk += guk_points;
m_pp.ldon_points_mir += mir_points;
m_pp.ldon_points_mmc += mmc_points;
m_pp.ldon_points_ruj += ruj_points;
m_pp.ldon_points_tak += tak_points;
points -= split_points;
if (split_points != 0) { // if anything left, recursively loop thru again
UpdateLDoNPoints(0, split_points);
UpdateLDoNPoints(LDoNThemes::Unused, split_points);
}
break;
}
case LDoNThemes::GUK: {
if(points < 0) {
if(m_pp.ldon_points_guk < (0 - points)) {
case LDoNThemes::GUK: {
if (points < 0) {
if (m_pp.ldon_points_guk < (0 - points)) {
return false;
}
is_loss = true;
}
m_pp.ldon_points_guk += points;
break;
}
case LDoNThemes::MIR: {
if(points < 0) {
if(m_pp.ldon_points_mir < (0 - points)) {
if (points < 0) {
if (m_pp.ldon_points_mir < (0 - points)) {
return false;
}
is_loss = true;
}
m_pp.ldon_points_mir += points;
break;
}
case LDoNThemes::MMC: {
if(points < 0) {
if(m_pp.ldon_points_mmc < (0 - points)) {
if (points < 0) {
if (m_pp.ldon_points_mmc < (0 - points)) {
return false;
}
is_loss = true;
}
m_pp.ldon_points_mmc += points;
break;
}
case LDoNThemes::RUJ: {
if(points < 0) {
if(m_pp.ldon_points_ruj < (0 - points)) {
if (points < 0) {
if (m_pp.ldon_points_ruj < (0 - points)) {
return false;
}
is_loss = true;
}
m_pp.ldon_points_ruj += points;
break;
}
case LDoNThemes::TAK: {
if(points < 0) {
if(m_pp.ldon_points_tak < (0 - points)) {
if (points < 0) {
if (m_pp.ldon_points_tak < (0 - points)) {
return false;
}
is_loss = true;
}
m_pp.ldon_points_tak += points;
break;
}
}
m_pp.ldon_points_available += points;
QuestEventID event_id = is_loss ? EVENT_LDON_POINTS_LOSS : EVENT_LDON_POINTS_GAIN;
if (parse->PlayerHasQuestSub(event_id)) {
const std::string &export_string = fmt::format(
"{} {}",
theme_id,
std::abs(points)
);
parse->EventPlayer(event_id, this, export_string, 0);
}
auto outapp = new EQApplicationPacket(OP_AdventurePointsUpdate, sizeof(AdventurePoints_Update_Struct));
AdventurePoints_Update_Struct* apus = (AdventurePoints_Update_Struct*)outapp->pBuffer;
auto *apus = (AdventurePoints_Update_Struct *) outapp->pBuffer;
apus->ldon_available_points = m_pp.ldon_points_available;
apus->ldon_guk_points = m_pp.ldon_points_guk;
apus->ldon_mirugal_points = m_pp.ldon_points_mir;
apus->ldon_guk_points = m_pp.ldon_points_guk;
apus->ldon_mirugal_points = m_pp.ldon_points_mir;
apus->ldon_mistmoore_points = m_pp.ldon_points_mmc;
apus->ldon_rujarkian_points = m_pp.ldon_points_ruj;
apus->ldon_takish_points = m_pp.ldon_points_tak;
apus->ldon_takish_points = m_pp.ldon_points_tak;
outapp->priority = 6;
QueuePacket(outapp);
safe_delete(outapp);
return true;

View File

@ -187,6 +187,8 @@ const char *QuestEventSubroutines[_LargestEventID] = {
"EVENT_SCRIBE_SPELL",
"EVENT_UNSCRIBE_SPELL",
"EVENT_LOOT_ADDED",
"EVENT_LDON_POINTS_GAIN",
"EVENT_LDON_POINTS_LOSS",
// Add new events before these or Lua crashes
"EVENT_SPELL_EFFECT_BOT",
"EVENT_SPELL_EFFECT_BUFF_TIC_BOT"
@ -2258,7 +2260,13 @@ void PerlembParser::ExportEventVariables(
ExportVar(package_name.c_str(), "augment_six", inst->GetAugmentItemID(EQ::invaug::SOCKET_END));
}
}
}
case EVENT_LDON_POINTS_GAIN:
case EVENT_LDON_POINTS_LOSS: {
Seperator sep(data);
ExportVar(package_name.c_str(), "theme_id", sep.arg[0]);
ExportVar(package_name.c_str(), "points", sep.arg[1]);
break;
}

View File

@ -129,6 +129,8 @@ typedef enum {
EVENT_SCRIBE_SPELL,
EVENT_UNSCRIBE_SPELL,
EVENT_LOOT_ADDED,
EVENT_LDON_POINTS_GAIN,
EVENT_LDON_POINTS_LOSS,
// Add new events before these or Lua crashes
EVENT_SPELL_EFFECT_BOT,
EVENT_SPELL_EFFECT_BUFF_TIC_BOT,

View File

@ -6610,7 +6610,9 @@ luabind::scope lua_register_events() {
luabind::value("unmemorize_spell", static_cast<int>(EVENT_UNMEMORIZE_SPELL)),
luabind::value("scribe_spell", static_cast<int>(EVENT_SCRIBE_SPELL)),
luabind::value("unscribe_spell", static_cast<int>(EVENT_UNSCRIBE_SPELL)),
luabind::value("loot_added", static_cast<int>(EVENT_LOOT_ADDED))
luabind::value("loot_added", static_cast<int>(EVENT_LOOT_ADDED)),
luabind::value("ldon_points_gain", static_cast<int>(EVENT_LDON_POINTS_GAIN)),
luabind::value("ldon_points_loss", static_cast<int>(EVENT_LDON_POINTS_LOSS))
)];
}

View File

@ -169,7 +169,9 @@ const char *LuaEvents[_LargestEventID] = {
"event_unmemorize_spell",
"event_scribe_spell",
"event_unscribe_spell",
"event_loot_added"
"event_loot_added",
"event_ldon_points_gain",
"event_ldon_points_loss"
};
extern Zone *zone;
@ -302,6 +304,8 @@ LuaParser::LuaParser() {
PlayerArgumentDispatch[EVENT_UNMEMORIZE_SPELL] = handle_player_memorize_scribe_spell;
PlayerArgumentDispatch[EVENT_SCRIBE_SPELL] = handle_player_memorize_scribe_spell;
PlayerArgumentDispatch[EVENT_UNSCRIBE_SPELL] = handle_player_memorize_scribe_spell;
PlayerArgumentDispatch[EVENT_LDON_POINTS_GAIN] = handle_player_ldon_points_gain_loss;
PlayerArgumentDispatch[EVENT_LDON_POINTS_LOSS] = handle_player_ldon_points_gain_loss;
ItemArgumentDispatch[EVENT_ITEM_CLICK] = handle_item_click;
ItemArgumentDispatch[EVENT_ITEM_CLICK_CAST] = handle_item_click;

View File

@ -1501,6 +1501,23 @@ void handle_player_memorize_scribe_spell(
}
}
void handle_player_ldon_points_gain_loss(
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_pushnumber(L, Strings::ToUnsignedInt(sep.arg[0]));
lua_setfield(L, -2, "theme_id");
lua_pushnumber(L, Strings::ToUnsignedInt(sep.arg[1]));
lua_setfield(L, -2, "points");
}
// Item
void handle_item_click(
QuestInterface *parse,

View File

@ -743,6 +743,15 @@ void handle_player_memorize_scribe_spell(
std::vector<std::any> *extra_pointers
);
void handle_player_ldon_points_gain_loss(
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,