PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/jeweller.php

https://bitbucket.org/marecki/orodlin-v.1
PHP | 999 lines | 830 code | 48 blank | 121 comment | 154 complexity | 512f7dbd6b7c8856252801a01a1e1474 MD5 | raw file
  1. <?php
  2. /**
  3. * File functions:
  4. * Jeweller - make rings
  5. *
  6. * @name : jeweller.php
  7. * @copyright : (C) 2006 Vallheru Team based on Gamers-Fusion ver 2.5
  8. * @author : thindil <thindil@users.sourceforge.net>
  9. * @version : 1.3
  10. * @since : 16.11.2006
  11. *
  12. */
  13. //
  14. //
  15. // This program is free software; you can redistribute it and/or modify
  16. // it under the terms of the GNU General Public License as published by
  17. // the Free Software Foundation; either version 2 of the License, or
  18. // (at your option) any later version.
  19. //
  20. // This program is distributed in the hope that it will be useful,
  21. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. // GNU General Public License for more details.
  24. //
  25. // You should have received a copy of the GNU General Public License
  26. // along with this program; if not, write to the Free Software
  27. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  28. //
  29. //
  30. $title = 'Warsztat jubilerski';
  31. require_once('includes/head.php');
  32. require_once('includes/checkexp.php');
  33. require_once('includes/artisan.php');
  34. /**
  35. * Get the localization for game
  36. */
  37. require_once('languages/'.$player -> lang.'/jeweller.php');
  38. if ($player -> location != 'Ardulith')
  39. {
  40. error(ERROR);
  41. }
  42. /**
  43. * Main menu
  44. */
  45. if (!isset($_GET['step']))
  46. {
  47. $_GET['step'] = '';
  48. $smarty -> assign(array('Jewellerinfo' => JEWELLER_INFO,
  49. 'Aplans' => A_PLANS,
  50. 'Aring' => A_RING,
  51. 'Amakering' => A_MAKE_RING,
  52. 'Amakering2' => A_MAKE_RING2,
  53. 'Playerclass' => $player -> clas,
  54. 'Aastral' => A_ASTRAL));
  55. }
  56. else
  57. {
  58. $smarty -> assign(array('Aback' => A_BACK,
  59. 'Message' => ''));
  60. }
  61. /**
  62. * Buy plans
  63. */
  64. if (isset ($_GET['step']) && $_GET['step'] == 'plans')
  65. {
  66. if (!isset($_GET['buy']))
  67. {
  68. showplans ('jeweller', 0, $player -> clas);
  69. }
  70. else
  71. {
  72. buyplan('jeweller', $_GET['buy'], $player -> id, $player -> credits, $player -> clas);
  73. }
  74. }
  75. /**
  76. * Make simple rings
  77. */
  78. if (isset($_GET['step']) && $_GET['step'] == 'make')
  79. {
  80. $objPlan = $db -> Execute('SELECT `id` FROM `jeweller` WHERE `name`=\''.RING.'\' AND `owner`='.$player -> id);
  81. if (!$objPlan -> fields['id'])
  82. {
  83. error(NO_PLAN);
  84. }
  85. $objPlan -> Close();
  86. $smarty -> assign(array('Ringinfo' => RING_INFO,
  87. 'Amake' => A_MAKE,
  88. 'Ramount' => R_AMOUNT));
  89. if (isset($_GET['make']) && $_GET['make'] == 'Y')
  90. {
  91. if (!ereg("^[1-9][0-9]*$", $_POST['amount']))
  92. {
  93. error(ERROR);
  94. }
  95. if ($player -> hp == 0)
  96. {
  97. error(YOU_DEAD);
  98. }
  99. $objAdamantium = $db -> Execute('SELECT `adamantium` FROM `minerals` WHERE `owner`='.$player -> id);
  100. if ($objAdamantium -> fields['adamantium'] < $_POST['amount'])
  101. {
  102. error(NO_ADAMANTIUM);
  103. }
  104. $objAdamantium -> Close();
  105. if ($player -> energy < $_POST['amount'])
  106. {
  107. error(NO_ENERGY);
  108. }
  109. /**
  110. * Add bonuses to ability
  111. */
  112. require_once('includes/abilitybonus.php');
  113. $intJeweller = abilitybonus('jeweller');
  114. $intChance = $intJeweller * 100;
  115. if ($intChance > 95)
  116. {
  117. $intChance = 95;
  118. }
  119. $intAmount = 0;
  120. for ($i = 0; $i < $_POST['amount']; $i++)
  121. {
  122. $intRoll = rand(1, 100);
  123. if ($intRoll < $intChance)
  124. {
  125. $intAmount ++;
  126. }
  127. }
  128. $intAbility = ($intAmount + $_POST['amount']) * 0.005 ;
  129. $intGainexp = $intAmount;
  130. if ($player -> clas == ARTISAN)
  131. {
  132. $intAbility = $intAbility * 2;
  133. $intGainexp = $intGainexp * 2;
  134. }
  135. $intAbility = round($intAbility*100, 0)/100;
  136. $intAbility = $intAbility ? $intAbility : 0.01;
  137. checkexp($player -> exp, $intGainexp, $player -> level, $player -> race, $player -> user, $player -> id, 0, 0, $player -> id, 'jeweller', $intAbility);
  138. if ($intAmount)
  139. {
  140. $objTest = $db -> Execute('SELECT `id` FROM `equipment` WHERE `owner`='.$player -> id.' AND `name`=\''.RING.'\' AND `status`=\'U\'');
  141. if (!$objTest -> fields['id'])
  142. {
  143. $db -> Execute('INSERT INTO `equipment` (`owner`, `name`, `power`, `type`, `cost`, `minlev`, `amount`) VALUES('.$player -> id.', \''.RING.'\', 0, \'I\', 3, 1, '.$intAmount.')');
  144. }
  145. else
  146. {
  147. $db -> Execute('UPDATE `equipment` SET `amount`=`amount`+'.$intAmount.' WHERE `id`='.$objTest -> fields['id']);
  148. }
  149. $objTest -> Close();
  150. }
  151. $db -> Execute('UPDATE `players` SET `energy`=`energy`-'.$_POST['amount'].' WHERE `id`='.$player -> id);
  152. $db -> Execute('UPDATE `minerals` SET `adamantium`=`adamantium`-'.$_POST['amount'].' WHERE `owner`='.$player -> id);
  153. $smarty -> assign('Message', YOU_MAKE.$intAmount.'</b> '.R_AMOUNT.YOU_GAIN3.$intGainexp.T_PD.$intAbility.T_ABILITY);
  154. }
  155. }
  156. /**
  157. * Make rings with bonus to stats
  158. */
  159. if (isset($_GET['step']) && $_GET['step'] == 'make2')
  160. {
  161. if ($player -> clas != ARTISAN)
  162. {
  163. error(WRONG_CLASS);
  164. }
  165. /**
  166. * Make rings menu
  167. */
  168. if (!isset($_GET['action']))
  169. {
  170. $objMaked = $db -> Execute('SELECT `id`, `name`, `n_energy`, `u_energy` FROM `jeweller_work` WHERE `owner`='.$player -> id.' AND `type`=\'N\'');
  171. if (!$objMaked -> fields['id'])
  172. {
  173. $objPlans = $db -> Execute('SELECT `id`, `name`, `level`, `bonus` FROM `jeweller` WHERE `owner`='.$player -> id.' AND `name`!=\''.RING.'\' ORDER BY `level`');
  174. if (!$objPlans -> fields['name'])
  175. {
  176. error(NO_PLANS);
  177. }
  178. $arrId = array();
  179. $arrName = array();
  180. $arrLevel = array();
  181. $arrAdam = array();
  182. $arrCryst = array();
  183. $arrMeteor = array();
  184. $arrEnergy = array();
  185. $arrChange = array();
  186. $arrBonus = array();
  187. $i = 0;
  188. while (!$objPlans -> EOF)
  189. {
  190. $arrId[$i] = $objPlans -> fields['id'];
  191. $arrName[$i] = $objPlans -> fields['name'];
  192. $arrLevel[$i] = $objPlans -> fields['level'];
  193. $arrAdam[$i] = $objPlans -> fields['level'];
  194. $arrCryst[$i] = ceil($objPlans -> fields['level'] / 2);
  195. $arrMeteor[$i] = ceil($objPlans -> fields['level'] / 4);
  196. $arrBonus[$i] = $objPlans -> fields['bonus'];
  197. $arrEnergy[$i] = $objPlans -> fields['level'] * 2;
  198. $intChange = $objPlans -> fields['level'] * 4;
  199. if ($player -> jeweller >= $intChange)
  200. {
  201. $arrChange[$i] = YES;
  202. }
  203. else
  204. {
  205. $arrChange[$i] = NO;
  206. }
  207. $i++;
  208. $objPlans -> MoveNext();
  209. }
  210. $objPlans -> Close();
  211. $smarty -> assign(array('Ringinfo' => RING_INFO,
  212. 'Tname' => T_NAME,
  213. 'Tlevel' => T_LEVEL,
  214. 'Tadam' => T_ADAM,
  215. 'Tcryst' => T_CRYST,
  216. 'Tmeteor' => T_METEOR,
  217. 'Tenergy' => T_ENERGY,
  218. 'Tbonus' => T_BONUS,
  219. 'Tchange' => T_CHANGE,
  220. 'Rname' => $arrName,
  221. 'Rlevel' => $arrLevel,
  222. 'Radam' => $arrAdam,
  223. 'Rcryst' => $arrCryst,
  224. 'Rmeteor' => $arrMeteor,
  225. 'Renergy' => $arrEnergy,
  226. 'Rbonus' => $arrBonus,
  227. 'Rid' => $arrId,
  228. 'Rchange' => $arrChange,
  229. 'Action' => '',
  230. 'Make' => '',
  231. 'Maked' => ''));
  232. /**
  233. * Select make ring
  234. */
  235. if (isset($_GET['make']))
  236. {
  237. if (!ereg("^[1-9][0-9]*$", $_GET['make']))
  238. {
  239. error(ERROR);
  240. }
  241. if ($player -> hp == 0)
  242. {
  243. error(YOU_DEAD);
  244. }
  245. if ($objMaked -> fields['id'])
  246. {
  247. error(ERROR);
  248. }
  249. $intKey = array_search($_GET['make'], $arrId);
  250. $arrBonus = array(R_AGI, R_STR, R_INT, R_WIS, R_SPE, R_CON);
  251. if ($arrChange[$intKey] == YES)
  252. {
  253. $strChange = 'Y';
  254. }
  255. else
  256. {
  257. $strChange = 'N';
  258. }
  259. $smarty -> assign(array('Make' => $_GET['make'],
  260. 'Rname2' => $arrName[$intKey],
  261. 'Rbonus2' => $arrBonus,
  262. 'Pjeweller' => $player -> jeweller,
  263. 'Change' => $strChange,
  264. 'Youmake' => YOU_MAKE,
  265. 'Ramount' => R_AMOUNT2,
  266. 'Withbon' => WITH_BON,
  267. 'Tenergy3' => R_ENERGY));
  268. }
  269. }
  270. else
  271. {
  272. $smarty -> assign(array('Ringinfo' => RING_INFO,
  273. 'Tname' => T_NAME,
  274. 'Tenergy' => T_ENERGY,
  275. 'Tenergy2' => T_ENERGY2,
  276. 'Youcontinue' => YOU_CONTINUE,
  277. 'Tenergy3' => R_ENERGY,
  278. 'Ramount' => R_AMOUNT2,
  279. 'Rname' => $objMaked -> fields['name'],
  280. 'Renergy' => $objMaked -> fields['n_energy'],
  281. 'Renergy2' => $objMaked -> fields['u_energy'],
  282. 'Action' => '',
  283. 'Make' => '',
  284. 'Maked' => $objMaked -> fields['id']));
  285. }
  286. $objMaked -> Close();
  287. }
  288. /**
  289. * Continue create rings
  290. */
  291. if (isset($_GET['action']) && $_GET['action'] == 'continue')
  292. {
  293. if (!ereg("^[1-9][0-9]*$", $_POST['make']) || !ereg("^[1-9][0-9]*$", $_POST['amount']))
  294. {
  295. error(ERROR);
  296. }
  297. if ($player -> hp == 0)
  298. {
  299. error(YOU_DEAD);
  300. }
  301. $objRing = $db -> Execute('SELECT `owner`, `name`, `n_energy`, `u_energy`, `bonus` FROM `jeweller_work` WHERE `id`='.$_POST['make']);
  302. if (!$objRing -> fields['owner'] || $objRing -> fields['owner'] != $player -> id)
  303. {
  304. error(NO_WORK);
  305. }
  306. $intEnergy = $_POST['amount'] + $objRing -> fields['u_energy'];
  307. if ($intEnergy > $objRing -> fields['n_energy'])
  308. {
  309. error(TOO_MUCH);
  310. }
  311. /**
  312. * When player assign need energy
  313. */
  314. if ($intEnergy == $objRing -> fields['n_energy'])
  315. {
  316. /**
  317. * Add bonuses to ability
  318. */
  319. require_once('includes/abilitybonus.php');
  320. $intJeweller = abilitybonus('jeweller');
  321. $objRing2 = $db -> Execute('SELECT `level`, `bonus`, `cost`, `type` FROM `jeweller` WHERE `owner`='.$player -> id.' AND `name`=\''.$objRing -> fields['name'].'\'');
  322. $intChance = ($intJeweller / $objRing2 -> fields['level']) * 50;
  323. if ($intChance > 95)
  324. {
  325. $intChance = 95;
  326. }
  327. $intGainexp = 0;
  328. $arrStats = array(R_AGI, R_STR, R_INT, R_WIS, R_SPE, R_CON);
  329. $arrStats2 = array('agility', 'strength', 'inteli', 'wisdom', 'speed', 'cond');
  330. $intKey = array_search($objRing -> fields['bonus'], $arrStats);
  331. $intStat = $player -> $arrStats2[$intKey];
  332. $intRoll = rand(1, 100);
  333. /**
  334. * Success
  335. */
  336. if ($intRoll <= $intChance)
  337. {
  338. echo (floor($intJeweller/2))." - ".$intJeweller." ";
  339. echo $intBonus = rand(floor($intJeweller/2), $intJeweller);
  340. if ($intBonus < 1)
  341. {
  342. $intBonus = 1;
  343. }
  344. if ($intBonus > $objRing2 -> fields['bonus'])
  345. {
  346. $intBonus = $objRing2 -> fields['bonus'];
  347. }
  348. $intBonus += floor($intStat / 50);
  349. $strName = $objRing -> fields['name']." ".$objRing -> fields['bonus'];
  350. $intCost = ceil($objRing2 -> fields['cost'] / 200);
  351. $objTest = $db -> Execute('SELECT `id` FROM `equipment` WHERE `owner`='.$player -> id.' AND status=\'U\' AND `name`=\''.$strName.'\' AND `power`='.$intBonus.' AND `cost`='.$intCost);
  352. if (!$objTest -> fields['id'])
  353. {
  354. $db -> Execute('INSERT INTO `equipment` (`owner`, `name`, `power`, `status`, `type`, `cost`, `minlev`, `amount`) VALUES('.$player -> id.', \''.$strName.'\', '.$intBonus.', \'U\', \''.$objRing2 -> fields['type'].'\', '.$intCost.', '.$objRing2 -> fields['level'].', 1)');
  355. }
  356. else
  357. {
  358. $db -> Execute('UPDATE `equipment` SET `amount`=`amount`+1 WHERE `id`='.$objTest -> fields['id']);
  359. }
  360. $objTest -> Close();
  361. $intGainexp = $objRing2 -> fields['level'] * 200;
  362. $intAbility = ($objRing -> fields['n_energy'] * 0.02);
  363. $smarty -> assign('Message', YOU_MAKE.$strName.YOU_GAIN3.$intGainexp.AND_EXP2.$intAbility.IN_JEWELLER);
  364. }
  365. else
  366. {
  367. $intAbility = ($objRing -> fields['n_energy'] * 0.01);
  368. $intGainexp = 0;
  369. $smarty -> assign('Message', YOU_TRY.$objRing -> fields['name'].BUT_FAIL.$intAbility.IN_JEWELLER);
  370. }
  371. $objRing2 -> Close();
  372. $db -> Execute('DELETE FROM `jeweller_work` WHERE `id`='.$_POST['make']);
  373. checkexp($player -> exp, $intGainexp, $player -> level, $player -> race, $player -> user, $player -> id, 0, 0, $player -> id, 'jeweller', $intAbility);
  374. }
  375. else
  376. {
  377. $db -> Execute('UPDATE `jeweller_work` SET `u_energy`='.$intEnergy.' WHERE `id`='.$_POST['make']);
  378. $smarty -> assign('Message', YOU_TRY.$objRing -> fields['name'].YOU_GAIN4);
  379. }
  380. $objRing -> Close();
  381. $db -> Execute('UPDATE `players` SET `energy`=`energy`-'.$_POST['amount'].' WHERE `id`='.$player -> id);
  382. $smarty -> assign('Action', $_GET['action']);
  383. }
  384. /**
  385. * Start create rings
  386. */
  387. if (isset($_GET['action']) && $_GET['action'] == 'create')
  388. {
  389. if (!ereg("^[1-9][0-9]*$", $_POST['make']) || !ereg("^[1-9][0-9]*$", $_POST['amount']))
  390. {
  391. error(ERROR);
  392. }
  393. $objRing = $db -> Execute('SELECT `owner`, `name`, `level`, `bonus`, `cost`, `type` FROM `jeweller` WHERE `id`='.$_POST['make']);
  394. if (!$objRing -> fields['owner'] || $objRing -> fields['owner'] != $player -> id)
  395. {
  396. error(NO_PLAN);
  397. }
  398. $intMake = floor($_POST['amount'] / ($objRing -> fields['level'] * 2));
  399. $intNeed = ($intMake < 1) ? 1 : $intMake;
  400. $intAdam = $objRing -> fields['level'] * $intNeed;
  401. $intCryst = ceil($objRing -> fields['level'] / 2) * $intNeed;
  402. $intMeteor = ceil($objRing -> fields['level'] / 4) * $intNeed;
  403. $objMinerals = $db -> Execute('SELECT `adamantium`, `crystal`, `meteor` FROM `minerals` WHERE `owner`='.$player -> id);
  404. if ($objMinerals -> fields['adamantium'] < $intAdam || $objMinerals -> fields['crystal'] < $intCryst || $objMinerals -> fields['meteor'] < $intMeteor)
  405. {
  406. error(NO_MINERALS);
  407. }
  408. $objMinerals -> Close();
  409. if ($player -> energy < $_POST['amount'])
  410. {
  411. error(NO_ENERGY);
  412. }
  413. $objRings = $db -> Execute('SELECT `id`, `amount` FROM `equipment` WHERE `owner`='.$player -> id.' AND `name`=\''.RING.'\' AND `status`=\'U\'');
  414. if ($objRings -> fields['amount'] < $intMake)
  415. {
  416. error(NO_RINGS);
  417. }
  418. /**
  419. * Add bonuses to ability
  420. */
  421. require_once('includes/abilitybonus.php');
  422. $intJeweller = abilitybonus('jeweller');
  423. $intChance = ($intJeweller / $objRing -> fields['level']) * 50;
  424. if ($intChance > 95)
  425. {
  426. $intChance = 95;
  427. }
  428. /**
  429. * Which stats have bonus
  430. */
  431. $intChange = $objRing -> fields['level'] * 4;
  432. $arrStats = array(R_AGI, R_STR, R_INT, R_WIS, R_SPE, R_CON);
  433. $arrStats2 = array('agility', 'strength', 'inteli', 'wisdom', 'speed', 'cond');
  434. if (isset($_POST['bonus']) && $player -> jeweller >= $intChange)
  435. {
  436. $strStat = $_POST['bonus'];
  437. $intKey = array_search($_POST['bonus'], $arrStats);
  438. $intStat = $player -> $arrStats2[$intKey];
  439. }
  440. else
  441. {
  442. $intRoll = rand(0, 5);
  443. $strStat = $arrStats[$intRoll];
  444. $intStat = $player -> $arrStats2[$intRoll];
  445. }
  446. /**
  447. * Start create items
  448. */
  449. $arrBonus = array();
  450. $arrAmount = array();
  451. $intAmount2 = 0;
  452. for ($i = 0; $i < $intMake; $i++)
  453. {
  454. $intRoll = rand(1, 100);
  455. if ($intRoll <= $intChance)
  456. {
  457. $intAmount2++;
  458. echo (floor($intJeweller/2))." - ".$intJeweller." ";
  459. echo $intBonus = rand(floor($intJeweller/2), $intJeweller);
  460. if ($intBonus < 1)
  461. {
  462. $intBonus = 1;
  463. }
  464. if ($intBonus > $objRing -> fields['bonus'])
  465. {
  466. $intBonus = $objRing -> fields['bonus'];
  467. }
  468. $intBonus += floor($intStat / 50);
  469. $intKey = array_search($intBonus, $arrBonus);
  470. if (!empty($intKey) || $intKey === 0)
  471. {
  472. $arrAmount[$intKey]++;
  473. }
  474. else
  475. {
  476. $arrBonus[] = $intBonus;
  477. $arrAmount[] = 1;
  478. }
  479. }
  480. }
  481. /**
  482. * Write to database and show info
  483. */
  484. $intAbility = 0;
  485. if ($intMake > 0)
  486. {
  487. $i = 0;
  488. $strName = $objRing -> fields['name']." ".$strStat;
  489. $intCost = ceil($objRing -> fields['cost'] / 200);
  490. foreach ($arrAmount as $intAmount)
  491. {
  492. $objTest = $db -> Execute('SELECT `id` FROM `equipment` WHERE `owner`='.$player -> id.' AND status=\'U\' AND `name`=\''.$strName.'\' AND `power`='.$arrBonus[$i].' AND `cost`='.$intCost);
  493. if (!$objTest -> fields['id'])
  494. {
  495. $db -> Execute('INSERT INTO `equipment` (`owner`, `name`, `power`, `status`, `type`, `cost`, `minlev`, `amount`) VALUES('.$player -> id.', \''.$strName.'\', '.$arrBonus[$i].', \'U\', \''.$objRing -> fields['type'].'\', '.$intCost.', '.$objRing -> fields['level'].', '.$intAmount.')');
  496. }
  497. else
  498. {
  499. $db -> Execute('UPDATE `equipment` SET `amount`=`amount`+'.$intAmount.' WHERE `id`='.$objTest -> fields['id']);
  500. }
  501. $objTest -> Close();
  502. $i ++;
  503. }
  504. $intGainexp = $objRing -> fields['level'] * 200;
  505. $intGainexp = floor($intGainexp * $intAmount2);
  506. $intAbility = 0.02 * $objRing -> fields['level'] * ($intAmount2 + $intMake);
  507. $smarty -> assign('Message', YOU_MAKE.$intAmount2.'</b> '.R_AMOUNT.$strName.YOU_GAIN3.$intGainexp.AND_EXP2.$intAbility.IN_JEWELLER);
  508. }
  509. else
  510. {
  511. $intAdam = $objRing -> fields['level'];
  512. $intCryst = ceil($objRing -> fields['level'] / 2);
  513. $intMeteor = ceil($objRing -> fields['level'] / 4);
  514. $intGainexp = 0;
  515. $intEnergy2 = ($objRing -> fields['level'] * 2);
  516. $intAbility = 0;
  517. $intEnergy = $_POST['amount'];
  518. $intMake = 1;
  519. $db -> Execute('INSERT INTO `jeweller_work` (`owner`, `name`, `n_energy`, `u_energy`, `bonus`, `type`) VALUES('.$player -> id.', \''.$objRing -> fields['name'].'\', '.$intEnergy2.', '.$_POST['amount'].', \''.$strStat.'\', \'N\')');
  520. $smarty -> assign('Message', YOU_TRY.$objRing -> fields['name'].YOU_GAIN4);
  521. }
  522. checkexp($player -> exp, $intGainexp, $player -> level, $player -> race, $player -> user, $player -> id, 0, 0, $player -> id, 'jeweller', $intAbility);
  523. $db -> Execute('UPDATE `minerals` SET `adamantium`=`adamantium`-'.$intAdam.', `crystal`=`crystal`-'.$intCryst.', `meteor`=`meteor`-'.$intMeteor.' WHERE `owner`='.$player -> id);
  524. $db -> Execute('UPDATE `players` SET `energy`=`energy`-'.$_POST['amount'].' WHERE `id`='.$player -> id);
  525. if ($objRings -> fields['amount'] == $intMake)
  526. {
  527. $db -> Execute('DELETE FROM `equipment` WHERE `id`='.$objRings -> fields['id']);
  528. }
  529. else
  530. {
  531. $db -> Execute('UPDATE `equipment` SET `amount`=`amount`-'.$intMake.' WHERE `id`='.$objRings -> fields['id']);
  532. }
  533. $objRings -> Close();
  534. $smarty -> assign('Action', $_GET['action']);
  535. }
  536. }
  537. /**
  538. * Make special rings with bonus to stats
  539. */
  540. if (isset($_GET['step']) && $_GET['step'] == 'make3')
  541. {
  542. if ($player -> clas != ARTISAN)
  543. {
  544. error(WRONG_CLASS);
  545. }
  546. /**
  547. * Main menu
  548. */
  549. $objMaked = $db -> Execute('SELECT `id`, `name`, `n_energy`, `u_energy` FROM `jeweller_work` WHERE `owner`='.$player -> id.' AND `type`=\'S\'');
  550. if (!$objMaked -> fields['id'])
  551. {
  552. $objPlans = $db -> Execute('SELECT `name`, `level` FROM `jeweller` WHERE `owner`='.$player -> id.' AND `name`!=\''.RING.'\' ORDER BY `level`');
  553. if (!$objPlans -> fields['name'])
  554. {
  555. error(NO_PLANS);
  556. }
  557. $arrName = array();
  558. $arrLevel = array();
  559. $arrMeteor = array();
  560. $arrEnergy = array();
  561. $i = 0;
  562. while (!$objPlans -> EOF)
  563. {
  564. $arrName[$i] = $objPlans -> fields['name'];
  565. $arrLevel[$i] = $objPlans -> fields['level'];
  566. $arrMeteor[$i] = ceil($objPlans -> fields['level'] / 2);
  567. $arrEnergy[$i] = $objPlans -> fields['level'] * 1.5;
  568. $i++;
  569. $objPlans -> MoveNext();
  570. }
  571. $objPlans -> Close();
  572. $objRings = $db -> Execute('SELECT `id`, `name`, `amount`, `minlev`, `power`, `cost` FROM `equipment` WHERE `owner`='.$player -> id.' AND `status`=\'U\' AND `type`=\'I\' AND `name`!=\''.RING.'\' AND `name` NOT LIKE \''.R_GNOME.'%\' AND `name` NOT LIKE \''.R_ELF.'%\' AND `name` NOT LIKE \''.R_DWARF.'%\' AND `name` NOT LIKE \''.R_GOD.'%\'');
  573. $arrRid = array();
  574. $arrRname = array();
  575. $arrRamount = array();
  576. $arrRpower = array();
  577. $arrRlevel = array();
  578. $arrRcost = array();
  579. $i = 0;
  580. while (!$objRings -> EOF)
  581. {
  582. $arrRid[$i] = $objRings -> fields['id'];
  583. $arrRname[$i] = $objRings -> fields['name'];
  584. $arrRamount[$i] = $objRings -> fields['amount'];
  585. $arrRpower[$i] = $objRings -> fields['power'];
  586. $arrRlevel[$i] = $objRings -> fields['minlev'];
  587. $arrRcost[$i] = $objRings -> fields['cost'];
  588. $i++;
  589. $objRings -> MoveNext();
  590. }
  591. $objRings -> Close();
  592. $smarty -> assign(array('Ringinfo' => RING_INFO,
  593. 'Tname' => T_NAME,
  594. 'Tlevel' => T_LEVEL,
  595. 'Tmeteor' => T_METEOR,
  596. 'Tenergy' => T_ENERGY,
  597. 'Amake' => A_MAKE,
  598. 'Ramount' => R_AMOUNT,
  599. 'Onspecial' => ON_SPECIAL,
  600. 'Ramount3' => R_AMOUNT2,
  601. 'Ramount4' => R_AMOUNT4,
  602. 'Renergy2' => R_ENERGY,
  603. 'Maked' => '',
  604. 'Rname' => $arrName,
  605. 'Rlevel' => $arrLevel,
  606. 'Rmeteor' => $arrMeteor,
  607. 'Renergy' => $arrEnergy,
  608. 'Rid2' => $arrRid,
  609. 'Rname2' => $arrRname,
  610. 'Ramount2' => $arrRamount,
  611. 'Rpower' => $arrRpower));
  612. }
  613. else
  614. {
  615. $smarty -> assign(array('Ringinfo' => RING_INFO,
  616. 'Tname' => T_NAME,
  617. 'Tenergy' => T_ENERGY,
  618. 'Tenergy2' => T_ENERGY2,
  619. 'Youcontinue' => YOU_CONTINUE,
  620. 'Tenergy3' => R_ENERGY,
  621. 'Ramount' => R_AMOUNT2,
  622. 'Rname' => $objMaked -> fields['name'],
  623. 'Renergy' => $objMaked -> fields['n_energy'],
  624. 'Renergy2' => $objMaked -> fields['u_energy'],
  625. 'Action' => '',
  626. 'Make' => '',
  627. 'Maked' => $objMaked -> fields['id']));
  628. }
  629. /**
  630. * Continue create special rings
  631. */
  632. if (isset($_GET['action']) && $_GET['action'] == 'continue')
  633. {
  634. if (!ereg("^[1-9][0-9]*$", $_POST['make']) || !ereg("^[0-9][0-9\.]*$", $_POST['amount']))
  635. {
  636. error(ERROR);
  637. }
  638. if ($player -> hp == 0)
  639. {
  640. error(YOU_DEAD);
  641. }
  642. $objRing = $db -> Execute('SELECT `owner`, `name`, `n_energy`, `u_energy`, `bonus` FROM `jeweller_work` WHERE `id`='.$_POST['make']);
  643. if (!$objRing -> fields['owner'] || $objRing -> fields['owner'] != $player -> id)
  644. {
  645. error(NO_WORK);
  646. }
  647. $intEnergy = $_POST['amount'] + $objRing -> fields['u_energy'];
  648. if ($intEnergy > $objRing -> fields['n_energy'])
  649. {
  650. error(TOO_MUCH);
  651. }
  652. /**
  653. * When player assign need energy
  654. */
  655. if ($intEnergy == $objRing -> fields['n_energy'])
  656. {
  657. /**
  658. * Add bonuses to ability
  659. */
  660. require_once('includes/abilitybonus.php');
  661. $intJeweller = abilitybonus('jeweller');
  662. /**
  663. * Select ring name
  664. */
  665. $arrRings = array(R_AGI, R_SPE, R_STR, R_CON, R_INT, R_WIS);
  666. $arrPrefix = array(R_ELF, R_DWARF, R_GNOME);
  667. $strName = $objRing -> fields['name'];
  668. $arrRingtype = explode(" ", $strName);
  669. $intAmount2 = count($arrRingtype) - 1;
  670. $intKey2 = array_search($arrRingtype[$intAmount2], $arrRings);
  671. $intName = $intAmount2 - ( ($intKey2 < 5) ? 1 : 2 );
  672. $strName2 = '';
  673. for ($i = 0; $i <= $intName; $i++)
  674. {
  675. if (!empty($strName2))
  676. {
  677. $strName2 = $strName2." ";
  678. }
  679. $strName2 = $strName2.$arrRingtype[$i];
  680. }
  681. $intKey2 = floor($intKey2 / 2);
  682. $strPrefix = $arrPrefix[$intKey2];
  683. $objRing2 = $db -> Execute('SELECT `level`, `cost`, `type` FROM `jeweller` WHERE `owner`='.$player -> id.' AND `name`=\''.$strName2.'\'');
  684. $intChance = floor(($intJeweller / 50) * 0.5) + 5;
  685. if ($intChance > 15)
  686. {
  687. $intChance = 15;
  688. }
  689. $intGainexp = 0;
  690. $intRoll = rand(1, 100);
  691. /**
  692. * Success
  693. */
  694. if ($intRoll <= $intChance)
  695. {
  696. $blnGod = false;
  697. $intRoll = rand(1, 100);
  698. if ($intRoll == 1)
  699. {
  700. $intRoll2 = rand(1, 2);
  701. if ($intRoll2 == 1)
  702. {
  703. $intGainexp = $objRing -> fields['n_energy'] * 500;
  704. $intAbility = $objRing -> fields['n_energy'] * 0.28;
  705. $blnGod = true;
  706. }
  707. }
  708. if ($intRoll <= $intChance && !$blnGod)
  709. {
  710. $intGainexp = $objRing -> fields['n_energy'] * 250;
  711. $intAbility = $objRing -> fields['n_energy'] * 0.14;
  712. }
  713. $intPower = (int)$objRing -> fields['bonus'];
  714. $intCost = ceil($objRing2 -> fields['cost'] / 10);
  715. $intAbility = $objRing -> fields['n_energy'] * 0.02;
  716. if ($blnGod)
  717. {
  718. $strName2 = R_GOD.$strName;
  719. $intPower = $intPower * 4;
  720. $objTest = $db -> Execute('SELECT `id` FROM `equipment` WHERE `owner`='.$player -> id.' AND `name`=\''.$strName2.'\' AND `status`=\'U\' AND `cost`='.$intCost.' AND `power`='.$intPower);
  721. if (!$objTest -> fields['id'])
  722. {
  723. $db -> Execute('INSERT INTO `equipment` (`owner`, `name`, `power`, `status`, `type`, `cost`, `minlev`, `amount`) VALUES('.$player -> id.', \''.$strName2.'\', \''.$intPower.'\', \'U\', \'I\', '.$intCost.', '.$intLevel.', '.$intGod.')');
  724. }
  725. else
  726. {
  727. $db -> Execute('UPDATE `equipment` SET `amount`=`amount`+'.$intGod.' WHERE `id`='.$player -> id);
  728. }
  729. $objTest -> Close();
  730. }
  731. else
  732. {
  733. $strName2 = $strPrefix.$strName;
  734. $intPower = $intPower * 2;
  735. $objTest = $db -> Execute('SELECT `id` FROM `equipment` WHERE `owner`='.$player -> id.' AND `name`=\''.$strName2.'\' AND `status`=\'U\' AND `cost`='.$intCost.' AND `power`='.$intPower);
  736. if (!$objTest -> fields['id'])
  737. {
  738. $db -> Execute('INSERT INTO `equipment` (`owner`, `name`, `power`, `status`, `type`, `cost`, `minlev`, `amount`) VALUES('.$player -> id.', \''.$strName2.'\', '.$intPower.', \'U\', \'I\', \''.$intCost.', '.$intLevel.', 1)');
  739. }
  740. else
  741. {
  742. $db -> Execute('UPDATE `equipment` SET `amount`=`amount`+'.$intSpecial.' WHERE `id`='.$player -> id);
  743. }
  744. $objTest -> Close();
  745. }
  746. $smarty -> assign('Message', YOU_MAKE.$strName.YOU_GAIN3.$intGainexp.AND_EXP2.$intAbility.IN_JEWELLER);
  747. }
  748. else
  749. {
  750. $intAbility = $objRing -> fields['n_energy'] * 0.01;
  751. $smarty -> assign('Message', YOU_TRY.$strName.BUT_FAIL.$intAbility.IN_JEWELLER);
  752. }
  753. checkexp($player -> exp, $intGainexp, $player -> level, $player -> race, $player -> user, $player -> id, 0, 0, $player -> id, 'jeweller', $intAbility);
  754. $objRing2 -> Close();
  755. $db -> Execute('DELETE FROM `jeweller_work` WHERE `id`='.$_POST['make']);
  756. }
  757. else
  758. {
  759. $db -> Execute('UPDATE `jeweller_work` SET `u_energy`='.$intEnergy.' WHERE `id`='.$_POST['make']);
  760. $smarty -> assign('Message', YOU_TRY.$objRing -> fields['name'].YOU_GAIN4);
  761. }
  762. $objRing -> Close();
  763. $db -> Execute('UPDATE `players` SET `energy`=`energy`-'.$_POST['amount'].' WHERE `id`='.$player -> id);
  764. }
  765. /**
  766. * Start create special rings
  767. */
  768. if (isset($_GET['action']) && $_GET['action'] == 'create')
  769. {
  770. if (!isset($_POST['rings']) || !ereg("^[1-9][0-9]*$", $_POST['rings']) || !ereg("^[0-9][0-9\.]*$", $_POST['amount']))
  771. {
  772. error(ERROR);
  773. }
  774. if ($objMaked -> fields['id'])
  775. {
  776. error(ERROR);
  777. }
  778. if ($player -> hp == 0)
  779. {
  780. error(YOU_DEAD);
  781. }
  782. $intKey = array_search($_POST['rings'], $arrRid);
  783. $intLevel = $arrRlevel[$intKey];
  784. $intMake = floor($_POST['amount'] / ($intLevel * 1.5));
  785. if (!$intMake)
  786. {
  787. $intMake = 1;
  788. }
  789. $intMeteor = ceil($intLevel / 2) * $intMake;
  790. $objMeteor = $db -> Execute('SELECT `meteor` FROM `minerals` WHERE `owner`='.$player -> id);
  791. if ($objMeteor -> fields['meteor'] < $intMeteor)
  792. {
  793. error(NO_METEOR);
  794. }
  795. $objMeteor -> Close();
  796. $intEnergys = $intLevel * 1.5;
  797. $intEnergy = $intEnergys * $intMake;
  798. if ($player -> energy < $intEnergy)
  799. {
  800. error(NO_ENERGY);
  801. }
  802. $intRamount = $arrRamount[$intKey];
  803. if ($intRamount < $intMake)
  804. {
  805. error(NO_RINGS);
  806. }
  807. /**
  808. * Select ring name
  809. */
  810. $arrRings = array(R_AGI, R_SPE, R_STR, R_CON, R_INT, R_WIS);
  811. $arrPrefix = array(R_ELF, R_DWARF, R_GNOME);
  812. $strName = $arrRname[$intKey];
  813. $arrRingtype = explode(" ", $strName);
  814. $intAmount2 = count($arrRingtype) - 1;
  815. $intKey2 = array_search($arrRingtype[$intAmount2], $arrRings);
  816. $intKey2 = floor($intKey2 / 2);
  817. $strPrefix = $arrPrefix[$intKey2];
  818. /**
  819. * Add bonuses to ability
  820. */
  821. require_once('includes/abilitybonus.php');
  822. $intJeweller = abilitybonus('jeweller');
  823. $intChance = floor(($intJeweller / 50) * 0.5) + 5;
  824. if ($intChance > 15)
  825. {
  826. $intChance = 15;
  827. }
  828. /**
  829. * Start create item
  830. */
  831. $intGod = 0;
  832. $intSpecial = 0;
  833. $intGainexp = 0;
  834. $intAbility = 0;
  835. for ($i = 0; $i < $intMake; $i++)
  836. {
  837. $intRoll = rand(1, 100);
  838. if ($intRoll == 1)
  839. {
  840. $intRoll2 = rand(1, 2);
  841. if ($intRoll2 == 1)
  842. {
  843. $intGod ++;
  844. $intGainexp = $intGainexp + ($intEnergys * 500);
  845. $intAbility = $intAbility + ($intEnergys * 0.28);
  846. continue;
  847. }
  848. }
  849. if ($intRoll <= $intChance)
  850. {
  851. $intSpecial ++;
  852. $intGainexp = $intGainexp + ($intEnergys * 250);
  853. $intAbility = $intAbility + ($intEnergys * 0.14);
  854. }
  855. else
  856. {
  857. $intAbility = $intAbility + 0.01 * $intEnergys;
  858. }
  859. }
  860. $intAbility = round($intAbility, 2);
  861. /**
  862. * Write to database and show info
  863. */
  864. if ($intMake)
  865. {
  866. $intCost = ceil($arrRcost[$intKey] / 10);
  867. $intPower = $arrRpower[$intKey];
  868. if ($intGod)
  869. {
  870. $strName2 = R_GOD.$strName;
  871. $intPower = $intPower * 4;
  872. $objTest = $db -> Execute('SELECT `id` FROM `equipment` WHERE `owner`='.$player -> id.' AND `name`=\''.$strName2.'\' AND `status`=\'U\' AND `cost`='.$intCost.' AND `power`='.$intPower);
  873. if (!$objTest -> fields['id'])
  874. {
  875. $db -> Execute('INSERT INTO `equipment` (`owner`, `name`, `power`, `status`, `type`, `cost`, `minlev`, `amount`) VALUES('.$player -> id.', \''.$strName2.'\', '.$intPower.', \'U\', \'I\', '.$intCost.', '.$intLevel.', '.$intGod.')');
  876. }
  877. else
  878. {
  879. $db -> Execute('UPDATE `equipment` SET `amount`=`amount`+'.$intGod.' WHERE `id`='.$player -> id);
  880. }
  881. $objTest -> Close();
  882. }
  883. $intPower = $arrRpower[$intKey];
  884. if ($intSpecial)
  885. {
  886. $strName2 = $strPrefix.$strName;
  887. $intPower *= 2;
  888. $objTest = $db -> Execute("SELECT `id` FROM `equipment` WHERE `owner`=".$player -> id." AND `name`='".$strName2."' AND `status`='U' AND `cost`=".$intCost." AND `power`=".$intPower);
  889. if (!$objTest -> fields['id'])
  890. {
  891. $db -> Execute("INSERT INTO `equipment` (`owner`, `name`, `power`, `status`, `type`, `cost`, `minlev`, `amount`) VALUES(".$player -> id.", '".$strName2."', '".$intPower."', 'U', 'I', '".$intCost."', '".$intLevel."', '".$intSpecial."')");
  892. }
  893. else
  894. {
  895. $db -> Execute("UPDATE `equipment` SET `amount`=`amount`+".$intSpecial." WHERE `id`=".$player -> id);
  896. }
  897. $objTest -> Close();
  898. }
  899. $intRings = $intGod + $intSpecial;
  900. $smarty -> assign('Message', '<br /><br />'.YOU_MAKE.$intRings.'</b> '.R_AMOUNT3.$strName.YOU_GAIN3.$intGainexp.AND_EXP2.$intAbility.IN_JEWELLER);
  901. }
  902. else
  903. {
  904. $intMeteor = ceil($intLevel / 2);
  905. $intGainexp = 0;
  906. $intEnergy2 = ($intLevel * 1.5);
  907. $intAbility = 0;
  908. $intEnergy = $_POST['amount'];
  909. $intMake = 1;
  910. $intPower = $arrRpower[$intKey];
  911. $db -> Execute('INSERT INTO `jeweller_work` (`owner`, `name`, `n_energy`, `u_energy`, `bonus`, `type`) VALUES('.$player -> id.', \''.$strName.'\', '.$intEnergy2.', '.$_POST['amount'].', '.$intPower.', \'S\')');
  912. $smarty -> assign('Message', YOU_TRY.$strName.YOU_GAIN4);
  913. }
  914. $db -> Execute('UPDATE `minerals` SET `meteor`=`meteor`-'.$intMeteor.' WHERE `owner`='.$player -> id);
  915. $db -> Execute('UPDATE `players` SET `energy`=`energy`-'.$intEnergy.' WHERE `id`='.$player -> id);
  916. checkexp($player -> exp, $intGainexp, $player -> level, $player -> race, $player -> user, $player -> id, 0, 0, $player -> id, 'jeweller', $intAbility);
  917. if ($intRamount == $intMake)
  918. {
  919. $db -> Execute('DELETE FROM `equipment` WHERE `id`='.$_POST['rings']);
  920. }
  921. else
  922. {
  923. $db -> Execute('UPDATE `equipment` SET `amount`=`amount`-'.$intMake.' WHERE `id`='.$_POST['rings']);
  924. }
  925. }
  926. }
  927. if (!isset($_GET['buy']))
  928. {
  929. $_GET['buy'] = '';
  930. }
  931. /**
  932. * Make astral constructions
  933. */
  934. if (isset($_GET['step']) && $_GET['step'] == 'astral')
  935. {
  936. if( !isset($_GET['component'] ))
  937. {
  938. makeastral3();
  939. }
  940. else
  941. {
  942. makeastral3($_GET['component']);
  943. }
  944. }
  945. /**
  946. * Assign variables to template and display page
  947. */
  948. $smarty -> assign(array('Step' => $_GET['step'], 'Buy' => $_GET['buy']));
  949. $smarty -> display('jeweller.tpl');
  950. require_once('includes/foot.php');
  951. ?>