diff --git a/zone/client.cpp b/zone/client.cpp index bd52d4438..43c69a2b4 100644 --- a/zone/client.cpp +++ b/zone/client.cpp @@ -6491,11 +6491,10 @@ void Client::SetAlternateCurrencyValue(uint32 currency_id, uint32 new_amount) SendAlternateCurrencyValue(currency_id); } -int Client::AddAlternateCurrencyValue(uint32 currency_id, int32 amount, int8 method) +int Client::AddAlternateCurrencyValue(uint32 currency_id, int amount, bool is_scripted) { - /* Added via Quest, rest of the logging methods may be done inline due to information available in that area of the code */ - if (method == 1){ + if (is_scripted) { /* QS: PlayerLogAlternateCurrencyTransactions :: Cursor to Item Storage */ if (RuleB(QueryServ, PlayerLogAlternateCurrencyTransactions)){ std::string event_desc = StringFormat("Added via Quest :: Cursor to Item :: alt_currency_id:%i amount:%i in zoneid:%i instid:%i", currency_id, GetZoneID(), GetInstanceID()); @@ -6503,32 +6502,47 @@ int Client::AddAlternateCurrencyValue(uint32 currency_id, int32 amount, int8 met } } - if(amount == 0) { + if (!amount) { return 0; } - if(!alternate_currency_loaded) { + if (!alternate_currency_loaded) { alternate_currency_queued_operations.push(std::make_pair(currency_id, amount)); return 0; } int new_value = 0; auto iter = alternate_currency.find(currency_id); - if(iter == alternate_currency.end()) { + if (iter == alternate_currency.end()) { new_value = amount; } else { new_value = (*iter).second + amount; } - if(new_value < 0) { + if (new_value < 0) { + new_value = 0; alternate_currency[currency_id] = 0; database.UpdateAltCurrencyValue(CharacterID(), currency_id, 0); } else { alternate_currency[currency_id] = new_value; database.UpdateAltCurrencyValue(CharacterID(), currency_id, new_value); } + SendAlternateCurrencyValue(currency_id); + QuestEventID event_id = amount > 0 ? EVENT_ALT_CURRENCY_GAIN : EVENT_ALT_CURRENCY_LOSS; + + if (parse->PlayerHasQuestSub(event_id)) { + const std::string &export_string = fmt::format( + "{} {} {}", + currency_id, + std::abs(amount), + new_value + ); + + parse->EventPlayer(event_id, this, export_string, 0); + } + return new_value; } diff --git a/zone/client.h b/zone/client.h index 4e4231e20..f58b69835 100644 --- a/zone/client.h +++ b/zone/client.h @@ -1493,7 +1493,7 @@ public: void ConsentCorpses(std::string consent_name, bool deny = false); void SendAltCurrencies(); void SetAlternateCurrencyValue(uint32 currency_id, uint32 new_amount); - int AddAlternateCurrencyValue(uint32 currency_id, int32 amount, int8 method = 0); + int AddAlternateCurrencyValue(uint32 currency_id, int amount, bool is_scripted = false); void SendAlternateCurrencyValues(); void SendAlternateCurrencyValue(uint32 currency_id, bool send_if_null = true); uint32 GetAlternateCurrencyValue(uint32 currency_id) const; diff --git a/zone/client_packet.cpp b/zone/client_packet.cpp index 76b54eabe..b4fa286b3 100644 --- a/zone/client_packet.cpp +++ b/zone/client_packet.cpp @@ -2626,7 +2626,7 @@ void Client::Handle_OP_AltCurrencyPurchase(const EQApplicationPacket *app) parse->EventPlayer(EVENT_ALT_CURRENCY_MERCHANT_BUY, this, export_string, 0); } - uint64 current_balance = AddAlternateCurrencyValue(alt_cur_id, -((int32) cost)); + uint64 current_balance = AddAlternateCurrencyValue(alt_cur_id, -((int) cost)); int16 charges = 1; if (item->MaxCharges != 0) { charges = item->MaxCharges; @@ -2701,7 +2701,7 @@ void Client::Handle_OP_AltCurrencyReclaim(const EQApplicationPacket *app) } else { SummonItem(item_id, reclaim->count, 0, 0, 0, 0, 0, 0, false, EQ::invslot::slotCursor); - AddAlternateCurrencyValue(reclaim->currency_id, -((int32)reclaim->count)); + AddAlternateCurrencyValue(reclaim->currency_id, -((int)reclaim->count)); } /* QS: PlayerLogAlternateCurrencyTransactions :: Cursor to Item Storage */ if (RuleB(QueryServ, PlayerLogAlternateCurrencyTransactions)) { diff --git a/zone/embparser.cpp b/zone/embparser.cpp index 88930fd42..c9e722da8 100644 --- a/zone/embparser.cpp +++ b/zone/embparser.cpp @@ -189,6 +189,8 @@ const char *QuestEventSubroutines[_LargestEventID] = { "EVENT_LOOT_ADDED", "EVENT_LDON_POINTS_GAIN", "EVENT_LDON_POINTS_LOSS", + "EVENT_ALT_CURRENCY_GAIN", + "EVENT_ALT_CURRENCY_LOSS", // Add new events before these or Lua crashes "EVENT_SPELL_EFFECT_BOT", "EVENT_SPELL_EFFECT_BUFF_TIC_BOT" @@ -2270,6 +2272,15 @@ void PerlembParser::ExportEventVariables( break; } + case EVENT_ALT_CURRENCY_GAIN: + case EVENT_ALT_CURRENCY_LOSS: { + Seperator sep(data); + ExportVar(package_name.c_str(), "currency_id", sep.arg[0]); + ExportVar(package_name.c_str(), "amount", sep.arg[1]); + ExportVar(package_name.c_str(), "total", sep.arg[2]); + break; + } + default: { break; } diff --git a/zone/event_codes.h b/zone/event_codes.h index 270c3dcf2..9d3f145c7 100644 --- a/zone/event_codes.h +++ b/zone/event_codes.h @@ -131,6 +131,9 @@ typedef enum { EVENT_LOOT_ADDED, EVENT_LDON_POINTS_GAIN, EVENT_LDON_POINTS_LOSS, + EVENT_ALT_CURRENCY_GAIN, + EVENT_ALT_CURRENCY_LOSS, + // Add new events before these or Lua crashes EVENT_SPELL_EFFECT_BOT, EVENT_SPELL_EFFECT_BUFF_TIC_BOT, diff --git a/zone/lua_client.cpp b/zone/lua_client.cpp index 4b4ebae70..888066248 100644 --- a/zone/lua_client.cpp +++ b/zone/lua_client.cpp @@ -1486,15 +1486,15 @@ void Lua_Client::Signal(int signal_id) { void Lua_Client::AddAlternateCurrencyValue(uint32 currency, int amount) { Lua_Safe_Call_Void(); - self->AddAlternateCurrencyValue(currency, amount, 1); + self->AddAlternateCurrencyValue(currency, amount, true); } -void Lua_Client::SetAlternateCurrencyValue(uint32 currency, int amount) { +void Lua_Client::SetAlternateCurrencyValue(uint32 currency, uint32 amount) { Lua_Safe_Call_Void(); self->SetAlternateCurrencyValue(currency, amount); } -int Lua_Client::GetAlternateCurrencyValue(uint32 currency) { +uint32 Lua_Client::GetAlternateCurrencyValue(uint32 currency) { Lua_Safe_Call_Int(); return self->GetAlternateCurrencyValue(currency); } @@ -3303,7 +3303,7 @@ luabind::scope lua_register_client() { .def("GetAccountFlags", (luabind::object(Lua_Client::*)(lua_State*))&Lua_Client::GetAccountFlags) .def("GetAggroCount", (uint32(Lua_Client::*)(void))&Lua_Client::GetAggroCount) .def("GetAllMoney", (uint64(Lua_Client::*)(void))&Lua_Client::GetAllMoney) - .def("GetAlternateCurrencyValue", (int(Lua_Client::*)(uint32))&Lua_Client::GetAlternateCurrencyValue) + .def("GetAlternateCurrencyValue", (uint32(Lua_Client::*)(uint32))&Lua_Client::GetAlternateCurrencyValue) .def("GetAnon", (int(Lua_Client::*)(void))&Lua_Client::GetAnon) .def("GetAugmentIDAt", (int(Lua_Client::*)(int,int))&Lua_Client::GetAugmentIDAt) .def("GetAugmentIDsBySlotID", (luabind::object(Lua_Client::*)(lua_State* L,int16))&Lua_Client::GetAugmentIDsBySlotID) @@ -3586,7 +3586,7 @@ luabind::scope lua_register_client() { .def("SetAATitle", (void(Lua_Client::*)(std::string,bool))&Lua_Client::SetAATitle) .def("SetAFK", (void(Lua_Client::*)(uint8))&Lua_Client::SetAFK) .def("SetAccountFlag", (void(Lua_Client::*)(const std::string&,const std::string&))&Lua_Client::SetAccountFlag) - .def("SetAlternateCurrencyValue", (void(Lua_Client::*)(uint32,int))&Lua_Client::SetAlternateCurrencyValue) + .def("SetAlternateCurrencyValue", (void(Lua_Client::*)(uint32,uint32))&Lua_Client::SetAlternateCurrencyValue) .def("SetAnon", (void(Lua_Client::*)(uint8))&Lua_Client::SetAnon) .def("SetBaseClass", (void(Lua_Client::*)(int))&Lua_Client::SetBaseClass) .def("SetBaseGender", (void(Lua_Client::*)(int))&Lua_Client::SetBaseGender) diff --git a/zone/lua_client.h b/zone/lua_client.h index e2f859cd3..8017555e2 100644 --- a/zone/lua_client.h +++ b/zone/lua_client.h @@ -376,8 +376,8 @@ public: void NotifyNewTitlesAvailable(); void Signal(int signal_id); void AddAlternateCurrencyValue(uint32 currency, int amount); - void SetAlternateCurrencyValue(uint32 currency, int amount); - int GetAlternateCurrencyValue(uint32 currency); + void SetAlternateCurrencyValue(uint32 currency, uint32 amount); + uint32 GetAlternateCurrencyValue(uint32 currency); void SendWebLink(const char *site); bool HasSpellScribed(int spell_id); void ClearAccountFlag(const std::string& flag); diff --git a/zone/lua_general.cpp b/zone/lua_general.cpp index 07724a510..5e952a803 100644 --- a/zone/lua_general.cpp +++ b/zone/lua_general.cpp @@ -6612,7 +6612,9 @@ luabind::scope lua_register_events() { luabind::value("unscribe_spell", static_cast(EVENT_UNSCRIBE_SPELL)), 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)) + luabind::value("ldon_points_loss", static_cast(EVENT_LDON_POINTS_LOSS)), + luabind::value("alt_currency_gain", static_cast(EVENT_ALT_CURRENCY_GAIN)), + luabind::value("alt_currency_loss", static_cast(EVENT_ALT_CURRENCY_LOSS)) )]; } diff --git a/zone/lua_parser.cpp b/zone/lua_parser.cpp index 783ada5ec..bd5a58441 100644 --- a/zone/lua_parser.cpp +++ b/zone/lua_parser.cpp @@ -171,7 +171,9 @@ const char *LuaEvents[_LargestEventID] = { "event_unscribe_spell", "event_loot_added", "event_ldon_points_gain", - "event_ldon_points_loss" + "event_ldon_points_loss", + "event_alt_currency_gain", + "event_alt_currency_loss" }; extern Zone *zone; @@ -306,6 +308,8 @@ LuaParser::LuaParser() { 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; + PlayerArgumentDispatch[EVENT_ALT_CURRENCY_GAIN] = handle_player_alt_currency_gain_loss; + PlayerArgumentDispatch[EVENT_ALT_CURRENCY_LOSS] = handle_player_alt_currency_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 8b041cbd4..ed4611fce 100644 --- a/zone/lua_parser_events.cpp +++ b/zone/lua_parser_events.cpp @@ -1518,6 +1518,26 @@ void handle_player_ldon_points_gain_loss( lua_setfield(L, -2, "points"); } +void handle_player_alt_currency_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, "currency_id"); + + lua_pushnumber(L, Strings::ToInt(sep.arg[1])); + lua_setfield(L, -2, "amount"); + + lua_pushnumber(L, Strings::ToUnsignedInt(sep.arg[2])); + lua_setfield(L, -2, "total"); +} + // Item void handle_item_click( QuestInterface *parse, diff --git a/zone/lua_parser_events.h b/zone/lua_parser_events.h index 336804802..89af5164b 100644 --- a/zone/lua_parser_events.h +++ b/zone/lua_parser_events.h @@ -752,6 +752,15 @@ void handle_player_ldon_points_gain_loss( std::vector *extra_pointers ); +void handle_player_alt_currency_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, diff --git a/zone/perl_client.cpp b/zone/perl_client.cpp index c6954479a..d980b950a 100644 --- a/zone/perl_client.cpp +++ b/zone/perl_client.cpp @@ -1472,12 +1472,12 @@ void Perl_Client_NotifyNewTitlesAvailable(Client* self) // @categories Account a self->NotifyNewTitlesAvailable(); } -void Perl_Client_AddAlternateCurrencyValue(Client* self, uint32 currency_id, int32 amount) // @categories Currency and Points +void Perl_Client_AddAlternateCurrencyValue(Client* self, uint32 currency_id, int amount) // @categories Currency and Points { - self->AddAlternateCurrencyValue(currency_id, amount); + self->AddAlternateCurrencyValue(currency_id, amount, true); } -void Perl_Client_SetAlternateCurrencyValue(Client* self, uint32 currency_id, int32 amount) // @categories Currency and Points +void Perl_Client_SetAlternateCurrencyValue(Client* self, uint32 currency_id, uint32 amount) // @categories Currency and Points { self->SetAlternateCurrencyValue(currency_id, amount); }