public static void LoadInstanceFromCoordinateData(string settingsCoordinateData) { try { ItemCollection l_ItemCollection = ItemCollection.Instance; string l_CoordinateString;//Format xxxxyyyy string[] l_CoordinatesData = settingsCoordinateData.Split(';'); string[] l_CoordinateData = l_CoordinatesData[0].Split(','); for (int i = 0; i < l_CoordinatesData.Length; i++) { ItemCollection.Item l_Item = new ItemCollection.Item(); l_CoordinateData = l_CoordinatesData[i].Split(','); if (l_CoordinateData.Length >= 6) { l_CoordinateString = l_CoordinateData[0]; if (l_ItemCollection.Items.TryGetValue(l_CoordinateString, out l_Item)) { //Item already loaded } else { //New item l_ItemCollection.Items[l_CoordinateString] = new ItemCollection.Item(int.Parse(l_CoordinateData[1]), int.Parse(l_CoordinateData[2]), l_CoordinateData[3], int.Parse(l_CoordinateData[4]), bool.Parse(l_CoordinateData[5])); } } } } catch (Exception) { } }
private IEnumerable<Coordinate> ScanPicture4Production() { ItemCollection l_ItemCollection = ItemCollection.Instance; string l_CoordinateString;//Format xxxxyyyy UpdateStatus(LogType.ScanProductionStart, null); var sw = new Stopwatch(); sw.Start(); var crdResultList = new List<Coordinate>(); var image = GetNewBrowserImageInvokeForced(); try { if (IsPopupPresent(image)) { TryClosePopup(); BlockUntilPopupIs(false, Settings.WaitOnPopupInMillis); image.Dispose(); image = GetNewBrowserImageInvokeForced(); } var color = Color.FromArgb(240, 210, 174).ToArgb(); var color2 = Color.FromArgb(131, 100, 67).ToArgb(); uint num = 0; // Using picture scanner so we can use Parallel. Graphics in C# is not thread-safe //Parallel.For(0, Settings.BotPictureWidth, i => for (int i = 0; i < Settings.BotPictureWidth; i++) { for (int j = 50; j < Settings.BotPictureHeight-150; j++) { if ((image.GetPixelRgb(i, j) == color) && (image.GetPixelRgb(i + 1, j) == color2)) { UpdateStatus(LogType.ScanProductionFound, (++num).ToString()); crdResultList.Add(new Coordinate(i, j)); var l_Item = new ItemCollection.Item(); l_CoordinateString = ItemCollection.MakePoint(i, j); if (l_ItemCollection.Items.TryGetValue(l_CoordinateString, out l_Item)) { //Item found in ItemCollection, update timestamp. var existingItem = l_ItemCollection.Items[l_CoordinateString]; l_ItemCollection.Items[l_CoordinateString] = new ItemCollection.Item(existingItem.m_OffsetX, existingItem.m_OffsetY, System.DateTime.Now.Ticks.ToString(), existingItem.YStepping, existingItem.LastClickWasSuccessful); } else { //Item not found in ItemCollection, add new one. l_ItemCollection.Items[l_CoordinateString] = new ItemCollection.Item(Settings.SupplyDistanceX, Settings.SupplyDistanceY, System.DateTime.Now.Ticks.ToString(), 0, true); } } } } sw.Stop(); UpdateStatus(LogType.ScanProductionStop, ((double) sw.ElapsedMilliseconds/1000).ToString("0.00")); if (Settings.SaveScanResults) { SaveScanResultToFile(image, crdResultList, Settings.SupplyDistanceX, Settings.SupplyDistanceY, "supplyresults.png"); } } finally { image.Dispose(); } return crdResultList; }
private List<Coordinate> ScanPicture4Collect() { ItemCollection l_ItemCollection = ItemCollection.Instance; string l_CoordinateString;//Format xxxxyyyy Sleeping(500); InjectClickAtInvokeForced(150, 50); UpdateStatus(LogType.ScanStart, null); var sw = new Stopwatch(); sw.Start(); var crdList = new List<Coordinate>(); var image = GetNewBrowserImageInvokeForced(); try { if (IsPopupPresent(image)) { TryClosePopup(); BlockUntilPopupIs(false, Settings.WaitOnPopupInMillis); image.Dispose(); image = GetNewBrowserImageInvokeForced(); } var itemColor = Color.FromArgb(191, 169, 135).ToArgb(); var goldBoxColor = Color.FromArgb(221, 189, 118).ToArgb(); var plungedColor1 = Color.FromArgb(248, 238, 214).ToArgb(); var plungedColor2 = Color.FromArgb(160, 144, 124).ToArgb(); var plungedColor3 = Color.FromArgb(197, 183, 149).ToArgb(); var wentBadColor1 = Color.FromArgb(255, 248, 229).ToArgb(); var wentBadColor2 = Color.FromArgb(255, 247, 217).ToArgb(); var wentBadColor3 = Color.FromArgb(43, 25, 4).ToArgb(); uint num = 0; // Using picture scanner so we can use Parallel. Graphics in C# is not thread-safe //Parallel.For(0, Settings.BotPictureWidth, i => for (int i = 0; i < Settings.BotPictureWidth; i++) { for (int j = 50; j < Settings.BotPictureHeight-150; j++) { { if (image.GetPixelRgb(i, j) == itemColor || image.GetPixelRgb(i, j) == goldBoxColor) { UpdateStatus(LogType.ScanFound, (++num).ToString()); //updateStatus(LogType.JustMessage, string.Format("x={0},y={1}", i, j)); crdList.Add(new Coordinate(i, j)); var l_Item = new ItemCollection.Item(); l_CoordinateString = ItemCollection.MakePoint(i,j); if (l_ItemCollection.Items.TryGetValue(l_CoordinateString, out l_Item)) { var existingItem = l_ItemCollection.Items[l_CoordinateString]; //Item found in ItemCollection, update timestamp. l_ItemCollection.Items[l_CoordinateString] = new ItemCollection.Item(existingItem.m_OffsetX, existingItem.m_OffsetY, System.DateTime.Now.Ticks.ToString(),existingItem.YStepping,existingItem.LastClickWasSuccessful); } else { //Item not found in ItemCollection, add new one. l_ItemCollection.Items[l_CoordinateString] = new ItemCollection.Item(Settings.CollectDistanceX, Settings.CollectDistanceY, System.DateTime.Now.Ticks.ToString(),0,true); } continue; } if (Settings.DoPlungedItemsClick) { // scan for plunged items if (image.GetPixelRgb(i, j) == plungedColor1 && image.GetPixelRgb(i - 3, j + 12) == plungedColor2 && image.GetPixelRgb(i + 9, j + 12) == plungedColor3) { UpdateStatus(LogType.PlungedScanFound, (++num).ToString()); crdList.Add(new Coordinate(i, j)); var l_Item = new ItemCollection.Item(); l_CoordinateString = ItemCollection.MakePoint(i, j); if (l_ItemCollection.Items.TryGetValue(l_CoordinateString, out l_Item)) { //Item found in ItemCollection, update timestamp. var existingItem = l_ItemCollection.Items[l_CoordinateString]; l_ItemCollection.Items[l_CoordinateString] = new ItemCollection.Item(existingItem.m_OffsetX, existingItem.m_OffsetY, System.DateTime.Now.Ticks.ToString(),existingItem.YStepping,existingItem.LastClickWasSuccessful); } else { //Item not found in ItemCollection, add new one. l_ItemCollection.Items[l_CoordinateString] = new ItemCollection.Item(Settings.CollectDistanceX, Settings.CollectDistanceY, System.DateTime.Now.Ticks.ToString(), 0, true); } continue; } // scan for "rotted supplies" items - dead fish if (image.GetPixelRgb(i - 6, j + 18) == wentBadColor1 && image.GetPixelRgb(i - 3, j + 18) == wentBadColor2 && image.GetPixelRgb(i + 28, j + 10) == wentBadColor3) { UpdateStatus(LogType.RottedSuppliesScanFound, (++num).ToString()); crdList.Add(new Coordinate(i, j)); var l_Item = new ItemCollection.Item(); l_CoordinateString = ItemCollection.MakePoint(i, j); if (l_ItemCollection.Items.TryGetValue(l_CoordinateString, out l_Item)) { //Item found in ItemCollection, update timestamp. var existingItem = l_ItemCollection.Items[l_CoordinateString]; l_ItemCollection.Items[l_CoordinateString] = new ItemCollection.Item(existingItem.m_OffsetX, existingItem.m_OffsetY, System.DateTime.Now.Ticks.ToString(), existingItem.YStepping, existingItem.LastClickWasSuccessful); } else { //Item not found in ItemCollection, add new one. l_ItemCollection.Items[l_CoordinateString] = new ItemCollection.Item(Settings.CollectDistanceX, Settings.CollectDistanceY, System.DateTime.Now.Ticks.ToString(), 0, true); } continue; } } } } } sw.Stop(); UpdateStatus(LogType.ScanStop, ((double) sw.ElapsedMilliseconds/1000).ToString("0.00")); if (Settings.SaveScanResults) { SaveScanResultToFile(image, crdList, 0, Settings.CollectDistanceY, "scanresults.png"); } } finally { // dispose potentially heavy resource image.Dispose(); } return crdList; }
private void DoSupplyClicks(IEnumerable<Coordinate> crdList) { var l_Item = new ItemCollection.Item(); UpdateStatus(LogType.ClickProductionStart, null); int num = 0; var lastGoodY = 0; var lastGoodX = 0; foreach (var coordinate in crdList) { var l_CoordinateString = ItemCollection.MakePoint(coordinate.X,coordinate.Y); if (ItemCollection.Instance.Items.TryGetValue(l_CoordinateString, out l_Item)) { l_Item.CalculateNewTrialCoordinates(); // we try to impose better trial coordinates for the item only if it has to tryout for the first time if(lastGoodY!=0 && l_Item.ReadyForTheFirstAdjustment) { l_Item.m_OffsetX = lastGoodX; l_Item.m_OffsetY = lastGoodY; } InjectClickAtInvokeForced(coordinate.X + l_Item.m_OffsetX, coordinate.Y + l_Item.m_OffsetY); num++; UpdateStatus(LogType.ClickProductionSelect, num.ToString()); BlockUntilPopupIs(true, Settings.WaitOnPopupInMillis); var image = GetNewBrowserImageInvokeForced(); try { l_Item.ClickSuccessful(false); if (IsPopupPresent(image)) { Coordinate cordClose; if (IsSupplyWinPresent(image, out cordClose)) { l_Item.ClickSuccessful(true); InjectClickAtInvokeForced(Settings.SupplyItemCoords.X, Settings.SupplyItemCoords.Y); UpdateStatus(LogType.ClickProductionDone, num.ToString()); BlockUntilPopupIs(false, Settings.WaitOnPopupInMillis); image.Dispose(); image = GetNewBrowserImageInvokeForced(); if (!IsPopupPresent(image)) { continue; } UpdateStatus(LogType.JustMessage, Resource.MainForm_DoSupplyClicks_Error_PopupRemained_SelectingSupplies); image.Image.Save("suppliesWindow.png", ImageFormat.Png); // try to close popup if (TryClosePopup()) continue; break; } if (IsGoodsWinPresent(image, out cordClose)) { l_Item.ClickSuccessful(true); //saveScanResultToFile(image, crdList, 0, collectDistanceY, "goodswin-ok.png"); bool isMilitary = false; //military units usually goes under this if (IsMilitaryWinPresent(image, out cordClose)) { isMilitary = true; if (Settings.DoMilitaryUnitsClicks) { ClickMilitaryItems(image); } else { UpdateStatus(LogType.JustMessage, Resource.MainForm_DoSupplyClicks_MilitaryClick_Disabled); TryClosePopup(); } } else { if (Settings.DoGoodsClicks) { InjectClickAtInvokeForced(Settings.GoodsItemCoords.X, Settings.GoodsItemCoords.Y); UpdateStatus(LogType.ClickProductionDone, num.ToString()); } else { UpdateStatus(LogType.JustMessage, Resource.MainForm_DoSupplyClicks_GoodsClick_Disabled); TryClosePopup(); } } BlockUntilPopupIs(false, Settings.WaitOnPopupInMillis); image.Dispose(); image = GetNewBrowserImageInvokeForced(); if (!IsPopupPresent(image)) { continue; } if (!isMilitary) UpdateStatus(LogType.JustMessage, Resource.MainForm_DoSupplyClicks_Error_PopupRemained_SelectingGoods); else UpdateStatus(LogType.JustMessage, Resource.MainForm_DoSupplyClicks_Error_PopupRemained_SelectingMilitary); image.Image.Save("goodsWindow.png", ImageFormat.Png); // try to close popup if (TryClosePopup()) continue; break; } UpdateStatus(LogType.JustMessage, string.Format(Resource.MainForm_DoSupplyClicks_NonProductionBuilding, num)); if (!TryClosePopup()) { return; } } } finally { // Save last good click for next one if (l_Item.LastClickWasSuccessful) { lastGoodX=l_Item.m_OffsetX; lastGoodY=l_Item.m_OffsetY; } ItemCollection.Instance.Items[l_CoordinateString] = l_Item; image.Dispose(); } } } UpdateStatus(LogType.ClickStop, null); }
private void DoCollectClicks(List<Coordinate> crdList) { ItemCollection.Item l_Item = new ItemCollection.Item(); UpdateStatus(LogType.ClickStart, null); // maximum number of items to click var maxToClick = crdList.Count > Settings.MaxItemsClickedInARow ? Settings.MaxItemsClickedInARow : crdList.Count; int maxClickedItems = Randomizer(maxToClick, Settings.RndPercentDontCollectInARow, false); if (maxClickedItems <= 0) maxClickedItems = 1; AddMessage(string.Format(Resource.MainForm_DoCollectClicks_Stealth_ClickingFirstXItems, maxClickedItems)); // hvatamo boje za proveru da li su kliknute kutije var image = GetNewBrowserImageInvokeForced(); var colors=new List<int>(); int num = 0; foreach (Coordinate coordinate in crdList) { colors.Add(image.GetPixelRgb(coordinate.X, coordinate.Y)); string l_CoordinateString = ItemCollection.MakePoint(coordinate.X,coordinate.Y); if (ItemCollection.Instance.Items.TryGetValue(l_CoordinateString, out l_Item)) { l_Item.CalculateNewTrialCoordinates(); InjectClickAtInvokeForced(coordinate.X + l_Item.m_OffsetX, coordinate.Y + l_Item.m_OffsetY); num++; UpdateStatus(LogType.ClickDone, num.ToString()); if (num >= maxClickedItems) break; Sleeping(200); } } image.Dispose(); Sleeping(500); // nova slika za proveru image = GetNewBrowserImageInvokeForced(); num = 0; foreach (Coordinate coordinate in crdList) { string l_CoordinateString = ItemCollection.MakePoint(coordinate.X, coordinate.Y); if (ItemCollection.Instance.Items.TryGetValue(l_CoordinateString, out l_Item)) { var colorNew = image.GetPixelRgb(coordinate.X, coordinate.Y); var colorOld = colors[num++]; // ako su boje iste onda click nije uspeo l_Item.ClickSuccessful(colorOld != colorNew); ItemCollection.Instance.Items[l_CoordinateString] = l_Item; } } image.Dispose(); UpdateStatus(LogType.ClickStop, null); }