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

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

https://github.com/SantiHarry/XG-Proyect-v2.10.x
PHP | 503 lines | 424 code | 52 blank | 27 comment | 78 complexity | 072f390cf131b81cf4353ad88f348681 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. // BOOST
  179. $geologe_boost = 1 + ( $CurrentUser['rpg_geologue'] * GEOLOGUE );
  180. $engineer_boost = 1 + ( $CurrentUser['rpg_ingenieur'] * ENGINEER_ENERGY );
  181. // PRODUCTION FORMULAS
  182. $metal_prod = eval ( $ProdGrid[$BuildID]['formule']['metal'] );
  183. $crystal_prod = eval ( $ProdGrid[$BuildID]['formule']['crystal'] );
  184. $deuterium_prod = eval ( $ProdGrid[$BuildID]['formule']['deuterium'] );
  185. $energy_prod = eval ( $ProdGrid[$BuildID]['formule']['energy'] );
  186. // PRODUCTION
  187. $Prod[1] = Production::production_amount ( $metal_prod , $geologe_boost );
  188. $Prod[2] = Production::production_amount ( $crystal_prod , $geologe_boost );
  189. $Prod[3] = Production::production_amount ( $deuterium_prod , $geologe_boost );
  190. if( $BuildID >= 4 )
  191. {
  192. $Prod[4] = Production::production_amount ( $energy_prod , $engineer_boost );
  193. $ActualProd = floor ( $Prod[4] );
  194. }
  195. else
  196. {
  197. $Prod[4] = Production::production_amount ( $energy_prod , 1 );
  198. $ActualProd = floor ( $Prod[$BuildID] );
  199. }
  200. if ( $BuildID != 12 )
  201. {
  202. $ActualNeed = floor ( $Prod[4] );
  203. }
  204. else
  205. {
  206. $ActualNeed = floor ( $Prod[3] );
  207. }
  208. $BuildStartLvl = $CurrentBuildtLvl - 2;
  209. if ($BuildStartLvl < 1)
  210. $BuildStartLvl = 1;
  211. $Table = "";
  212. $ProdFirst = 0;
  213. for ( $BuildLevel = $BuildStartLvl; $BuildLevel < $BuildStartLvl + 15; $BuildLevel++ )
  214. {
  215. if ( $BuildID != 42 )
  216. {
  217. // PRODUCTION FORMULAS
  218. $metal_prod = eval ( $ProdGrid[$BuildID]['formule']['metal'] );
  219. $crystal_prod = eval ( $ProdGrid[$BuildID]['formule']['crystal'] );
  220. $deuterium_prod = eval ( $ProdGrid[$BuildID]['formule']['deuterium'] );
  221. $energy_prod = eval ( $ProdGrid[$BuildID]['formule']['energy'] );
  222. // PRODUCTION
  223. $Prod[1] = Production::production_amount ( $metal_prod , $geologe_boost );
  224. $Prod[2] = Production::production_amount ( $crystal_prod , $geologe_boost );
  225. $Prod[3] = Production::production_amount ( $deuterium_prod , $geologe_boost );
  226. if( $BuildID >= 4 )
  227. {
  228. $Prod[4] = Production::production_amount ( $energy_prod , $engineer_boost );
  229. }
  230. else
  231. {
  232. $Prod[4] = Production::production_amount ( $energy_prod , 1 );
  233. }
  234. $bloc['build_lvl'] = ($CurrentBuildtLvl == $BuildLevel) ? "<font color=\"#ff0000\">".$BuildLevel."</font>" : $BuildLevel;
  235. if ($ProdFirst > 0)
  236. if ($BuildID != 12)
  237. $bloc['build_gain'] = "<font color=\"lime\">(". Format::pretty_number(floor($Prod[$BuildID] - $ProdFirst)) .")</font>";
  238. else
  239. $bloc['build_gain'] = "<font color=\"lime\">(". Format::pretty_number(floor($Prod[4] - $ProdFirst)) .")</font>";
  240. else
  241. $bloc['build_gain'] = "";
  242. if ($BuildID != 12)
  243. {
  244. $bloc['build_prod'] = Format::pretty_number(floor($Prod[$BuildID]));
  245. $bloc['build_prod_diff'] = Format::color_number( Format::pretty_number(floor($Prod[$BuildID] - $ActualProd)) );
  246. $bloc['build_need'] = Format::color_number( Format::pretty_number(floor($Prod[4])) );
  247. $bloc['build_need_diff'] = Format::color_number( Format::pretty_number(floor($Prod[4] - $ActualNeed)) );
  248. }
  249. else
  250. {
  251. $bloc['build_prod'] = Format::pretty_number(floor($Prod[4]));
  252. $bloc['build_prod_diff'] = Format::color_number( Format::pretty_number(floor($Prod[4] - $ActualProd)) );
  253. $bloc['build_need'] = Format::color_number( Format::pretty_number(floor($Prod[3])) );
  254. $bloc['build_need_diff'] = Format::color_number( Format::pretty_number(floor($Prod[3] - $ActualNeed)) );
  255. }
  256. if ($ProdFirst == 0)
  257. {
  258. if ($BuildID != 12)
  259. $ProdFirst = floor($Prod[$BuildID]);
  260. else
  261. $ProdFirst = floor($Prod[4]);
  262. }
  263. }
  264. else
  265. {
  266. $bloc['build_lvl'] = ($CurrentBuildtLvl == $BuildLevel) ? "<font color=\"#ff0000\">".$BuildLevel."</font>" : $BuildLevel;
  267. $bloc['build_range'] = ($BuildLevel * $BuildLevel) - 1;
  268. }
  269. $Table .= parsetemplate($Template, $bloc);
  270. }
  271. return $Table;
  272. }
  273. private function ShowRapidFireTo ($BuildID)
  274. {
  275. global $lang, $CombatCaps;
  276. $ResultString = "";
  277. for ($Type = 200; $Type < 500; $Type++)
  278. {
  279. if ($CombatCaps[$BuildID]['sd'][$Type] > 1)
  280. $ResultString .= $lang['in_rf_again']. " ". $lang['tech'][$Type] ." <font color=\"#00ff00\">".$CombatCaps[$BuildID]['sd'][$Type]."</font><br>";
  281. }
  282. return $ResultString;
  283. }
  284. private function ShowRapidFireFrom ($BuildID)
  285. {
  286. global $lang, $CombatCaps;
  287. $ResultString = "";
  288. for ($Type = 200; $Type < 500; $Type++)
  289. {
  290. if ($CombatCaps[$Type]['sd'][$BuildID] > 1)
  291. $ResultString .= $lang['in_rf_from']. " ". $lang['tech'][$Type] ." <font color=\"#ff0000\">".$CombatCaps[$Type]['sd'][$BuildID]."</font><br>";
  292. }
  293. return $ResultString;
  294. }
  295. public function __construct ($CurrentUser, $CurrentPlanet, $BuildID)
  296. {
  297. global $lang, $resource, $pricelist, $CombatCaps;
  298. $GateTPL = '';
  299. $DestroyTPL = '';
  300. $TableHeadTPL = '';
  301. $parse = $lang;
  302. $parse['dpath'] = DPATH;
  303. $parse['name'] = $lang['info'][$BuildID]['name'];
  304. $parse['image'] = $BuildID;
  305. $parse['description'] = $lang['info'][$BuildID]['description'];
  306. if($BuildID < 13 OR $BuildID == 43)
  307. $PageTPL = gettemplate('infos/info_buildings_table');
  308. elseif($BuildID < 200)
  309. $PageTPL = gettemplate('infos/info_buildings_general');
  310. elseif($BuildID < 400)
  311. $PageTPL = gettemplate('infos/info_buildings_fleet');
  312. elseif($BuildID < 600)
  313. $PageTPL = gettemplate('infos/info_buildings_defense');
  314. else
  315. $PageTPL = gettemplate('infos/info_officiers_general');
  316. //Sólo hay destroy en <200
  317. if($BuildID < 200 AND $BuildID != 33 AND $BuildID != 41)
  318. $DestroyTPL = gettemplate('infos/info_buildings_destroy');
  319. if ($BuildID >= 1 && $BuildID <= 3)
  320. {
  321. $PageTPL = gettemplate('infos/info_buildings_table');
  322. $TableHeadTPL = gettemplate('infos/info_production_header');
  323. $TableTPL = gettemplate('infos/info_production_body');
  324. }
  325. elseif ($BuildID == 4)
  326. {
  327. $PageTPL = gettemplate('infos/info_buildings_table');
  328. $TableHeadTPL = gettemplate('infos/info_production_simple_header');
  329. $TableTPL = gettemplate('infos/info_production_simple_body');
  330. }
  331. elseif ($BuildID == 12)
  332. {
  333. $TableHeadTPL = gettemplate('infos/info_energy_header');
  334. $TableTPL = gettemplate('infos/info_energy_body');
  335. }
  336. /*elseif ($BuildID >= 14 AND $BuildID <= 100 AND $BuildID != 42 AND $BuildID != 41 AND $BuildID != 33 AND $BuildID != 43)
  337. {
  338. No hacemos NADA
  339. }*/
  340. /*elseif ($BuildID == 33)
  341. {
  342. $PageTPL = gettemplate('infos/info_buildings_general');
  343. }
  344. elseif ($BuildID == 41)
  345. {
  346. $PageTPL = gettemplate('infos/info_buildings_general');
  347. }*/
  348. elseif ($BuildID == 42)
  349. {
  350. $TableHeadTPL = gettemplate('infos/info_range_header');
  351. $TableTPL = gettemplate('infos/info_range_body');
  352. }
  353. elseif ($BuildID == 43)
  354. {
  355. $GateTPL = gettemplate('infos/info_gate_table');
  356. if($_POST)
  357. message($this->DoFleetJump($CurrentUser, $CurrentPlanet), "game.php?page=infos&gid=43", 2);
  358. }
  359. /*elseif ($BuildID >= 106 && $BuildID <= 199)
  360. {
  361. NADA! -- $PageTPL = gettemplate('infos/info_buildings_general');
  362. }*/
  363. elseif ($BuildID >= 202 && $BuildID <= 250)
  364. {
  365. $PageTPL = gettemplate('infos/info_buildings_fleet');
  366. $parse['element_typ'] = $lang['tech'][200];
  367. $parse['rf_info_to'] = $this->ShowRapidFireTo($BuildID);
  368. $parse['rf_info_fr'] = $this->ShowRapidFireFrom($BuildID);
  369. $parse['hull_pt'] = Format::pretty_number ($pricelist[$BuildID]['metal'] + $pricelist[$BuildID]['crystal']);
  370. $parse['shield_pt'] = Format::pretty_number ($CombatCaps[$BuildID]['shield']);
  371. $parse['attack_pt'] = Format::pretty_number ($CombatCaps[$BuildID]['attack']);
  372. $parse['capacity_pt'] = Format::pretty_number ($pricelist[$BuildID]['capacity']);
  373. $parse['base_speed'] = Format::pretty_number ($pricelist[$BuildID]['speed']);
  374. $parse['base_conso'] = Format::pretty_number ($pricelist[$BuildID]['consumption']);
  375. if ($BuildID == 202)
  376. {
  377. $parse['upd_speed'] = "<font color=\"yellow\">(". Format::pretty_number ($pricelist[$BuildID]['speed2']) .")</font>";
  378. $parse['upd_conso'] = "<font color=\"yellow\">(". Format::pretty_number ($pricelist[$BuildID]['consumption2']) .")</font>";
  379. }
  380. elseif ($BuildID == 211)
  381. $parse['upd_speed'] = "<font color=\"yellow\">(". Format::pretty_number ($pricelist[$BuildID]['speed2']) .")</font>";
  382. }
  383. elseif ($BuildID >= 401 && $BuildID <= 450)
  384. {
  385. $PageTPL = gettemplate('infos/info_buildings_defense');
  386. $parse['element_typ'] = $lang['tech'][400];
  387. $parse['rf_info_to'] = $this->ShowRapidFireTo ($BuildID);
  388. $parse['rf_info_fr'] = $this->ShowRapidFireFrom ($BuildID);
  389. $parse['hull_pt'] = Format::pretty_number ($pricelist[$BuildID]['metal'] + $pricelist[$BuildID]['crystal']);
  390. $parse['shield_pt'] = Format::pretty_number ($CombatCaps[$BuildID]['shield']);
  391. $parse['attack_pt'] = Format::pretty_number ($CombatCaps[$BuildID]['attack']);
  392. }
  393. elseif ($BuildID == 502 && $BuildID == 503)
  394. {
  395. $PageTPL = gettemplate('infos/info_buildings_defense');
  396. $parse['element_typ'] = $lang['tech'][400];
  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. }