Story Time: Damage Calcs (09-2024 W2)


A while back, I took a course on making a JRPG batsys. Even by the end, it only scratched the surface of what such a system should be. It was a bit… basic, albeit a good starting point. Thus, I still had a lot of work to do when making Trigram Islands’ battle system ^^; One big part of it: the damage-calcs. What the course taught was this: just reducing the HP of the target by the attack power of the skill they were hit with. Felt it’d be better to go with something like what RPG Maker has. Speaking of, here’s an example of a formula in RM:


a.atk – (b.def / 2)


With a.atk being the user’s Attack stat and b.def being the target’s Defense stat. You can work with other params too. For example…


  • a.agi = attacker’s speed
  • b.mhp = target’s max hp


You can see how this makes things nice and customizable. That was what I wanted to replicate. Handling stuff like a.atk was easy. What wasn’t… was the other stuff. Parentheses, plus-signs and so on. Thankfully, there’s a third-party library to handle it: MathEval. It had a nice interface that cut out the need for my code to do the string-substitutions too, which is nice. The fun didn’t end there, though! XD I implemented a couple things RM didn’t have. For example, shorthands like these:


  • “userAvgAttack” for the average between the user’s Phys and Mag Atk
  • “targAvgDef” for the average between the target’s Phys and Mag Def
  • “userGreaterAtk” for the greater between the user’s Phys and Mag Atk


You can get the same results with RM, but you’d have to do a lot more typing. Compare “(a.atk + a.matk) / 2” to simply “userAvgAtk”. That’s a 10-keystroke difference! Maybe I should make a plugin for RM sometime that gives it the same convenience… All that said, I can’t blame the aforementioned course for what it didn’t do. After all, with how complex it is to code the average JRPG batsys from the ground up, it’d warrant multiple courses. And overall… I’m happy with the results I got ^^ Definitely gonna reuse my damage-calc code in another project.

Get Trigram Islands

Leave a comment

Log in with itch.io to leave a comment.