public void HandleEvent(PokemonCaptureEvent evt, Context ctx) { Func<ItemId, string> returnRealBallName = a => { switch (a) { case ItemId.ItemPokeBall: return ctx.Translations.GetTranslation(TranslationString.Pokeball); case ItemId.ItemGreatBall: return ctx.Translations.GetTranslation(TranslationString.GreatPokeball); case ItemId.ItemUltraBall: return ctx.Translations.GetTranslation(TranslationString.UltraPokeball); case ItemId.ItemMasterBall: return ctx.Translations.GetTranslation(TranslationString.MasterPokeball); default: return "Unknown"; } }; var catchType = evt.CatchType; var catchStatus = evt.Attempt > 1 ? ctx.Translations.GetTranslation(TranslationString.CatchStatusAttempt, evt.Status, evt.Attempt) : ctx.Translations.GetTranslation(TranslationString.CatchStatus, evt.Status); var familyCandies = evt.FamilyCandies > 0 ? ctx.Translations.GetTranslation(TranslationString.Candies, evt.FamilyCandies) : ""; Logger.Write(ctx.Translations.GetTranslation(TranslationString.EventPokemonCapture, catchStatus, catchType, evt.Id, evt.Level, evt.Cp, evt.MaxCp, evt.Perfection.ToString("0.00"), evt.Probability, evt.Distance.ToString("F2"), returnRealBallName(evt.Pokeball), evt.BallAmount, familyCandies), LogLevel.Caught); }
public void HandleEvent(EggIncubatorStatusEvent evt, Context ctx) { if (evt.WasAddedNow) Logger.Write($"Putting egg in incubator: {evt.KmRemaining:0.00}km left"); else Logger.Write($"Incubator status update: {evt.KmRemaining:0.00}km left"); }
public static void Execute(Context ctx, StateMachine machine) { if (ctx.LogicSettings.UseLuckyEggsWhileEvolving) { UseLuckyEgg(ctx.Client, ctx.Inventory, machine); } var pokemonToEvolveTask = ctx.Inventory.GetPokemonToEvolve(ctx.LogicSettings.PokemonsToEvolve); pokemonToEvolveTask.Wait(); var pokemonToEvolve = pokemonToEvolveTask.Result; foreach (var pokemon in pokemonToEvolve) { var evolveTask = ctx.Client.Inventory.EvolvePokemon(pokemon.Id); evolveTask.Wait(); var evolvePokemonOutProto = evolveTask.Result; machine.Fire(new PokemonEvolveEvent { Id = pokemon.PokemonId, Exp = evolvePokemonOutProto.ExperienceAwarded, Result = evolvePokemonOutProto.Result }); Thread.Sleep(3000); } }
public void HandleEvent(PokemonEvolveEvent evt, Context ctx) { Logger.Write(evt.Result == EvolvePokemonResponse.Types.Result.Success ? ctx.Translations.GetTranslation(TranslationString.EventPokemonEvolvedSuccess, evt.Id, evt.Exp) : ctx.Translations.GetTranslation(TranslationString.EventPokemonEvolvedFailed, evt.Id, evt.Result, evt.Id), LogLevel.Evolve); }
public void HandleEvent(PokemonEvolveEvent evt, Context ctx) { Logger.Write(evt.Result == EvolvePokemonResponse.Types.Result.Success ? $"{evt.Id} successfully for {evt.Exp}xp" : $"Failed {evt.Id}. EvolvePokemonOutProto.Result was {evt.Result}, stopping evolving {evt.Id}", LogLevel.Evolve); }
public static void Execute(Context ctx, StateMachine machine) { var duplicatePokemons = ctx.Inventory.GetDuplicatePokemonToTransfer(ctx.LogicSettings.KeepPokemonsThatCanEvolve, ctx.LogicSettings.PrioritizeIvOverCp, ctx.LogicSettings.PokemonsNotToTransfer).Result; foreach (var duplicatePokemon in duplicatePokemons) { if (duplicatePokemon.Cp >= ctx.LogicSettings.KeepMinCp || PokemonInfo.CalculatePokemonPerfection(duplicatePokemon) > ctx.LogicSettings.KeepMinIvPercentage) { continue; } ctx.Client.Inventory.TransferPokemon(duplicatePokemon.Id).Wait(); ctx.Inventory.DeletePokemonFromInvById(duplicatePokemon.Id); var bestPokemonOfType = ctx.LogicSettings.PrioritizeIvOverCp ? ctx.Inventory.GetHighestPokemonOfTypeByIv(duplicatePokemon).Result : ctx.Inventory.GetHighestPokemonOfTypeByCp(duplicatePokemon).Result; if (bestPokemonOfType == null) bestPokemonOfType = duplicatePokemon; machine.Fire(new TransferPokemonEvent { Id = duplicatePokemon.PokemonId, Perfection = PokemonInfo.CalculatePokemonPerfection(duplicatePokemon), Cp = duplicatePokemon.Cp, BestCp = bestPokemonOfType.Cp, BestPerfection = PokemonInfo.CalculatePokemonPerfection(bestPokemonOfType) }); } }
public static async Task Execute(Context ctx, StateMachine machine) { var highestsPokemonCp = await ctx.Inventory.GetHighestsCp(ctx.LogicSettings.AmountOfPokemonToDisplayOnStart); var pokemonPairedWithStatsCp = highestsPokemonCp.Select(pokemon => Tuple.Create(pokemon, PokemonInfo.CalculateMaxCp(pokemon), PokemonInfo.CalculatePokemonPerfection(pokemon), PokemonInfo.GetLevel(pokemon))).ToList(); var highestsPokemonPerfect = await ctx.Inventory.GetHighestsPerfect(ctx.LogicSettings.AmountOfPokemonToDisplayOnStart); var pokemonPairedWithStatsIv = highestsPokemonPerfect.Select(pokemon => Tuple.Create(pokemon, PokemonInfo.CalculateMaxCp(pokemon), PokemonInfo.CalculatePokemonPerfection(pokemon), PokemonInfo.GetLevel(pokemon))).ToList(); machine.Fire( new DisplayHighestsPokemonEvent { SortedBy = "CP", PokemonList = pokemonPairedWithStatsCp }); await Task.Delay(500); machine.Fire( new DisplayHighestsPokemonEvent { SortedBy = "IV", PokemonList = pokemonPairedWithStatsIv }); await Task.Delay(500); }
public async Task<IState> Execute(Context ctx, StateMachine machine) { if (ctx.LogicSettings.AmountOfPokemonToDisplayOnStart > 0) await DisplayPokemonStatsTask.Execute(ctx, machine); return new FarmState(); }
public static async Task Execute(Context ctx, StateMachine machine) { var pokemonToEvolveTask = await ctx.Inventory.GetPokemonToEvolve(ctx.LogicSettings.PokemonsToEvolve); var pokemonToEvolve = pokemonToEvolveTask.ToList(); if (pokemonToEvolve.Any()) { if (ctx.LogicSettings.UseLuckyEggsWhileEvolving) { if (pokemonToEvolve.Count() >= ctx.LogicSettings.UseLuckyEggsMinPokemonAmount) { await UseLuckyEgg(ctx.Client, ctx.Inventory, machine); } else { // Wait until we have enough pokemon return; } } foreach (var pokemon in pokemonToEvolve) { var evolveResponse = await ctx.Client.Inventory.EvolvePokemon(pokemon.Id); machine.Fire(new PokemonEvolveEvent { Id = pokemon.PokemonId, Exp = evolveResponse.ExperienceAwarded, Result = evolveResponse.Result }); await Task.Delay(3000); } } }
public static async Task Execute(Context ctx, StateMachine machine) { var highestsPokemonCp = await ctx.Inventory.GetHighestsCp(ctx.LogicSettings.AmountOfPokemonToDisplayOnStart); List<Tuple<PokemonData, int, double, double>> pokemonPairedWithStatsCP = new List<Tuple<PokemonData, int, double, double>>(); foreach (var pokemon in highestsPokemonCp) pokemonPairedWithStatsCP.Add(Tuple.Create(pokemon, PokemonInfo.CalculateMaxCp(pokemon), PokemonInfo.CalculatePokemonPerfection(pokemon), PokemonInfo.GetLevel(pokemon))); var highestsPokemonPerfect = await ctx.Inventory.GetHighestsPerfect(ctx.LogicSettings.AmountOfPokemonToDisplayOnStart); List<Tuple<PokemonData, int, double, double>> pokemonPairedWithStatsIV = new List<Tuple<PokemonData, int, double, double>>(); foreach (var pokemon in highestsPokemonPerfect) pokemonPairedWithStatsIV.Add(Tuple.Create(pokemon, PokemonInfo.CalculateMaxCp(pokemon), PokemonInfo.CalculatePokemonPerfection(pokemon), PokemonInfo.GetLevel(pokemon))); machine.Fire( new DisplayHighestsPokemonEvent { SortedBy = "Cp", PokemonList = pokemonPairedWithStatsCP }); await Task.Delay(500); machine.Fire( new DisplayHighestsPokemonEvent { SortedBy = "Iv", PokemonList = pokemonPairedWithStatsIV }); await Task.Delay(500); }
public IState Execute(Context ctx, StateMachine machine) { if (ctx.LogicSettings.EvolveAllPokemonAboveIv || ctx.LogicSettings.EvolveAllPokemonWithEnoughCandy) { EvolvePokemonTask.Execute(ctx, machine); } if (ctx.LogicSettings.TransferDuplicatePokemon) { TransferDuplicatePokemonTask.Execute(ctx, machine); } RecycleItemsTask.Execute(ctx, machine); if (ctx.LogicSettings.UseGpxPathing) { FarmPokestopsGpxTask.Execute(ctx, machine); } else { FarmPokestopsTask.Execute(ctx, machine); } machine.RequestDelay(10000); return this; }
public void HandleEvent(PokemonCaptureEvent evt, Context ctx) { Func<ItemId, string> returnRealBallName = a => { switch (a) { case ItemId.ItemPokeBall: return "Poke"; case ItemId.ItemGreatBall: return "Great"; case ItemId.ItemUltraBall: return "Ultra"; case ItemId.ItemMasterBall: return "Master"; default: return "Unknown"; } }; var catchStatus = evt.Attempt > 1 ? $"{evt.Status} Attempt #{evt.Attempt}" : $"{evt.Status}"; Logger.Write( $"({catchStatus}) | {evt.Id} Lvl {evt.Level} ({evt.Cp}/{evt.MaxCp} CP) ({evt.Perfection.ToString("0.00")}% perfect) | Chance: {evt.Probability}% | {Math.Round(evt.Distance)}m dist | with a {returnRealBallName(evt.Pokeball)}Ball.", LogLevel.Caught); }
public async Task<IState> Execute(Context ctx, StateMachine machine) { if (ctx.LogicSettings.EvolveAllPokemonAboveIv || ctx.LogicSettings.EvolveAllPokemonWithEnoughCandy) { await EvolvePokemonTask.Execute(ctx, machine); } if (ctx.LogicSettings.TransferDuplicatePokemon) { await TransferDuplicatePokemonTask.Execute(ctx, machine); } if (ctx.LogicSettings.RenameAboveIv) { await RenamePokemonTask.Execute(ctx, machine); } await RecycleItemsTask.Execute(ctx, machine); if (ctx.LogicSettings.UseEggIncubators) { await UseIncubatorsTask.Execute(ctx, machine); } if (ctx.LogicSettings.UseGpxPathing) { await FarmPokestopsGpxTask.Execute(ctx, machine); } else { await FarmPokestopsTask.Execute(ctx, machine); } return this; }
public void HandleEvent(TransferPokemonEvent evt, Context ctx) { Logger.Write( ctx.Translations.GetTranslation(TranslationString.EventPokemonTransferred, evt.Id, evt.Cp, evt.Perfection.ToString("0.00"), evt.BestCp, evt.BestPerfection.ToString("0.00"), evt.FamilyCandies), LogLevel.Transfer); }
private static void Main() { Logger.SetLogger(new ConsoleLogger(LogLevel.Info)); var machine = new StateMachine(); var stats = new Statistics(); stats.DirtyEvent += () => Console.Title = stats.ToString(); var aggregator = new StatisticsAggregator(stats); var listener = new ConsoleEventListener(); machine.EventListener += listener.Listen; machine.EventListener += aggregator.Listen; machine.SetFailureState(new LoginState()); SettingsUtil.Load(); var context = new Context(new ClientSettings(), new LogicSettings()); context.Client.Login.GoogleDeviceCodeEvent += LoginWithGoogle; machine.AsyncStart(new VersionCheckState(), context); Console.ReadLine(); }
private static void Main(string[] args) { var subPath = ""; if (args.Length > 0) subPath = Path.DirectorySeparatorChar + args[0]; Logger.SetLogger(new ConsoleLogger(LogLevel.Info), subPath); GlobalSettings settings = GlobalSettings.Load(subPath); var machine = new StateMachine(); var stats = new Statistics(); stats.DirtyEvent += () => Console.Title = stats.ToString(); var aggregator = new StatisticsAggregator(stats); var listener = new ConsoleEventListener(); var websocket = new WebSocketInterface(settings.WebSocketPort); machine.EventListener += listener.Listen; machine.EventListener += aggregator.Listen; machine.EventListener += websocket.Listen; machine.SetFailureState(new LoginState()); var context = new Context(new ClientSettings(settings), new LogicSettings(settings)); context.Navigation.UpdatePositionEvent += (lat, lng) => machine.Fire(new UpdatePositionEvent { Latitude = lat, Longitude = lng }); context.Client.Login.GoogleDeviceCodeEvent += LoginWithGoogle; machine.AsyncStart(new VersionCheckState(), context); Console.ReadLine(); }
public async Task<IState> Execute(Context ctx, StateMachine machine) { if(ctx.LogicSettings.AmountOfPokemonToDisplayOnStart > 0) await LogBestPokemonTask.Execute(ctx,machine); return new PositionCheckState(); }
public static async Task Execute(Context ctx, StateMachine machine) { var pokemons = await ctx.Inventory.GetPokemons(); foreach (var pokemon in pokemons) { var perfection = Math.Round(PokemonInfo.CalculatePokemonPerfection(pokemon)); var pokemonName = pokemon.PokemonId.ToString(); if (pokemonName.Length > 10 - perfection.ToString().Length) { pokemonName = pokemonName.Substring(0, 10 - perfection.ToString().Length); } var newNickname = $"{pokemonName}_{perfection}"; if (perfection > ctx.LogicSettings.KeepMinIvPercentage && newNickname != pokemon.Nickname && ctx.LogicSettings.RenameAboveIv) { var result = await ctx.Client.Inventory.NicknamePokemon(pokemon.Id, newNickname); machine.Fire(new NoticeEvent { Message = $"Pokemon {pokemon.PokemonId} ({pokemon.Id}) renamed from {pokemon.Nickname} to {newNickname}." }); } else if (newNickname == pokemon.Nickname && !ctx.LogicSettings.RenameAboveIv) { var result = await ctx.Client.Inventory.NicknamePokemon(pokemon.Id, pokemon.PokemonId.ToString()); machine.Fire(new NoticeEvent { Message = $"Pokemon {pokemon.PokemonId} ({pokemon.Id}) renamed from {pokemon.Nickname} to {pokemon.PokemonId}." }); } } }
public static async Task Execute(Context ctx, StateMachine machine) { // Refresh inventory so that the player stats are fresh await ctx.Inventory.RefreshCachedInventory(); var playerStats = (await ctx.Inventory.GetPlayerStats()).FirstOrDefault(); if (playerStats == null) return; var kmWalked = playerStats.KmWalked; var incubators = (await ctx.Inventory.GetEggIncubators()) .Where(x => x.UsesRemaining > 0 || x.ItemId == ItemId.ItemIncubatorBasicUnlimited) .OrderByDescending(x => x.ItemId == ItemId.ItemIncubatorBasicUnlimited) .ToList(); var unusedEggs = (await ctx.Inventory.GetEggs()) .Where(x => string.IsNullOrEmpty(x.EggIncubatorId)) .OrderBy(x => x.EggKmWalkedTarget - x.EggKmWalkedStart) .ToList(); foreach (var incubator in incubators) { if (incubator.PokemonId == 0) { // Unlimited incubators prefer short eggs, limited incubators prefer long eggs var egg = incubator.ItemId == ItemId.ItemIncubatorBasicUnlimited ? unusedEggs.FirstOrDefault() : unusedEggs.LastOrDefault(); if (egg == null) continue; var response = await ctx.Client.Inventory.UseItemEggIncubator(incubator.Id, egg.Id); unusedEggs.Remove(egg); machine.Fire(new EggIncubatorStatusEvent { IncubatorId = incubator.Id, WasAddedNow = true, PokemonId = egg.Id, KmToWalk = egg.EggKmWalkedTarget, KmRemaining = response.EggIncubator.TargetKmWalked - kmWalked }); await Task.Delay(500); } else { machine.Fire(new EggIncubatorStatusEvent { IncubatorId = incubator.Id, PokemonId = incubator.PokemonId, KmToWalk = incubator.TargetKmWalked - incubator.StartKmWalked, KmRemaining = incubator.TargetKmWalked - kmWalked }); } } }
public static async Task Execute(Context ctx, StateMachine machine) { Logger.Write("Looking for incense pokemon..", LogLevel.Debug); var incensePokemon = await ctx.Client.Map.GetIncensePokemons(); if (incensePokemon.Result == GetIncensePokemonResponse.Types.Result.IncenseEncounterAvailable) { var pokemon = new MapPokemon { EncounterId = incensePokemon.EncounterId, ExpirationTimestampMs = incensePokemon.DisappearTimestampMs, Latitude = incensePokemon.Latitude, Longitude = incensePokemon.Longitude, PokemonId = (PokemonId) incensePokemon.PokemonTypeId, SpawnPointId = incensePokemon.EncounterLocation }; if (ctx.LogicSettings.UsePokemonToNotCatchFilter && ctx.LogicSettings.PokemonsNotToCatch.Contains(pokemon.PokemonId)) { Logger.Write("Skipped " + pokemon.PokemonId); } else { var distance = LocationUtils.CalculateDistanceInMeters(ctx.Client.CurrentLatitude, ctx.Client.CurrentLongitude, pokemon.Latitude, pokemon.Longitude); await Task.Delay(distance > 100 ? 3000 : 500); var encounter = await ctx.Client.Encounter.EncounterIncensePokemon((long) pokemon.EncounterId, pokemon.SpawnPointId); if (encounter.Result == IncenseEncounterResponse.Types.Result.IncenseEncounterSuccess) { await CatchPokemonTask.Execute(ctx, machine, encounter, pokemon); } else if (encounter.Result == IncenseEncounterResponse.Types.Result.PokemonInventoryFull) { if (ctx.LogicClient.Settings.TransferDuplicatePokemon) { machine.Fire(new WarnEvent {Message = "PokemonInventory is Full.Transferring pokemons..."}); await TransferDuplicatePokemonTask.Execute(ctx, machine); } else machine.Fire(new WarnEvent { Message = "PokemonInventory is Full.Please Transfer pokemon manually or set TransferDuplicatePokemon to true in settings..." }); } else { machine.Fire(new WarnEvent {Message = $"Encounter problem: {encounter.Result}"}); } } } }
public void HandleEvent(PokemonCaptureEvent evt, Context ctx) { if (evt.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess) { _stats.TotalExperience += evt.Exp; _stats.TotalPokemons++; _stats.TotalStardust = evt.Stardust; _stats.Dirty(ctx.Inventory); } }
public void Listen(IEvent evt, Context ctx) { dynamic eve = evt; try { HandleEvent(eve); } catch { } Broadcast(Serialize(eve)); }
private static async Task<IOrderedEnumerable<MapPokemon>> GetNearbyPokemons(Context ctx) { var mapObjects = await ctx.Client.Map.GetMapObjects(); var pokemons = mapObjects.MapCells.SelectMany(i => i.CatchablePokemons) .OrderBy( i => LocationUtils.CalculateDistanceInMeters(ctx.Client.CurrentLatitude, ctx.Client.CurrentLongitude, i.Latitude, i.Longitude)); return pokemons; }
public static async Task Execute(Context ctx, StateMachine machine) { Logger.Write("Looking for pokemon..", LogLevel.Debug); var pokemons = await GetNearbyPokemons(ctx); foreach (var pokemon in pokemons) { if (ctx.LogicSettings.UsePokemonToNotCatchFilter && ctx.LogicSettings.PokemonsNotToCatch.Contains(pokemon.PokemonId)) { Logger.Write("Skipped " + pokemon.PokemonId); continue; } var distance = LocationUtils.CalculateDistanceInMeters(ctx.Client.CurrentLatitude, ctx.Client.CurrentLongitude, pokemon.Latitude, pokemon.Longitude); await Task.Delay(distance > 100 ? 3000 : 500); var encounter = await ctx.Client.Encounter.EncounterPokemon(pokemon.EncounterId, pokemon.SpawnPointId); if (encounter.Status == EncounterResponse.Types.Status.EncounterSuccess) { await CatchPokemonTask.Execute(ctx, machine, encounter, pokemon); } else if (encounter.Status == EncounterResponse.Types.Status.PokemonInventoryFull) { if (ctx.LogicClient.Settings.TransferDuplicatePokemon) { machine.Fire(new WarnEvent {Message = "PokemonInventory is Full.Transferring pokemons..."}); await TransferDuplicatePokemonTask.Execute(ctx, machine); } else machine.Fire(new WarnEvent { Message = "PokemonInventory is Full.Please Transfer pokemon manually or set TransferDuplicatePokemon to true in settings..." }); } else { machine.Fire(new WarnEvent {Message = $"Encounter problem: {encounter.Status}"}); } // If pokemon is not last pokemon in list, create delay between catches, else keep moving. if (!Equals(pokemons.ElementAtOrDefault(pokemons.Count() - 1), pokemon)) { await Task.Delay(ctx.LogicSettings.DelayBetweenPokemonCatch); } } }
public IState Execute(Context ctx, StateMachine machine) { var coordsPath = Directory.GetCurrentDirectory() + "\\Configs\\Coords.ini"; if (File.Exists(coordsPath)) { var latLngFromFile = LoadPositionFromDisk(machine); if (latLngFromFile != null) { var distance = LocationUtils.CalculateDistanceInMeters(latLngFromFile.Item1, latLngFromFile.Item2, ctx.Settings.DefaultLatitude, ctx.Settings.DefaultLongitude); var lastModified = File.Exists(coordsPath) ? (DateTime?) File.GetLastWriteTime(coordsPath) : null; if (lastModified != null) { var hoursSinceModified = (DateTime.Now - lastModified).HasValue ? (double?) ((DateTime.Now - lastModified).Value.Minutes/60.0) : null; if (hoursSinceModified != null && hoursSinceModified != 0) { var kmph = distance/1000/(double) hoursSinceModified; if (kmph < 80) // If speed required to get to the default location is < 80km/hr { File.Delete(coordsPath); machine.Fire(new WarnEvent { Message = "Detected realistic Traveling , using UserSettings.settings" }); } else { machine.Fire(new WarnEvent { Message = "Not realistic Traveling at " + kmph + ", using last saved Coords.ini" }); } } } } } machine.Fire(new WarnEvent { Message = $"Make sure Lat & Lng are right. Exit Program if not! Lat: {ctx.Client.CurrentLatitude} Lng: {ctx.Client.CurrentLongitude}" }); machine.RequestDelay(3000); return new FarmState(); }
public async Task<IState> Execute(Context ctx, StateMachine machine) { var coordsPath = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "Configs" + Path.DirectorySeparatorChar + "Coords.ini"; if (File.Exists(coordsPath)) { var latLngFromFile = LoadPositionFromDisk(machine); if (latLngFromFile != null) { var distance = LocationUtils.CalculateDistanceInMeters(latLngFromFile.Item1, latLngFromFile.Item2, ctx.Settings.DefaultLatitude, ctx.Settings.DefaultLongitude); var lastModified = File.Exists(coordsPath) ? (DateTime?) File.GetLastWriteTime(coordsPath) : null; if (lastModified != null) { var hoursSinceModified = (DateTime.Now - lastModified).HasValue ? (double?) ((DateTime.Now - lastModified).Value.Minutes/60.0) : null; if (hoursSinceModified != null && hoursSinceModified != 0) { var kmph = distance/1000/(double) hoursSinceModified; if (kmph < 80) // If speed required to get to the default location is < 80km/hr { File.Delete(coordsPath); machine.Fire(new WarnEvent { Message = "Detected realistic Traveling , using UserSettings.settings" }); } else { machine.Fire(new WarnEvent { Message = "Not realistic Traveling at " + kmph + ", using last saved Coords.ini" }); } } } } } machine.Fire(new WarnEvent { Message = ctx.Translations.GetTranslation(TranslationString.WelcomeWarning, ctx.Client.CurrentLatitude, ctx.Client.CurrentLongitude) }); return new InfoState(); }
public static async Task Execute(Context ctx, StateMachine machine) { var items = await ctx.Inventory.GetItemsToRecycle(ctx.Settings); foreach (var item in items) { await ctx.Client.Inventory.RecycleItem(item.ItemId, item.Count); machine.Fire(new ItemRecycledEvent {Id = item.ItemId, Count = item.Count}); await Task.Delay(500); } await ctx.Inventory.RefreshCachedInventory(); }
public static void Execute(Context ctx, StateMachine machine) { var items = ctx.Inventory.GetItemsToRecycle(ctx.Settings).Result; foreach (var item in items) { ctx.Client.Inventory.RecycleItem(item.ItemId, item.Count).Wait(); machine.Fire(new ItemRecycledEvent {Id = item.ItemId, Count = item.Count}); Thread.Sleep(500); } ctx.Inventory.RefreshCachedInventory().Wait(); }
public async Task<IState> Execute(Context ctx, StateMachine machine) { await CleanupOldFiles(); var autoUpdate = ctx.LogicSettings.AutoUpdate; var needupdate = IsLatest(); if (!needupdate || !autoUpdate) { if (!needupdate) { machine.Fire(new UpdateEvent { Message = $"Perfect! You already have the newest Version {RemoteVersion}" }); return new LoginState(); } machine.Fire(new UpdateEvent { Message = $"AutoUpdater is disabled. Get the latest release from: {LatestRelease}\n " }); return new LoginState(); } machine.Fire(new UpdateEvent {Message = "Downloading and apply Update...."}); var remoteReleaseUrl = $"https://github.com/NecronomiconCoding/NecroBot/releases/download/v{RemoteVersion}/"; const string zipName = "Release.zip"; var downloadLink = remoteReleaseUrl + zipName; var baseDir = Directory.GetCurrentDirectory(); var downloadFilePath = Path.Combine(baseDir, zipName); var tempPath = Path.Combine(baseDir, "tmp"); var extractedDir = Path.Combine(tempPath, "Release"); var destinationDir = baseDir + Path.DirectorySeparatorChar; Console.WriteLine(downloadLink); if (!DownloadFile(downloadLink, downloadFilePath)) return new LoginState(); machine.Fire(new UpdateEvent {Message = "Finished downloading newest Release..."}); if (!UnpackFile(downloadFilePath, tempPath)) return new LoginState(); machine.Fire(new UpdateEvent {Message = "Finished unpacking files..."}); if (!MoveAllFiles(extractedDir, destinationDir)) return new LoginState(); machine.Fire(new UpdateEvent {Message = "Update finished, you can close this window now."}); Process.Start(Assembly.GetEntryAssembly().Location); Environment.Exit(-1); return null; }
public async Task Start(IState initialState, Context ctx) { _ctx = ctx; var state = initialState; do { try { state = await state.Execute(ctx, this); } catch (Exception ex) { Fire(new ErrorEvent {Message = ex.ToString()}); state = _initialState; } } while (state != null); }