1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by Gorlum 17.08.2016 22:07 |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace V2Fleet; |
7
|
|
|
|
8
|
|
|
use Common\V2Location; |
9
|
|
|
use V2Unit\V2UnitList; |
10
|
|
|
use Vector\Vector; |
11
|
|
|
use Entity\KeyedModel; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class V2FleetModel |
15
|
|
|
* |
16
|
|
|
* @method V2FleetContainer buildContainer() |
17
|
|
|
* @method V2FleetContainer loadById(mixed $dbId) |
18
|
|
|
* |
19
|
|
|
* @package V2Fleet |
20
|
|
|
*/ |
21
|
|
|
class V2FleetModel extends KeyedModel { |
22
|
|
|
protected $location; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Name of table for this entity |
26
|
|
|
* |
27
|
|
|
* @var string $tableName |
28
|
|
|
*/ |
29
|
|
|
protected $tableName = 'fleets'; |
30
|
|
|
/** |
31
|
|
|
* Name of key field field in this table |
32
|
|
|
* |
33
|
|
|
* @var string $idFieldName |
34
|
|
|
*/ |
35
|
|
|
protected $idFieldName = 'fleet_id'; |
36
|
|
|
|
37
|
|
|
protected $exceptionClass = 'Entity\EntityException'; |
38
|
|
|
protected $entityContainerClass = 'V2Fleet\V2FleetContainer'; |
39
|
|
|
|
40
|
|
|
public function __construct(\Common\GlobalContainer $gc) { |
41
|
|
|
parent::__construct($gc); |
42
|
|
|
|
43
|
|
|
$this->extendProperties(array( |
44
|
|
|
'ownerId' => array(P_DB_FIELD => 'fleet_owner',), |
45
|
|
|
'missionType' => array(P_DB_FIELD => 'fleet_mission'), |
46
|
|
|
|
47
|
|
|
'fleet_amount' => array(P_DB_FIELD => 'fleet_amount'), |
48
|
|
|
'fleet_start_planet_id' => array(P_DB_FIELD => 'fleet_start_planet_id'), |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
'fleet_end_planet_id' => array(P_DB_FIELD => 'fleet_end_planet_id'), |
52
|
|
|
'fleet_target_owner' => array(P_DB_FIELD => 'fleet_target_owner'), |
53
|
|
|
|
54
|
|
|
// 'fleet_start_galaxy' => array(P_DB_FIELD => 'fleet_start_galaxy'), |
|
|
|
|
55
|
|
|
// 'fleet_start_system' => array(P_DB_FIELD => 'fleet_start_system'), |
56
|
|
|
// 'fleet_start_planet' => array(P_DB_FIELD => 'fleet_start_planet'), |
57
|
|
|
// 'fleet_start_type' => array(P_DB_FIELD => 'fleet_start_type'), |
58
|
|
|
// 'fleet_end_galaxy' => array(P_DB_FIELD => 'fleet_end_galaxy'), |
59
|
|
|
// 'fleet_end_system' => array(P_DB_FIELD => 'fleet_end_system'), |
60
|
|
|
// 'fleet_end_planet' => array(P_DB_FIELD => 'fleet_end_planet'), |
61
|
|
|
// 'fleet_end_type' => array(P_DB_FIELD => 'fleet_end_type'), |
62
|
|
|
// 'fleet_resource_metal' => array(P_DB_FIELD => 'fleet_resource_metal'), |
63
|
|
|
// 'fleet_resource_crystal' => array(P_DB_FIELD => 'fleet_resource_crystal'), |
64
|
|
|
// 'fleet_resource_deuterium' => array(P_DB_FIELD => 'fleet_resource_deuterium'), |
65
|
|
|
|
66
|
|
|
'groupId' => array(P_DB_FIELD => 'fleet_group'), |
67
|
|
|
'status' => array(P_DB_FIELD => 'fleet_mess'), |
68
|
|
|
|
69
|
|
|
'vectorDeparture' => array(P_DB_FIELD => 'fleet_start_galaxy'), |
70
|
|
|
'vectorArrive' => array(P_DB_FIELD => 'fleet_end_galaxy'), |
71
|
|
|
|
72
|
|
|
'timeDeparture' => array(P_DB_FIELD => 'start_time'), |
73
|
|
|
'timeArrive' => array(P_DB_FIELD => 'fleet_start_time'), |
74
|
|
|
'timeComplete' => array(P_DB_FIELD => 'fleet_end_stay'), |
75
|
|
|
'timeReturn' => array(P_DB_FIELD => 'fleet_end_time'), |
76
|
|
|
|
77
|
|
|
'units' => array(), |
78
|
|
|
'isReturning' => array(), |
79
|
|
|
) |
80
|
|
|
); |
81
|
|
|
|
82
|
|
|
$this->accessors->setAccessor('location', P_CONTAINER_GET, function (V2FleetContainer $that) { |
83
|
|
|
if (is_null($location = $that->getDirect('location'))) { |
84
|
|
|
$location = new V2Location(LOC_FLEET); |
85
|
|
|
$that->setDirect('location', $location); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return $location; |
89
|
|
|
}); |
90
|
|
|
|
91
|
|
|
$this->accessors->setAccessor('dbId', P_CONTAINER_SET, function (V2FleetContainer $that, $value) { |
92
|
|
|
$that->setDirect('dbId', $value); |
93
|
|
|
$that->location->setLocationId($value); |
94
|
|
|
}); |
95
|
|
|
|
96
|
|
|
$this->accessors->setAccessor('ownerId', P_CONTAINER_SET, function (V2FleetContainer $that, $value) { |
97
|
|
|
$that->setDirect('ownerId', $value); |
98
|
|
|
$that->location->setLocationPlayerId($value); |
99
|
|
|
}); |
100
|
|
|
|
101
|
|
|
$this->accessors->setAccessor('vectorDeparture', P_CONTAINER_IMPORT, array($this, 'importVector')); |
102
|
|
|
$this->accessors->setAccessor('vectorDeparture', P_CONTAINER_EXPORT, array($this, 'exportVector')); |
103
|
|
|
$this->accessors->setAccessor('vectorArrive', P_CONTAINER_IMPORT, array($this, 'importVector')); |
104
|
|
|
$this->accessors->setAccessor('vectorArrive', P_CONTAINER_EXPORT, array($this, 'exportVector')); |
105
|
|
|
|
106
|
|
|
|
107
|
|
|
$this->accessors->setAccessor('units', P_CONTAINER_GET, function (V2FleetContainer $that) { |
108
|
|
|
if (is_null($units = $that->getDirect('units'))) { |
109
|
|
|
$units = new V2UnitList(); |
110
|
|
|
$that->setDirect('units', $units); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
return $units; |
114
|
|
|
}); |
115
|
|
|
|
116
|
|
|
$this->accessors->setAccessor('isReturning', P_CONTAINER_GET, function (V2FleetContainer $that) { |
117
|
|
|
return $that->status == FLEET_FLAG_RETURNING; |
118
|
|
|
}); |
119
|
|
|
|
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function importVector(V2FleetContainer $that, $propertyName, $fieldName) { |
|
|
|
|
123
|
|
|
$prefix = $propertyName == 'vectorDeparture' ? 'fleet_start_' : 'fleet_end_'; |
124
|
|
|
$that->$propertyName = new Vector( |
125
|
|
|
$that->row[$prefix . 'galaxy'], |
126
|
|
|
$that->row[$prefix . 'system'], |
127
|
|
|
$that->row[$prefix . 'planet'], |
128
|
|
|
$that->row[$prefix . 'type'] |
129
|
|
|
); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function exportVector(V2FleetContainer $that, $propertyName, $fieldName) { |
|
|
|
|
133
|
|
|
$prefix = $propertyName == 'vectorDeparture' ? 'fleet_start_' : 'fleet_end_'; |
134
|
|
|
$that->row[$prefix . 'galaxy'] = $that->$propertyName->galaxy; |
135
|
|
|
$that->row[$prefix . 'system'] = $that->$propertyName->system; |
136
|
|
|
$that->row[$prefix . 'planet'] = $that->$propertyName->planet; |
137
|
|
|
$that->row[$prefix . 'type'] = $that->$propertyName->type; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @param array $array |
142
|
|
|
* |
143
|
|
|
* @return V2FleetContainer |
144
|
|
|
*/ |
145
|
|
|
public function fromArray($array) { |
146
|
|
|
/** |
147
|
|
|
* @var V2FleetContainer $cFleet |
148
|
|
|
*/ |
149
|
|
|
$cFleet = parent::fromArray($array); |
150
|
|
|
|
151
|
|
|
$cFleet->units->load($cFleet->location); |
152
|
|
|
|
153
|
|
|
foreach (array( |
154
|
|
|
RES_METAL => 'fleet_resource_metal', |
155
|
|
|
RES_CRYSTAL => 'fleet_resource_crystal', |
156
|
|
|
RES_DEUTERIUM => 'fleet_resource_deuterium', |
157
|
|
|
) as $resourceId => $fieldName) { |
158
|
|
|
$unit = \classSupernova::$gc->unitModel->buildContainer(); |
|
|
|
|
159
|
|
|
$unit->snId = $resourceId; |
160
|
|
|
$unit->level = $array[$fieldName]; |
161
|
|
|
$cFleet->units->attach($unit, $resourceId); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
return $cFleet; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
} |
168
|
|
|
|
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.