diff --git a/library/Library.csproj b/library/Library.csproj
index d2f6609d..b19564f8 100644
--- a/library/Library.csproj
+++ b/library/Library.csproj
@@ -126,6 +126,7 @@
+
diff --git a/library/Structures/GtsRecord4.cs b/library/Structures/GtsRecord4.cs
index b1f80bdd..e10865b8 100644
--- a/library/Structures/GtsRecord4.cs
+++ b/library/Structures/GtsRecord4.cs
@@ -195,44 +195,6 @@ namespace PkmnFoundations.Structures
{
if (!base.Validate()) return false;
- // todo: these checks belong on the pokemon class based on database fields.
- var thePokemon = (PokemonParty4)Pokemon;
-
- if (thePokemon.SpeciesID < 1 || thePokemon.SpeciesID > 493) return false;
-
- try
- {
- if (thePokemon.Form == null) return false;
- }
- catch (KeyNotFoundException)
- {
- return false; // form not in pokedex
- }
- if (thePokemon.SpeciesID == 479 && thePokemon.FormID != 0) return false; // rotoms
- if (thePokemon.SpeciesID == 487 && thePokemon.FormID != 0) return false; // origin giratina
- if (thePokemon.SpeciesID == 492 && thePokemon.FormID != 0) return false; // sky shaymin
- if (thePokemon.Form.Suffix == "spiky-eared") return false;
- if (thePokemon.Form.Suffix == "fairy") return false;
- if (thePokemon.Form.Suffix == "mega") return false;
- if (thePokemon.Form.Suffix == "mega-x") return false;
- if (thePokemon.Form.Suffix == "mega-y") return false;
- if (thePokemon.Form.Suffix == "primal") return false;
- if (thePokemon.SpeciesID == 25 && thePokemon.FormID > 0) return false; // cosplay pikachu
-
- if (thePokemon.HeldItemID < 0) return false;
- if (thePokemon.HeldItemID >= 112 && thePokemon.HeldItemID <= 134) return false;
- if (thePokemon.HeldItemID >= 428) return false;
-
- if (thePokemon.AbilityID <= 0) return false;
- if (thePokemon.AbilityID > 123) return false;
-
- foreach (MoveSlot move in thePokemon.Moves)
- {
- if (move.MoveID < 0) return false;
- if (move.MoveID == 165) return false; // struggle
- if (move.MoveID > 467) return false;
- }
-
return true;
}
diff --git a/library/Structures/GtsRecord5.cs b/library/Structures/GtsRecord5.cs
index 4013c7ae..906acda3 100644
--- a/library/Structures/GtsRecord5.cs
+++ b/library/Structures/GtsRecord5.cs
@@ -202,52 +202,6 @@ namespace PkmnFoundations.Structures
{
if (!base.Validate()) return false;
- // todo: these checks belong on the pokemon class based on database fields.
- var thePokemon = (PokemonParty5)Pokemon;
-
- if (thePokemon.SpeciesID < 1 || thePokemon.SpeciesID > 649) return false;
-
- try
- {
- if (thePokemon.Form == null) return false;
- }
- catch (KeyNotFoundException)
- {
- return false; // form not in pokedex
- }
- if (thePokemon.SpeciesID == 641 && thePokemon.FormID != 0) return false; // therian tornadus
- if (thePokemon.SpeciesID == 642 && thePokemon.FormID != 0) return false; // therian thundrus
- if (thePokemon.SpeciesID == 645 && thePokemon.FormID != 0) return false; // therian landorus
- if (thePokemon.SpeciesID == 646 && thePokemon.FormID != 0) return false; // black/white kyurem
- if (thePokemon.SpeciesID == 647 && thePokemon.FormID != 0) return false; // resolute keldeo
- if (thePokemon.Form.Suffix == "spiky-eared") return false;
- if (thePokemon.Form.Suffix == "fairy") return false;
- if (thePokemon.Form.Suffix == "mega") return false;
- if (thePokemon.Form.Suffix == "mega-x") return false;
- if (thePokemon.Form.Suffix == "mega-y") return false;
- if (thePokemon.Form.Suffix == "primal") return false;
- if (thePokemon.SpeciesID == 25 && thePokemon.FormID > 0) return false; // cosplay pikachu
-
- if (thePokemon.HeldItemID < 0) return false;
- if (thePokemon.HeldItemID >= 113 && thePokemon.HeldItemID <= 115) return false;
- if (thePokemon.HeldItemID >= 120 && thePokemon.HeldItemID <= 133) return false;
- if (thePokemon.HeldItemID >= 328 && thePokemon.HeldItemID <= 503) return false;
- if (thePokemon.HeldItemID >= 505 && thePokemon.HeldItemID <= 536) return false;
- if (thePokemon.HeldItemID == 574) return false;
- if (thePokemon.HeldItemID == 576) return false;
- if (thePokemon.HeldItemID >= 578 && thePokemon.HeldItemID <= 579) return false;
- if (thePokemon.HeldItemID >= 592) return false;
-
- if (thePokemon.AbilityID <= 0) return false;
- if (thePokemon.AbilityID > 164) return false;
-
- foreach (MoveSlot move in thePokemon.Moves)
- {
- if (move.MoveID < 0) return false;
- if (move.MoveID == 165) return false; // struggle
- if (move.MoveID > 559) return false;
- }
-
return true;
}
diff --git a/library/Structures/GtsRecordBase.cs b/library/Structures/GtsRecordBase.cs
index b05e7545..72be82bb 100644
--- a/library/Structures/GtsRecordBase.cs
+++ b/library/Structures/GtsRecordBase.cs
@@ -1,4 +1,5 @@
-using System;
+using PkmnFoundations.Support;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -103,6 +104,9 @@ namespace PkmnFoundations.Structures
if (thePokemon.Level > 100) return false;
if (thePokemon.EVs.ToArray().Select(i => (int)i).Sum() > 510) return false;
+ ValidationSummary summary = Pokemon.Validate();
+ if (!summary.IsValid) return false;
+
return true;
}
diff --git a/library/Structures/Pokemon4.cs b/library/Structures/Pokemon4.cs
index 1749abc9..2ff17ce9 100644
--- a/library/Structures/Pokemon4.cs
+++ b/library/Structures/Pokemon4.cs
@@ -311,5 +311,45 @@ namespace PkmnFoundations.Structures
{
get { return 136; }
}
+
+ public static ValidationSummary ValidateActual(PokemonBase thePokemon)
+ {
+ if (thePokemon.SpeciesID < 1 || thePokemon.SpeciesID > 493) return new ValidationSummary() { IsValid = false };
+
+ try
+ {
+ if (thePokemon.Form == null) return new ValidationSummary() { IsValid = false };
+ }
+ catch (KeyNotFoundException)
+ {
+ return new ValidationSummary() { IsValid = false }; // form not in pokedex
+ }
+ if (thePokemon.SpeciesID == 479 && thePokemon.FormID != 0) return new ValidationSummary() { IsValid = false }; // rotoms
+ if (thePokemon.SpeciesID == 487 && thePokemon.FormID != 0) return new ValidationSummary() { IsValid = false }; // origin giratina
+ if (thePokemon.SpeciesID == 492 && thePokemon.FormID != 0) return new ValidationSummary() { IsValid = false }; // sky shaymin
+ if (thePokemon.Form.Suffix == "spiky-eared") return new ValidationSummary() { IsValid = false };
+ if (thePokemon.Form.Suffix == "fairy") return new ValidationSummary() { IsValid = false };
+ if (thePokemon.Form.Suffix == "mega") return new ValidationSummary() { IsValid = false };
+ if (thePokemon.Form.Suffix == "mega-x") return new ValidationSummary() { IsValid = false };
+ if (thePokemon.Form.Suffix == "mega-y") return new ValidationSummary() { IsValid = false };
+ if (thePokemon.Form.Suffix == "primal") return new ValidationSummary() { IsValid = false };
+ if (thePokemon.SpeciesID == 25 && thePokemon.FormID > 0) return new ValidationSummary() { IsValid = false }; // cosplay pikachu
+
+ if (thePokemon.HeldItemID < 0) return new ValidationSummary() { IsValid = false };
+ if (thePokemon.HeldItemID >= 112 && thePokemon.HeldItemID <= 134) return new ValidationSummary() { IsValid = false };
+ if (thePokemon.HeldItemID >= 428) return new ValidationSummary() { IsValid = false };
+
+ if (thePokemon.AbilityID <= 0) return new ValidationSummary() { IsValid = false };
+ if (thePokemon.AbilityID > 123) return new ValidationSummary() { IsValid = false };
+
+ foreach (MoveSlot move in thePokemon.Moves)
+ {
+ if (move.MoveID < 0) return new ValidationSummary() { IsValid = false };
+ if (move.MoveID == 165) return new ValidationSummary() { IsValid = false }; // struggle
+ if (move.MoveID > 467) return new ValidationSummary() { IsValid = false };
+ }
+
+ return new ValidationSummary() { IsValid = true };
+ }
}
}
diff --git a/library/Structures/Pokemon5.cs b/library/Structures/Pokemon5.cs
index 33a43490..e638e1e6 100644
--- a/library/Structures/Pokemon5.cs
+++ b/library/Structures/Pokemon5.cs
@@ -294,5 +294,53 @@ namespace PkmnFoundations.Structures
{
get { return 136; }
}
+
+ public static ValidationSummary ValidateActual(PokemonBase thePokemon)
+ {
+ if (thePokemon.SpeciesID < 1 || thePokemon.SpeciesID > 649) return new ValidationSummary() { IsValid = false };
+
+ try
+ {
+ if (thePokemon.Form == null) return new ValidationSummary() { IsValid = false };
+ }
+ catch (KeyNotFoundException)
+ {
+ return new ValidationSummary() { IsValid = false }; // form not in pokedex
+ }
+ if (thePokemon.SpeciesID == 641 && thePokemon.FormID != 0) return new ValidationSummary() { IsValid = false }; // therian tornadus
+ if (thePokemon.SpeciesID == 642 && thePokemon.FormID != 0) return new ValidationSummary() { IsValid = false }; // therian thundrus
+ if (thePokemon.SpeciesID == 645 && thePokemon.FormID != 0) return new ValidationSummary() { IsValid = false }; // therian landorus
+ if (thePokemon.SpeciesID == 646 && thePokemon.FormID != 0) return new ValidationSummary() { IsValid = false }; // black/white kyurem
+ if (thePokemon.SpeciesID == 647 && thePokemon.FormID != 0) return new ValidationSummary() { IsValid = false }; // resolute keldeo
+ if (thePokemon.Form.Suffix == "spiky-eared") return new ValidationSummary() { IsValid = false };
+ if (thePokemon.Form.Suffix == "fairy") return new ValidationSummary() { IsValid = false };
+ if (thePokemon.Form.Suffix == "mega") return new ValidationSummary() { IsValid = false };
+ if (thePokemon.Form.Suffix == "mega-x") return new ValidationSummary() { IsValid = false };
+ if (thePokemon.Form.Suffix == "mega-y") return new ValidationSummary() { IsValid = false };
+ if (thePokemon.Form.Suffix == "primal") return new ValidationSummary() { IsValid = false };
+ if (thePokemon.SpeciesID == 25 && thePokemon.FormID > 0) return new ValidationSummary() { IsValid = false }; // cosplay pikachu
+
+ if (thePokemon.HeldItemID < 0) return new ValidationSummary() { IsValid = false };
+ if (thePokemon.HeldItemID >= 113 && thePokemon.HeldItemID <= 115) return new ValidationSummary() { IsValid = false };
+ if (thePokemon.HeldItemID >= 120 && thePokemon.HeldItemID <= 133) return new ValidationSummary() { IsValid = false };
+ if (thePokemon.HeldItemID >= 328 && thePokemon.HeldItemID <= 503) return new ValidationSummary() { IsValid = false };
+ if (thePokemon.HeldItemID >= 505 && thePokemon.HeldItemID <= 536) return new ValidationSummary() { IsValid = false };
+ if (thePokemon.HeldItemID == 574) return new ValidationSummary() { IsValid = false };
+ if (thePokemon.HeldItemID == 576) return new ValidationSummary() { IsValid = false };
+ if (thePokemon.HeldItemID >= 578 && thePokemon.HeldItemID <= 579) return new ValidationSummary() { IsValid = false };
+ if (thePokemon.HeldItemID >= 592) return new ValidationSummary() { IsValid = false };
+
+ if (thePokemon.AbilityID <= 0) return new ValidationSummary() { IsValid = false };
+ if (thePokemon.AbilityID > 164) return new ValidationSummary() { IsValid = false };
+
+ foreach (MoveSlot move in thePokemon.Moves)
+ {
+ if (move.MoveID < 0) return new ValidationSummary() { IsValid = false };
+ if (move.MoveID == 165) return new ValidationSummary() { IsValid = false }; // struggle
+ if (move.MoveID > 559) return new ValidationSummary() { IsValid = false };
+ }
+
+ return new ValidationSummary() { IsValid = true };
+ }
}
}
diff --git a/library/Structures/PokemonBase.cs b/library/Structures/PokemonBase.cs
index 5054482b..63c4a363 100644
--- a/library/Structures/PokemonBase.cs
+++ b/library/Structures/PokemonBase.cs
@@ -137,7 +137,7 @@ namespace PkmnFoundations.Structures
throw new NotSupportedException();
}
}
- public abstract String Nickname { get; set; }
+ public abstract string Nickname { get; set; }
public virtual bool IsShiny
{
@@ -178,6 +178,24 @@ namespace PkmnFoundations.Structures
}
}
+ public virtual ValidationSummary Validate()
+ {
+ // xxx: this is another one of those inheritance diamond things.
+ // Since we specialize by generation after specializing by
+ // structure type, we have to roll our own vtable here to be able
+ // to have generation-specific validation in each inheritance
+ // branch.
+ switch (this.Generation)
+ {
+ case Generations.Generation4:
+ return Pokemon4.ValidateActual(this);
+ case Generations.Generation5:
+ return Pokemon5.ValidateActual(this);
+ default:
+ return new ValidationSummary() { IsValid = true };
+ }
+ }
+
protected static List BlockScramble(uint personality)
{
int x = 4; // todo: this can be an argument but YAGNI
diff --git a/library/Support/ValidationSummary.cs b/library/Support/ValidationSummary.cs
new file mode 100644
index 00000000..3fb6e4df
--- /dev/null
+++ b/library/Support/ValidationSummary.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace PkmnFoundations.Support
+{
+ public struct ValidationSummary
+ {
+ public bool IsValid { get; set; }
+ }
+}