public void TeamProtection_Works(PBEMove move, PBEMove move2, PBETeamStatus teamStatus) { #region Setup PBERandom.SetSeed(0); PBESettings settings = PBESettings.DefaultSettings; var p0 = new TestPokemonCollection(1); p0[0] = new TestPokemon(settings, PBESpecies.Mienshao, 0, 100, move); var p1 = new TestPokemonCollection(1); p1[0] = new TestPokemon(settings, PBESpecies.Lucario, 0, 100, move2); var battle = new PBEBattle(PBEBattleFormat.Single, settings, new PBETrainerInfo(p0, "Trainer 0"), new PBETrainerInfo(p1, "Trainer 1")); battle.OnNewEvent += PBEBattle.ConsoleBattleEventHandler; battle.Begin(); PBETrainer t0 = battle.Trainers[0]; PBETrainer t1 = battle.Trainers[1]; PBEBattlePokemon mienshao = t0.Party[0]; PBEBattlePokemon lucario = t1.Party[0]; #endregion #region Use move and check Assert.True(PBEBattle.SelectActionsIfValid(t0, new PBETurnAction(mienshao, move, PBETurnTarget.AllyCenter))); Assert.True(PBEBattle.SelectActionsIfValid(t1, new PBETurnAction(lucario, move2, PBETurnTarget.FoeCenter))); battle.RunTurn(); Assert.True(battle.VerifyTeamStatusHappened(t0.Team, teamStatus, PBETeamStatusAction.Damage, damageVictim: mienshao) && !t0.Team.TeamStatus.HasFlag(teamStatus)); #endregion #region Cleanup battle.OnNewEvent -= PBEBattle.ConsoleBattleEventHandler; #endregion }
} // PBEFieldPosition.None means no victim public PBETeamStatusPacket(PBETeam team, PBETeamStatus teamStatus, PBETeamStatusAction teamStatusAction, PBEPokemon damageVictim) { var bytes = new List <byte>(); bytes.AddRange(BitConverter.GetBytes(Code)); bytes.Add((Team = team).Id); bytes.Add((byte)(TeamStatus = teamStatus)); bytes.Add((byte)(TeamStatusAction = teamStatusAction)); bytes.Add((byte)(DamageVictim = damageVictim == null ? PBEFieldPosition.None : damageVictim.FieldPosition)); Buffer = BitConverter.GetBytes((short)bytes.Count).Concat(bytes); }
internal PBETeamStatusPacket(PBETeam team, PBETeamStatus teamStatus, PBETeamStatusAction teamStatusAction) { using (var ms = new MemoryStream()) using (var w = new EndianBinaryWriter(ms, encoding: EncodingType.UTF16)) { w.Write(Code); w.Write((Team = team).Id); w.Write(TeamStatus = teamStatus); w.Write(TeamStatusAction = teamStatusAction); Data = new ReadOnlyCollection <byte>(ms.ToArray()); } }
} // PBEFieldPosition.None means no victim internal PBETeamStatusPacket(PBETeam team, PBETeamStatus teamStatus, PBETeamStatusAction teamStatusAction, PBEPokemon damageVictim) { using (var ms = new MemoryStream()) using (var w = new EndianBinaryWriter(ms, encoding: EncodingType.UTF16)) { w.Write(Code); w.Write((Team = team).Id); w.Write(TeamStatus = teamStatus); w.Write(TeamStatusAction = teamStatusAction); w.Write(DamageVictim = damageVictim == null ? PBEFieldPosition.None : damageVictim.FieldPosition); Data = new ReadOnlyCollection <byte>(ms.ToArray()); } }
internal PBETeamStatusPacket(PBETeam team, PBETeamStatus teamStatus, PBETeamStatusAction teamStatusAction, PBEBattlePokemon damageVictim = null) { using (var ms = new MemoryStream()) using (var w = new EndianBinaryWriter(ms, encoding: EncodingType.UTF16)) { w.Write(Code); w.Write((Team = team).Id); w.Write(TeamStatus = teamStatus); w.Write(TeamStatusAction = teamStatusAction); w.Write(damageVictim != null); if (damageVictim != null) { w.Write((DamageVictimTrainer = damageVictim.Trainer).Id); w.Write(DamageVictim = damageVictim.FieldPosition); } Data = new ReadOnlyCollection <byte>(ms.GetBuffer()); } }
public static bool VerifyTeamStatusHappened(this PBEBattle battle, PBETeam team, PBETeamStatus teamStatus, PBETeamStatusAction teamStatusAction, PBEBattlePokemon damageVictim = null) { foreach (IPBEPacket packet in battle.Events) { if (packet is PBETeamStatusPacket tsp && tsp.Team == team && tsp.TeamStatus == teamStatus && tsp.TeamStatusAction == teamStatusAction && tsp.DamageVictimTrainer?.TryGetPokemon(tsp.DamageVictim) == damageVictim) { return(true); } } return(false); }