|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Obblm\Core\Helper; |
|
4
|
|
|
|
|
5
|
|
|
use Obblm\Core\Entity\Team; |
|
6
|
|
|
use Obblm\Core\Entity\TeamVersion; |
|
7
|
|
|
use Obblm\Core\Contracts\RuleHelperInterface; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class TeamHelper |
|
11
|
|
|
* @package Obblm\Core\Helper |
|
12
|
|
|
*/ |
|
13
|
|
|
class TeamHelper |
|
14
|
|
|
{ |
|
15
|
|
|
private $ruleHelper; |
|
16
|
|
|
|
|
17
|
|
|
public function __construct(RuleHelper $ruleHelper) |
|
18
|
|
|
{ |
|
19
|
|
|
$this->ruleHelper = $ruleHelper; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @param Team $team |
|
24
|
|
|
* @return RuleHelperInterface |
|
25
|
|
|
* @throws \Exception |
|
26
|
|
|
*/ |
|
27
|
|
|
public function getRuleHelper(Team $team):RuleHelperInterface |
|
28
|
|
|
{ |
|
29
|
|
|
if (!$team->getRule()) { |
|
30
|
|
|
throw new \Exception('This team does not have a rule'); |
|
31
|
|
|
} |
|
32
|
|
|
return $this->ruleHelper->getHelper($team->getRule()); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
1 |
|
public static function getLastVersion(Team $team):TeamVersion |
|
36
|
|
|
{ |
|
37
|
1 |
|
$versions = $team->getVersions(); |
|
38
|
|
|
/** @var TeamVersion $last */ |
|
39
|
1 |
|
$last = $versions->first(); |
|
40
|
1 |
|
if ($last) { |
|
|
|
|
|
|
41
|
|
|
return $last; |
|
42
|
|
|
} |
|
43
|
1 |
|
$version = new TeamVersion(); |
|
44
|
1 |
|
$team->addVersion($version); |
|
45
|
1 |
|
return $version; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/********************** |
|
49
|
|
|
* TEAM HELPER METHODS |
|
50
|
|
|
**********************/ |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param Team $team |
|
54
|
|
|
* @return TeamVersion |
|
55
|
|
|
* @throws \Psr\Cache\InvalidArgumentException |
|
56
|
|
|
*/ |
|
57
|
|
|
public function createNewTeamVersion(Team $team):TeamVersion |
|
58
|
|
|
{ |
|
59
|
|
|
$treasure = $this->getNewTeamVersionTreasure($team); |
|
60
|
|
|
|
|
61
|
|
|
return (TeamHelper::getLastVersion($team)) |
|
62
|
|
|
->setTreasure($treasure); |
|
63
|
|
|
} |
|
64
|
|
|
public function getNewTeamVersionTreasure(Team $team):int |
|
65
|
|
|
{ |
|
66
|
|
|
if ($team->getVersions()->count() > 0) { |
|
67
|
|
|
return TeamHelper::getLastVersion($team)->getTreasure(); |
|
68
|
|
|
} |
|
69
|
|
|
return $this->getTeamBaseTreasure($team); |
|
70
|
|
|
} |
|
71
|
|
|
public function getTeamBaseTreasure(Team $team):int |
|
72
|
|
|
{ |
|
73
|
|
|
$options = $team->getCreationOptions(); |
|
74
|
|
|
if (isset($options['max_team_cost'])) { |
|
75
|
|
|
return $options['max_team_cost']; |
|
76
|
|
|
} |
|
77
|
|
|
return $this->ruleHelper->getHelper($team)->getMaxTeamCost(); |
|
78
|
|
|
} |
|
79
|
|
|
public function destructTeamVersion(Team $team):TeamVersion |
|
|
|
|
|
|
80
|
|
|
{ |
|
81
|
|
|
} |
|
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @param Team $team |
|
85
|
|
|
* @return bool |
|
86
|
|
|
* @throws \Exception |
|
87
|
|
|
*/ |
|
88
|
|
|
public function couldHaveApothecary(Team $team):bool |
|
89
|
|
|
{ |
|
90
|
|
|
if (!$team->getRule()) { |
|
91
|
|
|
throw new \Exception('This team does not have a rule'); |
|
92
|
|
|
} |
|
93
|
|
|
return (bool) $this->getRuleHelper($team)->couldHaveApothecary($team); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|