using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using BITKit; using BITKit.Entities; using BITKit.Sensors; using UnityEngine; namespace BITFALL.Props { public class Prop_BouncingBetty : MonoBehaviour { [SerializeReference,SubclassSelector] private ISensor rangeSensor; [SerializeReference, SubclassSelector] private IReference[] vfxTags; [SerializeField] private AnimationCurve damageCurve; [SerializeField] private LayerMask physicsLayer; [SerializeField] private float explosionRadius; [SerializeField] private float jumpForce; [SerializeField] private new Rigidbody rigidbody; private bool isTriggered; public async void OnDetected(Collider _collider) { if (isTriggered) return; isTriggered = true; var damaged = new List() ; rigidbody.AddForce(Vector3.up * jumpForce, ForceMode.Impulse); try { await Task.Delay(1000,destroyCancellationToken); } catch (OperationCanceledException) { return; } DI.Get().Spawn(new Location(transform), vfxTags.Select(x=>x.Value).ToArray()); foreach (var x in rangeSensor.Get()) { if (!x.TryGetComponent(out var entity)) continue; if(damaged.Contains(entity.Id))continue; entity.Invoke(new DamageMessage() { Target = entity, Damage = (int)damageCurve.Evaluate(Vector3.Distance(transform.position, entity.transform.position)) }); damaged.Add(entity.Id); } PhysicsHelper.Explosion(transform.position,explosionRadius,physicsLayer,1024*8); damaged.Clear(); Destroy(gameObject); } } }