
I've been using Roll20 as an excuse to get a little dirty with Javascript, a language that I've used for years but never bothered to master. I've also been GMing some old-school retroclone lately using Basic Fantasy Role-Playing Game. This has resulted in some extremely over-engineered code for handling a bit of the PC creation and game management. Even though this is far from done, and there are some pretty nasty JS faux-pas going on, I figured I'd share it to get feedback or perhaps inspire ideas in others. BFRpg.js is the bulk of the code I'm presenting. Its defines prototypes and helper functions for PCs, StatBlocks, Races and Classes. I've also defined the base races (dwarf, halfling, elf, and human) and classes (fighter, cleric, magic-user, and thief). Helper functions for Race and Class are able to identify legal choices based on StatBlock and (for class) Race. I've also included the concept of concordance , a naive distance measurement from the ideal - basically it attempts to calculate 'how dwarf-ish / elf-ish / fighter-ish etc, is a character's StatBlock). This provides the ability to build random characters that make sense. I've also implemented random name generators, based on race. Each race can define forenames and surnames as nested arrays of name components that will be concatenated at random. Forenames are further broken down into Male and Female. I've begun adding some of the tables for classes but don't do anything with them yet. You'll notice right at the top I muck about with the Function and String
global level prototypes. Don't do that, its bad. I'll fix it at some
point. <a href="https://gist.github.com/goblinHordes/7227708" rel="nofollow">https://gist.github.com/goblinHordes/7227708</a> BFRpg.chargen.js is just an on chat:message wrapper around the BFRpg.PlayerCharacter.random helper function. By issuing a !random_pc command in chat a new character will be spun up. JSON can be passed in that call to set specific features of the randomly generated PC. For instance !random_pc {"sex":"male", "class:dwarf"} would generate a random male dwarf. I've commented out the section that creates a new R20 Character from the PC since its still in debugging stages and its annoying to have to delete all the characters I create. I still need some error handling, you can easily cause an infinite loop by requesting an illegal character build such as a Dwarf Magic-User. <a href="https://gist.github.com/goblinHordes/7228010" rel="nofollow">https://gist.github.com/goblinHordes/7228010</a> I plan on adding Items, Weapons and Armor, as well as inventory management and Macro generation for attacks. I've got some work done on parsing NPC and monster statblocks for easily adding creatures for the PCs to fight as well, along with their macros. Hopefully I'll have more to show in the next few weeks. I still want to get back to my ActiveToken project as well, but I've left that alone since its in a working state. Let me know if you find any of this useful or have constructive criticism of my early JS experiments.