PageRenderTime 62ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

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

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