Zap that thing!

One of the really fun aspects playing D&D was the plethora of spells that where available to the various player characters. To a programmer they introduce a whole nightmare of very vague rules that have to be implements some-how hopefully without an endless chain of it thens, given whens or, God help us, gotos or even gosub (yikes any one remember Applesoft BASIC basic?)

saveordie.jpg

Because spellcasting is such a mine-field of subtle rules or at least rules that could never be applied in a game. For example the wish spell, In real game play a player could wish for, well almost anything, How would you do that in a computer game? The few times I have seen it in a game there was always a list of things you could choose from to happen.

So game designers usually opt for a more simplified spell system where the spells can be more closely codified. Usually blast this, heal that, protect this, or find that.

Well fortunately for me the Player's Guide has done most of the initial work for me. So to start I can have a simple spell base class like this,


package RPG::ADD::Spell;
 
use Moose;

has 'name' =>(
is =>'ro',
isa =>'Str',
init_arg => undef,);

has 'magic_type' =>(
is =>'ro',
isa =>'Str',
init_arg => undef,);

has 'reversible' =>(
is =>'ro',
isa =>'Bool',
init_arg => undef,);

has 'level' =>(
is =>'ro',
isa =>'Int',
init_arg => undef,);

has 'duration' =>(
is =>'ro',
isa =>'Str',
init_arg => undef,);

has 'area_of_effect' =>(
is =>'ro',
isa =>'Str',
init_arg => undef,);

has 'components' =>(
is =>'ro',
isa =>'ArrayRef[Str]',
init_arg => undef,);

has 'casting_time' =>(
is =>'ro',
isa =>'Int',
init_arg => undef,);

has 'saving_throw' =>(
is =>'ro',
isa =>'Str',
init_arg => undef,);

has 'description' =>(
is =>'ro',
isa =>'Str',
init_arg => undef,);

Well that was simple enough I just mimicked the structure present in the book. But this is only 1/4 of the story, It just describes my spell it does not implement it in any way.

Well I think Roles might be my best bet here to start. If I have a set of common roles for the types of magic each spell implements then I can reuse these roles for say enchanted items, monsters with magic properties or even magic placess.

So lets have a look at what a sleep spell might look like


package RPG::ADD::Spell;

use Moose;
with "RPG::ADD::Magic::Charm::Sleep"

has '+name'=>(
default=>'Sleep'
)

has '+duration'=>(
default=>'5'
)

... no need to bore you with silly typing you get the picture

Now my "RPG::ADD::Magic::Charm::Sleep" will have all the 'rules' that apply in this situation so I think this is a good start.

But, How to organize all of these spells?? Do I drop them all in a big bucket and let the application figure out where they belong then I would have to start adding in such attributes as 'cleric_spell' , 'mu_spell', etc ect. As well spells are also classified by Level do I leave that like I have in as an Attribure I can sort on or do I do something else??

Well more design work ahead.

Leave a comment

About byterock

user-pic Long time Perl guy, a few CPAN mods allot of work on DBD::Oracle and a few YAPC presentations