2
0
Fork 0
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.1 KiB
C#

2 years ago
using Entitas;
using UnityEngine;
using Game;
public class RecoverSystem : IExecuteSystem, IInitializeSystem
{
private IGroup<GameEntity> _entities;
public void Initialize()
{
_entities = Util.GetGroup(GameMatcher.Hp);
}
public void Execute()
{
foreach (var entity in _entities)
{
UpdateRecover(entity);
}
}
public void UpdateRecover(GameEntity entity)
{
var hp = entity.hp;
if (!hp.IsAlive)
{
return;
}
//护盾恢复
if (hp.ShieldRecoverTimeMax != 0)
{
if (hp.ShieldRecoverTime > 0)
{
hp.ShieldRecoverTime -= Time.deltaTime;
if (hp.ShieldRecoverTime < 0)
{
hp.ShieldRecoverTime = 0;
}
}
else
{
var newShield = hp.Shield.Value + hp.ShieldRecover * Time.deltaTime;
hp.Shield.Value = Mathf.Min(hp.ShieldMax.Value, newShield);
}
}
}
}