diff --git a/Assets/PerfectWorld/Scripts/Managers/EC_InventoryUI.cs b/Assets/PerfectWorld/Scripts/Managers/EC_InventoryUI.cs index 673c0867e3..4a09092de8 100644 --- a/Assets/PerfectWorld/Scripts/Managers/EC_InventoryUI.cs +++ b/Assets/PerfectWorld/Scripts/Managers/EC_InventoryUI.cs @@ -158,19 +158,15 @@ namespace BrewMonster.Scripts.Managers { if (buttons == null) { - Debug.LogWarning($"[UpdatePackageCooldowns] Buttons list is null for package {package}"); return; } var items = model.GetInventoryData(package); if (items == null) { - Debug.LogWarning($"[UpdatePackageCooldowns] Items dictionary is null for package {package}"); return; } - Debug.Log($"[UpdatePackageCooldowns] Updating package {package} with {buttons.Count} buttons and {items.Count} items"); - for (int slot = 0; slot < buttons.Count; slot++) { var button = buttons[slot]; diff --git a/Assets/PerfectWorld/Scripts/Managers/EC_IvtrItem/EC_IvtrItem.cs b/Assets/PerfectWorld/Scripts/Managers/EC_IvtrItem/EC_IvtrItem.cs index 212988c424..1a747fd600 100644 --- a/Assets/PerfectWorld/Scripts/Managers/EC_IvtrItem/EC_IvtrItem.cs +++ b/Assets/PerfectWorld/Scripts/Managers/EC_IvtrItem/EC_IvtrItem.cs @@ -1088,6 +1088,16 @@ namespace BrewMonster.Scripts.Managers /// public virtual bool SetItemInfo(byte[] pInfoData, int iDataLen) { + if (pInfoData != null && iDataLen > 0) + { + this.Content = new byte[iDataLen]; + Buffer.BlockCopy(pInfoData, 0, this.Content, 0, iDataLen); + } + else + { + this.Content = null; + } + m_bNeedUpdate = false; m_bUpdating = false; m_strDesc = string.Empty; diff --git a/Assets/PerfectWorld/Scripts/Network/CSNetwork/GPDataType.cs b/Assets/PerfectWorld/Scripts/Network/CSNetwork/GPDataType.cs index 4529932d38..f54a2439a4 100644 --- a/Assets/PerfectWorld/Scripts/Network/CSNetwork/GPDataType.cs +++ b/Assets/PerfectWorld/Scripts/Network/CSNetwork/GPDataType.cs @@ -1305,9 +1305,17 @@ namespace CSNetwork.GPDataType public uint count; public ushort crc; public ushort content_length; - public byte[] content; + //public byte[] content; }; + [StructLayout(LayoutKind.Sequential, Pack = 1)] + public struct cmd_empty_item_slot + { + public byte byPackage; + public byte bySlot; + } + + [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct cmd_get_own_money { diff --git a/Assets/PerfectWorld/Scripts/UI/Dialogs/DlgInstall.cs b/Assets/PerfectWorld/Scripts/UI/Dialogs/DlgInstall.cs index ca4ec6b309..5583f69f1a 100644 --- a/Assets/PerfectWorld/Scripts/UI/Dialogs/DlgInstall.cs +++ b/Assets/PerfectWorld/Scripts/UI/Dialogs/DlgInstall.cs @@ -411,12 +411,17 @@ namespace BrewMonster private void ClearEquipSlot() { + if (m_FirstInvSlot >= 0) + { + ReturnItemToInventory(m_FirstInvSlot); + } + m_SelectedEquip?.Freeze(false); m_SelectedEquip = null; m_FirstInvSlot = -1; m_TxtFirstName.text = "___"; ClearSlotIcon(m_SlotFirstParent); - if(m_Mode == InstallMode.Disenchase) + if (m_Mode == InstallMode.Disenchase) { m_install_price = -1; m_TxtMoney.text = "0"; @@ -425,6 +430,11 @@ namespace BrewMonster private void ClearMaterialSlot() { + if (m_SecondInvSlot >= 0) + { + ReturnItemToInventory(m_SecondInvSlot); + } + m_SelectedMaterial?.Freeze(false); m_SelectedMaterial = null; m_SecondInvSlot = -1; @@ -450,7 +460,7 @@ namespace BrewMonster // PAUIDIALOG pMsgBox; CECHostPlayer pHost = GetHostPlayer(); - if (pHost != null || m_Mode == InstallMode.Enchase) + if (pHost != null && m_Mode == InstallMode.Enchase) { // if( !m_pItema->GetDataPtr("ptr_CECIvtrItem") ) return; string message = ""; @@ -529,16 +539,18 @@ namespace BrewMonster // pMsgBox.SetLife(3); return; } + //pr UnityGameSession.c2s_CmdNPCSevEmbed( (ushort)m_SecondInvSlot, (ushort)m_FirstInvSlot, pIvtrB.GetTemplateID(), pIvtrA.GetTemplateID()); - // ClearEquipment(); - // ClearStone(); + ClearEquipSlot(); + ClearMaterialSlot(); pHost.GetPack(InventoryConst.IVTRTYPE_PACK).UnfreezeAllItems(); message = GetGameUIMan().GetStringFromTable(228); CECUIManager.Instance.ShowMessageBox("", message); + // GetGameUIMan().MessageBox("", GetGameUIMan().GetStringFromTable(228), // MB_OK, A3DCOLORRGBA(255, 255, 255, 160), &pMsgBox); // pMsgBox.SetLife(3); diff --git a/Assets/Scripts/CECHostPlayer.cs b/Assets/Scripts/CECHostPlayer.cs index 8f9983b766..f5d0fd0ed1 100644 --- a/Assets/Scripts/CECHostPlayer.cs +++ b/Assets/Scripts/CECHostPlayer.cs @@ -1,5 +1,6 @@ using BrewMonster; using BrewMonster.Assets.PerfectWorld.Scripts.Players; +using BrewMonster.Assets.PerfectWorld.Scripts.UI; using BrewMonster.Managers; using BrewMonster.Network; using BrewMonster.PerfectWorld.Scripts.Vfx; @@ -19,6 +20,7 @@ using PerfectWorld.Scripts.Managers; using System; using System.Collections; using System.Collections.Generic; +using System.Linq; using System.Runtime.InteropServices; using System.Text; using UnityEngine; @@ -27,9 +29,8 @@ using static BrewMonster.Scripts.Managers.EC_Inventory; using static CECPlayerWrapper; using cmd_select_target = CSNetwork.GPDataType.cmd_select_target; using Host_work_ID = BrewMonster.Scripts.CECHPWork.Host_work_ID; -using Trace_reason = BrewMonster.CECHPWorkTrace.Trace_reason; using ObjectCoords = System.Collections.Generic.List; -using System.Linq; +using Trace_reason = BrewMonster.CECHPWorkTrace.Trace_reason; namespace BrewMonster { @@ -2745,10 +2746,97 @@ namespace BrewMonster { case CommandID.OWN_ITEM_INFO: { - Debug.Log("[Inventory] OWN_ITEM_INFO received"); + //Debug.Log("[Inventory] OWN_ITEM_INFO received"); + //var data = Msg.dwParam1 as byte[]; + //int hostId = Convert.ToInt32(Msg.dwParam3); + //LogInventoryPacket("OWN_ITEM_INFO", data, hostId); + + //Handmade var data = Msg.dwParam1 as byte[]; - int hostId = Convert.ToInt32(Msg.dwParam3); - LogInventoryPacket("OWN_ITEM_INFO", data, hostId); + if (data == null || data.Length == 0) + return; + + byte byPackage = data[0]; + byte bySlot = data[1]; + int type = BitConverter.ToInt32(data, 2); + int expire_date = BitConverter.ToInt32(data, 6); + int state = BitConverter.ToInt32(data, 10); + uint count = BitConverter.ToUInt32(data, 14); + ushort crc = BitConverter.ToUInt16(data, 18); + ushort content_length = BitConverter.ToUInt16(data, 20); + + byte[] content = null; + if (content_length > 0 && 22 + content_length <= data.Length) + { + content = new byte[content_length]; + Buffer.BlockCopy(data, 22, content, 0, content_length); + + string hexDebug = BitConverter.ToString(content); + //Debug.Log($"[OWN_ITEM_INFO] Full Content Hex ({content_length} bytes): {hexDebug}"); + } + + //Debug.Log($"[OWN_ITEM_INFO] Parsed: package={byPackage}, slot={bySlot}, tid={type}, count={count}, content_len={content_length}"); + + EC_Inventory pInventory = GetInventory(byPackage); + EC_IvtrItem newItem = EC_IvtrItem.CreateItem(type, expire_date, (int)count); + + if (newItem != null) + { + newItem.SetProcType(state); + + newItem.GetDetailDataFromLocal(); + if (content != null && content.Length > 0) + { + newItem.SetItemInfo(content, content_length); + } + + pInventory.SetItem(bySlot, newItem); + + //Debug.Log($"[OWN_ITEM_INFO] Fixed Update: Pack {byPackage} Slot {bySlot} - Type {type}"); + } + + if (byPackage == InventoryConst.IVTRTYPE_EQUIPPACK) + { + UpdateEquipSkins(); + } + else if (byPackage == InventoryConst.IVTRTYPE_PACK) + { + if (newItem.IsEquipment()) + { + // TODO + } + } + var ui = GameObject.FindFirstObjectByType(); + + if (ui != null) + { + ui.RefreshAll(); + //Debug.Log($"[OWN_ITEM_INFO] Refreshed inventory UI after updating item at package={byPackage}, slot={bySlot}"); + } + break; + + } + case CommandID.EMPTY_ITEM_SLOT: + { + var data = Msg.dwParam1 as byte[]; + + cmd_empty_item_slot pCmd = GPDataTypeHelper.FromBytes(data); + EC_Inventory pInventory = GetPack(pCmd.byPackage); + if (pInventory == null) + return; + + EC_IvtrItem pItem = pInventory.GetItem(pCmd.bySlot); + if (pItem != null) + { + //UpdateRemovedItemSC(pItem->GetTemplateID(), pCmd->byPackage, pCmd->bySlot); + } + pInventory.SetItem(pCmd.bySlot, null); + + var ui = GameObject.FindFirstObjectByType(); + if (ui != null) + { + ui.RefreshAll(); + } break; } } @@ -7527,7 +7615,7 @@ namespace BrewMonster } return iReason == 0 ? true : false; } - private void OnMsgHstEmbedItem(ECMSG Msg) + public void OnMsgHstEmbedItem(ECMSG Msg) { cmd_embed_item pCmd = GPDataTypeHelper.FromBytes((byte[])Msg.dwParam1); EC_IvtrItem pEquip = m_pPack.GetItem(pCmd.equip_idx);