Skip to content

Commit

Permalink
Cleaned up weapon loading slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
Da-Teach committed Mar 5, 2011
1 parent 20839f8 commit b9454da
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions Questor.Modules/Combat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Questor.Modules
public class Combat
{
private readonly Dictionary<long, DateTime> _lastModuleActivation = new Dictionary<long, DateTime>();
private readonly Dictionary<long, DateTime> _lastLauncherReload = new Dictionary<long, DateTime>();
private readonly Dictionary<long, DateTime> _lastWeaponReload = new Dictionary<long, DateTime>();
private bool _isJammed;
public CombatState State { get; set; }

Expand All @@ -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);
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -168,6 +153,17 @@ public bool ReloadEnergyWeaponAmmo(ModuleCache weapon, EntityCache entity)
/// <returns>True if the (enough/correct) ammo is loaded, false if wrong/not enough ammo is loaded</returns>
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);
}

Expand Down

0 comments on commit b9454da

Please sign in to comment.