RelearnMove suggestion instead of copyMoves

This commit is contained in:
Kaphotics 2016-03-25 00:10:11 -07:00
parent ebb6349ceb
commit a2c42a2293
3 changed files with 42 additions and 7 deletions

View file

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace PKHeX
@ -11,6 +12,7 @@ namespace PKHeX
public bool Valid = true;
public bool SecondaryChecked;
public int[] RelearnBase;
public LegalityCheck[] vMoves = new LegalityCheck[4];
public LegalityCheck[] vRelearn = new LegalityCheck[4];
public string Report => getLegalityReport();
@ -26,6 +28,7 @@ namespace PKHeX
public void updateRelearnLegality()
{
RelearnBase = null;
try { vRelearn = verifyRelearn(); }
catch { for (int i = 0; i < 4; i++) vRelearn[i] = new LegalityCheck(Severity.Invalid, "Internal error."); }
SecondaryChecked = false;
@ -76,5 +79,24 @@ namespace PKHeX
return r;
}
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();
}
}
}

View file

@ -17,6 +17,7 @@ namespace PKHeX
public Severity Judgement = Severity.Valid;
public readonly string Comment = "Valid";
public bool Valid => Judgement >= Severity.Fishy;
public bool Flag;
public LegalityCheck() { }
public LegalityCheck(Severity s, string c)
@ -468,7 +469,7 @@ namespace PKHeX
else if (validMoves.Contains(Moves[i]))
res[i] = new LegalityCheck(Severity.Valid, "Level-up.");
else if (RelearnMoves.Contains(Moves[i]))
res[i] = new LegalityCheck(Severity.Valid, "Relearn Move.");
res[i] = new LegalityCheck(Severity.Valid, "Relearn Move.") {Flag = true};
else if (WC6Moves.Contains(Moves[i]))
res[i] = new LegalityCheck(Severity.Valid, "Wonder Card Non-Relearn Move.");
else
@ -509,6 +510,7 @@ namespace PKHeX
EncounterMatch = Link;
int[] moves = ((EncounterLink)EncounterMatch).RelearnMoves;
RelearnBase = moves;
for (int i = 0; i < 4; i++)
res[i] = moves[i] != Moves[i]
? new LegalityCheck(Severity.Invalid, $"Expected ID:{moves[i]}.")
@ -527,7 +529,7 @@ namespace PKHeX
? new LegalityCheck(Severity.Invalid, $"Expected ID:{moves[i]}.")
: new LegalityCheck(Severity.Valid, $"Matched WC #{wc.CardID.ToString("0000")}");
if (res.All(r => r.Valid))
{ EncounterMatch = wc; return res; }
{ EncounterMatch = wc; RelearnBase = moves; return res; }
}
EncounterMatch = null;
goto noRelearn; // No WC match
@ -575,6 +577,7 @@ namespace PKHeX
int[] rl = pk6.RelearnMoves;
string em = string.Join(", ", baseMoves);
RelearnBase = baseMoves.ToArray();
// Base Egg Move
for (int j = 0; j < req; j++)
res[j] = !baseMoves.Contains(rl[j])
@ -608,6 +611,8 @@ namespace PKHeX
? new LegalityCheck(Severity.Invalid, "Expected no Relearn Move in slot.")
: new LegalityCheck();
if (res[0].Valid)
RelearnBase = new[] { Moves[0], 0, 0, 0 };
return res;
}

View file

@ -1440,13 +1440,21 @@ namespace PKHeX
}
private void clickMoves(object sender, EventArgs e)
{
if (DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNo, "Copy current moves to Relearn Moves?"))
updateLegality();
int[] m = Legality.getSuggestedRelearn();
string[] s = new string[4];
for (int i = 0; i < 4; i++)
s[i] = movelist[m[i]];
string r = string.Join(Environment.NewLine, s);
if (DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNo, "Apply suggested relearn moves?", r))
return;
CB_RelearnMove1.SelectedIndex = CB_Move1.SelectedIndex > -1 ? CB_Move1.SelectedIndex : 0;
CB_RelearnMove2.SelectedIndex = CB_Move2.SelectedIndex > -1 ? CB_Move2.SelectedIndex : 0;
CB_RelearnMove3.SelectedIndex = CB_Move3.SelectedIndex > -1 ? CB_Move3.SelectedIndex : 0;
CB_RelearnMove4.SelectedIndex = CB_Move4.SelectedIndex > -1 ? CB_Move4.SelectedIndex : 0;
CB_RelearnMove1.SelectedValue = m[0];
CB_RelearnMove2.SelectedValue = m[1];
CB_RelearnMove3.SelectedValue = m[2];
CB_RelearnMove4.SelectedValue = m[3];
updateLegality();
}
// Prompted Updates of PKX Functions //
private bool changingFields;