This commit is contained in:
CortexCore
2023-11-15 23:54:54 +08:00
parent ee3ecec6cb
commit 3c837a4a33
356 changed files with 73756 additions and 26493 deletions

View File

@@ -2,6 +2,7 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using BITFALL.Combat;
using BITKit;
using BITKit.Entities;
using BITKit.Entities.Melee;
@@ -18,7 +19,7 @@ namespace BITFALL.Melee
{
public void Melee(MeleeCommand command) => MeleeService.Melee(command);
}
public struct MeleeDamageMessage:IDamageType{}
public class MeleeService : MonoBehaviour,IMeleeService
{
internal static MeleeService Singleton;
@@ -41,31 +42,41 @@ namespace BITFALL.Melee
if (Queue.TryDequeue(out var command) is false) return;
var colliders = Physics.OverlapSphere(command.Position, command.Range,detectLayer);
var damaged= new List<IUnityEntity>();
foreach (var x in colliders.Where(x=>x.GetComponent<IDamagable>() is not null))
var _damaged = new Dictionary<ulong, IUnityEntity>();
var hits = colliders
.Where(x => x.GetComponent<IDamagable>() is not null)
.Where(x => MathV.IsForward(command.Position, command.Forward, x.transform.position))
.Select(x => x.GetComponent<IDamagable>())
.Where(damageable =>damageable.UnityEntity?.Id != command.PlayerId)
.Where(damageable =>
{
if (command.IgnoreTags is null
|| !(command.IgnoreTags?.Length > 0)
|| damageable.UnityEntity is null
|| !damageable.UnityEntity.TryGetComponent<ITag>(out var iTags)) return true;
return !MathE.Contains(iTags.GetTags(), command.IgnoreTags);
})
.Where(x => x.UnityEntity is null || _damaged.TryAdd(x.UnityEntity.Id, x.UnityEntity))
;
if (command.Limit is not 0)
{
hits = hits.Take(command.Limit);
}
foreach (var x in hits)
{
try
{
var damageable = x.GetComponent<IDamagable>();
var toTarget = x.transform.position - (Vector3)command.Position;
toTarget = Vector3.ProjectOnPlane(toTarget, Vector3.up);
var damageable = x;
// 获取正前方的向量
var forward = command.Forward;
// 计算点积
var dotProduct = Vector3.Dot(toTarget.normalized, forward);
if (dotProduct < 0.8f) continue;
if (damaged.Contains(damageable.UnityEntity) || damageable.UnityEntity?.Id == command.PlayerId)
if (command.ForceHitStun)
{
continue;
if (damageable is not null && damageable.UnityEntity is not null && damageable.UnityEntity.TryGetComponent<IMeleeCombat>(out var combat))
{
combat.HitStun();
}
}
damaged.Add(damageable.UnityEntity);
var damageMsg =
new DamageMessage()
{
@@ -87,18 +98,18 @@ namespace BITFALL.Melee
damageable.Rigidbody.AddForceAtPositionAsync(command.Force, command.Position, ForceMode.Impulse)
.Forget();
if (x.TryGetComponent<ITag>(out var _tag))
if ((x as MonoBehaviour)!.TryGetComponent<ITag>(out var _tag))
{
DI.Get<VFXService>().Spawn(new Location
{
position = x.transform.position,
position = x.Rigidbody.position,
//rotation = Quaternion.identity,
}, _tag.GetTags());
}
}
catch (UnassignedReferenceException e)
{
Debug.LogWarning(x.name);
Debug.LogWarning(x);
Debug.LogException(e);
}