Add Move checking

Tweaked some inner logic to validate moves on creation of new
legalityanalysis for use in display, with refresh methods.
This commit is contained in:
Kaphotics 2016-03-11 20:56:40 -08:00
parent 20257ffc32
commit 9210ef06c6
2 changed files with 42 additions and 18 deletions

View file

@ -7,9 +7,21 @@ namespace PKHeX
public class LegalityAnalysis
{
private readonly PK6 pk6;
public bool[] vMoves = new bool[4];
public bool[] vRelearn = new bool[4];
public LegalityAnalysis(PK6 pk)
{
pk6 = pk;
updateRelearnLegality();
updateMoveLegality();
}
public void updateRelearnLegality()
{
vRelearn = getRelearnValidity(pk6.RelearnMoves);
}
public void updateMoveLegality()
{
vMoves = getMoveValidity(pk6.Moves, pk6.RelearnMoves);
}
public bool[] getMoveValidity(int[] Moves, int[] RelearnMoves)
@ -103,14 +115,13 @@ namespace PKHeX
res[i] = Moves[i] == 0;
return res;
}
public bool Valid = false;
public LegalityCheck EC, Nickname, PID, IDs, IVs, EVs, Encounter;
public string Report => getLegalityReport();
private string getLegalityReport()
{
if (!pk6.Gen6)
return "Analysis only implemented for X/Y & OR/AS.";
return "Analysis only available for Pokémon that originate from X/Y & OR/AS.";
EC = LegalityCheck.verifyECPID(pk6);
Nickname = LegalityCheck.verifyNickname(pk6);
@ -122,11 +133,21 @@ namespace PKHeX
var chks = new[] {EC, Nickname, PID, IVs, EVs, IDs, Encounter};
if (chks.All(chk => chk.Valid))
string r = "";
for (int i = 0; i < 4; i++)
if (!vMoves[i])
r += $"Invalid: Move {i + 1}{Environment.NewLine}";
for (int i = 0; i < 4; i++)
if (!vRelearn[i])
r += $"Invalid: Relearn Move {i + 1}{Environment.NewLine}";
if (r.Length == 0 && chks.All(chk => chk.Valid))
return "Legal!";
// Build result string...
return chks.Where(chk => !chk.Valid).Aggregate("", (current, inv) => current + $"{inv.Judgement}: {inv.Comment}{Environment.NewLine}");
r += chks.Where(chk => !chk.Valid).Aggregate("", (current, chk) => current + $"{chk.Judgement}: {chk.Comment}{Environment.NewLine}");
return r;
}
}
}

View file

@ -2067,7 +2067,6 @@ namespace PKHeX
updateIVs(null, null); // If the EC is changed, EC%6 (Characteristic) might be changed.
TB_PID.Select(60, 0); // position cursor at end of field
}
private void validateComboBox(object sender)
{
ComboBox cb = sender as ComboBox;
@ -2106,24 +2105,23 @@ namespace PKHeX
if (new[] { CB_Move1, CB_Move2, CB_Move3, CB_Move4 }.Contains(sender)) // Move
updatePP(sender, e);
int[] relearnMoves = { Util.getIndex(CB_RelearnMove1), Util.getIndex(CB_RelearnMove2), Util.getIndex(CB_RelearnMove3), Util.getIndex(CB_RelearnMove4) };
int[] moves = { Util.getIndex(CB_Move1), Util.getIndex(CB_Move2), Util.getIndex(CB_Move3), Util.getIndex(CB_Move4) };
// Refresh Relearn if...
if (new[] { CB_RelearnMove1, CB_RelearnMove2, CB_RelearnMove3, CB_RelearnMove4 }.Contains(sender))
{
PictureBox[] moveCB = { PB_WarnRelearn1, PB_WarnRelearn2, PB_WarnRelearn3, PB_WarnRelearn4 };
bool[] legal = Legality.getRelearnValidity(relearnMoves);
pk6.RelearnMoves = new[] { Util.getIndex(CB_RelearnMove1), Util.getIndex(CB_RelearnMove2), Util.getIndex(CB_RelearnMove3), Util.getIndex(CB_RelearnMove4) };
Legality.updateRelearnLegality();
PictureBox[] movePB = { PB_WarnRelearn1, PB_WarnRelearn2, PB_WarnRelearn3, PB_WarnRelearn4 };
for (int i = 0; i < 4; i++)
moveCB[i].Visible = !legal[i];
movePB[i].Visible = !Legality.vRelearn[i];
}
// Refresh Moves
// else, Refresh Moves
{
PictureBox[] moveCB = { PB_WarnMove1, PB_WarnMove2, PB_WarnMove3, PB_WarnMove4 };
bool[] legal = Legality.getMoveValidity(moves, relearnMoves);
pk6.Moves = new[] { Util.getIndex(CB_Move1), Util.getIndex(CB_Move2), Util.getIndex(CB_Move3), Util.getIndex(CB_Move4) };
Legality.updateMoveLegality();
PictureBox[] movePB = { PB_WarnMove1, PB_WarnMove2, PB_WarnMove3, PB_WarnMove4 };
for (int i = 0; i < 4; i++)
moveCB[i].Visible = !legal[i];
movePB[i].Visible = !Legality.vMoves[i];
}
}
private void validateLocation(object sender, EventArgs e)
@ -2153,7 +2151,12 @@ namespace PKHeX
Legality = new LegalityAnalysis(pk6);
// Refresh Move Legality
validateMove(CB_RelearnMove1, null);
PictureBox[] movePB = {PB_WarnMove1, PB_WarnMove2, PB_WarnMove3, PB_WarnMove4};
for (int i = 0; i < 4; i++)
movePB[i].Visible = !Legality.vMoves[i];
PictureBox[] relPB = {PB_WarnRelearn1, PB_WarnRelearn2, PB_WarnRelearn3, PB_WarnRelearn4};
for (int i = 0; i < 4; i++)
relPB[i].Visible = !Legality.vRelearn[i];
}
private void updateStats()
{