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

public class PickUpDayCycleBehaviour : CoreBehaviour
{
    private Vector3 startPosition;
    bool used = false;
    private bool spent;

    public class SetUsedAction : CoreAction
    {
    }

    protected override void InnerAwake()
    {
        AddActionHandler<SetUsedAction>(SetUsed);
        AddGlobalActionHandler<DayDirector.NewDayAction>(this, NewDay);
        this.startPosition = this.transform.position;
    }

    protected override void InnerUpdate()
    {

    }

    private void SetUsed(SetUsedAction action)
    {
        this.transform.position = Vector3.down * 100f;
        used = true;
    }

    private void NewDay(DayDirector.NewDayAction action)
    {
        if (!spent && used)
        {
            if (Random.Range(0f, 1f) > 0.33f)
            {
                this.transform.position = this.startPosition;
                used = false;
            }
            else
            {
                spent = true;
            }
        }
        if (spent && (Random.Range(0f, 1f) > 0.8f))
        {
            spent = false;
        }
    }
}
