Ejemplo n.º 1
0
    public void AddResource(RunnerResource resourceAdded, bool saveToMain)
    {
        if (saveToMain == false)
        {
            if (currentRunResources.Exists(x => x.resourceName == resourceAdded.resourceName))
            {
                currentRunResources.Find(x => x.resourceName == resourceAdded.resourceName).resourceVal += resourceAdded.resourceVal;
            }
            else
            {
                currentRunResources.Add(resourceAdded);
            }
        }
        else
        {
            if (allResources.Exists(x => x.resourceName == resourceAdded.resourceName))
            {
                allResources.Find(x => x.resourceName == resourceAdded.resourceName).resourceVal += resourceAdded.resourceVal;
            }
            else
            {
                allResources.Add(resourceAdded);
            }
        }

        if (resourceAdded.resourceType == ResourceType.Equipment)
        {
            equipMan.ObtainedNewEquipment(resourceAdded.resourceName);
        }
        resourceGameUI.ResourcePickedUp(resourceAdded);
    }
Ejemplo n.º 2
0
    public bool ResourceHasAmount(RunnerResource resourceCheck, bool includeCurrentResources)
    {
        RunnerResource allRef  = allResources.Find(x => x.resourceName == resourceCheck.resourceName);
        RunnerResource currRef = currentRunResources.Find(x => x.resourceName == resourceCheck.resourceName);

        int currentAmount = 0;

        //If item exists in both, add together
        if (allRef != null)
        {
            currentAmount += allRef.resourceVal;
        }
        if (currRef != null)
        {
            currentAmount += currRef.resourceVal;
        }

        //Debug.Log("Check if there are " + resourceCheck.resourceVal + " " + resourceCheck.resourceName
        //             + ". \n There are " + currentAmount + " found in all and current");

        if (currentAmount >= resourceCheck.resourceVal)
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
Ejemplo n.º 3
0
    public void SaveAllTempResources()
    {
        for (int i = 0; i < currentRunResources.Count; i++)
        {
            RunnerResource addRes = allResources.Find(x => x.resourceName == currentRunResources[i].resourceName);
            if (addRes != null)
            {
                addRes.resourceVal += currentRunResources[i].resourceVal;
            }
            else
            {
                allResources.Add(currentRunResources[i]);
            }
        }

        currentRunResources.Clear();
    }
Ejemplo n.º 4
0
    public void ResourcePickedUp(RunnerResource resource)
    {
        for (int i = 0; i < allResourceTexts.Count; i++)
        {
            //Find first null / inactive text
            if (allResourceTexts[i].associatedResource.resourceType == ResourceType.None)
            {
                allResourceTexts[i].associatedResource    = resource;
                allResourceTexts[i].resourceNameText.text = resource.resourceName;
                allResourceTexts[i].resourceValText.text  = resource.resourceVal.ToString();

                allResourceTexts[i].displayTimer = timeToDisplayUI;

                allResourceTexts[i].resourceNameText.gameObject.SetActive(true);
                allResourceTexts[i].resourceValText.gameObject.SetActive(true);

                break;
            }
        }
    }
Ejemplo n.º 5
0
    public void SavePercentageOfTempResources(float savePercentage)
    {
        for (int i = 0; i < currentRunResources.Count; i++)
        {
            RunnerResource addRes      = allResources.Find(x => x.resourceType == currentRunResources[i].resourceType);
            int            amountToAdd = (int)((float)currentRunResources[i].resourceVal * savePercentage);
            if (amountToAdd > 0)
            {
                if (addRes != null)
                {
                    addRes.resourceVal += amountToAdd;
                }
                else
                {
                    allResources.Add(currentRunResources[i]);
                }
            }
        }

        currentRunResources.Clear();
    }
Ejemplo n.º 6
0
    public void SpendResource(RunnerResource spendRes)
    {
        int amountRemaining = spendRes.resourceVal;
        //Subtract from current first
        RunnerResource currRef = currentRunResources.Find(x => x.resourceName == spendRes.resourceName);

        if (currRef != null)
        {
            if (currRef.resourceVal >= amountRemaining)
            {
                currRef.resourceVal -= amountRemaining;
                amountRemaining      = 0;
            }
            else
            {
                amountRemaining     -= currRef.resourceVal;
                currRef.resourceVal -= currRef.resourceVal;
            }
        }

        //If there is remaining, now check all resources
        if (amountRemaining > 0)
        {
            RunnerResource allRef = allResources.Find(x => x.resourceName == spendRes.resourceName);
            if (allRef != null)
            {
                if (allRef.resourceVal >= amountRemaining)
                {
                    allRef.resourceVal -= amountRemaining;
                }
                else
                {
                    Debug.LogError("[RESOURCE] attempting to spend more resources than are available");
                }
            }
        }
    }