Misc updates

condense some logic
This commit is contained in:
Kurt
2019-01-11 17:44:51 -08:00
parent ec76bd6b03
commit c591d2a69d
4 changed files with 17 additions and 28 deletions

View File

@@ -94,8 +94,8 @@ private void VerifyG1TradeEvo(LegalityAnalysis data)
if (!mustevolve)
return;
// Pokemon have been traded but it is not evolved, trade evos are sequential dex numbers
var unevolved = LegalityAnalysis.SpeciesStrings[pkm.Species];
var evolved = LegalityAnalysis.SpeciesStrings[pkm.Species + 1];
var unevolved = LegalityAnalysis.SpeciesStrings[pkm.Species];
data.AddLine(GetInvalid(string.Format(LEvoTradeReqOutsider, unevolved, evolved)));
}
}

View File

@@ -380,26 +380,13 @@ public override InventoryPouch[] Inventory
new InventoryPouchGB(InventoryType.PCItems, legalItems, 99, Offsets.PCItems, 50)
};
foreach (var p in pouch)
{
p.GetPouch(Data);
}
return pouch;
}
set
{
foreach (var p in value)
{
int ofs = 0;
for (int i = 0; i < p.Count; i++)
{
while (p.Items[ofs].Count == 0)
ofs++;
p.Items[i] = p.Items[ofs++];
}
while (ofs < p.Items.Length)
p.Items[ofs++] = new InventoryItem();
p.SetPouch(Data);
}
}
}

View File

@@ -98,7 +98,6 @@ public SAV2(byte[] data = null, GameVersion versionOverride = GameVersion.Any)
pkDat.CopyTo(Data, dest);
}
// Daycare currently undocumented for all Gen II games.
if (Offsets.Daycare >= 0)
{
int offset = Offsets.Daycare;
@@ -437,26 +436,13 @@ public override InventoryPouch[] Inventory
new InventoryPouchGB(InventoryType.PCItems, LegalItems.Concat(LegalKeyItems).Concat(LegalBalls).Concat(LegalTMHMs).ToArray(), 99, Offsets.PouchPC, 50)
};
foreach (var p in pouch)
{
p.GetPouch(Data);
}
return pouch;
}
set
{
foreach (var p in value)
{
int ofs = 0;
for (int i = 0; i < p.Count; i++)
{
while (p.Items[ofs].Count == 0)
ofs++;
p.Items[i] = p.Items[ofs++];
}
while (ofs < p.Items.Length)
p.Items[ofs++] = new InventoryItem();
p.SetPouch(Data);
}
}
}

View File

@@ -77,6 +77,9 @@ public override void SetPouch(byte[] Data)
{
if (Items.Length != PouchDataSize)
throw new ArgumentException("Item array length does not match original pouch size.");
SlideItemsDown();
switch (Type)
{
case InventoryType.TMHMs:
@@ -107,5 +110,18 @@ public override void SetPouch(byte[] Data)
break;
}
}
private void SlideItemsDown()
{
int ofs = 0;
for (int i = 0; i < Count; i++)
{
while (Items[ofs].Count == 0)
ofs++;
Items[i] = Items[ofs++];
}
while (ofs < Items.Length)
Items[ofs++] = new InventoryItem();
}
}
}