34 lines
1.1 KiB
C#
34 lines
1.1 KiB
C#
|
|
using System.Collections.Generic;
|
||
|
|
using OTG.Lab06.Abilities;
|
||
|
|
using OTG.Lab06.Core;
|
||
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
namespace OTG.Lab06.Effects
|
||
|
|
{
|
||
|
|
public sealed class IceNovaEffect : AbilityEffect
|
||
|
|
{
|
||
|
|
[SerializeField] private float visualLifetime = 1.2f;
|
||
|
|
[SerializeField] private LayerMask hitMask = ~0;
|
||
|
|
|
||
|
|
public override void Activate(AbilityCastContext context)
|
||
|
|
{
|
||
|
|
transform.position = context.Caster.position + Vector3.up * 0.05f;
|
||
|
|
|
||
|
|
float radius = Mathf.Max(0.1f, context.Ability.castRange);
|
||
|
|
Collider[] hits = Physics.OverlapSphere(context.Caster.position, radius, hitMask, QueryTriggerInteraction.Ignore);
|
||
|
|
var damaged = new HashSet<IDamageable>();
|
||
|
|
|
||
|
|
foreach (Collider hit in hits)
|
||
|
|
{
|
||
|
|
IDamageable damageable = hit.GetComponentInParent<IDamageable>();
|
||
|
|
if (damageable != null && damageable.IsAlive && damageable.Transform != context.Caster && damaged.Add(damageable))
|
||
|
|
{
|
||
|
|
damageable.TakeDamage(context.Ability.damage);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
Destroy(gameObject, visualLifetime);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|