DEV Community

Cover image for Random Generators to Make DMing Easier
Dominic Barajas
Dominic Barajas

Posted on

Random Generators to Make DMing Easier

Recently, I have been focused on making my dungeon mastering easier. In the course of searching for my first Software Engineering position, I do not have the time to prepare as much as I used to. Or account for every possible path my Adventuring group might take.

It was here that I applied my new skills and passion for software development. To make the job easier for me, I am developing some generators that will make my life easier. As well as expanding my knowledge and keeping up with my coding skills.

In a pinch, I'm great at coming up with non-player characters or towns or cities. However, remembering the stats and what I said for my notes late on are the trickiest parts.

So I've planned three applications to take some stress off of me while I play with my friends. It's my hope to host them on Herouku once I have them ready to go to production so that a lot of people can use them.

The goal of today's chat is to talk about the first of the three and maybe hint at the other two. The first one I'm working on is a fully developed version of the NPC generator I created for school. All my frontend work is done with React, and my NPC data is stored in Rails.

Dungeons and Dragons is a complex game where everything builds on top of itself. An elf, for example, receives specific stats and bonuses. These will affect everything they do, from their armor classes to the amount of damage they do. To get started, all I needed was a random name, race, a few stats, and a background. Verifying that RandomNPC does not fail and that everything is logged into the backend. By trial and error, I was able to develop a basic NPC.

To start out I created my constructor to store the state of the NPC

constructor(props) {
        super(props)
        this.handleClick = this.handleClick.bind(this)
        this.state = {
            firstName: "",
            lastName: "",
            title: "",
            race: "",
            sex: "",
            alignment: "",
            health: "",
            armor: "",
            melee: "",
            ranged: "",
            str: "",
            dex: "",
            con: "",
            int: "",
            wis: "",
            cha: "",
            npcClass: "",
            trait: "",
            background: ""
        }
    }
Enter fullscreen mode Exit fullscreen mode

From there came the trick part of making sure my code executed in the correct order to build a non-rule breaking character that made sense. I created containers to store all the arrays of data for each stat and description. Referencing them in my npcRandom.js class component that built the character from the click event of the simple one button press handy dandy generator.

I went through trial and error React being my most recent and less knowledgable framework when I finally got to presenting my data I was met with loads of

Undefined
Enter fullscreen mode Exit fullscreen mode

And errors of mismatched types and things of that nature. For determining which data was being passed through state and how it was being accessed, I relied heavily on my console.log. It was pretty simple to display things like names, classes, races, and traits. They are just strings I had to fetch from the NPC after it was instantiated. It was when I had to handle things like their armor or health. The method of presenting the data required me to go back and search my knowledge. I saved my armor as

“Padded 11”
Enter fullscreen mode Exit fullscreen mode

Which was a string but i needed to split the 11 from the padded show that they had padded armor and parse the 11 into a number because that was then added to the dex an NPC had. And the dex was an integer. Nothing too difficult in hindsight. Just took some tinkering to get it to present correctly. And low and behold created a nice little bit of presentational code I could use later for other things like melee weapons or for when I work on my second planned application.

<span>
          {npc.armor.split(" ").slice(0, 1) +
            " " +
            "AC:" +
            " " +
            (parseInt(npc.armor.split(" ").slice(1)) + npc.dex)}
        </span>

Enter fullscreen mode Exit fullscreen mode

The NPC Generator 2.0 is still under construction. I am updating my data tables and almost ready to add a separate table to store feats, spells, and classes to add more robust functionality. Once I have integrated those new kernels. Undoubtedly, I'll face a slew of new obstacles, and I'm excited to handle each one in turn. After that, I think I'll begin project number two. The Enubs guide to city and town planning. My plan is to take what I've learned from this and create a generator for quickly building fully fleshed-out villages, towns, and cities. As far as I know there is nothing like this out there, and for my sake I find it lacking in my gameplay.

Till next time my friends
Don't stop coding

Discussion (0)