Exemplo n.º 1
0
 /// <summary>
 /// 从包裹里面查询是否有某个物品
 /// 返回-1表示没有
 /// </summary>
 public int find(TezComData gameObject)
 {
     return(m_Slots.FindIndex((TezInventoryItemSlot slot) =>
     {
         return slot.item == gameObject;
     }));
 }
Exemplo n.º 2
0
        private TezInventoryItemSlot findSlotStackable(TezComData gameObject)
        {
            TezInventoryItemSlot result_slot = null;

            int result_index = 0;

            while (result_index < m_Slots.Count)
            {
                var slot = m_Slots[result_index];
                ///找空格子
                if (result_slot == null && slot.item == null)
                {
                    result_slot = slot;
                }

                ///找相同格子
                ///可堆叠的物品
                ///他们的模板相同
                if (slot.item != null && slot.item.templateAs(gameObject))
                {
                    result_slot = slot;
                    break;
                }

                result_index++;
            }

            return(result_slot);
        }
Exemplo n.º 3
0
        public void store(int slotIndex, TezComData gameObject, int count)
        {
            var slot = m_Slots[slotIndex];

            slot.item   = gameObject;
            slot.count += count;

            onItemAdded?.Invoke(slot);
        }
Exemplo n.º 4
0
        public bool store(TezComData gameObject, int count)
        {
            if (m_Inventory.tryGet(out var inventory))
            {
                inventory.store(gameObject, count);
                return(true);
            }

            return(false);
        }
Exemplo n.º 5
0
        public bool take(TezComData gameObject, int count)
        {
            if (m_Inventory.tryGet(out var inventory))
            {
                var index = inventory.find(gameObject);
                if (index > 0)
                {
                    inventory.take(index, count);
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 堆叠型加入
        /// </summary>
        public void store(TezComData gameObject, int count)
        {
            var stack_max_count = TezDatabaseItemConfig.getConfig(gameObject.category).stackCount;
            TezInventoryItemSlot result_slot = this.findSlotStackable(gameObject);

            ///找到空格子
            if (result_slot != null)
            {
                if (result_slot.item != null)
                {
                    result_slot.count += count;
                    var remain = result_slot.count - stack_max_count;
                    if (remain > 0)
                    {
                        result_slot.count = stack_max_count;
                        this.store(gameObject, remain);
                    }
                    else
                    {
                        gameObject.close();
                    }
                }
                else
                {
                    result_slot.item = gameObject;
                    if (count > stack_max_count)
                    {
                        result_slot.count = stack_max_count;
                        this.store(gameObject, count - stack_max_count);
                    }
                    else
                    {
                        result_slot.count = count;
                    }
                }
            }
            ///没有找到空格子
            else
            {
                result_slot       = this.createItemSlot();
                result_slot.item  = gameObject;
                result_slot.count = count;
                result_slot.index = m_Slots.Count;

                m_Slots.Add(result_slot);
            }

            onItemAdded?.Invoke(result_slot);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 存入
        /// 不允许堆叠
        /// </summary>
        public void store(TezComData gameObject)
        {
            TezInventoryItemSlot result_slot = this.findSlotUnstackable();

            ///找到空格子
            if (result_slot != null)
            {
                result_slot.item  = gameObject;
                result_slot.count = -1;
            }
            ///没有找到空格子
            else
            {
                result_slot       = this.createItemSlot();
                result_slot.item  = gameObject;
                result_slot.count = -1;
                result_slot.index = m_Slots.Count;

                m_Slots.Add(result_slot);
            }

            onItemAdded?.Invoke(result_slot);
        }
Exemplo n.º 8
0
 /// <summary>
 /// 存入
 /// </summary>
 public void store(TezComData item, int count)
 {
     m_Inventory.store(this.index, item, count);
 }
Exemplo n.º 9
0
        public void saveItem(TezComData my_object)
        {
//            var ruid = my_object.GUID;
        }
Exemplo n.º 10
0
 public override bool calculate(TezComData gameObject)
 {
     return(true);
 }
Exemplo n.º 11
0
 public abstract bool calculate(TezComData gameObject);
Exemplo n.º 12
0
 public override bool calculate(TezComData gameObject)
 {
     return(m_Function(gameObject));
 }