Vixen
c7401864
csharp
public sealed class WeaponState

What one holder's weapon is doing: ammunition, heat, kick, and whether it can fire.

Read the guide page for this →

Remarks

Deterministic and side-effect free about geometry. Firing produces a shot number and a cone width; where the pellets went is Deviate, a pure function both ends compute. That is what makes the server's check of a client's claim possible at all — it recomputes the cone rather than believing one.

⚠ Spread and recoil are separate, and keeping them apart is the design. Recoil is a learnable pattern — the tenth bullet goes where the tenth bullet always goes — and spread is the randomness. A game that folds them together can tune "hard to control" and "unpredictable" only together, which is why every weapon in such a game feels the same.

Fields and properties (11)

  • public WeaponTemplate Weapon

    Which weapon.

  • public int Magazine

    How many rounds are in it.

  • public int Reserve

    How many are carried beyond it. Zero when the weapon carries unlimited spares.

  • public uint Shots

    How many shots this holder has fired with it. Part of every pellet's seed.

  • public bool IsReloading

    Whether it is being reloaded.

  • public float ReloadRemaining

    How much of the reload is left, in seconds.

  • public ShotDirection Recoil

    Where the weapon has been kicked to, cumulative and in degrees.

  • public float Spread

    How wide the cone is right now, in degrees.

  • public bool IsMoving

    Whether the holder is moving. Widens the cone.

  • public bool IsAiming

    Whether the holder is aiming down the sights. Narrows it.

  • public float EffectiveSpread

    The cone the next shot would use, with the movement and aim multipliers applied.

Methods (8)

  • public WeaponState(WeaponTemplate weapon)

    Makes a state for a weapon, with a full magazine.

  • public FireFailure CanFire(bool triggerDown = true)

    Whether a shot could happen right now.

  • public FireFailure TryFire(out ShotFired shot, bool triggerDown = true)

    Fires one shot.

  • public void ReleaseTrigger()

    Says the trigger was let go, which is what ends a burst and a semi-automatic's shot.

  • public bool BeginReload()

    Starts a reload.

  • public bool CancelReload()

    Stops a reload where it is.

  • public void Tick(float delta)

    Advances the fire interval, the reload, the spread's recovery and the recoil's.

  • public void Refill()

    Puts everything back: full magazine, no kick, no spread. What a respawn does.

Used by (4)

  • ContentVixen.Gameplay.Shooting.Tests
  • HitClaimValidatorTestsVixen.Gameplay.Shooting.Tests
  • RewindBudgetTestsVixen.Gameplay.Shooting.Tests
  • WeaponStateTestsVixen.Gameplay.Shooting.Tests