1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Obblm\Core\Helper\Rule; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\Criteria; |
6
|
|
|
use Obblm\Core\Contracts\RuleHelperInterface; |
7
|
|
|
use Obblm\Core\Entity\Player; |
8
|
|
|
use Obblm\Core\Entity\PlayerVersion; |
9
|
|
|
use Obblm\Core\Entity\Rule; |
10
|
|
|
use Obblm\Core\Form\Player\ActionType; |
11
|
|
|
use Obblm\Core\Form\Player\InjuryType; |
12
|
|
|
use Obblm\Core\Helper\CoreTranslation; |
13
|
|
|
use Obblm\Core\Contracts\InducementInterface; |
14
|
|
|
use Obblm\Core\Helper\Rule\Inducement\StarPlayer; |
15
|
|
|
use Obblm\Core\Helper\Rule\Traits\AbstractInducementRuleTrait; |
16
|
|
|
use Obblm\Core\Helper\Rule\Traits\AbstractPlayerRuleTrait; |
17
|
|
|
use Obblm\Core\Helper\Rule\Traits\AbstractTeamRuleTrait; |
18
|
|
|
use Obblm\Core\Traits\ClassNameAsKeyTrait; |
19
|
|
|
|
20
|
|
|
abstract class AbstractRuleHelper extends RuleConfigBuilder implements RuleHelperInterface |
21
|
|
|
{ |
22
|
|
|
use ClassNameAsKeyTrait; |
23
|
|
|
|
24
|
|
|
protected $attachedRule; |
25
|
|
|
protected $rule = []; |
26
|
|
|
|
27
|
|
|
/**************** |
28
|
|
|
* COMPLIER PASS |
29
|
|
|
****************/ |
30
|
|
|
/** |
31
|
|
|
* @param Rule $rule |
32
|
|
|
* @return $this |
33
|
|
|
*/ |
34
|
1 |
|
public function attachRule(Rule $rule):RuleHelperInterface |
35
|
|
|
{ |
36
|
1 |
|
$this->setAttachedRule($rule); |
37
|
1 |
|
$this->build($rule->getRuleKey(), $rule->getRule()); |
38
|
1 |
|
return $this; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function getTransformedInducementsFor(string $roster) |
42
|
|
|
{ |
43
|
|
|
$table = $this->getInducementTable(); |
44
|
|
|
foreach ($table as $inducement) { |
45
|
|
|
if ($roster == 'halfling') { |
46
|
|
|
$inducement->setValue(10000); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
return $table; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/********** |
54
|
|
|
* CACHING |
55
|
|
|
*********/ |
56
|
|
|
|
57
|
2 |
|
public function getAttachedRule():?Rule |
58
|
|
|
{ |
59
|
2 |
|
return $this->attachedRule; |
60
|
|
|
} |
61
|
|
|
|
62
|
1 |
|
public function setAttachedRule(Rule $rule):RuleHelperInterface |
63
|
|
|
{ |
64
|
1 |
|
$this->attachedRule = $rule; |
65
|
1 |
|
$this->rule = $rule->getRule(); |
66
|
1 |
|
return $this; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/********************** |
70
|
|
|
* APPLICATION METHODS |
71
|
|
|
*********************/ |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return string |
75
|
|
|
*/ |
76
|
1 |
|
public function getInjuriesFormClass():string |
77
|
|
|
{ |
78
|
1 |
|
return InjuryType::class; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return string |
83
|
|
|
*/ |
84
|
1 |
|
public function getActionsFormClass():string |
85
|
|
|
{ |
86
|
1 |
|
return ActionType::class; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return string |
91
|
|
|
*/ |
92
|
1 |
|
public function getTemplateKey():string |
93
|
|
|
{ |
94
|
1 |
|
return $this->getAttachedRule()->getTemplate(); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
use AbstractTeamRuleTrait; |
98
|
|
|
|
99
|
|
|
use AbstractPlayerRuleTrait; |
100
|
|
|
|
101
|
|
|
/*************** |
102
|
|
|
* MISC METHODS |
103
|
|
|
**************/ |
104
|
|
|
public function getWeatherChoices():array |
105
|
|
|
{ |
106
|
|
|
$weather = []; |
107
|
|
|
$ruleKey = $this->getAttachedRule()->getRuleKey(); |
108
|
|
|
$fields = $this->rule['fields']; |
109
|
|
|
foreach ($fields as $fieldKey => $field) { |
110
|
|
|
$fieldLabel = CoreTranslation::getFieldKey($ruleKey, $fieldKey); |
111
|
|
|
$weather[$fieldLabel] = []; |
112
|
|
|
foreach ($field['weather'] as $fieldWeather) { |
113
|
|
|
$label = CoreTranslation::getWeatherKey($ruleKey, $fieldKey, $fieldWeather); |
114
|
|
|
$value = join(CoreTranslation::TRANSLATION_GLUE, [$ruleKey, 'default', $fieldWeather]); |
115
|
|
|
$weather[$fieldLabel][$label] = $value; |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
return $weather; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function createInducementAsPlayer(InducementInterface $inducement, $number = 0):?Player |
122
|
|
|
{ |
123
|
|
|
if (!$inducement instanceof StarPlayer) { |
124
|
|
|
return null; |
125
|
|
|
} |
126
|
|
|
$version = (new PlayerVersion()) |
127
|
|
|
->setCharacteristics($inducement->getCharacteristics()) |
128
|
|
|
->setValue($inducement->getValue()); |
129
|
|
|
if ($inducement->getSkills()) { |
130
|
|
|
$version->setSkills($inducement->getSkills()); |
131
|
|
|
} |
132
|
|
|
$player = (new Player()) |
133
|
|
|
->setNumber($number) |
134
|
|
|
->setType($inducement->getType()->getName()) |
135
|
|
|
->setName($inducement->getName()) |
136
|
|
|
->addVersion($version); |
137
|
|
|
return $player; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
public function createStarPlayerAsPlayer(string $key, int $number):Player |
141
|
|
|
{ |
142
|
|
|
$ruleKey = $this->getAttachedRule()->getRuleKey(); |
143
|
|
|
|
144
|
|
|
$starPlayer = $this->getStarPlayer($key); |
145
|
|
|
if (isset($starPlayer['multi_parts']) && $starPlayer['multi_parts']) { |
146
|
|
|
throw new \Exception('You cannot create a player with a multiple parts InducementInterface'); |
147
|
|
|
} |
148
|
|
|
$version = (new PlayerVersion()) |
149
|
|
|
->setCharacteristics($starPlayer['characteristics']) |
150
|
|
|
->setValue($starPlayer['cost']); |
151
|
|
|
if ($starPlayer['skills']) { |
152
|
|
|
$version->setSkills($starPlayer['skills']); |
153
|
|
|
} |
154
|
|
|
$player = (new Player()) |
155
|
|
|
->setNumber($number) |
156
|
|
|
->setType(CoreTranslation::getStarPlayerTitle($ruleKey)) |
157
|
|
|
->setName(CoreTranslation::getStarPlayerName($ruleKey, $key)) |
158
|
|
|
->addVersion($version); |
159
|
|
|
return $player; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
use AbstractInducementRuleTrait; |
163
|
|
|
} |
164
|
|
|
|