66 lines
1.9 KiB
C#
66 lines
1.9 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using BITFALL.Entities;
|
|
using BITKit;
|
|
using BITKit.Entities;
|
|
using BITKit.Sensors;
|
|
using UnityEngine;
|
|
using UnityEngine.Pool;
|
|
|
|
namespace BITFALL.Props
|
|
{
|
|
public struct ExplosionDamageMessage : IDamageType,IPlayerExplosionDamage
|
|
{
|
|
}
|
|
public class Prop_Explosive : MonoBehaviour
|
|
{
|
|
[SerializeReference, SubclassSelector] private ISensor rangeSensor;
|
|
[SerializeReference, SubclassSelector] private IReference[] vfxTags;
|
|
[SerializeField] private LayerMask physicsLayer;
|
|
[SerializeField] private float explosionRadius;
|
|
[SerializeField] private AnimationCurve damageCurve;
|
|
|
|
public virtual void Explosion(GameObject root = null)
|
|
{
|
|
var damaged = ListPool<ulong>.Get();
|
|
|
|
DI.Get<VFXService>().Spawn(new Location(transform), vfxTags.Select(x => x.Value).ToArray());
|
|
foreach (var x in rangeSensor.Get())
|
|
{
|
|
if (x.TryGetComponent<Entity>(out var entity) is false) continue;
|
|
if(entity.TryGetComponent<IStunObject>(out var stunObject))
|
|
{
|
|
stunObject.Stun(Vector3.Distance(transform.position, entity.transform.position), 0.5f);
|
|
}
|
|
if (damaged.TryAdd(entity.Id))
|
|
{
|
|
DamageService.Singleton.Execute(new DamageMessage()
|
|
{
|
|
Target = entity,
|
|
Damage = (int)damageCurve.Evaluate(Vector3.Distance(transform.position,
|
|
entity.transform.position)),
|
|
DamageType = new ExplosionDamageMessage()
|
|
});
|
|
// entity.Invoke<DamageMessage>(new DamageMessage()
|
|
// {
|
|
// Target = entity,
|
|
// Damage = (int)damageCurve.Evaluate(Vector3.Distance(transform.position,
|
|
// entity.transform.position))
|
|
// });
|
|
}
|
|
}
|
|
|
|
damaged.Clear();
|
|
ListPool<ulong>.Release(damaged);
|
|
PhysicsHelper.Explosion(transform.position, explosionRadius, physicsLayer, 1024 * 8);
|
|
Destroy(gameObject);
|
|
if (root)
|
|
{
|
|
Destroy(root);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|