using System.Numerics; namespace GamePort.Game; /// Jimmy's raw6 aim/release state (42659F/426744). The twenty owned /// projectiles survive unequip; this object is reset only with the modern scene. /// Source evidence and precision boundaries: gameplay/baseball.md. public sealed class BaseballGadget { public const int PoolSize = 20; private readonly BaseballProjectile[] projectiles = Enumerable.Range(0, PoolSize).Select(_ => new BaseballProjectile()).ToArray(); public IReadOnlyList Projectiles => projectiles; public bool Equipped { get; private set; } public bool PendingThrow { get; private set; } public bool AimVisible { get; private set; } public float CameraPitch { get; private set; } = 10; public float CameraHeight { get; private set; } = 200; public float SavedPitch { get; private set; } public float DisplayPitch { get; private set; } public int NextSlot { get; private set; } public int Throws { get; private set; } public event Action? EquippedChanged; public event Action? Thrown; public void Equip() { Equipped = true; CameraHeight += 30; //429707..429713 complete7CC; cleanup resets its defaults. EquippedChanged?.Invoke(true); } public void Release() { Equipped = AimVisible = false; CameraPitch = 0; CameraHeight = 200; //42871D does not write Jimmy1E26/1E28 or destroy its AB4 pool. EquippedChanged?.Invoke(false); } public void StepInput(PlayerInput input, Vector3 root, Vector3 euler, bool supported, float energy, bool exempt, Action stop, Action shooting, Action adjustEnergy) { if (!input.Fire) { AimVisible = false; shooting(false); if (!PendingThrow) return; Thrown?.Invoke(); //4265A9 requests10 before the launch virtual. projectiles[NextSlot].Launch(root, euler, SavedPitch); NextSlot = (NextSlot + 1) % PoolSize; PendingThrow = false; Throws++; adjustEnergy(-1); return; } if (!Equipped) return; stop(); if (energy <= 0 && !exempt || !supported) return; shooting(true); AimVisible = true; DisplayPitch = SavedPitch; if (!PendingThrow) { PendingThrow = true; return; //First hold arms without refreshing the saved pitch. } CameraPitch = Math.Clamp(CameraPitch, 0, 45); SavedPitch = CameraPitch; } public void StepCameraInput(PlayerInput input) { if (!Equipped) { CameraPitch=10; return; } if (!input.Fire) return; if (input.Backward) CameraPitch -= 20 * FixedStepClock.Step; else if (input.Forward) CameraPitch += 20 * FixedStepClock.Step; } public void Reset() { if (Equipped) Release(); PendingThrow = AimVisible = false; CameraPitch = 10; SavedPitch = DisplayPitch = 0; CameraHeight = 200; NextSlot = Throws = 0; foreach (var projectile in projectiles) projectile.Reset(); } } /// C3DBaseball owned pool entry. No invented ammo count or lifetime. public sealed class BaseballProjectile { public Vector3 Position { get; private set; } public Vector3 PreviousPosition { get; private set; } public Vector3 Velocity { get; private set; } public Vector3 PendingImpulse { get; private set; } public bool Supported { get; private set; } public bool Visible { get; private set; } public int CanvasId => 2; //40FB50 initializes2; a sequence caller is not recovered. public int Landings { get; private set; } public void Launch(Vector3 root, Vector3 euler, float pitch) { if (!float.IsFinite(root.X + root.Y + root.Z + euler.X + euler.Y + euler.Z + pitch) || pitch < 0 || pitch > 45) throw new ArgumentOutOfRangeException(nameof(pitch)); //384/38C use the player's full local transform. This bridge matches the //port's recovered Bubble Euler convention; generic original Euler remains //a declared precision/ownership boundary. Upright yaw is the tested path. var rotation = Matrix4x4.CreateRotationZ(-euler.Z * MathF.PI / 180) * Matrix4x4.CreateRotationX(-euler.X * MathF.PI / 180) * Matrix4x4.CreateRotationY(-euler.Y * MathF.PI / 180); Position = root + Vector3.Transform(new Vector3(0, 80, 50), rotation); var direction = Vector3.Transform(new Vector3(0, pitch * .02222222276031971f, 1), rotation); Velocity = direction / OriginalBodySupport.QuickMagnitude(direction) * 1800; //429A30 does not clear a reused entry's impulse/support state. PreviousPosition = Position; Visible = true; } public void Step(OriginalBodyPhysics physics, float seconds) { if (!Visible) return; PreviousPosition = Position; var result = physics.Step(new(Position, Velocity, Vector3.Zero, PendingImpulse, Supported), seconds, radius: 15, factor: 1, friction: .46f, profile: BodyResponseProfile.Baseball); Position = result.Body.Position; Velocity = result.Body.Velocity; PendingImpulse = result.Body.Impulse; Supported = result.Body.Supported; if (result.Landing != null) Landings++; } public void Hide() => Visible = false; //Source disables integration/pairs and hides, retaining body state. public void Reset() { Visible=Supported=false; Position=PreviousPosition=Velocity=PendingImpulse=Vector3.Zero; Landings=0; } }