public void Equip()
    {
        Debug.Log("tryimg to equip item");
        if (info.type == InventoryItem.Type.NonEquippable)
        {
            Debug.Log("Item cant be equipped!"); return;
        }

        int equipmentSlotIndex = GetEquipmentSlotIndex();

        InventoryItemObject equippedItem = PlayerSaveData.reference.trainData.equippedItems [equipmentSlotIndex];

        if (equippedItem != null)
        {
            if (GetLastSlot() != null)
            {
                Transform potentialSlot = InventorySystem.reference.FindEmptySlot(this, InventorySystem.SlotType.Wagon);
                if (potentialSlot != null)
                {
                    equippedItem.Place(potentialSlot);
                }
                else
                {
                    equippedItem.Place(GetLastSlot());
                }
            }
        }

        RemoveStats();
        PlayerSaveData.reference.trainData.equippedItems[equipmentSlotIndex] = this;
        ApplyStats();

        if (info.bonusInfo.equipmentDurability == 0)
        {
            info.durabilityInfo.max     *= (100 + PlayerSaveData.reference.trainData.bonusEquipmentDurability) / 100;
            info.durabilityInfo.current *= (100 + PlayerSaveData.reference.trainData.bonusEquipmentDurability) / 100;
        }
    }
Пример #2
0
    public void InitItem(GameObject item)
    {
        InventoryItemObject itemObject = item.GetComponent <InventoryItemObject>();
        Transform           slot       = null;

        foreach (SlotInfo info in slots)
        {
            if (info.type == itemObject.info.type)
            {
                slot = info.slot;
            }
        }
        if (slot == null)
        {
            Debug.Log("wrong item to init!");
            return;
        }
        itemObject.Place(slot);
    }