Reloading system with owned ammunition

Hello guys,
I am making a guns system. Each gun has a following fields:

  • maxAmmo
  • currentAmmo
    And Player has a ownedAmmo field.

Player can reload their gun only if currentAmmo != maxAmmo and when player has at least 1 ammo in ownedAmmo.

But I have no idea how to do the math for that system.
If anyone is able to help, or you need more info - respond.

Just an idea. Haven’t tested it, just typing directly into the forum.

private int maxAmmo = 30;
private int currentAmmo = 0;
private int ownedAmmo = 100;

public void Reload()
{
    if ((ownedAmmo > 0) && (currentAmmo != maxAmmo))  //Check if there is any ammo to reload from, and check that we need to even reload at all
    {
        int ammoToReload = maxAmmo - currentAmmo;  //Figure out how much ammo we need to top off the mag
        if (ammoToReload > ownedAmmo)  //Check if we have enough to top off the mag
        {
            ammoToReload = ownedAmmo;  //If we don't have enough to top off the mag entirely, we will just add what is available
        }
        currentAmmo += ammoToReload;  // Add to the mag
        ownedAmmo -= ammoToReload;  //Subtract what we added to the mag from our other ammo
    }
}