X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=PA.pm;h=2eb88b1f3abbcc33cda310d83e650ac589a51aec;hb=480a92ac89c055627316da5d72865be84a0d109d;hp=fbe2a8457de9ddd22f44ee1296dfaa66fbed5e69;hpb=9e84f393649d1ecbc24a94476352a28f49afa458;p=NDIRC.git diff --git a/PA.pm b/PA.pm index fbe2a84..2eb88b1 100644 --- a/PA.pm +++ b/PA.pm @@ -20,6 +20,7 @@ package ND::IRC::PA; use strict; use warnings; use ND::DB; +use ND::Include; use ND::IRC::Access; use ND::IRC::Misc; use POSIX; @@ -27,7 +28,7 @@ require Exporter; our @ISA = qw/Exporter/; -our @EXPORT = qw/checkPlanet checkGal shipEff shipStop parseValue prettyValue/; +our @EXPORT = qw/checkPlanet checkGal shipEff shipStop parseValue prettyValue calcXp/; sub checkPlanet { my ($x,$y,$z,$intel) = @_; @@ -138,50 +139,25 @@ FROM ship_stats WHERE name ILIKE ? #print $text; } -sub parseValue { - if (defined $_[0] && $_[0] =~ /^(-?\d+(?:\.\d+)?)([khMG])?$/){ - return $1 unless defined $2; - return $1*100 if $2 eq 'h'; - return $1*1000 if $2 eq 'k'; - return $1*1000000 if $2 eq 'M'; - return $1*1000000000 if $2 eq 'G'; - } - return $_[0]; -} - -sub prettyValue { - my ($value) = @_; - my $unit = ''; - my @units = ('k','M','G','T'); - for (my $i = 0; $value >= 1000;$i++){ - $value /= 1000; - $unit = $units[$i]; - } - return sprintf('%.2f%s', $value,$unit); -} - - -sub min { - my ($x,$y) = @_; - return ($x > $y ? $y : $x); -} - -sub max { - my ($x,$y) = @_; - return ($x < $y ? $y : $x); -} - sub calcXp { - my ($x,$y,$z,$roids) = @_; + my ($x,$y,$z,$roids,$cap) = @_; my ($avalue,$ascore) = $ND::DBH->selectrow_array(q{ SELECT value,score FROM current_planet_stats WHERE id = (SELECT planet FROM users WHERE hostmask ILIKE ?); }, undef, $ND::address); - my ($tvalue,$tscore) = $ND::DBH->selectrow_array(q{ - SELECT value,score FROM current_planet_stats WHERE - x = ? AND y = ? and z = ?; + my ($tvalue,$tscore,$tsize) = $ND::DBH->selectrow_array(q{ + SELECT value,score,size FROM current_planet_stats WHERE + x = ? AND y = ? and z = ?; }, undef, $x,$y,$z); + $cap = 0.25 unless $cap; + unless($roids){ + $roids = int($tsize*$cap); + }elsif ($roids < 10){ + $tsize = ceil($tsize*.75**($roids-1)); + $roids = int($cap*$tsize); + } + $tsize -= $roids; unless (defined $avalue && defined $ascore){ $ND::server->command("notice $ND::target You don't have a planet specified"); return; @@ -190,9 +166,11 @@ sub calcXp { $ND::server->command("notice $ND::target Doesn't seem to be a planet at $x:$y:$z"); return; } - my $xp = int(max($roids * 10 * (min(2,$tscore/$ascore) + min(2,$tvalue/$avalue) - 1),0)); + my $xp = pa_xp($roids,$ascore,$avalue,$tscore,$tvalue); my $score = 60 * $xp; - $ND::server->command("notice $ND::target You will gain $ND::B$xp$ND::B XP, $ND::B$score$ND::B score, if you steal $roids roids from $x:$y:$z"); + my $value = $roids*200; + my $totscore = prettyValue($score + $value); + $ND::server->command("notice $ND::target You will gain $ND::B$xp$ND::B XP, $ND::B$score$ND::B score, if you steal $roids roids ($ND::B$value$ND::B value), from $ND::B$x:$y:$z$ND::B, who will have $ND::B$tsize$ND::B roids left, total score gain will be: $ND::B$totscore$ND::B in total,"); } 1;