Commit graph

316 commits

Author SHA1 Message Date
Kurt
0b32cbf132 Update PKHeX.Core abstractions with latest logic
Co-Authored-By: Matt <17801814+sora10pls@users.noreply.github.com>
Co-Authored-By: SciresM <8676005+SciresM@users.noreply.github.com>
Co-Authored-By: Lusamine <30205550+Lusamine@users.noreply.github.com>
2022-02-04 17:35:15 -08:00
Kurt
9cde291595
Enumerate ability permissions in encounter templates, misc updates (#3368) 2022-01-08 22:34:04 -08:00
Kurt
47071b41f3
Refactoring: Span-based value writes and method signatures (#3361)
Existing `get`/`set` logic is flawed in that it doesn't work on Big Endian operating systems, and it allocates heap objects when it doesn't need to.

`System.Buffers.Binary.BinaryPrimitives` in the `System.Memory` NuGet package provides both Little Endian and Big Endian methods to read and write data; all the `get`/`set` operations have been reworked to use this new API. This removes the need for PKHeX's manual `BigEndian` class, as all functions are already covered by the BinaryPrimitives API.

The `StringConverter` has now been rewritten to accept a Span to read from & write to, no longer requiring a temporary StringBuilder.

Other Fixes included:
- The Super Training UI for Gen6 has been reworked according to the latest block structure additions.
- Cloning a Stadium2 Save File now works correctly (opening from the Folder browser list).
- Checksum & Sanity properties removed from parent PKM class, and is now implemented via interface.
2022-01-02 21:35:59 -08:00
Kurt
1d0993f852 Remove EvoBase, relocate functions to call sites
Utilize FormInfo to remap battle forms into hatch forms so the encounter matches something valid, and is flagged later in FormVerifier
2021-12-26 00:57:40 -08:00
Kurt
6b2ea0894e Bypass encounter slot check for radar slots
https://projectpokemon.org/home/forums/topic/57375-pkhex-new-update-legality-errors-contribution-page/?do=findComment&comment=271406
https://discord.com/channels/401014193211441153/679178558597496872/908489378043686944
2021-12-12 13:16:27 -08:00
Kurt
f1fe2f6a8c Minor clean 2021-12-09 19:30:12 -08:00
Kurt
fcd97d5989 Don't add TR moves as possible for BDSP origin 2021-12-06 00:01:13 -08:00
Kurt
40ed5898af Merge extended property patterns 2021-12-04 18:37:47 -08:00
Kurt
95454246b8 Skip eggs for EncounterTrade check
yay reusing Link Trade egg met locations wrong, ty ilca
2021-12-01 10:38:12 -08:00
Kurt
1c82b707f3 Add xmldoc, add egglevel get central location 2021-11-30 17:09:46 -08:00
Kurt
723514e89c
Update 21.11.19 - Brilliant Diamond & Shining Pearl (#3289)
Big thanks to @SciresM @sora10pls @Lusamine @architdate @ReignOfComputer for testing and contributing code / test cases. Can't add co-authors from the PR menu :(

Builds will fail because azure pipelines not yet updated with net6.
2021-11-19 18:23:49 -08:00
Kurt
256b3c66ca Recognize unhatched crystal eggs, 2F pokecenter location
lacking met location data on receipt, can result in 0 for eggs hatched on the second floor of a pokecenter

https://bulbapedia.bulbagarden.net/wiki/List_of_locations_by_index_number_(Generation_II)

Thanks Freezing Dart!
2021-10-19 21:53:22 -07:00
Kurt
dd9b31dbbe Remove unnecessary property
template stores the version; no need to refer to store it separate from the object
Generation being separate is fine for now
2021-10-08 23:30:03 -07:00
Kurt
2874f6fc69 Revise pichu volt tackle egg handling
Clean up ParseMovesWasEggPreRelearn as only EncounterEgg call into it, and no EncounterEgg has a special moves interface implemented.
2021-09-15 18:43:18 -07:00
Kurt
41b1aaeb19 Search mystery gift relearn moves for needed moves
Add to encountertrades searcher, for futureproofing

solves gen8 mg searching volt tackle pikachu
2021-09-06 11:43:42 -07:00
Kurt
7434af48bf Fix HT know move memory deferral
Checks if it can know the move up until the current format, rather than origin game
2021-08-28 13:44:10 -07:00
Kurt
0e2dac3ff6 Minor tweaks
Empty return for invalid species encountertemplate fetch
Expose property for ck3 @ 0xD7
show legal memory context items rather than gen8 always
2021-08-25 19:23:15 -07:00
Kurt
28e7473f1a Condense some expressions 2021-08-22 01:26:28 -07:00
Kurt
92d1666970 Make PIDIV a readonly struct
Add tests to ensure the optimization remains in effect later
2021-08-21 18:24:38 -07:00
Kurt
cd12962a50 Remove Tradeback state caching in PKM data
Since we have more metadata with move learn sourcing, we can check if it was traded to gen2 to get new moves / deleted.

Adjust call sites appropriately
might have some issues, to be ironed out maybe
2021-08-20 15:59:54 -07:00
Kurt
bedc52943e Trailing commas
No functional change
2021-08-20 13:49:20 -07:00
Kurt
934628b077 Pre-filter memory mismatch on moves
All over the place with prior commits; everything should be correct (and more robust) now.
2021-08-15 14:23:15 -07:00
Kurt
42330eb771 Memories and special moves, bite the bullet
Allocate a list :(
We need to keep all the secondary deferred around, since they have special movepools.
2021-08-15 09:47:31 -07:00
Kurt
7c60363b38 Rework match ranking to have multi levels of deferral 2021-08-15 09:28:47 -07:00
Kurt
b8e203bdef Remove invalidmatch tracking
The Encounter verifier method rarely rejects as our inner encounter matching methods are all-or-nothing. Don't bother keeping references for this bloat.
Ran the unit tests and nothing hit this logic.
2021-08-06 15:38:39 -07:00
Kurt
9f8642f7d2 Hide Generation/Game setters behind mutation method 2021-08-06 15:35:49 -07:00
Kurt
0a74f6c33d Ignore species for rby if not present
encounter moves not present for those, lol
2021-08-05 12:36:19 -07:00
Kurt
616acc8bbd Misc fixes 2021-08-04 19:54:04 -07:00
Kurt
83a72df7cc Include gen1 encounter moves in not-needed list
Might result in some illegal matches as it includes it for all evolutions in the chain, but whatever. Could probably rewrite the generator to only generate for different starting-species, but it's fine now.

Inline the max level calc
2021-08-04 19:07:20 -07:00
Kurt
66f1b23dc6 Consider the "SkipFormCheck" for gen7 scatterbug static
Rework to match the encounter slot form-ambiguous checks
2021-08-02 20:45:52 -07:00
Kurt
140f814f90 Update EncounterMovesetGenerator.cs 2021-08-02 20:25:16 -07:00
Kurt
846f9506fb Misc form handling update (EncounterSlots)
Mark gen7 Minior slots with 31
Mark gen2 Unown slots with 31
Mark gen4 Unown slots with 31
2021-07-31 22:41:52 -07:00
Kurt
1bc5cb1113 Handle special form cases for IsSane 2021-07-31 20:50:29 -07:00
Kurt
34f750d519 Remove unobtainable static encounters from gen4 tables
We don't do it for inaccessible static encounters in gen7/8, so anyone glitching/cheating will get an unrecognized encounter instead of "hey this exists, but you can't access it" error.
2021-07-30 13:09:26 -07:00
Kurt
a57e12db59 Remove unobtainable encounter slots from gen4 tables 2021-07-30 13:06:15 -07:00
Kurt
8e5e4487ba Change interface for method call to less restricted
Don't need "Name" or "LongName" for these methods.
2021-07-13 18:22:04 -07:00
Kurt
103aa9aa4b
Revise EncounterArea and EncounterType for clarity (#3228)
EncounterArea now stores a more specific type'd array for encounter slots. Better iteration and less casting, as the nonspecific `Slots` fetch is rarely referenced.

EncounterType renamed to GroundTile to reflect how it actually works in Gen4. Was previously an ambiguous field that was clarified a little; we can describe it a little better now. Keep the GUI the same to not scare the end users.

Change Trash Byte properties to get/set a Span. Trash Byte legality checking easier on the garbage collector?
2021-06-29 20:58:06 -07:00
Kurt
3e7775fc44
Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately (#3222)
* Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately

Don't store within the object, track the slot origin data separately.

Batch editing now pre-filters if using Box/Slot/Identifier logic; split up mods/filters as they're starting to get pretty hefty.

- Requesting a Box Data report now shows all slots in the save file (party, misc)
- Can now exclude backup saves from database search via toggle (separate from settings preventing load entirely)
- Replace some linq usages with direct code

* Remove WasLink virtual in PKM

Inline any logic, since we now have encounter objects to indicate matching, rather than the proto-legality logic checking properties of a PKM.

* Use Fateful to directly check gen5 mysterygift origins

No other encounter types in gen5 apply Fateful

* Simplify double ball comparison

Used to be separate for deferral cases, now no longer needed to be separate.

* Grab move/relearn reference and update locally

Fix relearn move identifier

* Inline defog HM transfer preference check

HasMove is faster than getting moves & checking contains. Skips allocation by setting values directly.

* Extract more met location metadata checks: WasBredEgg

* Replace Console.Write* with Debug.Write*

There's no console output UI, so don't include them in release builds.

* Inline WasGiftEgg, WasEvent, and WasEventEgg logic

Adios legality tags that aren't entirely correct for the specific format. Just put the computations in EncounterFinder.
2021-06-22 20:23:48 -07:00
Kurt
a07549f013 Extract sketch valid check
GetCanKnowMove should be checking for Smeargle knowing thousand arrows/waves.
GetNeededMoves should also return 1ka/1kw for needed moves, and then no encounters.

All uses of InvalidSketch are behind that method, so any future Smeargle modifications (like sketching a dummied move) will be checked (yay BDSP considerations).
2021-06-06 23:36:59 -07:00
Kurt
200bdbd553 Sanity check form prior to yield checks 2021-06-06 11:48:54 -07:00
Kurt
8222297da8 Remove enumerating when loading event templates
Just allocate the parent array and pass it to HashSet; having an ICollection, prevents resizing repeatedly and gc'ing the temp array is cheap.

Actually, only create a hashset if we're adding a gift from external DB. Saves on that allocation, and keeps the final result as an array (fastest iterating).
2021-06-04 13:48:02 -07:00
Kurt
8c970ec991 Minor tweaks
no functional change, readability++
add more xmldoc
2021-06-03 12:04:19 -07:00
Kurt
138501da2f Minor clean
Condense some expressions
Use less linq
Rename some fields
2021-05-29 15:31:47 -07:00
Kurt
54611032c9 Refine crystal egg checks
Disallow crystal eggs if met data is not present
Set crystal met location more fluidly
2021-05-23 12:50:42 -07:00
Kurt
e31980d15e Clean up nickname parsing, make Gender an int type
Breaking change for anyone using IBattleTemplate (alm)
2021-05-14 23:41:14 -07:00
Kurt
50b15cd740 Use range/index
More in line with modernizing the codebase with latest c# syntax

improve web-qr decode speed slightly (no linq skiptake)
get money/coin mask without a temporary string (lol performance)
2021-05-14 15:30:55 -07:00
Kurt
a7f3ce5766 Leak mismatched forms thru the possible check
The EncDB doesn't specify form; the encounter methods verify Form.

This is actually a fix; pkm that can change forms aren't really encounter trades, but we shouldn't be strict matching here.
2021-05-08 08:13:27 -07:00
Kurt
0719320e33 Eggs: explicitly pass generation instead of calculating 2021-04-17 20:09:02 -07:00
Kurt
893f22a664 Extract generation traversal list fetch to static class 2021-04-17 13:09:09 -07:00
Kurt
0626b0c29b
Add Breeding move ordering logic, and use in legality analysis (#3183)
* Initial bred moveset validation logic

Unpeel the inheritance via recursion and permitted moves

* Volt tackle considerations

* Optimize out empty slot skips

* Add tests, fix off-by-one's

* Require all base moves if empty slot in moveset

* Add test to prove failure per Anubis' provided test

* Tweak enum labels for easier debugging

When two enums share the same underlying value, the ToString/name of the value may be either of the two (or the last defined one, in my debugging). Just give it a separate magic value.

* Fix recursion oopsie

Also check for scenario where no-base-moves but not enough moves to push base moves out

* Add Crystal tutor checks

* Add specialized gen2 verification method

Game loops through father's moves and pushes in one iteration, rather than checking by type.

* Add another case with returning base move

* Add push-out requirement for re-added base moves

* Minor tweaks

Condense tests, fix another off-by-one noticed when creating tests

* Disallow inherited parent levelup moves

Disallow volt tackle on Gen2/R/S

* Split MoveBreed into generation specific classes

Gen2 behaves slightly different from Gen3/4, which behaves slightly different from Gen5... and Gen6 behaves differently too.

Add some xmldoc as the api is starting to solidify

* Add method overload that returns the parse

Verify that the parse order is as expected

* Add reordering suggestion logic

Try sorting first, then go nuclear with rebuilding.

* Return base moves if complete fail

* Set base moves when generating eggs, only.

* Use breed logic to check for egg ordering legality

Don't bother helping for split-breed species
2021-04-04 18:30:01 -07:00