private void InitBot(GlobalSettings settings, string profileName = "Unknown") { try { var newBot = CreateBowWindowData(settings, profileName); var session = new Session(newBot.Settings, newBot.Logic); session.Client.ApiFailure = new ApiFailureStrategy(session); newBot.GlobalSettings.MapzenAPI.SetSession(session); newBot.Session = session; session.EventDispatcher.EventReceived += evt => newBot.Listener.Listen(evt, session); session.EventDispatcher.EventReceived += evt => newBot.Aggregator.Listen(evt, session); session.Navigation.UpdatePositionEvent += (lat, lng, alt) => session.EventDispatcher.Send(new UpdatePositionEvent { Latitude = lat, Longitude = lng, Altitude = alt }); newBot.PokemonList.CollectionChanged += delegate { UpdatePokemonCollection(session); }; newBot.Stats.DirtyEvent += () => { StatsOnDirtyEvent(newBot); }; newBot._lat = settings.LocationSettings.DefaultLatitude; newBot._lng = settings.LocationSettings.DefaultLongitude; newBot.Machine.SetFailureState(new LoginState()); GlobalMapView.addMarker(newBot.GlobalPlayerMarker); BotsCollection.Add(newBot); } catch (Exception ex) { MessageBox.Show("Initializing of new bot failed! ex:\r\n" + ex.Message, "FatalError", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void InitBot(GlobalSettings settings, string profileName = "Unknown") { try { var newBot = CreateBowWindowData(settings, profileName); var session = new Session(newBot.Settings, newBot.Logic); session.Client.ApiFailure = new ApiFailureStrategy(session); newBot.GlobalSettings.MapzenAPI.SetSession(session); newBot.Session = session; session.EventDispatcher.EventReceived += evt => _listener.Listen(evt, session); session.EventDispatcher.EventReceived += evt => _statisticsAggregator.Listen(evt, session); session.Navigation.UpdatePositionEvent += (lat, lng, alt) => session.EventDispatcher.Send(new UpdatePositionEvent { Latitude = lat, Longitude = lng, Altitude = alt }); newBot.PokemonList.CollectionChanged += delegate { UpdatePokemonCollection(session); }; newBot.ItemList.CollectionChanged += delegate { UpdateItemCollection(session); }; session.Stats.DirtyEvent += () => { StatsOnDirtyEvent(newBot); }; newBot._lat = settings.LocationSettings.DefaultLatitude; newBot._lng = settings.LocationSettings.DefaultLongitude; newBot.Machine.SetFailureState(new LoginState()); GlobalMapView.addMarker(newBot.GlobalPlayerMarker); if (newBot.Logic.UseCustomRoute) { if (!IsNullOrEmpty(newBot.GlobalSettings.LocationSettings.CustomRouteName)) { var route = GlobalCatchemSettings.Routes.FirstOrDefault( x => string.Equals(x.Name, newBot.GlobalSettings.LocationSettings.CustomRouteName, StringComparison.CurrentCultureIgnoreCase)); if (route != null) { newBot.GlobalSettings.LocationSettings.CustomRoute = route.Route; } } } else if (!IsNullOrEmpty(newBot.GlobalSettings.LocationSettings.CustomRouteName)) { newBot.GlobalSettings.LocationSettings.CustomRouteName = ""; } #if DEBUG SeedTheBot(newBot); #endif BotsCollection.Add(newBot); if (newBot.GlobalSettings.AutoStartThisProfile) { newBot.Start(); } } catch (Exception ex) { MessageBox.Show("Initializing of new bot failed! ex:\r\n" + ex.Message, "FatalError", MessageBoxButton.OK, MessageBoxImage.Error); } }