// // ItemID (of module), DateTime of activation, TargetId (what are we shooting at), Target.TypeID, Targets Distance, Targets Velocity, Targets Shield %, Targets Armor %, Targets Hull %, Targets Shield HitPoints, Targets Armor HitPoints, Targets Hull HitPoints // public EachWeaponsVolleyCache(EveCom.Module module, EntityCache target) { // // reminder: this class and all the info within it is created (and destroyed!) each frame for each module! // //_module = module; //_target = target; //_self = self; ThisVolleyCacheCreated = DateTime.UtcNow; targetName = target.Name; // Name of target entity targetTypeID = target.TypeId; // TypeID of target entity targetGroupID = target.GroupId; // GroupID of target entity targetItemID = target.Id; // ItemID of target entity - tells us which entity specifically (globally unique) targetVelocity = target.Velocity; // Velocity of target entity targetDistance = target.Distance; // Distance of target entity from me targetShieldPercentage = target.ShieldPct; // Shield percentage of target entity targetArmorPercentage = target.ArmorPct; // Armor percentage of target entity targetHullPercentage = target.StructurePct; // Hull percentage of target entity //targetAngularVelocity = target.AngularVelocity; targetXCoordinate = target.XCoordinate; targetYCoordinate = target.YCoordinate; targetZCoordinate = target.ZCoordinate; myShipName = EveCom.MyShip.ToItem.Name; // Name of target entity myShipTypeID = QuestorCache.Instance.ActiveShip.TypeID; // TypeID of target entity myShipGroupID = (int)QuestorCache.Instance.ActiveShip.GroupID; // GroupID of target entity myShipVelocity = QuestorCache.Instance.MyShipEntity.Velocity; // Velocity of target entity myShipShieldPercentage = QuestorCache.Instance.ActiveShip.ShieldPct; // Shield percentage of target entity myShipArmorPercentage = QuestorCache.Instance.ActiveShip.ArmorPct; // Armor percentage of target entity myShipHullPercentage = QuestorCache.Instance.ActiveShip.HullPct; // Hull percentage of target entity myShipShieldHitPoints = EveCom.MyShip.Shield; // Shield HitPoints of target entity myShipArmorHitPoints = EveCom.MyShip.Armor; // Shield HitPoints of target entity myShipHullHitPoints = EveCom.MyShip.Hull; // Shield HitPoints of target entity myShipCapacitorPercentage = EveCom.MyShip.Capacitor; myShipXCoordinate = QuestorCache.Instance.MyShipEntity.XCoordinate; myShipYCoordinate = QuestorCache.Instance.MyShipEntity.YCoordinate; myShipZCoordinate = QuestorCache.Instance.MyShipEntity.ZCoordinate; moduleName = module.Type; moduleItemID = module.ID; moduleTypeID = module.TypeID; moduleGroupID = (int)module.GroupID; moduleFalloff = module.FalloffRange; moduleOptimal = module.OptimalRange; //moduleTargetID = module.TargetId; if (moduleGroupID != 53 && module.Charge != null) { if (Logging.DebugEachWeaponsVolleyCache) Logging.Log("DebugEachWeaponsVolleyCache", "[" + thisWasVolleyNumber + "] ModuleItemID [" + moduleItemID + "] ModuleTypeID [" + moduleTypeID + "] ModuleGroupID [" + moduleGroupID + "] ModuleCurrentCharges [" + moduleCurrentCharges + "]", Logging.Debug); moduleAmmoTypeName = module.Charge.Type; moduleAmmoTypeID = module.Charge.TypeID; moduleCurrentCharges = module.Charge.TypeID; } thisWasVolleyNumber = QuestorCache.Instance.VolleyCount; QuestorCache.Instance.VolleyCount++; ThisVolleyCacheCreated = DateTime.UtcNow; }
public static bool ReloadAll(EntityCache entity) { _reloadAllIteration++; if (Settings.Instance.DebugReloadAll) Logging.Log("debug ReloadAll", "Entering reloadAll function (again) - it iterates through all weapon stacks [" + _reloadAllIteration + "]", Logging.White); if (_reloadAllIteration > 12) { if (Settings.Instance.DebugReloadAll) Logging.Log("debug ReloadAll:", "reset iteration counter", Logging.Orange); return true; } IEnumerable<ModuleCache> weapons = Cache.Instance.Weapons; _weaponNumber = 0; foreach (ModuleCache weapon in weapons) { // Reloading energy weapons prematurely just results in unnecessary error messages, so let's not do that if (weapon.IsEnergyWeapon) continue; _weaponNumber++; if (weapon.IsReloadingAmmo || weapon.IsDeactivating || weapon.IsChangingAmmo || weapon.IsActive) { if (Settings.Instance.DebugReloadAll) Logging.Log("debug ReloadAll", "Weapon [" + _weaponNumber + "] is busy, moving on to next weapon", Logging.White); continue; } if (LastWeaponReload.ContainsKey(weapon.ItemId) && DateTime.UtcNow < LastWeaponReload[weapon.ItemId].AddSeconds(Time.Instance.ReloadWeaponDelayBeforeUsable_seconds)) { if (Settings.Instance.DebugReloadAll) Logging.Log("debug ReloadAll", "Weapon [" + _weaponNumber + "] has been reloaded recently, moving on to next weapon", Logging.White); continue; } if (!ReloadAmmo(weapon, entity, _weaponNumber)) return false; //by returning false here we make sure we only reload one gun (or stack) per iteration (basically per second) return false; } if (Settings.Instance.DebugReloadAll) Logging.Log("debug ReloadAll", "completely reloaded all weapons", Logging.White); //_lastReloadAll = DateTime.UtcNow; _reloadAllIteration = 0; return true; }
public bool CheckForPrimaryWeaponPriorityTargetsInOrder(EntityCache currentTarget, double distance) { try { // Do we have ANY warp scrambling entities targeted starting with currentTarget // this needs Settings.Instance.AddWarpScramblersToPrimaryWeaponsPriorityTargetList true, otherwise they will just get handled in any order below... if (Cache.Instance.FindPrimaryWeaponPriorityTarget(currentTarget, PrimaryWeaponPriority.WarpScrambler, Settings.Instance.AddWarpScramblersToPrimaryWeaponsPriorityTargetList, distance) != null) return true; // Do we have ANY ECM entities targeted starting with currentTarget // this needs Settings.Instance.AddECMsToPrimaryWeaponsPriorityTargetList true, otherwise they will just get handled in any order below... if (Cache.Instance.FindPrimaryWeaponPriorityTarget(currentTarget, PrimaryWeaponPriority.Jamming, Settings.Instance.AddECMsToPrimaryWeaponsPriorityTargetList, distance) != null) return true; // Do we have ANY tracking disrupting entities targeted starting with currentTarget // this needs Settings.Instance.AddTrackingDisruptorsToPrimaryWeaponsPriorityTargetList true, otherwise they will just get handled in any order below... if (Cache.Instance.FindPrimaryWeaponPriorityTarget(currentTarget, PrimaryWeaponPriority.TrackingDisrupting, Settings.Instance.AddTrackingDisruptorsToPrimaryWeaponsPriorityTargetList, distance) != null) return true; // Do we have ANY Neutralizing entities targeted starting with currentTarget // this needs Settings.Instance.AddNeutralizersToPrimaryWeaponsPriorityTargetList true, otherwise they will just get handled in any order below... if (Cache.Instance.FindPrimaryWeaponPriorityTarget(currentTarget, PrimaryWeaponPriority.Neutralizing, Settings.Instance.AddNeutralizersToPrimaryWeaponsPriorityTargetList, distance) != null) return true; // Do we have ANY Target Painting entities targeted starting with currentTarget // this needs Settings.Instance.AddTargetPaintersToPrimaryWeaponsPriorityTargetList true, otherwise they will just get handled in any order below... if (Cache.Instance.FindPrimaryWeaponPriorityTarget(currentTarget, PrimaryWeaponPriority.TargetPainting, Settings.Instance.AddTargetPaintersToPrimaryWeaponsPriorityTargetList, distance) != null) return true; // Do we have ANY Sensor Dampening entities targeted starting with currentTarget // this needs Settings.Instance.AddDampenersToPrimaryWeaponsPriorityTargetList true, otherwise they will just get handled in any order below... if (Cache.Instance.FindPrimaryWeaponPriorityTarget(currentTarget, PrimaryWeaponPriority.Dampening, Settings.Instance.AddDampenersToPrimaryWeaponsPriorityTargetList, distance) != null) return true; // Do we have ANY Webbing entities targeted starting with currentTarget // this needs Settings.Instance.AddWebifiersToPrimaryWeaponsPriorityTargetList true, otherwise they will just get handled in any order below... if (Cache.Instance.FindPrimaryWeaponPriorityTarget(currentTarget, PrimaryWeaponPriority.Webbing, Settings.Instance.AddWebifiersToPrimaryWeaponsPriorityTargetList, distance) != null) return true; return false; } catch (Exception ex) { Logging.Log("CheckForPrimaryWeaponPriorityTargetsInOrder", "Exception [" + ex + "]", Logging.Debug); return false; } }
private static void ActivateWarpDisruptor(EntityCache target) { List<ModuleCache> WarpDisruptors = Cache.Instance.Modules.Where(m => m.GroupId == (int)Group.WarpDisruptor).ToList(); // Find the first active weapon // Assist this weapon _weaponNumber = 0; foreach (ModuleCache WarpDisruptor in WarpDisruptors) { _weaponNumber++; if (Cache.Instance.LastActivatedTimeStamp != null && Cache.Instance.LastActivatedTimeStamp.ContainsKey(WarpDisruptor.ItemId)) { if (Cache.Instance.LastActivatedTimeStamp[WarpDisruptor.ItemId].AddMilliseconds(Time.Instance.WebDelay_milliseconds) > DateTime.UtcNow) { continue; } } // Are we on the right target? if (WarpDisruptor.IsActive) { if (WarpDisruptor.TargetId != target.Id) { if (WarpDisruptor.Click()) return; return; } continue; } // Are we deactivating? if (WarpDisruptor.IsDeactivating) continue; // Target is out of web range if (target.Distance >= WarpDisruptor.OptimalRange) continue; if (CanActivate(WarpDisruptor, target, false)) { if (WarpDisruptor.Activate(target)) { Logging.Log("Combat", "Activating [" + WarpDisruptor.TypeName + "][" + _weaponNumber + "] on [" + target.Name + "][" + Cache.Instance.MaskedID(target.Id) + "]", Logging.Teal); return; } continue; } } }
private static void ActivateRemoteRepair(EntityCache target) { List<ModuleCache> RemoteRepairers = Cache.Instance.Modules.Where(m => m.GroupId == (int)Group.RemoteArmorRepairer || m.GroupId == (int)Group.RemoteShieldRepairer || m.GroupId == (int)Group.RemoteHullRepairer ).ToList(); // Find the first active weapon // Assist this weapon _weaponNumber = 0; if (RemoteRepairers.Any()) { if (Settings.Instance.DebugRemoteRepair) Logging.Log("ActivateRemoteRepair", "RemoteRepairers [" + RemoteRepairers.Count() + "] Target Distance [" + Math.Round(target.Distance / 1000, 0) + "] RemoteRepairDistance [" + Math.Round(((double)Settings.Instance.RemoteRepairDistance / 1000), digits: 0) + "]", Logging.Debug); foreach (ModuleCache RemoteRepairer in RemoteRepairers) { _weaponNumber++; if (Cache.Instance.LastActivatedTimeStamp != null && Cache.Instance.LastActivatedTimeStamp.ContainsKey(RemoteRepairer.ItemId)) { if (Cache.Instance.LastActivatedTimeStamp[RemoteRepairer.ItemId].AddMilliseconds(Time.Instance.RemoteRepairerDelay_milliseconds) > DateTime.UtcNow) { continue; } } // Are we on the right target? if (RemoteRepairer.IsActive) { if (RemoteRepairer.TargetId != target.Id) { if (RemoteRepairer.Click()) return; return; } continue; } // Are we deactivating? if (RemoteRepairer.IsDeactivating) continue; // Target is out of RemoteRepair range if (target.Distance >= RemoteRepairer.MaxRange) continue; if (CanActivate(RemoteRepairer, target, false)) { if (RemoteRepairer.Activate(target)) { Logging.Log("Combat", "Activating [" + RemoteRepairer.TypeName + "][" + _weaponNumber + "] on [" + target.Name + "][" + Cache.Instance.MaskedID(target.Id) + "]", Logging.Teal); return; } continue; } } } }
public static bool ReloadAll(EntityCache entity, bool force = false) { if (Settings.Instance.DebugReloadAll) { if (Cache.Instance.MyShipEntity.Name == Settings.Instance.TransportShipName) { Logging.Log("ReloadAll", "You are in your TransportShip named [" + Settings.Instance.TransportShipName + "], no need to reload ammo!", Logging.Debug); return true; } if (Cache.Instance.MyShipEntity.Name == Settings.Instance.TravelShipName) { Logging.Log("ReloadAll", "You are in your TravelShipName named [" + Settings.Instance.TravelShipName + "], no need to reload ammo!", Logging.Debug); return true; } if (Cache.Instance.MyShipEntity.GroupId == (int)Group.Shuttle) { Logging.Log("ReloadAll", "You are in a Shuttle, no need to reload ammo!", Logging.Debug); return true; } } _reloadAllIteration++; if (Settings.Instance.DebugReloadAll) Logging.Log("debug ReloadAll", "Entering reloadAll function (again) - it iterates through all weapon stacks [" + _reloadAllIteration + "]", Logging.White); if (_reloadAllIteration > 12) { if (Settings.Instance.DebugReloadAll) Logging.Log("debug ReloadAll:", "reset iteration counter", Logging.Orange); return true; } _weaponNumber = 0; if (Settings.Instance.DebugReloadAll) Logging.Log("debug ReloadAll:", "Weapons (or stacks of weapons?): [" + Cache.Instance.Weapons.Count() + "]", Logging.Orange); if (Cache.Instance.Weapons.Any()) { foreach (ModuleCache weapon in Cache.Instance.Weapons) { _weaponNumber++; // Reloading energy weapons prematurely just results in unnecessary error messages, so let's not do that if (weapon.IsEnergyWeapon) { if (Settings.Instance.DebugReloadAll) Logging.Log("debug ReloadAll:", "if (weapon.IsEnergyWeapon) continue (energy weapons do not really need to reload)", Logging.Orange); continue; } if (weapon.IsReloadingAmmo) { if (Settings.Instance.DebugReloadAll) Logging.Log("debug ReloadAll", "[" + weapon.TypeName + "][" + _weaponNumber + "] is still reloading, moving on to next weapon", Logging.White); continue; } if (weapon.IsDeactivating) { if (Settings.Instance.DebugReloadAll) Logging.Log("debug ReloadAll", "[" + weapon.TypeName + "][" + _weaponNumber + "] is still Deactivating, moving on to next weapon", Logging.White); continue; } if (weapon.IsChangingAmmo) { if (Settings.Instance.DebugReloadAll) Logging.Log("debug ReloadAll", "[" + weapon.TypeName + "][" + _weaponNumber + "] is still Changing Ammo, moving on to next weapon", Logging.White); continue; } if (weapon.IsActive) { if (Settings.Instance.DebugReloadAll) Logging.Log("debug ReloadAll", "[" + weapon.TypeName + "][" + _weaponNumber + "] is Active, moving on to next weapon", Logging.White); continue; } if (Cache.Instance.LastReloadedTimeStamp != null && Cache.Instance.LastReloadedTimeStamp.ContainsKey(weapon.ItemId)) { if (DateTime.UtcNow < Cache.Instance.LastReloadedTimeStamp[weapon.ItemId].AddSeconds(Time.Instance.ReloadWeaponDelayBeforeUsable_seconds)) { if (Settings.Instance.DebugReloadAll) Logging.Log("debug ReloadAll", "Weapon [" + _weaponNumber + "] was just reloaded [" + Math.Round(DateTime.UtcNow.Subtract(Cache.Instance.LastReloadedTimeStamp[weapon.ItemId]).TotalSeconds, 0) + "] seconds ago , moving on to next weapon", Logging.White); continue; } } if (Cache.Instance.CurrentShipsCargo != null && Cache.Instance.CurrentShipsCargo.Items.Any()) { if (!ReloadAmmo(weapon, entity, _weaponNumber)) continue; //by returning false here we make sure we only reload one gun (or stack) per iteration (basically per second) } return false; } if (Settings.Instance.DebugReloadAll) Logging.Log("debug ReloadAll", "completely reloaded all weapons", Logging.White); _reloadAllIteration = 0; return true; } _reloadAllIteration = 0; return true; }
private static bool ReloadEnergyWeaponAmmo(ModuleCache weapon, EntityCache entity, int weaponNumber) { // Get ammo based on damage type IEnumerable<Ammo> correctAmmo = Settings.Instance.Ammo.Where(a => a.DamageType == Cache.Instance.MissionDamageType).ToList(); // Check if we still have that ammo in our cargo IEnumerable<Ammo> correctAmmoInCargo = correctAmmo.Where(a => Cache.Instance.CurrentShipsCargo.Items.Any(e => e.TypeId == a.TypeId)).ToList(); //check if mission specific ammo is defined if (Cache.Instance.MissionAmmo.Count() != 0) { correctAmmoInCargo = Cache.Instance.MissionAmmo.Where(a => a.DamageType == Cache.Instance.MissionDamageType).ToList(); } // Check if we still have that ammo in our cargo correctAmmoInCargo = correctAmmoInCargo.Where(a => Cache.Instance.CurrentShipsCargo.Items.Any(e => e.TypeId == a.TypeId && e.Quantity >= Settings.Instance.MinimumAmmoCharges)).ToList(); if (Cache.Instance.MissionAmmo.Count() != 0) { correctAmmoInCargo = Cache.Instance.MissionAmmo; } // We are out of ammo! :( if (!correctAmmoInCargo.Any()) { Logging.Log("Combat", "ReloadEnergyWeapon: not enough [" + Cache.Instance.MissionDamageType + "] ammo in cargohold: MinimumCharges: [" + Settings.Instance.MinimumAmmoCharges + "]", Logging.Orange); _States.CurrentCombatState = CombatState.OutOfAmmo; return false; } if (weapon.Charge != null) { IEnumerable<Ammo> areWeMissingAmmo = correctAmmoInCargo.Where(a => a.TypeId == weapon.Charge.TypeId); if (!areWeMissingAmmo.Any()) { Logging.Log("Combat", "ReloadEnergyWeaponAmmo: We have ammo loaded that does not have a full reload available in the cargo.", Logging.Orange); } } // Get the best possible ammo - energy weapons change ammo near instantly Ammo ammo = correctAmmoInCargo.Where(a => a.Range > (entity.Distance)).OrderBy(a => a.Range).FirstOrDefault(); //default // We do not have any ammo left that can hit targets at that range! if (ammo == null) { if (Settings.Instance.DebugReloadorChangeAmmo) Logging.Log("Combat", "ReloadEnergyWeaponAmmo: best possible ammo: [ ammo == null]", Logging.White); return false; } if (Settings.Instance.DebugReloadorChangeAmmo) Logging.Log("Combat", "ReloadEnergyWeaponAmmo: best possible ammo: [" + ammo.TypeId + "][" + ammo.DamageType + "]", Logging.White); if (Settings.Instance.DebugReloadorChangeAmmo) Logging.Log("Combat", "ReloadEnergyWeaponAmmo: best possible ammo: [" + entity.Name + "][" + Math.Round(entity.Distance / 1000, 0) + "]", Logging.White); DirectItem charge = Cache.Instance.CurrentShipsCargo.Items.OrderBy(e => e.Quantity).FirstOrDefault(e => e.TypeId == ammo.TypeId); // We do not have any ammo left that can hit targets at that range! if (charge == null) { if (Settings.Instance.DebugReloadorChangeAmmo) Logging.Log("Combat", "ReloadEnergyWeaponAmmo: We do not have any ammo left that can hit targets at that range!", Logging.Orange); return false; } if (Settings.Instance.DebugReloadorChangeAmmo) Logging.Log("Combat", "ReloadEnergyWeaponAmmo: charge: [" + charge.TypeName + "][" + charge.TypeId + "]", Logging.White); // We have enough ammo loaded if (weapon.Charge != null && weapon.Charge.TypeId == ammo.TypeId) { if (Settings.Instance.DebugReloadorChangeAmmo) Logging.Log("Combat", "ReloadEnergyWeaponAmmo: We have Enough Ammo of that type Loaded Already", Logging.White); return true; } // We are reloading, wait if (weapon.IsReloadingAmmo) return true; // We are reloading, wait if (weapon.IsChangingAmmo) return true; // Reload or change ammo if (weapon.Charge != null && weapon.Charge.TypeId == charge.TypeId) { // // reload // if (weapon.ReloadAmmo(charge, weaponNumber, (double) ammo.Range)) { return true; } return false; } // // change ammo // if (weapon.ChangeAmmo(charge, weaponNumber, (double) ammo.Range, entity.Name, entity.Distance)) { return true; } return false; }
/// <summary> Returns true if it can activate the weapon on the target /// </summary> /// <remarks> /// The idea behind this function is that a target that explodes is not being fired on within 5 seconds /// </remarks> /// <param name = "module"></param> /// <param name = "entity"></param> /// <param name = "isWeapon"></param> /// <returns></returns> private static bool CanActivate(ModuleCache module, EntityCache entity, bool isWeapon) { if (!module.IsOnline) { return false; } if (module.IsActive || !module.IsActivatable) { return false; } if (isWeapon && !entity.IsTarget) { Logging.Log("Combat.CanActivate", "We attempted to shoot [" + entity.Name + "][" + Math.Round(entity.Distance/1000, 2) + "] which is currently not locked!", Logging.Debug); return false; } if (isWeapon && entity.Distance > Cache.Instance.MaxRange) { Logging.Log("Combat.CanActivate", "We attempted to shoot [" + entity.Name + "][" + Math.Round(entity.Distance / 1000, 2) + "] which is out of weapons range!", Logging.Debug); return false; } if (module.IsReloadingAmmo) return false; if (module.IsChangingAmmo) return false; if (module.IsDeactivating) return false; // We have changed target, allow activation if (entity.Id != module.LastTargetId) return true; // We have reloaded, allow activation if (isWeapon && module.CurrentCharges == MaxCharges) return true; // if the module is not already active, we have a target, it is in range, we are not reloading then ffs shoot it... return true; }
public static bool ReloadAll(EntityCache entity, bool force = false) { _reloadAllIteration++; if (Settings.Instance.DebugReloadAll) Logging.Log("debug ReloadAll", "Entering reloadAll function (again) - it iterates through all weapon stacks [" + _reloadAllIteration + "]", Logging.White); if (_reloadAllIteration > 12) { if (Settings.Instance.DebugReloadAll) Logging.Log("debug ReloadAll:", "reset iteration counter", Logging.Orange); return true; } IEnumerable<ModuleCache> weapons = Cache.Instance.Weapons; _weaponNumber = 0; if (Settings.Instance.DebugReloadAll) Logging.Log("debug ReloadAll:", "Weapons (or stacks of weapons?): [" + Cache.Instance.Weapons.Count() + "]", Logging.Orange); foreach (ModuleCache weapon in weapons) { _weaponNumber++; // Reloading energy weapons prematurely just results in unnecessary error messages, so let's not do that if (weapon.IsEnergyWeapon) { if (Settings.Instance.DebugReloadAll) Logging.Log("debug ReloadAll:", "if (weapon.IsEnergyWeapon) continue (energy weapons do not really need to reload)", Logging.Orange); continue; } if (weapon.IsReloadingAmmo || weapon.IsDeactivating || weapon.IsChangingAmmo || weapon.IsActive) { if (Settings.Instance.DebugReloadAll) Logging.Log("debug ReloadAll", "Weapon [" + _weaponNumber + "] is busy, moving on to next weapon", Logging.White); continue; } if (LastWeaponReload.ContainsKey(weapon.ItemId) && DateTime.UtcNow < LastWeaponReload[weapon.ItemId].AddSeconds(Time.Instance.ReloadWeaponDelayBeforeUsable_seconds)) { if (Settings.Instance.DebugReloadAll) Logging.Log("debug ReloadAll", "Weapon [" + _weaponNumber + "] was just reloaded [" + Math.Round(DateTime.UtcNow.Subtract(LastWeaponReload[weapon.ItemId]).TotalSeconds, 0) + "] seconds ago , moving on to next weapon", Logging.White); continue; } if (Cache.Instance.CurrentShipsCargo != null && Cache.Instance.CurrentShipsCargo.Items.Any()) { if (!ReloadAmmo(weapon, entity, _weaponNumber)) return false; //by returning false here we make sure we only reload one gun (or stack) per iteration (basically per second) } continue; } if (Settings.Instance.DebugReloadAll) Logging.Log("debug ReloadAll", "completely reloaded all weapons", Logging.White); //_lastReloadAll = DateTime.UtcNow; _reloadAllIteration = 0; return true; }
public static bool WreckStatistics(IEnumerable<ItemCache> items, EntityCache containerEntity) { //if (Settings.Instance.DateTimeForLogs = EveTime) //{ // DateTimeForLogs = DateTime.UtcNow; //} //else //assume LocalTime //{ DateTimeForLogs = DateTime.Now; //} if (Settings.Instance.WreckLootStatistics) { if (containerEntity != null) { // Log all items found in the wreck File.AppendAllText(Settings.Instance.WreckLootStatisticsFile, "TIME: " + string.Format("{0:dd/MM/yyyy HH:mm:ss}", DateTimeForLogs) + "\n"); File.AppendAllText(Settings.Instance.WreckLootStatisticsFile, "NAME: " + containerEntity.Name + "\n"); File.AppendAllText(Settings.Instance.WreckLootStatisticsFile, "ITEMS:" + "\n"); foreach (ItemCache item in items.OrderBy(i => i.TypeId)) { File.AppendAllText(Settings.Instance.WreckLootStatisticsFile, "TypeID: " + item.TypeId.ToString(CultureInfo.InvariantCulture) + "\n"); File.AppendAllText(Settings.Instance.WreckLootStatisticsFile, "Name: " + item.Name + "\n"); File.AppendAllText(Settings.Instance.WreckLootStatisticsFile, "Quantity: " + item.Quantity.ToString(CultureInfo.InvariantCulture) + "\n"); File.AppendAllText(Settings.Instance.WreckLootStatisticsFile, "=\n"); } File.AppendAllText(Settings.Instance.WreckLootStatisticsFile, ";" + "\n"); } } return true; }
public EntityCache StargateByName(string locationName) { { return _stargate ?? (_stargate = Cache.Instance.EntitiesByName(locationName, Cache.Instance.Entities.Where(i => i.GroupId == (int)Group.Stargate)).FirstOrDefault(e => e.GroupId == (int)Group.Stargate)); } }
public bool OpenContainerInSpace(string module, EntityCache containerToOpen) { if (DateTime.UtcNow < Cache.Instance.NextLootAction) { return false; } if (Cache.Instance.InSpace && containerToOpen.Distance <= (int)Distances.ScoopRange) { Cache.Instance.ContainerInSpace = Cache.Instance.DirectEve.GetContainer(containerToOpen.Id); if (Cache.Instance.ContainerInSpace != null) { if (Cache.Instance.ContainerInSpace.Window == null) { containerToOpen.OpenCargo(); Cache.Instance.NextLootAction = DateTime.UtcNow.AddMilliseconds(Time.Instance.LootingDelay_milliseconds); Logging.Log(module, "Opening Container: waiting [" + Math.Round(Cache.Instance.NextLootAction.Subtract(DateTime.UtcNow).TotalSeconds, 0) + " sec]", Logging.White); return false; } if (!Cache.Instance.ContainerInSpace.Window.IsReady) { Logging.Log(module, "Container window is not ready", Logging.White); return false; } if (Cache.Instance.ContainerInSpace.Window.IsPrimary()) { Logging.Log(module, "Opening Container window as secondary", Logging.White); Cache.Instance.ContainerInSpace.Window.OpenAsSecondary(); Cache.Instance.NextLootAction = DateTime.UtcNow.AddMilliseconds(Time.Instance.LootingDelay_milliseconds); return true; } } return true; } Logging.Log(module, "Not in space or not in scoop range", Logging.Orange); return true; }
/// <summary> /// Invalidate the cached items /// </summary> public void InvalidateCache() { try { // // this list of variables is cleared every pulse. // _activeDrones = null; _agent = null; _aggressed = null; _allBookmarks = null; _ammoHangar = null; _approaching = null; _activeDrones = null; _bestDroneTargets = null; _bestPrimaryWeaponTargets = null; _bigObjects = null; _bigObjectsAndGates = null; _combatTargets = null; _currentShipsCargo = null; _containerInSpace = null; _containers = null; _entities = null; _entitiesNotSelf = null; _entitiesOnGrid = null; _entitiesById.Clear(); _fittingManagerWindow = null; _gates = null; _IDsinInventoryTree = null; _itemHangar = null; _jumpBridges = null; _lootContainer = null; _lootHangar = null; _lpStore = null; _maxLockedTargets = null; _maxDroneRange = null; _maxrange = null; _maxTargetRange = null; _modules = null; _modulesAsItemCache = null; _myShipEntity = null; _objects = null; _potentialCombatTargets = null; _primaryWeaponPriorityTargetsPerFrameCaching = null; _safeSpotBookmarks = null; _star = null; _stations = null; _stargate = null; _stargates = null; _targets = null; _targeting = null; _targetedBy = null; _TotalTargetsandTargeting = null; _unlootedContainers = null; _unlootedWrecksAndSecureCans = null; _weapons = null; _windows = null; _primaryWeaponPriorityEntities = null; _dronePriorityEntities = null; _preferredPrimaryWeaponTarget = null; //if (QuestorJustStarted && InvalidateCacheQuestorJustStartedFlag) //{ // InvalidateCacheQuestorJustStartedFlag = false; // if (Settings.Instance.DebugPreferredPrimaryWeaponTarget) Logging.Log("Cache.InvalidateCache", "QuestorJustStarted: initializing", Logging.Debug); if (_primaryWeaponPriorityTargets != null && _primaryWeaponPriorityTargets.Any()) { _primaryWeaponPriorityTargets.ForEach(pt => pt.ClearCache()); } if (_dronePriorityTargets != null && _dronePriorityTargets.Any()) { _dronePriorityTargets.ForEach(pt => pt.ClearCache()); } //} } catch (Exception exception) { Logging.Log("Cache.InvalidateCache", "Exception [" + exception + "]", Logging.Debug); } }
public EntityCache FindPrimaryWeaponPriorityTarget(EntityCache currentTarget, PrimaryWeaponPriority priorityType, bool AddECMTypeToPrimaryWeaponPriorityTargetList, double Distance, bool FindAUnTargetedEntity = true) { if (AddECMTypeToPrimaryWeaponPriorityTargetList) { //if (Settings.Instance.DebugGetBestTarget) Logging.Log(callingroutine + " Debug: GetBestTarget", "Checking for Neutralizing priority targets (currentTarget first)", Logging.Teal); // Choose any Neutralizing primary weapon priority targets try { EntityCache target = null; try { if (Cache.Instance.PrimaryWeaponPriorityEntities.Any(pt => pt.PrimaryWeaponPriorityLevel == priorityType)) { target = Cache.Instance.PrimaryWeaponPriorityEntities.Where(pt => ((FindAUnTargetedEntity || pt.IsReadyToShoot) && currentTarget != null && pt.Id == currentTarget.Id && pt.Distance < Distance && pt.IsActivePrimaryWeaponEwarType == priorityType && !pt.IsTooCloseTooFastTooSmallToHit) || ((FindAUnTargetedEntity || pt.IsReadyToShoot) && pt.Distance < Distance && pt.PrimaryWeaponPriorityLevel == priorityType && !pt.IsTooCloseTooFastTooSmallToHit)) .OrderByDescending(pt => pt.IsReadyToShoot) .ThenByDescending(pt => pt.IsCurrentTarget) .ThenByDescending(pt => !pt.IsNPCFrigate) .ThenByDescending(pt => pt.IsInOptimalRange) .ThenBy(pt => (pt.ShieldPct + pt.ArmorPct + pt.StructurePct)) .ThenBy(pt => pt.Distance) .FirstOrDefault(); } } catch (NullReferenceException) { } // Not sure why this happens, but seems to be no problem if (target != null) { if (!FindAUnTargetedEntity) { //if (Settings.Instance.DebugGetBestTarget) Logging.Log(callingroutine + " Debug: GetBestTarget", "NeutralizingPrimaryWeaponPriorityTarget [" + NeutralizingPriorityTarget.Name + "][" + Math.Round(NeutralizingPriorityTarget.Distance / 1000, 2) + "k][" + Cache.Instance.MaskedID(NeutralizingPriorityTarget.Id) + "] GroupID [" + NeutralizingPriorityTarget.GroupId + "]", Logging.Debug); Logging.Log("FindPrimaryWeaponPriorityTarget", "if (!FindAUnTargetedEntity) Cache.Instance.PreferredPrimaryWeaponTargetID = [ " + target.Name + "][" + Cache.Instance.MaskedID(target.Id) + "]", Logging.White); Cache.Instance.PreferredPrimaryWeaponTarget = target; Cache.Instance.LastPreferredPrimaryWeaponTargetDateTime = DateTime.UtcNow; return target; } return target; } return null; } catch (NullReferenceException) { } return null; } return null; }
public void ClearPerPocketCache() { try { _doWeCurrentlyHaveTurretsMounted = null; LastTargetPrimaryWeaponsWereShooting = null; LastDroneTargetID = null; ListOfWarpScramblingEntities.Clear(); ListOfJammingEntities.Clear(); ListOfTrackingDisruptingEntities.Clear(); ListNeutralizingEntities.Clear(); ListOfTargetPaintingEntities.Clear(); ListOfDampenuingEntities.Clear(); ListofWebbingEntities.Clear(); ListofContainersToLoot.Clear(); ListofMissionCompletionItemsToLoot.Clear(); ListOfUndockBookmarks = null; EntityNames.Clear(); EntityTypeID.Clear(); EntityGroupID.Clear(); EntityBounty.Clear(); EntityIsFrigate.Clear(); EntityIsNPCFrigate.Clear(); EntityIsCruiser.Clear(); EntityIsNPCCruiser.Clear(); EntityIsBattleCruiser.Clear(); EntityIsNPCBattleCruiser.Clear(); EntityIsBattleShip.Clear(); EntityIsNPCBattleShip.Clear(); EntityIsHighValueTarget.Clear(); EntityIsLowValueTarget.Clear(); EntityIsLargeCollidable.Clear(); EntityIsSentry.Clear(); EntityIsMiscJunk.Clear(); EntityIsBadIdea.Clear(); EntityIsFactionWarfareNPC.Clear(); EntityIsNPCByGroupID.Clear(); EntityIsEntutyIShouldLeaveAlone.Clear(); EntityHaveLootRights.Clear(); EntityIsStargate.Clear(); } catch (Exception ex) { Logging.Log("ClearPerPocketCache", "Exception [" + ex + "]", Logging.Debug); return; } }
/// <summary> Activate target painters /// </summary> public void ActivateTargetPainters(EntityCache target) { //if (DateTime.UtcNow < Cache.Instance.NextPainterAction) //if we just did something wait a fraction of a second // return; List<ModuleCache> targetPainters = Cache.Instance.Modules.Where(m => m.GroupId == (int)Group.TargetPainter).ToList(); // Find the first active weapon // Assist this weapon _weaponNumber = 0; foreach (ModuleCache painter in targetPainters) { if (painter.ActivatedTimeStamp.AddSeconds(3) > DateTime.UtcNow) continue; _weaponNumber++; // Are we on the right target? if (painter.IsActive) { if (painter.TargetId != target.Id) { painter.Click(); return; } continue; } // Are we deactivating? if (painter.IsDeactivating) continue; if (CanActivate(painter, target, false)) { Logging.Log("Combat", "Activating painter [" + _weaponNumber + "] on [" + target.Name + "][ID: " + Cache.Instance.MaskedID(target.Id) + "][" + Math.Round(target.Distance / 1000, 0) + "k away]", Logging.Teal); painter.Activate(target.Id); Cache.Instance.NextPainterAction = DateTime.UtcNow.AddMilliseconds(Time.Instance.PainterDelay_milliseconds); return; } } }
/// <summary> Returns true if it can activate the weapon on the target /// </summary> /// <remarks> /// The idea behind this function is that a target that explodes is not being fired on within 5 seconds /// </remarks> /// <param name = "module"></param> /// <param name = "entity"></param> /// <param name = "isWeapon"></param> /// <returns></returns> public bool CanActivate(ModuleCache module, EntityCache entity, bool isWeapon) { if (isWeapon && !entity.IsTarget) return false; // We have changed target, allow activation if (entity.Id != module.LastTargetId) return true; // We have reloaded, allow activation if (isWeapon && module.CurrentCharges == MaxCharges) return true; // We haven't reloaded, insert a wait-time if (_lastModuleActivation.ContainsKey(module.ItemId)) { if (DateTime.UtcNow.Subtract(_lastModuleActivation[module.ItemId]).TotalSeconds < 3) return false; _lastModuleActivation.Remove(module.ItemId); return true; } _lastModuleActivation.Add(module.ItemId, DateTime.UtcNow); return false; }
private static void ActivateRemoteRepair(EntityCache target) { if (DateTime.UtcNow < Cache.Instance.NextRemoteRepairAction) //if we just did something wait a fraction of a second return; List<ModuleCache> RemoteRepairers = Cache.Instance.Modules.Where(m => m.GroupId == (int)Group.RemoteArmorRepairer || m.GroupId == (int)Group.RemoteShieldRepairer || m.GroupId == (int)Group.RemoteHullRepairer ).ToList(); // Find the first active weapon // Assist this weapon _weaponNumber = 0; if (RemoteRepairers.Any()) { if (Settings.Instance.DebugRemoteRepair) Logging.Log("ActivateRemoteRepair", "RemoteRepairers [" + RemoteRepairers.Count() + "] Target Distance [" + Math.Round(target.Distance / 1000, 0) + "] RemoteRepairDistance [" + Math.Round(((double)Settings.Instance.RemoteRepairDistance / 1000), digits: 0) + "]", Logging.Debug); foreach (ModuleCache RemoteRepairer in RemoteRepairers) { _weaponNumber++; // Are we on the right target? if (RemoteRepairer.IsActive) { if (RemoteRepairer.TargetId != target.Id) { RemoteRepairer.Click(); return; } continue; } // Are we deactivating? if (RemoteRepairer.IsDeactivating) continue; // Target is out of RemoteRepair range if (target.Distance >= RemoteRepairer.MaxRange) continue; if (CanActivate(RemoteRepairer, target, false)) { Logging.Log("Combat", "Activating RemoteRepairer [" + _weaponNumber + "] on [" + target.Name + "][" + Cache.Instance.MaskedID(target.Id) + "]", Logging.Teal); RemoteRepairer.Activate(target.Id); Cache.Instance.NextRemoteRepairAction = DateTime.UtcNow.AddMilliseconds(Time.Instance.RemoteRepairerDelay_milliseconds); return; } } } }
/// <summary> Activate weapons /// </summary> private void ActivateWeapons(EntityCache target) { // When in warp there's nothing we can do, so ignore everything if (Cache.Instance.InWarp) { Cache.Instance.RemovePrimaryWeaponPriorityTargets(Cache.Instance.PrimaryWeaponPriorityTargets); Cache.Instance.RemoveDronePriorityTargets(Cache.Instance.DronePriorityTargets); if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: deactivate: we are in warp! doing nothing", Logging.Teal); return; } if (DateTime.UtcNow < Cache.Instance.NextWeaponAction) //if we just did something wait a fraction of a second { if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: deactivate: waiting on NextWeaponAction", Logging.Teal); return; } // // Do we really want a non-mission action moving the ship around at all!! (other than speed tanking)? // If you are not in a mission by all means let combat actions move you around as needed if (!Cache.Instance.InMission || Settings.Instance.SpeedTank) { if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: deactivate: we are NOT in a mission: navigateintorange", Logging.Teal); NavigateOnGrid.NavigateIntoRange(target, "Combat"); } if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: deactivate: after navigate into range...", Logging.Teal); // Get the weapons IEnumerable<ModuleCache> weapons = Cache.Instance.Weapons.ToList(); // TODO: Add check to see if there is better ammo to use! :) // Get distance of the target and compare that with the ammo currently loaded //Deactivate weapons that needs to be deactivated for this list of reasons... _weaponNumber = 0; foreach (ModuleCache weapon in weapons) { _weaponNumber++; if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: deactivate: for each weapon [" + _weaponNumber + "] in weapons", Logging.Teal); if (!weapon.IsActive) { if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: deactivate: weapon [" + _weaponNumber + "] is not active: no need to do anything", Logging.Teal); continue; } if (weapon.IsReloadingAmmo || weapon.IsDeactivating || weapon.IsChangingAmmo) { if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: deactivate: weapon [" + _weaponNumber + "] is reloading, deactivating or changing ammo: no need to do anything", Logging.Teal); continue; } //if (DateTime.UtcNow < Cache.Instance.NextReload) //if we should not yet reload we are likely in the middle of a reload and should wait! //{ // if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: deactivate: NextReload is still in the future: wait before doing anything with the weapon", Logging.teal); // return; //} // No ammo loaded if (weapon.Charge == null) { if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: deactivate: no ammo loaded? [" + _weaponNumber + "] reload will happen elsewhere", Logging.Teal); continue; } Ammo ammo = Settings.Instance.Ammo.FirstOrDefault(a => a.TypeId == weapon.Charge.TypeId); //use mission specific ammo if (Cache.Instance.MissionAmmo.Count() != 0) { if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: deactivate: MissionAmmocount is not 0", Logging.Teal); ammo = Cache.Instance.MissionAmmo.FirstOrDefault(a => a.TypeId == weapon.Charge.TypeId); } // How can this happen? Someone manually loaded ammo if (ammo == null) { if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: deactivate: ammo == null [" + _weaponNumber + "] someone manually loaded ammo?", Logging.Teal); continue; } // If we have already activated warp, deactivate the weapons if (!Cache.Instance.DirectEve.ActiveShip.Entity.IsWarping) { // Target is in range if (target.Distance <= ammo.Range) { if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: deactivate: target is in range: do nothing, wait until it is dead", Logging.Teal); continue; } } // Target is out of range, stop firing if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: deactivate: target is out of range, stop firing", Logging.Teal); weapon.Click(); return; } // Hack for max charges returning incorrect value if (!weapons.Any(w => w.IsEnergyWeapon)) { MaxCharges = Math.Max(MaxCharges, weapons.Max(l => l.MaxCharges)); MaxCharges = Math.Max(MaxCharges, weapons.Max(l => l.CurrentCharges)); } int weaponsActivatedThisTick = 0; int weaponsToActivateThisTick = Cache.Instance.RandomNumber(1, 2); // Activate the weapons (it not yet activated))) _weaponNumber = 0; foreach (ModuleCache weapon in weapons) { _weaponNumber++; // Are we reloading, deactivating or changing ammo? if (weapon.IsReloadingAmmo || weapon.IsDeactivating || weapon.IsChangingAmmo) { if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: Activate: weapon [" + _weaponNumber + "] is reloading, deactivating or changing ammo", Logging.Teal); continue; } // Are we on the right target? if (weapon.IsActive) { if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: Activate: weapon [" + _weaponNumber + "] is active already", Logging.Teal); if (weapon.TargetId != target.Id) { if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: Activate: weapon [" + _weaponNumber + "] is shooting at the wrong target: deactivating", Logging.Teal); weapon.Click(); return; } continue; } // No, check ammo type and if that is correct, activate weapon if (ReloadAmmo(weapon, target, _weaponNumber) && CanActivate(weapon, target, true)) { if (weaponsActivatedThisTick > weaponsToActivateThisTick) //if we have already activated x num of weapons return, which will wait until the next ProcessState return; if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: Activate: weapon [" + _weaponNumber + "] has the correct ammo: activate", Logging.Teal); weaponsActivatedThisTick++; //increment the num of weapons we have activated this ProcessState so that we might optionally activate more than one module per tick Logging.Log("Combat", "Activating weapon [" + _weaponNumber + "] on [" + target.Name + "][ID: " + Cache.Instance.MaskedID(target.Id) + "][" + Math.Round(target.Distance / 1000, 0) + "k away]", Logging.Teal); weapon.Activate(target.Id); Cache.Instance.NextWeaponAction = DateTime.UtcNow.AddMilliseconds(Time.Instance.WeaponDelay_milliseconds); //we know we are connected if we were able to get this far - update the lastknownGoodConnectedTime Cache.Instance.LastKnownGoodConnectedTime = DateTime.UtcNow; Cache.Instance.MyWalletBalance = Cache.Instance.DirectEve.Me.Wealth; continue; } } }
private static void ActivateWarpDisruptor(EntityCache target) { if (DateTime.UtcNow < Cache.Instance.NextWarpDisruptorAction) //if we just did something wait a fraction of a second return; List<ModuleCache> WarpDisruptors = Cache.Instance.Modules.Where(m => m.GroupId == (int)Group.WarpDisruptor).ToList(); // Find the first active weapon // Assist this weapon _weaponNumber = 0; foreach (ModuleCache WarpDisruptor in WarpDisruptors) { _weaponNumber++; // Are we on the right target? if (WarpDisruptor.IsActive) { if (WarpDisruptor.TargetId != target.Id) { WarpDisruptor.Click(); return; } continue; } // Are we deactivating? if (WarpDisruptor.IsDeactivating) continue; // Target is out of web range if (target.Distance >= WarpDisruptor.OptimalRange) continue; if (CanActivate(WarpDisruptor, target, false)) { Logging.Log("Combat", "Activating WarpDisruptor [" + _weaponNumber + "] on [" + target.Name + "][" + Cache.Instance.MaskedID(target.Id) + "]", Logging.Teal); WarpDisruptor.Activate(target.Id); Cache.Instance.NextWarpDisruptorAction = DateTime.UtcNow.AddMilliseconds(Time.Instance.WarpDisruptorDelay_milliseconds); return; } } }
/// <summary> Reload correct (tm) ammo for the NPC /// </summary> /// <param name = "weapon"></param> /// <param name = "entity"></param> /// <param name = "weaponNumber"></param> /// <returns>True if the (enough/correct) ammo is loaded, false if wrong/not enough ammo is loaded</returns> private static bool ReloadAmmo(ModuleCache weapon, EntityCache entity, int weaponNumber) { // We need the cargo bay open for both reload actions //if (!Cache.Instance.OpenCargoHold("Combat: ReloadAmmo")) return false; return weapon.IsEnergyWeapon ? ReloadEnergyWeaponAmmo(weapon, entity, weaponNumber) : ReloadNormalAmmo(weapon, entity, weaponNumber); }
/// <summary> Returns true if it can activate the weapon on the target /// </summary> /// <remarks> /// The idea behind this function is that a target that explodes is not being fired on within 5 seconds /// </remarks> /// <param name = "module"></param> /// <param name = "entity"></param> /// <param name = "isWeapon"></param> /// <returns></returns> private static bool CanActivate(ModuleCache module, EntityCache entity, bool isWeapon) { if (!module.IsOnline) { return false; } if (isWeapon && !entity.IsTarget) { Logging.Log("Combat.CanActivate", "We attempted to shoot [" + entity.Name + "][" + Math.Round(entity.Distance/1000, 2) + "] which is currently not locked!", Logging.Debug); return false; } if (isWeapon && entity.Distance > Cache.Instance.MaxRange) { Logging.Log("Combat.CanActivate", "We attempted to shoot [" + entity.Name + "][" + Math.Round(entity.Distance / 1000, 2) + "] which is out of weapons range!", Logging.Debug); return false; } // We have changed target, allow activation if (entity.Id != module.LastTargetId) return true; // We have reloaded, allow activation if (isWeapon && module.CurrentCharges == MaxCharges) return true; // We haven't reloaded, insert a wait-time if (_lastModuleActivation.ContainsKey(module.ItemId)) { if (DateTime.UtcNow.Subtract(_lastModuleActivation[module.ItemId]).TotalSeconds < 3) return false; _lastModuleActivation.Remove(module.ItemId); return true; } _lastModuleActivation.Add(module.ItemId, DateTime.UtcNow); return false; }
//~Combat() //{ // Interlocked.Decrement(ref CombatInstances); //} // Reload correct (tm) ammo for the NPC // (enough/correct) ammo is loaded, false if wrong/not enough ammo is loaded private static bool ReloadNormalAmmo(ModuleCache weapon, EntityCache entity, int weaponNumber, bool force = false) { if (Settings.Instance.WeaponGroupId == 53) return true; if (entity == null) { if (Settings.Instance.DebugReloadAll) Logging.Log("debug ReloadAll:", "if (entity == null)", Logging.Orange); return false; } List<Ammo> correctAmmoToUse = null; List<Ammo> correctAmmoInCargo = null; // // NOTE: This new setting is NOT ready for use! // NOTE: when we are finished molesting ReloadNormalAmmo we should do the same to the routine used for lasers... // // // ammo selection based on target size // if (Settings.Instance.SelectAmmoToUseBasedOnShipSize) { if (Cache.Instance.LastChangedAmmoTimeStamp != null && Cache.Instance.LastChangedAmmoTimeStamp.ContainsKey(weapon.ItemId)) { // // Do not allow the changing of ammo if we already changed ammo in the last 60 seconds AND we do not need to reload yet // if (DateTime.UtcNow < Cache.Instance.LastChangedAmmoTimeStamp[weapon.ItemId].AddSeconds(Time.Instance.EnforcedDelayBetweenArbitraryAmmoChanges)) { if (weapon.CurrentCharges >= Settings.Instance.MinimumAmmoCharges && !force) { if (Settings.Instance.DebugReloadAll) Logging.Log("debug ReloadAll:", "[" + weapon.TypeName + "] last reloaded [" + DateTime.UtcNow.Subtract(Cache.Instance.LastChangedAmmoTimeStamp[weapon.ItemId]).TotalSeconds + "sec ago] [ " + weapon.CurrentCharges + " ] charges in in [" + Cache.Instance.Weapons.Count() + "] total weapons, minimum of [" + Settings.Instance.MinimumAmmoCharges + "] charges, MaxCharges is [" + weapon.MaxCharges + "]", Logging.Orange); return true; } } } if (Settings.Instance.Ammo.Any(a => a.DamageType == Cache.Instance.MissionDamageType)) { // Get ammo based on damage type correctAmmoToUse = Settings.Instance.Ammo.Where(a => a.DamageType == Cache.Instance.MissionDamageType).ToList(); // // get Ammo Based on entity we are shooting's size class, default to normal ammo if we cant determine its size // if (entity.IsBattleship) { // this needs one more layer somewhere to determine the right damage type for battleships, etc (EM, kinetic, etc) and it needs to do it for // default, faction and mission specific layers // //correctAmmoToUse = Settings.Instance.Ammo.Where(a => a.DamageType == DamageType.BattleShip_EM).ToList(); } else if (entity.IsBattlecruiser) { //correctAmmoToUse = Settings.Instance.Ammo.Where(a => a.DamageType == DamageType.BattleShip_EM).ToList(); } else if (entity.IsCruiser) { //correctAmmoToUse = Settings.Instance.Ammo.Where(a => a.DamageType == DamageType.BattleShip_EM).ToList(); } else if (entity.IsFrigate) { //correctAmmoToUse = Settings.Instance.Ammo.Where(a => a.DamageType == DamageType.Frigate_EM).ToList(); } else if (entity.IsLargeCollidable) { //correctAmmoToUse = Settings.Instance.Ammo.Where(a => a.DamageType == DamageType.LargeCollidable_EM).ToList(); } else if (entity.IsPlayer) { //correctAmmoToUse = Settings.Instance.Ammo.Where(a => a.DamageType == DamageType.PVP_EM).ToList(); } // Check if we still have that ammo in our cargo correctAmmoInCargo = correctAmmoToUse.Where(a => Cache.Instance.CurrentShipsCargo.Items.Any(i => i.TypeId == a.TypeId && i.Quantity >= Settings.Instance.MinimumAmmoCharges)).ToList(); //check if mission specific ammo is defined if (Cache.Instance.MissionAmmo.Count() != 0) { correctAmmoInCargo = Cache.Instance.MissionAmmo.Where(a => a.DamageType == Cache.Instance.MissionDamageType).ToList(); } // Check if we still have that ammo in our cargo correctAmmoInCargo = correctAmmoInCargo.Where(a => Cache.Instance.CurrentShipsCargo.Items.Any(i => i.TypeId == a.TypeId && i.Quantity >= Settings.Instance.MinimumAmmoCharges)).ToList(); if (Cache.Instance.MissionAmmo.Count() != 0) { correctAmmoInCargo = Cache.Instance.MissionAmmo; } // We are out of ammo! :( if (!correctAmmoInCargo.Any()) { Logging.Log("Combat", "ReloadNormalAmmo: not enough [" + Cache.Instance.MissionDamageType + "] ammo in cargohold: MinimumCharges: [" + Settings.Instance.MinimumAmmoCharges + "]", Logging.Orange); _States.CurrentCombatState = CombatState.OutOfAmmo; return false; } } else { Logging.Log("Combat", "ReloadNormalAmmo: ammo is not defined properly in the ammo section of this characters settings xml", Logging.Orange); _States.CurrentCombatState = CombatState.OutOfAmmo; return false; } } else { // // normal ammo selection - ignore target attributes and uses the right ammo for the pocket // if (Settings.Instance.Ammo.Any(a => a.DamageType == Cache.Instance.MissionDamageType)) { // Get ammo based on damage type correctAmmoToUse = Settings.Instance.Ammo.Where(a => a.DamageType == Cache.Instance.MissionDamageType).ToList(); // Check if we still have that ammo in our cargo correctAmmoInCargo = correctAmmoToUse.Where(a => Cache.Instance.CurrentShipsCargo.Items.Any(i => i.TypeId == a.TypeId && i.Quantity >= Settings.Instance.MinimumAmmoCharges)).ToList(); //check if mission specific ammo is defined if (Cache.Instance.MissionAmmo.Count() != 0) { correctAmmoInCargo = Cache.Instance.MissionAmmo.Where(a => a.DamageType == Cache.Instance.MissionDamageType).ToList(); } // Check if we still have that ammo in our cargo correctAmmoInCargo = correctAmmoInCargo.Where(a => Cache.Instance.CurrentShipsCargo.Items.Any(i => i.TypeId == a.TypeId && i.Quantity >= Settings.Instance.MinimumAmmoCharges)).ToList(); if (Cache.Instance.MissionAmmo.Count() != 0) { correctAmmoInCargo = Cache.Instance.MissionAmmo; } // We are out of ammo! :( if (!correctAmmoInCargo.Any()) { Logging.Log("Combat", "ReloadNormalAmmo: not enough [" + Cache.Instance.MissionDamageType + "] ammo in cargohold: MinimumCharges: [" + Settings.Instance.MinimumAmmoCharges + "]", Logging.Orange); _States.CurrentCombatState = CombatState.OutOfAmmo; return false; } } else { Logging.Log("Combat", "ReloadNormalAmmo: ammo is not defined properly in the ammo section of this characters settings xml", Logging.Orange); _States.CurrentCombatState = CombatState.OutOfAmmo; return false; } } /****** if (weapon.Charge != null) { IEnumerable<Ammo> areWeMissingAmmo = correctAmmo.Where(a => a.TypeId == weapon.Charge.TypeId); if (!areWeMissingAmmo.Any()) { if (DateTime.UtcNow.Subtract(Cache.Instance.LastLoggingAction).TotalSeconds > 4) { Logging.Log("Combat", "ReloadNormalAmmo: We have ammo loaded that does not have a full reload available, checking cargo for other ammo", Logging.Orange); Cache.Instance.LastLoggingAction = DateTime.UtcNow; try { if (Settings.Instance.Ammo.Any()) { DirectItem availableAmmo = cargo.Items.OrderByDescending(i => i.Quantity).Where(a => Settings.Instance.Ammo.Any(i => i.TypeId == a.TypeId)).ToList().FirstOrDefault(); if (availableAmmo != null) { Cache.Instance.DamageType = Settings.Instance.Ammo.ToList().OrderByDescending(i => i.Quantity).Where(a => a.TypeId == availableAmmo.TypeId).ToList().FirstOrDefault().DamageType; Logging.Log("Combat", "ReloadNormalAmmo: found [" + availableAmmo.Quantity + "] units of [" + availableAmmo.TypeName + "] changed DamageType to [" + Cache.Instance.DamageType.ToString() + "]", Logging.Orange); return false; } Logging.Log("Combat", "ReloadNormalAmmo: unable to find any alternate ammo in your cargo", Logging.teal); _States.CurrentCombatState = CombatState.OutOfAmmo; return false; } } catch (Exception) { Logging.Log("Combat", "ReloadNormalAmmo: unable to find any alternate ammo in your cargo", Logging.teal); _States.CurrentCombatState = CombatState.OutOfAmmo; } return false; } } } *****/ // Get the best possible ammo Ammo ammo = correctAmmoInCargo.FirstOrDefault(); try { if (ammo != null && entity != null) { ammo = correctAmmoInCargo.Where(a => a.Range > entity.Distance).OrderBy(a => a.Range).FirstOrDefault(); } } catch (Exception exception) { Logging.Log("Combat", "ReloadNormalAmmo: Unable to find the correct ammo: waiting [" + exception + "]", Logging.Teal); return false; } // We do not have any ammo left that can hit targets at that range! if (ammo == null) { if (Settings.Instance.DebugReloadAll) Logging.Log("debug ReloadAll:", "We do not have any ammo left that can hit targets at that range!", Logging.Orange); return false; } // Do We have enough ammo loaded? if (weapon.Charge != null && weapon.Charge.TypeId == ammo.TypeId) { if (weapon.CurrentCharges >= Settings.Instance.MinimumAmmoCharges && !force) { if (Settings.Instance.DebugReloadAll) Logging.Log("debug ReloadAll:", "[ " + weapon.CurrentCharges + " ] charges in in [" + Cache.Instance.Weapons.Count() + "] total weapons, minimum of [" + Settings.Instance.MinimumAmmoCharges + "] charges, MaxCharges is [" + weapon.MaxCharges + "]", Logging.Orange); return true; } if (weapon.CurrentCharges >= weapon.MaxCharges && force) { // // even if force is true do not reload a weapon that is already full! // if (Settings.Instance.DebugReloadAll) Logging.Log("debug ReloadAll:", "[ " + weapon.CurrentCharges + " ] charges in [" + Cache.Instance.Weapons.Count() + "] total weapons, MaxCharges [" + weapon.MaxCharges + "]", Logging.Orange); return true; } if (force && weapon.CurrentCharges < weapon.MaxCharges) { // // allow the reload (and log it!) // if (Settings.Instance.DebugReloadAll) Logging.Log("debug ReloadAll:", "[ " + weapon.CurrentCharges + " ] charges in [" + Cache.Instance.Weapons.Count() + "] total weapons, MaxCharges [" + weapon.MaxCharges + "] - forced reloading proceeding", Logging.Orange); } } // Retry later, assume its ok now //if (!weapon.MatchingAmmo.Any()) //{ // LastWeaponReload[weapon.ItemId] = DateTime.UtcNow; //mark this weapon as reloaded... by the time we need to reload this timer will have aged enough... // return true; //} DirectItem charge = Cache.Instance.CurrentShipsCargo.Items.FirstOrDefault(e => e.TypeId == ammo.TypeId && e.Quantity >= Settings.Instance.MinimumAmmoCharges); // This should have shown up as "out of ammo" if (charge == null) { if (Settings.Instance.DebugReloadAll) Logging.Log("debug ReloadAll:", "This should have shown up as out of ammo", Logging.Orange); return false; } // If we are reloading, wait Time.ReloadWeaponDelayBeforeUsable_seconds (see time.cs) if (weapon.IsReloadingAmmo) { if (Settings.Instance.DebugReloadAll) Logging.Log("debug ReloadAll:", "We are already reloading, wait - weapon.IsReloadingAmmo [" + weapon.IsReloadingAmmo + "]", Logging.Orange); return true; } // If we are changing ammo, wait Time.ReloadWeaponDelayBeforeUsable_seconds (see time.cs) if (weapon.IsChangingAmmo) { if (Settings.Instance.DebugReloadAll) Logging.Log("debug ReloadAll:", "We are already changing ammo, wait - weapon.IsReloadingAmmo [" + weapon.IsReloadingAmmo + "]", Logging.Orange); return true; } try { // Reload or change ammo if (weapon.Charge != null && weapon.Charge.TypeId == charge.TypeId && !weapon.IsChangingAmmo) { if (weapon.ReloadAmmo(charge, weaponNumber, (double) ammo.Range)) { return true; } return false; } if (weapon.ChangeAmmo(charge, weaponNumber, (double) ammo.Range, entity.Name, entity.Distance)) { return true; } return false; } catch (Exception exception) { Logging.Log("Combat.ReloadNormalAmmo", "Exception [" + exception + "]", Logging.Debug); } // Return true as we are reloading ammo, assume it is the correct ammo... return true; }
public static bool ReloadEnergyWeaponAmmo(ModuleCache weapon, EntityCache entity, int weaponNumber) { DirectContainer cargo = Cache.Instance.DirectEve.GetShipsCargo(); // Get ammo based on damage type IEnumerable<Ammo> correctAmmo = Settings.Instance.Ammo.Where(a => a.DamageType == Cache.Instance.DamageType).ToList(); // Check if we still have that ammo in our cargo IEnumerable<Ammo> correctAmmoInCargo = correctAmmo.Where(a => cargo.Items.Any(i => i.TypeId == a.TypeId)).ToList(); //check if mission specific ammo is defined if (Cache.Instance.MissionAmmo.Count() != 0) { correctAmmoInCargo = Cache.Instance.MissionAmmo.Where(a => a.DamageType == Cache.Instance.DamageType).ToList(); } // Check if we still have that ammo in our cargo correctAmmoInCargo = correctAmmoInCargo.Where(a => cargo.Items.Any(i => i.TypeId == a.TypeId && i.Quantity >= Settings.Instance.MinimumAmmoCharges)).ToList(); if (Cache.Instance.MissionAmmo.Count() != 0) { correctAmmoInCargo = Cache.Instance.MissionAmmo; } // We are out of ammo! :( if (!correctAmmoInCargo.Any()) { Logging.Log("Combat", "ReloadEnergyWeapon: not enough [" + Cache.Instance.DamageType + "] ammo in cargohold: MinimumCharges: [" + Settings.Instance.MinimumAmmoCharges + "]", Logging.Orange); _States.CurrentCombatState = CombatState.OutOfAmmo; return false; } if (weapon.Charge != null) { IEnumerable<Ammo> areWeMissingAmmo = correctAmmoInCargo.Where(a => a.TypeId == weapon.Charge.TypeId); if (!areWeMissingAmmo.Any()) { Logging.Log("Combat", "ReloadEnergyWeaponAmmo: We have ammo loaded that does not have a full reload available in the cargo.", Logging.Orange); } } // Get the best possible ammo - energy weapons change ammo near instantly Ammo ammo = correctAmmoInCargo.Where(a => a.Range > (entity.Distance)).OrderBy(a => a.Range).FirstOrDefault(); //default // We do not have any ammo left that can hit targets at that range! if (ammo == null) { if (Settings.Instance.DebugReloadorChangeAmmo) Logging.Log("Combat", "ReloadEnergyWeaponAmmo: best possible ammo: [ ammo == null]", Logging.White); return false; } if (Settings.Instance.DebugReloadorChangeAmmo) Logging.Log("Combat", "ReloadEnergyWeaponAmmo: best possible ammo: [" + ammo.TypeId + "][" + ammo.DamageType + "]", Logging.White); if (Settings.Instance.DebugReloadorChangeAmmo) Logging.Log("Combat", "ReloadEnergyWeaponAmmo: best possible ammo: [" + entity.Name + "][" + Math.Round(entity.Distance / 1000, 0) + "]", Logging.White); DirectItem charge = cargo.Items.OrderBy(i => i.Quantity).FirstOrDefault(i => i.TypeId == ammo.TypeId); // We do not have any ammo left that can hit targets at that range! if (charge == null) { if (Settings.Instance.DebugReloadorChangeAmmo) Logging.Log("Combat", "ReloadEnergyWeaponAmmo: We do not have any ammo left that can hit targets at that range!", Logging.Orange); return false; } if (Settings.Instance.DebugReloadorChangeAmmo) Logging.Log("Combat", "ReloadEnergyWeaponAmmo: charge: [" + charge.TypeName + "][" + charge.TypeId + "]", Logging.White); // We have enough ammo loaded if (weapon.Charge != null && weapon.Charge.TypeId == ammo.TypeId) { if (Settings.Instance.DebugReloadorChangeAmmo) Logging.Log("Combat", "ReloadEnergyWeaponAmmo: We have Enough Ammo of that type Loaded Already", Logging.White); return true; } // We are reloading, wait at least 5 seconds if (LastWeaponReload.ContainsKey(weapon.ItemId) && DateTime.UtcNow < LastWeaponReload[weapon.ItemId].AddSeconds(5)) { if (Settings.Instance.DebugReloadorChangeAmmo) Logging.Log("Combat", "ReloadEnergyWeaponAmmo: We are currently reloading: waiting", Logging.White); return false; } LastWeaponReload[weapon.ItemId] = DateTime.UtcNow; // Reload or change ammo if (weapon.Charge != null && weapon.Charge.TypeId == charge.TypeId) { Logging.Log("Combat", "Reloading [" + weaponNumber + "] with [" + charge.TypeName + "][" + Math.Round((double)ammo.Range / 1000, 0) + "][TypeID: " + charge.TypeId + "]", Logging.Teal); weapon.ReloadAmmo(charge); weapon.ReloadTimeThisMission = weapon.ReloadTimeThisMission + 1; } else { Logging.Log("Combat", "Changing [" + weaponNumber + "] with [" + charge.TypeName + "][" + Math.Round((double)ammo.Range / 1000, 0) + "][TypeID: " + charge.TypeId + "] so we can hit [" + entity.Name + "][" + Math.Round(entity.Distance / 1000, 0) + "k]", Logging.Teal); weapon.ChangeAmmo(charge); weapon.ReloadTimeThisMission = weapon.ReloadTimeThisMission + 1; } // Return false as we are reloading ammo return false; }
/// <summary> Activate Nos /// </summary> private static void ActivateNos(EntityCache target) { List<ModuleCache> noses = Cache.Instance.Modules.Where(m => m.GroupId == (int)Group.NOS || m.GroupId == (int)Group.Neutralizer).ToList(); //Logging.Log("Combat: we have " + noses.Count.ToString() + " Nos modules"); // Find the first active weapon // Assist this weapon _weaponNumber = 0; foreach (ModuleCache nos in noses) { _weaponNumber++; if (Cache.Instance.LastActivatedTimeStamp != null && Cache.Instance.LastActivatedTimeStamp.ContainsKey(nos.ItemId)) { if (Cache.Instance.LastActivatedTimeStamp[nos.ItemId].AddMilliseconds(Time.Instance.NosDelay_milliseconds) > DateTime.UtcNow) { continue; } } // Are we on the right target? if (nos.IsActive) { if (nos.TargetId != target.Id) { if (nos.Click()) return; return; } continue; } // Are we deactivating? if (nos.IsDeactivating) continue; //Logging.Log("Combat: Distances Target[ " + Math.Round(target.Distance,0) + " Optimal[" + nos.OptimalRange.ToString()+"]"); // Target is out of Nos range if (target.Distance >= nos.MaxRange) continue; if (CanActivate(nos, target, false)) { if (nos.Activate(target)) { Logging.Log("Combat", "Activating [" + nos.TypeName + "][" + _weaponNumber + "] on [" + target.Name + "][" + Cache.Instance.MaskedID(target.Id) + "][" + Math.Round(target.Distance / 1000, 0) + "k away]", Logging.Teal); return; } continue; } Logging.Log("Combat", "Cannot Activate [" + nos.TypeName + "][" + _weaponNumber + "] on [" + target.Name + "][" + Cache.Instance.MaskedID(target.Id) + "][" + Math.Round(target.Distance / 1000, 0) + "k away]", Logging.Teal); } }
/// <summary> Reload correct (tm) ammo for the NPC /// </summary> /// <param name = "weapon"></param> /// <param name = "entity"></param> /// <param name = "weaponNumber"></param> /// <returns>True if the (enough/correct) ammo is loaded, false if wrong/not enough ammo is loaded</returns> public static bool ReloadNormalAmmo(ModuleCache weapon, EntityCache entity, int weaponNumber) { if (Settings.Instance.WeaponGroupId == 53) return true; if (entity == null) return false; DirectContainer cargo = Cache.Instance.DirectEve.GetShipsCargo(); // Get ammo based on damage type IEnumerable<Ammo> correctAmmo = Settings.Instance.Ammo.Where(a => a.DamageType == Cache.Instance.DamageType).ToList(); // Check if we still have that ammo in our cargo IEnumerable<Ammo> correctAmmoIncargo = correctAmmo.Where(a => cargo.Items.Any(i => i.TypeId == a.TypeId && i.Quantity >= Settings.Instance.MinimumAmmoCharges)).ToList(); //check if mission specific ammo is defined if (Cache.Instance.MissionAmmo.Count() != 0) { correctAmmoIncargo = Cache.Instance.MissionAmmo.Where(a => a.DamageType == Cache.Instance.DamageType).ToList(); } // Check if we still have that ammo in our cargo correctAmmoIncargo = correctAmmoIncargo.Where(a => cargo.Items.Any(i => i.TypeId == a.TypeId && i.Quantity >= Settings.Instance.MinimumAmmoCharges)).ToList(); if (Cache.Instance.MissionAmmo.Count() != 0) { correctAmmoIncargo = Cache.Instance.MissionAmmo; } // We are out of ammo! :( if (!correctAmmoIncargo.Any()) { Logging.Log("Combat", "ReloadNormalAmmo: not enough [" + Cache.Instance.DamageType + "] ammo in cargohold: MinimumCharges: [" + Settings.Instance.MinimumAmmoCharges + "]", Logging.Orange); _States.CurrentCombatState = CombatState.OutOfAmmo; return false; } /****** if (weapon.Charge != null) { IEnumerable<Ammo> areWeMissingAmmo = correctAmmo.Where(a => a.TypeId == weapon.Charge.TypeId); if (!areWeMissingAmmo.Any()) { if (DateTime.UtcNow.Subtract(Cache.Instance.LastLoggingAction).TotalSeconds > 4) { Logging.Log("Combat", "ReloadNormalAmmo: We have ammo loaded that does not have a full reload available, checking cargo for other ammo", Logging.Orange); Cache.Instance.LastLoggingAction = DateTime.UtcNow; try { if (Settings.Instance.Ammo.Any()) { DirectItem availableAmmo = cargo.Items.OrderByDescending(i => i.Quantity).Where(a => Settings.Instance.Ammo.Any(i => i.TypeId == a.TypeId)).ToList().FirstOrDefault(); if (availableAmmo != null) { Cache.Instance.DamageType = Settings.Instance.Ammo.ToList().OrderByDescending(i => i.Quantity).Where(a => a.TypeId == availableAmmo.TypeId).ToList().FirstOrDefault().DamageType; Logging.Log("Combat", "ReloadNormalAmmo: found [" + availableAmmo.Quantity + "] units of [" + availableAmmo.TypeName + "] changed DamageType to [" + Cache.Instance.DamageType.ToString() + "]", Logging.Orange); return false; } Logging.Log("Combat", "ReloadNormalAmmo: unable to find any alternate ammo in your cargo", Logging.teal); _States.CurrentCombatState = CombatState.OutOfAmmo; return false; } } catch (Exception) { Logging.Log("Combat", "ReloadNormalAmmo: unable to find any alternate ammo in your cargo", Logging.teal); _States.CurrentCombatState = CombatState.OutOfAmmo; } return false; } } } *****/ // Get the best possible ammo Ammo ammo = correctAmmoIncargo.FirstOrDefault(); try { if (ammo != null && entity != null) { ammo = correctAmmoIncargo.Where(a => a.Range > entity.Distance).OrderBy(a => a.Range).FirstOrDefault(); } } catch (Exception exception) { Logging.Log("Combat", "ReloadNormalAmmo: Unable to find the correct ammo: waiting [" + exception + "]", Logging.Teal); return false; } // We do not have any ammo left that can hit targets at that range! if (ammo == null) return false; // We have enough ammo loaded if (weapon.Charge != null && weapon.Charge.TypeId == ammo.TypeId && weapon.CurrentCharges >= Settings.Instance.MinimumAmmoCharges) { LastWeaponReload[weapon.ItemId] = DateTime.UtcNow; //mark this weapon as reloaded... by the time we need to reload this timer will have aged enough... return true; } // Retry later, assume its ok now //if (!weapon.MatchingAmmo.Any()) //{ // LastWeaponReload[weapon.ItemId] = DateTime.UtcNow; //mark this weapon as reloaded... by the time we need to reload this timer will have aged enough... // return true; //} DirectItem charge = cargo.Items.FirstOrDefault(i => i.TypeId == ammo.TypeId && i.Quantity >= Settings.Instance.MinimumAmmoCharges); // This should have shown up as "out of ammo" if (charge == null) return false; // We are reloading, wait Time.ReloadWeaponDelayBeforeUsable_seconds (see time.cs) if (LastWeaponReload.ContainsKey(weapon.ItemId) && DateTime.UtcNow < LastWeaponReload[weapon.ItemId].AddSeconds(Time.Instance.ReloadWeaponDelayBeforeUsable_seconds)) return true; LastWeaponReload[weapon.ItemId] = DateTime.UtcNow; try { // Reload or change ammo if (weapon.Charge != null && weapon.Charge.TypeId == charge.TypeId && !weapon.IsChangingAmmo) { if (DateTime.UtcNow.Subtract(Cache.Instance.LastLoggingAction).TotalSeconds > 10) { Cache.Instance.TimeSpentReloading_seconds = Cache.Instance.TimeSpentReloading_seconds + Time.Instance.ReloadWeaponDelayBeforeUsable_seconds; Cache.Instance.LastLoggingAction = DateTime.UtcNow; } Logging.Log("Combat", "Reloading [" + weaponNumber + "] with [" + charge.TypeName + "][" + Math.Round((double)ammo.Range / 1000, 0) + "][TypeID: " + charge.TypeId + "]", Logging.Teal); weapon.ReloadAmmo(charge); weapon.ReloadTimeThisMission = weapon.ReloadTimeThisMission + Time.Instance.ReloadWeaponDelayBeforeUsable_seconds; return false; } if (!weapon.IsChangingAmmo) { if (DateTime.UtcNow.Subtract(Cache.Instance.LastLoggingAction).TotalSeconds > 10) { Cache.Instance.TimeSpentReloading_seconds = Cache.Instance.TimeSpentReloading_seconds + Time.Instance.ReloadWeaponDelayBeforeUsable_seconds; Cache.Instance.LastLoggingAction = DateTime.UtcNow; } Logging.Log("Combat", "Changing [" + weaponNumber + "] with [" + charge.TypeName + "][" + Math.Round((double)ammo.Range / 1000, 0) + "][TypeID: " + charge.TypeId + "] so we can hit [" + entity.Name + "][" + Math.Round(entity.Distance / 1000, 0) + "k]", Logging.Teal); weapon.ChangeAmmo(charge); weapon.ReloadTimeThisMission = weapon.ReloadTimeThisMission + Time.Instance.ReloadWeaponDelayBeforeUsable_seconds; return false; } if (weapon.IsChangingAmmo) { Logging.Log("Combat", "Weapon [" + weaponNumber + "] is already reloading. waiting", Logging.Teal); return false; } } catch (Exception exception) { Logging.Log("Combat.ReloadNormalAmmo", "Exception [" + exception + "]", Logging.Debug); } // Return true as we are reloading ammo, assume it is the correct ammo... return true; }
/// <summary> Activate target painters /// </summary> private static void ActivateTargetPainters(EntityCache target) { List<ModuleCache> targetPainters = Cache.Instance.Modules.Where(m => m.GroupId == (int)Group.TargetPainter).ToList(); // Find the first active weapon // Assist this weapon _weaponNumber = 0; foreach (ModuleCache painter in targetPainters) { if (Cache.Instance.LastActivatedTimeStamp != null && Cache.Instance.LastActivatedTimeStamp.ContainsKey(painter.ItemId)) { if (Cache.Instance.LastActivatedTimeStamp[painter.ItemId].AddMilliseconds(Time.Instance.PainterDelay_milliseconds) > DateTime.UtcNow) { continue; } } _weaponNumber++; // Are we on the right target? if (painter.IsActive) { if (painter.TargetId != target.Id) { if (painter.Click()) return; return; } continue; } // Are we deactivating? if (painter.IsDeactivating) continue; if (CanActivate(painter, target, false)) { if (painter.Activate(target)) { Logging.Log("Combat", "Activating [" + painter.TypeName + "][" + _weaponNumber + "] on [" + target.Name + "][" + Cache.Instance.MaskedID(target.Id) + "][" + Math.Round(target.Distance / 1000, 0) + "k away]", Logging.Teal); return; } continue; } } }
/// <summary> Activate Nos /// </summary> public void ActivateNos(EntityCache target) { if (DateTime.UtcNow < Cache.Instance.NextNosAction) //if we just did something wait a fraction of a second return; List<ModuleCache> noses = Cache.Instance.Modules.Where(m => m.GroupId == (int)Group.NOS).ToList(); //Logging.Log("Combat: we have " + noses.Count.ToString() + " Nos modules"); // Find the first active weapon // Assist this weapon _weaponNumber = 0; foreach (ModuleCache nos in noses) { _weaponNumber++; // Are we on the right target? if (nos.IsActive) { if (nos.TargetId != target.Id) { nos.Click(); return; } continue; } // Are we deactivating? if (nos.IsDeactivating) continue; //Logging.Log("Combat: Distances Target[ " + Math.Round(target.Distance,0) + " Optimal[" + nos.OptimalRange.ToString()+"]"); // Target is out of Nos range if (target.Distance >= Settings.Instance.NosDistance) continue; if (CanActivate(nos, target, false)) { Logging.Log("Combat", "Activating Nos [" + _weaponNumber + "] on [" + target.Name + "][ID: " + Cache.Instance.MaskedID(target.Id) + "][" + Math.Round(target.Distance / 1000, 0) + "k away]", Logging.Teal); nos.Activate(target.Id); Cache.Instance.NextNosAction = DateTime.UtcNow.AddMilliseconds(Time.Instance.NosDelay_milliseconds); return; } Logging.Log("Combat", "Cannot Activate Nos [" + _weaponNumber + "] on [" + target.Name + "][ID: " + Cache.Instance.MaskedID(target.Id) + "][" + Math.Round(target.Distance / 1000, 0) + "k away]", Logging.Teal); } }
/// <summary> Activate weapons /// </summary> private static void ActivateWeapons(EntityCache target) { // When in warp there's nothing we can do, so ignore everything if (Cache.Instance.InSpace && Cache.Instance.InWarp) { if (Cache.Instance.PrimaryWeaponPriorityEntities != null && Cache.Instance.PrimaryWeaponPriorityEntities.Any()) { Cache.Instance.RemovePrimaryWeaponPriorityTargets(Cache.Instance.PrimaryWeaponPriorityEntities.ToList()); } if (Cache.Instance.UseDrones && Cache.Instance.DronePriorityEntities != null && Cache.Instance.DronePriorityEntities.Any()) { Cache.Instance.RemoveDronePriorityTargets(Cache.Instance.DronePriorityEntities.ToList()); } Cache.Instance.ClearPerPocketCache(); if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: deactivate: we are in warp! doing nothing", Logging.Teal); return; } if (!Cache.Instance.Weapons.Any()) { if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: you have no weapons?", Logging.Teal); return; } // // Do we really want a non-mission action moving the ship around at all!! (other than speed tanking)? // If you are not in a mission by all means let combat actions move you around as needed /* if (!Cache.Instance.InMission) { if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: deactivate: we are NOT in a mission: NavigateInToRange", Logging.Teal); NavigateOnGrid.NavigateIntoRange(target, "Combat"); } if (Settings.Instance.SpeedTank) { if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: deactivate: We are Speed Tanking: NavigateInToRange", Logging.Teal); NavigateOnGrid.NavigateIntoRange(target, "Combat"); } */ if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: deactivate: after navigate into range...", Logging.Teal); // Get the weapons // TODO: Add check to see if there is better ammo to use! :) // Get distance of the target and compare that with the ammo currently loaded //Deactivate weapons that needs to be deactivated for this list of reasons... _weaponNumber = 0; if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: deactivate: Do we need to deactivate any weapons?", Logging.Teal); if (Cache.Instance.Weapons.Any()) { foreach (ModuleCache weapon in Cache.Instance.Weapons) { _weaponNumber++; if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: deactivate: for each weapon [" + _weaponNumber + "] in weapons", Logging.Teal); if (Cache.Instance.LastActivatedTimeStamp != null && Cache.Instance.LastActivatedTimeStamp.ContainsKey(weapon.ItemId)) { if (Cache.Instance.LastActivatedTimeStamp[weapon.ItemId].AddMilliseconds(Time.Instance.WeaponDelay_milliseconds) > DateTime.UtcNow) { continue; } } if (!weapon.IsActive) { if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: deactivate: [" + weapon.TypeName + "][" + _weaponNumber + "] is not active: no need to do anything", Logging.Teal); continue; } if (weapon.IsReloadingAmmo) { if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: deactivate: [" + weapon.TypeName + "][" + _weaponNumber + "] is reloading ammo: waiting", Logging.Teal); continue; } if (weapon.IsDeactivating) { if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: deactivate: [" + weapon.TypeName + "][" + _weaponNumber + "] is deactivating: waiting", Logging.Teal); continue; } if (weapon.IsChangingAmmo) { if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: deactivate: [" + weapon.TypeName + "][" + _weaponNumber + "] is changing ammo: waiting", Logging.Teal); continue; } // No ammo loaded if (weapon.Charge == null) { if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: deactivate: no ammo loaded? [" + weapon.TypeName + "][" + _weaponNumber + "] reload will happen elsewhere", Logging.Teal); continue; } Ammo ammo = Settings.Instance.Ammo.FirstOrDefault(a => a.TypeId == weapon.Charge.TypeId); //use mission specific ammo if (Cache.Instance.MissionAmmo.Count() != 0) { if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: deactivate: MissionAmmocount is not 0", Logging.Teal); ammo = Cache.Instance.MissionAmmo.FirstOrDefault(a => a.TypeId == weapon.Charge.TypeId); } // How can this happen? Someone manually loaded ammo if (ammo == null) { if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: deactivate: ammo == null [" + weapon.TypeName + "][" + _weaponNumber + "] someone manually loaded ammo?", Logging.Teal); continue; } if (weapon.CurrentCharges >= 2) { // If we have already activated warp, deactivate the weapons if (!Cache.Instance.ActiveShip.Entity.IsWarping) { // Target is in range if (target.Distance <= ammo.Range) { if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: deactivate: target is in range: do nothing, wait until it is dead", Logging.Teal); continue; } } } // Target is out of range, stop firing if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: deactivate: target is out of range, stop firing", Logging.Teal); if (weapon.Click()) return; return; } // Hack for max charges returning incorrect value if (!Cache.Instance.Weapons.Any(w => w.IsEnergyWeapon)) { MaxCharges = Math.Max(MaxCharges, Cache.Instance.Weapons.Max(l => l.MaxCharges)); MaxCharges = Math.Max(MaxCharges, Cache.Instance.Weapons.Max(l => l.CurrentCharges)); } int weaponsActivatedThisTick = 0; int weaponsToActivateThisTick = Cache.Instance.RandomNumber(1, 4); // Activate the weapons (it not yet activated))) _weaponNumber = 0; if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: activate: Do we need to activate any weapons?", Logging.Teal); foreach (ModuleCache weapon in Cache.Instance.Weapons) { _weaponNumber++; if (Cache.Instance.LastActivatedTimeStamp != null && Cache.Instance.LastActivatedTimeStamp.ContainsKey(weapon.ItemId)) { if (Cache.Instance.LastActivatedTimeStamp[weapon.ItemId].AddMilliseconds(Time.Instance.WeaponDelay_milliseconds) > DateTime.UtcNow) { continue; } } // Are we reloading, deactivating or changing ammo? if (weapon.IsReloadingAmmo) { if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: Activate: [" + weapon.TypeName + "][" + _weaponNumber + "] is reloading, waiting.", Logging.Teal); continue; } if (weapon.IsDeactivating) { if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: Activate: [" + weapon.TypeName + "][" + _weaponNumber + "] is deactivating, waiting.", Logging.Teal); continue; } if (weapon.IsChangingAmmo) { if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: Activate: [" + weapon.TypeName + "][" + _weaponNumber + "] is changing ammo, waiting.", Logging.Teal); continue; } if (!target.IsTarget) { if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: Activate: [" + weapon.TypeName + "][" + _weaponNumber + "] is [" + target.Name + "] is not locked, waiting.", Logging.Teal); continue; } // Are we on the right target? if (weapon.IsActive) { if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: Activate: [" + weapon.TypeName + "][" + _weaponNumber + "] is active already", Logging.Teal); if (weapon.TargetId != target.Id && target.IsTarget) { if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: Activate: [" + weapon.TypeName + "][" + _weaponNumber + "] is shooting at the wrong target: deactivating", Logging.Teal); if (weapon.Click()) return; return; } continue; } // No, check ammo type and if that is correct, activate weapon if (ReloadAmmo(weapon, target, _weaponNumber) && CanActivate(weapon, target, true)) { if (weaponsActivatedThisTick > weaponsToActivateThisTick) { if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: if we have already activated x number of weapons return, which will wait until the next ProcessState", Logging.Teal); return; } if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: Activate: [" + weapon.TypeName + "][" + _weaponNumber + "] has the correct ammo: activate", Logging.Teal); if (weapon.Activate(target)) { weaponsActivatedThisTick++; //increment the number of weapons we have activated this ProcessState so that we might optionally activate more than one module per tick Logging.Log("Combat", "Activating weapon [" + _weaponNumber + "] on [" + target.Name + "][" + Cache.Instance.MaskedID(target.Id) + "][" + Math.Round(target.Distance / 1000, 0) + "k away]", Logging.Teal); continue; } continue; } if (Settings.Instance.DebugActivateWeapons) Logging.Log("Combat", "ActivateWeapons: ReloadReady [" + ReloadAmmo(weapon, target, _weaponNumber) + "] CanActivateReady [" + CanActivate(weapon, target, true) + "]", Logging.Teal); } } else { Logging.Log("Combat","ActivateWeapons: you have no weapons with groupID: [ " + Settings.Instance.WeaponGroupId + " ]",Logging.Debug); i = 0; foreach (ModuleCache __module in Cache.Instance.Modules.Where(e => e.IsOnline && e.IsActivatable)) { i++; Logging.Log("Fitted Modules", "[" + i + "] Module TypeID [ " + __module.TypeId + " ] ModuleGroupID [ " + __module.GroupId + " ] EveCentral Link [ http://eve-central.com/home/quicklook.html?typeid=" + __module.TypeId + " ]", Logging.Debug); } } }
/// <summary> Activate StasisWeb /// </summary> public void ActivateStasisWeb(EntityCache target) { if (DateTime.UtcNow < Cache.Instance.NextWebAction) //if we just did something wait a fraction of a second return; List<ModuleCache> webs = Cache.Instance.Modules.Where(m => m.GroupId == (int)Group.StasisWeb).ToList(); // Find the first active weapon // Assist this weapon _weaponNumber = 0; foreach (ModuleCache web in webs) { _weaponNumber++; // Are we on the right target? if (web.IsActive) { if (web.TargetId != target.Id) { web.Click(); return; } continue; } // Are we deactivating? if (web.IsDeactivating) continue; // Target is out of web range if (target.Distance >= web.OptimalRange) continue; if (CanActivate(web, target, false)) { Logging.Log("Combat", "Activating web [" + _weaponNumber + "] on [" + target.Name + "][ID: " + Cache.Instance.MaskedID(target.Id) + "]", Logging.Teal); web.Activate(target.Id); Cache.Instance.NextWebAction = DateTime.UtcNow.AddMilliseconds(Time.Instance.WebDelay_milliseconds); return; } } }