BITFALL/Assets/Artists/Scripts/Player/Survival/PlayerEatService.cs

39 lines
953 B
C#

using System;
using System.Collections;
using System.Collections.Generic;
using BITFALL.Entities.Inventory;
using BITFALL.Player.Inventory;
using BITKit;
using BITKit.Entities;
using UnityEngine;
namespace BITFALL.Player.Survival
{
public class PlayerEatService : EntityBehavior
{
[Inject] private IPlayerSurvivalService _survival;
[Inject] private IEntityInventory _inventory;
public override void OnStart()
{
_inventory.OnUsedItem += OnUseItem;
}
private void OnUseItem(IBasicItem arg)
{
if (arg.GetAssetable().TryGetProperty<PlayerEatAddHunger>(out var addHunger) &&
_survival.Elements.TryGetAny(x => x is PlayerSurvivalHunger, out var element))
{
element.Value += addHunger.Value;
}
if (arg.GetAssetable().TryGetProperty<PlayerEatAddThirst>(out var addThirst) &&
_survival.Elements.TryGetAny(x => x is PlayerSurvivalThirst, out element))
{
element.Value += addThirst.Value;
}
}
}
}