Completed
Push — master ( a13e43...d36035 )
by De Cramer
15s
created

MapRatings::onStartTurnEnd()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 1
nc 1
nop 2
crap 2
1
<?php
2
3
namespace eXpansion\Bundle\LocalMapRatings\Plugin;
4
5
use eXpansion\Bundle\LocalMapRatings\DataProviders\Listener\ListenerInterfaceExpMapRatings;
6
use eXpansion\Bundle\LocalMapRatings\Model\Maprating;
7
use eXpansion\Bundle\LocalMapRatings\Plugin\Gui\MapRatingsWidget;
8
use eXpansion\Bundle\LocalMapRatings\Services\MapRatingsService;
9
use eXpansion\Bundle\LocalRecords\Plugins\ChatNotification;
10
use eXpansion\Framework\Core\DataProviders\Listener\ListenerInterfaceExpApplication;
11
use eXpansion\Framework\Core\Model\UserGroups\Group;
12
use eXpansion\Framework\Core\Services\Application\Dispatcher;
13
use eXpansion\Framework\Core\Storage\Data\Player;
14
use eXpansion\Framework\Core\Storage\MapStorage;
15
use eXpansion\Framework\Core\Storage\PlayerStorage;
16
use eXpansion\Framework\GameManiaplanet\DataProviders\Listener\ListenerInterfaceMpLegacyChat;
17
use eXpansion\Framework\GameManiaplanet\DataProviders\Listener\ListenerInterfaceMpScriptMap;
18
use eXpansion\Framework\GameManiaplanet\DataProviders\Listener\ListenerInterfaceMpScriptMatch;
19
use Maniaplanet\DedicatedServer\Structures\Map;
20
21
22
class MapRatings implements ListenerInterfaceExpApplication, ListenerInterfaceMpScriptMatch,
0 ignored issues
show
Coding Style introduced by
The first item in a multi-line implements list must be on the line following the implements keyword
Loading history...
Coding Style introduced by
Only one interface may be specified per line in a multi-line implements declaration
Loading history...
23
    ListenerInterfaceMpScriptMap, ListenerInterfaceMpLegacyChat, ListenerInterfaceExpMapRatings
0 ignored issues
show
Coding Style introduced by
Only one interface may be specified per line in a multi-line implements declaration
Loading history...
24
{
25
26
    /**
27
     * @var MapStorage
28
     */
29
    private $mapStorage;
30
    /**
31
     * @var PlayerStorage
32
     */
33
    private $playerStorage;
34
35
    /**
36
     * @var ChatNotification
37
     */
38
    private $chatNotification;
39
    /**
40
     * @var Dispatcher
41
     */
42
    private $dispatcher;
0 ignored issues
show
Unused Code introduced by
The property $dispatcher is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
43
    /**
44
     * @var MapRatingsWidget
45
     */
46
    private $mapRatingsWidget;
47
    /**
48
     * @var Group
49
     */
50
    private $players;
51
    /**
52
     * @var MapRatingsService
53
     */
54
    private $mapRatingsService;
55
56
    /**
57
     * MapRatingService constructor.
58
     * @param MapStorage        $mapStorage
59
     * @param PlayerStorage     $playerStorage
60
     * @param ChatNotification  $chatNotification
61
     * @param MapRatingsWidget  $mapRatingsWidget
62
     * @param MapRatingsService $mapRatingsService
63
     * @param Group             $players
64
     */
65
    public function __construct(
66
        MapStorage $mapStorage,
67
        PlayerStorage $playerStorage,
68
        ChatNotification $chatNotification,
69
        MapRatingsWidget $mapRatingsWidget,
70
        MapRatingsService $mapRatingsService,
71
        Group $players
72
    ) {
73
        $this->mapStorage = $mapStorage;
74
        $this->playerStorage = $playerStorage;
75
        $this->chatNotification = $chatNotification;
76
        $this->mapRatingsWidget = $mapRatingsWidget;
77
        $this->players = $players;
78
        $this->mapRatingsService = $mapRatingsService;
79
    }
80
81
    /**
82
     * Called when a player chats.
83
     *
84
     * @param Player $player
85
     * @param        $text
86
     *
87
     * @return void
88
     */
89
    public function onPlayerChat(Player $player, $text)
90
    {
91
        if ($player->getPlayerId() == 0) {
92
            return;
93
        }
94
95
        if ($player->getPlayerId() != 0 && substr($text, 0, 1) != "/") {
96
            if ($text === "++") {
97
                $this->mapRatingsService->changeRating($player->getLogin(), 1);
98
99
                return;
100
            }
101
102
            if ($text === "--") {
103
                $this->mapRatingsService->changeRating($player->getLogin(), -1);
104
105
                return;
106
            }
107
        }
108
    }
109
110
    /**
111
     * called at eXpansion init
112
     *
113
     * @return void
114
     */
115
    public function onApplicationInit()
116
    {
117
118
    }
119
120
    /**
121
     * called when init is done and callbacks are enabled
122
     *
123
     * @return void
124
     */
125
    public function onApplicationReady()
126
    {
127
        $this->mapRatingsWidget->create($this->players);
128
        $this->mapRatingsService->load($this->mapStorage->getCurrentMap());
129
130
    }
131
132
    /**
133
     * called when requesting application stop
134
     *
135
     * @return void
136
     */
137
    public function onApplicationStop()
138
    {
139
140
    }
141
142
    /**
143
     * Callback sent when the "StartMatch" section start.
144
     *
145
     * @param int $count Each time this section is played, this number is incremented by one
146
     * @param int $time  Server time when the callback was sent
147
     *
148
     * @return void
149
     */
150
    public function onStartMatchStart($count, $time)
151
    {
152
153
    }
154
155
    /**
156
     * Callback sent when the "StartMatch" section end.
157
     *
158
     * @param int $count Each time this section is played, this number is incremented by one
159
     * @param int $time  Server time when the callback was sent
160
     *
161
     * @return void
162
     */
163
    public function onStartMatchEnd($count, $time)
164
    {
165
166
    }
167
168
    /**
169
     * Callback sent when the "EndMatch" section start.
170
     *
171
     * @param int $count Each time this section is played, this number is incremented by one
172
     * @param int $time  Server time when the callback was sent
173
     *
174
     * @return void
175
     */
176
    public function onEndMatchStart($count, $time)
177
    {
178
179
    }
180
181
    /**
182
     * Callback sent when the "EndMatch" section end.
183
     *
184
     * @param int $count Each time this section is played, this number is incremented by one
185
     * @param int $time  Server time when the callback was sent
186
     *
187
     * @return void
188
     */
189
    public function onEndMatchEnd($count, $time)
190
    {
191
        $this->mapRatingsService->save();
192
    }
193
194
    /**
195
     * Callback sent when the "StartTurn" section start.
196
     *
197
     * @param int $count Each time this section is played, this number is incremented by one
198
     * @param int $time  Server time when the callback was sent
199
     *
200
     * @return void
201
     */
202
    public function onStartTurnStart($count, $time)
203
    {
204
205
    }
206
207
    /**
208
     * Callback sent when the "StartTurn" section end.
209
     *
210
     * @param int $count Each time this section is played, this number is incremented by one
211
     * @param int $time  Server time when the callback was sent
212
     *
213
     * @return void
214
     */
215
    public function onStartTurnEnd($count, $time)
216
    {
217
218
    }
219
220
    /**
221
     * Callback sent when the "EndMatch" section start.
222
     *
223
     * @param int $count Each time this section is played, this number is incremented by one
224
     * @param int $time  Server time when the callback was sent
225
     *
226
     * @return void
227
     */
228
    public function onEndTurnStart($count, $time)
229
    {
230
231
    }
232
233
    /**
234
     * Callback sent when the "EndMatch" section end.
235
     *
236
     * @param int $count Each time this section is played, this number is incremented by one
237
     * @param int $time  Server time when the callback was sent
238
     *
239
     * @return void
240
     */
241
    public function onEndTurnEnd($count, $time)
242
    {
243
244
    }
245
246
    /**
247
     * Callback sent when the "StartRound" section start.
248
     *
249
     * @param int $count Each time this section is played, this number is incremented by one
250
     * @param int $time  Server time when the callback was sent
251
     *
252
     * @return void
253
     */
254
    public function onStartRoundStart($count, $time)
255
    {
256
257
    }
258
259
    /**
260
     * Callback sent when the "StartRound" section end.
261
     *
262
     * @param int $count Each time this section is played, this number is incremented by one
263
     * @param int $time  Server time when the callback was sent
264
     *
265
     * @return void
266
     */
267
    public function onStartRoundEnd($count, $time)
268
    {
269
270
    }
271
272
    /**
273
     * Callback sent when the "EndMatch" section start.
274
     *
275
     * @param int $count Each time this section is played, this number is incremented by one
276
     * @param int $time  Server time when the callback was sent
277
     *
278
     * @return void
279
     */
280
    public function onEndRoundStart($count, $time)
281
    {
282
283
    }
284
285
    /**
286
     * Callback sent when the "EndMatch" section end.
287
     *
288
     * @param int $count Each time this section is played, this number is incremented by one
289
     * @param int $time  Server time when the callback was sent
290
     *
291
     * @return void
292
     */
293
    public function onEndRoundEnd($count, $time)
294
    {
295
296
    }
297
298
299
    /**
300
     * Callback sent when the "StartMap" section start.
301
     *
302
     * @param int     $count     Each time this section is played, this number is incremented by one
303
     * @param int     $time      Server time when the callback was sent
304
     * @param boolean $restarted true if the map was restarted, false otherwise
305
     * @param Map     $map       Map started with.
306
     *
307
     * @return void
308
     * @throws \Propel\Runtime\Exception\PropelException
309
     */
310
    public function onStartMapStart($count, $time, $restarted, Map $map)
311
    {
312
        if ($restarted) {
313
            $this->mapRatingsService->save();
314
        }
315
316
        $this->mapRatingsService->load($map);
317
    }
318
319
    /**
320
     * Callback sent when the "StartMap" section end.
321
     *
322
     * @param int     $count     Each time this section is played, this number is incremented by one
323
     * @param int     $time      Server time when the callback was sent
324
     * @param boolean $restarted true if the map was restarted, false otherwise
325
     * @param Map     $map       Map started with.
326
     *
327
     * @return void
328
     */
329
    public function onStartMapEnd($count, $time, $restarted, Map $map)
330
    {
331
332
    }
333
334
    /**
335
     * Callback sent when the "EndMap" section start.
336
     *
337
     * @param int     $count     Each time this section is played, this number is incremented by one
338
     * @param int     $time      Server time when the callback was sent
339
     * @param boolean $restarted true if the map was restarted, false otherwise
340
     * @param Map     $map       Map started with.
341
     *
342
     * @return void
343
     * @throws \Propel\Runtime\Exception\PropelException
344
     */
345
    public function onEndMapStart($count, $time, $restarted, Map $map)
346
    {
347
        $this->mapRatingsService->save();
348
    }
349
350
    /**
351
     * Callback sent when the "EndMap" section end.
352
     *
353
     * @param int     $count     Each time this section is played, this number is incremented by one
354
     * @param int     $time      Server time when the callback was sent
355
     * @param boolean $restarted true if the map was restarted, false otherwise
356
     * @param Map     $map       Map started with.
357
     *
358
     * @return void
359
     */
360
    public function onEndMapEnd($count, $time, $restarted, Map $map)
361
    {
362
363
    }
364
365
    /**
366
     * Called when map ratings are loaded.
367
     *
368
     * @param Maprating[] $ratings
369
     * @return void
370
     */
371
    public function onMapRatingsLoaded($ratings)
372
    {
373
        $this->mapRatingsWidget->setRatings($ratings);
374
        $this->mapRatingsWidget->update($this->players);
375
    }
376
377
    /**
378
     * Called when map ratings are changed.
379
     *
380
     * @param string      $login
381
     * @param int         $score
382
     * @param Maprating[] $ratings
383
     * @return void
384
     */
385
    public function onMapRatingsChanged($login, $score, $ratings)
386
    {
387
        $this->mapRatingsWidget->setRatings($ratings);
388
        $this->mapRatingsWidget->update($this->players);
389
    }
390
}
391