protected void SetMovePaneDetailsFromIndex(int moveIndex)
        {
            int  moveId      = PokemonMove.GetPokemonMoveById(playerBattleParticipant.ActivePokemon.moveIds[moveIndex]).id;
            byte remainingPP = PlayerData
                               .singleton
                               .partyPokemon[PlayerBattleUIController.singleton.currentSelectedPartyPokemonIndex]
                               .movePPs
                               [moveIndex];

            SetMovePaneDetails(moveId, remainingPP);
        }
        /// <summary>
        /// Cheat command to get the moves of one of the opponent's pokemon's moves
        /// </summary>
        public PokemonMove[] CheatCommand_GetOpponentPokemonMoves(int partyIndex, out byte[] movePPs)
        {
            PokemonInstance pokemon = partyIndex >= 0 ? battleData.participantOpponent.GetPokemon()[partyIndex] : battleData.participantOpponent.ActivePokemon;

            movePPs = pokemon.movePPs;
            return(pokemon
                   .moveIds
                   .Where(x => !PokemonMove.MoveIdIsUnset(x))
                   .Select(x => PokemonMove.GetPokemonMoveById(x))
                   .ToArray());
        }
Ejemplo n.º 3
0
        protected virtual void ChooseAction(BattleData battleData)
        {
            if (actionHasBeenChosen)
            {
                return;
            }

            //This script is always for the opponent so battleData.participantPlayer is used to find the opponent
            PokemonInstance opposingPokemon = battleData.participantPlayer.ActivePokemon;

            //If opposing pokemon health below threshold, try use priority move
            if (opposingPokemon.HealthProportion < priorityMoveOpponentHealthThreshold)
            {
                int?priorityMoveIndex = FindUsablePriorityMoveIndex(ActivePokemon);

                if (priorityMoveIndex != null)
                {
                    SetChosenAction(new Action(this)
                    {
                        type = Action.Type.Fight,
                        fightUsingStruggle = false,
                        fightMoveTarget    = battleData.participantPlayer,
                        fightMoveIndex     = (int)priorityMoveIndex
                    });

                    return;
                }
            }

            //Normal case is to choose a move based on the moves' weightings
            float[] moveWeightings    = GetMoveWeightings(opposingPokemon);
            int     selectedMoveIndex = SelectFromWeightings(moveWeightings);

            SetChosenAction(new Action(this)
            {
                type = Action.Type.Fight,
                fightUsingStruggle = false,
                fightMoveTarget    = battleData.participantPlayer,
                fightMoveIndex     = selectedMoveIndex
            });

            PokemonMove move = PokemonMove.GetPokemonMoveById(ActivePokemon.moveIds[selectedMoveIndex]);

            if (move == null)
            {
                Debug.LogError("Move selected from weightings was null");
            }

            if (MoveIsStatOEMove(move))
            {
                statOEMovesUsed++;
            }
        }
Ejemplo n.º 4
0
        private float[] GetMoveWeightings(PokemonInstance opposingPokemon)
        {
            float[] weightings = new float[ActivePokemon.moveIds.Length];

            if (ActivePokemon.battleProperties.volatileStatusConditions.encoreTurns > 0)
            {
                weightings = GetEncoreMoveWeightings();
            }
            else
            {
                for (int i = 0; i < ActivePokemon.moveIds.Length; i++)
                {
                    weightings[i] = 1;

                    //Move unset
                    if (PokemonMove.MoveIdIsUnset(ActivePokemon.moveIds[i]))
                    {
                        weightings[i] = 0;
                        continue;
                    }

                    //Out of PP
                    if (ActivePokemon.movePPs[i] <= 0)
                    {
                        weightings[i] = 0;
                    }

                    PokemonMove move = PokemonMove.GetPokemonMoveById(ActivePokemon.moveIds[i]);

                    //Being taunted
                    if (ActivePokemon.battleProperties.volatileStatusConditions.tauntTurns > 0 &&
                        move.moveType == PokemonMove.MoveType.Status)
                    {
                        weightings[i] = 0;
                    }

                    //Being tormented
                    if (ActivePokemon.battleProperties.volatileStatusConditions.torment &&
                        ActivePokemon.battleProperties.lastMoveId == move.id)
                    {
                        weightings[i] = 0;
                    }

                    //Type advantage
                    weightings[i] *= GetTypeAdvantageWeighting(TypeAdvantage.CalculateMultiplier(move.type, opposingPokemon.species));
                }
            }

            return(weightings);
        }
        protected void SetMovePaneDetails(int moveId, byte remainingPP)
        {
            PokemonMove move = PokemonMove.GetPokemonMoveById(moveId);

            textName.text          = move.name;
            textPPValue.text       = remainingPP + "/" + move.maxPP;
            textDescription.text   = move.description;
            textPowerValue.text    = move.power != 0 ? move.power.ToString() : "-";
            textAccuracyValue.text = move.accuracy != 0 ? move.accuracy.ToString() : "-";

            imageCategory.sprite = SpriteStorage.GetMoveTypeSprite(move.moveType);
            imageType.sprite     = SpriteStorage.GetTypeSymbolSprite(move.type);

            ShowMovePane();
        }
        public override bool CheckCompatibility(PokemonInstance pokemon)
        {
            for (int moveIndex = 0; moveIndex < pokemon.moveIds.Length; moveIndex++)
            {
                if (!PokemonMove.MoveIdIsUnset(pokemon.moveIds[moveIndex]))
                {
                    if (pokemon.movePPs[moveIndex] < PokemonMove.GetPokemonMoveById(pokemon.moveIds[moveIndex]).maxPP)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        private byte GetMissingPP(PokemonInstance pokemon,
                                  int moveIndex)
        {
            byte moveMaxPP = PokemonMove.GetPokemonMoveById(pokemon.moveIds[moveIndex]).maxPP;

            if (moveMaxPP < pokemon.movePPs[moveIndex])
            {
                Debug.LogError("Move has more PP than its maximum (index " + moveIndex + ")");
                return(0);
            }
            else
            {
                return((byte)(moveMaxPP - pokemon.movePPs[moveIndex]));
            }
        }
        public void RefreshButtons()
        {
            int[] moveIds = playerBattleParticipant.ActivePokemon.moveIds;

            for (int i = 0; i < moveIds.Length; i++)
            {
                if (PokemonMove.MoveIdIsUnset(moveIds[i]))
                {
                    moveButtons[i].SetInteractable(false);
                }
                else
                {
                    moveButtons[i].SetInteractable(true);

                    moveButtons[i].SetName(PokemonMove.GetPokemonMoveById(moveIds[i]).name);
                }
            }
        }
Ejemplo n.º 9
0
        protected int?FindUsablePriorityMoveIndex(PokemonInstance pokemon)
        {
            for (int i = 0; i < pokemon.moveIds.Length; i++)
            {
                if (PokemonMove.MoveIdIsUnset(pokemon.moveIds[i]))
                {
                    continue;
                }

                if (PokemonMove.GetPokemonMoveById(pokemon.moveIds[i]).movePriority == true &&
                    pokemon.movePPs[i] > 0)
                {
                    return(i);
                }
            }

            return(null);
        }
Ejemplo n.º 10
0
        public override void SetPokemon(PokemonInstance pokemon)
        {
            if (pokemon != null)
            {
                for (byte i = 0; i < pokemon.moveIds.Length; i++)
                {
                    PokemonMove move = PokemonMove.GetPokemonMoveById(pokemon.moveIds[i]);

                    moveDetailsContainers[i].SetMove(move);
                }
            }
            else
            {
                foreach (PokemonDetailsMovesPaneMoveContainerController moveContainer in moveDetailsContainers)
                {
                    moveContainer.SetMove(null);
                }
            }
        }
Ejemplo n.º 11
0
        public void SetMoveById(int id, byte currentPP)
        {
            if (PokemonMove.MoveIdIsUnset(id))
            {
                SetShowState(false);
                return;
            }

            SetShowState(true);

            PokemonMove move = PokemonMove.GetPokemonMoveById(id);

            textName.text          = move.name;
            textPP.text            = currentPP.ToString() + "/" + move.maxPP.ToString();
            textDescription.text   = move.description;
            textPowerValue.text    = move.power != 0 ? move.power.ToString() : "-";
            textAccuracyValue.text = move.accuracy != 0 ? move.accuracy.ToString() : "-";
            imageType.sprite       = SpriteStorage.GetTypeSymbolSprite(move.type);
            imageCategory.sprite   = SpriteStorage.GetMoveTypeSprite(move.moveType);
        }
        /// <summary>
        /// Sets the details of the menu including actions to take when each button is used
        /// </summary>
        /// <param name="pokemon">The pokmeon to use for consideration</param>
        /// <param name="replaceMove">Whether the menu is being used for replacing a move (instead of for cancelling learning the move)</param>
        /// <param name="replacedMoveIndex">(Only relevant if replaceMove is true) The index of the move that is being considered for replacement</param>
        public void SetDetails(PokemonInstance pokemon,
                               int newMoveId,
                               bool replaceMove,
                               int replacedMoveIndex = -1)
        {
            if (textBoxController == null)
            {
                SetTextBoxController();
            }

            PokemonMove newMove = PokemonMove.GetPokemonMoveById(newMoveId);

            noButton.onClick.AddListener(() => learnMoveUIController.ConfirmAction_ReturnToLearnMoveMenu());

            if (replaceMove)
            {
                if (replacedMoveIndex < 0 || replacedMoveIndex > 3)
                {
                    Debug.LogError("replacedMoveIndex was invalid when setting details for replacing a move");
                }

                string prompt = replaceMovePrompt
                                .Replace("{pokemonName}", pokemon.GetDisplayName())
                                .Replace("{oldMoveName}", PokemonMove.GetPokemonMoveById(pokemon.moveIds[replacedMoveIndex]).name)
                                .Replace("{newMoveName}", newMove.name);

                textBoxController.SetTextInstant(prompt);

                yesButton.onClick.AddListener(() => learnMoveUIController.ConfirmAction_ReplaceMove(replacedMoveIndex));
            }
            else
            {
                string prompt = cancelLearnMovePrompt
                                .Replace("{pokemonName}", pokemon.GetDisplayName())
                                .Replace("{moveName}", newMove.name);

                textBoxController.SetTextInstant(prompt);

                yesButton.onClick.AddListener(() => learnMoveUIController.ConfirmAction_CancelLearningMove());
            }
        }
        public void SuggestChooseMoveIndex(int index)
        {
            int         moveId = playerBattleParticipant.ActivePokemon.moveIds[index];
            PokemonMove move   = PokemonMove.GetPokemonMoveById(moveId);

            if (playerBattleParticipant.ActivePokemon.movePPs[index] <= 0)
            {
                battleManager.DisplayPlayerInvalidSelectionMessage("That move has no PP");
            }
            else if (playerBattleParticipant.ActivePokemon.battleProperties.volatileStatusConditions.encoreTurns > 0 &&
                     moveId != playerBattleParticipant.ActivePokemon.battleProperties.volatileStatusConditions.encoreMoveId)
            {
                //If under influence of encore and trying to use a non-encored move

                battleManager.DisplayPlayerInvalidSelectionMessage(playerBattleParticipant.ActivePokemon.GetDisplayName() + " must provide an encore!");
            }
            else if (playerBattleParticipant.ActivePokemon.battleProperties.volatileStatusConditions.tauntTurns > 0 &&
                     move.moveType == PokemonMove.MoveType.Status)
            {
                //If under influence of taunt and trying to use a status move

                battleManager.DisplayPlayerInvalidSelectionMessage(playerBattleParticipant.ActivePokemon.GetDisplayName() + " can't use status moves while being taunted!");
            }
            else if (playerBattleParticipant.ActivePokemon.battleProperties.volatileStatusConditions.torment &&
                     playerBattleParticipant.ActivePokemon.battleProperties.lastMoveId == moveId)
            {
                //If under influence of torment and trying to use same move as last turn

                battleManager.DisplayPlayerInvalidSelectionMessage(playerBattleParticipant.ActivePokemon.GetDisplayName() + " can't use the same move as last turn while being tormented!");
            }
            else
            {
                menuFightController.CloseMenu();
                playerBattleParticipant.ChooseActionFight(index);
            }
        }
Ejemplo n.º 14
0
 private PokemonMove[] GetMoves() => PlayerData
 .singleton
 .partyPokemon[currentPokemonIndex]
 .moveIds
 .Select(x => !PokemonMove.MoveIdIsUnset(x) ? PokemonMove.GetPokemonMoveById(x) : null)
 .ToArray();
Ejemplo n.º 15
0
        protected float[] GetMoveWeightings(PokemonInstance target)
        {
            float[] weightings = new float[4] {
                1, 1, 1, 1
            };

            if (ActivePokemon.battleProperties.volatileStatusConditions.encoreTurns > 0)
            {
                weightings = GetEncoreMoveWeightings();
            }
            else
            {
                for (int i = 0; i < ActivePokemon.moveIds.Length; i++)
                {
                    //Move unset
                    if (PokemonMove.MoveIdIsUnset(ActivePokemon.moveIds[i]))
                    {
                        weightings[i] = 0;
                        continue;
                    }

                    PokemonMove move = PokemonMove.GetPokemonMoveById(ActivePokemon.moveIds[i]);

                    //Being taunted
                    if (ActivePokemon.battleProperties.volatileStatusConditions.tauntTurns > 0 &&
                        move.moveType == PokemonMove.MoveType.Status)
                    {
                        weightings[i] = 0;
                    }

                    //Being tormented
                    if (ActivePokemon.battleProperties.volatileStatusConditions.torment &&
                        ActivePokemon.battleProperties.lastMoveId == move.id)
                    {
                        weightings[i] = 0;
                    }

                    float effectivenessModifier = target.species.type2 == null
                        ? TypeAdvantage.CalculateMultiplier(move.type, target.species.type1)
                        : TypeAdvantage.CalculateMultiplier(move.type, target.species.type1, (Type)target.species.type2);

                    //Out of PP
                    if (ActivePokemon.movePPs[i] <= 0)
                    {
                        weightings[i] = 0;
                    }

                    //Status or attack move
                    if (move.moveType == PokemonMove.MoveType.Status)
                    {
                        weightings[i] *= GetStatOEWeighting(statOEMovesUsed);
                    }
                    else
                    {
                        weightings[i] *= GetAttackMoveWeighting(effectivenessModifier);
                    }

                    //Healing weight
                    weightings[i] *= GetHealingMoveWeighint(ActivePokemon.HealthProportion);
                }
            }

            return(weightings);
        }
Ejemplo n.º 16
0
 protected PokemonMove[] GetMoves() => GetSelectedPokemon()
 .moveIds
 .Where(x => !PokemonMove.MoveIdIsUnset(x))
 .Select(x => PokemonMove.GetPokemonMoveById(x))
 .ToArray();