| 1 |
<?php |
| 2 |
/** |
| 3 |
* File functions: |
| 4 |
* Astral plans |
| 5 |
* |
| 6 |
* @name : portals.php |
| 7 |
* @copyright : (C) 2006 Vallheru Team based on Gamers-Fusion ver 2.5 |
| 8 |
* @author : thindil <thindil@users.sourceforge.net> |
| 9 |
* @version : 1.2 |
| 10 |
* @since : 28.06.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: portals.php 398 2006-06-28 15:56:19Z thindil $ |
| 31 |
|
| 32 |
$title = "Astralny plan"; |
| 33 |
require_once("includes/head.php"); |
| 34 |
|
| 35 |
/** |
| 36 |
* Get the localization for game |
| 37 |
*/ |
| 38 |
require_once("languages/".$player -> lang."/portals.php"); |
| 39 |
|
| 40 |
if (!isset($_GET['step']) || !ereg("^[0-6]*$", $_GET['step'])) |
| 41 |
{ |
| 42 |
error(ERROR." (<a href=\"city.php\">".BACK."</a>)"); |
| 43 |
} |
| 44 |
|
| 45 |
if ($player -> location != 'Altara' && $player -> location != 'Astralny plan') |
| 46 |
{ |
| 47 |
error(ERROR." (<a href=\"city.php\">".BACK."</a>)"); |
| 48 |
} |
| 49 |
|
| 50 |
if ($player -> energy < 1) |
| 51 |
{ |
| 52 |
error(ERROR." (<a href=\"city.php\">".BACK."</a>)"); |
| 53 |
} |
| 54 |
|
| 55 |
if (!isset($_GET['go'])) |
| 56 |
{ |
| 57 |
if ($player -> hp <= 0) |
| 58 |
{ |
| 59 |
$db -> Execute("UPDATE `players` SET `miejsce`='Altara' WHERE `id`=".$player -> id); |
| 60 |
error(ERROR." (<a href=\"city.php\">".BACK."</a>)"); |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Function to count astral plans |
| 66 |
*/ |
| 67 |
function coutastralplans($intPlayerid, $strPlanname) |
| 68 |
{ |
| 69 |
global $db; |
| 70 |
|
| 71 |
$objAmount = $db -> Execute("SELECT `amount` FROM `astral_plans` WHERE `owner`=".$intPlayerid." AND `name`='".$strPlanname."' AND `location`='V'") or die($db -> ErrorMsg()); |
| 72 |
if ($objAmount -> fields['amount'] == 1) |
| 73 |
{ |
| 74 |
$db -> Execute("DELETE FROM `astral_plans` WHERE `owner`=".$intPlayerid." AND `name`='".$strPlanname."' AND `location`='V'"); |
| 75 |
} |
| 76 |
else |
| 77 |
{ |
| 78 |
$db -> Execute("UPDATE `astral_plans` SET `amount`=`amount`-1 WHERE `owner`=".$intPlayerid." AND `name`='".$strPlanname."' AND `location`='V'"); |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
$intNumber2 = $_GET['step'] + 1; |
| 83 |
$strName = "M".$intNumber2; |
| 84 |
$objPlan = $db -> Execute("SELECT `amount` FROM `astral_plans` WHERE `owner`=".$player -> id." AND `name`='".$strName."' AND `location`='V'"); |
| 85 |
if (!$objPlan -> fields['amount']) |
| 86 |
{ |
| 87 |
error(NO_MAP." (<a href=\"city.php\">".BACK."</a>)"); |
| 88 |
} |
| 89 |
$objPlan -> Close(); |
| 90 |
|
| 91 |
$arrMonsters = array(MONSTER1, MONSTER2, MONSTER3, MONSTER4, MONSTER5, MONSTER6, MONSTER7); |
| 92 |
|
| 93 |
/** |
| 94 |
* Main menu |
| 95 |
*/ |
| 96 |
if (!isset($_GET['go'])) |
| 97 |
{ |
| 98 |
$arrPlans = array(PLAN1, PLAN2, PLAN3, PLAN4, PLAN5, PLAN6, PLAN7); |
| 99 |
$smarty -> assign(array("Desc1" => DESC1, |
| 100 |
"Desc2" => DESC2, |
| 101 |
"Desc3" => DESC3, |
| 102 |
"Planname" => $arrPlans[$_GET['step']], |
| 103 |
"Monstername" => $arrMonsters[$_GET['step']], |
| 104 |
"Afight" => A_FIGHT)); |
| 105 |
$db -> Execute("UPDATE `players` SET `fight`=".$intNumber2.", `miejsce`='Astralny plan' WHERE `id`=".$player -> id); |
| 106 |
$_GET['go'] = ''; |
| 107 |
} |
| 108 |
|
| 109 |
/** |
| 110 |
* Fight with monster |
| 111 |
*/ |
| 112 |
if (isset($_GET['go']) && $_GET['go'] == 'fight') |
| 113 |
{ |
| 114 |
$objFight = $db -> Execute("SELECT `fight`, `hp` FROM `players` WHERE `id`=".$player -> id); |
| 115 |
|
| 116 |
/** |
| 117 |
* Fight with monster |
| 118 |
*/ |
| 119 |
if ($objFight -> fields['fight'] != 9999) |
| 120 |
{ |
| 121 |
if (!$objFight -> fields['fight']) |
| 122 |
{ |
| 123 |
error(ERROR." (<a href=\"city.php\">".BACK."</a>)"); |
| 124 |
} |
| 125 |
require_once ("includes/funkcje.php"); |
| 126 |
require_once("includes/turnfight.php"); |
| 127 |
|
| 128 |
require_once('class/monster_class.php'); |
| 129 |
require_once('class/fight_class.php'); |
| 130 |
$arrPower = array(7000, 8000, 9000, 10500, 12000, 15000, 19000); |
| 131 |
$arrAgility = array(7000, 8000, 9000, 10500, 12000, 15000, 19000); |
| 132 |
$arrSpeed = array(7000, 8000, 9000, 10500, 12000, 15000, 19000); |
| 133 |
$arrConstitution = array(7000, 8000, 9000, 10500, 12000, 15000, 19000); |
| 134 |
$arrWisdom = array(7000, 8000, 9000, 10500, 12000, 15000, 19000); |
| 135 |
$arrInteligence = array(7000, 8000, 9000, 10500, 12000, 15000, 19000); |
| 136 |
$arrHitpoints = array(15000, 20000, 25000, 30000, 40000, 50000, 60000); |
| 137 |
$arrLevel = array(40, 60, 80, 100, 150, 200, 250); |
| 138 |
$arrExp1 = array(500, 750, 1000, 1250, 1500, 1750, 2000); |
| 139 |
$arrExp2 = array(600, 900, 1250, 1500, 1750, 2000, 2500); |
| 140 |
$arrBonus = array(1, 1.5, 2, 2.5, 3, 3.5, 4); |
| 141 |
$intNumber = $objFight -> fields['fight'] - 1; |
| 142 |
|
| 143 |
if (!isset($_SESSION['amount'])) { |
| 144 |
$_SESSION['amount'] = 1; |
| 145 |
$_SESSION['mon0']['id'] = 9999; |
| 146 |
$_SESSION['mon0']['user'] = $arrMonsters[$intNumber]; |
| 147 |
$_SESSION['mon0']['level'] = $arrLevel[$intNumber]; |
| 148 |
$_SESSION['mon0']['credits'] = 0; |
| 149 |
$_SESSION['mon0']['exp'] = rand($arrExp1[$intNumber],$arrExp2[$intNumber]); |
| 150 |
$_SESSION['mon0']['actionpoints'] = $arrConstitution[$intNumber]; |
| 151 |
$_SESSION['mon0']['defence'] = $arrConstitution[$intNumber]; |
| 152 |
$_SESSION['mon0']['hp'] = $arrHitpoints[$intNumber]; |
| 153 |
$_SESSION['mon0']['damage'] = $arrPower[$intNumber]; |
| 154 |
$_SESSION['mon0']['hitmodificator'] = $arrAgility[$intNumber]; |
| 155 |
$_SESSION['mon0']['missmodificator'] = $arrAgility[$intNumber]; |
| 156 |
$_SESSION['mon0']['attackspeed'] = $arrSpeed[$intNumber]; |
| 157 |
|
| 158 |
$monster = new Monster(999,1,0); |
| 159 |
$attacker = new Fighter($player -> id); |
| 160 |
|
| 161 |
for ($k = 0; $k < $_SESSION['amount']; $k++) { |
| 162 |
//each monster identifier |
| 163 |
$strIndex = 'mon'.$k; |
| 164 |
$_SESSION[$strIndex]['id'] = $monster -> id; |
| 165 |
//each monster hit points |
| 166 |
$_SESSION[$strIndex]['hp'] = $monster -> hp; |
| 167 |
//each monster action points |
| 168 |
if ($attacker -> speed > $monster -> attackspeed) { |
| 169 |
$_SESSION[$strIndex]['ap'] = 1; |
| 170 |
} |
| 171 |
else { |
| 172 |
$_SESSION[$strIndex]['ap'] = floor($monster -> attackspeed / $attacker -> speed); |
| 173 |
if ($_SESSION[$strIndex]['ap'] > 5) { |
| 174 |
$_SESSION[$strIndex]['ap'] = 5; |
| 175 |
} |
| 176 |
} |
| 177 |
$tmpActionArr[$k][0] = $monster -> attackspeed; |
| 178 |
$tmpActionArr[$k][1] = $k; |
| 179 |
} |
| 180 |
$tmpActionArr[$k][0] = $attacker -> speed; |
| 181 |
$tmpActionArr[$k][1] = -1; |
| 182 |
|
| 183 |
/** |
| 184 |
* function to compare elements of actionArr |
| 185 |
*/ |
| 186 |
function aacmp($a,$b) { |
| 187 |
if ($a[0] == $b[0]) return 0; |
| 188 |
return ($a[0] > $b[0]) ? -1 : 1; |
| 189 |
} |
| 190 |
|
| 191 |
usort($tmpActionArr,"aacmp"); |
| 192 |
for ($k = 0; $k <= $_SESSION['amount']; $k++) { |
| 193 |
$actionArr[$k] = $tmpActionArr[$k][1]; |
| 194 |
} |
| 195 |
$_SESSION['actionArr'] = $actionArr; |
| 196 |
$_SESSION['exhaust']=0; |
| 197 |
if ($attacker -> speed > $monster -> attackspeed) { |
| 198 |
$_SESSION['points'] = floor($attacker -> speed / $monster -> attackspeed); |
| 199 |
if ($_SESSION['points'] > 5) { |
| 200 |
$_SESSION['points'] = 5; |
| 201 |
} |
| 202 |
} |
| 203 |
else { |
| 204 |
$_SESSION['points'] = 1; |
| 205 |
} |
| 206 |
$_SESSION['round']=0; |
| 207 |
} |
| 208 |
$strAdress = "portals.php?step=".$intNumber."&go=fight"; |
| 209 |
turnfight($strAdress); |
| 210 |
|
| 211 |
/* $enemy = array('name' => $arrMonsters[$intNumber], |
| 212 |
'strength' => $arrPower[$intNumber], |
| 213 |
'agility' => $arrAgility[$intNumber], |
| 214 |
'hp' => $arrHitpoints[$intNumber], |
| 215 |
'level' => $arrLevel[$intNumber], |
| 216 |
'endurance' => $arrConstitution[$intNumber], |
| 217 |
'speed' => $arrSpeed[$intNumber], |
| 218 |
'exp1' => $arrExp1[$intNumber], |
| 219 |
'exp2' => $arrExp2[$intNumber]); |
| 220 |
|
| 221 |
$arrehp = array(); |
| 222 |
$strAdress = "portals.php?step=".$intNumber."&go=fight"; |
| 223 |
$span = ($enemy['level'] / $player -> level); |
| 224 |
if ($span > 2) |
| 225 |
{ |
| 226 |
$span = 2; |
| 227 |
} |
| 228 |
$intExpgain = ceil(rand($enemy['exp1'],$enemy['exp2']) * $span); |
| 229 |
if (!isset ($_POST['action'])) |
| 230 |
{ |
| 231 |
turnfight($intExpgain, 0, '', $strAdress); |
| 232 |
} |
| 233 |
else |
| 234 |
{ |
| 235 |
turnfight($intExpgain, 0, $_POST['action'], $strAdress); |
| 236 |
}*/ |
| 237 |
} |
| 238 |
|
| 239 |
$objFight = $db -> Execute("SELECT `fight`, `hp` FROM `players` WHERE `id`=".$player -> id); |
| 240 |
|
| 241 |
/** |
| 242 |
* Win fight and search for components |
| 243 |
*/ |
| 244 |
if ($objFight -> fields['hp'] > 0 && $objFight -> fields['fight'] == 0 && $_SESSION['result'] == 'win') |
| 245 |
{ |
| 246 |
$arrChanges = array(90, 85, 80, 75, 70, 65, 60); |
| 247 |
$intRoll = rand(1, 100); |
| 248 |
if ($intRoll <= $arrChanges[$intNumber]) |
| 249 |
{ |
| 250 |
$strFindcomponent = COMPONENT; |
| 251 |
$strType = "C".$intNumber; |
| 252 |
$objTest = $db -> Execute("SELECT `amount` FROM `astral` WHERE `owner`=".$player -> id." AND `type`='".$strType."' AND `location`='V'") or die($db -> ErrorMsg()); |
| 253 |
if ($objTest -> fields['amount']) |
| 254 |
{ |
| 255 |
$db -> Execute("UPDATE `astral` SET `amount`=`amount`+1 WHERE `owner`=".$player -> id." AND `type`='".$strType."' AND `location`='V'") or die($db -> ErrorMsg()); |
| 256 |
} |
| 257 |
else |
| 258 |
{ |
| 259 |
$db -> Execute("INSERT INTO `astral` (`owner`, `type`) VALUES(".$player -> id.", '".$strType."')") or die($db -> ErrorMsg()); |
| 260 |
} |
| 261 |
$objTest -> Close(); |
| 262 |
} |
| 263 |
else |
| 264 |
{ |
| 265 |
$strFindcomponent = NOTHING; |
| 266 |
} |
| 267 |
$objItem = $db -> Execute("SELECT `id` FROM `equipment` WHERE `owner`=".$player -> id." AND `type`='W' AND status='E'"); |
| 268 |
if ($objItem -> fields['id']) |
| 269 |
{ |
| 270 |
$strSkill = 'atak'; |
| 271 |
} |
| 272 |
else |
| 273 |
{ |
| 274 |
$objItem2 = $db -> Execute("SELECT `id` FROM `equipment` WHERE `owner`=".$player ->id." AND `type`='B' AND status='E'"); |
| 275 |
if ($objItem2 -> fields['id']) |
| 276 |
{ |
| 277 |
$strSkill = 'shoot'; |
| 278 |
} |
| 279 |
else |
| 280 |
{ |
| 281 |
$strSkill = 'magia'; |
| 282 |
} |
| 283 |
} |
| 284 |
$objItem -> Close(); |
| 285 |
$db -> Execute("UPDATE `players` SET `energy`=`energy`-1, `miejsce`='Altara', `".$strSkill."`=`".$strSkill."`+".$arrBonus[$intNumber]." WHERE `id`=".$player -> id); |
| 286 |
coutastralplans($player -> id, $strName); |
| 287 |
error(YOU_WIN.$strFindcomponent); |
| 288 |
} |
| 289 |
if (isset($_SESSION['result'])) unset($_SESSION['result']); |
| 290 |
|
| 291 |
/** |
| 292 |
* Lost fight |
| 293 |
*/ |
| 294 |
if ($objFight -> fields['fight'] == 0 && $objFight -> fields['hp'] == 0) |
| 295 |
{ |
| 296 |
$db -> Execute("UPDATE `players` SET `energy`=`energy`-1, `miejsce`='Altara' WHERE `id`=".$player -> id); |
| 297 |
coutastralplans($player -> id, $strName); |
| 298 |
error(YOU_LOST2); |
| 299 |
} |
| 300 |
|
| 301 |
/** |
| 302 |
* Escape from fight |
| 303 |
*/ |
| 304 |
if ($objFight -> fields['fight'] == 9999) |
| 305 |
{ |
| 306 |
$db -> Execute("UPDATE `players` SET `energy`=`energy`-1, `miejsce`='Altara' WHERE `id`=".$player -> id); |
| 307 |
coutastralplans($player -> id, $strName); |
| 308 |
error(YOU_ESCAPE); |
| 309 |
} |
| 310 |
$objFight -> Close(); |
| 311 |
} |
| 312 |
|
| 313 |
/** |
| 314 |
* Assign variables to template and display page |
| 315 |
*/ |
| 316 |
$smarty -> assign(array("Go" => $_GET['go'], |
| 317 |
"Step" => $_GET['step'])); |
| 318 |
$smarty -> display ('portals.tpl'); |
| 319 |
|
| 320 |
require_once("includes/foot.php"); |
| 321 |
?> |