On multiple occasions I have experienced different behaviour than what is described in the calculations section so I looked at the code. According to the ApplyDamage function in inventory.lua, equipslots are iterated with 'pairs' which is just a wrapper for 'next'. The order next returns key - value pairs in is non-deterministic, so there should be no way to tell what armor piece takes damage first. Can anybody chime in on this?
Possible Answer to Armor Calculation (Warning: Reading this may make your brain explode!)Edit
Equipslots in inventory is just a list, which is retrieved as name=value pairs. It's looped in order, meaning that the armor is checked (and damage calculated) one armor at a time, from start of the list/array to the end.
The question is, what order is the list? Since an item is placed into the list similar to an array, I would guess it's:
- if no slots equipped yet, item is equipped at position 1.
- if position one is taken, and this is a different equipment slot, then next free position (position 2).
- if the slot already had something in it previously, then that slot is replaced by this one.
So given the above, if you start with nothing and add a log suit, that's now position 1. If you then add a football helmet, that's position 2. So in this case, log suit takes full damage, football helmet takes leftovers.
If you then replace the log suit with a marble suit (right-clicking on the marble suit), it will replace the log-suit AT POSITION 1. So the marble suit will still take full damage (although it was technically added AFTER the football helment), and football helmet takes the rest.
Now, if INSTEAD of the above, you again start with a log suit and football helmet equipped in order as described two paragraphs above, but you REMOVE the log suit (drop it on the ground, put it in inventory, etc.) so that there's no armor in the body slot, then add the marble suit AFTER that, things change. In this case, since the body slot was removed, the football helmet is now in slot one (the armor slot is "deleted" from the active items for the time being) when the armor is removed. When the marble suit is added, a new entry is created in that list, but since there is already an entry (the football helmet), it's added AFTER the football helmet. So this means that in this case, the football helmet takes the initial attack, and the leftovers then go to the marble suit.
Whew. That probably looks confusing as all hell, but it's the best way I could think of to explain this. Maybe I need to add a graphic or something.
Personally I reckon the devs could have avoided this kind of (IMO stupid) issue by always having these slots in the same place, so that way body armor would always be hit before helmet armor, for example. But no, they didn't, so we end up with this inconsisent seemingly random behaviour. The perils of a weakly typed language like lua...
220.127.116.11 18:47, August 21, 2013 (UTC)TheSquid