36 lines
868 B
C#
36 lines
868 B
C#
using UnityEngine;
|
|
|
|
public class InvulnerabilityInterceptor : BrokerInterceptor
|
|
{
|
|
Health health;
|
|
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
|
|
health = GetComponentInParent<Health>();
|
|
|
|
broker.OnIncomingDamage.Subscribe(HandleInvulnerability, GameConstants.BrokerEventPriority.Invulnerability);
|
|
}
|
|
|
|
|
|
private void HandleInvulnerability(DamageArgs args)
|
|
{
|
|
InvulnerabilityArgs invulnerabilityArgs = CObjectPool<InvulnerabilityArgs>.Get();
|
|
|
|
invulnerabilityArgs.user = user;
|
|
invulnerabilityArgs.isImmune = false;
|
|
|
|
|
|
if(health.Invulnerable)
|
|
{
|
|
args.currentValue = 0;
|
|
invulnerabilityArgs.isImmune = true;
|
|
}
|
|
|
|
broker.OnInvulnerable.Invoke(invulnerabilityArgs);
|
|
|
|
CObjectPool<InvulnerabilityArgs>.Release(invulnerabilityArgs);
|
|
}
|
|
}
|