コード例 #1
0
        private void LeftClickItemIcon(object[] eventParams)
        {
            Debug.Assert(eventParams.Length == 1 && eventParams[0] is ItemIcon);
            ItemIcon     itemIcon     = (ItemIcon)eventParams[0];
            SlotPosition slotPosition = itemIcon.Position;
            IPickupable  pickupable   = itemIcon.Item as IPickupable;
            IEquipable   equipable    = itemIcon.Item as IEquipable;

            if (_airItem.IsEmpty)
            {
                if (itemIcon.IsEquipmentIcon)
                {
                    equipable.OnUnequip(_equipment, _stats);
                }
                else if (itemIcon.Item is IStackable)
                {
                    EventManager.TriggerEvent(EventName.OPEN_SPLIT_SCREEN, eventParams);
                    return;
                }
                else
                {
                    pickupable.OnRemoveFromInventory(_inventory, slotPosition);
                }
                pickupable.OnPutInAir(_airItem, slotPosition);
            }
            else
            {
                IPickupable pickupableAir = _airItem.Item as IPickupable;
                if (slotPosition.RowIndex == EquipmentSlot.EQUIPMENT_SLOT_ROW_INDEX)
                {
                    IEquipable equipableAir = _airItem.Item as IEquipable;
                    if (equipableAir == null)
                    {
                        Debug.Log("Not equipable");
                        return;
                    }
                    if ((Equipment.EquipmentType)slotPosition.SlotIndex != equipableAir.EquipmentType)
                    {
                        Debug.Log("Not the same equipment type");
                        return;
                    }
                    if (equipable.IsDurable == false)
                    {
                        Debug.Log("Not durable");
                    }
                    equipable.OnUnequip(_equipment, _stats);
                    pickupableAir.OnRemoveFromAir(_airItem);
                    equipableAir.OnEquip(_equipment, _stats);
                    pickupable.OnPutInAir(_airItem, slotPosition);
                }
                else
                {
                    pickupable.OnRemoveFromInventory(_inventory, slotPosition);
                    pickupableAir.OnRemoveFromAir(_airItem);
                    pickupableAir.OnPutInInventory(_inventory, slotPosition);
                    pickupable.OnPutInAir(_airItem, slotPosition);
                }
            }
        }
コード例 #2
0
        public void RemoveItem(SlotPosition slotPosition)
        {
            _rows[slotPosition.RowIndex].RemoveItem(slotPosition.SlotIndex);
            UpdateCapacity();

            EventManager.TriggerEvent(EventName.UPDATE_INVENTORY);

            Debug.Log(this.ToString());
        }
コード例 #3
0
        public void AddItem(Item item, SlotPosition slotPosition)
        {
            Debug.Assert(item is IPickupable);

            _item             = item;
            _originalPosition = slotPosition;

            EventManager.TriggerEvent(EventName.UPDATE_AIR_ITEM);

            Debug.Log(this.ToString());
        }
コード例 #4
0
        public void SplitItem(SlotPosition slotPosition, int splitCount)
        {
            IStackable stackable = GetItem(slotPosition) as IStackable;

            Debug.Assert(stackable != null);
            stackable.Count -= splitCount;
            UpdateCapacity();

            EventManager.TriggerEvent(EventName.UPDATE_INVENTORY);

            Debug.Log(this.ToString());
        }
コード例 #5
0
        private void TryStackItem(Item item, SlotPosition slotPosition)
        {
            Item       itemInventory      = GetItem(slotPosition);
            IStackable stackableInventory = itemInventory as IStackable;
            IStackable stackable          = item as IStackable;

            if (stackableInventory != null && itemInventory.Name == item.Name)
            {
                int availableStackCount = Mathf.Min(stackable.Count, stackableInventory.StackLimit - stackableInventory.Count);
                stackableInventory.Count += availableStackCount;
                stackable.Count          -= availableStackCount;
            }
        }
コード例 #6
0
        private void DropItem(object[] eventParams)
        {
            Debug.Assert(eventParams.Length == 1 && eventParams[0] is ItemIcon);
            ItemIcon     itemIcon     = (ItemIcon)eventParams[0];
            SlotPosition slotPosition = itemIcon.Position;
            IPickupable  pickupable   = itemIcon.Item as IPickupable;
            IEquipable   equipable    = itemIcon.Item as IEquipable;

            if (slotPosition.RowIndex == EquipmentSlot.EQUIPMENT_SLOT_ROW_INDEX)
            {
                equipable.OnUnequip(_equipment, _stats);
            }
            else
            {
                pickupable.OnRemoveFromInventory(_inventory, itemIcon.Position);
            }
            pickupable.OnPutOnGround(transform.position);
        }
コード例 #7
0
        private void ReturnAirItem(object[] eventParams)
        {
            if (_airItem.IsEmpty)
            {
                return;
            }

            SlotPosition originalPosition = _airItem.OriginalPosition;
            Item         itemAir          = _airItem.Item;
            IPickupable  pickupableAir    = itemAir as IPickupable;
            IEquipable   equipableAir     = itemAir as IEquipable;
            IStackable   stackableAir     = itemAir as IStackable;

            pickupableAir.OnRemoveFromAir(_airItem);

            if (originalPosition.RowIndex == EquipmentSlot.EQUIPMENT_SLOT_ROW_INDEX)
            {
                Equipment.EquipmentType equipmentType = (Equipment.EquipmentType)originalPosition.SlotIndex;

                if (_equipment.EquipmentTable[equipmentType].IsEmpty)
                {
                    equipableAir.OnEquip(_equipment, _stats);
                }
                else
                {
                    pickupableAir.OnPutInInventory(_inventory);
                }
            }
            else
            {
                if (stackableAir != null)
                {
                    stackableAir.OnStack(_inventory, originalPosition);
                }
                else if (_inventory.IsItemEmpty(originalPosition))
                {
                    pickupableAir.OnPutInInventory(_inventory, originalPosition);
                }
                else
                {
                    pickupableAir.OnPutInInventory(_inventory);
                }
            }
        }
コード例 #8
0
        public void ConsumeItem(SlotPosition slotPosition)
        {
            Item        item       = GetItem(slotPosition);
            IPickupable pickupable = item as IPickupable;
            IStackable  stackable  = item as IStackable;

            if (stackable != null)
            {
                stackable.Count -= 1;
            }
            if (stackable == null || stackable.Count == 0)
            {
                pickupable.OnRemoveFromInventory(this, slotPosition);
            }
            UpdateCapacity();

            EventManager.TriggerEvent(EventName.UPDATE_INVENTORY);

            Debug.Log(this.ToString());
        }
コード例 #9
0
        private void LeftClickItemSlot(object[] eventParams)
        {
            Debug.Assert(eventParams.Length == 1 && eventParams[0] is SlotPosition);
            SlotPosition slotPosition = (SlotPosition)eventParams[0];

            if (_airItem.IsEmpty)
            {
                return;
            }

            IPickupable pickupable = _airItem.Item as IPickupable;

            if (slotPosition.RowIndex == EquipmentSlot.EQUIPMENT_SLOT_ROW_INDEX)
            {
                IEquipable equipable = _airItem.Item as IEquipable;
                if (equipable == null)
                {
                    Debug.Log("Not equipable");
                    return;
                }
                if ((Equipment.EquipmentType)slotPosition.SlotIndex != equipable.EquipmentType)
                {
                    Debug.Log("Not the same equipment type");
                    return;
                }
                if (equipable.IsDurable == false)
                {
                    Debug.Log("Not durable");
                }
                pickupable.OnRemoveFromAir(_airItem);
                equipable.OnEquip(_equipment, _stats);
            }
            else
            {
                pickupable.OnRemoveFromAir(_airItem);
                pickupable.OnPutInInventory(_inventory, slotPosition);
            }
        }
コード例 #10
0
        private void SplitStackableItem(object[] eventParams)
        {
            Debug.Assert(eventParams.Length == 2 && eventParams[0] is ItemIcon && eventParams[1] is int);
            ItemIcon     itemIcon     = (ItemIcon)eventParams[0];
            int          splitCount   = (int)eventParams[1];
            Item         item         = itemIcon.Item;
            SlotPosition slotPosition = itemIcon.Position;
            IStackable   stackable    = (IStackable)item;

            if (splitCount == stackable.Count)
            {
                IPickupable pickupable = (IPickupable)item;
                pickupable.OnRemoveFromInventory(_inventory, slotPosition);
                pickupable.OnPutInAir(_airItem, slotPosition);
            }
            else
            {
                Item splitItem = item.Copy();
                ((IStackable)splitItem).Count = splitCount;
                ((IPickupable)splitItem).OnPutInAir(_airItem, slotPosition);
                stackable.OnSplit(_inventory, slotPosition, splitCount);
            }
        }
コード例 #11
0
        public void AddItem(Item item, SlotPosition?slotPosition = null)
        {
            Debug.Assert(item is IPickupable);

            if (slotPosition == null)
            {
                if (IsFull)
                {
                    AddRows();
                }
                _rows[GetAvailableRowIndex()].AddItem(item);
            }
            else
            {
                SlotPosition position = slotPosition.GetValueOrDefault();
                AddRows(position.RowIndex - RowCount + 1);
                _rows[position.RowIndex].AddItem(item, position.SlotIndex);
            }

            EventManager.TriggerEvent(EventName.UPDATE_INVENTORY);

            Debug.Log(this.ToString());
        }
コード例 #12
0
 public void OnConsume(InventoryController playerInventory, AttributeController playerStats, SlotPosition slotPosition)
 {
     Debug.Log("Consume " + Name);
     playerInventory.ConsumeItem(slotPosition);
     ApplyBuff(playerStats);
 }
コード例 #13
0
 public void OnPutInAir(AirItemController playerAirItem, SlotPosition slotPosition)
 {
     Debug.Log("PutInAir " + Name);
     playerAirItem.AddItem(Copy(), slotPosition);
 }
コード例 #14
0
 public void OnRemoveFromInventory(InventoryController playerInventory, SlotPosition slotPosition)
 {
     Debug.Log("RemoveFromInventory " + Name);
     playerInventory.RemoveItem(slotPosition);
 }
コード例 #15
0
 public void OnSplit(InventoryController playerInventory, SlotPosition slotPosition, int splitCount)
 {
     Debug.Log("Split " + Name);
     playerInventory.SplitItem(slotPosition, splitCount);
 }
コード例 #16
0
 public void SetPosition(SlotPosition slotPosition)
 {
     _position = slotPosition;
 }
コード例 #17
0
 public Item GetItem(SlotPosition slotPosition)
 {
     Debug.Assert(slotPosition.RowIndex < RowCount && slotPosition.SlotIndex < InventoryRow.NUMBER_SLOTS);
     return(_rows[slotPosition.RowIndex].GetItem(slotPosition.SlotIndex));
 }
コード例 #18
0
 public bool IsItemEmpty(SlotPosition slotPosition)
 {
     return(slotPosition.RowIndex >= RowCount || _rows[slotPosition.RowIndex].IsItemEmpty(slotPosition.SlotIndex));
 }