-
Notifications
You must be signed in to change notification settings - Fork 1
/
user_defines.php
244 lines (224 loc) · 8.09 KB
/
user_defines.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<?php
class UserDefines {
function __construct($server, $user_id, $user_hash, $raw_user_data = '') {
$raw_user_data = trim($raw_user_data);
if (empty($raw_user_data)) {
if (empty($server)) {
$server = 'idlemaster';
}
$response = call_cne($server, $user_id, $user_hash, 'getUserDetails', '&instance_key=0');
$json_response = json_decode($response);
} else {
$json_response = json_decode ("{}");
$json_response->details = json_decode($raw_user_data);
}
$this->json_response = $json_response;
if (!empty($this->json_response->failure_reason) || empty($json_response->details) || empty($json_response->details->instance_id)) {
echo "You most likely entered an incorrect userid/hash, please go back and confirm your entry<br>";
die();
}
$this->user_json = $json_response->details;
$this->all_season_data = $this->user_json->seasons;
$this->instance_id = $this->user_json->instance_id;
$this->crafting_materials = $this->user_json->crafting_materials;
$this->reset_currency_spent = $this->user_json->reset_currency_spent;
$this->reset_currency = $this->user_json->reset_currency;
$this->taskmasters = $this->get_taskmasters();
$this->talents = $this->get_talents();
//For some reason the raw json and the data pulled directly from CNE differs.......
if (!empty($raw_user_data)) {
$this->can_buy_olympian = $this->user_json->objective_status[852]->complete;
} else {
$this->can_buy_olympian = $this->user_json->objective_status[825]->complete;
}
if (!empty($raw_user_data)) {
$this->can_buy_newt = $this->user_json->objective_status[854]->complete;
} else {
$this->can_buy_newt = $this->user_json->objective_status[827]->complete;
}
$this->loot = $this->get_loot();
$this->buffs = $this->get_buffs();
$crusader_info = $this->get_crusaders();
$this->crusaders = $crusader_info['crusaders'];
$this->total_ep = $crusader_info['total_ep'];
$this->number_owned_crusaders = $crusader_info['number_owned_crusaders'];
$this->chests = $this->get_chests();
$this->stats = $this->get_stats();
$this->max_areas_for_dungeons = $this->get_max_areas_for_dungeons();
$this->skins = $this->get_skins();
$this->formation_saves = $this->get_formation_saves();
$this->abilities = $this->get_abilities();
$this->missions = $this->get_missions();
$this->owned_crafting_recipes = $this->get_owned_crafting_recipes();
$this->total_gems = $this->get_total_level_one_gem_value();
$this->total_gems_available = $this->get_total_level_one_gem_value_available();
}
public function get_loot() {
$loot = array();
foreach($this->user_json->loot AS $id => $item) {
$loot[$item->loot_id] = $item;
}
return $loot;
}
public function get_buffs() {
$buffs = array();
foreach($this->user_json->buffs AS $item) {
$buffs[$item->buff_id] = $item;
}
return $buffs;
}
public function get_talents() {
$talents = array();
foreach($this->user_json->talents AS $talent_id => $levels) {
$talents[$talent_id] = $levels;
}
return $talents;
}
public function get_taskmasters() {
$taskmasters = array();
foreach($this->user_json->taskmasters->taskmasters AS $id => $taskmaster) {
$taskmasters[$taskmaster->id] = $taskmaster;
}
return $taskmasters;
}
public function get_crusaders() {
$this->set_assigned_gems();
$return = array();
$return['total_ep'] = 0;
$return['number_owned_crusaders'] = 0;
$return['crusaders'] = array();
foreach($this->user_json->heroes AS $hero) {
$return['crusaders'][$hero->hero_id] = $hero;
if (isset($this->assigned_gems[$hero->hero_id])) {
$return['crusaders'][$hero->hero_id]->gems = $this->assigned_gems[$hero->hero_id];
} else {
$return['crusaders'][$hero->hero_id]->gems = array();
}
if ($hero->owned == 1) {
$return['total_ep'] += $hero->disenchant;
$return['number_owned_crusaders'] += 1;
}
}
return $return;
}
public function get_missions() {
$missions = array('available_missions' => []);
foreach($this->user_json->mission_data AS $id => $mission) {
if (is_array($mission)) {
foreach ($mission AS $mission_info) {
$missions[$id][$mission_info->mission_id] = $mission_info;
}
} else {
$missions[$id] = $mission;
}
}
return $missions;
}
public function get_chests() {
$chests = array();
$chests[1] = $this->user_json->normal_loot_chests;
$chests[2] = $this->user_json->rare_loot_chests;
if (!empty($this->user_json->chests)) {
foreach($this->user_json->chests AS $id => $chest) {
$chests[$id] = $chest;
}
}
return $chests;
}
public function get_stats() {
$stats = array();
if (!empty($this->user_json->stats)) {
foreach($this->user_json->stats AS $stat => $value) {
$stats[$stat] = $value;
}
}
return $stats;
}
public function get_formation_saves() {
$formation_saves = array();
if (!empty($this->user_json->formation_saves)) {
foreach($this->user_json->formation_saves AS $formation_type => $formation_save) {
$formation_saves[$formation_type] = $formation_save;
}
}
return $formation_saves;
}
public function get_abilities() {
$abilities = array();
if (!empty($this->user_json->abilities)) {
foreach($this->user_json->abilities AS $ability) {
$abilities[$ability->ability_id] = $ability;
}
}
return $abilities;
}
public function get_owned_crafting_recipes() {
$owned_crafting_recipes = array();
foreach($this->user_json->owned_crafting_recipes AS $id => $owned_crafting_recipe) {
$owned_crafting_recipes[$id] = $owned_crafting_recipe;
}
return $owned_crafting_recipes;
}
public function get_skins() {
$skins = array();
if (!empty($this->user_json->skins) && !empty($this->user_json->skins->skins)) {
foreach($this->user_json->skins->skins AS $hero_skin) {
$skins[$hero_skin->id] = $hero_skin;
}
}
return $skins;
}
private function set_assigned_gems() {
$this->assigned_gems = array();
foreach($this->user_json->gems->assigned AS $crusader_id => $crusader_gems) {
$this->assigned_gems[$crusader_id] = $crusader_gems;
}
}
public function get_total_level_one_gem_value() {
$total_gems = array();
foreach ($this->user_json->gems->owned AS $gem_id => $gem_info) {
$total_gems[$gem_id] = 0;
foreach ($gem_info AS $level => $gems) {
$total_gems[$gem_id] += pow(2, ($level - 1)) * $gems;
}
}
return $total_gems;
}
public function get_total_level_one_gem_value_available() {
$total_gems_available = $this->total_gems;
foreach ($this->user_json->gems->assigned AS $hero_id => $runes_info) {
foreach ($runes_info AS $rune_slot => $gem_data) {
$total_gems_available[$gem_data->gem_id] -= pow(2, ($gem_data->level - 1));
}
}
return $total_gems_available;
}
public function generate_crusader_loot($game_defines) {
$this->crusader_loot = array();
foreach ($this->crusaders AS $crusader) {
if (empty($game_defines->crusader_loot[$crusader->hero_id])) {
continue;
}
foreach ($game_defines->crusader_loot[$crusader->hero_id] AS $crusader_loot_slot) {
foreach ($crusader_loot_slot AS $slot_id => $crusader_loot) {
if (!empty($this->loot[$crusader_loot->id])) {
$this->crusader_loot[$crusader->hero_id][$crusader_loot->slot_id] = $crusader_loot;
}
}
}
}
}
public function get_max_areas_for_dungeons() {
$max_areas_for_dungeons = array();
if (!empty($this->user_json->stats)) {
foreach($this->user_json->stats AS $stat => $value) {
if (preg_match('/objective_([0-9]+)_highest_area/', $stat, $objective_id)) {
//The 0th index contains the entire string, the 1st just has the capture group
$max_areas_for_dungeons[$objective_id[1]] = $value;
}
}
}
return $max_areas_for_dungeons;
}
}
?>