mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-27 06:20:25 +00:00
Add other iencounterable->pkm generators
not tested
This commit is contained in:
parent
0b4adf9763
commit
32f9f806db
9 changed files with 267 additions and 7 deletions
|
@ -28,6 +28,9 @@ namespace PKHeX.Core
|
|||
pk.CurrentLevel = Level;
|
||||
pk.Version = (int)Version;
|
||||
|
||||
int gender = Util.Rand.Next(2);
|
||||
pk.Gender = pk.GetSaneGender(gender);
|
||||
|
||||
var moves = Legal.GetEggMoves(pk, Species, pk.AltForm, Version);
|
||||
pk.Moves = moves;
|
||||
pk.SetMaximumPPCurrent(moves);
|
||||
|
|
|
@ -66,7 +66,6 @@ namespace PKHeX.Core
|
|||
pk.OT_Friendship = pk.PersonalInfo.BaseFriendship;
|
||||
pk.SetRandomIVs(flawless: 3);
|
||||
pk.RefreshAbility(Ability);
|
||||
SAV.ApplyHandlingTrainerInfo(pk);
|
||||
if (RelearnMoves != null)
|
||||
pk.RelearnMoves = RelearnMoves;
|
||||
if (RibbonClassic)
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
namespace PKHeX.Core
|
||||
using System;
|
||||
|
||||
namespace PKHeX.Core
|
||||
{
|
||||
public class EncounterSlotPermissions
|
||||
{
|
||||
|
@ -62,6 +64,70 @@
|
|||
}
|
||||
}
|
||||
|
||||
public PKM ConvertToPKM(ITrainerInfo SAV) => throw new System.NotImplementedException();
|
||||
public PKM ConvertToPKM(ITrainerInfo SAV)
|
||||
{
|
||||
var version = this.GetCompatibleVersion((GameVersion)SAV.Game);
|
||||
int lang = (int)Legal.GetSafeLanguage(Generation, (LanguageID)SAV.Language);
|
||||
int level = LevelMin;
|
||||
var pk = PKMConverter.GetBlank(Generation);
|
||||
int gender = Util.Rand.Next(2);
|
||||
pk.Gender = pk.GetSaneGender(gender);
|
||||
|
||||
int nature = Util.Rand.Next(25);
|
||||
pk.Nature = nature;
|
||||
pk.EncryptionConstant = Util.Rand32();
|
||||
pk.Species = Species;
|
||||
pk.Language = lang;
|
||||
pk.CurrentLevel = level;
|
||||
pk.Version = (int) version;
|
||||
pk.PID = Util.Rand32();
|
||||
pk.Nickname = PKX.GetSpeciesNameGeneration(Species, lang, Generation);
|
||||
pk.Ball = 4;
|
||||
pk.Met_Level = level;
|
||||
pk.Met_Location = Location;
|
||||
pk.MetDate = DateTime.Today;
|
||||
|
||||
SAV.ApplyToPKM(pk);
|
||||
pk.Language = lang;
|
||||
|
||||
pk.SetRandomIVs(flawless: 3);
|
||||
|
||||
if (Permissions.IsDexNav)
|
||||
{
|
||||
pk.RefreshAbility(2);
|
||||
var eggMoves = Legal.GetEggMoves(pk, Species, pk.AltForm, Version);
|
||||
if (eggMoves.Length > 0)
|
||||
pk.RelearnMove1 = eggMoves[Util.Rand.Next(eggMoves.Length)];
|
||||
}
|
||||
else
|
||||
{
|
||||
pk.RefreshAbility(Util.Rand.Next(2));
|
||||
}
|
||||
|
||||
switch (pk.Format)
|
||||
{
|
||||
case 3:
|
||||
case 4:
|
||||
PIDGenerator.SetValuesFromSeed(pk, PIDType.Method_1, Util.Rand32());
|
||||
if (pk.Format == 4)
|
||||
pk.EncounterType = TypeEncounter.GetIndex();
|
||||
break;
|
||||
case 6:
|
||||
pk.SetRandomMemory6();
|
||||
break;
|
||||
}
|
||||
|
||||
var moves = this is EncounterSlotMoves m ? m.Moves : Legal.GetEncounterMoves(pk, level, version);
|
||||
pk.Moves = moves;
|
||||
pk.SetMaximumPPCurrent(moves);
|
||||
pk.OT_Friendship = pk.PersonalInfo.BaseFriendship;
|
||||
if (pk.Format < 6)
|
||||
return pk;
|
||||
|
||||
SAV.ApplyHandlingTrainerInfo(pk);
|
||||
pk.SetRandomEC();
|
||||
|
||||
return pk;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
namespace PKHeX.Core
|
||||
using System;
|
||||
|
||||
namespace PKHeX.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Static Encounter Data
|
||||
|
@ -64,6 +66,87 @@
|
|||
private const string _name = "Static Encounter";
|
||||
public string Name => Version == GameVersion.Any ? _name : $"{_name} ({Version})";
|
||||
|
||||
public PKM ConvertToPKM(ITrainerInfo SAV) => throw new System.NotImplementedException();
|
||||
public PKM ConvertToPKM(ITrainerInfo SAV)
|
||||
{
|
||||
var version = this.GetCompatibleVersion((GameVersion)SAV.Game);
|
||||
int lang = (int)Legal.GetSafeLanguage(Generation, (LanguageID)SAV.Language);
|
||||
int level = LevelMin;
|
||||
var pk = PKMConverter.GetBlank(Generation);
|
||||
|
||||
pk.EncryptionConstant = Util.Rand32();
|
||||
pk.Species = Species;
|
||||
pk.Language = lang;
|
||||
pk.CurrentLevel = level;
|
||||
pk.Version = (int)version;
|
||||
pk.PID = Util.Rand32();
|
||||
pk.Nickname = PKX.GetSpeciesNameGeneration(Species, lang, Generation);
|
||||
pk.Ball = Ball;
|
||||
pk.Met_Level = level;
|
||||
pk.Met_Location = Location;
|
||||
var today = DateTime.Today;
|
||||
pk.MetDate = today;
|
||||
if (EggEncounter)
|
||||
{
|
||||
pk.Egg_Location = EggLocation;
|
||||
pk.EggMetDate = today;
|
||||
}
|
||||
|
||||
int nature = Nature == Nature.Random ? Util.Rand.Next(25) : (int)Nature;
|
||||
pk.Nature = nature;
|
||||
int gender = Gender < 0 ? Util.Rand.Next(2) : Gender;
|
||||
pk.Gender = pk.GetSaneGender(gender);
|
||||
pk.AltForm = Form;
|
||||
|
||||
SAV.ApplyToPKM(pk);
|
||||
pk.Language = lang;
|
||||
|
||||
pk.RefreshAbility(Ability >> 1);
|
||||
|
||||
if (IVs != null)
|
||||
pk.SetRandomIVs(IVs, FlawlessIVCount);
|
||||
else
|
||||
pk.SetRandomIVs(flawless: FlawlessIVCount);
|
||||
|
||||
switch (pk.Format)
|
||||
{
|
||||
case 3:
|
||||
case 4:
|
||||
PIDGenerator.SetValuesFromSeed(pk, Roaming ? PIDType.Method_1_Roamer : PIDType.Method_1, Util.Rand32());
|
||||
if (this is EncounterStaticTyped t)
|
||||
pk.EncounterType = t.TypeEncounter.GetIndex();
|
||||
break;
|
||||
case 6:
|
||||
pk.SetRandomMemory6();
|
||||
break;
|
||||
}
|
||||
|
||||
if (this is EncounterStaticPID pid)
|
||||
{
|
||||
pk.PID = pid.PID;
|
||||
if (pk is PK5 pk5)
|
||||
pk5.NPokémon = pid.NSparkle;
|
||||
}
|
||||
|
||||
this.CopyContestStatsTo(pk);
|
||||
|
||||
var moves = Moves ?? Legal.GetEncounterMoves(pk, level, version);
|
||||
pk.Moves = moves;
|
||||
pk.SetMaximumPPCurrent(moves);
|
||||
if (pk.Format >= 6 && Relearn != null)
|
||||
pk.RelearnMoves = Relearn;
|
||||
pk.OT_Friendship = pk.PersonalInfo.BaseFriendship;
|
||||
if (Fateful)
|
||||
pk.FatefulEncounter = true;
|
||||
|
||||
if (pk.Format < 6)
|
||||
return pk;
|
||||
if (RibbonWishing && pk is IRibbonSetEvent4 e4)
|
||||
e4.RibbonWishing = true;
|
||||
|
||||
SAV.ApplyHandlingTrainerInfo(pk);
|
||||
pk.SetRandomEC();
|
||||
|
||||
return pk;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
namespace PKHeX.Core
|
||||
using System;
|
||||
|
||||
namespace PKHeX.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Trade Encounter data
|
||||
|
@ -54,6 +56,67 @@
|
|||
0, 126, 254, 2001, 30002, 30001, 30001,
|
||||
};
|
||||
|
||||
public PKM ConvertToPKM(ITrainerInfo SAV) => throw new System.NotImplementedException();
|
||||
public PKM ConvertToPKM(ITrainerInfo SAV)
|
||||
{
|
||||
var version = this.GetCompatibleVersion((GameVersion)SAV.Game);
|
||||
int lang = (int)Legal.GetSafeLanguage(Generation, (LanguageID)SAV.Language);
|
||||
int level = CurrentLevel > 0 ? CurrentLevel : LevelMin;
|
||||
var pk = PKMConverter.GetBlank(Generation);
|
||||
|
||||
pk.EncryptionConstant = Util.Rand32();
|
||||
pk.Species = Species;
|
||||
pk.Language = lang;
|
||||
pk.CurrentLevel = level;
|
||||
pk.Version = (int)version;
|
||||
pk.PID = Util.Rand32();
|
||||
pk.Ball = Ball;
|
||||
pk.Met_Level = LevelMin;
|
||||
pk.Met_Location = Location;
|
||||
pk.MetDate = DateTime.Today;
|
||||
|
||||
int nature = Nature == Nature.Random ? Util.Rand.Next(25) : (int)Nature;
|
||||
pk.Nature = nature;
|
||||
int gender = Gender < 0 ? Util.Rand.Next(2) : Gender;
|
||||
pk.Gender = pk.GetSaneGender(gender);
|
||||
pk.AltForm = Form;
|
||||
|
||||
SAV.ApplyToPKM(pk);
|
||||
pk.TID = TID;
|
||||
pk.SID = SID;
|
||||
pk.OT_Name = GetOT(lang) ?? SAV.OT;
|
||||
pk.OT_Gender = GetOT(lang) != null ? OTGender : SAV.Gender;
|
||||
pk.SetNickname(GetNickname(lang));
|
||||
pk.Language = lang;
|
||||
|
||||
pk.RefreshAbility(Ability >> 1);
|
||||
|
||||
if (IVs != null)
|
||||
pk.SetRandomIVs(IVs, 0);
|
||||
else
|
||||
pk.SetRandomIVs(flawless: 3);
|
||||
|
||||
if (pk.Format == 6)
|
||||
pk.SetRandomMemory6();
|
||||
|
||||
if (pk is PK1 pk1 && this is EncounterTradeCatchRate c)
|
||||
pk1.Catch_Rate = (int)c.Catch_Rate;
|
||||
|
||||
this.CopyContestStatsTo(pk);
|
||||
|
||||
var moves = Moves ?? Legal.GetEncounterMoves(pk, level, version);
|
||||
pk.Moves = moves;
|
||||
pk.SetMaximumPPCurrent(moves);
|
||||
pk.OT_Friendship = pk.PersonalInfo.BaseFriendship;
|
||||
if (Fateful)
|
||||
pk.FatefulEncounter = true;
|
||||
|
||||
if (pk.Format < 6)
|
||||
return pk;
|
||||
|
||||
SAV.ApplyHandlingTrainerInfo(pk);
|
||||
pk.SetRandomEC();
|
||||
|
||||
return pk;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,5 +28,17 @@ namespace PKHeX.Core
|
|||
public static class EncounterTypeExtension
|
||||
{
|
||||
public static bool Contains(this EncounterType g1, int g2) => g1.HasFlag((EncounterType)(1 << g2));
|
||||
|
||||
public static int GetIndex(this EncounterType g)
|
||||
{
|
||||
int val = (int) g;
|
||||
for (int i = 0; i < 8 * sizeof(EncounterType); i++)
|
||||
{
|
||||
val >>= 1;
|
||||
if (val == 0)
|
||||
return i;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -492,5 +492,13 @@ namespace PKHeX.Core
|
|||
pk.OT_Intensity = 1;
|
||||
pk.OT_TextVar = pk.XY ? 43 : 27; // riverside road : battling spot
|
||||
}
|
||||
|
||||
public static void SetRandomMemory6(this PKM pk)
|
||||
{
|
||||
// for lack of better randomization :)
|
||||
pk.OT_Memory = 63;
|
||||
pk.OT_Intensity = 6;
|
||||
pk.OT_Feeling = 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -921,6 +921,22 @@ namespace PKHeX.Core
|
|||
return ivs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Randomizes the IVs within game constraints.
|
||||
/// </summary>
|
||||
/// <returns>Randomized IVs if desired.</returns>
|
||||
public int[] SetRandomIVs(int[] template, int? flawless = null)
|
||||
{
|
||||
int count = flawless ?? GetFlawlessIVCount();
|
||||
int[] ivs = new int[6];
|
||||
do
|
||||
{
|
||||
for (int i = 0; i < 6; i++)
|
||||
ivs[i] = template[i] < 0 ? (int) (Util.Rand32() & MaxIV) : template[i];
|
||||
} while (ivs.Count(z => z == MaxIV) < count);
|
||||
return ivs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the amount of flawless IVs that the <see cref="PKM"/> should have.
|
||||
/// </summary>
|
||||
|
|
|
@ -42,5 +42,15 @@
|
|||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void CopyContestStatsTo(this IContestStats source, IContestStats dest)
|
||||
{
|
||||
dest.CNT_Cool = source.CNT_Cool;
|
||||
dest.CNT_Beauty = source.CNT_Beauty;
|
||||
dest.CNT_Cute = source.CNT_Cute;
|
||||
dest.CNT_Smart = source.CNT_Smart;
|
||||
dest.CNT_Tough = source.CNT_Tough;
|
||||
dest.CNT_Sheen = source.CNT_Sheen;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue