mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-10 14:44:24 +00:00
Extract some event unlocking logic for core
This commit is contained in:
parent
76ab09f024
commit
11039f1119
4 changed files with 95 additions and 39 deletions
|
@ -0,0 +1,7 @@
|
|||
namespace PKHeX.Core;
|
||||
|
||||
public abstract class EventUnlocker<T> where T : SaveFile
|
||||
{
|
||||
protected T SAV { get; }
|
||||
protected EventUnlocker(T sav) => SAV = sav;
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
namespace PKHeX.Core;
|
||||
|
||||
public class EventUnlocker8b : EventUnlocker<SAV8BS>
|
||||
{
|
||||
public EventUnlocker8b(SAV8BS sav) : base(sav) { }
|
||||
|
||||
public bool UnlockReadySpiritomb => SAV.UgSaveData.TalkedNPC < 32;
|
||||
public bool UnlockReadyBoxLegend => SAV.Work.GetFlag(308) && SAV.Work.GetWork(84) != 5; // FE_D05R0114_SPPOKE_GET, WK_SCENE_D05R0114 (1-3 story related, 4 = captured, 5 = can retry)
|
||||
public bool UnlockReadyShaymin => SAV.Work.GetFlag(545) || !(SAV.Work.GetWork(276) == 1 && SAV.Zukan.HasNationalDex && SAV.Items.GetItemQuantity(452) == 1 && SAV.Work.GetSystemFlag(5)); // HAIHUEVENT_ID_D30, Oak's Letter
|
||||
public bool UnlockReadyDarkrai => SAV.Work.GetFlag(301) || !(SAV.Work.GetWork(275) == 1 && SAV.Zukan.HasNationalDex && SAV.Items.GetItemQuantity(454) == 1); // HAIHUEVENT_ID_D18, Member Card
|
||||
|
||||
// 0 = inactive, 1 = roaming, 2 = KOed, 3 = captured
|
||||
public bool UnlockReadyRoamerMesprit => SAV.Encounter.Roamer1Encount != 1;
|
||||
public bool UnlockReadyRoamerCresselia => SAV.Encounter.Roamer2Encount != 1;
|
||||
public bool ResetReadyRoamerMesprit => SAV.Encounter.Roamer1Encount != 0;
|
||||
public bool ResetReadyRoamerCresselia => SAV.Encounter.Roamer2Encount != 0;
|
||||
|
||||
public void UnlockBoxLegend()
|
||||
{
|
||||
SAV.Work.SetFlag(308, false); // captured
|
||||
SAV.Work.SetFlag(393, false); // clear vanish
|
||||
SAV.Work.SetFlag(1623, false); // can retry
|
||||
SAV.Work.SetWork(84, 5); // can retry
|
||||
}
|
||||
|
||||
public void UnlockSpiritomb()
|
||||
{
|
||||
var trainers = SAV.UgSaveData.GetTrainers();
|
||||
for (int i = 0; i < 32; i++)
|
||||
trainers[i] = (byte)(i + 1);
|
||||
}
|
||||
|
||||
public void UnlockShaymin()
|
||||
{
|
||||
SAV.Zukan.HasNationalDex = true; // dex
|
||||
SAV.Work.SetSystemFlag(5, true); // clear
|
||||
SAV.Work.SetWork(276, 1); // haihu
|
||||
SAV.Items.SetItemQuantity(452, 1); // letter
|
||||
SAV.Work.SetFlag(545, false); // clear vanish
|
||||
}
|
||||
|
||||
public void UnlockDarkrai()
|
||||
{
|
||||
SAV.Zukan.HasNationalDex = true; // dex
|
||||
SAV.Work.SetWork(275, 1); // haihu
|
||||
SAV.Items.SetItemQuantity(454, 1); // member
|
||||
SAV.Work.SetFlag(301, false); // clear vanish
|
||||
}
|
||||
|
||||
public void RespawnRoamer()
|
||||
{
|
||||
RespawnMesprit();
|
||||
RespawnCresselia();
|
||||
}
|
||||
|
||||
public void RespawnMesprit()
|
||||
{
|
||||
SAV.Work.SetFlag(249, false); // clear met
|
||||
SAV.Work.SetFlag(420, false); // clear vanish
|
||||
SAV.Encounter.Roamer1Encount = 0; // not actively roaming
|
||||
}
|
||||
|
||||
public void RespawnCresselia()
|
||||
{
|
||||
SAV.Work.SetFlag(245, false); // clear met
|
||||
SAV.Work.SetFlag(532, false); // clear vanish
|
||||
SAV.Encounter.Roamer2Encount = 0; // not actively roaming
|
||||
}
|
||||
}
|
|
@ -110,6 +110,7 @@ namespace PKHeX.Core
|
|||
public int BeforeZone { get => BitConverter.ToInt32(Data, Offset + OFS_ZONEHISTORY + 0x00); set => BitConverter.GetBytes(value).CopyTo(Data, Offset + OFS_ZONEHISTORY + 0x00); }
|
||||
public int OldZone { get => BitConverter.ToInt32(Data, Offset + OFS_ZONEHISTORY + 0x04); set => BitConverter.GetBytes(value).CopyTo(Data, Offset + OFS_ZONEHISTORY + 0x04); }
|
||||
|
||||
// Mesprit
|
||||
public int Roamer1ZoneID { get => BitConverter.ToInt32 (Data, Offset + OFS_ROAM1 + 0x00); set => BitConverter.GetBytes(value).CopyTo(Data, Offset + OFS_ROAM1 + 0x00); }
|
||||
public ulong Roamer1Seed { get => BitConverter.ToUInt64(Data, Offset + OFS_ROAM1 + 0x04); set => BitConverter.GetBytes(value).CopyTo(Data, Offset + OFS_ROAM1 + 0x04); }
|
||||
public uint Roamer1Species { get => BitConverter.ToUInt32(Data, Offset + OFS_ROAM1 + 0x0C); set => BitConverter.GetBytes(value).CopyTo(Data, Offset + OFS_ROAM1 + 0x0C); }
|
||||
|
@ -118,6 +119,7 @@ namespace PKHeX.Core
|
|||
public uint Roamer1Status { get => BitConverter.ToUInt32(Data, Offset + OFS_ROAM1 + 0x18); set => BitConverter.GetBytes(value).CopyTo(Data, Offset + OFS_ROAM1 + 0x18); }
|
||||
public byte Roamer1Encount { get => Data[Offset + OFS_ROAM1 + 0x1C]; set => Data[Offset + OFS_ROAM1 + 0x1C] = value; }
|
||||
|
||||
// Cresselia
|
||||
public int Roamer2ZoneID { get => BitConverter.ToInt32 (Data, Offset + OFS_ROAM2 + 0x00); set => BitConverter.GetBytes(value).CopyTo(Data, Offset + OFS_ROAM2 + 0x00); }
|
||||
public ulong Roamer2Seed { get => BitConverter.ToUInt64(Data, Offset + OFS_ROAM2 + 0x04); set => BitConverter.GetBytes(value).CopyTo(Data, Offset + OFS_ROAM2 + 0x04); }
|
||||
public uint Roamer2Species { get => BitConverter.ToUInt32(Data, Offset + OFS_ROAM2 + 0x0C); set => BitConverter.GetBytes(value).CopyTo(Data, Offset + OFS_ROAM2 + 0x0C); }
|
||||
|
|
|
@ -7,12 +7,14 @@ namespace PKHeX.WinForms
|
|||
{
|
||||
private readonly SAV8BS Origin;
|
||||
private readonly SAV8BS SAV;
|
||||
private readonly EventUnlocker8b Unlocker;
|
||||
|
||||
public SAV_Misc8b(SAV8BS sav)
|
||||
{
|
||||
InitializeComponent();
|
||||
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
|
||||
SAV = (SAV8BS)(Origin = sav).Clone();
|
||||
Unlocker = new EventUnlocker8b(sav);
|
||||
|
||||
ReadMain();
|
||||
}
|
||||
|
@ -28,11 +30,11 @@ namespace PKHeX.WinForms
|
|||
|
||||
private void ReadMain()
|
||||
{
|
||||
B_Spiritomb.Enabled = SAV.UgSaveData.TalkedNPC < 32;
|
||||
B_Darkrai.Enabled = SAV.Work.GetFlag(301) || !(SAV.Work.GetWork(275) == 1 && SAV.Zukan.HasNationalDex && SAV.Items.GetItemQuantity(454) == 1); // HAIHUEVENT_ID_D18, Member Card
|
||||
B_Shaymin.Enabled = SAV.Work.GetFlag(545) || !(SAV.Work.GetWork(276) == 1 && SAV.Zukan.HasNationalDex && SAV.Items.GetItemQuantity(452) == 1 && SAV.Work.GetSystemFlag(5)); // HAIHUEVENT_ID_D30, Oak's Letter
|
||||
B_DialgaPalkia.Enabled = SAV.Work.GetFlag(308) && SAV.Work.GetWork(84) != 5; // FE_D05R0114_SPPOKE_GET, WK_SCENE_D05R0114 (1-3 story related, 4 = captured, 5 = can retry)
|
||||
B_Roamer.Enabled = SAV.Encounter.Roamer1Encount != 1 || SAV.Encounter.Roamer2Encount != 1; // 0 = inactive, 1 = roaming, 2 = KOed, 3 = captured
|
||||
B_Spiritomb.Enabled = Unlocker.UnlockReadySpiritomb;
|
||||
B_Darkrai.Enabled = Unlocker.UnlockReadyDarkrai;
|
||||
B_Shaymin.Enabled = Unlocker.UnlockReadyShaymin;
|
||||
B_DialgaPalkia.Enabled = Unlocker.UnlockReadyBoxLegend;
|
||||
B_Roamer.Enabled = Unlocker.ResetReadyRoamerMesprit || Unlocker.ResetReadyRoamerCresselia;
|
||||
|
||||
B_RebattleEyecatch.Enabled = SAV.BattleTrainer.AnyDefeated;
|
||||
B_DefeatEyecatch.Enabled = SAV.BattleTrainer.AnyUndefeated;
|
||||
|
@ -44,61 +46,37 @@ namespace PKHeX.WinForms
|
|||
|
||||
private void B_Spiritomb_Click(object sender, EventArgs e)
|
||||
{
|
||||
var trainers = SAV.UgSaveData.GetTrainers();
|
||||
for (int i = 0; i < 32; i++)
|
||||
trainers[i] = (byte)(i + 1);
|
||||
Unlocker.UnlockSpiritomb();
|
||||
System.Media.SystemSounds.Asterisk.Play();
|
||||
B_Spiritomb.Enabled = false;
|
||||
B_Spiritomb.Enabled = Unlocker.UnlockReadySpiritomb;
|
||||
}
|
||||
|
||||
private void B_Shaymin_Click(object sender, EventArgs e)
|
||||
{
|
||||
SAV.Zukan.HasNationalDex = true; // dex
|
||||
SAV.Work.SetSystemFlag(5, true); // clear
|
||||
SAV.Work.SetWork(276, 1); // haihu
|
||||
SAV.Items.SetItemQuantity(452, 1); // letter
|
||||
SAV.Work.SetFlag(545, false); // clear vanish
|
||||
|
||||
Unlocker.UnlockShaymin();
|
||||
System.Media.SystemSounds.Asterisk.Play();
|
||||
B_Shaymin.Enabled = false;
|
||||
B_Shaymin.Enabled = Unlocker.UnlockReadyShaymin;
|
||||
}
|
||||
|
||||
private void B_Darkrai_Click(object sender, EventArgs e)
|
||||
{
|
||||
SAV.Zukan.HasNationalDex = true; // dex
|
||||
SAV.Work.SetWork(275, 1); // haihu
|
||||
SAV.Items.SetItemQuantity(454, 1); // member
|
||||
SAV.Work.SetFlag(301, false); // clear vanish
|
||||
|
||||
Unlocker.UnlockDarkrai();
|
||||
System.Media.SystemSounds.Asterisk.Play();
|
||||
B_Darkrai.Enabled = false;
|
||||
B_Darkrai.Enabled = Unlocker.UnlockReadyDarkrai;
|
||||
}
|
||||
|
||||
private void B_DialgaPalkia_Click(object sender, EventArgs e)
|
||||
{
|
||||
SAV.Work.SetFlag(308, false); // captured
|
||||
SAV.Work.SetFlag(393, false); // clear vanish
|
||||
SAV.Work.SetFlag(1623, false); // can retry
|
||||
SAV.Work.SetWork(84, 5); // can retry
|
||||
|
||||
Unlocker.UnlockBoxLegend();
|
||||
System.Media.SystemSounds.Asterisk.Play();
|
||||
B_DialgaPalkia.Enabled = false;
|
||||
B_DialgaPalkia.Enabled = Unlocker.UnlockReadyBoxLegend;
|
||||
}
|
||||
|
||||
private void B_Roamer_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Mesprit
|
||||
SAV.Work.SetFlag(249, false); // clear met
|
||||
SAV.Work.SetFlag(420, false); // clear vanish
|
||||
SAV.Encounter.Roamer1Encount = 0; // not actively roaming
|
||||
|
||||
// Cresselia
|
||||
SAV.Work.SetFlag(245, false); // clear met
|
||||
SAV.Work.SetFlag(532, false); // clear vanish
|
||||
SAV.Encounter.Roamer2Encount = 0; // not actively roaming
|
||||
|
||||
Unlocker.RespawnRoamer();
|
||||
System.Media.SystemSounds.Asterisk.Play();
|
||||
B_Roamer.Enabled = false;
|
||||
B_Roamer.Enabled = Unlocker.ResetReadyRoamerMesprit || Unlocker.ResetReadyRoamerCresselia;
|
||||
}
|
||||
|
||||
private void B_DefeatEyecatch_Click(object sender, EventArgs e)
|
||||
|
|
Loading…
Reference in a new issue