public override bool SwitchToNextAmmoMagazine() { MyWeaponDefinition weaponDefinition = WeaponProperties.WeaponDefinition; int currentIndex = weaponDefinition.GetAmmoMagazineIdArrayIndex(CurrentAmmoMagazineId); int ammoMagazinesCount = weaponDefinition.AmmoMagazinesId.Length; currentIndex += 1; if (currentIndex == ammoMagazinesCount) { currentIndex = 0; } return(SwitchAmmoMagazine(weaponDefinition.AmmoMagazinesId[currentIndex])); }
public override bool SwitchAmmoMagazineToNextAvailable() { MyWeaponDefinition weaponDefinition = WeaponProperties.WeaponDefinition; if (!weaponDefinition.HasAmmoMagazines()) { return(false); } int currentIndex = weaponDefinition.GetAmmoMagazineIdArrayIndex(CurrentAmmoMagazineId); int ammoMagazinesCount = weaponDefinition.AmmoMagazinesId.Length; for (int i = currentIndex + 1, j = 0; j != ammoMagazinesCount; i++, j++) { if (i == ammoMagazinesCount) { i = 0; // reset counter to not overflow } if (weaponDefinition.AmmoMagazinesId[i].SubtypeId != CurrentAmmoMagazineId.SubtypeId) { if (MySession.Static.CreativeMode) { return(SwitchAmmoMagazine(weaponDefinition.AmmoMagazinesId[i])); } else { int remainingAmmo = 0; if (m_remainingAmmos.TryGetValue(weaponDefinition.AmmoMagazinesId[i], out remainingAmmo)) { if (remainingAmmo > 0) { return(SwitchAmmoMagazine(weaponDefinition.AmmoMagazinesId[i])); } } if (m_user.AmmoInventory.GetItemAmount(weaponDefinition.AmmoMagazinesId[i]) > 0) { return(SwitchAmmoMagazine(weaponDefinition.AmmoMagazinesId[i])); } } } } return(false); }