public bool ChangeAmmo(DirectItem charge, int weaponNumber, double Range, String entityName = "n/a", Double entityDistance = 0) { if (!IsReloadingAmmo) { if (!IsChangingAmmo) { if (!InLimboState) { _module.ChangeAmmo(charge); Logging.Log("ChangeAmmo", "Changing [" + weaponNumber + "][" + _module.TypeName + "] with [" + charge.TypeName + "][" + Math.Round(Range / 1000, 0) + "] so we can hit [" + entityName + "][" + Math.Round(entityDistance / 1000, 0) + "k]", Logging.Teal); Cache.Instance.LastChangedAmmoTimeStamp[ItemId] = DateTime.UtcNow; if (Cache.Instance.ReloadTimePerModule.ContainsKey(ItemId)) { Cache.Instance.ReloadTimePerModule[ItemId] = Cache.Instance.ReloadTimePerModule[ItemId] + Time.Instance.ReloadWeaponDelayBeforeUsable_seconds; } else { Cache.Instance.ReloadTimePerModule[ItemId] = Time.Instance.ReloadWeaponDelayBeforeUsable_seconds; } return(true); } Logging.Log("ChangeAmmo", "[" + weaponNumber + "][" + _module.TypeName + "] is currently in a limbo state, waiting", Logging.Teal); return(false); } Logging.Log("ChangeAmmo", "[" + weaponNumber + "][" + _module.TypeName + "] is already changing ammo, waiting", Logging.Teal); return(false); } Logging.Log("ChangeAmmo", "[" + weaponNumber + "][" + _module.TypeName + "] is already reloading, waiting", Logging.Teal); return(false); }
public void SellItemsInHanger() { List <DirectItem> sellItemList = new List <DirectItem>(); itemHangerGrid.Invoke((MethodInvoker) delegate { foreach (DataGridViewRow row in itemHangerGrid.Rows) { try { if (Convert.ToBoolean(row.Cells["ItemHanger_Select"].Value) == true) { long itemId = (long)row.Cells["ItemHanger_ItemId"].Value; DirectItem item = Cache.Instance.ItemHanger.Items.FirstOrDefault(i => i.ItemId == itemId); if (item != null) { Logging.Log("OmniEveUI:SellItemsInHanger", "Adding item to list of items to be sold ItemId - " + itemId, Logging.Debug); SellItem sellItem = new SellItem(item, true); sellItem.OnSellItemFinished += OnSellItemFinished; _omniEve.AddAction(sellItem); } } } catch (Exception ex) { Logging.Log("OmniEveUI:SellItemsInHanger", "Exception [" + ex + "]", Logging.Debug); } } }); }
public ItemCache(DirectItem item, bool cacheRefineOutput) { Id = item.ItemId; Name = item.TypeName; TypeId = item.TypeId; GroupId = item.GroupId; BasePrice = item.BasePrice; Volume = item.Volume; Capacity = item.Capacity; MarketGroupId = item.MarketGroupId; PortionSize = item.PortionSize; Quantity = item.Quantity; QuantitySold = 0; RefineOutput = new List <ItemCache>(); if (cacheRefineOutput) { foreach (var i in item.Materials) { RefineOutput.Add(new ItemCache(i, false)); } } }
/// <summary> /// Arm does nothing but get into a (assembled) shuttle /// </summary> /// <returns></returns> public StorylineState Arm(Storyline storyline) { if (_nextAction > DateTime.UtcNow) { return(StorylineState.Arm); } // Are we in a shuttle? Yes, go to the agent if (Cache.Instance.ActiveShip.GroupId == (int)Group.Shuttle) { return(StorylineState.GotoAgent); } // Open the ship hangar if (!Cache.Instance.OpenShipsHangar("TransactionDataDelivery")) { return(StorylineState.Arm); } // Look for a shuttle DirectItem item = Cache.Instance.ShipHangar.Items.FirstOrDefault(i => i.Quantity == -1 && i.GroupId == (int)Group.Shuttle); if (item != null) { Logging.Log("TransactionDataDelivery", "Switching to shuttle", Logging.White); _nextAction = DateTime.UtcNow.AddSeconds(10); item.ActivateShip(); return(StorylineState.Arm); } Logging.Log("TransactionDataDelivery", "No shuttle found, going in active ship", Logging.Orange); return(StorylineState.GotoAgent); }
private void RunCreateBuyOrders() { _buyActions.Clear(); _newBuyOrders = 0; Logging.Log("Automation:RunCreateBuyOrders", "CreateBuyOrders State - Begin", Logging.Debug); string[] allLines = File.ReadAllLines("C:\\Users\\tjuckett\\Documents\\GitHub\\OmniEve\\output\\BuyOrders.txt"); foreach (string line in allLines) { try { string[] parameters = line.Split(','); int typeId = int.Parse(parameters[0]); int volume = int.Parse(parameters[2]); double buyPrice = double.Parse(parameters[3]); volume = volume / 2; if (volume * buyPrice > 100000000) { volume = (int)(10000000.0 / buyPrice); } if (volume <= 0) { volume = 1; } DirectOrder order = _myBuyOrders.FirstOrDefault(o => o.TypeId == typeId); DirectItem item = _itemsInHanger.FirstOrDefault(i => i.TypeId == typeId); if (order == null && item == null) { Logging.Log("Automation:RunCreateBuyOrders", "Adding type to create buy order for TypeId - " + typeId + " Volume - " + volume, Logging.Debug); BuyItem buyItem = new BuyItem(typeId, volume, true); buyItem.OnBuyItemFinished += OnBuyItemFinished; buyItem.OnBuyItemFinished += BuyItemFinished; _buyActions.Enqueue(buyItem); } } catch (Exception ex) { Logging.Log("Automation:RunCreateBuyOrders", "Exception [" + ex + "]", Logging.Debug); } } if (RunNextBuyAction() == true) { ChangeState(State.Processing); } else { ChangeState(State.MyOrders); } }
public static bool StartQuickSell(string module, bool sell) { if (DateTime.UtcNow.Subtract(_lastExecute).TotalSeconds < Time.Instance.Marketsellorderdelay_seconds) { return(false); } _lastExecute = DateTime.UtcNow; DirectItem directItem = Cache.Instance.ItemHangar.Items.FirstOrDefault(i => i.ItemId == _currentItem.Id); if (directItem == null) { Logging.Log(module, "Item " + _currentItem.Name + " no longer exists in the hanger", Logging.White); return(false); } // Update Quantity _currentItem.QuantitySold = _currentItem.Quantity - directItem.Quantity; if (sell) { DirectMarketActionWindow sellWindow = Cache.Instance.Windows.OfType <DirectMarketActionWindow>().FirstOrDefault(w => w.IsSellAction); // // if we do not yet have a sell window then start the QuickSell for this item // if (sellWindow == null || !sellWindow.IsReady || sellWindow.Item.ItemId != _currentItem.Id) { Logging.Log(module, "Starting QuickSell for " + _currentItem.Name, Logging.White); if (!directItem.QuickSell()) { _lastExecute = DateTime.UtcNow.AddSeconds(-5); Logging.Log(module, "QuickSell failed for " + _currentItem.Name + ", retrying in 5 seconds", Logging.White); return(false); } return(false); } // // what happens here if we have a sell window that is not a quick sell window? wont this hang? // // // proceed to the next state // // Mark as new execution _lastExecute = DateTime.UtcNow; return(true); } // // if we are not selling check to see if we should refine. // _States.CurrentValueDumpState = ValueDumpState.InspectRefinery; return(false); }
public ItemCache(DirectItem item) { Id = item.ItemId; Name = item.Name; TypeId = item.TypeId ?? -1; GroupId = item.GroupId ?? -1; MarketGroupId = item.MarketGroupId ?? -1; Quantity = item.Quantity ?? -1; QuantitySold = 0; }
private void SellItemFinished(DirectItem item, bool sold) { if (sold == true) { _newSellOrders++; } if (RunNextSellAction() == false) { Logging.Log("Automation:SellItemFinished", "CreateSellOrders State - End", Logging.Debug); ChangeState(State.CreateBuyOrders); } }
public static bool InjectSkillBook(int skillID) { IEnumerable <DirectItem> items = Cache.Instance.ItemHangar.Items.Where(k => k.TypeId == skillID).ToList(); if (DoWeHaveThisSkillAlreadyInOurItemHangar(skillID)) { if (Settings.Instance.DebugSkillTraining) { Logging.Log("InjectSkillBook", "SkillBook [" + skillID.ToString() + "] found in ItemHangar", Logging.Debug); } DirectItem SkillBookToInject = items.FirstOrDefault(s => s.TypeId == skillID); if (SkillBookToInject != null) { if (MyCharacterSheetSkills != null && !MyCharacterSheetSkills.Any(i => i.TypeName == SkillBookToInject.TypeName || i.GivenName == SkillBookToInject.TypeName)) { if (Settings.Instance.DebugSkillTraining) { Logging.Log("InjectSkillBook", "SkillBook: GivenName [" + SkillBookToInject.GivenName + "] TypeName [" + SkillBookToInject.TypeName + "] is being injected", Logging.Debug); } if (DoWeHaveTheRightPrerequisites(SkillBookToInject.TypeId)) { SkillBookToInject.InjectSkill(); skillWasInjected = true; return(true); } else { if (Settings.Instance.DebugSkillTraining) { Logging.Log("InjectSkillBook", "Skillbook: We don't have the right Prerequisites for " + SkillBookToInject.GivenName, Logging.Debug); } } } if (MyCharacterSheetSkills != null && MyCharacterSheetSkills.Any(i => i.TypeName == SkillBookToInject.TypeName)) { if (Settings.Instance.DebugSkillTraining) { Logging.Log("InjectSkillBook", "SkillBook: TypeName [" + SkillBookToInject.TypeName + "] is already injected, why are we trying to do so again? aborting injection attempt ", Logging.Debug); } return(true); } } return(false); } Logging.Log("InjectSkillBook", "We don't have this skill in our hangar", Logging.Debug); return(false); }
public static bool CreateSellOrder(string module, int duration, bool corp) { if (DateTime.UtcNow.Subtract(_lastExecute).TotalSeconds < Time.Instance.Marketsellorderdelay_seconds) { return(false); } _lastExecute = DateTime.UtcNow; DirectItem directItem = Cache.Instance.ItemHangar.Items.FirstOrDefault(i => i.ItemId == _currentItem.Id); if (directItem == null) { Logging.Log(module, "Item " + _currentItem.Name + " no longer exists in the hanger", Logging.White); return(false); } DirectMarketWindow marketWindow = Cache.Instance.Windows.OfType <DirectMarketWindow>().FirstOrDefault(); if (marketWindow == null) { Cache.Instance.OpenMarket(module); return(false); } if (!marketWindow.IsReady) { return(false); } if (marketWindow.DetailTypeId != directItem.TypeId) { marketWindow.LoadTypeId(directItem.TypeId); return(false); } DirectOrder competitor = marketWindow.SellOrders.Where(i => i.StationId == Cache.Instance.DirectEve.Session.StationId).OrderBy(i => i.Price).FirstOrDefault(); if (competitor != null) { double newprice = competitor.Price - 0.01; if (Cache.Instance.DirectEve.Session.StationId != null) { Cache.Instance.DirectEve.Sell(directItem, (int)Cache.Instance.DirectEve.Session.StationId, directItem.Quantity, newprice, duration, corp); } } return(true); }
public ItemCache(DirectItem item, bool cacheRefineOutput) { BasePrice = item.BasePrice; Capacity = item.Capacity; MarketGroupId = item.MarketGroupId; PortionSize = item.PortionSize; QuantitySold = 0; RefineOutput = new List <ItemCache>(); if (cacheRefineOutput) { foreach (DirectItem i in item.Materials) { RefineOutput.Add(new ItemCache(i, false)); } } }
private void OnCheckItemHangerAgainstMarketFinished(List <DirectItem> hangerItems) { Logging.Log("OmniEveUI: OnCheckItemHangerAgainstMarketFinished", "Checking items against new market orders, don't want to create orders for items that haven't even sold yet", Logging.White); marketGrid.Invoke((MethodInvoker) delegate { int ordersToAdd = 0; List <int> typeIdsRemoved = new List <int>();; foreach (DataGridViewRow row in marketGrid.Rows) { bool selected = (bool)row.Cells["Market_Select"].Value; int typeId = (int)row.Cells["Market_TypeId"].Value; DirectItem item = hangerItems.FirstOrDefault(h => h.TypeId == typeId); if (item != null && selected == true) { Logging.Log("OmniEveUI: OnCheckItemHangerAgainstMarketFinished", "We have this item already in our item hanger, no need to add a new order yet TypeId - " + typeId, Logging.White); ordersToAdd++; typeIdsRemoved.Add(typeId); row.Cells["Market_Select"].Value = false; } } if (ordersToAdd > 0) { Logging.Log("OmniEveUI: OnCheckItemHangerAgainstMarketFinished", "Adding new orders for all the ones that were taken away", Logging.White); foreach (DataGridViewRow row in marketGrid.Rows) { bool selected = (bool)row.Cells["Market_Select"].Value; int typeId = (int)row.Cells["Market_TypeId"].Value; if (row.DefaultCellStyle.BackColor == Color.LightGreen && row.DefaultCellStyle.ForeColor == Color.Black && ordersToAdd > 0 && selected == false && typeIdsRemoved.Find(t => t == typeId) == 0) { Logging.Log("OmniEveUI: OnCheckItemHangerAgainstMarketFinished", "Adding new order TypeId - " + typeId, Logging.White); row.Cells["Market_Select"].Value = true; ordersToAdd--; } } } }); //CheckState(); }
private void LogItem(string format, DirectItem item) { Log(format, "ItemId", item.ItemId); Log(format, "TypeId", item.TypeId); Log(format, "GroupId", item.GroupId); Log(format, "GroupName", item.GroupName); Log(format, "CategoryId", item.CategoryId); Log(format, "CategoryName", item.CategoryName); Log(format, "OwnerId", item.OwnerId); Log(format, "LocationId", item.LocationId); Log(format, "Quantity", item.Quantity); Log(format, "Stacksize", item.Stacksize); Log(format, "TypeName", item.TypeName); Log(format, "GivenName", item.GivenName); }
private void OnSellItemFinished(DirectItem itemSold, bool sold) { itemHangerGrid.Invoke((MethodInvoker) delegate { List <DataGridViewRow> rowsToRemove = new List <DataGridViewRow>(); foreach (DataGridViewRow row in itemHangerGrid.Rows) { try { if (itemSold.ItemId == (long)row.Cells["ItemHanger_ItemId"].Value) { if (sold == true) { rowsToRemove.Add(row); } else { row.DefaultCellStyle.BackColor = Color.Yellow; row.DefaultCellStyle.ForeColor = Color.Black; } } } catch (Exception ex) { Logging.Log("OmniEveUI:OnSellItemFinished", "Exception [" + ex + "]", Logging.Debug); } } // Remove all the rows that had sell orders created foreach (DataGridViewRow row in rowsToRemove) { itemHangerGrid.Rows.Remove(row); } }); //CheckState(); }
public ItemCache(DirectItem item) { _directItem = item; }
public void ChangeAmmo(DirectItem charge) { _module.ChangeAmmo(charge); }
public void ReloadAmmo(DirectItem charge) { _module.ReloadAmmo(charge); }
public void ProcessState() { if (!Cache.Instance.InStation) { return; } if (Cache.Instance.InSpace) { return; } if (DateTime.UtcNow < Cache.Instance.LastInSpace.AddSeconds(20)) // we wait 20 seconds after we last thought we were in space before trying to do anything in station { return; } DirectContainer hangar = null; if (_States.CurrentGrabState != States.GrabState.WaitForItems) { if (Cache.Instance.ItemHangar == null) { return; } if (!Cache.Instance.OpenShipsHangar("Grab")) { return; } if ("Local Hangar" == Hangar) { hangar = Cache.Instance.ItemHangar; } else if ("Ship Hangar" == Hangar) { hangar = Cache.Instance.ShipHangar; } else { hangar = Cache.Instance.DirectEve.GetCorporationHangar(Hangar); } } switch (_States.CurrentGrabState) { case GrabState.Idle: case GrabState.Done: break; case GrabState.Begin: _States.CurrentGrabState = GrabState.ReadyItemhangar; break; case GrabState.ReadyItemhangar: if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 2) { break; } if ("Local Hangar" == Hangar) { if (Cache.Instance.ItemHangar == null) { return; } } else if ("Ship Hangar" == Hangar) { if (!Cache.Instance.OpenShipsHangar("Drop")) { return; } if (hangar != null && (hangar.Window == null || !hangar.Window.IsReady)) { break; } } else if (Hangar != null) { if (hangar == null || !hangar.IsValid) { Logging.Log("Grab", "No Valid Corp Hangar found. Hangar: " + Hangar, Logging.White); _States.CurrentGrabState = States.GrabState.Idle; return; } } Logging.Log("Grab", "Opening Hangar", Logging.White); _States.CurrentGrabState = GrabState.OpenCargo; break; case GrabState.OpenCargo: if (Cache.Instance.CurrentShipsCargo == null) { Logging.Log("MoveItems", "if (Cache.Instance.CurrentShipsCargo == null)", Logging.Teal); return; } Logging.Log("Grab", "Opening Cargo Hold", Logging.White); _freeCargoCapacity = Cache.Instance.CurrentShipsCargo.Capacity - Cache.Instance.CurrentShipsCargo.UsedCapacity; _States.CurrentGrabState = Item == 00 ? GrabState.AllItems : GrabState.MoveItems; break; case GrabState.MoveItems: if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 2) { break; } if (Unit == 00) { if (hangar != null) { DirectItem grabItems = hangar.Items.FirstOrDefault(i => (i.TypeId == Item)); if (grabItems != null) { double totalVolum = grabItems.Quantity * grabItems.Volume; if (_freeCargoCapacity >= totalVolum) { //foreach (DirectItem item in items) //{ // Logging.Log("Grab", "Items: " + item.TypeName, Logging.White); //} Cache.Instance.CurrentShipsCargo.Add(grabItems, grabItems.Quantity); _freeCargoCapacity -= totalVolum; Logging.Log("Grab.MoveItems", "Moving all the items", Logging.White); _lastAction = DateTime.UtcNow; _States.CurrentGrabState = GrabState.WaitForItems; } else { _States.CurrentGrabState = GrabState.Done; Logging.Log("Grab.MoveItems", "No load capacity", Logging.White); } } } } else { if (hangar != null) { DirectItem grabItem = hangar.Items.FirstOrDefault(i => (i.TypeId == Item)); if (grabItem != null) { double totalVolum = Unit * grabItem.Volume; if (_freeCargoCapacity >= totalVolum) { Cache.Instance.CurrentShipsCargo.Add(grabItem, Unit); _freeCargoCapacity -= totalVolum; Logging.Log("Grab.MoveItems", "Moving item", Logging.White); _lastAction = DateTime.UtcNow; _States.CurrentGrabState = GrabState.WaitForItems; } else { _States.CurrentGrabState = GrabState.Done; Logging.Log("Grab.MoveItems", "No load capacity", Logging.White); } } } } break; case GrabState.AllItems: if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 2) { break; } if (hangar != null) { List <DirectItem> allItem = hangar.Items; if (allItem != null) { foreach (DirectItem item in allItem) { if (Cache.Instance.ActiveShip.ItemId == item.ItemId) { allItem.Remove(item); continue; } double totalVolum = item.Quantity * item.Volume; if (_freeCargoCapacity >= totalVolum) { Cache.Instance.CurrentShipsCargo.Add(item); _freeCargoCapacity -= totalVolum; } else { // we are out of room, should we do a partial item move? double quantityWeCanFit = _freeCargoCapacity / item.Volume; Cache.Instance.CurrentShipsCargo.Add(item, (int)quantityWeCanFit); //we are now "full" and should go "home" or "market" (how do we decide where to go ffs?) } } Logging.Log("Grab.AllItems", "Moving items", Logging.White); _lastAction = DateTime.UtcNow; _States.CurrentGrabState = GrabState.WaitForItems; } } break; case GrabState.WaitForItems: // Wait 5 seconds after moving if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 5) { break; } if (Cache.Instance.DirectEve.GetLockedItems().Count == 0) { Logging.Log("Grab", "Done", Logging.White); _States.CurrentGrabState = GrabState.Done; break; } break; } }
/// <summary> /// Check if we have kernite in station /// </summary> /// <returns></returns> public StorylineState PreAcceptMission(Storyline storyline) { DirectEve directEve = Cache.Instance.DirectEve; if (_nextAction > DateTime.UtcNow) { return(StorylineState.PreAcceptMission); } // the ore and ore quantity can be stored in the characters settings xml this is to facility mission levels other than 4. //The defaults are for level 4 so it will not break for those people that do not include these in their settings file // Level 1 <MaterialsForWarOreID>1230</MaterialsForWarOreID> // <MaterialsForWarOreQty>999</MaterialsForWarOreQty> // Level 4 <MaterialsForWarOreID>20</MaterialsForWarOreID> // <MaterialsForWarOreQty>8000</MaterialsForWarOreQty> int oreid = Settings.Instance.MaterialsForWarOreID; //1230; int orequantity = Settings.Instance.MaterialsForWarOreQty; //999 // Open the item hangar if (Cache.Instance.ItemHangar == null) { return(StorylineState.PreAcceptMission); } //if (Cache.Instance.ItemHangar.Window == null) //{ // Logging.Log("MaterialsForWar", "PreAcceptMission: ItemHangar is null", Logging.Orange); // if (!Cache.Instance.ReadyItemsHangar("MaterialsForWarPreparation")) return StorylineState.PreAcceptMission; // return StorylineState.PreAcceptMission; //} // Is there a market window? DirectMarketWindow marketWindow = directEve.Windows.OfType <DirectMarketWindow>().FirstOrDefault(); // Do we have the ore we need in the Item Hangar?. if (Cache.Instance.ItemHangar.Items.Where(i => i.TypeId == oreid).Sum(i => i.Quantity) >= orequantity) { DirectItem thisOreInhangar = Cache.Instance.ItemHangar.Items.FirstOrDefault(i => i.TypeId == oreid); if (thisOreInhangar != null) { Logging.Log("MaterialsForWarPreparation", "We have [" + Cache.Instance.ItemHangar.Items.Where(i => i.TypeId == oreid).Sum(i => i.Quantity).ToString(CultureInfo.InvariantCulture) + "] " + thisOreInhangar.TypeName + " in the item hangar accepting mission", Logging.White); } // Close the market window if there is one if (marketWindow != null) { marketWindow.Close(); } return(StorylineState.AcceptMission); } if (Cache.Instance.CurrentShipsCargo == null) { return(StorylineState.PreAcceptMission); } if (Cache.Instance.CurrentShipsCargo.Items.Where(i => i.TypeId == oreid).Sum(i => i.Quantity) >= orequantity) { DirectItem thisOreInhangar = Cache.Instance.CurrentShipsCargo.Items.FirstOrDefault(i => i.TypeId == oreid); if (thisOreInhangar != null) { Logging.Log("MaterialsForWarPreparation", "We have [" + Cache.Instance.CurrentShipsCargo.Items.Where(i => i.TypeId == oreid).Sum(i => i.Quantity).ToString(CultureInfo.InvariantCulture) + "] " + thisOreInhangar.TypeName + " in the CargoHold accepting mission", Logging.White); } // Close the market window if there is one if (marketWindow != null) { marketWindow.Close(); } return(StorylineState.AcceptMission); } if (Cache.Instance.DirectEve.HasSupportInstances()) { // We do not have enough ore, open the market window if (marketWindow == null) { _nextAction = DateTime.UtcNow.AddSeconds(10); Logging.Log("MaterialsForWarPreparation", "Opening market window", Logging.White); directEve.ExecuteCommand(DirectCmd.OpenMarket); return(StorylineState.PreAcceptMission); } // Wait for the window to become ready (this includes loading the ore info) if (!marketWindow.IsReady) { return(StorylineState.PreAcceptMission); } // Are we currently viewing ore orders? if (marketWindow.DetailTypeId != oreid) { // No, load the ore orders marketWindow.LoadTypeId(oreid); Logging.Log("MaterialsForWarPreparation", "Loading market window", Logging.White); _nextAction = DateTime.UtcNow.AddSeconds(5); return(StorylineState.PreAcceptMission); } // Get the median sell price InvType type = Cache.Instance.InvTypesById[20]; double? maxPrice = type.MedianSell * 4; // Do we have orders that sell enough ore for the mission? IEnumerable <DirectOrder> orders = marketWindow.SellOrders.Where(o => o.StationId == directEve.Session.StationId && o.Price < maxPrice).ToList(); if (!orders.Any() || orders.Sum(o => o.VolumeRemaining) < orequantity) { Logging.Log("MaterialsForWarPreparation", "Not enough (reasonably priced) ore available! Blacklisting agent for this Questor session!", Logging.Orange); // Close the market window marketWindow.Close(); // No, black list the agent in this Questor session (note we will never decline storylines!) return(StorylineState.BlacklistAgent); } // How much ore do we still need? int neededQuantity = orequantity - Cache.Instance.ItemHangar.Items.Where(i => i.TypeId == oreid).Sum(i => i.Quantity); if (neededQuantity > 0) { // Get the first order DirectOrder order = orders.OrderBy(o => o.Price).FirstOrDefault(); if (order != null) { // Calculate how much ore we still need int remaining = Math.Min(neededQuantity, order.VolumeRemaining); order.Buy(remaining, DirectOrderRange.Station); Logging.Log("MaterialsForWarPreparation", "Buying [" + remaining + "] ore", Logging.White); // Wait for the order to go through _nextAction = DateTime.UtcNow.AddSeconds(10); } } return(StorylineState.PreAcceptMission); } Logging.Log("MaterialsForWarPreparation", "No DirectEVE Instances Available: free version detected. Buy/Sell support not available. Blacklisting agent for this Questor session!", Logging.Orange); // Close the market window if (marketWindow != null) { marketWindow.Close(); } // No, black list the agent in this Questor session (note we will never decline storylines!) return(StorylineState.BlacklistAgent); }
/// <summary> /// Arm does nothing but get into a (assembled) shuttle /// </summary> /// <returns></returns> public StorylineState Arm(Storyline storyline) { if (_nextAction > DateTime.UtcNow) { return(StorylineState.Arm); } if (Cache.Instance.ActiveShip == null || Cache.Instance.ActiveShip.GivenName == null) { if (Settings.Instance.DebugArm) { Logging.Log("StorylineState.Arm", "if (Cache.Instance.ActiveShip == null)", Logging.Debug); } _nextAction = DateTime.UtcNow.AddSeconds(3); return(StorylineState.Arm); } if (Cache.Instance.ActiveShip.GivenName.ToLower() != Settings.Instance.TransportShipName.ToLower()) { // Open the ship hangar if (!Cache.Instance.OpenShipsHangar("MaterialsForWarPreparation")) { return(StorylineState.Arm); } List <DirectItem> ships = Cache.Instance.ShipHangar.Items; foreach (DirectItem ship in ships.Where(ship => ship.GivenName != null && ship.GivenName.ToLower() == Settings.Instance.TransportShipName.ToLower())) { Logging.Log("MaterialsForWarPreparation", "Making [" + ship.GivenName + "] active", Logging.White); ship.ActivateShip(); Cache.Instance.NextArmAction = DateTime.UtcNow.AddSeconds(Modules.Lookup.Time.Instance.SwitchShipsDelay_seconds); return(StorylineState.Arm); } if (Cache.Instance.ActiveShip.GivenName.ToLower() != Settings.Instance.TransportShipName.ToLower()) { Logging.Log("StorylineState.Arm", "Missing TransportShip named [" + Settings.Instance.TransportShipName + "]", Logging.Debug); return(StorylineState.GotoAgent); } } if (Cache.Instance.ItemHangar == null) { return(StorylineState.Arm); } IEnumerable <DirectItem> items = Cache.Instance.ItemHangar.Items.Where(k => k.TypeId == Settings.Instance.MaterialsForWarOreID).ToList(); if (!items.Any()) { if (Settings.Instance.DebugArm) { Logging.Log("StorylineState.Arm", "Ore for MaterialsForWar: typeID [" + Settings.Instance.MaterialsForWarOreID + "] not found in ItemHangar", Logging.Debug); } items = Cache.Instance.AmmoHangar.Items.Where(k => k.TypeId == Settings.Instance.MaterialsForWarOreID).ToList(); if (!items.Any()) { if (Settings.Instance.DebugArm) { Logging.Log("StorylineState.Arm", "Ore for MaterialsForWar: typeID [" + Settings.Instance.MaterialsForWarOreID + "] not found in AmmoHangar", Logging.Debug); } // // if we do not have the ore... either we can blacklist it right here, or continue normally // return(StorylineState.GotoAgent); //return StorylineState.BlacklistAgent; } } int oreIncargo = 0; foreach (DirectItem cargoItem in Cache.Instance.CurrentShipsCargo.Items.ToList()) { if (cargoItem.TypeId != Settings.Instance.MaterialsForWarOreID) { continue; } oreIncargo += cargoItem.Quantity; continue; } int oreToLoad = Settings.Instance.MaterialsForWarOreQty - oreIncargo; if (oreToLoad <= 0) { //OreLoaded = true; return(StorylineState.GotoAgent); } DirectItem item = items.FirstOrDefault(); if (item != null) { int moveOreQuantity = Math.Min(item.Stacksize, oreToLoad); Cache.Instance.CurrentShipsCargo.Add(item, moveOreQuantity); Logging.Log("StorylineState.Arm", "Moving [" + moveOreQuantity + "] units of Ore [" + item.TypeName + "] Stack size: [" + item.Stacksize + "] from hangar to CargoHold", Logging.White); _nextAction = DateTime.UtcNow.AddSeconds(Cache.Instance.RandomNumber(3, 6)); return(StorylineState.Arm); // you can only move one set of items per frame } Logging.Log("StorylineState.Arm", "defined TransportShip found, going in active ship", Logging.White); return(StorylineState.GotoAgent); }
public SellItem(DirectItem item, bool createOrder) { _item = item; _createOrder = createOrder; }
// This does not update thread's metadata. Better run Inbox.Update() after this. public void AddItem(DirectItem item) { UpdateItemList(new List <DirectItem> { item }); }
public void ProcessState() { if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 1) { return; } _lastAction = DateTime.UtcNow; if (Cache.Instance.ItemHangar == null) { return; } DirectMarketWindow marketWindow = Cache.Instance.Windows.OfType <DirectMarketWindow>().FirstOrDefault(); switch (_States.CurrentBuyLPIState) { case BuyLPIState.Idle: case BuyLPIState.Done: break; case BuyLPIState.Begin: /* * if(marketWindow != null) * marketWindow.Close(); * * if(lpstore != null) * lpstore.Close();*/ _States.CurrentBuyLPIState = BuyLPIState.ReadyItemhangar; break; case BuyLPIState.ReadyItemhangar: if (Cache.Instance.ItemHangar == null) { return; } if (!Cache.Instance.OpenShipsHangar("BuyLPI")) { return; } _States.CurrentBuyLPIState = BuyLPIState.OpenLpStore; break; case BuyLPIState.OpenLpStore: if (Cache.Instance.LPStore == null) { return; } _States.CurrentBuyLPIState = BuyLPIState.FindOffer; break; case BuyLPIState.FindOffer: if (Cache.Instance.LPStore != null) { BuyLPI._offer = Cache.Instance.LPStore.Offers.FirstOrDefault(o => o.TypeId == Item); // Wait for the amount of LP to change if (_lastLoyaltyPoints == Cache.Instance.LPStore.LoyaltyPoints) { break; } // Do not expect it to be 0 (probably means its reloading) if (Cache.Instance.LPStore.LoyaltyPoints == 0) { if (_loyaltyPointTimeout < DateTime.UtcNow) { Logging.Log("BuyLPI", "It seems we have no loyalty points left", Logging.White); _States.CurrentBuyLPIState = BuyLPIState.Done; break; } break; } _lastLoyaltyPoints = Cache.Instance.LPStore.LoyaltyPoints; // Find the offer if (_offer == null) { Logging.Log("BuyLPI", "Can't find offer with type name/id: " + Item + "!", Logging.White); _States.CurrentBuyLPIState = BuyLPIState.Done; break; } _States.CurrentBuyLPIState = BuyLPIState.CheckPetition; } _States.CurrentBuyLPIState = BuyLPIState.OpenLpStore; break; case BuyLPIState.CheckPetition: if (Cache.Instance.LPStore != null) { // Check LP if (_lastLoyaltyPoints < _offer.LoyaltyPointCost) { Logging.Log("BuyLPI", "Not enough loyalty points left", Logging.White); _States.CurrentBuyLPIState = BuyLPIState.Done; break; } // Check ISK if (Cache.Instance.DirectEve.Me.Wealth < _offer.IskCost) { Logging.Log("BuyLPI", "Not enough ISK left", Logging.White); _States.CurrentBuyLPIState = BuyLPIState.Done; break; } // Check items foreach (DirectLoyaltyPointOfferRequiredItem requiredItem in _offer.RequiredItems) { DirectItem ship = Cache.Instance.ShipHangar.Items.FirstOrDefault(i => i.TypeId == requiredItem.TypeId); DirectItem item = Cache.Instance.ItemHangar.Items.FirstOrDefault(i => i.TypeId == requiredItem.TypeId); if (item == null || item.Quantity < requiredItem.Quantity) { if (ship == null || ship.Quantity < requiredItem.Quantity) { Logging.Log("BuyLPI", "Missing [" + requiredItem.Quantity + "] x [" + requiredItem.TypeName + "]", Logging.White); //if(!_form.chkBuyItems.Checked) //{ // Logging.Log("BuyLPI","Done, do not buy item"); // States.CurrentBuyLPIState = BuyLPIState.Done; // break; //} Logging.Log("BuyLPI", "Are buying the item [" + requiredItem.TypeName + "]", Logging.White); _requiredUnit = Convert.ToInt32(requiredItem.Quantity); _requiredItemId = requiredItem.TypeId; _States.CurrentBuyLPIState = BuyLPIState.OpenMarket; return; } } _States.CurrentBuyLPIState = BuyLPIState.AcceptOffer; } _States.CurrentBuyLPIState = BuyLPIState.OpenLpStore; } break; case BuyLPIState.OpenMarket: if (marketWindow == null) { Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.OpenMarket); break; } if (!marketWindow.IsReady) { break; } _States.CurrentBuyLPIState = BuyLPIState.BuyItems; break; case BuyLPIState.BuyItems: Logging.Log("BuyLPI", "Opening Market", Logging.White); if (marketWindow != null && marketWindow.DetailTypeId != _requiredItemId) { marketWindow.LoadTypeId(_requiredItemId); break; } if (marketWindow != null) { IEnumerable <DirectOrder> orders = marketWindow.SellOrders.Where(o => o.StationId == Cache.Instance.DirectEve.Session.StationId); DirectOrder order = orders.OrderBy(o => o.Price).FirstOrDefault(); if (order == null) { Logging.Log("BuyLPI", "No orders", Logging.White); _States.CurrentBuyLPIState = BuyLPIState.Done; break; } order.Buy(_requiredUnit, DirectOrderRange.Station); } Logging.Log("BuyLPI", "Buy Item", Logging.White); _States.CurrentBuyLPIState = BuyLPIState.CheckPetition; break; case BuyLPIState.AcceptOffer: if (Cache.Instance.LPStore != null) { DirectLoyaltyPointOffer offer2 = Cache.Instance.LPStore.Offers.FirstOrDefault(o => o.TypeId == Item); if (offer2 != null) { Logging.Log("BuyLPI", "Accepting [" + offer2.TypeName + "]", Logging.White); offer2.AcceptOfferFromWindow(); } } _States.CurrentBuyLPIState = BuyLPIState.Quantity; break; case BuyLPIState.Quantity: _loyaltyPointTimeout = DateTime.UtcNow.AddSeconds(1); Unit = Unit - 1; if (Unit <= 0) { Logging.Log("BuyLPI", "Quantity limit reached", Logging.White); _States.CurrentBuyLPIState = BuyLPIState.Done; break; } _States.CurrentBuyLPIState = BuyLPIState.Begin; break; } }
private static void OnFrame(object sender, EventArgs eventArgs) { // New frame, invalidate old cache Cache.Instance.InvalidateCache(); Cache.Instance.LastFrame = DateTime.UtcNow; // Only pulse state changes every 1.5s if (DateTime.UtcNow.Subtract(_lastPulse).TotalMilliseconds < 300) { return; } _lastPulse = DateTime.UtcNow; // Session is not ready yet, do not continue if (!Cache.Instance.DirectEve.Session.IsReady) { return; } if (Cache.Instance.DirectEve.Session.IsReady) { Cache.Instance.LastSessionIsReady = DateTime.UtcNow; } // We are not in space or station, don't do shit yet! if (!Cache.Instance.InSpace && !Cache.Instance.InStation) { Cache.Instance.NextInSpaceorInStation = DateTime.UtcNow.AddSeconds(12); Cache.Instance.LastSessionChange = DateTime.UtcNow; return; } if (DateTime.UtcNow < Cache.Instance.NextInSpaceorInStation) { return; } if (Cache.Instance.SessionState != "Quitting") { // Update settings (settings only load if character name changed) if (!Settings.Instance.DefaultSettingsLoaded) { Settings.Instance.LoadSettings(); } } // Start _cleanup.ProcessState // Description: Closes Windows, and eventually other things considered 'cleanup' useful to more than just Questor(Missions) but also Anomalies, Mining, etc // _cleanup.ProcessState(); // Done // Cleanup State: ProcessState if (DateTime.UtcNow > _done) { return; } // Wait for the next action if (_nextAction >= DateTime.UtcNow) { return; } if (Cache.Instance.ItemHangar == null) { return; } if (Cache.Instance.LPStore == null) { _nextAction = DateTime.UtcNow.AddMilliseconds(WaitMillis); return; } // Wait for the amount of LP to change if (_lastLoyaltyPoints == Cache.Instance.LPStore.LoyaltyPoints) { return; } // Do not expect it to be 0 (probably means its reloading) if (Cache.Instance.LPStore.LoyaltyPoints == 0) { if (_loyaltyPointTimeout < DateTime.UtcNow) { Logging.Log("BuyLPI", "It seems we have no loyalty points left", Logging.White); _done = DateTime.UtcNow; return; } return; } _lastLoyaltyPoints = Cache.Instance.LPStore.LoyaltyPoints; // Find the offer DirectLoyaltyPointOffer offer = Cache.Instance.LPStore.Offers.FirstOrDefault(o => o.TypeId.ToString(CultureInfo.InvariantCulture) == _type || String.Compare(o.TypeName, _type, StringComparison.OrdinalIgnoreCase) == 0); if (offer == null) { Logging.Log("BuyLPI", " Can't find offer with type name/id: [" + _type + "]", Logging.White); _done = DateTime.UtcNow; return; } // Check LP if (_lastLoyaltyPoints < offer.LoyaltyPointCost) { Logging.Log("BuyLPI", "Not enough loyalty points left: you have [" + _lastLoyaltyPoints + "] and you need [" + offer.LoyaltyPointCost + "]", Logging.White); _done = DateTime.UtcNow; return; } // Check ISK if (Cache.Instance.DirectEve.Me.Wealth < offer.IskCost) { Logging.Log("BuyLPI", "Not enough ISK left: you have [" + Math.Round(Cache.Instance.DirectEve.Me.Wealth, 0) + "] and you need [" + offer.IskCost + "]", Logging.White); _done = DateTime.UtcNow; return; } // Check items foreach (DirectLoyaltyPointOfferRequiredItem requiredItem in offer.RequiredItems) { DirectItem item = Cache.Instance.ItemHangar.Items.FirstOrDefault(i => i.TypeId == requiredItem.TypeId); if (item == null || item.Quantity < requiredItem.Quantity) { Logging.Log("BuyLPI", "Missing [" + requiredItem.Quantity + "] x [" + requiredItem.TypeName + "]", Logging.White); _done = DateTime.UtcNow; return; } } // All passed, accept offer if (_quantity != null) { if (_totalQuantityOfOrders != null) { Logging.Log("BuyLPI", "Accepting " + offer.TypeName + " [ " + _quantity.Value + " ] of [ " + _totalQuantityOfOrders.Value + " ] orders and will cost another [" + Math.Round(((offer.IskCost * _quantity.Value) / (double)1000000), 2) + "mil isk]", Logging.White); } } offer.AcceptOfferFromWindow(); // Set next action + loyalty point timeout _nextAction = DateTime.UtcNow.AddMilliseconds(WaitMillis); _loyaltyPointTimeout = DateTime.UtcNow.AddSeconds(25); if (_quantity.HasValue) { _quantity = _quantity.Value - 1; if (_quantity.Value <= 0) { Logging.Log("BuyLPI", "Quantity limit reached", Logging.White); _done = DateTime.UtcNow; return; } } }
public void ProcessState() { if (!Cache.Instance.InStation) { return; } if (Cache.Instance.InSpace) { return; } if (DateTime.UtcNow < Cache.Instance.LastInSpace.AddSeconds(20)) // we wait 20 seconds after we last thought we were in space before trying to do anything in station { return; } //DirectMarketWindow marketWindow = Cache.Instance.Windows.OfType<DirectMarketWindow>().FirstOrDefault(); DirectMarketActionWindow sellWindow = Cache.Instance.Windows.OfType <DirectMarketActionWindow>().FirstOrDefault(w => w.IsSellAction); switch (_States.CurrentSellState) { case SellState.Idle: case SellState.Done: break; case SellState.Begin: _States.CurrentSellState = SellState.StartQuickSell; break; case SellState.StartQuickSell: if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 1) { break; } _lastAction = DateTime.UtcNow; if (Cache.Instance.ItemHangar == null) { break; } DirectItem directItem = Cache.Instance.ItemHangar.Items.FirstOrDefault(i => (i.TypeId == Item)); if (directItem == null) { Logging.Log("Sell", "Item " + Item + " no longer exists in the hanger", Logging.White); break; } // Update Quantity if (Unit == 00) { Unit = directItem.Quantity; } Logging.Log("Sell", "Starting QuickSell for " + Item, Logging.White); if (!directItem.QuickSell()) { _lastAction = DateTime.UtcNow.AddSeconds(-5); Logging.Log("Sell", "QuickSell failed for " + Item + ", retrying in 5 seconds", Logging.White); break; } _States.CurrentSellState = SellState.WaitForSellWindow; break; case SellState.WaitForSellWindow: //if (sellWindow == null || !sellWindow.IsReady || sellWindow.Item.ItemId != Item) // break; // Mark as new execution _lastAction = DateTime.UtcNow; Logging.Log("Sell", "Inspecting sell order for " + Item, Logging.White); _States.CurrentSellState = SellState.InspectOrder; break; case SellState.InspectOrder: // Let the order window stay open for 2 seconds if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 2) { break; } if (sellWindow != null) { if ((!sellWindow.OrderId.HasValue || !sellWindow.Price.HasValue || !sellWindow.RemainingVolume.HasValue)) { Logging.Log("Sell", "No order available for " + Item, Logging.White); sellWindow.Cancel(); _States.CurrentSellState = SellState.WaitingToFinishQuickSell; break; } double price = sellWindow.Price.Value; Logging.Log("Sell", "Selling " + Unit + " of " + Item + " [Sell price: " + (price * Unit).ToString("#,##0.00") + "]", Logging.White); sellWindow.Accept(); _States.CurrentSellState = SellState.WaitingToFinishQuickSell; } _lastAction = DateTime.UtcNow; break; case SellState.WaitingToFinishQuickSell: if (sellWindow == null || !sellWindow.IsReady || sellWindow.Item.ItemId != Item) { DirectWindow modal = Cache.Instance.Windows.FirstOrDefault(w => w.IsModal); if (modal != null) { modal.Close(); } _States.CurrentSellState = SellState.Done; break; } break; } }