A Roleing Class Gathers no Moose

Well it seems I am making a little progress with D&D 'Character' classes I think I even got a role that will stick. I did have a little unfinished business from my previous post with my 'Character' class that I have to fix.

Namely it is important to the game that I know the current value of an ability which may change, and the initial value which will not, but I do not want to add in all sorts of attributes with funny odd names. So putting on my game design/players hat for a second, the initial ability values (rolls) are use mostly at character creation, for race and class selection. After that they are only useful as tombstone data.

An example is if a character is enchanted somehow or is just getting old and looses some 'Constitution' her 'Resurrection Survival' throw will lower but the maximum number of times a 'Character' can be resurrected is the initial 'Constitution' so I need that as well.

failed-resurrection-saving-throw.jpg

So for game-play and 'programming', 99% of the time we use the 'Current Constitution' so it is much easier to just use 'constitution' as the attribute name rather than something else.

So in my character class I think it would be best to just make a sub that returns the 'tombstone' ability values (how I persist them is another story though) as I will use them rarely. So that problem is solved for now.

But looking at 'Constitution' the resurrection part only comes into play once you are 'Dead' so maybe I should create a 'Dead' role or for that matter a 'Dead' class, that the 'Character' has to be resurrected from and use the tombstone data to see if she can come back to life and what chance they have to make it back? I think I will look at that one later and just keep on track for now.

Anyway so now I have my base 'Character' class that looks like this

package Character;

use Moose;
has 'name' =>(
	is		=>'ro',
	isa		=>'Str',
);

has 'strength' =>(
	is		=>'rw',
	isa		=>'Int',
	default     =>0,
);

has 'intelligence' =>(
	is		=>'rw',
	isa		=>'Int',
	default     =>0,
);
 with qw( Languages );    
 
has 'wisdom' =>(
	is		=>'rw',
	isa		=>'Int',
	default     =>0,
);

has 'dexterity' =>(
	is		=>'rw',
	isa		=>'Int',
	default     =>0,
);
has 'constitution' =>(
	is		=>'rw',
	isa		=>'Int',
	default      =>0,
);
	
has 'charisma' =>(
	is		=>'rw',
	isa		=>'Int',
	default      =>0,
);
 with qw( Henchmen );    
So the pattern I am following is to exclude traits (roles) that are not common in all races and character classes, so you do not see any traits that relate to spell or pilfering ability. You might notice that I added in "Henchmen" (or Henchpersons if I want to be politically correct) at the end. 'Henchmen' are like 'Languages' in that there are a few attributes and methods that are directly affected by 'Charisma' so I created a role like this

package Henchmen;

use Moose::Role;
requires 'charisma';

has 'henchmen' => (
	is  => 'ro',
	isa  =>'ArrayRef[Henchman]',
	default	=>sub{[]},
);

sub hire_henchman {
   my $self = shift;
   my ($henchman) = @_;
   return 
      if (scalar($self->henchmen) >= $self->max_henchmen());
   push(@{$self->henchmen()},$henchman);
}

sub max_henchmen {
	my $self = shift;
	return 1
		if ($self->charisma()<3);
	return 15
		if ($self->charisma() >= 18);
  
	my %additional = (5=>2,6=>2,7=>3,8=>3,9=>4,10=>4,11=>4,12=>5,13=>5,14=>6,15=>7,16=>8,17=>10);
	return $additional{$self->charisma()};

}
Aficionados of D&D will notice I left our both 'Reaction Adjustment' and 'Loyalty Base'. These modifiers deal with 'Morale' which can apply to henchmen, as well NPCs, and even the odd Monster. Neat with roles you can really fine grain your traits.

At this point I have a choice to make. Some Ability scores modify a number of base traits. For example, Strength may modify up to five.

Do I add in all the other abilities and ability traits modifiers as roles or do I just add them in the class as subs and attributes?

Oh well something for the next Blog.

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