Пример #1
0
        private async void GameManagerViewModelOnCatchEscape(object sender, EventArgs eventArgs)
        {
            //CatchEscape.Begin();
            //CatchSuccess.SkipToFill();
            CatchSuccess.AutoReverse = true;
            PokeballCatchAnimationStartingTranslateX.Value = PokeballTransform.TranslateX;
            PokeballCatchAnimationStartingTranslateY.Value = PokeballTransform.TranslateY;
            PokeballCatchAnimationStartingScaleX.Value     = PokeballTransform.ScaleX;
            PokeballCatchAnimationStartingScaleY.Value     = PokeballTransform.ScaleY;
            await Task.Delay(TimeSpan.FromSeconds(new Random().Next(1, 5)));

            CatchSuccess.Begin();
            CatchEscape.Begin();
            //TODO (from advancedrei): This storyboard needs to delay 3 seconds, then reverse the animation so the user can try again.
        }
Пример #2
0
        /// <summary>
        ///     Launches the PokeBall for the current encounter, handling the different catch responses
        /// </summary>
        /// <returns></returns>
        private async Task ThrowPokeball(bool hitPokemon)
        {
            var caughtPokemonResponse =
                await
                GameClient.CatchPokemon(CurrentPokemon.EncounterId, CurrentPokemon.SpawnpointId, SelectedCaptureItem.ItemId, hitPokemon);

            switch (caughtPokemonResponse.Status)
            {
            case CatchPokemonResponse.Types.CatchStatus.CatchError:
                Logger.Write("CatchError!");
                // TODO: what can we do?
                break;

            case CatchPokemonResponse.Types.CatchStatus.CatchSuccess:
                CurrentCaptureAward = caughtPokemonResponse.CaptureAward;
                Logger.Write($"We caught {CurrentPokemon.PokemonId}");
                CatchSuccess?.Invoke(this, null);
                await GameClient.UpdateInventory();

                break;

            case CatchPokemonResponse.Types.CatchStatus.CatchEscape:
                Logger.Write($"{CurrentPokemon.PokemonId} escaped");
                CatchEscape?.Invoke(this, null);
                await GameClient.UpdateInventory();

                break;

            case CatchPokemonResponse.Types.CatchStatus.CatchFlee:
                Logger.Write($"{CurrentPokemon.PokemonId} fleed");
                CatchFlee?.Invoke(this, null);
                await new MessageDialog($"{CurrentPokemon.PokemonId} fleed").ShowAsyncQueue();
                await GameClient.UpdateInventory();

                ReturnToGameScreen.Execute();
                break;

            case CatchPokemonResponse.Types.CatchStatus.CatchMissed:
                Logger.Write($"We missed {CurrentPokemon.PokemonId}");
                await GameClient.UpdateInventory();

                CatchFlee?.Invoke(this, null);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        /// <summary>
        ///     Launches the PokeBall for the current encounter, handling the different catch responses
        /// </summary>
        /// <returns></returns>
        private async Task ThrowPokeball(bool hitPokemon)
        {
            var caughtPokemonResponse =
                await GameClient.CatchPokemon(CurrentPokemon.EncounterId, CurrentPokemon.SpawnpointId,
                                              SelectedCaptureItem.ItemId, hitPokemon);

            var nearbyPokemon = GameClient.NearbyPokemons.FirstOrDefault(pokemon => pokemon.EncounterId == CurrentPokemon.EncounterId);

            switch (caughtPokemonResponse.Status)
            {
            case CatchPokemonResponse.Types.CatchStatus.CatchError:
                Logger.Write("CatchError!");
                // TODO: what can we do?
                break;

            case CatchPokemonResponse.Types.CatchStatus.CatchSuccess:
                Logger.Write($"We caught {CurrentPokemon.PokemonId}");
                CurrentCaptureAward = caughtPokemonResponse.CaptureAward;
                CatchSuccess?.Invoke(this, null);
                GameClient.CatchablePokemons.Remove(CurrentPokemon);
                GameClient.NearbyPokemons.Remove(nearbyPokemon);
                break;

            case CatchPokemonResponse.Types.CatchStatus.CatchEscape:
                Logger.Write($"{CurrentPokemon.PokemonId} escaped");
                CatchEscape?.Invoke(this, null);
                break;

            case CatchPokemonResponse.Types.CatchStatus.CatchFlee:
                Logger.Write($"{CurrentPokemon.PokemonId} fled");
                CatchFlee?.Invoke(this, null);
                GameClient.CatchablePokemons.Remove(CurrentPokemon);
                GameClient.NearbyPokemons.Remove(nearbyPokemon);
                // We just go back because there's nothing else to do
                await GameClient.ToggleUpdateTimer();

                break;

            case CatchPokemonResponse.Types.CatchStatus.CatchMissed:
                Logger.Write($"We missed {CurrentPokemon.PokemonId}");
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            // We always need to update the inventory
            await GameClient.UpdateInventory();
        }
Пример #4
0
        /// <summary>
        ///     Launches the PokeBall for the current encounter, handling the different catch responses
        /// </summary>
        /// <returns></returns>
        private async Task <bool> ThrowPokeball(bool hitPokemon)
        {
            // We use to simulate a 5 second wait to get animation going
            // If server takes too much to reply then we don't use the delay
            var requestTime = DateTime.Now;

            var caughtPokemonResponse = await GameClient.CatchPokemon(CurrentPokemon.EncounterId, CurrentPokemon.SpawnpointId, SelectedCaptureItem.ItemId, hitPokemon);

            await GameClient.UpdateInventory();                                                  //TODO: Change to delta update inventory, so it doesn't take so long (and offico client does it too)

            SelectedCaptureItem = SelectPokeballType(LastItemUsed) ?? SelectAvailablePokeBall(); //To restore it after UpdateInventory, which overrides it

            var responseDelay = DateTime.Now - requestTime;

            if (responseDelay.TotalSeconds < 5 && hitPokemon)
            {
                await Task.Delay(TimeSpan.FromSeconds(5 - (int)responseDelay.TotalSeconds));
            }
            var nearbyPokemon = GameClient.NearbyPokemons.FirstOrDefault(pokemon => pokemon.EncounterId == CurrentPokemon.EncounterId);

            switch (caughtPokemonResponse.Status)
            {
            case CatchPokemonResponse.Types.CatchStatus.CatchError:
                Logger.Write("CatchError!");
                // TODO: what can we do?
                break;

            case CatchPokemonResponse.Types.CatchStatus.CatchSuccess:
                Logger.Write($"We caught {CurrentPokemon.PokemonId}");
                CurrentCaptureAward = caughtPokemonResponse.CaptureAward;
                CatchSuccess?.Invoke(this, null);
                _capturedPokemonId = caughtPokemonResponse.CapturedPokemonId;
                if (CurrentPokemon is MapPokemonWrapper)
                {
                    GameClient.CatchablePokemons.Remove((MapPokemonWrapper)CurrentPokemon);
                }
                else
                {
                    GameClient.LuredPokemons.Remove((LuredPokemon)CurrentPokemon);
                }
                GameClient.NearbyPokemons.Remove(nearbyPokemon);
                return(true);

            case CatchPokemonResponse.Types.CatchStatus.CatchEscape:
                Logger.Write($"{CurrentPokemon.PokemonId} escaped");
                CatchEscape?.Invoke(this, null);
                _canUseBerry = true;
                break;

            case CatchPokemonResponse.Types.CatchStatus.CatchFlee:
                Logger.Write($"{CurrentPokemon.PokemonId} fled");
                CatchFlee?.Invoke(this, null);
                if (CurrentPokemon is MapPokemonWrapper)
                {
                    GameClient.CatchablePokemons.Remove((MapPokemonWrapper)CurrentPokemon);
                }
                else
                {
                    GameClient.LuredPokemons.Remove((LuredPokemon)CurrentPokemon);
                }
                GameClient.NearbyPokemons.Remove(nearbyPokemon);
                // We just go back because there's nothing else to do
                GameClient.ToggleUpdateTimer();
                break;

            case CatchPokemonResponse.Types.CatchStatus.CatchMissed:
                Logger.Write($"We missed {CurrentPokemon.PokemonId}");
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(false);
        }
        /// <summary>
        ///     Launches the PokeBall for the current encounter, handling the different catch responses
        /// </summary>
        /// <returns></returns>
        private async Task <bool> ThrowPokeball(bool hitPokemon)
        {
            // We use to simulate a 5 second wait to get animation going
            // If server takes too much to reply then we don't use the delay
            var requestTime = DateTime.Now;

            // If we have a starter pokemon, send just the pokemonid in a EncounterTutorialComplete request
            if (CurrentPokemon.EncounterId == 0)
            {
                if (!hitPokemon)
                {
                    SelectedCaptureItem = SelectPokeballType(LastItemUsed) ?? SelectAvailablePokeBall(); //To restore it after UpdateInventory, which overrides it
                    return(false);
                }

                var encounterTutorialCompleteResponse = await GameClient.EncounterTutorialComplete(CurrentPokemon.PokemonId);

                var responseDelay = DateTime.Now - requestTime;
                if (responseDelay.TotalSeconds < 5 && hitPokemon)
                {
                    await Task.Delay(TimeSpan.FromSeconds(5 - (int)responseDelay.TotalSeconds));
                }

                //GameClient.UpdateInventory();
                SelectedCaptureItem = SelectPokeballType(LastItemUsed) ?? SelectAvailablePokeBall(); //To restore it after UpdateInventory, which overrides it

                switch (encounterTutorialCompleteResponse.Result)
                {
                case EncounterTutorialCompleteResponse.Types.Result.Success:
                    GameClient.CurrentSession.Logger.Info($"We caught {CurrentPokemon.PokemonId}");
                    CurrentCaptureAward = encounterTutorialCompleteResponse.CaptureAward;
                    CaptureXpToTotalCaptureXpConverter converter = new Utils.CaptureXpToTotalCaptureXpConverter();
                    GameClient.AddGameXP((int)converter.Convert(CurrentCaptureAward.Xp, typeof(int), null, null));
                    CatchSuccess?.Invoke(this, null);
                    if (encounterTutorialCompleteResponse.PokemonData != null)
                    {
                        _capturedPokemonId = encounterTutorialCompleteResponse.PokemonData.Id;
                    }
                    return(true);

                case EncounterTutorialCompleteResponse.Types.Result.Unset:
                    GameClient.CurrentSession.Logger.Info($"We got an 'unset' response for {CurrentPokemon.PokemonId}");
                    CurrentCaptureAward = new CaptureAward();
                    CatchSuccess?.Invoke(this, null);
                    _capturedPokemonId = 0;
                    return(true);

                default:
                    break;
                }
                GameClient.CurrentSession.Logger.Info($"{CurrentPokemon.PokemonId} escaped");
                CatchEscape?.Invoke(this, null);
                return(false);
            }
            else
            {
                var caughtPokemonResponse = await GameClient.CatchPokemon(CurrentPokemon.EncounterId, CurrentPokemon.SpawnpointId, SelectedCaptureItem.ItemId, hitPokemon);

                //GameClient.UpdateInventory(); //TODO: Change to delta update inventory, so it doesn't take so long (and offico client does it too)
                SelectedCaptureItem = SelectPokeballType(LastItemUsed) ?? SelectAvailablePokeBall(); //To restore it after UpdateInventory, which overrides it

                var responseDelay = DateTime.Now - requestTime;
                if (responseDelay.TotalSeconds < 5 && hitPokemon)
                {
                    await Task.Delay(TimeSpan.FromSeconds(5 - (int)responseDelay.TotalSeconds));
                }
                var nearbyPokemon = GameClient.NearbyPokemons.FirstOrDefault(pokemon => pokemon.EncounterId == CurrentPokemon.EncounterId);

                switch (caughtPokemonResponse.Status)
                {
                case CatchPokemonResponse.Types.CatchStatus.CatchError:
                    GameClient.CurrentSession.Logger.Info("CatchError!");
                    //await GameClient.UpdateInventory();
                    // TODO: what can we do?
                    break;

                case CatchPokemonResponse.Types.CatchStatus.CatchSuccess:
                    GameClient.CurrentSession.Logger.Info($"We caught {CurrentPokemon.PokemonId}");
                    CurrentCaptureAward = caughtPokemonResponse.CaptureAward;
                    CaptureXpToTotalCaptureXpConverter converter = new Utils.CaptureXpToTotalCaptureXpConverter();
                    GameClient.AddGameXP((int)converter.Convert(CurrentCaptureAward.Xp, typeof(int), null, null));
                    CatchSuccess?.Invoke(this, null);
                    _capturedPokemonId = caughtPokemonResponse.CapturedPokemonId;
                    //await GameClient.UpdatePlayerStats(); -> This will be done when we return to the game screen, to allow the LevelUp to be shown
                    //await GameClient.UpdateInventory();
                    if (CurrentPokemon is MapPokemonWrapper)
                    {
                        GameClient.CatchablePokemons.Remove((MapPokemonWrapper)CurrentPokemon);
                    }
                    else if (CurrentPokemon is LuredPokemon)
                    {
                        GameClient.LuredPokemons.Remove((LuredPokemon)CurrentPokemon);
                    }
                    else if (CurrentPokemon is IncensePokemon)
                    {
                        GameClient.IncensePokemons.Remove((IncensePokemon)CurrentPokemon);
                    }
                    GameClient.NearbyPokemons.Remove(nearbyPokemon);
                    return(true);

                case CatchPokemonResponse.Types.CatchStatus.CatchEscape:
                    GameClient.CurrentSession.Logger.Info($"{CurrentPokemon.PokemonId} escaped");
                    CatchEscape?.Invoke(this, null);
                    _canUseBerry = true;
                    //await GameClient.UpdateInventory();
                    break;

                case CatchPokemonResponse.Types.CatchStatus.CatchFlee:
                    GameClient.CurrentSession.Logger.Info($"{CurrentPokemon.PokemonId} fled");
                    CatchFlee?.Invoke(this, null);
                    //await GameClient.UpdateInventory();
                    if (CurrentPokemon is MapPokemonWrapper)
                    {
                        GameClient.CatchablePokemons.Remove((MapPokemonWrapper)CurrentPokemon);
                    }
                    else if (CurrentPokemon is LuredPokemon)
                    {
                        GameClient.LuredPokemons.Remove((LuredPokemon)CurrentPokemon);
                    }
                    else if (CurrentPokemon is IncensePokemon)
                    {
                        GameClient.IncensePokemons.Remove((IncensePokemon)CurrentPokemon);
                    }
                    GameClient.NearbyPokemons.Remove(nearbyPokemon);
                    // We just go back because there's nothing else to do
                    GameClient.ToggleUpdateTimer();
                    break;

                case CatchPokemonResponse.Types.CatchStatus.CatchMissed:
                    GameClient.CurrentSession.Logger.Info($"We missed {CurrentPokemon.PokemonId}");
                    //await GameClient.UpdateInventory();
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            return(false);
        }
Пример #6
0
        /// <summary>
        ///     Launches the PokeBall for the current encounter, handling the different catch responses
        /// </summary>
        /// <returns></returns>
        private async Task ThrowPokeball(bool hitPokemon)
        {
            // We use to simulate a 5 second wait to get animation going
            // If server takes too much to reply then we don't use the delay
            var requestTime           = DateTime.Now;
            var caughtPokemonResponse = await GameClient.CatchPokemon(CurrentPokemon.EncounterId, CurrentPokemon.SpawnpointId, SelectedCaptureItem.ItemId, hitPokemon);

            var responseDelay = DateTime.Now - requestTime;

            if (responseDelay.TotalSeconds < 5)
            {
                await Task.Delay(TimeSpan.FromSeconds(5 - (int)responseDelay.TotalSeconds));
            }
            var nearbyPokemon = GameClient.NearbyPokemons.FirstOrDefault(pokemon => pokemon.EncounterId == CurrentPokemon.EncounterId);

            switch (caughtPokemonResponse.Status)
            {
            case CatchPokemonResponse.Types.CatchStatus.CatchError:
                Logger.Write("CatchError!");
                // TODO: what can we do?
                break;

            case CatchPokemonResponse.Types.CatchStatus.CatchSuccess:
                Logger.Write($"We caught {CurrentPokemon.PokemonId}");
                CurrentCaptureAward = caughtPokemonResponse.CaptureAward;
                CatchSuccess?.Invoke(this, null);
                if (CurrentPokemon is MapPokemonWrapper)
                {
                    GameClient.CatchablePokemons.Remove((MapPokemonWrapper)CurrentPokemon);
                }
                else
                {
                    GameClient.LuredPokemons.Remove((LuredPokemon)CurrentPokemon);
                }
                GameClient.NearbyPokemons.Remove(nearbyPokemon);
                break;

            case CatchPokemonResponse.Types.CatchStatus.CatchEscape:
                Logger.Write($"{CurrentPokemon.PokemonId} escaped");
                CatchEscape?.Invoke(this, null);
                break;

            case CatchPokemonResponse.Types.CatchStatus.CatchFlee:
                Logger.Write($"{CurrentPokemon.PokemonId} fled");
                CatchFlee?.Invoke(this, null);
                if (CurrentPokemon is MapPokemonWrapper)
                {
                    GameClient.CatchablePokemons.Remove((MapPokemonWrapper)CurrentPokemon);
                }
                else
                {
                    GameClient.LuredPokemons.Remove((LuredPokemon)CurrentPokemon);
                }
                GameClient.NearbyPokemons.Remove(nearbyPokemon);
                // We just go back because there's nothing else to do
                GameClient.ToggleUpdateTimer();
                break;

            case CatchPokemonResponse.Types.CatchStatus.CatchMissed:
                Logger.Write($"We missed {CurrentPokemon.PokemonId}");
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            // We always need to update the inventory
            await GameClient.UpdateInventory();

            SelectStartingBall(true);
        }
Пример #7
0
        private async void PokeballUpdateLoop(ThreadPoolTimer timer)
        {
            if (UpdateLoopMutex.WaitOne(0))
            {
                DateTime curTime = DateTime.Now;

                // timeDelta is the seconds since last update
                float timeDelta = (curTime - prevTime).Milliseconds / 1000f;

                Vector3 gravity = new Vector3(0, 300f, 0);

                // Apply basic Kinematics
                ThrowItemPosition += (ThrowItemVelocity * timeDelta) + (.5f * gravity * timeDelta * timeDelta);
                ThrowItemVelocity += (gravity * timeDelta);

                /*
                 * Logger.Write("Position" + ThrowItemPosition.X + ", " + ThrowItemPosition.Y + ", " + ThrowItemPosition.Z);
                 * Logger.Write("Velocity" + ThrowItemVelocity.X + ", " + ThrowItemVelocity.Y + ", " + ThrowItemVelocity.Z);
                 */

                prevTime = curTime;

                // Shotty attempt at converting from world space to screen space without a matrix
                var translateX = ThrowItemPosition.X * Math.Max(1.0f - (ThrowItemPosition.Z / 400.0f), 0.0f);
                var translateY = ThrowItemPosition.Y - (ThrowItemPosition.Z);
                var scaleX     = Math.Max(1.0f - (ThrowItemPosition.Z / 200.0f), 0.0f);
                var scaleY     = scaleX;

                var pokeballStopped = false;
                var pokemonHit      = false;

                if (Vector3.DistanceSquared(PokemonPosition, ThrowItemPosition) < PokemonRadiusSq)
                {
                    // We hit the pokemon!
                    pokeballStopped = true;
                    pokemonHit      = true;
                    timer.Cancel();
                    Logger.Write("Hit Pokemon! " + ThrowItemPosition.X + ", " + ThrowItemPosition.Y + ", " + ThrowItemPosition.Z);
                }
                else if (ThrowItemPosition.Y > 50)
                {
                    // We missed the pokemon...
                    timer.Cancel();
                    pokeballStopped = true;
                    Logger.Write("Missed Pokemon! " + ThrowItemPosition.X + ", " + ThrowItemPosition.Y + ", " + ThrowItemPosition.Z);
                    // TODO: We need to use up a pokeball on the missed throw
                }

                UpdateLoopMutex.ReleaseMutex();

                await PokeballTransform.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
                {
                    PokeballTransform.TranslateX = PokeballCatchAnimationStartingTranslateX.Value = translateX;
                    PokeballTransform.TranslateY = PokeballCatchAnimationStartingTranslateY.Value = translateY;
                    PokeballTransform.ScaleX     = PokeballCatchAnimationStartingScaleX.Value = scaleX;
                    PokeballTransform.ScaleY     = PokeballCatchAnimationStartingScaleY.Value = scaleY;
                    if (pokeballStopped)
                    {
                        if (pokemonHit)
                        {
                            CatchSuccess.Begin();
                            ViewModel.UseSelectedCaptureItem.Execute(true);
                        }
                        else
                        {
                            // TODO: move the missed command if you want
                            ViewModel.UseSelectedCaptureItem.Execute(false);
                            PokeballTransform.TranslateX   = InitItemX;
                            PokeballTransform.TranslateY   = InitItemY;
                            PokeballTransform.ScaleX       = 1;
                            PokeballTransform.ScaleY       = 1;
                            LaunchPokeballButton.IsEnabled = true;
                        }
                    }
                });
            }
        }