Files
SimUL/Assets/Scripts/InteractableObjects/Fridge.cs
T
Vladimir Koshevarov 582f0e393e CleanupCode add eating
2023-03-14 13:56:14 +02:00

61 lines
1.8 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Fridge : BaseInteractableObject
{
[SerializeField]
private ContainerSO _containerSO;
[SerializeField]
//private ItemActionsUI _actionsMenu;
private Player _player;
private List<FoodItemSO> _foodObjects = new List<FoodItemSO>();
public override void Interact(Player player)
{
_player = player;
if (player.IsHoldContainerItem())
{
var playerContainer = player.GetContainerItem();
if (!playerContainer.IsSalebleItems())
{
if (_foodObjects.Count + playerContainer.GetItems().Count <= _containerSO.MaxCapacity)
{
foreach (FoodItemSO item in playerContainer.GetItems())
{
_foodObjects.Add(item);
}
player.ClearContainerItem();
Debug.Log($"Fridge have {_foodObjects.Count} pices of food");
}
else
Debug.Log($"Fridge is full");
}
}
else
{
//Eat menu
if (_foodObjects.Count > 0)
{
var hunger = player.Stats[StatsId.Food].MaxValue - player.Stats[StatsId.Food].Value;
var eatingItems = _foodObjects.Count < (hunger / 10) ? _foodObjects.Count : (hunger / 10);
StartCoroutine(EatRoutine(eatingItems));
_foodObjects.RemoveRange(0, (int)eatingItems);
}
}
}
private IEnumerator EatRoutine(float timeToEat)
{
_player.SetPlayerActing(PlayerStates.Eating);
yield return new WaitForSeconds(timeToEat);
_player.SetPlayerActing(PlayerStates.Awake);
yield break;
}
}