PageRenderTime 61ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 1ms

/src/2.10.5/upload/includes/pages/class.ShowInfosPage.php

https://github.com/SantiHarry/XG-Proyect-v2.10.x
PHP | 506 lines | 424 code | 55 blank | 27 comment | 78 complexity | a93e3e063ca9c231cf8b603097a2ca9c MD5 | raw file
  1. <?php
  2. /**
  3. * @project XG Proyect
  4. * @version 2.10.x build 0000
  5. * @copyright Copyright (C) 2008 - 2012
  6. */
  7. if(!defined('INSIDE')){ die(header("location:../../"));}
  8. class ShowInfosPage
  9. {
  10. private function GetNextJumpWaitTime($CurMoon)
  11. {
  12. global $resource;
  13. $JumpGateLevel = $CurMoon[$resource[43]];
  14. $LastJumpTime = $CurMoon['last_jump_time'];
  15. if ($JumpGateLevel > 0)
  16. {
  17. $WaitBetweenJmp = (60 * 60) * (1 / $JumpGateLevel);
  18. $NextJumpTime = $LastJumpTime + $WaitBetweenJmp;
  19. if ($NextJumpTime >= time())
  20. {
  21. $RestWait = $NextJumpTime - time();
  22. $RestString = " ". Format::pretty_time($RestWait);
  23. }
  24. else
  25. {
  26. $RestWait = 0;
  27. $RestString = "";
  28. }
  29. }
  30. else
  31. {
  32. $RestWait = 0;
  33. $RestString = "";
  34. }
  35. $RetValue['string'] = $RestString;
  36. $RetValue['value'] = $RestWait;
  37. return $RetValue;
  38. }
  39. private function DoFleetJump ($CurrentUser, $CurrentPlanet)
  40. {
  41. global $resource, $lang;
  42. if ($_POST)
  43. {
  44. $RestString = $this->GetNextJumpWaitTime ($CurrentPlanet);
  45. $NextJumpTime = $RestString['value'];
  46. $JumpTime = time();
  47. if ( $NextJumpTime == 0 )
  48. {
  49. $TargetPlanet = $_POST['jmpto'];
  50. $TargetGate = doquery ( "SELECT `id`, `sprungtor`, `last_jump_time` FROM {{table}} WHERE `id` = '". $TargetPlanet ."';", 'planets', true);
  51. if ($TargetGate['sprungtor'] > 0)
  52. {
  53. $RestString = $this->GetNextJumpWaitTime ( $TargetGate );
  54. $NextDestTime = $RestString['value'];
  55. if ( $NextDestTime == 0 )
  56. {
  57. $ShipArray = array();
  58. $SubQueryOri = "";
  59. $SubQueryDes = "";
  60. for ( $Ship = 200; $Ship < 300; $Ship++ )
  61. {
  62. $ShipLabel = "c". $Ship;
  63. $gemi_kontrol = $_POST[ $ShipLabel ];
  64. if (is_numeric($gemi_kontrol))
  65. {
  66. if ( $gemi_kontrol > $CurrentPlanet[ $resource[ $Ship ] ])
  67. {
  68. $ShipArray[ $Ship ] = $CurrentPlanet[ $resource[ $Ship ] ];
  69. }
  70. else
  71. {
  72. $ShipArray[ $Ship ] = $gemi_kontrol;
  73. }
  74. if ($ShipArray[ $Ship ] > 0)
  75. {
  76. $SubQueryOri .= "`". $resource[ $Ship ] ."` = `". $resource[ $Ship ] ."` - '". $ShipArray[ $Ship ] ."', ";
  77. $SubQueryDes .= "`". $resource[ $Ship ] ."` = `". $resource[ $Ship ] ."` + '". $ShipArray[ $Ship ] ."', ";
  78. }
  79. }
  80. }
  81. if ($SubQueryOri != "")
  82. {
  83. $QryUpdateOri = "UPDATE {{table}} SET ";
  84. $QryUpdateOri .= $SubQueryOri;
  85. $QryUpdateOri .= "`last_jump_time` = '". $JumpTime ."' ";
  86. $QryUpdateOri .= "WHERE ";
  87. $QryUpdateOri .= "`id` = '". $CurrentPlanet['id'] ."';";
  88. doquery ( $QryUpdateOri, 'planets');
  89. $QryUpdateDes = "UPDATE {{table}} SET ";
  90. $QryUpdateDes .= $SubQueryDes;
  91. $QryUpdateDes .= "`last_jump_time` = '". $JumpTime ."' ";
  92. $QryUpdateDes .= "WHERE ";
  93. $QryUpdateDes .= "`id` = '". $TargetGate['id'] ."';";
  94. doquery ( $QryUpdateDes, 'planets');
  95. $QryUpdateUsr = "UPDATE {{table}} SET ";
  96. $QryUpdateUsr .= "`current_planet` = '". $TargetGate['id'] ."' ";
  97. $QryUpdateUsr .= "WHERE ";
  98. $QryUpdateUsr .= "`id` = '". $CurrentUser['id'] ."';";
  99. doquery ( $QryUpdateUsr, 'users');
  100. $CurrentPlanet['last_jump_time'] = $JumpTime;
  101. $RestString = $this->GetNextJumpWaitTime ( $CurrentPlanet );
  102. $RetMessage = $lang['in_jump_gate_done'] . $RestString['string'];
  103. }
  104. else
  105. {
  106. $RetMessage = $lang['in_jump_gate_error_data'];
  107. }
  108. }
  109. else
  110. {
  111. $RetMessage = $lang['in_jump_gate_not_ready_target'] . $RestString['string'];
  112. }
  113. }
  114. else
  115. {
  116. $RetMessage = $lang['in_jump_gate_doesnt_have_one'];
  117. }
  118. }
  119. else
  120. {
  121. $RetMessage = $lang['in_jump_gate_already_used'] . $RestString['string'];
  122. }
  123. }
  124. else
  125. {
  126. $RetMessage = $lang['in_jump_gate_error_data'];
  127. }
  128. return $RetMessage;
  129. }
  130. private function BuildFleetListRows ($CurrentPlanet)
  131. {
  132. global $resource, $lang;
  133. $RowsTPL = gettemplate('infos/info_gate_rows');
  134. $CurrIdx = 1;
  135. $Result = "";
  136. for ($Ship = 200; $Ship < 250; $Ship++ )
  137. {
  138. if ($resource[$Ship] != "")
  139. {
  140. if ($CurrentPlanet[$resource[$Ship]] > 0)
  141. {
  142. $bloc['idx'] = $CurrIdx;
  143. $bloc['fleet_id'] = $Ship;
  144. $bloc['fleet_name'] = $lang['tech'][$Ship];
  145. $bloc['fleet_max'] = Format::pretty_number ( $CurrentPlanet[$resource[$Ship]] );
  146. $bloc['gate_ship_dispo'] = $lang['in_jump_gate_available'];
  147. $Result .= parsetemplate ( $RowsTPL, $bloc );
  148. $CurrIdx++;
  149. }
  150. }
  151. }
  152. return $Result;
  153. }
  154. private function BuildJumpableMoonCombo ( $CurrentUser, $CurrentPlanet )
  155. {
  156. global $resource;
  157. $QrySelectMoons = "SELECT * FROM {{table}} WHERE `planet_type` = '3' AND `id_owner` = '". intval($CurrentUser['id']) ."';";
  158. $MoonList = doquery ( $QrySelectMoons, 'planets');
  159. $Combo = "";
  160. while ( $CurMoon = mysql_fetch_assoc($MoonList) )
  161. {
  162. if ( $CurMoon['id'] != $CurrentPlanet['id'] )
  163. {
  164. $RestString = $this->GetNextJumpWaitTime ( $CurMoon );
  165. if ($CurMoon[$resource[43]] >= 1)
  166. $Combo .= "<option value=\"". $CurMoon['id'] ."\">[". $CurMoon['galaxy'] .":". $CurMoon['system'] .":". $CurMoon['planet'] ."] ". $CurMoon['name'] . $RestString['string'] ."</option>\n";
  167. }
  168. }
  169. return $Combo;
  170. }
  171. private function ShowProductionTable ($CurrentUser, $CurrentPlanet, $BuildID, $Template)
  172. {
  173. global $ProdGrid, $resource;
  174. $BuildLevelFactor = $CurrentPlanet[ $resource[$BuildID]."_porcent" ];
  175. $BuildTemp = $CurrentPlanet[ 'temp_max' ];
  176. $CurrentBuildtLvl = $CurrentPlanet[ $resource[$BuildID] ];
  177. $BuildLevel = ($CurrentBuildtLvl > 0) ? $CurrentBuildtLvl : 1;
  178. $EnergyLevel = $CurrentUser["energy_tech"];
  179. // BOOST
  180. $geologe_boost = 1 + ( $CurrentUser['rpg_geologue'] * GEOLOGUE );
  181. $engineer_boost = 1 + ( $CurrentUser['rpg_ingenieur'] * ENGINEER_ENERGY );
  182. // PRODUCTION FORMULAS
  183. $metal_prod = eval ( $ProdGrid[$BuildID]['formule']['metal'] );
  184. $crystal_prod = eval ( $ProdGrid[$BuildID]['formule']['crystal'] );
  185. $deuterium_prod = eval ( $ProdGrid[$BuildID]['formule']['deuterium'] );
  186. $energy_prod = eval ( $ProdGrid[$BuildID]['formule']['energy'] );
  187. // PRODUCTION
  188. $Prod[1] = Production::production_amount ( $metal_prod , $geologe_boost );
  189. $Prod[2] = Production::production_amount ( $crystal_prod , $geologe_boost );
  190. $Prod[3] = Production::production_amount ( $deuterium_prod , $geologe_boost );
  191. if( $BuildID >= 4 )
  192. {
  193. $Prod[4] = Production::production_amount ( $energy_prod , $engineer_boost );
  194. $ActualProd = floor ( $Prod[4] );
  195. }
  196. else
  197. {
  198. $Prod[4] = Production::production_amount ( $energy_prod , 1 );
  199. $ActualProd = floor ( $Prod[$BuildID] );
  200. }
  201. if ( $BuildID != 12 )
  202. {
  203. $ActualNeed = floor ( $Prod[4] );
  204. }
  205. else
  206. {
  207. $ActualNeed = floor ( $Prod[3] );
  208. }
  209. $BuildStartLvl = $CurrentBuildtLvl - 2;
  210. if ($BuildStartLvl < 1)
  211. $BuildStartLvl = 1;
  212. $Table = "";
  213. $ProdFirst = 0;
  214. for ( $BuildLevel = $BuildStartLvl; $BuildLevel < $BuildStartLvl + 15; $BuildLevel++ )
  215. {
  216. if ( $BuildID != 42 )
  217. {
  218. // PRODUCTION FORMULAS
  219. $metal_prod = eval ( $ProdGrid[$BuildID]['formule']['metal'] );
  220. $crystal_prod = eval ( $ProdGrid[$BuildID]['formule']['crystal'] );
  221. $deuterium_prod = eval ( $ProdGrid[$BuildID]['formule']['deuterium'] );
  222. $energy_prod = eval ( $ProdGrid[$BuildID]['formule']['energy'] );
  223. // PRODUCTION
  224. $Prod[1] = Production::production_amount ( $metal_prod , $geologe_boost );
  225. $Prod[2] = Production::production_amount ( $crystal_prod , $geologe_boost );
  226. $Prod[3] = Production::production_amount ( $deuterium_prod , $geologe_boost );
  227. if( $BuildID >= 4 )
  228. {
  229. $Prod[4] = Production::production_amount ( $energy_prod , $engineer_boost );
  230. }
  231. else
  232. {
  233. $Prod[4] = Production::production_amount ( $energy_prod , 1 );
  234. }
  235. $bloc['build_lvl'] = ($CurrentBuildtLvl == $BuildLevel) ? "<font color=\"#ff0000\">".$BuildLevel."</font>" : $BuildLevel;
  236. if ($ProdFirst > 0)
  237. if ($BuildID != 12)
  238. $bloc['build_gain'] = "<font color=\"lime\">(". Format::pretty_number(floor($Prod[$BuildID] - $ProdFirst)) .")</font>";
  239. else
  240. $bloc['build_gain'] = "<font color=\"lime\">(". Format::pretty_number(floor($Prod[4] - $ProdFirst)) .")</font>";
  241. else
  242. $bloc['build_gain'] = "";
  243. if ($BuildID != 12)
  244. {
  245. $bloc['build_prod'] = Format::pretty_number(floor($Prod[$BuildID]));
  246. $bloc['build_prod_diff'] = Format::color_number( Format::pretty_number(floor($Prod[$BuildID] - $ActualProd)) );
  247. $bloc['build_need'] = Format::color_number( Format::pretty_number(floor($Prod[4])) );
  248. $bloc['build_need_diff'] = Format::color_number( Format::pretty_number(floor($Prod[4] - $ActualNeed)) );
  249. }
  250. else
  251. {
  252. $bloc['build_prod'] = Format::pretty_number(floor($Prod[4]));
  253. $bloc['build_prod_diff'] = Format::color_number( Format::pretty_number(floor($Prod[4] - $ActualProd)) );
  254. $bloc['build_need'] = Format::color_number( Format::pretty_number(floor($Prod[3])) );
  255. $bloc['build_need_diff'] = Format::color_number( Format::pretty_number(floor($Prod[3] - $ActualNeed)) );
  256. }
  257. if ($ProdFirst == 0)
  258. {
  259. if ($BuildID != 12)
  260. $ProdFirst = floor($Prod[$BuildID]);
  261. else
  262. $ProdFirst = floor($Prod[4]);
  263. }
  264. }
  265. else
  266. {
  267. $bloc['build_lvl'] = ($CurrentBuildtLvl == $BuildLevel) ? "<font color=\"#ff0000\">".$BuildLevel."</font>" : $BuildLevel;
  268. $bloc['build_range'] = ($BuildLevel * $BuildLevel) - 1;
  269. }
  270. $Table .= parsetemplate($Template, $bloc);
  271. }
  272. return $Table;
  273. }
  274. private function ShowRapidFireTo ($BuildID)
  275. {
  276. global $lang, $CombatCaps;
  277. $ResultString = "";
  278. for ($Type = 200; $Type < 500; $Type++)
  279. {
  280. if ($CombatCaps[$BuildID]['sd'][$Type] > 1)
  281. $ResultString .= $lang['in_rf_again']. " ". $lang['tech'][$Type] ." <font color=\"#00ff00\">".$CombatCaps[$BuildID]['sd'][$Type]."</font><br>";
  282. }
  283. return $ResultString;
  284. }
  285. private function ShowRapidFireFrom ($BuildID)
  286. {
  287. global $lang, $CombatCaps;
  288. $ResultString = "";
  289. for ($Type = 200; $Type < 500; $Type++)
  290. {
  291. if ($CombatCaps[$Type]['sd'][$BuildID] > 1)
  292. $ResultString .= $lang['in_rf_from']. " ". $lang['tech'][$Type] ." <font color=\"#ff0000\">".$CombatCaps[$Type]['sd'][$BuildID]."</font><br>";
  293. }
  294. return $ResultString;
  295. }
  296. public function __construct ($CurrentUser, $CurrentPlanet, $BuildID)
  297. {
  298. global $lang, $resource, $pricelist, $CombatCaps;
  299. if ( !array_key_exists ( $BuildID , $resource ) )
  300. {
  301. die ( header ( 'Location: game.php?page=techtree' ) );
  302. }
  303. $GateTPL = '';
  304. $DestroyTPL = '';
  305. $TableHeadTPL = '';
  306. $parse = $lang;
  307. $parse['dpath'] = DPATH;
  308. $parse['name'] = $lang['info'][$BuildID]['name'];
  309. $parse['image'] = $BuildID;
  310. $parse['description'] = $lang['info'][$BuildID]['description'];
  311. if ($BuildID < 13 OR ($BuildID == 43 && $CurrentPlanet[$resource[43]] > 0))
  312. $PageTPL = gettemplate('infos/info_buildings_table');
  313. elseif($BuildID < 200)
  314. $PageTPL = gettemplate('infos/info_buildings_general');
  315. elseif($BuildID < 400)
  316. $PageTPL = gettemplate('infos/info_buildings_fleet');
  317. elseif($BuildID < 600)
  318. $PageTPL = gettemplate('infos/info_buildings_defense');
  319. else
  320. $PageTPL = gettemplate('infos/info_officiers_general');
  321. //Sólo hay destroy en <200
  322. if($BuildID < 200 AND $BuildID != 33 AND $BuildID != 41)
  323. $DestroyTPL = gettemplate('infos/info_buildings_destroy');
  324. if ($BuildID >= 1 && $BuildID <= 3)
  325. {
  326. $PageTPL = gettemplate('infos/info_buildings_table');
  327. $TableHeadTPL = gettemplate('infos/info_production_header');
  328. $TableTPL = gettemplate('infos/info_production_body');
  329. }
  330. elseif ($BuildID == 4)
  331. {
  332. $PageTPL = gettemplate('infos/info_buildings_table');
  333. $TableHeadTPL = gettemplate('infos/info_production_simple_header');
  334. $TableTPL = gettemplate('infos/info_production_simple_body');
  335. }
  336. elseif ($BuildID == 12)
  337. {
  338. $TableHeadTPL = gettemplate('infos/info_energy_header');
  339. $TableTPL = gettemplate('infos/info_energy_body');
  340. }
  341. /*elseif ($BuildID >= 14 AND $BuildID <= 100 AND $BuildID != 42 AND $BuildID != 41 AND $BuildID != 33 AND $BuildID != 43)
  342. {
  343. No hacemos NADA
  344. }*/
  345. /*elseif ($BuildID == 33)
  346. {
  347. $PageTPL = gettemplate('infos/info_buildings_general');
  348. }
  349. elseif ($BuildID == 41)
  350. {
  351. $PageTPL = gettemplate('infos/info_buildings_general');
  352. }*/
  353. elseif ($BuildID == 42)
  354. {
  355. $TableHeadTPL = gettemplate('infos/info_range_header');
  356. $TableTPL = gettemplate('infos/info_range_body');
  357. }
  358. elseif ($BuildID == 43)
  359. {
  360. $GateTPL = gettemplate('infos/info_gate_table');
  361. if($_POST)
  362. message($this->DoFleetJump($CurrentUser, $CurrentPlanet), "game.php?page=infos&gid=43", 2);
  363. }
  364. /*elseif ($BuildID >= 106 && $BuildID <= 199)
  365. {
  366. NADA! -- $PageTPL = gettemplate('infos/info_buildings_general');
  367. }*/
  368. elseif ($BuildID >= 202 && $BuildID <= 250)
  369. {
  370. $PageTPL = gettemplate('infos/info_buildings_fleet');
  371. $parse['element_typ'] = $lang['tech'][200];
  372. $parse['rf_info_to'] = $this->ShowRapidFireTo($BuildID);
  373. $parse['rf_info_fr'] = $this->ShowRapidFireFrom($BuildID);
  374. $parse['hull_pt'] = Format::pretty_number ($pricelist[$BuildID]['metal'] + $pricelist[$BuildID]['crystal']);
  375. $parse['shield_pt'] = Format::pretty_number ($CombatCaps[$BuildID]['shield']);
  376. $parse['attack_pt'] = Format::pretty_number ($CombatCaps[$BuildID]['attack']);
  377. $parse['capacity_pt'] = Format::pretty_number ($pricelist[$BuildID]['capacity']);
  378. $parse['base_speed'] = Format::pretty_number ($pricelist[$BuildID]['speed']);
  379. $parse['base_conso'] = Format::pretty_number ($pricelist[$BuildID]['consumption']);
  380. if ($BuildID == 202)
  381. {
  382. $parse['upd_speed'] = "<font color=\"yellow\">(". Format::pretty_number ($pricelist[$BuildID]['speed2']) .")</font>";
  383. $parse['upd_conso'] = "<font color=\"yellow\">(". Format::pretty_number ($pricelist[$BuildID]['consumption2']) .")</font>";
  384. }
  385. elseif ($BuildID == 211)
  386. $parse['upd_speed'] = "<font color=\"yellow\">(". Format::pretty_number ($pricelist[$BuildID]['speed2']) .")</font>";
  387. }
  388. elseif ( $BuildID >= 401 && $BuildID <= 550 )
  389. {
  390. $PageTPL = gettemplate('infos/info_buildings_defense');
  391. $parse['element_typ'] = $lang['tech'][400];
  392. if ( $BuildID < 500 )
  393. {
  394. $parse['rf_info_to'] = $this->ShowRapidFireTo ($BuildID);
  395. $parse['rf_info_fr'] = $this->ShowRapidFireFrom ($BuildID);
  396. }
  397. $parse['hull_pt'] = Format::pretty_number ($pricelist[$BuildID]['metal'] + $pricelist[$BuildID]['crystal']);
  398. $parse['shield_pt'] = Format::pretty_number ($CombatCaps[$BuildID]['shield']);
  399. $parse['attack_pt'] = Format::pretty_number ($CombatCaps[$BuildID]['attack']);
  400. }
  401. if ($TableHeadTPL != '')
  402. {
  403. $parse['table_head'] = parsetemplate ($TableHeadTPL, $lang);
  404. $parse['table_data'] = $this->ShowProductionTable ($CurrentUser, $CurrentPlanet, $BuildID, $TableTPL);
  405. }
  406. $page = parsetemplate($PageTPL, $parse);
  407. if ($GateTPL != '')
  408. {
  409. if ($CurrentPlanet[$resource[$BuildID]] > 0)
  410. {
  411. $RestString = $this->GetNextJumpWaitTime ( $CurrentPlanet );
  412. $parse['gate_start_link'] = BuildPlanetAdressLink ( $CurrentPlanet );
  413. if ($RestString['value'] != 0)
  414. {
  415. include(XGP_ROOT . 'includes/functions/InsertJavaScriptChronoApplet.php');
  416. $parse['gate_time_script'] = InsertJavaScriptChronoApplet ( "Gate", "1", $RestString['value'], TRUE );
  417. $parse['gate_wait_time'] = "<div id=\"bxx". "Gate" . "1" ."\"></div>";
  418. $parse['gate_script_go'] = InsertJavaScriptChronoApplet ( "Gate", "1", $RestString['value'], FALSE );
  419. }
  420. else
  421. {
  422. $parse['gate_time_script'] = "";
  423. $parse['gate_wait_time'] = "";
  424. $parse['gate_script_go'] = "";
  425. }
  426. $parse['gate_dest_moons'] = $this->BuildJumpableMoonCombo ($CurrentUser, $CurrentPlanet);
  427. $parse['gate_fleet_rows'] = $this->BuildFleetListRows ($CurrentPlanet);
  428. $page .= parsetemplate($GateTPL, $parse);
  429. }
  430. }
  431. if ($DestroyTPL != '')
  432. {
  433. if ($CurrentPlanet[$resource[$BuildID]] > 0)
  434. {
  435. $NeededRessources = GetBuildingPrice ($CurrentUser, $CurrentPlanet, $BuildID, TRUE, TRUE);
  436. $DestroyTime = GetBuildingTime ($CurrentUser, $CurrentPlanet, $BuildID) / 2;
  437. $parse['destroyurl'] = "game.php?page=buildings&cmd=destroy&building=".$BuildID;
  438. $parse['levelvalue'] = $CurrentPlanet[$resource[$BuildID]];
  439. $parse['nfo_metal'] = $lang['Metal'];
  440. $parse['nfo_crysta'] = $lang['Crystal'];
  441. $parse['nfo_deuter'] = $lang['Deuterium'];
  442. $parse['metal'] = Format::pretty_number ($NeededRessources['metal']);
  443. $parse['crystal'] = Format::pretty_number ($NeededRessources['crystal']);
  444. $parse['deuterium'] = Format::pretty_number ($NeededRessources['deuterium']);
  445. $parse['destroytime'] = Format::pretty_time ($DestroyTime);
  446. $page .= parsetemplate($DestroyTPL, $parse);
  447. }
  448. }
  449. display($page);
  450. }
  451. }