Aurithmetic (the art of computerized aura math)


I have Slow stopping an opposing Caster's Spell from going off, trapping it, and then releasing it. Now that I've done all that hard work for the framework of Spells, it's time to move on to Beasties. How difficult could that be?


Instead of drowning myself in code for another few weeks without any word, I'm going to show you around the code. How exciting!

Today we'll be looking at...


It handles everything to do with storing and operating on Aura values. Simple addition and subtraction to count Aura is pretty intuitive for players. It's not quite so intuitive for a computer though.

There's boilerplate like...


And this happy little helper class to hold a Caster's floating aura:


It's pretty sparse but only because OperationResult and Amount#SubtractedBy do the heavy lifting for us. Let's start with the operation result class.


Now we kick things up a notch to do actual work. Without getting too into the weeds, we have:

  • 3 Amount instances to store important values from an aura math operation
  • Normalize to handle removing aura values that are less than 1
  • SubtractBy to subtract an amount from this result

SubtractBy has some fun math to recalculate the stored values. It shouldn't be too complicated to piece together what's going on. If it is though then assume it works how you think it should :D

So that's all pretty straightforward, right? But you'll notice that we don't actually use OperationResult yet. Wellll


No don't leave! This is as complex as it gets, I promise!

Amount is actually a Dictionary<Aura.Type, int> and SubtractedBy ties everything together. Given two instances of Amount, sets of aura type amounts, we can subtract them and return the results. A simple example of that might look like this:

Aura.Amount amountA = new Aura.Amount() { { Aura.Type.Neutral, 2 } };
Aura.Amount amountB = new Aura.Amount() {
  { Aura.Type.Neutral, 1 },
  { Aura.Type.Dark, 1 }
};
Amount remaining = amountA.SubtractedBy(amountB).remainingAura; // { Aura.Type.Neutral, 1 }

The code isn't particularly sophisticated and I could do a lot better, as the comments suggest. It works great for now though so I'll revisit it when it matters. That's part of the reason I don't use the auto-tapper I wrote, but that's a post for another time.

I hope that you found this peek behind the curtain at least a little interesting. I try to write human-readable code but as the only dev that means me-readable code. I hope that it's you-readable too. You can at least take comfort in the fact that it's a lot less effort to teach you to count Aura than it was to teach a computer.

Leave a comment

Log in with itch.io to leave a comment.