mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-05-09 04:24:36 -05:00
Rewrite encounter suggestions
Don't clone legality templates, and keep suggested information minimal -- this isn't automod
This commit is contained in:
parent
693a630882
commit
5a20dc707d
|
|
@ -398,11 +398,11 @@ private static ModifyResult SetSuggestedPKMProperty(string name, PKMInfo info, s
|
|||
RibbonApplicator.SetAllValidRibbons(pk);
|
||||
return ModifyResult.Modified;
|
||||
case nameof(PKM.Met_Location):
|
||||
var encounter = info.SuggestedEncounter;
|
||||
var encounter = EncounterSuggestion.GetSuggestedMetInfo(pk);
|
||||
if (encounter == null)
|
||||
return ModifyResult.Error;
|
||||
|
||||
int level = encounter.Level;
|
||||
int level = encounter.LevelMin;
|
||||
int location = encounter.Location;
|
||||
int minlvl = Legal.GetLowestLevel(pk, encounter.LevelMin);
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,5 @@ internal sealed class PKMInfo
|
|||
|
||||
public bool Legal => Legality.Valid;
|
||||
internal IReadOnlyList<int> SuggestedRelearn => Legality.GetSuggestedRelearn();
|
||||
internal EncounterStatic? SuggestedEncounter => EncounterSuggestion.GetSuggestedMetInfo(Entity);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
using System.Linq;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace PKHeX.Core
|
||||
{
|
||||
|
|
@ -10,7 +11,7 @@ public static class EncounterSuggestion
|
|||
/// <summary>
|
||||
/// Gets an object containing met data properties that might be legal.
|
||||
/// </summary>
|
||||
public static EncounterStatic? GetSuggestedMetInfo(PKM pkm)
|
||||
public static EncounterSuggestionData? GetSuggestedMetInfo(PKM pkm)
|
||||
{
|
||||
int loc = GetSuggestedTransferLocation(pkm);
|
||||
|
||||
|
|
@ -19,26 +20,20 @@ public static class EncounterSuggestion
|
|||
|
||||
var w = EncounterSlotGenerator.GetCaptureLocation(pkm);
|
||||
if (w != null)
|
||||
return GetSuggestedEncounterWild(w, loc);
|
||||
return GetSuggestedEncounterWild(pkm, w, loc);
|
||||
|
||||
var s = EncounterStaticGenerator.GetStaticLocation(pkm);
|
||||
if (s != null)
|
||||
return GetSuggestedEncounterStatic(s, loc);
|
||||
return GetSuggestedEncounterStatic(pkm, s, loc);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static EncounterStatic GetSuggestedEncounterEgg(PKM pkm, int loc = -1)
|
||||
private static EncounterSuggestionData GetSuggestedEncounterEgg(PKM pkm, int loc = -1)
|
||||
{
|
||||
int lvl = GetSuggestedEncounterEggMetLevel(pkm);
|
||||
var evo = Legal.GetBaseSpecies(pkm);
|
||||
return new EncounterStatic
|
||||
{
|
||||
Species = evo.Species,
|
||||
Form = evo.Form,
|
||||
Location = loc != -1 ? loc : GetSuggestedEggMetLocation(pkm),
|
||||
Level = lvl,
|
||||
};
|
||||
var met = loc != -1 ? loc : GetSuggestedEggMetLocation(pkm);
|
||||
return new EncounterSuggestionData(pkm, met, lvl);
|
||||
}
|
||||
|
||||
public static int GetSuggestedEncounterEggMetLevel(PKM pkm)
|
||||
|
|
@ -67,26 +62,18 @@ public static int GetSuggestedEncounterEggLocationEgg(PKM pkm, bool traded = fal
|
|||
}
|
||||
}
|
||||
|
||||
private static EncounterStatic GetSuggestedEncounterWild(EncounterArea area, int loc = -1)
|
||||
private static EncounterSuggestionData GetSuggestedEncounterWild(PKM pkm, EncounterArea area, int loc = -1)
|
||||
{
|
||||
var slots = area.Slots.OrderBy(s => s.LevelMin);
|
||||
var first = slots.First();
|
||||
return new EncounterStatic
|
||||
{
|
||||
Location = loc != -1 ? loc : area.Location,
|
||||
Species = first.Species,
|
||||
Level = first.LevelMin,
|
||||
};
|
||||
var met = loc != -1 ? loc : area.Location;
|
||||
return new EncounterSuggestionData(pkm, first, met);
|
||||
}
|
||||
|
||||
private static EncounterStatic GetSuggestedEncounterStatic(EncounterStatic s, int loc = -1)
|
||||
private static EncounterSuggestionData GetSuggestedEncounterStatic(PKM pkm, EncounterStatic s, int loc = -1)
|
||||
{
|
||||
if (loc == -1)
|
||||
loc = s.Location;
|
||||
|
||||
// don't leak out the original EncounterStatic object
|
||||
var encounter = s.Clone(loc);
|
||||
return encounter;
|
||||
var met = loc != -1 ? loc : s.Location;
|
||||
return new EncounterSuggestionData(pkm, s, met);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -179,4 +166,52 @@ public static int GetSuggestedTransferLocation(PKM pkm)
|
|||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class EncounterSuggestionData : IRelearn
|
||||
{
|
||||
private readonly IEncounterable? Encounter;
|
||||
|
||||
public int[] Relearn => Encounter is IRelearn r ? r.Relearn : Array.Empty<int>();
|
||||
|
||||
public EncounterSuggestionData(PKM pkm, IEncounterable enc, int met)
|
||||
{
|
||||
Encounter = enc;
|
||||
Species = pkm.Species;
|
||||
Form = pkm.AltForm;
|
||||
Location = met;
|
||||
|
||||
LevelMin = enc.LevelMin;
|
||||
LevelMax = enc.LevelMax;
|
||||
}
|
||||
|
||||
public EncounterSuggestionData(PKM pkm, int met, int lvl)
|
||||
{
|
||||
Species = pkm.Species;
|
||||
Form = pkm.AltForm;
|
||||
Location = met;
|
||||
|
||||
LevelMin = lvl;
|
||||
LevelMax = lvl;
|
||||
}
|
||||
|
||||
public int Species { get; }
|
||||
public int Form { get; }
|
||||
public int Location { get; }
|
||||
|
||||
public int LevelMin { get; }
|
||||
public int LevelMax { get; }
|
||||
|
||||
public int GetSuggestedMetLevel(PKM pkm)
|
||||
{
|
||||
var clone = pkm.Clone();
|
||||
for (int i = clone.CurrentLevel; i > LevelMin; i--)
|
||||
{
|
||||
clone.Met_Level = i;
|
||||
var la = new LegalityAnalysis(clone);
|
||||
if (la.Valid)
|
||||
return i;
|
||||
}
|
||||
return LevelMin;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -741,7 +741,7 @@ private bool SetSuggestedMetLocation(bool silent = false)
|
|||
return false;
|
||||
}
|
||||
|
||||
int level = encounter.Level;
|
||||
int level = encounter.LevelMin;
|
||||
int location = encounter.Location;
|
||||
int minlvl = Legal.GetLowestLevel(Entity, encounter.LevelMin);
|
||||
if (minlvl == 0)
|
||||
|
|
@ -765,7 +765,7 @@ private bool SetSuggestedMetLocation(bool silent = false)
|
|||
|
||||
if (Entity.Format >= 3)
|
||||
{
|
||||
TB_MetLevel.Text = level.ToString();
|
||||
TB_MetLevel.Text = encounter.GetSuggestedMetLevel(Entity).ToString();
|
||||
CB_MetLocation.SelectedValue = location;
|
||||
|
||||
if (Entity.Gen6 && Entity.WasEgg && ModifyPKM)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user