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

39 lines
953 B
C#
Raw Normal View History

2023-10-02 23:24:56 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
2023-10-24 23:37:59 +08:00
using BITFALL.Entities.Inventory;
2023-10-02 23:24:56 +08:00
using BITFALL.Player.Inventory;
using BITKit;
using BITKit.Entities;
using UnityEngine;
namespace BITFALL.Player.Survival
{
2023-10-30 01:25:53 +08:00
public class PlayerEatService : EntityBehavior
2023-10-02 23:24:56 +08:00
{
2023-10-24 23:37:59 +08:00
[Inject] private IPlayerSurvivalService _survival;
[Inject] private IEntityInventory _inventory;
2023-10-02 23:24:56 +08:00
public override void OnStart()
{
2023-10-24 23:37:59 +08:00
_inventory.OnUsedItem += OnUseItem;
2023-10-02 23:24:56 +08:00
}
2023-10-24 23:37:59 +08:00
private void OnUseItem(IBasicItem arg)
2023-10-02 23:24:56 +08:00
{
2023-10-24 23:37:59 +08:00
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))
2023-10-02 23:24:56 +08:00
{
2023-10-24 23:37:59 +08:00
element.Value += addThirst.Value;
2023-10-02 23:24:56 +08:00
}
}
}
}