public void SetUp(BattleManager battleManager,
                          BattleParticipant playerParticipant)
        {
            singleton = this;
            this.playerParticipant           = playerParticipant;
            this.battleManager               = battleManager;
            currentSelectedPartyPokemonIndex = (byte)battleManager.battleData.participantPlayer.activePokemonIndex;

            #region Run Set-Up Functions

            menuFightController.SetUp();
            menuPartyController.SetUp();
            menuBagCategoryController.SetUp();

            #endregion

            #region Back Buttons

            menuFightController.buttonBack.onClick.AddListener(() => OpenRootMenu());

            menuBagController.buttonBack.onClick.AddListener(() => OpenRootMenu());

            menuBagCategoryController.buttonBack.onClick.AddListener(() =>
            {
                DisableAllMenus();
                menuBagController.Show();
                EventSystem.current.SetSelectedGameObject(menuBagController.buttonBack.gameObject);
            });

            menuPartyController.buttonBack.onClick.AddListener(() => OpenRootMenu());

            menuPartyPokemonController.buttonBack.onClick.AddListener(() =>
            {
                DisableAllMenus();
                menuPartyController.Show();
                EventSystem.current.SetSelectedGameObject(menuPartyController.pokemonButtons[0].gameObject);
            });

            menuPartyPokemonMovesController.buttonBack.onClick.AddListener(() =>
            {
                menuPartyPokemonMovesController.CloseMenu();
                DisableAllMenus();
                menuPartyPokemonController.Show();
                EventSystem.current.SetSelectedGameObject(menuPartyPokemonController.buttonBack.gameObject);
            });

            #endregion

            #region Root Menu Buttons

            if (playerBattleParticipant != null)
            {
                menuRootController.buttonRun.onClick.AddListener(() =>
                {
                    if (GetPlayerAllowedToFlee())
                    {
                        playerBattleParticipant.ChooseActionFlee();
                    }
                    else
                    {
                        battleManager.DisplayPlayerInvalidSelectionMessage("You can't flee!");
                    }
                });
            }

            menuRootController.buttonBag.onClick.AddListener(() =>
            {
                DisableAllMenus();
                menuBagController.Show();
                EventSystem.current.SetSelectedGameObject(menuBagController.buttonBack.gameObject);
            });

            menuRootController.buttonParty.onClick.AddListener(() =>
            {
                menuPartyController.RefreshButtons();
                DisableAllMenus();
                menuPartyController.Show();
                EventSystem.current.SetSelectedGameObject(menuPartyController.pokemonButtons[0].gameObject);
            });

            menuRootController.buttonFight.onClick.AddListener(() =>
            {
                DisableAllMenus();
                menuFightController.Show();
                EventSystem.current.SetSelectedGameObject(menuFightController.buttonBack.gameObject);
            });

            #endregion

            #region Fight Menu Buttons

            if (playerBattleParticipant != null)
            {
                menuFightController.SetCurrentPokemonIndex(playerBattleParticipant.activePokemonIndex);

                menuFightController.moveButtons[0].onClick.AddListener(() => SuggestChooseMoveIndex(0));

                menuFightController.moveButtons[1].onClick.AddListener(() => SuggestChooseMoveIndex(1));

                menuFightController.moveButtons[2].onClick.AddListener(() => SuggestChooseMoveIndex(2));

                menuFightController.moveButtons[3].onClick.AddListener(() => SuggestChooseMoveIndex(3));

                menuFightController.buttonMoveStruggle.onClick.AddListener(() =>
                {
                    playerBattleParticipant.ChooseActionFightStruggle();
                });
            }

            menuFightController.RefreshMoveButtons();

            #endregion

            #region Bag Menu Buttons

            menuBagController.buttonHPPPRestore.onClick.AddListener(() => OpenBagCategoryMenu(MenuBagCategoryController.BagCategory.HPPPRestore));
            menuBagController.buttonStatusItems.onClick.AddListener(() => OpenBagCategoryMenu(MenuBagCategoryController.BagCategory.StatusRestore));
            menuBagController.buttonPokeBalls.onClick.AddListener(() => OpenBagCategoryMenu(MenuBagCategoryController.BagCategory.PokeBalls));
            menuBagController.buttonBattleItems.onClick.AddListener(() => OpenBagCategoryMenu(MenuBagCategoryController.BagCategory.BattleItems));

            #endregion

            #region Bag Category Menu Buttons

            menuBagCategoryController.buttonNext.onClick.AddListener(() => menuBagCategoryController.NextPage());
            menuBagCategoryController.buttonPrevious.onClick.AddListener(() => menuBagCategoryController.PreviousPage());

            menuBagCategoryController.itemButtons[0].Button.onClick.AddListener(() => SuggestUseItemByPageIndex(0));
            menuBagCategoryController.itemButtons[1].Button.onClick.AddListener(() => SuggestUseItemByPageIndex(1));
            menuBagCategoryController.itemButtons[2].Button.onClick.AddListener(() => SuggestUseItemByPageIndex(2));
            menuBagCategoryController.itemButtons[3].Button.onClick.AddListener(() => SuggestUseItemByPageIndex(3));
            menuBagCategoryController.itemButtons[4].Button.onClick.AddListener(() => SuggestUseItemByPageIndex(4));
            menuBagCategoryController.itemButtons[5].Button.onClick.AddListener(() => SuggestUseItemByPageIndex(5));
            menuBagCategoryController.itemButtons[6].Button.onClick.AddListener(() => SuggestUseItemByPageIndex(6));
            menuBagCategoryController.itemButtons[7].Button.onClick.AddListener(() => SuggestUseItemByPageIndex(7));

            #endregion

            #region Party Menu Buttons

            menuPartyController.pokemonButtons[0].Button.onClick.AddListener(() => OpenPartyPokemonMenu(0));
            menuPartyController.pokemonButtons[1].Button.onClick.AddListener(() => OpenPartyPokemonMenu(1));
            menuPartyController.pokemonButtons[2].Button.onClick.AddListener(() => OpenPartyPokemonMenu(2));
            menuPartyController.pokemonButtons[3].Button.onClick.AddListener(() => OpenPartyPokemonMenu(3));
            menuPartyController.pokemonButtons[4].Button.onClick.AddListener(() => OpenPartyPokemonMenu(4));
            menuPartyController.pokemonButtons[5].Button.onClick.AddListener(() => OpenPartyPokemonMenu(5));

            menuPartyController.RefreshButtons();

            #endregion

            #region Party Pokemon Buttons

            menuPartyPokemonController.buttonCheckMoves.onClick.AddListener(() =>
            {
                OpenPartyPokemonMovesMenu();
            });

            if (playerBattleParticipant != null)
            {
                menuPartyPokemonController.buttonSendOut.onClick.AddListener(() =>
                {
                    bool isNull, healthPositive;

                    if (currentSelectedPartyPokemonIndex == playerBattleParticipant.activePokemonIndex)
                    {
                        battleManager.DisplayPlayerInvalidSelectionMessage("That is already your active pokemon");
                        return;
                    }

                    if (!playerBattleParticipant.GetAllowedToSwitchPokemon())
                    {
                        battleManager.DisplayPlayerInvalidSelectionMessage("You can't switch pokemon now!");
                        return;
                    }

                    Pokemon.PokemonInstance pokemon = PlayerData.singleton.partyPokemon[currentSelectedPartyPokemonIndex];
                    isNull = pokemon == null;

                    if (!isNull)
                    {
                        healthPositive = pokemon.health > 0;
                    }
                    else
                    {
                        healthPositive = false; //Health Postive is unecessary if pokemon is null
                    }
                    if (!isNull && healthPositive)
                    {
                        playerBattleParticipant.ChooseActionSwitchPokemon(currentSelectedPartyPokemonIndex);
                    }
                    else if (isNull)
                    {
                        Debug.LogError("Current selected pokemon is null when trying to choose switch pokemon action");
                    }
                    else
                    {
                        battleManager.DisplayPlayerInvalidSelectionMessage("You can't switch in a fainted pokemon");
                    }
                });
            }

            menuPartyPokemonController.buttonNext.onClick.AddListener(() =>
            {
                currentSelectedPartyPokemonIndex = (byte)((currentSelectedPartyPokemonIndex + 1) % PlayerPokemonCount);
                OpenPartyPokemonMenu(currentSelectedPartyPokemonIndex);
            });

            menuPartyPokemonController.buttonPrevious.onClick.AddListener(() =>
            {
                currentSelectedPartyPokemonIndex = (byte)((currentSelectedPartyPokemonIndex - 1 + PlayerPokemonCount) % PlayerPokemonCount);
                OpenPartyPokemonMenu(currentSelectedPartyPokemonIndex);
            });

            #endregion

            #region Party Pokemon Move Button Names

            menuPartyPokemonMovesController.SetUp();
            menuPartyPokemonMovesController.RefreshMoveButtons();

            #endregion
        }
Esempio n. 2
0
        /// <summary>
        /// Generate a PokemonInstance specifying many property values
        /// </summary>
        /// <returns>The PokemonInstance created</returns>
        public static PokemonInstance GenerateFull(
            int speciesId,
            int natureId,
            Stats <byte> effortValues,
            Stats <byte> individualValues,
            int[] _moves,
            byte[] movePPs,
            int experience,
            PokemonInstance.NonVolatileStatusCondition nonVolatileStatusCondition,
            PokemonInstance.BattleProperties battleProperties,
            Guid?_guid                 = null,
            string nickname            = "",
            Item heldItem              = null,
            int _health                = -1,
            bool?gender                = true,
            Stats <int> currentStats   = new Stats <int>(),                 //If all of these values are 0, they won't be used
            int pokeBallId             = PokemonInstance.defaultPokeBallId, //The poke ball id
            string originalTrainerName = "",
            Guid?_originalTrainerGuid  = null,
            bool cheatPokemon          = false,
            bool shinyPokemon          = false,
            long catchTime             = 0,
            byte?_friendship           = null // If this is null, the species' base friendship is used
            )
        {
            Guid guid = _guid == null?Guid.NewGuid() : (Guid)_guid;

            int[] moves = new int[4];

            //By default, the moves will be unset
            for (int i = 0; i < moves.Length; i++)
            {
                moves[i] = -1;
            }

            if (_moves.Length > 4)
            {
                Debug.LogWarning("Length of moves passed to GenerateFull was greater than 4");
                Array.Copy(_moves, moves, 4);
            }

            Array.Copy(_moves, moves, _moves.Length);

            Guid originalTrainerGuid = _originalTrainerGuid == null ? Guid.Empty : (Guid)_originalTrainerGuid;

            byte friendship = _friendship == null?PokemonSpecies.GetPokemonSpeciesById(speciesId).baseFriendship : (byte)_friendship;

            PokemonInstance instance = new PokemonInstance(individualValues)
            {
                speciesId    = speciesId,
                natureId     = natureId,
                effortValues = effortValues,
                moveIds      = moves,
                movePPs      = movePPs,
                experience   = experience,
                nonVolatileStatusCondition = nonVolatileStatusCondition,
                battleProperties           = battleProperties,
                guid                = guid,
                nickname            = nickname,
                heldItem            = heldItem,
                health              = _health > 0 ? _health : 1,
                gender              = gender,
                pokeBallId          = pokeBallId,
                originalTrainerName = originalTrainerName,
                originalTrainerGuid = originalTrainerGuid,
                cheatPokemon        = cheatPokemon,
                catchTime           = catchTime,
                friendship          = friendship
            };

            // Shininess
            instance.SetIsShiny(shinyPokemon);

            #region Setting Current Stats

            bool needToSetCurrentStats = false;

            foreach (Stats <int> .Stat stat in (Stats <int> .Stat[])Enum.GetValues(typeof(Stats <int> .Stat)))
            {
                if (currentStats.GetStat(stat) != 0)
                {
                    needToSetCurrentStats = true;
                    break;
                }
            }

            if (needToSetCurrentStats)
            {
                instance.SetCurrentStats(currentStats);
            }

            #endregion

            if (_health <= 0)
            {
                instance.RestoreFully();
            }

            return(instance);
        }