using System.Numerics; namespace GamePort.Game; public readonly record struct GrapplerAttachment(float Length,float InitialLength,float? RopeScaleZ, float FastReelTarget,Vector3 Velocity); public readonly record struct GrapplerSwing(float X,float Z,float Elapsed); /// Isolated426BE8/426DAC/429DC9/42A077 scalar contracts. Does not /// perform ray queries, body constraint, camera/visual ownership or live equip. public static class GrapplerMotion { public static GrapplerAttachment Attach(Vector3 root,Vector3 anchor,Vector3 velocity,float initialLength=0) { Finite(root);Finite(anchor);Finite(velocity);Finite(initialLength); double x=(double)anchor.X-root.X,y=(double)anchor.Y-root.Y,z=(double)anchor.Z-root.Z; float length=(float)(Math.Sqrt(x*x+y*y+z*z)-100); return new(length,initialLength==0?length:initialLength, initialLength==0?(float)((double)length*.0016666667070239782f):null, (float)((double)anchor.Y-root.Y-200),velocity with{Y=100}); } public static float HeldReel(float length,float seconds) { Finite(length);Time(seconds); return length>250?(float)(length-(double)seconds*250):length; } public static float FastReel(float length,float target,float seconds) { Finite(length);Finite(target);Time(seconds); return target=.2) { float gain=length<350?.95f:.98f; x=(float)(Math.Clamp(x,-50,50)*(double)gain); z=Math.Clamp(z,-50,50)*gain; time-=.2f; } return new(x,(float)z,time); } public static bool JumpDetaches(bool jumpHeld,bool fireHeld,bool attached)=>jumpHeld&&!fireHeld&&attached; internal static void Time(float value) { if(!float.IsFinite(value)||value<0||value>=1)throw new ArgumentOutOfRangeException(nameof(value)); } internal static void Finite(float value) { if(!float.IsFinite(value))throw new ArgumentOutOfRangeException(nameof(value)); } internal static void Finite(Vector3 value){Finite(value.X);Finite(value.Y);Finite(value.Z);} }