| 1 |
<?php |
| 2 |
/** |
| 3 |
* File functions: |
| 4 |
* Core arena |
| 5 |
* |
| 6 |
* @name : core.php |
| 7 |
* @copyright : (C) 2004,2005,2006,2007 Vallheru Team based on Gamers-Fusion ver 2.5 |
| 8 |
* @author : thindil <thindil@users.sourceforge.net> |
| 9 |
* @author : eyescream <tduda@users.sourceforge.net> |
| 10 |
* @author : Marek 'marq' Chodor <marek.chodor@gmail.com> |
| 11 |
* @version : 1.3 |
| 12 |
* @since : 10.09.2007 |
| 13 |
* |
| 14 |
*/ |
| 15 |
|
| 16 |
// |
| 17 |
// |
| 18 |
// This program is free software; you can redistribute it and/or modify |
| 19 |
// it under the terms of the GNU General Public License as published by |
| 20 |
// the Free Software Foundation; either version 2 of the License, or |
| 21 |
// (at your option) any later version. |
| 22 |
// |
| 23 |
// This program is distributed in the hope that it will be useful, |
| 24 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 25 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 26 |
// GNU General Public License for more details. |
| 27 |
// |
| 28 |
// You should have received a copy of the GNU General Public License |
| 29 |
// along with this program; if not, write to the Free Software |
| 30 |
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 31 |
// |
| 32 |
// $Id$ |
| 33 |
|
| 34 |
/** |
| 35 |
* function returns found core's id from random number |
| 36 |
*/ |
| 37 |
function whichcore ($number) { |
| 38 |
if ($number > 1156) return 0; |
| 39 |
if ($number > 1153) return 30; |
| 40 |
if ($number > 1148) return 29; |
| 41 |
if ($number > 1143) return 28; |
| 42 |
if ($number > 1136) return 27; |
| 43 |
if ($number > 1129) return 26; |
| 44 |
if ($number > 1120) return 25; |
| 45 |
if ($number > 1111) return 24; |
| 46 |
if ($number > 1100) return 23; |
| 47 |
if ($number > 1089) return 22; |
| 48 |
if ($number > 1076) return 21; |
| 49 |
if ($number > 1063) return 20; |
| 50 |
if ($number > 1048) return 19; |
| 51 |
if ($number > 1033) return 18; |
| 52 |
if ($number > 1016) return 17; |
| 53 |
if ($number > 999) return 16; |
| 54 |
if ($number > 680) return 0; |
| 55 |
if ($number > 670) return 15; |
| 56 |
if ($number > 649) return 14; |
| 57 |
if ($number > 618) return 13; |
| 58 |
if ($number > 586) return 12; |
| 59 |
if ($number > 551) return 11; |
| 60 |
if ($number > 514) return 10; |
| 61 |
if ($number > 475) return 9; |
| 62 |
if ($number > 435) return 8; |
| 63 |
if ($number > 390) return 7; |
| 64 |
if ($number > 340) return 6; |
| 65 |
if ($number > 285) return 5; |
| 66 |
if ($number > 225) return 4; |
| 67 |
if ($number > 150) return 3; |
| 68 |
if ($number > 80) return 2; |
| 69 |
return 1; |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* function for cores fight |
| 74 |
* arguments: attacker array, defender array |
| 75 |
* returns fight's log |
| 76 |
*/ |
| 77 |
function corefight(&$attacker,&$defender) { |
| 78 |
$attacksPerRound = min( floor($attacker['speed']/$defender['speed']), 5); |
| 79 |
$log = ''; |
| 80 |
for ($rounds=0; ($rounds<24 && $attacker['hp'] > 0 && $defender['hp'] > 0); $rounds++) { |
| 81 |
for ($i=0; $i < $attacksPerRound && $defender['hp'] > 0; $i++) { |
| 82 |
$damage = floor($attacker['attack'] * rand(90,110) / 100 - $defender['defence']); |
| 83 |
if ($damage < 0) $damage = 0; |
| 84 |
$defender['hp'] -= $damage; |
| 85 |
$log .= '<b>'.($attacker['name']).' ['.($attacker['user']).']</b> '.ATTACKS.' <b>'.($defender['name']).' ['.($defender['user']).']</b> '.AND_HITS.' <b>'.$damage.'</b> '.DAMAGES.' ('.($defender['hp']).' '.HP_LEFT.')<br/>'; |
| 86 |
} |
| 87 |
if ($defender['hp'] > 0) { |
| 88 |
$damage = floor($defender['attack'] * rand(90,110) / 100 - $attacker['defence']); |
| 89 |
if ($damage < 0) $damage = 0; |
| 90 |
$attacker['hp'] -= $damage; |
| 91 |
$log .= '<b>'.($defender['name']).' ['.($defender['user']).']</b> '.ATTACKS.' <b>'.($attacker['name']).' ['.($attacker['user']).']</b> '.AND_HITS.' <b>'.$damage.'</b> '.DAMAGES.' ('.($attacker['hp']).' '.HP_LEFT.')<br/>'; |
| 92 |
} |
| 93 |
} |
| 94 |
return $log; |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
$title = "Polana Chowańców"; |
| 99 |
require_once("includes/head.php"); |
| 100 |
|
| 101 |
if ($player -> location != 'Altara' && $player -> location != 'Ardulith') { |
| 102 |
error (ERROR); |
| 103 |
} |
| 104 |
|
| 105 |
//getting info about corepass and breeding |
| 106 |
$player -> raredata(); |
| 107 |
|
| 108 |
//getting language data |
| 109 |
require_once("languages/".$player -> lang."/core.php"); |
| 110 |
global $smarty; |
| 111 |
|
| 112 |
$smarty -> assign("Corepass" ,$player -> corepass); |
| 113 |
|
| 114 |
|
| 115 |
/** |
| 116 |
* without license |
| 117 |
*/ |
| 118 |
if ($player -> corepass !='Y') { |
| 119 |
//welcome |
| 120 |
if (!isset($_GET['answer'])) { |
| 121 |
$smarty -> assign(array( |
| 122 |
"Corepass" => ($player -> corepass), |
| 123 |
"Corepassinfo" => COREPASS_INFO, |
| 124 |
"Gold" => ($player -> credits) |
| 125 |
)); |
| 126 |
if ($player -> credits >= 500) { |
| 127 |
$smarty -> assign(array( |
| 128 |
"Havemoney" => HAVE_MONEY, |
| 129 |
"Ayes" => A_YES, |
| 130 |
"Ano" => A_NO |
| 131 |
)); |
| 132 |
} |
| 133 |
else { |
| 134 |
$smarty -> assign("Nomoney",NO_MONEY); |
| 135 |
} |
| 136 |
$smarty -> display('core.tpl'); |
| 137 |
} |
| 138 |
//buying license |
| 139 |
else if ($_GET['answer'] == 'yes') { |
| 140 |
if ($player -> corepass == 'Y') error(ERROR); |
| 141 |
if ($player -> credits < 500) { |
| 142 |
$smarty -> assign("Message",NO_MONEY); |
| 143 |
} |
| 144 |
else { |
| 145 |
global $db; |
| 146 |
$db -> Execute("UPDATE `players` SET `credits`=`credits`-500, `corepass`='Y' WHERE `id`=".($player -> id)); |
| 147 |
$smarty -> assign("Message",YES_LICENSE); |
| 148 |
} |
| 149 |
$smarty -> display('error1.tpl'); |
| 150 |
} |
| 151 |
} |
| 152 |
/** |
| 153 |
* with license |
| 154 |
*/ |
| 155 |
else { |
| 156 |
/** |
| 157 |
* main/welcome view |
| 158 |
*/ |
| 159 |
if (!isset($_GET['view'])) { |
| 160 |
$smarty -> assign (array( |
| 161 |
"view" => 'none', |
| 162 |
"Coremain" => CORE_MAIN, |
| 163 |
"Mycore" => A_MY_CORE, |
| 164 |
"Arena" => A_ARENA, |
| 165 |
"Train" => A_TRAIN, |
| 166 |
"Market" => A_MARKET, |
| 167 |
"Search" => A_SEARCH, |
| 168 |
"Breed" => A_BREED, |
| 169 |
"Monuments" => A_MONUMENTS, |
| 170 |
"Back" => BACK |
| 171 |
)); |
| 172 |
$smarty -> display('core.tpl'); |
| 173 |
} |
| 174 |
else { |
| 175 |
$smarty -> assign("view",$_GET['view']); |
| 176 |
global $db; |
| 177 |
switch ($_GET['view']) { |
| 178 |
/** |
| 179 |
* view my cores |
| 180 |
*/ |
| 181 |
case 'my': { |
| 182 |
//forms from other "view" |
| 183 |
if (isset($_POST['id'])) $_GET['id'] = $_POST['id']; |
| 184 |
//view list of cores |
| 185 |
if (!isset($_GET['id'])) { |
| 186 |
$list = ''; |
| 187 |
$corelist = $db -> Execute("SELECT `coresplayers`.`id`, `status`, `petname`, `coresbase`.`id` AS `name`, `arena` FROM `coresplayers`, `coresbase` WHERE `owner`=".($player -> id)." AND `base` = `coresbase`.`id` ORDER BY `status`, `coresbase`.`id`"); |
| 188 |
for ($i = 0, $j = 0; !$corelist -> EOF; $corelist -> MoveNext()) { |
| 189 |
if (($corelist -> fields["arena"]) == 'Z') { |
| 190 |
$normalnamelist[$i] = (($corelist -> fields["petname"]) != '') ? '<b>'.$corelist -> fields["petname"].'</b> - ' : '' ; |
| 191 |
$normalnamelist[$i] .= $names[$corelist -> fields["name"]]; |
| 192 |
$normalidlist[$i] = $corelist -> fields["id"]; |
| 193 |
$normalstatuslist[$i] = $corelist -> fields["status"]; |
| 194 |
$i++; |
| 195 |
} |
| 196 |
else { |
| 197 |
$magicnamelist[$j] = (($corelist -> fields["petname"]) != '') ? '<b>'.$corelist -> fields["petname"].'</b> - ' : '' ; |
| 198 |
$magicnamelist[$j] .= $names[$corelist -> fields["name"]]; |
| 199 |
$magicidlist[$j] = $corelist -> fields["id"]; |
| 200 |
$magicstatuslist[$j] = $corelist -> fields["status"]; |
| 201 |
$j++; |
| 202 |
} |
| 203 |
} |
| 204 |
if (isset($normalnamelist)) |
| 205 |
$smarty -> assign(array( |
| 206 |
"Normalnamelist" => $normalnamelist, |
| 207 |
"Normalidlist" => $normalidlist, |
| 208 |
"Normalstatuslist" => $normalstatuslist |
| 209 |
)); |
| 210 |
else $smarty -> assign("Normalnamelist", ''); |
| 211 |
if (isset($magicnamelist)) |
| 212 |
$smarty -> assign(array( |
| 213 |
"Magicnamelist" => $magicnamelist, |
| 214 |
"Magicidlist" => $magicidlist, |
| 215 |
"Magicstatuslist" => $magicstatuslist |
| 216 |
)); |
| 217 |
else $smarty -> assign("Magicnamelist", ''); |
| 218 |
$corelist -> Close(); |
| 219 |
$smarty -> assign(array( |
| 220 |
"Info" => MY_CORES_INFO, |
| 221 |
"List" => $list, |
| 222 |
"Back" => BACK |
| 223 |
)); |
| 224 |
$smarty -> display('core.tpl'); |
| 225 |
} |
| 226 |
//view one core |
| 227 |
else { |
| 228 |
//integercheck |
| 229 |
$coreid = (int)$_GET['id']; |
| 230 |
if (!isset($coreid) || $coreid == '') error(ERROR); |
| 231 |
|
| 232 |
if (isset($_GET['action'])) { |
| 233 |
$smarty -> assign("action",$_GET['action']); |
| 234 |
//change core name |
| 235 |
if ($_GET['action'] == 'changename' && isset($_POST['corename'])) { |
| 236 |
$core = $db -> Execute("SELECT `owner` FROM `coresplayers` WHERE `coresplayers`.`id` = ".$coreid); |
| 237 |
if (!isset($core) || $core -> EOF) error(NO_CORE); |
| 238 |
if ($core -> fields['owner'] != $player -> id) error(NOT_YOURS); |
| 239 |
$newname = str_replace( |
| 240 |
array("<",">","'","\""), |
| 241 |
array("<",">","'","""), |
| 242 |
$_POST['corename']); |
| 243 |
$db -> Execute("UPDATE `coresplayers` SET `petname`='".$newname."' WHERE `id`=".$coreid); |
| 244 |
$core -> Close(); |
| 245 |
$smarty -> assign("Message",NAME_CHANGED); |
| 246 |
$smarty -> display('error1.tpl'); |
| 247 |
} |
| 248 |
//sell core |
| 249 |
if ($_GET['action'] == 'sell') { |
| 250 |
$core = $db -> Execute("SELECT `owner`, `hp`, `status` FROM `coresplayers` WHERE `coresplayers`.`id` = ".$coreid); |
| 251 |
if (!isset($core) || $core -> EOF) error(NO_CORE); |
| 252 |
if ($core -> fields['owner'] != $player -> id) error(NOT_YOURS); |
| 253 |
if ($core -> fields['hp'] <= 0) error(IS_DEAD); |
| 254 |
if ($core -> fields['status'] == 'A') error(WRONG_STATUS); |
| 255 |
if (isset($_POST['prize'])) { |
| 256 |
//integercheck |
| 257 |
$prize = (int)$_POST['prize']; |
| 258 |
if (!isset($prize) || $prize == '') error(ERROR); |
| 259 |
if ($prize <= 0) error(BAD_PRIZE); |
| 260 |
$smarty -> assign("Sellinfo",''); |
| 261 |
$db -> Execute("UPDATE `coresplayers` SET `status`='S', `prize`=".$prize." WHERE `id`=".$coreid); |
| 262 |
$smarty -> assign("Sellinfo",''); |
| 263 |
$smarty -> assign("Message",YOU_SOLD); |
| 264 |
$smarty -> display('error1.tpl'); |
| 265 |
} |
| 266 |
else { |
| 267 |
$smarty -> assign("Sellinfo",SELL_INFO); |
| 268 |
} |
| 269 |
} |
| 270 |
//unsell core |
| 271 |
if ($_GET['action'] == 'unsell') { |
| 272 |
$core = $db -> Execute("SELECT `owner`, `status` FROM `coresplayers` WHERE `coresplayers`.`id` = ".$coreid); |
| 273 |
if (!isset($core) || $core -> EOF) error(NO_CORE); |
| 274 |
if ($core -> fields['owner'] != $player -> id) error(NOT_YOURS); |
| 275 |
if ($core -> fields['status'] != 'S') error(NOT_FORSALE); |
| 276 |
$db -> Execute("UPDATE `coresplayers` SET `status`='N', `prize`= 0 WHERE `id`=".$coreid); |
| 277 |
$smarty -> assign("Message",YOU_UNSOLD); |
| 278 |
$smarty -> display('error1.tpl'); |
| 279 |
} |
| 280 |
//pass core other player |
| 281 |
if ($_GET['action'] == 'pass') { |
| 282 |
$core = $db -> Execute("SELECT `status`, `owner`, `petname`, `coresbase`.`id` AS `name` FROM `coresplayers`, `coresbase` WHERE `coresplayers`.`id` = ".$coreid." AND `base`=`coresbase`.`id`"); |
| 283 |
if (!isset($core) || $core -> EOF) error(NO_CORE); |
| 284 |
if ($core -> fields['owner'] != $player -> id) error(NOT_YOURS); |
| 285 |
if (isset($_POST['pid'])) { |
| 286 |
//integercheck |
| 287 |
$newowner = (int)$_POST['pid']; |
| 288 |
if (!isset($newowner) || $newowner == '') error(ERROR); |
| 289 |
if ($newowner == $player -> id) error(NO_SELF); |
| 290 |
if ($core -> fields['status'] != 'N') error(WRONG_STATUS); |
| 291 |
$owner = $db -> Execute("SELECT `user`, `id` FROM `players` WHERE `id` = ".$newowner); |
| 292 |
if ( !isset($owner -> fields['id']) || $newowner != ($owner -> fields['id'])) error(NO_PLAYER); |
| 293 |
$db -> Execute("UPDATE `coresplayers` SET `owner` = ".$newowner." WHERE `id`=".$coreid); |
| 294 |
(isset($core -> fields['petname']) && $core -> fields['petname'] != '' ) ? $name = ($core -> fields['petname']).' - ' : $name = ''; |
| 295 |
$name .= $names[($core -> fields['name'])]; |
| 296 |
$msg = YOU_PASSED.' '.$name.' '.TO_PLAYER.' <a href="view.php?view='.$newowner.'">'.($owner -> fields['user']).'</a>'; |
| 297 |
$msg2 = YOU_GOT.' '.$name.' '.FROM_PLAYER.' <a href="view.php?view='.($player -> id).'">'.($player -> user).'</a>'; |
| 298 |
$smarty -> assign("Message",$msg); |
| 299 |
$smarty -> display('error1.tpl'); |
| 300 |
$smarty -> assign("Message",'<br/><a href="core.php">'.BACK.'</a>'); |
| 301 |
$smarty -> display('error1.tpl'); |
| 302 |
global $newdate; |
| 303 |
$strDate = $db -> DBDate($newdate); |
| 304 |
$db -> Execute('INSERT INTO `log` (`owner`, `log`, `czas`) VALUES('.$player -> id.', \''.$msg.'\', '.$strDate.');'); |
| 305 |
$db -> Execute('INSERT INTO `log` (`owner`, `log`, `czas`) VALUES('.$newowner.', \''.$msg2.'\', '.$strDate.');'); |
| 306 |
//there is no core to show after passing it |
| 307 |
break; |
| 308 |
} |
| 309 |
} |
| 310 |
//activate core |
| 311 |
if ($_GET['action'] == 'activate') { |
| 312 |
$core = $db -> Execute("SELECT `coresplayers`.`hp`, `owner`, `status`, `arena`, `value` FROM `coresplayers`, `coresbase` WHERE `coresplayers`.`id` = ".$coreid." AND `base`=`coresbase`.`id`"); |
| 313 |
if (!isset($core) || $core -> EOF) error(NO_CORE); |
| 314 |
if ($core -> fields['owner'] != $player -> id) error(NOT_YOURS); |
| 315 |
if ($core -> fields['hp'] <= 0) error(IS_DEAD); |
| 316 |
if ($core -> fields['status'] != 'N') error(WRONG_STATUS); |
| 317 |
if ($core -> fields['arena'] == 'Z') { |
| 318 |
$goldcost = ($core -> fields['value']) * 100; |
| 319 |
$platinumcost = $core -> fields['value']; |
| 320 |
$smarty -> assign("Cost",YOU_PAY." ".$goldcost." ".GOLD_PIECES.", ".$platinumcost." ".PLATINUM); |
| 321 |
if ($goldcost > $player -> credits || |
| 322 |
$platinumcost > $player -> platinum |
| 323 |
) $nomoney = NO_MONEY; |
| 324 |
else $nomoney = ''; |
| 325 |
} |
| 326 |
else { |
| 327 |
$minerals = $db -> Execute("SELECT `crystal`, `adamantium` FROM `minerals` WHERE `owner` = ".($player -> id)); |
| 328 |
$adamantium = $minerals -> fields['adamantium']; |
| 329 |
$crystal = $minerals -> fields['crystal']; |
| 330 |
$goldcost = ($core -> fields['value']) * 500; |
| 331 |
$platinumcost = ($core -> fields['value']) * 2; |
| 332 |
$adamantiumcost = $core -> fields['value']; |
| 333 |
$crystalcost = $core -> fields['value']; |
| 334 |
$smarty -> assign("Cost",YOU_PAY." ".$goldcost." ".GOLD_PIECES.", ".$platinumcost." ".PLATINUM.", ".$adamantiumcost." ".ADAMANTIUM.", ".$crystalcost." ".CRYSTAL); |
| 335 |
if ($goldcost > $player -> credits || |
| 336 |
$platinumcost > $player -> platinum || |
| 337 |
$adamantiumcost > $adamantium || |
| 338 |
$crystalcost > $crystal |
| 339 |
) $nomoney = NO_MONEY; |
| 340 |
else $nomoney = ''; |
| 341 |
} |
| 342 |
$smarty -> assign("Nomoney",$nomoney); |
| 343 |
if (isset($_POST['activate']) && $nomoney == '') { |
| 344 |
$smarty -> assign("Activateinfo",""); |
| 345 |
$db -> Execute("UPDATE `coresplayers` SET `status` = 'A' WHERE `id`=".$coreid); |
| 346 |
$db -> Execute("UPDATE `players` SET `credits` = `credits` - ".$goldcost.", `platinum` = `platinum` - ".$platinumcost." WHERE `id`=".($player -> id)); |
| 347 |
if ($core -> fields['arena'] == 'M') { |
| 348 |
$db -> Execute("UPDATE `minerals` SET `adamantium` = `adamantium` - ".$adamantiumcost.", `crystal` = `crystal` - ".$crystalcost." WHERE `owner`=".($player -> id)); |
| 349 |
} |
| 350 |
$smarty -> assign("Message",CORE_ACTIVATED); |
| 351 |
$smarty -> display('error1.tpl'); |
| 352 |
} |
| 353 |
else { |
| 354 |
$smarty -> assign("Activateinfo",ACTIVATE_INFO); |
| 355 |
} |
| 356 |
} |
| 357 |
//deactivate core |
| 358 |
if ($_GET['action'] == 'deactivate') { |
| 359 |
$core = $db -> Execute("SELECT `coresplayers`.`hp`, `owner`, `status`, `arena`, `value` FROM `coresplayers`, `coresbase` WHERE `coresplayers`.`id` = ".$coreid." AND `base`=`coresbase`.`id`"); |
| 360 |
if (!isset($core) || $core -> EOF) error(NO_CORE); |
| 361 |
if ($core -> fields['owner'] != $player -> id) error(NOT_YOURS); |
| 362 |
if ($core -> fields['status'] != 'A') error(WRONG_STATUS2); |
| 363 |
if ($core -> fields['arena'] == 'Z') { |
| 364 |
$goldcost = ($core -> fields['value']) * 100; |
| 365 |
$platinumcost = $core -> fields['value']; |
| 366 |
$smarty -> assign("Cost",YOU_PAY." ".$goldcost." ".GOLD_PIECES.", ".$platinumcost." ".PLATINUM); |
| 367 |
if ($goldcost > $player -> credits || |
| 368 |
$platinumcost > $player -> platinum |
| 369 |
) $nomoney = NO_MONEY; |
| 370 |
else $nomoney = ''; |
| 371 |
} |
| 372 |
else { |
| 373 |
$minerals = $db -> Execute("SELECT `crystal`, `adamantium` FROM `minerals` WHERE `owner` = ".($player -> id)); |
| 374 |
$adamantium = $minerals -> fields['adamantium']; |
| 375 |
$crystal = $minerals -> fields['crystal']; |
| 376 |
$goldcost = ($core -> fields['value']) * 500; |
| 377 |
$platinumcost = ($core -> fields['value']) * 2; |
| 378 |
$adamantiumcost = $core -> fields['value']; |
| 379 |
$crystalcost = $core -> fields['value']; |
| 380 |
$smarty -> assign("Cost",YOU_PAY." ".$goldcost." ".GOLD_PIECES.", ".$platinumcost." ".PLATINUM.", ".$adamantiumcost." ".ADAMANTIUM.", ".$crystalcost." ".CRYSTAL); |
| 381 |
if ($goldcost > $player -> credits || |
| 382 |
$platinumcost > $player -> platinum || |
| 383 |
$adamantiumcost > $adamantium || |
| 384 |
$crystalcost > $crystal |
| 385 |
) $nomoney = NO_MONEY; |
| 386 |
else $nomoney = ''; |
| 387 |
} |
| 388 |
$smarty -> assign("Nomoney",$nomoney); |
| 389 |
if (isset($_POST['deactivate']) && $nomoney == '') { |
| 390 |
$smarty -> assign("Deactivateinfo",""); |
| 391 |
$db -> Execute("UPDATE `coresplayers` SET `status` = 'N' WHERE `id`=".$coreid); |
| 392 |
$db -> Execute("UPDATE `players` SET `credits` = `credits` - ".$goldcost.", `platinum` = `platinum` - ".$platinumcost." WHERE `id`=".($player -> id)); |
| 393 |
if ($core -> fields['arena'] == 'M') { |
| 394 |
$db -> Execute("UPDATE `minerals` SET `adamantium` = `adamantium` - ".$adamantiumcost.", `crystal` = `crystal` - ".$crystalcost." WHERE `owner`=".($player -> id)); |
| 395 |
} |
| 396 |
$smarty -> assign("Message",CORE_DEACTIVATED); |
| 397 |
$smarty -> display('error1.tpl'); |
| 398 |
} |
| 399 |
else { |
| 400 |
$smarty -> assign("Deactivateinfo",DEACTIVATE_INFO); |
| 401 |
} |
| 402 |
} |
| 403 |
//free core |
| 404 |
if ($_GET['action'] == 'free') { |
| 405 |
$core = $db -> Execute("SELECT `owner` FROM `coresplayers` WHERE `coresplayers`.`id` = ".$coreid); |
| 406 |
if (!isset($core) || $core -> EOF) error(NO_CORE); |
| 407 |
if ($core -> fields['owner'] != $player -> id) error(NOT_YOURS); |
| 408 |
if (isset($_POST['free'])) { |
| 409 |
$db -> Execute("DELETE FROM `coresplayers` WHERE `id`=".$coreid); |
| 410 |
$smarty -> assign("Message",CORE_FREE); |
| 411 |
$smarty -> display('error1.tpl'); |
| 412 |
$smarty -> assign("Message",'<br/><a href="core.php">'.BACK.'</a>'); |
| 413 |
$smarty -> display('error1.tpl'); |
| 414 |
//there is no core to show after freeing it |
| 415 |
break; |
| 416 |
} |
| 417 |
} |
| 418 |
//heal core |
| 419 |
if ($_GET['action'] == 'heal') { |
| 420 |
$core = $db -> Execute("SELECT `owner`, `coresplayers`.`hp`, `coresplayers`.`max_hp`, `coresplayers`.`attack`, `coresplayers`.`defence`, `coresplayers`.`speed`, `cost` FROM `coresplayers`, `coresbase` WHERE `coresplayers`.`id` = ".$coreid." AND `coresplayers`.`base` = `coresbase`.`id`"); |
| 421 |
if (!isset($core) || $core -> EOF) error(NO_CORE); |
| 422 |
if ($core -> fields['owner'] != $player -> id) error(NOT_YOURS); |
| 423 |
if ($core -> fields['hp'] == $core -> fields['max_hp']) error(NO_NEED_HEAL); |
| 424 |
if ($core -> fields['hp'] == 0) error(NEED_RESURRECT); |
| 425 |
$cost = ceil(($core -> fields['attack'] + $core -> fields['defence'] + $core -> fields['speed']) * $core -> fields['cost'] / 2); |
| 426 |
$healinfo = HEAL_COST.' <b>'.$cost.'</b> '.GOLD_PIECES; |
| 427 |
$nomoney = ''; |
| 428 |
if (isset($_POST['heal'])) { |
| 429 |
if ($player -> credits < $cost) error(NO_MONEY); |
| 430 |
$db -> Execute("UPDATE `players` SET `credits` = `credits` - ".$cost." WHERE `id` = ".($player -> id)); |
| 431 |
$db -> Execute("UPDATE `coresplayers` SET `hp`=`max_hp` WHERE `id`=".$coreid); |
| 432 |
$smarty -> assign("Healinfo",""); |
| 433 |
$smarty -> assign("Message",CORE_HEALED); |
| 434 |
$smarty -> display('error1.tpl'); |
| 435 |
} |
| 436 |
else { |
| 437 |
if ($player -> credits < $cost) $nomoney = NO_MONEY; |
| 438 |
$smarty -> assign(array( |
| 439 |
"Healinfo" => $healinfo, |
| 440 |
"Nomoney" => $nomoney |
| 441 |
)); |
| 442 |
} |
| 443 |
} |
| 444 |
//resurrect core |
| 445 |
if ($_GET['action'] == 'resurrect') { |
| 446 |
$core = $db -> Execute("SELECT `owner`, `coresplayers`.`hp`, `coresplayers`.`attack`, `coresplayers`.`defence`, `coresplayers`.`speed`, `cost` FROM `coresplayers`, `coresbase` WHERE `coresplayers`.`id` = ".$coreid." AND `coresplayers`.`base` = `coresbase`.`id`"); |
| 447 |
if (!isset($core) || $core -> EOF) error(NO_CORE); |
| 448 |
if ($core -> fields['owner'] != $player -> id) error(NOT_YOURS); |
| 449 |
if ($core -> fields['hp'] > 0) error(NO_NEED_RES); |
| 450 |
$cost = ($core -> fields['attack'] + $core -> fields['defence'] + $core -> fields['speed']) * $core -> fields['cost']; |
| 451 |
$goldcost = ceil($cost / 2); |
| 452 |
$platinumcost = floor($cost / 100); |
| 453 |
$adamantiumcost = floor($cost / 200); |
| 454 |
$crystalcost = floor($cost / 200); |
| 455 |
$resinfo = RESURRECT_COST.' <b>'.$goldcost.'</b> '.GOLD_PIECES; |
| 456 |
if ($platinumcost > 0) $resinfo .= ', <b>'.$platinumcost.'</b> '.PLATINUM; |
| 457 |
if ($adamantiumcost > 0) $resinfo .= ', <b>'.$adamantiumcost.'</b> '.ADAMANTIUM; |
| 458 |
if ($crystalcost > 0) $resinfo .= ', <b>'.$crystalcost.'</b> '.CRYSTAL; |
| 459 |
$nomoney = ''; |
| 460 |
$minerals = $db -> Execute("SELECT `crystal`, `adamantium` FROM `minerals` WHERE `owner` = ".($player -> id)); |
| 461 |
$adamantium = $minerals -> fields['adamantium']; |
| 462 |
$crystal = $minerals -> fields['crystal']; |
| 463 |
if (isset($_POST['resurrect'])) { |
| 464 |
if ($player -> credits < $goldcost || |
| 465 |
$player -> platinum < $platinumcost || |
| 466 |
$adamantium < $adamantiumcost || |
| 467 |
$crystal < $crystalcost |
| 468 |
) error(NO_MONEY2); |
| 469 |
$db -> Execute("UPDATE `players` SET `credits` = `credits` - ".$goldcost.", `platinum` = `platinum` - ".$platinumcost." WHERE `id` = ".($player -> id)); |
| 470 |
if ($adamantiumcost > 0) $db -> Execute("UPDATE `minerals` SET `adamantium` = `adamantium` - ".$adamantiumcost.", `crystal` = `crystal` - ".$crystalcost." WHERE `owner` = ".($player -> id)); |
| 471 |
$db -> Execute("UPDATE `coresplayers` SET `hp`=`max_hp` WHERE `id`=".$coreid); |
| 472 |
$smarty -> assign("Resinfo",""); |
| 473 |
$smarty -> assign("Message",CORE_RESURRECTED); |
| 474 |
$smarty -> display('error1.tpl'); |
| 475 |
} |
| 476 |
else { |
| 477 |
if ($player -> credits < $goldcost || |
| 478 |
$player -> platinum < $platinumcost || |
| 479 |
$adamantium < $adamantiumcost || |
| 480 |
$crystal < $crystalcost |
| 481 |
) $nomoney = NO_MONEY2; |
| 482 |
$smarty -> assign(array( |
| 483 |
"Resinfo" => $resinfo, |
| 484 |
"Nomoney" => $nomoney |
| 485 |
)); |
| 486 |
} |
| 487 |
} |
| 488 |
} |
| 489 |
else $smarty -> assign("action",''); |
| 490 |
|
| 491 |
|
| 492 |
$core = $db -> Execute("SELECT `owner`, `petname`, `coresplayers`.`attack`, `coresplayers`.`defence`, `coresplayers`.`speed`, `gender`, `coresplayers`.`hp`, `max_hp`, `status`, `wins`, `loses`, `age`, `coresbase`.`id` AS `name`, `picture`, `atuta`, `atutd`, `atuts`, `maturity`, `arena`, `prize`, `rest` FROM `coresplayers`, `coresbase` WHERE `coresplayers`.`id` = ".$coreid." AND `base` = `coresbase`.`id`"); |
| 493 |
if (!isset($core) || $core -> EOF) error(NO_CORE); |
| 494 |
if ($core -> fields['owner'] != $player -> id) error(NOT_YOURS); |
| 495 |
|
| 496 |
$name = ''; |
| 497 |
if (($core -> fields["petname"]) != '') $name .= $core -> fields["petname"].' - '; |
| 498 |
$name .= $names[$core -> fields["name"]]; |
| 499 |
$age = $core -> fields['age']; |
| 500 |
if ($core -> fields['age'] < $core -> fields['maturity']) { |
| 501 |
$age .= ' ('.C_IMMATURE.')'; |
| 502 |
$rest = 0; |
| 503 |
} |
| 504 |
else { |
| 505 |
$age .= ' ('.C_MATURE.')'; |
| 506 |
$rest = $core -> fields['rest']; |
| 507 |
} |
| 508 |
$atut = ''; |
| 509 |
if ($core -> fields['atuta'] == 1) $atut .= C_ATTACK.' '; |
| 510 |
if ($core -> fields['atutd'] == 1) $atut .= C_DEFENCE.' '; |
| 511 |
if ($core -> fields['atuts'] == 1) $atut .= C_SPEED.' '; |
| 512 |
switch ($core -> fields['status']) { |
| 513 |
case 'A': { $status = ACTIVE; break; } |
| 514 |
case 'N': { $status = NONACTIVE; break; } |
| 515 |
case 'S': { $status = FORSALE." (".($core -> fields['prize'])." ".GOLD_PIECES.")"; break; } |
| 516 |
} |
| 517 |
if ($core -> fields['hp'] <= 0) $status = C_DEAD; |
| 518 |
$smarty -> assign(array( |
| 519 |
"view" => "display", |
| 520 |
"Ctitle" => $name, |
| 521 |
"Gender" => ($core -> fields["gender"] == 'M' ? GENDER_MALE : GENDER_FEMALE), |
| 522 |
"Arena" => ($core -> fields["arena"] == 'Z' ? ARENA_Z : ARENA_M), |
| 523 |
"Status" => $status, |
| 524 |
"Statuscode" => ($core -> fields['status']), |
| 525 |
"Coreid" => $coreid, |
| 526 |
"Name" => ($core -> fields["petname"]), |
| 527 |
"Species" => ($names[$core -> fields["name"]]), |
| 528 |
"Text" => ($description[$core -> fields["name"]]), |
| 529 |
"Hp" => ($core -> fields['hp']), |
| 530 |
"Maxhp" => ($core -> fields['max_hp']), |
| 531 |
"Attack" => ($core -> fields["attack"]), |
| 532 |
"Defence" => ($core -> fields["defence"]), |
| 533 |
"Speed" => ($core -> fields["speed"]), |
| 534 |
"Wins" => ($core -> fields["wins"]), |
| 535 |
"Loses" => ($core -> fields["loses"]), |
| 536 |
"Age" => $age, |
| 537 |
"Rest" => $rest, |
| 538 |
"Atut" => $atut, |
| 539 |
"Image" => ($core -> fields['picture']) |
| 540 |
)); |
| 541 |
|
| 542 |
$smarty -> display('core.tpl'); |
| 543 |
} |
| 544 |
break; |
| 545 |
} |
| 546 |
/** |
| 547 |
* search for cores |
| 548 |
*/ |
| 549 |
case 'search': { |
| 550 |
//szukanie chowańców |
| 551 |
$minerals = $db -> Execute("SELECT `meteor`, `adamantium`, `crystal` FROM `minerals` WHERE `owner` = ".($player -> id)); |
| 552 |
$maxminerals = min(floor(($minerals -> fields['adamantium'])/5), |
| 553 |
floor(($minerals -> fields['crystal'])/3), |
| 554 |
floor(($minerals -> fields['meteor'])) |
| 555 |
); |
| 556 |
$maxenergy = floor($player -> energy); |
| 557 |
$maxtries = min($maxminerals, $maxenergy); |
| 558 |
if (isset($_POST['times'])) { |
| 559 |
//integercheck |
| 560 |
$times = (int)$_POST['times']; |
| 561 |
if (!isset($times) || $times == '' || $times < 1) error(ERROR); |
| 562 |
if ($times > $maxenergy) error(NO_ENERGY); |
| 563 |
if ($times > $maxminerals) error(NO_MINERALS); |
| 564 |
//prepare hit array |
| 565 |
for ($i=1;$i<31;$i++) $hit[$i] = 0; |
| 566 |
$found = 0; |
| 567 |
for ($i=0;$i<$times;$i++) { |
| 568 |
$rzut = rand(1,10000); |
| 569 |
$core = whichcore($rzut); |
| 570 |
if ($core > 0) { |
| 571 |
$hit[$core]++; |
| 572 |
$found = 1; |
| 573 |
} |
| 574 |
} |
| 575 |
if ($found == 0) { |
| 576 |
$smarty -> assign(array( |
| 577 |
"Searchinfo" => '', |
| 578 |
"Nocores" => NO_CORES |
| 579 |
)); |
| 580 |
} |
| 581 |
else { |
| 582 |
$sqlpre = "INSERT INTO `coresplayers` (`owner`, `base`, `attack`, `defence`, `speed`, `hp`, `max_hp`, `age`, `gender`) VALUES"; |
| 583 |
$sql = ""; |
| 584 |
$list = ''; |
| 585 |
$gainExp = 0; |
| 586 |
for ($i=1;$i<31;$i++) |
| 587 |
if ($hit[$i] > 0) { |
| 588 |
$core = $db -> Execute("SELECT `arena`, `coresbase`.`id` AS `name`, `attack`, `defence`, `speed`, `hp`, `maturity` FROM `coresbase` WHERE `id`=".$i); |
| 589 |
$list .= '<li>'.($names[$core -> fields['name']]).' '.$hit[$i].' '.TIMES.'</li>'; |
| 590 |
$gainExp += ($core -> fields['arena'] == 'Z') ? 2 * $hit[$i] : 5 * $hit[$i]; |
| 591 |
for ($j=0;$j<$hit[$i];$j++) { |
| 592 |
$attack = round($core -> fields['attack'] * rand(950,1050) / 1000); |
| 593 |
$defence = round($core -> fields['defence'] * rand(950,1050) / 1000); |
| 594 |
$speed = round($core -> fields['speed'] * rand(950,1050) / 1000); |
| 595 |
$hp = round($core -> fields['hp'] * rand(950,1050) / 1000); |
| 596 |
$age = rand(0,$core -> fields['maturity'] * 2); |
| 597 |
($sql == '') ? $sql = '' : $sql .= ', '; |
| 598 |
$sql .= "(".($player -> id).", ".$i.", ".$attack.", ".$defence.", ".$speed.", ".$hp.", ".$hp.", ".$age.", "; |
| 599 |
$sql .= (rand(1,2) == 1) ? "'M')" : "'F')"; |
| 600 |
} |
| 601 |
} |
| 602 |
if ($gainExp > 0) { |
| 603 |
require_once('includes/checkexp.php'); |
| 604 |
checkexp($player -> exp, $gainExp, $player -> level, $player -> race, $player -> user, $player -> id, '', '', '','',0); |
| 605 |
} |
| 606 |
$db -> Execute($sqlpre.$sql); |
| 607 |
$smarty -> assign(array( |
| 608 |
"Searchinfo" => '', |
| 609 |
"Nocores" => '', |
| 610 |
"Gainexp" => $gainExp, |
| 611 |
"List" => $list |
| 612 |
)); |
| 613 |
} |
| 614 |
$db -> Execute("UPDATE `players` SET `energy` = `energy` - ".($times)." WHERE `id` = ".($player -> id)); |
| 615 |
$db -> Execute("UPDATE `minerals` SET `meteor` = `meteor` - ".($times).",`adamantium` = `adamantium` - ".($times*5).", `crystal` = `crystal` - ".($times*3)." WHERE `owner` = ".($player -> id)); |
| 616 |
} |
| 617 |
else { |
| 618 |
$smarty -> assign(array( |
| 619 |
"Searchinfo" => SEARCH_INFO, |
| 620 |
"Nocores" => '', |
| 621 |
"Maxtries" => $maxtries |
| 622 |
)); |
| 623 |
} |
| 624 |
|
| 625 |
$smarty -> display('core.tpl'); |
| 626 |
break; |
| 627 |
} |
| 628 |
/** |
| 629 |
* train core |
| 630 |
*/ |
| 631 |
case 'train': { |
| 632 |
if (!isset($_POST['id'])) { |
| 633 |
$cores = $db -> Execute("SELECT `coresplayers`.`id`, `petname`, `coresplayers`.`attack`, `coresplayers`.`defence`, `coresplayers`.`speed`, `coresplayers`.`hp`, `coresplayers`.`max_hp`, `coresbase`.`id` AS `name` FROM `coresplayers`, `coresbase` WHERE `base` = `coresbase`.`id` AND `status`='N' AND `coresplayers`.`hp` > 0 AND `owner` = ".($player -> id)." ORDER BY `coresbase`.`id`"); |
| 634 |
for ($i = 0; !$cores -> EOF ; $i++) { |
| 635 |
$namelist[$i] = ($cores -> fields['petname']).' ('.($names[$cores -> fields['name']]).')'; |
| 636 |
$attacklist[$i] = $cores -> fields['attack']; |
| 637 |
$defencelist[$i] = $cores -> fields['defence']; |
| 638 |
$speedlist[$i] = $cores -> fields['speed']; |
| 639 |
$hplist[$i] = ($cores -> fields['hp']).' / '.($cores -> fields['max_hp']); |
| 640 |
$idlist[$i] = $cores -> fields['id']; |
| 641 |
$cores -> MoveNext(); |
| 642 |
} |
| 643 |
if (isset($namelist)) |
| 644 |
$smarty -> assign(array( |
| 645 |
"Namelist" => $namelist, |
| 646 |
"Attacklist" => $attacklist, |
| 647 |
"Defencelist" => $defencelist, |
| 648 |
"Speedlist" => $speedlist, |
| 649 |
"Hplist" => $hplist, |
| 650 |
"Idlist" => $idlist, |
| 651 |
"Cost" => "", |
| 652 |
"Trained" => "N" |
| 653 |
)); |
| 654 |
else $smarty -> assign(array( |
| 655 |
"Namelist" => '', |
| 656 |
"Cost" => '', |
| 657 |
"Trained" => 'N' |
| 658 |
)); |
| 659 |
} |
| 660 |
else { |
| 661 |
//integercheck |
| 662 |
$coreid = (int)$_POST['id']; |
| 663 |
if (!isset($coreid) || $coreid == '') error(ERROR); |
| 664 |
$smarty -> assign("Namelist", ''); |
| 665 |
$smarty -> assign("Trained", ''); |
| 666 |
|
| 667 |
$core = $db -> Execute("SELECT `owner`, `petname`, `status`, `coresplayers`.`attack`, `coresplayers`.`defence`, `coresplayers`.`speed`, `coresplayers`.`hp`, `coresplayers`.`max_hp`, `coresbase`.`id` AS `name`, `arena`, `cost`, `atuta`, `atutd`, `atuts` FROM `coresplayers`, `coresbase` WHERE `base` = `coresbase`.`id` AND `coresplayers`.`id` = ".$coreid); |
| 668 |
if ($core -> fields['owner'] != $player -> id) error(NOT_YOURS); |
| 669 |
if ($core -> fields['status'] != 'N') error(WRONG_STATUS); |
| 670 |
|
| 671 |
$baseenergycost = 0.1 * $core -> fields['cost']; |
| 672 |
$corename = ($core -> fields['petname']).' ('.($names[$core -> fields['name']]).')'; |
| 673 |
|
| 674 |
$minerals = $db -> Execute("SELECT `adamantium`, `crystal` FROM `minerals` WHERE `owner` = ".($player -> id)); |
| 675 |
$adamantium = $minerals -> fields['adamantium']; |
| 676 |
$crystal = $minerals -> fields['crystal']; |
| 677 |
$platinum = $player -> platinum; |
| 678 |
|
| 679 |
|
| 680 |
if (isset($_POST['stat']) && isset($_POST['times'])) { |
| 681 |
//integercheck |
| 682 |
$times = (int)$_POST['times']; |
| 683 |
if (!isset($times) || $times == '' || $times < 1) error(ERROR); |
| 684 |
if ($_POST['stat'] != 'A' && $_POST['stat'] != 'D' && $_POST['stat'] != 'S') error(WRONG_STAT); |
| 685 |
|
| 686 |
$energycost = $baseenergycost * $times; |
| 687 |
if ($core -> fields['arena'] == 'Z') { |
| 688 |
$baseadamantiumcost = 1; |
| 689 |
$basecrystalcost = 1; |
| 690 |
$baseplatinumcost = 0; |
| 691 |
} |
| 692 |
else { |
| 693 |
$baseadamantiumcost = 3; |
| 694 |
$basecrystalcost = 2; |
| 695 |
$baseplatinumcost = 1; |
| 696 |
} |
| 697 |
if ($energycost > $player -> energy) error(NO_ENERGY); |
| 698 |
|
| 699 |
$templebless = $db -> Execute("SELECT `bless`, `blessval` FROM `players` WHERE `id` = ".($player -> id)); |
| 700 |
if ($templebless -> fields['bless'] == 'breeding') { |
| 701 |
$bless = $templebless -> fields['blessval']; |
| 702 |
$player -> breeding += $bless; |
| 703 |
} |
| 704 |
$gainbreed = 0; |
| 705 |
$gainstat = 0; |
| 706 |
$gainExp = 0; |
| 707 |
|
| 708 |
$statsum = $core -> fields['attack'] + $core -> fields['defence'] + $core -> fields['speed']; |
| 709 |
switch ($_POST['stat']) { |
| 710 |
case 'A': $stat = 'attack'; |
| 711 |
$mult = ($core -> fields['atuta'] == 1)? 1.5 : 1; |
| 712 |
$strStat = T_ATTACK; |
| 713 |
break; |
| 714 |
case 'D': $stat = 'defence'; |
| 715 |
$mult = ($core -> fields['atutd'] == 1)? 1.5 : 1; |
| 716 |
$strStat = T_DEFENCE; |
| 717 |
break; |
| 718 |
case 'S': $stat = 'speed'; |
| 719 |
$mult = ($core -> fields['atuts'] == 1)? 1.5 : 1; |
| 720 |
$strStat = T_SPEED; |
| 721 |
} |
| 722 |
$statsum += $core -> fields[$stat]; |
| 723 |
|
| 724 |
$adamantiumcost = 0; |
| 725 |
$crystalcost = 0; |
| 726 |
$platinumcost = 0; |
| 727 |
|
| 728 |
for ($i = 0; $i < $times; $i++) { |
| 729 |
//no minerals for succesfull training |
| 730 |
if ($adamantium < $adamantiumcost + $baseadamantiumcost || |
| 731 |
$crystal < $crystalcost + $basecrystalcost || |
| 732 |
$platinum < $platinumcost + $baseplatinumcost) { |
| 733 |
break; |
| 734 |
} |
| 735 |
$chance = 2000 * ($player -> breeding + $gainbreed) / ($statsum + $gainstat) - 5 * $core -> fields['cost']; |
| 736 |
if ($chance > 90) $chance = 90; |
| 737 |
if (rand(1,100) <= $chance) { |
| 738 |
$gainstat += (0.5 + ($player -> breeding + $gainbreed) / 50) * $mult; |
| 739 |
$gainbreed += $baseenergycost / 50; |
| 740 |
$gainExp += 5 * $core -> fields['cost'] * $baseenergycost; |
| 741 |
$adamantiumcost += $baseadamantiumcost; |
| 742 |
$crystalcost += $basecrystalcost; |
| 743 |
$platinumcost += $baseplatinumcost; |
| 744 |
} |
| 745 |
else { |
| 746 |
$gainbreed += $baseenergycost / 100; |
| 747 |
} |
| 748 |
} |
| 749 |
$energycost = $baseenergycost * $i; |
| 750 |
|
| 751 |
$gainbreed = round($gainbreed,2); |
| 752 |
$gainExp = floor($gainExp); |
| 753 |
|
| 754 |
$db -> Execute("UPDATE `coresplayers` SET `".$stat."` = `".$stat."` + ".$gainstat." WHERE `id` = ".$coreid); |
| 755 |
$playersql = "UPDATE `players` SET `energy` = `energy` - ".$energycost.", `platinum` = `platinum` - ".$platinumcost.", `breeding` = `breeding` + ".$gainbreed; |
| 756 |
if (isset($bless)) $playersql .= ", bless = '', blessval = 0"; |
| 757 |
$playersql .= " WHERE `id` = ".($player -> id); |
| 758 |
$db -> Execute($playersql); |
| 759 |
$db -> Execute("UPDATE `minerals` SET `adamantium` = `adamantium` - ".$adamantiumcost.", `crystal` = `crystal` - ".$crystalcost." WHERE `owner`=".($player -> id)); |
| 760 |
|
| 761 |
if ($gainExp > 0) { |
| 762 |
require_once('includes/checkexp.php'); |
| 763 |
checkexp($player -> exp, $gainExp, $player -> level, $player -> race, $player -> user, $player -> id, '', '', '','',0); |
| 764 |
} |
| 765 |
|
| 766 |
$smarty -> assign(array( |
| 767 |
"Cost" => '', |
| 768 |
"Gainstat" => $gainstat, |
| 769 |
"Stat" => $strStat, |
| 770 |
"Gainbreed" => $gainbreed, |
| 771 |
"GainExp" => $gainExp, |
| 772 |
"Adamantium" => $adamantiumcost, |
| 773 |
"Platinum" => $platinumcost, |
| 774 |
"Crystal" => $crystalcost, |
| 775 |
"Energy" => $energycost, |
| 776 |
"Trained" => "Y" |
| 777 |
)); |
| 778 |
} |
| 779 |
else { |
| 780 |
if ($core -> fields['arena'] == 'Z') { |
| 781 |
$cost = (FOR_ONE_TRAIN.' 1 '.ADAMANTIUM.', 1 '.CRYSTAL.', '.$baseenergycost.' '.ENERGY); |
| 782 |
} |
| 783 |
else { |
| 784 |
$cost = (FOR_ONE_TRAIN.' 3 '.ADAMANTIUM.', 2 '.CRYSTAL.', 1 '.PLATINUM.', '.$baseenergycost.' '.ENERGY); |
| 785 |
} |
| 786 |
$maxtries = floor($player -> energy / $baseenergycost); |
| 787 |
$smarty -> assign(array( |
| 788 |
"Cost" => $cost, |
| 789 |
"Maxtries" => $maxtries, |
| 790 |
"Corename" => $corename, |
| 791 |
"Coreid" => $coreid, |
| 792 |
"Trained" => "N" |
| 793 |
)); |
| 794 |
} |
| 795 |
} |
| 796 |
$smarty -> display('core.tpl'); |
| 797 |
break; |
| 798 |
} |
| 799 |
/** |
| 800 |
* buy cores |
| 801 |
*/ |
| 802 |
case 'market': { |
| 803 |
if (isset($_GET['buy'])) { |
| 804 |
$coreid = (int)$_GET['buy']; |
| 805 |
if (!isset($coreid) || $coreid == '') error(ERROR); |
| 806 |
$core = $db -> Execute("SELECT `prize`, `owner`, `status`, `coresbase`.`id` AS `name` FROM `coresplayers`, `coresbase` WHERE `base` = `coresbase`.`id` AND `coresplayers`.`id` = ".$coreid); |
| 807 |
if ($core -> fields['owner'] == $player -> id) error(IS_YOURS); |
| 808 |
if ($core -> fields['status'] != 'S') error(NOT_FOR_SALE); |
| 809 |
if ($core -> fields['prize'] > $player -> credits) error(NO_MONEY); |
| 810 |
$db -> Execute("UPDATE `players` SET `credits` = `credits` - ".($core -> fields['prize'])." WHERE `id` = ".($player -> id)); |
| 811 |
$db -> Execute("UPDATE `players` SET `bank` = `bank` + ".($core -> fields['prize'])." WHERE `id` = ".($core -> fields['owner'])); |
| 812 |
$db -> Execute("UPDATE `coresplayers` SET `prize` = 0, `status` = 'N', `owner` = ".($player -> id)." WHERE `id` = ".($coreid)); |
| 813 |
$smarty -> assign("Message",'<b>'.YOU_BOUGHT.'</b><br/><br/>'); |
| 814 |
$smarty -> display('error1.tpl'); |
| 815 |
global $newdate; |
| 816 |
$strDate = $db -> DBDate($newdate); |
| 817 |
$msg = '<a href="view.php?view='.($player -> id).'">'.($player -> user).'</a> '.BOUGHT.' '.($names[$core -> fields['name']]).'. '.YOU_GOT.' <b>'.($core -> fields['prize']).'</b> '.GOLD_PIECES.' '.TO_BANK; |
| 818 |
$db -> Execute('INSERT INTO `log` (`owner`, `log`, `czas`) VALUES('.($core -> fields['owner']).', \''.$msg.'\', '.$strDate.');'); |
| 819 |
} |
| 820 |
$cores = $db -> Execute("SELECT `players`.`id` AS `pid`, `coresplayers`.`id`, `user`, `prize`, `coresplayers`.`attack`, `coresplayers`.`defence`, `coresplayers`.`speed`, `coresplayers`.`max_hp`, `coresbase`.`id` AS `name`, `coresplayers`.`gender` FROM `players`, `coresplayers`, `coresbase` WHERE `status` = 'S' AND `owner`=`players`.`id` AND `base` = `coresbase`.`id` AND `owner` <> ".($player -> id)." ORDER BY `prize`, `coresbase`.`id`"); |
| 821 |
for ($i = 0; !$cores -> EOF ; $i++) { |
| 822 |
$namelist[$i] = $names[$cores -> fields['name']]; |
| 823 |
$attacklist[$i] = $cores -> fields['attack']; |
| 824 |
$defencelist[$i] = $cores -> fields['defence']; |
| 825 |
$speedlist[$i] = $cores -> fields['speed']; |
| 826 |
$hplist[$i] = $cores -> fields['max_hp']; |
| 827 |
$prizelist[$i] = $cores -> fields['prize']; |
| 828 |
$idlist[$i] = $cores -> fields['id']; |
| 829 |
$ownerlist[$i] = $cores -> fields['user']; |
| 830 |
$owneridlist[$i] = $cores -> fields['pid']; |
| 831 |
$genderlist[$i] = ($cores -> fields['gender'] == 'M') ? GENDER_MALE : GENDER_FEMALE; |
| 832 |
$cores -> MoveNext(); |
| 833 |
} |
| 834 |
if (isset($namelist)) { |
| 835 |
$smarty -> assign(array( |
| 836 |
"Namelist" => $namelist, |
| 837 |
"Attacklist" => $attacklist, |
| 838 |
"Defencelist" => $defencelist, |
| 839 |
"Speedlist" => $speedlist, |
| 840 |
"Hplist" => $hplist, |
| 841 |
"Prizelist" => $prizelist, |
| 842 |
"Idlist" => $idlist, |
| 843 |
"Genderlist" => $genderlist, |
| 844 |
"Ownerlist" => $ownerlist, |
| 845 |
"Owneridlist" => $owneridlist |
| 846 |
)); |
| 847 |
} |
| 848 |
else $smarty -> assign('Namelist', ''); |
| 849 |
$sellcores = $db -> Execute("SELECT `coresplayers`.`id`, `coresplayers`.`attack`, `coresplayers`.`defence`, `coresplayers`.`speed`, `coresplayers`.`hp`, `coresplayers`.`max_hp`, `coresbase`.`id` AS `name`, `petname`, `coresplayers`.`gender` FROM `coresplayers`, `coresbase` WHERE `status` = 'N' AND `coresplayers`.`hp` > 0 AND `base` = `coresbase`.`id` AND `owner` = ".($player -> id)." ORDER BY `coresbase`.`id`"); |
| 850 |
for ($i = 0; !$sellcores -> EOF ; $i++) { |
| 851 |
$salenamelist[$i] = ($sellcores -> fields['petname']).' ('.($names[$sellcores -> fields['name']]).')'; |
| 852 |
$saleattacklist[$i] = $sellcores -> fields['attack']; |
| 853 |
$saledefencelist[$i] = $sellcores -> fields['defence']; |
| 854 |
$salespeedlist[$i] = $sellcores -> fields['speed']; |
| 855 |
$salehplist[$i] = ($sellcores -> fields['hp']).' / '.($sellcores -> fields['max_hp']); |
| 856 |
$saleidlist[$i] = $sellcores -> fields['id']; |
| 857 |
$salegenderlist[$i] = ($sellcores -> fields['gender'] == 'M') ? GENDER_MALE : GENDER_FEMALE; |
| 858 |
$sellcores -> MoveNext(); |
| 859 |
} |
| 860 |
if (isset($salenamelist)) { |
| 861 |
$smarty -> assign(array( |
| 862 |
"SellNamelist" => $salenamelist, |
| 863 |
"SellAttacklist" => $saleattacklist, |
| 864 |
"SellDefencelist" => $saledefencelist, |
| 865 |
"SellSpeedlist" => $salespeedlist, |
| 866 |
"SellHplist" => $salehplist, |
| 867 |
"SellIdlist" => $saleidlist, |
| 868 |
"SellGenderlist" => $salegenderlist |
| 869 |
)); |
| 870 |
} |
| 871 |
else $smarty -> assign('SellNamelist', ''); |
| 872 |
$smarty -> display('core.tpl'); |
| 873 |
break; |
| 874 |
} |
| 875 |
/** |
| 876 |
* cores' arena |
| 877 |
*/ |
| 878 |
case 'arena': { |
| 879 |
//choosing cores to fight |
| 880 |
if (isset($_GET['arena'])) { |
| 881 |
if ($player -> energy < 0.5) error(NO_ENERGY); |
| 882 |
if ($_GET['arena'] != 'Z' && $_GET['arena'] != 'M') error(WRONG_ARENA); |
| 883 |
else $smarty -> assign("Arena",$_GET['arena']); |
| 884 |
$mycores = $db -> Execute("SELECT `coresplayers`.`id`, `coresplayers`.`petname`, `coresplayers`.`attack`, `coresplayers`.`defence`, `coresplayers`.`speed`, `coresplayers`.`max_hp`, `coresplayers`.`hp`, `coresbase`.`id` AS `name` FROM `coresplayers`, `coresbase` WHERE `status` = 'A' AND `base` = `coresbase`.`id` AND `coresplayers`.`hp` > 0 AND `coresbase`.`arena` = '".($_GET['arena'])."' AND `fights` < 3 AND `owner` = ".($player -> id)." ORDER BY `base`"); |
| 885 |
for ($i = 0; !$mycores -> EOF ; $i++) { |
| 886 |
$namelist[$i] = ($mycores -> fields['petname']).' ('.($names[$mycores -> fields['name']]).')'; |
| 887 |
$attacklist[$i] = $mycores -> fields['attack']; |
| 888 |
$defencelist[$i] = $mycores -> fields['defence']; |
| 889 |
$speedlist[$i] = $mycores -> fields['speed']; |
| 890 |
$hplist[$i] = ($mycores -> fields['hp']).' / '.($mycores -> fields['max_hp']); |
| 891 |
$idlist[$i] = $mycores -> fields['id']; |
| 892 |
$mycores -> MoveNext(); |
| 893 |
} |
| 894 |
if ($i == 0) error(NO_ACTIVE_CORE); |
| 895 |
|
| 896 |
$opcores = $db -> Execute("SELECT `user`, `owner`, `coresplayers`.`id`, `coresplayers`.`petname`, `coresbase`.`id` AS `name` FROM `players`, `coresplayers`, `coresbase` WHERE `status` = 'A' AND `base` = `coresbase`.`id` AND `coresplayers`.`hp` > 0 AND `coresbase`.`arena` = '".($_GET['arena'])."' AND `owner` <> ".($player -> id)." AND `fights` < 3 AND `owner`=`players`.`id` ORDER BY `base`"); |
| 897 |
|
| 898 |
for ($i = 0; !$opcores -> EOF ; $i++) { |
| 899 |
$onamelist[$i] = ($opcores -> fields['petname']).' ('.($names[$opcores -> fields['name']]).')'; |
| 900 |
$oidlist[$i] = $opcores -> fields['id']; |
| 901 |
$oownerlist[$i] = $opcores -> fields['user']; |
| 902 |
$oowneridlist[$i] = $opcores -> fields['owner']; |
| 903 |
$opcores -> MoveNext(); |
| 904 |
} |
| 905 |
if ($i == 0) error(NO_OPPONENTS); |
| 906 |
|
| 907 |
$smarty -> assign(array( |
| 908 |
"Namelist" => $namelist, |
| 909 |
"Attacklist" => $attacklist, |
| 910 |
"Defencelist" => $defencelist, |
| 911 |
"Speedlist" => $speedlist, |
| 912 |
"Hplist" => $hplist, |
| 913 |
"Idlist" => $idlist, |
| 914 |
"ONamelist" => $onamelist, |
| 915 |
"OIdlist" => $oidlist, |
| 916 |
"OOwnerlist" => $oownerlist, |
| 917 |
"OOwneridlist" => $oowneridlist, |
| 918 |
)); |
| 919 |
} |
| 920 |
//cores fight |
| 921 |
else if (isset($_GET['action']) && $_GET['action'] == 'fight') { |
| 922 |
//integercheck |
| 923 |
if (isset($_POST['my'])) $myid = (int)$_POST['my']; |
| 924 |
if (!isset($myid) || $myid == '') error(ERROR); |
| 925 |
if (isset($_POST['opponent'])) $opid = (int)$_POST['opponent']; |
| 926 |
if (!isset($opid) || $opid == '') error(ERROR); |
| 927 |
|
| 928 |
if ($player -> energy < 0.5) error(NO_ENERGY); |
| 929 |
|
| 930 |
$mycore = $db -> Execute("SELECT `owner`, `coresplayers`.`petname`, `coresplayers`.`attack`, `coresplayers`.`defence`, `coresplayers`.`speed`, `arena`, `fights`, `coresplayers`.`hp`, `coresplayers`.`max_hp`, `coresbase`.`id` AS `name`, `cost` FROM `coresplayers`, `coresbase` WHERE `status` = 'A' AND `base` = `coresbase`.`id` AND `coresplayers`.`id` = ".$myid); |
| 931 |
if (!isset($mycore) || $mycore -> EOF) error(NO_CORE); |
| 932 |
if ($mycore -> fields['fights'] > 2) error(YOURS_EXHAUSTED); |
| 933 |
if ($mycore -> fields['owner'] != $player -> id) error(NOT_YOURS); |
| 934 |
if ($mycore -> fields['hp'] <= 0) error(YOURS_IS_DEAD); |
| 935 |
|
| 936 |
//prepare attacker's core array |
| 937 |
$attacker['name'] = ($mycore -> fields['petname'] != '') ? ($mycore -> fields['petname']).' - ' : '' ; |
| 938 |
$attacker['name'] .= $names[($mycore -> fields['name'])]; |
| 939 |
$attacker['attack'] = $mycore -> fields['attack']; |
| 940 |
$attacker['defence'] = $mycore -> fields['defence']; |
| 941 |
$attacker['speed'] = $mycore -> fields['speed']; |
| 942 |
$attacker['hp'] = $mycore -> fields['hp']; |
| 943 |
$attacker['max_hp'] = $mycore -> fields['max_hp']; |
| 944 |
$attacker['user'] = $player -> user; |
| 945 |
$attacker['ownerid'] = $player -> id; |
| 946 |
|
| 947 |
$opcore = $db -> Execute("SELECT `players`.`id`, `user`, `owner`, `coresplayers`.`petname`, `coresplayers`.`attack`, `coresplayers`.`defence`, `coresplayers`.`speed`, `arena`, `fights`, `coresplayers`.`hp`, `coresplayers`.`max_hp`, `coresbase`.`id` AS `name`, `cost` FROM `players`, `coresplayers`, `coresbase` WHERE `status` = 'A' AND `base` = `coresbase`.`id` AND `coresplayers`.`id` = ".$opid." AND `owner` = `players`.`id`"); |
| 948 |
if (!isset($opcore) || $opcore -> EOF) error(NO_OPPONENT); |
| 949 |
if ($opcore -> fields['fights'] > 2) error(OPPONENTS_EXHAUSTED); |
| 950 |
if ($opcore -> fields['hp'] <= 0) error(OPPONENTS_IS_DEAD); |
| 951 |
if ($mycore -> fields['owner'] == $opcore -> fields['owner']) error(YOUR_OWN); |
| 952 |
if ($mycore -> fields['arena'] != $opcore -> fields['arena']) error(DIFFERENT_ARENA); |
| 953 |
|
| 954 |
//prepare defender's core array |
| 955 |
$defender['name'] = ($opcore -> fields['petname'] != '') ? ($opcore -> fields['petname']).' - ' : '' ; |
| 956 |
$defender['name'] .= $names[($opcore -> fields['name'])]; |
| 957 |
$defender['attack'] = $opcore -> fields['attack']; |
| 958 |
$defender['defence'] = $opcore -> fields['defence']; |
| 959 |
$defender['speed'] = $opcore -> fields['speed']; |
| 960 |
$defender['hp'] = $opcore -> fields['hp']; |
| 961 |
$defender['max_hp'] = $opcore -> fields['max_hp']; |
| 962 |
$defender['user'] = $opcore -> fields['user']; |
| 963 |
$defender['ownerid'] = $opcore -> fields['id']; |
| 964 |
|
| 965 |
$db -> Execute("UPDATE `players` SET `energy` = `energy` - 0.5 WHERE `id` = ".($player -> id)); |
| 966 |
|
| 967 |
//fight |
| 968 |
if ($attacker['speed'] < $defender['speed']) $fightlog = corefight($defender,$attacker); |
| 969 |
else $fightlog = corefight($attacker,$defender); |
| 970 |
|
| 971 |
//page title |
| 972 |
$fight = '['.($attacker['user']).'] '.($attacker['name']).' '.VERSUS.' '.($defender['name']).' ['.($defender['user']).']'; |
| 973 |
|
| 974 |
//after fight |
| 975 |
if ($attacker['hp'] < 0) $attacker['hp'] = 0; |
| 976 |
if ($defender['hp'] < 0) $defender['hp'] = 0; |
| 977 |
if ($attacker['hp'] > 0 && $defender['hp'] > 0) { |
| 978 |
$result = YOU_DRAW; |
| 979 |
$db -> Execute("UPDATE `coresplayers` SET `hp` = ".($attacker['hp']).", `fights` = `fights` + 1 WHERE `id` = ".$myid); |
| 980 |
$db -> Execute("UPDATE `coresplayers` SET `hp` = ".($defender['hp']).", `fights` = `fights` + 1 WHERE `id` = ".$opid); |
| 981 |
$smarty -> assign('Reward',''); |
| 982 |
$msg = CORE_M.' '.($attacker['name']).' [<a href="view.php?view='.($attacker['ownerid']).'">'.($attacker['user']).'</a>] '.ATTACKED.' '.($defender['name']).'. '.YOU_DRAW; |
| 983 |
} |
| 984 |
else if ($attacker['hp'] > 0 && $defender['hp'] == 0) { |
| 985 |
$result = YOU_WON; |
| 986 |
$gainHp = rand(1, ($opcore -> fields['cost'])) / 10; |
| 987 |
$db -> Execute("UPDATE `coresplayers` SET `hp` = ".($attacker['hp']).", `max_hp` = `max_hp` + ".$gainHp.", `fights` = `fights` + 1, `wins` = `wins` + 1 WHERE `id` = ".$myid); |
| 988 |
$db -> Execute("UPDATE `coresplayers` SET `hp` = ".($defender['hp']).", `fights` = `fights` + 1, `loses` = `loses` + 1 WHERE `id` = ".$opid); |
| 989 |
//attacker wins and get gold to hand |
| 990 |
$gainGold = ceil($defender['attack'] + $defender['defence'] + $defender['speed'] + $defender['max_hp']); |
| 991 |
$gainGold *= (($opcore -> fields['arena']) == 'Z') ? 2 : 3; |
| 992 |
$gainPlatinum = rand(0,ceil($gainGold/200)); |
| 993 |
$smarty -> assign('Reward',YOU_GOT.' <b>'.$gainGold.'</b> '.GOLD_PIECES.', <b>'.$gainPlatinum.'</b> '.PLATINUM); |
| 994 |
$db -> Execute("UPDATE `players` SET `credits` = `credits` + ".$gainGold.", `platinum` = `platinum` + ".$gainPlatinum." WHERE `id` = ".$attacker['ownerid']); |
| 995 |
$msg = CORE_M.' '.($attacker['name']).' [<a href="view.php?view='.($attacker['ownerid']).'">'.($attacker['user']).'</a>] '.ATTACKED.' '.($defender['name']).'. '.YOU_LOST; |
| 996 |
} |
| 997 |
else { |
| 998 |
$result = YOU_LOST; |
| 999 |
$gainHp = rand(1, ($mycore -> fields['cost'])) / 10; |
| 1000 |
$db -> Execute("UPDATE `coresplayers` SET `hp` = ".($attacker['hp']).", `fights` = `fights` + 1, `loses` = `loses` + 1 WHERE `id` = ".$myid); |
| 1001 |
$db -> Execute("UPDATE `coresplayers` SET `hp` = ".($defender['hp']).", `max_hp` = `max_hp` + ".$gainHp.", `fights` = `fights` + 1, `wins` = `wins` + 1 WHERE `id` = ".$opid); |
| 1002 |
//defender wins and get gold to bank |
| 1003 |
$gainGold = ceil($attacker['attack'] + $attacker['defence'] + $attacker['speed'] + $attacker['max_hp']); |
| 1004 |
$gainGold *= (($opcore -> fields['arena']) == 'Z') ? 2 : 3; |
| 1005 |
$gainPlatinum = rand(0,ceil($gainGold/200)); |
| 1006 |
$db -> Execute("UPDATE `players` SET `bank` = `bank` + ".$gainGold.", `platinum` = `platinum` + ".$gainPlatinum." WHERE `id` = ".$defender['ownerid']); |
| 1007 |
$smarty -> assign('Reward',''); |
| 1008 |
$msg = CORE_M.' '.($attacker['name']).' [<a href="view.php?view='.($attacker['ownerid']).'">'.($attacker['user']).'</a>] '.ATTACKED.' '.($defender['name']).'. '.YOU_WON.' '.YOU_GOT.' <b>'.($gainGold).'</b> '.GOLD_PIECES.', '.($gainPlatinum).PLATINUM; |
| 1009 |
} |
| 1010 |
|
| 1011 |
global $newdate; |
| 1012 |
$strDate = $db -> DBDate($newdate); |
| 1013 |
$db -> Execute('INSERT INTO `log` (`owner`, `log`, `czas`) VALUES('.($defender['ownerid']).', \''.$msg.'\', '.$strDate.');'); |
| 1014 |
|
| 1015 |
|
| 1016 |
$smarty -> assign(array( |
| 1017 |
"Fight" => $fight, |
| 1018 |
"Log" => $fightlog, |
| 1019 |
"Result" => $result, |
| 1020 |
"Arena" => '' |
| 1021 |
)); |
| 1022 |
} |
| 1023 |
//choosing arena - main view |
| 1024 |
else { |
| 1025 |
$smarty -> assign(array( |
| 1026 |
"Arena" => '', |
| 1027 |
"Fight" => '' |
| 1028 |
)); |
| 1029 |
} |
| 1030 |
$smarty -> display('core.tpl'); |
| 1031 |
break; |
| 1032 |
} |
| 1033 |
/** |
| 1034 |
* breeding cores |
| 1035 |
*/ |
| 1036 |
case 'breed': { |
| 1037 |
if (isset($_POST['maleid']) && isset($_POST['femaleid'])) { |
| 1038 |
//integercheck |
| 1039 |
$malecoreid = (int)$_POST['maleid']; |
| 1040 |
if (!isset($malecoreid) || $malecoreid == '') error(ERROR); |
| 1041 |
$femalecoreid = (int)$_POST['femaleid']; |
| 1042 |
if (!isset($femalecoreid) || $femalecoreid == '') error(ERROR); |
| 1043 |
|
| 1044 |
$malecore = $db -> Execute("SELECT `owner`, `coresplayers`.`attack`, `coresplayers`.`defence`, `coresplayers`.`speed`, `coresplayers`.`hp`, `coresplayers`.`max_hp`, `coresbase`.`id` AS `name`, `petname`, `gender`, `age`, `maturity`, `rest`, `status`, `arena`, `cost`, `base` FROM `coresplayers`, `coresbase` WHERE `coresbase`.`id` = `base` AND `coresplayers`.`id` = ".($malecoreid)); |
| 1045 |
|
| 1046 |
if ($malecore -> fields['owner'] != $player -> id) error(NOT_YOURS); |
| 1047 |
if ($malecore -> fields['status'] != 'N') error(WRONG_STATUS); |
| 1048 |
if ($malecore -> fields['hp'] <= 0) error(IS_DEAD); |
| 1049 |
if ($malecore -> fields['gender'] != 'M') error(WRONG_GENDER); |
| 1050 |
if ($malecore -> fields['age'] < $malecore -> fields['maturity']) error(TOO_YOUNG); |
| 1051 |
if ($malecore -> fields['rest'] > 0) error(NEED_REST); |
| 1052 |
|
| 1053 |
$femalecore = $db -> Execute("SELECT `owner`, `coresplayers`.`attack`, `coresplayers`.`defence`, `coresplayers`.`speed`, `coresplayers`.`hp`, `coresplayers`.`max_hp`, `coresbase`.`id` AS `name`, `petname`, `gender`, `age`, `maturity`, `rest`, `status` FROM `coresplayers`, `coresbase` WHERE `coresbase`.`id` = `base` AND `coresplayers`.`id` = ".($femalecoreid)); |
| 1054 |
|
| 1055 |
if ($femalecore -> fields['owner'] != $player -> id) error(NOT_YOURS); |
| 1056 |
if ($femalecore -> fields['status'] != 'N') error(WRONG_STATUS); |
| 1057 |
if ($femalecore -> fields['hp'] <= 0) error(IS_DEAD); |
| 1058 |
if ($femalecore -> fields['gender'] != 'F') error(WRONG_GENDER); |
| 1059 |
if ($femalecore -> fields['age'] < $femalecore -> fields['maturity']) error(TOO_YOUNG); |
| 1060 |
if ($femalecore -> fields['rest'] > 0) error(NEED_REST); |
| 1061 |
|
| 1062 |
if ($femalecore -> fields['name'] != $malecore -> fields['name']) error(WRONG_SPECIES); |
| 1063 |
|
| 1064 |
$statsum = $malecore -> fields['attack'] + $femalecore -> fields['attack'] + $malecore -> fields['defence'] + $femalecore -> fields['defence'] + $malecore -> fields['speed'] + $femalecore -> fields['speed']; |
| 1065 |
|
| 1066 |
$energycost = $malecore -> fields['cost']; |
| 1067 |
|
| 1068 |
$platinumcost = floor($statsum / 100); |
| 1069 |
$adamantiumcost = floor($statsum / 200); |
| 1070 |
$crystalcost = floor($statsum / 200); |
| 1071 |
$meteorcost = ($malecore -> fields['arena'] == 'M') ? floor($statsum / 400) : 0; |
| 1072 |
|
| 1073 |
$minerals = $db -> Execute("SELECT `adamantium`, `crystal`, `meteor` FROM `minerals` WHERE `owner` = ".($player -> id)); |
| 1074 |
|
| 1075 |
if ($platinumcost > $player -> platinum || |
| 1076 |
$adamantiumcost > $minerals -> fields['adamantium'] || |
| 1077 |
$crystalcost > $minerals -> fields['crystal'] || |
| 1078 |
$meteorcost > $minerals -> fields['meteor']) |
| 1079 |
$nominerals = NO_MINERALS; |
| 1080 |
|
| 1081 |
if ($energycost > $player -> energy) $noenergy = NO_ENERGY; |
| 1082 |
|
| 1083 |
if (isset($_POST['cross'])) { |
| 1084 |
if (isset($nominerals)) error(NO_MINERALS); |
| 1085 |
if (isset($noenergy)) error(NO_ENERGY); |
| 1086 |
$rest = ceil($malecore -> fields['maturity'] / 2); |
| 1087 |
|
| 1088 |
$templebless = $db -> Execute("SELECT `bless`, `blessval` FROM `players` WHERE `id` = ".($player -> id)); |
| 1089 |
if ($templebless -> fields['bless'] == 'breeding') { |
| 1090 |
$bless = $templebless -> fields['blessval']; |
| 1091 |
$player -> breeding += $bless; |
| 1092 |
} |
| 1093 |
|
| 1094 |
$chance = 1000 * $player -> breeding / $statsum - 5 * $malecore -> fields['cost']; |
| 1095 |
if ($chance > 90) $chance = 90; |
| 1096 |
|
| 1097 |
if (rand(1,100) <= $chance) { |
| 1098 |
$gainbreeding = round(0.03 * $energycost,2); |
| 1099 |
$gainExp = round($energycost * $malecore -> fields['cost'] * 10); |
| 1100 |
$newattack = rand(($malecore -> fields['attack']),($femalecore -> fields['attack'])) * rand(75,100) / 100; |
| 1101 |
$newdefence = rand(($malecore -> fields['defence']),($femalecore -> fields['defence'])) * rand(75,100) / 100; |
| 1102 |
$newspeed = rand(($malecore -> fields['speed']),($femalecore -> fields['speed'])) * rand(75,100) / 100; |
| 1103 |
$newhp = rand(($malecore -> fields['max_hp']),($femalecore -> fields['max_hp'])) * rand(75,100) / 100; |
| 1104 |
$newgender = (rand(1,2) == 1) ? 'M' : 'F'; |
| 1105 |
$db -> Execute("INSERT INTO `coresplayers` (`owner`, `base`, `attack`, `defence`, `speed`, `hp`, `max_hp`, `gender`) VALUES (".($player -> id).", ".($malecore -> fields['base']).", ".$newattack.", ".$newdefence.", ".$newspeed.", ".$newhp.", ".$newhp.", '".$newgender."')"); |
| 1106 |
$result = SUCCESS; |
| 1107 |
} |
| 1108 |
else { |
| 1109 |
$gainbreeding = round(0.01 * $energycost,2); |
| 1110 |
$result = LOSE; |
| 1111 |
} |
| 1112 |
|
| 1113 |
$db -> Execute("UPDATE `minerals` SET `adamantium` = `adamantium` - ".$adamantiumcost.", `crystal` = `crystal` - ".$crystalcost.", `meteor` = `meteor` - ".$meteorcost." WHERE `owner` = ".($player -> id)); |
| 1114 |
$db -> Execute("UPDATE `coresplayers` SET `rest` = ".$rest." WHERE `id` = ".$malecoreid." OR `id` = ".$femalecoreid); |
| 1115 |
|
| 1116 |
if (!isset($gainExp)) $gainExp = 0; |
| 1117 |
if ($gainExp > 0) { |
| 1118 |
require_once('includes/checkexp.php'); |
| 1119 |
checkexp($player -> exp, $gainExp, $player -> level, $player -> race, $player -> user, $player -> id, '', '', '','',0); |
| 1120 |
} |
| 1121 |
|
| 1122 |
$sql = "UPDATE `players` SET `breeding` = `breeding` + ".$gainbreeding.", `energy` = `energy` - ".$energycost.", `platinum` = `platinum` - ".$platinumcost; |
| 1123 |
if (isset($bless)) $sql .= ", `bless` = '', `blessval` = 0"; |
| 1124 |
$sql .= " WHERE `id` = ".($player -> id); |
| 1125 |
$db -> Execute($sql); |
| 1126 |
|
| 1127 |
$smarty -> assign(array( |
| 1128 |
"Result" => $result, |
| 1129 |
"Choosen" => 'Y', |
| 1130 |
"Gainbreed" => $gainbreeding, |
| 1131 |
"GainExp" => $gainExp |
| 1132 |
)); |
| 1133 |
|
| 1134 |
} |
| 1135 |
else { |
| 1136 |
|
| 1137 |
$malename = ($malecore -> fields['petname']).' ('.($names[$malecore -> fields['name']]).')'; |
| 1138 |
$maleattack = $malecore -> fields['attack']; |
| 1139 |
$maledefence = $malecore -> fields['defence']; |
| 1140 |
$malespeed = $malecore -> fields['speed']; |
| 1141 |
$malehp = ($malecore -> fields['hp']).' / '.($malecore -> fields['max_hp']); |
| 1142 |
|
| 1143 |
$femalename = ($femalecore -> fields['petname']).' ('.($names[$femalecore -> fields['name']]).')'; |
| 1144 |
$femaleattack = $femalecore -> fields['attack']; |
| 1145 |
$femaledefence = $femalecore -> fields['defence']; |
| 1146 |
$femalespeed = $femalecore -> fields['speed']; |
| 1147 |
$femalehp = ($femalecore -> fields['hp']).' / '.($femalecore -> fields['max_hp']); |
| 1148 |
|
| 1149 |
if (!isset($nominerals)) $nominerals = ''; |
| 1150 |
if (!isset($noenergy)) $noenergy = ''; |
| 1151 |
|
| 1152 |
$smarty -> assign(array( |
| 1153 |
"Result" => '', |
| 1154 |
"Choosen" => 'Y', |
| 1155 |
"Maleid" => $malecoreid, |
| 1156 |
"Malename" => $malename, |
| 1157 |
"Maleattack" => $maleattack, |
| 1158 |
"Maledefence" => $maledefence, |
| 1159 |
"Malespeed" => $malespeed, |
| 1160 |
"Malehp" => $malehp, |
| 1161 |
"Femaleid" => $femalecoreid, |
| 1162 |
"Femalename" => $femalename, |
| 1163 |
"Femaleattack" => $femaleattack, |
| 1164 |
"Femaledefence" => $femaledefence, |
| 1165 |
"Femalespeed" => $femalespeed, |
| 1166 |
"Femalehp" => $femalehp, |
| 1167 |
"Nominerals" => $nominerals, |
| 1168 |
"Adamantiumcost" => $adamantiumcost, |
| 1169 |
"Crystalcost" => $crystalcost, |
| 1170 |
"Platinumcost" => $platinumcost, |
| 1171 |
"Meteorcost" => $meteorcost, |
| 1172 |
"Energycost" => $energycost, |
| 1173 |
"Noenergy" => $noenergy |
| 1174 |
)); |
| 1175 |
} |
| 1176 |
} |
| 1177 |
else { |
| 1178 |
//list of male cores |
| 1179 |
$malecores = $db -> Execute("SELECT `coresplayers`.`id`, `coresplayers`.`attack`, `coresplayers`.`defence`, `coresplayers`.`speed`, `coresplayers`.`hp`, `coresplayers`.`max_hp`, `coresbase`.`id` AS `name`, `petname` FROM `coresplayers`, `coresbase` WHERE `status` = 'N' AND `coresplayers`.`hp` > 0 AND `base` = `coresbase`.`id` AND `rest` = 0 AND `age` >= `maturity` AND `gender` = 'M' AND `owner` = ".($player -> id)." ORDER BY `coresbase`.`id`"); |
| 1180 |
for ($i = 0; !$malecores -> EOF ; $i++) { |
| 1181 |
$malenamelist[$i] = ($malecores -> fields['petname']).' ('.($names[$malecores -> fields['name']]).')'; |
| 1182 |
$maleattacklist[$i] = $malecores -> fields['attack']; |
| 1183 |
$maledefencelist[$i] = $malecores -> fields['defence']; |
| 1184 |
$malespeedlist[$i] = $malecores -> fields['speed']; |
| 1185 |
$malehplist[$i] = ($malecores -> fields['hp']).' / '.($malecores -> fields['max_hp']); |
| 1186 |
$maleidlist[$i] = $malecores -> fields['id']; |
| 1187 |
$malecores -> MoveNext(); |
| 1188 |
} |
| 1189 |
if (isset($malenamelist)) { |
| 1190 |
$smarty -> assign(array( |
| 1191 |
"MaleNamelist" => $malenamelist, |
| 1192 |
"MaleAttacklist" => $maleattacklist, |
| 1193 |
"MaleDefencelist" => $maledefencelist, |
| 1194 |
"MaleSpeedlist" => $malespeedlist, |
| 1195 |
"MaleHplist" => $malehplist, |
| 1196 |
"MaleIdlist" => $maleidlist |
| 1197 |
)); |
| 1198 |
} |
| 1199 |
else error(NO_MALE_CORE); |
| 1200 |
|
| 1201 |
//list of female cores |
| 1202 |
$femalecores = $db -> Execute("SELECT `coresplayers`.`id`, `coresplayers`.`attack`, `coresplayers`.`defence`, `coresplayers`.`speed`, `coresplayers`.`hp`, `coresplayers`.`max_hp`, `coresbase`.`id` AS `name`, `petname` FROM `coresplayers`, `coresbase` WHERE `status` = 'N' AND `coresplayers`.`hp` > 0 AND `base` = `coresbase`.`id` AND `rest` = 0 AND `age` >= `maturity` AND `gender` = 'F' AND `owner` = ".($player -> id)." ORDER BY `coresbase`.`id`"); |
| 1203 |
for ($i = 0; !$femalecores -> EOF ; $i++) { |
| 1204 |
$femalenamelist[$i] = ($femalecores -> fields['petname']).' ('.($names[$femalecores -> fields['name']]).')'; |
| 1205 |
$femaleattacklist[$i] = $femalecores -> fields['attack']; |
| 1206 |
$femaledefencelist[$i] = $femalecores -> fields['defence']; |
| 1207 |
$femalespeedlist[$i] = $femalecores -> fields['speed']; |
| 1208 |
$femalehplist[$i] = ($femalecores -> fields['hp']).' / '.($femalecores -> fields['max_hp']); |
| 1209 |
$femaleidlist[$i] = $femalecores -> fields['id']; |
| 1210 |
$femalecores -> MoveNext(); |
| 1211 |
} |
| 1212 |
if (isset($femalenamelist)) { |
| 1213 |
$smarty -> assign(array( |
| 1214 |
"FemaleNamelist" => $femalenamelist, |
| 1215 |
"FemaleAttacklist" => $femaleattacklist, |
| 1216 |
"FemaleDefencelist" => $femaledefencelist, |
| 1217 |
"FemaleSpeedlist" => $femalespeedlist, |
| 1218 |
"FemaleHplist" => $femalehplist, |
| 1219 |
"FemaleIdlist" => $femaleidlist |
| 1220 |
)); |
| 1221 |
} |
| 1222 |
else error(NO_FEMALE_CORE); |
| 1223 |
|
| 1224 |
$smarty -> assign(array( |
| 1225 |
"Result" => '', |
| 1226 |
"Chosen" => '' |
| 1227 |
)); |
| 1228 |
|
| 1229 |
} |
| 1230 |
$smarty -> display('core.tpl'); |
| 1231 |
break; |
| 1232 |
} |
| 1233 |
/** |
| 1234 |
* best cores |
| 1235 |
*/ |
| 1236 |
case 'monuments': { |
| 1237 |
$bestnormal = $db -> Execute("SELECT `coresplayers`.`wins`, `petname`, `coresbase`.`id` AS `name`, `user`, `players`.`id` FROM `players`, `coresplayers`, `coresbase` WHERE `arena` = 'Z' AND `owner` = `players`.`id` AND `base` = `coresbase`.`id` ORDER BY `wins` DESC, `coresplayers`.`id` LIMIT 0 , 20"); |
| 1238 |
|
| 1239 |
$normalname = ''; |
| 1240 |
for($i = 0; !$bestnormal -> EOF; $i++, $bestnormal -> MoveNext()) { |
| 1241 |
$normalname[$i] = ($bestnormal -> fields['petname'] != '') ? '<b>'.($bestnormal -> fields['petname']).'</b> ('.$names[($bestnormal -> fields['name'])].')' : $names[($bestnormal -> fields['name'])]; |
| 1242 |
$normaluser[$i] = $bestnormal -> fields['user']; |
| 1243 |
$normalid[$i] = $bestnormal -> fields['id']; |
| 1244 |
$normalwins[$i] = $bestnormal -> fields['wins']; |
| 1245 |
} |
| 1246 |
if ($normalname != '') |
| 1247 |
$smarty -> assign(array( |
| 1248 |
"Normalcores" => 'Y', |
| 1249 |
"Normalname" => $normalname, |
| 1250 |
"Normalwins" => $normalwins, |
| 1251 |
"Normaluser" => $normaluser, |
| 1252 |
"Normalid" => $normalid, |
| 1253 |
)); |
| 1254 |
else $smarty -> assign("Normalcores", ''); |
| 1255 |
|
| 1256 |
$bestmagic = $db -> Execute("SELECT `coresplayers`.`wins`, `petname`, `coresbase`.`id` AS `name`, `user`, `players`.`id` FROM `players`, `coresplayers`, `coresbase` WHERE `arena` = 'M' AND `owner` = `players`.`id` AND `base` = `coresbase`.`id` ORDER BY `wins` DESC, `coresplayers`.`id` LIMIT 0 , 20"); |
| 1257 |
|
| 1258 |
$magicname = ''; |
| 1259 |
for($i = 0; !$bestmagic -> EOF; $i++, $bestmagic -> MoveNext()) { |
| 1260 |
$magicname[$i] = ($bestmagic -> fields['petname'] != '') ? '<b>'.($bestmagic -> fields['petname']).'</b> ('.$names[($bestmagic -> fields['name'])].')' : $names[($bestmagic -> fields['name'])]; |
| 1261 |
$magicuser[$i] = $bestmagic -> fields['user']; |
| 1262 |
$magicid[$i] = $bestmagic -> fields['id']; |
| 1263 |
$magicwins[$i] = $bestmagic -> fields['wins']; |
| 1264 |
} |
| 1265 |
if ($magicname != '') |
| 1266 |
$smarty -> assign(array( |
| 1267 |
"Magiccores" => 'Y', |
| 1268 |
"Magicname" => $magicname, |
| 1269 |
"Magicwins" => $magicwins, |
| 1270 |
"Magicuser" => $magicuser, |
| 1271 |
"Magicid" => $magicid, |
| 1272 |
)); |
| 1273 |
else $smarty -> assign("Magiccores", ''); |
| 1274 |
|
| 1275 |
$smarty -> display('core.tpl'); |
| 1276 |
break; |
| 1277 |
} |
| 1278 |
} |
| 1279 |
} |
| 1280 |
|
| 1281 |
} |
| 1282 |
|
| 1283 |
require_once("includes/foot.php"); |
| 1284 |
?> |