X-Git-Url: https://ruin.nu/git/%3CTMPL_VAR%20NAME=PAGE%3E?a=blobdiff_plain;f=Commands%2FPA.pm;h=1db6ac1c8db4f4a3e5d288425ec8f86f3cc73a06;hb=fbf88ef7c837a073498b1fc4902d7301c04ecc4e;hp=0d834846ae6e30b3edb9986f94fd657b5116441f;hpb=21cb796be35d56fc6620af557355ab57b6c00e88;p=NDIRC.git
diff --git a/Commands/PA.pm b/Commands/PA.pm
index 0d83484..1db6ac1 100644
--- a/Commands/PA.pm
+++ b/Commands/PA.pm
@@ -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)
{
@@ -46,11 +55,22 @@ sub p
}
my $f = $c->model->prepare(q{
-SELECT coords(x,y,z),ruler,planet,race,score,size,value,scorerank,sizerank,
- valuerank, xp, xprank, alliance, relationship, nick, planet_status, hit_us, channel
-FROM current_planet_stats WHERE (x = $1 AND y = $2 and z = $3) OR nick ILIKE $4 LIMIT 1
+WITH p AS (SELECT pid,coords(x,y,z),ruler,planet,race,score,size,value,scorerank,sizerank,
+ valuerank, xp, xprank, alliance, relationship, nick, planet_status, hit_us, channel
+ FROM current_planet_stats
+ WHERE (x = $1 AND y = $2 and z = $3) OR nick ILIKE $4 LIMIT 1
+), t AS (SELECT tag,bool_or(uid = $5) AS own,max(time) AS time
+ FROM planet_tags
+ WHERE pid = (SELECT pid FROM p)
+ AND ($6 OR uid = $5)
+ GROUP BY tag
+ ORDER BY time DESC
+), tags AS (SELECT array_to_string(array_agg(tag || CASE WHEN own THEN '*' ELSE '' END),' ') AS tags
+ FROM t
+)
+SELECT * FROM p, tags;
});
- $f->execute($x,$y,$z,$nick);
+ $f->execute($x,$y,$z,$nick,$c->uid,$c->check_user_roles(qw/irc_p_intel/) // 0);
if (my $planet = $f->fetchrow_hashref()){
for (keys %{$planet}){
$planet->{$_} = valuecolor(1,$planet->{$_});
@@ -59,7 +79,7 @@ FROM current_planet_stats WHERE (x = $1 AND y = $2 and z = $3) OR nick ILIKE $4
if ($c->check_user_roles(qw/irc_p_intel/)){
$ally = "Alliance=$planet->{alliance} ($planet->{relationship}), Nick=$planet->{nick} ($planet->{planet_status}), Channel: $planet->{channel}, Hostile Count: $planet->{hit_us},";
}
- $c->reply("$planet->{coords} $planet->{ruler} OF $planet->{planet},$ally Race=$planet->{race}, Score=$planet->{score} ($planet->{scorerank}), Size=$planet->{size} ($planet->{sizerank}), Value=$planet->{value} ($planet->{valuerank}), XP=$planet->{xp} ($planet->{xprank})");
+ $c->reply("$planet->{coords} $planet->{ruler} OF $planet->{planet},$ally Race=$planet->{race}, Score=$planet->{score} ($planet->{scorerank}), Size=$planet->{size} ($planet->{sizerank}), Value=$planet->{value} ($planet->{valuerank}), XP=$planet->{xp} ($planet->{xprank}) TAGS: $planet->{tags}");
}else{
$c->reply("Couldn't find planet: $msg");
}
@@ -71,16 +91,33 @@ sub g
my ($self, $c, $msg) = @_;
my ($x,$y) = ($msg =~ /(\d+)\D+(\d+)/) or die 'ARGS';
+ my $dbh = $c->model;
- my $f = $c->model->prepare(q{
+ my $f = $dbh->prepare(q{
SELECT score,scorerank,size,sizerank,value,valuerank,planets
FROM galaxies WHERE x = ? AND y = ? AND tick = (SELECT max(tick) from galaxies)
- });
+ });
$f->execute($x,$y);
- while (my @row = $f->fetchrow()){
- @row = map (valuecolor(1),@row);
- $c->reply("$x:$y Score=$row[0] ($row[1]), Size=$row[2] ($row[3]), Value=$row[4] ($row[5]), Planets=$row[6]");
+ my @row = $f->fetchrow;
+ unless (@row){
+ $c->reply("No planet at $x:$y");
+ return;
+ }
+ my @planets;
+ if ($c->check_user_roles(qw/irc_g_intel/)) {
+ my $query = $dbh->prepare(q{
+SELECT z,COALESCE(nick,'?') AS nick,COALESCE(alliance,'?') AS alliance
+FROM current_planet_stats
+WHERE x = $1 AND y = $2 ORDER BY z
+ });
+ $query->execute($x,$y);
+ while(my $p = $query->fetchrow_hashref){
+ push @planets, "$p->{z} [$p->{nick}/$p->{alliance}]";
+ }
}
+ @row = map (valuecolor(1),@row);
+ $c->reply("$x:$y Score=$row[0] ($row[1]), Size=$row[2] ($row[3]), Value=$row[4] ($row[5]), Planets=$row[6] - "
+ . join " ", @planets);
}
sub time
@@ -108,7 +145,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 +154,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 +180,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 $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,");
+ $cap = sprintf "%.1f", $cap*100;
+ $c->reply("You will gain $xp XP, $score score, if you steal $roids roids ($value value, $cap% cap), from $x:$y:$z, who will have $tsize roids left, total score gain will be: $totscore in total,");
}
sub fco
@@ -157,16 +195,16 @@ 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)
-WHERE ps.tick = $1 AND (2000.0*$2*$3/ps.value)::int = $4
+ 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);
if ($attackers->rows == 0){