diff --git a/Questor.Modules/Combat.cs b/Questor.Modules/Combat.cs index b416ee22e..0790b9d78 100644 --- a/Questor.Modules/Combat.cs +++ b/Questor.Modules/Combat.cs @@ -21,7 +21,7 @@ namespace Questor.Modules public class Combat { private readonly Dictionary _lastModuleActivation = new Dictionary(); - private readonly Dictionary _lastLauncherReload = new Dictionary(); + private readonly Dictionary _lastWeaponReload = new Dictionary(); private bool _isJammed; public CombatState State { get; set; } @@ -36,14 +36,6 @@ public class Combat public bool ReloadNormalAmmo(ModuleCache weapon, EntityCache entity) { var cargo = Cache.Instance.DirectEve.GetShipsCargo(); - if (cargo.Window == null) - { - Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.OpenCargoHoldOfActiveShip); - return false; - } - - if (!cargo.IsReady) - return false; // Get ammo based on damage type var correctAmmo = Settings.Instance.Ammo.Where(a => a.DamageType == Cache.Instance.DamageType); @@ -79,9 +71,9 @@ public bool ReloadNormalAmmo(ModuleCache weapon, EntityCache entity) return false; // We are reloading, wait at least 11 seconds - if (_lastLauncherReload.ContainsKey(weapon.ItemId) && DateTime.Now < _lastLauncherReload[weapon.ItemId].AddSeconds(22)) + if (_lastWeaponReload.ContainsKey(weapon.ItemId) && DateTime.Now < _lastWeaponReload[weapon.ItemId].AddSeconds(22)) return false; - _lastLauncherReload[weapon.ItemId] = DateTime.Now; + _lastWeaponReload[weapon.ItemId] = DateTime.Now; // Reload or change ammo if (weapon.Charge != null && weapon.Charge.TypeId == charge.TypeId) @@ -102,15 +94,8 @@ public bool ReloadNormalAmmo(ModuleCache weapon, EntityCache entity) public bool ReloadEnergyWeaponAmmo(ModuleCache weapon, EntityCache entity) { var cargo = Cache.Instance.DirectEve.GetShipsCargo(); - if (cargo.Window == null) - { - Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.OpenCargoHoldOfActiveShip); - return false; - } - - if (!cargo.IsReady) - return false; + // Get ammo based on damage type var correctAmmo = Settings.Instance.Ammo.Where(a => a.DamageType == Cache.Instance.DamageType); // Check if we still have that ammo in our cargo @@ -140,9 +125,9 @@ public bool ReloadEnergyWeaponAmmo(ModuleCache weapon, EntityCache entity) return true; // We are reloading, wait at least 5 seconds - if (_lastLauncherReload.ContainsKey(weapon.ItemId) && DateTime.Now < _lastLauncherReload[weapon.ItemId].AddSeconds(5)) + if (_lastWeaponReload.ContainsKey(weapon.ItemId) && DateTime.Now < _lastWeaponReload[weapon.ItemId].AddSeconds(5)) return false; - _lastLauncherReload[weapon.ItemId] = DateTime.Now; + _lastWeaponReload[weapon.ItemId] = DateTime.Now; // Reload or change ammo if (weapon.Charge != null && weapon.Charge.TypeId == charge.TypeId) @@ -168,6 +153,17 @@ public bool ReloadEnergyWeaponAmmo(ModuleCache weapon, EntityCache entity) /// True if the (enough/correct) ammo is loaded, false if wrong/not enough ammo is loaded public bool ReloadAmmo(ModuleCache weapon, EntityCache entity) { + // We need the cargo bay open for both reload actions + var cargo = Cache.Instance.DirectEve.GetShipsCargo(); + if (cargo.Window == null) + { + Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.OpenCargoHoldOfActiveShip); + return false; + } + + if (!cargo.IsReady) + return false; + return weapon.IsEnergyWeapon ? ReloadEnergyWeaponAmmo(weapon, entity) : ReloadNormalAmmo(weapon, entity); }