Encounter / Assets / Scripts / EncounterManagement / Shop.cs
Shop.cs
Raw
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// Handles general shop data and information about the items available
/// </summary>
public class Shop
{
    public string ShopOwnerName { get; private set; }
    public string ShopName { get; private set; }
    public Dictionary<Item, int> ItemsOnSale { get; private set; }
    public Dictionary<Consumable, int> ConsumablesOnSale { get; private set; }
    public Dictionary<Relic, int> RelicsOnSale { get; private set; }
    public Dictionary<Weapon, int> WeaponOnSale { get; private set; }
    public Dictionary<Apparel, int> ApparelOnSale { get; private set; }
    public Dictionary<Item, int> GetAll()
    {
        Dictionary<Item, int> output = new Dictionary<Item, int>();

        foreach (KeyValuePair<Item, int> item in ItemsOnSale)
            output.Add(item.Key, item.Value);
        foreach (KeyValuePair<Consumable, int> con in ConsumablesOnSale)
            output.Add(con.Key, con.Value);
        foreach (KeyValuePair<Relic, int> rel in RelicsOnSale)
            output.Add(rel.Key, rel.Value);
        foreach (KeyValuePair<Weapon, int> weapon in WeaponOnSale)
            output.Add(weapon.Key, weapon.Value);
        foreach (KeyValuePair<Apparel, int> apparel in ApparelOnSale)
            output.Add(apparel.Key, apparel.Value);

        return output;
    }

    public Shop()
    {

    }

    public Shop(string ownerName, string shopName)
    {
        this.ShopOwnerName = ownerName;
        this.ShopName = shopName;

        this.ItemsOnSale = new Dictionary<Item, int>();
        this.ConsumablesOnSale = new Dictionary<Consumable, int>();
        this.RelicsOnSale = new Dictionary<Relic, int>();
        this.WeaponOnSale = new Dictionary<Weapon, int>();
        this.ApparelOnSale = new Dictionary<Apparel, int>();
    }
    #region Adding
    public void Add(Item item, int amount)
    {
        if (ItemsOnSale.ContainsKey(item))
            ItemsOnSale[item] += amount;
        else
            ItemsOnSale.Add(item, amount);
    }
    public void Add(Consumable con, int amount)
    {
        if (ConsumablesOnSale.ContainsKey(con))
            ConsumablesOnSale[con] += amount;
        else
            ConsumablesOnSale.Add(con, amount);
    }
    public void Add(Relic relic, int amount)
    {
        if (RelicsOnSale.ContainsKey(relic))
            RelicsOnSale[relic] += amount;
        else
            RelicsOnSale.Add(relic, amount);
    }
    public void Add(Weapon weapon, int amount)
    {
        if (WeaponOnSale.ContainsKey(weapon))
            WeaponOnSale[weapon] += amount;
        else
            WeaponOnSale.Add(weapon, amount);
    }
    public void Add(Apparel apparel, int amount)
    {
        if (ApparelOnSale.ContainsKey(apparel))
            ApparelOnSale[apparel] += amount;
        else
            ApparelOnSale.Add(apparel, amount);
    }
    #endregion
    #region Removal
    public void Remove(Item item, int amount)
    {
        if (amount > ItemsOnSale[item])
            throw new ArgumentOutOfRangeException("Amount exceeds value stored in shop (item), please check logic.");

        if (amount < ItemsOnSale[item])
            ItemsOnSale[item] -= amount;
        else
            ItemsOnSale.Remove(item);
    }
    public void Remove(Consumable con, int amount)
    {
        if (amount > ConsumablesOnSale[con])
            throw new ArgumentOutOfRangeException("Amount exceeds value stored in shop (consumable), please check logic.");

        if (amount < ConsumablesOnSale[con])
            ConsumablesOnSale[con] -= amount;
        else
            ConsumablesOnSale.Remove(con);
    }
    public void Remove(Relic relic, int amount)
    {
        if (amount > RelicsOnSale[relic])
            throw new ArgumentOutOfRangeException("Amount exceeds value stored in shop (relic), please check logic.");

        if (amount < RelicsOnSale[relic])
            RelicsOnSale[relic] -= amount;
        else
            RelicsOnSale.Remove(relic);
    }
    public void Remove(Weapon weapon, int amount)
    {
        if (amount > WeaponOnSale[weapon])
            throw new ArgumentOutOfRangeException("Amount exceeds value stored in shop (weapon), please check logic.");

        if (amount < WeaponOnSale[weapon])
            WeaponOnSale[weapon] -= amount;
        else
            WeaponOnSale.Remove(weapon);
    }
    public void Remove(Apparel apparel, int amount)
    {
        if (amount > ApparelOnSale[apparel])
            throw new ArgumentOutOfRangeException("Amount exceeds value stored in shop (apparel), please check logic.");

        if (amount < ApparelOnSale[apparel])
            ApparelOnSale[apparel] -= amount;
        else
            ApparelOnSale.Remove(apparel);
    }
    #endregion
}