The description of Thornmail says "On being hit by basic attacks, returns 30% of damage taken as magic damage." I'd like to know how the defender's armor and the attacker's magic resist affect that number. For extra credit, do the defender's magic pen or attacker's armor pen factor in as well?
Damage | DefArmor | AttMagRes | DefMagPen | AttArmPen | ThornmailDamage
-------|----------|-----------|-----------|-----------|----------------
400 | 0 | 0 | 0 | 0 | 120¹
400 | 100 | 0 | 0 | 0 | 120? 60?
400 | 0 | 100 | 0 | 0 | 120? 60?²
400 | 100 | 100 | 0 | 0 | 120? 60? 30?
400 | 100 | 100 | 50 | 0 | ?????
400 | 100 | 100 | 0 | 50 | ?????
400 | 100 | 100 | 50 | 50 | ?????
¹ I know this example is dumb, since Thornmail grants +100 armor. But it's a simple base case
² Again, 0 armor is nonsensical. But I wanted to isolate the attacker's MR
EDIT:
I understand how armor (and MR) affect damage: (effectiveDamage = rawDamage * (100/(100+armor)). This question is not about how to make each calculation; it's about the order in which the calculations are derived. For example, I know that 400 raw damage on 100 armor gives 200 effective damage. I also know that 400 raw damage with 50 armor pen on 100 armor gives 300 penetrated damage. But which value does thornmail use? Is it .3 * effective or .3 * raw or .3 * penetrated? And from that point, does the attacker's magic resistance reduce incoming thornmail damage? If so, does the defender's magic pen reduce the attacker's MR?