예제 #1
0
        public void Wild_Battle_Throws_For_Illegal_Party_Size(PBEBattleFormat format, int count, bool expectException)
        {
            #region Setup and check
            PBEDataProvider.GlobalRandom.Seed = 0;
            PBESettings settings = PBESettings.DefaultSettings;

            var p0 = new TestPokemonCollection(1);
            p0[0] = new TestPokemon(settings, PBESpecies.Magikarp, 0, 100, PBEMove.Splash);

            var p1 = new TestPokemonCollection(count);
            p1[0] = new TestPokemon(settings, PBESpecies.Magikarp, 0, 100, PBEMove.Splash)
            {
                CaughtBall = PBEItem.None
            };
            for (int i = 1; i < count; i++)
            {
                p1[i] = p1[0];
            }

            if (expectException)
            {
                Assert.Throws <ArgumentException>(() => new PBEBattle(format, settings, new PBETrainerInfo(p0, "Trainer 0"), new PBEWildInfo(p1)));
            }
            #endregion
        }
예제 #2
0
 public PBEBattle(PBEBattleFormat battleFormat, PBESettings settings, IEnumerable <PBEPokemonShell> team0Party, IEnumerable <PBEPokemonShell> team1Party)
 {
     if (battleFormat >= PBEBattleFormat.MAX)
     {
         throw new ArgumentOutOfRangeException(nameof(battleFormat));
     }
     if (team0Party == null)
     {
         throw new ArgumentNullException(nameof(team0Party));
     }
     if (team1Party == null)
     {
         throw new ArgumentNullException(nameof(team1Party));
     }
     if (team0Party.Count() == 0 || team0Party.Count() > settings.MaxPartySize)
     {
         throw new ArgumentOutOfRangeException(nameof(team0Party));
     }
     if (team1Party.Count() == 0 || team1Party.Count() > settings.MaxPartySize)
     {
         throw new ArgumentOutOfRangeException(nameof(team1Party));
     }
     BattleFormat = battleFormat;
     Settings     = settings;
     Teams[0]     = new PBETeam(this, 0, team0Party, ref pkmnIdCounter);
     Teams[1]     = new PBETeam(this, 1, team1Party, ref pkmnIdCounter);
     CheckForReadiness();
 }
예제 #3
0
        internal static void VerifyPosition(PBEBattleFormat format, PBEFieldPosition pos)
        {
            if (pos != PBEFieldPosition.None && pos < PBEFieldPosition.MAX)
            {
                switch (format)
                {
                case PBEBattleFormat.Single:
                case PBEBattleFormat.Rotation:
                {
                    switch (pos)
                    {
                    case PBEFieldPosition.Center: return;
                    }
                    break;
                }

                case PBEBattleFormat.Double:
                {
                    switch (pos)
                    {
                    case PBEFieldPosition.Left:
                    case PBEFieldPosition.Right: return;
                    }
                    break;
                }

                case PBEBattleFormat.Triple:
                {
                    return;
                }
                }
            }
            throw new ArgumentOutOfRangeException(nameof(pos));
        }
예제 #4
0
        public static int GetFieldPositionIndex(this PBETrainer trainer, PBEFieldPosition position)
        {
            if (!trainer.OwnsSpot(position))
            {
                throw new ArgumentOutOfRangeException(nameof(position));
            }
            PBEBattleFormat battleFormat = trainer.Battle.BattleFormat;
            int             index        = trainer.Team.Trainers.IndexOf(trainer);

            switch (battleFormat)
            {
            case PBEBattleFormat.Single:
            {
                switch (position)
                {
                case PBEFieldPosition.Center: return(0);
                }
                break;
            }

            case PBEBattleFormat.Double:
            {
                switch (position)
                {
                case PBEFieldPosition.Left: return(0);

                case PBEFieldPosition.Right: return(index == 1 ? 0 : 1);
                }
                break;
            }

            case PBEBattleFormat.Triple:
            {
                switch (position)
                {
                case PBEFieldPosition.Left: return(0);

                case PBEFieldPosition.Center: return(index == 1 ? 0 : 1);

                case PBEFieldPosition.Right: return(index == 2 ? 0 : 2);
                }
                break;
            }

            case PBEBattleFormat.Rotation:
            {
                switch (position)
                {
                case PBEFieldPosition.Center: return(0);

                case PBEFieldPosition.Left: return(1);

                case PBEFieldPosition.Right: return(2);
                }
                break;
            }
            }
            throw new Exception();
        }
예제 #5
0
        /// <summary>
        /// Gets the position across from the inputted position for a specific battle format.
        /// </summary>
        /// <param name="battleFormat">The battle format.</param>
        /// <param name="position">The position.</param>
        /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="battleFormat"/> is invalid or <paramref name="position"/> is invalid for <paramref name="battleFormat"/>.</exception>
        public static PBEFieldPosition GetPositionAcross(PBEBattleFormat battleFormat, PBEFieldPosition position)
        {
            switch (battleFormat)
            {
            case PBEBattleFormat.Single:
            case PBEBattleFormat.Rotation:
            {
                if (position == PBEFieldPosition.Center)
                {
                    return(PBEFieldPosition.Center);
                }
                else
                {
                    throw new ArgumentOutOfRangeException(nameof(position));
                }
            }

            case PBEBattleFormat.Double:
            {
                if (position == PBEFieldPosition.Left)
                {
                    return(PBEFieldPosition.Right);
                }
                else if (position == PBEFieldPosition.Right)
                {
                    return(PBEFieldPosition.Left);
                }
                else
                {
                    throw new ArgumentOutOfRangeException(nameof(position));
                }
            }

            case PBEBattleFormat.Triple:
            {
                if (position == PBEFieldPosition.Left)
                {
                    return(PBEFieldPosition.Right);
                }
                else if (position == PBEFieldPosition.Center)
                {
                    return(PBEFieldPosition.Center);
                }
                else if (position == PBEFieldPosition.Right)
                {
                    return(PBEFieldPosition.Left);
                }
                else
                {
                    throw new ArgumentOutOfRangeException(nameof(position));
                }
            }

            default: throw new ArgumentOutOfRangeException(nameof(BattleFormat));
            }
        }
예제 #6
0
 public NetworkClient(PBEBattleFormat battleFormat, PBETeamShell teamShell)
     : base(new PBEBattle(battleFormat, teamShell.Settings), ClientMode.Online)
 {
     _teamShell = teamShell;
     _client    = new PBEClient {
         Battle = Battle
     };
     _client.Disconnected   += OnDisconnected;
     _client.Error          += OnError;
     _client.PacketReceived += OnPacketReceived;
 }
 public SinglePlayerClient(PBEBattleFormat battleFormat, PBETeamShell team1Shell, string team1TrainerName, PBETeamShell team2Shell, string team2TrainerName)
     : base(new PBEBattle(battleFormat, team1Shell, team1TrainerName, team2Shell, team2TrainerName), ClientMode.SinglePlayer)
 {
     BattleId               = 0;
     Team                   = Battle.Teams[0];
     ShowRawValues0         = true;
     ShowRawValues1         = false;
     Battle.OnNewEvent     += SinglePlayerBattle_OnNewEvent;
     Battle.OnStateChanged += SinglePlayerBattle_OnStateChanged;
     new Thread(Battle.Begin)
     {
         Name = "Battle Thread"
     }.Start();
 }
        public SinglePlayerClient(PBEBattleFormat battleFormat, PBESettings settings, IReadOnlyList <PBETrainerInfo> ti0, IReadOnlyList <PBETrainerInfo> ti1, string name) : base(name)
        {
            var b = new PBEBattle(battleFormat, settings, ti0, ti1, battleTerrain: PBERandom.RandomBattleTerrain());

            Battle            = b;
            Trainer           = b.Trainers[0];
            BattleView        = new BattleView(this);
            b.OnNewEvent     += SinglePlayerBattle_OnNewEvent;
            b.OnStateChanged += SinglePlayerBattle_OnStateChanged;
            new Thread(b.Begin)
            {
                Name = "Battle Thread"
            }.Start();
        }
예제 #9
0
        private bool VerifyTrainerCount(PBEBattleFormat format, int count)
        {
            switch (format)
            {
            case PBEBattleFormat.Single:
            case PBEBattleFormat.Rotation: return(count == 1);

            case PBEBattleFormat.Double: return(count == 1 || count == 2);

            case PBEBattleFormat.Triple: return(count == 1 || count == 3);

            default: throw new ArgumentOutOfRangeException(nameof(format));
            }
        }
예제 #10
0
        private static bool VerifyWildCount(PBEBattleFormat format, int count)
        {
            switch (format)
            {
            case PBEBattleFormat.Single: return(count == 1);

            case PBEBattleFormat.Double: return(count >= 1 && count <= 2);

            case PBEBattleFormat.Rotation:
            case PBEBattleFormat.Triple: return(count >= 1 && count <= 3);

            default: throw new ArgumentOutOfRangeException(nameof(format));
            }
        }
예제 #11
0
        public PBEBattle(PBEBattleFormat battleFormat, PBESettings settings)
        {
            if (battleFormat >= PBEBattleFormat.MAX)
            {
                throw new ArgumentOutOfRangeException(nameof(battleFormat));
            }
            BattleFormat = battleFormat;
            Settings     = settings;

            Teams[0] = new PBETeam(this, 0);
            Teams[1] = new PBETeam(this, 1);

            BattleState = PBEBattleState.WaitingForPlayers;
            OnStateChanged?.Invoke(this);
        }
예제 #12
0
 /// <summary>Creates a new <see cref="PBEBattle"/> object with the specified <see cref="PBEBattleFormat"/> and a copy of the specified <see cref="PBESettings"/>. <see cref="BattleState"/> will be <see cref="PBEBattleState.WaitingForPlayers"/>.</summary>
 /// <param name="battleFormat">The <see cref="PBEBattleFormat"/> of the battle.</param>
 /// <param name="settings">The <see cref="PBESettings"/> to copy for the battle to use.</param>
 public PBEBattle(PBEBattleFormat battleFormat, PBESettings settings)
 {
     if (battleFormat >= PBEBattleFormat.MAX)
     {
         throw new ArgumentOutOfRangeException(nameof(battleFormat));
     }
     if (settings == null)
     {
         throw new ArgumentNullException(nameof(settings));
     }
     BattleFormat = battleFormat;
     Settings     = new PBESettings(settings);
     Settings.MakeReadOnly();
     Teams       = new PBETeams(this);
     BattleState = PBEBattleState.WaitingForPlayers;
     OnStateChanged?.Invoke(this);
 }
예제 #13
0
        public static PBETrainer GetTrainer(this PBETeam team, PBEFieldPosition pos)
        {
            PBEBattleFormat format = team.Battle.BattleFormat;

            VerifyPosition(format, pos);
            int i = 0;

            if (team.Trainers.Count != 1)
            {
                switch (format)
                {
                case PBEBattleFormat.Double: i = pos == PBEFieldPosition.Left ? 0 : 1; break;

                case PBEBattleFormat.Triple: i = pos == PBEFieldPosition.Left ? 0 : pos == PBEFieldPosition.Center ? 1 : 2; break;
                }
            }
            return(team.Trainers[i]);
        }
예제 #14
0
 /// <summary>Creates a new <see cref="PBEBattle"/> object with the specified <see cref="PBEBattleFormat"/> and teams. Each team must have equal settings. The battle's settings are set to a copy of the teams' settings. <see cref="BattleState"/> will be <see cref="PBEBattleState.ReadyToBegin"/>.</summary>
 /// <param name="battleFormat">The <see cref="PBEBattleFormat"/> of the battle.</param>
 /// <param name="team1Shell">The <see cref="PBETeamShell"/> object to use to create <see cref="Teams"/>[0].</param>
 /// <param name="team1TrainerName">The name of the trainer(s) on <see cref="Teams"/>[0].</param>
 /// <param name="team2Shell">The <see cref="PBETeamShell"/> object to use to create <see cref="Teams"/>[1].</param>
 /// <param name="team2TrainerName">The name of the trainer(s) on <see cref="Teams"/>[1].</param>
 /// <exception cref="ArgumentNullException">Thrown when <paramref name="team1Shell"/> or <paramref name="team2Shell"/> are null.</exception>
 /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="team1Shell"/> and <paramref name="team2Shell"/> have unequal <see cref="PBETeamShell.Settings"/> or when <paramref name="team1TrainerName"/> or <paramref name="team2TrainerName"/> are invalid.</exception>
 public PBEBattle(PBEBattleFormat battleFormat, PBETeamShell team1Shell, string team1TrainerName, PBETeamShell team2Shell, string team2TrainerName)
 {
     if (battleFormat >= PBEBattleFormat.MAX)
     {
         throw new ArgumentOutOfRangeException(nameof(battleFormat));
     }
     if (team1Shell == null)
     {
         throw new ArgumentNullException(nameof(team1Shell));
     }
     if (team2Shell == null)
     {
         throw new ArgumentNullException(nameof(team2Shell));
     }
     if (string.IsNullOrWhiteSpace(team1TrainerName))
     {
         throw new ArgumentOutOfRangeException(nameof(team1TrainerName));
     }
     if (string.IsNullOrWhiteSpace(team2TrainerName))
     {
         throw new ArgumentOutOfRangeException(nameof(team2TrainerName));
     }
     if (team1Shell.IsDisposed)
     {
         throw new ObjectDisposedException(nameof(team1Shell));
     }
     if (team2Shell.IsDisposed)
     {
         throw new ObjectDisposedException(nameof(team2Shell));
     }
     if (!team1Shell.Settings.Equals(team2Shell.Settings))
     {
         throw new ArgumentOutOfRangeException(nameof(team1Shell.Settings), "Team settings must be equal to each other.");
     }
     BattleFormat = battleFormat;
     Settings     = new PBESettings(team1Shell.Settings);
     Settings.MakeReadOnly();
     Teams = new PBETeams(this, team1Shell, team1TrainerName, team2Shell, team2TrainerName);
     CheckForReadiness();
 }
예제 #15
0
 public PBEBattle(PBEBattleFormat battleFormat, PBESettings settings, PBETrainerInfo ti0, PBETrainerInfo ti1, PBEBattleTerrain battleTerrain = PBEBattleTerrain.Plain, PBEWeather weather = PBEWeather.None)
     : this(battleFormat, settings, new[] { ti0 }, new[] { ti1 }, battleTerrain : battleTerrain, weather : weather)
 {
 }
예제 #16
0
        public PBEBattle(PBEBattleFormat battleFormat, PBESettings settings, IReadOnlyList <PBETrainerInfo> ti0, IReadOnlyList <PBETrainerInfo> ti1, PBEBattleTerrain battleTerrain = PBEBattleTerrain.Plain, PBEWeather weather = PBEWeather.None)
        {
            if (battleFormat >= PBEBattleFormat.MAX)
            {
                throw new ArgumentOutOfRangeException(nameof(battleFormat));
            }
            if (battleTerrain >= PBEBattleTerrain.MAX)
            {
                throw new ArgumentOutOfRangeException(nameof(battleTerrain));
            }
            if (weather >= PBEWeather.MAX)
            {
                throw new ArgumentOutOfRangeException(nameof(weather));
            }
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }
            if (!settings.IsReadOnly)
            {
                throw new ArgumentException("Settings must be read-only.", nameof(settings));
            }
            if (ti0 == null || ti0.Any(t => t == null))
            {
                throw new ArgumentNullException(nameof(ti0));
            }
            if (ti1 == null || ti1.Any(t => t == null))
            {
                throw new ArgumentNullException(nameof(ti1));
            }
            BattleTerrain = battleTerrain;
            BattleFormat  = battleFormat;
            Settings      = settings;
            Weather       = weather;
            Teams         = new PBETeams(this, ti0, ti1, out ReadOnlyCollection <PBETrainer> trainers);
            Trainers      = trainers;

            void QueueUp(PBETeam team, int i, PBEFieldPosition pos)
            {
                PBETrainer t;

                if (team.Trainers.Count == 1)
                {
                    t = team.Trainers[0];
                }
                else
                {
                    t = team.GetTrainer(pos);
                    i = 0;
                }
                PBEList <PBEBattlePokemon> party = t.Party;

                if (i < party.Count)
                {
                    PBEBattlePokemon p = party[i];
                    p.Trainer.SwitchInQueue.Add((p, pos));
                }
            }

            switch (BattleFormat)
            {
            case PBEBattleFormat.Single:
            {
                foreach (PBETeam team in Teams)
                {
                    QueueUp(team, 0, PBEFieldPosition.Center);
                }
                break;
            }

            case PBEBattleFormat.Double:
            {
                foreach (PBETeam team in Teams)
                {
                    QueueUp(team, 0, PBEFieldPosition.Left);
                    QueueUp(team, 1, PBEFieldPosition.Right);
                }
                break;
            }

            case PBEBattleFormat.Triple:
            {
                foreach (PBETeam team in Teams)
                {
                    QueueUp(team, 0, PBEFieldPosition.Left);
                    QueueUp(team, 1, PBEFieldPosition.Center);
                    QueueUp(team, 2, PBEFieldPosition.Right);
                }
                break;
            }

            case PBEBattleFormat.Rotation:
            {
                foreach (PBETeam team in Teams)
                {
                    QueueUp(team, 0, PBEFieldPosition.Center);
                    QueueUp(team, 1, PBEFieldPosition.Left);
                    QueueUp(team, 2, PBEFieldPosition.Right);
                }
                break;
            }

            default: throw new ArgumentOutOfRangeException(nameof(BattleFormat));
            }

            BattleState = PBEBattleState.ReadyToBegin;
            OnStateChanged?.Invoke(this);
        }
예제 #17
0
        public BattleGUI(PBEBattleFormat format)
        {
            _positions = new PkmnPosition[2][];
            switch (format)
            {
            case PBEBattleFormat.Single:
            {
                _positions[0] = new PkmnPosition[1]
                {
                    new PkmnPosition(0.015f, 0.25f, 0.40f, 0.95f)     // Center
                };
                _positions[1] = new PkmnPosition[1]
                {
                    new PkmnPosition(0.10f, 0.015f, 0.73f, 0.51f)     // Center
                };
                break;
            }

            case PBEBattleFormat.Double:
            {
                _positions[0] = new PkmnPosition[2]
                {
                    new PkmnPosition(0.015f, 0.25f, 0.25f, 0.92f),    // Left
                    new PkmnPosition(0.295f, 0.27f, 0.58f, 0.96f)     // Right
                };
                _positions[1] = new PkmnPosition[2]
                {
                    new PkmnPosition(0.38f, 0.035f, 0.85f, 0.53f),    // Left
                    new PkmnPosition(0.10f, 0.015f, 0.63f, 0.52f)     // Right
                };
                break;
            }

            case PBEBattleFormat.Triple:
            {
                _positions[0] = new PkmnPosition[3]
                {
                    new PkmnPosition(0.015f, 0.25f, 0.12f, 0.96f),   // Left
                    new PkmnPosition(0.295f, 0.27f, 0.38f, 0.89f),   // Center
                    new PkmnPosition(0.575f, 0.29f, 0.7f, 0.94f)     // Right
                };
                _positions[1] = new PkmnPosition[3]
                {
                    new PkmnPosition(0.66f, 0.055f, 0.91f, 0.525f),   // Left
                    new PkmnPosition(0.38f, 0.035f, 0.75f, 0.55f),    // Center
                    new PkmnPosition(0.10f, 0.015f, 0.56f, 0.53f)     // Right
                };
                break;
            }

            case PBEBattleFormat.Rotation:
            {
                _positions[0] = new PkmnPosition[3]
                {
                    new PkmnPosition(0.015f, 0.25f, 0.06f, 0.99f),    // Left
                    new PkmnPosition(0.295f, 0.27f, 0.4f, 0.89f),     // Center
                    new PkmnPosition(0.575f, 0.29f, 0.88f, 1.025f)    // Right
                };
                _positions[1] = new PkmnPosition[3]
                {
                    new PkmnPosition(0.66f, 0.055f, 0.97f, 0.48f),   // Left
                    new PkmnPosition(0.38f, 0.035f, 0.75f, 0.55f),   // Center
                    new PkmnPosition(0.10f, 0.015f, 0.5f, 0.49f)     // Right
                };
                break;
            }

            default: throw new ArgumentOutOfRangeException(nameof(format));
            }
        }