Up till now, it's saved character inventories based upon character position within the saved character info array as it existed on first loading up the battle.
dude really? how did you manage to get rpg and arena relatively bug free?
okay, first of all, people do instinctively learn orders, positions, relations and all kinds of patterns. Letting the framework decide how to order the characters basically fucks up people's mind. NEVER do that nor let that happen. You can let the gamer decide how to order the game items, but you are never allowed to mess up with the order of skills or any controls (like the hover thing).
if you want to finally get rid of this random swapping bug, you will have to restart with an adequate design.
Use defines or constants (or what ever this adobe thingy got) to assign unique ids to all characters. Implement the character list in a way that all characters have one definite position and NEVER change it. Like really NEVER. Use black squares or red crosses or what ever to mark the dead characters or the ones that are already on the field. But do not mix the order in any arrays or lists.
Use single ton pattern to assign unique ids to all items. If you don't know how to implement the single ton, run throw all items and find unused id to be assigned to new item. Do not store in the item itself whether it is equipped or not and who carries it. Rather add two array to all characters, store in one of these the equipped items and in another array the rest of items. Each time the user equips/unequips/drops/whatever the item run throw both array, do what ever is necessary to ensure consistency and redraw the item window.
Do not rely on the framework. All frameworks have bugs and you don't have time to find these bugs and work arounds. Assume the framework tries to trick you and build in means to get everything right.
Store into the save file the id of a character together with its data. When you load the file identify the character depending on the id, not on the position. Assign then a designated position in the array of characters to the loaded one.
As for the items, store the id of the character, who carries it, together with the item. Once the item is loaded, use the character's id to decide where to put the item, do NOT use any array indices.
Do not add the bonuses or debuffs to the current health variable or current resist. There are a lot of other minor bugs coming from this mistake, e.g. bonus hp from static shield goes lost, if you unequip a shield or an orb.
You need to implement this stuff functionally (instead of imperatively). Write a function that runs through all items and sums up all bonuses and debuffs, but do not store the value. Call this method each time you need to draw the hp bar or calculate the current hp for some actions, but do not store the calculated result. You will have to call this function each time you need the value.
Make it easy for yourself and implement all buffs and debuffs like these are items, items that cannot be traded and that do expire. In the class of a character add an additional array for these buff-items and debuff-items. Do NOT ever store any sums or current values. Implement a function for each property (like hp or resist) that always runs over all constants and items and calculates the current value or the sum, but never store it!
And stop using byte data types or anything below int. WTF you are trying to create? A game that would fit on a 3.5" disk?
Let's say you got 100 units on the field, everyone carries 10 items and has 10 buffs and debuffs. That makes no more than 3000 entities. Even if you have 10 properties, you would quasi-save 90000 bytes by using byte instead of int. WTF dude?? 100 KB is not worth the headache. Use int for all game object properties! And since you keep mixing singed and unsigned types, use always signed. Your values are not gonna get that high to blow up an int.
This might sound rough, but when did you release the game? Like two months ago? And you still have a project stopper in the product. Forget all the minor bugs, which you can fix in 5 minutes. It does no matter whether you got 100 minor bugs or not, but it does matter if you have 1 project stopper. Ignore all the other stuff until you sort out this item mess.