Pokemon3D.GameModes.Monsters.Pokemon.LearnMove C# (CSharp) Method

LearnMove() private method

Attempts to teach this Pokémon a level up move from a specific level. It makes the Pokémon forget a random move if the Pokémon has a full moveset.
private LearnMove ( int level ) : bool
level int
return bool
        private bool LearnMove(int level)
        {
            var levelMoves = LevelMoves.Where(x => x.Level == level);
            foreach (var levelMove in levelMoves)
            {
                if (levelMove != null)
                {
                    // check if Pokémon does not already know this move:
                    if (!_saveModel.Moves.Any(x => x.Id == levelMove.Id))
                    {
                        var moveList = _saveModel.Moves.ToList();

                        // delete random move when this Pokémon already has 4 moves:
                        if (moveList.Count == POKEMON_MAX_MOVE_COUNT)
                        {
                            moveList.RemoveAt(GlobalRandomProvider.Instance.Rnd.Next(0, moveList.Count));
                        }

                        // get the move model to grab the PP from that:
                        var moveModel = _gameMode.GetMoveModel(levelMove.Id);
                        moveList.Add(new PokemonMoveModel
                        {
                            Id = moveModel.Id,
                            CurrentPP = moveModel.PP,
                            MaxPP = moveModel.PP
                        });

                        _saveModel.Moves = moveList.ToArray();
                    }
                }
            }
            return levelMoves.Count() > 0;
        }