This commit is contained in:
CortexCore 2025-03-09 13:38:32 +08:00
parent 787ae12bf8
commit 88f1ff1b04
14 changed files with 181 additions and 35 deletions

View File

@ -9,8 +9,9 @@ namespace BITFALL
{
public record BulletData
{
public uint Token;
public int Token;
public int Initiator;
public int ScriptableId;
public float3 Position;
public quaternion Rotation;
public float3 Forward;
@ -19,6 +20,6 @@ namespace BITFALL
public int StartSpeed;
public int MaxDamage;
public int InitialDamage;
public ulong AddressId;
public int AddressId;
}
}

View File

@ -3,7 +3,8 @@
"rootNamespace": "",
"references": [
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
"GUID:d8b63aba1907145bea998dd612889d6b"
"GUID:d8b63aba1907145bea998dd612889d6b",
"GUID:953d83d56b66feb4fa28a9eb2c4d78cb"
],
"includePlatforms": [],
"excludePlatforms": [],

View File

@ -10,23 +10,28 @@ namespace Net.Project.B.Cosmetics
{
}
public interface IRequiredCosmeticsClass{}
[Serializable]
public struct CosmeticsHand:ICosmeticsClass
{
public override bool Equals(object obj) => this.GetType() == obj?.GetType();
public override int GetHashCode() => GetType().GetHashCode();
}
[Serializable]
public struct CosmeticsModel:ICosmeticsClass
public struct CosmeticsModel:ICosmeticsClass,IRequiredCosmeticsClass
{
public override bool Equals(object obj) => this.GetType() == obj?.GetType();
public override int GetHashCode() => GetType().GetHashCode();
}
[Serializable]
public struct CosmeticsHat:ICosmeticsClass
{
public override bool Equals(object obj) => this.GetType() == obj?.GetType();
public override int GetHashCode() => GetType().GetHashCode();
}
public class CosmeticsCustomizeComponent

8
Src/Damage.meta Normal file
View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b456f6649dfe6dc44ac8154edc7612af
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,47 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
using UnityEngine;
namespace Net.Project.B.Damage
{
public interface IDamageData
{
public int Index { get; set; }
public int InitialDamage { get; }
public int FinalDamage { get; }
}
public struct DamageData:IDamageData
{
public int Index { get; set; }
public int InitialDamage { get; set; }
public int FinalDamage { get; set; }
}
public interface IDamageType
{
}
public interface IDamageReport
{
public int Index { get; }
public ulong InitialTick { get; }
public ulong FinalTick { get; }
public int Initiator { get; }
public int Target { get; }
public int InitialDamage { get; }
public int FinalDamage { get; }
public bool IsFatal { get; }
public IDamageType DamageType { get; }
IReadOnlyCollection<IDamageData> Reports { get; }
}
public interface IDamageService
{
public event Func<IDamageReport, UniTask<IDamageData>> DamageFactor;
public event Action<IDamageReport> OnDamaged;
public UniTask<IDamageReport> CreateDamageAsync(int initiator, int target, int initialDamage, IDamageType damageType);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 375a295c2e9786f438297f37b096a6c7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,18 @@
{
"name": "Net.Project.B.Damage",
"rootNamespace": "",
"references": [
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
"GUID:d8b63aba1907145bea998dd612889d6b",
"GUID:f51ebe6a0ceec4240a699833d6309b23"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 0a14a5a3c0b252a479623fb0cdc70fdf
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -2,11 +2,25 @@ using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using BITKit;
using BITKit.Entities;
using BITKit.WorldNode;
using Cysharp.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
namespace Net.Project.B.Health
{
public interface IHealthComponent
{
public int MaxHealthPoint { get; }
}
[Serializable]
public class HealthComponent:IHealthComponent,IWorldNode
{
public int maxHealthPoint = 100;
public int MaxHealthPoint => maxHealthPoint;
}
/// <summary>
/// 生命值服务
/// </summary>
@ -36,13 +50,31 @@ namespace Net.Project.B.Health
/// <returns></returns>
public UniTask<int> AddHealth(int id,int value,object arg);
}
public class HealthService:IHealthService
{
private static HealthService _singleton;
public HealthService()
public class HealthService:IHealthService,IDisposable
{ private static HealthService _singleton;
private readonly IEntitiesService _entitiesService;
private static readonly ConcurrentDictionary<int, IHealthComponent> HealthComponents = new();
public HealthService(IEntitiesService entitiesService)
{
_entitiesService = entitiesService;
_singleton = this;
_entitiesService.OnAdd += OnAdd;
}
private void OnAdd(IEntity obj)
{
if (obj.ServiceProvider.GetService<IHealthComponent>() is {} healthComponent)
{
if (HealthComponents.TryAdd(obj.Id, healthComponent))
{
Healths.TryAdd(obj.Id, healthComponent.MaxHealthPoint <=0 ? 100 : healthComponent.MaxHealthPoint);
}
}
}
[BITCommand]
public static void SetHealth(int id, int newHealth)
{
@ -55,6 +87,7 @@ namespace Net.Project.B.Health
{
Healths.GetOrAdd(id,100);
_singleton.AddHealth(id, newHealth, null).Forget();
}
@ -75,15 +108,21 @@ namespace Net.Project.B.Health
}
public UniTask<int> AddHealth(int id, int value,object arg)
{
var current = Healths.GetOrAdd(id,100);
if (Healths.TryGetValue(id,out var current) is false) return UniTask.FromResult(-1);
foreach (var func in OnHealthChange.CastAsFunc())
{
value =func.Invoke(id,current, value, arg);
}
var newHp = Math.Clamp(current + value, -1, 100);
var newHp = Math.Clamp(current + value, -1, HealthComponents[id].MaxHealthPoint);
Healths.Set(id,newHp);
OnHealthChanged?.Invoke(id,current,newHp,arg);
return UniTask.FromResult(newHp);
}
public void Dispose()
{
_entitiesService.OnAdd -= OnAdd;
}
}
}

View File

@ -3,10 +3,19 @@ using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using BITKit;
using BITKit.Entities;
using BITKit.WorldNode;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace Net.Project.B.Health
{
[Serializable]
public class KnockedComponent:IKnockedComponent,IWorldNode{}
public interface IKnockedComponent
{
}
/// <summary>
/// 击倒服务
/// </summary>
@ -32,19 +41,25 @@ namespace Net.Project.B.Health
public class KnockedService : IKnockedService,IDisposable
{
private readonly IEntitiesService _entitiesService;
private readonly IHealthService _healthService;
private readonly ILogger<KnockedService> _logger;
public KnockedService(IHealthService healthService, ILogger<KnockedService> logger)
public KnockedService(IHealthService healthService, ILogger<KnockedService> logger, IEntitiesService entitiesService)
{
_healthService = healthService;
_logger = logger;
_entitiesService = entitiesService;
_healthService.OnHealthPlus += OnHealthPlus;
_healthService.OnHealthChanged += OnHealthChanged;
}
private int OnHealthPlus(int id, int oldHp, int plus, object sendor)
{
if (_entitiesService.TryGetEntity(id, out var entity) is false) return plus;
if (entity.ServiceProvider.GetService<IKnockedComponent>() is null) return plus;
var isKnocked = _knocked.Contains(id);
if (oldHp < 0) return plus;
if ((oldHp + plus) > -1) return plus;
@ -57,7 +72,7 @@ namespace Net.Project.B.Health
var nextHealth = currentHealth + plus;
_knockedHealth[id] = nextHealth;
_onKnockedHealthChanged?.Invoke(id, currentHealth, nextHealth);
_logger.LogInformation($"Entity {id} 的击倒生命值减少了,剩余{_knockedHealth[id]}");
// _logger.LogInformation($"Entity {id} 的击倒生命值减少了,剩余{_knockedHealth[id]}");
return 0;
}
_knockedHealth.Set(id,-1);
@ -66,7 +81,7 @@ namespace Net.Project.B.Health
_knockedHealth.TryAdd(id, 100);
_knocked.Add(id);
_onKnocked?.Invoke(id, true);
_logger.LogInformation($"Entity {id} 被击倒了");
// _logger.LogInformation($"Entity {id} 被击倒了");
return 0;
}
@ -79,7 +94,7 @@ namespace Net.Project.B.Health
_knockedHealth.TryRemove(arg1,out _);
_onKnocked?.Invoke(arg1, false);
_logger.LogInformation($"Entity {arg1} 自起了");
// _logger.LogInformation($"Entity {arg1} 自起了");
}
private static readonly HashSet<int> _knocked = new();

View File

@ -3,7 +3,8 @@
"rootNamespace": "",
"references": [
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
"GUID:f51ebe6a0ceec4240a699833d6309b23"
"GUID:f51ebe6a0ceec4240a699833d6309b23",
"GUID:d750d221812bb1d48baff92e6ef73e28"
],
"includePlatforms": [],
"excludePlatforms": [],

View File

@ -20,8 +20,6 @@ namespace Net.Project.B.Interaction
/// </summary>
public interface IWorldInteractable
{
public int Id { get; }
public IWorldInteractable Root { get; }
public IWorldInteractionType InteractionType { get; }
public object WorldObject { get; set; }
}
@ -30,18 +28,6 @@ namespace Net.Project.B.Interaction
/// </summary>
public interface IWorldInteractionService
{
/// <summary>
/// 注册可互动对象
/// </summary>
/// <param name="interactable"></param>
/// <returns></returns>
public bool Register(IWorldInteractable interactable);
/// <summary>
/// 注销可互动对象
/// </summary>
/// <param name="interactable"></param>
/// <returns></returns>
public bool Unregister(IWorldInteractable interactable);
/// <summary>
/// 尝试获取互动
/// </summary>

View File

@ -11,14 +11,16 @@ namespace Net.Project.B.Interaction
public class WorldInteractable : IWorldInteractable,IWorldNode
{
public GameObject gameObject;
public int Id => gameObject.GetInstanceID();
public IWorldInteractable Root => this;
public IWorldInteractionType InteractionType => null;
public object WorldObject
{
get => gameObject;
set => throw new NotImplementedException("Can do that");
set
{
if (value is GameObject go) gameObject = go;
}
}
}
}

View File

@ -1,3 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using BITKit;
@ -12,7 +13,11 @@ namespace Net.Project.B.UX
public interface IUXBuyStation:IUXPanel{}
public interface IUXControlMode:IUXPanel{}
public interface IUXCosmetics:IUXPanel{}
public interface IUXDialogue:IUXPanel{}
public interface IUXDialogue : IUXPanel
{
event Func<string, string> OnSubtitle;
}
public interface IUXInventory : IUXPanel
{