| 1 |
<?php |
| 2 |
/** |
| 3 |
* File functions: |
| 4 |
* Explore forest and mountains |
| 5 |
* |
| 6 |
* @name : explore.php |
| 7 |
* @copyright : (C) 2004,2005,2006 Vallheru Team based on Gamers-Fusion ver 2.5 |
| 8 |
* @author : thindil <thindil@users.sourceforge.net> |
| 9 |
* @version : 1.3 |
| 10 |
* @since : 30.10.2006 |
| 11 |
* |
| 12 |
*/ |
| 13 |
|
| 14 |
// |
| 15 |
// |
| 16 |
// This program is free software; you can redistribute it and/or modify |
| 17 |
// it under the terms of the GNU General Public License as published by |
| 18 |
// the Free Software Foundation; either version 2 of the License, or |
| 19 |
// (at your option) any later version. |
| 20 |
// |
| 21 |
// This program is distributed in the hope that it will be useful, |
| 22 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 |
// GNU General Public License for more details. |
| 25 |
// |
| 26 |
// You should have received a copy of the GNU General Public License |
| 27 |
// along with this program; if not, write to the Free Software |
| 28 |
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 29 |
// |
| 30 |
// $Id: explore.php 796 2006-10-30 14:39:28Z thindil $ |
| 31 |
|
| 32 |
$title = "Poszukiwania"; |
| 33 |
require_once("includes/head.php"); |
| 34 |
require_once("includes/funkcje.php"); |
| 35 |
require_once("includes/turnfight.php"); |
| 36 |
require_once("includes/battle.php"); |
| 37 |
|
| 38 |
/** |
| 39 |
* Get the localization for game |
| 40 |
*/ |
| 41 |
require_once("languages/".$player -> lang."/explore.php"); |
| 42 |
|
| 43 |
if ($player -> location == 'Altara') |
| 44 |
{ |
| 45 |
error (ERROR); |
| 46 |
} |
| 47 |
if ($player -> hp <= 0) |
| 48 |
{ |
| 49 |
if ($player -> location == 'Góry') |
| 50 |
error (YOU_DEAD2, 1, 'gory.php'); |
| 51 |
elseif ($player -> location == '') |
| 52 |
error (YOU_DEAD2, 1, 'las.php'); |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
/** |
| 57 |
* Assign variables to template |
| 58 |
*/ |
| 59 |
$smarty -> assign(array("Link" => '', |
| 60 |
"Menu" => '', |
| 61 |
"Youwant" => YOU_WANT, |
| 62 |
"Ayes" => YES, |
| 63 |
"Ano" => NO)); |
| 64 |
|
| 65 |
/** |
| 66 |
* Function to fight with monsters |
| 67 |
*/ |
| 68 |
function battle($type,$adress) |
| 69 |
{ |
| 70 |
require_once('class/monster_class.php'); |
| 71 |
require_once('class/fight_class.php'); |
| 72 |
global $player; |
| 73 |
global $smarty; |
| 74 |
global $enemy; |
| 75 |
global $arrehp; |
| 76 |
global $db; |
| 77 |
if ($player -> hp <= 0) |
| 78 |
{ |
| 79 |
error (NO_LIFE); |
| 80 |
} |
| 81 |
if ($type == 'T') |
| 82 |
{ |
| 83 |
if (!isset ($_POST['action'])) |
| 84 |
{ |
| 85 |
//prepare session variables for monsters and player |
| 86 |
$monster = new Monster($player -> fight,1,0); |
| 87 |
$attacker = new Fighter($player -> id); |
| 88 |
$_SESSION['amount'] = 1; |
| 89 |
for ($k = 0; $k < $_SESSION['amount']; $k++) { |
| 90 |
//each monster identifier |
| 91 |
$strIndex = 'mon'.$k; |
| 92 |
$_SESSION[$strIndex]['id'] = $monster -> id; |
| 93 |
//each monster hit points |
| 94 |
$_SESSION[$strIndex]['hp'] = $monster -> hp; |
| 95 |
//each monster action points |
| 96 |
if ($attacker -> speed > $monster -> attackspeed) { |
| 97 |
$_SESSION[$strIndex]['ap'] = 1; |
| 98 |
} |
| 99 |
else { |
| 100 |
$_SESSION[$strIndex]['ap'] = floor($monster -> attackspeed / $attacker -> speed); |
| 101 |
if ($_SESSION[$strIndex]['ap'] > 5) { |
| 102 |
$_SESSION[$strIndex]['ap'] = 5; |
| 103 |
} |
| 104 |
} |
| 105 |
$tmpActionArr[$k][0] = $monster -> attackspeed; |
| 106 |
$tmpActionArr[$k][1] = $k; |
| 107 |
} |
| 108 |
$tmpActionArr[$k][0] = $attacker -> speed; |
| 109 |
$tmpActionArr[$k][1] = -1; |
| 110 |
|
| 111 |
/** |
| 112 |
* function to compare elements of actionArr |
| 113 |
*/ |
| 114 |
function aacmp($a,$b) { |
| 115 |
if ($a[0] == $b[0]) return 0; |
| 116 |
return ($a[0] > $b[0]) ? -1 : 1; |
| 117 |
} |
| 118 |
|
| 119 |
usort($tmpActionArr,"aacmp"); |
| 120 |
for ($k = 0; $k <= $_SESSION['amount']; $k++) { |
| 121 |
$actionArr[$k] = $tmpActionArr[$k][1]; |
| 122 |
} |
| 123 |
$_SESSION['actionArr'] = $actionArr; |
| 124 |
$_SESSION['exhaust']=0; |
| 125 |
if ($attacker -> speed > $monster -> attackspeed) { |
| 126 |
$_SESSION['points'] = floor($attacker -> speed / $monster -> attackspeed); |
| 127 |
if ($_SESSION['points'] > 5) { |
| 128 |
$_SESSION['points'] = 5; |
| 129 |
} |
| 130 |
} |
| 131 |
else { |
| 132 |
$_SESSION['points'] = 1; |
| 133 |
} |
| 134 |
$_SESSION['round']=0; |
| 135 |
} |
| 136 |
turnfight ($adress); |
| 137 |
if (isset($_SESSION['result'])) unset($_SESSION['result']); |
| 138 |
} |
| 139 |
else |
| 140 |
{ |
| 141 |
$monster = new Monster($player -> fight,1,0); |
| 142 |
$attacker = new Fighter($player -> id); |
| 143 |
pvmfastfight ($attacker,$monster,1,1); |
| 144 |
} |
| 145 |
$fight = $db -> Execute("SELECT `fight`, `hp` FROM `players` WHERE `id`=".$player -> id); |
| 146 |
if ($fight -> fields['fight'] == 0) |
| 147 |
{ |
| 148 |
$player -> energy = $player -> energy - 1; |
| 149 |
if ($player -> energy < 0) |
| 150 |
{ |
| 151 |
$player -> energy = 0; |
| 152 |
} |
| 153 |
$db -> Execute("UPDATE players SET energy=".$player -> energy." WHERE id=".$player -> id); |
| 154 |
if ($player -> location == 'Góry') |
| 155 |
{ |
| 156 |
if ($fight -> fields['hp'] > 0) |
| 157 |
{ |
| 158 |
$smarty -> assign ("Link", "<br /><br /><a href=\"explore.php?akcja=gory\">".A_REFRESH."</a><br />"); |
| 159 |
} |
| 160 |
else |
| 161 |
{ |
| 162 |
$smarty -> assign ("Link", "<br /><br /><a href=\"gory.php\">".A_REFRESH."</a><br />"); |
| 163 |
} |
| 164 |
} |
| 165 |
if ($player -> location == 'Las') |
| 166 |
{ |
| 167 |
if ($fight -> fields['hp'] > 0) |
| 168 |
{ |
| 169 |
$smarty -> assign ("Link", "<br /><br /><a href=\"explore.php\">".A_REFRESH."</a><br />"); |
| 170 |
} |
| 171 |
else |
| 172 |
{ |
| 173 |
$smarty -> assign ("Link", "<br /><br /><a href=\"las.php\">".A_REFRESH."</a><br />"); |
| 174 |
} |
| 175 |
} |
| 176 |
} |
| 177 |
$fight -> Close(); |
| 178 |
// $enemy1 -> Close(); |
| 179 |
} |
| 180 |
|
| 181 |
/** |
| 182 |
* If player not escape - start fight |
| 183 |
*/ |
| 184 |
if (isset($_GET['step']) && $_GET['step'] == 'battle') |
| 185 |
{ |
| 186 |
if (!isset ($_GET['type'])) |
| 187 |
{ |
| 188 |
$type = 'T'; |
| 189 |
} |
| 190 |
else |
| 191 |
{ |
| 192 |
$type = $_GET['type']; |
| 193 |
} |
| 194 |
battle($type,'explore.php?step=battle'); |
| 195 |
} |
| 196 |
|
| 197 |
/** |
| 198 |
* If player escape |
| 199 |
*/ |
| 200 |
if (isset($_GET['step']) && $_GET['step'] == 'run') |
| 201 |
{ |
| 202 |
$enemy = $db -> Execute("SELECT `level`, `speed`, `name`, `exp1`, `exp2`, `id` FROM `monsters` WHERE `id`=".$player -> fight); |
| 203 |
if ($player -> fight == 0) |
| 204 |
{ |
| 205 |
error(NO_MONSTER); |
| 206 |
} |
| 207 |
if (empty($enemy -> fields)) |
| 208 |
{ |
| 209 |
error(ERROR); |
| 210 |
} |
| 211 |
/** |
| 212 |
* Add bonus from rings |
| 213 |
*/ |
| 214 |
$arrEquip = $player -> equipment(); |
| 215 |
if ($arrEquip[9][2]) |
| 216 |
{ |
| 217 |
$arrRingtype = explode(" ", $arrEquip[9][1]); |
| 218 |
$intAmount = count($arrRingtype) - 1; |
| 219 |
if ($arrRingtype[$intAmount] == R_SPE4) |
| 220 |
{ |
| 221 |
$player -> speed = $player -> speed + $arrEquip[9][2]; |
| 222 |
} |
| 223 |
} |
| 224 |
if ($arrEquip[10][2]) |
| 225 |
{ |
| 226 |
$arrRingtype = explode(" ", $arrEquip[10][1]); |
| 227 |
$intAmount = count($arrRingtype) - 1; |
| 228 |
if ($arrRingtype[$intAmount] == R_SPE4) |
| 229 |
{ |
| 230 |
$player -> speed = $player -> speed + $arrEquip[10][2]; |
| 231 |
} |
| 232 |
} |
| 233 |
$chance = (rand(1, $player -> level * 100) + $player -> speed - $enemy -> fields['speed']); |
| 234 |
$intChance2 = rand(1, 10); |
| 235 |
$smarty -> assign(array("Chance" => $chance, |
| 236 |
"Chance2" => $intChance2)); |
| 237 |
if (($intChance2 < 3)||($chance > 0)) |
| 238 |
{ |
| 239 |
$intExpGain = 2; |
| 240 |
$intExpLvl = ceil($enemy -> fields['level']/10); |
| 241 |
if ($intExpGain < $intExpLvl) |
| 242 |
$intExpGain = $intExpLvl; |
| 243 |
$smarty -> assign(array("Ename" => $enemy -> fields['name'], |
| 244 |
"Expgain" => $intExpGain, |
| 245 |
"Escapesucc" => ESCAPE_SUCC, |
| 246 |
"Escapesucc2" => ESCAPE_SUCC2, |
| 247 |
"Escapesucc3" => ESCAPE_SUCC3)); |
| 248 |
checkexp($player -> exp, $intExpGain, $player -> level, $player -> race, $player -> user, $player -> id, 0, 0, $player -> id, '', 0); |
| 249 |
$db -> Execute("UPDATE `players` SET `fight`=0 WHERE `id`=".$player -> id); |
| 250 |
} |
| 251 |
else |
| 252 |
{ |
| 253 |
$strMessage = ESCAPE_FAIL." ".$enemy -> fields['name']." ".ESCAPE_FAIL2.".<br />"; |
| 254 |
$smarty -> assign ("Message", $strMessage); |
| 255 |
$smarty -> display ('error1.tpl'); |
| 256 |
battle('T','explore.php?step=battle'); |
| 257 |
} |
| 258 |
$hp = $db -> Execute("SELECT `hp` FROM `players` WHERE `id`=".$player -> id); |
| 259 |
$smarty -> assign ("Health", $hp -> fields['hp']); |
| 260 |
if ($player -> location == 'Góry' && $hp -> fields['hp'] > 0) |
| 261 |
{ |
| 262 |
$smarty -> assign (array("Yes" => "explore.php?akcja=gory", |
| 263 |
"No" => "gory.php")); |
| 264 |
} |
| 265 |
if ($player -> location == 'Las' && $hp -> fields['hp'] > 0) |
| 266 |
{ |
| 267 |
$smarty -> assign(array("Yes" => "explore.php", |
| 268 |
"No" => "las.php")); |
| 269 |
} |
| 270 |
$hp -> Close(); |
| 271 |
} |
| 272 |
|
| 273 |
/** |
| 274 |
* Explore moutains - main menu |
| 275 |
*/ |
| 276 |
if ($player -> hp > 0 && !isset($_GET['action']) && $player -> location == 'Góry' && !isset($_GET['step'])) |
| 277 |
{ |
| 278 |
if (!empty($player -> fight)) |
| 279 |
{ |
| 280 |
$enemy = $db -> Execute("SELECT `name` FROM `monsters` WHERE `id`=".$player -> fight); |
| 281 |
error (FIGHT1.$enemy -> fields['name'].FIGTH2."<br /> |
| 282 |
<a href=\"explore.php?step=battle\">".YES."</a><br /> |
| 283 |
<a href=\"explore.php?step=run\">".NO."</a><br />"); |
| 284 |
$enemy -> Close(); |
| 285 |
} |
| 286 |
else |
| 287 |
{ |
| 288 |
$smarty -> assign(array("Minfo" => M_INFO, |
| 289 |
"Howmuch" => HOW_MUCH, |
| 290 |
"Tenergy" => T_ENERGY, |
| 291 |
"Awalk" => T_WALK)); |
| 292 |
} |
| 293 |
} |
| 294 |
|
| 295 |
/** |
| 296 |
* Explore mountains - random encouter |
| 297 |
*/ |
| 298 |
if (isset($_GET['action']) && $_GET['action'] == 'moutains' && $player -> location == 'Góry' && !isset($_GET['step'])) |
| 299 |
{ |
| 300 |
if (!isset($_POST['amount']) || !ereg("^[0-9][0-9\.]*$", $_POST['amount'])) |
| 301 |
{ |
| 302 |
error(ERROR); |
| 303 |
} |
| 304 |
if ($_POST['amount'] > $player -> energy) |
| 305 |
{ |
| 306 |
error(TIRED2); |
| 307 |
} |
| 308 |
if ($player -> hp <= 0) |
| 309 |
{ |
| 310 |
error(YOU_DEAD2, 1, 'gory.php'); |
| 311 |
} |
| 312 |
if (!empty($player -> fight)) |
| 313 |
{ |
| 314 |
$enemy = $db -> Execute("SELECT `name` FROM `monsters` WHERE `id`=".$player -> fight); |
| 315 |
error (FIGHT3.$enemy -> fields['name'].FIGHT2."<br /> |
| 316 |
<a href=\"explore.php?step=battle\">".YES."</a><br /> |
| 317 |
<a href=\"explore.php?step=run\">".NO."</a><br />"); |
| 318 |
} |
| 319 |
$objMaps = $db -> Execute("SELECT `value` FROM `settings` WHERE `setting`='maps'"); |
| 320 |
$intAmount2 = $_POST['amount'] * 2; |
| 321 |
$arrGold = array(0, 0); |
| 322 |
$arrHerbs = array(0, 0, 0, 0); |
| 323 |
$intMeteor = 0; |
| 324 |
$intAstral = 0; |
| 325 |
$strEnemy = ''; |
| 326 |
$strBridge = ''; |
| 327 |
for ($i = 1; $i < $intAmount2; $i++) |
| 328 |
{ |
| 329 |
$intRoll = rand(1, 20); |
| 330 |
if ($intRoll == 9) |
| 331 |
{ |
| 332 |
$intAmount = rand(1,1000); |
| 333 |
$arrGold[0] = $arrGold[0] + $intAmount; |
| 334 |
} |
| 335 |
if ($intRoll == 10) |
| 336 |
{ |
| 337 |
$intAmount = rand(1,15); |
| 338 |
$intMeteor = $intMeteor + $intAmount; |
| 339 |
} |
| 340 |
if ($intRoll >= 11 && $intRoll <= 13) |
| 341 |
{ |
| 342 |
$intAmount = rand(1,10); |
| 343 |
$arrHerbs[0] = $arrHerbs[0] + $intAmount; |
| 344 |
} |
| 345 |
if ($intRoll >= 14 && $intRoll <= 15) |
| 346 |
{ |
| 347 |
$intAmount = rand(1,10); |
| 348 |
$arrHerbs[1] = $arrHerbs[1] + $intAmount; |
| 349 |
} |
| 350 |
if ($intRoll == 16) |
| 351 |
{ |
| 352 |
$intAmount = rand(1,10); |
| 353 |
$arrHerbs[2] = $arrHerbs[2] + $intAmount; |
| 354 |
} |
| 355 |
if ($intRoll == 18) |
| 356 |
{ |
| 357 |
$intAmount = rand(1,10); |
| 358 |
$arrHerbs[3] = $arrHerbs[3] + $intAmount; |
| 359 |
} |
| 360 |
if ($intRoll == 19) |
| 361 |
{ |
| 362 |
$intRoll2 = rand(1, 50); |
| 363 |
if ($intRoll2 == 50 && $objMaps -> fields['value'] > 0 && $player -> maps < 20 && $player -> rank != 'Bohater') |
| 364 |
{ |
| 365 |
$objMaps -> fields['value'] --; |
| 366 |
$player -> maps ++; |
| 367 |
$arrGold[1] ++; |
| 368 |
} |
| 369 |
} |
| 370 |
if ($intRoll == 20) |
| 371 |
{ |
| 372 |
require_once('includes/findastral.php'); |
| 373 |
$strResult = findastral(2); |
| 374 |
if ($strResult != false) |
| 375 |
{ |
| 376 |
$intAstral ++; |
| 377 |
} |
| 378 |
} |
| 379 |
if ($intRoll > 5 && $intRoll < 9) |
| 380 |
{ |
| 381 |
$intRoll2 = rand(1,5); |
| 382 |
if ($intRoll2 < 5 ) |
| 383 |
{ |
| 384 |
$arrMonsters = array(65, 67, 69, 71, 73, 74, 75, 77, 82); |
| 385 |
$intRoll3 = rand(0, 8); |
| 386 |
} |
| 387 |
if ($intRoll2 == 5) |
| 388 |
{ |
| 389 |
$arrMonsters = array(88, 92, 99, 114); |
| 390 |
$intRoll3 = rand(0, 3); |
| 391 |
} |
| 392 |
$enemy = $db -> Execute("SELECT `name`, `id` FROM `monsters` WHERE `id`=".$arrMonsters[$intRoll3]); |
| 393 |
$db -> Execute("UPDATE `players` SET `fight`=".$enemy -> fields['id']." WHERE `id`=".$player -> id); |
| 394 |
$strEnemy = YOU_MEET." ".$enemy -> fields['name'].FIGHT2."<br /> |
| 395 |
<a href=\"explore.php?step=battle\">".YES."</a><br /> |
| 396 |
<a href=\"explore.php?step=run\">".NO."</a><br />"; |
| 397 |
$player -> fight = $enemy -> fields['id']; |
| 398 |
$enemy -> Close(); |
| 399 |
break; |
| 400 |
} |
| 401 |
if ($intRoll == 17) |
| 402 |
{ |
| 403 |
$objBridge = $db -> Execute("SELECT `bridge` FROM `players` WHERE `id`=".$player -> id); |
| 404 |
if ($objBridge -> fields['bridge'] == 'N') |
| 405 |
{ |
| 406 |
$strBridge = ACTION8; |
| 407 |
break; |
| 408 |
} |
| 409 |
$objBridge -> Close(); |
| 410 |
} |
| 411 |
} |
| 412 |
|
| 413 |
$intHerbsum = array_sum($arrHerbs); |
| 414 |
$intGoldsum = array_sum($arrGold); |
| 415 |
if ($intHerbsum) |
| 416 |
{ |
| 417 |
$objHerbs = $db -> Execute("SELECT `gracz` FROM `herbs` WHERE `gracz`=".$player -> id); |
| 418 |
if ($objHerbs -> fields['gracz']) |
| 419 |
{ |
| 420 |
$db -> Execute("UPDATE `herbs` SET `illani`=`illani`+".$arrHerbs[0].", `illanias`=`illanias`+".$arrHerbs[1].", `nutari`=`nutari`+".$arrHerbs[2].", `dynallca`=`dynallca`+".$arrHerbs[3]." WHERE `gracz`=".$player -> id); |
| 421 |
} |
| 422 |
else |
| 423 |
{ |
| 424 |
$db -> Execute("INSERT INTO `herbs` (`gracz`, `illani`, `illanias`, `nutari`, `dynallca`) VALUES(".$player -> id.", ".$arrHerbs[0].", ".$arrHerbs[1].", ".$arrHerbs[2].", ".$arrHerbs[3].")"); |
| 425 |
} |
| 426 |
$objHerbs -> Close(); |
| 427 |
} |
| 428 |
if ($intMeteor) |
| 429 |
{ |
| 430 |
$objMinerals = $db -> Execute("SELECT `owner` FROM `minerals` WHERE `owner`=".$player -> id); |
| 431 |
if ($objMinerals -> fields['owner']) |
| 432 |
{ |
| 433 |
$db -> Execute("UPDATE `minerals` SET `meteor`=`meteor`+".$intMeteor." WHERE `owner`=".$player -> id); |
| 434 |
} |
| 435 |
else |
| 436 |
{ |
| 437 |
$db -> Execute("INSERT INTO `minerals` (`owner`, `meteor`) VALUES(".$player -> id.", ".$intMeteor.")"); |
| 438 |
} |
| 439 |
$objMinerals -> Close(); |
| 440 |
} |
| 441 |
$fltAmount = $i / 2; |
| 442 |
$strFind = YOU_GO.$fltAmount.T_AMOUNT2; |
| 443 |
if ($intHerbsum || $intGoldsum || $intAstral || $intMeteor) |
| 444 |
{ |
| 445 |
$strFind = $strFind.YOU_FIND; |
| 446 |
$arrAmounts = array($intMeteor, $arrHerbs[0], $arrHerbs[1], $arrHerbs[2], $arrHerbs[3], $intAstral, $arrGold[0], $arrGold[1]); |
| 447 |
$arrText = array(T_METEOR, HERB1, HERB2, HERB3, HERB4, T_ASTRALS, T_GOLD, T_MAPS); |
| 448 |
$i = 0; |
| 449 |
foreach ($arrAmounts as $intAmount) |
| 450 |
{ |
| 451 |
if ($intAmount) |
| 452 |
{ |
| 453 |
$strFind = $strFind.$intAmount.$arrText[$i]; |
| 454 |
} |
| 455 |
$i ++; |
| 456 |
} |
| 457 |
$strFind = $strFind."<br />"; |
| 458 |
} |
| 459 |
if (!$intHerbsum && !$intGoldsum && !$intAstral && $strEnemy == '' && $strBridge == '') |
| 460 |
{ |
| 461 |
$strFind = $strFind.FIND_NOTHING; |
| 462 |
} |
| 463 |
$db -> Execute("UPDATE `players` SET `credits`=`credits`+".$arrGold[0].", `energy`=`energy`-".$fltAmount.", `maps`=".$player -> maps." WHERE `id`=".$player -> id); |
| 464 |
$db -> Execute("UPDATE `settings` SET `value`=".$objMaps -> fields['value']." WHERE `setting`='maps'"); |
| 465 |
$objMaps -> Close(); |
| 466 |
$smarty -> assign(array("Youfind" => $strFind, |
| 467 |
"Howmuch" => HOW_MUCH, |
| 468 |
"Tenergy" => T_ENERGY, |
| 469 |
"Awalk" => T_WALK, |
| 470 |
"Enemy" => $strEnemy, |
| 471 |
"Bridge" => $strBridge)); |
| 472 |
} |
| 473 |
|
| 474 |
/** |
| 475 |
* Bridge of death in moutains |
| 476 |
*/ |
| 477 |
if (isset($_GET['action']) && $_GET['action'] == 'moutains' && $player -> location == 'Góry') |
| 478 |
{ |
| 479 |
if (isset($_GET['step']) && $_GET['step'] == 'first') |
| 480 |
{ |
| 481 |
if (!isset($_POST['check']) || isset($_SESSION['bridge'])) |
| 482 |
{ |
| 483 |
error(ERROR); |
| 484 |
} |
| 485 |
$_SESSION['bridge'] = 1; |
| 486 |
$smarty -> assign(array("Fquestion" => F_QUESTION, |
| 487 |
"Anext" => A_NEXT)); |
| 488 |
} |
| 489 |
if (isset ($_GET['step']) && $_GET['step'] == 'second') |
| 490 |
{ |
| 491 |
if (!isset($_SESSION['bridge']) || $_SESSION['bridge'] != 1 || $player -> hp <= 0) |
| 492 |
{ |
| 493 |
error(ERROR); |
| 494 |
} |
| 495 |
$answer = strip_tags($_POST['fanswer']); |
| 496 |
if ($answer == $player -> id) |
| 497 |
{ |
| 498 |
$_SESSION['bridge'] = 2; |
| 499 |
$smarty -> assign (array("Answer" => "true", |
| 500 |
"Squestion" => S_QUESTION, |
| 501 |
"Anext" => A_NEXT)); |
| 502 |
} |
| 503 |
else |
| 504 |
{ |
| 505 |
unset($_SESSION['bridge']); |
| 506 |
$db -> Execute("UPDATE `players` SET `hp`=0 WHERE `id`=".$player -> id); |
| 507 |
$smarty -> assign (array("Answer" => "false", |
| 508 |
"Qfail" => Q_FAIL)); |
| 509 |
} |
| 510 |
} |
| 511 |
if (isset ($_GET['step']) && $_GET['step'] == 'third') |
| 512 |
{ |
| 513 |
if (!isset($_SESSION['bridge']) || $_SESSION['bridge'] != 2 || $player -> hp <= 0) |
| 514 |
{ |
| 515 |
error(ERROR); |
| 516 |
} |
| 517 |
if (!isset($_POST['sanswer'])) |
| 518 |
{ |
| 519 |
$_POST['sanswer'] = ''; |
| 520 |
} |
| 521 |
$answer = strip_tags($_POST['sanswer']); |
| 522 |
$answer = strtolower($answer); |
| 523 |
$gamename = strtolower($gamename); |
| 524 |
if ($answer == $gamename) |
| 525 |
{ |
| 526 |
$_SESSION['bridge'] = 3; |
| 527 |
$query = $db -> Execute("SELECT `id` FROM `bridge`"); |
| 528 |
$amount = $query -> RecordCount(); |
| 529 |
$query -> Close(); |
| 530 |
$number = rand(1,$amount); |
| 531 |
$test = $db -> Execute("SELECT `temp` FROM `players` WHERE `id`=".$player -> id); |
| 532 |
if ($test -> fields['temp'] != 0) |
| 533 |
{ |
| 534 |
$number = $test -> fields['temp']; |
| 535 |
} |
| 536 |
$test -> Close(); |
| 537 |
$question = $db -> Execute("SELECT `question` FROM `bridge` WHERE `id`=".$number); |
| 538 |
$db -> Execute("UPDATE `players` SET `temp`=".$number." WHERE `id`=".$player -> id); |
| 539 |
$smarty -> assign(array("Question" => $question -> fields['question'], |
| 540 |
"Number" => $number, |
| 541 |
"Answer" => "true", |
| 542 |
"Tquestion" => T_QUESTION, |
| 543 |
"Anext" => A_NEXT)); |
| 544 |
$question -> Close(); |
| 545 |
} |
| 546 |
else |
| 547 |
{ |
| 548 |
unset($_SESSION['bridge']); |
| 549 |
$db -> Execute("UPDATE `players` SET `hp`=0 WHERE `id`=".$player -> id); |
| 550 |
$smarty -> assign(array("Answer" => "false", |
| 551 |
"Qfail" => Q_FAIL)); |
| 552 |
} |
| 553 |
} |
| 554 |
if (isset ($_GET['step']) && $_GET['step'] == 'forth') |
| 555 |
{ |
| 556 |
if (!isset($_SESSION['bridge']) || $_SESSION['bridge'] != 3 || $player -> hp <= 0) |
| 557 |
{ |
| 558 |
error(ERROR); |
| 559 |
} |
| 560 |
unset($_SESSION['bridge']); |
| 561 |
if (!isset($_POST['tanswer'])) |
| 562 |
{ |
| 563 |
$_POST['tanswer'] = ''; |
| 564 |
} |
| 565 |
if (!isset($_POST['number'])) |
| 566 |
{ |
| 567 |
$_POST['number'] = 1; |
| 568 |
} |
| 569 |
$answer = $db -> Execute("SELECT `answer` FROM `bridge` WHERE `id`=".$_POST['number']); |
| 570 |
$test = $db -> Execute("SELECT `bridge` FROM `players` WHERE `id`=".$player -> id); |
| 571 |
if ($test -> fields['bridge'] == 'Y') |
| 572 |
{ |
| 573 |
error(ONLY_ONCE); |
| 574 |
} |
| 575 |
$test -> Close(); |
| 576 |
$db -> Execute("UPDATE `players` SET `temp`=0 WHERE `id`=".$player -> id); |
| 577 |
$panswer = strip_tags($_POST['tanswer']); |
| 578 |
$panswer = strtolower($panswer); |
| 579 |
$answer -> fields['answer'] = strtolower($answer -> fields['answer']); |
| 580 |
if ($panswer == $answer -> fields['answer']) |
| 581 |
{ |
| 582 |
$query = $db -> Execute("SELECT count(*) FROM `equipment` WHERE `owner`=0 AND `minlev`<=".$player -> level); |
| 583 |
$amount = $query -> fields['count(*)']; |
| 584 |
$query -> Close(); |
| 585 |
$roll = rand (0, ($amount-1)); |
| 586 |
$arritem = $db -> SelectLimit("SELECT * FROM `equipment` WHERE `owner`=0", 1, $roll); |
| 587 |
$test = $db -> Execute("SELECT `id` FROM `equipment` WHERE `name`='".$arritem -> fields['name']."' AND `wt`=".$arritem -> fields['maxwt']." AND `type`='".$arritem -> fields['type']."' AND `status`='U' AND `owner`=".$player -> id." AND `power`=".$arritem -> fields['power']." AND `zr`=".$arritem -> fields['zr']." AND `szyb`=".$arritem -> fields['szyb']." AND `maxwt`=".$arritem -> fields['maxwt']." AND `cost`=1 AND `poison`=0"); |
| 588 |
if (!$test -> fields['id']) |
| 589 |
{ |
| 590 |
$db -> Execute("INSERT INTO `equipment` (`owner`, `name`, `power`, `type`, `cost`, `zr`, `wt`, `minlev`, `maxwt`, `amount`, `szyb`, `twohand`) VALUES(".$player -> id.",'".$arritem -> fields['name']."',".$arritem -> fields['power'].",'".$arritem -> fields['type']."',1,".$arritem -> fields['zr'].",".$arritem -> fields['maxwt'].",".$arritem -> fields['minlev'].",".$arritem -> fields['maxwt'].",1,".$arritem -> fields['szyb'].",'".$arritem -> fields['twohand']."')"); |
| 591 |
} |
| 592 |
else |
| 593 |
{ |
| 594 |
$db -> Execute("UPDATE `equipment` SET `amount`=`amount`+1 WHERE `id`=".$test -> fields['id']); |
| 595 |
} |
| 596 |
$test -> Close(); |
| 597 |
$db -> Execute("UPDATE `players` SET `bridge`='Y' WHERE `id`=".$player -> id); |
| 598 |
$smarty -> assign(array("Answer" => "true", |
| 599 |
"Item" => $arritem -> fields['name'], |
| 600 |
"Qsucc" => Q_SUCC, |
| 601 |
"Qsucc2" => Q_SUCC2, |
| 602 |
"Arefresh" => A_REFRESH)); |
| 603 |
} |
| 604 |
else |
| 605 |
{ |
| 606 |
$db -> Execute("UPDATE `players` SET `hp`=0 WHERE `id`=".$player -> id); |
| 607 |
$smarty -> assign(array("Answer" => "false", |
| 608 |
"Qfail" => Q_FAIL)); |
| 609 |
} |
| 610 |
} |
| 611 |
} |
| 612 |
|
| 613 |
/** |
| 614 |
* Explore forest - main menu |
| 615 |
*/ |
| 616 |
if ($player -> hp > 0 && !isset ($_GET['action']) && $player -> location == 'Las' && !isset($_GET['step'])) |
| 617 |
{ |
| 618 |
if (!empty($player -> fight)) |
| 619 |
{ |
| 620 |
$enemy = $db -> Execute("SELECT `name` FROM `monsters` WHERE `id`=".$player -> fight); |
| 621 |
error (FIGHT3.$enemy -> fields['name'].FIGHT2."<br /> |
| 622 |
<a href=explore.php?step=battle&type=T>".Y_TURN_F."</a><br /> |
| 623 |
<a href=explore.php?step=battle&type=N>".Y_NORM_F."</a><br /> |
| 624 |
<a href=explore.php?step=run>".NO."</a><br />"); |
| 625 |
} |
| 626 |
else |
| 627 |
{ |
| 628 |
$smarty -> assign(array("Finfo" => F_INFO, |
| 629 |
"Howmuch" => HOW_MUCH, |
| 630 |
"Tenergy" => T_ENERGY, |
| 631 |
"Awalk" => T_WALK)); |
| 632 |
} |
| 633 |
} |
| 634 |
|
| 635 |
/** |
| 636 |
* Explore forest - random encouter |
| 637 |
*/ |
| 638 |
if (isset($_GET['action']) && $_GET['action'] == 'forest' && $player -> location == 'Las') |
| 639 |
{ |
| 640 |
if (!isset($_POST['amount']) || !ereg("^[0-9][0-9\.]*$", $_POST['amount'])) |
| 641 |
{ |
| 642 |
error(ERROR); |
| 643 |
} |
| 644 |
if ($_POST['amount'] > $player -> energy) |
| 645 |
{ |
| 646 |
error(TIRED2); |
| 647 |
} |
| 648 |
if ($player -> hp <= 0) |
| 649 |
{ |
| 650 |
error(YOU_DEAD2,1,'las.php'); |
| 651 |
} |
| 652 |
if (!empty($player -> fight)) |
| 653 |
{ |
| 654 |
$enemy = $db -> Execute("SELECT `name` FROM `monsters` WHERE `id`=".$player -> fight); |
| 655 |
error (FIGHT3.$enemy -> fields['name'].FIGHT2."<br /><br /> |
| 656 |
» <a href=\"explore.php?step=battle\">".YES."</a><br /> |
| 657 |
» <a href=\"explore.php?step=run\">".NO."</a><br />"); |
| 658 |
} |
| 659 |
$objMaps = $db -> Execute("SELECT `value` FROM `settings` WHERE `setting`='maps'"); |
| 660 |
$intAmount = $_POST['amount'] * 2; |
| 661 |
$arrGold = array(0, 0, 0); |
| 662 |
$arrHerbs = array(0, 0, 0, 0); |
| 663 |
$intAstral = 0; |
| 664 |
$strEnemy = ''; |
| 665 |
for ($i = 1; $i < $intAmount; $i++) |
| 666 |
{ |
| 667 |
$intRoll = rand(1, 19); |
| 668 |
if ($intRoll == 9) |
| 669 |
{ |
| 670 |
$intGold = rand(1,1000); |
| 671 |
$arrGold[0] = $arrGold[0] + $intGold; |
| 672 |
} |
| 673 |
if ($intRoll == 10) |
| 674 |
{ |
| 675 |
$intEnergy = rand(1, 2); |
| 676 |
$arrGold[1] = $arrGold[1] + $intEnergy; |
| 677 |
} |
| 678 |
if ($intRoll >= 11 && $intRoll <= 13) |
| 679 |
{ |
| 680 |
$intHerb = rand(1,10); |
| 681 |
$arrHerbs[0] = $arrHerbs[0] + $intHerb; |
| 682 |
} |
| 683 |
if ($intRoll >= 14 && $intRoll <= 15) |
| 684 |
{ |
| 685 |
$intHerb = rand(1,10); |
| 686 |
$arrHerbs[1] = $arrHerbs[1] + $intHerb; |
| 687 |
} |
| 688 |
if ($intRoll == 16) |
| 689 |
{ |
| 690 |
$intHerb = rand(1,10); |
| 691 |
$arrHerbs[2] = $arrHerbs[2] + $intHerb; |
| 692 |
} |
| 693 |
if ($intRoll == 17) |
| 694 |
{ |
| 695 |
$intHerb = rand(1,10); |
| 696 |
$arrHerbs[3] = $arrHerbs[3] + $intHerb; |
| 697 |
} |
| 698 |
if ($intRoll == 18) |
| 699 |
{ |
| 700 |
$intRoll2 = rand(1, 50); |
| 701 |
if ($intRoll2 == 50 && $objMaps -> fields['value'] > 0 && $player -> maps < 20 && $player -> rank != 'Bohater') |
| 702 |
{ |
| 703 |
$objMaps -> fields['value'] --; |
| 704 |
$player -> maps ++; |
| 705 |
$arrGold[2] ++; |
| 706 |
} |
| 707 |
} |
| 708 |
if ($intRoll == 19) |
| 709 |
{ |
| 710 |
require_once('includes/findastral.php'); |
| 711 |
$strResult = findastral(2); |
| 712 |
if ($strResult != false) |
| 713 |
{ |
| 714 |
$intAstral ++; |
| 715 |
} |
| 716 |
} |
| 717 |
if ($intRoll > 5 && $intRoll < 9) |
| 718 |
{ |
| 719 |
$intRoll2 = rand(1,5); |
| 720 |
if ($intRoll2 < 5 ) |
| 721 |
{ |
| 722 |
$arrMonsters = array(2, 4, 8, 10, 15, 19, 22, 25); |
| 723 |
$intRoll3 = rand(0, 7); |
| 724 |
} |
| 725 |
if ($intRoll2 == 5) |
| 726 |
{ |
| 727 |
$arrMonsters = array(35, 40, 46, 55); |
| 728 |
$intRoll3 = rand(0, 3); |
| 729 |
} |
| 730 |
$enemy = $db -> Execute("SELECT `name`, `id` FROM `monsters` WHERE `id`=".$arrMonsters[$intRoll3]); |
| 731 |
$db -> Execute("UPDATE `players` SET `fight`=".$enemy -> fields['id']." WHERE `id`=".$player -> id); |
| 732 |
$strEnemy = YOU_MEET." ".$enemy -> fields['name'].FIGHT2."<br /><br /> |
| 733 |
» <a href=\"explore.php?step=battle\">".YES."</a><br /> |
| 734 |
» <a href=\"explore.php?step=run\">".NO."</a><br />"; |
| 735 |
$player -> fight = $enemy -> fields['id']; |
| 736 |
$enemy -> Close(); |
| 737 |
break; |
| 738 |
} |
| 739 |
} |
| 740 |
|
| 741 |
$intHerbsum = array_sum($arrHerbs); |
| 742 |
$intGoldsum = array_sum($arrGold); |
| 743 |
if ($intHerbsum) |
| 744 |
{ |
| 745 |
$objHerbs = $db -> Execute("SELECT `gracz` FROM `herbs` WHERE `gracz`=".$player -> id); |
| 746 |
if ($objHerbs -> fields['gracz']) |
| 747 |
{ |
| 748 |
$db -> Execute("UPDATE `herbs` SET `illani`=`illani`+".$arrHerbs[0].", `illanias`=`illanias`+".$arrHerbs[1].", `nutari`=`nutari`+".$arrHerbs[2].", `dynallca`=`dynallca`+".$arrHerbs[3]." WHERE `gracz`=".$player -> id) or die("Błąd"); |
| 749 |
} |
| 750 |
else |
| 751 |
{ |
| 752 |
$db -> Execute("INSERT INTO `herbs` (`gracz`, `illani`, `illanias`, `nutari`, `dynallca`) VALUES(".$player -> id.", ".$arrHerbs[0].", ".$arrHerbs[1].", ".$arrHerbs[2].", ".$arrHerbs[3].")"); |
| 753 |
} |
| 754 |
$objHerbs -> Close(); |
| 755 |
} |
| 756 |
$fltAmount = $i / 2; |
| 757 |
$strFind = YOU_GO.$fltAmount.T_AMOUNT2; |
| 758 |
if ($intHerbsum || $intGoldsum || $intAstral) |
| 759 |
{ |
| 760 |
$strFind = $strFind.YOU_FIND; |
| 761 |
$arrAmounts = array($arrHerbs[0], $arrHerbs[1], $arrHerbs[2], $arrHerbs[3], $intAstral, $arrGold[0], $arrGold[1], $arrGold[2]); |
| 762 |
$arrText = array(HERB1, HERB2, HERB3, HERB4, T_ASTRALS, T_GOLD, T_ENERGY2, T_MAPS); |
| 763 |
$i = 0; |
| 764 |
foreach ($arrAmounts as $intAmount) |
| 765 |
{ |
| 766 |
if ($intAmount) |
| 767 |
{ |
| 768 |
$strFind = $strFind.$intAmount.$arrText[$i]; |
| 769 |
} |
| 770 |
$i ++; |
| 771 |
} |
| 772 |
$strFind = $strFind."<br />"; |
| 773 |
} |
| 774 |
if (!$intHerbsum && !$intGoldsum && !$intAstral && $strEnemy == '') |
| 775 |
{ |
| 776 |
$strFind = $strFind.FIND_NOTHING; |
| 777 |
} |
| 778 |
$fltEnergy = $fltAmount - $arrGold[1]; |
| 779 |
$db -> Execute("UPDATE `players` SET `credits`=`credits`+".$arrGold[0].", `energy`=`energy`-".$fltEnergy.", `maps`=".$player -> maps." WHERE `id`=".$player -> id); |
| 780 |
$db -> Execute("UPDATE `settings` SET `value`=".$objMaps -> fields['value']." WHERE `setting`='maps'"); |
| 781 |
$objMaps -> Close(); |
| 782 |
$smarty -> assign(array("Youfind" => $strFind, |
| 783 |
"Howmuch" => HOW_MUCH, |
| 784 |
"Tenergy" => T_ENERGY, |
| 785 |
"Awalk" => T_WALK, |
| 786 |
"Enemy" => $strEnemy)); |
| 787 |
} |
| 788 |
|
| 789 |
/** |
| 790 |
* Initialization of variables |
| 791 |
*/ |
| 792 |
if (!isset($_GET['step'])) |
| 793 |
{ |
| 794 |
$_GET['step'] = ''; |
| 795 |
} |
| 796 |
if (!isset($_GET['action'])) |
| 797 |
{ |
| 798 |
$_GET['action'] = ''; |
| 799 |
} |
| 800 |
if (!isset($rzut)) |
| 801 |
{ |
| 802 |
$rzut = ''; |
| 803 |
} |
| 804 |
|
| 805 |
$smarty -> assign(array("Step" => $_GET['step'], |
| 806 |
"Fight" => $player -> fight, |
| 807 |
"Action" => $_GET['action'], |
| 808 |
"Location" => $player -> location, |
| 809 |
"Roll" => $rzut, |
| 810 |
"Health" => $player -> hp)); |
| 811 |
$smarty -> display('explore.tpl'); |
| 812 |
|
| 813 |
require_once("includes/foot.php"); |
| 814 |
?> |