]> ruin.nu Git - NDIRC.git/blobdiff - Commands/PA.pm
Introduce a uid member for the context and use it intead of the host in commands
[NDIRC.git] / Commands / PA.pm
index 811d102dab3a8ee8ab4386d8ca4cff22ed13d29f..52fb3a007a1241c3cdc9e234f3c244cc3defde45 100644 (file)
@@ -25,10 +25,19 @@ use feature ':5.10';
 
 use Moose;
 use MooseX::MethodAttributes;
+use POSIX qw/pow/;
 
 use NDIRC::Misc;
 use ND::Include;
 
+
+sub bcalc
+       : Help(Lists bcalc and stats info)
+{
+       my ($self, $c, $msg) = @_;
+       $c->reply("http://game.planetarion.com/bcalc.pl http://game.planetarion.com/manual.php?page=stats");
+}
+
 sub p
        : Help(usage: .p X:Y:Z | or .p nick with high enough access)
 {
@@ -108,7 +117,7 @@ SELECT date_trunc('seconds',now() + (($1 - tick()) || ' hr')::interval) AT TIME
 }
 
 sub xp
-       : Help(syntax: .xp X:Y:Z [roids] [cap] | if roids < 10 then it's taken as the wave, cap is a floating point number, defaults to 0.25)
+       : Help(syntax: .xp X:Y:Z [roids] [cap] | if roids < 10 then it's taken as the wave, cap is a floating point number, defaults to cap according to your value)
 {
        my ($self, $c, $msg) = @_;
 
@@ -117,17 +126,17 @@ sub xp
 
        my ($avalue,$ascore) = $c->model->selectrow_array(q{
 SELECT value,score FROM current_planet_stats
-WHERE id = (SELECT planet FROM users WHERE hostmask ILIKE ?)
-               }, undef, $c->host);
+WHERE pid = (SELECT pid FROM users WHERE uid = ?)
+               }, undef, $c->uid);
        my ($tvalue,$tscore,$tsize) = $c->model->selectrow_array(q{
 SELECT value,score,size FROM current_planet_stats
 WHERE x = ? AND y = ? and z = ?
                }, undef, $x,$y,$z);
-       $cap //= 0.25;
+       $cap //= min(0.25,0.25 * pow($tvalue/$avalue , 0.5));
        unless($roids){
                $roids = int($tsize*$cap);
        }elsif ($roids < 10){
-               $tsize = ceil($tsize*.75**($roids-1));
+               $tsize = int($tsize*.75**($roids-1));
                $roids = int($cap*$tsize);
        }
        $tsize -= $roids;
@@ -143,7 +152,8 @@ WHERE x = ? AND y = ? and z = ?
        my $score = 60 * $xp;
        my $value = $roids*200;
        my $totscore = prettyValue($score + $value);
-       $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,");
+       $cap = sprintf "%.1f", $cap*100;
+       $c->reply("You will gain <b>$xp</b> XP, <b>$score</b> score, if you steal <b>$roids</b> roids (<b>$value</b> value, <b>$cap%</b> cap), 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
@@ -157,15 +167,15 @@ sub fco
 
        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);
+       pid = (SELECT pid FROM users WHERE uid = $1)
+               }, undef, $c->uid,$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)
+       JOIN planet_stats ps using (pid)
 WHERE ps.tick = $1 AND trunc(2000.0*$2*$3/ps.value)::int = $4
                });
        $attackers->execute($tick,$agents,$value,$stolen);