RiftMayhem/Assets/Scripts/EntityBroker/ScrollingTextInterceptor.cs

79 lines
2.9 KiB
C#

using UnityEngine;
public class ScrollingTextInterceptor : BrokerInterceptor
{
public ScrollingText scrollingTextPrefab;
protected ScrollingText scrollingText;
protected override void Awake()
{
base.Awake();
broker.OnInvulnerable.Subscribe(OnInvulnerable);
broker.OnDodge.Subscribe(OnDodge);
broker.OnBlock.Subscribe(OnBlock);
broker.OnIncomingDamageProcessed.Subscribe(OnDamage);
broker.OnIncomingHealProcessed.Subscribe(OnHeal);
}
private void OnInvulnerable(InvulnerabilityArgs args)
{
if (!args.isImmune) return;
if (scrollingTextPrefab != null)
{
scrollingText = GameObjectPoolManager.Instance.Get(scrollingTextPrefab.gameObject, this.transform.position + new Vector3(Random.Range(-0.5f, 0.5f), 2f, Random.Range(-0.5f, 0.5f)), Quaternion.identity).GetComponent<ScrollingText>();
scrollingText.Show("Invulnerable", Color.gray, 1.5f);
}
}
private void OnDodge(DodgeArgs args)
{
if (!args.dodgedSuccessfully) return;
if (scrollingTextPrefab != null)
{
scrollingText = GameObjectPoolManager.Instance.Get(scrollingTextPrefab.gameObject, this.transform.position + new Vector3(Random.Range(-0.5f, 0.5f), 2f, Random.Range(-0.5f, 0.5f)), Quaternion.identity).GetComponent<ScrollingText>();
scrollingText.ShowDodge("Dodge!");
}
}
private void OnBlock(BlockArgs args)
{
if (!args.blockedSuccessfully) return;
if (scrollingTextPrefab != null)
{
scrollingText = GameObjectPoolManager.Instance.Get(scrollingTextPrefab.gameObject, this.transform.position + new Vector3(Random.Range(-0.5f, 0.5f), 2f, Random.Range(-0.5f, 0.5f)), Quaternion.identity).GetComponent<ScrollingText>();
scrollingText.ShowBlock("Blocked!");
}
}
private void OnDamage(DamageArgs args)
{
if (scrollingTextPrefab != null && args.currentValue < 0)
{
scrollingText = GameObjectPoolManager.Instance.Get(scrollingTextPrefab.gameObject, this.transform.position + new Vector3(Random.Range(-0.5f, 0.5f), 2f, Random.Range(-0.5f, 0.5f)), Quaternion.identity).GetComponent<ScrollingText>();
if (args.isCrit)
scrollingText.ShowCrit(args.currentValue.ToString("0.0"));
else
scrollingText.ShowHit(args.currentValue.ToString("0.0"));
}
}
private void OnHeal(HealArgs args)
{
if (scrollingTextPrefab != null && args.currentValue > 0)
{
scrollingText = GameObjectPoolManager.Instance.Get(scrollingTextPrefab.gameObject, this.transform.position + new Vector3(Random.Range(-0.5f, 0.5f), 2f, Random.Range(-0.5f, 0.5f)), Quaternion.identity).GetComponent<ScrollingText>();
scrollingText.ShowHeal(args.currentValue.ToString("0.0"));
}
}
}