private IEnumerator BoxPokemonClickedCoroutine(byte pokemonIndex)
        {
            textBoxController.Show();

            string choicePrompt = "What would you like to do with " + CurrentBoxPokemon[pokemonIndex].GetDisplayName() + "?";

            yield return(StartCoroutine(textBoxController.WaitForUserChoice(
                                            boxPokemonSelectedOptions,
                                            choicePrompt
                                            )));

            switch (textBoxController.userChoiceIndexSelected)
            {
            case 0:
                //Do nothing
                break;

            case 1:
                yield return(StartCoroutine(TryWithdrawBoxPokemon(pokemonIndex)));

                RefreshPartyPokemon();
                RefreshCurrentBox();
                break;

            default:
                Debug.LogError("Unknown choice selected");
                break;
            }

            textBoxController.Hide();
            SetControlEnabled(true);
            ReturnToSelectedGameObjectBeforePokemonClicked();
        }
Пример #2
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;
        }
Пример #3
0
        private void OnActionChosen_Use()
        {
            if (CurrentItem.CanBeUsedFromBag())
            {
                if (CurrentItem is GeneralItem generalCurrentItem &&
                    !generalCurrentItem.GetRequireTargetPokemon())
                {
                    // General items that don't require a pokemon target to be used

                    // Items are handled for individual cases as functionalities are too unique to generalise

                    // Switch statement for different possible items that are being used
                    switch (generalCurrentItem.id)
                    {
                    case GeneralItem.repelId:
                    case GeneralItem.superRepelId:
                    case GeneralItem.maxRepelId:
                        OnActionChosen_Use_Repel(generalCurrentItem);
                        break;

                    default:
                        Debug.LogError("Unhandled general no-target-pokemon item id - " + generalCurrentItem.id);
                        break;
                    }

                    PlayerData.singleton.inventory.RemoveItem(CurrentItem, 1);

                    textBoxController.Show();
                    textBoxController.SetTextInstant($"{CurrentItem.itemName} was used");
                    textBoxController.SetHideDelay(1.5F);

                    ChangeToSectionSelection(false);
                }
                else
                {
                    // Default case

                    pokemonSelectionMode = PokemonSelectionMode.Use;
                    ChangeToPokemonSelection();
                }
            }
Пример #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
        }