1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by Gorlum 11.10.2017 13:16 |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Fleet; |
7
|
|
|
|
8
|
|
|
use SN; |
9
|
|
|
use Planet\DBStaticPlanet; |
10
|
|
|
|
11
|
|
|
class MissionEspionage extends MissionData { |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @var MissionEspionageReport $missionReport |
15
|
|
|
*/ |
16
|
|
|
public $missionReport; |
17
|
|
|
|
18
|
|
|
private $target_message = ''; |
19
|
|
|
|
20
|
|
|
public function flt_mission_spy() { |
21
|
|
|
$lang = SN::$lang; |
22
|
|
|
$fleet_array = sys_unit_str2arr($this->fleet['fleet_array']); |
23
|
|
|
|
24
|
|
|
if (isset($this->dstUserRow['id']) && isset($this->dstPlanetRow['id']) && isset($this->fleetOwnerRow['id']) && $fleet_array[SHIP_SPY] >= 1) { |
25
|
|
|
// TODO: Наемники, губернаторы, артефакты и прочее имперское |
26
|
|
|
$this->doSpying(); |
27
|
|
|
|
28
|
|
|
msg_send_simple_message($this->fleetOwnerRow['id'], '', $this->fleet['fleet_start_time'], MSG_TYPE_SPY, $lang['sys_mess_qg'], $lang['sys_mess_spy_report'], |
29
|
|
|
json_encode($this->missionReport, JSON_UNESCAPED_UNICODE), STRING_NEED_ESCAPING, false, STRING_IS_JSON_ENCODED); |
30
|
|
|
|
31
|
|
|
$this->target_message = "{$lang['sys_mess_spy_enemy_fleet']} {$this->srcPlanetRow['name']} " . uni_render_coordinates_href($this->srcPlanetRow, '', 3); |
32
|
|
|
$this->target_message .= " {$lang['sys_mess_spy_seen_at']} {$this->dstPlanetRow['name']} " . uni_render_coordinates($this->dstPlanetRow); |
33
|
|
|
if ($this->missionReport->isSpyDetected()) { |
34
|
|
|
$this->target_message .= "<br />{$lang['sys_mess_spy_destroyed_enemy']}"; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
msg_send_simple_message( |
38
|
|
|
$this->fleet['fleet_target_owner'], |
39
|
|
|
'', |
40
|
|
|
$this->fleet['fleet_start_time'], |
41
|
|
|
MSG_TYPE_SPY, |
42
|
|
|
$lang['sys_mess_spy_control'], |
43
|
|
|
$lang['sys_mess_spy_activity'], |
44
|
|
|
$this->target_message |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
$this->dbApplyChanges(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
protected function scanGroup($group_name) { |
52
|
|
|
foreach ($this->general->getGroupsByName($group_name) as $unit_id) { |
53
|
|
|
$this->missionReport->addUnit($unit_id, mrc_get_level($this->dstUserRow, $this->dstPlanetRow, $unit_id, false, true)); |
|
|
|
|
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
protected function doSpying() { |
58
|
|
|
$this->missionReport = new MissionEspionageReport($this); |
59
|
|
|
|
60
|
|
|
$spy_diff_empire = $this->missionReport->getEmpireSpyDiff(); |
61
|
|
|
$planetSpyDiff = $this->missionReport->getPlanetSpyDiff(); |
62
|
|
|
|
63
|
|
|
if ($planetSpyDiff >= 2) { |
64
|
|
|
$this->scanGroup('fleet'); |
65
|
|
|
} |
66
|
|
|
if ($planetSpyDiff >= 3) { |
67
|
|
|
$this->scanGroup('defense'); |
68
|
|
|
} |
69
|
|
|
if ($planetSpyDiff >= 5) { |
70
|
|
|
$this->scanGroup('structures'); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
if ($spy_diff_empire >= 0) { |
74
|
|
|
$this->scanGroup('tech'); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
// Launching detection calculations |
78
|
|
|
$this->missionReport->isSpyDetected(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
protected function dbApplyChanges() { |
82
|
|
|
if (is_object($this->missionReport) && $this->missionReport->isSpyDetected()) { |
83
|
|
|
DbFleetStatic::db_fleet_delete($this->fleet['fleet_id']); |
84
|
|
|
|
85
|
|
|
$debris_planet_id = $this->dstPlanetRow['planet_type'] == PT_PLANET ? $this->dstPlanetRow['id'] : $this->dstPlanetRow['parent_planet']; |
86
|
|
|
|
87
|
|
|
$spy_cost = get_unit_param(SHIP_SPY, P_COST); |
88
|
|
|
|
89
|
|
|
DBStaticPlanet::db_planet_set_by_id($debris_planet_id, |
90
|
|
|
"`debris_metal` = `debris_metal` + " . floor($this->missionReport->getProbesNumber() * $spy_cost[RES_METAL] * 0.3) . ", `debris_crystal` = `debris_crystal` + " . floor($this->missionReport->getProbesNumber() * $spy_cost[RES_CRYSTAL] * 0.3)); |
91
|
|
|
} else { |
92
|
|
|
DbFleetStatic::fleet_send_back($this->fleet); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
} |
97
|
|
|
|