1
This commit is contained in:
@@ -11,7 +11,8 @@
|
||||
"GUID:ef0bb553b58b90b488bdbe8672e3be0b",
|
||||
"GUID:677cd05ca06c46b4395470200b1acdad",
|
||||
"GUID:30cdc242b1ac6a944a460f4ab0b77b88",
|
||||
"GUID:7efac18f239530141802fb139776f333"
|
||||
"GUID:7efac18f239530141802fb139776f333",
|
||||
"GUID:48ef04d98836e2640bf90b524bdff904"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using BITFALL.Entities.Inventory;
|
||||
using BITFALL.Player.Inventory;
|
||||
using BITKit;
|
||||
using BITKit.Entities;
|
||||
@@ -10,34 +11,27 @@ namespace BITFALL.Player.Survival
|
||||
{
|
||||
public class PlayerEatService : EntityComponent
|
||||
{
|
||||
private IPlayerSurvivalService _survival;
|
||||
private IPlayerInventory _inventory;
|
||||
[Inject] private IPlayerSurvivalService _survival;
|
||||
[Inject] private IEntityInventory _inventory;
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
base.OnStart();
|
||||
_inventory = entity.Get<IPlayerInventory>();
|
||||
_inventory.OnUseItem += OnUseItem;
|
||||
_survival = entity.Get<IPlayerSurvivalService>();
|
||||
_inventory.OnUsedItem += OnUseItem;
|
||||
}
|
||||
|
||||
private bool OnUseItem(IBasicItem arg)
|
||||
private void OnUseItem(IBasicItem arg)
|
||||
{
|
||||
var used = false;
|
||||
if (arg.GetAssetable().TryGetProperty<PlayerEatAddHunger>(out var addHunger) &&
|
||||
_survival.Elements.TryGetAny(x => x is PlayerSurvivalHunger, out var element))
|
||||
{
|
||||
if (arg.GetAssetable().TryGetProperty<PlayerEatAddHunger>(out var addHunger) &&
|
||||
_survival.Elements.TryGetAny(x => x is PlayerSurvivalHunger, out var element))
|
||||
{
|
||||
element.Value += addHunger.Value;
|
||||
used = true;
|
||||
}
|
||||
if (arg.GetAssetable().TryGetProperty<PlayerEatAddThirst>(out var addThirst) &&
|
||||
_survival.Elements.TryGetAny(x => x is PlayerSurvivalThirst, out element))
|
||||
{
|
||||
element.Value += addThirst.Value;
|
||||
used = true;
|
||||
}
|
||||
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;
|
||||
}
|
||||
return used;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -26,11 +26,24 @@ namespace BITFALL.Player.Survival
|
||||
public override void OnAwake()
|
||||
{
|
||||
Elements = initialElements;
|
||||
_health.OnSetAlive += OnSetAlive;
|
||||
}
|
||||
|
||||
private void OnSetAlive(bool obj)
|
||||
{
|
||||
if (obj)
|
||||
{
|
||||
foreach (var VARIABLE in Elements)
|
||||
{
|
||||
VARIABLE.Value = 100;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnUpdate(float deltaTime)
|
||||
{
|
||||
if (_interval.AllowUpdate is false) return;
|
||||
if (_health.IsAlive is false) return;
|
||||
foreach (var x in Elements)
|
||||
{
|
||||
x.Value -= 1;
|
||||
@@ -38,12 +51,12 @@ namespace BITFALL.Player.Survival
|
||||
{
|
||||
_damageService.Execute(new DamageMessage()
|
||||
{
|
||||
damageType = new SurvivalDamage()
|
||||
DamageType = new SurvivalDamage()
|
||||
{
|
||||
element = x,
|
||||
},
|
||||
target = entity,
|
||||
damage = 1,
|
||||
Target = entity,
|
||||
Damage = 1,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user