using UnityEngine;
using System.Collections;
using Framework.Entities;
using System.Collections.Generic;

public class AlchemistBag : CoreBehaviour
{
    public int medicineCount = 0;
    public int invisibilityCount = 0;
    public int destroyCount = 0;
    public int banishmentCount = 0;

    public int medHerbsCount = 0;
    public int invDropCount = 0;
    public int destroyDustCount = 0;
    public int banishGemCount = 0;

    public int medicineCost = 3;
    public int shadowCost = 2;
    public int destroyCost = 4;

    private bool firstMed = true;
    private bool firstShadow = true;
    private bool firstMark = true;

    protected override void InnerAwake()
    {

    }

    protected override void InnerUpdate()
    {

    }

    public List<string> Craft()
    {
        int maxMedCraft = 0;
        int maxShadowCraft = 0;
        int maxDestroyCraft = 0;
        if (this.medHerbsCount >= this.medicineCost)
        {
            maxMedCraft = Mathf.FloorToInt((float)medHerbsCount / (float)medicineCost);
            this.medHerbsCount -= medicineCost * maxMedCraft;
            this.medicineCount += maxMedCraft;
            if (firstMed)
            {
                Announce(new Journal.AddEntryAction(Journal.LoadText("MedIntro")[0]));
                firstMed = false;
            }
        }
        if (this.invDropCount >= this.shadowCost)
        {
            maxShadowCraft = Mathf.FloorToInt((float)invDropCount / (float)shadowCost);
            this.invDropCount -= this.shadowCost * maxShadowCraft;
            this.invisibilityCount += maxShadowCraft;
            if (firstShadow)
            {
                Announce(new Journal.AddEntryAction(Journal.LoadText("ShadowIntro")[0]));
                firstShadow = false;
            }
        }
        if (this.destroyDustCount >= this.destroyCost)
        {
            maxDestroyCraft = Mathf.FloorToInt((float)destroyDustCount / (float)destroyCost);
            this.destroyDustCount -= this.destroyCost * maxDestroyCraft;
            this.destroyCount += maxDestroyCraft;
            if (firstMark)
            {
                Announce(new Journal.AddEntryAction(Journal.LoadText("MarkIntro")[0]));
                firstMark = false;
            }
        }
        List<string> results = new List<string>();
        if(maxMedCraft > 0)
        {
            results.Add(maxMedCraft + " bowl(s) of medicine");
        }
        if (maxShadowCraft > 0)
        {
            results.Add(maxShadowCraft + " vial(s) of cloaking potion");
        }
        if (maxDestroyCraft > 0)
        {
            results.Add(maxDestroyCraft + " death shard(s)");
        }
        return results;
    }

    public void CraftMedicine()
    {
        if (this.medHerbsCount >= this.medicineCost)
        {
            this.medHerbsCount -= medicineCost;
            this.medicineCount++;
        }
    }

    public void CraftShadow()
    {
        if (this.invDropCount >= this.shadowCost)
        {
            this.invDropCount -= this.shadowCost;
            this.invisibilityCount++;
        }
    }
}
