diff --git a/Irpg/Action.pm b/Irpg/Action.pm index 76dcc8e2a2a4ed76a5e0804f0b4a43bee05a3e1d..31480314ecce7c27563cd0ab75bc7e14a0a6be9a 100644 --- a/Irpg/Action.pm +++ b/Irpg/Action.pm @@ -2,6 +2,7 @@ package Irpg::Action; use strict; use warnings; +use POSIX; use Irpg::Utils qw(:text); use Irpg::Irc qw(:interaction); use Exporter qw(import); @@ -70,13 +71,40 @@ sub choose_action { return 'steal'; } +sub minimize { + my $x = shift; + return unless defined($x); + return 5*exp(-pow($x,2)/5000); +} + +sub maximize { + my $x = shift; + return unless defined($x); + return 5+pow($x,2)/1000; +} + +sub perc_defeat { + my $lvl_gap = shift; + return unless defined($lvl_gap); + return 5 if $lvl_gap == 0; + return $lvl_gap > 0 ? minimize($lvl_gap) : maximize($lvl_gap); +} + +sub perc_victory { + my $lvl_gap = shift; + return unless defined($lvl_gap); + return 5 if $lvl_gap == 0; + return $lvl_gap > 0 ? maximize($lvl_gap) : minimize($lvl_gap); +} + sub fight_result { my ($p1, $p2, $win, $wanted) = @_; return unless $p1 && $p2 && defined($win); my @queue = (); if ($win) { - my $gain = int($rps->{$p2}{level}/4); - $gain = 7 if $gain < 7; + #my $gain = int($rps->{$p2}{level}/4); + #$gain = 7 if $gain < 7; + my $gain = perc_victory($rps->{$p2}{level} - $rps->{$p1}{level}); $gain *= $rps->{$p1}{class}->{MOD_CRT} if ($win == 2); $gain *= 1.2 if ($wanted); $gain = int(($gain/100)*$rps->{$p1}{next}); @@ -86,8 +114,7 @@ sub fight_result { duration($gain)." is removed from $p1\'s clock."); if ($win == 2) { $gain = int(0.05*$rps->{$p2}{next}); - $gain = $rps->{$p2}{class}->real_gain($gain); - $rps->{$p2}{next} += $gain; + $rps->{$p2}{next} += $rps->{$p2}{class}->real_gain($gain); push(@queue, "$p1 has dealt $p2 a Critical Strike! ". duration($gain)." is added to $p2\'s clock. ". @@ -95,8 +122,9 @@ sub fight_result { } } else { - my $gain = $rps->{$p2}{level}/7; - $gain = 7 if $gain < 7; + #my $gain = $rps->{$p2}{level}/7; + #$gain = 7 if $gain < 7; + my $gain = perc_defeat($rps->{$p2}{level} - $rps->{$p1}{level}); $gain *= 1.2 if ($wanted); $gain = int(($gain/100)*$rps->{$p1}{next}); $gain = $rps->{$p1}{class}->real_gain($gain); @@ -114,8 +142,9 @@ sub mystic_result { return unless $p1 && $p2 && defined($win); my @queue = (); if ($win) { - my $gain = int($rps->{$p2}{level}/8); - $gain = 5 if $gain < 5; + #my $gain = int($rps->{$p2}{level}/8); + #$gain = 5 if $gain < 5; + my $gain = perc_victory($rps->{$p2}{level} - $rps->{$p1}{level})*0.70; $gain *= 1.2 if ($wanted); $gain = int(($gain/100)*$rps->{$p1}{next}); $gain = -$rps->{$p1}{class}->real_gain(-$gain); @@ -139,8 +168,9 @@ sub mystic_result { } } else { - my $gain = $rps->{$p2}{level}/10; - $gain = 5 if $gain < 5; + #my $gain = $rps->{$p2}{level}/10; + #$gain = 5 if $gain < 5; + my $gain = perc_defeat($rps->{$p2}{level} - $rps->{$p1}{level})*0.70; $gain *= 1.2 if ($wanted); $gain = int(($gain/100)*$rps->{$p1}{next}); $gain = $rps->{$p1}{class}->real_gain($gain); @@ -178,13 +208,13 @@ sub steal_result { " own demise."); Irpg::Irc::notice( "You (rightfully) acquired a new level $item2 $type, which ". - "looks far better than your old level $item1 $type! ". + "looks far better than your old level $item1 $type! ". "You left your old one to whom you took the new from.", $rps->{$p1}{nick}); Irpg::Irc::notice( "Waking up from your daydreaming, you realize your level ". "$item2 $type has been stolen, and replaced by a level ". - "$item1 $type!", + "$item1 $type!", $rps->{$p2}{nick}); } else { @@ -199,7 +229,7 @@ sub steal_result { my $type = "ring"; my $val = 0; while( my ($k,$v) = each(%{$rps->{$p2}{item}}) ) { - my ($v_d,) = $v =~ m/(\d+)\D?/; + my ($v_d,) = $v =~ m/(\d+)\D?/; ($type, $val) = ($k, $v_d) if ($v_d > $val) } my ($item1,) = $rps->{$p1}{item}{$type} =~ m/(\d+)\D?/; @@ -216,13 +246,13 @@ sub steal_result { "self."; Irpg::Irc::notice( "You (rightfully) acquired a new level $item2 $type, which ". - "looks far better than your old level $item1 $type! ". + "looks far better than your old level $item1 $type! ". "You left your old one to whom you took the new from.", $rps->{$p1}{nick}); Irpg::Irc::notice( "Waking up from your daydreaming, you realize your level ". "$item2 $type has been stolen, and replaced by a level ". - "$item1 $type!", + "$item1 $type!", $rps->{$p2}{nick}); } else {