Commit graph

192 commits

Author SHA1 Message Date
Kurt
a57f40ae7d Break up PKX into separate classes
Many years ago, PKX used to be a >4,000 line bloated file, which spun off multiple classes like CommonEdits and most of the early non-GUI PKM related logic. Now, it's just a stub to source the latest generation & personal table.

Separate files = more concise info, and more room to grow to do more advanced things.
Makes the IsPresent methods public (no longer internal).
2022-05-06 20:38:55 -07:00
Kurt
59ceec3c65 Extract EffortValues class, add $rand + $suggest
Renames IV/EV verifier field objects for Legality Checks due to class name clashing.
2022-05-06 15:47:54 -07:00
Kurt
9deafa851a
Create initial movesets for Alpha entities correctly, verify initial mastery (#3489)
* Draft checks for encounter slot mastery

* Check encounter mastery flags

* Add moves for LA static encounters that don't follow learnset

* Add moves on crossover LA static encounters

* add alpha moveset population method

Now generates and applies moves as the game does
Updates some handling of other methods to use Span

* Show better message for bad mastery init flags

* Insert descending if candidates have same level

Level 78 Yanmega:
- [01] [10] Quick Attack
- [06] [15] Gust
- [11] [20] Silver Wind
- [18] [28] Hypnosis
- [25] [35] Air Slash
- [34] [45] Ancient Power
- [43] [54] Crunch
- [43] [54] Bug Buzz

Yields:
AlphaMove
Crunch*
Bug Buzz*
Ancient Power

* Descending order due to iteration

Co-authored-by: Lusamine <30205550+Lusamine@users.noreply.github.com>
2022-05-06 15:43:23 -07:00
Kurt
41578132cf Minor tweaks
Add Get/Set Relearn method to PKM.cs
Alpha Mastered move now indicates incomplete text entry (like moves/relearn)
Split up legal move indication helper class, use DI to allow other implementations of DataSource to be returned (pkhex mobile?).
Remove unused gender refresh method (see previous added UserControl commit)
Add helper method to center control within control
2022-05-02 18:11:31 -07:00
Kurt
fa76da56c9 Inline some Rand32 calls
No functional change
2022-04-26 20:21:26 -07:00
Kurt
5be9863ef4 Sanitize gender on species/form change
clean up some if expressions
2022-04-25 17:30:16 -07:00
Kurt
cc1c3e8d42 Refactor stat loading to allow spans
Can load stats without allocating
2022-04-08 21:08:06 -07:00
Kurt
d91d242719 Stackalloc EV/AV checks 2022-03-13 22:33:17 -07:00
Kurt
d95ba482f3 Reduce allocation in methodfinder IV set 2022-03-13 19:39:38 -07:00
Kurt
d5ae6764aa Stackalloc IVs for template->pkm fill 2022-03-13 19:24:08 -07:00
Kurt
69fafcab83 Performance: Slightly reduce allocations in moveset validation (#3460)
* Reuses move parse result objects for each encounter parsed in a LegalityCheck attempt, instead of creating a new object.
* Ensures the objects are never-null, and makes cleanup easier.

Slightly adjusts some other parts of the moveset validation to reduce allocations.
2022-03-12 17:39:00 -08:00
Kurt
51975e4bdd Only push move if doesn't already have
Closes #3439
2022-02-17 20:53:21 -08:00
Kurt
0eece2711a Set the calc h/w float regardless of epsilon
epsilon no longer required per #3417
closes #3434
2022-02-12 18:48:33 -08:00
Kurt
6da235f0e8 Set 3 flawless IVs if randomizing alpha IVs
Closes #3428
2022-02-09 19:26:18 -08:00
Kurt
d17639f956 Add alpha move for encounter slots
oops
Closes #3427
2022-02-09 19:21:45 -08:00
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
659fc9978b Stackalloc marking set & raid IV gen 2022-01-08 22:48:33 -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
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
25316fbaef Add IV ceiling for GBL GO encounters 2021-09-17 17:56:15 -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
de94876822 Minor tweaks
no functional change
2021-07-30 16:22:10 -07:00
Kurt
a10d1df9ca Extract pkm filename'ing logic to allow behavior replacing
injecting dependencies

replace the virtual inheritance with a type check
2021-07-28 19:28:56 -07:00
Kurt
46f50a3a56 Use named consts for magic gender values
More personal magic value comparisons
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
49488bb503 Use invariant culture for ToUpper/ToLower
Turkish is quite the language; let's try to prevent any errors down the road for internal/game string case changes.
2021-06-24 09:16:36 -07:00
Kurt
a10b35190c Minor tweaks
off by 1 max range for gen2 slot -> pk2
SetRandomIVs already sets IVs inside the method, retval is for knowing what the new value sare
show WC8 restricted version rather than defaulting to SH
pass the rand object rather than fetching for the current thread every loop for Unown & random IV shuffling
Use ToLowerInvariant for resource fetching, should resolve the turkish issue
Check typeof(T) first, not that we check for ToolStripItem or ContextMenuStrip with this function.
2021-06-24 00:36:04 -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
565f161226 Show shiny state of encounter in db
Force shiny state for GO encounters

For encounters, this interface property is mainly just for exposing metadata for sprites.
2021-05-18 10:36:45 -07:00
Kurt
acdbda4e12 Split DateUtil from Util class 2021-05-14 16:46:48 -07:00
Kurt
2f078e6565 Minor tweaks
Make HP IV set use single array fetch, less memory required
add some xmldoc
2021-04-20 01:02:32 -07:00
Kurt
6bce4eea14 Minor clean
Annotations (nullable), some switch cases for readability
2021-03-14 16:16:55 -07:00
Kurt
0d05715582 Fix reflective convert
Adding setters for Hidden Power caused the IVs to get mutated, same for some other values. The DateTime could return null if undefined.

Used to be Declared only (properties in destination class), but GBPKM has shared Nick/Lang/IV logic.
513648638f

Just do the GBPKM fixup at the end to copy the remaining properties manually. Set HP type if the conversion was from future 31IV games.
2021-02-15 13:52:49 -08:00
Kurt
680e8b711d Add some code analysis for try-return with nullable out 2021-01-17 00:05:07 -08:00
Kurt
bb1d23e112 Minor clean
Use some enums, save a few virtual/static fetches
2021-01-16 12:01:40 -08:00
Kurt
1f3d3112d3 Move some future-evolution tables to separate class 2021-01-02 19:11:46 -08:00
Kurt
09089da14e Use more expression return style
Reduces indentation & bracketing, a bit more concise
2021-01-01 17:08:49 -08:00
Kurt
de840f40d4 Invert some "!is" to "is not" 2020-12-29 00:58:08 -08:00
Kurt
ee5349ff98 moar is or 2020-12-25 12:30:26 -08:00
Kurt
93910df2c6 Use new switch statements 2020-12-23 17:14:38 -08:00
Kurt
997e0751f3 Minor clean
Handle remainder of c#9 sugar
Fix some spelling mistakes
2020-12-21 23:37:07 -08:00
Kurt
62018cce1a Unify concepts with different names
AltForm & Form & Forme => Form
GenNumber & Generation => Generation

Extract out SpeciesForm interface, and re-add IGeneration

For those using PKHeX as a dependency, this should be a pretty straightforward manual replacement... GenNumber and AltForm should be quick find-replace`s.
2020-12-10 20:42:30 -08:00
Kurt
5bc5b611cb Make RefreshAbility virtual, add overrides for gen3&5
Gen5: set HA bit if hidden ability
Gen3: prevent setting AbilityBit if it doesn't have 2 distinct abilities

Failed test now passes; all tests are passing!
2020-11-29 15:02:57 -08:00
Kurt
0af0c05bac Update go slot list yield and move fetch 2020-11-18 21:34:40 -08:00
Kurt
26e0f31c95 Include date legality parameters for LGPE
Extract common abstract class for GO transferred encounters
Clamp minlevel instead of met level
Add optional parameter for GO IV randomization
Update go legality binaries with latest
2020-11-16 15:32:22 -08:00
Kurt
72e209a156 Split some methods, handle flow for go enc 2020-11-11 21:22:13 -08:00
Kurt
9264150b2b Add shiny1 batch editor, add ctrl-shiny (1)
GUI: Ctrl click star to get shiny1, shift click for shiny0, any-click to get random

make Alt click modify the SID instead of PID

add SetShinySID shiny type
2020-10-25 10:42:48 -07:00
Kurt
6239f59b9d Inline checksum logic for gen3, simplify else case 2020-10-18 09:16:52 -07:00
Kurt
a34434f7cb Make pkm.Data a readonly field rather than property 2020-09-26 12:09:02 -07:00