|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by Gorlum 17.08.2016 22:07 |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace V2Fleet; |
|
7
|
|
|
|
|
8
|
|
|
use V2Unit\V2UnitContainer; |
|
9
|
|
|
use V2Unit\V2UnitList; |
|
10
|
|
|
use V2Unit\V2UnitModel; |
|
11
|
|
|
use Vector\Vector; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Class V2FleetModel |
|
15
|
|
|
* |
|
16
|
|
|
* @method V2FleetContainer buildContainer() |
|
17
|
|
|
* method V2FleetContainer fromArray(array $array) |
|
18
|
|
|
* @method V2FleetContainer loadById(mixed $dbId) |
|
19
|
|
|
* |
|
20
|
|
|
* @package V2Fleet |
|
21
|
|
|
*/ |
|
22
|
|
|
class V2FleetModel extends \Entity\KeyedModel { |
|
23
|
|
|
protected $locationType = LOC_FLEET; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Return location type |
|
27
|
|
|
* |
|
28
|
|
|
* @param \Entity\EntityContainer $cEntity |
|
29
|
|
|
* |
|
30
|
|
|
* @return int |
|
31
|
|
|
*/ |
|
32
|
|
|
public function getLocationType($cEntity) { |
|
|
|
|
|
|
33
|
|
|
return $this->locationType; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Return location ID |
|
38
|
|
|
* |
|
39
|
|
|
* @param \Entity\EntityContainer $cEntity |
|
40
|
|
|
* |
|
41
|
|
|
* @return mixed |
|
42
|
|
|
*/ |
|
43
|
|
|
public function getLocationId($cEntity) { |
|
44
|
|
|
return $cEntity->dbId; |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Name of table for this entity |
|
50
|
|
|
* |
|
51
|
|
|
* @var string $tableName |
|
52
|
|
|
*/ |
|
53
|
|
|
protected $tableName = 'fleets'; |
|
54
|
|
|
/** |
|
55
|
|
|
* Name of key field field in this table |
|
56
|
|
|
* |
|
57
|
|
|
* @var string $idFieldName |
|
58
|
|
|
*/ |
|
59
|
|
|
protected $idFieldName = 'fleet_id'; |
|
60
|
|
|
|
|
61
|
|
|
// protected $exceptionClass = 'Entity\EntityException'; |
|
|
|
|
|
|
62
|
|
|
protected $entityContainerClass = 'V2Fleet\V2FleetContainer'; |
|
63
|
|
|
|
|
64
|
|
|
// protected $properties = array( |
|
|
|
|
|
|
65
|
|
|
// 'dbId' => array(P_DB_FIELD => 'fleet_id',), |
|
66
|
|
|
// 'ownerId' => array(P_DB_FIELD => 'fleet_owner',), |
|
67
|
|
|
// 'missionType' => array(P_DB_FIELD => 'fleet_mission'), |
|
68
|
|
|
// |
|
69
|
|
|
// 'fleet_amount' => array(P_DB_FIELD => 'fleet_amount'), |
|
70
|
|
|
// 'fleet_start_planet_id' => array(P_DB_FIELD => 'fleet_start_planet_id'), |
|
71
|
|
|
// |
|
72
|
|
|
//// 'fleet_start_galaxy' => array(P_DB_FIELD => 'fleet_start_galaxy'), |
|
73
|
|
|
//// 'fleet_start_system' => array(P_DB_FIELD => 'fleet_start_system'), |
|
74
|
|
|
//// 'fleet_start_planet' => array(P_DB_FIELD => 'fleet_start_planet'), |
|
75
|
|
|
//// 'fleet_start_type' => array(P_DB_FIELD => 'fleet_start_type'), |
|
76
|
|
|
// |
|
77
|
|
|
// 'fleet_end_planet_id' => array(P_DB_FIELD => 'fleet_end_planet_id'), |
|
78
|
|
|
// 'fleet_target_owner' => array(P_DB_FIELD => 'fleet_target_owner'), |
|
79
|
|
|
// |
|
80
|
|
|
//// 'fleet_end_galaxy' => array(P_DB_FIELD => 'fleet_end_galaxy'), |
|
81
|
|
|
//// 'fleet_end_system' => array(P_DB_FIELD => 'fleet_end_system'), |
|
82
|
|
|
//// 'fleet_end_planet' => array(P_DB_FIELD => 'fleet_end_planet'), |
|
83
|
|
|
//// 'fleet_end_type' => array(P_DB_FIELD => 'fleet_end_type'), |
|
84
|
|
|
// |
|
85
|
|
|
//// 'fleet_resource_metal' => array(P_DB_FIELD => 'fleet_resource_metal'), |
|
86
|
|
|
//// 'fleet_resource_crystal' => array(P_DB_FIELD => 'fleet_resource_crystal'), |
|
87
|
|
|
//// 'fleet_resource_deuterium' => array(P_DB_FIELD => 'fleet_resource_deuterium'), |
|
88
|
|
|
// |
|
89
|
|
|
// 'groupId' => array(P_DB_FIELD => 'fleet_group'), |
|
90
|
|
|
// 'status' => array(P_DB_FIELD => 'fleet_mess'), |
|
91
|
|
|
// |
|
92
|
|
|
// 'vectorDeparture' => array(P_DB_FIELD => 'fleet_start_galaxy'), |
|
93
|
|
|
// 'vectorArrive' => array(P_DB_FIELD => 'fleet_end_galaxy'), |
|
94
|
|
|
// |
|
95
|
|
|
// 'timeDeparture' => array(P_DB_FIELD => 'start_time'), |
|
96
|
|
|
// 'timeArrive' => array(P_DB_FIELD => 'fleet_start_time'), |
|
97
|
|
|
// 'timeComplete' => array(P_DB_FIELD => 'fleet_end_stay'), |
|
98
|
|
|
// 'timeReturn' => array(P_DB_FIELD => 'fleet_end_time'), |
|
99
|
|
|
// |
|
100
|
|
|
// 'units' => array(), |
|
101
|
|
|
// 'isReturning' => array(), |
|
102
|
|
|
// ); |
|
103
|
|
|
|
|
104
|
|
|
public function __construct(\Common\GlobalContainer $gc) { |
|
105
|
|
|
parent::__construct($gc); |
|
106
|
|
|
|
|
107
|
|
|
$this->extendProperties(array( |
|
108
|
|
|
'ownerId' => array(P_DB_FIELD => 'fleet_owner',), |
|
109
|
|
|
'missionType' => array(P_DB_FIELD => 'fleet_mission'), |
|
110
|
|
|
|
|
111
|
|
|
'fleet_amount' => array(P_DB_FIELD => 'fleet_amount'), |
|
112
|
|
|
'fleet_start_planet_id' => array(P_DB_FIELD => 'fleet_start_planet_id'), |
|
113
|
|
|
|
|
114
|
|
|
// 'fleet_start_galaxy' => array(P_DB_FIELD => 'fleet_start_galaxy'), |
|
|
|
|
|
|
115
|
|
|
// 'fleet_start_system' => array(P_DB_FIELD => 'fleet_start_system'), |
|
116
|
|
|
// 'fleet_start_planet' => array(P_DB_FIELD => 'fleet_start_planet'), |
|
117
|
|
|
// 'fleet_start_type' => array(P_DB_FIELD => 'fleet_start_type'), |
|
118
|
|
|
|
|
119
|
|
|
'fleet_end_planet_id' => array(P_DB_FIELD => 'fleet_end_planet_id'), |
|
120
|
|
|
'fleet_target_owner' => array(P_DB_FIELD => 'fleet_target_owner'), |
|
121
|
|
|
|
|
122
|
|
|
// 'fleet_end_galaxy' => array(P_DB_FIELD => 'fleet_end_galaxy'), |
|
|
|
|
|
|
123
|
|
|
// 'fleet_end_system' => array(P_DB_FIELD => 'fleet_end_system'), |
|
124
|
|
|
// 'fleet_end_planet' => array(P_DB_FIELD => 'fleet_end_planet'), |
|
125
|
|
|
// 'fleet_end_type' => array(P_DB_FIELD => 'fleet_end_type'), |
|
126
|
|
|
|
|
127
|
|
|
// 'fleet_resource_metal' => array(P_DB_FIELD => 'fleet_resource_metal'), |
|
|
|
|
|
|
128
|
|
|
// 'fleet_resource_crystal' => array(P_DB_FIELD => 'fleet_resource_crystal'), |
|
129
|
|
|
// 'fleet_resource_deuterium' => array(P_DB_FIELD => 'fleet_resource_deuterium'), |
|
130
|
|
|
|
|
131
|
|
|
'groupId' => array(P_DB_FIELD => 'fleet_group'), |
|
132
|
|
|
'status' => array(P_DB_FIELD => 'fleet_mess'), |
|
133
|
|
|
|
|
134
|
|
|
'vectorDeparture' => array(P_DB_FIELD => 'fleet_start_galaxy'), |
|
135
|
|
|
'vectorArrive' => array(P_DB_FIELD => 'fleet_end_galaxy'), |
|
136
|
|
|
|
|
137
|
|
|
'timeDeparture' => array(P_DB_FIELD => 'start_time'), |
|
138
|
|
|
'timeArrive' => array(P_DB_FIELD => 'fleet_start_time'), |
|
139
|
|
|
'timeComplete' => array(P_DB_FIELD => 'fleet_end_stay'), |
|
140
|
|
|
'timeReturn' => array(P_DB_FIELD => 'fleet_end_time'), |
|
141
|
|
|
|
|
142
|
|
|
'units' => array(), |
|
143
|
|
|
'isReturning' => array(), |
|
144
|
|
|
) |
|
145
|
|
|
); |
|
146
|
|
|
|
|
147
|
|
|
$this->accessors->setAccessor('units', P_CONTAINER_GET, function (V2FleetContainer $that) { |
|
148
|
|
|
if (is_null($units = $that->getDirect('units'))) { |
|
149
|
|
|
$units = new V2UnitList(); |
|
150
|
|
|
$that->setDirect('units', $units); |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
return $units; |
|
154
|
|
|
}); |
|
155
|
|
|
|
|
156
|
|
|
$this->accessors->setAccessor('isReturning', P_CONTAINER_GET, function (V2FleetContainer $that) { |
|
157
|
|
|
return $that->status == 1; |
|
158
|
|
|
}); |
|
159
|
|
|
|
|
160
|
|
|
$this->accessors->setAccessor('vectorDeparture', P_CONTAINER_IMPORT, array($this, 'importVector')); |
|
161
|
|
|
$this->accessors->setAccessor('vectorDeparture', P_CONTAINER_EXPORT, array($this, 'exportVector')); |
|
162
|
|
|
$this->accessors->setAccessor('vectorArrive', P_CONTAINER_IMPORT, array($this, 'importVector')); |
|
163
|
|
|
$this->accessors->setAccessor('vectorArrive', P_CONTAINER_EXPORT, array($this, 'exportVector')); |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
public function importVector(V2FleetContainer $that, $propertyName, $fieldName) { |
|
|
|
|
|
|
167
|
|
|
$prefix = $propertyName == 'vectorDeparture' ? 'fleet_start_' : 'fleet_end_'; |
|
168
|
|
|
$that->$propertyName = new Vector( |
|
169
|
|
|
$that->row[$prefix . 'galaxy'], |
|
170
|
|
|
$that->row[$prefix . 'system'], |
|
171
|
|
|
$that->row[$prefix . 'planet'], |
|
172
|
|
|
$that->row[$prefix . 'type'] |
|
173
|
|
|
); |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
public function exportVector(V2FleetContainer $that, $propertyName, $fieldName) { |
|
|
|
|
|
|
177
|
|
|
$prefix = $propertyName == 'vectorDeparture' ? 'fleet_start_' : 'fleet_end_'; |
|
178
|
|
|
$that->row[$prefix . 'galaxy'] = $that->$propertyName->galaxy; |
|
179
|
|
|
$that->row[$prefix . 'system'] = $that->$propertyName->system; |
|
180
|
|
|
$that->row[$prefix . 'planet'] = $that->$propertyName->planet; |
|
181
|
|
|
$that->row[$prefix . 'type'] = $that->$propertyName->type; |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* @param array $array |
|
186
|
|
|
* |
|
187
|
|
|
* @return V2FleetContainer |
|
188
|
|
|
*/ |
|
189
|
|
|
public function fromArray($array) { |
|
190
|
|
|
/** |
|
191
|
|
|
* @var V2FleetContainer $cFleet |
|
192
|
|
|
*/ |
|
193
|
|
|
$cFleet = parent::fromArray($array); |
|
194
|
|
|
|
|
195
|
|
|
$cFleet->units->load($this->getLocationType($cFleet), $this->getLocationId($cFleet)); |
|
196
|
|
|
|
|
197
|
|
|
foreach (array( |
|
198
|
|
|
RES_METAL => 'fleet_resource_metal', |
|
199
|
|
|
RES_CRYSTAL => 'fleet_resource_crystal', |
|
200
|
|
|
RES_DEUTERIUM => 'fleet_resource_deuterium', |
|
201
|
|
|
) as $resourceId => $fieldName) { |
|
202
|
|
|
$unit = \classSupernova::$gc->unitModel->buildContainer(); |
|
|
|
|
|
|
203
|
|
|
$unit->snId = $resourceId; |
|
204
|
|
|
$unit->level = $array[$fieldName]; |
|
205
|
|
|
$cFleet->units->attach($unit, $resourceId); |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
return $cFleet; |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
} |
|
212
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.