1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by Gorlum 18.04.2018 16:30 |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Fleet; |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
use Core\EntityDb; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class Fleet |
13
|
|
|
* @package Fleet |
14
|
|
|
* |
15
|
|
|
* @property int|string $id - bigint - |
16
|
|
|
* @property int|string $fleet_owner - bigint - |
17
|
|
|
* @property int $fleet_mission - int - |
18
|
|
|
* @property int|string $fleet_amount - bigint - |
19
|
|
|
* @property string $fleet_array - mediumtext - |
20
|
|
|
* @property int $fleet_start_time - int - |
21
|
|
|
* @property int|string $fleet_start_planet_id - bigint - |
22
|
|
|
* @property int $fleet_start_galaxy - int - |
23
|
|
|
* @property int $fleet_start_system - int - |
24
|
|
|
* @property int $fleet_start_planet - int - |
25
|
|
|
* @property int $fleet_start_type - int - |
26
|
|
|
* @property int $fleet_end_time - int - |
27
|
|
|
* @property int $fleet_end_stay - int - |
28
|
|
|
* @property int|string $fleet_end_planet_id - bigint - |
29
|
|
|
* @property int $fleet_end_galaxy - int - |
30
|
|
|
* @property int $fleet_end_system - int - |
31
|
|
|
* @property int $fleet_end_planet - int - |
32
|
|
|
* @property int $fleet_end_type - int - |
33
|
|
|
* @property int|string $fleet_resource_metal - decimal - |
34
|
|
|
* @property int|string $fleet_resource_crystal - decimal - |
35
|
|
|
* @property int|string $fleet_resource_deuterium - decimal - |
36
|
|
|
* @property int|string $fleet_target_owner - int - |
37
|
|
|
* @property int|string $fleet_group - varchar - |
38
|
|
|
* @property int $fleet_mess - int - |
39
|
|
|
* @property int $start_time - int - |
40
|
|
|
*/ |
41
|
|
|
class Fleet extends EntityDb { |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var string $_activeClass |
45
|
|
|
*/ |
46
|
|
|
protected $_activeClass = '\\Fleet\\RecordFleet'; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var RecordFleet $_container |
50
|
|
|
*/ |
51
|
|
|
protected $_container; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Information about ships |
55
|
|
|
* |
56
|
|
|
* @var array[] $shipInfo |
57
|
|
|
*/ |
58
|
|
|
protected static $shipInfo = []; |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Fleet constructor. |
63
|
|
|
*/ |
64
|
|
|
public function __construct() { |
65
|
|
|
parent::__construct(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return RecordFleet |
70
|
|
|
*/ |
71
|
|
|
public function _getContainer() { |
72
|
|
|
return $this->_container; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param int $shipId |
78
|
|
|
* |
79
|
|
|
* @return array |
80
|
|
|
*/ |
81
|
|
|
protected static function getUnitInfo($shipId) { |
82
|
|
|
if (!isset(static::$shipInfo[$shipId])) { |
83
|
|
|
static::$shipInfo[$shipId] = get_unit_param($shipId); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
return static::$shipInfo[$shipId]; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param int $resourceId |
91
|
|
|
* |
92
|
|
|
* @return float[] - [(int)$shipId => (float)costInMetal] |
93
|
|
|
*/ |
94
|
|
|
public function getShipsBasicCosts($resourceId = RES_METAL) { |
95
|
|
|
$result = []; |
96
|
|
|
foreach ($this->getShipList() as $shipId => $shipAmount) { |
97
|
|
|
$result[$shipId] = getStackableUnitsCost([$shipId => 1], $resourceId); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
return $result; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Get cost of single ship in metal |
105
|
|
|
* |
106
|
|
|
* @param int $shipId |
107
|
|
|
* |
108
|
|
|
* @return int|float |
109
|
|
|
*/ |
110
|
|
|
public function getShipCostInMetal($shipId) { |
111
|
|
|
return getStackableUnitsCost([$shipId => 1], RES_METAL); |
112
|
|
|
// |
|
|
|
|
113
|
|
|
// if(!isset(static::getUnitInfo($shipId)[P_COST_METAL])) { |
114
|
|
|
// static::$shipInfo[$shipId][P_COST_METAL] = get_unit_cost_in(static::getUnitInfo($shipId)[P_COST], RES_METAL); |
115
|
|
|
// } |
116
|
|
|
// |
117
|
|
|
// return static::getUnitInfo($shipId)[P_COST_METAL]; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Get fleet cost in metal |
122
|
|
|
* |
123
|
|
|
* @return float|int |
124
|
|
|
*/ |
125
|
|
|
public function getCostInMetal() { |
126
|
|
|
return getStackableUnitsCost($this->getShipList(), RES_METAL); |
127
|
|
|
// |
|
|
|
|
128
|
|
|
// $result = 0; |
129
|
|
|
// foreach($this->getShipList() as $shipId => $amount) { |
130
|
|
|
// $result += $amount * $this->getShipCostInMetal($shipId); |
131
|
|
|
// } |
132
|
|
|
// |
133
|
|
|
// return $result; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Get single ship basic capacity |
138
|
|
|
* |
139
|
|
|
* @param int $shipId |
140
|
|
|
* |
141
|
|
|
* @return int|mixed |
142
|
|
|
*/ |
143
|
|
|
public function getShipCapacity($shipId) { |
144
|
|
|
if (!isset(static::getUnitInfo($shipId)[P_CAPACITY])) { |
145
|
|
|
static::$shipInfo[$shipId][P_CAPACITY] = 0; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
return static::getUnitInfo($shipId)[P_CAPACITY]; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Get current fleet capacity counting loaded resources and fuel |
153
|
|
|
* |
154
|
|
|
* @return float|int |
155
|
|
|
*/ |
156
|
|
|
public function getCapacityActual() { |
157
|
|
|
$result = 0; |
158
|
|
|
foreach ($this->getShipList() as $shipId => $amount) { |
159
|
|
|
$result += $amount * $this->getShipCapacity($shipId); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
$result = max(0, $result - array_sum($this->getResourceList())); |
163
|
|
|
|
164
|
|
|
return $result; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
public function isEmpty() { |
168
|
|
|
return parent::isEmpty(); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
// Using RecordFleet functions --------------------------------------------------------------------------------------- |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @param int $shipSnId |
175
|
|
|
* @param float $shipCount |
176
|
|
|
* |
177
|
|
|
* @throws \Exception |
178
|
|
|
*/ |
179
|
|
|
public function changeShipCount($shipSnId, $shipCount) { |
180
|
|
|
$this->_getContainer()->changeShipCount($shipSnId, $shipCount); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* @param int $resourceId |
185
|
|
|
* @param float $resourceCount |
186
|
|
|
* |
187
|
|
|
* @throws \Exception |
188
|
|
|
*/ |
189
|
|
|
public function changeResource($resourceId, $resourceCount) { |
190
|
|
|
$this->_getContainer()->changeResource($resourceId, $resourceCount); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* @return float[] - [shipSnId => $shipAmount] |
195
|
|
|
*/ |
196
|
|
|
public function getShipList() { |
197
|
|
|
return $this->_getContainer()->getShipList(); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @return float[] - [$resourceSnId => $resourceAmount] |
202
|
|
|
*/ |
203
|
|
|
public function getResourceList() { |
204
|
|
|
return $this->_getContainer()->getResourceList(); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
public function getShipCount() { |
208
|
|
|
return $this->_getContainer()->getShipCount(); |
209
|
|
|
// return array_sum($this->getShipList()); |
|
|
|
|
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
} |
213
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.