1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Talent\Service; |
4
|
|
|
|
5
|
|
|
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Shared\Model\SpecValueObject; |
6
|
|
|
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Talent\Model\TalentsValueObject; |
7
|
|
|
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Talent\Model\TalentValueObject; |
8
|
|
|
use Kubinashi\BattlenetApi\WorldOfWarcraft\Model\SpellValueObject; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @author Willy Reiche |
12
|
|
|
* @since 2017-08-28 |
13
|
|
|
* @version 1.0 |
14
|
|
|
*/ |
15
|
|
|
class TalentService |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @param \StdClass $responseObject |
19
|
|
|
* |
20
|
|
|
* @return TalentValueObject[] |
21
|
|
|
*/ |
22
|
|
|
public function prepareTalentValueObject($responseObject) |
23
|
|
|
{ |
24
|
|
|
$talents = []; |
25
|
|
|
|
26
|
|
|
foreach ($responseObject->talents as $talent) { |
27
|
|
|
if (empty($talent->calcSpec)) { |
28
|
|
|
continue; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
$selected = false; |
32
|
|
|
if (isset($talent->selected)) { |
33
|
|
|
$selected = true; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
$talentsValueObject = $this->prepareTalentsValueObject($talent); |
37
|
|
|
$specValueObject = $this->prepareSpecValueObject($talent->spec); |
38
|
|
|
|
39
|
|
|
$talents[] = new TalentValueObject( |
40
|
|
|
$selected, |
41
|
|
|
$talentsValueObject, |
42
|
|
|
$specValueObject, |
43
|
|
|
$talent->calcTalent, |
44
|
|
|
$talent->calcSpec |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
return $talents; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param \StdClass $talent |
53
|
|
|
* @return TalentsValueObject[] |
54
|
|
|
*/ |
55
|
|
|
private function prepareTalentsValueObject($talent) |
56
|
|
|
{ |
57
|
|
|
$talents = []; |
58
|
|
|
foreach ($talent->talents as $talent) { |
59
|
|
|
$cooldown = ""; |
60
|
|
|
if (isset($talent->spell->cooldown)) { |
61
|
|
|
$cooldown = $talent->spell->cooldown; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$spell = new SpellValueObject( |
65
|
|
|
$talent->spell->id, |
66
|
|
|
$talent->spell->name, |
67
|
|
|
$talent->spell->icon, |
68
|
|
|
$talent->spell->description, |
69
|
|
|
$talent->spell->castTime, |
70
|
|
|
$cooldown |
71
|
|
|
); |
72
|
|
|
|
73
|
|
|
$spec = $this->prepareSpecValueObject($talent->spec); |
74
|
|
|
|
75
|
|
|
$talents[] = new TalentsValueObject( |
76
|
|
|
$talent->tier, |
77
|
|
|
$talent->column, |
78
|
|
|
$spell, |
79
|
|
|
$spec |
80
|
|
|
); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
return $talents; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param \StdClass $spec |
88
|
|
|
* @return SpecValueObject |
89
|
|
|
*/ |
90
|
|
|
private function prepareSpecValueObject($spec) |
91
|
|
|
{ |
92
|
|
|
return new SpecValueObject( |
93
|
|
|
$spec->name, |
94
|
|
|
$spec->role, |
95
|
|
|
$spec->backgroundImage, |
96
|
|
|
$spec->icon, |
97
|
|
|
$spec->description, |
98
|
|
|
$spec->order |
99
|
|
|
); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|