From 859a1be3ed264a774555e0eedb944f7c91261878 Mon Sep 17 00:00:00 2001 From: jakubsuchybio Date: Sat, 24 Sep 2016 16:53:21 +0200 Subject: [PATCH 01/18] Refactor TeamColor Converter --- PokemonGo-UWP/Utils/Game/Converters.cs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/PokemonGo-UWP/Utils/Game/Converters.cs b/PokemonGo-UWP/Utils/Game/Converters.cs index 9b299ecba..21ae701a2 100644 --- a/PokemonGo-UWP/Utils/Game/Converters.cs +++ b/PokemonGo-UWP/Utils/Game/Converters.cs @@ -790,9 +790,26 @@ public class PlayerTeamToTeamColorBrushConverter : IValueConverter public object Convert(object value, Type targetType, object parameter, string language) { var teamColor = (TeamColor)value; - return new SolidColorBrush(teamColor == TeamColor.Neutral - ? Color.FromArgb(255, 26, 237, 213) - : teamColor == TeamColor.Blue ? Color.FromArgb(255, 40, 89, 237) : teamColor == TeamColor.Red ? Color.FromArgb(255, 237, 90, 90) : Color.FromArgb(255, 254, 196, 50)); + Color color; + switch (teamColor) + { + case TeamColor.Neutral: + color = Color.FromArgb(255, 26, 237, 213); + break; + case TeamColor.Blue: + color = Color.FromArgb(255, 40, 89, 237); + break; + case TeamColor.Red: + color = Color.FromArgb(255, 237, 90, 90); + break; + case TeamColor.Yellow: + color = Color.FromArgb(255, 254, 196, 50); + break; + default: + color = Color.FromArgb(255, 0, 0, 0); + break; + } + return new SolidColorBrush(color); } public object ConvertBack(object value, Type targetType, object parameter, string language) @@ -1949,7 +1966,7 @@ public object Convert(object value, Type targetType, object parameter, string la var res = ((size.Width - externalMargin) / minColumns) - internalMargin; //https://msdn.microsoft.com/en-us/windows/uwp/layout/design-and-ui-intro#effective-pixels-and-scaling - var width = ((int)res / 4) * 4; //round to 4 - win 10 optimized + var width = ((int)res / 4) * 4; //round to 4 - win 10 optimized return width; } From 9e300e9e07d99d44d8550c4018574fc67c2966d9 Mon Sep 17 00:00:00 2001 From: jakubsuchybio Date: Sat, 24 Sep 2016 17:14:38 +0200 Subject: [PATCH 02/18] Uncomment map not rendering gyms --- PokemonGo-UWP/Utils/GameClient.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PokemonGo-UWP/Utils/GameClient.cs b/PokemonGo-UWP/Utils/GameClient.cs index 65a319f73..36c2721be 100644 --- a/PokemonGo-UWP/Utils/GameClient.cs +++ b/PokemonGo-UWP/Utils/GameClient.cs @@ -724,7 +724,7 @@ private static async Task UpdateMapObjects() .ToArray(); Logger.Write($"Found {newGyms.Length} nearby Gyms"); // For now, we do not show the gyms on the map, as they are not complete yet. Code remains, so we can still work on it. - //NearbyGyms.UpdateWith(newGyms, x => new FortDataWrapper(x), (x, y) => x.Id == y.Id); + NearbyGyms.UpdateWith(newGyms, x => new FortDataWrapper(x), (x, y) => x.Id == y.Id); // Update LuredPokemon var newLuredPokemon = newPokeStops.Where(item => item.LureInfo != null).Select(item => new LuredPokemon(item.LureInfo, item.Latitude, item.Longitude)).ToArray(); From dd89f378494d22cbdef6196de4ba039d93388f5c Mon Sep 17 00:00:00 2001 From: jakubsuchybio Date: Sat, 24 Sep 2016 17:16:03 +0200 Subject: [PATCH 03/18] Reformat and untabify GameClient.cs --- PokemonGo-UWP/Utils/GameClient.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PokemonGo-UWP/Utils/GameClient.cs b/PokemonGo-UWP/Utils/GameClient.cs index 36c2721be..447b26a3c 100644 --- a/PokemonGo-UWP/Utils/GameClient.cs +++ b/PokemonGo-UWP/Utils/GameClient.cs @@ -1278,4 +1278,4 @@ public static async Task VerifyChallenge(string token) #endregion } -} +} \ No newline at end of file From c2c5c4436863b9851d4eff07aad8c9cf3c73f689 Mon Sep 17 00:00:00 2001 From: jakubsuchybio Date: Sat, 24 Sep 2016 17:23:29 +0200 Subject: [PATCH 04/18] Add missing handlers for gyms in GameClient --- PokemonGo-UWP/Utils/GameClient.cs | 53 +++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/PokemonGo-UWP/Utils/GameClient.cs b/PokemonGo-UWP/Utils/GameClient.cs index 447b26a3c..88a488d8a 100644 --- a/PokemonGo-UWP/Utils/GameClient.cs +++ b/PokemonGo-UWP/Utils/GameClient.cs @@ -1180,7 +1180,7 @@ public static async Task AddFortModifier(string pokesto #region Gym Handling /// - /// Gets the details for the given Gym + /// Gets the details for the given Gym /// /// /// @@ -1191,11 +1191,52 @@ public static async Task GetGymDetails(string gymid, doub return await _client.Fort.GetGymDetails(gymid, latitude, longitude); } - /// The following _client.Fort methods need implementation: - /// FortDeployPokemon - /// FortRecallPokemon - /// StartGymBattle - /// AttackGym + /// + /// Deploy Pokemon to stay in the gym for its defending + /// + /// + /// + /// + public static async Task FortDeployPokemon(string gymid, ulong pokemonId) + { + return await _client.Fort.FortDeployPokemon(gymid, pokemonId); + } + + /// + /// Recall pokemon from the battle in the gym + /// + /// + /// + /// + public static async Task FortRecallPokemon(string gymid, ulong pokemonId) + { + return await _client.Fort.FortRecallPokemon(gymid, pokemonId); + } + + /// + /// Start the Gym Battle + /// + /// + /// + /// + /// + public static async Task StartGymBattle(string gymid, ulong defendingPokemonId, IEnumerable attackingPokemonIds) + { + return await _client.Fort.StartGymBattle(gymid, defendingPokemonId, attackingPokemonIds); + } + + /// + /// Attacks the Gym (sends list of BattleAction to get processed in the fight) + /// + /// + /// + /// + /// + /// + public static async Task AttackGym(string gymid, string battleId, List battleActions, POGOProtos.Data.Battle.BattleAction lastRetrievedAction) + { + return await _client.Fort.AttackGym(gymid, battleId, battleActions, lastRetrievedAction); + } #endregion From e5129a95096e91574d72285f9959faa52d0518a6 Mon Sep 17 00:00:00 2001 From: jakubsuchybio Date: Sat, 24 Sep 2016 19:52:02 +0200 Subject: [PATCH 05/18] Add GymMembership data and wire few new properties for gym --- .../Controls/OutdoorBackground.xaml.cs | 2 +- PokemonGo-UWP/Entities/FortDataWrapper.cs | 56 ++++++++++++++- .../Entities/GymMembershipWrapper.cs | 60 ++++++++++++++++ PokemonGo-UWP/PokemonGo-UWP.csproj | 1 + .../ViewModels/EnterGymPageViewModel.cs | 44 +++++++----- PokemonGo-UWP/Views/EnterGymPage.xaml | 72 ++++++++----------- 6 files changed, 175 insertions(+), 60 deletions(-) create mode 100644 PokemonGo-UWP/Entities/GymMembershipWrapper.cs diff --git a/PokemonGo-UWP/Controls/OutdoorBackground.xaml.cs b/PokemonGo-UWP/Controls/OutdoorBackground.xaml.cs index ec75891fe..5bbb43bbf 100644 --- a/PokemonGo-UWP/Controls/OutdoorBackground.xaml.cs +++ b/PokemonGo-UWP/Controls/OutdoorBackground.xaml.cs @@ -36,8 +36,8 @@ public OutdoorBackground() DayPic.Visibility = Visibility.Collapsed; NightPic.Visibility = Visibility.Visible; } - } + private Windows.UI.Color ColorFromString(string hex) { hex = hex.Replace("#", string.Empty); diff --git a/PokemonGo-UWP/Entities/FortDataWrapper.cs b/PokemonGo-UWP/Entities/FortDataWrapper.cs index 3fab2ce18..38de84993 100644 --- a/PokemonGo-UWP/Entities/FortDataWrapper.cs +++ b/PokemonGo-UWP/Entities/FortDataWrapper.cs @@ -18,7 +18,7 @@ using POGOProtos.Inventory.Item; namespace PokemonGo_UWP.Entities -{ +{ public class FortDataWrapper : IUpdatable, INotifyPropertyChanged { [JsonProperty, JsonConverter(typeof(ProtobufJsonNetConverter))] @@ -134,6 +134,60 @@ public void UpdateCooldown(long newCooldownTimestampMs) public long GymPoints => _fortData.GymPoints; + public int GymMaxPoints + { + get + { + var gp = GymPoints; + if (gp < 2000) + return 2000; + else if (gp < 4000) + return 4000; + else if (gp < 8000) + return 8000; + else if (gp < 12000) + return 12000; + else if (gp < 16000) + return 16000; + else if (gp < 20000) + return 20000; + else if (gp < 30000) + return 30000; + else if (gp < 40000) + return 40000; + else + return 50000; + } + } + + public int GymLevel + { + get + { + var gp = GymPoints; + if (gp < 2000) + return 1; + else if (gp < 4000) + return 2; + else if (gp < 8000) + return 3; + else if (gp < 12000) + return 4; + else if (gp < 16000) + return 5; + else if (gp < 20000) + return 6; + else if (gp < 30000) + return 7; + else if (gp < 40000) + return 8; + else if (gp < 50000) + return 9; + else + return 10; + } + } + public string Id => _fortData.Id; public bool IsInBattle => _fortData.IsInBattle; diff --git a/PokemonGo-UWP/Entities/GymMembershipWrapper.cs b/PokemonGo-UWP/Entities/GymMembershipWrapper.cs new file mode 100644 index 000000000..bf21a16c0 --- /dev/null +++ b/PokemonGo-UWP/Entities/GymMembershipWrapper.cs @@ -0,0 +1,60 @@ +using System; +using System.ComponentModel; +using Windows.Devices.Geolocation; +using Windows.Foundation; +using Windows.Storage; +using Google.Protobuf; +using PokemonGo.RocketAPI.Extensions; +using PokemonGo_UWP.Utils; +using PokemonGo_UWP.Utils.Game; +using PokemonGo_UWP.Utils.Helpers; +using PokemonGo_UWP.Views; +using POGOProtos.Enums; +using POGOProtos.Map.Fort; +using Template10.Common; +using Template10.Mvvm; +using Google.Protobuf.Collections; +using Newtonsoft.Json; +using POGOProtos.Inventory.Item; +using POGOProtos.Data.Gym; +using POGOProtos.Data.Player; + +namespace PokemonGo_UWP.Entities +{ + public class GymMembershipWrapper : INotifyPropertyChanged + { + [JsonProperty, JsonConverter(typeof(ProtobufJsonNetConverter))] + private GymMembership _gymMembership; + private PokemonDataWrapper _pokemonData; + + public GymMembershipWrapper(GymMembership gymMembership) + { + _gymMembership = gymMembership; + _pokemonData = new PokemonDataWrapper(_gymMembership.PokemonData); + } + + #region Wrapped Properties + + public PokemonId PokemonId => _pokemonData.PokemonId; + public int PokemonCp => _pokemonData.Cp; + public string PokemonName => _pokemonData.Name; + + public string PlayerName => _gymMembership.TrainerPublicProfile.Name; + public int PlayerLevel => _gymMembership.TrainerPublicProfile.Level; + public PlayerAvatar PlayerAvatar => _gymMembership.TrainerPublicProfile.Avatar; + + #endregion + + + #region INotifyPropertyChanged + + public event PropertyChangedEventHandler PropertyChanged; + + protected virtual void OnPropertyChanged(string propertyName) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + + #endregion + } +} \ No newline at end of file diff --git a/PokemonGo-UWP/PokemonGo-UWP.csproj b/PokemonGo-UWP/PokemonGo-UWP.csproj index 7a70bc9ba..e72fbb68b 100644 --- a/PokemonGo-UWP/PokemonGo-UWP.csproj +++ b/PokemonGo-UWP/PokemonGo-UWP.csproj @@ -768,6 +768,7 @@ PoGoPivotHeader.xaml + diff --git a/PokemonGo-UWP/ViewModels/EnterGymPageViewModel.cs b/PokemonGo-UWP/ViewModels/EnterGymPageViewModel.cs index 835926352..fc0bafe4e 100644 --- a/PokemonGo-UWP/ViewModels/EnterGymPageViewModel.cs +++ b/PokemonGo-UWP/ViewModels/EnterGymPageViewModel.cs @@ -15,6 +15,7 @@ using Template10.Services.NavigationService; using Newtonsoft.Json; using Google.Protobuf; +using POGOProtos.Data.Gym; namespace PokemonGo_UWP.ViewModels { @@ -36,6 +37,7 @@ public override async Task OnNavigatedToAsync(object parameter, NavigationMode m // Recovering the state CurrentGym = JsonConvert.DeserializeObject((string)suspensionState[nameof(CurrentGym)]); CurrentGymInfo = JsonConvert.DeserializeObject((string)suspensionState[nameof(CurrentGymInfo)]); + CurrentMembers = GetCurrentMembers(CurrentGymInfo); CurrentEnterResponse = JsonConvert.DeserializeObject((string)suspensionState[nameof(CurrentEnterResponse)]); } else @@ -45,8 +47,8 @@ public override async Task OnNavigatedToAsync(object parameter, NavigationMode m CurrentGym = (FortDataWrapper)NavigationHelper.NavigationState[nameof(CurrentGym)]; NavigationHelper.NavigationState.Remove(nameof(CurrentGym)); Logger.Write($"Entering {CurrentGym.Id}"); - CurrentGymInfo = - await GameClient.GetGymDetails(CurrentGym.Id, CurrentGym.Latitude, CurrentGym.Longitude); + CurrentGymInfo = await GameClient.GetGymDetails(CurrentGym.Id, CurrentGym.Latitude, CurrentGym.Longitude); + CurrentMembers = GetCurrentMembers(CurrentGymInfo); Busy.SetBusy(false); } } @@ -88,11 +90,14 @@ public override async Task OnNavigatingFromAsync(NavigatingEventArgs args) /// private GetGymDetailsResponse _currentGymInfo; + private ObservableCollection _currentMembers; + /// /// Results of the current Gym enter /// private GetGymDetailsResponse _currentEnterResponse; + #endregion #region Bindable Game Vars @@ -124,6 +129,12 @@ public GetGymDetailsResponse CurrentEnterResponse set { Set(ref _currentEnterResponse, value); } } + public ObservableCollection CurrentMembers + { + get { return _currentMembers; } + set { Set(ref _currentMembers, value); } + } + #endregion #region Game Logic @@ -135,26 +146,24 @@ public GetGymDetailsResponse CurrentEnterResponse /// /// Going back to map page /// - public DelegateCommand ReturnToGameScreen => _returnToGameScreen ?? ( - _returnToGameScreen = - new DelegateCommand( - () => { NavigationService.Navigate(typeof(GameMapPage), GameMapNavigationModes.GymUpdate); }, - () => true) - ); + public DelegateCommand ReturnToGameScreen => + _returnToGameScreen ?? ( _returnToGameScreen = new DelegateCommand( () => + { + NavigationService.Navigate(typeof(GameMapPage), GameMapNavigationModes.GymUpdate); + },() => true)); private DelegateCommand _abandonGym; /// /// Going back to map page /// - public DelegateCommand AbandonGym => _abandonGym ?? ( - _abandonGym = new DelegateCommand(() => + public DelegateCommand AbandonGym => + _abandonGym ?? (_abandonGym = new DelegateCommand(() => { // Re-enable update timer GameClient.ToggleUpdateTimer(); NavigationService.GoBack(); - }, () => true) - ); + }, () => true)); #endregion @@ -180,18 +189,21 @@ public GetGymDetailsResponse CurrentEnterResponse #endregion + private ObservableCollection GetCurrentMembers(GetGymDetailsResponse currentGymInfo) => + new ObservableCollection( + currentGymInfo.GymState.Memberships.Select(m => new GymMembershipWrapper(m))); + private DelegateCommand _enterCurrentGym; /// /// Enters the current Gym, don't know what to do then /// - public DelegateCommand EnterCurrentGym => _enterCurrentGym ?? ( - _enterCurrentGym = new DelegateCommand(async () => + public DelegateCommand EnterCurrentGym => + _enterCurrentGym ?? ( _enterCurrentGym = new DelegateCommand(async () => { Busy.SetBusy(true, "Entering Gym"); Logger.Write($"Entering {CurrentGymInfo.Name} [ID = {CurrentGym.Id}]"); - CurrentEnterResponse = - await GameClient.GetGymDetails(CurrentGym.Id, CurrentGym.Latitude, CurrentGym.Longitude); + CurrentEnterResponse = await GameClient.GetGymDetails(CurrentGym.Id, CurrentGym.Latitude, CurrentGym.Longitude); Busy.SetBusy(false); switch (CurrentEnterResponse.Result) { diff --git a/PokemonGo-UWP/Views/EnterGymPage.xaml b/PokemonGo-UWP/Views/EnterGymPage.xaml index 5c99b358e..1ac004e2d 100644 --- a/PokemonGo-UWP/Views/EnterGymPage.xaml +++ b/PokemonGo-UWP/Views/EnterGymPage.xaml @@ -1,4 +1,4 @@ - - - + - @@ -48,22 +47,15 @@ - - - @@ -78,16 +70,16 @@ - - @@ -100,7 +92,7 @@ - @@ -108,14 +100,12 @@ - - - - - + + @@ -132,8 +122,8 @@ - @@ -141,9 +131,7 @@ Foreground="{Binding CurrentGym.OwnedByTeam, Converter={StaticResource PlayerTeamToTeamColorBrushConverter}}"> - - - + @@ -152,10 +140,10 @@ - + - + @@ -164,23 +152,23 @@ - - - - + Visibility="{Binding IsEnabled, Converter={StaticResource NegateBooleanToVisibilityConverter}}"> - + Visibility="{Binding NotInRange, Converter={StaticResource BooleanToVisibilityConverter}}" /> + FontSize="12" Foreground="White" Margin="8,4,8,4" + Text="Not yet level five." + Visibility="{Binding NotLvl5Yet, Converter={StaticResource BooleanToVisibilityConverter}}" /> diff --git a/PokemonGo-UWP/Views/EnterGymPage.xaml.cs b/PokemonGo-UWP/Views/EnterGymPage.xaml.cs index 0a6ca005c..60e96778f 100644 --- a/PokemonGo-UWP/Views/EnterGymPage.xaml.cs +++ b/PokemonGo-UWP/Views/EnterGymPage.xaml.cs @@ -26,39 +26,12 @@ public EnterGymPage() protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); - SubscribeToEnterEvents(); } protected override void OnNavigatingFrom(NavigatingCancelEventArgs e) { base.OnNavigatingFrom(e); - UnsubscribeToEnterEvents(); - } - - #endregion - - #region Handlers - - private void SubscribeToEnterEvents() - { - ViewModel.EnterOutOfRange += GameManagerViewModelOnEnterOutOfRange; - ViewModel.EnterSuccess += GameManagerViewModelOnEnterSuccess; - } - - private void UnsubscribeToEnterEvents() - { - ViewModel.EnterOutOfRange -= GameManagerViewModelOnEnterOutOfRange; - ViewModel.EnterSuccess -= GameManagerViewModelOnEnterSuccess; - } - - private void GameManagerViewModelOnEnterOutOfRange(object sender, EventArgs eventArgs) - { - OutOfRangeTextBlock.Visibility = ErrorMessageBorder.Visibility = Visibility.Visible; - } - - private void GameManagerViewModelOnEnterSuccess(object sender, EventArgs eventArgs) - { } #endregion From 9f90ef6b4e6e697a8bfe8d4bf751c18213e23007 Mon Sep 17 00:00:00 2001 From: jakubsuchybio Date: Mon, 26 Sep 2016 01:43:24 +0200 Subject: [PATCH 07/18] Preparation for PlayerTeamSelect --- PokemonGo-UWP/ViewModels/EnterGymPageViewModel.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/PokemonGo-UWP/ViewModels/EnterGymPageViewModel.cs b/PokemonGo-UWP/ViewModels/EnterGymPageViewModel.cs index 1d29e8b26..ac7f6bc9d 100644 --- a/PokemonGo-UWP/ViewModels/EnterGymPageViewModel.cs +++ b/PokemonGo-UWP/ViewModels/EnterGymPageViewModel.cs @@ -56,6 +56,8 @@ public override async Task OnNavigatedToAsync(object parameter, NavigationMode m NavigationHelper.NavigationState.Remove(nameof(CurrentGym)); await CalculateGymData(CurrentGym); + + await CheckPlayerTeamSelection(); } } @@ -230,8 +232,18 @@ private void UpdateBindableData() StartBattle.RaiseCanExecuteChanged(); } - private DelegateCommand _deployPokemon; + private void CheckPlayerTeamSelection() + { + if(GameClient.PlayerStats.Level >= 5 && GameClient.PlayerProfile.Team == TeamColor.Neutral) + { + // TODO Modal dialog with teams and selection + // TODO modal dialog with confirmation + } + } + + + private DelegateCommand _deployPokemon; public DelegateCommand DeployPokemon => _deployPokemon ?? (_deployPokemon = new DelegateCommand( async() => { @@ -282,7 +294,6 @@ private void UpdateBindableData() private DelegateCommand _startBattle; - public DelegateCommand StartBattle => _startBattle ?? (_startBattle = new DelegateCommand(async () => { From 3243bb60166c57e73a3dcd557bb82731c17bd22f Mon Sep 17 00:00:00 2001 From: jakubsuchybio Date: Mon, 26 Sep 2016 03:35:32 +0200 Subject: [PATCH 08/18] Wire up SetPlayerTeam --- PokemonGo-UWP/App.xaml | 1 - .../MessageDialog/PoGoTeamSelectDialog.xaml | 168 ++++++++++++ .../PoGoTeamSelectDialog.xaml.cs | 251 ++++++++++++++++++ PokemonGo-UWP/PokemonGo-UWP.csproj | 7 + PokemonGo-UWP/Utils/Game/Converters.cs | 9 +- PokemonGo-UWP/Utils/GameClient.cs | 9 + .../ViewModels/EnterGymPageViewModel.cs | 67 ++++- 7 files changed, 494 insertions(+), 18 deletions(-) create mode 100644 PokemonGo-UWP/Controls/MessageDialog/PoGoTeamSelectDialog.xaml create mode 100644 PokemonGo-UWP/Controls/MessageDialog/PoGoTeamSelectDialog.xaml.cs diff --git a/PokemonGo-UWP/App.xaml b/PokemonGo-UWP/App.xaml index da2cd3e66..d4baecfe4 100644 --- a/PokemonGo-UWP/App.xaml +++ b/PokemonGo-UWP/App.xaml @@ -93,7 +93,6 @@ - diff --git a/PokemonGo-UWP/Controls/MessageDialog/PoGoTeamSelectDialog.xaml b/PokemonGo-UWP/Controls/MessageDialog/PoGoTeamSelectDialog.xaml new file mode 100644 index 000000000..9173bfb31 --- /dev/null +++ b/PokemonGo-UWP/Controls/MessageDialog/PoGoTeamSelectDialog.xaml @@ -0,0 +1,168 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +