Dungeoneer: added math logic from Knockout.js