This commit is contained in:
CortexCore
2023-10-20 19:31:12 +08:00
parent 5cd094ed9a
commit a160813262
1878 changed files with 630581 additions and 4485 deletions

View File

@@ -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,
});
}
}
}
}
}