using System;using System.Linq;
 public sealed class LashGroundStrikeState:LashCastState
 {
  float highest;bool impacted,startedInAir,loopStarted;Vector3 direction;
  public override void OnEnter(){base.OnEnter();highest=characterBody.footPosition.y;startedInAir=characterMotor&&!characterMotor.isGrounded;direction=Vector3.ProjectOnPlane(GetAimRay().direction,Vector3.up).normalized;if(direction.sqrMagnitude<.01f)direction=characterDirection.forward;controller?.Voice(1);if(startedInAir)controller?.Motion("ability_groundstrike_airdrop_start",.3f,true);else controller?.GroundStrikeFinish(false);LashAudio.Play(gameObject,"lash_ground_strike_downstrike_",.75f);if(startedInAir)LashEffects.Cast(characterBody,"groundstrike_air",.7f);}
  public override void FixedUpdate()
  {
   base.FixedUpdate();highest=Mathf.Max(highest,characterBody.footPosition.y);
   if(!impacted)
   {
    // Test contact BEFORE writing the downward dive velocity. The floor probe
    // also handles contact frames where the motor's grounded flag lags behind.
    bool contact=characterMotor&&characterMotor.isGrounded;
    if(startedInAir&&fixedAge>.2f&&!contact&&characterMotor&&characterMotor.velocity.y<=0)
     contact=Physics.Raycast(characterBody.footPosition+Vector3.up*.15f,Vector3.down,out var hit,.35f,LayerIndex.world.mask,QueryTriggerInteraction.Ignore)&&hit.normal.y>.35f;
    if((!startedInAir&&fixedAge>=.2f)||(startedInAir&&fixedAge>.2f&&contact)||fixedAge>8)Impact();
    else if(startedInAir&&fixedAge>.15f&&isAuthority&&characterMotor)
    {
     characterMotor.velocity=Vector3.down*50+direction*9;
     if(!loopStarted){loopStarted=true;controller?.Motion("ability_groundstrike_airdrop_loop",8f,true);}
    }
   }
   if(impacted&&fixedAge>=impactAt+.2f&&isAuthority)outer.SetNextStateToMain();
  }
  float impactAt;
  void Impact(){impacted=true;impactAt=fixedAge;if(isAuthority&&characterMotor){var v=characterMotor.velocity;if(v.y<0)v.y=0;characterMotor.velocity=v;}if(startedInAir)controller?.GroundStrikeFinish();LashEffects.Cast(characterBody,"groundstrike_impact",1.4f);LashAudio.Play(gameObject,"lash_ground_strike_impact",.8f);if(NetworkServer.active){float height=Mathf.Clamp(highest-characterBody.footPosition.y,0,25),coefficient=5+height*.45f;foreach(var target in LashTargeting.Nearby(characterBody,characterBody.footPosition,10).ToArray()){var offset=Vector3.ProjectOnPlane(target.corePosition-characterBody.corePosition,Vector3.up);if(offset.sqrMagnitude<4||Vector3.Dot(offset.normalized,direction)>=Mathf.Cos(60*Mathf.Deg2Rad))LashTargeting.Damage(characterBody,target,coefficient);}}}
 }
