|
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\Exception\NoVersionException; |
|
13
|
|
|
use Obblm\Core\Helper\PlayerHelper; |
|
14
|
|
|
use Obblm\Core\Helper\Rule\Roster\Roster; |
|
15
|
|
|
|
|
16
|
|
|
/**************************** |
|
17
|
|
|
* TEAM INFORMATION METHODS |
|
18
|
|
|
***************************/ |
|
19
|
|
|
trait AbstractTeamRuleTrait |
|
20
|
|
|
{ |
|
21
|
|
|
abstract public function getRoster(Team $team):RosterInterface; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @return int |
|
25
|
|
|
*/ |
|
26
|
1 |
|
public function getMaxTeamCost():int |
|
27
|
|
|
{ |
|
28
|
1 |
|
return ($this->rule['max_team_cost']) ? $this->rule['max_team_cost'] : TeamValue::LIMIT; |
|
|
|
|
|
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param Team $team |
|
33
|
|
|
* @return int |
|
34
|
|
|
*/ |
|
35
|
1 |
|
public function getRerollCost(Team $team):int |
|
36
|
|
|
{ |
|
37
|
|
|
/** @var Roster $roster */ |
|
38
|
1 |
|
$roster = $this->getRosters()->get($team->getRoster()); |
|
39
|
1 |
|
return (int) $roster->getRerollCost(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param Team $team |
|
44
|
|
|
* @return int |
|
45
|
|
|
*/ |
|
46
|
1 |
|
public function getApothecaryCost(Team $team):int |
|
|
|
|
|
|
47
|
|
|
{ |
|
48
|
1 |
|
return (int) $this->rule['sidelines_cost']['apothecary']; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @param Team $team |
|
53
|
|
|
* @return int |
|
54
|
|
|
*/ |
|
55
|
1 |
|
public function getCheerleadersCost(Team $team):int |
|
|
|
|
|
|
56
|
|
|
{ |
|
57
|
1 |
|
return (int) $this->rule['sidelines_cost']['cheerleaders']; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @param Team $team |
|
62
|
|
|
* @return int |
|
63
|
|
|
*/ |
|
64
|
1 |
|
public function getAssistantsCost(Team $team):int |
|
|
|
|
|
|
65
|
|
|
{ |
|
66
|
1 |
|
return (int) $this->rule['sidelines_cost']['assistants']; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @param Team $team |
|
71
|
|
|
* @return int |
|
72
|
|
|
*/ |
|
73
|
1 |
|
public function getPopularityCost(Team $team):int |
|
|
|
|
|
|
74
|
|
|
{ |
|
75
|
1 |
|
return (int) $this->rule['sidelines_cost']['popularity']; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @param Team $team |
|
80
|
|
|
* @return bool |
|
81
|
|
|
* @throws \Exception |
|
82
|
|
|
*/ |
|
83
|
1 |
|
public function couldHaveApothecary(Team $team):bool |
|
84
|
|
|
{ |
|
85
|
|
|
/** @var Roster $roster */ |
|
86
|
1 |
|
$roster = $this->getRosters()->get($team->getRoster()); |
|
87
|
1 |
|
return (bool) $roster->canHaveApothecary(); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function calculateTeamRate(TeamVersion $version):?int |
|
91
|
|
|
{ |
|
92
|
|
|
return $this->calculateTeamValue($version) / 10000; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
2 |
|
public function calculateTeamValue(TeamVersion $version, bool $excludeDisposable = false):int |
|
96
|
|
|
{ |
|
97
|
2 |
|
if (!$version->getTeam()) { |
|
98
|
1 |
|
throw new InvalidArgumentException(); |
|
99
|
|
|
} |
|
100
|
1 |
|
$value = 0; |
|
101
|
|
|
// Players |
|
102
|
1 |
|
$roster = $this->getRoster($version->getTeam()); |
|
103
|
|
|
// TODO: Bug => players are not version's one (because of dead players) |
|
104
|
1 |
|
foreach ($version->getTeam()->getAvailablePlayers() as $player) { |
|
105
|
1 |
|
if ($player->getPosition()) { |
|
106
|
|
|
try { |
|
107
|
1 |
|
$playerVersion = PlayerHelper::getLastVersion($player); |
|
108
|
1 |
|
} catch (NoVersionException $e) { // It's a new player ! |
|
109
|
1 |
|
$playerVersion = (new PlayerVersion()); |
|
110
|
1 |
|
$player->addVersion($playerVersion); |
|
111
|
1 |
|
$version->addPlayerVersion($playerVersion); |
|
112
|
1 |
|
$position = $roster->getPosition($player->getPosition()); |
|
113
|
|
|
$this->setPlayerDefaultValues($playerVersion, $position); |
|
|
|
|
|
|
114
|
|
|
} |
|
115
|
|
|
if (!$playerVersion->isMissingNextGame() && !($this->playerIsDisposable($playerVersion) && $excludeDisposable)) { |
|
116
|
|
|
$value += $playerVersion->getValue(); |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
// Sidelines |
|
121
|
1 |
|
$value += $version->getRerolls() * $this->getRerollCost($version->getTeam()); |
|
122
|
1 |
|
$value += $version->getAssistants() * $this->getAssistantsCost($version->getTeam()); |
|
123
|
1 |
|
$value += $version->getCheerleaders() * $this->getCheerleadersCost($version->getTeam()); |
|
124
|
1 |
|
$value += $version->getPopularity() * $this->getPopularityCost($version->getTeam()); |
|
125
|
1 |
|
$value += ($version->getApothecary()) ? $this->getApothecaryCost($version->getTeam()) : 0; |
|
126
|
|
|
|
|
127
|
1 |
|
return $value; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
abstract public function setPlayerDefaultValues(PlayerVersion $version, PositionInterface $position): ?PlayerVersion; |
|
131
|
|
|
abstract public function playerIsDisposable(PlayerVersion $version):bool; |
|
132
|
|
|
/** @return RosterInterface[]|ArrayCollection */ |
|
133
|
|
|
abstract public function getRosters():ArrayCollection; |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* @return array |
|
137
|
|
|
*/ |
|
138
|
|
|
public function getInjuriesTable():array |
|
139
|
|
|
{ |
|
140
|
|
|
return (array) $this->getInjuries(); |
|
|
|
|
|
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
2 |
|
public function getMaxPlayersByType($rosterKey, $typeKey): int |
|
144
|
|
|
{ |
|
145
|
|
|
/** @var PositionInterface $position */ |
|
146
|
2 |
|
$position = $this->getRosters()->get($rosterKey)->getPosition($typeKey); |
|
147
|
1 |
|
return (int) $position->getMax(); |
|
148
|
|
|
} |
|
149
|
|
|
} |
|
150
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths