1
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using BITKit;
|
||||
using BITKit.Entities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITFALL.Player.Survival
|
||||
{
|
||||
[Serializable]
|
||||
public struct SurvivalDamage : IDamageType
|
||||
{
|
||||
public IPlayerSurvivalElement element;
|
||||
public string Message;
|
||||
}
|
||||
[CustomType(typeof(IPlayerSurvivalService))]
|
||||
public class PlayerSurvivalService : EntityComponent, IPlayerSurvivalService
|
||||
{
|
||||
public IPlayerSurvivalElement[] Elements { get; set; } = Array.Empty<IPlayerSurvivalElement>();
|
||||
[SerializeReference, SubclassSelector] private IPlayerSurvivalElement[] initialElements = Array.Empty<IPlayerSurvivalElement>();
|
||||
private readonly IntervalUpdate _interval = new(1);
|
||||
[SerializeReference,SubclassSelector,Inject] private IDamageService _damageService;
|
||||
[Inject]
|
||||
private IHealth _health;
|
||||
public override void OnAwake()
|
||||
{
|
||||
Elements = initialElements;
|
||||
}
|
||||
|
||||
public override void OnUpdate(float deltaTime)
|
||||
{
|
||||
if (_interval.AllowUpdate is false) return;
|
||||
foreach (var x in Elements)
|
||||
{
|
||||
x.Value -= 1;
|
||||
if (x.Value <= 0)
|
||||
{
|
||||
_damageService.Execute(new DamageMessage()
|
||||
{
|
||||
damageType = new SurvivalDamage()
|
||||
{
|
||||
element = x,
|
||||
},
|
||||
target = entity,
|
||||
damage = 1,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user