Merge pull request 'feature/hp_pet' (#175) from feature/hp_pet into develop

Reviewed-on: https://git.pthub.vn/Unity/perfect-world-unity/pulls/175
This commit is contained in:
hungdk
2026-02-27 03:37:34 +00:00
10 changed files with 108 additions and 6 deletions
@@ -3,6 +3,7 @@ using BrewMonster.Common;
using BrewMonster.Network;
using BrewMonster.Scripts;
using BrewMonster.Scripts.UI;
using BrewMonster.UI;
using CSNetwork.GPDataType;
using ModelRenderer.Scripts.GameData;
using PerfectWorld.Scripts.Managers;
@@ -16,7 +17,7 @@ using UnityEngine.UI;
namespace BrewMonster.Scripts.Managers
{
public class EC_InventoryUI : MonoBehaviour
public class EC_InventoryUI : AUIDialog
{
[Header("Pack Buttons (assign in Inspector)")]
[SerializeField] private List<Button> inventoryPackButtons = new List<Button>(); // byPackage: 0
@@ -435,6 +435,8 @@ namespace PerfectWorld.Scripts.Managers
return ByteToStringUtils.ByteArrayToCP936String(m_pDBEssence.file_matter);
}
// Get essence data
public IVTR_ESSENCE_PETEGG GetEssence() { return m_Essence; }
}
}
@@ -1618,6 +1618,13 @@ namespace CSNetwork.S2CCommand
{
public int[] cmdParams;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct CONTENTNPCSevHatchPet
{
public int iIvtrIdx;
public int idEgg;
};
}
// Player and NPC state
@@ -1066,5 +1066,20 @@ namespace CSNetwork.C2SCommand
}
return SerializeCommand(icmd, cmd, false);
}
public static Octets CreateNPCSevHatchPetCmd(int i_IvtrIdx, int i_idEgg)
{
var cmd = new cmd_sevnpc_serve
{
service_type = NPC_service_type.GP_NPCSEV_HATCHPET,
len = (uint)Marshal.SizeOf<CONTENTNPCSevHatchPet>()
};
CONTENTNPCSevHatchPet content = new CONTENTNPCSevHatchPet()
{
iIvtrIdx = i_IvtrIdx,
idEgg = i_idEgg,
};
return SerializeCommand(CommandID.SEVNPC_SERVE, cmd, content);
}
}
}
@@ -749,6 +749,7 @@ namespace CSNetwork
EC_ManMessage.PostMessage(EC_MsgDef.MSG_HST_CORRECTPOS, (int)MANAGER_INDEX.MAN_PLAYER, 0, pDataBuf,
pCmdHeader, iHostID);
break;
case CommandID.EMPTY_ITEM_SLOT:
case CommandID.OWN_ITEM_INFO:
EC_ManMessage.PostMessage(EC_MsgDef.MSG_HST_OWNITEMINFO, (int)MANAGER_INDEX.MAN_PLAYER, 0, pDataBuf,
pCmdHeader, iHostID);
@@ -1984,5 +1985,11 @@ namespace CSNetwork
gamedatasend.Data = C2SCommandFactory.CreateDebugCmd(icmd, param1);
SendProtocol(gamedatasend);
}
public void c2s_SendCmdNPCSevHatchPet(int iIvtrIdx, int idEgg)
{
gamedatasend gamedatasend = new gamedatasend();
gamedatasend.Data = C2SCommandFactory.CreateNPCSevHatchPetCmd(iIvtrIdx, idEgg);
SendProtocol(gamedatasend);
}
}
}
@@ -779,6 +779,10 @@ namespace BrewMonster.Network
{
Instance._gameSession.c2s_CmdDebug(icmd, param1);
}
public static void c2s_CmdNPCSevHatchPet(int iIvtrIdx, int idEgg)
{
Instance._gameSession.c2s_SendCmdNPCSevHatchPet(iIvtrIdx, idEgg);
}
}
/// <summary>
@@ -307,7 +307,7 @@ namespace BrewMonster.Scripts.Pet
m_iPetSlotNum = iNewNum;
}
// Check whether corral has empty slots
int GetEmptySlotNum()
public int GetEmptySlotNum()
{
int iCount = 0;
@@ -12,6 +12,7 @@ using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using static BrewMonster.Scripts.Managers.EC_Inventory;
namespace BrewMonster.UI
{
@@ -332,7 +333,8 @@ namespace BrewMonster.UI
detailedItem.GetDetailDataFromLocal();
}
EC_IvtrPetEgg petEgg = detailedItem as EC_IvtrPetEgg;
//EC_IvtrPetEgg petEgg = detailedItem as EC_IvtrPetEgg;
EC_IvtrPetEgg petEgg = item as EC_IvtrPetEgg;
if(petEgg == null)
{
return;
@@ -349,7 +351,7 @@ namespace BrewMonster.UI
m_pCurrentEgg = petEgg;
m_nSlot = slotIndex;
SetDataPtr(petEgg, "");
petEgg.Freeze(true);
UpdateEggUI(petEgg);
SetInventorySlotGray(btn, true);
@@ -522,7 +524,18 @@ namespace BrewMonster.UI
private void OnCommandConfirm()
{
//TODO: Send hatch command to server with m_pCurrentEgg
EC_IvtrItem pItem = (EC_IvtrItem)(GetDataPtr(""));
if (pItem != null)
{
pItem.Freeze(false);
GetHostPlayer().HatchPet(m_nSlot);
Debug.LogError("m_nSlot = " + m_nSlot);
SetDataPtr(null, "");
GetGameUIMan().EndNPCService();
Show(false);
GetGameUIMan().GetDialog("Win_Inventory").Show(false);
GetHostPlayer().GetPack(Inventory_type.IVTRTYPE_PACK).UnfreezeAllItems();
}
}
private void OnCommandCancel()
@@ -530,7 +543,7 @@ namespace BrewMonster.UI
ClearEgg();
GetGameUIMan().EndNPCService();
Show(false);
GetHostPlayer().GetPack(InventoryConst.IVTRTYPE_PACK).UnfreezeAllItems();
GetHostPlayer().GetPack(Inventory_type.IVTRTYPE_PACK).UnfreezeAllItems();
}
public void SetEgg(EC_IvtrItem pItem, int nSlot)
@@ -52,7 +52,11 @@ namespace BrewMonster
foreach (var it in items)
{
if (it != null && it.Slot >= 0 && it.Slot < size)
{
if (it.Content != null && it.Content.Length > 0)
it.SetItemInfo(it.Content, it.Content.Length);
inv.SetItem(it.Slot, it);
}
}
}
}
+49
View File
@@ -9,6 +9,9 @@ using System.Runtime.InteropServices;
using BrewMonster.Assets.PerfectWorld.Scripts.Players;
using UnityEngine;
using static BrewMonster.Scripts.Pet.CECPetData;
using BrewMonster.Scripts.Managers;
using static PerfectWorld.Scripts.Managers.EC_IvtrEquip;
using PerfectWorld.Scripts.Managers;
namespace BrewMonster
{
@@ -166,5 +169,51 @@ namespace BrewMonster
{
return m_pPetCorral;
}
// Hatch pet
public bool HatchPet(int iIvtrIdx)
{
EC_IvtrItem pItem = m_pPack.GetItem(iIvtrIdx);
if (pItem == null || pItem.GetClassID() != (int)EQUIP_CLASS_ID.ICID_PETEGG)
return false;
CECGameRun pGameRun = EC_Game.GetGameRun();
EC_IvtrPetEgg pEgg = (EC_IvtrPetEgg)pItem;
IVTR_ESSENCE_PETEGG e = pEgg.GetEssence();
// Check profession
if ((e.req_class & (1 << m_iProfession)) == 0)
{
pGameRun.AddFixedMessage((int)FixedMsg.FIXMSG_WRONGPROF);
return false;
}
// Check level
int iLevelReq = Math.Max((int)e.level, e.req_level);
if (GetMaxLevelSofar() < iLevelReq)
{
pGameRun.AddFixedMessage((int)FixedMsg.FIXMSG_LEVELTOOLOW);
return false;
}
// Check money
if (GetMoneyAmount() < pEgg.GetDBEssence().money_hatched)
{
pGameRun.AddFixedMessage((int)FixedMsg.FIXMSG_NEEDMONEY);
return false;
}
// Check whether pet corral is full
if (m_pPetCorral.GetEmptySlotNum() == 0)
{
pGameRun.AddFixedMessage((int)FixedMsg.FIXMSG_PET_CORRALFULL);
return false;
}
UnityGameSession.c2s_CmdNPCSevHatchPet(iIvtrIdx, pItem.GetTemplateID());
return true;
}
}
}