Home Artists Posts Import Register

Content

I just thought maybe this would be interesting to see. This is the spell "cleave" which is a black magic spell that consumes the wound stacks on the target for a damage boost. This is actually one of the simpler spells in the game; most have several dozen lines of code in their onCast or onHit handlers.

Files

Comments

DarkPhoenix

I'm kind of surprised there aren't any enums/constants for some of this, but otherwise looks like standard Javascript. Or are you using Typescript?

outsiderartisan

This is just ordinary JS. Enums aren't natively supported in JS, but I do make sure stuff is within the relevant range of possible values when appropriate, usually just with an array. When this data gets fed to the Spell constructor, for example, the damage "type" will get checked against an array of possible damage types. As far as constants, there is a default Spell that fills in undefined properties, but I just fill out most of the data anyway. Like, "healing," "cooldown," and "onCast" could be omitted here. There are still some magic numbers I should maybe clean up into constants, like the 0.03 damage multiplier per stack, but I think of it like this: where am I gonna set all these tiny little per-spell modifiers where they'd be *that* much easier to access and understand than in the spell's definition? That's just the conclusion I came to, that it was better to keep them here. I may move them just to the top of the file if I find myself playing with the values in patches, but I don't plan to move them too far. I think if the spells were less bespoke it'd make more sense to clean those up now, but as things are, I think it's fine.

DarkPhoenix

Well, Javascript does have enums, but only if you use Babel and Flow, which isn't likely in a Twine project. I was trained as an object-oriented programmer, and I still tend to think in objects first.

Derpy

Crazy how you code so much things and all we do is press a button and boom. Fucking someone