2016-03-12 03:43:40 +00:00
|
|
|
|
using System;
|
2016-03-25 07:10:11 +00:00
|
|
|
|
using System.Collections.Generic;
|
2016-03-05 04:43:00 +00:00
|
|
|
|
using System.Linq;
|
2016-02-23 06:52:48 +00:00
|
|
|
|
|
|
|
|
|
namespace PKHeX
|
|
|
|
|
{
|
2016-03-14 03:19:04 +00:00
|
|
|
|
public partial class LegalityAnalysis
|
2016-02-23 06:52:48 +00:00
|
|
|
|
{
|
|
|
|
|
private readonly PK6 pk6;
|
2016-03-18 00:25:21 +00:00
|
|
|
|
private object EncounterMatch;
|
2016-04-16 18:35:16 +00:00
|
|
|
|
private List<WC6> CardMatch;
|
2016-03-28 05:05:51 +00:00
|
|
|
|
private Type EncounterType;
|
2016-07-04 01:36:04 +00:00
|
|
|
|
private LegalityCheck ECPID, Nickname, IDs, IVs, EVs, Encounter, Level, Ribbons, Ability, Ball, History, OTMemory, HTMemory, Region, Form, Misc, Gender;
|
|
|
|
|
private LegalityCheck[] Checks => new[] { Encounter, Level, Form, Ball, Ability, Ribbons, ECPID, Nickname, IVs, EVs, IDs, History, OTMemory, HTMemory, Region, Misc, Gender };
|
2016-03-14 03:19:04 +00:00
|
|
|
|
|
2016-03-14 01:09:12 +00:00
|
|
|
|
public bool Valid = true;
|
2016-03-14 03:19:04 +00:00
|
|
|
|
public bool SecondaryChecked;
|
2016-03-25 07:10:11 +00:00
|
|
|
|
public int[] RelearnBase;
|
2016-03-14 03:19:04 +00:00
|
|
|
|
public LegalityCheck[] vMoves = new LegalityCheck[4];
|
|
|
|
|
public LegalityCheck[] vRelearn = new LegalityCheck[4];
|
|
|
|
|
public string Report => getLegalityReport();
|
2016-04-04 00:11:58 +00:00
|
|
|
|
public string VerboseReport => getVerboseLegalityReport();
|
2016-03-14 03:19:04 +00:00
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public LegalityAnalysis(PKM pk)
|
2016-02-23 06:52:48 +00:00
|
|
|
|
{
|
2016-06-20 04:22:43 +00:00
|
|
|
|
if (!(pk is PK6))
|
|
|
|
|
return;
|
2016-07-09 01:11:21 +00:00
|
|
|
|
pk6 = (PK6) pk;
|
2016-06-30 05:59:20 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
updateRelearnLegality();
|
|
|
|
|
updateMoveLegality();
|
|
|
|
|
updateChecks();
|
|
|
|
|
getLegalityReport();
|
|
|
|
|
}
|
|
|
|
|
catch { Valid = false; }
|
2016-03-12 04:56:40 +00:00
|
|
|
|
}
|
2016-03-14 03:19:04 +00:00
|
|
|
|
|
2016-03-12 04:56:40 +00:00
|
|
|
|
public void updateRelearnLegality()
|
|
|
|
|
{
|
2016-03-14 03:19:04 +00:00
|
|
|
|
try { vRelearn = verifyRelearn(); }
|
2016-03-12 17:16:41 +00:00
|
|
|
|
catch { for (int i = 0; i < 4; i++) vRelearn[i] = new LegalityCheck(Severity.Invalid, "Internal error."); }
|
2016-03-14 03:19:04 +00:00
|
|
|
|
SecondaryChecked = false;
|
2016-03-12 04:56:40 +00:00
|
|
|
|
}
|
|
|
|
|
public void updateMoveLegality()
|
|
|
|
|
{
|
2016-03-14 03:19:04 +00:00
|
|
|
|
try { vMoves = verifyMoves(); }
|
2016-03-12 17:16:41 +00:00
|
|
|
|
catch { for (int i = 0; i < 4; i++) vMoves[i] = new LegalityCheck(Severity.Invalid, "Internal error."); }
|
2016-03-14 03:19:04 +00:00
|
|
|
|
SecondaryChecked = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateChecks()
|
|
|
|
|
{
|
2016-03-18 00:25:21 +00:00
|
|
|
|
Encounter = verifyEncounter();
|
2016-03-28 05:05:51 +00:00
|
|
|
|
EncounterType = EncounterMatch?.GetType();
|
2016-03-14 03:19:04 +00:00
|
|
|
|
ECPID = verifyECPID();
|
|
|
|
|
Nickname = verifyNickname();
|
|
|
|
|
IDs = verifyID();
|
|
|
|
|
IVs = verifyIVs();
|
|
|
|
|
EVs = verifyEVs();
|
2016-03-19 05:49:21 +00:00
|
|
|
|
Level = verifyLevel();
|
2016-03-20 22:20:11 +00:00
|
|
|
|
Ribbons = verifyRibbons();
|
2016-03-21 15:01:08 +00:00
|
|
|
|
Ability = verifyAbility();
|
|
|
|
|
Ball = verifyBall();
|
2016-05-06 03:05:22 +00:00
|
|
|
|
History = verifyHistory();
|
|
|
|
|
OTMemory = verifyOTMemory();
|
|
|
|
|
HTMemory = verifyHTMemory();
|
2016-05-11 23:20:31 +00:00
|
|
|
|
Region = verifyRegion();
|
2016-04-14 10:17:03 +00:00
|
|
|
|
Form = verifyForm();
|
2016-04-22 02:32:22 +00:00
|
|
|
|
Misc = verifyMisc();
|
2016-07-04 01:36:04 +00:00
|
|
|
|
Gender = verifyGender();
|
2016-03-14 03:19:04 +00:00
|
|
|
|
SecondaryChecked = true;
|
2016-02-23 06:52:48 +00:00
|
|
|
|
}
|
2016-03-09 03:20:26 +00:00
|
|
|
|
private string getLegalityReport()
|
|
|
|
|
{
|
2016-06-20 04:22:43 +00:00
|
|
|
|
if (pk6 == null || !pk6.Gen6)
|
2016-03-12 04:56:40 +00:00
|
|
|
|
return "Analysis only available for Pokémon that originate from X/Y & OR/AS.";
|
2016-03-14 03:19:04 +00:00
|
|
|
|
|
2016-04-14 10:17:03 +00:00
|
|
|
|
var chks = Checks;
|
2016-03-12 03:43:40 +00:00
|
|
|
|
|
2016-03-12 04:56:40 +00:00
|
|
|
|
string r = "";
|
|
|
|
|
for (int i = 0; i < 4; i++)
|
2016-03-12 17:16:41 +00:00
|
|
|
|
if (!vMoves[i].Valid)
|
|
|
|
|
r += $"{vMoves[i].Judgement} Move {i + 1}: {vMoves[i].Comment}" + Environment.NewLine;
|
2016-03-12 04:56:40 +00:00
|
|
|
|
for (int i = 0; i < 4; i++)
|
2016-03-12 17:16:41 +00:00
|
|
|
|
if (!vRelearn[i].Valid)
|
|
|
|
|
r += $"{vRelearn[i].Judgement} Relearn Move {i + 1}: {vRelearn[i].Comment}" + Environment.NewLine;
|
2016-03-12 04:56:40 +00:00
|
|
|
|
|
|
|
|
|
if (r.Length == 0 && chks.All(chk => chk.Valid))
|
2016-03-12 03:43:40 +00:00
|
|
|
|
return "Legal!";
|
|
|
|
|
|
2016-03-14 01:09:12 +00:00
|
|
|
|
Valid = false;
|
2016-03-12 03:43:40 +00:00
|
|
|
|
// Build result string...
|
2016-03-12 04:56:40 +00:00
|
|
|
|
r += chks.Where(chk => !chk.Valid).Aggregate("", (current, chk) => current + $"{chk.Judgement}: {chk.Comment}{Environment.NewLine}");
|
|
|
|
|
|
2016-04-04 00:11:58 +00:00
|
|
|
|
return r.TrimEnd();
|
|
|
|
|
}
|
|
|
|
|
private string getVerboseLegalityReport()
|
|
|
|
|
{
|
|
|
|
|
string r = getLegalityReport() + Environment.NewLine;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
if (pk6 == null)
|
|
|
|
|
return r;
|
2016-04-04 00:11:58 +00:00
|
|
|
|
r += "===" + Environment.NewLine + Environment.NewLine;
|
2016-04-16 18:36:01 +00:00
|
|
|
|
int rl = r.Length;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
|
if (vMoves[i].Valid)
|
|
|
|
|
r += $"{vMoves[i].Judgement} Move {i + 1}: {vMoves[i].Comment}" + Environment.NewLine;
|
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
|
if (vRelearn[i].Valid)
|
|
|
|
|
r += $"{vRelearn[i].Judgement} Relearn Move {i + 1}: {vRelearn[i].Comment}" + Environment.NewLine;
|
|
|
|
|
|
|
|
|
|
if (rl != r.Length) // move info added, break for next section
|
|
|
|
|
r += Environment.NewLine;
|
2016-04-04 00:11:58 +00:00
|
|
|
|
|
2016-04-14 10:17:03 +00:00
|
|
|
|
var chks = Checks;
|
2016-06-30 05:59:20 +00:00
|
|
|
|
r += chks.Where(chk => chk != null && chk.Valid && chk.Comment != "Valid").OrderBy(chk => chk.Judgement) // Fishy sorted to top
|
2016-04-08 05:28:26 +00:00
|
|
|
|
.Aggregate("", (current, chk) => current + $"{chk.Judgement}: {chk.Comment}{Environment.NewLine}");
|
2016-04-04 00:11:58 +00:00
|
|
|
|
return r.TrimEnd();
|
2016-03-09 03:20:26 +00:00
|
|
|
|
}
|
2016-03-25 07:10:11 +00:00
|
|
|
|
|
|
|
|
|
public int[] getSuggestedRelearn()
|
|
|
|
|
{
|
|
|
|
|
if (RelearnBase == null)
|
|
|
|
|
return new int[4];
|
|
|
|
|
|
|
|
|
|
if (!pk6.WasEgg)
|
|
|
|
|
return RelearnBase;
|
|
|
|
|
|
|
|
|
|
List<int> window = new List<int>(RelearnBase);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
|
if (!vMoves[i].Valid || vMoves[i].Flag)
|
|
|
|
|
window.Add(pk6.Moves[i]);
|
|
|
|
|
|
|
|
|
|
if (window.Count < 4)
|
|
|
|
|
window.AddRange(new int[4 - window.Count]);
|
|
|
|
|
return window.Skip(window.Count - 4).Take(4).ToArray();
|
|
|
|
|
}
|
2016-02-23 06:52:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|