a primitive design for determining attack success.
it’s a numbers game.
The tabletop RPG space has matured a great deal since I first played Advanced Dungeons & Dragons in the 1980’s, and a substantial body of theory content has been produced over the years. I am hardly an expert in the field, and I haven’t played a tabletop game in over a decade. I hope my more sophisticated readers will forgive me if I have come up with something rudimentary or dull!
At its most basic level, two combatants will roll a ten-sided die (ie, randomly generate a number between one and ten). The system will then add modifiers based on character traits or weapons to each roll, and the highest of the two numbers will succeed. If the attacker rolls high, the attack will hit. If the defender wins the roll, the attack will miss. Let’s start with only a small number of modifiers:
Attacker: character accuracy statistic and, if applicable, weapon accuracy.
Defender: speed statistic.
How would we go about producing these numbers? We could dash something together quickly:
a weapon is a kind of thing.
a person has a weapon called the equipped weapon.
a shotgun is a weapon.
attacker is a person that varies.
defender is a person that varies.
to decide what number is the attack roll:
let A be the accuracy of the attacker;
let W be the accuracy of the equipped weapon of the attacker;
let R be a random number from 1 to 10;
decide on (R + A + W);
This is fine, so far as an initial idea goes, but I don’t think it’s the right approach. If the idea is to make a large, complex game that can handle all sorts of different combat conditions, we do not want to limit ourselves to a single phrase deciding a number. What if we need to add more scenarios, such as rolls involving special bonuses or unique weapon considerations? In the long run, we will likely prefer something more modular, like a rulebook producing a number.
It isn’t hard to start.
to-hit is a rulebook producing a number.
We can transpose our definition, then use a rule to subtract the defender’s roll from the attacker’s roll. If the result is a positive number, we can consider the attack successful. This can be the default rule, but we are free to add more as new situations develop.
a to-hit rule (this is the standard to-hit rule):
let A be the accuracy of the attacker;
let W be the accuracy of the equipped weapon of the attacker;
let R be a random number from 1 to 10;
let attack roll be (R + A + W);
let S be the speed of the defender;
let R2 be a random number from 1 to 10;
let defense roll be (R2 + S);
rule succeeds with result (attack roll - defense roll);
In a very simple implementation, we might use a check rule to handle missed attacks. Let’s whip up a new action, then do something with it.
attacking it with is an action applying to two things.
check an actor attacking something with something:
if the number produced by the to-hit rules is less than one:
say "[if the actor is the player]Your[otherwise][The actor]'s[end if] attack misses!" instead;
Something’s missing (heh), though, isn’t it? I haven’t added command grammar for the attacking it with action. That’s because Inform includes a dizzying variety of synonyms for the attacking action’s attack command, each of which stands in our way. Let’s clear a path before moving forward.
repurposing in-use commands.
Inform has a built-in attacking action already. It only supports one noun, so it doesn’t allow for attacking something with something. We’ll need to start by disabling the many commands Inform has associated with this action. There are a lot of them.
understand the command "attack" as something new.
understand the command "kill" as something new.
understand the command "break" as something new.
understand the command "smash" as something new.
understand the command "torture" as something new.
understand the command "wreck" as something new.
understand the command "crack" as something new.
understand the command "murder" as something new.
understand the command "punch" as something new.
understand the command "thump" as something new.
understand the command "hit" as something new.
understand the command "fight" as something new.
understand the command "torture" as something new.
understand the command "destroy" as something new.
As a matter of preference, I will not be adding all of these commands back in. In fact, I think this will do for now.
understand "attack [something] with [something preferably held]" as attacking it with.
As a convenience, let’s go a step further. Since the player has an equipped weapon, we probably shouldn’t force the player to type the weapon name every time. I’ll add a second action that only specifies a target.
vaguely attacking is an action applying to one thing.
understand "attack [something]" as vaguely attacking.
Since this is a combat focused game that won’t involve a large variety of actions involving enemies, I’m going to do something a little unusual next. This can cause problems if the situation isn’t completely right for it, so use caution with this tactic (the limitations are discussed here). With this grammar, a player typing an enemy’s name will perform a vaguely attacking action:
understand "[enemy]" as vaguely attacking.
Our work isn’t done, though. We need to turn vaguely attacking into something with a specified weapon. Since a person has an equipped weapon, we can tap into that. Be sure everyone starts with an equipped weapon specified!
first before vaguely attacking:
try attacking the noun with the equipped weapon of the actor instead;
There. Down the line, we’ll almost certainly want to add checks (is the second noun a weapon? is the noun an enemy? and so forth), but this is enough for now.
some output.
With that sorted, let’s add a very rudimentary carry out action.
carry out an actor attacking something with something:
say "[if the actor is the player]Your attack strikes [the noun][otherwise][The actor] strikes you[end if]!";
…and an every turn attack by any enemies present:
every turn when an enemy is in the location:
repeat with E running through enemies in the location:
try E attacking the player with the equipped weapon of E;
The results are not terribly exciting yet:
>gurgler
Your attack strikes gurgler!
Gurgler’s attack misses!
>g
Your attack strikes gurgler!
Gurgler’s attack misses!
>g
Your attack misses!
Gurgler strikes you!
This is just a beginning, of course. We have no damage delivery method yet, and allowing the player to attack first every time will likely rob encounters of suspense. We will have to come up with something better there!
next.
who gets to attack first?

Leave a comment