void UpdateUI(ResourceType resourceType, bool interactable)
    {
        switch (mode)
        {
        case Mode.Merchant:
            resourceViewers[(int)resourceType].Setup(activeShipInventory.GetResource(resourceType), interactable, myHarbor.GetResourceValue(resourceType));
            break;

        case Mode.Boarding:
            resourceViewers[(int)resourceType].Setup(activeShipInventory.GetResource(resourceType), interactable, ResourceInventory.GetDefaultValue(resourceType));
            break;
        }
        SetTexts();
    }
Exemple #2
0
 protected override bool ActivateCondition(ToolController owner, GameObject target)
 {
     if (target == null)
     {
         return(false);
     }
     if (target.GetComponentInParent <HealthComponent>() == null && inventoryComponent.GetResource(RepairNaniteResource) < NanitesPerCycle)
     {
         Debug.Log("Target in LoopCondition() returned null");
         var popTxt = Instantiate(popText);
         popTxt.GetComponentInChildren <TextMeshProUGUI>().SetText("Cannot repair!");
         return(false);
     }
     return(true);
 }
Exemple #3
0
    void Awake()
    {
        if (UIRoot.GetPlayer() != null)
        {
            playerInventory = UIRoot.GetPlayer().GetComponent <ResourceInventory>();

            AddNewText("Select resource from dropdown to add 50 of that resource");

            var resourceDropDown = Instantiate(DropDown);
            resourceDropDown.transform.SetParent(vLayoutGroup.transform);

            foreach (var resource in resourceList)
            {
                resourceNamesList.Add(resource.DisplayName);

                if (resource.DisplayName == "Thruster Fuel")
                {
                    fuel = resource;
                }
            }

            resourceDropDown.options.Clear();

            resourceDropDown.AddOptions(resourceNamesList);
            resourceDropDown.onValueChanged.AddListener(evt =>
            {
                playerInventory.TryAdd(resourceList[resourceDropDown.value], 50);
            });

            AddNewButton("Kill Octo", () => { playerInventory.SetResource(fuel, 0f); });

            fuelStat = AddNewText("Fuel Stat: " + playerInventory.GetResource(fuel));
        }
    }
Exemple #4
0
 private void Update()
 {
     if (UIRoot.GetPlayer() != null)
     {
         fuelStat.GetComponent <TextMeshProUGUI>().SetText("Fuel Stat: " + playerInventory.GetResource(fuel));
     }
 }
    public bool CanCraftSatellite(ResourceInventory ResourceInv, InventoryController SourceInv, SatelliteInventory TargetInv, SatelliteRecipe CraftRecipe)
    {
        if (SourceInv == null || TargetInv == null || ResourceInv == null || TargetInv == null)
        {
            Debug.LogError(SourceInv);
            Debug.LogError(TargetInv);
            Debug.LogError(ResourceInv);
            return(false);
        }
        foreach (var itemIn in CraftRecipe.ItemInput)
        {
            if (SourceInv.GetItemAmount(itemIn.item) < itemIn.amount)
            {
                return(false);
            }
        }

        foreach (var resIn in CraftRecipe.ResourceInput)
        {
            if (ResourceInv.GetResource(resIn.resource) < resIn.amount)
            {
                return(false);
            }
        }

        if (CraftRecipe.CreatesByProducts)
        {
            foreach (var resOut in CraftRecipe.ResourceByProducts)
            {
                if (ResourceInv.GetResource(resOut.resource) + resOut.amount > resOut.resource.GetMaximum())
                {
                    return(false);                                                                                         //holy crap this is a kludge. TODO: Fix this
                }
            }
        }

        if (TargetInv.StoredSatellites.Count != 0 && TargetInv.StoredSatellites[0] != null)
        {
            return(false);
        }
        return(true);
    }
    public bool CanCraft(ResourceInventory ResourceInv, InventoryController SourceInv, InventoryController TargetInv, Recipe CraftRecipe)
    {
        if (SourceInv == null || TargetInv == null || ResourceInv == null)
        {
            Debug.LogError(SourceInv);
            Debug.LogError(TargetInv);
            Debug.LogError(ResourceInv);
            return(false);
        }
        foreach (var itemIn in CraftRecipe.ItemInput)
        {
            if (SourceInv.GetItemAmount(itemIn.item) < itemIn.amount)
            {
                return(false);
            }
        }

        foreach (var resIn in CraftRecipe.ResourceInput)
        {
            if (ResourceInv.GetResource(resIn.resource) < resIn.amount)
            {
                return(false);
            }
        }

        if (CraftRecipe.CreatesByProducts)
        {
            foreach (var resOut in CraftRecipe.ResourceByProducts)
            {
                if (ResourceInv.GetResource(resOut.resource) + resOut.amount > resOut.resource.GetMaximum())
                {
                    return(false);                                                                                         //holy crap this is a kludge. TODO: Fix this
                }
            }
        }
        if (TargetInv.GetItemBucketFillAmount() + CraftRecipe.ItemOuputSpace > TargetInv.GetItemBucketCap())
        {
            return(false);
        }

        return(true);
    }
    public bool CraftConsumable(ResourceInventory ResourceInv, InventoryController SourceInv, ResourceInventory TargetInv, ConsumableRecipe CraftRecipe, bool ByPassCraftCheck = false)
    {
        if (!ByPassCraftCheck) //optimization to skip checking if we can craft this recipe
        {
            if (!CanCraftConsumable(ResourceInv, SourceInv, TargetInv, CraftRecipe))
            {
                return(false);
            }
        }

        foreach (var itemIn in CraftRecipe.ItemInput) //TODO Optimize data structure to allow use of a single foreach for inputs
        {
            SourceInv.RemoveFromItemBucket(itemIn.item, itemIn.amount);
        }
        foreach (var resourceIn in CraftRecipe.ResourceInput)
        {
            ResourceInv.RemoveResource(resourceIn.resource, resourceIn.amount);
        }

        if (CraftRecipe.isUpgrade)
        {
            Debug.Log("Before Amount: " + TargetInv.GetResource(CraftRecipe.Output));
            //if(CraftRecipe.Output.name == "Health")
            //{
            //    UIRootModule.UIRoot.GetScreen<GameHUD>().healthUpgrade.Upgrade(CraftRecipe.OutputAmount);
            //}
            if (CraftRecipe.Output.name == "Fuel")
            {
                UIRootModule.UIRoot.GetScreen <GameHUD>().fuelUpgrade.Upgrade(CraftRecipe.OutputAmount);
            }
            //Add Resource already contains a clamp so resource cannot go over max
            TargetInv.AddResource(CraftRecipe.Output, CraftRecipe.Output.GetMaximum());
            Debug.Log("After Amount: " + TargetInv.GetResource(CraftRecipe.Output));
        }
        else
        {
            //Add Resource already contains a clamp so resource cannot go over max
            TargetInv.AddResource(CraftRecipe.Output, CraftRecipe.OutputAmount);
        }
        return(true);
    }
    private void GenerateDial(Resource resource)
    {
        var newDial = Instantiate(dial);

        newDial.transform.SetParent(dialLayout.transform);

        var dialText = newDial.GetComponent <GetObjectsDial>().GetText();

        dialText.SetText($"{resource.DisplayName} ({resource.Abreviation})");
        dialText.color = resource.ResourceColor;

        var capacityText = newDial.GetComponent <GetObjectsDial>().GetCapacityText();

        capacityText.SetText($"{storageOwner.GetResource(resource).ToString()}/{resource.GetMaximum().ToString()}");
        capacityText.color = resource.ResourceColor;

        newDial.GetComponent <GetObjectsDial>().GetBKImage().color = new Color(resource.ResourceColor.r, resource.ResourceColor.g, resource.ResourceColor.b, 0.2f);

        var fillImage = newDial.GetComponent <GetObjectsDial>().GetFillImage();

        fillImage.color      = resource.ResourceColor;
        fillImage.fillAmount = storageOwner.GetResource(resource) / resource.GetMaximum();
        updateDial.Add(resource, newDial);
    }
Exemple #9
0
 private void UpdateOwnedAmounts()
 {
     foreach (var kvp in TextToResource)
     {
         kvp.Key.SetText(shipInventory.GetResource(kvp.Value).ToString());
     }
     foreach (var kvp in TextToItem)
     {
         int amount = playerInventory.GetItemAmount(kvp.Value);
         if (amount < 0)
         {
             amount = 0;
         }
         kvp.Key.SetText(amount.ToString());
     }
 }
    /* public void TryOffload(ResourceInventory Target)
     * {
     *   string temp;
     *   TryOffload(Target,out temp);
     * }*/


    public void TryOffload(ResourceInventory Target)
    {
        if (Target.CanAdd(NaniteResource, NaniteOffloadAmount))
        {
            if (LinkedInventory.GetResource(NaniteResource) >= NaniteOffloadAmount)
            {
                //player-facing poptext
                if (AntiSpamTimer <= Time.time)
                {
                    var poptext = Instantiate(popText); //No this doesn't cause memleaks, I know it looks bad but it doesn't
                    poptext.popText.SetText($"{NaniteResource.DisplayName} added");
                    AntiSpamTimer = Time.time + AntiSpam;
                }


                Target.AddResource(NaniteResource, NaniteOffloadAmount);
                LinkedInventory.RemoveResource(NaniteResource, NaniteOffloadAmount);
                Debug.Log(Target.GetResource(NaniteResource));
            }
            else
            {
                //player-facing poptext
                if (AntiSpamTimer <= Time.time)
                {
                    var poptext = Instantiate(popText);
                    poptext.popText.SetText($"No {NaniteResource.DisplayName} available");
                    AntiSpamTimer = Time.time + AntiSpam;
                }

                //error = OffloadEmptyMsg;
                return;
            }
        }
        else
        {
            //player-facing poptext
            var poptext = Instantiate(popText);
            poptext.popText.SetText($"{NaniteResource.DisplayName} full");

            //error = OffloadFullMsg;
            Debug.Log("Player Inv Full");
            return;
        }
        //error = null;
    }
Exemple #11
0
    void Awake()
    {
        playerInventory = UIRoot.GetPlayer().GetComponent <ResourceInventory>();

        foreach (var resource in resources)
        {
            var currentAmount = playerInventory.GetResource(resource);
            var newLine       = Instantiate(defaultText);

            newLine.transform.SetParent(contentGroup.transform);

            newLine.GetComponent <TextMeshProUGUI>().SetText(resource.DisplayName + ": " + currentAmount);

            //save an association between the resource and the new entry we've created so we can pick out
            //specific resources to update later
            resourceList.Add(resource, newLine);

            ResourceController.RegisterOnAddDelegate(resource, playerInventory, UpdateResourceAmount);
        }
    }
    public bool CanCraftConsumable(ResourceInventory ResourceInv, InventoryController SourceInv, ResourceInventory TargetInv, ConsumableRecipe CraftRecipe)
    {
        if (SourceInv == null || TargetInv == null || ResourceInv == null || TargetInv == null)
        {
            Debug.LogError(SourceInv);
            Debug.LogError(TargetInv);
            Debug.LogError(ResourceInv);
            return(false);
        }

        foreach (var itemIn in CraftRecipe.ItemInput)
        {
            if (SourceInv.GetItemAmount(itemIn.item) < itemIn.amount)
            {
                return(false);
            }
        }

        foreach (var resIn in CraftRecipe.ResourceInput)
        {
            if (ResourceInv.GetResource(resIn.resource) < resIn.amount)
            {
                return(false);
            }
        }

        if (CraftRecipe.isUpgrade)
        {
            return(true);
        }

        var resource = CraftRecipe.Output;

        if (TargetInv.GetResource(resource) == resource.GetMaximum())
        {
            Debug.Log($"{resource} is full");
        }
        return(true);
    }
Exemple #13
0
    public void UpdateResourceAmount(Resource resource, float DeltaValue)
    {
        var updateLine = resourceList[resource];

        updateLine.GetComponent <TextMeshProUGUI>().SetText(resource.DisplayName + ": " + playerInventory.GetResource(resource));
    }