Core/Spells: move spell resistance calculation into separate function (and some cosmetic changes)

Ref #7254