Ejemplo n.º 1
0
        public async void NicknamePokemon(IEnumerable <PokemonData> pokemons, string nickname)
        {
            SetState(false);
            var pokemonDatas = pokemons as IList <PokemonData> ?? pokemons.ToList();

            foreach (var pokemon in pokemonDatas)
            {
                var newName = new StringBuilder(nickname);
                newName.Replace("{Name}", Convert.ToString(pokemon.PokemonId));
                newName.Replace("{CP}", Convert.ToString(pokemon.Cp));
                newName.Replace("{IV}",
                                Convert.ToString(Math.Round(_session.Inventory.GetPerfect(pokemon)), CultureInfo.InvariantCulture));
                newName.Replace("{IA}", Convert.ToString(pokemon.IndividualAttack));
                newName.Replace("{ID}", Convert.ToString(pokemon.IndividualDefense));
                newName.Replace("{IS}", Convert.ToString(pokemon.IndividualStamina));
                if (nickname.Length > 12)
                {
                    Logger.Write($"\"{newName}\" is too long, please choose another name");
                    if (pokemonDatas.Count() == 1)
                    {
                        SetState(true);
                        return;
                    }
                    continue;
                }
                await RenameSpecificPokemonTask.Execute(_session, pokemon, nickname);
            }
            await ReloadPokemonList();
        }
Ejemplo n.º 2
0
 private async void olvPokemonList_ButtonClick(object sender, CellClickEventArgs e)
 {
     try
     {
         var pokemon = e.Model as PokemonObject;
         var cName   = olvPokemonList.AllColumns[e.ColumnIndex].AspectToStringFormat;
         if (cName.Equals("Transfer"))
         {
             // ReSharper disable once PossibleNullReferenceException
             TransferPokemon(new List <PokemonData> {
                 pokemon.PokemonData
             });
         }
         else if (cName.Equals("Power Up"))
         {
             // ReSharper disable once PossibleNullReferenceException
             PowerUpPokemon(new List <PokemonData> {
                 pokemon.PokemonData
             });
         }
         else if (cName.Equals("Evolve"))
         {
             // ReSharper disable once PossibleNullReferenceException
             EvolvePokemon(new List <PokemonData> {
                 pokemon.PokemonData
             });
         }
     }
     catch (Exception ex)
     {
         Logger.Write(ex.ToString(), LogLevel.Error);
         await ReloadPokemonList();
     }
 }
Ejemplo n.º 3
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            Text = @"NecroBot2 " + Application.ProductVersion;
            speedLable.Parent            = gMapControl1;
            showMoreCheckBox.Parent      = gMapControl1;
            followTrainerCheckBox.Parent = gMapControl1;
            togglePrecalRoute.Parent     = gMapControl1;

            InitializeBot();
            InitializePokemonForm();
            InitializeMap();
            VersionHelper.CheckVersion();
            showMoreCheckBox.Enabled = false;
            btnRefresh.Enabled       = false;
            if (BoolNeedsSetup)
            {
                startStopBotToolStripMenuItem.Text = "■ Exit";
                Logger.Write("First time here? Go to settings to set your basic info.", LogLevel.Error);
            }
            else
            {
                GlobalSettings.Load("");
            }
            if (VersionHelper.CheckKillSwitch())
            {
                startStopBotToolStripMenuItem.Text = "■ Exit";
            }
        }
Ejemplo n.º 4
0
        private async void ItemBox_ItemClick(object sender, EventArgs e)
        {
            var item = (ItemData)sender;

            using (var form = new ItemForm(item))
            {
                var result = form.ShowDialog();
                if (result != DialogResult.OK)
                {
                    return;
                }
                SetState(false);
                switch (item.ItemId)
                {
                case ItemId.ItemLuckyEgg:
                {
                    if (_session.Client == null)
                    {
                        Logger.Write($"Bot must be running first!", LogLevel.Warning);
                        SetState(true);
                        return;
                    }
                    await UseLuckyEggTask.Execute(_session);
                }
                break;

                case ItemId.ItemIncenseOrdinary:
                {
                    if (_session.Client == null)
                    {
                        Logger.Write($"Bot must be running first!", LogLevel.Error);
                        SetState(true);
                        return;
                    }
                    await UseIncenseTask.Execute(_session);
                }
                break;

                default:
                {
                    await
                    RecycleSpecificItemTask.Execute(_session, item.ItemId, decimal.ToInt32(form.numCount.Value));
                }
                break;
                }
                await ReloadPokemonList();
            }
        }
Ejemplo n.º 5
0
        private async Task ReloadPokemonList()
        {
            SetState(false);
            try
            {
                await _session.Inventory.RefreshCachedInventory();

                var itemTemplates = await _session.Client.Download.GetItemTemplates();

                var inventory = await _session.Inventory.GetCachedInventory();

                var profile = await _session.Client.Player.GetPlayer();

                var inventoryAppliedItems = await _session.Inventory.GetAppliedItems();

                var appliedItems =
                    inventoryAppliedItems.Where(aItems => aItems?.Item != null)
                    .SelectMany(aItems => aItems.Item)
                    .ToDictionary(item => item.ItemId, item => TimeHelper.FromUnixTimeUtc(item.ExpireMs));

                PokemonObject.Initilize(itemTemplates);

                var pokemons =
                    inventory.InventoryDelta.InventoryItems.Select(i => i?.InventoryItemData?.PokemonData)
                    .Where(p => p != null && p.PokemonId > 0)
                    .OrderByDescending(PokemonInfo.CalculatePokemonPerfection)
                    .ThenByDescending(key => key.Cp)
                    .OrderBy(key => key.PokemonId);
                _families = inventory.InventoryDelta.InventoryItems
                            .Select(i => i.InventoryItemData.Candy)
                            .Where(p => p != null && p.FamilyId > 0)
                            .OrderByDescending(p => p.FamilyId);

                var pokemonObjects = new List <PokemonObject>();
                foreach (var pokemon in pokemons)
                {
                    var pokemonObject = new PokemonObject(pokemon);
                    var family        = _families.First(i => (int)i.FamilyId <= (int)pokemon.PokemonId);
                    pokemonObject.Candy = family.Candy_;
                    pokemonObjects.Add(pokemonObject);
                }

                var prevTopItem = olvPokemonList.TopItemIndex;
                olvPokemonList.SetObjects(pokemonObjects);
                olvPokemonList.TopItemIndex = prevTopItem;

                var pokemoncount =
                    inventory.InventoryDelta.InventoryItems
                    .Select(i => i.InventoryItemData?.PokemonData)
                    .Count(p => p != null && p.PokemonId > 0);
                var eggcount =
                    inventory.InventoryDelta.InventoryItems
                    .Select(i => i.InventoryItemData?.PokemonData)
                    .Count(p => p != null && p.IsEgg);
                lblPokemonList.Text =
                    $"{pokemoncount + eggcount} / {profile.PlayerData.MaxPokemonStorage} ({pokemoncount} pokemon, {eggcount} eggs)";

                var items =
                    inventory.InventoryDelta.InventoryItems
                    .Select(i => i.InventoryItemData?.Item)
                    .Where(i => i != null)
                    .OrderBy(i => i.ItemId);
                var itemscount =
                    inventory.InventoryDelta.InventoryItems
                    .Select(i => i.InventoryItemData?.Item)
                    .Where(i => i != null)
                    .Sum(i => i.Count) + 1;

                flpItems.Controls.Clear();
                foreach (var item in items)
                {
                    var box = new ItemBox(item);
                    if (appliedItems.ContainsKey(item.ItemId))
                    {
                        box.expires = appliedItems[item.ItemId];
                    }
                    box.ItemClick += ItemBox_ItemClick;
                    flpItems.Controls.Add(box);
                }
                lblInventory.Text = itemscount + @" / " + profile.PlayerData.MaxItemStorage;
            }
            catch (ArgumentNullException)
            {
                Logger.Write("Please start the bot or wait until login is finished before loading Pokemon List",
                             LogLevel.Warning);
                SetState(true);
                return;
            }
            catch (Exception ex)
            {
                Logger.Write(ex.ToString(), LogLevel.Error);
            }
            SetState(true);
        }
Ejemplo n.º 6
0
 private static void UnhandledExceptionEventHandler(object obj, UnhandledExceptionEventArgs args)
 {
     Logger.Write("Exception caught, writing LogBuffer.", force: true);
     throw new Exception();
 }
Ejemplo n.º 7
0
        private void InitializeBot()
        {
            var strCulture = Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName;

            var culture = CultureInfo.CreateSpecificCulture("en");

            CultureInfo.DefaultThreadCurrentCulture = culture;
            Thread.CurrentThread.CurrentCulture     = culture;

            AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionEventHandler;

            _logger = new ConsoleLogger(LogLevel.LevelUp);
            Logger.SetLogger(_logger, subPath);

            var profilePath       = Path.Combine(Directory.GetCurrentDirectory(), subPath);
            var profileConfigPath = Path.Combine(profilePath, "config");
            var authFile          = Path.Combine(profileConfigPath, "auth.json");
            var configFile        = Path.Combine(profileConfigPath, "config.json");

            BoolNeedsSetup = false;

            if (File.Exists(configFile))
            {
                _settings = GlobalSettings.Load(subPath, true);
                _settings.Auth.Load(authFile);
            }
            else
            {
                _settings = new GlobalSettings
                {
                    ProfilePath             = profilePath,
                    ProfileConfigPath       = profileConfigPath,
                    GeneralConfigPath       = Path.Combine(Directory.GetCurrentDirectory(), "config"),
                    TranslationLanguageCode = strCulture
                };
                BoolNeedsSetup = true;
            }

            _session = new Session(new ClientSettings(_settings), new LogicSettings(_settings));

            _machine = new StateMachine();
            var stats = new Statistics();

            // var strVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(3); NOT USED ATM

            //Status bar
            stats.DirtyEvent +=
                () =>
                SetStatusText(stats.GetTemplatedStats(
                                  _session.Translation.GetTranslation(TranslationString.StatsTemplateString),
                                  _session.Translation.GetTranslation(TranslationString.StatsXpTemplateString)));

            var aggregator = new StatisticsAggregator(stats);
            var listener   = new ConsoleEventListener();

            _session.EventDispatcher.EventReceived += evt => listener.Listen(evt, _session);
            _session.EventDispatcher.EventReceived += evt => aggregator.Listen(evt, _session);

            if (_settings.UseWebsocket)
            {
                var websocket = new WebSocketInterface(_settings.WebSocketPort, _session);
                _session.EventDispatcher.EventReceived += evt => websocket.Listen(evt, _session);
            }

            _machine.SetFailureState(new LoginState());
            Logger.SetLoggerContext(_session);

            _session.Navigation.UpdatePositionEvent +=
                (lat, lng) => _session.EventDispatcher.Send(new UpdatePositionEvent {
                Latitude = lat, Longitude = lng
            });
            _session.Navigation.UpdatePositionEvent += Navigation_UpdatePositionEvent;

            RouteOptimizeUtil.RouteOptimizeEvent +=
                optimizedroute =>
                _session.EventDispatcher.Send(new OptimizeRouteEvent {
                OptimizedRoute = optimizedroute
            });
            RouteOptimizeUtil.RouteOptimizeEvent += InitializePokestopsAndRoute;

            Navigation.GetHumanizeRouteEvent +=
                (route, destination) =>
                _session.EventDispatcher.Send(new GetHumanizeRouteEvent {
                Route = route, Destination = destination
            });
            Navigation.GetHumanizeRouteEvent += UpdateMap;

            FarmPokestopsTask.LootPokestopEvent +=
                pokestop => _session.EventDispatcher.Send(new LootPokestopEvent {
                Pokestop = pokestop
            });
            FarmPokestopsTask.LootPokestopEvent += UpdateMap;

            CatchNearbyPokemonsTask.PokemonEncounterEvent +=
                mappokemons =>
                _session.EventDispatcher.Send(new PokemonsEncounterEvent {
                EncounterPokemons = mappokemons
            });
            CatchNearbyPokemonsTask.PokemonEncounterEvent += UpdateMap;

            CatchIncensePokemonsTask.PokemonEncounterEvent +=
                mappokemons =>
                _session.EventDispatcher.Send(new PokemonsEncounterEvent {
                EncounterPokemons = mappokemons
            });
            CatchIncensePokemonsTask.PokemonEncounterEvent += UpdateMap;
        }