PageRenderTime 56ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/kowal.php

https://bitbucket.org/marecki/orodlin-v.1
PHP | 692 lines | 603 code | 19 blank | 70 comment | 148 complexity | 4afe8628dc1ebb99c273c360651b66a9 MD5 | raw file
  1. <?php
  2. /**
  3. * File functions:
  4. * Blacksmith - making items - weapons, armors, shields, helmets, plate legs, arrowsheads
  5. *
  6. * @name : kowal.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. * @version : 1.4
  11. * @since : 23.03.2007
  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$
  31. $title='Kuźnia';
  32. require_once('includes/head.php');
  33. require_once('includes/checkexp.php');
  34. require_once('includes/artisan.php');
  35. /**
  36. * Get the localization for game
  37. */
  38. require_once('languages/'.$player -> lang.'/kowal.php');
  39. if ($player -> location != 'Ardulith')
  40. {
  41. error (ERROR);
  42. }
  43. if ($player -> hp <= 0)
  44. {
  45. error (YOU_DEAD);
  46. }
  47. function special(&$intItemStat, $intItembonus, $fltPlayerStat, $intMax, $charAgility='')
  48. {
  49. $intX = $intItembonus + $fltPlayerStat / 50;
  50. if($charAgility !='a')
  51. $intItemStat += $intX > $intMax ? $intMax : $intX;
  52. else
  53. $intItemStat -= $intX > $intMax ? $intMax : $intX;
  54. }
  55. /**
  56. * Function create items
  57. */
  58. function createitem()
  59. {
  60. global $db;
  61. global $player;
  62. global $arrItem;
  63. global $intAbility;
  64. global $intItems;
  65. global $intGainexp;
  66. global $intChance;
  67. global $intCost;
  68. global $intExp;
  69. global $arrMaxbonus;
  70. global $intKey;
  71. global $intSmith;
  72. if (rand(1,100) <= $intChance)
  73. {
  74. $strName = $arrItem['name'];
  75. $intPower = $arrItem['power'];
  76. $intAgi = $arrItem['zr'];
  77. $intDur = $arrItem['wt'];
  78. $blnSpecial = false;
  79. if (floor( rand(1,100) - $intAbility / 100) < 21) // special item! Smithy ('ability') skill increases the chance
  80. {
  81. $intRoll3 = rand(1, 100);
  82. $intItembonus = rand(ceil($intSmith/2), ceil($intSmith));
  83. if ($arrItem['type'] == 'A' || $arrItem['type'] == 'L') // Dragon armor and plate legs -only special for non artisans.
  84. {
  85. if ($intRoll3 < 34)
  86. {
  87. if ($arrItem['type'] == 'A')
  88. {
  89. $strName = DRAGON2.$arrItem['name'];
  90. $intItembonus *= 2;
  91. }
  92. else
  93. {
  94. $strName = DRAGON3.$arrItem['name'];
  95. }
  96. special($intPower, $intItembonus, $player -> strength, $arrMaxbonus[$intKey] * $arrItem['power']);
  97. if ($player -> clas == ARTISAN)
  98. {
  99. $intPower += $player -> strength / 20;
  100. }
  101. }
  102. if ($player -> clas == ARTISAN)
  103. {
  104. if (($intRoll3 > 34 && $intRoll3 < 68)) //Dwarven armor
  105. {
  106. $strName = ($arrItem['type'] == 'A' ? DWARFS2 : DWARFS3).$arrItem['name'];
  107. special($intDur, $intItembonus, $player -> inteli, $arrItem['wt'] * 10);
  108. $intDur += $player -> inteli / 20;
  109. }
  110. if ($intRoll3 > 68) // Elven armor/plate legs.
  111. {
  112. if ($arrItem['type'] == 'A')
  113. {
  114. $strName = ELFS2.$arrItem['name'];
  115. }
  116. else
  117. {
  118. $strName = ELFS3.$arrItem['name'];
  119. $intItembonus = ceil($intItembonus / 2);
  120. }
  121. special($intAgi, $intItembonus, $player -> agility, $arrMaxbonus[$intKey] * $arrItem['zr'], 'a');
  122. $intAgi -= $player -> agility / 20;
  123. }
  124. if ($intRoll3 == 34) // 1% chance for special dragon (power+durability)
  125. {
  126. if ($arrItem['type'] == 'A')
  127. {
  128. $strName = DRAGON2.$arrItem['name'];
  129. $intItembonus *= 2;
  130. }
  131. else
  132. {
  133. $strName = DRAGON3.$arrItem['name'];
  134. }
  135. special($intPower, $intItembonus, $player -> strength, $arrMaxbonus[$intKey] * $arrItem['power']);
  136. special($intDur, $intItembonus, $player -> inteli, $arrItem['wt'] * 10);
  137. $intDur += $player -> inteli / 20;
  138. $intPower += $player -> strength / 20;
  139. }
  140. if ($intRoll3 == 68) // 1% chance for elven + durability
  141. {
  142. if ($arrItem['type'] == 'A')
  143. {
  144. $strName = ELFS2.$arrItem['name'];
  145. special($intAgi, $intItembonus, $player -> agility, $arrMaxbonus[$intKey] * $arrItem['zr'], 'a');
  146. }
  147. else
  148. {
  149. $strName = ELFS3.$arrItem['name'];
  150. special($intAgi,ceil($intItembonus / 2), $player -> agility, $arrMaxbonus[$intKey] * $arrItem['zr'], 'a');
  151. }
  152. special($intDur, $intItembonus, $player -> inteli, $arrItem['wt'] * 10);
  153. $intDur += $player -> inteli / 20;
  154. $intAgi -= $player -> agility / 20;
  155. }
  156. $blnSpecial = true;
  157. }
  158. }
  159. else // Weapons, helmets, shields
  160. {
  161. if ($intRoll3 < 51) // dragon
  162. {
  163. $strName = ($arrItem['type'] == 'W' || $arrItem['type'] == 'H' ? DRAGON1 : DRAGON2).$arrItem['name'];
  164. special($intPower, $intItembonus, $player -> strength, $arrMaxbonus[$intKey] * $arrItem['power']);
  165. if ($player -> clas == ARTISAN)
  166. {
  167. $intPower += $player -> strength / 20;
  168. }
  169. $blnSpecial = true;
  170. }
  171. if( $player -> clas == ARTISAN && $intRoll3 > 50)
  172. {
  173. if ($intRoll3 == 51) //dragon+durability
  174. {
  175. $strName = ($arrItem['type'] == 'W' || $arrItem['type'] == 'H' ? DRAGON1 : DRAGON2).$arrItem['name'];
  176. special($intPower, $intItembonus, $player -> strength, $arrMaxbonus[$intKey] * $arrItem['power']);
  177. special($intDur, $intItembonus, $player -> inteli, $arrItem['wt'] * 10);
  178. $intDur += $player -> inteli / 20;
  179. $intPower += $player -> strength / 20;
  180. }
  181. else // dwarven
  182. {
  183. $strName = ($arrItem['type'] == 'W' || $arrItem['type'] == 'H' ? DWARFS1 : DWARFS2).$arrItem['name'];
  184. special($intDur, $intItembonus, $player -> inteli, $arrItem['wt'] * 10);
  185. $intDur += $player -> inteli / 20;
  186. }
  187. $blnSpecial = true;
  188. }
  189. }
  190. }
  191. $intGainexp += $intExp * $arrItem['level'] * ($blnSpecial ? 100 + $intAbility / 10 : 1);
  192. $intItems ++;
  193. $intAbility = round($intAbility + $arrItem['level'] / 100,3);
  194. if ($arrItem['type'] == 'A')
  195. {
  196. $intAbility = round($intAbility + $arrItem['level'] / 100,3);
  197. }
  198. $arrRepair = array(1, 4, 16, 64, 256);
  199. $intRepaircost = $arrItem['level'] * $arrRepair[$intKey];
  200. if ($arrItem['type'] == 'W' || $arrItem['type'] == 'A')
  201. {
  202. $intRepaircost *= 2;
  203. }
  204. $intPower = (int)$intPower;
  205. $intAgi = (int)$intAgi;
  206. $intDur = (int)$intDur;
  207. $intCost = (int)$intCost;
  208. $test = $db -> getRow('SELECT `id` FROM `equipment` WHERE `name`=\''.$strName.'\' AND `wt`='.$intDur.' AND `type`=\''.$arrItem['type'].'\' AND `status`=\'U\' AND `owner`='.$player -> id.' AND `power`='.$intPower.' AND `zr`='.$intAgi.' AND `szyb`='.$arrItem['szyb'].' AND `maxwt`='.$intDur.' AND `poison`=0 AND `cost`='.$intCost.' AND `minlev` = '.$arrItem['level']);
  209. if (empty($test))
  210. {
  211. $db -> Execute('INSERT INTO `equipment` (`owner`, `name`, `power`, `type`, `cost`, `zr`, `wt`, `minlev`, `maxwt`, `amount`, `magic`, `poison`, `szyb`, `twohand`, `repair`) VALUES('.$player -> id.', \''.$strName.'\', '.$intPower.', \''.$arrItem['type'].'\', '.$intCost.', '.$intAgi.', '.$intDur.', '.$arrItem['level'].', '.$intDur.', 1, \'N\', 0,'.$arrItem['szyb'].', \''.$arrItem['twohand'].'\', '.$intRepaircost.')');
  212. }
  213. else
  214. {
  215. $db -> Execute('UPDATE `equipment` SET `amount`=`amount`+1 WHERE `id`='.$test['id']);
  216. }
  217. unset($test);
  218. }
  219. else
  220. {
  221. $intAbility += 0.005 * $arrItem['level'];
  222. if ($arrItem['type'] == 'A')
  223. {
  224. $intAbility += 0.005 * $arrItem['level'];
  225. }
  226. }
  227. }
  228. /**
  229. * Buy plans of items
  230. */
  231. if (isset ($_GET['kowal']) && $_GET['kowal'] == 'plany')
  232. {
  233. $smarty -> assign(array('Hereis' => HERE_IS,
  234. 'Aplansw' => A_PLANS_W,
  235. 'Aplansa' => A_PLANS_A,
  236. 'Aplansh' => A_PLANS_H,
  237. 'Aplansl' => A_PLANS_L,
  238. 'Aplanss' => A_PLANS_S));
  239. /**
  240. * Show avaiable plans
  241. */
  242. if (isset($_GET['dalej']))
  243. {
  244. $arrType = array('W', 'A', 'H', 'L', 'S');
  245. if (!in_array($_GET['dalej'], $arrType))
  246. {
  247. error (ERROR);
  248. }
  249. showplans ('smith', 0, $player -> lang, $_GET['dalej']);
  250. }
  251. /**
  252. * Buy new plan
  253. */
  254. if (isset($_GET['buy']))
  255. {
  256. buyplan ('smith', $_GET['buy'], $player -> id, $player -> credits);
  257. }
  258. }
  259. /**
  260. * Making items
  261. */
  262. if (isset ($_GET['kowal']) && $_GET['kowal'] == 'kuznia')
  263. {
  264. if (!isset($_GET['rob']) && !isset($_GET['konty']))
  265. {
  266. $smarty -> assign(array('Hereis' => SMITH_INFO,
  267. 'Amakew' => A_MAKE_W,
  268. 'Amakea' => A_MAKE_A,
  269. 'Amakeh' => A_MAKE_H,
  270. 'Amakel' => A_MAKE_L,
  271. 'Amakes' => A_MAKE_S,
  272. 'Amaker' => A_MAKE_R));
  273. if (isset($_GET['type']))
  274. {
  275. $arrType = array('W', 'A', 'H', 'L', 'S');
  276. if (!in_array($_GET['type'], $arrType))
  277. {
  278. error (ERROR);
  279. }
  280. showplans ('smith', $player -> id, $player -> lang, $_GET['type']);
  281. }
  282. showunfinished('smith_work', $player -> id);
  283. }
  284. else
  285. {
  286. $arrEquip = $player -> equipment();
  287. $arrRings = array(R_AGI, R_STR, R_INT);
  288. $arrStat = array('agility', 'strength', 'inteli');
  289. if ($arrEquip[9][2])
  290. {
  291. $arrRingtype = explode(" ", $arrEquip[9][1]);
  292. $intAmount = count($arrRingtype) - 1;
  293. $intKey = array_search($arrRingtype[$intAmount], $arrRings);
  294. if ($intKey != NULL)
  295. {
  296. $strStat = $arrStat[$intKey];
  297. $player -> $strStat = $player -> $strStat + $arrEquip[9][2];
  298. }
  299. }
  300. if ($arrEquip[10][2])
  301. {
  302. $arrRingtype = explode(" ", $arrEquip[10][1]);
  303. $intAmount = count($arrRingtype) - 1;
  304. $intKey = array_search($arrRingtype[$intAmount], $arrRings);
  305. if ($intKey != NULL)
  306. {
  307. $strStat = $arrStat[$intKey];
  308. $player -> $strStat = $player -> $strStat + $arrEquip[10][2];
  309. }
  310. }
  311. }
  312. if (isset($_GET['ko']))
  313. {
  314. if ($player -> hp == 0)
  315. {
  316. error (YOU_DEAD);
  317. }
  318. if (!ereg("^[1-9][0-9]*$", $_GET['ko']))
  319. {
  320. error (ERROR);
  321. }
  322. $objMaked = $db -> Execute('SELECT `name` FROM `smith_work` WHERE `id`='.$_GET['ko']);
  323. $smarty -> assign(array('Link' => 'kowal.php?kowal=kuznia&konty='.$_GET['ko'],
  324. 'Name' => $objMaked -> fields['name'],
  325. 'Assignen' => ASSIGN_EN,
  326. 'Senergy' => S_ENERGY,
  327. 'Amake' => A_MAKE));
  328. $objMaked -> Close();
  329. }
  330. if (isset($_GET['dalej']))
  331. {
  332. if ($player -> hp == 0)
  333. {
  334. error (YOU_DEAD);
  335. }
  336. if (!ereg("^[1-9][0-9]*$", $_GET['dalej']))
  337. {
  338. error (ERROR);
  339. }
  340. $objSmith = $db -> Execute('SELECT `name` FROM `smith` WHERE `id`='.$_GET['dalej']);
  341. $smarty -> assign(array('Link' => 'kowal.php?kowal=kuznia&rob='.$_GET['dalej'],
  342. 'Name' => $objSmith -> fields['name'],
  343. 'Assignen' => ASSIGN_EN,
  344. 'Senergy' => S_ENERGY,
  345. 'Amake' => A_MAKE,
  346. 'Mcopper' => M_COPPER,
  347. 'Mbronze' => M_BRONZE,
  348. 'Mbrass' => M_BRASS,
  349. 'Miron' => M_IRON,
  350. 'Msteel' => M_STEEL));
  351. $objSmith -> Close();
  352. }
  353. /**
  354. * Continue making items
  355. */
  356. if (isset($_GET['konty']))
  357. {
  358. if (!ereg("^[1-9][0-9]*$", $_GET['konty']) || !ereg("^[1-9][0-9]*$", $_POST['razy']))
  359. {
  360. error (ERROR);
  361. }
  362. $objWork = $db -> Execute('SELECT * FROM `smith_work` WHERE `id`='.$_GET['konty']);
  363. $objSmith = $db -> Execute('SELECT `name`, `type`, `cost`, `amount`, `level`, `twohand` FROM `smith` WHERE owner='.$player -> id.' AND name=\''.$objWork -> fields['name'].'\'');
  364. if ($player -> energy < $_POST['razy'])
  365. {
  366. error (NO_ENERGY);
  367. }
  368. $intNeed = ($objWork -> fields['n_energy'] - $objWork -> fields['u_energy']);
  369. if ($_POST['razy'] > $intNeed)
  370. {
  371. error (TOO_MUCH);
  372. }
  373. if ($objWork -> fields['owner'] != $player -> id)
  374. {
  375. error (NO_ITEM);
  376. }
  377. /**
  378. * Add bonuses to ability
  379. */
  380. require_once('includes/abilitybonus.php');
  381. $intSmith = abilitybonus('ability');
  382. $intItems = 0;
  383. $intGainexp = 0;
  384. $intAbility = 0;
  385. $arrMineral = array('copper', 'bronze', 'brass', 'iron', 'steel');
  386. $intKey = array_search($objWork -> fields['mineral'], $arrMineral);
  387. $arrMaxbonus = array(6, 10, 14, 17, 20);
  388. // Item cost: No of metal bars required to create one item * factor based on metal type.
  389. $intCost = $objSmith -> fields['amount'] * $arrMaxbonus[$intKey] * 3;
  390. $arrName = array(M_COPPER, M_BRONZE, M_BRASS, M_IRON, M_STEEL);
  391. if ($objSmith -> fields['type'] == 'W' || $objSmith -> fields['type'] == 'A')
  392. {
  393. $arrDur = array(40, 80, 160, 320, 640);
  394. }
  395. else
  396. {
  397. $arrDur = array(20, 40, 80, 160, 320);
  398. }
  399. $intPower = $objSmith -> fields['level'];
  400. if ($objSmith -> fields['type'] == 'A')
  401. {
  402. $intPower *= 3;
  403. $intAgility = floor($objSmith -> fields['level'] / 2);
  404. $intExp = 2;
  405. }
  406. elseif ($objSmith -> fields['type'] == 'L')
  407. {
  408. $intAgility = floor($objSmith -> fields['level'] / 5);
  409. $intExp = 1;
  410. }
  411. else
  412. {
  413. $intAgility = 0;
  414. $intExp = 1;
  415. }
  416. $strName = $objSmith -> fields['name']." ".$arrName[$intKey];
  417. $arrItem = array('power' => $intPower,
  418. 'wt' => $arrDur[$intKey],
  419. 'name' => $strName,
  420. 'type' => $objSmith -> fields['type'],
  421. 'level' => $objSmith -> fields['level'],
  422. 'szyb' => 0,
  423. 'zr' => $intAgility,
  424. 'cost' => $intCost,
  425. 'twohand' => $objSmith -> fields['twohand']);
  426. if ($player -> clas == ARTISAN)
  427. {
  428. $intExp *= 2;
  429. }
  430. $intChance = (50 - $arrMaxbonus[$intKey]) * $intSmith / $objSmith -> fields['level'];
  431. if ($intChance > 95)
  432. {
  433. $intChance = 95;
  434. }
  435. if ($_POST['razy'] == $intNeed)
  436. {
  437. createitem();
  438. if ($player -> clas == ARTISAN)
  439. {
  440. $intAbility *= 2;
  441. }
  442. $intGainexp = ceil($intGainexp);
  443. $intAbility = round($intAbility*100, 0)/100;
  444. if ($intItems)
  445. {
  446. $smarty -> assign ('Message', YOU_MAKE.$strName.AND_GAIN2.$intGainexp.AND_EXP2.$intAbility.IN_SMITH);
  447. }
  448. else
  449. {
  450. $intGainexp = 0;
  451. $smarty -> assign ('Message', YOU_TRY.$strName.BUT_FAIL.$intAbility.IN_SMITH);
  452. }
  453. $db -> Execute('DELETE FROM `smith_work` WHERE `owner`='.$player -> id);
  454. checkexp($player -> exp, $intGainexp, $player -> level, $player -> race, $player -> user, $player -> id, 0, 0, $player -> id, 'ability', $intAbility);
  455. }
  456. else
  457. {
  458. $uenergia = ($_POST['razy'] + $objWork -> fields['u_energy']);
  459. $intEnergy = $objSmith -> fields['level'];
  460. if ($objSmith -> fields['type'] == 'A')
  461. {
  462. $intEnergy *= 2;
  463. }
  464. $procent = round(($uenergia / $intEnergy) * 100);
  465. $need = $objWork -> fields['n_energy'] - $uenergia;
  466. $db -> Execute('UPDATE `smith_work` SET `u_energy`=`u_energy`+'.$_POST['razy'].' WHERE `owner`='.$player -> id);
  467. $smarty -> assign ('Message', YOU_WORK.$strName.NEXT_EN.$_POST['razy'].NOW_IS.$procent.YOU_NEED2.$need.S_ENERGY);
  468. }
  469. $db -> Execute('UPDATE `players` SET `energy`=`energy`-'.$_POST['razy'].' WHERE `id`='.$player -> id);
  470. }
  471. /**
  472. * Start making items
  473. */
  474. if (isset($_GET['rob']))
  475. {
  476. if (!ereg("^[1-9][0-9]*$", $_GET['rob']) || !isset($_POST['mineral']))
  477. {
  478. error(ERROR);
  479. }
  480. if (!isset($_POST['razy']))
  481. {
  482. error(HOW_MANY);
  483. }
  484. if (!ereg("^[1-9][0-9]*$", $_POST['razy']))
  485. {
  486. error(ERROR);
  487. }
  488. $arrMineral = array('copper', 'bronze', 'brass', 'iron', 'steel');
  489. if (!in_array($_POST['mineral'], $arrMineral))
  490. {
  491. error(ERROR);
  492. }
  493. $objTest = $db -> Execute('SELECT `id` FROM `smith_work` WHERE `owner`='.$player -> id);
  494. if ($objTest -> fields['id'])
  495. {
  496. error(YOU_MAKE2);
  497. }
  498. $objTest -> Close();
  499. $objSmith = $db -> Execute('SELECT `owner`, `name`, `type`, `cost`, `amount`, `level`, `twohand` FROM `smith` WHERE id='.$_GET['rob']);
  500. $objMineral = $db -> Execute('SELECT `'.$_POST['mineral'].'` FROM `minerals` WHERE `owner`='.$player -> id);
  501. $strMineral = $_POST['mineral'];
  502. $intAmount = floor($_POST['razy'] / $objSmith -> fields['level']);
  503. $intEnergy = $objSmith -> fields['level'];
  504. $intEnergy2 = $intAmount * $objSmith -> fields['level'];
  505. if ($objSmith -> fields['type'] == 'A')
  506. {
  507. $intAmount = floor($intAmount/2);
  508. $intEnergy *= 2;
  509. }
  510. $intAmineral = $objSmith -> fields['amount'] * ($intAmount ? $intAmount : 1);
  511. if ($intAmineral > $objMineral -> fields[$strMineral])
  512. {
  513. error (NO_MAT);
  514. }
  515. if ($player -> energy < $_POST['razy'])
  516. {
  517. error (NO_ENERGY);
  518. }
  519. if ($objSmith -> fields['owner'] != $player -> id)
  520. {
  521. error (NO_PLANS);
  522. }
  523. /**
  524. * Add bonuses to ability
  525. */
  526. require_once('includes/abilitybonus.php');
  527. $intSmith = abilitybonus('smith');
  528. $intItems = 0;
  529. $intGainexp = 0;
  530. $intAbility = 0;
  531. $intKey = array_search($_POST['mineral'], $arrMineral);
  532. $arrMaxbonus = array(6, 10, 14, 17, 20);
  533. // Item cost: No of metal bars required to create one item * factor based on metal type.
  534. $intCost = $objSmith -> fields['amount'] * $arrMaxbonus[$intKey] * 3;
  535. $arrName = array(M_COPPER, M_BRONZE, M_BRASS, M_IRON, M_STEEL);
  536. if ($objSmith -> fields['type'] == 'W' || $objSmith -> fields['type'] == 'A')
  537. {
  538. $arrDur = array(40, 80, 160, 320, 640);
  539. }
  540. else
  541. {
  542. $arrDur = array(20, 40, 80, 160, 320);
  543. }
  544. $intPower = $objSmith -> fields['level'];
  545. if ($objSmith -> fields['type'] == 'A')
  546. {
  547. $intPower *= 3;
  548. $intAgility = floor($objSmith -> fields['level'] / 2);
  549. $intExp = 2;
  550. }
  551. elseif ($objSmith -> fields['type'] == 'L')
  552. {
  553. $intAgility = floor($objSmith -> fields['level'] / 5);
  554. $intExp = 1;
  555. }
  556. else
  557. {
  558. $intAgility = 0;
  559. $intExp = 1;
  560. }
  561. $strName = $objSmith -> fields['name'].' '.$arrName[$intKey];
  562. $arrItem = array('power' => $intPower,
  563. 'wt' => $arrDur[$intKey],
  564. 'name' => $strName,
  565. 'type' => $objSmith -> fields['type'],
  566. 'level' => $objSmith -> fields['level'],
  567. 'szyb' => 0,
  568. 'zr' => $intAgility,
  569. 'cost' => $intCost,
  570. 'twohand' => $objSmith -> fields['twohand']);
  571. if ($player -> clas == ARTISAN)
  572. {
  573. $intExp *= 2;
  574. }
  575. $intChance = (50 - $arrMaxbonus[$intKey]) * $intSmith / $objSmith -> fields['level'];
  576. if ($intChance > 95)
  577. {
  578. $intChance = 95;
  579. }
  580. if ($intAmount > 0)
  581. {
  582. for ($i = 1; $i <= $intAmount; $i++)
  583. {
  584. createitem();
  585. }
  586. $intGainexp = ceil($intGainexp);
  587. if ($player -> clas == ARTISAN)
  588. {
  589. $intAbility *= 2;
  590. }
  591. $intAbility = round($intAbility*100, 0)/100;
  592. $intAbility = $intAbility ? $intAbility : 0.01;
  593. $smarty -> assign ('Message', YOU_MAKE.$objSmith -> fields['name'].'</b> <b>'.$intItems.AND_GAIN2.$intGainexp.AND_EXP2.$intAbility.IN_SMITH);
  594. checkexp($player -> exp, $intGainexp, $player -> level, $player -> race, $player -> user, $player -> id, 0, 0, $player -> id, 'ability', $intAbility);
  595. }
  596. else
  597. {
  598. $procent = round(($_POST['razy'] / $intEnergy) * 100);
  599. $need = ($intEnergy - $_POST['razy']);
  600. $intEnergy2 = $_POST['razy'];
  601. $db -> Execute('INSERT INTO `smith_work` (`owner`, `name`, `u_energy`, `n_energy`, `mineral`) VALUES('.$player -> id.', \''.$objSmith -> fields['name'].'\', '.$_POST['razy'].', '.$intEnergy.', \''.$_POST['mineral'].'\')');
  602. $smarty -> assign ('Message', YOU_WORK.$objSmith -> fields['name'].YOU_USE.$_POST['razy'].AND_MAKE.$procent.TO_END.$need.S_ENERGY);
  603. }
  604. $db -> Execute('UPDATE `minerals` SET `'.$_POST['mineral'].'`=`'.$_POST['mineral'].'`-'.$intAmineral.' WHERE `owner`='.$player -> id);
  605. $db -> Execute('UPDATE `players` SET `energy`=`energy`-'.$intEnergy2.' WHERE `id`='.$player -> id);
  606. }
  607. }
  608. /**
  609. * Make astral constructions
  610. */
  611. if (isset($_GET['kowal']) && $_GET['kowal'] == 'astral')
  612. {
  613. if( !isset($_GET['component'] ))
  614. {
  615. makeastral1();
  616. }
  617. else
  618. {
  619. makeastral1('ability', $_GET['component']);
  620. }
  621. }
  622. /**
  623. * Initialization of variables
  624. */
  625. if (!isset($_GET['kowal']))
  626. {
  627. $_GET['kowal'] = '';
  628. $smarty -> assign(array('Smithinfo' => SMITH_INFO,
  629. 'Aplans' => A_PLANS,
  630. 'Asmith' => A_SMITH,
  631. 'Aastral' => A_ASTRAL));
  632. }
  633. else
  634. {
  635. $smarty -> assign('Aback', A_BACK);
  636. }
  637. if (!isset($_GET['dalej']))
  638. {
  639. $_GET['dalej'] = '';
  640. }
  641. if (!isset($_GET['buy']))
  642. {
  643. $_GET['buy'] = '';
  644. }
  645. if (!isset($_GET['rob']))
  646. {
  647. $_GET['rob'] = '';
  648. }
  649. if (!isset($_GET['konty']))
  650. {
  651. $_GET['konty'] = '';
  652. }
  653. if (!isset($_GET['type']))
  654. {
  655. $_GET['type'] = '';
  656. }
  657. if (!isset($_GET['ko']))
  658. {
  659. $_GET['ko'] = '';
  660. }
  661. /**
  662. * Assign variables to template and display page
  663. */
  664. $smarty -> assign(array('Smith' => $_GET['kowal'],
  665. 'Next' => $_GET['dalej'],
  666. 'Buy' => $_GET['buy'],
  667. 'Make' => $_GET['rob'],
  668. 'Continue' => $_GET['konty'],
  669. 'Type' => $_GET['type'],
  670. 'Cont' => $_GET['ko']));
  671. $smarty -> display ('kowal.tpl');
  672. require_once('includes/foot.php');
  673. ?>