[Quest API] Add EVENT_ALT_CURRENCY_GAIN and EVENT_ALT_CURRENCY_LOSS to Perl/Lua (#3734)

* [Quest API] Add EVENT_ALT_CURRENCY_GAIN and EVENT_ALT_CURRENCY_LOSS

- Add `EVENT_ALT_CURRENCY_GAIN`.
- Add `EVENT_ALT_CURRENCY_LOSS`.
- Export `$currency_id`, `$amount`, and `$total.

- Add `event_alt_currency_gain`.
- Add `event_alt_currency_loss`.
- Export `e.currency_id`, `e.amount`, and `e.total.

- Convert `int8 method` to `bool is_scripted` in `Client::AddAlternateCurrencyValue`.
- Properly utilize `is_scripted` parameter in `perl_client.cpp`.
- Allows operators to perform events on alternate currency gains/losses.

* Update lua_general.cpp

* Cleanup types.

* Update lua_client.cpp
This commit is contained in:
Alex King 2023-12-16 23:40:24 -05:00 committed by GitHub
parent 8aae59eebe
commit 9739c1c8ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 85 additions and 22 deletions

View File

@ -6491,11 +6491,10 @@ void Client::SetAlternateCurrencyValue(uint32 currency_id, uint32 new_amount)
SendAlternateCurrencyValue(currency_id); 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 */ /* 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 */ /* QS: PlayerLogAlternateCurrencyTransactions :: Cursor to Item Storage */
if (RuleB(QueryServ, PlayerLogAlternateCurrencyTransactions)){ 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()); 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; return 0;
} }
if(!alternate_currency_loaded) { if (!alternate_currency_loaded) {
alternate_currency_queued_operations.push(std::make_pair(currency_id, amount)); alternate_currency_queued_operations.push(std::make_pair(currency_id, amount));
return 0; return 0;
} }
int new_value = 0; int new_value = 0;
auto iter = alternate_currency.find(currency_id); auto iter = alternate_currency.find(currency_id);
if(iter == alternate_currency.end()) { if (iter == alternate_currency.end()) {
new_value = amount; new_value = amount;
} else { } else {
new_value = (*iter).second + amount; new_value = (*iter).second + amount;
} }
if(new_value < 0) { if (new_value < 0) {
new_value = 0;
alternate_currency[currency_id] = 0; alternate_currency[currency_id] = 0;
database.UpdateAltCurrencyValue(CharacterID(), currency_id, 0); database.UpdateAltCurrencyValue(CharacterID(), currency_id, 0);
} else { } else {
alternate_currency[currency_id] = new_value; alternate_currency[currency_id] = new_value;
database.UpdateAltCurrencyValue(CharacterID(), currency_id, new_value); database.UpdateAltCurrencyValue(CharacterID(), currency_id, new_value);
} }
SendAlternateCurrencyValue(currency_id); 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; return new_value;
} }

View File

@ -1493,7 +1493,7 @@ public:
void ConsentCorpses(std::string consent_name, bool deny = false); void ConsentCorpses(std::string consent_name, bool deny = false);
void SendAltCurrencies(); void SendAltCurrencies();
void SetAlternateCurrencyValue(uint32 currency_id, uint32 new_amount); 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 SendAlternateCurrencyValues();
void SendAlternateCurrencyValue(uint32 currency_id, bool send_if_null = true); void SendAlternateCurrencyValue(uint32 currency_id, bool send_if_null = true);
uint32 GetAlternateCurrencyValue(uint32 currency_id) const; uint32 GetAlternateCurrencyValue(uint32 currency_id) const;

View File

@ -2626,7 +2626,7 @@ void Client::Handle_OP_AltCurrencyPurchase(const EQApplicationPacket *app)
parse->EventPlayer(EVENT_ALT_CURRENCY_MERCHANT_BUY, this, export_string, 0); 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; int16 charges = 1;
if (item->MaxCharges != 0) { if (item->MaxCharges != 0) {
charges = item->MaxCharges; charges = item->MaxCharges;
@ -2701,7 +2701,7 @@ void Client::Handle_OP_AltCurrencyReclaim(const EQApplicationPacket *app)
} }
else { else {
SummonItem(item_id, reclaim->count, 0, 0, 0, 0, 0, 0, false, EQ::invslot::slotCursor); 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 */ /* QS: PlayerLogAlternateCurrencyTransactions :: Cursor to Item Storage */
if (RuleB(QueryServ, PlayerLogAlternateCurrencyTransactions)) { if (RuleB(QueryServ, PlayerLogAlternateCurrencyTransactions)) {

View File

@ -189,6 +189,8 @@ const char *QuestEventSubroutines[_LargestEventID] = {
"EVENT_LOOT_ADDED", "EVENT_LOOT_ADDED",
"EVENT_LDON_POINTS_GAIN", "EVENT_LDON_POINTS_GAIN",
"EVENT_LDON_POINTS_LOSS", "EVENT_LDON_POINTS_LOSS",
"EVENT_ALT_CURRENCY_GAIN",
"EVENT_ALT_CURRENCY_LOSS",
// 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"
@ -2270,6 +2272,15 @@ void PerlembParser::ExportEventVariables(
break; 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: { default: {
break; break;
} }

View File

@ -131,6 +131,9 @@ typedef enum {
EVENT_LOOT_ADDED, EVENT_LOOT_ADDED,
EVENT_LDON_POINTS_GAIN, EVENT_LDON_POINTS_GAIN,
EVENT_LDON_POINTS_LOSS, EVENT_LDON_POINTS_LOSS,
EVENT_ALT_CURRENCY_GAIN,
EVENT_ALT_CURRENCY_LOSS,
// 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

@ -1486,15 +1486,15 @@ void Lua_Client::Signal(int signal_id) {
void Lua_Client::AddAlternateCurrencyValue(uint32 currency, int amount) { void Lua_Client::AddAlternateCurrencyValue(uint32 currency, int amount) {
Lua_Safe_Call_Void(); 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(); Lua_Safe_Call_Void();
self->SetAlternateCurrencyValue(currency, amount); self->SetAlternateCurrencyValue(currency, amount);
} }
int Lua_Client::GetAlternateCurrencyValue(uint32 currency) { uint32 Lua_Client::GetAlternateCurrencyValue(uint32 currency) {
Lua_Safe_Call_Int(); Lua_Safe_Call_Int();
return self->GetAlternateCurrencyValue(currency); 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("GetAccountFlags", (luabind::object(Lua_Client::*)(lua_State*))&Lua_Client::GetAccountFlags)
.def("GetAggroCount", (uint32(Lua_Client::*)(void))&Lua_Client::GetAggroCount) .def("GetAggroCount", (uint32(Lua_Client::*)(void))&Lua_Client::GetAggroCount)
.def("GetAllMoney", (uint64(Lua_Client::*)(void))&Lua_Client::GetAllMoney) .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("GetAnon", (int(Lua_Client::*)(void))&Lua_Client::GetAnon)
.def("GetAugmentIDAt", (int(Lua_Client::*)(int,int))&Lua_Client::GetAugmentIDAt) .def("GetAugmentIDAt", (int(Lua_Client::*)(int,int))&Lua_Client::GetAugmentIDAt)
.def("GetAugmentIDsBySlotID", (luabind::object(Lua_Client::*)(lua_State* L,int16))&Lua_Client::GetAugmentIDsBySlotID) .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("SetAATitle", (void(Lua_Client::*)(std::string,bool))&Lua_Client::SetAATitle)
.def("SetAFK", (void(Lua_Client::*)(uint8))&Lua_Client::SetAFK) .def("SetAFK", (void(Lua_Client::*)(uint8))&Lua_Client::SetAFK)
.def("SetAccountFlag", (void(Lua_Client::*)(const std::string&,const std::string&))&Lua_Client::SetAccountFlag) .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("SetAnon", (void(Lua_Client::*)(uint8))&Lua_Client::SetAnon)
.def("SetBaseClass", (void(Lua_Client::*)(int))&Lua_Client::SetBaseClass) .def("SetBaseClass", (void(Lua_Client::*)(int))&Lua_Client::SetBaseClass)
.def("SetBaseGender", (void(Lua_Client::*)(int))&Lua_Client::SetBaseGender) .def("SetBaseGender", (void(Lua_Client::*)(int))&Lua_Client::SetBaseGender)

View File

@ -376,8 +376,8 @@ public:
void NotifyNewTitlesAvailable(); void NotifyNewTitlesAvailable();
void Signal(int signal_id); void Signal(int signal_id);
void AddAlternateCurrencyValue(uint32 currency, int amount); void AddAlternateCurrencyValue(uint32 currency, int amount);
void SetAlternateCurrencyValue(uint32 currency, int amount); void SetAlternateCurrencyValue(uint32 currency, uint32 amount);
int GetAlternateCurrencyValue(uint32 currency); uint32 GetAlternateCurrencyValue(uint32 currency);
void SendWebLink(const char *site); void SendWebLink(const char *site);
bool HasSpellScribed(int spell_id); bool HasSpellScribed(int spell_id);
void ClearAccountFlag(const std::string& flag); void ClearAccountFlag(const std::string& flag);

View File

@ -6612,7 +6612,9 @@ luabind::scope lua_register_events() {
luabind::value("unscribe_spell", static_cast<int>(EVENT_UNSCRIBE_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_gain", static_cast<int>(EVENT_LDON_POINTS_GAIN)),
luabind::value("ldon_points_loss", static_cast<int>(EVENT_LDON_POINTS_LOSS)) luabind::value("ldon_points_loss", static_cast<int>(EVENT_LDON_POINTS_LOSS)),
luabind::value("alt_currency_gain", static_cast<int>(EVENT_ALT_CURRENCY_GAIN)),
luabind::value("alt_currency_loss", static_cast<int>(EVENT_ALT_CURRENCY_LOSS))
)]; )];
} }

View File

@ -171,7 +171,9 @@ const char *LuaEvents[_LargestEventID] = {
"event_unscribe_spell", "event_unscribe_spell",
"event_loot_added", "event_loot_added",
"event_ldon_points_gain", "event_ldon_points_gain",
"event_ldon_points_loss" "event_ldon_points_loss",
"event_alt_currency_gain",
"event_alt_currency_loss"
}; };
extern Zone *zone; extern Zone *zone;
@ -306,6 +308,8 @@ LuaParser::LuaParser() {
PlayerArgumentDispatch[EVENT_UNSCRIBE_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_GAIN] = handle_player_ldon_points_gain_loss;
PlayerArgumentDispatch[EVENT_LDON_POINTS_LOSS] = 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] = handle_item_click;
ItemArgumentDispatch[EVENT_ITEM_CLICK_CAST] = handle_item_click; ItemArgumentDispatch[EVENT_ITEM_CLICK_CAST] = handle_item_click;

View File

@ -1518,6 +1518,26 @@ void handle_player_ldon_points_gain_loss(
lua_setfield(L, -2, "points"); 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<std::any> *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 // Item
void handle_item_click( void handle_item_click(
QuestInterface *parse, QuestInterface *parse,

View File

@ -752,6 +752,15 @@ void handle_player_ldon_points_gain_loss(
std::vector<std::any> *extra_pointers std::vector<std::any> *extra_pointers
); );
void handle_player_alt_currency_gain_loss(
QuestInterface *parse,
lua_State* L,
Client* client,
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

@ -1472,12 +1472,12 @@ void Perl_Client_NotifyNewTitlesAvailable(Client* self) // @categories Account a
self->NotifyNewTitlesAvailable(); 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); self->SetAlternateCurrencyValue(currency_id, amount);
} }