Class AmmoReserveState
Mutable state tracking a weapon's spare ammo reserve, separate from the loaded magazine.
Inherited Members
Namespace: Serenity.GameWeapon.Domain.Entities
Assembly: Serenity.GameWeapon.Domain.dll
Syntax
public class AmmoReserveState
Constructors
AmmoReserveState(int, int)
Creates a new AmmoReserveState with the specified capacity.
Declaration
public AmmoReserveState(int maxCapacity, int currentAmmo = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| int | maxCapacity | The maximum reserve capacity. A negative value means infinite. |
| int | currentAmmo | The initial reserve ammo. Ignored when the reserve is infinite; otherwise clamped to the range [0, maxCapacity]. |
Properties
CurrentAmmo
Gets the current number of rounds held in reserve.
Declaration
public int CurrentAmmo { get; }
Property Value
| Type | Description |
|---|---|
| int |
IsEmpty
Gets whether the reserve is empty. An infinite reserve is never empty.
Declaration
public bool IsEmpty { get; }
Property Value
| Type | Description |
|---|---|
| bool |
IsInfinite
Gets whether this reserve has no capacity limit.
Declaration
public bool IsInfinite { get; }
Property Value
| Type | Description |
|---|---|
| bool |
MaxCapacity
Gets the maximum reserve capacity. A negative value means the reserve is infinite.
Declaration
public int MaxCapacity { get; }
Property Value
| Type | Description |
|---|---|
| int |
Methods
Add(int)
Adds rounds to the reserve. No-op when infinite; otherwise capped at max capacity.
Declaration
public void Add(int amount)
Parameters
| Type | Name | Description |
|---|---|---|
| int | amount | The number of rounds to add. |
Fill()
Fills the reserve to full capacity. No-op when infinite (already unlimited).
Declaration
public void Fill()
Withdraw(int)
Withdraws up to the requested amount of rounds from the reserve.
Declaration
public int Withdraw(int requested)
Parameters
| Type | Name | Description |
|---|---|---|
| int | requested | The number of rounds requested. |
Returns
| Type | Description |
|---|---|
| int | The number of rounds actually granted: an infinite reserve always grants the full request; a finite reserve grants at most its current ammo. Never negative. |