-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathTrophy.php
155 lines (135 loc) · 3.45 KB
/
Trophy.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
namespace Tustin\PlayStation\Model\Trophy;
use Tustin\PlayStation\Model;
use Tustin\PlayStation\Enum\TrophyType;
class Trophy extends Model
{
public function __construct(private TrophyGroup $trophyGroup, private int $id)
{
parent::__construct($trophyGroup->getHttpClient());
}
/**
* Creates a new trophy from existing data.
*/
public static function fromObject(TrophyGroup $trophyGroup, object $data): self
{
$trophy = new static($trophyGroup, $data->trophyId);
$trophy->setCache($data);
return $trophy;
}
/**
* Gets the trophy name.
*/
public function name(): string
{
return $this->pluck('trophyName');
}
/**
* Gets the trophy id.
*/
public function id(): int
{
return $this->id ??= $this->pluck('id');
}
/**
* Gets the trophy details.
*/
public function detail(): string
{
return $this->pluck('trophyDetail');
}
/**
* Gets the trophy type. (platinum, bronze, silver, gold)
*/
public function type(): TrophyType
{
return TrophyType::from($this->pluck('trophyType'));
}
/**
* Get the trophy earned rate.
*/
public function earnedRate(): float
{
return $this->pluck('trophyEarnedRate');
}
/**
* Check if the trophy is hidden.
*/
public function hidden(): bool
{
return $this->pluck('trophyHidden');
}
/**
* Gets the trophy icon URL.
*/
public function iconUrl(): string
{
return $this->pluck('trophyIconUrl');
}
/**
* Gets the trophy progress target value, if any.
*/
public function progressTargetValue(): string
{
return $this->pluck('trophyProgressTargetValue') ?? '';
}
/**
* Gets the trophy reward name, if any.
* Examples: "Emote", "Profile Avatar", "Profile Banner"
*/
public function rewardName(): string
{
return $this->pluck('trophyRewardName') ?? '';
}
/**
* Gets the trophy reward image url, if any.
*/
public function rewardImageUrl(): string
{
return $this->pluck('trophyRewardImageUrl') ?? '';
}
/**
* Check if the user have earned this trophy.
*/
public function earned(): bool
{
return $this->pluck('earned');
}
/**
* Get the date and time the user earned this trophy, if any.
*/
public function earnedDateTime(): string
{
return $this->pluck('earnedDateTime') ?? '';
}
/**
* Get the progress count for the user on this trophy, if any.
*/
public function progress(): string
{
return $this->pluck('progress') ?? '';
}
/**
* Get the progress percentage for the user on this trophy, if any.
*/
public function progressRate(): string
{
return $this->pluck('progressRate') ?? '';
}
/**
* Get the date and time when a progress was made for the user on this trophy, if any.
*/
public function progressedDateTime(): string
{
return $this->pluck('progressedDateTime') ?? '';
}
/**
* Fetches the trophy data from the API.
*/
public function fetch(): object
{
return $this->get('trophy/v1/npCommunicationIds/' . $this->trophyGroup->title()->npCommunicationId() . '/trophies/' . $this->id(), [
'npServiceName' => $this->trophyGroup->title()->serviceName()
]);
}
}