2018-10-28 18:15:40 +00:00
|
|
|
namespace PKHeX.Core
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Locks associated to a given NPC PKM that appears before a <see cref="EncounterStaticShadow"/>.
|
|
|
|
/// </summary>
|
2021-12-05 02:32:35 +00:00
|
|
|
public readonly record struct NPCLock
|
2018-10-28 18:15:40 +00:00
|
|
|
{
|
2021-08-22 01:24:38 +00:00
|
|
|
private readonly int Species;
|
|
|
|
private readonly byte Nature;
|
|
|
|
private readonly byte Gender;
|
|
|
|
private readonly byte Ratio;
|
|
|
|
private readonly byte State;
|
2018-10-28 18:15:40 +00:00
|
|
|
|
2021-08-22 00:44:43 +00:00
|
|
|
public int FramesConsumed => Seen ? 5 : 7;
|
2021-08-22 01:24:38 +00:00
|
|
|
public bool Seen => State > 1;
|
|
|
|
public bool Shadow => State != 0;
|
2022-02-09 17:26:10 +00:00
|
|
|
public (byte Nature, byte Gender) GetLock => (Nature, Gender);
|
2021-08-22 00:44:43 +00:00
|
|
|
|
|
|
|
// Not-Shadow
|
2019-01-07 04:58:57 +00:00
|
|
|
public NPCLock(short s, byte n, byte g, byte r)
|
2018-10-28 18:15:40 +00:00
|
|
|
{
|
|
|
|
Species = s;
|
|
|
|
Nature = n;
|
|
|
|
Gender = g;
|
|
|
|
Ratio = r;
|
2021-08-22 01:24:38 +00:00
|
|
|
State = 0;
|
2018-10-28 18:15:40 +00:00
|
|
|
}
|
|
|
|
|
2021-08-22 00:44:43 +00:00
|
|
|
// Shadow
|
2019-01-07 04:58:57 +00:00
|
|
|
public NPCLock(short s, bool seen = false)
|
2018-10-28 18:15:40 +00:00
|
|
|
{
|
|
|
|
Species = s;
|
2021-08-22 00:44:43 +00:00
|
|
|
Nature = 0;
|
|
|
|
Gender = 0;
|
|
|
|
Ratio = 0;
|
2021-08-22 01:24:38 +00:00
|
|
|
State = seen ? (byte)2 : (byte)1;
|
2018-10-28 18:15:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public bool MatchesLock(uint PID)
|
|
|
|
{
|
2021-08-22 01:24:38 +00:00
|
|
|
if (Shadow && Nature == 0) // Non-locked shadow
|
2018-10-28 18:15:40 +00:00
|
|
|
return true;
|
|
|
|
if (Gender != 2 && Gender != ((PID & 0xFF) < Ratio ? 1 : 0))
|
|
|
|
return false;
|
|
|
|
if (Nature != PID % 25)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-08-22 00:44:43 +00:00
|
|
|
#if DEBUG
|
|
|
|
public override string ToString()
|
|
|
|
{
|
|
|
|
var sb = new System.Text.StringBuilder(64);
|
|
|
|
sb.Append((Species)Species);
|
2021-08-22 01:24:38 +00:00
|
|
|
if (State != 0)
|
2021-08-22 00:44:43 +00:00
|
|
|
sb.Append(" (Shadow)");
|
|
|
|
if (Seen)
|
|
|
|
sb.Append(" [Seen]");
|
|
|
|
sb.Append(" - ");
|
|
|
|
sb.Append("Nature: ").Append((Nature)Nature);
|
|
|
|
if (Gender != 2)
|
|
|
|
sb.Append(", ").Append("Gender: ").Append(Gender);
|
|
|
|
return sb.ToString();
|
|
|
|
}
|
|
|
|
#endif
|
2018-10-28 18:15:40 +00:00
|
|
|
}
|
2021-08-22 00:44:43 +00:00
|
|
|
}
|