Ejemplo n.º 1
0
        // Temp - start a test wild battle
        public void TempCreateWildBattle(Map map, Map.Layout.Block block, EncounterTable.Encounter encounter)
        {
            Save sav      = Save;
            var  me       = new PBETrainerInfo(sav.PlayerParty, sav.PlayerName);
            var  wildPkmn = PartyPokemon.GetTestWildPokemon(encounter);
            var  wild     = new PBETrainerInfo(new Party {
                wildPkmn
            }, "Wild " + PBELocalizedString.GetSpeciesName(wildPkmn.Species).English);

            void OnBattleEnded()
            {
                void FadeFromTransitionEnded()
                {
                    _fadeFromTransition = null;
                }

                _fadeFromTransition = new FadeFromColorTransition(20, 0, FadeFromTransitionEnded);
                _battleGUI          = null;
            }

            _battleGUI = new BattleGUI(new PBEBattle(PBEBattleFormat.Single, PBESettings.DefaultSettings, me, wild,
                                                     battleTerrain: Overworld.GetPBEBattleTerrainFromBlock(block.BlocksetBlock),
                                                     weather: Overworld.GetPBEWeatherFromMap(map)),
                                       OnBattleEnded);
            void OnBattleTransitionEnded()
            {
                _battleTransition = null;
            }

            _battleTransition = new SpiralTransition(OnBattleTransitionEnded);
        }
Ejemplo n.º 2
0
 internal PBETrainerInfo(PBETrainerInfo other, byte?onlyForTrainer)
 {
     Id   = other.Id;
     Name = other.Name;
     if (onlyForTrainer is not null && onlyForTrainer.Value == Id)
     {
         Inventory = other.Inventory;
         Party     = other.Party;
     }
Ejemplo n.º 3
0
            internal PBETeamInfo(EndianBinaryReader r)
            {
                Id = r.ReadByte();
                var trainers = new PBETrainerInfo[r.ReadByte()];

                for (int i = 0; i < trainers.Length; i++)
                {
                    trainers[i] = new PBETrainerInfo(r);
                }
                Trainers = new ReadOnlyCollection <PBETrainerInfo>(trainers);
            }
Ejemplo n.º 4
0
 internal PBETrainerInfo(PBETrainerInfo other, byte?onlyForTrainer)
 {
     Id   = other.Id;
     Name = other.Name;
     if (onlyForTrainer.HasValue && onlyForTrainer.Value == Id)
     {
         Inventory = other.Inventory;
         Party     = other.Party;
     }
     else
     {
         Inventory = PBEEmptyReadOnlyCollection <PBEInventorySlotInfo> .Value;
         Party     = PBEEmptyReadOnlyCollection <PBEBattlePokemonInfo> .Value;
     }
 }
Ejemplo n.º 5
0
 internal PBETrainerInfo(PBETrainerInfo other, byte?onlyForTrainer)
 {
     Id    = other.Id;
     Name  = other.Name;
     Party = onlyForTrainer.HasValue && onlyForTrainer.Value == Id ? other.Party : _emptyParty;
 }
Ejemplo n.º 6
0
        private void OnClientConnected(object sender, PBEServerClient client)
        {
            // Need to spawn a new thread so "WaitOne()" doesn't block the thread that receives client packets
            new Thread(() =>
            {
                lock (this)
                {
                    // Wait for the server to be in a state where no events will be sent
                    _resetEvent.WaitOne();

                    string name = PBEDataProvider.GlobalRandom.RandomElement(new string[] { "Sasha", "Nikki", "Lara", "Violet", "Naomi", "Rose", "Sabrina", "Nicole" });
                    if (_battlerCounter < NumBattlers)
                    {
                        byte i = _battlerCounter;
                        Console.WriteLine($"Client connected ({client.IP} {i} {name})");
                        var newPlayer = new Player(this, client, i, name);
                        IPBEPokemonCollection party = newPlayer.AskForParty(RequireLegalParties);
                        if (party == null)
                        {
                            newPlayer.Dispose();
                            return;
                        }
                        _incomingTrainers[i / NumTrainersPerTeam][i % NumTrainersPerTeam] = new PBETrainerInfo(party, name);
                        _battlers[i] = newPlayer;
                        _readyPlayers.Add(client, newPlayer);

                        // Start battle
                        if (++_battlerCounter == NumBattlers)
                        {
                            Console.WriteLine("All players connected!");
                            _battle                 = new PBEBattle(BattleFormat, Settings, _incomingTrainers[0], _incomingTrainers[1]);
                            _incomingTrainers       = null;
                            _battle.OnNewEvent     += PBEBattle.ConsoleBattleEventHandler;
                            _battle.OnNewEvent     += BattleEventHandler;
                            _battle.OnStateChanged += BattleStateHandler;
                            _server.Battle          = _battle;
                            BattleStateHandler(_battle); // Call RunTurn, which sends battle packet
                        }
                    }
                    else
                    {
                        Console.WriteLine($"Client connected ({client.IP} {byte.MaxValue} {name})");
                        var newPlayer   = new Player(this, client, byte.MaxValue, name);
                        var chakoPackay = new PBEPlayerJoinedPacket(name);
                        foreach (Player p in _readyPlayers.Values.ToArray())
                        {
                            p.Send(chakoPackay);
                            if (!p.WaitForResponse(typeof(PBEResponsePacket)) && p.BattleId != byte.MaxValue)
                            {
                                newPlayer.Dispose();
                                return;
                            }
                        }
                        _spectatorPackets.Add(chakoPackay);
                        foreach (IPBEPacket packet in _spectatorPackets)
                        {
                            newPlayer.Send(packet);
                            if (!newPlayer.WaitForResponse(typeof(PBEResponsePacket)))
                            {
                                newPlayer.Dispose();
                                return;
                            }
                        }
                        _readyPlayers.Add(client, newPlayer);
                    }
                }
            })
            {
                Name = "Client Connected Thread"
            }.Start();
        }