示例#1
0
 public GameObject GetLootDropObject(Components.ItemName item)
 {
     Debug.Log("Loot: " + item.ToString());
     dropLoot.transform.GetChild(0).GetComponent <SpriteRenderer>().sprite = iconMap[item];
     dropLoot.GetComponent <AddToInventory>().itemName = item;
     return(dropLoot);
 }
示例#2
0
    private void AddNewLoot(Components.ItemName item)
    {
        GameObject newLoot = Instantiate(itemLootSlot, lootPanel.transform);

        newLoot.transform.GetChild(0).GetComponent <Image>().sprite = iconMap[item];
        newLoot.GetComponentInChildren <Text>().text = "1";
    }
    public void PutIntoWorkshopInventory()
    {
        bool       updated  = false;
        GameObject heldItem = ItemDragHandler.heldItem;

        Components.ItemName heldItemName = heldItem.GetComponent <WorkshopShipComponent>().itemName;
        foreach (Transform itemSlot in transform)
        {
            WorkshopShipComponent component = itemSlot.GetComponentInChildren <WorkshopShipComponent>();
            if (component != null && component.itemName.Equals(heldItemName))
            {
                int quantity = int.Parse(itemSlot.GetComponentInChildren <Text>().text) + 1;
                itemSlot.GetComponentInChildren <Text>().text = quantity.ToString();
                Destroy(heldItem);
                updated = true;
                break;
            }
        }

        if (!updated)
        {
            foreach (Transform itemSlot in transform)
            {
                WorkshopShipComponent component = itemSlot.GetComponentInChildren <WorkshopShipComponent>();
                if (component == null)
                {
                    heldItem.transform.SetParent(itemSlot);
                    heldItem.transform.localPosition = Vector3.zero;
                    heldItem.GetComponent <CanvasGroup>().blocksRaycasts = true;
                    itemSlot.GetComponentInChildren <Text>().text        = "1";
                    break;
                }
            }
        }
    }
示例#4
0
 public void RemoveFromWorkshopInventory(Components.ItemName item, int quantity)
 {
     if (workshopInventory[item] > 1)
     {
         workshopInventory[item] -= quantity;
     }
     else
     {
         workshopInventory.Remove(item);
     }
 }
示例#5
0
 public void UninstallComponent(Components.ItemName item)
 {
     if (installedComponents[item] > 1)
     {
         installedComponents[item]--;
     }
     else
     {
         installedComponents.Remove(item);
     }
     AddToWorkshopInventory(item, 1);
 }
示例#6
0
    public void AddToWorkshopInventory(Components.ItemName item, int quantity)
    {
        int result;

        if (workshopInventory.TryGetValue(item, out result))
        {
            result += quantity;
        }
        else
        {
            workshopInventory.Add(item, quantity);
        }
    }
示例#7
0
    public void AddToCargo(Components.ItemName item)
    {
        int result;

        if (cargo.TryGetValue(item, out result))
        {
            cargo[item] = ++result;
        }
        else
        {
            cargo.Add(item, 1);
        }
    }
示例#8
0
    public void InstallComponent(Components.ItemName item)
    {
        int quantity;

        if (installedComponents.TryGetValue(item, out quantity))
        {
            installedComponents[item]++;
        }
        else
        {
            installedComponents.Add(item, 1);
        }
        RemoveFromWorkshopInventory(item, 1);
    }
示例#9
0
    public void UpdateLoot(Components.ItemName item)
    {
        int index;

        if (lootMap.TryGetValue(item, out index))
        {
            UpdateExistingLoot(index);
        }
        else
        {
            AddNewLoot(item);
            lootMap.Add(item, nextIndex);
            nextIndex++;
        }
    }
示例#10
0
    public void DropLoot()
    {
        Transform transform = GetComponent <Transform>();
        int       lootIndex = UnityEngine.Random.Range(0, loots.Count);
        float     dice      = UnityEngine.Random.Range(0, 100f);
        float     chance    = loots[lootIndex].chance;

        chance = chance > 1 ? chance : chance * 100;
        if (dice <= chance)
        {
            Components.ItemName itemName = loots[lootIndex].item;
            GameObject          dropLoot = levelUi.GetLootDropObject(itemName);
            Instantiate(dropLoot, transform.position, Quaternion.identity);
        }
    }
 public void OnDrop(PointerEventData eventData)
 {
     if (!Item)
     {
         GameObject          heldItem     = ItemDragHandler.heldItem;
         Components.ItemName heldItemName = heldItem.GetComponent <WorkshopShipComponent>().itemName;
         if (installableItems.Contains(heldItemName))
         {
             heldItem.transform.SetParent(transform);
             Item.transform.localPosition = Vector3.zero;
             inventory.InstallComponent(heldItemName);
             installedItem = heldItem.GetComponent <WorkshopShipComponent>();
         }
     }
 }