From 8aae59eebeccbac876fc6c5f9c377508db9a16e7 Mon Sep 17 00:00:00 2001 From: Alex King <89047260+Kinglykrab@users.noreply.github.com> Date: Sat, 16 Dec 2023 23:31:25 -0500 Subject: [PATCH] [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 --- zone/client.cpp | 107 +++++++++++++++++++++++++------------ zone/embparser.cpp | 8 +++ zone/event_codes.h | 2 + zone/lua_general.cpp | 4 +- zone/lua_parser.cpp | 6 ++- zone/lua_parser_events.cpp | 17 ++++++ zone/lua_parser_events.h | 9 ++++ 7 files changed, 116 insertions(+), 37 deletions(-) diff --git a/zone/client.cpp b/zone/client.cpp index 727e69684..bd52d4438 100644 --- a/zone/client.cpp +++ b/zone/client.cpp @@ -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; diff --git a/zone/embparser.cpp b/zone/embparser.cpp index 155cb7810..88930fd42 100644 --- a/zone/embparser.cpp +++ b/zone/embparser.cpp @@ -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; } diff --git a/zone/event_codes.h b/zone/event_codes.h index 27a0c4d31..270c3dcf2 100644 --- a/zone/event_codes.h +++ b/zone/event_codes.h @@ -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, diff --git a/zone/lua_general.cpp b/zone/lua_general.cpp index c3d85a4b8..07724a510 100644 --- a/zone/lua_general.cpp +++ b/zone/lua_general.cpp @@ -6610,7 +6610,9 @@ luabind::scope lua_register_events() { luabind::value("unmemorize_spell", static_cast(EVENT_UNMEMORIZE_SPELL)), luabind::value("scribe_spell", static_cast(EVENT_SCRIBE_SPELL)), luabind::value("unscribe_spell", static_cast(EVENT_UNSCRIBE_SPELL)), - luabind::value("loot_added", static_cast(EVENT_LOOT_ADDED)) + luabind::value("loot_added", static_cast(EVENT_LOOT_ADDED)), + luabind::value("ldon_points_gain", static_cast(EVENT_LDON_POINTS_GAIN)), + luabind::value("ldon_points_loss", static_cast(EVENT_LDON_POINTS_LOSS)) )]; } diff --git a/zone/lua_parser.cpp b/zone/lua_parser.cpp index d34094c37..783ada5ec 100644 --- a/zone/lua_parser.cpp +++ b/zone/lua_parser.cpp @@ -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; diff --git a/zone/lua_parser_events.cpp b/zone/lua_parser_events.cpp index ac1762096..8b041cbd4 100644 --- a/zone/lua_parser_events.cpp +++ b/zone/lua_parser_events.cpp @@ -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 *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, diff --git a/zone/lua_parser_events.h b/zone/lua_parser_events.h index a8eaf1dbe..336804802 100644 --- a/zone/lua_parser_events.h +++ b/zone/lua_parser_events.h @@ -743,6 +743,15 @@ void handle_player_memorize_scribe_spell( std::vector *extra_pointers ); +void handle_player_ldon_points_gain_loss( + QuestInterface *parse, + lua_State* L, + Client* client, + std::string data, + uint32 extra_data, + std::vector *extra_pointers +); + // Item void handle_item_click( QuestInterface *parse,