示例#1
0
        private void HandleBattleRequest(PSXAPI.Response.Payload.BattleRequest request, bool isPlayerSide)
        {
            if (isPlayerSide)
            {
                var p1 = request;
                var active = p1.RequestInfo.active;
                var activePokemon = p1.RequestInfo.side.pokemon.ToList().Find(x => x.active);

                CurrentBattlingPokemonIndex = p1.RequestInfo.side.pokemon.ToList().FindIndex(x => x.active) + 1;

                UpdateBattleHealth(p1.RequestInfo.side.pokemon);

                ResponseID = request.RequestID;
                PlayerBattleSide = p1.RequestInfo.side;

                if (_team is null || _team.Count <= 0)
                    SelectedPokemonIndex = p1.RequestInfo.side.pokemon.ToList().IndexOf(activePokemon);
                else
                    SelectedPokemonIndex = _team.IndexOf(_team.Find(p => p.PokemonData.Pokemon.Payload.Personality == activePokemon.personality));
                UpdateSelectedPokemonIndex();
                var pokemons = p1.RequestInfo.side.pokemon;
                if (p1.RequestInfo is null) return;
                if (p1.RequestInfo.active is null is false && p1.RequestInfo.active.Length > 0)
                {
                    PlayerAcivePokemon = new SwitchedPokemon[p1.RequestInfo.active.Length];
                    for (var i = 0; i < p1.RequestInfo.active.Length; i++)
                    {
                        var condition = pokemons[i].condition;
                        var details = pokemons[i].details;
                        var newPoke = GetSwitchedPokemon(details, condition);
                        PlayerAcivePokemon[i] = newPoke;
                        PlayerAcivePokemon[i].Moves = p1.RequestInfo.active[i].moves;
                        PlayerAcivePokemon[i].Trainer = p1.RequestInfo.active[i].trainer;
                        PlayerAcivePokemon[i].Personality = p1.RequestInfo.active[i].personality;
                    }
                }
示例#2
0
        public static SwitchedPokemon GetSwitchedPokemon(string text, string hpstatus)
        {
            SwitchedPokemon switchPkmn = new SwitchedPokemon();

            switchPkmn.Shiny = text.ToLowerInvariant().Contains("shiny");

            string[] array = text.Split(new string[]
            {
                ", "
            }, StringSplitOptions.None);
            foreach (string text2 in array)
            {
                if (text2 == "F")
                {
                    switchPkmn.Gender = "F";
                }
                if (text2 == "M")
                {
                    switchPkmn.Gender = "M";
                }
                if (text2 != array[0] && text2.Length > 1 && text2.Substring(0, 1) == "L")
                {
                    switchPkmn.Level = Convert.ToInt32(text2.Substring(1));
                }
            }
            if (array[0].ToLower().Contains("-mega-x"))
            {
                switchPkmn.Forme = "-mega-x";
                array[0].Replace("-mega-x", "");
            }
            else if (array[0].ToLower().Contains("-mega-y"))
            {
                switchPkmn.Forme = "-mega-y";
                array[0].Replace("-mega-y", "");
            }
            else if (array[0].ToLower().Contains("-mega"))
            {
                switchPkmn.Forme = "-mega";
                array[0].Replace("-mega", "");
            }
            else if (array[0].ToLower().Contains("-primal"))
            {
                switchPkmn.Forme = "-primal";
                array[0].Replace("-primal", "");
            }
            else if (array[0].ToLowerInvariant().Contains("mimikyubusted"))
            {
                switchPkmn.Forme = "mimikyubusted";
                array[0].Replace("mimikyubusted", "");
            }
            else if (array[0].ToLowerInvariant().Contains("wishiwashischool"))
            {
                switchPkmn.Forme = "wishiwashischool";
                array[0].Replace("wishiwashischool", "");
            }
            switchPkmn.ID = PokemonManager.Instance.GetIdByName(array[0]);
            if (switchPkmn.Level == 0)
            {
                switchPkmn.Level = 100;
            }
            if (hpstatus == "")
            {
                hpstatus = "50/50";
            }
            array = hpstatus.Split(new string[]
            {
                " "
            }, StringSplitOptions.None);
            string[] array3 = array[0].Split(new string[]
            {
                "/"
            }, StringSplitOptions.None);
            if (array3.Length == 1)
            {
                switchPkmn.Health    = Convert.ToInt32(Regex.Replace(array3[0], "[^0-9.-]", string.Empty));
                switchPkmn.MaxHealth = 100;
            }
            else
            {
                switchPkmn.Health    = Convert.ToInt32(Regex.Replace(array3[0], "[^0-9.-]", string.Empty));
                switchPkmn.MaxHealth = Convert.ToInt32(Regex.Replace(array3[1], "[^0-9.-]", string.Empty));
            }
            if (array.Length > 1)
            {
                switchPkmn.Status = string.IsNullOrEmpty(array[1]) ? "OK" : array[1];
            }
            return(switchPkmn);
        }
示例#3
0
        public Battle(string playerName, PSXAPI.Response.Battle data, List<Pokemon> team)
        {
            IsUpdated = false;

            Data = data;

            _playerName = playerName;

            IsWild = data.CanCatch;

            IsFinished = data.Ended;

            _team = team;

            if (data.Mapping1 != null && !string.IsNullOrEmpty(playerName))
            {
                if (data.Mapping1.ToList().Any(name => name.ToLowerInvariant() == _playerName.ToLowerInvariant()))
                    PlayerSide = 1;
            }

            if (data.Mapping2 != null && !string.IsNullOrEmpty(playerName))
            {
                if (data.Mapping2.ToList().Any(name => name.ToLowerInvariant() == _playerName.ToLowerInvariant()))
                    PlayerSide = 2;
            }

            

            if (data.Request1 != null)
            {
                HandleBattleRequest(data.Request1, PlayerSide == 1);
            }
            if (data.Request2 != null)
            {
                HandleBattleRequest(data.Request2, PlayerSide == 2);
            }

            if (data.Log != null && data.Log.Length > 0)
            {
                var switchTxt = data.Log.ToList().Find(m => m.Contains("switch") && m.Split('|')[1] == "switch");
                if (!string.IsNullOrEmpty(switchTxt))
                {
                    string[] array = switchTxt.Split(new char[]
                    {
                        '|'
                    });
                    if (array.Length > 1)
                    {
                        SwitchedPokemon pokemon = null;
                        var pokeName = "";
                        var side = Convert.ToInt32(array[2].Substring(0, 2).Replace("p", "").Replace("a", "").Replace("b", "").Replace("c", ""));
                        var personality = 0;
                        if (array.Length >= 7)
                        {
                            pokemon = GetSwitchedPokemon(array[3], array[4]);
                            pokeName = array[5];
                            int.TryParse(array[6], out personality);
                        }
                        else
                        {
                            pokemon = GetSwitchedPokemon(array[3], string.Empty);
                            pokeName = array[4];
                            int.TryParse(array[5], out personality);
                        }

                        if (pokemon is null) return;

                        if (side == PlayerSide)
                        {
                            //player
                            var req = PlayerSide == 1 ? Data.Request1 : Data.Request2;
                            var index = PlayerBattleSide.pokemon.ToList().IndexOf(req.RequestInfo.side.pokemon.FirstOrDefault(x => x.personality == personality));
                            SelectedPokemonIndex = index < 0 ? SelectedPokemonIndex : index;
                            team[index].UpdateHealth(pokemon.Health, pokemon.MaxHealth);
                        }
                        else
                        {
                            //oppoenent
                            var req = PlayerSide == 1 ? Data.Request2 : Data.Request1;
                            var index = req.RequestInfo.side.pokemon.ToList().IndexOf(req.RequestInfo.side.pokemon.FirstOrDefault(x => x.personality == personality));
                            CurrentHealth = pokemon.Health;
                            OpponentHealth = pokemon.MaxHealth;
                            OpponentGender = pokemon.Gender;
                            OpponentId = pokemon.ID;
                            OpponentLevel = pokemon.Level;
                            OpponentStatus = pokemon.Status;
                            IsShiny = pokemon.Shiny;
                            if (index >= 0)
                                OpponentStats = new PokemonStats(req.RequestInfo.side.pokemon[index].stats, pokemon.MaxHealth);
                        }
                    }
                }
            }
        }