Aetheria/Assets/Scripts/Gameplay/Weapons/Lightning.cs
2026-06-21 09:37:54 +01:00

80 lines
2.5 KiB
C#

using System;
using UnityEngine;
public class Lightning : MonoBehaviour
{
public LightningCompute LightningCompute;
public float HitRadius;
public float Damage { get; set; }
public float Penetration { get; set; }
public float Spread { get; set; }
public DamageType DamageType { get; set; }
public EntityInstance Source { get; set; }
public float Range { get; set; }
public EntityInstance Target { get; set; }
public Transform Barrel { get; set; }
private bool _colliderHit;
private Vector3 _colliderLocalPosition;
private Transform _colliderTransform;
private Vector3 _endpoint;
public void Fire()
{
_colliderHit = false;
LightningCompute.OnLeaderComplete = null;
LightningCompute.FixedEndpoint = false;
_endpoint = Barrel.position + Barrel.forward * Range;
if (AetheriaYmirPhysicsBridge.Instance.TryCastZoneHulls(
Source?.ZoneRenderer,
Source?.Entity,
Barrel.position,
Barrel.forward,
Range,
HitRadius,
out var hits))
{
foreach (var hit in hits)
{
var hull = hit.Hull;
var entity = hull.Entity;
if (entity.Shield != null && entity.Shield.Item.Active.Value)
{
LightningCompute.OnLeaderComplete = () =>
{
hit.Shield?.ShowHit(hit.Point, Mathf.Sqrt(Damage));
};
}
else
{
LightningCompute.OnLeaderComplete = null;
}
_colliderHit = true;
_colliderLocalPosition = hull.transform.InverseTransformPoint(hit.Point);
_colliderTransform = hull.transform;
LightningCompute.FixedEndpoint = true;
_endpoint = hit.Point;
break;
}
}
LightningCompute.OnPulseComplete = () =>
GetComponent<Prototype>().ReturnToPool();
LightningCompute.StartAnimation();
}
private void Update()
{
if (Barrel == null) return;
if (_colliderHit)
{
if (_colliderTransform) _endpoint = _colliderTransform.TransformPoint(_colliderLocalPosition);
}
LightningCompute.EndPosition = _endpoint;
LightningCompute.StartPosition = Barrel.position;
}
}