1
This commit is contained in:
@@ -41,33 +41,46 @@ 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<IEntity>();
|
||||
var damaged= new List<IUnityEntity>();
|
||||
foreach (var x in colliders.Where(x=>x.GetComponent<IDamagable>() is not null))
|
||||
{
|
||||
try
|
||||
{
|
||||
var damageable = x.GetComponent<IDamagable>();
|
||||
if (damaged.Contains(damageable.Entity) || damageable.Entity.Id == command.PlayerId)
|
||||
|
||||
var toTarget = x.transform.position - (Vector3)command.Position;
|
||||
|
||||
toTarget = Vector3.ProjectOnPlane(toTarget, Vector3.up);
|
||||
|
||||
// 获取正前方的向量
|
||||
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)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
damaged.Add(damageable.Entity);
|
||||
damaged.Add(damageable.UnityEntity);
|
||||
var damageMsg =
|
||||
new DamageMessage()
|
||||
{
|
||||
Initiator = UnityEntitiesService.Get(command.PlayerId) as IEntity,
|
||||
Initiator = UnityEntitiesService.Get(command.PlayerId) as IUnityEntity,
|
||||
DamageType = new MeleeDamageMessage
|
||||
{
|
||||
|
||||
},
|
||||
Target = damageable.Entity,
|
||||
Target = damageable.UnityEntity,
|
||||
Damage = command.Damage is 0 ? 64 : command.Damage,
|
||||
Hit = damageable,
|
||||
};
|
||||
if (command.PlayerId !=default)
|
||||
{
|
||||
damageMsg.Initiator = UnityEntitiesService.Get(command.PlayerId) as IEntity;
|
||||
damageMsg.Initiator = UnityEntitiesService.Get(command.PlayerId) as IUnityEntity;
|
||||
}
|
||||
damageService.Execute(damageMsg);
|
||||
|
||||
|
Reference in New Issue
Block a user