243 lines
6.4 KiB
C#
243 lines
6.4 KiB
C#
using BrewMonster.Network;
|
|
using BrewMonster.Scripts.Skills;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Unity.VisualScripting;
|
|
using static BrewMonster.SkillArrayWrapper;
|
|
using UnityEngine;
|
|
using BrewMonster.Scripts.Managers;
|
|
using UnityEditorInternal.Profiling.Memory.Experimental;
|
|
using BrewMonster.Scripts;
|
|
|
|
namespace BrewMonster
|
|
{
|
|
// Item shortcut class - represents a shortcut to an inventory item
|
|
public class CECSCItem : CECShortcut
|
|
{
|
|
private int m_iIvtr;
|
|
private int m_iSlot;
|
|
private int m_tidItem;
|
|
private string m_strIconFile;
|
|
private bool m_bAutoFind;
|
|
|
|
// Constructor
|
|
public CECSCItem() : base()
|
|
{
|
|
m_iSCType = (int)ShortcutType.SCT_ITEM;
|
|
m_iIvtr = 0;
|
|
m_iSlot = 0;
|
|
m_tidItem = 0;
|
|
m_strIconFile = "";
|
|
m_bAutoFind = false;
|
|
}
|
|
|
|
// Copy constructor
|
|
public CECSCItem(CECSCItem src) : base()
|
|
{
|
|
m_iSCType = (int)ShortcutType.SCT_ITEM;
|
|
m_iIvtr = src.m_iIvtr;
|
|
m_iSlot = src.m_iSlot;
|
|
m_tidItem = src.m_tidItem;
|
|
m_strIconFile = src.m_strIconFile;
|
|
m_bAutoFind = src.m_bAutoFind;
|
|
}
|
|
|
|
// Initialize object
|
|
public bool Init(int iIvtr, int iSlot, EC_IvtrItem pItem)
|
|
{
|
|
m_iIvtr = iIvtr;
|
|
m_iSlot = iSlot;
|
|
|
|
if (pItem != null)
|
|
{
|
|
m_tidItem = pItem.GetTemplateID();
|
|
m_strIconFile = pItem.GetIconFile();
|
|
}
|
|
else
|
|
{
|
|
m_tidItem = 0;
|
|
m_strIconFile = "";
|
|
}
|
|
return true;
|
|
}
|
|
|
|
// Clone this shortcut
|
|
public override CECShortcut Clone()
|
|
{
|
|
return new CECSCItem(this);
|
|
}
|
|
|
|
// Execute this shortcut - use the item
|
|
public override bool Execute()
|
|
{
|
|
CECHostPlayer pHost = EC_Game.GetGameRun()?.GetHostPlayer();
|
|
if(pHost == null)
|
|
return false;
|
|
|
|
EC_IvtrItem pItem = GetItem();
|
|
if (pItem == null)
|
|
{
|
|
if (m_bAutoFind)
|
|
{
|
|
if(!AutoFindItem())
|
|
return false;
|
|
|
|
pItem = GetItem();
|
|
if(pItem == null)
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
return pHost.UseItemInPack(m_iIvtr, m_iSlot);
|
|
}
|
|
|
|
public virtual string GetIconFile()
|
|
{
|
|
return m_strIconFile;
|
|
}
|
|
|
|
public virtual string GetDesc()
|
|
{
|
|
EC_IvtrItem pItem = GetItem();
|
|
if (pItem != null)
|
|
{
|
|
return pItem.GetDesc();
|
|
}
|
|
return "";
|
|
}
|
|
|
|
public virtual int GetCoolTime(ref int piMax)
|
|
{
|
|
EC_IvtrItem pItem = GetItem();
|
|
if (pItem != null)
|
|
{
|
|
int? maxNullable = null;
|
|
int result = pItem.GetCoolTime(out maxNullable);
|
|
piMax = maxNullable ?? 0;
|
|
return result;
|
|
}
|
|
|
|
piMax = 0;
|
|
return 0;
|
|
}
|
|
|
|
public int GetInventory()
|
|
{
|
|
return m_iIvtr;
|
|
}
|
|
|
|
public int GetIvtrSlot()
|
|
{
|
|
return m_iSlot;
|
|
}
|
|
|
|
public int GetItemTID()
|
|
{
|
|
return m_tidItem;
|
|
}
|
|
|
|
public void MoveItem(int iIvtr, int iSlot)
|
|
{
|
|
m_iIvtr = iIvtr;
|
|
m_iSlot = iSlot;
|
|
UpdateItemData();
|
|
}
|
|
|
|
public bool GetAutoFindFlag()
|
|
{
|
|
return m_bAutoFind;
|
|
}
|
|
|
|
public void SetAutoFindFlag(bool bAutoFind)
|
|
{
|
|
m_bAutoFind = bAutoFind;
|
|
}
|
|
|
|
// Update item associated data after m_iIvtr or m_iSlot changed
|
|
private void UpdateItemData()
|
|
{
|
|
EC_IvtrItem pItem = GetItem();
|
|
if (pItem != null)
|
|
{
|
|
m_tidItem = pItem.GetTemplateID();
|
|
m_strIconFile = pItem.GetIconFile();
|
|
}
|
|
else
|
|
{
|
|
m_tidItem = 0;
|
|
m_strIconFile = "";
|
|
}
|
|
}
|
|
|
|
// Auto find item in all inventory slots by template ID
|
|
private bool AutoFindItem()
|
|
{
|
|
if(m_tidItem == 0)
|
|
return false;
|
|
|
|
CECHostPlayer pHost = EC_Game.GetGameRun()?.GetHostPlayer();
|
|
if(pHost == null)
|
|
return false;
|
|
|
|
EC_Inventory pPack = pHost.GetPack(EC_Inventory.Inventory_type.IVTRTYPE_PACK);
|
|
if (pPack != null)
|
|
{
|
|
int iSlot = pPack.FindItem(m_tidItem);
|
|
if (iSlot >= 0)
|
|
{
|
|
m_iIvtr = EC_Inventory.Inventory_type.IVTRTYPE_PACK;
|
|
m_iSlot = iSlot;
|
|
UpdateItemData();
|
|
return true;
|
|
}
|
|
}
|
|
|
|
EC_Inventory pEquipPack = pHost.GetPack(EC_Inventory.Inventory_type.IVTRTYPE_EQUIPPACK);
|
|
if (pEquipPack != null)
|
|
{
|
|
int iSlot = pPack.FindItem(m_tidItem);
|
|
if (iSlot >= 0)
|
|
{
|
|
m_iIvtr = InventoryConst.IVTRTYPE_EQUIPPACK;
|
|
m_iSlot = iSlot;
|
|
UpdateItemData();
|
|
return true;
|
|
}
|
|
}
|
|
|
|
EC_Inventory pTaskPack = pHost.GetPack(EC_Inventory.Inventory_type.IVTRTYPE_TASKPACK);
|
|
if (pTaskPack != null)
|
|
{
|
|
int iSlot = pPack.FindItem(m_tidItem);
|
|
if (iSlot >= 0)
|
|
{
|
|
m_iIvtr = InventoryConst.IVTRTYPE_TASKPACK;
|
|
m_iSlot = iSlot;
|
|
UpdateItemData();
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private EC_IvtrItem GetItem()
|
|
{
|
|
CECHostPlayer pHost = EC_Game.GetGameRun()?.GetHostPlayer();
|
|
if(pHost == null)
|
|
return null;
|
|
|
|
EC_Inventory pIvtr = pHost.GetPack(m_iIvtr);
|
|
if (pIvtr == null)
|
|
return null;
|
|
|
|
return pIvtr.GetItem(m_iSlot);
|
|
}
|
|
}
|
|
}
|