forked from pokepark/PokemonRaidBot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetDB.php
279 lines (255 loc) · 13.3 KB
/
getDB.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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
<?php
// Init SQL stuff.
$SQL = '';
$SQL_UPDATE = '';
$SQL_eggs = '';
$SQL_file = __DIR__ . '/sql/game-master-raid-boss-pokedex.sql';
$proto_url = "https://raw.githubusercontent.com/Furtif/POGOProtos/master/base/base.proto";
$game_master_url = "https://raw.githubusercontent.com/PokeMiners/game_masters/master/latest/latest.json";
//Parse the form ID's from pogoprotos
$proto = file($proto_url);
$count = count($proto);
$form_ids = array();
$start=false;
for($i=0;$i<$count;$i++) {
$data = explode("=",str_replace(";","",$proto[$i]));
// Found first pokemon, start collecting data
if(count($data) == 2 && trim($data[0]) == "UNOWN_A") $start = true;
if($start) {
// End of pokemon data, no need to loop further
if(trim($data[0]) == "}") {
break;
}else if(count($data) == 2) {
$form_ids[trim($data[0])] = trim($data[1]);
}
}
}
unset($proto);
// Set ID's for mega evolutions
// Using negative to prevent mixup with actual form ID's
// Collected from pogoprotos (hoping they won't change, so hard coding them here)
$mega_ids = array("MEGA"=>-1,"MEGA_X"=>-2,"MEGA_Y"=>-3);
$weatherboost_table = array(
"POKEMON_TYPE_BUG" => "3",
"POKEMON_TYPE_DARK" => "8",
"POKEMON_TYPE_DRAGON" => "6",
"POKEMON_TYPE_ELECTRIC" => "3",
"POKEMON_TYPE_FAIRY" => "5",
"POKEMON_TYPE_FIGHTING" => "5",
"POKEMON_TYPE_FIRE" => "12",
"POKEMON_TYPE_FLYING" => "6",
"POKEMON_TYPE_GHOST" => "8",
"POKEMON_TYPE_GRASS" => "12",
"POKEMON_TYPE_GROUND" => "12",
"POKEMON_TYPE_ICE" => "7",
"POKEMON_TYPE_NORMAL" => "4",
"POKEMON_TYPE_POISON" => "5",
"POKEMON_TYPE_PSYCHIC" => "6",
"POKEMON_TYPE_ROCK" => "4",
"POKEMON_TYPE_STEEL" => "7",
"POKEMON_TYPE_WATER" => "3"
);
function calculate_cps($base_stats) {
// CP = (Attack * Defense^0.5 * Stamina^0.5 * CP_Multiplier^2) / 10
$cp_multiplier = array(20 => 0.5974 ,25 =>0.667934 );
$min = floor((($base_stats['baseAttack']+10)*(($base_stats['baseDefense']+10)**0.5)*(($base_stats['baseStamina']+10)**0.5)*$cp_multiplier[20]**2)/10);
$max = floor((($base_stats['baseAttack']+15)*(($base_stats['baseDefense']+15)**0.5)*(($base_stats['baseStamina']+15)**0.5)*$cp_multiplier[20]**2)/10);
$min_weather = floor((($base_stats['baseAttack']+10)*(($base_stats['baseDefense']+10)**0.5)*(($base_stats['baseStamina']+10)**0.5)*$cp_multiplier[25]**2)/10);
$max_weather = floor((($base_stats['baseAttack']+15)*(($base_stats['baseDefense']+15)**0.5)*(($base_stats['baseStamina']+15)**0.5)*$cp_multiplier[25]**2)/10);
return [$min,$max,$min_weather,$max_weather];
}
$master = json_decode(file_get_contents($game_master_url),true);
foreach($master as $row) {
$part = explode("_",$row['templateId']);
$form_data = [];
$pokemon_id = "";
if(count($part)<2) continue;
if($part[0] == "FORMS") {
// Found Pokemon form data
// Get pokemon ID
$pokemon_id = ltrim(str_replace("V","",$part[1]),'0');
unset($part[0]);
unset($part[1]);
unset($part[2]);
// Pokemon name
$pokemon_name = implode("_",$part);
// Get pokemon forms
if(!isset($row['data']['formSettings']['forms'])) {
$form_data[] = array("form"=>$pokemon_name."_NORMAL");
}else {
$form_data = $row['data']['formSettings']['forms'];
}
foreach($form_data as $form) {
$form_name = strtolower(str_replace($pokemon_name."_","",$form['form']));
if($form_name != "purified" && $form_name != "shadow") {
// Nidoran
$poke_name = ucfirst(strtolower(str_replace(["_FEMALE","_MALE"],["♀","♂"],$row['data']['formSettings']['pokemon'])));
// Ho-oh
$poke_name = str_replace("_","-",$poke_name);
$poke_shiny = 0;
if(!isset($form_ids[$form['form']])) {
$form_id = 0;
}else {
$form_id = $form_ids[$form['form']];
}
$form_asset_suffix = (isset($form['assetBundleValue']) ? $form['assetBundleValue'] : (isset($form['assetBundleSuffix'])?$form['assetBundleSuffix']:"00"));
$pokemon_array[$pokemon_id][$form_name] = [ "pokemon_name"=>$poke_name,
"pokemon_form_name"=>$form_name,
"pokemon_form_id"=>$form_id,
"asset_suffix"=>$form_asset_suffix,
"shiny"=>$poke_shiny
];
}
}
}else if($part[0] == "TEMPORARY" && $part[1] == "EVOLUTION") {
// Found Mega pokemon data
// Get pokemon ID
$pokemon_id = ltrim(str_replace("V","",$part[2]),'0');
unset($part[0]);
unset($part[1]);
unset($part[2]);
unset($part[3]);
// Pokemon name
$pokemon_name = implode("_",$part);
$form_data = $row['data']['temporaryEvolutionSettings']['temporaryEvolutions'];
foreach($form_data as $form) {
// Nidoran
$poke_name = ucfirst(strtolower(str_replace(["_FEMALE","_MALE"],["♀","♂"],$pokemon_name)));
// Ho-oh
$poke_name = str_replace("_","-",$poke_name);
$form_name = str_replace("TEMP_EVOLUTION_","",$form['temporaryEvolutionId']);
$form_asset_suffix = $form['assetBundleValue'];
$poke_shiny = 0;
$form_id = $mega_ids[$form_name];
$pokemon_array[$pokemon_id][$form_name] = [ "pokemon_name"=>$poke_name,
"pokemon_form_name"=>$form_name,
"pokemon_form_id"=>$form_id,
"asset_suffix"=>$form_asset_suffix,
"shiny"=>$poke_shiny
];
}
}else if ($part[1] == "POKEMON" && $part[0][0] == "V" && isset($row['data']['pokemonSettings'])) {
// Found Pokemon data
$pokemon_id = (int)str_replace("V","",$part[0]);
$form_name = str_replace($row['data']['pokemonSettings']['pokemonId']."_","",substr($row['data']['templateId'],14));
if($form_name != 'PURIFIED' && $form_name != 'SHADOW' && $form_name != 'NORMAL'
&& isset($pokemon_array[$pokemon_id])
&& isset($row['data']['pokemonSettings']['stats']['baseAttack'])
&& isset($row['data']['pokemonSettings']['stats']['baseDefense'])
&& isset($row['data']['pokemonSettings']['stats']['baseStamina'])) {
if($form_name == $row['data']['pokemonSettings']['pokemonId']) {
$form_name = "normal";
}else {
$form_name = strtolower($form_name);
}
$CPs = calculate_cps($row['data']['pokemonSettings']['stats']);
$min_cp = $CPs[0];
$max_cp = $CPs[1];
$min_weather_cp = $CPs[2];
$max_weather_cp = $CPs[3];
$weather = $weatherboost_table[$row['data']['pokemonSettings']['type']];
# Add type2 weather boost only if there is a second type and it's not the same weather as the first type!
if(
isset($row['data']['pokemonSettings']['type2'])
&& $weatherboost_table[$row['data']['pokemonSettings']['type2']] != $weatherboost_table[$row['data']['pokemonSettings']['type']]
) {
$weather .= $weatherboost_table[$row['data']['pokemonSettings']['type2']];
}
if(isset($pokemon_array[$pokemon_id][$form_name])) {
$pokemon_array[$pokemon_id][$form_name]["min_cp"] = $min_cp;
$pokemon_array[$pokemon_id][$form_name]["max_cp"] = $max_cp;
$pokemon_array[$pokemon_id][$form_name]["min_weather_cp"] = $min_weather_cp;
$pokemon_array[$pokemon_id][$form_name]["max_weather_cp"] = $max_weather_cp;
$pokemon_array[$pokemon_id][$form_name]["weather"] = $weather;
}else {
// Fill data for Pokemon that have form data but no stats for forms specifically
foreach($pokemon_array[$pokemon_id] as $form=>$data) {
$pokemon_array[$pokemon_id][$form]["min_cp"] = $min_cp;
$pokemon_array[$pokemon_id][$form]["max_cp"] = $max_cp;
$pokemon_array[$pokemon_id][$form]["min_weather_cp"] = $min_weather_cp;
$pokemon_array[$pokemon_id][$form]["max_weather_cp"] = $max_weather_cp;
$pokemon_array[$pokemon_id][$form]["weather"] = $weather;
}
}
if(isset($row['data']['pokemonSettings']['evolutionBranch'])) {
foreach($row['data']['pokemonSettings']['evolutionBranch'] as $temp_evolution) {
if(isset($temp_evolution['temporaryEvolution'])) {
$form_name = str_replace("TEMP_EVOLUTION_","",$temp_evolution['temporaryEvolution']);
$pokemon_array[$pokemon_id][$form_name]["min_cp"] = $min_cp;
$pokemon_array[$pokemon_id][$form_name]["max_cp"] = $max_cp;
$pokemon_array[$pokemon_id][$form_name]["min_weather_cp"] = $min_weather_cp;
$pokemon_array[$pokemon_id][$form_name]["max_weather_cp"] = $max_weather_cp;
$pokemon_array[$pokemon_id][$form_name]["weather"] = $weather;
}
}
}
}
}
}
// Save data to file.
if(!empty($pokemon_array)) {
// Add eggs to SQL data.
echo 'Adding raids eggs to pokemons' . PHP_EOL;
for($e = 1; $e <= 6; $e++) {
$pokemon_id = '999'.$e;
$form_name = 'normal';
$pokemon_name = 'Level '. $e .' Egg';
$pokemon_array[$pokemon_id][$form_name] = [ "pokemon_name"=>$pokemon_name,
"pokemon_form_name"=>$form_name,
"pokemon_form_id"=>0,
"asset_suffix"=>0,
"shiny"=>0,
"min_cp"=>0,
"max_cp"=>0,
"min_weather_cp"=>0,
"max_weather_cp"=>0,
"weather"=>0
];
}
// Add delete command to SQL data.
echo 'Adding delete sql command to the beginning' . PHP_EOL;
$DEL = 'DELETE FROM `pokemon`;' . PHP_EOL;
$DEL .= 'TRUNCATE `pokemon`;' . PHP_EOL;
foreach($pokemon_array as $id => $forms) {
$pokemon_id = $id;
foreach($forms as $form=>$data) {
// Check that data is set, if not the mon is probably not in the game yet and there's no point in having them in a broken state
if(isset($data['weather']) && isset($data['min_cp']) && isset($data['max_cp']) && isset($data['min_weather_cp']) && isset($data['max_weather_cp'])) {
$poke_form = $form;
$poke_name = $data['pokemon_name'];
$form_id = $data['pokemon_form_id'];
$form_asset_suffix = $data['asset_suffix'];
$poke_min_cp = $data['min_cp'];
$poke_max_cp = $data['max_cp'];
$poke_min_weather_cp = $data['min_weather_cp'];
$poke_max_weather_cp = $data['max_weather_cp'];
$poke_weather = $data['weather'];
$poke_shiny = $data['shiny'];
if($pokemon_id == 150 && $data['pokemon_form_name']=="a") {
// Because logic and consistency
$poke_form = "armored";
}else {
$poke_form = strtolower($data['pokemon_form_name']);
}
$QM = "'";
$SEP = ",";
echo $poke_name." ".$poke_form.PHP_EOL;
$SQL .= "REPLACE INTO pokemon SET pokedex_id=\"${pokemon_id}\", pokemon_name=\"${poke_name}\", pokemon_form_name=\"${poke_form}\", pokemon_form_id=\"${form_id}\", asset_suffix=\"${form_asset_suffix}\", min_cp=\"${poke_min_cp}\", max_cp=\"${poke_max_cp}\", min_weather_cp=\"${poke_min_weather_cp}\", max_weather_cp=\"${poke_max_weather_cp}\", weather=\"${poke_weather}\", shiny=\"${poke_shiny}\";" . PHP_EOL;
}
}
}
$SQL = $DEL . $SQL . $SQL_UPDATE;
// Save data.
//echo $SQL . PHP_EOL;
echo 'Saving data to ' . $SQL_file . PHP_EOL;
file_put_contents($SQL_file, $SQL);
} else {
echo 'Failed to get pokemon data!' . PHP_EOL;
}
// File successfully created?
if(is_file($SQL_file)) {
echo 'Finished!' . PHP_EOL;
} else {
echo 'Failed to save file: ' . $SQL_file . PHP_EOL;
}
?>