Hello, I'm trying to set up a damage formula for my project and having trouble (0 experience with this sort of thing).
What I'm trying to do is have attack - defense and magic attack - magic defence calculated seperately within the same attack, for example, if the target has 1000 defense and 700 m.defense, and I attack with a weapon that has 500 atk, and 1000 m.atk, I'd want it to deal 300 damage.
The closest I've got trying to come up with it myself was :
(a.atk - b.def) + (a.mat - b.mdf) * 1
but this ended up, as far as I can tell, getting -500 from the first set of brackets, which... doesn't really work well.
I'm sure there's probably a stupidly easy answer here that I'm missing. :kaosigh:
So, if you want Atk, Mat, Def, and MDf to all contribute to the same formula, the results of the individual brackets aren't actually going to matter if the numbers don't change. You could easily do (Atk+Mat) - (Def+Mdf) and still get the same result, assuming that the numbers being added and subtracted are always the same.
From what I understand based on the example you gave though, it sounds like you want to pull the highest number out from the two possible damage calculations, considering the Mat-Mdf example only used the result of 1000 Mat vs. 700 Mdf divorced from the physical stats. This is fortunately very easy!
If that's what you're going for, you'll want to use Math.max. Specifically for your example:
Math.max(a.atk - b.def, a.mat - b.mdf);
What this formula will do is select which item in the array (separated by commas) will yield the highest result, and select that number. So, if your Atk is lower than the target's Def and would deal no damage, but your Mat is higher than the target's Mdf, only the magic stats will apply in this calculation.
If for whatever reason that's not what you're going for, I think you might need to be a bit more specific, since I can't think of any way to add 500+1000 minus 1000+700 and pull any positive number.