private void Start()
    {
        if (resource_inventory == null)
        {
            resource_inventory = new List <Resource_Attributes>();

            //Debug.Log("Resource Inventory init successfully!");
        }
        else
        {
            resource_inventory.Clear();
        }

        foreach (Resource_V2.ResourceType rsc_t in System.Enum.GetValues(typeof(Resource_V2.ResourceType)))
        {
            Resource_Attributes temp = FindResourceAttribute(rsc_t);

            if (temp == null)
            {
                temp = gameObject.AddComponent <Resource_Attributes>();
                resource_inventory.Add(temp);
            }

            temp.resource_type   = rsc_t;
            temp.resource_amount = 0;

            //Debug logging stuff
            //Resource_Attributes temp = resource_inventory.Find(x => x.resource_type == rsc_t);
            //Debug.Log("Init Resource_Attributes to Inv: " + temp.resource_type.ToString() + " " + temp.resource_amount.ToString());
        }
    }
示例#2
0
    void AddResourcesToInventory(object caller, AddResourceArgs args)
    {
        Resource_Attributes temp = FindResourceAttribute(args.resource_type);

        if (temp != null)
        {
            temp.resource_amount += args.resource_amount;
        }

        PrintResourceInventory();
    }
示例#3
0
    private Resource_Attributes FindResourceAttribute(Resource_V2.ResourceType type)
    {
        Resource_Attributes temp = null;

        foreach (Resource_Attributes ra in resource_inventory)
        {
            if (ra.resource_type == type)
            {
                temp = ra;
                break;
            }
        }
        return(temp);
    }
    public static bool TryTakeResource(Resource_Attributes attributes)
    {
        Resource_Attributes inventory_ra = FindResourceAttribute(attributes.resource_type);

        if (inventory_ra.resource_amount >= attributes.resource_amount)
        {
            //no need to clamp
            inventory_ra.resource_amount -= attributes.resource_amount;
            return(true);
        }
        else
        {
            return(false);
        }
    }
    //TODO: Towers cost a LIST of resources. This ain't gonna work. Refactor to accept param Resource_Attributes instead of this garbage!
    //Tries to take the amount of resources asked out of the inventory. Return bool indicates success/failure
    public static bool TryTakeResource(Resource_V2.ResourceType type, int amount)
    {
        Resource_Attributes temp = FindResourceAttribute(type);

        if (temp.resource_amount >= amount)
        {
            //no need to clamp
            temp.resource_amount -= amount;
            return(true);
        }
        else
        {
            return(false);
        }
    }
示例#6
0
    //TODO: Develop a better strategy for reducing the number of resources returned upon refund. it's currently a magic number...
    private void RefundResources()
    {
        List <Resource_Attributes> refund_ras = new List <Resource_Attributes>();

        foreach (Resource_Attributes ra in price_list)
        {
            Resource_Attributes ra_to_add = gameObject.AddComponent <Resource_Attributes>();
            ra_to_add.resource_amount = ra.resource_amount;
            ra_to_add.resource_type   = ra.resource_type;

            ra_to_add.resource_amount = (int)(ra_to_add.resource_amount * .75f);

            refund_ras.Add(ra_to_add);
        }

        Resource_Inventory.AddResourcesToInventory(refund_ras);
    }
    public static void RemoveLives(int lives)
    {
        if (lives <= 0)
        {
            return;             //someone is trying to goof my system!!! I ain't gonna have it...
        }
        Resource_Attributes cur_lives_attribute = FindResourceAttribute(Resource_V2.ResourceType.lives);

        if (cur_lives_attribute.resource_amount > lives)
        {
            cur_lives_attribute.resource_amount -= lives;
        }
        else
        {
            cur_lives_attribute.resource_amount = 0;
            GameOverHandler.DoGameOver();
        }
    }
示例#8
0
    //sets resource_amount of type argument to amount argument
    public void SetResourceAmount(Resource_V2.ResourceType type, int amount)
    {
        Resource_Attributes temp = FindResourceAttribute(type);

        temp.resource_amount = amount;
    }
示例#9
0
    public int GetResourceAmount(Resource_V2.ResourceType type)
    {
        Resource_Attributes temp = FindResourceAttribute(type);

        return(temp.resource_amount);
    }
    //will add argument amount to the resource_amount of type argument
    public static void AppendResourceAmount(Resource_V2.ResourceType type, int amount)
    {
        Resource_Attributes temp = FindResourceAttribute(type);

        temp.resource_amount += amount;
    }