2018-06-09 15:12:47 +00:00
|
|
|
|
using System;
|
2018-04-04 02:34:24 +00:00
|
|
|
|
using System.Linq;
|
2020-03-04 02:23:00 +00:00
|
|
|
|
using FluentAssertions;
|
2018-03-28 02:45:22 +00:00
|
|
|
|
using PKHeX.Core;
|
2018-11-06 23:25:35 +00:00
|
|
|
|
using Xunit;
|
2018-03-28 02:45:22 +00:00
|
|
|
|
|
|
|
|
|
namespace PKHeX.Tests.Simulator
|
|
|
|
|
{
|
|
|
|
|
public class ShowdownSetTests
|
|
|
|
|
{
|
2018-05-20 03:48:03 +00:00
|
|
|
|
static ShowdownSetTests()
|
|
|
|
|
{
|
2018-05-27 22:57:28 +00:00
|
|
|
|
if (!EncounterEvent.Initialized)
|
|
|
|
|
EncounterEvent.RefreshMGDB();
|
2018-05-20 03:48:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-06 23:25:35 +00:00
|
|
|
|
[Fact]
|
2018-03-28 02:45:22 +00:00
|
|
|
|
public void SimulatorGetParse()
|
|
|
|
|
{
|
2018-05-12 04:44:09 +00:00
|
|
|
|
foreach (var setstr in Sets)
|
|
|
|
|
{
|
|
|
|
|
var set = new ShowdownSet(setstr).Text;
|
|
|
|
|
var lines = set.Split('\n').Select(z => z.Trim());
|
2018-11-06 23:25:35 +00:00
|
|
|
|
Assert.True(lines.All(z => setstr.Contains(z)), setstr);
|
2018-05-12 04:44:09 +00:00
|
|
|
|
}
|
2018-03-28 02:45:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-06 23:25:35 +00:00
|
|
|
|
[Fact]
|
2018-03-28 02:45:22 +00:00
|
|
|
|
public void SimulatorGetEncounters()
|
|
|
|
|
{
|
|
|
|
|
var set = new ShowdownSet(SetGlaceonUSUMTutor);
|
2020-12-11 04:42:30 +00:00
|
|
|
|
var pk7 = new PK7 {Species = set.Species, Form = set.Form, Moves = set.Moves};
|
2020-06-28 04:36:53 +00:00
|
|
|
|
var encounters = EncounterMovesetGenerator.GenerateEncounters(pk7, set.Moves, GameVersion.MN);
|
|
|
|
|
Assert.True(!encounters.Any());
|
2018-03-28 02:45:22 +00:00
|
|
|
|
pk7.HT_Name = "PKHeX";
|
2020-06-28 04:36:53 +00:00
|
|
|
|
encounters = EncounterMovesetGenerator.GenerateEncounters(pk7, set.Moves, GameVersion.MN);
|
|
|
|
|
var first = encounters.FirstOrDefault();
|
2019-09-24 01:13:51 +00:00
|
|
|
|
Assert.NotNull(first);
|
2018-03-29 03:40:07 +00:00
|
|
|
|
|
2020-11-14 16:20:48 +00:00
|
|
|
|
var egg = (EncounterEgg)first!;
|
2019-11-27 00:55:28 +00:00
|
|
|
|
var info = new SimpleTrainerInfo(GameVersion.SN);
|
2018-03-29 03:40:07 +00:00
|
|
|
|
var pk = egg.ConvertToPKM(info);
|
2018-11-06 23:25:35 +00:00
|
|
|
|
Assert.True(pk.Species != set.Species);
|
2018-03-29 03:40:07 +00:00
|
|
|
|
|
|
|
|
|
var la = new LegalityAnalysis(pk);
|
2018-11-06 23:25:35 +00:00
|
|
|
|
Assert.True(la.Valid);
|
2018-03-30 04:04:05 +00:00
|
|
|
|
|
2020-11-02 21:03:08 +00:00
|
|
|
|
var test = EncounterMovesetGenerator.GenerateEncounters(pk7, info).ToList();
|
2018-04-01 03:37:36 +00:00
|
|
|
|
foreach (var t in test)
|
|
|
|
|
{
|
2020-11-02 21:03:08 +00:00
|
|
|
|
var convert = t.ConvertToPKM(info);
|
|
|
|
|
var la2 = new LegalityAnalysis(convert);
|
2018-11-06 23:25:35 +00:00
|
|
|
|
Assert.True(la2.Valid);
|
2018-04-01 03:37:36 +00:00
|
|
|
|
}
|
2018-03-28 02:45:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-06 23:25:35 +00:00
|
|
|
|
[Fact]
|
2018-05-20 03:48:03 +00:00
|
|
|
|
public void SimulatorGetWC3()
|
|
|
|
|
{
|
|
|
|
|
var set = new ShowdownSet(SetROCKSMetang);
|
2020-12-11 04:42:30 +00:00
|
|
|
|
var pk3 = new PK3 { Species = set.Species, Form = set.Form, Moves = set.Moves };
|
2018-05-20 03:48:03 +00:00
|
|
|
|
var encs = EncounterMovesetGenerator.GenerateEncounters(pk3, set.Moves, GameVersion.R);
|
2018-11-06 23:25:35 +00:00
|
|
|
|
Assert.True(encs.Any());
|
2018-05-20 03:48:03 +00:00
|
|
|
|
encs = EncounterMovesetGenerator.GenerateEncounters(pk3, set.Moves, GameVersion.R);
|
|
|
|
|
var first = encs.FirstOrDefault();
|
2019-09-24 01:13:51 +00:00
|
|
|
|
Assert.NotNull(first);
|
2018-05-20 03:48:03 +00:00
|
|
|
|
|
2020-11-14 16:20:48 +00:00
|
|
|
|
var wc3 = (WC3)first!;
|
2019-11-27 00:55:28 +00:00
|
|
|
|
var info = new SimpleTrainerInfo(GameVersion.R);
|
2018-05-20 03:48:03 +00:00
|
|
|
|
var pk = wc3.ConvertToPKM(info);
|
|
|
|
|
|
|
|
|
|
var la = new LegalityAnalysis(pk);
|
2018-11-06 23:25:35 +00:00
|
|
|
|
Assert.True(la.Valid);
|
2018-05-20 03:48:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-06 23:25:35 +00:00
|
|
|
|
[Fact]
|
2018-05-20 16:06:32 +00:00
|
|
|
|
public void SimulatorGetCelebi()
|
|
|
|
|
{
|
|
|
|
|
var set = new ShowdownSet(SetCelebi);
|
2020-12-11 04:42:30 +00:00
|
|
|
|
var pk7 = new PK7 { Species = set.Species, Form = set.Form, Moves = set.Moves };
|
2018-05-20 16:06:32 +00:00
|
|
|
|
var encs = EncounterMovesetGenerator.GenerateEncounters(pk7, set.Moves, GameVersion.X);
|
2018-11-06 23:25:35 +00:00
|
|
|
|
Assert.True(encs.Any());
|
2018-05-20 16:06:32 +00:00
|
|
|
|
encs = EncounterMovesetGenerator.GenerateEncounters(pk7, set.Moves, GameVersion.X);
|
|
|
|
|
var first = encs.FirstOrDefault();
|
2019-09-24 01:13:51 +00:00
|
|
|
|
Assert.NotNull(first);
|
2018-05-20 16:06:32 +00:00
|
|
|
|
|
2020-11-14 16:20:48 +00:00
|
|
|
|
var enc = first!;
|
2019-11-27 00:55:28 +00:00
|
|
|
|
var info = new SimpleTrainerInfo(GameVersion.SN);
|
2018-05-20 16:06:32 +00:00
|
|
|
|
var pk = enc.ConvertToPKM(info);
|
|
|
|
|
|
|
|
|
|
var la = new LegalityAnalysis(pk);
|
2018-11-06 23:25:35 +00:00
|
|
|
|
Assert.True(la.Valid);
|
2018-05-20 16:06:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-06 23:25:35 +00:00
|
|
|
|
[Fact]
|
2018-08-30 04:03:30 +00:00
|
|
|
|
public void SimulatorGetSplitBreed()
|
|
|
|
|
{
|
|
|
|
|
var set = new ShowdownSet(SetMunchSnorLax);
|
2020-12-11 04:42:30 +00:00
|
|
|
|
var pk7 = new PK7 { Species = set.Species, Form = set.Form, Moves = set.Moves, HT_Name = "PKHeX" }; // !! specify the HT name, we need tutors for this one
|
2018-08-30 04:03:30 +00:00
|
|
|
|
var encs = EncounterMovesetGenerator.GenerateEncounters(pk7, set.Moves, GameVersion.SN).ToList();
|
2018-11-06 23:25:35 +00:00
|
|
|
|
Assert.True(encs.Count > 0);
|
|
|
|
|
Assert.True(encs.All(z => z.Species > 150));
|
2018-08-30 04:03:30 +00:00
|
|
|
|
|
2019-11-27 00:55:28 +00:00
|
|
|
|
var info = new SimpleTrainerInfo(GameVersion.SN);
|
2018-08-30 04:03:30 +00:00
|
|
|
|
var enc = encs[0];
|
|
|
|
|
var pk = enc.ConvertToPKM(info);
|
|
|
|
|
|
|
|
|
|
var la = new LegalityAnalysis(pk);
|
2018-11-06 23:25:35 +00:00
|
|
|
|
Assert.True(la.Valid);
|
2018-08-30 04:03:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-06 23:25:35 +00:00
|
|
|
|
[Fact]
|
2018-10-01 23:48:37 +00:00
|
|
|
|
public void SimulatorGetVCEgg1()
|
|
|
|
|
{
|
|
|
|
|
var set = new ShowdownSet(SetSlowpoke12);
|
2020-12-11 04:42:30 +00:00
|
|
|
|
var pk7 = new PK7 { Species = set.Species, Form = set.Form, Moves = set.Moves, HT_Name = "PKHeX" };
|
2018-10-01 23:48:37 +00:00
|
|
|
|
var encs = EncounterMovesetGenerator.GenerateEncounters(pk7, set.Moves, GameVersion.GD).ToList();
|
2018-11-06 23:25:35 +00:00
|
|
|
|
Assert.True(encs.Count > 0);
|
2018-10-01 23:48:37 +00:00
|
|
|
|
|
2019-11-27 00:55:28 +00:00
|
|
|
|
var info = new SimpleTrainerInfo(GameVersion.SN);
|
2018-10-01 23:48:37 +00:00
|
|
|
|
var enc = encs[0];
|
|
|
|
|
var pk = enc.ConvertToPKM(info);
|
|
|
|
|
|
|
|
|
|
var la = new LegalityAnalysis(pk);
|
2018-11-06 23:25:35 +00:00
|
|
|
|
Assert.True(la.Valid);
|
2018-10-01 23:48:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-06 23:25:35 +00:00
|
|
|
|
[Fact]
|
2018-05-20 15:19:03 +00:00
|
|
|
|
public void SimulatorGetSmeargle()
|
|
|
|
|
{
|
|
|
|
|
var set = new ShowdownSet(SetSmeargle);
|
2020-12-11 04:42:30 +00:00
|
|
|
|
var pk7 = new PK7 { Species = set.Species, Form = set.Form, Moves = set.Moves };
|
2018-05-20 15:19:03 +00:00
|
|
|
|
var encs = EncounterMovesetGenerator.GenerateEncounters(pk7, set.Moves, GameVersion.MN);
|
2018-11-06 23:25:35 +00:00
|
|
|
|
Assert.True(encs.Any());
|
2018-05-20 15:19:03 +00:00
|
|
|
|
encs = EncounterMovesetGenerator.GenerateEncounters(pk7, set.Moves, GameVersion.MN);
|
|
|
|
|
var first = encs.FirstOrDefault();
|
2018-11-06 23:25:35 +00:00
|
|
|
|
Assert.NotNull(first);
|
2018-05-20 15:19:03 +00:00
|
|
|
|
|
2020-11-14 16:20:48 +00:00
|
|
|
|
var enc = first!;
|
2019-11-27 00:55:28 +00:00
|
|
|
|
var info = new SimpleTrainerInfo(GameVersion.SN);
|
2018-05-20 15:19:03 +00:00
|
|
|
|
var pk = enc.ConvertToPKM(info);
|
|
|
|
|
|
|
|
|
|
var la = new LegalityAnalysis(pk);
|
2018-11-06 23:25:35 +00:00
|
|
|
|
Assert.True(la.Valid);
|
2018-05-20 15:19:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-06 23:25:35 +00:00
|
|
|
|
[Fact]
|
2018-06-09 15:12:47 +00:00
|
|
|
|
public void SimulatorParseMultiple()
|
|
|
|
|
{
|
|
|
|
|
var text = string.Join("\r\n\r\n", Sets);
|
|
|
|
|
var lines = text.Split(new[] {"\r\n", "\n"}, StringSplitOptions.None);
|
2020-12-29 05:42:54 +00:00
|
|
|
|
var sets = ShowdownParsing.GetShowdownSets(lines);
|
2018-11-06 23:25:35 +00:00
|
|
|
|
Assert.True(sets.Count() == Sets.Length);
|
2018-06-09 15:12:47 +00:00
|
|
|
|
|
2020-12-29 05:42:54 +00:00
|
|
|
|
sets = ShowdownParsing.GetShowdownSets(Enumerable.Empty<string>());
|
2018-11-06 23:25:35 +00:00
|
|
|
|
Assert.True(!sets.Any());
|
2018-06-09 15:12:47 +00:00
|
|
|
|
|
2020-12-29 05:42:54 +00:00
|
|
|
|
sets = ShowdownParsing.GetShowdownSets(new [] {"", " ", " "});
|
2018-11-06 23:25:35 +00:00
|
|
|
|
Assert.True(!sets.Any());
|
2018-06-09 15:12:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-04 02:23:00 +00:00
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(SetDuplicateMoves, 3)]
|
|
|
|
|
public void SimulatorParseDuplicate(string text, int moveCount)
|
|
|
|
|
{
|
|
|
|
|
var set = new ShowdownSet(text);
|
|
|
|
|
var actual = set.Moves.Count(z => z != 0);
|
|
|
|
|
actual.Should().Be(moveCount);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-14 04:39:35 +00:00
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(LowLevelElectrode)]
|
|
|
|
|
public void SimulatorParseEncounter(string text)
|
|
|
|
|
{
|
|
|
|
|
var set = new ShowdownSet(text);
|
2020-12-11 04:42:30 +00:00
|
|
|
|
var pk7 = new PK7 { Species = set.Species, Form = set.Form, Moves = set.Moves, CurrentLevel = set.Level };
|
2020-03-14 04:39:35 +00:00
|
|
|
|
var encs = EncounterMovesetGenerator.GenerateEncounters(pk7, set.Moves);
|
2020-12-22 06:33:48 +00:00
|
|
|
|
var tr3 = encs.First(z => z is EncounterTrade3);
|
2021-03-16 06:51:58 +00:00
|
|
|
|
var pk3 = tr3.ConvertToPKM(new SAV3FRLG());
|
2020-03-14 04:39:35 +00:00
|
|
|
|
|
|
|
|
|
var la = new LegalityAnalysis(pk3);
|
|
|
|
|
la.Valid.Should().BeTrue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private const string LowLevelElectrode =
|
|
|
|
|
@"BOLICHI (Electrode)
|
|
|
|
|
IVs: 19 HP / 16 Atk / 18 Def / 25 SpA / 19 SpD / 25 Spe
|
|
|
|
|
Ability: Static
|
|
|
|
|
Level: 3
|
|
|
|
|
Hasty Nature
|
|
|
|
|
- Charge
|
|
|
|
|
- Tackle
|
|
|
|
|
- Screech
|
|
|
|
|
- Sonic Boom";
|
|
|
|
|
|
2020-03-04 02:23:00 +00:00
|
|
|
|
private const string SetDuplicateMoves =
|
|
|
|
|
@"Kingler-Gmax @ Master Ball
|
|
|
|
|
Ability: Sheer Force
|
|
|
|
|
Shiny: Yes
|
|
|
|
|
EVs: 252 Atk / 4 SpD / 252 Spe
|
|
|
|
|
Jolly Nature
|
|
|
|
|
- Crabhammer
|
|
|
|
|
- Rock Slide
|
|
|
|
|
- Rock Slide
|
|
|
|
|
- X-Scissor";
|
|
|
|
|
|
2018-05-20 03:48:03 +00:00
|
|
|
|
private const string SetROCKSMetang =
|
|
|
|
|
@"Metang
|
|
|
|
|
IVs: 20 HP / 3 Atk / 26 Def / 1 SpA / 6 SpD / 8 Spe
|
|
|
|
|
Ability: Clear Body
|
|
|
|
|
Level: 30
|
|
|
|
|
Adamant Nature
|
|
|
|
|
- Take Down
|
|
|
|
|
- Confusion
|
|
|
|
|
- Metal Claw
|
|
|
|
|
- Refresh";
|
|
|
|
|
|
2018-03-28 02:45:22 +00:00
|
|
|
|
private const string SetGlaceonUSUMTutor =
|
|
|
|
|
@"Glaceon (F) @ Assault Vest
|
|
|
|
|
IVs: 0 Atk
|
|
|
|
|
EVs: 252 HP / 252 SpA / 4 SpD
|
|
|
|
|
Ability: Ice Body
|
|
|
|
|
Level: 100
|
|
|
|
|
Shiny: Yes
|
|
|
|
|
Modest Nature
|
|
|
|
|
- Blizzard
|
|
|
|
|
- Water Pulse
|
|
|
|
|
- Shadow Ball
|
|
|
|
|
- Hyper Voice";
|
|
|
|
|
|
2018-05-20 15:19:03 +00:00
|
|
|
|
private const string SetSmeargle =
|
|
|
|
|
@"Smeargle @ Focus Sash
|
|
|
|
|
Ability: Own Tempo
|
|
|
|
|
EVs: 248 HP / 8 Def / 252 Spe
|
|
|
|
|
Jolly Nature
|
|
|
|
|
- Sticky Web
|
|
|
|
|
- Nuzzle
|
|
|
|
|
- Taunt
|
|
|
|
|
- Whirlwind";
|
|
|
|
|
|
2018-05-20 16:06:32 +00:00
|
|
|
|
private const string SetCelebi =
|
|
|
|
|
@"Celebi @ Toxic Orb
|
|
|
|
|
Ability: Natural Cure
|
|
|
|
|
Jolly Nature
|
|
|
|
|
- Recover
|
|
|
|
|
- Heal Bell
|
|
|
|
|
- Safeguard
|
|
|
|
|
- Hold Back";
|
|
|
|
|
|
2018-06-16 03:30:23 +00:00
|
|
|
|
private const string SetNicknamedTypeNull =
|
|
|
|
|
@"Reliance (Type: Null) @ Eviolite
|
|
|
|
|
EVs: 252 HP / 4 Def / 252 SpD
|
|
|
|
|
Ability: Battle Armor
|
|
|
|
|
Careful Nature
|
|
|
|
|
- Facade
|
|
|
|
|
- Swords Dance
|
|
|
|
|
- Sleep Talk
|
|
|
|
|
- Rest";
|
|
|
|
|
|
2018-08-30 04:03:30 +00:00
|
|
|
|
private const string SetMunchSnorLax =
|
|
|
|
|
@"Snorlax @ Choice Band
|
|
|
|
|
Ability: Thick Fat
|
|
|
|
|
Level: 50
|
|
|
|
|
EVs: 84 HP / 228 Atk / 180 Def / 12 SpD / 4 Spe
|
|
|
|
|
Adamant Nature
|
|
|
|
|
- Double-Edge
|
|
|
|
|
- High Horsepower
|
|
|
|
|
- Self-Destruct
|
|
|
|
|
- Fire Punch";
|
|
|
|
|
|
2018-10-01 23:48:37 +00:00
|
|
|
|
private const string SetSlowpoke12 =
|
|
|
|
|
@"Threat (Slowpoke) @ Eviolite
|
|
|
|
|
Ability: Regenerator
|
|
|
|
|
Shiny: Yes
|
|
|
|
|
EVs: 248 HP / 252 Atk / 8 SpD
|
|
|
|
|
Adamant Nature
|
|
|
|
|
- Body Slam
|
|
|
|
|
- Earthquake
|
|
|
|
|
- Belly Drum
|
|
|
|
|
- Iron Tail";
|
|
|
|
|
|
2018-05-12 04:44:09 +00:00
|
|
|
|
private static readonly string[] Sets =
|
|
|
|
|
{
|
|
|
|
|
SetGlaceonUSUMTutor,
|
2018-06-16 03:30:23 +00:00
|
|
|
|
SetNicknamedTypeNull,
|
2018-08-30 04:03:30 +00:00
|
|
|
|
SetMunchSnorLax,
|
2018-05-12 04:44:09 +00:00
|
|
|
|
|
2018-05-20 03:48:03 +00:00
|
|
|
|
@"Greninja @ Choice Specs
|
|
|
|
|
Ability: Battle Bond
|
|
|
|
|
EVs: 252 SpA / 4 SpD / 252 Spe
|
|
|
|
|
Timid Nature
|
|
|
|
|
- Hydro Pump
|
|
|
|
|
- Spikes
|
|
|
|
|
- Water Shuriken
|
2018-05-12 04:44:09 +00:00
|
|
|
|
- Dark Pulse",
|
|
|
|
|
};
|
2018-03-28 02:45:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|