]> ruin.nu Git - NDIRC.git/blob - PA.pm
remove debug output, and truncate the target size
[NDIRC.git] / PA.pm
1 #**************************************************************************
2 #   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
3 #                                                                         *
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.                                   *
8 #                                                                         *
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.                          *
13 #                                                                         *
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 #**************************************************************************/
19 package ND::IRC::PA;
20 use strict;
21 use warnings;
22 use ND::DB;
23 use ND::Include;
24 use ND::IRC::Access;
25 use ND::IRC::Misc;
26 use POSIX;
27 require Exporter;
28
29 our @ISA = qw/Exporter/;
30
31 our @EXPORT = qw/checkPlanet checkGal shipEff shipStop parseValue prettyValue calcXp/;
32
33 sub checkPlanet {
34         my ($x,$y,$z,$intel) = @_;
35         DB();
36         my $f = $ND::DBH->prepare("SELECT ruler,planet,race,score,size,value,scorerank,sizerank,valuerank, xp, xprank, alliance FROM current_planet_stats WHERE x = ? AND y = ? and z = ?");
37         $f->execute($x,$y,$z);
38         while (my @row = $f->fetchrow()){
39                 @row = map (valuecolor(1),@row);
40                 my $ally = "";
41                 $ally = " Alliance=$row[11]," if $intel;
42                 $ND::server->command("notice $ND::target $x:$y:$z $row[0] OF $row[1],$ally Race=$row[2], Score=$row[3] ($row[6]), Size=$row[4] ($row[7]), Value=$row[5] ($row[8]), XP=$row[9] ($row[10])");
43         }
44 }
45 sub checkGal {
46         my ($x,$y) = @_;
47         DB();
48         my $f = $ND::DBH->prepare("SELECT name,score,size,value FROM galaxies WHERE x = ? AND y = ? and tick = (SELECT max(tick) from galaxies)");
49         $f->execute($x,$y);
50         while (my @row = $f->fetchrow()){
51                 @row = map (valuecolor(1),@row);
52                 $ND::server->command("notice $ND::target $x:$y $row[0], Score=$row[1], Size=$row[2], Value=$row[3]");
53         }
54 }
55
56 sub shipEff {
57         my ($amount,$ship,$value) = @_;
58         $ship = "\%$ship\%";
59         $amount = parseValue($amount);
60         $value = parseValue($value);
61         $value *= -1.5 if defined $value and $value < 0;
62
63         my @ship = $ND::DBH->selectrow_array(q{
64 SELECT name,target,"type",damage,metal+crystal+eonium,init,"class",guns,race
65 FROM ship_stats WHERE name ILIKE ?
66                 }, undef, $ship);
67         if (@ship){
68                 my $type = "kill";
69                 $type = "stun" if $ship[2] eq 'Emp';
70                 $type = "steal" if ($ship[2] eq 'Steal') or ($ship[2] eq 'Pod');
71
72                 $amount = int(($value*100/$ship[4])) if $amount eq 'value';
73                 $value = prettyValue(($amount*$ship[4]/100));
74                 my $text = "$amount $ship[0] ($ship[5]:$value) will $type:";
75                 my $st = $ND::DBH->prepare(q{
76                         SELECT name,"class","type",armor,metal+crystal+eonium,init,target,eres,race
77                         FROM ship_stats WHERE "class" = ?
78                         });
79                 $st->execute($ship[1]);
80                 while (my @target = $st->fetchrow()){
81                         my $dead = $ship[2] eq 'Emp' ? int($amount*$ship[7]*(100-$target[7])/100) : int($amount*$ship[3]/$target[3]);
82                         $value = prettyValue($dead*$target[4]/100);
83                         if (($target[6] eq $ship[6]) and ($target[5] <= $ship[5])){
84                                 $target[5] = "${ND::C}04$target[5]$ND::C";
85                         }elsif(($target[6] eq $ship[6]) and ($target[5] > $ship[5])){
86                                 $target[5] = "${ND::C}12$target[5]$ND::C";
87                         }
88                         $target[0] = "${ND::C}04$target[0]$ND::C" if $target[2] eq 'Norm' || $target[2] eq 'Cloak';
89                         $target[0] = "${ND::C}12$target[0]$ND::C" if $target[2] eq 'Emp';
90                         $target[0] = "${ND::C}13$target[0]$ND::C" if $target[2] eq 'Steal';
91                         $text .= " $ND::B$dead$ND::B $target[0] ($target[5]:$value),";
92                 }
93                 chop $text;
94                 $ND::server->command("notice $ND::target $text");
95         }
96         #print $text;
97 }
98
99 sub shipStop {
100         my ($amount,$ship,$value) = @_;
101         $ship = "\%$ship\%";
102         $amount = parseValue($amount);
103         $value = parseValue($value);
104         $value *= -1.5 if defined $value and $value < 0;
105
106         my @ship = $ND::DBH->selectrow_array(q{
107 SELECT name,target,"type",armor,metal+crystal+eonium,init,"class",eres,race
108 FROM ship_stats WHERE name ILIKE ?
109                 }, undef, $ship);
110         if (@ship){
111                 $ship[0] = "${ND::C}04$ship[0]$ND::C" if $ship[2] eq 'Norm';
112                 $ship[0] = "${ND::C}12$ship[0]$ND::C" if $ship[2] eq 'Emp';
113                 $ship[0] = "${ND::C}13$ship[0]$ND::C" if $ship[2] eq 'Steal';
114
115                 $amount = int(($value*100/$ship[4])) if $amount eq 'value';
116                 $value = prettyValue(($amount*$ship[4]/100));
117                 my $text = "To stop $amount $ship[0] ($ship[5]:$value) you need:";
118                 my $st = $ND::DBH->prepare(q{
119                         SELECT name,"class","type",damage,metal+crystal+eonium,init,target,guns,race
120                         FROM ship_stats WHERE "target" = ?
121                         });
122                 $st->execute($ship[6]);
123                 while (my @stopper = $st->fetchrow()){
124                         my $needed = $stopper[2] eq 'Emp' ? ceil($amount*100/(100-$ship[7])/$stopper[7]) : ceil($amount*$ship[3]/$stopper[3]);
125                         $value = prettyValue($needed*$stopper[4]/100);
126                         if (($stopper[1] eq $ship[1]) and ($ship[5] <= $stopper[5])){
127                                 $stopper[5] = "${ND::C}04$stopper[5]$ND::C";
128                         }elsif(($stopper[1] eq $ship[1]) and ($ship[5] > $stopper[5])){
129                                 $stopper[5] = "${ND::C}12$stopper[5]$ND::C";
130                         }
131                         $stopper[0] = "${ND::C}04$stopper[0]$ND::C" if $stopper[2] eq 'Norm' || $stopper[2] eq 'Cloak';
132                         $stopper[0] = "${ND::C}12$stopper[0]$ND::C" if $stopper[2] eq 'Emp';
133                         $stopper[0] = "${ND::C}13$stopper[0]$ND::C" if $stopper[2] eq 'Steal';
134                         $text .= " $ND::B$needed$ND::B $stopper[0] ($stopper[5]:$value),";
135                 }
136                 chop $text;
137                 $ND::server->command("notice $ND::target $text");
138         }
139         #print $text;
140 }
141
142 sub calcXp {
143         my ($x,$y,$z,$roids,$cap) = @_;
144
145         my ($avalue,$ascore) = $ND::DBH->selectrow_array(q{
146                 SELECT value,score FROM current_planet_stats WHERE 
147                         id = (SELECT planet FROM users WHERE hostmask ILIKE ?);
148                 }, undef, $ND::address);
149         my ($tvalue,$tscore,$tsize) = $ND::DBH->selectrow_array(q{
150                 SELECT value,score,size FROM current_planet_stats WHERE 
151                 x = ? AND y = ? and z = ?;
152                 }, undef, $x,$y,$z);
153         $cap = 0.25 unless $cap;
154         unless($roids){
155                 $roids = int($tsize*$cap);
156         }elsif ($roids < 10){
157                 $tsize *= int(.75**($roids-1));
158                 $roids = int($cap*$tsize);
159         }
160         $tsize -= $roids;
161         unless (defined $avalue && defined $ascore){
162                 $ND::server->command("notice $ND::target You don't have a planet specified");
163                 return;
164         }
165         unless (defined $tvalue && defined $tscore){
166                 $ND::server->command("notice $ND::target Doesn't seem to be a planet at $x:$y:$z");
167                 return;
168         }
169         my $xp = int(max($roids * 10 * (min(2,$tscore/$ascore) + min(2,$tvalue/$avalue) - 1),0));
170         my $score = 60 * $xp;
171         my $value = $roids*200;
172         my $totscore = prettyValue($score + $value);
173         $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,");
174 }
175
176 1;