From 944bc0326027cf0746351c3d2aad255da7ef3a6a Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Fri, 8 May 2009 18:37:41 +0200 Subject: [PATCH] Converted the .fco command --- Commands/PA.pm | 34 ++++++++++++++++++++++++++++++++++ PA.pm | 42 ------------------------------------------ 2 files changed, 34 insertions(+), 42 deletions(-) diff --git a/Commands/PA.pm b/Commands/PA.pm index a71e897..b629592 100644 --- a/Commands/PA.pm +++ b/Commands/PA.pm @@ -146,4 +146,38 @@ WHERE x = ? AND y = ? and z = ? $c->reply("You will gain $xp XP, $score score, if you steal $roids roids ($value value), from $x:$y:$z, who will have $tsize roids left, total score gain will be: $totscore in total,"); } +sub fco + : Help(syntax: .fco agents stolen [tick] | tick can be omitted if you're doing this the same tick you got cov opped, if you have different amount of your resources stolen, specify the highest amount. Only works if less than 10% of your resources and < 10,000*agents were stolen) +{ + my ($self, $c, $msg) = @_; + + my ($agents,$stolen,$tick) = $msg =~ /^(\d+)\s+(\d+)\s*(\d+)?$/ or die 'ARGS'; + + $tick //= $c->model->selectrow_array(q{SELECT tick()}); + + my ($value,$score) = $c->model->selectrow_array(q{ +SELECT value,score FROM planet_stats WHERE tick = $2 AND + id = (SELECT planet FROM users WHERE hostmask ILIKE $1) + }, undef, $c->host,$tick); + unless ($value){ + $c->reply("You don't have a planet registered."); + return; + } + my $attackers = $c->model->prepare(q{ +SELECT coords(p.x,p.y,p.z), ruler, planet FROM current_planet_stats p + JOIN planet_stats ps using (id) +WHERE ps.tick = $1 AND (2000.0*$2*$3/ps.value)::int = $4 + }); + $attackers->execute($tick,$agents,$value,$stolen); + if ($attackers->rows == 0){ + $c->reply("No cov opper found, did you specify the right tick, and was the stolen amount not capped?"); + }else{ + my $coords = ''; + while (my $attacker = $attackers->fetchrow_hashref){ + $coords .= " ($attacker->{coords} : $attacker->{ruler} OF $attacker->{planet})"; + } + $c->reply("The planet that cov opped you is one of: $coords"); + } +} + 1; diff --git a/PA.pm b/PA.pm index 1eb7675..094c567 100644 --- a/PA.pm +++ b/PA.pm @@ -145,46 +145,4 @@ sub shipColor { return "$ND::C$c$string$ND::O"; } -sub findCovOpper { - my ($stolen, $command) = @_; - - my $tick = $ND::tick; - my $agents; - - if (defined $stolen && $stolen =~ /(\d+) (\d+) (\d+)/){ - $tick = $1; - $agents = $2; - $stolen = $3; - }elsif (defined $stolen && $stolen =~ /(\d+) (\d+)/){ - $agents = $1; - $stolen = $2; - }else{ - $ND::server->command("notice $ND::nick syntax: .$command [tick] agents stolen | tick can be omitted if you're doing this the same tick you got cov opped, if you have different amount of your resources stolen, specify the highest amount. Only works if less than 10% of your resources and < 10,000*agents were stolen"); - return; - } - - my ($value,$score) = $ND::DBH->selectrow_array(q{ - SELECT value,score FROM planet_stats WHERE - id = (SELECT planet FROM users WHERE hostmask ILIKE ?) AND tick = ?; - }, undef, $ND::address,$tick); - unless ($value){ - $ND::server->command("notice $ND::nick No value found for tick $tick, can't find your cov opper."); - return; - } - my $attackers = $ND::DBH->prepare(q{ - SELECT coords(p.x,p.y,p.z), ruler, planet FROM current_planet_stats p JOIN planet_stats ps using (id) WHERE - ps.tick = $1 AND (2000.0*$2*$3/ps.value)::int = $4 ; - }); - $attackers->execute($tick,$agents,$value,$stolen); - if ($attackers->rows == 0){ - $ND::server->command("notice $ND::nick No cov opper found, did you specify the right tick, and was the stolen amount not capped?"); - return; - } - my $coords = ''; - while (my $attacker = $attackers->fetchrow_hashref){ - $coords .= " ($attacker->{coords} : $attacker->{ruler} OF $attacker->{planet})"; - } - $ND::server->command("notice $ND::nick The planet that cov opped you is one of: $coords"); -} - 1; -- 2.39.2