Add suggested met location fetch

Closes #450
This commit is contained in:
Kurt 2016-11-26 23:23:45 -08:00
parent 20f2a0fc61
commit 8f73c9b0ac
4 changed files with 96 additions and 0 deletions

View file

@ -232,5 +232,56 @@ namespace PKHeX
return null;
return Legal.getValidMoves(pkm, Tutor: tutor, Machine: tm, MoveReminder: reminder).Skip(1).ToArray(); // skip move 0
}
public EncounterStatic getSuggestedMetInfo()
{
if (pkm.WasEgg)
return new EncounterStatic
{
Location = getSuggestedEggMetLocation(pkm),
Level = 1,
};
var capture = Legal.getCaptureLocation(pkm);
if (capture != null)
return new EncounterStatic
{
Location = capture.Location,
Level = capture.Slots.First().LevelMin,
};
var encounter = Legal.getStaticLocation(pkm);
return encounter;
}
private static int getSuggestedEggMetLocation(PKM pkm)
{
// Return one of legal hatch locations for game
switch ((GameVersion)pkm.Version)
{
case GameVersion.D:
case GameVersion.P:
case GameVersion.Pt:
return pkm.Format > 4 ? 30001 /* Transporter */ : 4; // Solaceon Town
case GameVersion.HG:
case GameVersion.SS:
return pkm.Format > 4 ? 30001 /* Transporter */ : 182; // Route 34
case GameVersion.B:
case GameVersion.W:
return 16; // Route 3
case GameVersion.X:
case GameVersion.Y:
return 38; // Route 7
case GameVersion.AS:
case GameVersion.OR:
return 318; // Battle Resort
case GameVersion.SN:
case GameVersion.MN:
break;
}
return -1;
}
}
}

View file

@ -541,6 +541,20 @@ namespace PKHeX
return curr.Count() >= poss.Count();
}
internal static EncounterArea getCaptureLocation(PKM pkm)
{
return (from area in getEncounterSlots(pkm)
let slots = getValidEncounterSlots(pkm, area, pkm.AO).ToArray()
where slots.Any()
select new EncounterArea
{
Location = area.Location, Slots = slots,
}).FirstOrDefault();
}
internal static EncounterStatic getStaticLocation(PKM pkm)
{
return getStaticEncounters(pkm).FirstOrDefault();
}
internal static bool getCanBeCaptured(int species, int gen, GameVersion version = GameVersion.Any)
{
switch (gen)

View file

@ -1759,6 +1759,7 @@
this.Label_MetLocation.TabIndex = 1;
this.Label_MetLocation.Text = "Met Location:";
this.Label_MetLocation.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
this.Label_MetLocation.Click += new System.EventHandler(this.clickMetLocation);
//
// CB_MetLocation
//

View file

@ -1841,6 +1841,36 @@ namespace PKHeX
updateLegality();
}
private void clickMetLocation(object sender, EventArgs e)
{
if (HaX)
return;
var encounter = Legality.getSuggestedMetInfo();
if (encounter == null || encounter.Location < 0)
{
Util.Alert("Unable to provide a suggestion.");
return;
}
int level = encounter.Level;
int location = encounter.Location;
if (pkm.Met_Level == level && pkm.Met_Location == location)
return;
var met_list = GameInfo.getLocationList((GameVersion)pkm.Version, SAV.Generation, egg: false);
var locstr = met_list.FirstOrDefault(loc => loc.Value == location)?.Text;
string suggestion = $"Set Met Location to {locstr} @ level {level}?";
if (Util.Prompt(MessageBoxButtons.YesNo, suggestion) != DialogResult.Yes)
return;
TB_MetLevel.Text = level.ToString();
if (pkm.CurrentLevel < level)
TB_Level.Text = level.ToString();
CB_MetLocation.SelectedValue = location;
}
// Prompted Updates of PKX Functions //
private bool changingFields;
private void updateBall(object sender, EventArgs e)