コード例 #1
0
        private static async Task RecycleItems(ISession session, CancellationToken cancellationToken, int itemCount, ItemId item, int maxItemToKeep = 1000)
        {
            int itemsToRecycle = 0;
            int itemsToKeep    = itemCount - _diff;

            if (itemsToKeep < 0)
            {
                itemsToKeep = 0;
            }

            if (maxItemToKeep > 0)
            {
                itemsToKeep = Math.Min(itemsToKeep, maxItemToKeep);
            }
            itemsToRecycle = itemCount - itemsToKeep;
            if (itemsToRecycle > 0)
            {
                _diff -= itemsToRecycle;
                cancellationToken.ThrowIfCancellationRequested();
                TinyIoC.TinyIoCContainer.Current.Resolve <MultiAccountManager>().ThrowIfSwitchAccountRequested();
                await session.Client.Inventory.RecycleItem(item, itemsToRecycle).ConfigureAwait(false);

                await session.Inventory.UpdateInventoryItem(item).ConfigureAwait(false);

                if (session.LogicSettings.VerboseRecycling)
                {
                    session.EventDispatcher.Send(new ItemRecycledEvent {
                        Id = item, Count = itemsToRecycle
                    });
                }

                DelayingUtils.Delay(session.LogicSettings.RecycleActionDelay, 500);
            }
        }
コード例 #2
0
        public static async Task UseLuckyEgg(ISession session)
        {
            var inventoryContent = session.Inventory.GetItems();

            var luckyEggs = inventoryContent.Where(p => p.ItemId == ItemId.ItemLuckyEgg);
            var luckyEgg  = luckyEggs.FirstOrDefault();

            if (_lastLuckyEggTime.AddMinutes(30).Ticks > DateTime.Now.Ticks)
            {
                return;
            }

            _lastLuckyEggTime = DateTime.Now;
            var responseLuckyEgg = await session.Client.Inventory.UseItemXpBoost();

            if (responseLuckyEgg.Result == UseItemXpBoostResponse.Types.Result.Success)
            {
                if (luckyEgg != null)
                {
                    session.EventDispatcher.Send(new UseLuckyEggEvent {
                        Count = luckyEgg.Count - 1
                    });
                }
                TinyIoCContainer.Current.Resolve <MultiAccountManager>().DisableSwitchAccountUntil(DateTime.Now.AddMinutes(30));
            }
            DelayingUtils.Delay(session.LogicSettings.DelayBetweenPlayerActions, 0);
        }
コード例 #3
0
        public static async Task Execute(ISession session, ulong pokemonId)
        {
            using (var blocker = new BlockableScope(session, Model.BotActions.Envolve))
            {
                if (!await blocker.WaitToRun())
                {
                    return;
                }


                var all = await session.Inventory.GetPokemons();

                var pokemons = all.OrderByDescending(x => x.Cp).ThenBy(n => n.StaminaMax);
                var pokemon  = pokemons.FirstOrDefault(p => p.Id == pokemonId);

                if (pokemon == null)
                {
                    return;
                }

                var evolveResponse = await session.Client.Inventory.EvolvePokemon(pokemon.Id);

                session.EventDispatcher.Send(new PokemonEvolveEvent
                {
                    Id       = pokemon.PokemonId,
                    Exp      = evolveResponse.ExperienceAwarded,
                    UniqueId = pokemon.Id,
                    Result   = evolveResponse.Result
                });
                DelayingUtils.Delay(session.LogicSettings.EvolveActionDelay, 0);
            }
        }
コード例 #4
0
        private static async Task RemoveItems(int itemCount, ItemId item, CancellationToken cancellationToken, ISession session)
        {
            int itemsToRecycle = 0;
            int itemsToKeep    = itemCount - diff;

            if (itemsToKeep < 0)
            {
                itemsToKeep = 0;
            }
            itemsToRecycle = itemCount - itemsToKeep;

            if (itemsToRecycle != 0)
            {
                diff -= itemsToRecycle;
                cancellationToken.ThrowIfCancellationRequested();
                await session.Client.Inventory.RecycleItem(item, itemsToRecycle);

                session.EventDispatcher.Send(new ItemRecycledEvent {
                    Id = item, Count = itemsToRecycle
                });
                if (session.LogicSettings.Teleport)
                {
                    await Task.Delay(session.LogicSettings.DelayRecyleItem);
                }
                else
                {
                    await DelayingUtils.Delay(session.LogicSettings.DelayBetweenPlayerActions, 500);
                }
            }
        }
コード例 #5
0
        private static async Task RecycleItems(ISession session, CancellationToken cancellationToken, int itemCount, ItemId item, int maxItemToKeep = 1000)
        {
            int itemsToRecycle = 0;
            int itemsToKeep    = itemCount - _diff;

            if (itemsToKeep < 0)
            {
                itemsToKeep = 0;
            }

            if (maxItemToKeep > 0)
            {
                itemsToKeep = Math.Min(itemsToKeep, maxItemToKeep);
            }
            itemsToRecycle = itemCount - itemsToKeep;
            if (itemsToRecycle > 0)
            {
                _diff -= itemsToRecycle;
                cancellationToken.ThrowIfCancellationRequested();
                await session.Client.Inventory.RecycleItem(item, itemsToRecycle);

                if (session.LogicSettings.VerboseRecycling)
                {
                    session.EventDispatcher.Send(new ItemRecycledEvent {
                        Id = item, Count = itemsToRecycle
                    });
                }

                DelayingUtils.Delay(session.LogicSettings.RecycleActionDelay, 500);
            }
        }
コード例 #6
0
        //this task is duplicated, may need remove to clean up.
        public static async Task Execute(ISession session, ulong pokemonId)
        {
            using (var blocker = new BlockableScope(session, BotActions.Upgrade))
            {
                if (!await blocker.WaitToRun())
                {
                    return;
                }

                var all      = session.Inventory.GetPokemons();
                var pokemons = all.OrderByDescending(x => x.Cp).ThenBy(n => n.StaminaMax);
                var pokemon  = pokemons.FirstOrDefault(p => p.Id == pokemonId);

                if (pokemon == null)
                {
                    return;
                }

                var upgradeResult = await session.Inventory.UpgradePokemon(pokemon.Id);

                if (upgradeResult.Result.ToString().ToLower().Contains("success"))
                {
                    Logger.Write("Pokemon Upgraded:" + session.Translation.GetPokemonTranslation(upgradeResult.UpgradedPokemon.PokemonId) + ":" + upgradeResult.UpgradedPokemon.Cp, LogLevel.LevelUp);

                    session.EventDispatcher.Send(new PokemonLevelUpEvent
                    {
                        Id       = upgradeResult.UpgradedPokemon.PokemonId,
                        Cp       = upgradeResult.UpgradedPokemon.Cp,
                        UniqueId = pokemon.Id
                    });
                }
                DelayingUtils.Delay(session.LogicSettings.DelayBetweenPlayerActions, 0);
            }
        }
コード例 #7
0
        private static async Task RecycleItems(ISession session, CancellationToken cancellationToken, int itemCount, ItemId item)
        {
            int itemsToRecycle = 0;
            int itemsToKeep    = itemCount - Diff;

            if (itemsToKeep < 0)
            {
                itemsToKeep = 0;
            }
            itemsToRecycle = itemCount - itemsToKeep;
            if (itemsToRecycle != 0)
            {
                Diff -= itemsToRecycle;
                cancellationToken.ThrowIfCancellationRequested();
                await session.Client.Inventory.RecycleItem(item, itemsToRecycle);

                if (session.LogicSettings.VerboseRecycling)
                {
                    session.EventDispatcher.Send(new ItemRecycledEvent {
                        Id = item, Count = itemsToRecycle
                    });
                }
                DelayingUtils.Delay(session.LogicSettings.DelayBetweenPlayerActions, 500);
            }
        }
コード例 #8
0
        public async Task <bool> CatchFirstPokemon(ISession session)
        {
            var firstPokeList = new List <PokemonId>
            {
                PokemonId.Bulbasaur,
                PokemonId.Charmander,
                PokemonId.Squirtle
            };

            var firstpokeRnd = session.Client.Rnd.Next(0, 2);
            var firstPoke    = firstPokeList[firstpokeRnd];

            var res = await session.Client.Encounter.EncounterTutorialComplete(firstPoke);

            await DelayingUtils.Delay(7000, 2000);

            if (res.Result != EncounterTutorialCompleteResponse.Types.Result.Success)
            {
                return(false);
            }
            session.EventDispatcher.Send(new NoticeEvent()
            {
                Message = session.Translation.GetTranslation(TranslationString.TutorialPoke, session.Translation.GetPokemonName(firstPoke))
            });
            return(true);
        }
コード例 #9
0
        public static async Task Execute(ISession session, ulong pokemonId, CancellationToken cancellationToken)
        {
            if (!await CheckBotStateTask.Execute(session, cancellationToken))
            {
                return;
            }

            var prevState = session.State;

            session.State = BotState.Evolve;
            var all = await session.Inventory.GetPokemons();

            var pokemons = all.OrderByDescending(x => x.Cp).ThenBy(n => n.StaminaMax);
            var pokemon  = pokemons.FirstOrDefault(p => p.Id == pokemonId);

            if (pokemon == null)
            {
                return;
            }

            if (!string.IsNullOrEmpty(pokemon.DeployedFortId))
            {
                session.EventDispatcher.Send(new WarnEvent()
                {
                    Message = $"Pokemon {(string.IsNullOrEmpty(pokemon.Nickname) ? pokemon.PokemonId.ToString() : pokemon.Nickname)} is signed to defend a GYM!"
                });
                return;
            }

            var evolveResponse = await session.Client.Inventory.EvolvePokemon(pokemon.Id);

            session.EventDispatcher.Send(new PokemonEvolveEvent
            {
                Uid    = pokemon.Id,
                Id     = pokemon.PokemonId,
                Exp    = evolveResponse.ExperienceAwarded,
                Result = evolveResponse.Result
            });

            if (evolveResponse.EvolvedPokemonData != null)
            {
                var pokemonFamilies = await session.Inventory.GetPokemonFamilies();

                var pokemonSettings = (await session.Inventory.GetPokemonSettings()).ToList();
                var setting         = pokemonSettings.Single(q => q.PokemonId == evolveResponse.EvolvedPokemonData.PokemonId);
                var family          = pokemonFamilies.First(q => q.FamilyId == setting.FamilyId);
                session.EventDispatcher.Send(new PokemonEvolveDoneEvent
                {
                    Uid        = evolveResponse.EvolvedPokemonData.Id,
                    Id         = evolveResponse.EvolvedPokemonData.PokemonId,
                    Cp         = evolveResponse.EvolvedPokemonData.Cp,
                    Perfection = evolveResponse.EvolvedPokemonData.CalculatePokemonPerfection(),
                    Family     = family.FamilyId,
                    Candy      = family.Candy_
                });
            }
            await DelayingUtils.Delay(session.LogicSettings.DelayEvolvePokemon, 25000);

            session.State = prevState;
        }
コード例 #10
0
ファイル: PokemonListTask.cs プロジェクト: samfloKIT/NecroBot
        public static async Task Execute(ISession session)
        {
            // Refresh inventory so that the player stats are fresh
            //await session.Inventory.RefreshCachedInventory();

            var myPokemonSettings = await session.Inventory.GetPokemonSettings();

            var pokemonSettings = myPokemonSettings.ToList();

            var myPokemonFamilies = await session.Inventory.GetPokemonFamilies();

            var pokemonFamilies = myPokemonFamilies.ToArray();

            var allPokemonInBag = await session.Inventory.GetHighestsCp(1000);

            var pkmWithIv = allPokemonInBag.Select(p => {
                var settings = pokemonSettings.Single(x => x.PokemonId == p.PokemonId);
                return(Tuple.Create(
                           p,
                           PokemonInfo.CalculatePokemonPerfection(p),
                           pokemonFamilies.Single(x => settings.FamilyId == x.FamilyId).Candy_
                           ));
            });

            session.EventDispatcher.Send(
                new PokemonListEvent
            {
                PokemonList = pkmWithIv.ToList()
            });

            DelayingUtils.Delay(session.LogicSettings.DelayBetweenPlayerActions, 0);
        }
コード例 #11
0
        public async Task <bool> SelectNicnname(ISession session)
        {
            var res = await session.Client.Misc.ClaimCodename(session.LogicSettings.DesiredNickname);

            if (res.Status == ClaimCodenameResponse.Types.Status.SUCCESS)
            {
                session.EventDispatcher.Send(new NoticeEvent()
                {
                    Message = $"Your name is now: {res.Codename}"
                });
                await session.Client.Misc.MarkTutorialComplete(new RepeatedField <TutorialState>()
                {
                    TutorialState.NameSelection
                });
            }
            else if (res.Status == ClaimCodenameResponse.Types.Status.CODENAME_CHANGE_NOT_ALLOWED || res.Status == ClaimCodenameResponse.Types.Status.CURRENT_OWNER)
            {
                await session.Client.Misc.MarkTutorialComplete(new RepeatedField <TutorialState>()
                {
                    TutorialState.NameSelection
                });
            }
            else
            {
                session.EventDispatcher.Send(new NoticeEvent()
                {
                    Message = $"Name selection failed! Error: {res.Status}"
                });
            }
            await DelayingUtils.Delay(3000, 2000);

            return(res.Status == ClaimCodenameResponse.Types.Status.SUCCESS);
        }
コード例 #12
0
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var pokemons = await session.Inventory.GetPokemons();

            var pokemonDatas     = pokemons as IList <PokemonData> ?? pokemons.ToList();
            var pokemonsFiltered =
                pokemonDatas.Where(pokemon => !session.LogicSettings.PokemonsNotToTransfer.Contains(pokemon.PokemonId))
                .ToList().OrderBy(poke => poke.Cp);

            if (session.LogicSettings.KeepPokemonsThatCanEvolve)
            {
                pokemonsFiltered =
                    pokemonDatas.Where(pokemon => !session.LogicSettings.PokemonsToEvolve.Contains(pokemon.PokemonId))
                    .ToList().OrderBy(poke => poke.Cp);
            }

            var orderedPokemon = pokemonsFiltered.OrderBy(poke => poke.Cp);

            foreach (var pokemon in orderedPokemon)
            {
                cancellationToken.ThrowIfCancellationRequested();
                if ((pokemon.Cp >= session.LogicSettings.KeepMinCp) ||
                    (PokemonInfo.CalculatePokemonPerfection(pokemon) >= session.LogicSettings.KeepMinIvPercentage &&
                     session.LogicSettings.PrioritizeIvOverCp) ||
                    (PokemonInfo.GetLevel(pokemon) >= session.LogicSettings.KeepMinLvl &&
                     session.LogicSettings.UseKeepMinLvl) ||
                    pokemon.Favorite == 1)
                {
                    continue;
                }

                await session.Client.Inventory.TransferPokemon(pokemon.Id);

                await session.Inventory.DeletePokemonFromInvById(pokemon.Id);

                var bestPokemonOfType = (session.LogicSettings.PrioritizeIvOverCp
                    ? await session.Inventory.GetHighestPokemonOfTypeByIv(pokemon)
                    : await session.Inventory.GetHighestPokemonOfTypeByCp(pokemon)) ?? pokemon;

                var setting = session.Inventory.GetPokemonSettings()
                              .Result.Single(q => q.PokemonId == pokemon.PokemonId);
                var family = session.Inventory.GetPokemonFamilies().Result.First(q => q.FamilyId == setting.FamilyId);

                family.Candy_++;

                session.EventDispatcher.Send(new TransferPokemonEvent
                {
                    Id             = pokemon.PokemonId,
                    Perfection     = PokemonInfo.CalculatePokemonPerfection(pokemon),
                    Cp             = pokemon.Cp,
                    BestCp         = bestPokemonOfType.Cp,
                    BestPerfection = PokemonInfo.CalculatePokemonPerfection(bestPokemonOfType),
                    FamilyCandies  = family.Candy_
                });

                DelayingUtils.Delay(session.LogicSettings.DelayBetweenPlayerActions, 0);
            }
        }
コード例 #13
0
        public static async Task Execute(ISession session)
        {
            PlayerStats playerStats = await session.Inventory.GetPlayerStats(refreshCache : true);

            if (playerStats == null)
            {
                return;
            }

            var kmWalked = playerStats.KmWalked;

            var incubators = (await session.Inventory.GetEggIncubators())
                             .Where(x => x.UsesRemaining > 0 || x.ItemId == ItemId.ItemIncubatorBasicUnlimited)
                             .OrderByDescending(x => x.ItemId == ItemId.ItemIncubatorBasicUnlimited)
                             .ToList();

            var unusedEggs = (await session.Inventory.GetEggs())
                             .Where(x => string.IsNullOrEmpty(x.EggIncubatorId))
                             .OrderBy(x => x.EggKmWalkedTarget - x.EggKmWalkedStart)
                             .ToList();

            session.EventDispatcher.Send(
                new EggsListEvent
            {
                PlayerKmWalked = kmWalked,
                Incubators     = incubators,
                UnusedEggs     = unusedEggs
            });

            DelayingUtils.Delay(session.LogicSettings.DelayBetweenPlayerActions, 0);
        }
コード例 #14
0
        public static async Task UseLuckyEgg(ISession session)
        {
            var inventoryContent = await session.Inventory.GetItems().ConfigureAwait(false);

            var luckyEgg = inventoryContent.FirstOrDefault(p => p.ItemId == ItemId.ItemLuckyEgg);

            if (luckyEgg.Count == 0) // We tried to use egg but we don't have any more. Just return.
            {
                return;
            }

            if (_lastLuckyEggTime.AddMinutes(30).Ticks > DateTime.Now.Ticks)
            {
                return;
            }

            var responseLuckyEgg = await session.Client.Inventory.UseItemXpBoost().ConfigureAwait(false);

            if (responseLuckyEgg.Result == UseItemXpBoostResponse.Types.Result.Success)
            {
                _lastLuckyEggTime = DateTime.Now;

                // Get refreshed lucky egg so we have an accurate count.
                luckyEgg = inventoryContent.FirstOrDefault(p => p.ItemId == ItemId.ItemLuckyEgg);

                if (luckyEgg != null)
                {
                    session.EventDispatcher.Send(new UseLuckyEggEvent {
                        Count = luckyEgg.Count
                    });
                }
                TinyIoCContainer.Current.Resolve <MultiAccountManager>().DisableSwitchAccountUntil(DateTime.Now.AddMinutes(30));
            }
            DelayingUtils.Delay(session.LogicSettings.DelayBetweenPlayerActions, 0);
        }
コード例 #15
0
        public static async Task UseLuckyEgg(ISession session)
        {
            await session.Inventory.RefreshCachedInventory();

            var inventoryContent = await session.Inventory.GetItems();

            var luckyEggs = inventoryContent.Where(p => p.ItemId == ItemId.ItemLuckyEgg);
            var luckyEgg  = luckyEggs.FirstOrDefault();

            if (_lastLuckyEggTime.AddMinutes(30).Ticks > DateTime.Now.Ticks)
            {
                return;
            }

            _lastLuckyEggTime = DateTime.Now;
            await session.Client.Inventory.UseItemXpBoost();

            if (luckyEgg != null)
            {
                session.EventDispatcher.Send(new UseLuckyEggEvent {
                    Count = luckyEgg.Count - 1
                });
            }
            DelayingUtils.Delay(session.LogicSettings.DelayBetweenPlayerActions, 0);
        }
コード例 #16
0
        public async Task <GetInventoryResponse> RefreshCachedInventory(int retries = 0)
        {
            if (retries > 3)
            {
                return(null);
            }

            var now = DateTime.UtcNow;
            var ss  = new SemaphoreSlim(10);

            await ss.WaitAsync();

            try
            {
                _lastRefresh     = now;
                _cachedInventory = await _client.Inventory.GetInventory();

                return(_cachedInventory);
            }
            catch (NullReferenceException)
            {
                ss.Release();
                DelayingUtils.Delay(3000, 3000);
                return(await RefreshCachedInventory(++retries));
            }
            finally
            {
                ss.Release();
            }
        }
コード例 #17
0
ファイル: RecycleItemsTask.cs プロジェクト: niwa010222/emsin
        public static async Task DropItem(ISession session, ItemId item, int count)
        {
            using (var blocker = new BlockableScope(session, BotActions.RecycleItem))
            {
                if (!await blocker.WaitToRun())
                {
                    return;
                }

                if (count > 0)
                {
                    await session.Client.Inventory.RecycleItem(item, count);

                    await session.Inventory.UpdateInventoryItem(item, -count);

                    if (session.LogicSettings.VerboseRecycling)
                    {
                        session.EventDispatcher.Send(new ItemRecycledEvent {
                            Id = item, Count = count
                        });
                    }

                    DelayingUtils.Delay(session.LogicSettings.RecycleActionDelay, 500);
                }
            }
        }
コード例 #18
0
        public async Task <List <Candy> > GetPokemonFamilies(int retries = 0)
        {
            if (retries > 3)
            {
                return(null);
            }

            IEnumerable <Candy> families = null;
            var inventory = GetCachedInventory();

            try
            {
                families = from item in inventory
                           where item.InventoryItemData?.Candy != null
                           where item.InventoryItemData?.Candy.FamilyId != PokemonFamilyId.FamilyUnset
                           group item by item.InventoryItemData?.Candy.FamilyId
                           into family
                           select new Candy
                {
                    FamilyId = family.First().InventoryItemData.Candy.FamilyId,
                    Candy_   = family.First().InventoryItemData.Candy.Candy_
                };
            }
            catch (NullReferenceException)
            {
                DelayingUtils.Delay(3000, 3000);
                return(await GetPokemonFamilies(++retries));
            }

            return(families.ToList());
        }
コード例 #19
0
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            if (session.LogicSettings.AutoFavoritePokemon)
            {
                await FavoritePokemonTask.Execute(session, cancellationToken);
            }

            await session.Inventory.RefreshCachedInventory();

            var duplicatePokemons =
                await
                session.Inventory.GetDuplicatePokemonToTransfer(
                    session.LogicSettings.PokemonsNotToTransfer,
                    session.LogicSettings.PokemonsToEvolve,
                    session.LogicSettings.KeepPokemonsThatCanEvolve,
                    session.LogicSettings.PrioritizeIvOverCp);

            var orderedPokemon = duplicatePokemons.OrderBy(poke => poke.Cp);

            var pokemonSettings = await session.Inventory.GetPokemonSettings();

            var pokemonFamilies = await session.Inventory.GetPokemonFamilies();

            foreach (var duplicatePokemon in orderedPokemon)
            {
                cancellationToken.ThrowIfCancellationRequested();

                await session.Client.Inventory.TransferPokemon(duplicatePokemon.Id);

                await session.Inventory.DeletePokemonFromInvById(duplicatePokemon.Id);

                var bestPokemonOfType = (session.LogicSettings.PrioritizeIvOverCp
                    ? await session.Inventory.GetHighestPokemonOfTypeByIv(duplicatePokemon)
                    : await session.Inventory.GetHighestPokemonOfTypeByCp(duplicatePokemon)) ?? duplicatePokemon;

                var setting = pokemonSettings.SingleOrDefault(q => q.PokemonId == duplicatePokemon.PokemonId);
                var family  = pokemonFamilies.FirstOrDefault(q => q.FamilyId == setting.FamilyId);

                family.Candy_++;

                session.EventDispatcher.Send(new TransferPokemonEvent
                {
                    Id             = duplicatePokemon.PokemonId,
                    Perfection     = PokemonInfo.CalculatePokemonPerfection(duplicatePokemon),
                    Cp             = duplicatePokemon.Cp,
                    BestCp         = bestPokemonOfType.Cp,
                    BestPerfection = PokemonInfo.CalculatePokemonPerfection(bestPokemonOfType),
                    FamilyCandies  = family.Candy_
                });

                // Padding the TransferEvent with player-choosen delay before instead of after.
                // This is to remedy too quick transfers, often happening within a second of the
                // previous action otherwise

                DelayingUtils.Delay(session.LogicSettings.TransferActionDelay, 0);
            }
        }
コード例 #20
0
        //Please do not change GetPokeStops() in this file, it's specifically set
        //to only find stops within 40 meters
        //this is for gpx pathing, we are not going to the pokestops,
        //so do not make it more than 40 because it will never get close to those stops.
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var pokestopList = await GetPokeStops(session);

            while (pokestopList.Any())
            {
                cancellationToken.ThrowIfCancellationRequested();

                pokestopList =
                    pokestopList.OrderBy(
                        i =>
                        LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                session.Client.CurrentLongitude, i.Latitude, i.Longitude)).ToList();
                var pokeStop = pokestopList[0];
                pokestopList.RemoveAt(0);
                if (pokeStop.Used)
                {
                    break;
                }
                var fortInfo = await session.Client.Fort.GetFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude);

                await DelayingUtils.Delay(session.LogicSettings.DelayBetweenPlayerActions, 2000);

                var fortSearch =
                    await session.Client.Fort.SearchFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude);

                await DelayingUtils.Delay(session.LogicSettings.DelayPokestop, 5000);

                if (fortSearch.ExperienceAwarded > 0)
                {
                    session.Runtime.StopsHit++;
                    session.Runtime.PokestopsToCheckGym--;
                    session.EventDispatcher.Send(new FortUsedEvent
                    {
                        Id        = pokeStop.Id,
                        Name      = fortInfo.Name,
                        Exp       = fortSearch.ExperienceAwarded,
                        Gems      = fortSearch.GemsAwarded,
                        Items     = StringUtils.GetSummedFriendlyNameOfItemAwardList(fortSearch.ItemsAwarded),
                        Latitude  = pokeStop.Latitude,
                        Longitude = pokeStop.Longitude
                    });
                    session.MapCache.UsedPokestop(pokeStop, session);
                    session.EventDispatcher.Send(new InventoryNewItemsEvent()
                    {
                        Items = fortSearch.ItemsAwarded.ToItemList()
                    });
                }
                if (pokeStop.LureInfo != null)
                {//because we're all f*****g idiots for not catching this sooner
                    await CatchLurePokemonsTask.Execute(session, pokeStop.BaseFortData, cancellationToken);
                }
            }
        }
コード例 #21
0
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            //await session.Inventory.RefreshCachedInventory();

            var pokemons = await session.Inventory.GetPokemons();

            foreach (var pokemon in pokemons)
            {
                cancellationToken.ThrowIfCancellationRequested();

                var perfection  = Math.Round(PokemonInfo.CalculatePokemonPerfection(pokemon));
                var pokemonName = session.Translation.GetPokemonTranslation(pokemon.PokemonId);
                // iv number + templating part + pokemonName <= 12
                var nameLength = 12 -
                                 (perfection.ToString(CultureInfo.InvariantCulture).Length +
                                  session.LogicSettings.RenameTemplate.Length - 6);
                if (pokemonName.Length > nameLength)
                {
                    pokemonName = pokemonName.Substring(0, nameLength);
                }
                var newNickname = string.Format(session.LogicSettings.RenameTemplate, pokemonName, perfection);
                var oldNickname = pokemon.Nickname.Length != 0 ? pokemon.Nickname : pokemon.PokemonId.ToString();

                // If "RenameOnlyAboveIv" = true only rename pokemon with IV over "KeepMinIvPercentage"
                // Favorites will be skipped
                if ((!session.LogicSettings.RenameOnlyAboveIv ||
                     perfection >= session.LogicSettings.KeepMinIvPercentage) &&
                    newNickname != oldNickname)
                {
                    var result = await session.Client.Inventory.NicknamePokemon(pokemon.Id, newNickname);

                    if (result.Result == NicknamePokemonResponse.Types.Result.Success)
                    {
                        pokemon.Nickname = newNickname;
                        await session.Inventory.DeletePokemonFromInvById(pokemon.Id);

                        await session.Inventory.AddPokemonToCache(pokemon);

                        session.EventDispatcher.Send(new NoticeEvent
                        {
                            Message = session.Translation.GetTranslation(
                                TranslationString.PokemonRename,
                                session.Translation.GetPokemonTranslation(pokemon.PokemonId),
                                pokemon.Id,
                                oldNickname,
                                newNickname
                                )
                        });
                    }
                    //Delay only if the pokemon was really renamed!
                    DelayingUtils.Delay(session.LogicSettings.RenamePokemonActionDelay, 500);
                }
            }
        }
コード例 #22
0
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var duplicatePokemons =
                await
                session.Inventory.GetDuplicatePokemonToTransfer(session.LogicSettings.KeepPokemonsThatCanEvolve,
                                                                session.LogicSettings.PrioritizeIvOverCp,
                                                                session.LogicSettings.PokemonsNotToTransfer);

            var pokemonSettings = await session.Inventory.GetPokemonSettings();

            var pokemonFamilies = await session.Inventory.GetPokemonFamilies();

            foreach (var duplicatePokemon in duplicatePokemons)
            {
                cancellationToken.ThrowIfCancellationRequested();
                var pokemonTransferFilter = session.Inventory.GetPokemonTransferFilter(duplicatePokemon.PokemonId);

                if (duplicatePokemon.Cp >=
                    pokemonTransferFilter.KeepMinCp ||
                    PokemonInfo.CalculatePokemonPerfection(duplicatePokemon) >
                    pokemonTransferFilter.KeepMinIvPercentage ||
                    pokemonTransferFilter.Moves.Contains(duplicatePokemon.Move1) ||
                    pokemonTransferFilter.Moves.Contains(duplicatePokemon.Move2))
                {
                    continue;
                }

                await session.Client.Inventory.TransferPokemon(duplicatePokemon.Id);

                await session.Inventory.DeletePokemonFromInvById(duplicatePokemon.Id);

                var bestPokemonOfType = (session.LogicSettings.PrioritizeIvOverCp
                    ? await session.Inventory.GetHighestPokemonOfTypeByIv(duplicatePokemon)
                    : await session.Inventory.GetHighestPokemonOfTypeByCp(duplicatePokemon)) ?? duplicatePokemon;

                var setting = pokemonSettings.Single(q => q.PokemonId == duplicatePokemon.PokemonId);
                var family  = pokemonFamilies.First(q => q.FamilyId == setting.FamilyId);

                family.Candy_++;

                session.EventDispatcher.Send(new TransferPokemonEvent
                {
                    Id             = duplicatePokemon.PokemonId,
                    Perfection     = PokemonInfo.CalculatePokemonPerfection(duplicatePokemon),
                    Cp             = duplicatePokemon.Cp,
                    BestCp         = bestPokemonOfType.Cp,
                    BestPerfection = PokemonInfo.CalculatePokemonPerfection(bestPokemonOfType),
                    FamilyCandies  = family.Candy_
                });

                DelayingUtils.Delay(session.LogicSettings.DelayBetweenPlayerActions, 0);
            }
        }
コード例 #23
0
ファイル: StateMachine.cs プロジェクト: jabr212/Catchem-PoGo
        public async Task Start(IState initialState, Session session,
                                CancellationToken cancellationToken = default(CancellationToken))
        {
            var state = initialState;

            do
            {
                try
                {
                    state = await state.Execute(session, cancellationToken);
                }
                catch (InvalidResponseException ex)
                {
                    session.EventDispatcher.Send(new ErrorEvent
                    {
                        Message = session.Translation.GetTranslation(TranslationString.NianticServerUnstable)
                    });
                    if (session.Profile != null && session.Profile.Banned)
                    {
                        session.EventDispatcher.Send(new ErrorEvent
                        {
                            Message = session.Translation.GetTranslation(TranslationString.NianticPlayerBanned)
                        });
                    }
                    else if (session.Profile != null && session.Profile.Warn)
                    {
                        session.EventDispatcher.Send(new ErrorEvent
                        {
                            Message = session.Translation.GetTranslation(TranslationString.NianticPlayerWarn)
                        });
                    }
                    Logger.Write("[NIANTIC] " + ex.Message, LogLevel.Error);
                    state = _initialState;
                    await DelayingUtils.Delay(15000, 10000);
                }
                catch (OperationCanceledException)
                {
                    session.EventDispatcher.Send(new WarnEvent {
                        Message = session.Translation.GetTranslation(TranslationString.OperationCanceled)
                    });
                    break;
                }
                catch (Exception ex)
                {
                    session.EventDispatcher.Send(new ErrorEvent {
                        Message = ex.ToString()
                    });
                    state = _initialState;
                    await DelayingUtils.Delay(15000, 10000);
                }
            } while (state != null);
        }
コード例 #24
0
        public static async Task Execute(ISession session, ulong pokemonId)
        {
            using (var blocker = new BlockableScope(session, BotActions.Envolve))
            {
                if (!await blocker.WaitToRun())
                {
                    return;
                }


                var all = await session.Inventory.GetPokemons();

                var pokemons = all.OrderByDescending(x => x.Cp).ThenBy(n => n.StaminaMax);
                var pokemon  = pokemons.FirstOrDefault(p => p.Id == pokemonId);

                if (pokemon == null)
                {
                    return;
                }

                var pokemonSettings = await session.Inventory.GetPokemonSettings();

                var pokemonFamilies = await session.Inventory.GetPokemonFamilies();

                var setting = pokemonSettings.FirstOrDefault(q => pokemon != null && q.PokemonId == pokemon.PokemonId);
                var family  = pokemonFamilies.FirstOrDefault(q => setting != null && q.FamilyId == setting.FamilyId);

                if (setting.CandyToEvolve > family.Candy_)
                {
                    return;
                }
                family.Candy_ -= setting.CandyToEvolve;

                var evolveResponse = await session.Client.Inventory.EvolvePokemon(pokemon.Id);

                // Update setting after evolve.
                setting = pokemonSettings.FirstOrDefault(q => pokemon != null && q.PokemonId == evolveResponse.EvolvedPokemonData.PokemonId);

                session.EventDispatcher.Send(new PokemonEvolveEvent
                {
                    OriginalId     = pokemonId,
                    Id             = pokemon.PokemonId,
                    Exp            = evolveResponse.ExperienceAwarded,
                    UniqueId       = pokemon.Id,
                    Result         = evolveResponse.Result,
                    EvolvedPokemon = evolveResponse.EvolvedPokemonData,
                    PokemonSetting = setting,
                    Family         = family
                });
                DelayingUtils.Delay(session.LogicSettings.EvolveActionDelay, 0);
            }
        }
コード例 #25
0
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            await session.Inventory.RefreshCachedInventory();

            var duplicatePokemons =
                await
                session.Inventory.GetDuplicatePokemonToTransfer(
                    session.LogicSettings.PokemonsNotToTransfer,
                    session.LogicSettings.PokemonsToEvolve,
                    session.LogicSettings.KeepPokemonsThatCanEvolve,
                    session.LogicSettings.PrioritizeIvOverCp);

            var orderedPokemon = duplicatePokemons.OrderBy(poke => poke.Cp);

            var pokemonSettings = await session.Inventory.GetPokemonSettings();

            var pokemonFamilies = await session.Inventory.GetPokemonFamilies();

            foreach (var duplicatePokemon in orderedPokemon)
            {
                cancellationToken.ThrowIfCancellationRequested();

                await session.Client.Inventory.TransferPokemon(duplicatePokemon.Id);

                await session.Inventory.DeletePokemonFromInvById(duplicatePokemon.Id);

                var bestPokemonOfType = (session.LogicSettings.PrioritizeIvOverCp
                    ? await session.Inventory.GetHighestPokemonOfTypeByIv(duplicatePokemon)
                    : await session.Inventory.GetHighestPokemonOfTypeByCp(duplicatePokemon)) ?? duplicatePokemon;

                var setting = pokemonSettings.SingleOrDefault(q => q.PokemonId == duplicatePokemon.PokemonId);
                var family  = pokemonFamilies.FirstOrDefault(q => q.FamilyId == setting.FamilyId);

                family.Candy_++;

                session.EventDispatcher.Send(new TransferPokemonEvent
                {
                    Id             = duplicatePokemon.PokemonId,
                    Perfection     = PokemonInfo.CalculatePokemonPerfection(duplicatePokemon),
                    Cp             = duplicatePokemon.Cp,
                    BestCp         = bestPokemonOfType.Cp,
                    BestPerfection = PokemonInfo.CalculatePokemonPerfection(bestPokemonOfType),
                    FamilyCandies  = family.Candy_
                });

                DelayingUtils.Delay(session.LogicSettings.DelayBetweenPlayerActions, 0);
            }
        }
コード例 #26
0
        private async void transferMultiple(ulong[] ids)
        {
            foreach (ulong id in ids)
            {
                ReleasePokemonResponse rps = await this._session.Client.Inventory.TransferPokemon(id);

                Logger.Write($"Transfer result: {rps.Result} - Candies retrieved: {rps.CandyAwarded.ToString()} id: {id.ToString()}", LogLevel.Transfer);
                Logger.Write($"Transfer result: {rps.Result} - Candies retrieved: {rps.CandyAwarded.ToString()} id: {id.ToString()}");
                DelayingUtils.Delay(this._session.LogicSettings.DelayBetweenPlayerActions, 0);
            }
            await this.getPokemons();

            Logger.Write($"Transfer of {ids.Length} pokemons completed");
        }
コード例 #27
0
        private async void evolveMultiple(ulong[] ids)
        {
            foreach (ulong id in ids)
            {
                EvolvePokemonResponse eps = await this._session.Client.Inventory.EvolvePokemon(id);

                Logger.Write($"Evolve result: {eps.EvolvedPokemonData.PokemonId} CP: {eps.EvolvedPokemonData.Cp} XP: {eps.ExperienceAwarded.ToString()} id: {id.ToString()}", LogLevel.Evolve);
                Logger.Write($"Evolve result: {eps.EvolvedPokemonData.PokemonId} CP: {eps.EvolvedPokemonData.Cp} XP: {eps.ExperienceAwarded.ToString()} id: {id.ToString()}");
                DelayingUtils.Delay(this._session.LogicSettings.DelayBetweenPlayerActions, 0);
            }
            await this.getPokemons();

            Logger.Write($"Evolving of {ids.Length} pokemons completed");
        }
コード例 #28
0
        public static async Task Execute(ISession session, ulong pokemonId)
        {
            using (var blocker = new BlockableScope(session, Model.BotActions.Transfer))
            {
                if (!await blocker.WaitToRun())
                {
                    return;
                }

                var all = await session.Inventory.GetPokemons();

                var pokemons = all.OrderBy(x => x.Cp).ThenBy(n => n.StaminaMax);
                var pokemon  = pokemons.FirstOrDefault(p => p.Id == pokemonId);

                if (pokemon == null)
                {
                    return;
                }

                var pokemonSettings = await session.Inventory.GetPokemonSettings();

                var pokemonFamilies = await session.Inventory.GetPokemonFamilies();

                await session.Client.Inventory.TransferPokemon(pokemonId);

                await session.Inventory.DeletePokemonFromInvById(pokemonId);

                var bestPokemonOfType = (session.LogicSettings.PrioritizeIvOverCp
                    ? await session.Inventory.GetHighestPokemonOfTypeByIv(pokemon)
                    : await session.Inventory.GetHighestPokemonOfTypeByCp(pokemon)) ?? pokemon;

                var setting = pokemonSettings.Single(q => q.PokemonId == pokemon.PokemonId);
                var family  = pokemonFamilies.First(q => q.FamilyId == setting.FamilyId);

                family.Candy_++;

                // Broadcast event as everyone would benefit
                session.EventDispatcher.Send(new Logic.Event.TransferPokemonEvent
                {
                    Id             = pokemon.PokemonId,
                    Perfection     = Logic.PoGoUtils.PokemonInfo.CalculatePokemonPerfection(pokemon),
                    Cp             = pokemon.Cp,
                    BestCp         = bestPokemonOfType.Cp,
                    BestPerfection = Logic.PoGoUtils.PokemonInfo.CalculatePokemonPerfection(bestPokemonOfType),
                    FamilyCandies  = family.Candy_
                });

                DelayingUtils.Delay(session.LogicSettings.TransferActionDelay, 0);
            }
        }
コード例 #29
0
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            if (!await CheckBotStateTask.Execute(session, cancellationToken))
            {
                return;
            }
            var prevState = session.State;

            session.State = BotState.Renaming;

            var pokemons = await session.Inventory.GetPokemons();

            foreach (var pokemon in pokemons)
            {
                cancellationToken.ThrowIfCancellationRequested();

                var perfection  = Math.Round(pokemon.CalculatePokemonPerfection());
                var pokemonName = session.Translation.GetPokemonName(pokemon.PokemonId);
                // iv number + templating part + pokemonName <= 12
                var nameLength = 12 -
                                 (perfection.ToString(CultureInfo.InvariantCulture).Length +
                                  session.LogicSettings.RenameTemplate.Length - 6);
                if (pokemonName.Length > nameLength)
                {
                    pokemonName = pokemonName.Substring(0, nameLength);
                }
                var newNickname = string.Format(session.LogicSettings.RenameTemplate, pokemonName, perfection);
                var oldNickname = pokemon.Nickname.Length != 0 ? pokemon.Nickname : session.Translation.GetPokemonName(pokemon.PokemonId);

                // If "RenameOnlyAboveIv" = true only rename pokemon with IV over "KeepMinIvPercentage"
                // Favorites will be skipped
                if ((!session.LogicSettings.RenameOnlyAboveIv || perfection >= session.LogicSettings.KeepMinIvPercentage) &&
                    newNickname != oldNickname && pokemon.Favorite == 0)
                {
                    await session.Client.Inventory.NicknamePokemon(pokemon.Id, newNickname);

                    await DelayingUtils.Delay(session.LogicSettings.DelayBetweenPlayerActions, 2000);

                    session.EventDispatcher.Send(new NoticeEvent
                    {
                        Message =
                            session.Translation.GetTranslation(TranslationString.PokemonRename, session.Translation.GetPokemonName(pokemon.PokemonId),
                                                               pokemon.Id, oldNickname, newNickname)
                    });
                }
            }
            session.State = prevState;
        }
コード例 #30
0
ファイル: EvolvePokemonTask.cs プロジェクト: niwa010222/emsin
        private static async Task Evolve(ISession session, List <PokemonData> pokemonToEvolve)
        {
            var pokemonSettings = await session.Inventory.GetPokemonSettings();

            var pokemonFamilies = await session.Inventory.GetPokemonFamilies();

            int sequence = 1;

            foreach (var pokemon in pokemonToEvolve)
            {
                var setting =
                    pokemonSettings.FirstOrDefault(q => pokemon != null && q.PokemonId == pokemon.PokemonId);
                var family = pokemonFamilies.FirstOrDefault(q => setting != null && q.FamilyId == setting.FamilyId);

                if (family.Candy_ < setting.CandyToEvolve)
                {
                    continue;
                }
                // no cancellationToken.ThrowIfCancellationRequested here, otherwise the lucky egg would be wasted.
                var evolveResponse = await session.Client.Inventory.EvolvePokemon(pokemon.Id);

                if (evolveResponse.Result == EvolvePokemonResponse.Types.Result.Success)
                {
                    family.Candy_ -= setting.CandyToEvolve;
                    await session.Inventory.UpdateCandy(family, -setting.CandyToEvolve);

                    await session.Inventory.DeletePokemonFromInvById(pokemon.Id);

                    await session.Inventory.AddPokemonToCache(evolveResponse.EvolvedPokemonData);
                }


                session.EventDispatcher.Send(new PokemonEvolveEvent
                {
                    Id             = pokemon.PokemonId,
                    Exp            = evolveResponse.ExperienceAwarded,
                    UniqueId       = pokemon.Id,
                    Result         = evolveResponse.Result,
                    Sequence       = pokemonToEvolve.Count() == 1 ? 0 : sequence++,
                    Family         = family,
                    PokemonSetting = setting
                });

                if (!pokemonToEvolve.Last().Equals(pokemon))
                {
                    DelayingUtils.Delay(session.LogicSettings.EvolveActionDelay, 0);
                }
            }
        }