PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/kopalnia.php

https://bitbucket.org/marecki/orodlin-v.1
PHP | 199 lines | 142 code | 13 blank | 44 comment | 45 complexity | 3f25722b2724b02594343ec9487a288e MD5 | raw file
  1. <?php
  2. /**
  3. * File functions:
  4. * Mines in moutains
  5. *
  6. * @name : kopalnia.php
  7. * @copyright : (C) 2004,2005,2006 Vallheru Team based on Gamers-Fusion ver 2.5
  8. * @author : thindil <thindil@users.sourceforge.net>
  9. * @author : Zamareth <zamareth@users.sourceforge.net>
  10. * @version : 1.3
  11. * @since : 19.09.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: kopalnia.php 760 2006-10-24 12:09:02Z thindil $
  31. $title = 'Kopalnia';
  32. require_once('includes/head.php');
  33. require_once('includes/checkexp.php');
  34. /**
  35. * Get the localization for game
  36. */
  37. require_once('languages/'.$player -> lang.'/kopalnia.php');
  38. if ($player -> location != 'Góry')
  39. {
  40. error(ERROR);
  41. }
  42. /**
  43. * Dig for minerals
  44. */
  45. if (isset($_GET['action']) && $_GET['action'] == 'dig')
  46. {
  47. if (!isset($_POST['amount']) || !preg_match("/^[1-9][0-9]*$/", $_POST['amount']))
  48. {
  49. error(ERROR);
  50. }
  51. integercheck($_POST['amount']);
  52. if ($player -> hp < 1)
  53. {
  54. error(YOU_DEAD." (<a href=\"gory.php\">".BACK."</a>)");
  55. }
  56. if ($player -> energy < $_POST['amount'])
  57. {
  58. error(NO_ENERGY." (<a href=\"gory.php\">".BACK."</a>)");
  59. }
  60. /**
  61. * Count bonus to ability
  62. */
  63. require_once('includes/abilitybonus.php');
  64. $fltAbility = abilitybonus('mining');
  65. $fltGainAbility = 0;
  66. $arrMinerals = array(0, 0);
  67. $arrGold = array(0, 0);
  68. $strInfo = '';
  69. $intGainExp = 0;
  70. $intLostHPSum = 0;
  71. for ($i = 0; $i < $_POST['amount']; $i++)
  72. {
  73. $intRoll = rand(1, 10);
  74. if ($intRoll > 4 && $intRoll < 10)
  75. {
  76. $fltGainAbility += 0.1;
  77. }
  78. if ($intRoll == 5)
  79. {
  80. $intAmount = max(1, ceil((rand(1, 20) * 1 / 8) * (1 + ($fltAbility + $fltGainAbility) / 20)));
  81. $intGainExp += ceil($player -> level / 3);
  82. $arrMinerals[0] += $intAmount; // crystal
  83. }
  84. if ($intRoll == 6)
  85. {
  86. $intAmount = max(1, ceil((rand(1, 20) * 1 / 5) * (1 + ($fltAbility + $fltGainAbility) / 20)));
  87. $intGainExp += ceil($player -> level / 3);
  88. $arrMinerals[1] += $intAmount; // adamantium
  89. }
  90. if ($intRoll == 7 || $intRoll == 8)
  91. {
  92. $intAmount = max(1, ceil((rand(1, 20) * 1 / 3) * (1 + ($fltAbility + $fltGainAbility) / 20)));
  93. $intGainExp += ceil($player -> level / 3);
  94. $arrGold[1] += $intAmount; // platinum
  95. }
  96. if ($intRoll == 9)
  97. {
  98. $intAmount = max(1, ceil(rand(50, 200) * (1 + ($fltAbility + $fltGainAbility) / 20)));
  99. $arrGold[0] += $intAmount; // gold
  100. }
  101. if ($intRoll == 10)
  102. {
  103. $intLostHP = rand(1, 100);
  104. if ($intLostHP < 51)
  105. {
  106. $intLostHPSum += $intLostHP;
  107. }
  108. if ($intLostHPSum > $player -> hp - 1)
  109. {
  110. $intLostHPSum = min($intLostHPSum, $player -> hp);
  111. $strInfo = '<br />'.DEAD_MAN.'. (<a href="gory.php">'.BACK.'</a>)';
  112. break;
  113. }
  114. }
  115. if ($intLostHPSum > 0 )
  116. {
  117. $strInfo = M_LOST_HP1.$intLostHPSum.M_LOST_HP2;
  118. }
  119. }
  120. $oldFetchMode = $db -> SetFetchMode(ADODB_FETCH_NUM);
  121. $arrBless = $db -> GetRow('SELECT `bless`, `blessval` FROM `players` WHERE `id`='.$player -> id);
  122. if (isset($arrBless) && $arrBless[0] == 'hp' && $intLostHPSum < $arrBless[1])
  123. {
  124. $intLostHPSum = $arrBless[1];
  125. }
  126. $intMinSum = array_sum($arrMinerals);
  127. $intGoldSum = array_sum($arrGold);
  128. if ($intMinSum)
  129. {
  130. $arrMinCheck = $db -> GetRow('SELECT `adamantium`, `crystal`, `owner` FROM `minerals` WHERE `owner`='.$player -> id);
  131. $db -> SetFetchMode($oldFetchMode);
  132. if (empty($arrMinCheck))
  133. {
  134. $db -> Execute('INSERT INTO `minerals` (`owner`, `crystal`, `adamantium`) VALUES('.$player -> id.', '.$arrMinerals[0].', '.$arrMinerals[1].')');
  135. }
  136. else
  137. {
  138. $db -> Execute('UPDATE `minerals` SET `crystal`=`crystal`+'.$arrMinerals[0].', `adamantium`=`adamantium`+'.$arrMinerals[1].' WHERE `owner`='.$player -> id);
  139. }
  140. }
  141. $strFind = YOU_GO.$i.T_AMOUNT2;
  142. if ($intGoldSum || $intMinSum)
  143. {
  144. $strFind = $strFind.YOU_FIND;
  145. if ($arrMinerals[0])
  146. {
  147. $strFind .= $arrMinerals[0].T_CRYSTALS;
  148. }
  149. if ($arrMinerals[1])
  150. {
  151. $strFind .= $arrMinerals[1].T_ADAMANTIUM;
  152. }
  153. if ($arrGold[1])
  154. {
  155. $strFind .= $arrGold[1].T_MITHRIL;
  156. }
  157. if ($arrGold[0])
  158. {
  159. $strFind .= T_GOLD.$arrGold[0].T_GOLD2;
  160. }
  161. $strFind .= $fltGainAbility.T_ABILITY.$intGainExp.T_GAIN_EXP;
  162. }
  163. if (!$fltGainAbility && $strInfo == '')
  164. {
  165. $strFind .= T_NOTHING;
  166. }
  167. $strFind .= $strInfo;
  168. $strBless = isset($arrBless) && $arrBless[0] == 'hp' ? ', `bless`=\'\', `blessval`=0' : '';
  169. $db -> Execute('UPDATE `players` SET `credits`=`credits`+'.$arrGold[0].', `platinum`=`platinum`+'.$arrGold[1].', `hp`=`hp`-'.$intLostHPSum.$strBless.', `energy`=`energy`-'.$i.' WHERE `id`='.$player -> id);
  170. $smarty -> assign('Youfind', $strFind);
  171. checkexp ($player -> exp, $intGainExp, $player -> level, $player -> race, $player -> user, $player -> id, 0, 0, $player -> id, 'mining', $fltGainAbility);
  172. }
  173. /**
  174. * Initialization of variables
  175. */
  176. if (!isset($_GET['action']))
  177. {
  178. $_GET['action'] = '';
  179. }
  180. /**
  181. * Assign variables to template and display page
  182. */
  183. $smarty -> assign('Health', isset($intLostHPSum) ? $player -> hp - $intLostHPSum : $player -> hp);
  184. $smarty -> display ('kopalnia.tpl');
  185. require_once('includes/foot.php');
  186. ?>