|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Obblm\Core\Helper\Rule\Roster; |
|
4
|
|
|
|
|
5
|
|
|
use Obblm\Core\Contracts\PositionInterface; |
|
6
|
|
|
use Obblm\Core\Contracts\RosterInterface; |
|
7
|
|
|
use Obblm\Core\Exception\NotFoundKeyException; |
|
8
|
|
|
use Obblm\Core\Helper\CoreTranslation; |
|
9
|
|
|
use Obblm\Core\Helper\Optionable; |
|
10
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
|
11
|
|
|
|
|
12
|
|
|
abstract class AbstractRoster extends Optionable implements RosterInterface |
|
13
|
|
|
{ |
|
14
|
|
|
const DEFAULT_INDUCEMENT_OPTIONS = [ |
|
15
|
|
|
'discount_bribe' => false, |
|
16
|
|
|
'discount_halfling_master_chef' => false, |
|
17
|
|
|
'extra_apothecary' => true, |
|
18
|
|
|
'igor' => false |
|
19
|
|
|
]; |
|
20
|
|
|
|
|
21
|
|
|
protected $key; |
|
22
|
|
|
protected $name; |
|
23
|
|
|
protected $translationDomain; |
|
24
|
|
|
protected $positions = []; |
|
25
|
|
|
protected $special_rules; |
|
26
|
|
|
protected $additionalValidators; |
|
27
|
|
|
protected $tier; |
|
28
|
|
|
protected $rerollCost; |
|
29
|
|
|
protected $canHaveApothecary; |
|
30
|
|
|
protected $inducementOptions; |
|
31
|
|
|
|
|
32
|
1 |
|
protected function hydrateWithOptions() |
|
33
|
|
|
{ |
|
34
|
1 |
|
$this->setKey($this->options['key']) |
|
35
|
1 |
|
->setName($this->options['name']) |
|
36
|
1 |
|
->setTranslationDomain($this->options['translation_domain']) |
|
37
|
1 |
|
->setSpecialRules($this->options['special_rules']) |
|
38
|
1 |
|
->setTier($this->options['tier']) |
|
39
|
1 |
|
->setAdditionalValidators($this->options['additional_validators']) |
|
40
|
1 |
|
->setInducementTypes($this->options['inducement_options']) |
|
41
|
1 |
|
->setRerollCost($this->options['reroll_cost']) |
|
42
|
1 |
|
->setCanHaveApothecary($this->options['can_have_apothecary']); |
|
43
|
1 |
|
$this->hydratePositions($this->options['player_types']); |
|
44
|
1 |
|
} |
|
45
|
|
|
|
|
46
|
1 |
|
protected function hydratePositions(array $positions): self |
|
47
|
|
|
{ |
|
48
|
1 |
|
$positionClassName = $this->getPositionClass(); |
|
49
|
1 |
|
foreach ($positions as $key => $position) { |
|
50
|
1 |
|
$position['key'] = $key; |
|
51
|
1 |
|
$position['name'] = CoreTranslation::getPlayerKeyType( |
|
52
|
1 |
|
$this->getTranslationDomain(), |
|
53
|
1 |
|
$this->getKey(), |
|
54
|
1 |
|
$key |
|
55
|
|
|
); |
|
56
|
1 |
|
$position['translation_domain'] = $this->getTranslationDomain(); |
|
57
|
1 |
|
$this->positions[$key] = (new $positionClassName($position)) |
|
58
|
1 |
|
->setRoster($this); |
|
59
|
|
|
} |
|
60
|
1 |
|
return $this; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @return string |
|
65
|
|
|
*/ |
|
66
|
1 |
|
public function getPositionClass(): string |
|
67
|
|
|
{ |
|
68
|
1 |
|
return Position::class; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @return string |
|
73
|
|
|
*/ |
|
74
|
1 |
|
public function getKey(): string |
|
75
|
|
|
{ |
|
76
|
1 |
|
return $this->key; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @return string |
|
81
|
|
|
*/ |
|
82
|
|
|
public function getName(): string |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->name; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @return string |
|
89
|
|
|
*/ |
|
90
|
1 |
|
public function getTranslationDomain(): string |
|
91
|
|
|
{ |
|
92
|
1 |
|
return $this->translationDomain; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @return array |
|
97
|
|
|
*/ |
|
98
|
1 |
|
public function getPositions(): ?array |
|
99
|
|
|
{ |
|
100
|
1 |
|
return $this->positions; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
2 |
|
public function getPosition($key): ?PositionInterface |
|
104
|
|
|
{ |
|
105
|
2 |
|
if (!isset($this->positions[$key])) { |
|
106
|
2 |
|
throw new NotFoundKeyException($key, "positions", self::class); |
|
107
|
|
|
} |
|
108
|
1 |
|
return $this->positions[$key]; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @return bool |
|
113
|
|
|
*/ |
|
114
|
1 |
|
public function canHaveApothecary():bool |
|
115
|
|
|
{ |
|
116
|
1 |
|
return $this->canHaveApothecary; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @return bool |
|
121
|
|
|
*/ |
|
122
|
|
|
public function getCanHaveApothecary():bool |
|
123
|
|
|
{ |
|
124
|
|
|
return $this->canHaveApothecary; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* @return int |
|
129
|
|
|
*/ |
|
130
|
1 |
|
public function getRerollCost():int |
|
131
|
|
|
{ |
|
132
|
1 |
|
return $this->rerollCost; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* @return array |
|
137
|
|
|
*/ |
|
138
|
|
|
public function getInducementOptions():?array |
|
139
|
|
|
{ |
|
140
|
|
|
return $this->inducementOptions; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* @param string $key |
|
145
|
|
|
* @return $this |
|
146
|
|
|
*/ |
|
147
|
1 |
|
public function setKey(string $key): self |
|
148
|
|
|
{ |
|
149
|
1 |
|
$this->key = $key; |
|
150
|
1 |
|
return $this; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* @param string $name |
|
155
|
|
|
* @return $this |
|
156
|
|
|
*/ |
|
157
|
1 |
|
public function setName(string $name): self |
|
158
|
|
|
{ |
|
159
|
1 |
|
$this->name = $name; |
|
160
|
1 |
|
return $this; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* @param string $translationDomain |
|
165
|
|
|
* @return $this |
|
166
|
|
|
*/ |
|
167
|
1 |
|
public function setTranslationDomain(string $translationDomain): self |
|
168
|
|
|
{ |
|
169
|
1 |
|
$this->translationDomain = $translationDomain; |
|
170
|
1 |
|
return $this; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* @param array $positions |
|
175
|
|
|
* @return $this |
|
176
|
|
|
*/ |
|
177
|
|
|
public function setPositions(array $positions): self |
|
178
|
|
|
{ |
|
179
|
|
|
$this->positions = $positions; |
|
180
|
|
|
return $this; |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* @param array $inducementTypes |
|
185
|
|
|
* @return $this |
|
186
|
|
|
*/ |
|
187
|
1 |
|
public function setInducementTypes(array $inducementTypes): self |
|
188
|
|
|
{ |
|
189
|
1 |
|
$this->inducementTypes = $inducementTypes; |
|
|
|
|
|
|
190
|
1 |
|
return $this; |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
/** |
|
194
|
|
|
* @param int $rerollCost |
|
195
|
|
|
* @return $this |
|
196
|
|
|
*/ |
|
197
|
1 |
|
public function setRerollCost(int $rerollCost): self |
|
198
|
|
|
{ |
|
199
|
1 |
|
$this->rerollCost = $rerollCost; |
|
200
|
1 |
|
return $this; |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
/** |
|
204
|
|
|
* @param bool $canHaveApothecary |
|
205
|
|
|
* @return $this |
|
206
|
|
|
*/ |
|
207
|
1 |
|
public function setCanHaveApothecary(bool $canHaveApothecary): self |
|
208
|
|
|
{ |
|
209
|
1 |
|
$this->canHaveApothecary = $canHaveApothecary; |
|
210
|
1 |
|
return $this; |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
/** |
|
214
|
|
|
* @return array |
|
215
|
|
|
*/ |
|
216
|
|
|
public function getSpecialRules():array |
|
217
|
|
|
{ |
|
218
|
|
|
return $this->special_rules; |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
/** |
|
222
|
|
|
* @param array $special_rules |
|
223
|
|
|
* @return $this |
|
224
|
|
|
*/ |
|
225
|
1 |
|
public function setSpecialRules(array $special_rules): self |
|
226
|
|
|
{ |
|
227
|
1 |
|
$this->special_rules = $special_rules; |
|
228
|
1 |
|
return $this; |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
/** |
|
232
|
|
|
* @return array |
|
233
|
|
|
*/ |
|
234
|
|
|
public function getAdditionalValidators(): ?array |
|
235
|
|
|
{ |
|
236
|
|
|
return $this->additionalValidators; |
|
237
|
|
|
} |
|
238
|
|
|
|
|
239
|
|
|
/** |
|
240
|
|
|
* @param array $additionalValidators |
|
241
|
|
|
* @return $this |
|
242
|
|
|
*/ |
|
243
|
1 |
|
public function setAdditionalValidators(array $additionalValidators): self |
|
244
|
|
|
{ |
|
245
|
1 |
|
$this->additionalValidators = $additionalValidators; |
|
246
|
1 |
|
return $this; |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
/** |
|
250
|
|
|
* @return int |
|
251
|
|
|
*/ |
|
252
|
|
|
public function getTier():int |
|
253
|
|
|
{ |
|
254
|
|
|
return $this->tier; |
|
255
|
|
|
} |
|
256
|
|
|
|
|
257
|
|
|
/** |
|
258
|
|
|
* @param int|null $tier |
|
259
|
|
|
* @return $this |
|
260
|
|
|
*/ |
|
261
|
1 |
|
public function setTier(?int $tier): self |
|
262
|
|
|
{ |
|
263
|
1 |
|
$this->tier = $tier; |
|
264
|
1 |
|
return $this; |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
public function __toString(): string |
|
268
|
|
|
{ |
|
269
|
|
|
return $this->name; |
|
270
|
|
|
} |
|
271
|
|
|
|
|
272
|
1 |
|
public function configureOptions(OptionsResolver $resolver):void |
|
273
|
|
|
{ |
|
274
|
1 |
|
$resolver->setDefaults([ |
|
275
|
1 |
|
'key' => null, |
|
276
|
|
|
'name' => null, |
|
277
|
|
|
'translation_domain' => null, |
|
278
|
|
|
'player_types' => [], |
|
279
|
|
|
'additional_validators' => [], |
|
280
|
|
|
'special_rules' => [], |
|
281
|
|
|
'tier' => null, |
|
282
|
1 |
|
'inducement_options' => self::DEFAULT_INDUCEMENT_OPTIONS, |
|
283
|
1 |
|
'reroll_cost' => 0, |
|
284
|
|
|
'can_have_apothecary' => true, |
|
285
|
|
|
]) |
|
286
|
1 |
|
->setRequired('key') |
|
287
|
1 |
|
->setRequired('name') |
|
288
|
1 |
|
->setRequired('translation_domain') |
|
289
|
1 |
|
->setAllowedTypes('key', ['string']) |
|
290
|
1 |
|
->setAllowedTypes('name', ['string']) |
|
291
|
1 |
|
->setAllowedTypes('translation_domain', ['string']) |
|
292
|
1 |
|
->setAllowedTypes('player_types', ['array']) |
|
293
|
1 |
|
->setAllowedTypes('special_rules', ['array']) |
|
294
|
1 |
|
->setAllowedTypes('tier', ['int', 'null']) |
|
295
|
1 |
|
->setAllowedTypes('additional_validators', ['array']) |
|
296
|
1 |
|
->setAllowedTypes('inducement_options', ['array']) |
|
297
|
1 |
|
->setAllowedTypes('reroll_cost', ['int']) |
|
298
|
1 |
|
->setAllowedTypes('can_have_apothecary', ['bool']) |
|
299
|
|
|
; |
|
300
|
1 |
|
} |
|
301
|
|
|
} |
|
302
|
|
|
|