|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file contains functionality relating to a BZFS world file |
|
4
|
|
|
* |
|
5
|
|
|
* @package BZiON\Models |
|
6
|
|
|
* @license https://github.com/allejo/bzion/blob/master/LICENSE.md GNU General Public License Version 3 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* A BZFlag server map |
|
11
|
|
|
* @package BZiON\Models |
|
12
|
|
|
*/ |
|
13
|
|
|
class Map extends AvatarModel implements NamedModel |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* The name of the map |
|
17
|
|
|
* @var string |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $name; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* A description of the map |
|
23
|
|
|
* @var string |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $description; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* The world size of the map |
|
29
|
|
|
* @var int|null |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $world_size; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Whether or not the map is randomly generated each match |
|
35
|
|
|
* @var bool |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $randomly_generated; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* The number of a shots this map has |
|
41
|
|
|
* @var int |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $shot_count; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Whether or not this map has ricochet |
|
47
|
|
|
* @var bool |
|
48
|
|
|
*/ |
|
49
|
|
|
protected $ricochet; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Whether or not this map has jumping |
|
53
|
|
|
* @var bool |
|
54
|
|
|
*/ |
|
55
|
|
|
protected $jumping; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* The game mode this map supports |
|
59
|
|
|
* |
|
60
|
|
|
* @see Map::GAME_MODE_CTF |
|
61
|
|
|
* @see Map::GAME_MODE_AHOD |
|
62
|
|
|
* |
|
63
|
|
|
* @var int |
|
64
|
|
|
*/ |
|
65
|
|
|
protected $game_mode; |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Whether or not this map is currently not in rotation on the official game servers |
|
69
|
|
|
* |
|
70
|
|
|
* @var bool |
|
71
|
|
|
*/ |
|
72
|
|
|
protected $is_inactive; |
|
73
|
|
|
|
|
74
|
|
|
const DELETED_COLUMN = 'is_deleted'; |
|
75
|
|
|
const TABLE = "maps"; |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* The location where avatars will be stored |
|
79
|
|
|
*/ |
|
80
|
|
|
const AVATAR_LOCATION = "/web/assets/imgs/avatars/maps/"; |
|
81
|
|
|
|
|
82
|
|
|
const CREATE_PERMISSION = Permission::ADD_MAP; |
|
83
|
|
|
const EDIT_PERMISSION = Permission::EDIT_MAP; |
|
84
|
|
|
const SOFT_DELETE_PERMISSION = Permission::SOFT_DELETE_MAP; |
|
85
|
|
|
const HARD_DELETE_PERMISSION = Permission::HARD_DELETE_MAP; |
|
86
|
|
|
|
|
87
|
|
|
const GAME_MODE_CTF = 1; |
|
88
|
|
|
const GAME_MODE_AHOD = 2; |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* {@inheritdoc} |
|
92
|
|
|
*/ |
|
93
|
|
|
protected function assignResult($map) |
|
94
|
|
|
{ |
|
95
|
|
|
$this->name = $map['name']; |
|
96
|
|
|
$this->description = $map['description']; |
|
97
|
|
|
$this->world_size = $map['world_size']; |
|
98
|
|
|
$this->randomly_generated = $map['randomly_generated']; |
|
99
|
|
|
$this->alias = $map['alias']; |
|
100
|
|
|
$this->avatar = $map['avatar']; |
|
101
|
|
|
$this->shot_count = $map['shot_count']; |
|
102
|
|
|
$this->ricochet = $map['ricochet']; |
|
103
|
|
|
$this->jumping = $map['jumping']; |
|
104
|
|
|
$this->game_mode = $map['game_mode']; |
|
105
|
|
|
$this->is_inactive = $map['is_inactive']; |
|
106
|
|
|
$this->is_deleted = $map['is_deleted']; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Add a new map |
|
111
|
|
|
* |
|
112
|
|
|
* @param string $name The name of the map |
|
113
|
|
|
* @param string|null $alias The custom API-friendly alias of the map |
|
114
|
|
|
* @param string $description The description of the map |
|
115
|
|
|
* @param string|null $avatar An image of the map |
|
116
|
|
|
* |
|
117
|
|
|
* @since 0.11.0 The `$status` argument has been removed |
|
118
|
|
|
* |
|
119
|
|
|
* @return static |
|
120
|
|
|
*/ |
|
121
|
|
|
public static function addMap($name, $alias = null, $description = '', $avatar = null) |
|
122
|
|
|
{ |
|
123
|
|
|
return self::create(array( |
|
124
|
|
|
'name' => $name, |
|
125
|
|
|
'alias' => $alias, |
|
126
|
|
|
'description' => $description, |
|
127
|
|
|
'avatar' => $avatar, |
|
128
|
|
|
)); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* Get the name of the map |
|
133
|
|
|
* |
|
134
|
|
|
* @return string |
|
135
|
|
|
*/ |
|
136
|
|
|
public function getName() |
|
137
|
|
|
{ |
|
138
|
|
|
return $this->name; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* Get the description of the map |
|
143
|
|
|
* |
|
144
|
|
|
* @return string |
|
145
|
|
|
*/ |
|
146
|
|
|
public function getDescription() |
|
147
|
|
|
{ |
|
148
|
|
|
return $this->description; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* Get the world size of the map |
|
153
|
|
|
* |
|
154
|
|
|
* @return int|null |
|
155
|
|
|
*/ |
|
156
|
|
|
public function getWorldSize() |
|
157
|
|
|
{ |
|
158
|
|
|
return $this->world_size; |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* Get the number of shots this map has |
|
163
|
|
|
* |
|
164
|
|
|
* @return int |
|
165
|
|
|
*/ |
|
166
|
|
|
public function getShotCount() |
|
167
|
|
|
{ |
|
168
|
|
|
return $this->shot_count; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* Get the game mode supported by this map |
|
173
|
|
|
* |
|
174
|
|
|
* @see Map::GAME_MODE_CTF |
|
175
|
|
|
* @see Map::GAME_MODE_AHOD |
|
176
|
|
|
* |
|
177
|
|
|
* @return int |
|
178
|
|
|
*/ |
|
179
|
|
|
public function getGameMode() |
|
180
|
|
|
{ |
|
181
|
|
|
return (int)$this->game_mode; |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* Get whether or not the map is randomly generated each match |
|
186
|
|
|
* |
|
187
|
|
|
* @return bool |
|
188
|
|
|
*/ |
|
189
|
|
|
public function isRandomlyGenerated() |
|
190
|
|
|
{ |
|
191
|
|
|
return (bool)$this->randomly_generated; |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
/** |
|
195
|
|
|
* Get whether or not ricochet is enabled |
|
196
|
|
|
* |
|
197
|
|
|
* @return bool |
|
198
|
|
|
*/ |
|
199
|
|
|
public function isRicochetEnabled() |
|
200
|
|
|
{ |
|
201
|
|
|
return (bool)$this->ricochet; |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* Get whether or not jumping is enabled |
|
206
|
|
|
* |
|
207
|
|
|
* @return bool |
|
208
|
|
|
*/ |
|
209
|
|
|
public function isJumpingEnabled() |
|
210
|
|
|
{ |
|
211
|
|
|
return (bool)$this->jumping; |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
/** |
|
215
|
|
|
* Get whether or not this map is inactive. |
|
216
|
|
|
* |
|
217
|
|
|
* An inactive map is one that is not currently in rotation on official match servers. |
|
218
|
|
|
* |
|
219
|
|
|
* @return bool |
|
220
|
|
|
*/ |
|
221
|
|
|
public function isInactive() |
|
222
|
|
|
{ |
|
223
|
|
|
return (bool)$this->is_inactive; |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
/** |
|
227
|
|
|
* Set the name of the map |
|
228
|
|
|
* |
|
229
|
|
|
* @param string $name The new name |
|
230
|
|
|
* @return self |
|
231
|
|
|
*/ |
|
232
|
|
|
public function setName($name) |
|
233
|
|
|
{ |
|
234
|
|
|
return $this->updateProperty($this->name, 'name', $name); |
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
|
|
/** |
|
238
|
|
|
* Set the description of the map |
|
239
|
|
|
* |
|
240
|
|
|
* @param string $description The new description |
|
241
|
|
|
* @return self |
|
242
|
|
|
*/ |
|
243
|
|
|
public function setDescription($description) |
|
244
|
|
|
{ |
|
245
|
|
|
return $this->updateProperty($this->description, 'description', $description); |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
/** |
|
249
|
|
|
* Set the world size of this map |
|
250
|
|
|
* |
|
251
|
|
|
* @param int $world_size |
|
252
|
|
|
* |
|
253
|
|
|
* @return Map |
|
254
|
|
|
*/ |
|
255
|
|
|
public function setWorldSize($world_size) |
|
256
|
|
|
{ |
|
257
|
|
|
return $this->updateProperty($this->world_size, 'world_size', $world_size); |
|
258
|
|
|
} |
|
259
|
|
|
|
|
260
|
|
|
/** |
|
261
|
|
|
* Set the number of shots this map has |
|
262
|
|
|
* |
|
263
|
|
|
* @param int $shot_count |
|
264
|
|
|
* |
|
265
|
|
|
* @return self |
|
266
|
|
|
*/ |
|
267
|
|
|
public function setShotCount($shot_count) |
|
268
|
|
|
{ |
|
269
|
|
|
return $this->updateProperty($this->shot_count, 'shot_count', $shot_count); |
|
270
|
|
|
} |
|
271
|
|
|
|
|
272
|
|
|
/** |
|
273
|
|
|
* Set whether or not this map is randomly generated |
|
274
|
|
|
* |
|
275
|
|
|
* @param bool $randomly_generated |
|
276
|
|
|
* |
|
277
|
|
|
* @return Map |
|
278
|
|
|
*/ |
|
279
|
|
|
public function setRandomlyGenerated($randomly_generated) |
|
280
|
|
|
{ |
|
281
|
|
|
return $this->updateProperty($this->randomly_generated, 'randomly_generated', $randomly_generated); |
|
282
|
|
|
} |
|
283
|
|
|
|
|
284
|
|
|
/** |
|
285
|
|
|
* Set whether or not this map supports ricochet |
|
286
|
|
|
* |
|
287
|
|
|
* @param bool $ricochet |
|
288
|
|
|
* |
|
289
|
|
|
* @return self |
|
290
|
|
|
*/ |
|
291
|
|
|
public function setRicochetEnabled($ricochet) |
|
292
|
|
|
{ |
|
293
|
|
|
return $this->updateProperty($this->ricochet, 'ricochet', $ricochet); |
|
294
|
|
|
} |
|
295
|
|
|
|
|
296
|
|
|
/** |
|
297
|
|
|
* Set whether or not this map supports jumping |
|
298
|
|
|
* |
|
299
|
|
|
* @param bool $jumping |
|
300
|
|
|
* |
|
301
|
|
|
* @return self |
|
302
|
|
|
*/ |
|
303
|
|
|
public function setJumpingEnabled($jumping) |
|
304
|
|
|
{ |
|
305
|
|
|
return $this->updateProperty($this->jumping, 'jumping', $jumping); |
|
306
|
|
|
} |
|
307
|
|
|
|
|
308
|
|
|
/** |
|
309
|
|
|
* Set the game mode for this map |
|
310
|
|
|
* |
|
311
|
|
|
* @param int $game_mode |
|
312
|
|
|
* |
|
313
|
|
|
* @see Map::GAME_MODE_CTF |
|
314
|
|
|
* @see Map::GAME_MODE_AHOD |
|
315
|
|
|
* |
|
316
|
|
|
* @return Map |
|
317
|
|
|
*/ |
|
318
|
|
|
public function setGameMode($game_mode) |
|
319
|
|
|
{ |
|
320
|
|
|
return $this->updateProperty($this->game_mode, 'game_mode', $game_mode); |
|
321
|
|
|
} |
|
322
|
|
|
|
|
323
|
|
|
/** |
|
324
|
|
|
* Set whether or not this map is in active rotation on official match servers. |
|
325
|
|
|
* |
|
326
|
|
|
* @param bool $inactive |
|
327
|
|
|
* |
|
328
|
|
|
* @return static |
|
329
|
|
|
*/ |
|
330
|
|
|
public function setInactive($inactive) |
|
331
|
|
|
{ |
|
332
|
|
|
return $this->updateProperty($this->is_inactive, 'is_inactive', $inactive); |
|
333
|
|
|
} |
|
334
|
|
|
|
|
335
|
|
|
/** |
|
336
|
|
|
* Get the number of matches played on this map |
|
337
|
|
|
* |
|
338
|
|
|
* @return int |
|
339
|
|
|
*/ |
|
340
|
|
|
public function countMatches() |
|
341
|
|
|
{ |
|
342
|
|
|
return Match::getQueryBuilder() |
|
343
|
|
|
->active() |
|
344
|
|
|
->where('map')->is($this) |
|
345
|
|
|
->count(); |
|
346
|
|
|
} |
|
347
|
|
|
|
|
348
|
|
|
/** |
|
349
|
|
|
* Get a query builder for news |
|
350
|
|
|
* |
|
351
|
|
|
* @throws Exception |
|
352
|
|
|
* |
|
353
|
|
|
* @return QueryBuilderFlex |
|
354
|
|
|
*/ |
|
355
|
|
|
public static function getQueryBuilder() |
|
356
|
|
|
{ |
|
357
|
|
|
return QueryBuilderFlex::createForModel(Map::class) |
|
|
|
|
|
|
358
|
|
|
->setNameColumn('name') |
|
359
|
|
|
; |
|
360
|
|
|
} |
|
361
|
|
|
|
|
362
|
|
|
/** |
|
363
|
|
|
* {@inheritdoc} |
|
364
|
|
|
*/ |
|
365
|
|
|
public static function getActiveModels(QueryBuilderFlex &$qb) |
|
366
|
|
|
{ |
|
367
|
|
|
$qb |
|
368
|
|
|
->whereNot(self::DELETED_COLUMN, '=', self::DELETED_VALUE) |
|
369
|
|
|
->whereNot('is_inactive', '=', true) |
|
370
|
|
|
; |
|
371
|
|
|
|
|
372
|
|
|
return true; |
|
373
|
|
|
} |
|
374
|
|
|
} |
|
375
|
|
|
|
This check looks for accesses to local static members using the fully qualified name instead of
self::.While this is perfectly valid, the fully qualified name of
Certificate::TRIPLEDES_CBCcould just as well be replaced byself::TRIPLEDES_CBC. Referencing local members withself::assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.