示例#1
0
        private void OnPacketReceived(object sender, IPBEPacket packet)
        {
            Debug.WriteLine($"Packet received (\"{packet.GetType().Name}\")");
            switch (packet)
            {
            case PBEMatchCancelledPacket _:
            {
                BattleView.AddMessage("Match cancelled!", messageBox: false);
                break;
            }

            case PBEPlayerJoinedPacket pjp:
            {
                int id = pjp.BattleId;
                if (pjp.IsMe)
                {
                    BattleId = id;
                    if (id < 2)
                    {
                        Team           = Battle.Teams[id];
                        ShowRawValues0 = id == 0;
                        ShowRawValues1 = id == 1;
                    }
                }
                else
                {
                    BattleView.AddMessage(string.Format("{0} joined the game.", pjp.TrainerName), messageBox: false);
                }
                if (id < 2)
                {
                    Battle.Teams[id].TrainerName = pjp.TrainerName;
                }
                Send(new PBEResponsePacket());
                break;
            }

            case PBEPartyRequestPacket _:
            {
                Send(new PBEPartyResponsePacket(_teamShell));
                break;
            }

            case PBEActionsRequestPacket _:
            case PBESwitchInRequestPacket _:
            case PBEWinnerPacket _:
            {
                Battle.Events.Add(packet);
                StartPacketThread();
                Send(new PBEResponsePacket());
                break;
            }

            default:
            {
                Battle.Events.Add(packet);
                Send(new PBEResponsePacket());
                break;
            }
            }
        }
示例#2
0
 private void SwitchesLoop()
 {
     if (_index == SwitchesRequired)
     {
         _bv.Actions.SwitchesBuilder = null;
         _onSwitchesReady(_switches);
         _onSwitchesReady = null !;
     }
     else
     {
         _bv.AddMessage($"You must send in {SwitchesRequired - _index} Pokémon.", messageLog: false);
         _bv.Actions.DisplaySwitches(_index);
     }
 }
示例#3
0
 private void ActionsLoop()
 {
     if (_index == _pkmn.Length)
     {
         _bv.Actions.ActionsBuilder = null;
         _onActionsReady(_actions);
         _onActionsReady = null !;
     }
     else
     {
         PBEBattlePokemon pkmn = _pkmn[_index];
         _bv.AddMessage($"What will {pkmn.Nickname} do?", messageLog: false);
         _bv.Actions.DisplayActions(_index, pkmn);
     }
 }
示例#4
0
 public void SwitchesLoop(bool begin)
 {
     if (begin)
     {
         Switches.Clear();
         StandBy.Clear();
         PositionStandBy.Clear();
     }
     else
     {
         _switchesRequired--;
     }
     if (_switchesRequired == 0)
     {
         OnSwitchesReady();
     }
     else
     {
         BattleView.AddMessage($"You must send in {_switchesRequired} Pokémon.", messageLog: false);
         BattleView.Actions.DisplaySwitches();
     }
 }
示例#5
0
        public void ActionsLoop(bool begin)
        {
            if (begin)
            {
                foreach (PBEBattlePokemon pkmn in Trainer.Party)
                {
                    pkmn.TurnAction = null;
                }
                _actions.Clear();
                _actions.AddRange(Trainer.ActiveBattlersOrdered);
                StandBy.Clear();
            }
            int i = _actions.FindIndex(p => p.TurnAction == null);

            if (i == -1)
            {
                OnActionsReady(_actions.Select(p => p.TurnAction).ToArray());
            }
            else
            {
                BattleView.AddMessage($"What will {_actions[i].Nickname} do?", messageLog: false);
                BattleView.Actions.DisplayActions(_actions[i]);
            }
        }
示例#6
0
 private void OnDisconnected(object sender, EventArgs e)
 {
     Debug.WriteLine("Disconnected from host");
     BattleView.AddMessage("Disconnected from host.", messageBox: false);
 }
示例#7
0
 private void OnConnected()
 {
     Debug.WriteLine("Connected to {0}", _client.RemoteIP);
     BattleView.AddMessage("Connected to host.", messageBox: false);
 }
示例#8
0
 protected override void OnSwitchesReady()
 {
     BattleView.AddMessage($"Waiting for {(Team.OpposingTeam.SwitchInsRequired > 0 ? Team.OpposingTeam.TrainerName : "host")}...", messageLog: false);
     Send(new PBESwitchInResponsePacket(Switches));
 }
示例#9
0
 protected override void OnActionsReady(PBETurnAction[] acts)
 {
     BattleView.AddMessage($"Waiting for {Team.OpposingTeam.TrainerName}...", messageLog: false);
     Send(new PBEActionsResponsePacket(acts));
 }
        // Returns true if the next packet should be run immediately
        protected virtual bool ProcessPacket(IPBEPacket packet)
        {
            switch (packet)
            {
            case PBEPkmnEXPChangedPacket _:
            case PBEMoveLockPacket _:
            case PBEMovePPChangedPacket _:
            case PBEIllusionPacket _:
            case PBETransformPacket _:
            case PBEBattlePacket _:
            case PBEActionsRequestPacket _:
            case PBESwitchInRequestPacket _: return(true);

            /*case PBEPkmnEXPChangedPacket pecp:
             * {
             *  PBEBattlePokemon pokemon = pecp.PokemonTrainer.GetPokemon(pecp.Pokemon);
             *  if (pokemon.FieldPosition != PBEFieldPosition.None)
             *  {
             *      BattleView.Field.UpdatePokemon(pokemon, true, false);
             *  }
             *  break;
             * }*/// Commented out because we don't have EXP bars
            case PBEPkmnFaintedPacket pfp:
            {
                PBEBattlePokemon pokemon = pfp.PokemonTrainer.GetPokemon(pfp.Pokemon);
                BattleView.Field.HidePokemon(pokemon, pfp.OldPosition);
                break;
            }

            case PBEPkmnFaintedPacket_Hidden pfph:
            {
                PBEBattlePokemon pokemon = pfph.PokemonTrainer.GetPokemon(pfph.OldPosition);
                BattleView.Field.HidePokemon(pokemon, pfph.OldPosition);
                break;
            }

            case IPBEPkmnFormChangedPacket pfcp:
            {
                PBEBattlePokemon pokemon = pfcp.PokemonTrainer.GetPokemon(pfcp.Pokemon);
                BattleView.Field.UpdatePokemon(pokemon, true, true);
                break;
            }

            case IPBEPkmnHPChangedPacket phcp:
            {
                PBEBattlePokemon pokemon = phcp.PokemonTrainer.GetPokemon(phcp.Pokemon);
                BattleView.Field.UpdatePokemon(pokemon, true, false);
                break;
            }

            case PBEPkmnLevelChangedPacket plcp:
            {
                PBEBattlePokemon pokemon = plcp.PokemonTrainer.GetPokemon(plcp.Pokemon);
                if (pokemon.FieldPosition != PBEFieldPosition.None)
                {
                    BattleView.Field.UpdatePokemon(pokemon, true, false);
                }
                break;
            }

            case IPBEPkmnSwitchInPacket psip:
            {
                if (!psip.Forced)
                {
                    foreach (IPBEPkmnSwitchInInfo_Hidden info in psip.SwitchIns)
                    {
                        BattleView.Field.ShowPokemon(psip.Trainer.GetPokemon(info.FieldPosition));
                    }
                }
                break;
            }

            case PBEPkmnSwitchOutPacket psop:
            {
                PBEBattlePokemon pokemon = psop.PokemonTrainer.GetPokemon(psop.Pokemon);
                BattleView.Field.HidePokemon(pokemon, psop.OldPosition);
                break;
            }

            case PBEPkmnSwitchOutPacket_Hidden psoph:
            {
                PBEBattlePokemon pokemon = psoph.PokemonTrainer.GetPokemon(psoph.OldPosition);
                BattleView.Field.HidePokemon(pokemon, psoph.OldPosition);
                break;
            }

            case PBEStatus1Packet s1p:
            {
                PBEBattlePokemon status1Receiver = s1p.Status1ReceiverTrainer.GetPokemon(s1p.Status1Receiver);
                BattleView.Field.UpdatePokemon(status1Receiver, true, false);
                break;
            }

            case PBEStatus2Packet s2p:
            {
                PBEBattlePokemon status2Receiver = s2p.Status2ReceiverTrainer.GetPokemon(s2p.Status2Receiver);
                switch (s2p.Status2)
                {
                case PBEStatus2.Airborne: BattleView.Field.UpdatePokemon(status2Receiver, false, true); break;

                case PBEStatus2.Disguised:
                {
                    switch (s2p.StatusAction)
                    {
                    case PBEStatusAction.Ended: BattleView.Field.UpdatePokemon(status2Receiver, true, true); break;
                    }
                    break;
                }

                case PBEStatus2.ShadowForce: BattleView.Field.UpdatePokemon(status2Receiver, false, true); break;

                case PBEStatus2.Substitute:
                {
                    switch (s2p.StatusAction)
                    {
                    case PBEStatusAction.Added:
                    case PBEStatusAction.Ended: BattleView.Field.UpdatePokemon(status2Receiver, false, true); break;
                    }
                    break;
                }

                case PBEStatus2.Transformed:
                {
                    switch (s2p.StatusAction)
                    {
                    case PBEStatusAction.Added: BattleView.Field.UpdatePokemon(status2Receiver, false, true); break;
                    }
                    break;
                }

                case PBEStatus2.Underground: BattleView.Field.UpdatePokemon(status2Receiver, false, true); break;

                case PBEStatus2.Underwater: BattleView.Field.UpdatePokemon(status2Receiver, false, true); break;
                }
                break;
            }

            case PBEWeatherPacket wp:
            {
                switch (wp.WeatherAction)
                {
                case PBEWeatherAction.Added:
                case PBEWeatherAction.Ended: BattleView.Field.UpdateWeather(); break;
                }
                break;
            }

            case IPBEWildPkmnAppearedPacket wpap:
            {
                PBETrainer wildTrainer = Battle.Teams[1].Trainers[0];
                foreach (IPBEPkmnAppearedInfo_Hidden info in wpap.Pokemon)
                {
                    BattleView.Field.ShowPokemon(wildTrainer.GetPokemon(info.FieldPosition));
                }
                break;
            }

            case IPBEAutoCenterPacket acp:
            {
                PBEBattlePokemon pokemon0 = acp is IPBEAutoCenterPacket_0 acp0
                        ? acp.Pokemon0Trainer.GetPokemon(acp0.Pokemon0)
                        : acp.Pokemon0Trainer.GetPokemon(acp.Pokemon0OldPosition);

                PBEBattlePokemon pokemon1 = acp is IPBEAutoCenterPacket_1 acp1
                        ? acp.Pokemon1Trainer.GetPokemon(acp1.Pokemon1)
                        : acp.Pokemon1Trainer.GetPokemon(acp.Pokemon1OldPosition);

                BattleView.Field.MovePokemon(pokemon0, acp.Pokemon0OldPosition);
                BattleView.Field.MovePokemon(pokemon1, acp.Pokemon1OldPosition);
                break;
            }

            case PBETurnBeganPacket tbp:
            {
                BattleView.AddMessage($"Turn {tbp.TurnNumber}", messageBox: false);
                return(true);
            }
            }
            string?message = PBEBattle.GetDefaultMessage(Battle, packet, showRawHP: !HideNonOwned, userTrainer: Trainer);

            if (string.IsNullOrEmpty(message))
            {
                return(true);
            }
            BattleView.AddMessage(message);
            return(false);
        }