Roasted Moose With all the Mixins

In my last D&D post I left off with my six abilities as attributes in my character class and two 'traits/roles', ('Languages' and 'Henchmen') it did leave me with the question. Should I treat all or just some these character abilities as 'trait/roles' or should some be subs in my base class or $flip back and make my base abilities roles or even to go back to square one again and just make them subs in my original base class??

So I did a little reading and thinking and personally all these little code snippets do make my base class a little less cluttered which is nice but doesn't give me much. So I was wondering if I could reuse any of them and perhaps benefit from code reuse.

Lets have a look at the 'Opens Doors On A' abilities that all characters have and is modified by strength. Well in the game it is not only characters who can open doors, NPCs, Henchmen, Monsters, Magic and even the Wind can open a door.

Slamming a large door shut as you retreat out of a room is a good way to slow down a horde of Kobolds that are on your tail but it's not going to do much but annoy that Troll that is on your scent. So I guess the ability to 'Open Doors' is transferable and yes you have to have some sort of 'Strength' to open a door so I might be able to reuse it someplace.

These reusable titbits or Mixins look like a great idea, they do of course have some detractors even myself learned to hate them when programming with 'Flavors' in 'Lisp' But they might be good here. As I can see some of the common abilities are potentially used in all sorts of other classes.

Of course now with all the potential Mixins of D&D my class diagram might become just as obfuscated as the career path of the typical middle aged DM.

09opart.large.gif

I could go back and make Strength a Role but opening a door is an action not a property though you can say

  • Open door with Strength

you can also

  • Open door with Magic
  • Open door with Key
  • Open door with Lock Pick

So I think I will go forward with


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

Here I think the 'with' part of the Moose syntax need a little clarification, In my understanding it is 'Character->OpenDoorsOnA ->with->strength' rather than 'Character->with->strength->OpenDoorsOnA' as the attributes or the role are added to the class not the attribute that requires it.

Anyway my role will look like this


use Moose::Role;
requires 'strength';

sub open_door_on_a {
my $self = shift;

return 6
if ($self->strength() > 18);

given ($self->strength() ){
when([0..7]){
return 1;
};
when([8..15]){
return 2;
};
when([17..18]){
return 3;
};
default {
return 0;
};
};

}

That will work fine 99% of the time except when I have a fighter class that has good old 18(00) strength how am I going to work that in? How about an Ochre Jelly it doesn't have any strength per say but it can eat its way though or door or even go under it??

I guess I am getting close now to creating my First Character Class, as in D&D class not programming class.

Well at least I have my next post now.


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