architdate / PKHeX-Plugins

Plugins for PKHeX
MIT License
585 stars 133 forks source link

Random IVs from ShowdownSet #82

Closed easyworld closed 3 years ago

easyworld commented 3 years ago

Describe the problem I try this c# code to generate pkm from pokemon showdown

using PKHeX.Core;
using PKHeX.Core.AutoMod;
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string ps2 = @"Stakataka @ Weakness Policy  
Ability: Beast Boost  
EVs: 252 HP / 252 Atk / 4 SpD  
Brave Nature  
IVs: 2 Spe  
- Body Press  
- Gyro Ball  
- Rock Slide  
- Trick Room  
";
            var set = new ShowdownSet(ps2);
            Console.WriteLine(string.Join(",", set.IVs));
            RibbonStrings.ResetDictionary(GameInfo.Strings.ribbons);
            var sav = TrainerSettings.GetSavedTrainerData(8);
            var pkm = sav.GetLegalFromSet(set, out var type);
            Console.WriteLine(string.Join(",", pkm.IVs));
            Console.ReadLine();
        }
    }
}

And found the second console output gave random IVs, like 31,11,31,31,31,26. (first console output is correct, which is 31,31,31,2,31,31)

To Reproduce I try to generate by myself in PKHex with Auto-Legality Mod (805 - Stakataka - 1695A7B79620.zip) It seems that IVs are legal: capture

Expected behavior If it is legal, the IVs should be 31,31,31,2,31,31

architdate commented 3 years ago

This is intended behavior

ALM goes down the list of games to attempt to legalize in each game. Stakataka is possible in sword and shield via max lair so that is likely the legalized pokemon you have gotten.

Max lair like other gen 8 raids follows the XOROSHIRO rng method which allocates the IVs based on a random seed. ALM emulates how the game assigns the seed and the values dependent on the seed.

However the game cannot feasibly check for xoroshiro legality since reversing the seed can be cpu intensive and time consuming.

So if you really want to generate stakataka with those specific ivs, add the following line before GetLegalFromSet

APILegality.UseXOROSHIRO = false;

This should generate the set without bothering with the xoroshiro rng legality

architdate commented 3 years ago

Please do let me know if that works, and if so close the issue. Thanks 👍

Lusamine commented 3 years ago

Alternate workaround if you want to preserve legality is to use a move or batch editor command to force a gen 7 encounter instead.

Stakataka @ Weakness Policy
Ability: Beast Boost
EVs: 252 HP / 252 Atk / 4 SpD
Lonely Nature
IVs: 17 Def / 0 Spe
=Gen7=true
- Gyro Ball
- High Horsepower
- Rock Slide
- Trick Room
Stakataka @ Weakness Policy
Ability: Beast Boost
EVs: 252 HP / 252 Atk / 4 SpD
Lonely Nature
IVs: 17 Def / 0 Spe
- Toxic
- High Horsepower
- Rock Slide
- Trick Room
easyworld commented 3 years ago

Please do let me know if that works, and if so close the issue. Thanks 👍

It works, thank you very much.

Alternate workaround if you want to preserve legality is to use a move or batch editor command to force a gen 7 encounter instead.

Stakataka @ Weakness Policy
Ability: Beast Boost
EVs: 252 HP / 252 Atk / 4 SpD
Lonely Nature
IVs: 17 Def / 0 Spe
=Gen7=true
- Gyro Ball
- High Horsepower
- Rock Slide
- Trick Room
Stakataka @ Weakness Policy
Ability: Beast Boost
EVs: 252 HP / 252 Atk / 4 SpD
Lonely Nature
IVs: 17 Def / 0 Spe
- Toxic
- High Horsepower
- Rock Slide
- Trick Room

It also works, thank you very much.