1
This commit is contained in:
@@ -6,6 +6,7 @@ using BITKit.Entities;
|
||||
using BITKit.WorldNode;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
|
||||
namespace Net.Project.B.Health
|
||||
@@ -73,10 +74,13 @@ namespace Net.Project.B.Health
|
||||
private readonly IEntitiesService _entitiesService;
|
||||
|
||||
private static readonly ConcurrentDictionary<int, IHealthComponent> HealthComponents = new();
|
||||
|
||||
public HealthService(IEntitiesService entitiesService)
|
||||
|
||||
private readonly ILogger<HealthService> _logger;
|
||||
|
||||
public HealthService(IEntitiesService entitiesService, ILogger<HealthService> logger)
|
||||
{
|
||||
_entitiesService = entitiesService;
|
||||
_logger = logger;
|
||||
_singleton = this;
|
||||
|
||||
_entitiesService.OnAdd += OnAdd;
|
||||
@@ -128,7 +132,17 @@ namespace Net.Project.B.Health
|
||||
}
|
||||
var newHp = Math.Clamp(current + value, -1, HealthComponents[id].MaxHealthPoint);
|
||||
Healths.Set(id,HealthComponents[id].HealthPoint = newHp);
|
||||
OnHealthChanged?.Invoke(id,current,newHp,arg);
|
||||
|
||||
try
|
||||
{
|
||||
OnHealthChanged?.Invoke(id, current, newHp, arg);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogCritical(e, e.Message);
|
||||
}
|
||||
|
||||
|
||||
return UniTask.FromResult(newHp);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user