public static PSXAPI.Request.Evs GetEvsSetPacket(string stat, System.Guid pokemonGuid, PokemonStats evs, int amount) { if (Stats.ContainsKey(stat.ToUpperInvariant())) { var packet = new PSXAPI.Request.Evs { Action = PSXAPI.Request.EvsAction.Skill, Pokemon = pokemonGuid }; switch (Stats[stat.ToUpperInvariant()]) { case StatType.Attack: packet.Atk = amount; packet.Def = evs.GetStat(StatType.Defence); packet.Hp = evs.GetStat(StatType.Health); packet.SpAtk = evs.GetStat(StatType.SpAttack); packet.SpDef = evs.GetStat(StatType.SpDefence); packet.Speed = evs.GetStat(StatType.Speed); break; case StatType.Health: packet.Atk = evs.GetStat(StatType.Attack); packet.Def = evs.GetStat(StatType.Defence); packet.Hp = amount; packet.SpAtk = evs.GetStat(StatType.SpAttack); packet.SpDef = evs.GetStat(StatType.SpDefence); packet.Speed = evs.GetStat(StatType.Speed); break; case StatType.SpAttack: packet.Atk = evs.GetStat(StatType.Attack); packet.Def = evs.GetStat(StatType.Defence); packet.Hp = evs.GetStat(StatType.Health); packet.SpAtk = amount; packet.SpDef = evs.GetStat(StatType.SpDefence); packet.Speed = evs.GetStat(StatType.Speed); break; case StatType.SpDefence: packet.Atk = evs.GetStat(StatType.Attack); packet.Def = evs.GetStat(StatType.Defence); packet.Hp = evs.GetStat(StatType.Health); packet.SpAtk = evs.GetStat(StatType.SpAttack); packet.SpDef = amount; packet.Speed = evs.GetStat(StatType.Speed); break; case StatType.Speed: packet.Atk = evs.GetStat(StatType.Attack); packet.Def = evs.GetStat(StatType.Defence); packet.Hp = evs.GetStat(StatType.Health); packet.SpAtk = evs.GetStat(StatType.SpAttack); packet.SpDef = evs.GetStat(StatType.SpDefence); packet.Speed = amount; break; case StatType.Defence: packet.Atk = evs.GetStat(StatType.Attack); packet.Def = amount; packet.Hp = evs.GetStat(StatType.Health); packet.SpAtk = evs.GetStat(StatType.SpAttack); packet.SpDef = evs.GetStat(StatType.SpDefence); packet.Speed = evs.GetStat(StatType.Speed); break; } return(packet); } return(null); }
private void HandleBattleRequest(PSXAPI.Response.Payload.BattleRequest request, bool isPlayerSide) { if (isPlayerSide) { var p1 = request; CurrentBattlingPokemonIndex = p1.RequestInfo.side.pokemon.ToList().FindIndex(x => x.active) + 1; UpdateBattlePokemon(p1.RequestInfo.side.pokemon); ResponseID = request.RequestID; PlayerBattleSide = p1.RequestInfo.side; UpdateSelectedPokemonIndex(); var pokemons = p1.RequestInfo.side.pokemon; PlayerRequest = p1.RequestInfo; if (p1.RequestInfo != null && p1.RequestInfo.active != null) { PlayerAcivePokemon = new List <SwitchedPokemon>(); foreach (var pActive in p1.RequestInfo.active) { if (pActive?.trainer?.ToLowerInvariant() != _playerName?.ToLowerInvariant()) { continue; } var mainPoke = pokemons.FirstOrDefault(x => x.personality == pActive?.personality); if (mainPoke != null) { mainPoke.moveData = pActive?.moves; PlayerAcivePokemon.Add(GetSwitchedPokemon(mainPoke)); } } } else { PlayerAcivePokemon = null; } RepeatAttack = PlayerAcivePokemon != null && PlayerAcivePokemon.Any(p => p.RepeatAttack); } else { var p2 = request; PokemonCount = p2.RequestInfo.side.pokemon.Length; var opponent = p2.RequestInfo.side.pokemon.ToList().Find(x => x.active); var Poke = GetSwitchedPokemon(opponent.details, opponent.condition); OpponentGender = Poke.Gender; OpponentId = Poke.ID; OpponentStats = new PokemonStats(opponent.stats, Poke.MaxHealth); IsShiny = Poke.Shiny; OpponentLevel = Poke.Level; OpponentStatus = Poke.Status; OpponentHealth = Poke.MaxHealth; CurrentHealth = Poke.Health; OpponentForme = Poke.Forme; if (!IsWild && opponent.trainer != null) { TrainerName = opponent.trainer; } ResponseID = p2.RequestID; var pokemons = p2.RequestInfo.side.pokemon; //OpponenetAllPokemon = new List<SwitchedPokemon>(); //foreach(var pkm in pokemons) //{ // OpponenetAllPokemon.Add(GetSwitchedPokemon(pkm)); //} if (p2.RequestInfo != null && p2.RequestInfo.active != null) { OpponentActivePokemon = new List <SwitchedPokemon>(); foreach (var opActive in p2.RequestInfo.active) { var main = pokemons.FirstOrDefault(x => x.personality == opActive.personality); if (main != null) { main.moveData = opActive.moves; var newPoke = GetSwitchedPokemon(main); OpponentActivePokemon.Add(newPoke); } } } else { OpponentActivePokemon = null; } } IsTrapped = GetActivePokemon?.maybeTrapped == true || GetActivePokemon?.maybeDisabled == true; }
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); } } } } }