1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Obblm\Core\Helper\Rule\Traits; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
6
|
|
|
use Obblm\Core\Entity\PlayerVersion; |
7
|
|
|
use Obblm\Core\Entity\Team; |
8
|
|
|
use Obblm\Core\Entity\TeamVersion; |
9
|
|
|
use Obblm\Core\Exception\InvalidArgumentException; |
10
|
|
|
use Obblm\Core\Exception\NotFoundRuleKeyException; |
11
|
|
|
use Obblm\Core\Exception\NoVersionException; |
12
|
|
|
use Obblm\Core\Helper\PlayerHelper; |
13
|
|
|
use Obblm\Core\Helper\Rule\Roster\Roster; |
14
|
|
|
use Obblm\Core\Validator\Constraints\TeamValue; |
15
|
|
|
|
16
|
|
|
/**************************** |
17
|
|
|
* TEAM INFORMATION METHODS |
18
|
|
|
***************************/ |
19
|
|
|
trait AbstractTeamRuleTrait |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @return int |
23
|
|
|
*/ |
24
|
1 |
|
public function getMaxTeamCost():int |
25
|
|
|
{ |
26
|
1 |
|
return ($this->rule['max_team_cost']) ? $this->rule['max_team_cost'] : TeamValue::LIMIT; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param Team $team |
31
|
|
|
* @return int |
32
|
|
|
* @throws \Exception |
33
|
|
|
*/ |
34
|
1 |
|
public function getRerollCost(Team $team):int |
35
|
|
|
{ |
36
|
|
|
/** @var Roster $roster */ |
37
|
1 |
|
$roster = $this->getRosters()->get($team->getRoster()); |
|
|
|
|
38
|
1 |
|
return (int) $roster->getRerollCost(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param Team $team |
43
|
|
|
* @return int |
44
|
|
|
*/ |
45
|
1 |
|
public function getApothecaryCost(Team $team):int |
|
|
|
|
46
|
|
|
{ |
47
|
1 |
|
return (int) $this->rule['sidelines_cost']['apothecary']; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param Team $team |
52
|
|
|
* @return int |
53
|
|
|
*/ |
54
|
1 |
|
public function getCheerleadersCost(Team $team):int |
|
|
|
|
55
|
|
|
{ |
56
|
1 |
|
return (int) $this->rule['sidelines_cost']['cheerleaders']; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param Team $team |
61
|
|
|
* @return int |
62
|
|
|
*/ |
63
|
1 |
|
public function getAssistantsCost(Team $team):int |
|
|
|
|
64
|
|
|
{ |
65
|
1 |
|
return (int) $this->rule['sidelines_cost']['assistants']; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param Team $team |
70
|
|
|
* @return int |
71
|
|
|
*/ |
72
|
1 |
|
public function getPopularityCost(Team $team):int |
|
|
|
|
73
|
|
|
{ |
74
|
1 |
|
return (int) $this->rule['sidelines_cost']['popularity']; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param Team $team |
79
|
|
|
* @return bool |
80
|
|
|
* @throws \Exception |
81
|
|
|
*/ |
82
|
1 |
|
public function couldHaveApothecary(Team $team):bool |
83
|
|
|
{ |
84
|
|
|
/** @var Roster $roster */ |
85
|
1 |
|
$roster = $this->getRosters()->get($team->getRoster()); |
86
|
1 |
|
return (bool) $roster->canHaveApothecary(); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function calculateTeamRate(TeamVersion $version):?int |
90
|
|
|
{ |
91
|
|
|
return $this->calculateTeamValue($version) / 10000; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function calculateTeamValue(TeamVersion $version, bool $excludeDisposable = false):int |
95
|
|
|
{ |
96
|
|
|
if (!$version->getTeam()) { |
97
|
|
|
throw new InvalidArgumentException(); |
98
|
|
|
} |
99
|
|
|
$value = 0; |
100
|
|
|
// Players |
101
|
|
|
// TODO: Bug => players are not version's one (because od dead players) |
102
|
|
|
foreach ($version->getTeam()->getAvailablePlayers() as $player) { |
103
|
|
|
if ($player->getType()) { |
104
|
|
|
try { |
105
|
|
|
$playerVersion = PlayerHelper::getLastVersion($player); |
106
|
|
|
} catch (NoVersionException $e) { // It's a new player ! |
107
|
|
|
$playerVersion = (new PlayerVersion()); |
108
|
|
|
$player->addVersion($playerVersion); |
109
|
|
|
$version->addPlayerVersion($playerVersion); |
110
|
|
|
$this->setPlayerDefaultValues($playerVersion); |
111
|
|
|
} |
112
|
|
|
if (!$playerVersion->isMissingNextGame() && !($this->playerIsDisposable($playerVersion) && $excludeDisposable)) { |
113
|
|
|
$value += $playerVersion->getValue(); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
// Sidelines |
118
|
|
|
$value += $version->getRerolls() * $this->getRerollCost($version->getTeam()); |
119
|
|
|
$value += $version->getAssistants() * $this->getAssistantsCost($version->getTeam()); |
120
|
|
|
$value += $version->getCheerleaders() * $this->getCheerleadersCost($version->getTeam()); |
121
|
|
|
$value += $version->getPopularity() * $this->getPopularityCost($version->getTeam()); |
122
|
|
|
$value += ($version->getApothecary()) ? $this->getApothecaryCost($version->getTeam()) : 0; |
123
|
|
|
|
124
|
|
|
return $value; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
abstract public function setPlayerDefaultValues(PlayerVersion $version): ?PlayerVersion; |
128
|
|
|
abstract public function playerIsDisposable(PlayerVersion $version):bool; |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @return array |
132
|
|
|
*/ |
133
|
|
|
public function getInjuriesTable():array |
134
|
|
|
{ |
135
|
|
|
return (array) $this->getInjuries(); |
|
|
|
|
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
public function getMaxPlayersByType($rosterKey, $typeKey): int |
139
|
|
|
{ |
140
|
|
|
/** @var Roster $roster */ |
141
|
|
|
$roster = $this->getRosters()->get($rosterKey); |
142
|
|
|
if (!$type = $roster->getPlayerTypes()[$typeKey]) { |
143
|
|
|
throw new NotFoundRuleKeyException($typeKey, 'toto'); |
|
|
|
|
144
|
|
|
} |
145
|
|
|
return (int) $type['max']; |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|