As I stated in my first post, the first part of my game I decided to work on was recruiting random characters (called “Adventurers” in my game) and displaying them to the player because I thought it would be easy. In some ways, I was right since this is mostly a coding challenge rather than a game engine specific challenge and I’m already pretty good at coding.
Pathfinder 2E Characters
For those not familiar with PF2E, here’s a quick summary of what stats a character has and how they’re built.
There are 6 Abilities:
- Strength (STR)
- Dexterity (DEX)
- Constitution (CON)
- Intelligence (INT)
- Wisdom (WIS)
- Charisma (CHA)
These abilities govern a variety of skills, saves, and class abilities. Your ability score is added to almost everything you do. I’ll go into detail about this another time. The important thing here is that you want a high score in your class’s Key Ability as that’s the ability that most of your class features will use to determine success. At character creation, you can get a maximum score of 4 in any ability.
When you generate a character you:
- Pick an Ancestry (e.g. human, goblin, elf, dwarf) – this provides boosts (+1) and flaws (-1) to certain abilities
- Pick a Background (e.g. barkeeper, soldier, gambler) – this also provides boosts to certain abilities, and training in some skills
- Pick a Class (e.g. Alchemist, Fighter, Wizard) – from this, you get a boost to the Key Ability, training in some skills, and will ultimately determine how your character engages in combat
- Finally, you get four free boosts that you can allocate any ability (but only one boost per ability, no doubling up)
So, the rules I need to follow are:
- Pick Ancestry, Background, Class and apply all the boosts and skills training
- Apply the free boosts at the end
- Make sure the class’s Key Ability is at least 3, although it should ideally be 4
- Pick a name from the character’s ancestry
Generating Adventurers
Adventurer Options
Let’s take a look at the Ancestry choices. I’ve limited it to just the common ones for the first version of my game. There’s 8 there already and they all get a whole plethora of unique feats and things that I’ll have to code later, so starting with just a few seems sensible.
Ancestry | Ability Boost | Ability Flaw |
Dwarf | CON, WIS, Free | CHA |
Elf | DEX, INT, Free | CON |
Gnome | CON, CHA, Free | STR |
Goblin | DEX, CHA, Free | WIS |
Halfling | DEX, WIS, Free | STR |
Human | Free, Free | – |
Leshy | CON, WIS, Free | INT |
Orc | Free, Free | – |
That’s not too bad. “Free” here just means that you normally choose where the boost goes with the only caveat being that you can’t apply two boosts to the same Ability in this step. So a Dwarf can’t use their Free boost on CON or WIS. This is fine, code-wise – we’ll just apply it randomly.
There are an awful lot of backgrounds with a wide variety of boost combinations. Usually you get one boost that can go in one of two abilities and one free one.
And now onto the classes I’ve chosen – I’ve grabbed the remastered ones from the first Player Core for now. I’d like to add all the classes eventually, but there’s a lot and coding just these first 8 will almost certainly be a massive challenge by itself. The classes we have are:
Class | Key Ability |
Bard | Charisma |
Cleric | Wisdom |
Druid | Wisdom |
Fighter | Strength OR Dexterity |
Ranger | Strength OR Dexterity |
Rogue | Dexterity OR other!? |
Witch | Intelligence |
Wizard | Intelligence |
I’m already seeing a complication with this – some classes can choose a Key Ability. I’m going to ignore Rogue’s “other” Key Ability for now since that’s related to sub-classes and that’s not essential for my first pass at a random character generator.
The Algorithm
With all this in mind, I began writing code. I’m not going to just copy-paste that here since it’s not exactly easy reading, but here’s how it works:
- Choose an Ancestry completely at random. Apply the Boosts and Flaws. Free Boosts are applied randomly
- Search for a Background where at least one of the Boosts matches the Ancestry Boosts (except for CON, since there are no classes where CON is the key ability). Apply the Boosts
- Check which of the Adventurer’s Abilities is 2 and find a Class where one of the Key Ability options matches that Adventurer Ability. Set the Adventurer’s Key Ability to that one and apply the Boost there.
- Apply one boost to the Adventurer’s Key Ability. Choose at random for the other three.
An Example
We roll Goblin as our Ancestry. Boosts are applied to DEX and CHA. Flaw is applied to WIS. The Free Boost is chosen to be INT.
- Ancestry: Goblin
- Background: ???
- Class: ???
- Abilities:
- STR: 0
- DEX: 1
- CON: 0
- INT: 1
- WIS: -1
- CHA: 1
The Backgrounds are filtered down to those which have at least one of DEX, INT, or CHA as a boost. Some examples are Hunter (DEX, WIS), Merchant (INT, CHA), Tinker (DEX, INT). From these, Tinker is chosen at random, and we apply the two Boosts to DEX and INT.
- Ancestry: Goblin
- Background: Tinker
- Class: ???
- Abilities:
- STR: 0
- DEX: 2
- CON: 0
- INT: 2
- WIS: -1
- CHA: 1
Now the Class is chosen. The candidates are: Fighter (STR/DEX), Ranger (STR/DEX), Rogue (DEX), Witch (INT), Wizard (INT). At random, we get Ranger. Since Ranger can have STR or DEX as the Key Ability, we check to see which one matches – in this case DEX – and apply that Boost and set DEX as the Key Ability.
- Ancestry: Goblin
- Background: Tinker
- Class: Ranger
- Abilities:
- STR: 0
- DEX: 3*
- CON: 0
- INT: 2
- WIS: -1
- CHA: 1
Finally, the four Free Boosts are applied. One goes to the Key Ability (DEX). The others are randomly assigned to STR, WIS, and CHA. So the final character is:
- Ancestry: Goblin
- Background: Tinker
- Class: Ranger
- Abilities:
- STR: 1
- DEX: 4*
- CON: 0
- INT: 2
- WIS: 0
- CHA: 2
Maybe not the best ranger, strictly speaking, but still viable. I’d probably give them a bow and stick them at the back!
Closing Thoughts
Now, anyone who’s played PF2E will be able to point out that my adventurer generation algorithm does not produce particularly optimised characters, and that is a very valid criticism. But I actually see this as a good thing.
Hear me out.
Part of the fun of XCOM, for me, is having characters who don’t necessarily have perfect stats. You often have to make do with some less-than-ideal soldiers – certainly at the start of the game – and I find it interesting that it forces me to choose perks that fit the soldier rather than just making the exact same choices each time.
Later, you get access to a training facility that lets you choose the soldier’s class, and I do intend to put in something similar in my game so you can retrain classes, or make some changes to boosts.
If it turns out that this isn’t fun or interesting, I’ll change it later. For now, I’m happy with this choice.