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