From 6957c2d574a948b63e87913f72d785ccf7fb93af Mon Sep 17 00:00:00 2001 From: ElTata <gennuso2015@perso.iiens.net> Date: Wed, 2 Oct 2019 01:33:31 +0200 Subject: [PATCH] classes wip: - player now have 6 stats - Irpg/Classes/*.pm files are classes (POO) of classes (RPG) (oof) - each implements modificators on stats - base classe is Farmer, other inherit of this one - atk/def method implemented for now --- Irpg/Classes/Farmer.pm | 56 +++++++++++++++++++++++++++++++++++++++++ Irpg/Classes/Mage.pm | 28 +++++++++++++++++++++ Irpg/Classes/Thief.pm | 28 +++++++++++++++++++++ Irpg/Classes/Warrior.pm | 28 +++++++++++++++++++++ Irpg/Main.pm | 30 ++++++++++++---------- Irpg/Users.pm | 31 ++++++++++++++++++----- Irpg/Utils.pm | 44 ++++++++++++++++++++++++++++---- 7 files changed, 221 insertions(+), 24 deletions(-) create mode 100644 Irpg/Classes/Farmer.pm create mode 100644 Irpg/Classes/Mage.pm create mode 100644 Irpg/Classes/Thief.pm create mode 100644 Irpg/Classes/Warrior.pm diff --git a/Irpg/Classes/Farmer.pm b/Irpg/Classes/Farmer.pm new file mode 100644 index 0000000..69f03f3 --- /dev/null +++ b/Irpg/Classes/Farmer.pm @@ -0,0 +1,56 @@ +package Irpg::Classes::Farmer; + +use strict; +use warnings; + +sub new { + my ($class, $pl_stats) = @_; + my $self = {}; + bless $self, $class; + $self->{STATS} = $pl_stats; + $self->{NAME} = 'Farmer'; + + #modificators + $self->{MOD_STR} = 1; # strength + $self->{MOD_CON} = 1; # constitution + $self->{MOD_WIS} = 1; # wisdom + $self->{MOD_INT} = 1; # intelligence + $self->{MOD_CHA} = 1; # charisma + $self->{MOD_DEX} = 1; # dexterity + $self->{MOD_POS} = 1; # positive events + $self->{MOD_NEG} = 1; # negative events + $self->{MOD_EQP} = 1; # equipement + return $self; +} + +sub str { + my $self = shift; + return $self->{STATS}->{str} * $self->{MOD_STR}; +} + +sub con { + my $self = shift; + return $self->{STATS}->{con} * $self->{MOD_CON}; +} + +sub wis { + my $self = shift; + return $self->{STATS}->{wis} * $self->{MOD_WIS}; +} + +sub int { + my $self = shift; + return $self->{STATS}->{int} * $self->{MOD_INT}; +} + +sub cha { + my $self = shift; + return $self->{STATS}->{cha} * $self->{MOD_CHA}; +} + +sub dex { + my $self = shift; + return $self->{STATS}->{dex} * $self->{MOD_DEX}; +} + +1; diff --git a/Irpg/Classes/Mage.pm b/Irpg/Classes/Mage.pm new file mode 100644 index 0000000..0d52502 --- /dev/null +++ b/Irpg/Classes/Mage.pm @@ -0,0 +1,28 @@ +package Irpg::Classes::Mage; + +use strict; +use warnings; +use Irpg::Classes::Farmer; +our @ISA = qw(Farmer); + +sub new { + my ($class, $pl_stats) = @_; + my $self = $class->SUPER::new($pl_stats); + bless $self, $class; + $self->{NAME} = 'Mage'; + $self->{MOD_WIS} = 1.2; + $self->{MOD_INT} = 1.2; + return $self; +} + +sub atk { + my $self = shift; + return $self->int() + $self->dex(); +} + +sub def { + my $self = shift; + return $self->wis() + $self->dex(); +} + +1; diff --git a/Irpg/Classes/Thief.pm b/Irpg/Classes/Thief.pm new file mode 100644 index 0000000..739446b --- /dev/null +++ b/Irpg/Classes/Thief.pm @@ -0,0 +1,28 @@ +package Irpg::Classes::Thief; + +use strict; +use warnings; +use Irpg::Classes::Farmer; +our @ISA = qw(Farmer); + +sub new { + my ($class, $pl_stats) = @_; + my $self = $class->SUPER::new($pl_stats); + bless $self, $class; + $self->{NAME} = 'Thief'; + $self->{MOD_CHA} = 1.2; + $self->{MOD_DEX} = 1.2; + return $self; +} + +sub atk { + my $self = shift; + return $self->int() + $self->dex(); +} + +sub def { + my $self = shift; + return $self->con() + $self->dex(); +} + +1; diff --git a/Irpg/Classes/Warrior.pm b/Irpg/Classes/Warrior.pm new file mode 100644 index 0000000..020c20e --- /dev/null +++ b/Irpg/Classes/Warrior.pm @@ -0,0 +1,28 @@ +package Irpg::Classes::Warrior; + +use strict; +use warnings; +use Irpg::Classes::Farmer; +our @ISA = qw(Farmer); + +sub new { + my ($class, $pl_stats) = @_; + my $self = $class->SUPER::new($pl_stats); + bless $self, $class; + $self->{NAME} = 'Warrior'; + $self->{MOD_STR} = $pl_stats->{str}*1.2; + $self->{MOD_CON} = $pl_stats->{con}*1.2; + return $self; +} + +sub atk { + my $self = shift; + return $self->str() + $self->dex(); +} + +sub def { + my $self = shift; + return $self->con() + $self->dex(); +} + +1; diff --git a/Irpg/Main.pm b/Irpg/Main.pm index 1454e74..0a832ad 100644 --- a/Irpg/Main.pm +++ b/Irpg/Main.pm @@ -13,15 +13,13 @@ use strict; use warnings; use Irpg::Utils qw(:DEFAULT &checksplits &duration &backup &writedb); use Irpg::Irc qw(:DEFAULT :interaction $inbytes); -use Irpg::Quest; -use Irpg::Fight; -use Irpg::Event; -use Irpg::Admin; -use Irpg::Users; use Exporter qw(import); our @EXPORT = qw(&init_hashes &rpcheck &parse &penalize &ha &finduser); our @EXPORT_OK = qw($pausemode $silentmode $primnick $lastreg); +foreach (qw(Quest Fight Event Admin Users)) { + eval "use Irpg::$_"; +} my %commands; # filling at the very bottom @@ -256,9 +254,12 @@ sub rpcheck { # check levels, update database ### ALL MODULES CHEKS ### # statements using $rpreport do not bother with scaling by the clock because # $rpreport is adjusted by the number of seconds since last rpcheck() - Irpg::Quest::rpcheck($rpreport, $online); ### QUEST BUSINESS ### - Irpg::Fight::rpcheck($rpreport, $online); ### FIGHT BUSINESS ### - Irpg::Event::rpcheck($rpreport, $online); ### EVENT BUSINESS ### + foreach (qw(Quest Fight Event)) { + eval 'Irpg::'.$_.'::rpcheck($rpreport, $online'; + } +# Irpg::Quest::rpcheck($rpreport, $online); ### QUEST BUSINESS ### +# Irpg::Fight::rpcheck($rpreport, $online); ### FIGHT BUSINESS ### +# Irpg::Event::rpcheck($rpreport, $online); ### EVENT BUSINESS ### ### TOP PLAYERS REPORT ### if ($rpreport && $rpreport%36000==0) { # 10 hours @@ -549,11 +550,14 @@ sub help { my ($k, $v); -while (($k,$v) = each %$Irpg::Quest::commands) {$commands{$k} = $v;} -while (($k,$v) = each %$Irpg::Fight::commands) {$commands{$k} = $v;} -while (($k,$v) = each %$Irpg::Event::commands) {$commands{$k} = $v;} -while (($k,$v) = each %$Irpg::Admin::commands) {$commands{$k} = $v;} -while (($k,$v) = each %$Irpg::Users::commands) {$commands{$k} = $v;} +foreach (qw(Quest Fight Event Admin Users)) { + eval 'while (($k,$v) = each %$Irpg::'.$_.'::commands) {$commands{$k} = $v;}'; +} +#while (($k,$v) = each %$Irpg::Quest::commands) {$commands{$k} = $v;} +#while (($k,$v) = each %$Irpg::Fight::commands) {$commands{$k} = $v;} +#while (($k,$v) = each %$Irpg::Event::commands) {$commands{$k} = $v;} +#while (($k,$v) = each %$Irpg::Admin::commands) {$commands{$k} = $v;} +#while (($k,$v) = each %$Irpg::Users::commands) {$commands{$k} = $v;} undef $k; undef $v; diff --git a/Irpg/Users.pm b/Irpg/Users.pm index aab3e81..e39921f 100644 --- a/Irpg/Users.pm +++ b/Irpg/Users.pm @@ -132,7 +132,7 @@ sub register { sub chtitle { my ($userhost, $usernick, $username, $source, @arg) = @_; if (!defined($username)) { - Irpg::Irc::notice("You are not logged in.", $usernick) + Irpg::Irc::notice("You are not logged in.", $usernick); } elsif (!defined($arg[0])) { Irpg::Irc::notice("Try: CHTITLE <new title>", $usernick); @@ -236,7 +236,7 @@ sub whoami { sub newpass { my ($userhost, $usernick, $username, $source, @arg) = @_; if (!defined($username)) { - Irpg::Irc::notice("You are not logged in.", $usernick) + Irpg::Irc::notice("You are not logged in.", $usernick); } elsif (!defined($arg[0])) { Irpg::Irc::privmsg("Try: NEWPASS <new password>", $usernick); @@ -250,7 +250,7 @@ sub newpass { sub align { my ($userhost, $usernick, $username, $source, @arg) = @_; if (!defined($username)) { - Irpg::Irc::notice("You are not logged in.", $usernick) + Irpg::Irc::notice("You are not logged in.", $usernick); } elsif (!defined($arg[0]) || (lc($arg[0]) ne "good" && lc($arg[0]) ne "neutral" && lc($arg[0]) ne "evil")) { @@ -268,7 +268,7 @@ sub align { sub gender { my ($userhost, $usernick, $username, $source, @arg) = @_; if (!defined($username)) { - Irpg::Irc::notice("You are not logged in.", $usernick) + Irpg::Irc::notice("You are not logged in.", $usernick); } elsif (!defined($arg[0]) || $arg[0] =~ /[^MFN]/) { Irpg::Irc::notice("Try: GENDER <F[emale]|N[eutral]|M[ale]>",$usernick); @@ -285,7 +285,7 @@ sub gender { sub rmplayer { my ($userhost, $usernick, $username, $source, @arg) = @_; if (!defined($username)) { - Irpg::Irc::notice("You are not logged in.", $usernick) + Irpg::Irc::notice("You are not logged in.", $usernick); } else { Irpg::Irc::privmsg("Account $username removed.",$usernick); @@ -333,6 +333,22 @@ sub info { } } +sub testclass { + my ($userhost, $usernick, $username, $source, @arg) = @_; + if (!defined($username)) { + Irpg::Irc::notice("You are not logged in.", $usernick); + } + else { + Irpg::Irc::privmsg("Classe ". + $rps->{$username}{class}->{NAME}. + " Raw stats : ". + join(', ', map { "$_ $rps->{$username}{stats}{$_}" } keys($rps->{$username}{stats})). + " Modified stats : ". + join(', ', map { "$_ ".eval('$rps->{$username}{class}->'.$_.'()') } keys($rps->{$username}{stats})). + "", $source); + } +} + our $commands = { register => {ref => \®ister, adm => 0, prv => 1, pub => 0, hlp => 'REGISTER <char name> <password <char title> :'. @@ -371,7 +387,10 @@ our $commands = { hlp => 'WHOAMI : check your current status'}, info => {ref => \&info, adm => 0, prv => 1, pub => 0, - hlp => 'INFO : get some info about the bot.'} + hlp => 'INFO : get some info about the bot.'}, + + class => {ref => \&testclass, adm => 0, prv => 1, pub => 1, + hlp => 'CLASS : class info'} }; 1; diff --git a/Irpg/Utils.pm b/Irpg/Utils.pm index 3d9eb0e..2c0e611 100644 --- a/Irpg/Utils.pm +++ b/Irpg/Utils.pm @@ -29,7 +29,13 @@ our %EXPORT_TAGS = (text=>[qw(&duration &pronoun &mksalt)], data=>[qw(&readconfig &createdb &loaddb &backup &writedb)]); -my $_configfile = '.irpg.conf'; +foreach (<Irpg/Classes/*.pm>) { + s/Irpg\/Classes\/(\w+)\.pm/$1/; + eval "require Irpg::Classes::$_"; +} + + +my $_configfile = '.irpg.conf.dev'; my $opts; my $rps; @@ -191,7 +197,6 @@ sub readconfig { } elsif ($key eq "server") { push(@{$opts{servers}},$val); } elsif ($key eq "listenchan") { push(@{$opts{listenchan}},$val); } - elsif ($key eq "okurl") { push(@{$opts{okurl}},$val); } else { $opts{$key} = $val; } } close(CONF); @@ -234,12 +239,13 @@ sub loaddb { # load the players database if (!open(RPS,$opts->{dbfile}) && -e $opts->{dbfile}) { Irpg::Irc::sts("QUIT :loaddb() failed: $!"); } + my $classname; while ($l=<RPS>) { chomp($l); next if $l =~ /^#/; # skip comments my @i = split("\t",$l); - print Dumper(@i) if @i != 34; - if (@i != 34) { + print Dumper(@i) if @i != 41; + if (@i != 41) { Irpg::Irc::sts("QUIT: Anomaly in loaddb(); line $. of $opts->{dbfile} has ". "wrong fields (".scalar(@i).")"); debug("Anomaly in loaddb(); line $. of $opts->{dbfile} has wrong ". @@ -279,8 +285,18 @@ sub loaddb { # load the players database $rps{$i[0]}{item}{shield}, $rps{$i[0]}{item}{tunic}, $rps{$i[0]}{item}{weapon}, + $rps{$i[0]}{stats}{str}, + $rps{$i[0]}{stats}{con}, + $rps{$i[0]}{stats}{wis}, + $rps{$i[0]}{stats}{int}, + $rps{$i[0]}{stats}{cha}, + $rps{$i[0]}{stats}{dex}, + $classname, $rps{$i[0]}{alignment}, $rps{$i[0]}{gender}) = (@i[1..7],($sock?$i[8]:0),@i[9..$#i]); + + $rps{$i[0]}{class} = eval 'Irpg::Classes::'.$classname. + '->new($rps{$i[0]}{stats})'; } close(RPS); debug("loaddb(): loaded ".scalar(keys(%rps))." accounts, ". @@ -330,6 +346,13 @@ sub writedb { "shield", "tunic", "weapon", + "str", + "con", + "wis", + "int", + "char", + "dex", + "class", "alignment", "gender")."\n"; my $k; @@ -368,6 +391,13 @@ sub writedb { $rps->{$k}{item}{shield}, $rps->{$k}{item}{tunic}, $rps->{$k}{item}{weapon}, + $rps->{$k}{stats}{str}, + $rps->{$k}{stats}{con}, + $rps->{$k}{stats}{wis}, + $rps->{$k}{stats}{int}, + $rps->{$k}{stats}{cha}, + $rps->{$k}{stats}{dex}, + $rps->{$k}{class}->{NAME}, $rps->{$k}{alignment}, $rps->{$k}{gender})."\n"; } @@ -409,6 +439,10 @@ sub createdb { $rps{$uname}{nick} = ""; $rps{$uname}{userhost} = ""; $rps{$uname}{level} = 0; + foreach (qw(str con wis int cha dex)) { + $rps{$uname}{stats}{$_} = 1; + } + $rps{$uname}{class} = Irpg::Classes::Farmer->new($rps{$uname}{stats}); $rps{$uname}{online} = 0; $rps{$uname}{idled} = 0; $rps{$uname}{created} = time(); @@ -428,9 +462,9 @@ sub createdb { "pen_logout","pen_logout","pen_title") { $rps{$uname}{$pen} = 0; } + $rps = \%rps; writedb(); print "OK, wrote you into $opts->{dbfile}.\n"; - $rps = \%rps; return $rps; } -- GitLab