From eed1fd8a4320d85c534ea59e216f139ad6de7e8d Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 29 Jun 2020 20:54:48 -0400 Subject: [PATCH] Add DyeArmorBySlot(slot, red, green, blue, use_tint) to Perl/Lua. --- zone/client.h | 1 + zone/inventory.cpp | 16 ++++++++++++++++ zone/lua_client.cpp | 12 ++++++++++++ zone/lua_client.h | 2 ++ zone/perl_client.cpp | 29 +++++++++++++++++++++++++++++ 5 files changed, 60 insertions(+) diff --git a/zone/client.h b/zone/client.h index 91319b04a..20ae0795b 100644 --- a/zone/client.h +++ b/zone/client.h @@ -276,6 +276,7 @@ public: GetItems_Struct* GetTraderItems(); void SendBazaarWelcome(); void DyeArmor(EQ::TintProfile* dye); + void DyeArmorBySlot(uint8 slot, uint8 red, uint8 green, uint8 blue, uint8 use_tint = 0x00); uint8 SlotConvert(uint8 slot,bool bracer=false); void MessageString(uint32 type, uint32 string_id, uint32 distance = 0); void MessageString(uint32 type, uint32 string_id, const char* message,const char* message2=0,const char* message3=0,const char* message4=0,const char* message5=0,const char* message6=0,const char* message7=0,const char* message8=0,const char* message9=0, uint32 distance = 0); diff --git a/zone/inventory.cpp b/zone/inventory.cpp index 993cdac8a..54ae07b7d 100644 --- a/zone/inventory.cpp +++ b/zone/inventory.cpp @@ -2228,6 +2228,22 @@ void Client::DyeArmor(EQ::TintProfile* dye){ } +void Client::DyeArmorBySlot(uint8 slot, uint8 red, uint8 green, uint8 blue, uint8 use_tint) { + uint8 item_slot = SlotConvert(slot); + EQ::ItemInstance* item_instance = this->m_inv.GetItem(item_slot); + if (item_instance) { + uint32 armor_color = ((uint32)red << 16) | ((uint32)green << 8) | ((uint32)blue); + item_instance->SetColor(armor_color); + database.SaveCharacterMaterialColor(this->CharacterID(), slot, armor_color); + database.SaveInventory(CharacterID(), item_instance, item_slot); + m_pp.item_tint.Slot[slot].UseTint = (use_tint ? 0xFF : 0x00); + } + m_pp.item_tint.Slot[slot].Red = red; + m_pp.item_tint.Slot[slot].Green = green; + m_pp.item_tint.Slot[slot].Blue = blue; + SendWearChange(slot); +} + #if 0 bool Client::DecreaseByItemType(uint32 type, uint8 amt) { const ItemData* TempItem = 0; diff --git a/zone/lua_client.cpp b/zone/lua_client.cpp index 88d085f41..70adce43f 100644 --- a/zone/lua_client.cpp +++ b/zone/lua_client.cpp @@ -75,6 +75,16 @@ void Lua_Client::Duck() { self->Duck(); } +void Lua_Client::DyeArmorBySlot(uint8 slot, uint8 red, uint8 green, uint8 blue) { + Lua_Safe_Call_Void(); + self->DyeArmorBySlot(slot, red, green, blue); +} + +void Lua_Client::DyeArmorBySlot(uint8 slot, uint8 red, uint8 green, uint8 blue, uint8 use_tint) { + Lua_Safe_Call_Void(); + self->DyeArmorBySlot(slot, red, green, blue, use_tint); +} + void Lua_Client::Stand() { Lua_Safe_Call_Void(); self->Stand(); @@ -1622,6 +1632,8 @@ luabind::scope lua_register_client() { .def("SendToGuildHall", (void(Lua_Client::*)(void))&Lua_Client::SendToGuildHall) .def("GetAnon", (bool(Lua_Client::*)(void))&Lua_Client::GetAnon) .def("Duck", (void(Lua_Client::*)(void))&Lua_Client::Duck) + .def("DyeArmorBySlot", (void(Lua_Client::*)(uint8,uint8,uint8,uint8))&Lua_Client::DyeArmorBySlot) + .def("DyeArmorBySlot", (void(Lua_Client::*)(uint8,uint8,uint8,uint8,uint8))&Lua_Client::DyeArmorBySlot) .def("Stand", (void(Lua_Client::*)(void))&Lua_Client::Stand) .def("SetGM", (void(Lua_Client::*)(bool))&Lua_Client::SetGM) .def("SetPVP", (void(Lua_Client::*)(bool))&Lua_Client::SetPVP) diff --git a/zone/lua_client.h b/zone/lua_client.h index 1453c46e9..45eeb27a4 100644 --- a/zone/lua_client.h +++ b/zone/lua_client.h @@ -42,6 +42,8 @@ public: void SendToGuildHall(); bool GetAnon(); void Duck(); + void DyeArmorBySlot(uint8 slot, uint8 red, uint8 green, uint8 blue); + void DyeArmorBySlot(uint8 slot, uint8 red, uint8 green, uint8 blue, uint8 use_tint); void Stand(); void SetGM(bool v); void SetPVP(bool v); diff --git a/zone/perl_client.cpp b/zone/perl_client.cpp index 393f8ea28..8a13df9d3 100644 --- a/zone/perl_client.cpp +++ b/zone/perl_client.cpp @@ -312,6 +312,34 @@ XS(XS_Client_Duck) { XSRETURN_EMPTY; } +XS(XS_Client_DyeArmorBySlot); /* prototype to pass -Wmissing-prototypes */ +XS(XS_Client_DyeArmorBySlot) { + dXSARGS; + if (items != 5 && items != 6) + Perl_croak(aTHX_ "Usage: Client::DyeArmorBySlot(THIS, uint8 slot, uint8 red, uint8 green, uint8 blue, [uint8 use_tint = 0x00])"); + { + Client *THIS; + uint8 slot = (uint8) SvUV(ST(1)); + uint8 red = (uint8) SvUV(ST(2)); + uint8 green = (uint8) SvUV(ST(3)); + uint8 blue = (uint8) SvUV(ST(4)); + uint8 use_tint = 0x00; + if (items == 6) { + use_tint = (uint8) SvUV(ST(5)); + } + 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."); + + THIS->DyeArmorBySlot(slot, red, green, blue, use_tint); + } + XSRETURN_EMPTY; +} + XS(XS_Client_Stand); /* prototype to pass -Wmissing-prototypes */ XS(XS_Client_Stand) { dXSARGS; @@ -6585,6 +6613,7 @@ XS(boot_Client) { newXSproto(strcpy(buf, "Disconnect"), XS_Client_Disconnect, file, "$"); newXSproto(strcpy(buf, "DropItem"), XS_Client_DropItem, file, "$$"); newXSproto(strcpy(buf, "Duck"), XS_Client_Duck, file, "$"); + newXSproto(strcpy(buf, "DyeArmorBySlot"), XS_Client_DyeArmorBySlot, file, "$$$$$;$"); newXSproto(strcpy(buf, "Escape"), XS_Client_Escape, file, "$"); newXSproto(strcpy(buf, "ExpeditionMessage"), XS_Client_ExpeditionMessage, file, "$$$"); newXSproto(strcpy(buf, "FailTask"), XS_Client_FailTask, file, "$$");