1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
namespace App\Lib\DsManager\Models;
|
4
|
|
|
|
5
|
|
|
|
6
|
|
|
/**
|
7
|
|
|
* Class Module
|
8
|
|
|
* @package App\Lib\DsManager\Models
|
9
|
|
|
*/
|
10
|
|
|
use App\Lib\Helpers\Config;
|
11
|
|
|
|
12
|
|
|
/**
|
13
|
|
|
* Class Module
|
14
|
|
|
* @package App\Lib\DsManager\Models
|
15
|
|
|
*/
|
16
|
|
|
class Module
|
17
|
|
|
{
|
18
|
|
|
/**
|
19
|
|
|
* @var
|
20
|
|
|
*/
|
21
|
|
|
private $moduleCode;
|
22
|
|
|
/**
|
23
|
|
|
* @var
|
24
|
|
|
*/
|
25
|
|
|
private $configuration;
|
26
|
|
|
|
27
|
|
|
/**
|
28
|
|
|
* @param $module
|
29
|
|
|
*/
|
30
|
|
|
public function __construct($module)
|
31
|
|
|
{
|
32
|
|
|
$this->moduleCode = $module;
|
33
|
|
|
$this->configuration = Config::get("modules.modules")[$module];
|
34
|
|
|
if ($this->configuration == null) throw new \InvalidArgumentException("Not a valid Module supplied");
|
35
|
|
|
}
|
36
|
|
|
|
37
|
|
|
/**
|
38
|
|
|
*
|
39
|
|
|
*/
|
40
|
|
|
public function isOffensive()
|
41
|
|
|
{
|
42
|
|
|
return ($this->configuration["character"] === 1);
|
43
|
|
|
}
|
44
|
|
|
|
45
|
|
|
/**
|
46
|
|
|
*
|
47
|
|
|
*/
|
48
|
|
|
public function isBalanced()
|
49
|
|
|
{
|
50
|
|
|
return ($this->configuration["character"] === 2);
|
51
|
|
|
}
|
52
|
|
|
|
53
|
|
|
/**
|
54
|
|
|
*
|
55
|
|
|
*/
|
56
|
|
|
public function isDefensive()
|
57
|
|
|
{
|
58
|
|
|
return ($this->configuration["character"] === 4);
|
59
|
|
|
}
|
60
|
|
|
|
61
|
|
|
/**
|
62
|
|
|
* @return string
|
63
|
|
|
*/
|
64
|
|
|
function __toString()
|
|
|
|
|
65
|
|
|
{
|
66
|
|
|
return "" . $this->moduleCode;
|
67
|
|
|
}
|
68
|
|
|
|
69
|
|
|
|
70
|
|
|
/**
|
71
|
|
|
* @param Team $team
|
72
|
|
|
* @return bool
|
73
|
|
|
*/
|
74
|
|
|
public function isApplicableToTeam(Team $team)
|
75
|
|
|
{
|
76
|
|
|
return $this->isApplicableToArray($team->playersPerRoleArray());
|
77
|
|
|
}
|
78
|
|
|
|
79
|
|
|
public function isApplicableToArray($playersForRole)
|
80
|
|
|
{
|
81
|
|
|
$roles = $this->getRoleNeeded();
|
82
|
|
|
foreach ($roles as $role => $numbP) {
|
83
|
|
|
if (!(isset($playersForRole[$role]) && $playersForRole[$role] >= $numbP)) {
|
84
|
|
|
return false;
|
85
|
|
|
}
|
86
|
|
|
}
|
87
|
|
|
return true;
|
88
|
|
|
}
|
89
|
|
|
|
90
|
|
|
|
91
|
|
|
/**
|
92
|
|
|
* @param bool $complete
|
93
|
|
|
* @return array
|
94
|
|
|
*/
|
95
|
|
|
public function getRoleNeeded($complete = false)
|
96
|
|
|
{
|
97
|
|
|
$rolesNeeded = [];
|
98
|
|
|
$roles = \App\Lib\Helpers\Config::get('modules.roles');
|
|
|
|
|
99
|
|
|
$rolesKeys = array_keys($roles);
|
100
|
|
|
foreach ($this->configuration["roles"] as $index => $playNum) {
|
101
|
|
|
if ($playNum != 0 || $complete)
|
102
|
|
|
$rolesNeeded[$rolesKeys[$index]] = $playNum;
|
103
|
|
|
}
|
104
|
|
|
|
105
|
|
|
return $rolesNeeded;
|
106
|
|
|
}
|
107
|
|
|
|
108
|
|
|
|
109
|
|
|
} |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.