Move Relearn checks to Analysis.cs

Keeping logic out of Main.cs
This commit is contained in:
Kaphotics
2016-02-23 19:19:25 -08:00
parent c4f9819314
commit b3a4cc858e
2 changed files with 50 additions and 50 deletions

View File

@@ -1,4 +1,6 @@
using System.Linq;
using System;
using System.Linq;
using System.Windows.Forms;
namespace PKHeX
{
@@ -39,12 +41,12 @@ public LegalityAnalysis(PK6 pk)
public bool[] getMoveValidity(int[] Moves, int[] RelearnMoves)
{
if (Moves.Length != 4)
return null;
return new bool[4];
bool[] res = { true, true, true, true };
if (!pk6.Gen6)
return new[] {true, true, true, true};
return res;
bool[] res = new bool[4];
if (pk6.Species == 235)
{
for (int i = 0; i < 4; i++)
@@ -63,28 +65,38 @@ public bool[] getMoveValidity(int[] Moves, int[] RelearnMoves)
public bool[] getRelearnValidity(int[] Moves)
{
bool[] res = new bool[4];
if (Moves.Length != 4)
return new bool[4];
bool[] res = {true, true, true, true};
if (!pk6.Gen6)
goto noRelearn;
bool egg = pk6.Egg_Location > 1000 || pk6.Egg_Location == 318;
bool evnt = pk6.Met_Location > 40000 || pk6.Egg_Location > 40000;
int[] relearnMoves = ValidRelearnMoves;
if (evnt)
{
// Check Event Info
// Not Implemented
}
if (egg)
{
for (int i = 0; i < 4; i++)
res[i] &= relearnMoves.Contains(Moves[i]);
return res;
if (pk6.Egg_Location == 0) // Never Egg
{
if (pk6.Met_Location > 40000) // Event
{
// Not Implemented
}
else
{
// Check for DexNav
// Not Implemented
}
}
else
bool dexnav = false;
if (dexnav) // not implemented
{
// Check Bred Moves
return res;
}
return new[] { true, true, true, true };
// Should have no relearn moves.
noRelearn:
for (int i = 0; i < 4; i++)
res[i] &= Moves[i] == 0;
return res;
}
public LegalityCheck EC, Nickname, PID, IDs, IVs, EVs;

View File

@@ -2055,49 +2055,37 @@ private void validateComboBox2(object sender, EventArgs e)
}
private void validateMove(object sender, EventArgs e)
{
validateComboBox(sender, e);
if (!fieldsLoaded)
return;
int Version = Util.getIndex(CB_GameOrigin); // 24,25 = XY, 26,27 = ORAS, 28,29 = ???
bool gen6 = Version >= 24 && Version <= 29;
int species = Util.getIndex(CB_Species);
int index = Array.IndexOf(new[] { CB_Move1, CB_Move2, CB_Move3, CB_Move4 }, sender);
int[] moves =
{
Util.getIndex(CB_Move1), Util.getIndex(CB_Move2),
Util.getIndex(CB_Move3), Util.getIndex(CB_Move4)
};
validateComboBox(sender, e);
int[] relearnMoves =
{
Util.getIndex(CB_RelearnMove1), Util.getIndex(CB_RelearnMove2),
Util.getIndex(CB_RelearnMove3), Util.getIndex(CB_RelearnMove4)
};
if (index > -1) // Move
if (new[] { CB_Move1, CB_Move2, CB_Move3, CB_Move4 }.Contains(sender)) // Move
{
updatePP(sender, e);
int[] moves =
{
Util.getIndex(CB_Move1), Util.getIndex(CB_Move2),
Util.getIndex(CB_Move3), Util.getIndex(CB_Move4)
};
PictureBox[] moveCB = {PB_WarnMove1, PB_WarnMove2, PB_WarnMove3, PB_WarnMove4};
bool[] x = Legality.getMoveValidity(moves, relearnMoves);
bool[] legal = Legality.getMoveValidity(moves, relearnMoves);
for (int i = 0; i < 4; i++)
moveCB[i].Visible = !x[i];
moveCB[i].Visible = !legal[i];
}
else
{
int eggloc = Util.getIndex(CB_EggLocation);
bool egg = CHK_AsEgg.Checked && (eggloc > 1000 || eggloc == 318);
index = Array.IndexOf(new[] {CB_RelearnMove1, CB_RelearnMove2, CB_RelearnMove3, CB_RelearnMove4}, sender);
ComboBox cb = new[] {CB_RelearnMove1, CB_RelearnMove2, CB_RelearnMove3, CB_RelearnMove4}[index];
PictureBox pb = new[] {PB_WarnRelearn1, PB_WarnRelearn2, PB_WarnRelearn3, PB_WarnRelearn4}[index];
if (!egg & gen6)
{
pb.Visible = Util.getIndex(cb) > 0;
}
else if (egg && gen6)
{
pb.Visible = !Legality.ValidRelearnMoves.Contains(relearnMoves[index]);
}
else
{
pb.Visible = false;
}
PictureBox[] moveCB = { PB_WarnRelearn1, PB_WarnRelearn2, PB_WarnRelearn3, PB_WarnRelearn4 };
bool[] legal = Legality.getRelearnValidity(relearnMoves);
for (int i = 0; i < 4; i++)
moveCB[i].Visible = !legal[i];
// Refresh move states
foreach (ComboBox c in new[] { CB_Move1, CB_Move2, CB_Move3, CB_Move4 })
validateMove(c, e);
}