forked from brewk/wowspreadsheet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pets.js
263 lines (191 loc) · 8.02 KB
/
pets.js
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
/* ***********************************
*** Copyright (c) 2016 bruk
*** This script is free software; you can redistribute it and/or modify
*** it under the terms of the GNU General Public License as published by
*** the Free Software Foundation; either version 3 of the License, or
*** (at your option) any later version.
***
*** Want to keep up to date or suggest modifications to this script?
*** then hop on over to http://twitter.com/bruk
************************************* */
// **** Outputs Detailed Pet information
// *** Example template: https://docs.google.com/spreadsheets/d/1yf3s3yLpHbdomLuKELr79w-azTLVnBwGJ1Uhegs1M1o/edit?usp=sharing
// **** usage: =transpose(pets(region,toonName,realmName))
// **** Coulumn Outputs:
// * Collected, Fav Need Upgrade, Num Favs to Level, Fav Lvls Needed, Total WildPets
// * Missing Rares (nonwild)
// * Missing Rare (Wild Caught)
// * Missing Max Level (nonwild)
// * Missing Max Level (wild caught)
// * Missing Pets
// * Missing Pet Source
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ IMPORTANT!!! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// You need to put your api key here, inside the quotes of line 25
// Request one here: https://dev.battle.net/apps/register
// Step by step instructions: http://bruk.org/api
var apikey = "";
// Everything below this, you shouldn't have to edit
//***************************************************************
/* globals Utilities, UrlFetchApp */
/* exported pets */
function pets(region,toonName,realmName)
{
if (!toonName || !realmName)
{
return " "; // If there's nothing in the column, don't even bother calling the API
}
Utilities.sleep(Math.floor((Math.random() * 10000) + 1000)); // This is a random sleepy time so that we dont spam the api and get bonked with an error
//Getting rid of any sort of pesky no width white spaces we may run into
toonName = toonName.replace(/[\u200B-\u200D\uFEFF]/g, "");
region = region.replace(/[\u200B-\u200D\uFEFF]/g, "");
realmName = realmName.replace(/[\u200B-\u200D\uFEFF]/g, "");
region = region.toLowerCase(); // if we don't do this, it screws up the avatar display 9_9
toonName = toonName.replace(/[\u200B-\u200D\uFEFF]/g, "");
region = region.replace(/[\u200B-\u200D\uFEFF]/g, "");
realmName = realmName.replace(/[\u200B-\u200D\uFEFF]/g, "");
region = region.toLowerCase(); // if we don't do this, it screws up the avatar display 9_9
var toonJSON = UrlFetchApp.fetch("https://"+region+".api.battle.net/wow/character/"+realmName+"/"+toonName+"?fields=pets&?locale=en_US&apikey="+apikey+"");
var toon = JSON.parse(toonJSON.toString());
//Init all the curds!
var needUpgrade = 0;
var needLevel = 0;
var levels = 0;
var battlePet = 0;
var petBattleArray = [ ];
var i =0;
var stuff =toon.pets.numCollected;
//Lets go through that json array
for (i=0; i<stuff; i++)
{
//first we'll sort out some favorite stuff, may not be handy for some people, but favorites are one of my favorite things
//for keeping my pets sorted
if (toon.pets.collected[i].isFavorite === true)
{
if (toon.pets.collected[i].qualityId != 3)
{
needUpgrade++;
}
if (toon.pets.collected[i].stats.level != 25)
{
needLevel++;
levels = levels + (25 - toon.pets.collected[i].stats.level);
}
}
//Because there can be duplicates, check if the pet already exists in our table
//if it doesn't exist, then it must be the best version we've found so far, so initilize quality and levels
if (!petBattleArray[toon.pets.collected[i].creatureId])
{
petBattleArray[toon.pets.collected[i].creatureId] = {};
petBattleArray[toon.pets.collected[i].creatureId].quality = toon.pets.collected[i].qualityId;
petBattleArray[toon.pets.collected[i].creatureId].name = toon.pets.collected[i].creatureName;
petBattleArray[toon.pets.collected[i].creatureId].level = toon.pets.collected[i].stats.level;
//check if it's a wild caught battle pet
if (toon.pets.collected[i].itemId> 1)
{
petBattleArray[toon.pets.collected[i].creatureId].wild = "0";
}
else
{
petBattleArray[toon.pets.collected[i].creatureId].wild = "1";
}
}
//so we DO have this pet already.. well we better see if it's the best quality or best leveled one
else
{
if (petBattleArray[toon.pets.collected[i].creatureId].quality < toon.pets.collected[i].petQualityId )
{
petBattleArray[toon.pets.collected[i].creatureId].quality = toon.pets.collected[i].petQualityId;
}
if (petBattleArray[toon.pets.collected[i].creatureId].level < toon.pets.collected[i].creatureId.level)
{
petBattleArray[toon.pets.collected[i].creatureId].level = toon.pets.collected[i].level;
}
}
//check if it's a wild pet, and if so increase the number of wild caught pets in or "favorite's table"
if (toon.pets.collected[i].spellId == "0")
{
battlePet++;
}
}
//really got lazy here with the array and counter names here
//the lengh of this array can be fricken massive since it's based on the pets' ids (80k+)
var arrayCounter = petBattleArray.length;
var smallArrayAll = [ ]; // this is for finding what we're missing, it gets outputted into a secret hidden array
var ticktock5 = 0;
var smallArrayQ = [ ]; //quality
var ticktock3 = 0;
var smallArrayL = [ ]; // level
var ticktock4 = 0;
var smallArrayQW = [ ]; //quality wilds
var ticktock = 0;
var smallArrayLW = [ ]; //level wilds
var ticktock2 = 0;
//this will be used to store our string that represents the quality of the pet in the output
var quality = 0;
// FEL-PUP FIXER UP
if (petBattleArray[91823])
{
petBattleArray[91823].wild = "0";
}
for (i=0; i<arrayCounter; i++)
{
if (petBattleArray[i])
{
smallArrayAll[ticktock5] = i;
ticktock5++;
if (petBattleArray[i].quality === 0)
{
quality = "(p) ";
}
else if (petBattleArray[i].quality == 1)
{
quality = "(c) ";
}
else if (petBattleArray[i].quality == 2)
{
quality = "(u) ";
}
if (petBattleArray[i].quality<3)
{
if (petBattleArray[i].wild>0)
{
smallArrayQW[ticktock]= quality + petBattleArray[i].name;
ticktock++;
}
else
{
smallArrayQ[ticktock3]= quality + petBattleArray[i].name;
ticktock3++;
}
}
if (petBattleArray[i].level<25)
{
if (petBattleArray[i].wild>0)
{
smallArrayLW[ticktock2]= "(" + petBattleArray[i].level + ") " + petBattleArray[i].name;
ticktock2++;
}
else
{
smallArrayL[ticktock4]= "(" + petBattleArray[i].level + ") " + petBattleArray[i].name;
ticktock4++;
}
}
}
}
var thumbnail = "http://"+region+".battle.net/static-render/"+region+"/"+ toon.thumbnail;
var numbersArray = [ toon.pets.numCollected, needUpgrade, needLevel, levels, battlePet ];
var wordsArray = [ "Collected", "Fav Need Upgrade", "Num Favs to Level", "Fav Lvls Needed", "Total WildPets" ];
var petInfo = [
wordsArray,
numbersArray,
smallArrayQ,
smallArrayQW,
smallArrayL,
smallArrayLW,
smallArrayAll,
thumbnail
];
return petInfo;
// return;
}