using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public enum ItemID
{
    Sword1,
    Sword2,
    Sword3,
    Sword4,

    Ninja1,
    Ninja2,
    Ninja3,
    Ninja4,

    Bow1,
    Bow2,
    Bow3,
    Bow4,

    Cannon1,
    Cannon2,
    Cannon3,
    Cannon4,

    Heal1,
    Heal2,
    Heal3,
    Heal4
}

// NOTE: There are no hybrid attacking items. It's either melee only, or ranged only.

public class CharacterItem 
{
    public string m_name;

    public bool m_usable; // Just healing for now

    public int m_weaponMinRange;
    public int m_weaponMaxRange;

    public int m_attackBuff;
    public int m_healing;

    public int m_cost;

    const float SELL_GOLD_MULT = 0.75f;

    public int SellCost
    {
        get { return (int)(m_cost * SELL_GOLD_MULT); }
    }
    
    public bool IsMeleeWeapon
    {
        get { return (( m_weaponMinRange == 1 ) && ( m_weaponMaxRange ==1 )) ; }
    }

    public bool IsRangedWeapon
    {
        get { return ( m_weaponMinRange > 1 ); }
    }

    public bool IsUsable
    {
        get { return (m_usable);  }
    }

    public static CharacterItem NewMeleeWeapon( ItemID id, int cost, string name, int damage )
    {
        CharacterItem item = new CharacterItem();
        item.m_name = name;
        item.m_weaponMinRange = 1;
        item.m_weaponMaxRange = 1;
        item.m_attackBuff = damage;
        item.m_cost = cost;
        ms_items.Add(id, item);
        return item;
    }

    public static CharacterItem NewRangedWeapon(ItemID id, int cost, string name, int maxRange, int damage)
    {
        CharacterItem item = new CharacterItem();
        item.m_name = name;
        item.m_weaponMinRange = 2;
        item.m_weaponMaxRange = maxRange;
        item.m_attackBuff = damage;
        item.m_cost = cost;
        ms_items.Add(id, item);
        return item;
    }

    public static CharacterItem NewHealingItem(ItemID id, int cost, string name, int healAmount)
    {
        CharacterItem item = new CharacterItem();
        item.m_name = name;
        item.m_healing = healAmount;
        item.m_usable = true;
        item.m_cost = cost;
        ms_items.Add(id, item);
        return item;
    }

    public static Dictionary<ItemID, CharacterItem> ms_items = new Dictionary<ItemID, CharacterItem>();

    static public CharacterItem GetItem(ItemID id)
    {
        CharacterItem retVal;
        if (ms_items.TryGetValue(id, out retVal))
        {
            return retVal;
        }
        Debug.LogError("Item not found :" + id);
        return null;
    }

    static CharacterItem()
    {
        NewMeleeWeapon(ItemID.Sword1, 100, "Wooden Sword", 5);
        NewMeleeWeapon(ItemID.Sword2, 200, "Iron Sword", 9);
        NewMeleeWeapon(ItemID.Sword3, 400, "Steel Sword", 16);
        NewMeleeWeapon(ItemID.Sword4, 800, "Mithril Sword", 25);

        NewMeleeWeapon(ItemID.Ninja1, 1500, "Katana", 33);
        NewMeleeWeapon(ItemID.Ninja2, 2700, "Honed Blade", 45);
        NewMeleeWeapon(ItemID.Ninja3, 4000, "Critical Blade", 55);
        NewMeleeWeapon(ItemID.Ninja4, 6000, "The Scimitar", 70);

        NewRangedWeapon(ItemID.Bow1, 150, "Wooden Bow", 2, 3);
        NewRangedWeapon(ItemID.Bow2, 300, "Iron Bow", 2, 7);
        NewRangedWeapon(ItemID.Bow3, 550, "Steel Bow", 2, 13);
        NewRangedWeapon(ItemID.Bow4, 1000, "Elven Bow", 2, 20);
        
        NewRangedWeapon(ItemID.Cannon1, 2000, "Long Shot", 3, 25);
        NewRangedWeapon(ItemID.Cannon2, 3500, "Honed Shot", 3, 35);
        NewRangedWeapon(ItemID.Cannon3, 5000, "Power Shot", 3, 45);
        NewRangedWeapon(ItemID.Cannon4, 7000, "Critical Shot", 4, 55);

        NewHealingItem(ItemID.Heal1, 20, "Healing Herb", 9);
        NewHealingItem(ItemID.Heal2, 80, "Healing Seeds", 15);
        NewHealingItem(ItemID.Heal3, 150, "Healing Salve", 27);
        NewHealingItem(ItemID.Heal4, 250, "Healing Elixir", 36);       

    }
}
