|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace eXpansion\Bundle\WidgetBestRecords\Plugins; |
|
4
|
|
|
|
|
5
|
|
|
use eXpansion\Bundle\Dedimania\DataProviders\Listener\DedimaniaDataListener; |
|
6
|
|
|
use eXpansion\Bundle\Dedimania\Structures\DedimaniaPlayer; |
|
7
|
|
|
use eXpansion\Bundle\Dedimania\Structures\DedimaniaRecord; |
|
8
|
|
|
use eXpansion\Bundle\LocalRecords\DataProviders\Listener\RecordsDataListener; |
|
9
|
|
|
use eXpansion\Bundle\LocalRecords\Model\Record; |
|
10
|
|
|
use eXpansion\Bundle\WidgetBestRecords\Plugins\Gui\BestRecordsWidget; |
|
11
|
|
|
use eXpansion\Bundle\WidgetBestRecords\Plugins\Gui\PBWidget; |
|
12
|
|
|
use eXpansion\Framework\Core\Model\UserGroups\Group; |
|
13
|
|
|
use eXpansion\Framework\Core\Plugins\StatusAwarePluginInterface; |
|
14
|
|
|
use eXpansion\Framework\Core\Services\DedicatedConnection\Factory; |
|
15
|
|
|
use eXpansion\Framework\Core\Storage\Data\Player; |
|
16
|
|
|
use eXpansion\Framework\Core\Storage\MapStorage; |
|
17
|
|
|
use eXpansion\Framework\Core\Storage\PlayerStorage; |
|
18
|
|
|
use eXpansion\Framework\GameManiaplanet\DataProviders\Listener\ListenerInterfaceMpLegacyPlayer; |
|
19
|
|
|
use eXpansion\Framework\GameManiaplanet\DataProviders\Listener\ListenerInterfaceMpScriptMatch; |
|
20
|
|
|
|
|
21
|
|
|
class BestRecords implements StatusAwarePluginInterface, RecordsDataListener, DedimaniaDataListener, ListenerInterfaceMpScriptMatch, ListenerInterfaceMpLegacyPlayer |
|
22
|
|
|
{ |
|
23
|
|
|
/** @var Factory */ |
|
24
|
|
|
protected $factory; |
|
25
|
|
|
/** |
|
26
|
|
|
* @var PlayerStorage |
|
27
|
|
|
*/ |
|
28
|
|
|
private $playerStorage; |
|
29
|
|
|
/** |
|
30
|
|
|
* @var BestRecordsWidget |
|
31
|
|
|
*/ |
|
32
|
|
|
private $widget; |
|
33
|
|
|
/** |
|
34
|
|
|
* @var Group |
|
35
|
|
|
*/ |
|
36
|
|
|
private $players; |
|
37
|
|
|
|
|
38
|
|
|
/** @var Group[] */ |
|
39
|
|
|
private $widgetGroups; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var Group |
|
43
|
|
|
*/ |
|
44
|
|
|
private $allPlayers; |
|
45
|
|
|
/** |
|
46
|
|
|
* @var PBWidget |
|
47
|
|
|
*/ |
|
48
|
|
|
private $PBWidget; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @var MapStorage |
|
52
|
|
|
*/ |
|
53
|
|
|
private $mapStorage; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Debug constructor. |
|
57
|
|
|
* |
|
58
|
|
|
* @param MapStorage $mapStorage |
|
59
|
|
|
* @param PlayerStorage $playerStorage |
|
60
|
|
|
* @param BestRecordsWidget $widget |
|
61
|
|
|
* @param PBWidget $PBWidget |
|
62
|
|
|
* @param Group $players |
|
63
|
|
|
* @param Group $allPlayers |
|
64
|
|
|
*/ |
|
65
|
|
View Code Duplication |
public function __construct( |
|
|
|
|
|
|
66
|
|
|
MapStorage $mapStorage, |
|
67
|
|
|
PlayerStorage $playerStorage, |
|
68
|
|
|
BestRecordsWidget $widget, |
|
69
|
|
|
PBWidget $PBWidget, |
|
70
|
|
|
Group $players, |
|
71
|
|
|
Group $allPlayers |
|
72
|
|
|
) { |
|
73
|
|
|
$this->playerStorage = $playerStorage; |
|
74
|
|
|
$this->widget = $widget; |
|
75
|
|
|
$this->players = $players; |
|
76
|
|
|
$this->allPlayers = $allPlayers; |
|
77
|
|
|
$this->PBWidget = $PBWidget; |
|
78
|
|
|
$this->mapStorage = $mapStorage; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Set the status of the plugin |
|
83
|
|
|
* |
|
84
|
|
|
* @param boolean $status |
|
85
|
|
|
* |
|
86
|
|
|
* @return void |
|
87
|
|
|
*/ |
|
88
|
|
|
public function setStatus($status) |
|
89
|
|
|
{ |
|
90
|
|
|
if ($status) { |
|
91
|
|
|
$map = $this->mapStorage->getCurrentMap(); |
|
92
|
|
|
$this->setAuthorTime($map->authorTime); |
|
93
|
|
|
|
|
94
|
|
|
foreach ($this->allPlayers->getLogins() as $login) { |
|
95
|
|
|
$this->widgetGroups[$login] = $this->PBWidget->create($login); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
$this->widget->create($this->allPlayers); |
|
99
|
|
|
} else { |
|
100
|
|
|
$this->widget->destroy($this->allPlayers); |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Called when local records are loaded. |
|
106
|
|
|
* |
|
107
|
|
|
* @param Record[] $records |
|
108
|
|
|
* @throws \Propel\Runtime\Exception\PropelException |
|
109
|
|
|
*/ |
|
110
|
|
|
public function onLocalRecordsLoaded($records) |
|
111
|
|
|
{ |
|
112
|
|
|
if (count($records) > 0) { |
|
113
|
|
|
$this->widget->setLocalRecord($records[0]); |
|
114
|
|
|
} else { |
|
115
|
|
|
$this->widget->setLocalRecord(null); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
foreach ($records as $record) { |
|
119
|
|
|
$login = $record->getPlayer()->getLogin(); |
|
120
|
|
|
// set records to widget |
|
121
|
|
|
$this->PBWidget->setPB($login, $record->getScore()); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
// update for all players on server |
|
125
|
|
|
$this->updateAuthorPB(null); |
|
126
|
|
|
$this->widget->update($this->allPlayers); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* Called when a player finishes map for the very first time (basically first record). |
|
131
|
|
|
* |
|
132
|
|
|
* @param Record $record |
|
133
|
|
|
* @param Record[] $records |
|
134
|
|
|
* @param $position |
|
135
|
|
|
* @throws \Propel\Runtime\Exception\PropelException |
|
136
|
|
|
*/ |
|
137
|
|
|
public function onLocalRecordsFirstRecord(Record $record, $records, $position) |
|
138
|
|
|
{ |
|
139
|
|
|
$this->widget->setLocalRecord($record); |
|
140
|
|
|
$this->widget->update($this->allPlayers); |
|
141
|
|
|
$this->updateAuthorPB($record->getPlayer()->getLogin(), $record->getScore()); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* Called when a player finishes map and does same time as before. |
|
146
|
|
|
* |
|
147
|
|
|
* @param Record $record |
|
148
|
|
|
* @param Record $oldRecord |
|
149
|
|
|
* @param Record[] $records |
|
150
|
|
|
* @throws \Propel\Runtime\Exception\PropelException |
|
151
|
|
|
*/ |
|
152
|
|
|
public function onLocalRecordsSameScore(Record $record, Record $oldRecord, $records) |
|
153
|
|
|
{ |
|
154
|
|
|
$this->updateAuthorPB($record->getPlayer()->getLogin(), $record->getScore()); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* Called when a player finishes map with better time and has better position. |
|
159
|
|
|
* |
|
160
|
|
|
* @param Record $record |
|
161
|
|
|
* @param Record $oldRecord |
|
162
|
|
|
* @param Record[] $records |
|
163
|
|
|
* @param int $position |
|
164
|
|
|
* @param int $oldPosition |
|
165
|
|
|
* @throws \Propel\Runtime\Exception\PropelException |
|
166
|
|
|
*/ |
|
167
|
|
View Code Duplication |
public function onLocalRecordsBetterPosition(Record $record, Record $oldRecord, $records, $position, $oldPosition) |
|
|
|
|
|
|
168
|
|
|
{ |
|
169
|
|
|
if ($position == 1) { |
|
170
|
|
|
$this->widget->setLocalRecord($record); |
|
171
|
|
|
$this->widget->update($this->allPlayers); |
|
172
|
|
|
} |
|
173
|
|
|
$this->updateAuthorPB($record->getPlayer()->getLogin(), $record->getScore()); |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* Called when a player finishes map with better time but keeps same position. |
|
178
|
|
|
* |
|
179
|
|
|
* @param Record $record |
|
180
|
|
|
* @param Record $oldRecord |
|
181
|
|
|
* @param Record[] $records |
|
182
|
|
|
* @param $position |
|
183
|
|
|
* @throws \Propel\Runtime\Exception\PropelException |
|
184
|
|
|
*/ |
|
185
|
|
View Code Duplication |
public function onLocalRecordsSamePosition(Record $record, Record $oldRecord, $records, $position) |
|
|
|
|
|
|
186
|
|
|
{ |
|
187
|
|
|
if ($position == 1) { |
|
188
|
|
|
$this->widget->setLocalRecord($record); |
|
189
|
|
|
$this->widget->update($this->allPlayers); |
|
190
|
|
|
} |
|
191
|
|
|
$this->updateAuthorPB($record->getPlayer()->getLogin(), $record->getScore()); |
|
192
|
|
|
|
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* @param mixed $authorTime |
|
197
|
|
|
*/ |
|
198
|
|
|
public function setAuthorTime($authorTime) |
|
199
|
|
|
{ |
|
200
|
|
|
$this->PBWidget->setAuthorTime($authorTime); |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
private function updateAuthorPB($login, $pbTime = null) |
|
204
|
|
|
{ |
|
205
|
|
|
if ($login == null) { |
|
206
|
|
|
foreach ($this->widgetGroups as $group) { |
|
207
|
|
|
if ($pbTime) { |
|
208
|
|
|
$this->PBWidget->setPB($login, $pbTime); |
|
209
|
|
|
} |
|
210
|
|
|
$this->PBWidget->update($group); |
|
211
|
|
|
} |
|
212
|
|
|
} else { |
|
213
|
|
|
if ($pbTime) { |
|
214
|
|
|
$this->PBWidget->setPB($login, $pbTime); |
|
215
|
|
|
} |
|
216
|
|
|
if (isset($this->widgetGroups[$login])) { |
|
217
|
|
|
$this->PBWidget->update($this->widgetGroups[$login]); |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
} |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
/** |
|
224
|
|
|
* Called when dedimania records are loaded. |
|
225
|
|
|
* |
|
226
|
|
|
* @param DedimaniaRecord[] $records |
|
227
|
|
|
*/ |
|
228
|
|
|
public function onDedimaniaRecordsLoaded($records) |
|
229
|
|
|
{ |
|
230
|
|
|
if (count($records) > 0) { |
|
231
|
|
|
$this->widget->setDedimaniaRecord($records[0]); |
|
232
|
|
|
} else { |
|
233
|
|
|
$this->widget->setDedimaniaRecord(null); |
|
234
|
|
|
} |
|
235
|
|
|
$this->widget->update($this->allPlayers); |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
/** |
|
239
|
|
|
* @param DedimaniaRecord $record |
|
240
|
|
|
* @param DedimaniaRecord $oldRecord |
|
241
|
|
|
* @param DedimaniaRecord[] $records |
|
242
|
|
|
* @param int $position |
|
243
|
|
|
* @param int $oldPosition |
|
244
|
|
|
* @return void |
|
245
|
|
|
*/ |
|
246
|
|
|
public function onDedimaniaRecordsUpdate( |
|
247
|
|
|
DedimaniaRecord $record, |
|
248
|
|
|
DedimaniaRecord $oldRecord, |
|
249
|
|
|
$records, |
|
250
|
|
|
$position, |
|
251
|
|
|
$oldPosition |
|
252
|
|
|
) { |
|
253
|
|
|
if ($position == 1) { |
|
254
|
|
|
$this->widget->setDedimaniaRecord($record); |
|
255
|
|
|
$this->widget->update($this->allPlayers); |
|
256
|
|
|
} |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
/** |
|
260
|
|
|
* @param DedimaniaPlayer $player |
|
261
|
|
|
* @return void |
|
262
|
|
|
*/ |
|
263
|
|
|
public function onDedimaniaPlayerConnect(DedimaniaPlayer $player) |
|
264
|
|
|
{ |
|
265
|
|
|
// |
|
266
|
|
|
} |
|
267
|
|
|
|
|
268
|
|
|
/** |
|
269
|
|
|
* @param DedimaniaPlayer $player |
|
270
|
|
|
* @return void |
|
271
|
|
|
*/ |
|
272
|
|
|
public function onDedimaniaPlayerDisconnect(DedimaniaPlayer $player) |
|
273
|
|
|
{ |
|
274
|
|
|
// |
|
275
|
|
|
} |
|
276
|
|
|
|
|
277
|
|
|
/** |
|
278
|
|
|
* @param Player $player |
|
279
|
|
|
* @return void |
|
280
|
|
|
*/ |
|
281
|
|
|
public function onPlayerConnect(Player $player) |
|
282
|
|
|
{ |
|
283
|
|
|
$this->widgetGroups[$player->getLogin()] = $this->PBWidget->create($player->getLogin()); |
|
284
|
|
|
} |
|
285
|
|
|
|
|
286
|
|
|
/** |
|
287
|
|
|
* @param Player $player |
|
288
|
|
|
* @param string $disconnectionReason |
|
289
|
|
|
* @return void |
|
290
|
|
|
*/ |
|
291
|
|
|
public function onPlayerDisconnect(Player $player, $disconnectionReason) |
|
292
|
|
|
{ |
|
293
|
|
|
if (isset($this->widgetGroups[$player->getLogin()])) { |
|
294
|
|
|
unset($this->widgetGroups[$player->getLogin()]); |
|
295
|
|
|
} |
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
/** |
|
299
|
|
|
* @param Player $oldPlayer |
|
300
|
|
|
* @param Player $player |
|
301
|
|
|
* @return void |
|
302
|
|
|
*/ |
|
303
|
|
|
public function onPlayerInfoChanged(Player $oldPlayer, Player $player) |
|
304
|
|
|
{ |
|
305
|
|
|
// |
|
306
|
|
|
} |
|
307
|
|
|
|
|
308
|
|
|
/** |
|
309
|
|
|
* @param Player $oldPlayer |
|
310
|
|
|
* @param Player $player |
|
311
|
|
|
* @return void |
|
312
|
|
|
*/ |
|
313
|
|
|
public function onPlayerAlliesChanged(Player $oldPlayer, Player $player) |
|
314
|
|
|
{ |
|
315
|
|
|
// |
|
316
|
|
|
} |
|
317
|
|
|
|
|
318
|
|
|
/** |
|
319
|
|
|
* Callback sent when the "StartMatch" section start. |
|
320
|
|
|
* |
|
321
|
|
|
* @param int $count Each time this section is played, this number is incremented by one |
|
322
|
|
|
* @param int $time Server time when the callback was sent |
|
323
|
|
|
* |
|
324
|
|
|
* @return void |
|
325
|
|
|
*/ |
|
326
|
|
|
public function onStartMatchStart($count, $time) |
|
327
|
|
|
{ |
|
328
|
|
|
|
|
329
|
|
|
$map = $this->mapStorage->getCurrentMap(); |
|
330
|
|
|
$this->PBWidget->setAuthorTime($map->authorTime); |
|
331
|
|
|
} |
|
332
|
|
|
|
|
333
|
|
|
/** |
|
334
|
|
|
* Callback sent when the "StartMatch" section end. |
|
335
|
|
|
* |
|
336
|
|
|
* @param int $count Each time this section is played, this number is incremented by one |
|
337
|
|
|
* @param int $time Server time when the callback was sent |
|
338
|
|
|
* |
|
339
|
|
|
* @return void |
|
340
|
|
|
*/ |
|
341
|
|
|
public function onStartMatchEnd($count, $time) |
|
342
|
|
|
{ |
|
343
|
|
|
// |
|
344
|
|
|
} |
|
345
|
|
|
|
|
346
|
|
|
/** |
|
347
|
|
|
* Callback sent when the "EndMatch" section start. |
|
348
|
|
|
* |
|
349
|
|
|
* @param int $count Each time this section is played, this number is incremented by one |
|
350
|
|
|
* @param int $time Server time when the callback was sent |
|
351
|
|
|
* |
|
352
|
|
|
* @return void |
|
353
|
|
|
*/ |
|
354
|
|
|
public function onEndMatchStart($count, $time) |
|
355
|
|
|
{ |
|
356
|
|
|
// |
|
357
|
|
|
} |
|
358
|
|
|
|
|
359
|
|
|
/** |
|
360
|
|
|
* Callback sent when the "EndMatch" section end. |
|
361
|
|
|
* |
|
362
|
|
|
* @param int $count Each time this section is played, this number is incremented by one |
|
363
|
|
|
* @param int $time Server time when the callback was sent |
|
364
|
|
|
* |
|
365
|
|
|
* @return void |
|
366
|
|
|
*/ |
|
367
|
|
|
public function onEndMatchEnd($count, $time) |
|
368
|
|
|
{ |
|
369
|
|
|
$this->PBWidget->reset(); |
|
370
|
|
|
} |
|
371
|
|
|
|
|
372
|
|
|
/** |
|
373
|
|
|
* Callback sent when the "StartTurn" section start. |
|
374
|
|
|
* |
|
375
|
|
|
* @param int $count Each time this section is played, this number is incremented by one |
|
376
|
|
|
* @param int $time Server time when the callback was sent |
|
377
|
|
|
* |
|
378
|
|
|
* @return void |
|
379
|
|
|
*/ |
|
380
|
|
|
public function onStartTurnStart($count, $time) |
|
381
|
|
|
{ |
|
382
|
|
|
// |
|
383
|
|
|
} |
|
384
|
|
|
|
|
385
|
|
|
/** |
|
386
|
|
|
* Callback sent when the "StartTurn" section end. |
|
387
|
|
|
* |
|
388
|
|
|
* @param int $count Each time this section is played, this number is incremented by one |
|
389
|
|
|
* @param int $time Server time when the callback was sent |
|
390
|
|
|
* |
|
391
|
|
|
* @return void |
|
392
|
|
|
*/ |
|
393
|
|
|
public function onStartTurnEnd($count, $time) |
|
394
|
|
|
{ |
|
395
|
|
|
// |
|
396
|
|
|
} |
|
397
|
|
|
|
|
398
|
|
|
/** |
|
399
|
|
|
* Callback sent when the "EndMatch" section start. |
|
400
|
|
|
* |
|
401
|
|
|
* @param int $count Each time this section is played, this number is incremented by one |
|
402
|
|
|
* @param int $time Server time when the callback was sent |
|
403
|
|
|
* |
|
404
|
|
|
* @return void |
|
405
|
|
|
*/ |
|
406
|
|
|
public function onEndTurnStart($count, $time) |
|
407
|
|
|
{ |
|
408
|
|
|
// |
|
409
|
|
|
} |
|
410
|
|
|
|
|
411
|
|
|
/** |
|
412
|
|
|
* Callback sent when the "EndMatch" section end. |
|
413
|
|
|
* |
|
414
|
|
|
* @param int $count Each time this section is played, this number is incremented by one |
|
415
|
|
|
* @param int $time Server time when the callback was sent |
|
416
|
|
|
* |
|
417
|
|
|
* @return void |
|
418
|
|
|
*/ |
|
419
|
|
|
public function onEndTurnEnd($count, $time) |
|
420
|
|
|
{ |
|
421
|
|
|
// |
|
422
|
|
|
} |
|
423
|
|
|
|
|
424
|
|
|
/** |
|
425
|
|
|
* Callback sent when the "StartRound" section start. |
|
426
|
|
|
* |
|
427
|
|
|
* @param int $count Each time this section is played, this number is incremented by one |
|
428
|
|
|
* @param int $time Server time when the callback was sent |
|
429
|
|
|
* |
|
430
|
|
|
* @return void |
|
431
|
|
|
*/ |
|
432
|
|
|
public function onStartRoundStart($count, $time) |
|
433
|
|
|
{ |
|
434
|
|
|
// |
|
435
|
|
|
} |
|
436
|
|
|
|
|
437
|
|
|
/** |
|
438
|
|
|
* Callback sent when the "StartRound" section end. |
|
439
|
|
|
* |
|
440
|
|
|
* @param int $count Each time this section is played, this number is incremented by one |
|
441
|
|
|
* @param int $time Server time when the callback was sent |
|
442
|
|
|
* |
|
443
|
|
|
* @return void |
|
444
|
|
|
*/ |
|
445
|
|
|
public function onStartRoundEnd($count, $time) |
|
446
|
|
|
{ |
|
447
|
|
|
// |
|
448
|
|
|
} |
|
449
|
|
|
|
|
450
|
|
|
/** |
|
451
|
|
|
* Callback sent when the "EndMatch" section start. |
|
452
|
|
|
* |
|
453
|
|
|
* @param int $count Each time this section is played, this number is incremented by one |
|
454
|
|
|
* @param int $time Server time when the callback was sent |
|
455
|
|
|
* |
|
456
|
|
|
* @return void |
|
457
|
|
|
*/ |
|
458
|
|
|
public function onEndRoundStart($count, $time) |
|
459
|
|
|
{ |
|
460
|
|
|
// |
|
461
|
|
|
} |
|
462
|
|
|
|
|
463
|
|
|
/** |
|
464
|
|
|
* Callback sent when the "EndMatch" section end. |
|
465
|
|
|
* |
|
466
|
|
|
* @param int $count Each time this section is played, this number is incremented by one |
|
467
|
|
|
* @param int $time Server time when the callback was sent |
|
468
|
|
|
* |
|
469
|
|
|
* @return void |
|
470
|
|
|
*/ |
|
471
|
|
|
public function onEndRoundEnd($count, $time) |
|
472
|
|
|
{ |
|
473
|
|
|
// |
|
474
|
|
|
} |
|
475
|
|
|
} |
|
476
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.