1 #**************************************************************************
2 # Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu> *
4 # This program is free software; you can redistribute it and/or modify *
5 # it under the terms of the GNU General Public License as published by *
6 # the Free Software Foundation; either version 2 of the License, or *
7 # (at your option) any later version. *
9 # This program is distributed in the hope that it will be useful, *
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 # GNU General Public License for more details. *
14 # You should have received a copy of the GNU General Public License *
15 # along with this program; if not, write to the *
16 # Free Software Foundation, Inc., *
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 #**************************************************************************/
29 our @ISA = qw/Exporter/;
31 our @EXPORT = qw/checkPlanet checkGal shipEff shipStop parseValue prettyValue calcXp/;
37 if ($msg =~ /(\d+)\D+(\d+)\D+(\d+)/){
44 $ND::server->command("notice $ND::target usage .p X:Y:Z".(officer() ? ' or .p nick' : ''));
47 my $f = $ND::DBH->prepare(q{SELECT coords(x,y,z),ruler,planet,race,score,size,value,scorerank,sizerank,
48 valuerank, xp, xprank, alliance, relationship, nick, planet_status, hit_us, channel
49 FROM current_planet_stats WHERE (x = $1 AND y = $2 and z = $3) OR nick ILIKE $4 LIMIT 1
51 $f->execute($x,$y,$z,$nick);
52 if (my $planet = $f->fetchrow_hashref()){
53 for (keys %{$planet}){
54 $planet->{$_} = valuecolor(1,$planet->{$_});
57 if (officer() || dc()){
58 $ally = "Alliance=$planet->{alliance} ($planet->{relationship}), Nick=$planet->{nick} ($planet->{planet_status}), Channel: $planet->{channel}, Hostile Count: $planet->{hit_us},";
60 $ND::server->command("notice $ND::target $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})");
62 $ND::server->command("notice $ND::target Couldn't find planet: $msg");
68 my $f = $ND::DBH->prepare("SELECT name,score,size,value FROM galaxies WHERE x = ? AND y = ? and tick = (SELECT max(tick) from galaxies)");
70 while (my @row = $f->fetchrow()){
71 @row = map (valuecolor(1),@row);
72 $ND::server->command("notice $ND::target $x:$y $row[0], Score=$row[1], Size=$row[2], Value=$row[3]");
77 my ($amount,$ship,$value) = @_;
79 $amount = parseValue($amount);
80 $value = parseValue($value);
81 $value *= -1.5 if defined $value and $value < 0;
84 my @ship = $ND::DBH->selectrow_array(q{
85 SELECT name,target,"type",damage,metal+crystal+eonium,init,"class",guns,race
86 FROM ship_stats WHERE name ILIKE ?
90 $type = "stun" if $ship[2] eq 'Emp';
91 $type = "steal" if ($ship[2] eq 'Steal') or ($ship[2] eq 'Pod');
93 $amount = int(($value*100/$ship[4])) if $amount eq 'value';
94 $feud = '(FEUD: '.int($amount/0.75).') ' if defined $value;
95 $value = prettyValue(($amount*$ship[4]/100));
96 my $text = "$amount $feud $ship[0] ($ship[5]:$value) will $type:";
97 my $st = $ND::DBH->prepare(q{
98 SELECT name,"class","type",armor,metal+crystal+eonium,init,target,eres,race
99 FROM ship_stats WHERE "class" = ?
101 $st->execute($ship[1]);
102 while (my @target = $st->fetchrow()){
103 my $dead = $ship[2] eq 'Emp' ? int($amount*$ship[7]*(100-$target[7])/100) : int($amount*$ship[3]/$target[3]);
104 $value = prettyValue($dead*$target[4]/100);
105 if (($target[6] eq $ship[6]) and ($target[5] <= $ship[5])){
106 $target[5] = "${ND::C}04$target[5]$ND::C";
107 }elsif(($target[6] eq $ship[6]) and ($target[5] > $ship[5])){
108 $target[5] = "${ND::C}12$target[5]$ND::C";
110 $target[0] = "${ND::C}04$target[0]$ND::C" if $target[2] eq 'Norm' || $target[2] eq 'Cloak';
111 $target[0] = "${ND::C}12$target[0]$ND::C" if $target[2] eq 'Emp';
112 $target[0] = "${ND::C}13$target[0]$ND::C" if $target[2] eq 'Steal';
113 $text .= " $ND::B$dead$ND::B $target[0] ($target[5]:$value),";
116 $ND::server->command("notice $ND::target $text");
122 my ($amount,$ship,$value) = @_;
124 $amount = parseValue($amount);
125 $value = parseValue($value);
126 $value *= -1.5 if defined $value and $value < 0;
129 my @ship = $ND::DBH->selectrow_array(q{
130 SELECT name,target,"type",armor,metal+crystal+eonium,init,"class",eres,race
131 FROM ship_stats WHERE name ILIKE ?
134 $ship[0] = "${ND::C}04$ship[0]$ND::C" if $ship[2] eq 'Norm';
135 $ship[0] = "${ND::C}12$ship[0]$ND::C" if $ship[2] eq 'Emp';
136 $ship[0] = "${ND::C}13$ship[0]$ND::C" if $ship[2] eq 'Steal';
138 $amount = int(($value*100/$ship[4])) if $amount eq 'value';
139 $feud = '(FEUD: '.int($amount/0.75).') ' if defined $value;
140 $value = prettyValue(($amount*$ship[4]/100));
141 my $text = "To stop $amount $feud $ship[0] ($ship[5]:$value) you need:";
142 my $st = $ND::DBH->prepare(q{
143 SELECT name,"class","type",damage,metal+crystal+eonium,init,target,guns,race
144 FROM ship_stats WHERE "target" = ?
146 $st->execute($ship[6]);
147 while (my @stopper = $st->fetchrow()){
148 my $needed = $stopper[2] eq 'Emp' ? ceil($amount*100/(100-$ship[7])/$stopper[7]) : ceil($amount*$ship[3]/$stopper[3]);
149 $value = prettyValue($needed*$stopper[4]/100);
150 if (($stopper[1] eq $ship[1]) and ($ship[5] <= $stopper[5])){
151 $stopper[5] = "${ND::C}04$stopper[5]$ND::C";
152 }elsif(($stopper[1] eq $ship[1]) and ($ship[5] > $stopper[5])){
153 $stopper[5] = "${ND::C}12$stopper[5]$ND::C";
155 $stopper[0] = "${ND::C}04$stopper[0]$ND::C" if $stopper[2] eq 'Norm' || $stopper[2] eq 'Cloak';
156 $stopper[0] = "${ND::C}12$stopper[0]$ND::C" if $stopper[2] eq 'Emp';
157 $stopper[0] = "${ND::C}13$stopper[0]$ND::C" if $stopper[2] eq 'Steal';
158 $text .= " $ND::B$needed$ND::B $stopper[0] ($stopper[5]:$value),";
161 $ND::server->command("notice $ND::target $text");
167 my ($x,$y,$z,$roids,$cap) = @_;
169 my ($avalue,$ascore) = $ND::DBH->selectrow_array(q{
170 SELECT value,score FROM current_planet_stats WHERE
171 id = (SELECT planet FROM users WHERE hostmask ILIKE ?);
172 }, undef, $ND::address);
173 my ($tvalue,$tscore,$tsize) = $ND::DBH->selectrow_array(q{
174 SELECT value,score,size FROM current_planet_stats WHERE
175 x = ? AND y = ? and z = ?;
177 $cap = 0.25 unless $cap;
179 $roids = int($tsize*$cap);
180 }elsif ($roids < 10){
181 $tsize = ceil($tsize*.75**($roids-1));
182 $roids = int($cap*$tsize);
185 unless (defined $avalue && defined $ascore){
186 $ND::server->command("notice $ND::target You don't have a planet specified");
189 unless (defined $tvalue && defined $tscore){
190 $ND::server->command("notice $ND::target Doesn't seem to be a planet at $x:$y:$z");
193 my $xp = pa_xp($roids,$ascore,$avalue,$tscore,$tvalue);
194 my $score = 60 * $xp;
195 my $value = $roids*200;
196 my $totscore = prettyValue($score + $value);
197 $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,");