### Copyright (C) The Holy Ghost 2017 ###This program is released under the GPL 3.0 and artistic license 2.0. package HollyGameAI::AIInterface; our @ISA = "Interface"; sub AIInterface { my $class = shift; $self = $class->SUPER::Interface(qw(@_)); ### e.g. qw(swim fly) bless $self, $class; } ### Copyright (C) The Holy Ghost 2017 ###This program is released under the GPL 3.0 and artistic license 2.0. package HollyGameAI::Factory; our @ISA = "HollyGameAI::Interface"; sub Factory { my $class = shift; my $self = $class->SUPER::Interface(@_); ### include abstract method names return bless $self, $class; } ### Copyright (C) The Holy Ghost 2017 ###This program is released under the GPL 3.0 and artistic license 2.0. ### with thanks to gregorovius from perlmonks package HollyGameAI::Interface; use Carp; sub Interface { my $class = shift; my $self = {inheritors => (), abstract_methods => shift, ### e.g. qw(swim fly) }; bless $self, $class; } sub import { my $method = caller; push (@{ $self->{inheritors}}, $method); } sub INIT { my $bad = 0; for my $class ($self->{inheritors}) { for my $meth ($self->{abstract_methods}) { no strict 'refs'; unless (defined &{"${class}::$meth"}) { $bad = 1; warn "HolyGameAI : Class $class should implement HolyGameAI Interface but does not define $meth.\n"; } } } croak "HollyGameAI : Source compilation aborted at interface binding time\n" if $bad; } ### Copyright (C) The Holy Ghost 2017 ###This program is released under the GPL 3.0 and artistic license 2.0. package HollyGameAI::MutualExclusiveAI; use lib "../HollyGameAI"; use Factory; sub MutualExclusiveAI { my $class = shift; my $self = { aiclass => HollyGameAI::Factory->Factory(@_) }; bless $self, $class; } ### Copyright (C) The Holy Ghost 2017 ###This program is released under the GPL 3.0 and artistic license 2.0. package HollyGameAI::MutualExclusiveDeityAI; our @ISA = "MutualExclusiveAI"; sub MutualExclusiveDeityAI { my $class = shift; my $self = $self->SUPER::MutualExclusiveAI(qw(cast donate swim fly empower)); bless $self, $class; } ### Copyright (C) The Holy Ghost 2017 ###This program is released under the GPL 3.0 and artistic license 2.0. package HollyGameAI::RNG; ### Random Number God, dice class sub RNG { my $class = shift; my $self = { dx => 0 }; return bless $self, $class; } sub set { my ($self, $dxx) = @_; $self->{dx} = $dxx; } sub rollDX { my $self = shift; return rand($dx); } sub rollD1 { my $self = shift; return rand(1); } sub rollD3 { my $self = shift; return rand(3); } sub rollD6 { my $self = shift; return rand(6); } sub rollD10 { my $self = shift; return rand(10); } sub rollD20 { my $self = shift; return rand(20); } sub rollPreviousDX { my $self = shift; return rand($self->{dx}); } sub roll { my ($self, $dxx) = shift; $self->set($dxx); given ($self->{dx}) { when ($_ = 0) { return 0; } when ($_ == 1) { return rollD1; } when ($_ == 3) { return rollD3; } when ($_ == 6) { return rollD6; } when ($_ == 10) { return rollD10; } when ($_ == 20) { return rollD20; } } return 0; }