1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Collection\Service; |
4
|
|
|
|
5
|
|
|
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Collection\Model\CollectionValueObject; |
6
|
|
|
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Collection\Model\MountValueObject; |
7
|
|
|
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Collection\Model\PetStatValueObject; |
8
|
|
|
use Kubinashi\BattlenetApi\WorldOfWarcraft\CharacterProfileApi\Collection\Model\PetValueObject; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @author Willy Reiche |
12
|
|
|
* @since 2017-08-28 |
13
|
|
|
* @version 1.0 |
14
|
|
|
*/ |
15
|
|
|
class CollectionService |
16
|
|
|
{ |
17
|
|
|
const MOUNT = 'MOUNT'; |
18
|
|
|
const PET = 'PET'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @param \StdClass $object |
22
|
|
|
* @param string $type |
23
|
|
|
* |
24
|
|
|
* @return CollectionValueObject |
25
|
|
|
*/ |
26
|
|
|
public function prepareCollectionValueObject($object, $type) |
27
|
|
|
{ |
28
|
|
|
$collected = []; |
29
|
|
|
foreach ($object->collected as $collect) { |
30
|
|
|
switch ($type) { |
31
|
|
|
case self::MOUNT: |
32
|
|
|
$collected[] = $this->prepareMountValueObject($collect); |
33
|
|
|
break; |
34
|
|
|
case self::PET: |
35
|
|
|
$collected[] = $this->preparePetValueObject($collect); |
36
|
|
|
break; |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
return new CollectionValueObject( |
41
|
|
|
$object->numCollected, |
42
|
|
|
$object->numNotCollected, |
43
|
|
|
$collected |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param \StdClass $mount |
49
|
|
|
* @return MountValueObject |
50
|
|
|
*/ |
51
|
|
|
private function prepareMountValueObject(\StdClass $mount) |
52
|
|
|
{ |
53
|
|
|
return new MountValueObject( |
54
|
|
|
$mount->name, |
55
|
|
|
$mount->spellId, |
56
|
|
|
$mount->creatureId, |
57
|
|
|
$mount->itemId, |
58
|
|
|
$mount->qualityId, |
59
|
|
|
$mount->icon, |
60
|
|
|
$mount->isGround, |
61
|
|
|
$mount->isFlying, |
62
|
|
|
$mount->isAquatic, |
63
|
|
|
$mount->isJumping |
64
|
|
|
); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param \StdClass $pet |
69
|
|
|
* @return PetValueObject |
70
|
|
|
*/ |
71
|
|
|
private function preparePetValueObject($pet) |
72
|
|
|
{ |
73
|
|
|
$petStatValueObject = $this->preparePetStatsValueObject($pet->stats); |
74
|
|
|
|
75
|
|
|
return new PetValueObject( |
76
|
|
|
$pet->name, |
77
|
|
|
$pet->spellId, |
78
|
|
|
$pet->creatureId, |
79
|
|
|
$pet->itemId, |
80
|
|
|
$pet->qualityId, |
81
|
|
|
$pet->icon, |
82
|
|
|
$petStatValueObject, |
83
|
|
|
$pet->battlePetGuid, |
84
|
|
|
$pet->isFavorite, |
85
|
|
|
$pet->isFirstAbilitySlotSelected, |
86
|
|
|
$pet->isSecondAbilitySlotSelected, |
87
|
|
|
$pet->isThirdAbilitySlotSelected, |
88
|
|
|
$pet->creatureName, |
89
|
|
|
$pet->canBattle |
90
|
|
|
); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param \StdClass $stats |
95
|
|
|
* @return PetStatValueObject |
96
|
|
|
*/ |
97
|
|
|
private function preparePetStatsValueObject($stats) |
98
|
|
|
{ |
99
|
|
|
return new PetStatValueObject( |
100
|
|
|
$stats->speciesId, |
101
|
|
|
$stats->breedId, |
102
|
|
|
$stats->petQualityId, |
103
|
|
|
$stats->level, |
104
|
|
|
$stats->health, |
105
|
|
|
$stats->power, |
106
|
|
|
$stats->speed |
107
|
|
|
); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|