public void ChangeAmmo(bool moveUp) { if (ammoClips.Count == 0) { return; } if (delayLeft > 0) { return; } currentClipIndex += moveUp ? 1 : -1; currentClipIndex = currentClipIndex % ammoClips.Count; while (currentClipIndex < 0) { currentClipIndex += ammoClips.Count; } if (currentClip != null) { currentClip.OnReload -= ReloadHandler; } currentClip = ammoClips[currentClipIndex]; if (currentClip.GetAmmoInfo().loaded == 0) { currentClip.StartReload(); } OnWeaponChange?.Invoke(this); currentClip.OnReload += ReloadHandler; }
public AmmoClip(AmmoClip other) { ammoType = other.ammoType; this.clipSize = other.clipSize; this.maxAmmo = other.maxAmmo; this.reloadTime = other.reloadTime; ammoReserves = other.ammoReserves; currentlyInClip = other.currentlyInClip; }
public bool RestoreAmmo(Type ammoType, int amount) { AmmoClip clip = ammoClips.Find(x => x.clip.ammoType == ammoType); if (clip == null) { throw new ApplicationException("restoring unexisting ammo"); } if (clip.IsFull()) { return(false); } clip.RestoreAmmo(amount); OnAmmoChange?.Invoke(this); return(true); }
private void ReloadHandler(AmmoClip clip) { OnAmmoChange?.Invoke(this); }