|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Obblm\Core\Entity; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Serializer\Annotation\Ignore; |
|
6
|
|
|
use Obblm\Core\Repository\RuleRepository; |
|
7
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
8
|
|
|
use Doctrine\Common\Collections\Collection; |
|
9
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @ORM\Entity(repositoryClass=RuleRepository::class) |
|
13
|
|
|
* @ORM\Table(name="obblm_rule") |
|
14
|
|
|
*/ |
|
15
|
|
|
class Rule |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @ORM\Id() |
|
19
|
|
|
* @ORM\GeneratedValue() |
|
20
|
|
|
* @ORM\Column(type="integer") |
|
21
|
|
|
*/ |
|
22
|
|
|
private $id; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @ORM\Column(type="string", unique=true, length=255) |
|
26
|
|
|
*/ |
|
27
|
|
|
private $ruleKey; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @ORM\Column(type="string", length=255, nullable=true) |
|
31
|
|
|
*/ |
|
32
|
|
|
private $ruleDirectory; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @ORM\Column(type="string", length=255) |
|
36
|
|
|
*/ |
|
37
|
|
|
private $template; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @ORM\Column(type="string", length=255) |
|
41
|
|
|
*/ |
|
42
|
|
|
private $name; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @ORM\Column(type="string", length=255, nullable=true) |
|
46
|
|
|
*/ |
|
47
|
|
|
private $description; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @ORM\Column(type="array", nullable=true) |
|
51
|
|
|
*/ |
|
52
|
|
|
private $rule = []; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @ORM\Column(type="boolean") |
|
56
|
|
|
*/ |
|
57
|
|
|
private $postBb2020; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @ORM\Column(type="boolean") |
|
61
|
|
|
*/ |
|
62
|
|
|
private $readOnly; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @ORM\OneToMany(targetEntity=Team::class, mappedBy="rule") |
|
66
|
|
|
* @Ignore() |
|
67
|
|
|
*/ |
|
68
|
|
|
private $teams; |
|
69
|
|
|
|
|
70
|
|
|
protected $injuryTable = []; |
|
71
|
|
|
|
|
72
|
|
|
public function __construct() |
|
73
|
|
|
{ |
|
74
|
|
|
$this->postBb2020 = false; |
|
75
|
|
|
$this->readOnly = false; |
|
76
|
|
|
$this->teams = new ArrayCollection(); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function getId(): ?int |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->id; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function getRuleKey(): ?string |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->ruleKey; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function setRuleKey(string $ruleKey): self |
|
90
|
|
|
{ |
|
91
|
|
|
$this->ruleKey = $ruleKey; |
|
92
|
|
|
|
|
93
|
|
|
return $this; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function getRuleDirectory(): ?string |
|
97
|
|
|
{ |
|
98
|
|
|
return $this->ruleDirectory; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
public function setRuleDirectory(string $ruleDirectory): self |
|
102
|
|
|
{ |
|
103
|
|
|
$this->ruleDirectory = $ruleDirectory; |
|
104
|
|
|
|
|
105
|
|
|
return $this; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function getTemplate(): ?string |
|
109
|
|
|
{ |
|
110
|
|
|
return $this->template; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
public function setTemplate(string $template): self |
|
114
|
|
|
{ |
|
115
|
|
|
$this->template = $template; |
|
116
|
|
|
|
|
117
|
|
|
return $this; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
public function getName(): ?string |
|
121
|
|
|
{ |
|
122
|
|
|
return $this->name; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
public function setName(string $name): self |
|
126
|
|
|
{ |
|
127
|
|
|
$this->name = $name; |
|
128
|
|
|
|
|
129
|
|
|
return $this; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
public function getDescription(): ?string |
|
133
|
|
|
{ |
|
134
|
|
|
return $this->description; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
public function setDescription(?string $description): self |
|
138
|
|
|
{ |
|
139
|
|
|
$this->description = $description; |
|
140
|
|
|
|
|
141
|
|
|
return $this; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
public function getRule(): ?array |
|
145
|
|
|
{ |
|
146
|
|
|
return $this->rule; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
public function setRule(?array $rule): self |
|
150
|
|
|
{ |
|
151
|
|
|
$this->rule = $rule; |
|
152
|
|
|
$this->constructInjuryTable($rule); |
|
153
|
|
|
|
|
154
|
|
|
return $this; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
public function getPostBb2020(): ?bool |
|
158
|
|
|
{ |
|
159
|
|
|
return $this->postBb2020; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
public function isPostBb2020(): ?bool |
|
163
|
|
|
{ |
|
164
|
|
|
return $this->getPostBb2020(); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
public function setPostBb2020(bool $postBb2020): self |
|
168
|
|
|
{ |
|
169
|
|
|
$this->postBb2020 = $postBb2020; |
|
170
|
|
|
|
|
171
|
|
|
return $this; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
public function getReadOnly(): ?bool |
|
175
|
|
|
{ |
|
176
|
|
|
return $this->readOnly; |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
public function isReadOnly(): ?bool |
|
180
|
|
|
{ |
|
181
|
|
|
return $this->getReadOnly(); |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
public function setReadOnly(bool $readOnly): self |
|
185
|
|
|
{ |
|
186
|
|
|
$this->readOnly = $readOnly; |
|
187
|
|
|
|
|
188
|
|
|
return $this; |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* @return Collection|Team[] |
|
193
|
|
|
* @Ignore() |
|
194
|
|
|
*/ |
|
195
|
|
|
public function getTeams(): Collection |
|
196
|
|
|
{ |
|
197
|
|
|
return $this->teams; |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
public function addTeam(Team $team): self |
|
201
|
|
|
{ |
|
202
|
|
|
if (!$this->teams->contains($team)) { |
|
203
|
|
|
$this->teams[] = $team; |
|
204
|
|
|
$team->setRule($this); |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
return $this; |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
public function removeTeam(Team $team): self |
|
211
|
|
|
{ |
|
212
|
|
|
if ($this->teams->contains($team)) { |
|
213
|
|
|
$this->teams->removeElement($team); |
|
214
|
|
|
// set the owning side to null (unless already changed) |
|
215
|
|
|
if ($team->getRule() === $this) { |
|
216
|
|
|
$team->setRule(null); |
|
217
|
|
|
} |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
return $this; |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
public function __toString(): ?string |
|
224
|
|
|
{ |
|
225
|
|
|
return $this->ruleKey; |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
/** |
|
229
|
|
|
* Methods |
|
230
|
|
|
*/ |
|
231
|
|
|
|
|
232
|
|
|
/** |
|
233
|
|
|
* Construct Injury Table |
|
234
|
|
|
* |
|
235
|
|
|
* @param array $rule |
|
236
|
|
|
* |
|
237
|
|
|
*/ |
|
238
|
|
|
protected function constructInjuryTable($rule) |
|
239
|
|
|
{ |
|
240
|
|
|
foreach ($rule['injuries'] as $injuryKey => $injury) { |
|
241
|
|
|
if (isset($injury['from']) && isset($injury['to'])) { |
|
242
|
|
|
for ($key = $injury['from']; $key <= $injury['to']; $key++) { |
|
243
|
|
|
$this->injuryTable[$key] = $injuryKey; |
|
244
|
|
|
} |
|
245
|
|
|
} elseif (isset($injury['from'])) { |
|
246
|
|
|
$this->injuryTable[$injury['from']] = $injuryKey; |
|
247
|
|
|
} |
|
248
|
|
|
} |
|
249
|
|
|
} |
|
250
|
|
|
|
|
251
|
|
|
/** |
|
252
|
|
|
* Get Experience Level For Experience Value |
|
253
|
|
|
* |
|
254
|
|
|
* @param integer $experience |
|
255
|
|
|
* |
|
256
|
|
|
* @return string|boolean |
|
257
|
|
|
*/ |
|
258
|
|
|
public function getExperienceLevelForValue($experience) |
|
259
|
|
|
{ |
|
260
|
|
|
$datas = $this->getRule(); |
|
261
|
|
|
ksort($datas['experience']); |
|
262
|
|
|
$last = false; |
|
263
|
|
|
foreach ($datas['experience'] as $key => $level) { |
|
264
|
|
|
if ($experience >= $key) { |
|
265
|
|
|
$last = $level; |
|
266
|
|
|
} |
|
267
|
|
|
} |
|
268
|
|
|
return $last; |
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
|
/** |
|
272
|
|
|
* Get Injury For Value |
|
273
|
|
|
* |
|
274
|
|
|
* @param integer $value |
|
275
|
|
|
* |
|
276
|
|
|
* @return array|boolean |
|
277
|
|
|
*/ |
|
278
|
|
|
public function getInjury($value) |
|
279
|
|
|
{ |
|
280
|
|
|
return (isset($this->injuryTable[$value])) ? array( |
|
281
|
|
|
'key_name' => $this->injuryTable[$value], |
|
282
|
|
|
'effect' => $this->getInjuryEffect($this->injuryTable[$value]) |
|
283
|
|
|
) : false ; |
|
284
|
|
|
} |
|
285
|
|
|
|
|
286
|
|
|
/** |
|
287
|
|
|
* Get Injury Effect For Injury Key Name |
|
288
|
|
|
* |
|
289
|
|
|
* @param string $keyName |
|
290
|
|
|
* |
|
291
|
|
|
* @return array|boolean |
|
292
|
|
|
*/ |
|
293
|
|
|
public function getInjuryEffect($keyName) |
|
294
|
|
|
{ |
|
295
|
|
|
$datas = $this->getRule(); |
|
296
|
|
|
return ($datas['injuries'][$keyName]) ? $datas['injuries'][$keyName]['effects'] : false; |
|
297
|
|
|
} |
|
298
|
|
|
} |
|
299
|
|
|
|