Esempio n. 1
0
        private IEnumerator OnItemSelected_Buy(int index)
        {
            controlAllowed = false;
            textBoxController.Show();

            Item item = currentItems[index];

            string[] userChoices = GetBuyUserChoices(item);

            yield return(StartCoroutine(textBoxController.WaitForUserChoice(
                                            userChoices,
                                            "How much would you like to buy?"
                                            )));

            if (textBoxController.userChoiceIndexSelected == 0) //Cancel
            {
                //Do nothing and proceed to ending this coroutine (after the else block)
            }
            else
            {
                //1 is subtracted as first option is cancel
                ushort quantitySelected = buyQuantityOptions[textBoxController.userChoiceIndexSelected - 1];
                int    totalCost        = item.BuyPrice * quantitySelected;

                bool userCanAffordSelected = PlayerData.singleton.profile.money >= totalCost;

                if (userCanAffordSelected)
                {
                    PlayerData.singleton.inventory.AddItem(item, quantitySelected);
                    PlayerData.singleton.profile.money -= totalCost;
                    RefreshPlayerMoneyText();

                    //TODO - sound fx for purchase made
                    yield return(StartCoroutine(
                                     textBoxController.RevealText("Thank you for your purchase", true)
                                     ));
                }
                else
                {
                    yield return(StartCoroutine(
                                     textBoxController.RevealText("Sorry but you don't seem to have enough money for that.", true)
                                     ));
                }
            }

            textBoxController.Hide();
            controlAllowed = true;
        }
        private IEnumerator TryWithdrawBoxPokemon(byte pokemonIndex)
        {
            PokemonInstance pokemon = CurrentBoxPokemon[pokemonIndex];

            if (!PlayerData.singleton.PartyIsFull)
            {
                PlayerData.singleton.AddNewPartyPokemon(pokemon);
                CurrentBoxPokemon[pokemonIndex] = null;
                PlayerData.singleton.boxPokemon.CleanEmptySpaces();
            }
            else
            {
                yield return(StartCoroutine(
                                 textBoxController.RevealText("Party is already full", true)
                                 ));
            }
        }
Esempio n. 3
0
        private IEnumerator AnimationCoroutine()
        {
            evolutionCanBeCancelled    = true;
            evolutionHasBeenCancelled  = false;
            EvolutionAnimationComplete = null;

            float musicInitialVolume = MusicSourceController.singleton.GetVolume();

            MusicSourceController.singleton.SetVolume(musicVolume);

            Sprite startSprite = entranceArguments.PokemonSprite;

            PokemonSpecies endSpecies = PokemonSpecies.GetPokemonSpeciesById(entranceArguments.evolution.targetId);

            Sprite endSprite = endSpecies.LoadSprite(PokemonSpecies.SpriteType.Front1, entranceArguments.pokemon.gender, entranceArguments.pokemon.IsShiny);

            pokemonSpriteController.SetSprite(startSprite);

            yield return(new WaitForSeconds(initialPauseTime));

            SoundFXController.singleton.PlayPokemonCry(entranceArguments.pokemon.speciesId);

            for (byte i = 0; i < bounceCount; i++)
            {
                yield return(StartCoroutine(Animation_Bounce(pokemonSpriteController.pokemonSpriteObject, bounceHeight, bounceSingleTime)));
            }

            yield return(new WaitForSeconds(bounceToShrinkDelayTime));

            yield return(StartCoroutine(GradualEffect((t) =>
            {
                pokemonSpriteController.SetScale(1 - t);
                pokemonSpriteController.SetWhiteness(t);
            },
                                                      shrinkTime)));

            if (!evolutionHasBeenCancelled)
            {
                pokemonSpriteController.SetSprite(endSprite);
            }

            evolutionCanBeCancelled = false; //Once sprite has been changed, evolution can't be cancelled

            yield return(StartCoroutine(GradualEffect((t) =>
            {
                pokemonSpriteController.SetScale(t);
                pokemonSpriteController.SetWhiteness(1 - t);
            },
                                                      unshrinkTime)));

            if (!evolutionHasBeenCancelled)
            {
                //Evolution is allowed to be completed

                SoundFXController.singleton.PlaySound("evolution_end");
                SoundFXController.singleton.PlayPokemonCry(endSpecies.id);

                yield return(StartCoroutine(
                                 textBoxController.RevealText(entranceArguments.pokemon.GetDisplayName()
                                                              + " evolved into a "
                                                              + endSpecies.name
                                                              + '!', true)
                                 ));

                //Once animation is completed, evolve the pokemon
                entranceArguments.pokemon.Evolve(entranceArguments.evolution);
            }
            else
            {
                //Evolution is cancelled

                yield return(StartCoroutine(
                                 textBoxController.RevealText("Oh, "
                                                              + entranceArguments.pokemon.GetDisplayName()
                                                              + " stopped evolving", true)
                                 ));
            }

            yield return(new WaitForSeconds(endDelayTime));

            MusicSourceController.singleton.SetVolume(musicInitialVolume);

            EvolutionAnimationComplete?.Invoke();
            yield break;
        }
Esempio n. 4
0
        private IEnumerator MainTradeSceneCoroutine()
        {
            #region Initial Setup

            waitingForPlayerChoice = false;
            tradeReadyToExecute    = false;

            //Check arguments are set
            if (!TradeEntranceArguments.argumentsSet)
            {
                Debug.LogError("Trade entrance arguments not set");
                GameSceneManager.CloseTradeScene();
                yield break;
            }

            //Set up trade stage
            tradeStage = 0;

            //Read entrance arguments
            networkStream = TradeEntranceArguments.networkStream;
            otherUserName = TradeEntranceArguments.otherUserName;
            disallowedSendPokemonGuids = TradeEntranceArguments.disallowedSendPokemonGuids;

            //Set the other user's displayed name according to newly-read-from-entrance-arguments name
            tradeUIController.RefreshOtherUserName();

            //Initialise offered pokemon
            playerOfferedPokemonLocator = null;
            otherUserOfferedPokemon     = null;

            //Create comms manager
            commsManager = new Connection.NetworkTradeCommsManager(
                stream: networkStream,
                serializer: Serialize.DefaultSerializer);

            //Start listening
            commsManager.StartListening();

            #endregion

            #region Trade Decision Loop

            tradeUIController.SetInteractionEnabled(true);

            while (true)
            {
                #region Comm Receiving

                Connection.NetworkCommsManager.Comm comm = commsManager.GetNextComm();

                if (comm != null)
                {
                    yield return(StartCoroutine(HandleTradeComm(comm)));
                }

                #endregion

                #region Actions Needing To Be Taken

                if (locatorToBeConfirmed != null)
                {
                    if (tradeStage != TradeStage.ChoosingOffer && tradeStage != TradeStage.ConfirmingOfferChoice)
                    {
                        Debug.LogError("Locator to be confirmed has been set when not in correct trade stage");
                    }
                    else if (tradeStage == TradeStage.ChoosingOffer)
                    {
                        yield return(StartCoroutine(SetTradeStage(TradeStage.ConfirmingOfferChoice)));
                    }
                }
                else if (tryingToConfirmCloseTrade)
                {
                    if (tradeStage != TradeStage.ChoosingOffer)
                    {
                        Debug.LogError("Trying to close trade when not in correct trade stage");
                    }
                    else
                    {
                        tryingToConfirmCloseTrade = false;
                        yield return(StartCoroutine(SetTradeStage(TradeStage.ConfirmingCancelTrade)));
                    }
                }
                else if (needToNotifyPlayerDisallowedTrade)
                {
                    if (tradeStage != TradeStage.ChoosingOffer && tradeStage != TradeStage.ConfirmingOfferChoice)
                    {
                        Debug.LogError("Trying to notify player of disallowed offer when not choosing offer pokemon");
                    }
                    else
                    {
                        needToNotifyPlayerDisallowedTrade = false;

                        textBoxController.Show();
                        yield return(StartCoroutine(
                                         textBoxController.RevealText(otherUserName + disallowedOfferPokemonMessageSuffix, true)
                                         ));

                        textBoxController.Hide();
                    }
                }

                #endregion

                #region Other user making decision being waited for

                //Waiting for other user's offer and other user's offer has been set
                if (tradeStage == TradeStage.WaitingForOtherUserOffer && otherUserOfferedPokemon != null)
                {
                    yield return(StartCoroutine(SetTradeStage(TradeStage.DecidingOnOffer)));
                }

                //Waiting for other user decision on offer and other user has accepted trade
                if (tradeStage == TradeStage.WaitingForOtherUserDecisionOnOffer && otherUserAcceptedTrade)
                {
                    tradeReadyToExecute = true;
                    break; //Break loop to execute trade
                }

                #endregion

                #region User Making Choices during Trade Stages

                if (waitingForPlayerChoice)
                {
                    if (textBoxController.userChoiceIndexSelected >= 0) //If choice has been made
                    {
                        switch (tradeStage)
                        {
                        case TradeStage.ConfirmingOfferChoice:
                            yield return(StartCoroutine(ConfirmOfferChoiceMade()));

                            break;

                        case TradeStage.WaitingForOtherUserOffer:
                            yield return(StartCoroutine(CancelOfferedPokemon()));

                            break;

                        case TradeStage.DecidingOnOffer:
                            yield return(StartCoroutine(DecisionOnOfferChoiceMade()));

                            break;

                        case TradeStage.ConfirmingCancelTrade:
                            yield return(StartCoroutine(ConfirmCancelTradeChoiceMade()));

                            break;

                        default:
                            Debug.LogError("Text box waiting for user choice when not on selection trade stage");
                            break;
                        }
                    }
                }

                #endregion

                if (commsManager.CommsConnErrorOccured)
                {
                    break;
                }

                yield return(new WaitForFixedUpdate());
            }

            #endregion

            #region Dealing with Circumstances of Loop Breaking

            if (tradeReadyToExecute) //Trade decided successfully
            {
                CloseNetworking();

                tradeUIController.Hide();

                yield return(StartCoroutine(ExecuteTrade()));

                CloseTradeScene();
            }
            else if (commsManager.CommsConnErrorOccured) //Connection error occured
            {
                yield return(StartCoroutine(
                                 textBoxController.RevealText(connErrorOccuredMessage, true)
                                 ));

                CloseTradeScene();
            }
            else //Unknown reason
            {
                Debug.LogError("Main trade scene loop closed for unknown reason");
                GameSceneManager.CloseTradeScene();
            }

            #endregion
        }
        public IEnumerator RunAnimation(PokemonInstance sendPmon,
                                        PokemonInstance recvPmon)
        {
            textBoxController = TextBoxController.GetTextBoxController(gameObject.scene);

            PokeBall sendPokeBall = PokeBall.GetPokeBallById(sendPmon.pokeBallId);
            PokeBall recvPokeBall = PokeBall.GetPokeBallById(recvPmon.pokeBallId);

            Vector3 pokemonInitialScale = PokemonTransform.localScale;

            //Initialise visibilities
            pokemonImage.enabled  = true;
            pokeBallImage.enabled = false;

            //Initialise sprites
            pokemonImage.sprite  = sendPmon.LoadSprite(PokemonSpecies.SpriteType.Front1);
            pokeBallImage.sprite = sendPokeBall.GetSprite(PokeBall.SpriteType.Neutral);

            //Initialise positions
            PokemonTransform.position  = mainRootTransform.position;
            PokeBallTransform.position = mainRootTransform.position;

            //Goodbye message
            yield return(StartCoroutine(
                             textBoxController.RevealText(goodbyeMessagePrefix + sendPmon.GetDisplayName() + goodbyeMessageSuffix, true)
                             ));

            //Send pokemon cry
            SoundFXController.PlayPokemonCry(sendPmon.speciesId);

            //Send pokemon bouncing
            for (byte i = 0; i < sendPmonBonuceCount; i++)
            {
                yield return(StartCoroutine(Animation_Bounce(PokemonTransform)));
            }

            //Delay
            yield return(new WaitForSeconds(jumpScaleDelay));

            //Open and show poke ball
            pokeBallImage.enabled = true;
            pokeBallImage.sprite  = sendPokeBall.GetSprite(PokeBall.SpriteType.Open);

            //Shrink and hide pokemon
            yield return(StartCoroutine(GradualEffect(
                                            t =>
            {
                PokemonTransform.localScale = pokemonInitialScale * (1 - t);
            },
                                            shrinkGrowTime)));

            pokemonImage.enabled = false;

            //Close poke ball
            pokeBallImage.sprite = sendPokeBall.GetSprite(PokeBall.SpriteType.Neutral);

            //Delay
            yield return(new WaitForSeconds(pokeBallCloseSendDelay));

            //Send away poke ball
            yield return(StartCoroutine(Animation_GradualLinearFunctionMovement(PokeBallTransform,
                                                                                pokeBallOffScreenTransform.position,
                                                                                t => Vector2.up * pokeBallFactorDisplacementCurve_y.Evaluate(t),
                                                                                t => Vector2.right * pokeBallAddedDisplacementCurve_x.Evaluate(t) * addedDisplacementFactor,
                                                                                pokeBallSendReturnTime)));

            //Wait
            yield return(new WaitForSeconds(pokeBallReturnDelay));

            //Switch pokemon and poke ball sprites
            pokemonImage.sprite  = recvPmon.LoadSprite(PokemonSpecies.SpriteType.Front1);
            pokeBallImage.sprite = recvPokeBall.GetSprite(PokeBall.SpriteType.Neutral);

            //Return poke ball
            yield return(StartCoroutine(Animation_GradualLinearFunctionMovement(PokeBallTransform,
                                                                                mainRootTransform.position,
                                                                                t => Vector2.up * pokeBallFactorDisplacementCurve_y.Evaluate(t),
                                                                                t => Vector2.right * pokeBallAddedDisplacementCurve_x.Evaluate(t) * addedDisplacementFactor,
                                                                                pokeBallSendReturnTime)));

            //Delay
            yield return(new WaitForSeconds(pokeBallRecvOpenDelay));

            //Open poke ball
            pokeBallImage.sprite = recvPokeBall.GetSprite(PokeBall.SpriteType.Open);

            //Show and grow pokemon
            pokemonImage.enabled = true;
            yield return(StartCoroutine(GradualEffect(
                                            t =>
            {
                PokemonTransform.localScale = pokemonInitialScale * t;
            },
                                            shrinkGrowTime)));

            //Delay
            yield return(new WaitForSeconds(jumpScaleDelay));

            //Recv pokemon cry
            SoundFXController.PlayPokemonCry(recvPmon.speciesId);

            //Receive pokemon bouncing
            for (byte i = 0; i < recvPmonBounceCount; i++)
            {
                yield return(StartCoroutine(Animation_Bounce(PokemonTransform)));
            }

            //Delay
            yield return(new WaitForSeconds(endDelayTime));

            //Receiving message
            yield return(StartCoroutine(
                             textBoxController.RevealText(receiveMessagePrefix + recvPmon.GetDisplayName() + receiveMessageSuffix, true)
                             ));
        }