Example #1
0
    // Returns the amount actually spent, in case firing a full round
    // would drop us below 0 ammo, you can scale down the last shot.
    // You could also implement a TrySpend that aborts for insufficient ammo.
    public int Spend(AmmoType type, int amount)
    {
        AmmoEntry held  = _inventory[(int)type];
        int       spend = Mathf.Min(amount, held.currentMag);

        held.currentMag      -= spend;
        _inventory[(int)type] = held;
        return(spend);
    }
Example #2
0
    public int SyncCurrentMag(AmmoType type)
    {
        AmmoEntry held       = _inventory[(int)type];
        int       syncAmount = weaponSelection.weaponSlots[weaponSelection.selectedSlot].gameObject.GetComponentInChildren <GunScript>().currentMag;

        held.currentMag       = syncAmount;
        _inventory[(int)type] = held;
        return(syncAmount);
    }
Example #3
0
    // Returns amount collected, so you can choose to not consume
    // pickups if you're already full (ie. return value is zero).
    public int Collect(AmmoType type, int amount)
    {
        AmmoEntry held    = _inventory[(int)type];
        int       collect = Mathf.Min(amount, held.Stockpile - held.currentMag);

        held.currentMag      += collect;
        _inventory[(int)type] = held;
        return(collect);
    }
Example #4
0
    public int Collect(AmmoType type, int amount)
    {
        AmmoEntry held    = _inventory[(int)type];
        int       collect = Mathf.Min(amount, held.maxCapacity - held.stock);

        held.stock           += collect;
        _inventory[(int)type] = held;
        return(collect);
    }
Example #5
0
    public int Reload(AmmoType type, int amount)
    {
        AmmoEntry held         = _inventory[(int)type];
        int       reloadAmount = Mathf.Min(amount, held.Stockpile);

        held.Stockpile       -= reloadAmount;
        held.currentMag      += reloadAmount;
        _inventory[(int)type] = held;
        return(reloadAmount);
    }