Whats This About?Having funRPGs are funPerl is funHow can we use one to make the othermore fun?
RPGsI like tabletop RPGs and will play mostsystemsHowever, running combats takes toomuch time and effortI want to pay attention to my players,not logistics
PerlPerl is really, really good at automatingthingsRPG combats are simple and defined bydeterministic statesDont we have something to handledeterministic states?
FSAFinite State AutomatonHuh?An FSA is a set of rules defining eachstate and how to move to other states
FSAs, ContdAn FSA models a system that movesfrom one state to the next by a specific,limited set of rulesGiven an initial state and some data,you can tell which state youll end up in... and where to go from there
Yet More FSAsFSAs have multiple possible destinationstates when transitioningEach transition is tested; the first onethats true is the destination stateOrder transitions by priority
Perl + RPGs == <3So, what do we have here?A way of keeping track of whose turn itis in an RPG combat, and some othersmall things like condition expirationsNote that only the Pathfinder/d20system uses FSA::Engine; its not arequirement
What Isnt It?It doesnt track creature healthIt doesnt record what actions one takesIts not a virtual tabletopIt does not replace the GMComplete or pretty (right now)
What Is It?It tracks who goes whenIt tracks simple statuses... and if a status precludes someonefrom acting, it skips themThats itAnything more is a bug
Why Is It?Every other tool does too much(Almost) Every other tool needsWindowsEvery other tool requires a GUI
Why an FSA?Why not just use a REPL and somevariables?Lets think about how RPG combatsworkThe model fits really well
Why an FSA?What happens in an RPG combat?Different creatures take their turnsThe order matters but what that orderis doesntTheres some state that affects whodoes what when
Why an FSA?Turns are grouped into rounds, roundsare grouped into a combatLoop over the combatants turns everyround until theres no combatants fromone side leftEvery step of the way is determined bythe state of the system at the time
Why an FSA?Therefore, we need something thatmoves from one of a finite list of statesto another based upon the existingstateIt turns out FSAs are really good at that
Automata in PerlWeve got a few automata in Perl: POE::NFA FSA::Rules FSA::Engine
FSA::EngineMoose roleAdds some attributes and methodsThese attributes and methods controlthe automatonThe docs are good, I wont repeat themhere
Using FSA::EngineIts a Moose role, so you compose it intoyour class as you would any other roleThen there are some attributes andmethods you need to write which tellthe FSA how to transition statesReally easy, seriously
The App ItselfIts simple, reallyStart it, it asks for a list of combatants(PCs and NPCs)Then it runs a combat until one sidewins
Poking Under The Cover Each different game system is supported by a ruleset class This ruleset class is actually the brain of the app It determines who goes when and most everything else
But...What if a player changes their mind?
Undo SupportWhen thinking about this feature, Iinvestigated various undo frameworkson CPANThey do what they say on the tin...... but they require me to write lots ofboring codeIsnt there an easier way?
Undo SupportIt turns out there isThe FSA runs various coderefs todetermine which state to advance toThese coderefs use attributes andvariables in scope for the transitionsubs
Therefore...All we need for undo support is to find away to snapshot the object attributesand lexicals and a way to roll back thatto that snapshot and then tell the statemachine to go to the next state
The MagicThe trick here is realizing that its notreally undo that we needIts just moving the FSA to anotherstateIf we can fake that, then it doesntreally matter that its fake undo
How?If this was just package variables itd beeasyBut its modern Perl and that meanslexicalsThankfully, Perl is awesomeWe have tools for that, like PadWalker
PadWalker?Every so often, take a snapshot of thelexical padPush it onto a stackWhen requested, unwind the stack, tellthe FSA to go to the next stateUndo support!
But...It *is* a bit of a hackIts simpleBut its cheatingPatches welcome
Future DirectionsOther RPG systemsSerialize state to disk for resumingsessions laterAdd support for holding/delayingactions and other things of that sort
Questions?Code is on github at http://bit.ly/LlqIcRSlides at http://slidesha.re/LSTqT4
Let LinkedIn power your SlideShare experience
Let LinkedIn power your SlideShare experience
Customize SlideShare content based on your interests
We will import your LinkedIn profile and you will be visible on SlideShare.
Keep up to date when your LinkedIn contacts post on SlideShare