@arken/node 1.4.5 → 1.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -4
- package/build/data/generated/airtable.json +2 -2
- package/build/data/generated/gameInfos.json +1 -1
- package/build/data/generated/games.json +1 -1
- package/build/util/decoder.js +907 -849
- package/package.json +3 -5
- package/src/data/generated/airtable.json +2 -2
- package/src/data/generated/gameInfos.json +1 -1
- package/src/data/generated/games.json +1 -1
- package/src/util/decoder.ts +3 -3
package/build/util/decoder.js
CHANGED
|
@@ -1,905 +1,963 @@
|
|
|
1
|
-
|
|
2
|
-
var __importDefault =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
1
|
+
'use strict'
|
|
2
|
+
var __importDefault =
|
|
3
|
+
(this && this.__importDefault) ||
|
|
4
|
+
function (mod) {
|
|
5
|
+
return mod && mod.__esModule ? mod : { default: mod }
|
|
6
|
+
}
|
|
7
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
8
|
+
exports.getTokenIdFromItem =
|
|
9
|
+
exports.normalizeItem =
|
|
10
|
+
exports.getItemFromTokenId =
|
|
11
|
+
exports.decodeItem =
|
|
12
|
+
exports.setTokenCache =
|
|
13
|
+
exports.getTokenCache =
|
|
14
|
+
exports.clearDatabase =
|
|
15
|
+
void 0
|
|
16
|
+
const lokijs_1 = __importDefault(require('lokijs'))
|
|
17
|
+
const incremental_indexeddb_adapter_1 = __importDefault(require('lokijs/src/incremental-indexeddb-adapter'))
|
|
18
|
+
const items_1 = require('../data/items')
|
|
19
|
+
const items_type_1 = require('../data/items.type')
|
|
20
|
+
const probabilityCache_1 = __importDefault(require('../data/probabilityCache'))
|
|
21
|
+
const math_1 = require('./math')
|
|
22
|
+
const useLocalStorage = false
|
|
23
|
+
const useIndexedDb = false
|
|
24
|
+
const useLoki = true
|
|
25
|
+
let tokenCache = {}
|
|
26
|
+
const dbCon = new lokijs_1.default('arken.db', {
|
|
27
|
+
adapter:
|
|
28
|
+
typeof window !== 'undefined'
|
|
29
|
+
? new incremental_indexeddb_adapter_1.default()
|
|
30
|
+
: new (require('lokijs/src/loki-fs-structured-adapter'))(),
|
|
31
|
+
autoload: true,
|
|
32
|
+
autoloadCallback: databaseInitialize,
|
|
33
|
+
autosave: true,
|
|
34
|
+
autosaveInterval: 4000,
|
|
35
|
+
})
|
|
26
36
|
const db = {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
37
|
+
config: undefined,
|
|
38
|
+
items: undefined,
|
|
39
|
+
}
|
|
30
40
|
function databaseInitialize() {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
41
|
+
var _a, _b, _c, _d
|
|
42
|
+
db.config = dbCon.getCollection('config')
|
|
43
|
+
db.items = dbCon.getCollection('items')
|
|
44
|
+
if (dbCon.getCollection('items')) {
|
|
45
|
+
dbCon.getCollection('items').chain().remove()
|
|
46
|
+
}
|
|
47
|
+
const cacheBreaker = 1665261167 * 1000
|
|
48
|
+
const updatedAt =
|
|
49
|
+
(_d =
|
|
50
|
+
(_c =
|
|
51
|
+
(_b = (_a = db.items) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0
|
|
52
|
+
? void 0
|
|
53
|
+
: _b[0]) === null || _c === void 0
|
|
54
|
+
? void 0
|
|
55
|
+
: _c.meta) === null || _d === void 0
|
|
56
|
+
? void 0
|
|
57
|
+
: _d.created
|
|
58
|
+
if (!updatedAt || updatedAt < cacheBreaker) {
|
|
34
59
|
if (dbCon.getCollection('items')) {
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
const cacheBreaker = 1665261167 * 1000;
|
|
38
|
-
const updatedAt = (_d = (_c = (_b = (_a = db.items) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.meta) === null || _d === void 0 ? void 0 : _d.created;
|
|
39
|
-
if (!updatedAt || updatedAt < cacheBreaker) {
|
|
40
|
-
if (dbCon.getCollection('items')) {
|
|
41
|
-
dbCon.getCollection('items').chain().remove();
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
if (db.config === null) {
|
|
45
|
-
db.config = dbCon.addCollection('config', {
|
|
46
|
-
// clone: true,
|
|
47
|
-
unique: 'key',
|
|
48
|
-
});
|
|
49
|
-
db.config.insert({
|
|
50
|
-
key: 'updatedAt',
|
|
51
|
-
value: cacheBreaker,
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
db.config.find({
|
|
55
|
-
key: 'updatedAt',
|
|
56
|
-
}).value = cacheBreaker;
|
|
57
|
-
if (db.items === null) {
|
|
58
|
-
// Add a collection to the database
|
|
59
|
-
db.items = dbCon.addCollection('items', {
|
|
60
|
-
// clone: true,
|
|
61
|
-
unique: 'tokenId',
|
|
62
|
-
});
|
|
60
|
+
dbCon.getCollection('items').chain().remove()
|
|
63
61
|
}
|
|
62
|
+
}
|
|
63
|
+
if (db.config === null) {
|
|
64
|
+
db.config = dbCon.addCollection('config', {
|
|
65
|
+
// clone: true,
|
|
66
|
+
unique: 'key',
|
|
67
|
+
})
|
|
68
|
+
db.config.insert({
|
|
69
|
+
key: 'updatedAt',
|
|
70
|
+
value: cacheBreaker,
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
db.config.find({
|
|
74
|
+
key: 'updatedAt',
|
|
75
|
+
}).value = cacheBreaker
|
|
76
|
+
if (db.items === null) {
|
|
77
|
+
// Add a collection to the database
|
|
78
|
+
db.items = dbCon.addCollection('items', {
|
|
79
|
+
// clone: true,
|
|
80
|
+
unique: 'tokenId',
|
|
81
|
+
})
|
|
82
|
+
}
|
|
64
83
|
}
|
|
65
84
|
function clearDatabase() {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
85
|
+
if (dbCon.getCollection('config')) {
|
|
86
|
+
dbCon.getCollection('config').chain().remove()
|
|
87
|
+
}
|
|
88
|
+
if (dbCon.getCollection('items')) {
|
|
89
|
+
dbCon.getCollection('items').chain().remove()
|
|
90
|
+
}
|
|
72
91
|
}
|
|
73
|
-
exports.clearDatabase = clearDatabase
|
|
92
|
+
exports.clearDatabase = clearDatabase
|
|
74
93
|
function getTokenCache() {
|
|
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
|
-
|
|
94
|
+
// if (useLoki) {
|
|
95
|
+
// var db = new loki('arken.db')
|
|
96
|
+
// // Add a collection to the database
|
|
97
|
+
// var items = db.addCollection('items')
|
|
98
|
+
// }
|
|
99
|
+
// if (useIndexedDb) {
|
|
100
|
+
// // This works on all devices/browsers, and uses IndexedDBShim as a final fallback
|
|
101
|
+
// // @ts-ignore
|
|
102
|
+
// var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB || window.shimIndexedDB;
|
|
103
|
+
// // Open (or create) the database
|
|
104
|
+
// var open = indexedDB.open("RuneItems", 1);
|
|
105
|
+
// // Create the schema
|
|
106
|
+
// open.onupgradeneeded = function() {
|
|
107
|
+
// var db = open.result;
|
|
108
|
+
// var store = db.createObjectStore("TokenData", {keyPath: "tokenId"});
|
|
109
|
+
// // var index = store.createIndex("NameIndex", ["name.last", "name.first"]);
|
|
110
|
+
// };
|
|
111
|
+
// open.onsuccess = function() {
|
|
112
|
+
// // Start a new transaction
|
|
113
|
+
// var db = open.result;
|
|
114
|
+
// var tx = db.transaction("TokenData", "readwrite");
|
|
115
|
+
// var store = tx.objectStore("TokenData");
|
|
116
|
+
// var index = store.index("NameIndex");
|
|
117
|
+
// // Query the data
|
|
118
|
+
// var getJohn = store.get(12345);
|
|
119
|
+
// // var getBob = index.get(["Smith", "Bob"]);
|
|
120
|
+
// getJohn.onsuccess = function() {
|
|
121
|
+
// console.log(getJohn.result.name.first); // => "John"
|
|
122
|
+
// };
|
|
123
|
+
// // Close the db when the transaction is done
|
|
124
|
+
// tx.oncomplete = function() {
|
|
125
|
+
// db.close();
|
|
126
|
+
// };
|
|
127
|
+
// }
|
|
128
|
+
// }
|
|
129
|
+
return tokenCache
|
|
111
130
|
}
|
|
112
|
-
exports.getTokenCache = getTokenCache
|
|
131
|
+
exports.getTokenCache = getTokenCache
|
|
113
132
|
function setTokenCache(_tokenCache) {
|
|
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
|
-
|
|
133
|
+
tokenCache = tokenCache
|
|
134
|
+
// if (useLoki) {
|
|
135
|
+
// const db = new loki('arken.db')
|
|
136
|
+
// // Add a collection to the database
|
|
137
|
+
// const items = db.addCollection('items')
|
|
138
|
+
// }
|
|
139
|
+
// if (useIndexedDb) {
|
|
140
|
+
// // This works on all devices/browsers, and uses IndexedDBShim as a final fallback
|
|
141
|
+
// // @ts-ignore
|
|
142
|
+
// var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB || window.shimIndexedDB;
|
|
143
|
+
// // Open (or create) the database
|
|
144
|
+
// var open = indexedDB.open("RuneItems", 1);
|
|
145
|
+
// // Create the schema
|
|
146
|
+
// open.onupgradeneeded = function() {
|
|
147
|
+
// var db = open.result;
|
|
148
|
+
// var store = db.createObjectStore("TokenData", {keyPath: "tokenId"});
|
|
149
|
+
// // var index = store.createIndex("NameIndex", ["name.last", "name.first"]);
|
|
150
|
+
// };
|
|
151
|
+
// open.onsuccess = function() {
|
|
152
|
+
// // Start a new transaction
|
|
153
|
+
// var db = open.result;
|
|
154
|
+
// var tx = db.transaction("TokenData", "readwrite");
|
|
155
|
+
// var store = tx.objectStore("TokenData");
|
|
156
|
+
// var index = store.index("NameIndex");
|
|
157
|
+
// // Add some data
|
|
158
|
+
// for (const item of _tokenCache) {
|
|
159
|
+
// store.put(item);
|
|
160
|
+
// }
|
|
161
|
+
// // Close the db when the transaction is done
|
|
162
|
+
// tx.oncomplete = function() {
|
|
163
|
+
// db.close();
|
|
164
|
+
// };
|
|
165
|
+
// }
|
|
166
|
+
// }
|
|
148
167
|
}
|
|
149
|
-
exports.setTokenCache = setTokenCache
|
|
168
|
+
exports.setTokenCache = setTokenCache
|
|
150
169
|
function getItemTokenCache(tokenId) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
// console.log('Token NOT found in cache', tokenId)
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
if (useLocalStorage && window.localStorage) {
|
|
167
|
-
const tokenCacheText = window.localStorage.getItem(`zzz_tokenCache_${tokenId}`);
|
|
168
|
-
if (tokenCacheText) {
|
|
169
|
-
let tokenCacheItem = JSON.parse(tokenCacheText);
|
|
170
|
-
const now = new Date();
|
|
171
|
-
if (now.getTime() > tokenCacheItem.expiry) {
|
|
172
|
-
window.localStorage.removeItem(`zzz_tokenCache_${tokenId}`);
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
tokenCache[tokenId] = tokenCacheItem.value;
|
|
176
|
-
console.log(99999999, tokenCacheItem.value);
|
|
177
|
-
return tokenCacheItem.value;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
170
|
+
var _a
|
|
171
|
+
try {
|
|
172
|
+
// console.log(9999, tokenCache[tokenId])
|
|
173
|
+
if (tokenCache[tokenId]) return tokenCache[tokenId]
|
|
174
|
+
if (useLoki) {
|
|
175
|
+
const result = (_a = db.items) === null || _a === void 0 ? void 0 : _a.findOne({ tokenId: tokenId })
|
|
176
|
+
if (result) {
|
|
177
|
+
// console.log('Token found in cache', result)
|
|
178
|
+
return result
|
|
179
|
+
} else {
|
|
180
|
+
// console.log('Token NOT found in cache', tokenId)
|
|
181
|
+
}
|
|
180
182
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
+
if (useLocalStorage && window.localStorage) {
|
|
184
|
+
const tokenCacheText = window.localStorage.getItem(`zzz_tokenCache_${tokenId}`)
|
|
185
|
+
if (tokenCacheText) {
|
|
186
|
+
let tokenCacheItem = JSON.parse(tokenCacheText)
|
|
187
|
+
const now = new Date()
|
|
188
|
+
if (now.getTime() > tokenCacheItem.expiry) {
|
|
189
|
+
window.localStorage.removeItem(`zzz_tokenCache_${tokenId}`)
|
|
190
|
+
return
|
|
191
|
+
}
|
|
192
|
+
tokenCache[tokenId] = tokenCacheItem.value
|
|
193
|
+
console.log(99999999, tokenCacheItem.value)
|
|
194
|
+
return tokenCacheItem.value
|
|
195
|
+
}
|
|
183
196
|
}
|
|
197
|
+
} catch (e) {
|
|
198
|
+
console.log(e, tokenId)
|
|
199
|
+
}
|
|
184
200
|
}
|
|
185
201
|
function setItemTokenCache(item) {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
}
|
|
196
|
-
// console.log('Updating item', item)
|
|
197
|
-
(_b = db.items) === null || _b === void 0 ? void 0 : _b.update(result);
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
try {
|
|
201
|
-
// console.log('Inserting item', item)
|
|
202
|
-
(_c = db.items) === null || _c === void 0 ? void 0 : _c.insert(item);
|
|
203
|
-
}
|
|
204
|
-
catch (e) {
|
|
205
|
-
(_d = db.items) === null || _d === void 0 ? void 0 : _d.update(item);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
// db.saveDatabase()
|
|
202
|
+
var _a, _b, _c, _d
|
|
203
|
+
try {
|
|
204
|
+
tokenCache[item.tokenId] = item
|
|
205
|
+
if (useLoki) {
|
|
206
|
+
// Find and update an existing document
|
|
207
|
+
const result = (_a = db.items) === null || _a === void 0 ? void 0 : _a.findOne({ tokenId: item.tokenId })
|
|
208
|
+
if (result) {
|
|
209
|
+
for (const key of Object.keys(item)) {
|
|
210
|
+
result[key] = item[key]
|
|
209
211
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
212
|
+
// console.log('Updating item', item)
|
|
213
|
+
;(_b = db.items) === null || _b === void 0 ? void 0 : _b.update(result)
|
|
214
|
+
} else {
|
|
215
|
+
try {
|
|
216
|
+
// console.log('Inserting item', item)
|
|
217
|
+
;(_c = db.items) === null || _c === void 0 ? void 0 : _c.insert(item)
|
|
218
|
+
} catch (e) {
|
|
219
|
+
;(_d = db.items) === null || _d === void 0 ? void 0 : _d.update(item)
|
|
216
220
|
}
|
|
221
|
+
}
|
|
222
|
+
// db.saveDatabase()
|
|
217
223
|
}
|
|
218
|
-
|
|
219
|
-
|
|
224
|
+
if (useLocalStorage && window.localStorage) {
|
|
225
|
+
const ttl = 3 * 24 * 60 * 60 * 1000
|
|
226
|
+
localStorage.setItem(
|
|
227
|
+
`zzz_tokenCache_${item.tokenId}`,
|
|
228
|
+
JSON.stringify({
|
|
229
|
+
expiry: new Date().getTime() + ttl,
|
|
230
|
+
value: item,
|
|
231
|
+
})
|
|
232
|
+
)
|
|
220
233
|
}
|
|
234
|
+
} catch (e) {
|
|
235
|
+
console.log(e, item)
|
|
236
|
+
}
|
|
221
237
|
}
|
|
222
238
|
function decodeItem(tokenId) {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
return normalizeItem(getItemFromTokenId(tokenId));
|
|
239
|
+
const tokenCacheItem = getItemTokenCache(tokenId)
|
|
240
|
+
if (tokenId && tokenCacheItem) return tokenCacheItem
|
|
241
|
+
return normalizeItem(getItemFromTokenId(tokenId))
|
|
227
242
|
}
|
|
228
|
-
exports.decodeItem = decodeItem
|
|
243
|
+
exports.decodeItem = decodeItem
|
|
229
244
|
function getItemFromTokenId(tokenId) {
|
|
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
|
-
else {
|
|
265
|
-
type = parseInt(tokenId.slice(9, 11));
|
|
266
|
-
modStart = 11;
|
|
267
|
-
}
|
|
268
|
-
const mods = [];
|
|
269
|
-
let modIndex = modStart;
|
|
270
|
-
while (modIndex < tokenId.length) {
|
|
271
|
-
const variant = parseInt(tokenId.slice(modIndex, modIndex + 1));
|
|
272
|
-
if (variant === 2) {
|
|
273
|
-
const attributeId = parseInt(tokenId.slice(modIndex + 1, modIndex + 4));
|
|
274
|
-
const value = parseInt(tokenId.slice(modIndex + 4, modIndex + 7));
|
|
275
|
-
if (Number.isNaN(value))
|
|
276
|
-
break;
|
|
277
|
-
mods.push({
|
|
278
|
-
variant,
|
|
279
|
-
attributeId,
|
|
280
|
-
value,
|
|
281
|
-
});
|
|
282
|
-
modIndex += 7;
|
|
283
|
-
}
|
|
284
|
-
else {
|
|
285
|
-
const value = parseInt(tokenId.slice(modIndex + 1, modIndex + 4));
|
|
286
|
-
if (Number.isNaN(value))
|
|
287
|
-
break;
|
|
288
|
-
mods.push({
|
|
289
|
-
variant,
|
|
290
|
-
value,
|
|
291
|
-
});
|
|
292
|
-
modIndex += 4;
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
const item = Object.assign(Object.assign(Object.assign(Object.assign({}, defaultItem), { id }), JSON.parse(JSON.stringify(items_1.itemData[items_type_1.ItemsMainCategoriesType.OTHER].find((i) => i.id === id)))), { type,
|
|
296
|
-
version,
|
|
297
|
-
mods,
|
|
298
|
-
tokenId, shortTokenId: `${tokenId.slice(0, 23)}...${tokenId.slice(-3)}` });
|
|
299
|
-
return item;
|
|
245
|
+
const tokenCacheItem = getItemTokenCache(tokenId)
|
|
246
|
+
if (tokenId && tokenCacheItem) return tokenCacheItem
|
|
247
|
+
const defaultItem = {
|
|
248
|
+
tokenId,
|
|
249
|
+
details: {},
|
|
250
|
+
branches: {},
|
|
251
|
+
shorthand: [],
|
|
252
|
+
mods: [],
|
|
253
|
+
attributes: [],
|
|
254
|
+
perfection: null,
|
|
255
|
+
category: items_type_1.ItemsMainCategoriesType.WEAPONS,
|
|
256
|
+
slots: [],
|
|
257
|
+
meta: {
|
|
258
|
+
harvestYield: 0,
|
|
259
|
+
harvestFeeToken: '',
|
|
260
|
+
harvestFeePercent: 0,
|
|
261
|
+
harvestFees: {},
|
|
262
|
+
chanceToSendHarvestToHiddenPool: 0,
|
|
263
|
+
chanceToLoseHarvest: 0,
|
|
264
|
+
harvestBurn: 0,
|
|
265
|
+
attributes: {},
|
|
266
|
+
},
|
|
267
|
+
}
|
|
268
|
+
if (!tokenId || parseInt(tokenId) === 0 || Number.isNaN(parseInt(tokenId))) return defaultItem
|
|
269
|
+
try {
|
|
270
|
+
const version = parseInt(tokenId.slice(1, 4))
|
|
271
|
+
const id = parseInt(tokenId.slice(4, 9))
|
|
272
|
+
let type = 0
|
|
273
|
+
let modStart = 9
|
|
274
|
+
if (version === 1) {
|
|
275
|
+
modStart = 9
|
|
276
|
+
} else {
|
|
277
|
+
type = parseInt(tokenId.slice(9, 11))
|
|
278
|
+
modStart = 11
|
|
300
279
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
280
|
+
const mods = []
|
|
281
|
+
let modIndex = modStart
|
|
282
|
+
while (modIndex < tokenId.length) {
|
|
283
|
+
const variant = parseInt(tokenId.slice(modIndex, modIndex + 1))
|
|
284
|
+
if (variant === 2) {
|
|
285
|
+
const attributeId = parseInt(tokenId.slice(modIndex + 1, modIndex + 4))
|
|
286
|
+
const value = parseInt(tokenId.slice(modIndex + 4, modIndex + 7))
|
|
287
|
+
if (Number.isNaN(value)) break
|
|
288
|
+
mods.push({
|
|
289
|
+
variant,
|
|
290
|
+
attributeId,
|
|
291
|
+
value,
|
|
292
|
+
})
|
|
293
|
+
modIndex += 7
|
|
294
|
+
} else {
|
|
295
|
+
const value = parseInt(tokenId.slice(modIndex + 1, modIndex + 4))
|
|
296
|
+
if (Number.isNaN(value)) break
|
|
297
|
+
mods.push({
|
|
298
|
+
variant,
|
|
299
|
+
value,
|
|
300
|
+
})
|
|
301
|
+
modIndex += 4
|
|
302
|
+
}
|
|
304
303
|
}
|
|
305
|
-
|
|
304
|
+
const item = Object.assign(
|
|
305
|
+
Object.assign(
|
|
306
|
+
Object.assign(Object.assign({}, defaultItem), { id }),
|
|
307
|
+
JSON.parse(
|
|
308
|
+
JSON.stringify(items_1.itemData[items_type_1.ItemsMainCategoriesType.OTHER].find((i) => i.id === id))
|
|
309
|
+
)
|
|
310
|
+
),
|
|
311
|
+
{ type, version, mods, tokenId, shortTokenId: `${tokenId.slice(0, 23)}...${tokenId.slice(-3)}` }
|
|
312
|
+
)
|
|
313
|
+
return item
|
|
314
|
+
} catch (e) {
|
|
315
|
+
// console.log('Token is invalid', tokenId)
|
|
316
|
+
console.log(e)
|
|
317
|
+
}
|
|
318
|
+
return defaultItem
|
|
306
319
|
}
|
|
307
|
-
exports.getItemFromTokenId = getItemFromTokenId
|
|
320
|
+
exports.getItemFromTokenId = getItemFromTokenId
|
|
308
321
|
function normalizeItem(item) {
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
322
|
+
var _a, _b, _c, _d
|
|
323
|
+
try {
|
|
324
|
+
const tokenCacheItem = getItemTokenCache(item.tokenId)
|
|
325
|
+
if (item.tokenId && tokenCacheItem) return tokenCacheItem
|
|
326
|
+
const branch = item.branches[1]
|
|
327
|
+
const branchAttributes = branch ? JSON.parse(JSON.stringify(branch.attributes)) : []
|
|
328
|
+
if (!item.meta) item.meta = {}
|
|
329
|
+
item.meta = Object.assign(
|
|
330
|
+
{
|
|
331
|
+
harvestYield: 0,
|
|
332
|
+
pending: 0,
|
|
333
|
+
bonus: 0,
|
|
334
|
+
harvestBurn: 0,
|
|
335
|
+
chanceToSendHarvestToHiddenPool: 0,
|
|
336
|
+
chanceToLoseHarvest: 0,
|
|
337
|
+
guildId: null,
|
|
338
|
+
characterId: null,
|
|
339
|
+
itemIndex: 0,
|
|
340
|
+
itemLength: 0,
|
|
341
|
+
modIndex: 0,
|
|
342
|
+
modLength: 0,
|
|
343
|
+
rand: 0,
|
|
344
|
+
removeFees: 0,
|
|
345
|
+
freezeFees: 0,
|
|
346
|
+
magicFind: 0,
|
|
347
|
+
unableUseRuneword: null,
|
|
348
|
+
currentRewardToken: null,
|
|
349
|
+
hasEarlyUnstakeLocked: null,
|
|
350
|
+
hasEarlyUnstakeNoReward: null,
|
|
351
|
+
hiddenPoolPid: null,
|
|
352
|
+
swapToken: null,
|
|
353
|
+
swapAmount: null,
|
|
354
|
+
feeToken: null,
|
|
355
|
+
feeAmount: null,
|
|
356
|
+
feeReduction: 0,
|
|
357
|
+
unstakeLocked: false,
|
|
358
|
+
classRequired: 0,
|
|
359
|
+
harvestFeeToken: '',
|
|
360
|
+
harvestFeePercent: 0,
|
|
361
|
+
worldstoneShardChance: 0,
|
|
362
|
+
randomRuneExchange: 0,
|
|
363
|
+
harvestFees: {},
|
|
364
|
+
attributes: {},
|
|
365
|
+
},
|
|
366
|
+
item.meta
|
|
367
|
+
)
|
|
368
|
+
item.attributes = branchAttributes
|
|
369
|
+
let prevMod = null
|
|
370
|
+
if (item.id === 1) {
|
|
371
|
+
if (item.mods) {
|
|
372
|
+
item.mods[0].attributeId = items_1.ItemAttributesByName[items_1.Games.Raid.id].HarvestYield.id
|
|
373
|
+
item.mods[1].attributeId = items_1.ItemAttributesByName[items_1.Games.Raid.id].HarvestFee.id
|
|
374
|
+
item.mods[2].attributeId = items_1.ItemAttributesByName[items_1.Games.Raid.id].HarvestFeeToken.id
|
|
375
|
+
}
|
|
376
|
+
} else if (item.id === 2) {
|
|
377
|
+
if (item.mods) {
|
|
378
|
+
item.mods[0].attributeId = items_1.ItemAttributesByName[items_1.Games.Raid.id].HarvestYield.id
|
|
379
|
+
item.mods[1].attributeId = items_1.ItemAttributesByName[items_1.Games.Raid.id].SendHarvestHiddenPool.id
|
|
380
|
+
item.mods[2].attributeId = items_1.ItemAttributesByName[items_1.Games.Raid.id].BurnEntireHarvest.id
|
|
381
|
+
}
|
|
382
|
+
} else if (item.id === 3) {
|
|
383
|
+
if (item.mods) {
|
|
384
|
+
item.mods[0].attributeId = items_1.ItemAttributesByName[items_1.Games.Raid.id].HarvestYield.id
|
|
385
|
+
item.mods[1].attributeId = items_1.ItemAttributesByName[items_1.Games.Raid.id].HarvestBurn.id
|
|
386
|
+
item.mods[2].attributeId = items_1.ItemAttributesByName[items_1.Games.Raid.id].FindShard.id
|
|
387
|
+
delete item.mods[3]
|
|
388
|
+
delete item.mods[4]
|
|
389
|
+
delete item.mods[5]
|
|
390
|
+
delete item.mods[6]
|
|
391
|
+
item.mods[2].value = 100
|
|
392
|
+
}
|
|
393
|
+
} else if (item.id === 4) {
|
|
394
|
+
if (item.mods) {
|
|
395
|
+
item.mods[0].attributeId = items_1.ItemAttributesByName[items_1.Games.Raid.id].FindShard.id
|
|
396
|
+
item.mods[0].value = 100
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
if (item.mods) {
|
|
400
|
+
for (const i in item.mods) {
|
|
401
|
+
const mod = item.mods[i]
|
|
402
|
+
const branchAttribute = branchAttributes[i]
|
|
403
|
+
if (!branchAttribute) {
|
|
404
|
+
// console.log(`Branch attribute doesn't exist on item definition`, item, mod)
|
|
405
|
+
continue
|
|
327
406
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
item.mods[2].attributeId = items_1.ItemAttributesByName[items_1.Games.Raid.id].BurnEntireHarvest.id;
|
|
333
|
-
}
|
|
407
|
+
if (branchAttribute.value === undefined) {
|
|
408
|
+
if (branchAttribute.min === branchAttribute.max) {
|
|
409
|
+
branchAttribute.value = branchAttribute.min
|
|
410
|
+
}
|
|
334
411
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
412
|
+
if (mod.attributeId === items_1.ItemAttributesByName[items_1.Games.Raid.id].HarvestYield.id) {
|
|
413
|
+
item.meta.harvestYield += mod.value
|
|
414
|
+
} else if (mod.attributeId === items_1.ItemAttributesByName[items_1.Games.Raid.id].HarvestFeeToken.id) {
|
|
415
|
+
item.meta.harvestFees[
|
|
416
|
+
branchAttribute.param1 ? branchAttribute.param1.map[mod.value] : branchAttribute.map[mod.value]
|
|
417
|
+
] = prevMod.value
|
|
418
|
+
} else if (mod.attributeId === items_1.ItemAttributesByName[items_1.Games.Raid.id].SendHarvestHiddenPool.id) {
|
|
419
|
+
item.meta.chanceToSendHarvestToHiddenPool += mod.value
|
|
420
|
+
} else if (mod.attributeId === items_1.ItemAttributesByName[items_1.Games.Raid.id].BurnEntireHarvest.id) {
|
|
421
|
+
item.meta.chanceToLoseHarvest += mod.value
|
|
422
|
+
} else if (mod.attributeId === items_1.ItemAttributesByName[items_1.Games.Raid.id].HarvestBurn.id) {
|
|
423
|
+
item.meta.harvestBurn += mod.value
|
|
424
|
+
} else if (mod.attributeId === items_1.ItemAttributesByName[items_1.Games.Raid.id].FindShard.id) {
|
|
425
|
+
if (branchAttribute.value !== undefined) mod.value = branchAttribute.value
|
|
426
|
+
item.meta.worldstoneShardChance += mod.value
|
|
427
|
+
} else if (mod.attributeId === items_1.ItemAttributesByName[items_1.Games.Raid.id].RemoveFees.id) {
|
|
428
|
+
item.meta.feeReduction += mod.value
|
|
429
|
+
} else if (mod.attributeId === items_1.ItemAttributesByName[items_1.Games.Raid.id].RandomRuneExchange.id) {
|
|
430
|
+
item.meta.randomRuneExchange += mod.value
|
|
431
|
+
} else if (mod.attributeId === items_1.ItemAttributesByName[items_1.Games.Raid.id].UnstakeLocked.id) {
|
|
432
|
+
item.meta.unstakeLocked = true
|
|
433
|
+
} else if (mod.attributeId === items_1.ItemAttributesByName[items_1.Games.Raid.id].SpecificClass.id) {
|
|
434
|
+
item.meta.classRequired = mod.value
|
|
435
|
+
} else if (mod.attributeId === items_1.ItemAttributesByName[items_1.Games.Raid.id].Rarity.id) {
|
|
436
|
+
item.rarity = items_1.ItemRarity[items_1.ItemRarityNameById[mod.value]]
|
|
346
437
|
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
438
|
+
if (mod.attributeId > 0) {
|
|
439
|
+
// if (!item.meta.attributes[mod.attributeId]) item.meta.attributes[mod.attributeId] = 0
|
|
440
|
+
// item.meta.attributes[mod.attributeId] += mod.value
|
|
441
|
+
item.attributes[i] = Object.assign(
|
|
442
|
+
Object.assign(
|
|
443
|
+
Object.assign(
|
|
444
|
+
Object.assign({}, item.attributes[i] || {}),
|
|
445
|
+
items_1.ItemAttributesById[mod.attributeId] || {}
|
|
446
|
+
),
|
|
447
|
+
branchAttribute
|
|
448
|
+
),
|
|
449
|
+
mod
|
|
450
|
+
)
|
|
352
451
|
}
|
|
353
|
-
if (item.
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
item.meta.harvestYield += mod.value;
|
|
368
|
-
}
|
|
369
|
-
else if (mod.attributeId === items_1.ItemAttributesByName[items_1.Games.Raid.id].HarvestFeeToken.id) {
|
|
370
|
-
item.meta.harvestFees[branchAttribute.param1 ? branchAttribute.param1.map[mod.value] : branchAttribute.map[mod.value]] = prevMod.value;
|
|
371
|
-
}
|
|
372
|
-
else if (mod.attributeId === items_1.ItemAttributesByName[items_1.Games.Raid.id].SendHarvestHiddenPool.id) {
|
|
373
|
-
item.meta.chanceToSendHarvestToHiddenPool += mod.value;
|
|
374
|
-
}
|
|
375
|
-
else if (mod.attributeId === items_1.ItemAttributesByName[items_1.Games.Raid.id].BurnEntireHarvest.id) {
|
|
376
|
-
item.meta.chanceToLoseHarvest += mod.value;
|
|
377
|
-
}
|
|
378
|
-
else if (mod.attributeId === items_1.ItemAttributesByName[items_1.Games.Raid.id].HarvestBurn.id) {
|
|
379
|
-
item.meta.harvestBurn += mod.value;
|
|
380
|
-
}
|
|
381
|
-
else if (mod.attributeId === items_1.ItemAttributesByName[items_1.Games.Raid.id].FindShard.id) {
|
|
382
|
-
if (branchAttribute.value !== undefined)
|
|
383
|
-
mod.value = branchAttribute.value;
|
|
384
|
-
item.meta.worldstoneShardChance += mod.value;
|
|
385
|
-
}
|
|
386
|
-
else if (mod.attributeId === items_1.ItemAttributesByName[items_1.Games.Raid.id].RemoveFees.id) {
|
|
387
|
-
item.meta.feeReduction += mod.value;
|
|
388
|
-
}
|
|
389
|
-
else if (mod.attributeId === items_1.ItemAttributesByName[items_1.Games.Raid.id].RandomRuneExchange.id) {
|
|
390
|
-
item.meta.randomRuneExchange += mod.value;
|
|
391
|
-
}
|
|
392
|
-
else if (mod.attributeId === items_1.ItemAttributesByName[items_1.Games.Raid.id].UnstakeLocked.id) {
|
|
393
|
-
item.meta.unstakeLocked = true;
|
|
394
|
-
}
|
|
395
|
-
else if (mod.attributeId === items_1.ItemAttributesByName[items_1.Games.Raid.id].SpecificClass.id) {
|
|
396
|
-
item.meta.classRequired = mod.value;
|
|
397
|
-
}
|
|
398
|
-
else if (mod.attributeId === items_1.ItemAttributesByName[items_1.Games.Raid.id].Rarity.id) {
|
|
399
|
-
item.rarity = items_1.ItemRarity[items_1.ItemRarityNameById[mod.value]];
|
|
400
|
-
}
|
|
401
|
-
if (mod.attributeId > 0) {
|
|
402
|
-
// if (!item.meta.attributes[mod.attributeId]) item.meta.attributes[mod.attributeId] = 0
|
|
403
|
-
// item.meta.attributes[mod.attributeId] += mod.value
|
|
404
|
-
item.attributes[i] = Object.assign(Object.assign(Object.assign(Object.assign({}, (item.attributes[i] || {})), (items_1.ItemAttributesById[mod.attributeId] || {})), branchAttribute), mod);
|
|
405
|
-
}
|
|
406
|
-
if (item.attributes[i]) {
|
|
407
|
-
item.branches[1].attributes[i] = item.attributes[i];
|
|
408
|
-
if (!item.branches[1].attributes[i].param1) {
|
|
409
|
-
item.branches[1].attributes[i].param1 = {};
|
|
410
|
-
item.branches[1].attributes[i].param1.min = item.branches[1].attributes[i].min;
|
|
411
|
-
item.branches[1].attributes[i].param1.max = item.branches[1].attributes[i].max;
|
|
412
|
-
item.branches[1].attributes[i].param1.value = item.branches[1].attributes[i].value;
|
|
413
|
-
item.branches[1].attributes[i].param1.map = item.branches[1].attributes[i].map;
|
|
414
|
-
}
|
|
415
|
-
else {
|
|
416
|
-
item.branches[1].attributes[i].param1.value = item.branches[1].attributes[i].value;
|
|
417
|
-
item.branches[1].attributes[i].min = item.branches[1].attributes[i].param1.min;
|
|
418
|
-
item.branches[1].attributes[i].max = item.branches[1].attributes[i].param1.max;
|
|
419
|
-
item.branches[1].attributes[i].map = item.branches[1].attributes[i].param1.map;
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
prevMod = mod;
|
|
423
|
-
}
|
|
452
|
+
if (item.attributes[i]) {
|
|
453
|
+
item.branches[1].attributes[i] = item.attributes[i]
|
|
454
|
+
if (!item.branches[1].attributes[i].param1) {
|
|
455
|
+
item.branches[1].attributes[i].param1 = {}
|
|
456
|
+
item.branches[1].attributes[i].param1.min = item.branches[1].attributes[i].min
|
|
457
|
+
item.branches[1].attributes[i].param1.max = item.branches[1].attributes[i].max
|
|
458
|
+
item.branches[1].attributes[i].param1.value = item.branches[1].attributes[i].value
|
|
459
|
+
item.branches[1].attributes[i].param1.map = item.branches[1].attributes[i].map
|
|
460
|
+
} else {
|
|
461
|
+
item.branches[1].attributes[i].param1.value = item.branches[1].attributes[i].value
|
|
462
|
+
item.branches[1].attributes[i].min = item.branches[1].attributes[i].param1.min
|
|
463
|
+
item.branches[1].attributes[i].max = item.branches[1].attributes[i].param1.max
|
|
464
|
+
item.branches[1].attributes[i].map = item.branches[1].attributes[i].param1.map
|
|
465
|
+
}
|
|
424
466
|
}
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
467
|
+
prevMod = mod
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
// if (item.tokenId === "100300016012001003200700120130022011003200201020030142039011202100700000115") debugger;
|
|
471
|
+
if (Object.keys(item.meta.harvestFees).length > 0) {
|
|
472
|
+
item.meta.harvestFeeToken = Object.keys(item.meta.harvestFees)[0]
|
|
473
|
+
item.meta.harvestFeePercent = item.meta.harvestFees[Object.keys(item.meta.harvestFees)[0]]
|
|
474
|
+
}
|
|
475
|
+
if (branch === null || branch === void 0 ? void 0 : branch.perfection) {
|
|
476
|
+
const perfection = [...branch.perfection]
|
|
477
|
+
const attributes = branch.attributes
|
|
478
|
+
// if (item.tokenId === '1001000041000100015647') {
|
|
479
|
+
// console.log(perfection)
|
|
480
|
+
// console.log(item.attributes)
|
|
481
|
+
// console.log(branch.attributes)
|
|
482
|
+
// }
|
|
483
|
+
if (perfection.length) {
|
|
484
|
+
const shorthand = []
|
|
485
|
+
for (let i = 0; i < perfection.length; i++) {
|
|
486
|
+
if (perfection[i] === undefined || perfection[i] === null || !attributes[i]) {
|
|
487
|
+
perfection[i] = undefined
|
|
488
|
+
continue
|
|
489
|
+
}
|
|
490
|
+
perfection[i] =
|
|
491
|
+
perfection[i] === attributes[i].max
|
|
492
|
+
? perfection[i] - attributes[i].min === 0
|
|
493
|
+
? 1
|
|
494
|
+
: (attributes[i].value - attributes[i].min) / (perfection[i] - attributes[i].min)
|
|
495
|
+
: attributes[i].max - perfection[i] === 0
|
|
496
|
+
? 1
|
|
497
|
+
: 1 - (attributes[i].value - perfection[i]) / (attributes[i].max - perfection[i])
|
|
429
498
|
}
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
499
|
+
item.perfection = (0, math_1.average)(perfection.filter((p) => Number.isFinite(p)))
|
|
500
|
+
// if (item.tokenId === '1001000041000100015647') {
|
|
501
|
+
// console.log(perfection, branch.attributes[0].max, perfection[0], 1)
|
|
502
|
+
// }
|
|
503
|
+
if (Number.isFinite(item.perfection) && item.perfection <= 1) {
|
|
504
|
+
item.perfection = parseFloat((Math.floor(item.perfection * 100) / 100).toFixed(2))
|
|
505
|
+
if (item.perfection < 0) {
|
|
506
|
+
item.perfection = 0
|
|
507
|
+
}
|
|
508
|
+
const size = 20000
|
|
509
|
+
if (!probabilityCache_1.default[item.id]) {
|
|
510
|
+
probabilityCache_1.default[item.id] = {}
|
|
511
|
+
;[...Array(101).keys()].map(function (n) {
|
|
512
|
+
probabilityCache_1.default[item.id][n] = 0
|
|
513
|
+
})
|
|
514
|
+
;[...Array(size).keys()].map(function () {
|
|
515
|
+
const rando = Math.floor(
|
|
516
|
+
(branch.perfection.reduce(function (prev, cur, i) {
|
|
517
|
+
return (
|
|
518
|
+
prev +
|
|
519
|
+
(cur === null || cur === undefined
|
|
520
|
+
? 0
|
|
521
|
+
: cur === attributes[i].max
|
|
522
|
+
? ((0, math_1.randInt)(attributes[i].min, attributes[i].max) - attributes[i].min) /
|
|
523
|
+
(attributes[i].max - attributes[i].min)
|
|
524
|
+
: 1 -
|
|
525
|
+
((0, math_1.randInt)(attributes[i].min, attributes[i].max) - attributes[i].min) /
|
|
526
|
+
(attributes[i].max - attributes[i].min))
|
|
527
|
+
)
|
|
528
|
+
}, 0) /
|
|
529
|
+
branch.perfection.filter((p) => p !== undefined && p !== null).length) *
|
|
530
|
+
// Fury: ((randInt(3, 7)-3)/(7-3)+(randInt(20, 40)-20)/(40-20)+(1-(randInt(20, 40)-20)/(40-20)))/3
|
|
531
|
+
100
|
|
532
|
+
).toFixed(0)
|
|
533
|
+
probabilityCache_1.default[item.id][rando]++
|
|
534
|
+
})
|
|
535
|
+
}
|
|
536
|
+
// @ts-ignore
|
|
537
|
+
const total = [...Array(101).keys()].reduce((prev, cur) => prev + probabilityCache_1.default[item.id][cur], 0)
|
|
538
|
+
const mythic = probabilityCache_1.default[item.id][100] / total
|
|
539
|
+
const epic =
|
|
540
|
+
// @ts-ignore
|
|
541
|
+
[...Array(99 - 90).keys()].reduce((prev, cur) => prev + probabilityCache_1.default[item.id][cur + 90], 0) /
|
|
542
|
+
total
|
|
543
|
+
const rare =
|
|
544
|
+
// @ts-ignore
|
|
545
|
+
[...Array(89 - 70).keys()].reduce((prev, cur) => prev + probabilityCache_1.default[item.id][cur + 70], 0) /
|
|
546
|
+
total
|
|
547
|
+
const magical =
|
|
548
|
+
// @ts-ignore
|
|
549
|
+
[...Array(70 - 0).keys()].reduce((prev, cur) => prev + probabilityCache_1.default[item.id][cur + 0], 0) /
|
|
550
|
+
total
|
|
551
|
+
const roll =
|
|
552
|
+
item.perfection * 100 > 3
|
|
553
|
+
? (0, math_1.average)(
|
|
554
|
+
// @ts-ignore
|
|
555
|
+
[...Array(6).keys()].reduce(
|
|
556
|
+
(prev, cur) =>
|
|
557
|
+
// @ts-ignore
|
|
558
|
+
probabilityCache_1.default[item.id][parseInt(cur + item.perfection * 100 - 3)] === 0
|
|
559
|
+
? prev
|
|
560
|
+
: // @ts-ignore
|
|
561
|
+
[...prev, probabilityCache_1.default[item.id][parseInt(cur + item.perfection * 100 - 3)]],
|
|
562
|
+
[]
|
|
563
|
+
)
|
|
564
|
+
) / total
|
|
565
|
+
: probabilityCache_1.default[item.id][item.perfection * 100] / total
|
|
566
|
+
item.meta.probability = {
|
|
567
|
+
mythic,
|
|
568
|
+
epic,
|
|
569
|
+
rare,
|
|
570
|
+
magical,
|
|
571
|
+
roll,
|
|
572
|
+
}
|
|
573
|
+
} else {
|
|
574
|
+
item.perfection = null
|
|
575
|
+
}
|
|
576
|
+
} else {
|
|
577
|
+
item.perfection = null
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
// if (!item.meta) {
|
|
581
|
+
// item.meta = {
|
|
582
|
+
// harvestYield: 0,
|
|
583
|
+
// harvestFeeToken: '',
|
|
584
|
+
// harvestFeePercent: 0,
|
|
585
|
+
// harvestFees: {},
|
|
586
|
+
// chanceToSendHarvestToHiddenPool: 0,
|
|
587
|
+
// chanceToLoseHarvest: 0,
|
|
588
|
+
// harvestBurn: 0,
|
|
589
|
+
// }
|
|
590
|
+
// }
|
|
591
|
+
// if (item.rarity && item.branches[1]?.presets) {
|
|
592
|
+
// for (const attributeIndex in item.attributes) {
|
|
593
|
+
// item.attributes[attributeIndex].value = item.branches[1].presets[item.rarity.id][attributeIndex]
|
|
594
|
+
// }
|
|
595
|
+
// }
|
|
596
|
+
// Normalize rarity based on perfection
|
|
597
|
+
if (!item.rarity) {
|
|
598
|
+
if ((_a = item.attributes.find((a) => a.id === 40)) === null || _a === void 0 ? void 0 : _a.value) {
|
|
599
|
+
item.rarity =
|
|
600
|
+
items_1.ItemRarity[
|
|
601
|
+
items_1.ItemRarityNameById[
|
|
602
|
+
((_b = item.attributes.find((a) => a.id === 40)) === null || _b === void 0 ? void 0 : _b.value) || 5
|
|
603
|
+
]
|
|
604
|
+
]
|
|
605
|
+
} else if (item.perfection === 1) {
|
|
606
|
+
item.rarity = items_1.ItemRarity.Mythic
|
|
607
|
+
} else if (item.perfection >= 0.9) {
|
|
608
|
+
item.rarity = items_1.ItemRarity.Epic
|
|
609
|
+
} else if (item.perfection >= 0.7) {
|
|
610
|
+
item.rarity = items_1.ItemRarity.Rare
|
|
611
|
+
} else if (item.perfection >= 0) {
|
|
612
|
+
item.rarity = items_1.ItemRarity.Magical
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
// Normalize perfection basd on rarity
|
|
616
|
+
if (item.rarity && item.perfection === null) {
|
|
617
|
+
if (item.rarity.id === items_1.ItemRarity.Mythic) {
|
|
618
|
+
item.perfection = 1
|
|
619
|
+
} else if (item.rarity.id === items_1.ItemRarity.Epic) {
|
|
620
|
+
item.perfection = 0.9
|
|
621
|
+
} else if (item.rarity.id === items_1.ItemRarity.Rare) {
|
|
622
|
+
item.perfection = 0.7
|
|
623
|
+
} else if (item.rarity.id === items_1.ItemRarity.Magical) {
|
|
624
|
+
item.perfection = 0.35
|
|
625
|
+
} else {
|
|
626
|
+
item.perfection = 1
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
if (item.branches) {
|
|
630
|
+
// Set .value if .min and .max are same
|
|
631
|
+
for (const bIndex of Object.keys(item.branches)) {
|
|
632
|
+
const branchIndex = Number(bIndex)
|
|
633
|
+
for (const attributeIndex in item.branches[branchIndex].attributes) {
|
|
634
|
+
if (item.branches[branchIndex].attributes[attributeIndex].value === undefined) {
|
|
635
|
+
if (
|
|
636
|
+
item.branches[branchIndex].attributes[attributeIndex].min ===
|
|
637
|
+
item.branches[branchIndex].attributes[attributeIndex].max
|
|
638
|
+
) {
|
|
639
|
+
item.branches[branchIndex].attributes[attributeIndex].value =
|
|
640
|
+
item.branches[branchIndex].attributes[attributeIndex].min
|
|
641
|
+
if (branchIndex === 1) {
|
|
642
|
+
item.attributes[attributeIndex].value = item.branches[branchIndex].attributes[attributeIndex].value
|
|
643
|
+
}
|
|
523
644
|
}
|
|
645
|
+
}
|
|
524
646
|
}
|
|
525
|
-
//
|
|
526
|
-
// item.
|
|
527
|
-
//
|
|
528
|
-
//
|
|
529
|
-
//
|
|
530
|
-
//
|
|
531
|
-
//
|
|
532
|
-
//
|
|
533
|
-
//
|
|
647
|
+
// for (const attributeIndex in item.attributes) {
|
|
648
|
+
// // item.branches[branchIndex].attributes[i] = item.attributes[i]
|
|
649
|
+
// if (!item.branches[branchIndex].attributes[attributeIndex].param1) {
|
|
650
|
+
// item.branches[branchIndex].attributes[attributeIndex].param1 = {}
|
|
651
|
+
// item.branches[branchIndex].attributes[attributeIndex].param1.min = item.branches[branchIndex].attributes[attributeIndex].min
|
|
652
|
+
// item.branches[branchIndex].attributes[attributeIndex].param1.max = item.branches[branchIndex].attributes[attributeIndex].max
|
|
653
|
+
// item.branches[branchIndex].attributes[attributeIndex].param1.value = item.branches[branchIndex].attributes[attributeIndex].value
|
|
654
|
+
// item.branches[branchIndex].attributes[attributeIndex].param1.map = item.branches[branchIndex].attributes[attributeIndex].map
|
|
655
|
+
// } else {
|
|
656
|
+
// item.branches[branchIndex].attributes[attributeIndex].param1.value = item.branches[branchIndex].attributes[attributeIndex].value
|
|
657
|
+
// item.branches[branchIndex].attributes[attributeIndex].min = item.branches[branchIndex].attributes[attributeIndex].param1.min
|
|
658
|
+
// item.branches[branchIndex].attributes[attributeIndex].max = item.branches[branchIndex].attributes[attributeIndex].param1.max
|
|
659
|
+
// item.branches[branchIndex].attributes[attributeIndex].map = item.branches[branchIndex].attributes[attributeIndex].param1.map
|
|
534
660
|
// }
|
|
535
|
-
//
|
|
536
|
-
//
|
|
537
|
-
//
|
|
538
|
-
//
|
|
661
|
+
// if (branchIndex === 1) {
|
|
662
|
+
// if (!item.attributes[attributeIndex].param1) {
|
|
663
|
+
// item.attributes[attributeIndex].param1 = item.branches[branchIndex].attributes[attributeIndex].param1
|
|
664
|
+
// }
|
|
539
665
|
// }
|
|
540
666
|
// }
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
667
|
+
}
|
|
668
|
+
// Set preset and attribute values based on rarity
|
|
669
|
+
for (const bIndex of Object.keys(item.branches)) {
|
|
670
|
+
const branchIndex = Number(bIndex)
|
|
671
|
+
if (!item.branches[branchIndex].attributes) continue
|
|
672
|
+
const presets = item.branches[branchIndex].presets
|
|
673
|
+
if (!presets) {
|
|
674
|
+
const perf = item.branches[branchIndex].perfection
|
|
675
|
+
const attrs = item.branches[branchIndex].attributes
|
|
676
|
+
// TODO: figure out if attribute min or max is best and push that into array of perfs (requires spec)
|
|
677
|
+
// if (!perf) {
|
|
678
|
+
// perf = []
|
|
679
|
+
// for (const pp in item.branches[branchIndex].attributes) {
|
|
680
|
+
// perf.push(item.perfection)
|
|
681
|
+
// }
|
|
682
|
+
// }
|
|
683
|
+
item.branches[branchIndex].presets = {
|
|
684
|
+
[items_1.ItemRarity.Magical.id]: [],
|
|
685
|
+
[items_1.ItemRarity.Rare.id]: [],
|
|
686
|
+
[items_1.ItemRarity.Epic.id]: [],
|
|
687
|
+
[items_1.ItemRarity.Mythic.id]: [],
|
|
688
|
+
[items_1.ItemRarity.Unique.id]: [],
|
|
689
|
+
}
|
|
690
|
+
for (const pIndex in perf) {
|
|
691
|
+
if (perf[pIndex] === undefined || perf[pIndex] === null) continue
|
|
692
|
+
item.branches[branchIndex].presets[items_1.ItemRarity.Magical.id][pIndex] = Math.floor(
|
|
693
|
+
perf[pIndex] === attrs[pIndex].max
|
|
694
|
+
? (attrs[pIndex].max - attrs[pIndex].min) * 0.2 + attrs[pIndex].min
|
|
695
|
+
: attrs[pIndex].max - (attrs[pIndex].max - attrs[pIndex].min) * 0.2
|
|
696
|
+
)
|
|
697
|
+
item.branches[branchIndex].presets[items_1.ItemRarity.Rare.id][pIndex] = Math.floor(
|
|
698
|
+
perf[pIndex] === attrs[pIndex].max
|
|
699
|
+
? (attrs[pIndex].max - attrs[pIndex].min) * 0.7 + attrs[pIndex].min
|
|
700
|
+
: attrs[pIndex].max - (attrs[pIndex].max - attrs[pIndex].min) * 0.7
|
|
701
|
+
)
|
|
702
|
+
item.branches[branchIndex].presets[items_1.ItemRarity.Epic.id][pIndex] = Math.floor(
|
|
703
|
+
perf[pIndex] === attrs[pIndex].max
|
|
704
|
+
? (attrs[pIndex].max - attrs[pIndex].min) * 0.95 + attrs[pIndex].min
|
|
705
|
+
: attrs[pIndex].max - (attrs[pIndex].max - attrs[pIndex].min) * 0.95
|
|
706
|
+
)
|
|
707
|
+
item.branches[branchIndex].presets[items_1.ItemRarity.Mythic.id][pIndex] = perf[pIndex]
|
|
708
|
+
item.branches[branchIndex].presets[items_1.ItemRarity.Unique.id][pIndex] = perf[pIndex]
|
|
709
|
+
}
|
|
558
710
|
}
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
item.perfection = 0.35;
|
|
572
|
-
}
|
|
573
|
-
else {
|
|
574
|
-
item.perfection = 1;
|
|
711
|
+
if (item.rarity) {
|
|
712
|
+
for (const b2Index of Object.keys(item.branches)) {
|
|
713
|
+
const branch2Index = Number(b2Index)
|
|
714
|
+
if (!((_c = item.branches[branch2Index].presets) === null || _c === void 0 ? void 0 : _c[item.rarity.id]))
|
|
715
|
+
continue
|
|
716
|
+
for (const presetIndex in item.branches[branch2Index].presets[item.rarity.id]) {
|
|
717
|
+
const preset = item.branches[branch2Index].presets[item.rarity.id][presetIndex]
|
|
718
|
+
if (item.branches[branch2Index].attributes[presetIndex].value !== undefined) continue
|
|
719
|
+
item.branches[branch2Index].attributes[presetIndex].value = preset
|
|
720
|
+
if (branch2Index === 1) {
|
|
721
|
+
item.attributes[presetIndex].value = preset
|
|
722
|
+
}
|
|
575
723
|
}
|
|
724
|
+
}
|
|
576
725
|
}
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
// for (const attributeIndex in item.attributes) {
|
|
594
|
-
// // item.branches[branchIndex].attributes[i] = item.attributes[i]
|
|
595
|
-
// if (!item.branches[branchIndex].attributes[attributeIndex].param1) {
|
|
596
|
-
// item.branches[branchIndex].attributes[attributeIndex].param1 = {}
|
|
597
|
-
// item.branches[branchIndex].attributes[attributeIndex].param1.min = item.branches[branchIndex].attributes[attributeIndex].min
|
|
598
|
-
// item.branches[branchIndex].attributes[attributeIndex].param1.max = item.branches[branchIndex].attributes[attributeIndex].max
|
|
599
|
-
// item.branches[branchIndex].attributes[attributeIndex].param1.value = item.branches[branchIndex].attributes[attributeIndex].value
|
|
600
|
-
// item.branches[branchIndex].attributes[attributeIndex].param1.map = item.branches[branchIndex].attributes[attributeIndex].map
|
|
601
|
-
// } else {
|
|
602
|
-
// item.branches[branchIndex].attributes[attributeIndex].param1.value = item.branches[branchIndex].attributes[attributeIndex].value
|
|
603
|
-
// item.branches[branchIndex].attributes[attributeIndex].min = item.branches[branchIndex].attributes[attributeIndex].param1.min
|
|
604
|
-
// item.branches[branchIndex].attributes[attributeIndex].max = item.branches[branchIndex].attributes[attributeIndex].param1.max
|
|
605
|
-
// item.branches[branchIndex].attributes[attributeIndex].map = item.branches[branchIndex].attributes[attributeIndex].param1.map
|
|
606
|
-
// }
|
|
607
|
-
// if (branchIndex === 1) {
|
|
608
|
-
// if (!item.attributes[attributeIndex].param1) {
|
|
609
|
-
// item.attributes[attributeIndex].param1 = item.branches[branchIndex].attributes[attributeIndex].param1
|
|
610
|
-
// }
|
|
611
|
-
// }
|
|
612
|
-
// }
|
|
613
|
-
}
|
|
614
|
-
// Set preset and attribute values based on rarity
|
|
615
|
-
for (const bIndex of Object.keys(item.branches)) {
|
|
616
|
-
const branchIndex = Number(bIndex);
|
|
617
|
-
if (!item.branches[branchIndex].attributes)
|
|
618
|
-
continue;
|
|
619
|
-
const presets = item.branches[branchIndex].presets;
|
|
620
|
-
if (!presets) {
|
|
621
|
-
const perf = item.branches[branchIndex].perfection;
|
|
622
|
-
const attrs = item.branches[branchIndex].attributes;
|
|
623
|
-
// TODO: figure out if attribute min or max is best and push that into array of perfs (requires spec)
|
|
624
|
-
// if (!perf) {
|
|
625
|
-
// perf = []
|
|
626
|
-
// for (const pp in item.branches[branchIndex].attributes) {
|
|
627
|
-
// perf.push(item.perfection)
|
|
628
|
-
// }
|
|
629
|
-
// }
|
|
630
|
-
item.branches[branchIndex].presets = {
|
|
631
|
-
[items_1.ItemRarity.Magical.id]: [],
|
|
632
|
-
[items_1.ItemRarity.Rare.id]: [],
|
|
633
|
-
[items_1.ItemRarity.Epic.id]: [],
|
|
634
|
-
[items_1.ItemRarity.Mythic.id]: [],
|
|
635
|
-
[items_1.ItemRarity.Unique.id]: [],
|
|
636
|
-
};
|
|
637
|
-
for (const pIndex in perf) {
|
|
638
|
-
if (perf[pIndex] === undefined || perf[pIndex] === null)
|
|
639
|
-
continue;
|
|
640
|
-
item.branches[branchIndex].presets[items_1.ItemRarity.Magical.id][pIndex] = Math.floor(perf[pIndex] === attrs[pIndex].max
|
|
641
|
-
? (attrs[pIndex].max - attrs[pIndex].min) * 0.2 + attrs[pIndex].min
|
|
642
|
-
: attrs[pIndex].max - (attrs[pIndex].max - attrs[pIndex].min) * 0.2);
|
|
643
|
-
item.branches[branchIndex].presets[items_1.ItemRarity.Rare.id][pIndex] = Math.floor(perf[pIndex] === attrs[pIndex].max
|
|
644
|
-
? (attrs[pIndex].max - attrs[pIndex].min) * 0.7 + attrs[pIndex].min
|
|
645
|
-
: attrs[pIndex].max - (attrs[pIndex].max - attrs[pIndex].min) * 0.7);
|
|
646
|
-
item.branches[branchIndex].presets[items_1.ItemRarity.Epic.id][pIndex] = Math.floor(perf[pIndex] === attrs[pIndex].max
|
|
647
|
-
? (attrs[pIndex].max - attrs[pIndex].min) * 0.95 + attrs[pIndex].min
|
|
648
|
-
: attrs[pIndex].max - (attrs[pIndex].max - attrs[pIndex].min) * 0.95);
|
|
649
|
-
item.branches[branchIndex].presets[items_1.ItemRarity.Mythic.id][pIndex] = perf[pIndex];
|
|
650
|
-
item.branches[branchIndex].presets[items_1.ItemRarity.Unique.id][pIndex] = perf[pIndex];
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
if (item.rarity) {
|
|
654
|
-
for (const b2Index of Object.keys(item.branches)) {
|
|
655
|
-
const branch2Index = Number(b2Index);
|
|
656
|
-
if (!((_c = item.branches[branch2Index].presets) === null || _c === void 0 ? void 0 : _c[item.rarity.id]))
|
|
657
|
-
continue;
|
|
658
|
-
for (const presetIndex in item.branches[branch2Index].presets[item.rarity.id]) {
|
|
659
|
-
const preset = item.branches[branch2Index].presets[item.rarity.id][presetIndex];
|
|
660
|
-
if (item.branches[branch2Index].attributes[presetIndex].value !== undefined)
|
|
661
|
-
continue;
|
|
662
|
-
item.branches[branch2Index].attributes[presetIndex].value = preset;
|
|
663
|
-
if (branch2Index === 1) {
|
|
664
|
-
item.attributes[presetIndex].value = preset;
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
}
|
|
669
|
-
}
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
// Normalize main branch map attribute values
|
|
729
|
+
if (branch === null || branch === void 0 ? void 0 : branch.perfection) {
|
|
730
|
+
for (const attributeIndex in branch.attributes) {
|
|
731
|
+
const attribute = branch.attributes[attributeIndex]
|
|
732
|
+
const perfection = branch.perfection[attributeIndex]
|
|
733
|
+
if (perfection === undefined || perfection == null) {
|
|
734
|
+
if (attribute.value === undefined && attribute.map) {
|
|
735
|
+
attribute.value = attribute.min
|
|
736
|
+
item.attributes[attributeIndex] = attribute
|
|
737
|
+
}
|
|
670
738
|
}
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
if (item.branches) {
|
|
742
|
+
// Normalize branch values and perfection
|
|
743
|
+
for (const bIndex of Object.keys(item.branches)) {
|
|
744
|
+
const branchIndex = Number(bIndex)
|
|
745
|
+
if (branchIndex === 1) {
|
|
746
|
+
for (const attributeIndex in item.branches[branchIndex].attributes) {
|
|
747
|
+
const attribute = item.branches[branchIndex].attributes[attributeIndex]
|
|
748
|
+
if (attribute.param1.value !== undefined) {
|
|
749
|
+
if (!item.meta.attributes[attribute.id]) item.meta.attributes[attribute.id] = 0
|
|
750
|
+
item.meta.attributes[attribute.id] += attribute.param1.value
|
|
682
751
|
}
|
|
752
|
+
}
|
|
753
|
+
continue
|
|
683
754
|
}
|
|
684
|
-
if (item.branches)
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
attribute.param1.value = closestKey;
|
|
760
|
-
}
|
|
761
|
-
else {
|
|
762
|
-
const alignedValue = Math.floor((attribute.param1.max - attribute.param1.min) * targetPerfection);
|
|
763
|
-
attribute.param1.value = attribute.param1.min + alignedValue;
|
|
764
|
-
}
|
|
765
|
-
// if (!item.branches[branchIndex].perfection) {
|
|
766
|
-
// item.branches[branchIndex].perfection = []
|
|
767
|
-
// }
|
|
768
|
-
// if (item.branches[branchIndex].perfection[attributeIndex] === undefined) {
|
|
769
|
-
// item.branches[branchIndex].perfection[attributeIndex] = targetPerfection
|
|
770
|
-
// }
|
|
771
|
-
// if (!item.meta.attributes[attribute.id]) item.meta.attributes[attribute.id] = 0
|
|
772
|
-
if (Number.isFinite(attribute.param1.value)) {
|
|
773
|
-
if (!item.meta.attributes[attribute.id])
|
|
774
|
-
item.meta.attributes[attribute.id] = 0;
|
|
775
|
-
item.meta.attributes[attribute.id] += attribute.param1.value;
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
}
|
|
755
|
+
if (!item.branches[branchIndex].attributes) continue
|
|
756
|
+
for (const attributeIndex in item.branches[branchIndex].attributes) {
|
|
757
|
+
if (
|
|
758
|
+
!item.branches[1] ||
|
|
759
|
+
!item.branches[1].perfection ||
|
|
760
|
+
!item.branches[1].attributes ||
|
|
761
|
+
!item.branches[branchIndex] ||
|
|
762
|
+
!item.branches[branchIndex].attributes[attributeIndex]
|
|
763
|
+
) {
|
|
764
|
+
break
|
|
765
|
+
}
|
|
766
|
+
const attribute = item.branches[branchIndex].attributes[attributeIndex]
|
|
767
|
+
if (!attribute.param1) {
|
|
768
|
+
continue
|
|
769
|
+
}
|
|
770
|
+
if (Number.isFinite(attribute.param1.value)) {
|
|
771
|
+
if (!item.meta.attributes[attribute.id]) item.meta.attributes[attribute.id] = 0
|
|
772
|
+
item.meta.attributes[attribute.id] += attribute.param1.value
|
|
773
|
+
continue
|
|
774
|
+
}
|
|
775
|
+
// let targetAttribute = item.branches[branchIndex].attributes[attributeIndex]
|
|
776
|
+
let targetPerfection
|
|
777
|
+
// let attributePerfection
|
|
778
|
+
if (Number.isFinite(item.branches[1].perfection[attributeIndex])) {
|
|
779
|
+
targetPerfection =
|
|
780
|
+
item.branches[1].perfection[attributeIndex] === item.branches[1].attributes[attributeIndex].param1.max
|
|
781
|
+
? (item.branches[1].attributes[attributeIndex].param1.value -
|
|
782
|
+
item.branches[1].attributes[attributeIndex].param1.min) /
|
|
783
|
+
(item.branches[1].attributes[attributeIndex].param1.max -
|
|
784
|
+
item.branches[1].attributes[attributeIndex].param1.min)
|
|
785
|
+
: 1 -
|
|
786
|
+
(item.branches[1].attributes[attributeIndex].param1.value -
|
|
787
|
+
item.branches[1].attributes[attributeIndex].param1.min) /
|
|
788
|
+
(item.branches[1].attributes[attributeIndex].param1.max -
|
|
789
|
+
item.branches[1].attributes[attributeIndex].param1.min)
|
|
790
|
+
} else {
|
|
791
|
+
// targetAttribute = item.branches[branchIndex].attributes[attributeIndex]
|
|
792
|
+
targetPerfection = item.perfection // item.branches[branchIndex].perfection[attributeIndex]
|
|
793
|
+
}
|
|
794
|
+
// if (targetPerfection && targetAttribute) {
|
|
795
|
+
// attributePerfection =
|
|
796
|
+
// targetPerfection === targetAttribute.param1.max
|
|
797
|
+
// ? targetPerfection - targetAttribute.param1.min === 0
|
|
798
|
+
// ? 1
|
|
799
|
+
// : (targetAttribute.param1.value - targetAttribute.param1.min) /
|
|
800
|
+
// (targetPerfection - targetAttribute.param1.min)
|
|
801
|
+
// : targetAttribute.param1.max - targetPerfection === 0
|
|
802
|
+
// ? 1
|
|
803
|
+
// : 1 -
|
|
804
|
+
// (targetAttribute.param1.value - targetPerfection) /
|
|
805
|
+
// (targetAttribute.param1.max - targetPerfection)
|
|
806
|
+
// } else {
|
|
807
|
+
// attributePerfection = targetPerfection
|
|
808
|
+
// }
|
|
809
|
+
if (attribute.param1.map) {
|
|
810
|
+
const kindofClose = Math.floor((attribute.param1.max - attribute.param1.min) * targetPerfection)
|
|
811
|
+
const closestKey = Object.keys(attribute.param1.map).sort((a, b) => {
|
|
812
|
+
return Math.abs(kindofClose - Number(a)) - Math.abs(kindofClose - Number(b))
|
|
813
|
+
})[0]
|
|
814
|
+
attribute.param1.value = closestKey
|
|
815
|
+
} else {
|
|
816
|
+
const alignedValue = Math.floor((attribute.param1.max - attribute.param1.min) * targetPerfection)
|
|
817
|
+
attribute.param1.value = attribute.param1.min + alignedValue
|
|
818
|
+
}
|
|
819
|
+
// if (!item.branches[branchIndex].perfection) {
|
|
820
|
+
// item.branches[branchIndex].perfection = []
|
|
821
|
+
// }
|
|
822
|
+
// if (item.branches[branchIndex].perfection[attributeIndex] === undefined) {
|
|
823
|
+
// item.branches[branchIndex].perfection[attributeIndex] = targetPerfection
|
|
824
|
+
// }
|
|
825
|
+
// if (!item.meta.attributes[attribute.id]) item.meta.attributes[attribute.id] = 0
|
|
826
|
+
if (Number.isFinite(attribute.param1.value)) {
|
|
827
|
+
if (!item.meta.attributes[attribute.id]) item.meta.attributes[attribute.id] = 0
|
|
828
|
+
item.meta.attributes[attribute.id] += attribute.param1.value
|
|
829
|
+
}
|
|
779
830
|
}
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
// item.meta.odds = odds
|
|
797
|
-
// }
|
|
798
|
-
item.shorthand = shorthand.map((s) => s + '').join('-');
|
|
799
|
-
}
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
// Normalize shorthand
|
|
834
|
+
if (branch === null || branch === void 0 ? void 0 : branch.perfection) {
|
|
835
|
+
const perfection = [...branch.perfection]
|
|
836
|
+
const attributes = branch.attributes
|
|
837
|
+
if (perfection.length) {
|
|
838
|
+
const shorthand = []
|
|
839
|
+
// let odds = 1
|
|
840
|
+
for (let i = 0; i < perfection.length; i++) {
|
|
841
|
+
if (perfection[i] === undefined || perfection[i] === null || !attributes[i]) {
|
|
842
|
+
continue
|
|
843
|
+
}
|
|
844
|
+
const value = attributes[i].map ? attributes[i].map[attributes[i].value] : attributes[i].value
|
|
845
|
+
shorthand.push(value)
|
|
846
|
+
// odds *= (value - attributes[i].min + 1)
|
|
800
847
|
}
|
|
801
|
-
//
|
|
802
|
-
//
|
|
803
|
-
// let mean = 0
|
|
804
|
-
// let totalMean = 0
|
|
805
|
-
// let odds = 1
|
|
806
|
-
// for (const attributeIndex in item.branches[1].attributes) {
|
|
807
|
-
// const attribute = item.branches[1].attributes[attributeIndex]
|
|
808
|
-
// if (attribute.min === undefined || attribute.max === undefined) continue
|
|
809
|
-
// if (attribute.min === attribute.max) continue
|
|
810
|
-
// if (attribute.map) continue
|
|
811
|
-
// if (attribute.id === ItemAttributesByName[Games.Raid.id].RandomPerfection1.id || attribute.id === ItemAttributesByName[Games.Raid.id].RandomPerfection2.id || attribute.id === ItemAttributesByName[Games.Raid.id].RandomPerfection3.id || attribute.id === ItemAttributesByName[Games.Raid.id].RandomPerfection4.id || attribute.id === ItemAttributesByName[Games.Raid.id].RandomPerfection5.id) continue
|
|
812
|
-
// odds *= (attribute.max - attribute.min + 1)
|
|
813
|
-
// }
|
|
814
|
-
// if (odds > 1) {
|
|
815
|
-
// }
|
|
848
|
+
// if (odds > 1) {
|
|
849
|
+
// item.meta.odds = odds
|
|
816
850
|
// }
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
if (item.tokenId === '100300014012001002201900120130012011001200200720030122039008202100600000875')
|
|
840
|
-
item.perfection = -13;
|
|
841
|
-
if (item.tokenId === '100301201142040003200100520130200000000000000000000000000000000000000000001')
|
|
842
|
-
item.branches[1].description[1] = '"So long, I barely knew thee."';
|
|
843
|
-
// if (item.exclusiveConditions) {
|
|
844
|
-
// const conditionMatch = []
|
|
845
|
-
// for (const condition of item.exclusiveConditions) {
|
|
846
|
-
// if (condition === 'stream') {
|
|
847
|
-
// const now = new Date()
|
|
848
|
-
// // const eventStart = nextDate(0, 20).getTime() / 1000
|
|
849
|
-
// // const eventEnd = nextDate(0, 23, 59).getTime() / 1000 // 4 hours later
|
|
850
|
-
// // conditionMatch.push(now > streamStart && now < streamEnd)
|
|
851
|
-
// // const now = (new Date()).getTime() / 1000
|
|
852
|
-
// // const eventStart = 1660321091
|
|
853
|
-
// // const eventEnd = 1660324091
|
|
854
|
-
// conditionMatch.push(now.getDay() === 0 && now.getHours() >= 15 && now.getHours() <= 23) // 3-7PM UTC
|
|
855
|
-
// }
|
|
856
|
-
// if (condition === 'halloween') {
|
|
857
|
-
// const now = new Date()
|
|
858
|
-
// const eventStart = new Date(`October 31, ${now.getFullYear()} 00:00:00`)
|
|
859
|
-
// const eventEnd = new Date(`November 1, ${now.getFullYear()} 00:00:00`)
|
|
860
|
-
// conditionMatch.push(now > eventStart && now < eventEnd)
|
|
861
|
-
// }
|
|
862
|
-
// if (condition === 'christmas') {
|
|
863
|
-
// const now = new Date()
|
|
864
|
-
// const eventStart = new Date(`December 24, ${now.getFullYear()} 00:00:00`)
|
|
865
|
-
// const eventEnd = new Date(`December 26, ${now.getFullYear()} 00:00:00`)
|
|
866
|
-
// conditionMatch.push(now > eventStart && now < eventEnd)
|
|
867
|
-
// }
|
|
868
|
-
// }
|
|
869
|
-
// if (conditionMatch.includes(true)) {
|
|
870
|
-
// item.isSecret = false
|
|
871
|
-
// item.isUltraSecret = false
|
|
872
|
-
// item.isCraftable = true
|
|
873
|
-
// }
|
|
874
|
-
// }
|
|
851
|
+
item.shorthand = shorthand.map((s) => s + '').join('-')
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
// Normalize odds
|
|
855
|
+
// if (item.meta && item.branches?.[1]) {
|
|
856
|
+
// let mean = 0
|
|
857
|
+
// let totalMean = 0
|
|
858
|
+
// let odds = 1
|
|
859
|
+
// for (const attributeIndex in item.branches[1].attributes) {
|
|
860
|
+
// const attribute = item.branches[1].attributes[attributeIndex]
|
|
861
|
+
// if (attribute.min === undefined || attribute.max === undefined) continue
|
|
862
|
+
// if (attribute.min === attribute.max) continue
|
|
863
|
+
// if (attribute.map) continue
|
|
864
|
+
// if (attribute.id === ItemAttributesByName[Games.Raid.id].RandomPerfection1.id || attribute.id === ItemAttributesByName[Games.Raid.id].RandomPerfection2.id || attribute.id === ItemAttributesByName[Games.Raid.id].RandomPerfection3.id || attribute.id === ItemAttributesByName[Games.Raid.id].RandomPerfection4.id || attribute.id === ItemAttributesByName[Games.Raid.id].RandomPerfection5.id) continue
|
|
865
|
+
// odds *= (attribute.max - attribute.min + 1)
|
|
866
|
+
// }
|
|
867
|
+
// if (odds > 1) {
|
|
868
|
+
// }
|
|
869
|
+
// }
|
|
870
|
+
// Normalize perfection
|
|
871
|
+
if (item.perfection === undefined || item.perfection === null) {
|
|
872
|
+
item.perfection = 1
|
|
875
873
|
}
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
console.log(e);
|
|
874
|
+
if (!item.tokenId) {
|
|
875
|
+
item.tokenId = getTokenIdFromItem(item)
|
|
879
876
|
}
|
|
880
|
-
|
|
881
|
-
|
|
877
|
+
if (item.branches[2]) {
|
|
878
|
+
item.branches[2].initialCharge =
|
|
879
|
+
item.branches[2].initialCharge !== undefined ? item.branches[2].initialCharge : item.initialCharge
|
|
880
|
+
item.branches[2].maxCharge =
|
|
881
|
+
item.branches[2].maxCharge !== undefined ? item.branches[2].maxCharge : item.maxCharge
|
|
882
|
+
const chargeMultiplier = {
|
|
883
|
+
[items_1.ItemRarity.Magical.id]: 4,
|
|
884
|
+
[items_1.ItemRarity.Rare.id]: 3,
|
|
885
|
+
[items_1.ItemRarity.Epic.id]: 2,
|
|
886
|
+
[items_1.ItemRarity.Mythic.id]: 1,
|
|
887
|
+
}
|
|
888
|
+
item.branches[2].initialCharge *= chargeMultiplier[item.rarity.id]
|
|
889
|
+
item.branches[2].maxCharge *= chargeMultiplier[item.rarity.id]
|
|
890
|
+
}
|
|
891
|
+
item.slug =
|
|
892
|
+
(_d = item.name) === null || _d === void 0 ? void 0 : _d.replace(/ /gi, '-').replace(/"/gi, '').toLowerCase()
|
|
893
|
+
if (item.tokenId === '100300014012001002201900120130012011001200200720030122039008202100600000875')
|
|
894
|
+
item.perfection = -13
|
|
895
|
+
if (item.tokenId === '100301201142040003200100520130200000000000000000000000000000000000000000001')
|
|
896
|
+
item.branches[1].description[1] = '"So long, I barely knew thee."'
|
|
897
|
+
// if (item.exclusiveConditions) {
|
|
898
|
+
// const conditionMatch = []
|
|
899
|
+
// for (const condition of item.exclusiveConditions) {
|
|
900
|
+
// if (condition === 'stream') {
|
|
901
|
+
// const now = new Date()
|
|
902
|
+
// // const eventStart = nextDate(0, 20).getTime() / 1000
|
|
903
|
+
// // const eventEnd = nextDate(0, 23, 59).getTime() / 1000 // 4 hours later
|
|
904
|
+
// // conditionMatch.push(now > streamStart && now < streamEnd)
|
|
905
|
+
// // const now = (new Date()).getTime() / 1000
|
|
906
|
+
// // const eventStart = 1660321091
|
|
907
|
+
// // const eventEnd = 1660324091
|
|
908
|
+
// conditionMatch.push(now.getDay() === 0 && now.getHours() >= 15 && now.getHours() <= 23) // 3-7PM UTC
|
|
909
|
+
// }
|
|
910
|
+
// if (condition === 'halloween') {
|
|
911
|
+
// const now = new Date()
|
|
912
|
+
// const eventStart = new Date(`October 31, ${now.getFullYear()} 00:00:00`)
|
|
913
|
+
// const eventEnd = new Date(`November 1, ${now.getFullYear()} 00:00:00`)
|
|
914
|
+
// conditionMatch.push(now > eventStart && now < eventEnd)
|
|
915
|
+
// }
|
|
916
|
+
// if (condition === 'christmas') {
|
|
917
|
+
// const now = new Date()
|
|
918
|
+
// const eventStart = new Date(`December 24, ${now.getFullYear()} 00:00:00`)
|
|
919
|
+
// const eventEnd = new Date(`December 26, ${now.getFullYear()} 00:00:00`)
|
|
920
|
+
// conditionMatch.push(now > eventStart && now < eventEnd)
|
|
921
|
+
// }
|
|
922
|
+
// }
|
|
923
|
+
// if (conditionMatch.includes(true)) {
|
|
924
|
+
// item.isSecret = false
|
|
925
|
+
// item.isUltraSecret = false
|
|
926
|
+
// item.isCraftable = true
|
|
927
|
+
// }
|
|
928
|
+
// }
|
|
929
|
+
} catch (e) {
|
|
930
|
+
// console.log('Token is invalid', tokenId)
|
|
931
|
+
console.log(e)
|
|
932
|
+
}
|
|
933
|
+
setItemTokenCache(item)
|
|
934
|
+
return item
|
|
882
935
|
}
|
|
883
|
-
exports.normalizeItem = normalizeItem
|
|
936
|
+
exports.normalizeItem = normalizeItem
|
|
884
937
|
function pad(n, width, z = '0') {
|
|
885
|
-
|
|
886
|
-
|
|
938
|
+
const nn = n + ''
|
|
939
|
+
return nn.length >= width ? nn : new Array(width - nn.length + 1).join(z) + nn
|
|
887
940
|
}
|
|
888
941
|
function getTokenIdFromItem(item, rand = 1) {
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
942
|
+
const version = 3
|
|
943
|
+
let attrs = ''
|
|
944
|
+
for (let i = 0; i < 8; i++) {
|
|
945
|
+
const attribute = item.attributes[i]
|
|
946
|
+
if (attribute && (attribute === null || attribute === void 0 ? void 0 : attribute.id)) {
|
|
947
|
+
attrs +=
|
|
948
|
+
'2' +
|
|
949
|
+
pad((attribute === null || attribute === void 0 ? void 0 : attribute.id) || 0, 3) +
|
|
950
|
+
pad((attribute === null || attribute === void 0 ? void 0 : attribute.value) || 0, 3)
|
|
951
|
+
} else {
|
|
952
|
+
attrs +=
|
|
953
|
+
'0' +
|
|
954
|
+
pad((attribute === null || attribute === void 0 ? void 0 : attribute.id) || 0, 3) +
|
|
955
|
+
pad((attribute === null || attribute === void 0 ? void 0 : attribute.value) || 0, 3)
|
|
899
956
|
}
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
957
|
+
}
|
|
958
|
+
attrs += '00000'
|
|
959
|
+
attrs += pad(rand, 3)
|
|
960
|
+
return `1${pad(version, 3)}${pad(item.id, 5)}${pad(item.type, 2)}${attrs}`
|
|
903
961
|
}
|
|
904
|
-
exports.getTokenIdFromItem = getTokenIdFromItem
|
|
905
|
-
//# sourceMappingURL=decoder.js.map
|
|
962
|
+
exports.getTokenIdFromItem = getTokenIdFromItem
|
|
963
|
+
//# sourceMappingURL=decoder.js.map
|