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-03-28 05:05:51 +00:00
|
|
|
|
private Type EncounterType;
|
2016-03-22 04:31:06 +00:00
|
|
|
|
private LegalityCheck ECPID, Nickname, IDs, IVs, EVs, Encounter, Level, Ribbons, Ability, Ball, HandlerMemories;
|
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-02-23 06:52:48 +00:00
|
|
|
|
public LegalityAnalysis(PK6 pk)
|
|
|
|
|
{
|
|
|
|
|
pk6 = pk;
|
2016-03-12 04:56:40 +00:00
|
|
|
|
updateRelearnLegality();
|
|
|
|
|
updateMoveLegality();
|
2016-03-14 03:19:04 +00:00
|
|
|
|
updateChecks();
|
2016-03-14 01:09:12 +00:00
|
|
|
|
getLegalityReport();
|
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-03-22 04:31:06 +00:00
|
|
|
|
HandlerMemories = verifyHandlerMemories();
|
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-03-12 03:57:33 +00:00
|
|
|
|
if (!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-08 05:28:26 +00:00
|
|
|
|
var chks = new[] { Encounter, Level, Ball, Ability, Ribbons, ECPID, Nickname, IVs, EVs, IDs, HandlerMemories };
|
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;
|
|
|
|
|
r += "===" + Environment.NewLine + Environment.NewLine;
|
|
|
|
|
|
2016-04-08 05:28:26 +00:00
|
|
|
|
var chks = new[] { Encounter, Level, Ball, Ability, Ribbons, ECPID, Nickname, IVs, EVs, IDs, HandlerMemories };
|
|
|
|
|
r += chks.Where(chk => chk.Valid && chk.Comment != "Valid").OrderBy(chk => chk.Judgement) // Fishy sorted to top
|
|
|
|
|
.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
|
|
|
|
}
|
|
|
|
|
}
|