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

public class TimeManager : MonoBehaviour {

	
	// Update is called once per frame
	void Update ()
	{
		SetConsumableTime();
		ApplyTimeModifiers();
		ApplyComfort();
	}

	void FixedUpdate()
	{
		UpdatePlayerComfortStates();
	}

	void SetConsumableTime()
	{
		GlobalTime.drinkModifier += Time.deltaTime / GameManager.instance.defaultDrinkConsumeSpeed;
		GlobalTime.foodModifier += Time.deltaTime / GameManager.instance.defaultFoodConsumeSpeed;
	}

	void ApplyTimeModifiers()
	{
		GlobalTime.ModifyTime(Time.deltaTime / GameManager.instance.realSecondsInHour *-1);
		//GlobalTime.ModifyTime(GlobalTime.comfortModifier * Time.deltaTime * 0.1f);
		GlobalTime.ModifyTime(GlobalTime.drinkModifier *Time.deltaTime * 0.1f * -1);
		GlobalTime.ModifyTime(GlobalTime.foodModifier * Time.deltaTime * 0.1f * -1);
	}

	void ApplyComfort()
	{
		float amount = GlobalTime.comfortModifier * 0.01f;
		GlobalTime.ModifyTime(amount * Time.deltaTime);
	}

	void UpdatePlayerComfortStates()
	{
		GameManager.instance.player.SetComfortState(ComfortZone.NoFood, 1 - GlobalTime.foodModifier < GameManager.instance.foodAffectComfortTreshold);
		GameManager.instance.player.SetComfortState(ComfortZone.NoWater, 1 - GlobalTime.drinkModifier < GameManager.instance.foodAffectComfortTreshold);
	}
}
