From 42849ca3cef74e7fccdf507cf7e7f5c065de247e Mon Sep 17 00:00:00 2001 From: ElTata <gennuso2015@perso.iiens.net> Date: Fri, 4 Oct 2019 10:11:21 +0200 Subject: [PATCH] classes wip: - bugfix: corrected regex in Farmer class, added missing parenthesis in Action.pm and condition in do_action() - changed some text --- Irpg/Action.pm | 19 +++++++++---------- Irpg/Admin.pm | 2 +- Irpg/Classes/Farmer.pm | 12 ++++++------ Irpg/Event.pm | 3 ++- Irpg/Main.pm | 8 +++----- Irpg/Users.pm | 13 ++++++------- 6 files changed, 27 insertions(+), 30 deletions(-) diff --git a/Irpg/Action.pm b/Irpg/Action.pm index e08ab17..63085d1 100644 --- a/Irpg/Action.pm +++ b/Irpg/Action.pm @@ -234,9 +234,8 @@ sub steal_result { sub perform_action { my ($p1, $p2, $action_type) = @_; return unless $p1 && $p2 && $action_type; - my ($p1atk, $p2def); - $p1atk = eval '$rps->{$p1}{class}->'.$action_type.'_atk()'; - $p2def = eval '$rps->{$p2}{class}->'.$action_type.'_def()'; + my $p1atk = eval '$rps->{$p1}{class}->'.$action_type.'_atk()'; + my $p2def = eval '$rps->{$p2}{class}->'.$action_type.'_def()'; my $p1sum = itemsum($p1,1); my $p2sum = itemsum($p2,1); my $p1roll = int(rand($p1sum) * $p1atk); @@ -251,8 +250,7 @@ sub perform_action { my $align_mod = $rps->{$p1}{alignment} eq "g" ? 0.05 : $rps->{$p1}{alignment} eq "e" ? -0.10 : 1; - if ($p1roll >= $p1sum * $rps->{$p1}{class}->atk() - * ($rps->{$p1}{class}->{CRIT_SK} + $align_mod)) { + if ($p1roll >= $p1sum * $p1atk * ($rps->{$p1}{class}->{CRIT_SK} + $align_mod)) { # CRITICAL STRIKE $ret->{vict}++; } @@ -317,7 +315,7 @@ sub collision_action { $mesg .= ($ret_action->{vict} ? 'stolen ': 'been caught stealing '). - 'from '.pronoun(3, $rps->{$p2}{gender}."!"); + 'from '.pronoun(3, $rps->{$p2}{gender})."! "; } $mesg .= shift @$res_action; Irpg::Irc::chanmsg(Irpg::Utils::clog($mesg)); @@ -412,7 +410,7 @@ sub do_action { return; } my $p2; - if (exists($arg[0]) && !(grep { $arg[0] } @opps)) { + if (exists($arg[0]) && !(grep { $arg[0] eq $_ } @opps)) { if (exists($rps->{$arg[0]})) { Irpg::Irc::notice( "You searched every places you know, but $arg[0] ". @@ -434,6 +432,7 @@ sub do_action { else { $p2 = $opps[int(rand(@opps))]; } + $rps->{$username}{actions}--; my $p1 = $username; my $action_type = choose_action($p1); my $ret_action = perform_action($p1, $p2, $action_type); @@ -446,19 +445,19 @@ sub do_action { if ($action_type eq 'fight') { $mesg .= "$p1 $p1_res has provoked $p2 $p2_res in a fight, and ". - ($ret_action->{vict} ? 'won': 'lost')."!"; + ($ret_action->{vict} ? 'won': 'lost')."! "; } elsif ($action_type eq 'mystic') { $mesg .= "$p1 $p1_res has performed mystical deeds on $p2 $p2_res, and ". ($ret_action->{vict} ? 'dazed '.pronoun(3, $rps->{$p2}{gender}): 'got confused'). - "!"; + "! "; } else { #($action_type eq 'steal') $mesg .= "$p1 $p1_res has sneaked on $p2 $p2_res in the shadows and ". ($ret_action->{vict} ? 'stolen ' : 'been caught stealing '). - 'from '.pronoun(3, $rps->{$p2}{gender}."!"); + 'from '.pronoun(3, $rps->{$p2}{gender})."! "; } $mesg .= shift @$res_action; Irpg::Irc::chanmsg(Irpg::Utils::clog($mesg)); diff --git a/Irpg/Admin.pm b/Irpg/Admin.pm index edfa2da..c8abe21 100644 --- a/Irpg/Admin.pm +++ b/Irpg/Admin.pm @@ -216,7 +216,7 @@ sub clearq { } -our commands = { +our $commands = { go => {ref => \&join_chans, adm => 1, prv => 1, pub => 0, hlp => 'GO <chan>[ <chan> ...] : join the given chan(s)'}, diff --git a/Irpg/Classes/Farmer.pm b/Irpg/Classes/Farmer.pm index 340d512..1123b22 100644 --- a/Irpg/Classes/Farmer.pm +++ b/Irpg/Classes/Farmer.pm @@ -82,31 +82,31 @@ sub steal_def { sub real_gain { # to apply on TTL modificators my ($self, $time) = @_; - return unless ($time =~ m/^-?\d$/); + return unless ($time =~ m/^-?\d+$/); $time = $time >= 0 ? $time*(1-($self->cha()-1)/10): # add less time $time*(1+($self->cha()-1)/10); # remove more time - return Core::int($time); + return CORE::int($time); } sub real_sum { # to apply on itemsum my ($self, $sum) = @_; - return unless ($sum =~ m/^-?\d$/); + return unless ($sum =~ m/^-?\d+$/); $sum = $sum >= 0 ? $sum*(1+($self->str()-1)/10): $sum*(1-($self->str()-1)/10); - return Core::int($sum); + return CORE::int($sum); } sub real_lvl { # to apply on found items my ($self, $lvl) = @_; - return unless ($lvl =~ m/^-?\d$/); + return unless ($lvl =~ m/^-?\d+$/); $lvl = $lvl >= 0 ? $lvl*(1+($self->wis()-1)/10): $lvl*(1-($self->wis()-1)/10); - return Core::int($lvl); + return CORE::int($lvl); } diff --git a/Irpg/Event.pm b/Irpg/Event.pm index ca0f599..6143528 100644 --- a/Irpg/Event.pm +++ b/Irpg/Event.pm @@ -30,9 +30,10 @@ sub find_item { # find item for argument player my $ulevel; for my $num (1 .. int($rps->{$u}{level}*1.5)) { if (rand(1.4**($num/4)) < 1) { - $level = $rps->{$u}{class}->real_lvl($num); + $level = $num; } } + $level = $rps->{$u}{class}->real_lvl($level); if ($rps->{$u}{level} >= 25 && rand(40) < 1) { $ulevel = $rps->{$u}{class}->real_lvl(50+int(rand(25))); if ($ulevel >= $level && $ulevel > int($rps->{$u}{item}{helm})) { diff --git a/Irpg/Main.pm b/Irpg/Main.pm index 932f225..67f0d22 100644 --- a/Irpg/Main.pm +++ b/Irpg/Main.pm @@ -317,20 +317,18 @@ sub rpcheck { # check levels, update database $rps->{$k}{next} = int($opts->{rpbase} * ($opts->{rpstep}**$rps->{$k}{level})); } - Irpg::Irc::chanmsg("$k, the $rps->{$k}{title}, has attained level ". + Irpg::Irc::chanmsg("$k, the $rps->{$k}{title} ". + "$rps->{$k}{class}->{NAME}, has attained level ". "$rps->{$k}{level}! Next level in ". duration($rps->{$k}{next})."."); - print "item\n"; find_item($k); - print "chall\n"; challenge_opp($k); - print "bite\n"; } if ($rps->{$k}{next_f} < 1 && $rps->{$k}{actions} < int($rps->{$k}{level}/10)) { $rps->{$k}{actions}++; $rps->{$k}{next_f} = 3600; # 1 hour - Irpg::Irc::notice("You feel ready for a new fight !", $rps->{$k}{nick}); + Irpg::Irc::notice("You feel ready to perform a new deed !", $rps->{$k}{nick}); } } # attempt to make sure this is an actual user, and not just an diff --git a/Irpg/Users.pm b/Irpg/Users.pm index 55a0912..d96fe53 100644 --- a/Irpg/Users.pm +++ b/Irpg/Users.pm @@ -309,14 +309,15 @@ sub rmplayer { sub info { my ($userhost, $usernick, $username, $source, @arg) = @_; my $info; + my $admins = join(", ", map { $rps->{$_}{nick} } + grep { $rps->{$_}{isadmin} && + $rps->{$_}{online} } + keys(%$rps)); if (!Irpg::Main::ha($usernick)) { $info = "IRPG bot by ElTata, ". "based on jotun's initial work.". "https://gennuso.iiens.net/irpg. On via: ". - $opts->{servers}->[0].". Admins online: ". - join(", ", map { $rps->{$_}{nick} } - grep { $rps->{$_}{isadmin} && - $rps->{$_}{online} } keys(%$rps))."."; + $opts->{servers}->[0].". Admins online: $admins"; Irpg::Irc::privmsg($info, $usernick); } else { @@ -337,9 +338,7 @@ sub info { $queuedbytes, scalar(@Irpg::Irc::queue), $opts->{servers}->[0], - join(", ",map { $rps->{$_}{nick} } - grep { $rps->{$_}{isadmin} && $rps->{$_}{online} } - keys(%$rps))); + $admins); Irpg::Irc::privmsg($info, $usernick, 1); } } -- GitLab