| 1 |
<?php |
| 2 |
/** |
| 3 |
* File functions: |
| 4 |
* Fletcher shop - buy arrows and bows |
| 5 |
* |
| 6 |
* @name : bows.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.2 |
| 10 |
* @since : 09.07.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: bows.php 449 2006-07-09 19:12:03Z thindil $ |
| 31 |
|
| 32 |
$title = "Fleczer"; |
| 33 |
require_once("includes/head.php"); |
| 34 |
|
| 35 |
/** |
| 36 |
* Get the localization for game |
| 37 |
*/ |
| 38 |
require_once("languages/".$player -> lang."/bows.php"); |
| 39 |
|
| 40 |
if ($player -> location != 'Altara' && $player -> location != 'Ardulith') |
| 41 |
{ |
| 42 |
error (ERROR); |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Show list items in shop |
| 47 |
*/ |
| 48 |
if (!isset ($_GET['buy']) && !isset($_GET['step'])) |
| 49 |
{ |
| 50 |
$arrname = array(); |
| 51 |
$arrpower = array(); |
| 52 |
$arrspeed = array(); |
| 53 |
$arrdur = array(); |
| 54 |
$arrlevel = array(); |
| 55 |
$arrcost = array(); |
| 56 |
$arrid = array(); |
| 57 |
$arrLink = array(); |
| 58 |
$i = 0; |
| 59 |
$wep = $db -> Execute("SELECT * FROM bows WHERE lang='".$player -> lang."' ORDER BY minlev ASC"); |
| 60 |
while (!$wep -> EOF) |
| 61 |
{ |
| 62 |
$arrname[$i] = $wep -> fields['name']; |
| 63 |
$arrpower[$i] = $wep -> fields['power']; |
| 64 |
$arrspeed[$i] = $wep -> fields['szyb']; |
| 65 |
$arrdur[$i] = $wep -> fields['maxwt']; |
| 66 |
$arrlevel[$i] = $wep -> fields['minlev']; |
| 67 |
$arrcost[$i] = $wep -> fields['cost']; |
| 68 |
$arrid[$i] = $wep -> fields['id']; |
| 69 |
if ($wep -> fields['type'] == 'R') |
| 70 |
{ |
| 71 |
$arrLink[$i] = 'arrows='; |
| 72 |
} |
| 73 |
else |
| 74 |
{ |
| 75 |
$arrLink[$i] = 'buy='; |
| 76 |
} |
| 77 |
$wep -> MoveNext(); |
| 78 |
$i = $i + 1; |
| 79 |
} |
| 80 |
$wep -> Close(); |
| 81 |
/** |
| 82 |
* Select name of the best archer |
| 83 |
*/ |
| 84 |
$objArcher = $db -> Execute("SELECT user FROM players ORDER BY shoot DESC"); |
| 85 |
if ($objArcher -> fields['user'] == $player -> user) |
| 86 |
{ |
| 87 |
$objArcher = $db -> Execute("SELECT user FROM players WHERE user!='".$player -> user."' ORDER BY shoot DESC"); |
| 88 |
} |
| 89 |
$strArcher = $objArcher -> fields['user']; |
| 90 |
$objArcher -> Close(); |
| 91 |
$smarty -> assign ( array("Name" => $arrname, |
| 92 |
"Power" => $arrpower, |
| 93 |
"Speed" => $arrspeed, |
| 94 |
"Durability" => $arrdur, |
| 95 |
"Level" => $arrlevel, |
| 96 |
"Cost" => $arrcost, |
| 97 |
"Itemid" => $arrid, |
| 98 |
"Tlink" => $arrLink, |
| 99 |
"Shopinfo" => SHOP_INFO, |
| 100 |
"Archername" => $strArcher, |
| 101 |
"Shopinfo2" => SHOP_INFO2, |
| 102 |
"Iname" => I_NAME, |
| 103 |
"Idur" => I_DUR, |
| 104 |
"Iefect" => I_EFECT, |
| 105 |
"Icost" => I_COST, |
| 106 |
"Ilevel" => I_LEVEL, |
| 107 |
"Ispeed" => I_SPEED, |
| 108 |
"Ioption" => I_OPTION, |
| 109 |
"Abuy" => A_BUY, |
| 110 |
"Asteal" => A_STEAL)); |
| 111 |
} |
| 112 |
|
| 113 |
/** |
| 114 |
* Buy bows |
| 115 |
*/ |
| 116 |
if (isset ($_GET['buy'])) |
| 117 |
{ |
| 118 |
if (!ereg("^[1-9][0-9]*$", $_GET['buy'])) |
| 119 |
{ |
| 120 |
error (ERROR); |
| 121 |
} |
| 122 |
$arm = $db -> Execute("SELECT * FROM bows WHERE id=".$_GET['buy']); |
| 123 |
if (!$arm -> fields['id']) |
| 124 |
{ |
| 125 |
error (NO_ITEM); |
| 126 |
} |
| 127 |
if ($arm -> fields['cost'] > $player -> credits) |
| 128 |
{ |
| 129 |
error (NO_MONEY); |
| 130 |
} |
| 131 |
$newcost = ceil($arm -> fields['cost'] * .75); |
| 132 |
$test = $db -> Execute("SELECT id FROM equipment WHERE name='".$arm -> fields['name']."' AND wt=".$arm -> fields['maxwt']." AND type='B' AND status='U' AND owner=".$player -> id." AND power=".$arm -> fields['power']." AND zr=".$arm -> fields['zr']." AND szyb=".$arm -> fields['szyb']." AND maxwt=".$arm -> fields['maxwt']." AND cost=".$newcost); |
| 133 |
if (!$test -> fields['id']) |
| 134 |
{ |
| 135 |
$db -> Execute("INSERT INTO equipment (owner, name, power, type, cost, zr, wt, minlev, maxwt, amount, szyb, twohand, repair) VALUES(".$player -> id.",'".$arm -> fields['name']."',".$arm -> fields['power'].",'B',".$newcost.",".$arm -> fields['zr'].",".$arm -> fields['maxwt'].",".$arm -> fields['minlev'].",".$arm -> fields['maxwt'].",1,".$arm -> fields['szyb'].",'Y', ".$arm -> fields['repair'].")") or error(E_DB); |
| 136 |
} |
| 137 |
else |
| 138 |
{ |
| 139 |
$db -> Execute("UPDATE equipment SET amount=amount+1 WHERE id=".$test -> fields['id']); |
| 140 |
} |
| 141 |
$test -> Close(); |
| 142 |
$db -> Execute("UPDATE players SET credits=credits-".$arm -> fields['cost']." WHERE id=".$player -> id); |
| 143 |
$smarty -> assign ( array("Name" => $arm -> fields['name'], |
| 144 |
"Power" => $arm -> fields['power'], |
| 145 |
"Cost" => $arm -> fields['cost'], |
| 146 |
"Youbuy" => YOU_BUY, |
| 147 |
"Goldcoins" => GOLD_COINS, |
| 148 |
"Damage" => DAMAGE, |
| 149 |
"With" => WITH, |
| 150 |
"Tamount4" => '')); |
| 151 |
$arm -> Close(); |
| 152 |
} |
| 153 |
|
| 154 |
/** |
| 155 |
* Buy arrows |
| 156 |
*/ |
| 157 |
if (isset($_GET['arrows'])) |
| 158 |
{ |
| 159 |
if (!ereg("^[1-9][0-9]*$", $_GET['arrows'])) |
| 160 |
{ |
| 161 |
error (ERROR); |
| 162 |
} |
| 163 |
$objArm = $db -> Execute("SELECT * FROM bows WHERE id=".$_GET['arrows']); |
| 164 |
if (!$objArm -> fields['id']) |
| 165 |
{ |
| 166 |
error (NO_ITEM); |
| 167 |
} |
| 168 |
$intAllcost = $objArm -> fields['cost']; |
| 169 |
$intOnecost = ceil($objArm -> fields['cost'] / 20); |
| 170 |
$smarty -> assign(array("Arrowsname" => $objArm -> fields['name'], |
| 171 |
"Arrowscost" => $intAllcost, |
| 172 |
"Arrowscost2" => $intOnecost, |
| 173 |
"Arrowsid" => $objArm -> fields['id'], |
| 174 |
"Tamount" => T_AMOUNT, |
| 175 |
"Fora" => FOR_A, |
| 176 |
"Tamount2" => T_AMOUNT2, |
| 177 |
"Tamount3" => T_AMOUNT3, |
| 178 |
"Tarrows" => T_ARROWS)); |
| 179 |
if (isset($_GET['step']) && $_GET['step'] == 'buy') |
| 180 |
{ |
| 181 |
if ((isset($_POST['arrows1']) && $_POST['arrows1'] > 0) && (isset($_POST['arrows2']) && $_POST['arrows2'] > 0)) |
| 182 |
{ |
| 183 |
error(ERROR); |
| 184 |
} |
| 185 |
if (isset($_POST['arrows1']) && $_POST['arrows1'] > 0) |
| 186 |
{ |
| 187 |
if (!ereg("^[1-9][0-9]*$", $_POST['arrows1'])) |
| 188 |
{ |
| 189 |
error (ERROR); |
| 190 |
} |
| 191 |
$intCost = $intAllcost * $_POST['arrows1']; |
| 192 |
if ($intCost > $player -> credits) |
| 193 |
{ |
| 194 |
error (NO_MONEY); |
| 195 |
} |
| 196 |
$intAmount = $objArm -> fields['maxwt'] * $_POST['arrows1']; |
| 197 |
} |
| 198 |
if (isset($_POST['arrows2']) && $_POST['arrows2'] > 0) |
| 199 |
{ |
| 200 |
if (!ereg("^[1-9][0-9]*$", $_POST['arrows2'])) |
| 201 |
{ |
| 202 |
error (ERROR); |
| 203 |
} |
| 204 |
$intCost = ceil($intOnecost * $_POST['arrows2']); |
| 205 |
if ($intCost > $player -> credits) |
| 206 |
{ |
| 207 |
error (NO_MONEY); |
| 208 |
} |
| 209 |
$intAmount = $_POST['arrows2']; |
| 210 |
} |
| 211 |
if ((isset($_POST['arrows1']) && $_POST['arrows1'] > 0) || (isset($_POST['arrows2']) && $_POST['arrows2'] > 0)) |
| 212 |
{ |
| 213 |
$intNewcost = ceil($intAllcost * 0.75); |
| 214 |
$test = $db -> Execute("SELECT id FROM equipment WHERE name='".$objArm -> fields['name']."' AND owner=".$player -> id." AND status='U' AND cost=".$intNewcost); |
| 215 |
if (!$test -> fields['id']) |
| 216 |
{ |
| 217 |
$db -> Execute("INSERT INTO equipment (owner, name, power, cost, wt, szyb, minlev, maxwt, type) VALUES(".$player -> id.",'".$objArm -> fields['name']."',".$objArm -> fields['power'].",".$intNewcost.",".$intAmount.",".$objArm -> fields['szyb'].",".$objArm -> fields['minlev'].",".$intAmount.",'".$objArm -> fields['type']."')") or error(E_DB); |
| 218 |
} |
| 219 |
else |
| 220 |
{ |
| 221 |
$db -> Execute("UPDATE equipment SET wt=wt+".$intAmount.", maxwt=maxwt+".$intAmount." WHERE id=".$test -> fields['id']); |
| 222 |
} |
| 223 |
$test -> Close(); |
| 224 |
$db -> Execute("UPDATE players SET credits=credits-".$intCost." WHERE id=".$player -> id); |
| 225 |
$smarty -> assign(array("Name" => $objArm -> fields['name'], |
| 226 |
"Power" => $objArm -> fields['power'], |
| 227 |
"Cost" => $intCost, |
| 228 |
"Youbuy" => YOU_BUY, |
| 229 |
"Goldcoins" => GOLD_COINS, |
| 230 |
"Damage" => DAMAGE, |
| 231 |
"With" => WITH, |
| 232 |
"Tamount4" => $intAmount)); |
| 233 |
} |
| 234 |
else |
| 235 |
{ |
| 236 |
error(ERROR); |
| 237 |
} |
| 238 |
} |
| 239 |
$objArm -> Close(); |
| 240 |
} |
| 241 |
|
| 242 |
/** |
| 243 |
* Steal items from shop |
| 244 |
*/ |
| 245 |
if (isset ($_GET['steal'])) |
| 246 |
{ |
| 247 |
require_once("includes/steal.php"); |
| 248 |
require_once("includes/checkexp.php"); |
| 249 |
steal($_GET['steal']); |
| 250 |
} |
| 251 |
if ($player -> clas != 'Złodziej') |
| 252 |
{ |
| 253 |
$player -> crime = 0; |
| 254 |
} |
| 255 |
|
| 256 |
/** |
| 257 |
* Initialization of variables |
| 258 |
*/ |
| 259 |
if (!isset($_GET['buy'])) |
| 260 |
{ |
| 261 |
$_GET['buy'] = ''; |
| 262 |
} |
| 263 |
if (!isset($_GET['arrows'])) |
| 264 |
{ |
| 265 |
$_GET['arrows'] = ''; |
| 266 |
} |
| 267 |
if (!isset($_GET['step'])) |
| 268 |
{ |
| 269 |
$_GET['step'] = ''; |
| 270 |
} |
| 271 |
|
| 272 |
/** |
| 273 |
* Assign variables and display page |
| 274 |
*/ |
| 275 |
$smarty -> assign(array("Buy" => $_GET['buy'], |
| 276 |
"Crime" => $player -> crime, |
| 277 |
"Arrows" => $_GET['arrows'], |
| 278 |
"Step" => $_GET['step'], |
| 279 |
"Location" => $player -> location)); |
| 280 |
$smarty -> display ('bows.tpl'); |
| 281 |
|
| 282 |
require_once("includes/foot.php"); |
| 283 |
?> |