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 operator /(Vector3 v,float d)=>v*(1/d);public static float Distance(Vector3 a,Vector3 b)=>(a-b).magnitude;public static Vector3 Cross(Vector3 a,Vector3 b)=>new Vector3(a.y*b.z-a.z*b.y,a.z*b.x-a.x*b.z,a.x*b.y-a.y*b.x);public static Vector3 Lerp(Vector3 a,Vector3 b,float t)=>a+(b-a)*Mathf.Clamp01(t);}
public static class Mathf{public static float Min(float a,float b)=>Math.Min(a,b);public static int Min(int a,int b)=>Math.Min(a,b);public static float Sqrt(float v)=>(float)Math.Sqrt(v);public static float Sin(float v)=>(float)Math.Sin(v);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 class UObj{public static implicit operator bool(UObj v)=>v!=null;}
public class Transform{public Vector3 position,forward=new Vector3(0,0,1);}
public class GameObject:UObj{public readonly Dictionary<Type,object> parts=new Dictionary<Type,object>();public Transform transform=new Transform();public T GetComponent<T>()where T:class=>parts.TryGetValue(typeof(T),out var x)?x as T:null;public T AddComponent<T>()where T:Component,new(){var t=new T{gameObject=this};parts[typeof(T)]=t;return t;}}
public class Component:UObj{public GameObject gameObject;public Transform transform=>gameObject.transform;public T GetComponent<T>()where T:class=>gameObject.GetComponent<T>();}
public class CharacterBody:Component{public static List<CharacterBody> readOnlyInstancesList=new List<CharacterBody>();public Health healthComponent=new Health();public TeamComponent teamComponent=new TeamComponent();public Input inputBank=new Input();public Motor characterMotor;public bool isBoss;public Vector3 corePosition=>transform.position+Vector3.up;public Vector3 footPosition=>transform.position;public void AddTimedBuff(object b,float t){} public static CharacterBody Make(Vector3 point,int team=2){var go=new GameObject();go.transform.position=point;var b=go.AddComponent<CharacterBody>();b.teamComponent.teamIndex=team;readOnlyInstancesList.Add(b);return b;}}
public class Health:UObj{public bool alive=true;}
public class TeamComponent:UObj{public int teamIndex=2;}
public struct TeamMask{int owner;public static TeamMask GetUnprotectedTeams(int t)=>new TeamMask{owner=t};public bool HasTeam(int t)=>t>0&&t!=owner;}
public class Input:UObj{public Vector3 aimDirection=new Vector3(0,0,1);}
public class CapsuleCollider:Component{public Bounds bounds;}
public struct Bounds{public Vector3 center,min;}
public class CharacterMotor{public struct HitGroundInfo{}public delegate void HitGroundDelegate(ref HitGroundInfo i);}
public class Motor:Component{public bool isGrounded;public Vector3 velocity;public event CharacterMotor.HitGroundDelegate onHitGroundAuthority;public void Hit(){var h=new CharacterMotor.HitGroundInfo();onHitGroundAuthority?.Invoke(ref h);}}
public class Controller{public int released;public void Motion(string n,float d,bool full){}public void ReleaseLowerBody(){released++;}}
public class Machine{public LashCastState Next;public int Exits;public void SetNextState(LashCastState s){Next=s;}public void SetNextStateToMain(){Exits++;}}
public class LashCastState{public CharacterBody characterBody;public Motor characterMotor;public Controller controller=new Controller();public Machine outer=new Machine();public bool isAuthority=true;public float fixedAge;public object gameObject=>characterBody.gameObject;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 class NetworkWriter{public List<object> Data=new List<object>();public void Write(byte x)=>Data.Add(x);public void Write(Vector3 x)=>Data.Add(x);public void Write(GameObject x)=>Data.Add(x);}
public class NetworkReader{readonly Queue<object> data;public NetworkReader(NetworkWriter w){data=new Queue<object>(w.Data);}public byte ReadByte()=>(byte)data.Dequeue();public Vector3 ReadVector3()=>(Vector3)data.Dequeue();public GameObject ReadGameObject()=>(GameObject)data.Dequeue();}
public static class NetworkServer{public static bool active=true;}
public static class Time{public static float fixedDeltaTime=.02f;}
public static class LashAudio{public static void Play(object a,string b,float c){}}
public static class LashEffects{public static int Impacts;public static void Cast(CharacterBody a,string b,float c){}public static void Impact(CharacterBody b,Vector3 p,float d){Impacts++;}}
public static class LashTargeting{public static List<CharacterBody> NearbyResults=new List<CharacterBody>();public static Dictionary<CharacterBody,int> Hits=new Dictionary<CharacterBody,int>();public static IEnumerable<CharacterBody> Nearby(CharacterBody b,Vector3 p,float r)=>NearbyResults;public static void Damage(CharacterBody a,CharacterBody b,float c){if(!Hits.ContainsKey(b))Hits[b]=0;Hits[b]++;}}
public static class RoR2Content{public static class Buffs{public static object Slow50=new object();}}
public class LashSlamVictim:Component{public int lands,releases;public void Begin(CharacterBody b){}public void Throw(Vector3 d,Vector3 p,float s){}public void Land(Vector3 p){lands++;}public void Release(){releases++;}}
public class Test
{
 static void Check(bool ok,string m){if(!ok)throw new Exception(m);}
 static LashDeathSlamThrowState Cast(){Physics.Floor=false;var b=CharacterBody.Make(new Vector3(0,18,0),1);var motor=b.gameObject.AddComponent<Motor>();b.characterMotor=motor;var s=new LashDeathSlamThrowState{characterBody=b,characterMotor=motor,Landing=new Vector3(14,0,0)};s.OnEnter();return s;}
 public static void Main()
 {
  CharacterBody.readOnlyInstancesList.Clear();var owner=CharacterBody.Make(Vector3.zero,1);
  var points=new[]{new Vector3(10,0,0),new Vector3(-10,0,0),new Vector3(0,0,-10),new Vector3(0,0,10),new Vector3(0,10,0),new Vector3(0,-10,0)};
  foreach(var p in points)CharacterBody.Make(p);CharacterBody.Make(new Vector3(36,0,0));CharacterBody.Make(new Vector3(1,0,0),1);var dead=CharacterBody.Make(new Vector3(1,0,0));dead.healthComponent.alive=false;
  var acquired=LashDeathSlamRules.Acquire(owner);Check(acquired.Length==6,"Sphere ignored direction or included ally/dead/out-of-range target");Console.WriteLine("Actual acquisition: enemies front/back/left/right/above/below included; self/ally/dead/outside excluded PASS");
  for(int i=0;i<40;i++)CharacterBody.Make(new Vector3(2+i*.1f,0,0));acquired=LashDeathSlamRules.Acquire(owner);Check(acquired.Length==32&&acquired.Distinct().Count()==32,"Crowd count/dedup incorrect");Console.WriteLine("Actual acquisition: 32-target crowd cap and uniqueness PASS");
  var state=Cast();state.fixedAge=.2f;state.FixedUpdate();Check(state.characterMotor.velocity.y==0&&state.outer.Next==null,"Pull phase should hover");state.fixedAge=.5f;state.FixedUpdate();Check(state.characterMotor.velocity.y<0&&state.characterMotor.velocity.x>0,"Caster does not dive toward marker");Check(LashEffects.Impacts==0,"Premature impact");state.fixedAge=2;state.FixedUpdate();Check(state.outer.Next==null&&LashEffects.Impacts==0&&state.characterMotor.velocity.y<0,"Timer faked a ground impact");state.characterMotor.Hit();state.FixedUpdate();Check(state.outer.Next is LashDeathSlamImpactState,"Actual motor contact did not enter impact state");Console.WriteLine("Actual throw: hover -> aimed caster descent; elapsed timer cannot explode; ground-hit enters impact PASS");
  var cancelled=Cast();cancelled.fixedAge=5.1f;cancelled.FixedUpdate();Check(cancelled.outer.Exits==1&&LashEffects.Impacts==0,"Invalid landing caused a timer explosion");Console.WriteLine("Actual throw: invalid landing timeout cancels without explosion PASS");
  var fallback=Cast();fallback.fixedAge=.5f;Physics.Floor=true;fallback.FixedUpdate();Check(fallback.outer.Next is LashDeathSlamImpactState,"Physical floor fallback failed");Physics.Floor=false;Console.WriteLine("Actual throw: floor probe contact fallback PASS");
  var target=CharacterBody.Make(Vector3.zero);var victim=target.gameObject.AddComponent<LashSlamVictim>();LashTargeting.NearbyResults.Clear();LashTargeting.NearbyResults.Add(target);LashTargeting.Hits.Clear();LashEffects.Impacts=0;
  var impact=new LashDeathSlamImpactState{characterBody=state.characterBody,characterMotor=state.characterMotor,Point=Vector3.zero,Targets=new[]{target.gameObject}};impact.OnEnter();Check(LashEffects.Impacts==1&&victim.lands==1&&victim.releases==1&&LashTargeting.Hits[target]==1,"Not one coordinated impact or duplicate target damage");Console.WriteLine("Actual impact: one explosion, target landing/release, deduplicated captured + area damage PASS");
  LashTargeting.NearbyResults.Clear();LashTargeting.Hits.Clear();impact.OnEnter();Check(LashTargeting.Hits[target]==1,"Captured target missed due to stale sphere collider");Console.WriteLine("Actual impact: captured target damaged even when collider query is empty PASS");
  var writer=new NetworkWriter();LashDeathSlamRules.WriteTargets(writer,acquired.Select(b=>b.gameObject).ToArray());var decoded=LashDeathSlamRules.ReadTargets(new NetworkReader(writer));Check(decoded.Length==32&&decoded[31]==acquired[31].gameObject,"Target payload mismatch");writer=new NetworkWriter();writer.Write((byte)33);bool rejected=false;try{LashDeathSlamRules.ReadTargets(new NetworkReader(writer));}catch(InvalidOperationException){rejected=true;}Check(rejected,"Invalid payload accepted");Console.WriteLine("Actual target codec: 32 references roundtrip; oversized payload rejected PASS (fixture codec)");
 }
}
