|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Class Unit |
|
5
|
|
|
* |
|
6
|
|
|
* @property int $unitId |
|
7
|
|
|
* @property int $count |
|
8
|
|
|
* @method int getCount() - TODO - DEPRECATED - не существует, но используется в UBE |
|
9
|
|
|
* @method int getUnitId() |
|
10
|
|
|
* @method int getType() |
|
11
|
|
|
* @method int getTimeStart() |
|
12
|
|
|
* @method int getTimeFinish() |
|
13
|
|
|
* @see Unit::__get() |
|
14
|
|
|
* |
|
15
|
|
|
*/ |
|
16
|
|
|
class Unit extends DBRowLocation { |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Type of this location |
|
20
|
|
|
* |
|
21
|
|
|
* @var int $locationType |
|
22
|
|
|
*/ |
|
23
|
|
|
protected static $locationType = LOC_UNIT_NUMERIC; |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
// DBRow inheritance ************************************************************************************************* |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Table name in DB |
|
30
|
|
|
* |
|
31
|
|
|
* @var string |
|
32
|
|
|
*/ |
|
33
|
|
|
protected static $_table = 'unit'; |
|
34
|
|
|
/** |
|
35
|
|
|
* Name of ID field in DB |
|
36
|
|
|
* |
|
37
|
|
|
* @var string |
|
38
|
|
|
*/ |
|
39
|
|
|
protected static $_dbIdFieldName = 'unit_id'; |
|
40
|
|
|
/** |
|
41
|
|
|
* DB_ROW to Class translation scheme |
|
42
|
|
|
* |
|
43
|
|
|
* @var array |
|
44
|
|
|
*/ |
|
45
|
|
|
protected static $_properties = array( |
|
46
|
|
|
'dbId' => array( |
|
47
|
|
|
P_DB_FIELD => 'unit_id', |
|
48
|
|
|
), |
|
49
|
|
|
|
|
50
|
|
|
// Location data is taken from container |
|
51
|
|
|
'playerOwnerId' => array( |
|
52
|
|
|
P_DB_FIELD => 'unit_player_id', |
|
53
|
|
|
P_METHOD_INJECT => 'injectLocation', |
|
54
|
|
|
P_READ_ONLY => true, |
|
55
|
|
|
), |
|
56
|
|
|
// 'locationType' => array( |
|
|
|
|
|
|
57
|
|
|
// P_DB_FIELD => 'unit_location_type', |
|
58
|
|
|
// P_READ_ONLY => true, |
|
59
|
|
|
// ), |
|
60
|
|
|
// 'locationDbId' => array( |
|
61
|
|
|
// P_DB_FIELD => 'unit_location_id', |
|
62
|
|
|
// P_READ_ONLY => true, |
|
63
|
|
|
// ), |
|
64
|
|
|
|
|
65
|
|
|
'type' => array( |
|
66
|
|
|
P_DB_FIELD => 'unit_type', |
|
67
|
|
|
P_FUNC_INPUT => 'intval', |
|
68
|
|
|
), |
|
69
|
|
|
'unitId' => array( |
|
70
|
|
|
P_DB_FIELD => 'unit_snid', |
|
71
|
|
|
P_METHOD_SET => 'setUnitId', |
|
72
|
|
|
P_FUNC_INPUT => 'intval', |
|
73
|
|
|
), |
|
74
|
|
|
'count' => array( |
|
75
|
|
|
P_DB_FIELD => 'unit_level', |
|
76
|
|
|
P_FUNC_INPUT => 'floatval', |
|
77
|
|
|
), |
|
78
|
|
|
|
|
79
|
|
|
'timeStart' => array( |
|
80
|
|
|
P_DB_FIELD => 'unit_time_start', |
|
81
|
|
|
P_FUNC_INPUT => 'sqlStringToUnixTimeStamp', |
|
82
|
|
|
P_FUNC_OUTPUT => 'unixTimeStampToSqlString', |
|
83
|
|
|
), |
|
84
|
|
|
'timeFinish' => array( |
|
85
|
|
|
P_DB_FIELD => 'unit_time_finish', |
|
86
|
|
|
P_FUNC_INPUT => 'sqlStringToUnixTimeStamp', |
|
87
|
|
|
P_FUNC_OUTPUT => 'unixTimeStampToSqlString', |
|
88
|
|
|
), |
|
89
|
|
|
); |
|
90
|
|
|
|
|
91
|
|
|
// New statics ******************************************************************************************************* |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @var bool |
|
95
|
|
|
*/ |
|
96
|
|
|
protected static $_is_static_init = false; |
|
97
|
|
|
/** |
|
98
|
|
|
* @var string |
|
99
|
|
|
*/ |
|
100
|
|
|
protected static $_sn_group_name = ''; |
|
101
|
|
|
/** |
|
102
|
|
|
* @var array |
|
103
|
|
|
*/ |
|
104
|
|
|
protected static $_group_unit_id_list = array(); |
|
105
|
|
|
|
|
106
|
|
|
|
|
107
|
|
|
// Properties from fields ******************************************************************************************** |
|
108
|
|
|
protected $_unitId = 0; |
|
109
|
|
|
// TODO - Type is extracted on-the-fly from $info |
|
110
|
|
|
protected $_type = 0; |
|
111
|
|
|
|
|
112
|
|
|
protected $_count = 0; |
|
113
|
|
|
|
|
114
|
|
|
// Internal properties *********************************************************************************************** |
|
115
|
|
|
|
|
116
|
|
|
protected $_timeStart = 0; |
|
117
|
|
|
protected $_timeFinish = 0; |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* Passport info per unit |
|
121
|
|
|
* |
|
122
|
|
|
* @var array $info |
|
123
|
|
|
*/ |
|
124
|
|
|
public $info = array(); |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* @var Bonus $unit_bonus |
|
128
|
|
|
*/ |
|
129
|
|
|
public $unit_bonus = null; |
|
130
|
|
|
|
|
131
|
|
|
|
|
132
|
|
|
// DBRow inheritance ************************************************************************************************* |
|
133
|
|
|
|
|
134
|
|
|
public function __construct() { |
|
135
|
|
|
parent::__construct(); |
|
136
|
|
|
$this->unit_bonus = new Bonus(); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
// TODO - пустой так же если нет locatedAt |
|
140
|
|
|
// или DBID |
|
141
|
|
|
// или locationType == LOC_NONE |
|
142
|
|
|
// Но тогда оверврайт в UBEUnit наверное |
|
143
|
|
|
public function isEmpty() { |
|
144
|
|
|
return $this->_count <= 0 || $this->getLocatedAtDbId() == 0 || $this->getLocatedAtType() == LOC_NONE; |
|
|
|
|
|
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
|
|
148
|
|
|
|
|
149
|
|
|
// New statics ******************************************************************************************************* |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* Статический иницилизатор. ДОЛЖЕН БЫТЬ ВЫЗВАН ПЕРЕД ИСПОЛЬЗВОАНИЕМ КЛАССА! |
|
153
|
|
|
* |
|
154
|
|
|
* @param string $group_name |
|
155
|
|
|
*/ |
|
156
|
|
|
public static function _init($group_name = '') { |
|
157
|
|
|
if(static::$_is_static_init) { |
|
158
|
|
|
return; |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
if($group_name) { |
|
162
|
|
|
static::$_sn_group_name = $group_name; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
if(static::$_sn_group_name) { |
|
166
|
|
|
static::$_group_unit_id_list = sn_get_groups(static::$_sn_group_name); |
|
|
|
|
|
|
167
|
|
|
empty(static::$_group_unit_id_list) ? static::$_group_unit_id_list = array() : false; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* Проверяет - принадлежит ли указанный ID юнита данной группе |
|
174
|
|
|
* |
|
175
|
|
|
* @param int $unit_id |
|
176
|
|
|
* |
|
177
|
|
|
* @return bool |
|
178
|
|
|
*/ |
|
179
|
|
|
public static function is_in_group($unit_id) { |
|
180
|
|
|
return isset(static::$_group_unit_id_list[$unit_id]); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
|
|
184
|
|
|
// Properties from fields ******************************************************************************************** |
|
185
|
|
|
|
|
186
|
|
|
public function setUnitId($unitId) { |
|
187
|
|
|
// TODO - Reset combat stats?? |
|
188
|
|
|
$this->_unitId = $unitId; |
|
189
|
|
|
|
|
190
|
|
|
if($this->_unitId) { |
|
191
|
|
|
$this->info = get_unit_param($this->_unitId); |
|
|
|
|
|
|
192
|
|
|
$this->_type = $this->info[P_UNIT_TYPE]; |
|
193
|
|
|
} else { |
|
194
|
|
|
$this->info = array(); |
|
195
|
|
|
$this->_type = 0; |
|
196
|
|
|
} |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
protected function setCount($value) { |
|
200
|
|
|
// TODO - Reset combat stats?? |
|
201
|
|
|
if($value < 0) { |
|
202
|
|
|
classSupernova::$debug->error('Can not set Unit::$count to negative value'); |
|
203
|
|
|
} |
|
204
|
|
|
$this->_count = $value; |
|
205
|
|
|
// $this->propertiesChanged['count'] = true; |
|
|
|
|
|
|
206
|
|
|
|
|
207
|
|
|
return $this->_count; |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
/** |
|
211
|
|
|
* @param int $value |
|
212
|
|
|
* |
|
213
|
|
|
* @return int |
|
214
|
|
|
*/ |
|
215
|
|
|
// TODO - some calcs ?????? |
|
|
|
|
|
|
216
|
|
|
public function adjustCount($value) { |
|
217
|
|
|
$this->count += $value; |
|
218
|
|
|
$this->propertiesAdjusted['count'] += $value; |
|
219
|
|
|
|
|
220
|
|
|
return $this->_count; |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
/** |
|
224
|
|
|
* Extracts resources value from db_row |
|
225
|
|
|
* |
|
226
|
|
|
* @param array $db_row |
|
227
|
|
|
* |
|
228
|
|
|
* @internal param Unit $that |
|
229
|
|
|
* @version 41a6.71 |
|
230
|
|
|
*/ |
|
231
|
|
|
protected function injectLocation(array &$db_row) { |
|
232
|
|
|
$db_row['unit_player_id'] = $this->getPlayerOwnerId(); |
|
233
|
|
|
$db_row['unit_location_type'] = $this->getLocatedAtType(); |
|
234
|
|
|
$db_row['unit_location_id'] = $this->getLocatedAtDbId(); |
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
|
|
// TODO - __GET, __SET, __IS_NULL, __EMPTY - короче, магметоды |
|
238
|
|
|
// А еще нужны методы для вытаскивания ЧИСТОГО и БОНУСНОГО значений |
|
239
|
|
|
// Магметоды вытаскивают чистые значения. А если нам нужны бонусные - вытаскивают их спецметоды ??? Хотя бонусные вроде используются чаще... |
|
240
|
|
|
// Наоборот - для совместимости с MRC_GET_LEVEL() |
|
241
|
|
|
// Да не - чистые. Там уже всё совсем будет иначе и совместимост с MRC_GET_LEVEL() не требуется |
|
242
|
|
|
|
|
243
|
|
|
|
|
244
|
|
|
// TODO - DEBUG |
|
245
|
|
|
public function zeroDbId() { |
|
246
|
|
|
$this->_dbId = 0; |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
/** |
|
250
|
|
|
* Lock all fields that belongs to operation |
|
251
|
|
|
* |
|
252
|
|
|
* @param DBLock $dbId - Object that accumulates locks |
|
253
|
|
|
* |
|
254
|
|
|
*/ |
|
255
|
|
|
public function dbGetLockById($dbId) { |
|
256
|
|
|
// "LEFT JOIN {{users}} as u on u.id = {{unit}}.unit_player_id"; |
|
257
|
|
|
$dbId->addPlayerLock('unit', 'unit_player_id'); |
|
258
|
|
|
// TODO: Implement dbGetLock() method. |
|
259
|
|
|
} |
|
260
|
|
|
|
|
261
|
|
|
} |
|
262
|
|
|
|
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.