IEnumerator ReloadGun(Gun gun, GunData gunData, AmmoCategory category, int availableAmmo, float reloadTime) { PlayAudio(startReloadAudio); animator.SetTrigger("IsReload"); // Start playing audio x seconds before full reload time where x is the length of the end reload audio length yield return(new WaitForSeconds(reloadTime - endReloadAudioLength)); PlayAudio(endReloadAudio); yield return(new WaitForSeconds(endReloadAudioLength)); // round magazine size to highest int and ensure magazine can hold at least 1 bullet after modifiers int magazineSizeAdjusted = (int)Mathf.Ceil(gunData.MagazineSize * gunData.MagazineSizeMultiplier.Value); magazineSizeAdjusted = Mathf.Max(1, magazineSizeAdjusted); int maximumReloadAmount = Mathf.Min(availableAmmo, magazineSizeAdjusted - gun.BulletsInMagazine); // maximum amount should never exceed magazine size gun.IncreaseMagazine(maximumReloadAmount); gun.PlayerAmmoStorage.ReduceAmmoAmount(category, maximumReloadAmount); reloadCoroutine = null; onReload?.Invoke(gun); }
// ============ Jettison Ammo ============ public static void AutoJettisonAmmo(MechHeatSequence __instance) { try { if (!__instance.IsComplete) { return; } Mech mech = __instance.OwningMech; if (mech == null || mech.IsDead || mech.HasMovedThisRound || mech.IsProne || mech.IsShutDown) { return; } if (!FriendOrFoe(mech, Settings.AutoJettisonAmmo, Settings.AutoJettisonEnemyAmmo)) { return; } Dictionary <AmmoCategory, bool> checkedType = new Dictionary <AmmoCategory, bool>(); List <AmmunitionBox> jettison = new List <AmmunitionBox>(); foreach (AmmunitionBox box in mech.ammoBoxes) { if (box.CurrentAmmo <= 0) { continue; } AmmoCategory type = box.ammoCategory; if (checkedType.ContainsKey(type)) { if (checkedType[type]) { jettison.Add(box); } continue; } bool canUseAmmo = mech.Weapons.Any(e => e.AmmoCategory == type && e.DamageLevel < ComponentDamageLevel.NonFunctional); if (!canUseAmmo) { jettison.Add(box); } checkedType[type] = !canUseAmmo; } if (jettison.Count <= 0) { return; } foreach (AmmunitionBox box in jettison) { ZeroAmmo(box, mech.uid, __instance.SequenceGUID); } foreach (AmmoCategory type in checkedType.Where(e => e.Value).Select(e => e.Key)) { Combat.MessageCenter.PublishMessage(new AddSequenceToStackMessage(new ShowActorInfoSequence(mech, type + " AMMO JETTISONED", FloatieMessage.MessageNature.Buff, false))); } } catch (Exception ex) { Error(ex); } }
/** * used to initialise new GunData assets created within the gun creator tool */ public void InitialiseGunData(FireMode fireMode, AmmoCategory ammoCategory, GameObject projectilePrefab, int damage, int magazineSize, int roundsPerMinute, float baseSpreadRadius, int baseCritChance, float baseCritMultiplier, int baseStunChance) { this.fireMode = fireMode; this.ammoCategory = ammoCategory; this.projectilePrefab = projectilePrefab; this.damage = damage; this.magazineSize = magazineSize; this.roundsPerMinute = roundsPerMinute; this.baseSpreadRadius = baseSpreadRadius; this.baseCritChance = baseCritChance; this.baseCritMultiplier = baseCritMultiplier; this.baseStunChance = baseStunChance; }
/** * Used to initialise two equal length arrays based on ammo categories available and set * each element in startingAmmoCategories equal to the enums available */ void InitialiseArraysInInspector() { string[] ammoCategories = System.Enum.GetNames(typeof(AmmoCategory)); int categoryCount = ammoCategories.Length; startingAmmoCategories = new AmmoCategory[categoryCount]; startingAmmoAmounts = new int[startingAmmoCategories.Length]; for (int i = 0; i < categoryCount; i++) { AmmoCategory type = (AmmoCategory)System.Enum.Parse(typeof(AmmoCategory), ammoCategories[i]); startingAmmoCategories[i] = type; } }
void SetNewGunData() { fireMode = (FireMode)EditorGUILayout.EnumPopup("Fire Mode: ", fireMode); ammoCategory = (AmmoCategory)EditorGUILayout.EnumPopup("Ammo Type: ", ammoCategory);; damage = EditorGUILayout.IntSlider("Damage: ", damage, 1, 1000); magazineSize = EditorGUILayout.IntSlider("Magazine Size: ", magazineSize, 1, 100); roundsPerMinute = EditorGUILayout.IntSlider("Rounds Per Minute: ", roundsPerMinute, 1, 500); baseSpreadRadius = EditorGUILayout.Slider("Spread Radius: ", baseSpreadRadius, 0, 10); baseSpreadRadius = (float)System.Math.Round(baseSpreadRadius, 2); baseCritChance = EditorGUILayout.IntSlider("Base Crit Chance: ", baseCritChance, 0, 100); baseCritMultiplier = EditorGUILayout.Slider("Base Crit Multiplier: ", baseCritMultiplier, 0, 3); baseCritMultiplier = (float)System.Math.Round(baseCritMultiplier, 2); baseStunChance = EditorGUILayout.IntSlider("Base Stun Chance: ", baseStunChance, 0, 100); }
public override void Perform(Gun gun, GunData gunData) { if (cooldown.IsCooldown) { return; } AmmoCategory category = gunData.AmmoCategory; int availableAmmo = gun.PlayerAmmoStorage.GetAmmoAmount(category); if (availableAmmo > 0) { float reloadMultiplier = gunData.ReloadTimeMultiplier.Value; float reloadTimeAdjusted = reloadTime * reloadMultiplier; animator.SetFloat("reloadTimeMultiplier", reloadMultiplier); cooldown.StartCooldownTimer(reloadTimeAdjusted); reloadCoroutine = StartCoroutine(ReloadGun(gun, gunData, category, availableAmmo, reloadTimeAdjusted)); } }
void OnUpdate(Gun target) { elapsedTime += Time.deltaTime; if (elapsedTime >= maxTimeBetweenBulletReloadInSeconds) { AmmoCategory category = target.GunData.AmmoCategory; int availableAmmo = target.PlayerAmmoStorage.GetAmmoAmount(category); if (availableAmmo > 0) { int magazineSizeAdjusted = (int)Mathf.Ceil(target.GunData.MagazineSize * target.GunData.MagazineSizeMultiplier.Value); if (target.BulletsInMagazine < magazineSizeAdjusted) { target.IncreaseMagazine(1); target.PlayerAmmoStorage.ReduceAmmoAmount(category, 1); } elapsedTime = 0f; } } }
public void ReduceAmmoAmount(AmmoCategory category, int amount) { ammoTypeAndAmount[category] -= amount; }
public void AddAmmoAmount(AmmoCategory category, int amount) { ammoTypeAndAmount[category] += amount; }
public int GetAmmoAmount(AmmoCategory category) { return(ammoTypeAndAmount[category]); }
private static bool ApplyFilter(MechComponentDef item, FilterInfo filter) { if (filter == null) { //Control.LogDebug($"--- empty filter"); return(true); } if (filter.ComponentTypes != null && filter.ComponentTypes.Length > 0 && !filter.ComponentTypes.Contains(item.ComponentType)) { //Control.LogDebug($"--- not component type"); return(false); } if (filter.WeaponCategories != null && filter.WeaponCategories.Length > 0) { if (item.ComponentType == ComponentType.Weapon) { if (!(item is WeaponDef weapon)) { Control.LogError( $"{item.ComponentType} have weapon type but not contain WeaponDef"); return(false); } if (!filter.WeaponCategories.Contains(weapon.Category)) { //Control.LogDebug($"--- weapon, wrong weapon type"); return(false); } } else if (item.ComponentType == ComponentType.AmmunitionBox) { if (!(item is AmmunitionBoxDef ammo)) { Control.LogError( $"{item.Description.Id} have AmmunitionBox type but not contain AmmunitionBoxDef"); return(false); } WeaponCategory wc; AmmoCategory category = ammo.Ammo.Category; if (category == AmmoCategory.AC2 || category == AmmoCategory.AC5 || category == AmmoCategory.AC10 || category == AmmoCategory.AC20 || category == AmmoCategory.GAUSS) { wc = WeaponCategory.Ballistic; } else if (category == AmmoCategory.Flamer) { wc = WeaponCategory.Energy; } else if (category == AmmoCategory.LRM || category == AmmoCategory.SRM) { wc = WeaponCategory.Missile; } else if (category == AmmoCategory.MG) { wc = WeaponCategory.AntiPersonnel; } else if (category == AmmoCategory.AMS) { wc = WeaponCategory.AMS; } else { Control.LogError($"{item.Description.Id} have wrong ammo type {category}"); return(false); } if (!filter.WeaponCategories.Contains(wc)) { //Control.LogDebug($"--- ammo, wrong weapon type"); return(false); } } } if (filter.Categories != null && filter.Categories.Length > 0) { if (!filter.Categories.Any(item.IsCategory)) { //Control.LogDebug($"--- not found category"); return(false); } } if (filter.NotCategories != null && filter.NotCategories.Length > 0) { if (filter.NotCategories.Any(item.IsCategory)) { //Control.LogDebug($"--- found forbidden category"); return(false); } } return(true); }