]> ruin.nu Git - NDIRC.git/blob - PA.pm
e5f20bf7b42fa743282232816e77c686efa48329
[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         my $feud = '';
63
64         my @ship = $ND::DBH->selectrow_array(q{
65 SELECT name,target,"type",damage,metal+crystal+eonium,init,"class",guns,race
66 FROM ship_stats WHERE name ILIKE ?
67                 }, undef, $ship);
68         if (@ship){
69                 my $type = "kill";
70                 $type = "stun" if $ship[2] eq 'Emp';
71                 $type = "steal" if ($ship[2] eq 'Steal') or ($ship[2] eq 'Pod');
72
73                 $amount = int(($value*100/$ship[4])) if $amount eq 'value';
74                 $feud = '(FEUD: '.int($amount/0.75).') ' if defined $value;
75                 $value = prettyValue(($amount*$ship[4]/100));
76                 my $text = "$amount $feud $ship[0] ($ship[5]:$value) will $type:";
77                 my $st = $ND::DBH->prepare(q{
78                         SELECT name,"class","type",armor,metal+crystal+eonium,init,target,eres,race
79                         FROM ship_stats WHERE "class" = ?
80                         });
81                 $st->execute($ship[1]);
82                 while (my @target = $st->fetchrow()){
83                         my $dead = $ship[2] eq 'Emp' ? int($amount*$ship[7]*(100-$target[7])/100) : int($amount*$ship[3]/$target[3]);
84                         $value = prettyValue($dead*$target[4]/100);
85                         if (($target[6] eq $ship[6]) and ($target[5] <= $ship[5])){
86                                 $target[5] = "${ND::C}04$target[5]$ND::C";
87                         }elsif(($target[6] eq $ship[6]) and ($target[5] > $ship[5])){
88                                 $target[5] = "${ND::C}12$target[5]$ND::C";
89                         }
90                         $target[0] = "${ND::C}04$target[0]$ND::C" if $target[2] eq 'Norm' || $target[2] eq 'Cloak';
91                         $target[0] = "${ND::C}12$target[0]$ND::C" if $target[2] eq 'Emp';
92                         $target[0] = "${ND::C}13$target[0]$ND::C" if $target[2] eq 'Steal';
93                         $text .= " $ND::B$dead$ND::B $target[0] ($target[5]:$value),";
94                 }
95                 chop $text;
96                 $ND::server->command("notice $ND::target $text");
97         }
98         #print $text;
99 }
100
101 sub shipStop {
102         my ($amount,$ship,$value) = @_;
103         $ship = "\%$ship\%";
104         $amount = parseValue($amount);
105         $value = parseValue($value);
106         $value *= -1.5 if defined $value and $value < 0;
107         my $feud = '';
108
109         my @ship = $ND::DBH->selectrow_array(q{
110 SELECT name,target,"type",armor,metal+crystal+eonium,init,"class",eres,race
111 FROM ship_stats WHERE name ILIKE ?
112                 }, undef, $ship);
113         if (@ship){
114                 $ship[0] = "${ND::C}04$ship[0]$ND::C" if $ship[2] eq 'Norm';
115                 $ship[0] = "${ND::C}12$ship[0]$ND::C" if $ship[2] eq 'Emp';
116                 $ship[0] = "${ND::C}13$ship[0]$ND::C" if $ship[2] eq 'Steal';
117
118                 $amount = int(($value*100/$ship[4])) if $amount eq 'value';
119                 $feud = '(FEUD: '.int($amount/0.75).') ' if defined $value;
120                 $value = prettyValue(($amount*$ship[4]/100));
121                 my $text = "To stop $amount $feud $ship[0] ($ship[5]:$value) you need:";
122                 my $st = $ND::DBH->prepare(q{
123                         SELECT name,"class","type",damage,metal+crystal+eonium,init,target,guns,race
124                         FROM ship_stats WHERE "target" = ?
125                         });
126                 $st->execute($ship[6]);
127                 while (my @stopper = $st->fetchrow()){
128                         my $needed = $stopper[2] eq 'Emp' ? ceil($amount*100/(100-$ship[7])/$stopper[7]) : ceil($amount*$ship[3]/$stopper[3]);
129                         $value = prettyValue($needed*$stopper[4]/100);
130                         if (($stopper[1] eq $ship[1]) and ($ship[5] <= $stopper[5])){
131                                 $stopper[5] = "${ND::C}04$stopper[5]$ND::C";
132                         }elsif(($stopper[1] eq $ship[1]) and ($ship[5] > $stopper[5])){
133                                 $stopper[5] = "${ND::C}12$stopper[5]$ND::C";
134                         }
135                         $stopper[0] = "${ND::C}04$stopper[0]$ND::C" if $stopper[2] eq 'Norm' || $stopper[2] eq 'Cloak';
136                         $stopper[0] = "${ND::C}12$stopper[0]$ND::C" if $stopper[2] eq 'Emp';
137                         $stopper[0] = "${ND::C}13$stopper[0]$ND::C" if $stopper[2] eq 'Steal';
138                         $text .= " $ND::B$needed$ND::B $stopper[0] ($stopper[5]:$value),";
139                 }
140                 chop $text;
141                 $ND::server->command("notice $ND::target $text");
142         }
143         #print $text;
144 }
145
146 sub calcXp {
147         my ($x,$y,$z,$roids,$cap) = @_;
148
149         my ($avalue,$ascore) = $ND::DBH->selectrow_array(q{
150                 SELECT value,score FROM current_planet_stats WHERE 
151                         id = (SELECT planet FROM users WHERE hostmask ILIKE ?);
152                 }, undef, $ND::address);
153         my ($tvalue,$tscore,$tsize) = $ND::DBH->selectrow_array(q{
154                 SELECT value,score,size FROM current_planet_stats WHERE 
155                 x = ? AND y = ? and z = ?;
156                 }, undef, $x,$y,$z);
157         $cap = 0.25 unless $cap;
158         unless($roids){
159                 $roids = int($tsize*$cap);
160         }elsif ($roids < 10){
161                 $tsize = ceil($tsize*.75**($roids-1));
162                 $roids = int($cap*$tsize);
163         }
164         $tsize -= $roids;
165         unless (defined $avalue && defined $ascore){
166                 $ND::server->command("notice $ND::target You don't have a planet specified");
167                 return;
168         }
169         unless (defined $tvalue && defined $tscore){
170                 $ND::server->command("notice $ND::target Doesn't seem to be a planet at $x:$y:$z");
171                 return;
172         }
173         my $xp = pa_xp($roids,$ascore,$avalue,$tscore,$tvalue);
174         my $score = 60 * $xp;
175         my $value = $roids*200;
176         my $totscore = prettyValue($score + $value);
177         $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,");
178 }
179
180 1;