1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Obblm\Core\Helper\Rule\Traits; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
6
|
|
|
use Obblm\Core\Contracts\PositionInterface; |
7
|
|
|
use Obblm\Core\Contracts\RosterInterface; |
8
|
|
|
use Obblm\Core\Entity\PlayerVersion; |
9
|
|
|
use Obblm\Core\Entity\Team; |
10
|
|
|
use Obblm\Core\Entity\TeamVersion; |
11
|
|
|
use Obblm\Core\Exception\InvalidArgumentException; |
12
|
|
|
use Obblm\Core\Helper\PlayerHelper; |
13
|
|
|
use Obblm\Core\Helper\Rule\Roster\Roster; |
14
|
|
|
use Obblm\Core\Validator\Constraints\Team\AdditionalSkills; |
15
|
|
|
use Obblm\Core\Validator\Constraints\Team\Value; |
16
|
|
|
|
17
|
|
|
/**************************** |
18
|
|
|
* TEAM INFORMATION METHODS |
19
|
|
|
***************************/ |
20
|
|
|
trait AbstractTeamRuleTrait |
21
|
|
|
{ |
22
|
|
|
abstract public function getRoster(Team $team):RosterInterface; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @return int |
26
|
|
|
*/ |
27
|
1 |
|
public function getMaxTeamCost(Team $team = null):int |
28
|
|
|
{ |
29
|
1 |
|
if ($team && $team->getCreationOption('max_team_cost')) { |
30
|
|
|
return $team->getCreationOption('max_team_cost'); |
|
|
|
|
31
|
|
|
} |
32
|
|
|
|
33
|
1 |
|
return ($this->rule['max_team_cost']) ? $this->rule['max_team_cost'] : Value::LIMIT; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param Team $team |
38
|
|
|
* @return int |
39
|
|
|
*/ |
40
|
1 |
|
public function getRerollCost(Team $team):int |
41
|
|
|
{ |
42
|
|
|
/** @var Roster $roster */ |
43
|
1 |
|
$roster = $this->getRosters()->get($team->getRoster()); |
44
|
1 |
|
return (int) $roster->getRerollCost(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param Team $team |
49
|
|
|
* @return int |
50
|
|
|
*/ |
51
|
1 |
|
public function getApothecaryCost(Team $team):int |
|
|
|
|
52
|
|
|
{ |
53
|
1 |
|
return (int) $this->rule['sidelines_cost']['apothecary']; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param Team $team |
58
|
|
|
* @return int |
59
|
|
|
*/ |
60
|
1 |
|
public function getCheerleadersCost(Team $team):int |
|
|
|
|
61
|
|
|
{ |
62
|
1 |
|
return (int) $this->rule['sidelines_cost']['cheerleaders']; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param Team $team |
67
|
|
|
* @return int |
68
|
|
|
*/ |
69
|
1 |
|
public function getAssistantsCost(Team $team):int |
|
|
|
|
70
|
|
|
{ |
71
|
1 |
|
return (int) $this->rule['sidelines_cost']['assistants']; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param Team $team |
76
|
|
|
* @return int |
77
|
|
|
*/ |
78
|
1 |
|
public function getPopularityCost(Team $team):int |
|
|
|
|
79
|
|
|
{ |
80
|
1 |
|
return (int) $this->rule['sidelines_cost']['popularity']; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param Team $team |
85
|
|
|
* @return bool |
86
|
|
|
* @throws \Exception |
87
|
|
|
*/ |
88
|
1 |
|
public function couldHaveApothecary(Team $team):bool |
89
|
|
|
{ |
90
|
|
|
/** @var Roster $roster */ |
91
|
1 |
|
$roster = $this->getRosters()->get($team->getRoster()); |
92
|
1 |
|
return (bool) $roster->canHaveApothecary(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function calculateTeamRate(TeamVersion $version):?int |
96
|
|
|
{ |
97
|
|
|
return $this->calculateTeamValue($version) / 10000; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function calculateInducementsCost(array $inducements):int |
101
|
|
|
{ |
102
|
|
|
$cost = 0; |
103
|
|
|
foreach ($inducements as $key) { |
104
|
|
|
$cost += $this->getInducement($key)->getValue(); |
|
|
|
|
105
|
|
|
} |
106
|
|
|
return $cost; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function updatePlayerVersionCost(PlayerVersion $playerVersion) |
110
|
|
|
{ |
111
|
|
|
$position = $this->getPlayerPosition($playerVersion->getPlayer()); |
|
|
|
|
112
|
|
|
if ($playerVersion->getPlayer()->getTeam()->getCreationOption('skills_allowed') && $playerVersion->getPlayer()->getTeam()->getCreationOption('skills_allowed.choice') == AdditionalSkills::NOT_FREE) { |
113
|
|
|
if (!$playerVersion->isHiredStarPlayer() && !$playerVersion->getPlayer()->isStarPlayer()) { |
|
|
|
|
114
|
|
|
$extra = $this->getPlayerVersionExtraCosts($playerVersion); |
|
|
|
|
115
|
|
|
$playerVersion->setValue($position->getCost() + $extra); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
120
|
2 |
|
public function calculateTeamValue(TeamVersion $version, bool $excludeDisposable = false):int |
121
|
|
|
{ |
122
|
2 |
|
if (!$version->getTeam()) { |
123
|
1 |
|
throw new InvalidArgumentException(); |
124
|
|
|
} |
125
|
1 |
|
$value = 0; |
126
|
|
|
// Players |
127
|
1 |
|
$roster = $this->getRoster($version->getTeam()); |
|
|
|
|
128
|
1 |
|
foreach ($version->getNotDeadPlayerVersions() as $playerVersion) { |
129
|
|
|
$player = $playerVersion->getPlayer(); |
130
|
|
|
if ($player->getPosition()) { |
131
|
|
|
$playerVersion = PlayerHelper::getLastVersion($player); |
132
|
|
|
//$this->updatePlayerVersionCost($playerVersion); |
133
|
|
|
if (!$playerVersion->isMissingNextGame() && !($this->playerIsDisposable($playerVersion) && $excludeDisposable)) { |
134
|
|
|
$value += $playerVersion->getValue(); |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
// Sidelines |
139
|
1 |
|
$value += $version->getRerolls() * $this->getRerollCost($version->getTeam()); |
140
|
1 |
|
$value += $version->getAssistants() * $this->getAssistantsCost($version->getTeam()); |
141
|
1 |
|
$value += $version->getCheerleaders() * $this->getCheerleadersCost($version->getTeam()); |
142
|
1 |
|
$value += $version->getPopularity() * $this->getPopularityCost($version->getTeam()); |
143
|
1 |
|
$value += ($version->getApothecary()) ? $this->getApothecaryCost($version->getTeam()) : 0; |
144
|
|
|
|
145
|
1 |
|
return $value; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
abstract public function setPlayerDefaultValues(PlayerVersion $version, PositionInterface $position): ?PlayerVersion; |
149
|
|
|
abstract public function playerIsDisposable(PlayerVersion $version):bool; |
150
|
|
|
/** @return RosterInterface[]|ArrayCollection */ |
151
|
|
|
abstract public function getRosters():ArrayCollection; |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @return array |
155
|
|
|
*/ |
156
|
|
|
public function getInjuriesTable():array |
157
|
|
|
{ |
158
|
|
|
return (array) $this->getInjuries(); |
|
|
|
|
159
|
|
|
} |
160
|
|
|
|
161
|
2 |
|
public function getMaxPlayersByType($rosterKey, $typeKey): int |
162
|
|
|
{ |
163
|
|
|
/** @var PositionInterface $position */ |
164
|
2 |
|
$position = $this->getRosters()->get($rosterKey)->getPosition($typeKey); |
165
|
1 |
|
return (int) $position->getMax(); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
public function applyTeamExtraCosts(TeamVersion $version, $creationPhase = false) |
169
|
|
|
{ |
170
|
|
|
if ($creationPhase && |
171
|
|
|
$version->getTeam()->getCreationOption('skills_allowed') && |
172
|
|
|
$version->getTeam()->getCreationOption('skills_allowed.choice') == AdditionalSkills::NOT_FREE) { |
173
|
|
|
foreach ($version->getNotDeadPlayerVersions() as $playerVersion) { |
174
|
|
|
if (!$playerVersion->isHiredStarPlayer() && !$playerVersion->getPlayer()->isStarPlayer()) { |
175
|
|
|
$extra = $this->getPlayerVersionExtraCosts($playerVersion); |
176
|
|
|
$position = $this->getPlayerPosition($playerVersion->getPlayer()); |
177
|
|
|
$playerVersion->setValue($position->getCost() + $extra); |
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
|