mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-16 00:58:01 +00:00
997ca29fe6
Checks.cs : fix duplicate analysis result (encountertrade machoke is legal & illegal), nope, legal. Core.cs : Add version bypass if none assigned. EncounterSlot.cs: Handle yellow kadabra EncounterTrade: Handle must-evolves. now at 75: graveler (SM trade)
166 lines
6.1 KiB
C#
166 lines
6.1 KiB
C#
using System;
|
|
using System.Linq;
|
|
|
|
namespace PKHeX.Core
|
|
{
|
|
public class EncounterSlotPermissions
|
|
{
|
|
public int StaticIndex { get; set; } = -1;
|
|
public int MagnetPullIndex { get; set; } = -1;
|
|
public int StaticCount { get; set; }
|
|
public int MagnetPullCount { get; set; }
|
|
|
|
public bool AllowDexNav { get; set; }
|
|
public bool Pressure { get; set; }
|
|
public bool DexNav { get; set; }
|
|
public bool WhiteFlute { get; set; }
|
|
public bool BlackFlute { get; set; }
|
|
public bool IsNormalLead => !(WhiteFlute || BlackFlute || DexNav);
|
|
public bool IsDexNav => AllowDexNav && DexNav;
|
|
public EncounterSlotPermissions Clone() => (EncounterSlotPermissions)MemberwiseClone();
|
|
}
|
|
/// <summary>
|
|
/// Wild Encounter Slot data
|
|
/// </summary>
|
|
public class EncounterSlot : IEncounterable, IGeneration, ILocation, IVersion
|
|
{
|
|
public int Species { get; set; }
|
|
public int Form { get; set; }
|
|
public int LevelMin { get; set; }
|
|
public int LevelMax { get; set; }
|
|
public SlotType Type { get; set; } = SlotType.Any;
|
|
public EncounterType TypeEncounter { get; set; } = EncounterType.None;
|
|
public int SlotNumber { get; set; }
|
|
public int Generation { get; set; } = -1;
|
|
internal EncounterSlotPermissions _perm;
|
|
public EncounterSlotPermissions Permissions => _perm ?? (_perm = new EncounterSlotPermissions());
|
|
public GameVersion Version { get; set; }
|
|
|
|
internal EncounterArea Area { private get; set; }
|
|
public int Location { get => Area.Location; set { } }
|
|
public bool EggEncounter => false;
|
|
public int EggLocation { get => 0; set { } }
|
|
|
|
public EncounterSlot Clone()
|
|
{
|
|
var slot = (EncounterSlot) MemberwiseClone();
|
|
if (_perm != null)
|
|
slot._perm = Permissions.Clone();
|
|
return slot;
|
|
}
|
|
|
|
public bool FixedLevel => LevelMin == LevelMax;
|
|
|
|
public bool IsMatchStatic(int index, int count) => index == Permissions.StaticIndex && count == Permissions.StaticCount;
|
|
public bool IsMatchMagnet(int index, int count) => index == Permissions.MagnetPullIndex && count == Permissions.MagnetPullCount;
|
|
|
|
public string Name
|
|
{
|
|
get
|
|
{
|
|
const string wild = "Wild Encounter";
|
|
if (Type == SlotType.Any)
|
|
return wild;
|
|
return $"{wild} {Type.ToString().Replace("_", " ")}";
|
|
}
|
|
}
|
|
|
|
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 nature = Util.Rand.Next(25);
|
|
SAV.ApplyToPKM(pk);
|
|
|
|
pk.Species = Species;
|
|
int gender = pk.PersonalInfo.RandomGender;
|
|
pk.Language = lang;
|
|
pk.CurrentLevel = level;
|
|
pk.Version = (int)version;
|
|
pk.AltForm = Form;
|
|
pk.Nickname = PKX.GetSpeciesNameGeneration(Species, lang, Generation);
|
|
pk.Ball = GetBall();
|
|
|
|
if (pk.Format > 2 || Version == GameVersion.C)
|
|
{
|
|
pk.Met_Location = Location;
|
|
pk.Met_Level = level;
|
|
if (Version == GameVersion.C && pk is PK2 pk2 && this is EncounterSlot1 slot)
|
|
pk2.Met_TimeOfDay = slot.Time.RandomValidTime();
|
|
|
|
if (pk.Format >= 4)
|
|
pk.MetDate = DateTime.Today;
|
|
}
|
|
pk.Language = lang;
|
|
|
|
var ability = Util.Rand.Next(0, 2);
|
|
var pidtype = GetPIDType();
|
|
if (pidtype == PIDType.PokeSpot)
|
|
PIDGenerator.SetRandomPokeSpotPID(pk, nature, gender, ability, SlotNumber);
|
|
else
|
|
PIDGenerator.SetRandomWildPID(pk, pk.Format, nature, ability, gender, pidtype);
|
|
|
|
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)];
|
|
}
|
|
|
|
switch (pk.Format)
|
|
{
|
|
case 1 when Species == 64 && Version == GameVersion.YW: // Kadabra
|
|
((PK1)pk).Catch_Rate = 96;
|
|
break;
|
|
case 3:
|
|
case 4:
|
|
if (pk.Format == 4)
|
|
pk.EncounterType = TypeEncounter.GetIndex();
|
|
pk.Gender = pk.GetSaneGender(gender);
|
|
break;
|
|
case 5:
|
|
if (Type == SlotType.HiddenGrotto)
|
|
pk.RefreshAbility(2);
|
|
break;
|
|
case 6:
|
|
pk.SetRandomMemory6();
|
|
break;
|
|
}
|
|
|
|
var moves = this is EncounterSlotMoves m ? m.Moves : Legal.GetEncounterMoves(pk, level, version);
|
|
if (pk.Format == 1 && moves.All(z => z == 0))
|
|
moves = ((PersonalInfoG1)PersonalTable.RB[Species]).Moves;
|
|
else if (Version == GameVersion.XD)
|
|
pk.FatefulEncounter = true;
|
|
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;
|
|
}
|
|
|
|
private PIDType GetPIDType()
|
|
{
|
|
if (Version == GameVersion.XD)
|
|
return PIDType.PokeSpot;
|
|
return PIDType.None; // depends on format, let the program auto-detect.
|
|
}
|
|
|
|
private int GetBall()
|
|
{
|
|
if (Type == SlotType.BugContest)
|
|
return 24; // Sport
|
|
if (Type.HasFlag(SlotType.Safari))
|
|
return 5; // Safari
|
|
return 4; // Poké Ball
|
|
}
|
|
}
|
|
}
|