Move mail get to sav obj

This commit is contained in:
Kurt 2021-05-22 09:28:04 -07:00
parent 96115916b2
commit 15afd6f3bc
4 changed files with 28 additions and 19 deletions

View file

@ -562,6 +562,13 @@ namespace PKHeX.Core
protected abstract int MailOffset { get; } protected abstract int MailOffset { get; }
public int GetMailOffset(int index) => (index * Mail3.SIZE) + MailOffset; public int GetMailOffset(int index) => (index * Mail3.SIZE) + MailOffset;
public Mail GetMail(int i)
{
var ofs = GetMailOffset(i);
var data = Large.Slice(ofs, Mail3.SIZE);
return new Mail3(data, ofs, Japanese);
}
public abstract string EBerryName { get; } public abstract string EBerryName { get; }
public abstract bool IsEBerryEngima { get; } public abstract bool IsEBerryEngima { get; }
public abstract MysteryEvent3 MysteryEvent { get; set; } public abstract MysteryEvent3 MysteryEvent { get; set; }

View file

@ -544,5 +544,11 @@ namespace PKHeX.Core
} }
public byte[] GetMailData(int ofs) => General.Slice(ofs, Mail4.SIZE); public byte[] GetMailData(int ofs) => General.Slice(ofs, Mail4.SIZE);
public Mail4 GetMail(int i)
{
int ofs = GetMailOffset(i);
return new Mail4(GetMailData(ofs), ofs);
}
} }
} }

View file

@ -207,5 +207,12 @@ namespace PKHeX.Core
public static int GetMailOffset(int index) => (index * Mail5.SIZE) + 0x1DD00; public static int GetMailOffset(int index) => (index * Mail5.SIZE) + 0x1DD00;
public byte[] GetMailData(int offset) => GetData(offset, Mail5.SIZE); public byte[] GetMailData(int offset) => GetData(offset, Mail5.SIZE);
public int GetBattleBoxSlot(int slot) => BattleBoxOffset + (slot * SIZE_STORED); public int GetBattleBoxSlot(int slot) => BattleBoxOffset + (slot * SIZE_STORED);
public Mail GetMail(int i)
{
int ofs = GetMailOffset(i);
var data = GetMailData(ofs);
return new Mail5(data, ofs);
}
} }
} }

View file

@ -68,13 +68,9 @@ namespace PKHeX.WinForms
case SAV3 sav3: case SAV3 sav3:
m = new Mail3[6 + 10]; m = new Mail3[6 + 10];
for (int i = 0; i < m.Length; i++) for (int i = 0; i < m.Length; i++)
{ m[i] = sav3.GetMail(i);
var ofs = sav3.GetMailOffset(i);
var data = sav3.Large.Slice(ofs, Mail3.SIZE);
m[i] = new Mail3(data, ofs, sav3.Japanese);
}
MailItemID = Enumerable.Range(0x79, 12).ToArray(); MailItemID = new[] {121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132};
PartyBoxCount = 6; PartyBoxCount = 6;
break; break;
case SAV4 sav4: case SAV4 sav4:
@ -82,14 +78,11 @@ namespace PKHeX.WinForms
for (int i = 0; i < p.Count; i++) for (int i = 0; i < p.Count; i++)
m[i] = new Mail4(((PK4)p[i]).GetHeldMailData()); m[i] = new Mail4(((PK4)p[i]).GetHeldMailData());
for (int i = p.Count, j = 0; i < m.Length; i++, j++) for (int i = p.Count, j = 0; i < m.Length; i++, j++)
{ m[i] = sav4.GetMail(j);
int ofs = sav4.GetMailOffset(j); var l4 = (Mail4)m[^1];
m[i] = new Mail4(sav4.GetMailData(ofs), ofs);
}
var l4 = (Mail4)m.Last();
ResetVer = l4.AuthorVersion; ResetVer = l4.AuthorVersion;
ResetLang = l4.AuthorLanguage; ResetLang = l4.AuthorLanguage;
MailItemID = Enumerable.Range(0x89, 12).ToArray(); MailItemID = new[] {137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148};
PartyBoxCount = p.Count; PartyBoxCount = p.Count;
break; break;
case SAV5 sav5: case SAV5 sav5:
@ -97,15 +90,11 @@ namespace PKHeX.WinForms
for (int i = 0; i < p.Count; i++) for (int i = 0; i < p.Count; i++)
m[i] = new Mail5(((PK5)p[i]).GetHeldMailData()); m[i] = new Mail5(((PK5)p[i]).GetHeldMailData());
for (int i = p.Count, j = 0; i < m.Length; i++, j++) for (int i = p.Count, j = 0; i < m.Length; i++, j++)
{ m[i] = sav5.GetMail(j);
int ofs = SAV5.GetMailOffset(j); var l5 = (Mail5)m[^1];
var data = sav5.GetMailData(ofs);
m[i] = new Mail5(data, ofs);
}
var l5 = (Mail5)m.Last();
ResetVer = l5.AuthorVersion; ResetVer = l5.AuthorVersion;
ResetLang = l5.AuthorLanguage; ResetLang = l5.AuthorLanguage;
MailItemID = Enumerable.Range(0x89, 12).ToArray(); MailItemID = new[] {137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148};
PartyBoxCount = p.Count; PartyBoxCount = p.Count;
break; break;
} }