Extract some reused logic

Put the methods in Tables4; kinda breaks the 'only arrays here' rule but
they only reference values in this file(partial class).
This commit is contained in:
Kurt 2019-02-20 22:10:15 -08:00
parent 1b221e052c
commit 941b1b5c47
3 changed files with 46 additions and 31 deletions

View file

@ -170,11 +170,7 @@ namespace PKHeX.Core
return -1;
if (pkm.Format >= 5) // Transporter
{
return pkm.Gen4 && pkm.FatefulEncounter && Legal.CrownBeasts.Contains(pkm.Species)
? (pkm.Species == 251 ? Legal.Transfer4_CelebiUnused : Legal.Transfer4_CrownUnused) // Celebi : Beast
: Legal.Transfer4; // Pokétransfer (not Crown)
}
return Legal.GetTransfer45MetLocation(pkm);
return -1;
}
}

View file

@ -161,7 +161,6 @@ namespace PKHeX.Core
015, 019, 057, 070, 432, 249, 127, 431 // Defog(DPPt)
};
internal static readonly HashSet<int> HM_4_RemovePokeTransfer = new HashSet<int>
{
015, 019, 057, 070, 249, 127, 431 // Defog(DPPt) & Whirlpool(HGSS) excluded
@ -211,7 +210,6 @@ namespace PKHeX.Core
};
internal static readonly bool[] ReleasedHeldItems_4 = Enumerable.Range(0, MaxItemID_4_HGSS+1).Select(i => HeldItems_HGSS.Contains((ushort)i) && !UnreleasedItems_4.Contains(i)).ToArray();
internal static readonly HashSet<int> CrownBeasts = new HashSet<int> { 251, 243, 244, 245 };
internal static readonly int[] Tutors_4 =
{
@ -282,5 +280,42 @@ namespace PKHeX.Core
{
2000, 2002, 2009, 2010, 2011, 2013, 2014
};
internal static int GetTransfer45MetLocation(PKM pk5)
{
if (pk5.Gen4 && pk5.FatefulEncounter)
{
var spec = pk5.Species;
if (spec == 251) // Celebi
return Transfer4_CelebiUnused;
if (243 <= spec && spec <= 245) // Beast
return Transfer4_CrownUnused;
}
return Transfer4; // Pokétransfer (not Crown);
}
internal static int[] RemoveMovesHM45(int[] moves)
{
var banned = GetFavorableHMBanlist(moves);
for (int i = 0; i < 4; i++)
{
if (banned.Contains(moves[i]))
moves[i] = 0;
}
return moves;
}
/// <summary>
/// Transfer via advantageous game
/// </summary>
/// <param name="moves">Current moves</param>
/// <returns>Preferred move ban list</returns>
private static HashSet<int> GetFavorableHMBanlist(int[] moves)
{
// if has defog, return ban list with whirlpool
return moves.Contains(432) ? HM_HGSS : HM_DPPt;
}
}
}

View file

@ -381,16 +381,13 @@ namespace PKHeX.Core
pk5.AltForm = 0;
pk5.HeldItem = 0;
}
else
else if(!Legal.HeldItems_BW.Contains((ushort)HeldItem))
{
pk5.HeldItem = Legal.HeldItems_BW.Contains((ushort) HeldItem) ? HeldItem : 0;
pk5.HeldItem = 0; // if valid, it's already copied
}
// Fix PP
pk5.Move1_PP = pk5.GetMovePP(pk5.Move1, pk5.Move1_PPUps);
pk5.Move2_PP = pk5.GetMovePP(pk5.Move2, pk5.Move2_PPUps);
pk5.Move3_PP = pk5.GetMovePP(pk5.Move3, pk5.Move3_PPUps);
pk5.Move4_PP = pk5.GetMovePP(pk5.Move4, pk5.Move4_PPUps);
pk5.HealPP();
// Disassociate Nature and PID, pk4 getter does PID%25
pk5.Nature = Nature;
@ -399,9 +396,7 @@ namespace PKHeX.Core
BitConverter.GetBytes((uint)0).CopyTo(pk5.Data, 0x44);
// Met / Crown Data Detection
pk5.Met_Location = pk5.Gen4 && pk5.FatefulEncounter && Legal.CrownBeasts.Contains(pk5.Species)
? (pk5.Species == 251 ? Legal.Transfer4_CelebiUnused : Legal.Transfer4_CrownUnused) // Celebi : Beast
: Legal.Transfer4; // Pokétransfer (not Crown)
pk5.Met_Location = Legal.GetTransfer45MetLocation(pk5);
// Egg Location is not modified; when clearing Pt/HGSS egg data, the location will revert to Faraway Place
// pk5.Egg_Location = Egg_Location;
@ -410,26 +405,15 @@ namespace PKHeX.Core
BitConverter.GetBytes((ushort)0).CopyTo(pk5.Data, 0x86);
pk5.Ball = Ball;
// Transfer Nickname and OT Name
// Transfer Nickname and OT Name, update encoding
pk5.Nickname = Nickname;
pk5.OT_Name = OT_Name;
// Fix Level
pk5.Met_Level = Experience.GetLevel(pk5.EXP, pk5.Species, 0);
pk5.Met_Level = pk5.CurrentLevel;
// Remove HM moves; Defog should be kept if both are learned.
int[] banned = Moves.Contains(250) && Moves.Contains(432) // Whirlpool & Defog
? new[] {15, 19, 57, 70, 250, 249, 127, 431} // No Whirlpool
: new[] {15, 19, 57, 70, 249, 127, 431};// Transfer via advantageous game
int[] newMoves = pk5.Moves;
for (int i = 0; i < 4; i++)
{
if (banned.Contains(newMoves[i]))
newMoves[i] = 0;
}
pk5.Moves = newMoves;
pk5.Moves = Legal.RemoveMovesHM45(pk5.Moves);
pk5.FixMoves();
pk5.RefreshChecksum();