Completed
Pull Request — master (#168)
by De Cramer
08:32
created

MethodGetNumberLapsDataProvider::request()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 9
nc 4
nop 0
1
<?php
2
3
namespace eXpansion\Framework\GameTrackmania\DataProviders\ScriptBaseRounds;
4
5
use eXpansion\Framework\Core\DataProviders\AbstractDataProvider;
6
use eXpansion\Framework\Core\DataProviders\MethodScriptDataProviderInterface;
7
use eXpansion\Framework\Core\Storage\MapStorage;
8
use Maniaplanet\DedicatedServer\Connection;
9
10
/**
11
 * Class MethodGetNumberLapsDataProvider
12
 *
13
 * @author    de Cramer Oliver<[email protected]>
14
 * @copyright 2017 eXpansion
15
 * @package eXpansion\Framework\GameTrackmania\DataProviders
16
 */
17
class MethodGetNumberLapsDataProvider extends AbstractDataProvider implements MethodScriptDataProviderInterface
18
{
19
    /** @var Connection */
20
    protected $connection;
21
22
    /** @var MapStorage */
23
    protected $mapStorage;
24
25
    /**
26
     * MethodGetNumberLapsDataProvider constructor.
27
     *
28
     * @param Connection $connection
29
     * @param MapStorage $mapStorage
30
     */
31
    public function __construct(Connection $connection, MapStorage $mapStorage)
32
    {
33
        $this->connection = $connection;
34
        $this->mapStorage = $mapStorage;
35
    }
36
37
    /**
38
     * @inheritdoc
39
     *
40
     * @param string $pluginId
41
     * @param mixed $pluginService
42
     */
43
    public function registerPlugin($pluginId, $pluginService)
44
    {
45
        parent::registerPlugin($pluginId, $pluginService);
46
47
        $pluginService->setCurrentDataProvider($this);
48
    }
49
50
    /**
51
     * Request call to fetch something..
52
     *
53
     * @return void
54
     */
55
    public function request()
56
    {
57
        $scriptSettings = $this->connection->getModeScriptSettings();
58
        $currentMap = $this->mapStorage->getCurrentMap();
59
60
        $nbLaps = 1;
61
        if ($currentMap->lapRace) {
62
            $nbLaps = $currentMap->nbLaps;
63
        }
64
65
        if ($scriptSettings['S_ForceLapsNb'] != -1) {
66
            $nbLaps = $scriptSettings['S_ForceLapsNb'];
67
        }
68
69
        $this->dispatch('set', [$nbLaps]);
70
    }
71
}
72