]> ruin.nu Git - NDIRC.git/commitdiff
Converted the .fco command
authorMichael Andreen <harv@ruin.nu>
Fri, 8 May 2009 16:37:41 +0000 (18:37 +0200)
committerMichael Andreen <harv@ruin.nu>
Sat, 9 May 2009 13:35:50 +0000 (15:35 +0200)
Commands/PA.pm
PA.pm

index a71e897b3d6eb81239aaf4e861fa0d27c1d6ae80..b629592f9216af1eede5465c3251c7f619e04581 100644 (file)
@@ -146,4 +146,38 @@ WHERE x = ? AND y = ? and z = ?
        $c->reply("You will gain <b>$xp</b> XP, <b>$score</b> score, if you steal $roids roids (<b>$value</b> value), from <b>$x:$y:$z</b>, who will have <b>$tsize</b> roids left, total score gain will be: <b>$totscore</b> 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 1eb767520d5a478d1c475575865d7b5ea2287893..094c5671df25dcda4e952684b5db31d940a6cf8f 100644 (file)
--- 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;