1
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user