mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-23 12:33:06 +00:00
parent
2d34411203
commit
13e0f35e00
4 changed files with 101 additions and 7 deletions
|
@ -65,10 +65,10 @@ namespace PKHeX.Core
|
|||
return GetSlotsFuzzy(chain);
|
||||
if (pkm.Met_Location != Location)
|
||||
return Array.Empty<EncounterSlot4>();
|
||||
return GetSlotsMatching(chain, pkm.Met_Level);
|
||||
return GetSlotsMatching(chain, pkm.Met_Level, pkm);
|
||||
}
|
||||
|
||||
private IEnumerable<EncounterSlot4> GetSlotsMatching(IReadOnlyList<EvoCriteria> chain, int lvl)
|
||||
private IEnumerable<EncounterSlot4> GetSlotsMatching(IReadOnlyList<EvoCriteria> chain, int lvl, PKM pk)
|
||||
{
|
||||
foreach (var slot in Slots)
|
||||
{
|
||||
|
@ -86,12 +86,57 @@ namespace PKHeX.Core
|
|||
if (!slot.IsLevelWithinRange(lvl))
|
||||
break;
|
||||
|
||||
if (Type is SlotType.HoneyTree && IsInaccessibleHoneySlotLocation(slot, pk))
|
||||
break;
|
||||
|
||||
yield return slot;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsInaccessibleHoneySlotLocation(EncounterSlot4 slot, PKM pk)
|
||||
{
|
||||
// A/B/C tables, only Munchlax is a 'C' encounter, and A/B are accessible from any tree.
|
||||
// C table encounters are only available from 4 trees, which are determined by TID/SID of the save file.
|
||||
if (slot.Species is not (int)Species.Munchlax)
|
||||
return false;
|
||||
|
||||
// We didn't encode the honey tree index to the encounter slot resource.
|
||||
// Check if any of the slot's location doesn't match any of the groupC trees' area location ID.
|
||||
var location = pk.Met_Location;
|
||||
var trees = SAV4Sinnoh.CalculateMunchlaxTrees(pk.TID, pk.SID);
|
||||
return LocationID_HoneyTree[trees.Tree1] != location
|
||||
&& LocationID_HoneyTree[trees.Tree2] != location
|
||||
&& LocationID_HoneyTree[trees.Tree3] != location
|
||||
&& LocationID_HoneyTree[trees.Tree4] != location;
|
||||
}
|
||||
|
||||
private static readonly byte[] LocationID_HoneyTree =
|
||||
{
|
||||
20, // 00 Route 205 Floaroma
|
||||
20, // 01 Route 205 Eterna
|
||||
21, // 02 Route 206
|
||||
22, // 03 Route 207
|
||||
23, // 04 Route 208
|
||||
24, // 05 Route 209
|
||||
25, // 06 Route 210 Solaceon
|
||||
25, // 07 Route 210 Celestic
|
||||
26, // 08 Route 211
|
||||
27, // 09 Route 212 Hearthome
|
||||
27, // 10 Route 212 Pastoria
|
||||
28, // 11 Route 213
|
||||
29, // 12 Route 214
|
||||
30, // 13 Route 215
|
||||
33, // 14 Route 218
|
||||
36, // 15 Route 221
|
||||
37, // 16 Route 222
|
||||
47, // 17 Valley Windworks
|
||||
48, // 18 Eterna Forest
|
||||
49, // 19 Fuego Ironworks
|
||||
58, // 20 Floaroma Meadow
|
||||
};
|
||||
|
||||
// original met level cannot be inferred
|
||||
private IEnumerable<EncounterSlot4> GetSlotsFuzzy(IReadOnlyList<EvoCriteria> chain)
|
||||
{
|
||||
|
|
|
@ -89,10 +89,54 @@ namespace PKHeX.Core
|
|||
if (slot.Form != evo.Form && slot.Species is not (int)Species.Burmy)
|
||||
break;
|
||||
|
||||
if (Type is SlotType.HoneyTree && IsInaccessibleHoneySlotLocation(slot, pkm))
|
||||
break;
|
||||
|
||||
yield return slot;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
private static bool IsInaccessibleHoneySlotLocation(EncounterSlot8b slot, PKM pk)
|
||||
{
|
||||
// A/B/C tables, only Munchlax is a 'C' encounter, and A/B are accessible from any tree.
|
||||
// C table encounters are only available from 4 trees, which are determined by TID/SID of the save file.
|
||||
if (slot.Species is not (int)Species.Munchlax)
|
||||
return false;
|
||||
|
||||
// We didn't encode the honey tree index to the encounter slot resource.
|
||||
// Check if any of the slot's location doesn't match any of the groupC trees' area location ID.
|
||||
var location = pk.Met_Location;
|
||||
var trees = SAV4Sinnoh.CalculateMunchlaxTrees(pk.TID, pk.SID);
|
||||
return LocationID_HoneyTree[trees.Tree1] != location
|
||||
&& LocationID_HoneyTree[trees.Tree2] != location
|
||||
&& LocationID_HoneyTree[trees.Tree3] != location
|
||||
&& LocationID_HoneyTree[trees.Tree4] != location;
|
||||
}
|
||||
|
||||
private static readonly ushort[] LocationID_HoneyTree =
|
||||
{
|
||||
359, // 00 Route 205 Floaroma
|
||||
361, // 01 Route 205 Eterna
|
||||
362, // 02 Route 206
|
||||
364, // 03 Route 207
|
||||
365, // 04 Route 208
|
||||
367, // 05 Route 209
|
||||
373, // 06 Route 210 Solaceon
|
||||
375, // 07 Route 210 Celestic
|
||||
378, // 08 Route 211
|
||||
379, // 09 Route 212 Hearthome
|
||||
383, // 10 Route 212 Pastoria
|
||||
385, // 11 Route 213
|
||||
392, // 12 Route 214
|
||||
394, // 13 Route 215
|
||||
400, // 14 Route 218
|
||||
404, // 15 Route 221
|
||||
407, // 16 Route 222
|
||||
197, // 17 Valley Windworks
|
||||
199, // 18 Eterna Forest
|
||||
201, // 19 Fuego Ironworks
|
||||
253, // 20 Floaroma Meadow
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -129,9 +129,9 @@ namespace PKHeX.Core
|
|||
SetData(General, tree.Data, OFS_HONEY + (HONEY_SIZE * index));
|
||||
}
|
||||
|
||||
public int[] GetMunchlaxTrees() => CalculateMunchlaxTrees(TID, SID);
|
||||
public MunchlaxTreeSet4 GetMunchlaxTrees() => CalculateMunchlaxTrees(TID, SID);
|
||||
|
||||
private static int[] CalculateMunchlaxTrees(int tid, int sid)
|
||||
public static MunchlaxTreeSet4 CalculateMunchlaxTrees(int tid, int sid)
|
||||
{
|
||||
int A = (tid >> 8) % 21;
|
||||
int B = (tid & 0x00FF) % 21;
|
||||
|
@ -145,7 +145,7 @@ namespace PKHeX.Core
|
|||
if (B == D) D = (D + 1) % 21;
|
||||
if (C == D) D = (D + 1) % 21;
|
||||
|
||||
return new[] {A, B, C, D};
|
||||
return new(A, B, C, D);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -228,4 +228,9 @@ namespace PKHeX.Core
|
|||
Stopwatch,
|
||||
Alarm_Clock,
|
||||
}
|
||||
}
|
||||
|
||||
public readonly record struct MunchlaxTreeSet4(int Tree1, int Tree2, int Tree3, int Tree4)
|
||||
{
|
||||
public int[] ToArray() => new[] { Tree1, Tree2, Tree3, Tree4 };
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace PKHeX.WinForms
|
|||
};
|
||||
|
||||
// Get Munchlax tree for this savegame in screen
|
||||
MunchlaxTrees = SAV.GetMunchlaxTrees();
|
||||
MunchlaxTrees = SAV.GetMunchlaxTrees().ToArray();
|
||||
|
||||
const string sep = "- ";
|
||||
L_Tree0.Text = string.Join(Environment.NewLine, MunchlaxTrees.Select(z => sep + CB_TreeList.Items[z]));
|
||||
|
|
Loading…
Reference in a new issue