From 892fb58b181929fbad045cec8483fa35454d3f06 Mon Sep 17 00:00:00 2001 From: Kinglykrab Date: Sat, 1 Aug 2015 00:11:18 -0400 Subject: [PATCH] Added $client->GetMoney(type, subtype) to Perl/Lua. Types: - 0: Copper - 1: Silver - 2: Gold - 3: Platinum Sub Types (if applicable): - 0: On Character - 1: In Bank - 2: On Cursor - 3: Shared Bank (only applies to Type 3/Platinum) --- zone/client.cpp | 76 ++++++++++++++++++++++++++++++++++++++++++++ zone/client.h | 1 + zone/lua_client.cpp | 8 ++++- zone/lua_client.h | 1 + zone/perl_client.cpp | 31 ++++++++++++++++++ 5 files changed, 116 insertions(+), 1 deletion(-) diff --git a/zone/client.cpp b/zone/client.cpp index 47b2eea68..f784e507e 100644 --- a/zone/client.cpp +++ b/zone/client.cpp @@ -8592,3 +8592,79 @@ void Client::SendHPUpdateMarquee(){ std::string health_update_notification = StringFormat("Health: %u%%", health_percentage); this->SendMarqueeMessage(15, 510, 0, 3000, 3000, health_update_notification); } + +uint32 Client::GetMoney(uint8 type, uint8 subtype) { + uint32 value = 0; + switch (type) { + case 0: { + switch (subtype) { + case 0: + value = static_cast(m_pp.copper); + break; + case 1: + value = static_cast(m_pp.copper_bank); + break; + case 2: + value = static_cast(m_pp.copper_cursor); + break; + default: + break; + } + break; + } + case 1: { + switch (subtype) { + case 0: + value = static_cast(m_pp.silver); + break; + case 1: + value = static_cast(m_pp.silver_bank); + break; + case 2: + value = static_cast(m_pp.silver_cursor); + break; + default: + break; + } + break; + } + case 2: { + switch (subtype) { + case 0: + value = static_cast(m_pp.gold); + break; + case 1: + value = static_cast(m_pp.gold_bank); + break; + case 2: + value = static_cast(m_pp.gold_cursor); + break; + default: + break; + } + break; + } + case 3: { + switch (subtype) { + case 0: + value = static_cast(m_pp.platinum); + break; + case 1: + value = static_cast(m_pp.platinum_bank); + break; + case 2: + value = static_cast(m_pp.platinum_cursor); + break; + case 3: + value = static_cast(m_pp.platinum_shared); + break; + default: + break; + } + break; + } + default: + break; + } + return value; +} \ No newline at end of file diff --git a/zone/client.h b/zone/client.h index 22c81290c..64017fec3 100644 --- a/zone/client.h +++ b/zone/client.h @@ -663,6 +663,7 @@ public: bool HasMoney(uint64 copper); uint64 GetCarriedMoney(); uint64 GetAllMoney(); + uint32 GetMoney(uint8 type, uint8 subtype); bool IsDiscovered(uint32 itemid); void DiscoverItem(uint32 itemid); diff --git a/zone/lua_client.cpp b/zone/lua_client.cpp index 7aa78d11d..b7dad0ce3 100644 --- a/zone/lua_client.cpp +++ b/zone/lua_client.cpp @@ -1315,6 +1315,11 @@ void Lua_Client::QuestReward(Lua_Mob target, uint32 copper, uint32 silver, uint3 self->QuestReward(target, copper, silver, gold, platinum, itemid, exp, faction); } +uint32 Lua_Client::GetMoney(uint8 type, uint8 subtype) { + Lua_Safe_Call_Int(); + return self->GetMoney(type, subtype); +} + luabind::scope lua_register_client() { return luabind::class_("Client") .def(luabind::constructor<>()) @@ -1576,7 +1581,8 @@ luabind::scope lua_register_client() { .def("QuestReward", (void(Lua_Client::*)(Lua_Mob, uint32, uint32, uint32, uint32))&Lua_Client::QuestReward) .def("QuestReward", (void(Lua_Client::*)(Lua_Mob, uint32, uint32, uint32, uint32, uint32))&Lua_Client::QuestReward) .def("QuestReward", (void(Lua_Client::*)(Lua_Mob, uint32, uint32, uint32, uint32, uint32, uint32))&Lua_Client::QuestReward) - .def("QuestReward", (void(Lua_Client::*)(Lua_Mob, uint32, uint32, uint32, uint32, uint32, uint32, bool))&Lua_Client::QuestReward); + .def("QuestReward", (void(Lua_Client::*)(Lua_Mob, uint32, uint32, uint32, uint32, uint32, uint32, bool))&Lua_Client::QuestReward) + .def("GetMoney", (uint32(Lua_Client::*)(uint8, uint8))&Lua_Client::GetMoney); } luabind::scope lua_register_inventory_where() { diff --git a/zone/lua_client.h b/zone/lua_client.h index f3f0e1897..e50a16b98 100644 --- a/zone/lua_client.h +++ b/zone/lua_client.h @@ -256,6 +256,7 @@ public: int GetAggroCount(); uint64 GetCarriedMoney(); uint64 GetAllMoney(); + uint32 GetMoney(uint8 type, uint8 subtype); void OpenLFGuildWindow(); void Signal(uint32 id); void AddAlternateCurrencyValue(uint32 currency, int amount); diff --git a/zone/perl_client.cpp b/zone/perl_client.cpp index de9e8512a..0eb3b918b 100644 --- a/zone/perl_client.cpp +++ b/zone/perl_client.cpp @@ -6280,6 +6280,36 @@ XS(XS_Client_QuestReward) XSRETURN_EMPTY; } +XS(XS_Client_GetMoney); +XS(XS_Client_GetMoney) +{ + dXSARGS; + if (items != 3) + Perl_croak(aTHX_ "Usage: GetMoney(THIS, type, subtype)"); + { + Client* THIS; + uint32 RETVAL; + uint8 type = (uint8)SvUV(ST(1)); + uint8 subtype = (uint8)SvUV(ST(2)); + dXSTARG; + + if (sv_derived_from(ST(0), "Client")) { + IV tmp = SvIV((SV*)SvRV(ST(0))); + THIS = INT2PTR(Client *,tmp); + } + else + Perl_croak(aTHX_ "THIS is not of type Client"); + + if(THIS == nullptr) + Perl_croak(aTHX_ "THIS is nullptr, avoiding crash."); + + RETVAL = THIS->GetMoney(type, subtype); + XSprePUSH; PUSHn((uint32)RETVAL); + } + XSRETURN(1); +} + + #ifdef __cplusplus extern "C" #endif @@ -6527,6 +6557,7 @@ XS(boot_Client) newXSproto(strcpy(buf, "GetTargetRingZ"), XS_Client_GetTargetRingZ, file, "$$"); newXSproto(strcpy(buf, "QuestReward"), XS_Client_QuestReward, file, "$$;$$$$$$$"); newXSproto(strcpy(buf, "CalcEXP"), XS_Client_CalcEXP, file, "$"); + newXSproto(strcpy(buf, "GetMoney"), XS_Client_GetMoney, file, "$$$"); XSRETURN_YES; }