65 lines
2.6 KiB
C#
65 lines
2.6 KiB
C#
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);
|
|
|
|
/// <summary>Isolated426BE8/426DAC/429DC9/42A077 scalar contracts. Does not
|
|
/// perform ray queries, body constraint, camera/visual ownership or live equip.</summary>
|
|
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<length?(float)(length-(double)seconds*950):length;
|
|
}
|
|
|
|
public static GrapplerSwing Swing(GrapplerSwing state,float seconds,float offsetX,float offsetZ,float length)
|
|
{
|
|
Finite(state.X);Finite(state.Z);Finite(state.Elapsed);Time(seconds);
|
|
Finite(offsetX);Finite(offsetZ);Finite(length);
|
|
float time=state.Elapsed+seconds;
|
|
float x=(float)(state.X-(double)offsetX*seconds*.17);
|
|
//42A0C2 stores Z but retains its unrounded x87 value through damping.
|
|
double z=state.Z-(double)offsetZ*seconds*.17;
|
|
if(time>=.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);}
|
|
}
|