public void Dust() { navigation.StartBot(); while (true) { try { navigation.StartDust(); if (navigation.ActualLocation == Places.DustMap) { for (int i = ocr.GetDustStep(); i <= 5; i++) { BattleAlgorithm battleAlgorithm = new BattleAlgorithm(); battleAlgorithm.Run(i); if (i != 5) { navigation.WaitForNextDustStep(i); } else { navigation.EndDust(); } } } } catch (Exception ex) { writer.WriteError($"{ex.Message}"); navigation.StartBot(); } } }
/// <summary> /// Comprueba si hay un error /// </summary> public void CheckForError() { WriteHelper Writer = new WriteHelper(); var image = ScreenCapture(); if (image == null) { Writer.WriteError("No se puede contactar con el emulador!"); Console.ReadKey(); } }
public bool DustWorker(int r, Dictionary <Places, PositionState> dic, bool force) { Thread.Sleep(2000); if (dic.FirstOrDefault(_g => _g.Key == Enum.Parse <Places>($"DustPosition{r}")).Value != PositionState.Played) { nav.TapDustPosition(Enum.Parse <Places>($"DustPosition{r}")); WriteHelper.WriteLine($"Intentado luchar contra el enemigo en la posición: {r} "); nav.WaitForLocation(Places.BattlePopUp); var battlePower = ocr.GetDustPlayersPower(); var margin = config.GetEnemyMargin(); int difference = -1; if (force) { difference = (battlePower.Item1 + margin) - battlePower.Item2; } else { difference = battlePower.Item1 - battlePower.Item2; } if (difference > 0) { nav.TapInGoDustFight(); nav.WaitForLocation(Places.Battle); nav.DoubleSpeed(); nav.WaitForLocation(Places.BattleFinish); nav.TapFinishBattle(); nav.WaitForLocation(Places.DustMap); return(true); } WriteHelper.WriteError($"El enemigo en la posición {r} es demasiado poderoso!"); nav.KeyScap(); } return(false); }
public void Run(int i) { Image image = nav.ScreenCapture(); nav.ShowDustIncomingStep(i); var positionStates = nav.GetDustPositionStates(image); Places myPosition = nav.GetMyDustPositionStates(positionStates); if (nav.IsPositionBattleFinished(image, myPosition) == false) { if (DustBucle(myPosition, positionStates) == false) { WriteHelper.WriteError($"No se ha podido luchar contra nadie. Intentamos luchar contra alguien más fuerte."); DustBucle(myPosition, positionStates, true); } } else { WriteHelper.WriteWarning($"Ya se han luchado las peleas de esta etapa."); } }
/// <summary> /// Captura la pantalla /// </summary> /// <returns></returns> public Image ScreenCapture() { WriteHelper Writer = new WriteHelper(); try { //return Image.FromFile(ImagePath); Image result = null; byte[] data = Convert.FromBase64String(ReturnExec(@"exec-out ""screencap -p | base64""", Commands.CommandEnum.Adb)); using (var stream = new MemoryStream(data, 0, data.Length)) { result = Image.FromStream(stream); } result.Save(ImagePath); return(result); } catch (Exception) { Writer.WriteError($"No se puede contactar con el emulador!"); Thread.Sleep(1000); return(null); } }
/// <summary> /// Espera hasta que se obtiene la ubicación seleccionada /// </summary> /// <param name="location"></param> /// <returns></returns> public bool WaitForLocation(Places location) { bool result = false; int tryCount = 50; if (location == Places.Battle) { tryCount = 1000; } if (location == Places.BattleFinish) { tryCount = 5000; } if (location == Places.DustMap) { tryCount = 15000; } if (location == Places.DustFinished) { tryCount = 600000; } ConsoleSpiner spin = new ConsoleSpiner(); WriteHelper.Write($"Esperando por la localización: {location} "); for (int i = 0; i < tryCount; i++) { var _actualLocation = ActualLocation; if (_actualLocation == location) { result = true; break; } if (location == Places.Battle) { if (_actualLocation == Places.ApplePopUp) { break; } if (_actualLocation == Places.SpellPopUp) { TapContinueInSpellPopUp(); } if (_actualLocation == Places.LifePopUp) { TapNoInLifePopUp(); Thread.Sleep(4000); TapInGoFight(); } } spin.Turn(); } spin.FinishTurn(); if (result) { WriteHelper.WriteSuccessfully($"Navegación completada: {location}"); } else { WriteHelper.WriteError($"No se ha conseguido completar la navegación: {location}"); } return(result); }