PageRenderTime 39ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/game-core/src/dilizium.php

https://github.com/Biggerskimo/WOT-Game
PHP | 208 lines | 146 code | 27 blank | 35 comment | 31 complexity | 75aea545f544932a174e43d5ccc8909d MD5 | raw file
  1. <?php
  2. /*
  3. This file is part of WOT Game.
  4. WOT Game is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU Affero General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. WOT Game is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with WOT Game. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. define('INSIDE', true);
  16. $ugamela_root_path = './';
  17. include($ugamela_root_path . 'extension.inc');
  18. include($ugamela_root_path . 'common.'.$phpEx);
  19. if(!check_user()){ header("Location: login.php"); die();}
  20. //
  21. // Esta funcion permite cambiar el planeta actual.
  22. //
  23. include($ugamela_root_path . 'includes/planet_toggle.'.$phpEx);
  24. $dpath = (!$user["dpath"]) ? DEFAULT_SKINPATH : $user["dpath"];
  25. if(!defined('BUILDLIST')) define('BUILDLIST', 50);
  26. if(!defined('MESSAGEFOLDERS')) define('MESSAGEFOLDERS', 40);
  27. if(!defined('IMPERIUM')) define('IMPERIUM', 20);
  28. if(!defined('GALAXY_SCANS')) define('GALAXY_SCANS', 30);
  29. if(!defined('NO_ADS')) define('NO_ADS', 55);
  30. $features = unserialize($user['diliziumFeatures']);
  31. if($_POST) {
  32. //$dilizium = $user['dilizium'];
  33. //$features = unserialize($user['diliziumFeatures']);
  34. // build list
  35. $buildListDays = abs(intval($_POST['buildList']));
  36. $buildListCosts = $buildListDays * BUILDLIST;
  37. if($buildListCosts > $user['dilizium']) $buildListDays = floor($user['dilizium'] / BUILDLIST);
  38. $buildListCosts = $buildListDays * BUILDLIST;
  39. $user['lostDilizium'] += $buildListCosts;
  40. $user['dilizium'] -= $buildListCosts;
  41. if($features['buildList'] < time()) $features['buildList'] = (time() + $buildListDays * 24 * 60 * 60);
  42. else $features['buildList'] += $buildListDays * 24 * 60 * 60;
  43. // message folders
  44. $messageFoldersDays = abs(intval($_POST['messageFolders']));
  45. $messageFoldersCosts = $messageFoldersDays * MESSAGEFOLDERS;
  46. if($messageFoldersCosts > $user['dilizium']) $messageFoldersDays = floor($user['dilizium'] / MESSAGEFOLDERS);
  47. $messageFoldersCosts = $messageFoldersDays * MESSAGEFOLDERS;
  48. $user['lostDilizium'] += $messageFoldersCosts;
  49. $user['dilizium'] -= $messageFoldersCosts;
  50. if($features['messageFolders'] < time()) $features['messageFolders'] = (time() + $messageFoldersDays * 24 * 60 * 60);
  51. else $features['messageFolders'] += $messageFoldersDays * 24 * 60 * 60;
  52. // imperium
  53. $imperiumDays = abs(intval($_POST['imperium']));
  54. $imperiumCosts = $imperiumDays * IMPERIUM;
  55. if($imperiumCosts > $user['dilizium']) $imperiumDays = floor($user['dilizium'] / IMPERIUM);
  56. $imperiumCosts = $imperiumDays * IMPERIUM;
  57. $user['lostDilizium'] += $imperiumCosts;
  58. $user['dilizium'] -= $imperiumCosts;
  59. if($features['imperium'] < time()) $features['imperium'] = (time() + $imperiumDays * 24 * 60 * 60);
  60. else $features['imperium'] += $imperiumDays * 24 * 60 * 60;
  61. if($imperiumDays) {
  62. $page .= '<script type="text/javascript">parent["LeftMenu"].location.reload();</script>';
  63. }
  64. // scans in galaxy
  65. $galaxyScansDays = abs(intval($_POST['galaxyScans']));
  66. $galaxyScansCosts = $galaxyScansDays * GALAXY_SCANS;
  67. if($galaxyScansCosts > $user['dilizium']) $galaxyScansDays = floor($user['dilizium'] / GALAXY_SCANS);
  68. $galaxyScansCosts = $galaxyScansDays * GALAXY_SCANS;
  69. $user['lostDilizium'] += $galaxyScansCosts;
  70. $user['dilizium'] -= $galaxyScansCosts;
  71. if($features['galaxyScans'] < time()) $features['galaxyScans'] = (time() + $galaxyScansDays * 24 * 60 * 60);
  72. else $features['galaxyScans'] += $galaxyScansDays * 24 * 60 * 60;
  73. // no ads
  74. $noAdsDays = abs(intval($_POST['noAds']));
  75. $noAdsCosts = $noAdsDays * NO_ADS;
  76. if($noAdsCosts > $user['dilizium']) $noAdsDays = floor($user['dilizium'] / NO_ADS);
  77. $noAdsCosts = $noAdsDays * NO_ADS;
  78. $user['lostDilizium'] += $noAdsCosts;
  79. $user['dilizium'] -= $noAdsCosts;
  80. if($features['noAds'] < time()) $features['noAds'] = (time() + $noAdsDays * 24 * 60 * 60);
  81. else $features['noAds'] += $noAdsDays * 24 * 60 * 60;
  82. // save
  83. $user['diliziumFeatures'] = serialize($features);
  84. $sql = "UPDATE ugml".LW_N."_users
  85. SET diliziumFeatures = '".$user['diliziumFeatures']."',
  86. lostDilizium = '".$user['lostDilizium']."'
  87. WHERE id = '".$user['id']."'";
  88. WCF::getDB()->registerShutdownUpdate($sql);
  89. WCF::getSession()->setUpdate(true);
  90. }
  91. $page .= '<script type="text/javascript">
  92. var costsM = 0;
  93. function calculateCosts(container) {
  94. var old = document.getElementById(container + "C").firstChild.data;
  95. var days = document.getElementById(container + "V").value;
  96. if(days < 0) {
  97. document.getElementById(container + "V").value = 0;
  98. days = 0;
  99. }
  100. var costsPerDay = document.getElementById(container + "D").firstChild.data;
  101. var costs = days * costsPerDay;
  102. document.getElementById(container + "C").firstChild.data = costs;
  103. var diff = costs - old;
  104. costsM += diff;
  105. document.getElementById("costs").firstChild.data = costsM;
  106. if(costsM > document.getElementById("dilizium").firstChild.data) document.getElementById("costs").style.color = "red";
  107. else document.getElementById("costs").style.color = "";
  108. }
  109. </script>';
  110. $page .= '<form name="dilizium" action="dilizium.php" method="post">';
  111. $page .= '<table width="470">';
  112. $page .= '<tr>';
  113. $page .= '<td class="c" colspan="4">Infos</td>';
  114. $page .= '</tr>';
  115. $page .= '<tr>';
  116. $page .= '<td class="l" colspan="2">Aktueller Dilizium-Vorrat:</td>';
  117. $page .= '<td class="l" colspan="2"><span id="dilizium">'.$user['dilizium'].'</span></td>';
  118. $page .= '</tr>';
  119. $page .= '<tr>';
  120. $page .= '<td class="l" colspan="2">Dein Werbe-Link:</td>';
  121. $page .= '<td class="l" colspan="2"><input name="linktext" type="text" style="width: 96%;" value="http://lost-worlds.net/ref.php?u='.WCF::getUser()->userID.'" onClick="this.form.linktext.select(); this.form.linktext.focus();" /></td>';
  122. $page .= '</tr>';
  123. $page .= '<tr>';
  124. $page .= '<td class="c" colspan="4">Verwenden</td>';
  125. $page .= '</tr>';
  126. $page .= '<tr>';
  127. $page .= '<td class="c">Zweck</td>';
  128. $page .= '<td class="c">Kosten/Tag</td>';
  129. $page .= '<td class="c">Tage</td>';
  130. $page .= '<td class="c">Effektive Kosten</td>';
  131. $page .= '</tr>';
  132. $page .= '<tr>';
  133. if($features['buildList'] > time()) $page .= '<td class="l"><span title="Noch ca. '.round(($features['buildList'] - time()) / (24 * 60 * 60)).' Tag(e) aktiviert">Bauliste</span></td>';
  134. else $page .= '<td class="l"><span title="Nicht aktiviert">Bauliste</span></td>';
  135. $page .= '<td class="l"><span id="buildListD">'.BUILDLIST.'</span></td>';
  136. $page .= '<td class="l"><input id="buildListV" name="buildList" type="text" size="3" maxlength="2" onKeyUp="calculateCosts(\'buildList\');" /></td>';
  137. $page .= '<td class="l"><span id="buildListC">0</span></td>';
  138. $page .= '</tr>';
  139. $page .= '<tr>';
  140. if($features['messageFolders'] > time()) $page .= '<td class="l"><span title="Noch ca. '.round(($features['messageFolders'] - time()) / (24 * 60 * 60)).' Tag(e) aktiviert">Nachrichten-Ordner</span></td>';
  141. else $page .= '<td class="l"><span title="Nicht aktiviert">Nachrichten-Ordner</span></td>';
  142. $page .= '<td class="l"><span id="messageFoldersD">'.MESSAGEFOLDERS.'</span></td>';
  143. $page .= '<td class="l"><input id="messageFoldersV" name="messageFolders" type="text" size="3" maxlength="2" onKeyUp="calculateCosts(\'messageFolders\');" /></td>';
  144. $page .= '<td class="l"><span id="messageFoldersC">0</span></td>';
  145. $page .= '</tr>';
  146. $page .= '<tr>';
  147. if($features['imperium'] > time()) $page .= '<td class="l"><span title="Noch ca. '.round(($features['imperium'] - time()) / (24 * 60 * 60)).' Tag(e) aktiviert">Imperiums-Ansicht</span></td>';
  148. else $page .= '<td class="l"><span title="Nicht aktiviert">Imperiums-Ansicht</span></td>';
  149. $page .= '<td class="l"><span id="imperiumD">'.IMPERIUM.'</span></td>';
  150. $page .= '<td class="l"><input id="imperiumV" name="imperium" type="text" size="3" maxlength="2" onKeyUp="calculateCosts(\'imperium\');" /></td>';
  151. $page .= '<td class="l"><span id="imperiumC">0</span></td>';
  152. $page .= '</tr>';
  153. $page .= '<tr>';
  154. if($features['galaxyScans'] > time()) $page .= '<td class="l"><span title="Noch ca. '.round(($features['galaxyScans'] - time()) / (24 * 60 * 60)).' Tag(e) aktiviert">Spionageberichte in Galaxie-Ansicht</span></td>';
  155. else $page .= '<td class="l"><span title="Nicht aktiviert">Spionageberichte in Galaxie-Ansicht</span></td>';
  156. $page .= '<td class="l"><span id="galaxyScansD">'.GALAXY_SCANS.'</span></td>';
  157. $page .= '<td class="l"><input id="galaxyScansV" name="galaxyScans" type="text" size="3" maxlength="2" onKeyUp="calculateCosts(\'galaxyScans\');" /></td>';
  158. $page .= '<td class="l"><span id="galaxyScansC">0</span></td>';
  159. $page .= '</tr>';
  160. /*
  161. $page .= '<tr>';
  162. if($features['noAds'] > time()) $page .= '<td class="l"><span title="Noch ca. '.round(($features['noAds'] - time()) / (24 * 60 * 60)).' Tag(e) aktiviert">Werbefreiheit</span></td>';
  163. else $page .= '<td class="l"><span title="Nicht aktiviert">Werbefreiheit</span></td>';
  164. $page .= '<td class="l"><span id="noAdsD">'.NO_ADS.'</span></td>';
  165. $page .= '<td class="l"><input id="noAdsV" name="noAds" type="text" size="3" maxlength="2" onKeyUp="calculateCosts(\'noAds\');" /></td>';
  166. $page .= '<td class="l"><span id="noAdsC">0</span></td>';
  167. $page .= '</tr>';*/
  168. $page .= '<tr>';
  169. $page .= '<td class="l" colspan="3">Gesamt</td>';
  170. $page .= '<td class="l"><span id="costs">0</span></td>';
  171. $page .= '</tr>';
  172. $page .= '<tr>';
  173. $page .= '<th colspan="4"><input type="submit" value="Absenden" /></th>';
  174. $page .= '</tr>';
  175. $page .= '</table>';
  176. $page .= '</form>';
  177. display($page);
  178. ?>