This commit is contained in:
CortexCore
2025-06-26 23:34:50 +08:00
parent a772331918
commit 1e4643f20f
15 changed files with 318 additions and 17 deletions

View File

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

View File

@@ -83,8 +83,16 @@ namespace Net.Project.B.Health
}
_knockedHealth.TryAdd(id, 100);
_knocked.Add(id);
_onKnocked?.Invoke(id, true);
// _logger.LogInformation($"Entity {id} 被击倒了");
try
{
_onKnocked?.Invoke(id, true);
}
catch (Exception e)
{
_logger.LogCritical(e, e.Message);
}
// _logger.LogInformation($"Entity {id} 被击倒了");
//return 0;
return -Math.Abs(oldHp-1);
}