using System;using System.Linq;using System.Collections.Generic;
public struct Vector3{public float x,y,z;public Vector3(float a,float b,float c){x=a;y=b;z=c;}public static Vector3 up=>new Vector3(0,1,0);public static Vector3 down=>new Vector3(0,-1,0);public static Vector3 zero=>new Vector3();public float sqrMagnitude=>x*x+y*y+z*z;public float magnitude=>(float)Math.Sqrt(sqrMagnitude);public Vector3 normalized=>magnitude>0?this*(1/magnitude):zero;public static Vector3 operator +(Vector3 a,Vector3 b)=>new Vector3(a.x+b.x,a.y+b.y,a.z+b.z);public static Vector3 operator -(Vector3 a,Vector3 b)=>new Vector3(a.x-b.x,a.y-b.y,a.z-b.z);public static Vector3 operator *(Vector3 a,float b)=>new Vector3(a.x*b,a.y*b,a.z*b);public static float Dot(Vector3 a,Vector3 b)=>a.x*b.x+a.y*b.y+a.z*b.z;public static Vector3 ProjectOnPlane(Vector3 a,Vector3 n)=>a-n*Dot(a,n);public static Vector3 ClampMagnitude(Vector3 v,float max)=>v.magnitude>max?v.normalized*max:v;public static Vector3 Lerp(Vector3 a,Vector3 b,float t)=>a+(b-a)*Mathf.Clamp01(t);}
public static class Mathf{public const float Deg2Rad=(float)Math.PI/180;public static float Max(float a,float b)=>Math.Max(a,b);public static float Clamp(float v,float a,float b)=>Math.Max(a,Math.Min(b,v));public static float Clamp01(float v)=>Clamp(v,0,1);public static float Cos(float a)=>(float)Math.Cos(a);public static float SmoothStep(float a,float b,float t){t=Clamp01(t);return a+(b-a)*t*t*(3-2*t);}}
public enum QueryTriggerInteraction{Ignore}
public struct RaycastHit{public Vector3 normal;}
public static class Physics{public static bool Floor;public static bool Raycast(Vector3 a,Vector3 b,out RaycastHit hit,float distance,int mask,QueryTriggerInteraction q){hit=new RaycastHit{normal=Vector3.up};return Floor;}}
public sealed class Mask{public int mask;}
public static class LayerIndex{public static Mask world=new Mask();}
public static class NetworkServer{public static bool active=false;}
public sealed class Body{public Vector3 footPosition,corePosition;}
public class CharacterMotor{public struct HitGroundInfo{}public delegate void HitGroundDelegate(ref HitGroundInfo info);}
public class CapsuleCollider{public static implicit operator bool(CapsuleCollider c)=>c!=null;public Bounds bounds;}
public struct Bounds{public Vector3 center,min;}
public sealed class Motor{public event CharacterMotor.HitGroundDelegate onHitGroundAuthority;public T GetComponent<T>()where T:class=>null;public void GroundHit(){var info=new CharacterMotor.HitGroundInfo();onHitGroundAuthority?.Invoke(ref info);}public static implicit operator bool(Motor m)=>m!=null;public bool isGrounded;public Vector3 velocity;}
public sealed class Input{public static implicit operator bool(Input i)=>i!=null;public Vector3 moveVector;}
public sealed class Direction{public Vector3 forward=new Vector3(0,0,1);}
public sealed class Controller{public int AirFinishes,GroundFinishes,Loops;public void GroundStrikeFinish(bool aerial=true){if(aerial)AirFinishes++;else GroundFinishes++;}public void Voice(int i){}public void Motion(string n,float d,bool f){if(n.EndsWith("_loop"))Loops++;}}
public sealed class Machine{public int Exits;public LashCastState Next;public void SetNextState(LashCastState s){Next=s;}public void SetNextStateToMain(){Exits++;}}
public struct Ray{public Vector3 direction;}
public class LashCastState{public Body characterBody=new Body();public Motor characterMotor=new Motor();public Input inputBank=new Input();public Direction characterDirection=new Direction();public Controller controller=new Controller();public Machine outer=new Machine();public object gameObject=new object();public bool isAuthority=true;public float fixedAge;public Vector3 Aim=new Vector3(0,0,1);public virtual void OnEnter(){}public virtual void OnExit(){}public virtual void FixedUpdate(){}public virtual void OnSerialize(NetworkWriter w){}public virtual void OnDeserialize(NetworkReader r){}public Ray GetAimRay()=>new Ray{direction=Aim};}
public class NetworkWriter{public List<object> Data=new List<object>();public void Write(bool x)=>Data.Add(x);public void Write(float x)=>Data.Add(x);public void Write(Vector3 x)=>Data.Add(x);}
public class NetworkReader{readonly Queue<object> data;public NetworkReader(NetworkWriter w){data=new Queue<object>(w.Data);}public bool ReadBoolean()=>(bool)data.Dequeue();public float ReadSingle()=>(float)data.Dequeue();public Vector3 ReadVector3()=>(Vector3)data.Dequeue();}
public static class LashAudio{public static void Play(object a,string b,float c){}}
public static class LashEffects{public static void Cast(Body a,string b,float c){}}
public static class LashTargeting{public static Body[] Nearby(Body b,Vector3 p,float r)=>Array.Empty<Body>();public static void Damage(Body a,Body b,float c){}}
public class Test
{
 static void Check(bool x,string s){if(!x)throw new Exception(s);}
 static LashGroundStrikeState Dive(){Physics.Floor=false;var s=new LashGroundStrikeState();s.OnEnter();s.fixedAge=.16f;s.FixedUpdate();Check(s.characterMotor.velocity.z>20&&s.characterMotor.velocity.y<0,"No forward aimed descent");return s;}
 static void Contact(int type){var s=Dive();if(type==0)s.characterMotor.isGrounded=true;else if(type==1)Physics.Floor=true;else s.characterMotor.GroundHit();s.fixedAge=.18f;s.FixedUpdate();var impact=s.outer.Next as LashGroundStrikeImpactState;Check(impact!=null&&impact.Aerial,"No explicit aerial impact state");s.OnExit();impact.characterMotor=s.characterMotor;impact.controller=s.controller;impact.OnEnter();Check(impact.controller.AirFinishes==1&&impact.characterMotor.velocity.z==0&&impact.characterMotor.velocity.x==0,"No aerial animation / momentum retained");impact.fixedAge=.26f;impact.FixedUpdate();Check(impact.outer.Exits==1,"Recovery failed to return control");Console.WriteLine("Ground contact "+type+": actual dive -> impact state, aerial recovery and momentum clear PASS");}
 public static void Main(){Contact(0);Contact(1);Contact(2);var s=Dive();s.Aim=new Vector3(1,0,0);s.fixedAge=.3f;s.FixedUpdate();Check(s.characterMotor.velocity.x>20&&Math.Abs(s.characterMotor.velocity.z)<.001,"Aim not updated in flight");s.inputBank.moveVector=new Vector3(0,0,1);s.fixedAge=.32f;s.FixedUpdate();Check(s.characterMotor.velocity.z>0,"Movement input ignored");Check(s.outer.Next==null,"Premature impact");Console.WriteLine("Actual dive: live aim steering + movement input + continued airborne descent PASS");
 var grounded=new LashGroundStrikeState();grounded.characterMotor.isGrounded=true;grounded.OnEnter();grounded.fixedAge=.22f;grounded.FixedUpdate();var groundHit=(LashGroundStrikeImpactState)grounded.outer.Next;groundHit.controller=grounded.controller;groundHit.OnEnter();Check(groundHit.controller.GroundFinishes==1&&groundHit.controller.AirFinishes==0,"Ground and air animations conflated");Console.WriteLine("Grounded recovery remains separate PASS");
 var wire=new NetworkWriter();var original=new LashGroundStrikeImpactState{Aerial=true,Height=17,Direction=new Vector3(1,0,0)};original.OnSerialize(wire);var remote=new LashGroundStrikeImpactState();remote.OnDeserialize(new NetworkReader(wire));Check(remote.Aerial&&remote.Height==17&&remote.Direction.x==1,"State payload lost");Console.WriteLine("Actual impact-state payload roundtrip PASS (fixture codec, not live networking)");
 var origin=new Vector3(12,2,0);var caster=new Vector3(0,18,0);var lift=LashSlamTrajectory.Lift(origin,caster,.8f);Check(lift.y==20&&lift.x==12,"Victim not raised to caster altitude");var gather=new Vector3(0,18,3);var destination=new Vector3(20,0,8);var start=LashSlamTrajectory.Sample(lift,gather,destination,0);var pulled=LashSlamTrajectory.Sample(lift,gather,destination,.3f);var slam=LashSlamTrajectory.Sample(lift,gather,destination,LashSlamTrajectory.TotalSeconds);Check(start.y==20&&pulled.y==18&&pulled.z==3&&slam.y==0&&slam.x==20,"Lift/pull/slam sequence incorrect");Check(LashSlamTrajectory.Sample(lift,gather,destination,.15f).y>17,"Victim pulled to floor before slam");Console.WriteLine("Actual trajectory: caster-height lift -> pull near caster -> aimed ground slam PASS");}
}
