1
This commit is contained in:
@@ -61,12 +61,13 @@ namespace BITKit.Entities
|
||||
}
|
||||
public record DamageMessage
|
||||
{
|
||||
public IEntity initiator;
|
||||
public IEntity target;
|
||||
public int damage;
|
||||
public IDamagable hit;
|
||||
public Location location;
|
||||
public IDamageType damageType;
|
||||
public IEntity Initiator;
|
||||
public IEntity Target;
|
||||
public bool RawDamage;
|
||||
public int Damage;
|
||||
public IDamagable Hit;
|
||||
public Location Location;
|
||||
public IDamageType DamageType;
|
||||
}
|
||||
public interface IDamageCallback
|
||||
{
|
||||
@@ -92,13 +93,13 @@ namespace BITKit.Entities
|
||||
{
|
||||
while (Messages.TryDequeue(out var damageMessage))
|
||||
{
|
||||
var unityEntity = (Entity)damageMessage.target;
|
||||
var unityEntity = (Entity)damageMessage.Target;
|
||||
if (unityEntity is null || !unityEntity.TryGetComponent<IHealth>(out var heal) || !heal.IsAlive) continue;
|
||||
|
||||
damageMessage.initiator?.Invoke(damageMessage);
|
||||
damageMessage.target?.Invoke(damageMessage);
|
||||
damageMessage.Initiator?.Invoke(damageMessage);
|
||||
damageMessage.Target?.Invoke(damageMessage);
|
||||
|
||||
foreach (var x in damageMessage.target?.GetCallbacks<IDamageCallback>()!)
|
||||
foreach (var x in damageMessage.Target?.GetCallbacks<IDamageCallback>()!)
|
||||
{
|
||||
x.OnGetDamage(damageMessage);
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Remoting.Contexts;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
@@ -19,7 +20,7 @@ namespace BITKit.Entities
|
||||
/// <summary>
|
||||
/// 当受到伤害时的回调
|
||||
/// </summary>
|
||||
public event Func<DamageMessage,int,int> OnDamage;
|
||||
public event Func<DamageMessage,int,int> OnDamageFactory;
|
||||
int HealthPoint { get; set; }
|
||||
int MaxHealthPoint { get; set; }
|
||||
bool IsAlive { get; }
|
||||
@@ -33,7 +34,7 @@ namespace BITKit.Entities
|
||||
|
||||
public event Action<int> OnSetHealthPoint;
|
||||
public event Action<bool> OnSetAlive;
|
||||
public event Func<DamageMessage,int, int> OnDamage;
|
||||
public event Func<DamageMessage,int, int> OnDamageFactory;
|
||||
|
||||
public int HealthPoint
|
||||
{
|
||||
@@ -82,11 +83,13 @@ namespace BITKit.Entities
|
||||
|
||||
private void OnGetDamage(DamageMessage damageMessage)
|
||||
{
|
||||
if (damageMessage.target != entity) return;
|
||||
var damage = damageMessage.damage;
|
||||
foreach (var x in OnDamage.CastAsFunc())
|
||||
if (damageMessage.Target != entity) return;
|
||||
if (IsAlive is false) return;
|
||||
var damage = damageMessage.Damage;
|
||||
foreach (var x in OnDamageFactory.CastAsFunc().Reverse())
|
||||
{
|
||||
damage = x.Invoke(damageMessage,damage);
|
||||
damage = x.Invoke(damageMessage,damage);
|
||||
if (damage <= 0) break;
|
||||
}
|
||||
AddHP(-damage);
|
||||
}
|
||||
|
@@ -21,7 +21,7 @@ namespace BITKit.Entities
|
||||
}
|
||||
private void OnGetDamage(DamageMessage obj)
|
||||
{
|
||||
if (obj.target != entity) return;
|
||||
if (obj.Target != entity) return;
|
||||
DamageMessages.Enqueue(obj);
|
||||
onGetDamage?.Invoke(obj);
|
||||
foreach (var x in callbacks)
|
||||
|
Reference in New Issue
Block a user