diff --git a/Irpg/Event.pm b/Irpg/Event.pm index 6143528ab719b36706b2424a158e927269a9e21c..c231fc2d3a759481009176f45daf63d3e3069646 100644 --- a/Irpg/Event.pm +++ b/Irpg/Event.pm @@ -6,7 +6,7 @@ use Irpg::Utils qw(:text); use Irpg::Irc qw(:interaction); use Irpg::Action; use Exporter qw(import); -our @EXPORT = qw(find_item); +our @EXPORT = qw(find_item evilchase); our @EXPORT_OK = qw(hog); my $opts; @@ -348,23 +348,56 @@ sub evilness { } } +sub evilchase { + my ($player, $positions) = @_; + return unless ($player && $positions); + my ($x_pos, $y_pos) = ($rps->{$player}{x}, $rps->{$player}{y}); + my @opps = (); + for (my $x = $x_pos-3; $x <= $x_pos+3; $x++) { + for (my $y = $y_pos-3; $y <= $y_pos+3; $y++) { + if (exists($positions->{x}{y}) && + $positions->{x}{y}{user} ne $player) { + push @opps, $positions->{x}{y}{user}; + } + } + } + return unless (@opps); + my $opp = $opps[int(rand(@opps))]; + Irpg::Irc::chanmsg("$player, full of hatred and disdain for ". + pronoun(2, $rps->{$player}{gender})." kind, has chased ". + "after $opp who passed by."); + collision_action($player, $opp); +} + + sub goodness { my @players = grep { $rps->{$_}{alignment} eq "g" && $rps->{$_}{online} } keys(%$rps); return unless @players > 1; - splice(@players,int(rand(@players)),1) while @players > 2; - my $gain = 5 + int(rand(8)); - Irpg::Irc::chanmsg(Irpg::Utils::clog( - "$players[0] and $players[1] have not let the iniquities of ". - "evil men poison them. Together have they prayed to their ". - "god, and it is his light that now shines upon them. $gain\% ". - "of their time is removed from their clocks.")); - $rps->{$players[0]}{next} += int($rps->{$players[0]}{class}->real_gain(-$gain/100)); - $rps->{$players[1]}{next} += int($rps->{$players[1]}{class}->real_gain(-$gain/100)); - Irpg::Irc::chanmsg("$players[0] reaches next level in ". - duration($rps->{$players[0]}{next})."."); - Irpg::Irc::chanmsg("$players[1] reaches next level in ". - duration($rps->{$players[1]}{next})."."); + if (int(rand(2)) < 1) { + splice(@players,int(rand(@players)),1) while @players > 2; + my $gain = 5 + int(rand(8)); + Irpg::Irc::chanmsg(Irpg::Utils::clog( + "$players[0] and $players[1] have not let the iniquities of ". + "evil men poison them. Together have they prayed to their ". + "God, and it is his light that now shines upon them. $gain\% ". + "of their time is removed from their clocks.")); + $rps->{$players[0]}{next} += int($rps->{$players[0]}{class}->real_gain(-$gain/100)); + $rps->{$players[1]}{next} += int($rps->{$players[1]}{class}->real_gain(-$gain/100)); + Irpg::Irc::chanmsg("$players[0] reaches next level in ". + duration($rps->{$players[0]}{next})."."); + Irpg::Irc::chanmsg("$players[1] reaches next level in ". + duration($rps->{$players[1]}{next})."."); + } + else { + my $user = $players[int(rand(@players))]; + Irpg::Irc::chanmsg(Irpg::Utils::clog( + "$user has been good to ". + pronoun(2, $rps->{$user}{gender})." kind, and ". + pronoun(2, $rps->{$user}{gender})." God has rewarded ". + pronoun(3, $rps->{$user}{gender})." with a new piece of equipment")); + find_item($user); + } } sub rpcheck { diff --git a/Irpg/Main.pm b/Irpg/Main.pm index 5fd1ba7474762154d006ed615cc9bb720cdb3acd..d4c2f66c3addeebb73a291e60a4367d213c3750c 100644 --- a/Irpg/Main.pm +++ b/Irpg/Main.pm @@ -200,6 +200,7 @@ sub moveplayers { # temporary hash to hold player positions, detect collisions my @questers = movequesters(); my %positions = (); + my @who_fought = (); for my $player (keys(%$rps)) { next unless ($rps->{$player}{online}); next if (!$questers[0] || grep { $player eq $_ } @questers); @@ -223,12 +224,20 @@ sub moveplayers { $positions{$rps->{$player}{x}}{$rps->{$player}{y}}{battled}=1; collision_action($player, $positions{$rps->{$player}{x}}{$rps->{$player}{y}}{user}); + push @who_fought, $player; } } else { $positions{$rps->{$player}{x}}{$rps->{$player}{y}}{battled}=0; $positions{$rps->{$player}{x}}{$rps->{$player}{y}}{user}=$player; } + # at the last move, evil users who has not fought + # chase near players + if ($i == $opts->{self_clock}-1 + && $rps->{$player}{alignment} == 'e' + && !(grep { $player eq $_ } @who_fought)) { + evilchase($player, \%positions); + } } } }