2018-11-11 04:23:21 +00:00
|
|
|
|
using PKHeX.Core;
|
|
|
|
|
using PKHeX.Core.Searching;
|
|
|
|
|
using PKHeX.WinForms.Controls;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
2018-12-31 01:33:31 +00:00
|
|
|
|
using System.Runtime.CompilerServices;
|
2018-11-11 04:23:21 +00:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
2019-09-29 16:47:06 +00:00
|
|
|
|
using PKHeX.Drawing;
|
|
|
|
|
using PKHeX.WinForms.Properties;
|
2018-11-11 04:23:21 +00:00
|
|
|
|
using static PKHeX.Core.MessageStrings;
|
|
|
|
|
|
|
|
|
|
namespace PKHeX.WinForms
|
|
|
|
|
{
|
|
|
|
|
public partial class SAV_Encounters : Form
|
|
|
|
|
{
|
|
|
|
|
private readonly PKMEditor PKME_Tabs;
|
|
|
|
|
private SaveFile SAV => PKME_Tabs.RequestSaveFile;
|
2021-02-07 06:33:13 +00:00
|
|
|
|
private readonly SummaryPreviewer ShowSet = new();
|
2018-11-11 04:23:21 +00:00
|
|
|
|
|
|
|
|
|
public SAV_Encounters(PKMEditor f1)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
PKME_Tabs = f1;
|
|
|
|
|
|
2019-11-16 23:56:30 +00:00
|
|
|
|
var grid = EncounterPokeGrid;
|
|
|
|
|
var smallWidth = grid.Width;
|
|
|
|
|
var smallHeight = grid.Height;
|
|
|
|
|
grid.InitializeGrid(6, 11, SpriteUtil.Spriter);
|
|
|
|
|
grid.SetBackground(Resources.box_wp_clean);
|
|
|
|
|
var newWidth = grid.Width;
|
|
|
|
|
var newHeight = grid.Height;
|
|
|
|
|
var wdelta = newWidth - smallWidth;
|
|
|
|
|
if (wdelta != 0)
|
|
|
|
|
Width += wdelta;
|
|
|
|
|
var hdelta = newHeight - smallHeight;
|
|
|
|
|
if (hdelta != 0)
|
|
|
|
|
Height += hdelta;
|
|
|
|
|
|
|
|
|
|
PKXBOXES = grid.Entries.ToArray();
|
2018-11-11 04:23:21 +00:00
|
|
|
|
|
|
|
|
|
// Enable Scrolling when hovered over
|
|
|
|
|
foreach (var slot in PKXBOXES)
|
|
|
|
|
{
|
|
|
|
|
// Enable Click
|
|
|
|
|
slot.MouseClick += (sender, e) =>
|
|
|
|
|
{
|
2020-11-14 16:20:48 +00:00
|
|
|
|
if (sender == null)
|
|
|
|
|
return;
|
2018-11-11 04:23:21 +00:00
|
|
|
|
if (ModifierKeys == Keys.Control)
|
|
|
|
|
ClickView(sender, e);
|
|
|
|
|
};
|
2019-10-28 03:39:07 +00:00
|
|
|
|
slot.ContextMenuStrip = mnu;
|
2021-04-12 01:09:54 +00:00
|
|
|
|
if (Main.Settings.Hover.HoverSlotShowText)
|
2021-02-07 06:33:13 +00:00
|
|
|
|
slot.MouseEnter += (o, args) => ShowHoverTextForSlot(slot, args);
|
2018-11-11 04:23:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Counter = L_Count.Text;
|
|
|
|
|
L_Viewed.Text = string.Empty; // invis for now
|
|
|
|
|
L_Viewed.MouseEnter += (sender, e) => hover.SetToolTip(L_Viewed, L_Viewed.Text);
|
|
|
|
|
PopulateComboBoxes();
|
|
|
|
|
|
2018-12-31 01:33:31 +00:00
|
|
|
|
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
|
GetTypeFilters();
|
2018-12-31 01:33:31 +00:00
|
|
|
|
|
2018-11-11 04:23:21 +00:00
|
|
|
|
// Load Data
|
|
|
|
|
L_Count.Text = "Ready...";
|
|
|
|
|
|
|
|
|
|
CenterToParent();
|
|
|
|
|
}
|
|
|
|
|
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
|
private void GetTypeFilters()
|
2018-12-31 01:33:31 +00:00
|
|
|
|
{
|
|
|
|
|
var types = (EncounterOrder[])Enum.GetValues(typeof(EncounterOrder));
|
|
|
|
|
var checks = types.Select(z => new CheckBox
|
|
|
|
|
{
|
|
|
|
|
Name = z.ToString(),
|
|
|
|
|
Text = z.ToString(),
|
|
|
|
|
AutoSize = true,
|
|
|
|
|
Checked = true,
|
|
|
|
|
Padding = Padding.Empty,
|
|
|
|
|
Margin = Padding.Empty,
|
|
|
|
|
}).ToArray();
|
|
|
|
|
foreach (var chk in checks)
|
|
|
|
|
{
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
|
TypeFilters.Controls.Add(chk);
|
|
|
|
|
TypeFilters.SetFlowBreak(chk, true);
|
2018-12-31 01:33:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private EncounterOrder[] GetTypes()
|
|
|
|
|
{
|
|
|
|
|
return TypeFilters.Controls.OfType<CheckBox>().Where(z => z.Checked).Select(z => z.Name)
|
|
|
|
|
.Select(z => (EncounterOrder)Enum.Parse(typeof(EncounterOrder), z)).ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-11 04:23:21 +00:00
|
|
|
|
private readonly PictureBox[] PKXBOXES;
|
Fracture the encounter matching checks to allow progressive validation (#3137)
## Issue
We want to discard-but-remember any slots that aren't a perfect fit, on the off chance that a better one exists later in the search space. If there's no better match, then we gotta go with what we got.
## Example:
Wurmple exists in area `X`, and also has a more rare slot for Silcoon, with the same level for both slots.
* We have a Silcoon that we've leveled up a few times.
Was our Silcoon originally a Wurmple, or was it caught as a Silcoon?
* To be sure, we have to check the EC/PID if the Wurmple wouldn't evolve into Cascoon instead.
* We don't want to wholly reject that Wurmple slot, as maybe the Met Level isn't within Silcoon's slot range.
---
Existing implementation would store "deferred" matches in a list; we only need to keep 1 of these matches around (less allocation!). We also want to differentiate between a "good" deferral and a "bad" deferral; I don't think this is necessary but it's currently used by Mystery Gift matching (implemented for the Eeveelution mystery gifts which matter for evolution moves).
The existing logic didn't use inheritance, and instead had static methods being reused across generations. Quite kludgy. Also, the existing logic was a pain to modify the master encounter yield methods, as one generation's quirks had to not impact all other generations that used the method.
---
The new implementation splits out the encounter yielding methods to be separate for each generation / subset. Now, things don't have to check `WasLink` for Gen7 origin, because Pokémon Link wasn't a thing in Gen7.
---
## Future
Maybe refactoring yielders into "GameCores" that expose yielding behaviors / properties, rather than the static logic. As more generations and side-gamegroups get added (thanks LGPE/GO/GameCube), all this switch stuff gets annoying to maintain instead of just overriding/inheritance.
## Conclusion
This shouldn't impact any legality results negatively; if you notice any regressions, report them! This should reduce false flags where we didn't defer-discard an encounter when we should have (wild area mons being confused with raids).
2021-01-30 01:55:27 +00:00
|
|
|
|
private List<IEncounterInfo> Results = new();
|
2018-11-11 04:23:21 +00:00
|
|
|
|
private int slotSelected = -1; // = null;
|
2020-10-18 18:02:39 +00:00
|
|
|
|
private Image? slotColor;
|
2018-11-11 04:23:21 +00:00
|
|
|
|
private const int RES_MAX = 66;
|
|
|
|
|
private const int RES_MIN = 6;
|
|
|
|
|
private readonly string Counter;
|
|
|
|
|
|
2021-02-07 06:33:13 +00:00
|
|
|
|
private bool GetShiftedIndex(ref int index)
|
|
|
|
|
{
|
|
|
|
|
if (index >= RES_MAX)
|
|
|
|
|
return false;
|
|
|
|
|
index += SCR_Box.Value * RES_MIN;
|
|
|
|
|
return index < Results.Count;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-11 04:23:21 +00:00
|
|
|
|
// Important Events
|
|
|
|
|
private void ClickView(object sender, EventArgs e)
|
|
|
|
|
{
|
2019-09-25 01:14:15 +00:00
|
|
|
|
var pb = WinFormsUtil.GetUnderlyingControl<PictureBox>(sender);
|
2019-09-29 16:47:06 +00:00
|
|
|
|
int index = Array.IndexOf(PKXBOXES, pb);
|
2018-11-11 04:23:21 +00:00
|
|
|
|
if (index >= RES_MAX)
|
|
|
|
|
{
|
|
|
|
|
System.Media.SystemSounds.Exclamation.Play();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
index += SCR_Box.Value * RES_MIN;
|
|
|
|
|
if (index >= Results.Count)
|
|
|
|
|
{
|
|
|
|
|
System.Media.SystemSounds.Exclamation.Play();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-31 01:33:31 +00:00
|
|
|
|
var enc = Results[index];
|
|
|
|
|
var pk = enc.ConvertToPKM(SAV);
|
|
|
|
|
pk.RefreshChecksum();
|
|
|
|
|
PKME_Tabs.PopulateFields(pk, false);
|
2018-11-11 04:23:21 +00:00
|
|
|
|
slotSelected = index;
|
2019-11-16 01:34:18 +00:00
|
|
|
|
slotColor = SpriteUtil.Spriter.View;
|
2018-11-11 04:23:21 +00:00
|
|
|
|
FillPKXBoxes(SCR_Box.Value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void PopulateComboBoxes()
|
|
|
|
|
{
|
|
|
|
|
// Set the Text
|
|
|
|
|
CB_Species.InitializeBinding();
|
2018-12-31 01:33:31 +00:00
|
|
|
|
CB_GameOrigin.InitializeBinding();
|
2018-11-11 04:23:21 +00:00
|
|
|
|
|
2019-06-02 02:12:41 +00:00
|
|
|
|
var Any = new ComboItem(MsgAny, -1);
|
2018-11-11 04:23:21 +00:00
|
|
|
|
|
|
|
|
|
var DS_Species = new List<ComboItem>(GameInfo.SpeciesDataSource);
|
|
|
|
|
DS_Species.RemoveAt(0); DS_Species.Insert(0, Any); CB_Species.DataSource = DS_Species;
|
|
|
|
|
|
|
|
|
|
// Set the Move ComboBoxes too..
|
|
|
|
|
var DS_Move = new List<ComboItem>(GameInfo.MoveDataSource);
|
|
|
|
|
DS_Move.RemoveAt(0); DS_Move.Insert(0, Any);
|
|
|
|
|
{
|
|
|
|
|
foreach (ComboBox cb in new[] { CB_Move1, CB_Move2, CB_Move3, CB_Move4 })
|
|
|
|
|
{
|
|
|
|
|
cb.InitializeBinding();
|
|
|
|
|
cb.DataSource = new BindingSource(DS_Move, null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-31 01:33:31 +00:00
|
|
|
|
var DS_Version = new List<ComboItem>(GameInfo.VersionDataSource);
|
|
|
|
|
DS_Version.Insert(0, Any); CB_GameOrigin.DataSource = DS_Version;
|
|
|
|
|
|
2018-11-11 04:23:21 +00:00
|
|
|
|
// Trigger a Reset
|
2020-10-18 18:02:39 +00:00
|
|
|
|
ResetFilters(this, EventArgs.Empty);
|
2018-11-11 04:23:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ResetFilters(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
CB_Species.SelectedIndex = 0;
|
|
|
|
|
CB_Move1.SelectedIndex = CB_Move2.SelectedIndex = CB_Move3.SelectedIndex = CB_Move4.SelectedIndex = 0;
|
2018-12-31 01:33:31 +00:00
|
|
|
|
CB_GameOrigin.SelectedIndex = 0;
|
2018-11-11 04:23:21 +00:00
|
|
|
|
|
|
|
|
|
RTB_Instructions.Clear();
|
2020-10-18 18:02:39 +00:00
|
|
|
|
if (sender == this)
|
2019-01-01 07:39:08 +00:00
|
|
|
|
return; // still starting up
|
2018-12-31 01:33:31 +00:00
|
|
|
|
foreach (var chk in TypeFilters.Controls.OfType<CheckBox>())
|
|
|
|
|
chk.Checked = true;
|
2018-11-11 04:23:21 +00:00
|
|
|
|
|
2019-01-01 07:39:08 +00:00
|
|
|
|
System.Media.SystemSounds.Asterisk.Play();
|
2018-11-11 04:23:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// View Updates
|
Fracture the encounter matching checks to allow progressive validation (#3137)
## Issue
We want to discard-but-remember any slots that aren't a perfect fit, on the off chance that a better one exists later in the search space. If there's no better match, then we gotta go with what we got.
## Example:
Wurmple exists in area `X`, and also has a more rare slot for Silcoon, with the same level for both slots.
* We have a Silcoon that we've leveled up a few times.
Was our Silcoon originally a Wurmple, or was it caught as a Silcoon?
* To be sure, we have to check the EC/PID if the Wurmple wouldn't evolve into Cascoon instead.
* We don't want to wholly reject that Wurmple slot, as maybe the Met Level isn't within Silcoon's slot range.
---
Existing implementation would store "deferred" matches in a list; we only need to keep 1 of these matches around (less allocation!). We also want to differentiate between a "good" deferral and a "bad" deferral; I don't think this is necessary but it's currently used by Mystery Gift matching (implemented for the Eeveelution mystery gifts which matter for evolution moves).
The existing logic didn't use inheritance, and instead had static methods being reused across generations. Quite kludgy. Also, the existing logic was a pain to modify the master encounter yield methods, as one generation's quirks had to not impact all other generations that used the method.
---
The new implementation splits out the encounter yielding methods to be separate for each generation / subset. Now, things don't have to check `WasLink` for Gen7 origin, because Pokémon Link wasn't a thing in Gen7.
---
## Future
Maybe refactoring yielders into "GameCores" that expose yielding behaviors / properties, rather than the static logic. As more generations and side-gamegroups get added (thanks LGPE/GO/GameCube), all this switch stuff gets annoying to maintain instead of just overriding/inheritance.
## Conclusion
This shouldn't impact any legality results negatively; if you notice any regressions, report them! This should reduce false flags where we didn't defer-discard an encounter when we should have (wild area mons being confused with raids).
2021-01-30 01:55:27 +00:00
|
|
|
|
private IEnumerable<IEncounterInfo> SearchDatabase()
|
2018-11-11 04:23:21 +00:00
|
|
|
|
{
|
|
|
|
|
var settings = GetSearchSettings();
|
|
|
|
|
var moves = settings.Moves.ToArray();
|
2020-01-04 19:09:50 +00:00
|
|
|
|
|
|
|
|
|
// If nothing is specified, instead of just returning all possible encounters, just return nothing.
|
2021-06-04 00:36:16 +00:00
|
|
|
|
if (settings.Species <= 0 && moves.Length == 0 && Main.Settings.EncounterDb.ReturnNoneIfEmptySearch)
|
Fracture the encounter matching checks to allow progressive validation (#3137)
## Issue
We want to discard-but-remember any slots that aren't a perfect fit, on the off chance that a better one exists later in the search space. If there's no better match, then we gotta go with what we got.
## Example:
Wurmple exists in area `X`, and also has a more rare slot for Silcoon, with the same level for both slots.
* We have a Silcoon that we've leveled up a few times.
Was our Silcoon originally a Wurmple, or was it caught as a Silcoon?
* To be sure, we have to check the EC/PID if the Wurmple wouldn't evolve into Cascoon instead.
* We don't want to wholly reject that Wurmple slot, as maybe the Met Level isn't within Silcoon's slot range.
---
Existing implementation would store "deferred" matches in a list; we only need to keep 1 of these matches around (less allocation!). We also want to differentiate between a "good" deferral and a "bad" deferral; I don't think this is necessary but it's currently used by Mystery Gift matching (implemented for the Eeveelution mystery gifts which matter for evolution moves).
The existing logic didn't use inheritance, and instead had static methods being reused across generations. Quite kludgy. Also, the existing logic was a pain to modify the master encounter yield methods, as one generation's quirks had to not impact all other generations that used the method.
---
The new implementation splits out the encounter yielding methods to be separate for each generation / subset. Now, things don't have to check `WasLink` for Gen7 origin, because Pokémon Link wasn't a thing in Gen7.
---
## Future
Maybe refactoring yielders into "GameCores" that expose yielding behaviors / properties, rather than the static logic. As more generations and side-gamegroups get added (thanks LGPE/GO/GameCube), all this switch stuff gets annoying to maintain instead of just overriding/inheritance.
## Conclusion
This shouldn't impact any legality results negatively; if you notice any regressions, report them! This should reduce false flags where we didn't defer-discard an encounter when we should have (wild area mons being confused with raids).
2021-01-30 01:55:27 +00:00
|
|
|
|
return Array.Empty<IEncounterInfo>();
|
2018-11-11 04:23:21 +00:00
|
|
|
|
var pk = SAV.BlankPKM;
|
|
|
|
|
|
|
|
|
|
var species = settings.Species <= 0 ? Enumerable.Range(1, SAV.MaxSpeciesID) : new[] { settings.Species };
|
2018-12-31 01:33:31 +00:00
|
|
|
|
var versions = settings.GetVersions(SAV);
|
|
|
|
|
var results = species.SelectMany(z => GetEncounters(z, moves, pk, versions));
|
2018-11-11 04:23:21 +00:00
|
|
|
|
if (settings.SearchEgg != null)
|
|
|
|
|
results = results.Where(z => z.EggEncounter == settings.SearchEgg);
|
2021-05-18 23:17:57 +00:00
|
|
|
|
if (settings.SearchShiny != null)
|
|
|
|
|
results = results.Where(z => z.IsShiny == settings.SearchShiny);
|
2018-11-11 04:23:21 +00:00
|
|
|
|
|
|
|
|
|
// return filtered results
|
Fracture the encounter matching checks to allow progressive validation (#3137)
## Issue
We want to discard-but-remember any slots that aren't a perfect fit, on the off chance that a better one exists later in the search space. If there's no better match, then we gotta go with what we got.
## Example:
Wurmple exists in area `X`, and also has a more rare slot for Silcoon, with the same level for both slots.
* We have a Silcoon that we've leveled up a few times.
Was our Silcoon originally a Wurmple, or was it caught as a Silcoon?
* To be sure, we have to check the EC/PID if the Wurmple wouldn't evolve into Cascoon instead.
* We don't want to wholly reject that Wurmple slot, as maybe the Met Level isn't within Silcoon's slot range.
---
Existing implementation would store "deferred" matches in a list; we only need to keep 1 of these matches around (less allocation!). We also want to differentiate between a "good" deferral and a "bad" deferral; I don't think this is necessary but it's currently used by Mystery Gift matching (implemented for the Eeveelution mystery gifts which matter for evolution moves).
The existing logic didn't use inheritance, and instead had static methods being reused across generations. Quite kludgy. Also, the existing logic was a pain to modify the master encounter yield methods, as one generation's quirks had to not impact all other generations that used the method.
---
The new implementation splits out the encounter yielding methods to be separate for each generation / subset. Now, things don't have to check `WasLink` for Gen7 origin, because Pokémon Link wasn't a thing in Gen7.
---
## Future
Maybe refactoring yielders into "GameCores" that expose yielding behaviors / properties, rather than the static logic. As more generations and side-gamegroups get added (thanks LGPE/GO/GameCube), all this switch stuff gets annoying to maintain instead of just overriding/inheritance.
## Conclusion
This shouldn't impact any legality results negatively; if you notice any regressions, report them! This should reduce false flags where we didn't defer-discard an encounter when we should have (wild area mons being confused with raids).
2021-01-30 01:55:27 +00:00
|
|
|
|
var comparer = new ReferenceComparer<IEncounterInfo>();
|
2019-11-17 05:55:38 +00:00
|
|
|
|
results = results.Distinct(comparer); // only distinct objects
|
|
|
|
|
|
2021-06-04 00:48:32 +00:00
|
|
|
|
if (Main.Settings.EncounterDb.FilterUnavailableSpecies)
|
|
|
|
|
{
|
|
|
|
|
results = SAV is SAV8SWSH
|
|
|
|
|
? results.Where(z => ((PersonalInfoSWSH)PersonalTable.SWSH.GetFormEntry(z.Species, z.Form)).IsPresentInGame)
|
|
|
|
|
: results.Where(z => z.Generation <= 7);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-09 03:14:27 +00:00
|
|
|
|
if (RTB_Instructions.Lines.Any(line => line.Length > 0))
|
|
|
|
|
{
|
|
|
|
|
var filters = StringInstruction.GetFilters(RTB_Instructions.Lines).ToArray();
|
|
|
|
|
BatchEditing.ScreenStrings(filters);
|
|
|
|
|
results = results.Where(enc => BatchEditing.IsFilterMatch(filters, enc)); // Compare across all filters
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-17 05:55:38 +00:00
|
|
|
|
return results;
|
2018-11-11 04:23:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-18 18:02:39 +00:00
|
|
|
|
private sealed class ReferenceComparer<T> : IEqualityComparer<T> where T : class
|
2018-11-11 04:23:21 +00:00
|
|
|
|
{
|
2020-10-18 18:02:39 +00:00
|
|
|
|
public bool Equals(T? x, T? y)
|
|
|
|
|
{
|
|
|
|
|
if (x == null)
|
|
|
|
|
return false;
|
|
|
|
|
if (y == null)
|
|
|
|
|
return false;
|
|
|
|
|
return RuntimeHelpers.GetHashCode(x).Equals(RuntimeHelpers.GetHashCode(y));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int GetHashCode(T obj)
|
|
|
|
|
{
|
|
|
|
|
if (obj == null) throw new ArgumentNullException(nameof(obj));
|
|
|
|
|
return RuntimeHelpers.GetHashCode(obj);
|
|
|
|
|
}
|
2018-12-31 01:33:31 +00:00
|
|
|
|
}
|
2018-11-11 04:23:21 +00:00
|
|
|
|
|
Fracture the encounter matching checks to allow progressive validation (#3137)
## Issue
We want to discard-but-remember any slots that aren't a perfect fit, on the off chance that a better one exists later in the search space. If there's no better match, then we gotta go with what we got.
## Example:
Wurmple exists in area `X`, and also has a more rare slot for Silcoon, with the same level for both slots.
* We have a Silcoon that we've leveled up a few times.
Was our Silcoon originally a Wurmple, or was it caught as a Silcoon?
* To be sure, we have to check the EC/PID if the Wurmple wouldn't evolve into Cascoon instead.
* We don't want to wholly reject that Wurmple slot, as maybe the Met Level isn't within Silcoon's slot range.
---
Existing implementation would store "deferred" matches in a list; we only need to keep 1 of these matches around (less allocation!). We also want to differentiate between a "good" deferral and a "bad" deferral; I don't think this is necessary but it's currently used by Mystery Gift matching (implemented for the Eeveelution mystery gifts which matter for evolution moves).
The existing logic didn't use inheritance, and instead had static methods being reused across generations. Quite kludgy. Also, the existing logic was a pain to modify the master encounter yield methods, as one generation's quirks had to not impact all other generations that used the method.
---
The new implementation splits out the encounter yielding methods to be separate for each generation / subset. Now, things don't have to check `WasLink` for Gen7 origin, because Pokémon Link wasn't a thing in Gen7.
---
## Future
Maybe refactoring yielders into "GameCores" that expose yielding behaviors / properties, rather than the static logic. As more generations and side-gamegroups get added (thanks LGPE/GO/GameCube), all this switch stuff gets annoying to maintain instead of just overriding/inheritance.
## Conclusion
This shouldn't impact any legality results negatively; if you notice any regressions, report them! This should reduce false flags where we didn't defer-discard an encounter when we should have (wild area mons being confused with raids).
2021-01-30 01:55:27 +00:00
|
|
|
|
private static IEnumerable<IEncounterInfo> GetEncounters(int species, int[] moves, PKM pk, IReadOnlyList<GameVersion> vers)
|
2018-12-31 01:33:31 +00:00
|
|
|
|
{
|
|
|
|
|
pk.Species = species;
|
2021-02-03 19:48:23 +00:00
|
|
|
|
pk.SetGender(pk.GetSaneGender());
|
2018-11-11 04:23:21 +00:00
|
|
|
|
return EncounterMovesetGenerator.GenerateEncounters(pk, moves, vers);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private SearchSettings GetSearchSettings()
|
|
|
|
|
{
|
|
|
|
|
var settings = new SearchSettings
|
|
|
|
|
{
|
|
|
|
|
Format = SAV.Generation, // 0->(n-1) => 1->n
|
|
|
|
|
Generation = SAV.Generation,
|
|
|
|
|
|
|
|
|
|
Species = WinFormsUtil.GetIndex(CB_Species),
|
|
|
|
|
|
|
|
|
|
BatchInstructions = RTB_Instructions.Lines,
|
2018-12-31 01:33:31 +00:00
|
|
|
|
Version = WinFormsUtil.GetIndex(CB_GameOrigin),
|
2018-11-11 04:23:21 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
settings.AddMove(WinFormsUtil.GetIndex(CB_Move1));
|
|
|
|
|
settings.AddMove(WinFormsUtil.GetIndex(CB_Move2));
|
|
|
|
|
settings.AddMove(WinFormsUtil.GetIndex(CB_Move3));
|
|
|
|
|
settings.AddMove(WinFormsUtil.GetIndex(CB_Move4));
|
|
|
|
|
|
|
|
|
|
if (CHK_IsEgg.CheckState != CheckState.Indeterminate)
|
|
|
|
|
settings.SearchEgg = CHK_IsEgg.CheckState == CheckState.Checked;
|
|
|
|
|
|
2021-05-18 23:17:57 +00:00
|
|
|
|
if (CHK_Shiny.CheckState != CheckState.Indeterminate)
|
|
|
|
|
settings.SearchShiny = CHK_Shiny.CheckState == CheckState.Checked;
|
|
|
|
|
|
2018-11-11 04:23:21 +00:00
|
|
|
|
return settings;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async void B_Search_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
B_Search.Enabled = false;
|
2018-12-31 01:33:31 +00:00
|
|
|
|
EncounterMovesetGenerator.PriorityList = GetTypes();
|
2018-11-11 04:23:21 +00:00
|
|
|
|
var search = SearchDatabase();
|
|
|
|
|
|
|
|
|
|
var results = await Task.Run(() => search.ToList()).ConfigureAwait(true);
|
|
|
|
|
|
|
|
|
|
if (results.Count == 0)
|
|
|
|
|
WinFormsUtil.Alert(MsgDBSearchNone);
|
|
|
|
|
|
|
|
|
|
SetResults(results); // updates Count Label as well.
|
|
|
|
|
System.Media.SystemSounds.Asterisk.Play();
|
|
|
|
|
B_Search.Enabled = true;
|
2018-12-31 01:33:31 +00:00
|
|
|
|
EncounterMovesetGenerator.ResetFilters();
|
2018-11-11 04:23:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateScroll(object sender, ScrollEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.OldValue != e.NewValue)
|
|
|
|
|
FillPKXBoxes(e.NewValue);
|
|
|
|
|
}
|
|
|
|
|
|
Fracture the encounter matching checks to allow progressive validation (#3137)
## Issue
We want to discard-but-remember any slots that aren't a perfect fit, on the off chance that a better one exists later in the search space. If there's no better match, then we gotta go with what we got.
## Example:
Wurmple exists in area `X`, and also has a more rare slot for Silcoon, with the same level for both slots.
* We have a Silcoon that we've leveled up a few times.
Was our Silcoon originally a Wurmple, or was it caught as a Silcoon?
* To be sure, we have to check the EC/PID if the Wurmple wouldn't evolve into Cascoon instead.
* We don't want to wholly reject that Wurmple slot, as maybe the Met Level isn't within Silcoon's slot range.
---
Existing implementation would store "deferred" matches in a list; we only need to keep 1 of these matches around (less allocation!). We also want to differentiate between a "good" deferral and a "bad" deferral; I don't think this is necessary but it's currently used by Mystery Gift matching (implemented for the Eeveelution mystery gifts which matter for evolution moves).
The existing logic didn't use inheritance, and instead had static methods being reused across generations. Quite kludgy. Also, the existing logic was a pain to modify the master encounter yield methods, as one generation's quirks had to not impact all other generations that used the method.
---
The new implementation splits out the encounter yielding methods to be separate for each generation / subset. Now, things don't have to check `WasLink` for Gen7 origin, because Pokémon Link wasn't a thing in Gen7.
---
## Future
Maybe refactoring yielders into "GameCores" that expose yielding behaviors / properties, rather than the static logic. As more generations and side-gamegroups get added (thanks LGPE/GO/GameCube), all this switch stuff gets annoying to maintain instead of just overriding/inheritance.
## Conclusion
This shouldn't impact any legality results negatively; if you notice any regressions, report them! This should reduce false flags where we didn't defer-discard an encounter when we should have (wild area mons being confused with raids).
2021-01-30 01:55:27 +00:00
|
|
|
|
private void SetResults(List<IEncounterInfo> res)
|
2018-11-11 04:23:21 +00:00
|
|
|
|
{
|
|
|
|
|
Results = res;
|
2021-06-04 00:32:13 +00:00
|
|
|
|
ShowSet.Clear();
|
2018-11-11 04:23:21 +00:00
|
|
|
|
|
|
|
|
|
SCR_Box.Maximum = (int)Math.Ceiling((decimal)Results.Count / RES_MIN);
|
|
|
|
|
if (SCR_Box.Maximum > 0) SCR_Box.Maximum--;
|
|
|
|
|
|
|
|
|
|
slotSelected = -1; // reset the slot last viewed
|
|
|
|
|
SCR_Box.Value = 0;
|
|
|
|
|
FillPKXBoxes(0);
|
|
|
|
|
|
|
|
|
|
L_Count.Text = string.Format(Counter, Results.Count);
|
|
|
|
|
B_Search.Enabled = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FillPKXBoxes(int start)
|
|
|
|
|
{
|
2021-05-27 17:27:50 +00:00
|
|
|
|
var boxes = PKXBOXES;
|
2020-10-18 18:02:39 +00:00
|
|
|
|
if (Results.Count == 0)
|
2018-11-11 04:23:21 +00:00
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < RES_MAX; i++)
|
2020-10-18 18:02:39 +00:00
|
|
|
|
{
|
2021-05-27 17:27:50 +00:00
|
|
|
|
boxes[i].Image = null;
|
|
|
|
|
boxes[i].BackgroundImage = null;
|
2020-10-18 18:02:39 +00:00
|
|
|
|
}
|
2018-11-11 04:23:21 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2021-05-27 17:27:50 +00:00
|
|
|
|
|
|
|
|
|
// Load new sprites
|
2018-11-11 04:23:21 +00:00
|
|
|
|
int begin = start*RES_MIN;
|
|
|
|
|
int end = Math.Min(RES_MAX, Results.Count - begin);
|
|
|
|
|
for (int i = 0; i < end; i++)
|
|
|
|
|
{
|
|
|
|
|
var enc = Results[i + begin];
|
2021-05-27 17:27:50 +00:00
|
|
|
|
boxes[i].Image = GetImage(enc);
|
2018-11-11 04:23:21 +00:00
|
|
|
|
}
|
2021-05-27 17:27:50 +00:00
|
|
|
|
|
|
|
|
|
// Clear empty slots
|
2018-11-11 04:23:21 +00:00
|
|
|
|
for (int i = end; i < RES_MAX; i++)
|
2021-05-27 17:27:50 +00:00
|
|
|
|
boxes[i].Image = null;
|
2018-11-11 04:23:21 +00:00
|
|
|
|
|
2021-05-27 17:27:50 +00:00
|
|
|
|
// Reset backgrounds for all
|
2018-11-11 04:23:21 +00:00
|
|
|
|
for (int i = 0; i < RES_MAX; i++)
|
2021-05-27 17:27:50 +00:00
|
|
|
|
boxes[i].BackgroundImage = SpriteUtil.Spriter.Transparent;
|
|
|
|
|
|
|
|
|
|
// Reload last viewed index's background if still within view
|
2018-11-11 04:23:21 +00:00
|
|
|
|
if (slotSelected != -1 && slotSelected >= begin && slotSelected < begin + RES_MAX)
|
2021-05-27 17:27:50 +00:00
|
|
|
|
boxes[slotSelected - begin].BackgroundImage = slotColor ?? SpriteUtil.Spriter.View;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Image GetImage(IEncounterTemplate enc)
|
|
|
|
|
{
|
|
|
|
|
var gender = GetDisplayGender(enc);
|
|
|
|
|
return SpriteUtil.GetSprite(enc.Species, enc.Form, gender, 0, 0, enc.EggEncounter, enc.IsShiny, enc.Generation);
|
2018-11-11 04:23:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-27 17:27:50 +00:00
|
|
|
|
public static int GetDisplayGender(IEncounterTemplate enc) => enc switch
|
|
|
|
|
{
|
|
|
|
|
EncounterSlotGO g => (int) g.Gender & 1,
|
|
|
|
|
EncounterStatic s => Math.Max(0, s.Gender),
|
|
|
|
|
EncounterTrade t => Math.Max(0, t.Gender),
|
|
|
|
|
MysteryGift f => Math.Max(0, f.Gender),
|
|
|
|
|
_ => 0,
|
|
|
|
|
};
|
|
|
|
|
|
2018-11-11 04:23:21 +00:00
|
|
|
|
private void Menu_Exit_Click(object sender, EventArgs e) => Close();
|
|
|
|
|
|
|
|
|
|
protected override void OnMouseWheel(MouseEventArgs e)
|
|
|
|
|
{
|
2019-11-16 01:34:18 +00:00
|
|
|
|
if (!EncounterPokeGrid.RectangleToScreen(EncounterPokeGrid.ClientRectangle).Contains(MousePosition))
|
2018-11-11 04:23:21 +00:00
|
|
|
|
return;
|
|
|
|
|
int oldval = SCR_Box.Value;
|
|
|
|
|
int newval = oldval + (e.Delta < 0 ? 1 : -1);
|
|
|
|
|
if (newval >= SCR_Box.Minimum && SCR_Box.Maximum >= newval)
|
|
|
|
|
FillPKXBoxes(SCR_Box.Value = newval);
|
|
|
|
|
}
|
2021-02-07 06:33:13 +00:00
|
|
|
|
|
|
|
|
|
private void ShowHoverTextForSlot(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var pb = (PictureBox)sender;
|
|
|
|
|
int index = Array.IndexOf(PKXBOXES, pb);
|
|
|
|
|
if (!GetShiftedIndex(ref index))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ShowSet.Show(pb, Results[index]);
|
|
|
|
|
}
|
2018-11-11 04:23:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|