Пример #1
0
    public override SummarizedItem Summarize()
    {
        SummarizedItem sumItem = base.Summarize();

        sumItem.derivatedType = (int)type;
        return(sumItem);
    }
Пример #2
0
    private Item GetItem(SummarizedItem si)
    {
        switch (si.itemType)
        {
        case Item.ItemType.Backpack:
            return(Arsenal.Instance.Get((BackpackItem.Type)si.derivatedType, false));

        case Item.ItemType.Body:
            return(Arsenal.Instance.Get((BodyItem.Type)si.derivatedType, false, false));

        case Item.ItemType.Head:
            return(Arsenal.Instance.Get((HeadItem.Type)si.derivatedType, false));

        case Item.ItemType.Horse:
            return(Arsenal.Instance.Get((HorseItem.Type)si.derivatedType, false));

        case Item.ItemType.Resource:
            return(ResourceDictionary.instance.GetResourceItem((InteractionType.Type)si.derivatedType));

        case Item.ItemType.Second:
            return(Arsenal.Instance.Get((SecondItem.Type)si.derivatedType, false));

        case Item.ItemType.Shield:
            return(Arsenal.Instance.Get((ShieldItem.Type)si.derivatedType, false));

        case Item.ItemType.Weapon:
            return(Arsenal.Instance.Get((WeaponItem.Type)si.derivatedType, false));

        default:
            Debug.LogError("Unsuported Item type : " + si.itemType.ToString());
            return(null);
        }
    }
Пример #3
0
    private GameObject InstanciatePickable(SummarizedItem si)
    {
        switch (si.itemType)
        {
        case Item.ItemType.Backpack:
            return(Arsenal.Instance.GetPickable((BackpackItem.Type)si.derivatedType));

        case Item.ItemType.Body:
            return(Arsenal.Instance.GetPickable((BodyItem.Type)si.derivatedType, false));

        case Item.ItemType.Head:
            return(Arsenal.Instance.GetPickable((HeadItem.Type)si.derivatedType));

        case Item.ItemType.Horse:
            return(Arsenal.Instance.GetPickable((HorseItem.Type)si.derivatedType));

        case Item.ItemType.Second:
            return(Arsenal.Instance.GetPickable((SecondItem.Type)si.derivatedType));

        case Item.ItemType.Shield:
            return(Arsenal.Instance.GetPickable((ShieldItem.Type)si.derivatedType));

        case Item.ItemType.Weapon:
            return(Arsenal.Instance.GetPickable((WeaponItem.Type)si.derivatedType));

        default:
            Debug.LogError("Unsuported Item type : " + si.itemType.ToString());
            return(null);
        }
    }
Пример #4
0
    public override SummarizedItem Summarize()
    {
        SummarizedItem sumItem = base.Summarize();

        sumItem.derivatedType = (int)resource.interactionType;
        return(sumItem);
    }
Пример #5
0
    private void Update()
    {
        if (Input.GetMouseButton(0) && hoveredForgeItem != null && validationTime < forgeValidationDuration && enoughResources)
        {
            validationSlider.gameObject.SetActive(true);
            validationTime += Time.deltaTime;
            if (validationTime >= forgeValidationDuration)
            {
                foreach (KeyValuePair <SummarizedItem, int> entry in hoveredForgeItem.cost)
                {
                    PlayerController.MainInstance.inventory.RemoveItem(entry.Key, entry.Value, true);
                }
                PlayerController.MainInstance.inventory.AddItem(hoveredForgeItem.summarizedItem, 1);
                lastCraftedItem = hoveredForgeItem.summarizedItem;
                onCraftedItem.Invoke();

                enoughResources = HasEnoughResources(hoveredForgeItem);
                enoughResourceMessage.SetActive(!enoughResources);
            }
            validationSlider.value = Mathf.Clamp(validationTime / forgeValidationDuration, 0f, 1f);
        }
        else
        {
            validationSlider.gameObject.SetActive(false);
            validationTime = 0f;
        }
        if (Input.GetMouseButton(0))
        {
            validationSlider.transform.position = Input.mousePosition;
        }
    }
Пример #6
0
 private void AssignBasics(ForgeItem forgeItem, Item baseItem, SummarizedItem summarized)
 {
     forgeItem.itemName.text  = baseItem.itemName;
     forgeItem.icon           = baseItem.itemIcon;
     forgeItem.description    = baseItem.description;
     forgeItem.summarizedItem = summarized;
 }
Пример #7
0
    public virtual SummarizedItem Summarize()
    {
        SummarizedItem sumItem = new SummarizedItem();

        sumItem.itemType      = itemType;
        sumItem.load          = load;
        sumItem.derivatedType = -1;
        return(sumItem);
    }
Пример #8
0
    public void AddItem(Item item, int count)
    {
        if (!item)
        {
            return;
        }

        SummarizedItem si = item.Summarize();

        AddItem(si, count);
    }
Пример #9
0
    public int TryAddItem(SummarizedItem si, int count)
    {
        int maxTransfert = (int)((capacity - load) / si.load);
        int transfert    = Mathf.Min(maxTransfert, count);

        if (transfert > 0)
        {
            AddItem(si, transfert);
        }
        return(transfert > 0 ? transfert : 0);
    }
Пример #10
0
 public void AddItem(SummarizedItem si, int count)
 {
     if (!inventory.ContainsKey(si))
     {
         inventory.Add(si, count);
     }
     else
     {
         inventory[si] += count;
     }
     UpdateContent();
 }
Пример #11
0
 public void RemoveItem(SummarizedItem si, int resourceCount, bool forceUpdate = true)
 {
     if (inventory.ContainsKey(si))
     {
         inventory[si] = Mathf.Max(0, inventory[si] - resourceCount);
         if (inventory[si] <= 0)
         {
             inventory.Remove(si);
         }
     }
     if (forceUpdate)
     {
         UpdateContent();
     }
 }
Пример #12
0
 private bool IsDefault(SummarizedItem si)
 {
     if (si.itemType == Item.ItemType.Body && si.derivatedType == (int)BodyItem.defaultType)
     {
         return(true);
     }
     else if (si.itemType == Item.ItemType.Head && si.derivatedType == (int)HeadItem.defaultType)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Пример #13
0
    public static InteractionType.Type GetPickableInteraction(SummarizedItem item)
    {
        switch (item.itemType)
        {
        case ItemType.Weapon: return(InteractionType.Type.pickableWeapon);

        case ItemType.Backpack: return(InteractionType.Type.pickableBackpack);

        case ItemType.Shield: return(InteractionType.Type.pickableShield);

        case ItemType.Second: return(InteractionType.Type.pickableSecond);

        case ItemType.Head: return(InteractionType.Type.pickableHead);

        default: return(InteractionType.Type.none);
        }
    }
Пример #14
0
    public void OnResourceClick(ResourceIcon icon)
    {
        if (icon.data && (Input.GetMouseButtonUp(0) || Input.GetMouseButtonUp(1)))
        {
            string         resourceName   = icon.data.name;
            SummarizedItem si             = ResourceDictionary.instance.GetResourceItem(icon.data.interactionType).Summarize();
            int            transfertCount = Input.GetMouseButtonUp(0) ? 1 : 10;
            transfertCount = Mathf.Min(transfertCount, interactionUI.resourceContainer.inventory[resourceName]);
            transfertCount = inventory.TryAddItem(si, transfertCount);

            if (transfertCount > 0)
            {
                interactionUI.resourceContainer.RemoveItem(resourceName, transfertCount);
            }
            else
            {
                PlayerController.MainInstance.interactionController.ThrowHelp("Container", "full");
            }
        }
    }
Пример #15
0
    public void RemoveItem(Item item, int resourceCount, bool forceUpdate = true)
    {
        SummarizedItem si = item.Summarize();

        RemoveItem(si, resourceCount, forceUpdate);
    }