PageRenderTime 363ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/classes/missions/MissionCaseExpedition.php

https://bitbucket.org/jybox/2mex
PHP | 363 lines | 288 code | 48 blank | 27 comment | 34 complexity | 4e02a5551104d101a99f2c188cedeee5 MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, LGPL-3.0, Apache-2.0
  1. <?php
  2. /**
  3. * 2Moons
  4. * Copyright (C) 2011 Slaver
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. * @package 2Moons
  20. * @author Slaver <slaver7@gmail.com>
  21. * @copyright 2009 Lucky <lucky@xgproyect.net> (XGProyecto)
  22. * @copyright 2011 Slaver <slaver7@gmail.com> (Fork/2Moons)
  23. * @license http://www.gnu.org/licenses/gpl.html GNU GPLv3 License
  24. * @version 1.6.1 (2011-11-19)
  25. * @info $Id: MissionCaseExpedition.php 2072 2011-11-17 13:21:40Z slaver7 $
  26. * @link http://code.google.com/p/2moons/
  27. */
  28. class MissionCaseExpedition extends MissionFunctions
  29. {
  30. function __construct($Fleet)
  31. {
  32. $this->_fleet = $Fleet;
  33. }
  34. function TargetEvent()
  35. {
  36. $this->UpdateFleet('fleet_mess', 2);
  37. $this->SaveFleet();
  38. }
  39. function EndStayEvent()
  40. {
  41. global $pricelist, $db, $reslist, $LANG;
  42. $LNG = $LANG->GetUserLang($this->_fleet['fleet_owner']);
  43. foreach($reslist['fleet'] as $ID)
  44. {
  45. $Expowert[$ID] = ($pricelist[$ID]['metal'] + $pricelist[$ID]['crystal']) / 1000;
  46. }
  47. $Expowert[202] = 12;
  48. $Expowert[203] = 47;
  49. $Expowert[204] = 12;
  50. $Expowert[205] = 110;
  51. $Expowert[206] = 47;
  52. $Expowert[207] = 160;
  53. $farray = explode(";", $this->_fleet['fleet_array']);
  54. $FleetPoints = 0;
  55. $FleetCapacity = 0;
  56. foreach ($farray as $Item => $Group)
  57. {
  58. if (empty($Group)) continue;
  59. $Class = explode (",", $Group);
  60. $FleetCount[$Class[0]] = $Class[1];
  61. $FleetCapacity += $Class[1] * $pricelist[$Class[0]]['capacity'];
  62. $FleetPoints += $Class[1] * $Expowert[$Class[0]];
  63. }
  64. $FleetCapacity -= $this->_fleet['fleet_resource_metal'] + $this->_fleet['fleet_resource_crystal'] + $this->_fleet['fleet_resource_deuterium'] + $this->_fleet['fleet_resource_darkmatter'];
  65. $GetEvent = mt_rand(1, 9);
  66. switch($GetEvent)
  67. {
  68. case 1:
  69. $WitchFound = mt_rand(1,3);
  70. $FindSize = mt_rand(0, 100);
  71. if(10 < $FindSize) {
  72. $WitchSize = 1;
  73. $Factor = (mt_rand(10, 50) / $WitchFound) * $GLOBALS['CONFIG'][$this->_fleet['fleet_universe']]['resource_multiplier'];
  74. $Message = $LNG['sys_expe_found_ress_1_'.mt_rand(1,4)];
  75. } elseif(0 < $FindSize && 10 >= $FindSize) {
  76. $WitchSize = 2;
  77. $Factor = (mt_rand(52, 100) / $WitchFound) * $GLOBALS['CONFIG'][$this->_fleet['fleet_universe']]['resource_multiplier'];
  78. $Message = $LNG['sys_expe_found_ress_2_'.mt_rand(1,3)];
  79. } elseif(0 == $FindSize) {
  80. $WitchSize = 3;
  81. $Factor = (mt_rand(102, 200) / $WitchFound) * $GLOBALS['CONFIG'][$this->_fleet['fleet_universe']]['resource_multiplier'];
  82. $Message = $LNG['sys_expe_found_ress_3_'.mt_rand(1,2)];
  83. }
  84. $StatFactor = $db->uniquequery("SELECT MAX(total_points) as total FROM `".STATPOINTS."` WHERE `stat_type` = 1 AND `universe` = '".$this->_fleet['fleet_universe']."';");
  85. $MaxPoints = ($StatFactor['total'] < 5000000) ? 9000 : 12000;
  86. $Size = min($Factor * MAX(MIN($FleetPoints / 1000, $MaxPoints), 200), $FleetCapacity);
  87. switch($WitchFound)
  88. {
  89. case 1:
  90. $this->UpdateFleet('fleet_resource_metal', $this->_fleet['fleet_resource_metal'] + $Size);
  91. break;
  92. case 2:
  93. $this->UpdateFleet('fleet_resource_crystal', $this->_fleet['fleet_resource_crystal'] + $Size);
  94. break;
  95. case 3:
  96. $this->UpdateFleet('fleet_resource_deuterium', $this->_fleet['fleet_resource_deuterium'] + $Size);
  97. break;
  98. }
  99. break;
  100. case 2:
  101. $FindSize = mt_rand(0, 100);
  102. if(10 < $FindSize) {
  103. $Size = mt_rand(100, 300);
  104. $Message = $LNG['sys_expe_found_dm_1_'.mt_rand(1,5)];
  105. } elseif(0 < $FindSize && 10 >= $FindSize) {
  106. $Size = mt_rand(301, 600);
  107. $Message = $LNG['sys_expe_found_dm_2_'.mt_rand(1,4)];
  108. } elseif(0 == $FindSize) {
  109. $Size = mt_rand(601, 3000);
  110. $Message = $LNG['sys_expe_found_dm_3_'.mt_rand(1,2)];
  111. }
  112. $this->UpdateFleet('fleet_resource_darkmatter', $this->_fleet['fleet_resource_darkmatter'] + $Size);
  113. break;
  114. case 3:
  115. default:
  116. $FindSize = mt_rand(0, 100);
  117. if(10 < $FindSize) {
  118. $Size = mt_rand(10, 50);
  119. $Message = $LNG['sys_expe_found_ships_1_'.mt_rand(1,4)];
  120. $MaxFound = 300000;
  121. } elseif(0 < $FindSize && 10 >= $FindSize) {
  122. $Size = mt_rand(52, 100);
  123. $Message = $LNG['sys_expe_found_ships_2_'.mt_rand(1,2)];
  124. $MaxFound = 600000;
  125. } elseif(0 == $FindSize) {
  126. $Size = mt_rand(102, 200);
  127. $Message = $LNG['sys_expe_found_ships_3_'.mt_rand(1,2)];
  128. $MaxFound = 1200000;
  129. }
  130. $StatFactor = $db->countquery("SELECT MAX(total_points) FROM `".STATPOINTS."` WHERE `stat_type` = 1 AND `universe` = '".$this->_fleet['fleet_universe']."';");
  131. $MaxPoints = ($StatFactor < 5000000) ? 4500 : 6000;
  132. $FoundShips = max(round($Size * min($FleetPoints, $MaxPoints)), 10000);
  133. $FoundShipMess = "";
  134. $NewFleetArray = "";
  135. $LNG += $LANG->GetUserLang($this->_fleet['fleet_owner'], array('TECH'));
  136. $Found = array();
  137. foreach($reslist['fleet'] as $ID)
  138. {
  139. if(!isset($FleetCount[$ID]) || $ID == 208 || $ID == 209 || $ID == 214)
  140. continue;
  141. $MaxFound = floor($FoundShips / ($pricelist[$ID]['metal'] + $pricelist[$ID]['crystal']));
  142. if($MaxFound <= 0)
  143. continue;
  144. $Count = mt_rand(0, $MaxFound);
  145. if($Count <= 0)
  146. continue;
  147. $Found[$ID] += $Count;
  148. $FoundShips -= $Count * ($pricelist[$ID]['metal'] + $pricelist[$ID]['crystal']);
  149. $FoundShipMess .= '<br>'.$LNG['tech'][$ID].': '.pretty_number($Count);
  150. if($FoundShips <= 0)
  151. break;
  152. }
  153. foreach($FleetCount as $ID => $Count)
  154. $NewFleetArray .= $ID.",".floattostring($Count + $Found[$ID]).";";
  155. $Message .= $FoundShipMess;
  156. $this->UpdateFleet('fleet_array', $NewFleetArray);
  157. $this->UpdateFleet('fleet_amount', array_sum($FleetCount));
  158. break;
  159. case 4:
  160. $Chance = mt_rand(1,2);
  161. if($Chance == 1) {
  162. $Points = array(-3,-5,-8);
  163. $Which = 1;
  164. $Def = -3;
  165. $Name = $LNG['sys_expe_attackname_1'];
  166. $Add = 0;
  167. $Rand = array(5,3,2);
  168. $DefenderFleetArray = "204,5;206,3;207,2;";
  169. } else {
  170. $Points = array(-4,-6,-9);
  171. $Which = 2;
  172. $Def = 3;
  173. $Name = $LNG['sys_expe_attackname_2'];
  174. $Add = 0.1;
  175. $Rand = array(4,3,2);
  176. $DefenderFleetArray = "205,5;215,3;213,2;";
  177. }
  178. $LNG += $LANG->GetUserLang($this->_fleet['fleet_owner'], array('L18N'));
  179. $FindSize = mt_rand(0, 100);
  180. if(10 < $FindSize) {
  181. $Message = $LNG['sys_expe_attack_'.$Which.'_1_'.$Rand[0]];
  182. $MaxAttackerPoints = 0.3 + $Add + (mt_rand($Points[0], abs($Points[0])) * 0.01);
  183. } elseif(0 < $FindSize && 10 >= $FindSize) {
  184. $Message = $LNG['sys_expe_attack_'.$Which.'_2_'.$Rand[1]];
  185. $MaxAttackerPoints = 0.3 + $Add + (mt_rand($Points[1], abs($Points[1])) * 0.01);
  186. } elseif(0 == $FindSize) {
  187. $Message = $LNG['sys_expe_attack_'.$Which.'_3_'.$Rand[2]];
  188. $MaxAttackerPoints = 0.3 + $Add + (mt_rand($Points[2], abs($Points[2])) * 0.01);
  189. }
  190. foreach($FleetCount as $ID => $count)
  191. {
  192. $DefenderFleetArray .= $ID.",".round($count * $MaxAttackerPoints).";";
  193. }
  194. $AttackerTechno = $db->uniquequery('SELECT id,username,military_tech,defence_tech,shield_tech,rpg_amiral,dm_defensive,dm_attack FROM '.USERS.' WHERE id='.$this->_fleet['fleet_owner'].";");
  195. $DefenderTechno = array('id' => 0, 'username' => $Name, 'military_tech' => (min($AttackerTechno['military_tech'] + $Def,0)), 'defence_tech' => (min($AttackerTechno['defence_tech'] + $Def,0)), 'shield_tech' => (min($AttackerTechno['shield_tech'] + $Def,0)), 'rpg_amiral' => 0, 'dm_defensive' => 0, 'dm_attack' => 0);
  196. $attackFleets[$this->_fleet['fleet_id']]['fleet'] = $this->_fleet;
  197. $attackFleets[$this->_fleet['fleet_id']]['user'] = $AttackerTechno;
  198. $attackFleets[$this->_fleet['fleet_id']]['user']['factor'] = getFactors($attackFleets[$this->_fleet['fleet_id']]['user'], 'attack', $this->_fleet['fleet_start_time']);
  199. $attackFleets[$this->_fleet['fleet_id']]['detail'] = array();
  200. $temp = explode(';', $this->_fleet['fleet_array']);
  201. foreach ($temp as $temp2)
  202. {
  203. $temp2 = explode(',', $temp2);
  204. if ($temp2[0] < 100) continue;
  205. if (!isset($attackFleets[$this->_fleet['fleet_id']]['detail'][$temp2[0]]))
  206. $attackFleets[$this->_fleet['fleet_id']]['detail'][$temp2[0]] = 0;
  207. $attackFleets[$this->_fleet['fleet_id']]['detail'][$temp2[0]] += $temp2[1];
  208. }
  209. $defense = array();
  210. $defRowDef = explode(';', $DefenderFleetArray);
  211. foreach ($defRowDef as $Element)
  212. {
  213. $Element = explode(',', $Element);
  214. if ($Element[0] < 100) continue;
  215. if (!isset($defense[$defRow['fleet_id']]['def'][$Element[0]]))
  216. $defense[0][$Element[0]] = 0;
  217. $defense[0]['def'][$Element[0]] += $Element[1];
  218. }
  219. $defense[0]['user'] = $DefenderTechno;
  220. $defense[0]['user']['factor'] = 0;
  221. require_once('calculateAttack.php');
  222. $start = microtime(true);
  223. $result = calculateAttack($attackFleets, $defense, $GLOBALS['CONFIG'][$this->_fleet['fleet_universe']]['Fleet_Cdr'], $GLOBALS['CONFIG'][$this->_fleet['fleet_universe']]['Defs_Cdr']);
  224. $totaltime = microtime(true) - $start;
  225. foreach ($attackFleets as $fleetID => $attacker)
  226. {
  227. $fleetArray = '';
  228. $totalCount = 0;
  229. foreach ($attacker['detail'] as $element => $amount)
  230. {
  231. if ($amount)
  232. $fleetArray .= $element.','.$amount.';';
  233. $totalCount += $amount;
  234. }
  235. if ($totalCount <= 0)
  236. $this->KillFleet();
  237. else
  238. {
  239. $this->UpdateFleet('fleet_array', substr($fleetArray, 0, -1));
  240. $this->UpdateFleet('fleet_amount', $totalCount);
  241. }
  242. }
  243. require_once('GenerateReport.php');
  244. $INFO = $this->_fleet;
  245. $INFO['steal'] = array('metal' => 0, 'crystal' => 0, 'deuterium' => 0);
  246. $INFO['moon']['des'] = 0;
  247. $INFO['moon']['chance'] = 0;
  248. $raport = GenerateReport($result, $INFO);
  249. $SQL = "INSERT INTO ".RW." SET ";
  250. $SQL .= "`raport` = '".serialize($raport)."', ";
  251. $SQL .= "`time` = '".$this->_fleet['fleet_start_time']."', ";
  252. $SQL .= "`rid` = '".$rid."';";
  253. $db->query($SQL);
  254. $rid = $db->GetInsertID();
  255. switch($result['won'])
  256. {
  257. case "r":
  258. $ColorAtt = "red";
  259. $ColorDef = "green";
  260. break;
  261. case "w":
  262. $ColorAtt = "orange";
  263. $ColorDef = "orange";
  264. case "a":
  265. $ColorAtt = "green";
  266. $ColorDef = "red";
  267. break;
  268. }
  269. $MessageAtt = sprintf('<a href="CombatReport.php?raport=%s" target="_blank"><center><font color="%s">%s %s</font></a><br><br><font color="%s">%s: %s</font> <font color="%s">%s: %s</font><br>%s %s:<font color="#adaead">%s</font> %s:<font color="#ef51ef">%s</font> %s:<font color="#f77542">%s</font><br>%s %s:<font color="#adaead">%s</font> %s:<font color="#ef51ef">%s</font><br></center>', $rid, $ColorAtt, $LNG['sys_mess_attack_report'], sprintf($LNG['sys_adress_planet'], $this->_fleet['fleet_end_galaxy'], $this->_fleet['fleet_end_system'], $this->_fleet['fleet_end_planet']), $ColorAtt, $LNG['sys_perte_attaquant'], pretty_number($result['lost']['att']), $ColorDef, $LNG['sys_perte_defenseur'], pretty_number($result['lost']['def']), $LNG['sys_gain'], $LNG['Metal'], pretty_number($steal['metal']), $LNG['Crystal'], pretty_number($steal['crystal']), $LNG['Deuterium'], pretty_number($steal['deuterium']), $LNG['sys_debris'], $LNG['Metal'], pretty_number($result['debree']['att'][0]+$result['debree']['def'][0]), $LNG['Crystal'], pretty_number($result['debree']['att'][1]+$result['debree']['def'][1]));
  270. SendSimpleMessage($this->_fleet['fleet_owner'], 0, $this->_fleet['fleet_start_time'], 3, $LNG['sys_mess_tower'], $LNG['sys_mess_attack_report'], $MessageAtt);
  271. break;
  272. case 5:
  273. $this->KillFleet();
  274. $Message = $LNG['sys_expe_lost_fleet_'.mt_rand(1,4)];
  275. break;
  276. case 6:
  277. # http://owiki.de/Expedition#Ver.C3.A4nderte_Flugzeit
  278. $MoreTime = mt_rand(0, 100);
  279. $Wrapper = array();
  280. $Wrapper[] = 2;
  281. $Wrapper[] = 2;
  282. $Wrapper[] = 2;
  283. $Wrapper[] = 2;
  284. $Wrapper[] = 2;
  285. $Wrapper[] = 2;
  286. $Wrapper[] = 2;
  287. $Wrapper[] = 3;
  288. $Wrapper[] = 3;
  289. $Wrapper[] = 5;
  290. if($MoreTime < 75) {
  291. $this->UpdateFleet('fleet_end_time', ($this->_fleet['fleet_end_time'] - $this->_fleet['fleet_end_stay']) + ($this->_fleet['fleet_end_stay'] - $this->_fleet['fleet_start_time']) * $Wrapper[mt_rand(0, 9)]);
  292. $Message = $LNG['sys_expe_time_slow_'.mt_rand(1,6)];
  293. } else {
  294. $this->UpdateFleet('fleet_end_time', max(1, ($this->_fleet['fleet_end_time'] - $this->_fleet['fleet_end_stay']) - ($this->_fleet['fleet_end_stay'] - $this->_fleet['fleet_start_time']) / 3 * $Wrapper[mt_rand(0, 9)]));
  295. $Message = $LNG['sys_expe_time_fast_'.mt_rand(1,3)];
  296. }
  297. break;
  298. default:
  299. $Message = $LNG['sys_expe_nothing_'.mt_rand(1,8)];
  300. break;
  301. }
  302. SendSimpleMessage($this->_fleet['fleet_owner'], 0, $this->_fleet['fleet_end_stay'], 15, $LNG['sys_mess_tower'], $LNG['sys_expe_report'], $Message);
  303. $this->UpdateFleet('fleet_mess', 1);
  304. $this->SaveFleet();
  305. }
  306. function ReturnEvent()
  307. {
  308. global $LANG;
  309. $LNG = $LANG->GetUserLang($this->_fleet['fleet_owner']);
  310. $Message = sprintf($LNG['sys_expe_back_home'], $LNG['Metal'], pretty_number($this->_fleet['fleet_resource_metal']), $LNG['Crystal'], pretty_number($this->_fleet['fleet_resource_crystal']), $LNG['Deuterium'], pretty_number($this->_fleet['fleet_resource_deuterium']), $LNG['Darkmatter'], pretty_number($this->_fleet['fleet_resource_darkmatter']));
  311. SendSimpleMessage($this->_fleet['fleet_owner'], 0, $this->_fleet['fleet_end_time'], 15, $LNG['sys_mess_tower'], $LNG['sys_expe_report'], $Message);
  312. $this->RestoreFleet();
  313. }
  314. }
  315. ?>