logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    Class WeaponArsenal

    Mutable ordered collection of acquired weapon identities, tracking which one is currently active.

    Inheritance
    object
    WeaponArsenal
    Inherited Members
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    Namespace: Serenity.GameWeapon.Domain.Entities
    Assembly: Serenity.GameWeapon.Domain.dll
    Syntax
    public class WeaponArsenal
    Remarks

    Owns no weapon state itself — it only orders and selects among WeaponIds already registered elsewhere (see IGameWeaponService.RegisterWeapon). Adding, removing, and switching are all expressed in terms of list position; see Remove(WeaponId) for the reindexing rule applied when the active weapon itself is removed.

    Constructors

    WeaponArsenal()

    Declaration
    public WeaponArsenal()

    Fields

    MinimumWeaponsToCycle

    The minimum number of weapons the arsenal must hold for CycleNext() to do anything.

    Declaration
    public const int MinimumWeaponsToCycle = 2
    Field Value
    Type Description
    int

    NoActiveWeaponIndex

    The ActiveIndex value that means no weapon is active.

    Declaration
    public const int NoActiveWeaponIndex = -1
    Field Value
    Type Description
    int

    Properties

    Active

    Gets the currently active weapon, or the default WeaponId when the arsenal is empty.

    Declaration
    public WeaponId Active { get; }
    Property Value
    Type Description
    WeaponId

    ActiveIndex

    Gets the index of the currently active weapon within the arsenal, or NoActiveWeaponIndex when empty.

    Declaration
    public int ActiveIndex { get; }
    Property Value
    Type Description
    int

    Count

    Gets the number of weapons currently in the arsenal.

    Declaration
    public int Count { get; }
    Property Value
    Type Description
    int

    Methods

    Add(WeaponId)

    Adds a weapon to the end of the arsenal. Idempotent — adding an already-present weapon is a no-op. The first weapon ever added becomes the active one.

    Declaration
    public bool Add(WeaponId id)
    Parameters
    Type Name Description
    WeaponId id

    The weapon identity to add.

    Returns
    Type Description
    bool

    True if the weapon was added; false if it was already present.

    Contains(WeaponId)

    Checks whether the given weapon is present in the arsenal.

    Declaration
    public bool Contains(WeaponId id)
    Parameters
    Type Name Description
    WeaponId id

    The weapon identity to look for.

    Returns
    Type Description
    bool

    True if id is present; otherwise false.

    CycleNext()

    Advances the active weapon to the next one in the arsenal, wrapping around.

    Declaration
    public bool CycleNext()
    Returns
    Type Description
    bool

    True if the active weapon changed; false when fewer than two weapons are present.

    Remove(WeaponId)

    Removes a weapon from the arsenal.

    Declaration
    public bool Remove(WeaponId id)
    Parameters
    Type Name Description
    WeaponId id

    The weapon identity to remove.

    Returns
    Type Description
    bool

    True if the weapon was removed; false if it was not present.

    Remarks

    Reindexing rule for ActiveIndex:

    • Removing a weapon before the active one shifts ActiveIndex down by one, so it keeps pointing at the same active weapon.
    • Removing a weapon after the active one leaves ActiveIndex unchanged.
    • Removing the active weapon itself leaves ActiveIndex pointing at the same slot, which now holds the weapon that was immediately after it — i.e. the active selection advances forward. If the active weapon was the last slot (nothing to advance into), it falls back to the new last weapon instead.
    • Removing the only weapon in the arsenal empties it: ActiveIndex becomes -1 and Active becomes the default WeaponId.

    SetActive(WeaponId)

    Sets the active weapon directly.

    Declaration
    public bool SetActive(WeaponId id)
    Parameters
    Type Name Description
    WeaponId id

    The weapon identity to make active.

    Returns
    Type Description
    bool

    True if the weapon was found and made active; false if it was not present.

    ToSnapshot()

    Creates an immutable snapshot of the current arsenal.

    Declaration
    public ArsenalSnapshot ToSnapshot()
    Returns
    Type Description
    ArsenalSnapshot

    An ArsenalSnapshot reflecting the current order and active selection.

    In this article
    © 2026 Serenity. All Rights Reserved