mirror of
https://github.com/kwsch/PKHeX
synced 2024-09-22 23:32:00 +00:00
Minor refactoring
Switch EncounterGeneric to IEncounterable. A way to tie together all encounters. Added a few setters for mystery gifts if the code is ever reused in other projects for that purpose. No functional change.
This commit is contained in:
parent
ed47e389d4
commit
e7bf0b9a2c
14 changed files with 66 additions and 51 deletions
|
@ -654,10 +654,10 @@ namespace PKHeX
|
|||
|
||||
if (Encounter is int)
|
||||
minspec = (int)Encounter;
|
||||
else if (Encounter is EncounterGeneric[])
|
||||
minspec = vs.Reverse().First(s => ((EncounterGeneric[]) Encounter).Any(slot => slot.Species == s.Species)).Species;
|
||||
else if (Encounter is EncounterGeneric)
|
||||
minspec = vs.Reverse().First(s => ((EncounterGeneric) Encounter).Species == s.Species).Species;
|
||||
else if (Encounter is IEncounterable[])
|
||||
minspec = vs.Reverse().First(s => ((IEncounterable[]) Encounter).Any(slot => slot.Species == s.Species)).Species;
|
||||
else if (Encounter is IEncounterable)
|
||||
minspec = vs.Reverse().First(s => ((IEncounterable) Encounter).Species == s.Species).Species;
|
||||
else
|
||||
minspec = vs.Last().Species;
|
||||
|
||||
|
@ -670,11 +670,11 @@ namespace PKHeX
|
|||
var t = Encounter;
|
||||
if (pkm.WasEgg)
|
||||
return "Egg";
|
||||
if (t is EncounterGeneric)
|
||||
return ((EncounterGeneric)t).Name;
|
||||
if (t is EncounterGeneric[])
|
||||
if (t is IEncounterable)
|
||||
return ((IEncounterable)t).Name;
|
||||
if (t is IEncounterable[])
|
||||
{
|
||||
var arr = (EncounterGeneric[])t;
|
||||
var arr = (IEncounterable[])t;
|
||||
if (arr.Any())
|
||||
return arr.First().Name;
|
||||
}
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
namespace PKHeX
|
||||
{
|
||||
public abstract class EncounterGeneric
|
||||
{
|
||||
public virtual int Species { get; set; }
|
||||
public abstract string Name { get; }
|
||||
}
|
||||
}
|
|
@ -1,7 +1,8 @@
|
|||
namespace PKHeX
|
||||
{
|
||||
public class EncounterLink : EncounterGeneric
|
||||
public class EncounterLink : IEncounterable
|
||||
{
|
||||
public int Species { get; set; }
|
||||
public int Level;
|
||||
public int Location = 30011;
|
||||
public int Ability = 1;
|
||||
|
@ -19,6 +20,6 @@
|
|||
public bool ORAS = false;
|
||||
public bool SM = false;
|
||||
|
||||
public override string Name => "Pokémon Link Gift";
|
||||
public string Name => "Pokémon Link Gift";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
namespace PKHeX
|
||||
{
|
||||
public class EncounterSlot : EncounterGeneric
|
||||
public class EncounterSlot : IEncounterable
|
||||
{
|
||||
public int Species { get; set; }
|
||||
public int Form;
|
||||
public int LevelMin;
|
||||
public int LevelMax;
|
||||
|
@ -24,7 +25,6 @@
|
|||
Pressure = template.Pressure;
|
||||
}
|
||||
|
||||
public override string Name => "Wild Encounter";
|
||||
public string Name => "Wild Encounter";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
namespace PKHeX
|
||||
{
|
||||
public class EncounterStatic : EncounterGeneric
|
||||
public class EncounterStatic : IEncounterable
|
||||
{
|
||||
public int Species { get; set; }
|
||||
public int Level;
|
||||
|
||||
public int Location = 0;
|
||||
|
@ -24,6 +25,6 @@
|
|||
public bool RibbonWishing = false;
|
||||
public bool SkipFormCheck = false;
|
||||
|
||||
public override string Name => "Static Encounter";
|
||||
public string Name => "Static Encounter";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
namespace PKHeX
|
||||
{
|
||||
public class EncounterTrade : EncounterGeneric
|
||||
public class EncounterTrade : IEncounterable
|
||||
{
|
||||
public int Species { get; set; }
|
||||
public int Level;
|
||||
|
||||
public int Location = 30001;
|
||||
|
@ -16,6 +17,6 @@
|
|||
public int Gender = -1;
|
||||
public int OTGender = -1;
|
||||
|
||||
public override string Name => "In-game Trade";
|
||||
public string Name => "In-game Trade";
|
||||
}
|
||||
}
|
||||
|
|
8
PKHeX/Legality/Structures/IEncounterable.cs
Normal file
8
PKHeX/Legality/Structures/IEncounterable.cs
Normal file
|
@ -0,0 +1,8 @@
|
|||
namespace PKHeX
|
||||
{
|
||||
public interface IEncounterable
|
||||
{
|
||||
int Species { get; }
|
||||
string Name { get; }
|
||||
}
|
||||
}
|
|
@ -3,7 +3,7 @@ using System.Linq;
|
|||
|
||||
namespace PKHeX
|
||||
{
|
||||
public abstract class MysteryGift : EncounterGeneric
|
||||
public abstract class MysteryGift : IEncounterable
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
|
@ -92,9 +92,10 @@ namespace PKHeX
|
|||
return getMysteryGift(data);
|
||||
}
|
||||
public string Type => GetType().Name;
|
||||
public override string Name => $"Event Gift ({Type})";
|
||||
public string Name => $"Event Gift ({Type})";
|
||||
|
||||
// Properties
|
||||
public virtual int Species { get { return -1; } set { } }
|
||||
public abstract bool GiftUsed { get; set; }
|
||||
public abstract string CardTitle { get; set; }
|
||||
public abstract int CardID { get; set; }
|
||||
|
@ -109,7 +110,7 @@ namespace PKHeX
|
|||
public string getCardHeader() => (CardID > 0 ? $"Card #: {CardID:0000}" : "N/A") + $" - {CardTitle.Replace('\u3000',' ').Trim()}";
|
||||
|
||||
// Search Properties
|
||||
public virtual int[] Moves => new int[4];
|
||||
public virtual int[] Moves { get { return new int[4]; } set { } }
|
||||
public virtual int[] RelearnMoves { get { return new int[4]; } set { } }
|
||||
public virtual bool IsShiny => false;
|
||||
public virtual bool IsEgg { get { return false; } set { } }
|
||||
|
|
|
@ -46,8 +46,7 @@ namespace PKHeX
|
|||
public int Move2 { get { return BitConverter.ToUInt16(Data, 0x14); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x14); } }
|
||||
public int Move3 { get { return BitConverter.ToUInt16(Data, 0x16); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x16); } }
|
||||
public int Move4 { get { return BitConverter.ToUInt16(Data, 0x18); } set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x18); } }
|
||||
public override int Species { get { return BitConverter.ToUInt16(Data, 0x1A); }
|
||||
}
|
||||
public override int Species { get { return BitConverter.ToUInt16(Data, 0x1A); } set { BitConverter.GetBytes((ushort) value).CopyTo(Data, 0x1A); } }
|
||||
public int Form { get { return Data[0x1C]; } set { Data[0x1C] = (byte)value; } }
|
||||
public int Language { get { return Data[0x1D]; } set { Data[0x1D] = (byte)value; } }
|
||||
public string Nickname
|
||||
|
@ -143,10 +142,7 @@ namespace PKHeX
|
|||
public int[] IVs => new[] { IV_HP, IV_ATK, IV_DEF, IV_SPE, IV_SPA, IV_SPD };
|
||||
public bool IsNicknamed => Nickname.Length > 0;
|
||||
|
||||
public override int[] Moves
|
||||
{
|
||||
get { return new[] { Move1, Move2, Move3, Move4 }; }
|
||||
}
|
||||
public override int[] Moves => new[] { Move1, Move2, Move3, Move4 };
|
||||
public override bool IsPokémon { get { return CardType == 1; } set { if (value) CardType = 1; } }
|
||||
public override bool IsItem { get { return CardType == 2; } set { if (value) CardType = 2; } }
|
||||
public bool IsPower { get { return CardType == 3; } set { if (value) CardType = 3; } }
|
||||
|
|
|
@ -61,11 +61,11 @@ namespace PKHeX
|
|||
}
|
||||
}
|
||||
|
||||
public override int Species => Gift.PK.Species;
|
||||
public override int[] Moves => Gift.PK.Moves;
|
||||
public override bool IsShiny => Gift.PK.IsShiny;
|
||||
public override bool IsEgg => Gift.PK.IsEgg;
|
||||
public override int HeldItem => Gift.PK.HeldItem;
|
||||
public override int Species { get { return Gift.Species; } set { Gift.Species = value; } }
|
||||
public override int[] Moves { get { return Gift.Moves; } set { Gift.Moves = value; } }
|
||||
public override int HeldItem { get { return Gift.HeldItem; } set { Gift.HeldItem = value; } }
|
||||
public override bool IsShiny => Gift.IsShiny;
|
||||
public override bool IsEgg { get { return Gift.IsEgg; } set { Gift.IsEgg = value; } }
|
||||
|
||||
public override PKM convertToPKM(SaveFile SAV)
|
||||
{
|
||||
|
@ -146,15 +146,15 @@ namespace PKHeX
|
|||
|
||||
private GiftType PGTGiftType { get { return (GiftType)Data[0]; } set {Data[0] = (byte)value; } }
|
||||
public bool IsHatched => PGTGiftType == GiftType.Pokémon;
|
||||
public override bool IsEgg => PGTGiftType == GiftType.PokémonEgg;
|
||||
public bool IsManaphyEgg => PGTGiftType == GiftType.ManaphyEgg;
|
||||
public override bool IsItem { get { return PGTGiftType == GiftType.Item; } set { if (value) CardType = (int)GiftType.Item; } }
|
||||
public override bool IsEgg { get { return PGTGiftType == GiftType.PokémonEgg; } set { if (value) { PGTGiftType = GiftType.PokémonEgg; PK.IsEgg = true; } } }
|
||||
public bool IsManaphyEgg { get { return PGTGiftType == GiftType.ManaphyEgg; } set { if (value) PGTGiftType = GiftType.ManaphyEgg; } }
|
||||
public override bool IsItem { get { return PGTGiftType == GiftType.Item; } set { if (value) PGTGiftType = GiftType.Item; } }
|
||||
public override bool IsPokémon { get { return PGTGiftType == GiftType.Pokémon || PGTGiftType == GiftType.PokémonEgg || PGTGiftType == GiftType.ManaphyEgg; } set { } }
|
||||
|
||||
public override int Species => PK.Species;
|
||||
public override int[] Moves => PK.Moves;
|
||||
public override int Species { get { return PK.Species; } set { PK.Species = value; } }
|
||||
public override int[] Moves { get { return PK.Moves; } set { PK.Moves = value; } }
|
||||
public override int HeldItem { get { return PK.HeldItem; } set { PK.HeldItem = value; } }
|
||||
public override bool IsShiny => PK.IsShiny;
|
||||
public override int HeldItem => PK.HeldItem;
|
||||
|
||||
public override PKM convertToPKM(SaveFile SAV)
|
||||
{
|
||||
|
|
|
@ -171,7 +171,7 @@ namespace PKHeX
|
|||
set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x4A3); } }
|
||||
}
|
||||
|
||||
public class PL6_PKM //: PokemonLink
|
||||
public class PL6_PKM : IEncounterable
|
||||
{
|
||||
|
||||
internal const int Size = 0xA0;
|
||||
|
@ -328,5 +328,6 @@ namespace PKHeX
|
|||
}
|
||||
}
|
||||
|
||||
public string Name => "Pokémon Link";
|
||||
}
|
||||
}
|
|
@ -98,7 +98,7 @@ namespace PKHeX
|
|||
|
||||
// Pokémon Properties
|
||||
public override bool IsPokémon { get { return CardType == 0; } set { if (value) CardType = 0; } }
|
||||
public override bool IsShiny { get { return PIDType == 2; } }
|
||||
public override bool IsShiny => PIDType == 2;
|
||||
public int TID {
|
||||
get { return BitConverter.ToUInt16(Data, 0x68); }
|
||||
set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x68); } }
|
||||
|
@ -226,6 +226,13 @@ namespace PKHeX
|
|||
public override int[] Moves
|
||||
{
|
||||
get { return new[] { Move1, Move2, Move3, Move4 }; }
|
||||
set
|
||||
{
|
||||
if (value.Length > 0) Move1 = value[0];
|
||||
if (value.Length > 1) Move2 = value[1];
|
||||
if (value.Length > 2) Move3 = value[2];
|
||||
if (value.Length > 3) Move4 = value[3];
|
||||
}
|
||||
}
|
||||
public override int[] RelearnMoves
|
||||
{
|
||||
|
|
|
@ -93,7 +93,7 @@ namespace PKHeX
|
|||
|
||||
// Pokémon Properties
|
||||
public override bool IsPokémon { get { return CardType == 0; } set { if (value) CardType = 0; } }
|
||||
public override bool IsShiny { get { return PIDType == 2; } }
|
||||
public override bool IsShiny => PIDType == 2;
|
||||
public int TID {
|
||||
get { return BitConverter.ToUInt16(Data, 0x68); }
|
||||
set { BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x68); } }
|
||||
|
@ -223,6 +223,13 @@ namespace PKHeX
|
|||
public override int[] Moves
|
||||
{
|
||||
get { return new[] { Move1, Move2, Move3, Move4 }; }
|
||||
set
|
||||
{
|
||||
if (value.Length > 0) Move1 = value[0];
|
||||
if (value.Length > 1) Move2 = value[1];
|
||||
if (value.Length > 2) Move3 = value[2];
|
||||
if (value.Length > 3) Move4 = value[3];
|
||||
}
|
||||
}
|
||||
public override int[] RelearnMoves
|
||||
{
|
||||
|
|
|
@ -115,7 +115,7 @@
|
|||
<Compile Include="Legality\Structures\DexLevel.cs" />
|
||||
<Compile Include="Legality\Structures\EggMoves.cs" />
|
||||
<Compile Include="Legality\Structures\EncounterArea.cs" />
|
||||
<Compile Include="Legality\Structures\EncounterGeneric.cs" />
|
||||
<Compile Include="Legality\Structures\IEncounterable.cs" />
|
||||
<Compile Include="Legality\Structures\EncounterLink.cs" />
|
||||
<Compile Include="Legality\Structures\EncounterSlot.cs" />
|
||||
<Compile Include="Legality\Structures\EncounterStatic.cs" />
|
||||
|
|
Loading…
Reference in a new issue