Fibinger Ádám
2019-10-15 cc3ac843ada92f513339d893c8da534e3c5b9ae7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<?php
 
 
namespace EOG\Models;
 
 
class MatchHistory implements \Iterator, \Countable
{
    const ROLE_ATTACK = 'att';
    const ROLE_DEFEND = 'def';
 
    protected $sites = [
        'Bank' => [
            'CEO Office / Executive Lounge',
            'Open Area / Staff Room',
            'Tellers\' Office / Archives',
            'Basement CCTV Room / Basement Lockers',
        ],
 
        'Border' => [
            'Supply Room / Customs Inspection',
            'Workshop / Ventilation Room',
            'Bathroom / Tellers',
            'Armory Lockers / Archives',
        ],
 
        'Club House' => [
            'Bedroom / Gym',
            'Cash Room / CCTV Room',
            'Bar / Stock Room',
            'Basement Church / Basement Arsenal Room',
        ],
 
        'Coastline' => [
            'Billiards Room / Hookah Lounge',
            'Theater / Penthouse',
            'Kitchen / Service Entrance',
            'Blue Bar / Sunrise Bar',
        ],
 
        'Consulate' => [
            'Meeting Room / Consulate Office',
            'Press Room / Lobby',
            'Basement Archives / Tellers',
            'Basement Cafeteria / Basement Garage',
        ],
 
        'Kafe Dostoyevsky' => [
            '3rd Floor Cocktail Lounge',
            'Fireplace Hall / Mining Room',
            'Reading Room / Fireplace Hall',
            'Kitchen Service / Kitchen Cooking'
        ],
 
        'Villa' => [
            'Aviator Room / Games Room',
            'Trophy Room / Statuary Room',
            'Living Room / Library',
            'Dining Room / Kitchen'
        ]
    ];
 
    private $position = 0;
 
    protected $currentMap = 'Villa';
    protected $history = [
        [
            'site' => 'Aviator Room / Games Room',
            'win' => Stripe::TEAM_ORANGE,
            'win_role' => self::ROLE_DEFEND
        ],
        [
            'site' => 'Trophy Room / Statuary Room',
            'win' => Stripe::TEAM_BLUE,
            'win_role' => self::ROLE_ATTACK
        ],
        [
            'site' => 'Dining Room / Kitchen',
            'win' => Stripe::TEAM_ORANGE,
            'win_role' => self::ROLE_ATTACK
        ]
    ];
 
    /**
     * @return array
     */
    public function getSites(): array
    {
        return $this->sites;
    }
 
    /**
     * @return string
     */
    public function getCurrentMap(): string
    {
        return $this->currentMap;
    }
 
    /**
     * @return array
     */
    public function getHistory(): array
    {
        return $this->history;
    }
 
    private function validMap($mapName)
    {
        $mapList = array_keys($this->sites);
        return in_array($mapName, $mapList);
    }
 
    private function validSite($siteName)
    {
        return in_array($siteName, $this->sites[$this->currentMap]);
    }
 
    public function setCurrentMap(string $mapName)
    {
 
        if (!$this->validMap($mapName)) {
            throw new \InvalidArgumentException("No such map: " . $mapName);
        }
 
        $this->currentMap = $mapName;
    }
 
    public function addHistoryItem(string $site, string $winner = Stripe::TEAM_BLUE, $win_role = MatchHistory::ROLE_DEFEND)
    {
        if (!$this->validSite($site)) {
            throw new \InvalidArgumentException("No such site: " . $site . " on map: " . $this->currentMap);
        }
        if (!in_array($winner, [Stripe::TEAM_BLUE, Stripe::TEAM_ORANGE])) {
            throw new \InvalidArgumentException("No such team: " . $winner);
        }
        if (!in_array($win_role, [MatchHistory::ROLE_DEFEND, MatchHistory::ROLE_ATTACK])) {
            throw new \InvalidArgumentException("No such role: " . $win_role);
        }
 
        $this->history[] = [
            'site' => $site,
            'win' => $winner,
            'win_role' => $win_role
        ];
    }
 
    public function getState(): array
    {
        return
            [
                'history' => $this->history,
                'map' => $this->currentMap
            ];
    }
 
    public function loadState(array $state): self
    {
        if (!empty($state['map'])) {
            $this->setCurrentMap($state['map']);
        }
 
        if (!empty($state['history'])) {
            foreach ($state['history'] as $item) {
                $this->addHistoryItem($item['site'], $item['win'], $item['win_role']);
            }
        }
        return $this;
    }
 
    public function current()
    {
        return $this->history[$this->position];
    }
 
    public function next()
    {
        $this->position++;
    }
 
    public function key()
    {
        return $this->position;
    }
 
    public function valid()
    {
        return isset($this->history[$this->position]);
    }
 
    public function rewind()
    {
        $this->position = 0;
    }
 
    public function count()
    {
        return count($this->history);
    }
 
}