rendered paste bodysub team_battle { # pit three players against three other players
my @opp = grep { $rps{$_}{online} } keys(%rps);
return if @opp < 6;
splice(@opp,int(rand(@opp)),1) while @opp > 6;
fisher_yates_shuffle(\@opp);
my $mysum = itemsum($opp[0],1) + itemsum($opp[1],1) + itemsum($opp[2],1);
my $oppsum = itemsum($opp[3],1) + itemsum($opp[4],1) + itemsum($opp[5],1);
my $gain = $rps{$opp[0]}{next};
for my $p (1,2) {
$gain = $rps{$opp[$p]}{next} if $gain > $rps{$opp[$p]}{next};
}
$gain = int($gain*.20);
my $myroll = int(rand($mysum));
my $opproll = int(rand($oppsum));
if ($myroll >= $opproll) {
chanmsg(clog("$opp[0], $opp[1], and $opp[2] [$myroll/$mysum] have ".
"team battled $opp[3], $opp[4], and $opp[5] [$opproll/".
"$oppsum] and won! ".duration($gain)." is removed from ".
"their clocks."));
$rps{$opp[0]}{next} -= $gain;
$rps{$opp[1]}{next} -= $gain;
$rps{$opp[2]}{next} -= $gain;
}
else {
chanmsg(clog("$opp[0], $opp[1], and $opp[2] [$myroll/$mysum] have ".
"team battled $opp[3], $opp[4], and $opp[5] [$opproll/".
"$oppsum] and lost! ".duration($gain)." is added to ".
"their clocks."));
$rps{$opp[0]}{next} += $gain;
$rps{$opp[1]}{next} += $gain;
$rps{$opp[2]}{next} += $gain;
}
}