1
Scripting and Reverse Engineering / Item Sorting II (Final Fantasy VII)
« on: 2021-03-03 02:50:03 »
Hey,
I didn't want to necro this post: https://forums.qhimm.com/index.php?topic=16079.msg226836#msg226836 so thought I'd make a new one.
I hope anyone can help me understand specifically what NFITC1 means about the bubble sort and field / battle condition.
If I do the bubble sort based on the field condition, I do not get the same results as the game.
Can someone please explain how NFITC1's answer would function? Do I check the condition once then BS from there or am i missing something?
Here's my code;
Cheers
I didn't want to necro this post: https://forums.qhimm.com/index.php?topic=16079.msg226836#msg226836 so thought I'd make a new one.
I hope anyone can help me understand specifically what NFITC1 means about the bubble sort and field / battle condition.
If I do the bubble sort based on the field condition, I do not get the same results as the game.
Can someone please explain how NFITC1's answer would function? Do I check the condition once then BS from there or am i missing something?
Here's my code;
Code: [Select]
for (var i = player.inventory.items.Length; i > 0; i--)
{
for (var j = player.inventory.items.Length - 1; j >= 0; j--)
{
if (j != 0)
{
var i1 = player.inventory.items[j];
var i2 = player.inventory.items[j - 1];
var swapID = ShouldSwap(i1, i2);
if (swapID == 1)
{
player.inventory.items[j] = i2;
player.inventory.items[j - 1] = i1;
}
}
}
}
private static int ShouldSwap(
Player.PlayerInventory.InventoryItem item1,
Player.PlayerInventory.InventoryItem item2)
{
if (item1.sortTag.Contains(SortingTag.Field))
{
return item2.sortTag.Contains(SortingTag.Field) ?0 : 1;
}
else
{
return item2.sortTag.Contains(SortingTag.Field) ?-1 : 0;
}
}
Cheers