1
This commit is contained in:
36
Assets/Artists/Scripts/Player/Survival/PlayerEatService.cs
Normal file
36
Assets/Artists/Scripts/Player/Survival/PlayerEatService.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using BITFALL.Player.Inventory;
|
||||
using BITKit;
|
||||
using BITKit.Entities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITFALL.Player.Survival
|
||||
{
|
||||
public class PlayerEatService : EntityComponent
|
||||
{
|
||||
private IPlayerSurvivalService _survival;
|
||||
private IPlayerInventory _inventory;
|
||||
public override void OnStart()
|
||||
{
|
||||
base.OnStart();
|
||||
_inventory = entity.Get<IPlayerInventory>();
|
||||
_inventory.OnUseItem += OnUseItem;
|
||||
_survival = entity.Get<IPlayerSurvivalService>();
|
||||
}
|
||||
|
||||
private bool OnUseItem(IBasicItem arg)
|
||||
{
|
||||
switch (arg)
|
||||
{
|
||||
case var _ when arg.GetAssetable().TryGetProperty<PlayerEatAddHunger>(out var addHunger) &&
|
||||
_survival.Elements.TryGetAny(x => x is PlayerSurvivalHunger, out var hunger):
|
||||
hunger.Value += addHunger.Value;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user