mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-08-23 07:04:14 -05:00
Misc reorg
use shared class for pk1/2 setnotnicknamed fix extendedeurope values (copypaste from extendedAmericas) move ball out of verifiers, move nature/movetype with ball
This commit is contained in:
@@ -26,8 +26,8 @@ public static void SetNickname(this PKM pk, string nick = null)
|
||||
{
|
||||
pk.IsNicknamed = false;
|
||||
pk.Nickname = PKX.GetSpeciesNameGeneration(pk.Species, pk.Language, pk.Format);
|
||||
if (pk is PK1 pk1) pk1.SetNotNicknamed();
|
||||
if (pk is PK2 pk2) pk2.SetNotNicknamed();
|
||||
if (pk is _K12 pk12)
|
||||
pk12.SetNotNicknamed();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -516,8 +516,7 @@ public static int GetMaximumEV(this PKM pk, int index)
|
||||
EVs[index] = 0;
|
||||
var sum = EVs.Sum();
|
||||
int remaining = 510 - sum;
|
||||
var newEV = Math.Min(Math.Max(remaining, 0), 252);
|
||||
return newEV;
|
||||
return Math.Min(Math.Max(remaining, 0), 252);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -72,6 +72,7 @@ private static IEnumerable<EncounterSlot1> GetSlots1_GW(byte[] data, ref int ofs
|
||||
int rate = data[ofs++];
|
||||
return rate == 0 ? Enumerable.Empty<EncounterSlot1>() : ReadSlots(data, ref ofs, 10, t, rate);
|
||||
}
|
||||
|
||||
private static EncounterSlot1[] GetSlots1_F(byte[] data, ref int ofs)
|
||||
{
|
||||
int count = data[ofs++];
|
||||
@@ -96,7 +97,7 @@ private static EncounterSlot1[] GetSlots2_GW(byte[] data, ref int ofs, SlotType
|
||||
{
|
||||
for (int i = 0; i < slotCount; i++)
|
||||
{
|
||||
int index = i + r*slotCount;
|
||||
int index = i + (r * slotCount);
|
||||
slots[index].Rate = rates[r];
|
||||
slots[index].SlotNumber = i;
|
||||
slots[index].Time = r == 1 ? EncounterTime.Day : EncounterTime.Night;
|
||||
@@ -131,6 +132,7 @@ private static List<EncounterSlot1> GetSlots2_F(byte[] data, ref int ofs, SlotTy
|
||||
while (rate != 0xFF);
|
||||
return slots;
|
||||
}
|
||||
|
||||
private static EncounterSlot1[] GetSlots2_H(byte[] data, ref int ofs, SlotType t)
|
||||
{
|
||||
// slot set ends in 0xFF
|
||||
@@ -182,6 +184,7 @@ private static IEnumerable<EncounterArea> GetAreas2(byte[] data, ref int ofs, Sl
|
||||
ofs++;
|
||||
return areas;
|
||||
}
|
||||
|
||||
private static List<EncounterArea> GetAreas2_F(byte[] data, ref int ofs)
|
||||
{
|
||||
var areas = new List<EncounterArea>();
|
||||
@@ -226,6 +229,7 @@ private static List<EncounterArea> GetAreas2_F(byte[] data, ref int ofs)
|
||||
}
|
||||
return areas;
|
||||
}
|
||||
|
||||
private static IEnumerable<EncounterArea> GetAreas2_H(byte[] data, ref int ofs)
|
||||
{
|
||||
// Read Location Table
|
||||
@@ -287,23 +291,25 @@ private static IEnumerable<EncounterSlot> GetSlots3(byte[] data, ref int ofs, in
|
||||
{
|
||||
for (int i = 0; i < numslots; i++)
|
||||
{
|
||||
int Species = BitConverter.ToInt16(data, ofs + 4 + i * 4);
|
||||
int o = ofs + (i * 4);
|
||||
int Species = BitConverter.ToInt16(data, o + 4);
|
||||
if (Species <= 0)
|
||||
continue;
|
||||
|
||||
slots.Add(new EncounterSlot
|
||||
{
|
||||
LevelMin = data[ofs + 2 + i * 4],
|
||||
LevelMax = data[ofs + 3 + i * 4],
|
||||
LevelMin = data[o + 2],
|
||||
LevelMax = data[o + 3],
|
||||
Species = Species,
|
||||
SlotNumber = i,
|
||||
Type = t
|
||||
});
|
||||
}
|
||||
}
|
||||
ofs += 2 + numslots * 4;
|
||||
ofs += 2 + (numslots * 4);
|
||||
return slots;
|
||||
}
|
||||
|
||||
private static IEnumerable<EncounterSlot> GetSlots3_F(byte[] data, ref int ofs, int numslots)
|
||||
{
|
||||
var slots = new List<EncounterSlot>();
|
||||
@@ -313,14 +319,14 @@ private static IEnumerable<EncounterSlot> GetSlots3_F(byte[] data, ref int ofs,
|
||||
{
|
||||
for (int i = 0; i < numslots; i++)
|
||||
{
|
||||
int Species = BitConverter.ToInt16(data, ofs + 4 + i * 4);
|
||||
int Species = BitConverter.ToInt16(data, ofs + 4 + (i * 4));
|
||||
if (Species <= 0)
|
||||
continue;
|
||||
|
||||
var slot = new EncounterSlot
|
||||
{
|
||||
LevelMin = data[ofs + 2 + i*4],
|
||||
LevelMax = data[ofs + 3 + i*4],
|
||||
LevelMin = data[ofs + 2 + (i * 4)],
|
||||
LevelMax = data[ofs + 3 + (i * 4)],
|
||||
Species = Species,
|
||||
};
|
||||
if (i < 2)
|
||||
@@ -341,7 +347,7 @@ private static IEnumerable<EncounterSlot> GetSlots3_F(byte[] data, ref int ofs,
|
||||
slots.Add(slot);
|
||||
}
|
||||
}
|
||||
ofs += 2 + numslots * 4;
|
||||
ofs += 2 + (numslots * 4);
|
||||
return slots;
|
||||
}
|
||||
|
||||
@@ -351,8 +357,9 @@ private static EncounterSlot[] GetSlots4_DPPt_G(byte[] data, int ofs, int numslo
|
||||
|
||||
for (int i = 0; i < numslots; i++)
|
||||
{
|
||||
int level = data[ofs + i*8];
|
||||
int species = BitConverter.ToInt32(data, ofs + i*8 + 4);
|
||||
int o = ofs + (i * 8);
|
||||
int level = data[o];
|
||||
int species = BitConverter.ToInt32(data, o + 4);
|
||||
slots[i] = new EncounterSlot
|
||||
{
|
||||
LevelMax = level,
|
||||
@@ -364,6 +371,7 @@ private static EncounterSlot[] GetSlots4_DPPt_G(byte[] data, int ofs, int numslo
|
||||
}
|
||||
return slots;
|
||||
}
|
||||
|
||||
private static EncounterSlot[] GetSlots4_HGSS_G(byte[] data, int ofs, int numslots, SlotType t)
|
||||
{
|
||||
var slots = new EncounterSlot[numslots * 3];
|
||||
@@ -372,7 +380,7 @@ private static EncounterSlot[] GetSlots4_HGSS_G(byte[] data, int ofs, int numslo
|
||||
for (int i = 0; i < numslots; i++)
|
||||
{
|
||||
int level = data[ofs + i];
|
||||
int species = BitConverter.ToUInt16(data, ofs + numslots + i * 2);
|
||||
int species = BitConverter.ToUInt16(data, ofs + numslots + (i * 2));
|
||||
slots[i] = new EncounterSlot
|
||||
{
|
||||
LevelMin = level,
|
||||
@@ -382,15 +390,16 @@ private static EncounterSlot[] GetSlots4_HGSS_G(byte[] data, int ofs, int numslo
|
||||
Type = t
|
||||
};
|
||||
slots[numslots + i] = slots[i].Clone();
|
||||
slots[numslots + i].Species = BitConverter.ToUInt16(data, ofs + numslots * 3 + i * 2);
|
||||
slots[numslots + i].Species = BitConverter.ToUInt16(data, ofs + (numslots * 3) + (i * 2));
|
||||
slots[numslots + i].Type = t;
|
||||
slots[numslots * 2 + i] = slots[i].Clone();
|
||||
slots[numslots * 2 + i].Species = BitConverter.ToUInt16(data, ofs + numslots * 5 + i * 2);
|
||||
slots[numslots * 2 + i].Type = t;
|
||||
slots[(numslots * 2) + i] = slots[i].Clone();
|
||||
slots[(numslots * 2) + i].Species = BitConverter.ToUInt16(data, ofs + (numslots * 5) + (i * 2));
|
||||
slots[(numslots * 2) + i].Type = t;
|
||||
}
|
||||
|
||||
return slots;
|
||||
}
|
||||
|
||||
private static List<EncounterSlot> GetSlots4_G_Replace(byte[] data, int ofs, int slotSize, EncounterSlot[] ReplacedSlots, int[] slotnums, SlotType t = SlotType.Grass)
|
||||
{
|
||||
//Special slots like GBA Dual Slot. Those slot only contain the info of species id, the level is copied from one of the first grass slots
|
||||
@@ -404,7 +413,7 @@ private static List<EncounterSlot> GetSlots4_G_Replace(byte[] data, int ofs, int
|
||||
if (baseSlot.LevelMin <= 0)
|
||||
continue;
|
||||
|
||||
int species = BitConverter.ToUInt16(data, ofs + i / (4 / slotSize) * slotSize);
|
||||
int species = BitConverter.ToUInt16(data, ofs + (i / (4 / slotSize) * slotSize));
|
||||
if (species <= 0 || baseSlot.Species == species) // Empty or duplicate
|
||||
continue;
|
||||
|
||||
@@ -416,21 +425,22 @@ private static List<EncounterSlot> GetSlots4_G_Replace(byte[] data, int ofs, int
|
||||
}
|
||||
return slots;
|
||||
}
|
||||
|
||||
private static IEnumerable<EncounterSlot> GetSlots4DPPt_WFR(byte[] data, int ofs, int numslots, SlotType t)
|
||||
{
|
||||
var slots = new List<EncounterSlot>();
|
||||
for (int i = 0; i < numslots; i++)
|
||||
{
|
||||
// max, min, unused, unused, [32bit species]
|
||||
int Species = BitConverter.ToInt32(data, ofs + 4 + i * 8);
|
||||
int Species = BitConverter.ToInt32(data, ofs + 4 + (i * 8));
|
||||
if (Species <= 0)
|
||||
continue;
|
||||
// fishing and surf slots with species = 0 are not added
|
||||
// DPPt does not have fishing or surf swarms
|
||||
slots.Add(new EncounterSlot
|
||||
{
|
||||
LevelMax = data[ofs + 0 + i * 8],
|
||||
LevelMin = data[ofs + 1 + i * 8],
|
||||
LevelMax = data[ofs + 0 + (i * 8)],
|
||||
LevelMin = data[ofs + 1 + (i * 8)],
|
||||
Species = Species,
|
||||
SlotNumber = i,
|
||||
Type = t
|
||||
@@ -439,13 +449,14 @@ private static IEnumerable<EncounterSlot> GetSlots4DPPt_WFR(byte[] data, int ofs
|
||||
EncounterUtil.MarkEncountersStaticMagnetPull(slots, PersonalTable.HGSS);
|
||||
return slots;
|
||||
}
|
||||
|
||||
private static IEnumerable<EncounterSlot> GetSlots4HGSS_WFR(byte[] data, int ofs, int numslots, SlotType t)
|
||||
{
|
||||
var slots = new List<EncounterSlot>();
|
||||
for (int i = 0; i < numslots; i++)
|
||||
{
|
||||
// min, max, [16bit species]
|
||||
int Species = BitConverter.ToInt16(data, ofs + 2 + i * 4);
|
||||
int Species = BitConverter.ToInt16(data, ofs + 2 + (i * 4));
|
||||
if (t == SlotType.Rock_Smash && Species <= 0)
|
||||
continue;
|
||||
// fishing and surf slots with species = 0 are added too, it is needed for the swarm encounters,
|
||||
@@ -453,8 +464,8 @@ private static IEnumerable<EncounterSlot> GetSlots4HGSS_WFR(byte[] data, int ofs
|
||||
|
||||
slots.Add(new EncounterSlot
|
||||
{
|
||||
LevelMin = data[ofs + 0 + i * 4],
|
||||
LevelMax = data[ofs + 1 + i * 4],
|
||||
LevelMin = data[ofs + 0 + (i * 4)],
|
||||
LevelMax = data[ofs + 1 + (i * 4)],
|
||||
Species = Species,
|
||||
SlotNumber = i,
|
||||
Type = t
|
||||
@@ -563,8 +574,10 @@ private static EncounterArea GetArea4DPPt(byte[] data, bool pt = false)
|
||||
// get all permutations of trophy inhabitants
|
||||
var trophy = regular[0].Concat(slots).ToArray();
|
||||
for (int i = 0; i < trophy.Length; i++)
|
||||
for (int j = i + 1; j < trophy.Length; j++)
|
||||
regular.Add(new List<EncounterSlot>{trophy[i], trophy[j]});
|
||||
{
|
||||
for (int j = i + 1; j < trophy.Length; j++)
|
||||
regular.Add(new List<EncounterSlot>{trophy[i], trophy[j]});
|
||||
}
|
||||
}
|
||||
|
||||
var set = new[] { regular, pair0, pair1, pair2, pair3 };
|
||||
@@ -601,6 +614,7 @@ private static EncounterArea GetArea4DPPt(byte[] data, bool pt = false)
|
||||
|
||||
return Area4;
|
||||
}
|
||||
|
||||
private static IEnumerable<EncounterSlot> MarkStaticMagnetExtras(IEnumerable<IEnumerable<List<EncounterSlot>>> product)
|
||||
{
|
||||
var trackPermute = new List<EncounterSlot>();
|
||||
@@ -608,6 +622,7 @@ private static IEnumerable<EncounterSlot> MarkStaticMagnetExtras(IEnumerable<IEn
|
||||
MarkStaticMagnetPermute(p.SelectMany(z => z), trackPermute);
|
||||
return trackPermute;
|
||||
}
|
||||
|
||||
private static void MarkStaticMagnetPermute(IEnumerable<EncounterSlot> grp, List<EncounterSlot> trackPermute)
|
||||
{
|
||||
EncounterUtil.MarkEncountersStaticMagnetPullPermutation(grp, PersonalTable.HGSS, trackPermute);
|
||||
@@ -688,6 +703,7 @@ private static EncounterArea GetArea4HGSS(byte[] data)
|
||||
slot.Area = Area4;
|
||||
return Area4;
|
||||
}
|
||||
|
||||
private static readonly EncounterSlot[] SlotsHGSS_Staryu =
|
||||
{
|
||||
new EncounterSlot { Species = 120, LevelMin = 20, LevelMax = 20, Type = SlotType.Good_Rod },
|
||||
@@ -707,14 +723,14 @@ private static EncounterArea GetArea4HGSS_Headbutt(byte[] data)
|
||||
// 12-17 Special trees
|
||||
for (int i = 0; i < 18; i++)
|
||||
{
|
||||
int Species = BitConverter.ToInt16(data, 6 + i*4);
|
||||
int Species = BitConverter.ToInt16(data, 6 + (i * 4));
|
||||
if (Species <= 0)
|
||||
continue;
|
||||
Slots.Add(new EncounterSlot
|
||||
{
|
||||
Species = Species,
|
||||
LevelMin = data[8 + i*4],
|
||||
LevelMax = data[9 + i*4],
|
||||
LevelMin = data[8 + (i * 4)],
|
||||
LevelMax = data[9 + (i * 4)],
|
||||
Type = i <= 11 ? SlotType.Headbutt : SlotType.Headbutt_Special
|
||||
});
|
||||
}
|
||||
@@ -818,6 +834,7 @@ public static EncounterArea[] GetArray1_GW(byte[] data)
|
||||
}
|
||||
return areas.Where(area => area.Slots.Length != 0).ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the encounter areas with <see cref="EncounterSlot"/> information from Pokémon Yellow (Generation 1) Fishing data.
|
||||
/// </summary>
|
||||
@@ -830,15 +847,16 @@ public static EncounterArea[] GetArray1_FY(byte[] data)
|
||||
EncounterArea[] areas = new EncounterArea[count];
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
int ofs = i*size + 1;
|
||||
int ofs = (i * size) + 1;
|
||||
areas[i] = new EncounterArea
|
||||
{
|
||||
Location = data[i*size + 0],
|
||||
Location = data[(i * size) + 0],
|
||||
Slots = ReadSlots_FY(data, ref ofs, 4, SlotType.Super_Rod, -1)
|
||||
};
|
||||
}
|
||||
return areas;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the encounter areas with <see cref="EncounterSlot"/> information from Generation 1 Fishing data.
|
||||
/// </summary>
|
||||
@@ -851,13 +869,13 @@ public static EncounterArea[] GetArray1_F(byte[] data)
|
||||
int count = 0;
|
||||
for (int i = 0; i < ptr.Length; i++)
|
||||
{
|
||||
map[i] = data[i*3 + 0];
|
||||
map[i] = data[(i * 3) + 0];
|
||||
if (map[i] == 0xFF)
|
||||
{
|
||||
count = i;
|
||||
break;
|
||||
}
|
||||
ptr[i] = BitConverter.ToInt16(data, i * 3 + 1);
|
||||
ptr[i] = BitConverter.ToInt16(data, (i * 3) + 1);
|
||||
}
|
||||
|
||||
EncounterArea[] areas = new EncounterArea[count];
|
||||
@@ -927,6 +945,7 @@ public static EncounterArea[] GetArray2_F(byte[] data)
|
||||
areas.Add(new EncounterArea { Location = 0x2E, Slots = f[3].Slots }); // Silver Cave (2: Inside, 3: Outside)
|
||||
return areas.ToArray();
|
||||
}
|
||||
|
||||
public static EncounterArea[] GetArray2_H(byte[] data)
|
||||
{
|
||||
int ofs = 0;
|
||||
|
||||
@@ -10,18 +10,20 @@ public enum TreeEncounterAvailable
|
||||
{
|
||||
/// <summary> Encounter is possible a reachable tree </summary>
|
||||
ValidTree,
|
||||
|
||||
/// <summary> Encounter is only possible a tree reachable only with walk-through walls cheats </summary>
|
||||
InvalidTree,
|
||||
|
||||
/// <summary> Encounter is not possible in any tree </summary>
|
||||
Impossible
|
||||
}
|
||||
|
||||
/// <summary> Coordinate / Index Relationship for a Headbutt Tree </summary>
|
||||
internal class TreeCoordinates
|
||||
internal sealed class TreeCoordinates
|
||||
{
|
||||
internal int X { get; }
|
||||
internal int Y { get; }
|
||||
internal int Index => (X*Y + X+Y) / 5 % 10;
|
||||
internal int Index => ((X*Y) + X+Y) / 5 % 10;
|
||||
|
||||
public TreeCoordinates(int x, int y)
|
||||
{
|
||||
@@ -31,10 +33,11 @@ public TreeCoordinates(int x, int y)
|
||||
}
|
||||
|
||||
/// <summary> Trees on a given map </summary>
|
||||
public class TreesArea
|
||||
public sealed class TreesArea
|
||||
{
|
||||
private const int PivotCount = 10;
|
||||
private static int[][] TrainerModerateTreeIndex { get; } = GenerateTrainersTreeIndex();
|
||||
private static readonly int[][] TrainerModerateTreeIndex = GenerateTrainersTreeIndex();
|
||||
|
||||
private static int[][] GenerateTrainersTreeIndex()
|
||||
{
|
||||
// A tree have a low encounter or moderate encounter base on the TID Pivot Index (TID % 10)
|
||||
@@ -49,13 +52,10 @@ private static int[][] GenerateTrainersTreeIndex()
|
||||
}
|
||||
return TrainersIndex;
|
||||
}
|
||||
|
||||
internal static TreesArea[] GetArray(byte[][] entries) => entries.Select(z => new TreesArea(z)).ToArray();
|
||||
|
||||
public int Location { get; private set; }
|
||||
public TreeEncounterAvailable[] GetTrees(SlotType t) => t == SlotType.Headbutt
|
||||
? TrainerModerateEncounterTree
|
||||
: TrainerLowEncounterTree;
|
||||
|
||||
private TreeEncounterAvailable[] TrainerModerateEncounterTree { get; set; }
|
||||
private TreeEncounterAvailable[] TrainerLowEncounterTree { get; set; }
|
||||
private int[] ValidTreeIndex { get; set; }
|
||||
@@ -63,6 +63,10 @@ private static int[][] GenerateTrainersTreeIndex()
|
||||
private TreeCoordinates[] ValidTrees { get; set; }
|
||||
private TreeCoordinates[] InvalidTrees { get; set; }
|
||||
|
||||
public TreeEncounterAvailable[] GetTrees(SlotType t) => t == SlotType.Headbutt
|
||||
? TrainerModerateEncounterTree
|
||||
: TrainerLowEncounterTree;
|
||||
|
||||
private TreesArea(byte[] entry)
|
||||
{
|
||||
ReadAreaRawData(entry);
|
||||
@@ -116,6 +120,7 @@ private TreeEncounterAvailable GetAvailableModerate(int[] moderate)
|
||||
return TreeEncounterAvailable.InvalidTree;
|
||||
return TreeEncounterAvailable.Impossible;
|
||||
}
|
||||
|
||||
private TreeEncounterAvailable GetAvailableLow(int[] moderate)
|
||||
{
|
||||
if (ValidTreeIndex.Except(moderate).Any())
|
||||
|
||||
@@ -23,7 +23,7 @@ internal static string GetEncounterLocation(this ILocation Encounter, int gen, i
|
||||
if (loc < 0)
|
||||
return null;
|
||||
|
||||
if (version == 15) // handle C/XD locations
|
||||
if (version == (int)GameVersion.CXD) // handle C/XD locations
|
||||
{
|
||||
var locs = GameInfo.Strings.metCXD_00000;
|
||||
return loc >= locs.Length ? null : locs[loc];
|
||||
|
||||
@@ -259,7 +259,7 @@ public static bool CheckVivillonPattern(int form, int country, int region)
|
||||
if (!VivillonCountryTable[form].Contains(country))
|
||||
return false; // Country mismatch
|
||||
|
||||
CountryTable ct = Array.Find(RegionFormTable, t => t.countryID == country);
|
||||
var ct = Array.Find(RegionFormTable, t => t.countryID == country);
|
||||
if (ct.otherforms == null) // empty struct = no forms referenced
|
||||
return true; // No subregion table
|
||||
|
||||
@@ -317,6 +317,6 @@ public static bool IsConsoleRegionCountryValid(int consoleRegion, int country)
|
||||
}
|
||||
|
||||
private static readonly HashSet<int> ExtendedAmericas = new HashSet<int> {153, 156, 168, 174, 186};
|
||||
private static readonly HashSet<int> ExtendedEurope = new HashSet<int> { 153, 156, 168, 174, 186 };
|
||||
private static readonly HashSet<int> ExtendedEurope = new HashSet<int> {169, 184, 185};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user