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(); }
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(); } }
private void MainForm_Load(object sender, EventArgs e) { Text = @"RocketBot v" + Application.ProductVersion; //User activity tracking, help us get more information to make RocketBot better //Everything is anonymous Analytics.Initialize("UzL1tnZa9Yw2qcJWRIbcwGFmWGuovXez"); Analytics.Client.Identify(MachineIdHelper.GetMachineId(), new Traits()); Analytics.Client.Track(MachineIdHelper.GetMachineId(), "App started"); speedLable.Parent = gMapControl1; showMoreCheckBox.Parent = gMapControl1; followTrainerCheckBox.Parent = gMapControl1; togglePrecalRoute.Parent = gMapControl1; InitializeBot(); InitializePokemonForm(); InitializeMap(); CheckVersion(); if (BoolNeedsSetup) { //startStopBotToolStripMenuItem.Enabled = false; Logger.Write("First time here? Go to settings to set your basic info."); GlobalSettings.Load(""); } }
public void CheckVersion() { try { var match = new Regex( @"\[assembly\: AssemblyVersion\(""(\d{1,})\.(\d{1,})\.(\d{1,})\.(\d{1,})""\)\]") .Match(DownloadServerVersion()); if (!match.Success) { return; } var gitVersion = new Version( string.Format( "{0}.{1}.{2}.{3}", match.Groups[1], match.Groups[2], match.Groups[3], match.Groups[4])); // makes sense to display your version and say what the current one is on github Logger.Write("Your version is " + Application.ProductVersion); Logger.Write("Github version is " + gitVersion); Logger.Write("You can find it at www.GitHub.com/TheUnnameOrganization/RocketBot/releases"); } catch (Exception) { Logger.Write("Unable to check for updates now...", LogLevel.Error); } }
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(); } }
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 => Utils.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); }
private static void UnhandledExceptionEventHandler(object obj, UnhandledExceptionEventArgs args) { Logger.Write("Exception caught, writing LogBuffer.", force: true); throw new Exception(); }