@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.
@@ -1,905 +1,963 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getTokenIdFromItem = exports.normalizeItem = exports.getItemFromTokenId = exports.decodeItem = exports.setTokenCache = exports.getTokenCache = exports.clearDatabase = void 0;
7
- const lokijs_1 = __importDefault(require("lokijs"));
8
- const incremental_indexeddb_adapter_1 = __importDefault(require("lokijs/src/incremental-indexeddb-adapter"));
9
- const items_1 = require("../data/items");
10
- const items_type_1 = require("../data/items.type");
11
- const probabilityCache_1 = __importDefault(require("../data/probabilityCache"));
12
- const math_1 = require("./math");
13
- const useLocalStorage = false;
14
- const useIndexedDb = false;
15
- const useLoki = true;
16
- let tokenCache = {};
17
- const dbCon = new lokijs_1.default('rune.db', {
18
- adapter: typeof window !== 'undefined'
19
- ? new incremental_indexeddb_adapter_1.default()
20
- : new (require('lokijs/src/loki-fs-structured-adapter'))(),
21
- autoload: true,
22
- autoloadCallback: databaseInitialize,
23
- autosave: true,
24
- autosaveInterval: 4000,
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
- config: undefined,
28
- items: undefined,
29
- };
37
+ config: undefined,
38
+ items: undefined,
39
+ }
30
40
  function databaseInitialize() {
31
- var _a, _b, _c, _d;
32
- db.config = dbCon.getCollection('config');
33
- db.items = dbCon.getCollection('items');
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
- dbCon.getCollection('items').chain().remove();
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
- if (dbCon.getCollection('config')) {
67
- dbCon.getCollection('config').chain().remove();
68
- }
69
- if (dbCon.getCollection('items')) {
70
- dbCon.getCollection('items').chain().remove();
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
- // if (useLoki) {
76
- // var db = new loki('rune.db')
77
- // // Add a collection to the database
78
- // var items = db.addCollection('items')
79
- // }
80
- // if (useIndexedDb) {
81
- // // This works on all devices/browsers, and uses IndexedDBShim as a final fallback
82
- // // @ts-ignore
83
- // var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB || window.shimIndexedDB;
84
- // // Open (or create) the database
85
- // var open = indexedDB.open("RuneItems", 1);
86
- // // Create the schema
87
- // open.onupgradeneeded = function() {
88
- // var db = open.result;
89
- // var store = db.createObjectStore("TokenData", {keyPath: "tokenId"});
90
- // // var index = store.createIndex("NameIndex", ["name.last", "name.first"]);
91
- // };
92
- // open.onsuccess = function() {
93
- // // Start a new transaction
94
- // var db = open.result;
95
- // var tx = db.transaction("TokenData", "readwrite");
96
- // var store = tx.objectStore("TokenData");
97
- // var index = store.index("NameIndex");
98
- // // Query the data
99
- // var getJohn = store.get(12345);
100
- // // var getBob = index.get(["Smith", "Bob"]);
101
- // getJohn.onsuccess = function() {
102
- // console.log(getJohn.result.name.first); // => "John"
103
- // };
104
- // // Close the db when the transaction is done
105
- // tx.oncomplete = function() {
106
- // db.close();
107
- // };
108
- // }
109
- // }
110
- return tokenCache;
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
- tokenCache = tokenCache;
115
- // if (useLoki) {
116
- // const db = new loki('rune.db')
117
- // // Add a collection to the database
118
- // const items = db.addCollection('items')
119
- // }
120
- // if (useIndexedDb) {
121
- // // This works on all devices/browsers, and uses IndexedDBShim as a final fallback
122
- // // @ts-ignore
123
- // var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB || window.shimIndexedDB;
124
- // // Open (or create) the database
125
- // var open = indexedDB.open("RuneItems", 1);
126
- // // Create the schema
127
- // open.onupgradeneeded = function() {
128
- // var db = open.result;
129
- // var store = db.createObjectStore("TokenData", {keyPath: "tokenId"});
130
- // // var index = store.createIndex("NameIndex", ["name.last", "name.first"]);
131
- // };
132
- // open.onsuccess = function() {
133
- // // Start a new transaction
134
- // var db = open.result;
135
- // var tx = db.transaction("TokenData", "readwrite");
136
- // var store = tx.objectStore("TokenData");
137
- // var index = store.index("NameIndex");
138
- // // Add some data
139
- // for (const item of _tokenCache) {
140
- // store.put(item);
141
- // }
142
- // // Close the db when the transaction is done
143
- // tx.oncomplete = function() {
144
- // db.close();
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
- var _a;
152
- try {
153
- // console.log(9999, tokenCache[tokenId])
154
- if (tokenCache[tokenId])
155
- return tokenCache[tokenId];
156
- if (useLoki) {
157
- const result = (_a = db.items) === null || _a === void 0 ? void 0 : _a.findOne({ tokenId: tokenId });
158
- if (result) {
159
- // console.log('Token found in cache', result)
160
- return result;
161
- }
162
- else {
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
- catch (e) {
182
- console.log(e, tokenId);
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
- var _a, _b, _c, _d;
187
- try {
188
- tokenCache[item.tokenId] = item;
189
- if (useLoki) {
190
- // Find and update an existing document
191
- const result = (_a = db.items) === null || _a === void 0 ? void 0 : _a.findOne({ tokenId: item.tokenId });
192
- if (result) {
193
- for (const key of Object.keys(item)) {
194
- result[key] = item[key];
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
- if (useLocalStorage && window.localStorage) {
211
- const ttl = 3 * 24 * 60 * 60 * 1000;
212
- localStorage.setItem(`zzz_tokenCache_${item.tokenId}`, JSON.stringify({
213
- expiry: new Date().getTime() + ttl,
214
- value: item,
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
- catch (e) {
219
- console.log(e, item);
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
- const tokenCacheItem = getItemTokenCache(tokenId);
224
- if (tokenId && tokenCacheItem)
225
- return tokenCacheItem;
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
- const tokenCacheItem = getItemTokenCache(tokenId);
231
- if (tokenId && tokenCacheItem)
232
- return tokenCacheItem;
233
- const defaultItem = {
234
- tokenId,
235
- details: {},
236
- branches: {},
237
- shorthand: [],
238
- mods: [],
239
- attributes: [],
240
- perfection: null,
241
- category: items_type_1.ItemsMainCategoriesType.WEAPONS,
242
- slots: [],
243
- meta: {
244
- harvestYield: 0,
245
- harvestFeeToken: '',
246
- harvestFeePercent: 0,
247
- harvestFees: {},
248
- chanceToSendHarvestToHiddenPool: 0,
249
- chanceToLoseHarvest: 0,
250
- harvestBurn: 0,
251
- attributes: {},
252
- },
253
- };
254
- if (!tokenId || parseInt(tokenId) === 0 || Number.isNaN(parseInt(tokenId)))
255
- return defaultItem;
256
- try {
257
- const version = parseInt(tokenId.slice(1, 4));
258
- const id = parseInt(tokenId.slice(4, 9));
259
- let type = 0;
260
- let modStart = 9;
261
- if (version === 1) {
262
- modStart = 9;
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
- catch (e) {
302
- // console.log('Token is invalid', tokenId)
303
- console.log(e);
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
- return defaultItem;
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
- var _a, _b, _c, _d;
310
- try {
311
- const tokenCacheItem = getItemTokenCache(item.tokenId);
312
- if (item.tokenId && tokenCacheItem)
313
- return tokenCacheItem;
314
- const branch = item.branches[1];
315
- const branchAttributes = branch ? JSON.parse(JSON.stringify(branch.attributes)) : [];
316
- if (!item.meta)
317
- item.meta = {};
318
- item.meta = Object.assign({ harvestYield: 0, pending: 0, bonus: 0, harvestBurn: 0, chanceToSendHarvestToHiddenPool: 0, chanceToLoseHarvest: 0, guildId: null, characterId: null, itemIndex: 0, itemLength: 0, modIndex: 0, modLength: 0, rand: 0, removeFees: 0, freezeFees: 0, magicFind: 0, unableUseRuneword: null, currentRewardToken: null, hasEarlyUnstakeLocked: null, hasEarlyUnstakeNoReward: null, hiddenPoolPid: null, swapToken: null, swapAmount: null, feeToken: null, feeAmount: null, feeReduction: 0, unstakeLocked: false, classRequired: 0, harvestFeeToken: '', harvestFeePercent: 0, worldstoneShardChance: 0, randomRuneExchange: 0, harvestFees: {}, attributes: {} }, item.meta);
319
- item.attributes = branchAttributes;
320
- let prevMod = null;
321
- if (item.id === 1) {
322
- if (item.mods) {
323
- item.mods[0].attributeId = items_1.ItemAttributesByName[items_1.Games.Raid.id].HarvestYield.id;
324
- item.mods[1].attributeId = items_1.ItemAttributesByName[items_1.Games.Raid.id].HarvestFee.id;
325
- item.mods[2].attributeId = items_1.ItemAttributesByName[items_1.Games.Raid.id].HarvestFeeToken.id;
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
- else if (item.id === 2) {
329
- if (item.mods) {
330
- item.mods[0].attributeId = items_1.ItemAttributesByName[items_1.Games.Raid.id].HarvestYield.id;
331
- item.mods[1].attributeId = items_1.ItemAttributesByName[items_1.Games.Raid.id].SendHarvestHiddenPool.id;
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
- else if (item.id === 3) {
336
- if (item.mods) {
337
- item.mods[0].attributeId = items_1.ItemAttributesByName[items_1.Games.Raid.id].HarvestYield.id;
338
- item.mods[1].attributeId = items_1.ItemAttributesByName[items_1.Games.Raid.id].HarvestBurn.id;
339
- item.mods[2].attributeId = items_1.ItemAttributesByName[items_1.Games.Raid.id].FindShard.id;
340
- delete item.mods[3];
341
- delete item.mods[4];
342
- delete item.mods[5];
343
- delete item.mods[6];
344
- item.mods[2].value = 100;
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
- else if (item.id === 4) {
348
- if (item.mods) {
349
- item.mods[0].attributeId = items_1.ItemAttributesByName[items_1.Games.Raid.id].FindShard.id;
350
- item.mods[0].value = 100;
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.mods) {
354
- for (const i in item.mods) {
355
- const mod = item.mods[i];
356
- const branchAttribute = branchAttributes[i];
357
- if (!branchAttribute) {
358
- // console.log(`Branch attribute doesn't exist on item definition`, item, mod)
359
- continue;
360
- }
361
- if (branchAttribute.value === undefined) {
362
- if (branchAttribute.min === branchAttribute.max) {
363
- branchAttribute.value = branchAttribute.min;
364
- }
365
- }
366
- if (mod.attributeId === items_1.ItemAttributesByName[items_1.Games.Raid.id].HarvestYield.id) {
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
- // if (item.tokenId === "100300016012001003200700120130022011003200201020030142039011202100700000115") debugger;
426
- if (Object.keys(item.meta.harvestFees).length > 0) {
427
- item.meta.harvestFeeToken = Object.keys(item.meta.harvestFees)[0];
428
- item.meta.harvestFeePercent = item.meta.harvestFees[Object.keys(item.meta.harvestFees)[0]];
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
- if (branch === null || branch === void 0 ? void 0 : branch.perfection) {
431
- const perfection = [...branch.perfection];
432
- const attributes = branch.attributes;
433
- // if (item.tokenId === '1001000041000100015647') {
434
- // console.log(perfection)
435
- // console.log(item.attributes)
436
- // console.log(branch.attributes)
437
- // }
438
- if (perfection.length) {
439
- const shorthand = [];
440
- for (let i = 0; i < perfection.length; i++) {
441
- if (perfection[i] === undefined || perfection[i] === null || !attributes[i]) {
442
- perfection[i] = undefined;
443
- continue;
444
- }
445
- perfection[i] =
446
- perfection[i] === attributes[i].max
447
- ? perfection[i] - attributes[i].min === 0
448
- ? 1
449
- : (attributes[i].value - attributes[i].min) / (perfection[i] - attributes[i].min)
450
- : attributes[i].max - perfection[i] === 0
451
- ? 1
452
- : 1 - (attributes[i].value - perfection[i]) / (attributes[i].max - perfection[i]);
453
- }
454
- item.perfection = (0, math_1.average)(perfection.filter((p) => Number.isFinite(p)));
455
- // if (item.tokenId === '1001000041000100015647') {
456
- // console.log(perfection, branch.attributes[0].max, perfection[0], 1)
457
- // }
458
- if (Number.isFinite(item.perfection) && item.perfection <= 1) {
459
- item.perfection = parseFloat((Math.floor(item.perfection * 100) / 100).toFixed(2));
460
- if (item.perfection < 0) {
461
- item.perfection = 0;
462
- }
463
- const size = 20000;
464
- if (!probabilityCache_1.default[item.id]) {
465
- probabilityCache_1.default[item.id] = {};
466
- [...Array(101).keys()].map(function (n) {
467
- probabilityCache_1.default[item.id][n] = 0;
468
- });
469
- [...Array(size).keys()].map(function () {
470
- const rando = Math.floor((branch.perfection.reduce(function (prev, cur, i) {
471
- return (prev +
472
- (cur === null || cur === undefined
473
- ? 0
474
- : cur === attributes[i].max
475
- ? ((0, math_1.randInt)(attributes[i].min, attributes[i].max) - attributes[i].min) /
476
- (attributes[i].max - attributes[i].min)
477
- : 1 -
478
- ((0, math_1.randInt)(attributes[i].min, attributes[i].max) - attributes[i].min) /
479
- (attributes[i].max - attributes[i].min)));
480
- }, 0) /
481
- branch.perfection.filter((p) => p !== undefined && p !== null).length) *
482
- // Fury: ((randInt(3, 7)-3)/(7-3)+(randInt(20, 40)-20)/(40-20)+(1-(randInt(20, 40)-20)/(40-20)))/3
483
- 100).toFixed(0);
484
- probabilityCache_1.default[item.id][rando]++;
485
- });
486
- }
487
- // @ts-ignore
488
- const total = [...Array(101).keys()].reduce((prev, cur) => prev + probabilityCache_1.default[item.id][cur], 0);
489
- const mythic = probabilityCache_1.default[item.id][100] / total;
490
- const epic =
491
- // @ts-ignore
492
- [...Array(99 - 90).keys()].reduce((prev, cur) => prev + probabilityCache_1.default[item.id][cur + 90], 0) / total;
493
- const rare =
494
- // @ts-ignore
495
- [...Array(89 - 70).keys()].reduce((prev, cur) => prev + probabilityCache_1.default[item.id][cur + 70], 0) / total;
496
- const magical =
497
- // @ts-ignore
498
- [...Array(70 - 0).keys()].reduce((prev, cur) => prev + probabilityCache_1.default[item.id][cur + 0], 0) / total;
499
- const roll = item.perfection * 100 > 3
500
- ? (0, math_1.average)(
501
- // @ts-ignore
502
- [...Array(6).keys()].reduce((prev, cur) =>
503
- // @ts-ignore
504
- probabilityCache_1.default[item.id][parseInt(cur + item.perfection * 100 - 3)] === 0
505
- ? prev
506
- : // @ts-ignore
507
- [...prev, probabilityCache_1.default[item.id][parseInt(cur + item.perfection * 100 - 3)]], [])) / total
508
- : probabilityCache_1.default[item.id][item.perfection * 100] / total;
509
- item.meta.probability = {
510
- mythic,
511
- epic,
512
- rare,
513
- magical,
514
- roll,
515
- };
516
- }
517
- else {
518
- item.perfection = null;
519
- }
520
- }
521
- else {
522
- item.perfection = null;
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
- // if (!item.meta) {
526
- // item.meta = {
527
- // harvestYield: 0,
528
- // harvestFeeToken: '',
529
- // harvestFeePercent: 0,
530
- // harvestFees: {},
531
- // chanceToSendHarvestToHiddenPool: 0,
532
- // chanceToLoseHarvest: 0,
533
- // harvestBurn: 0,
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
- // if (item.rarity && item.branches[1]?.presets) {
537
- // for (const attributeIndex in item.attributes) {
538
- // item.attributes[attributeIndex].value = item.branches[1].presets[item.rarity.id][attributeIndex]
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
- // Normalize rarity based on perfection
542
- if (!item.rarity) {
543
- if ((_a = item.attributes.find((a) => a.id === 40)) === null || _a === void 0 ? void 0 : _a.value) {
544
- item.rarity = items_1.ItemRarity[items_1.ItemRarityNameById[((_b = item.attributes.find((a) => a.id === 40)) === null || _b === void 0 ? void 0 : _b.value) || 5]];
545
- }
546
- else if (item.perfection === 1) {
547
- item.rarity = items_1.ItemRarity.Mythic;
548
- }
549
- else if (item.perfection >= 0.9) {
550
- item.rarity = items_1.ItemRarity.Epic;
551
- }
552
- else if (item.perfection >= 0.7) {
553
- item.rarity = items_1.ItemRarity.Rare;
554
- }
555
- else if (item.perfection >= 0) {
556
- item.rarity = items_1.ItemRarity.Magical;
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
- // Normalize perfection basd on rarity
560
- if (item.rarity && item.perfection === null) {
561
- if (item.rarity.id === items_1.ItemRarity.Mythic) {
562
- item.perfection = 1;
563
- }
564
- else if (item.rarity.id === items_1.ItemRarity.Epic) {
565
- item.perfection = 0.9;
566
- }
567
- else if (item.rarity.id === items_1.ItemRarity.Rare) {
568
- item.perfection = 0.7;
569
- }
570
- else if (item.rarity.id === items_1.ItemRarity.Magical) {
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
- if (item.branches) {
578
- // Set .value if .min and .max are same
579
- for (const bIndex of Object.keys(item.branches)) {
580
- const branchIndex = Number(bIndex);
581
- for (const attributeIndex in item.branches[branchIndex].attributes) {
582
- if (item.branches[branchIndex].attributes[attributeIndex].value === undefined) {
583
- if (item.branches[branchIndex].attributes[attributeIndex].min ===
584
- item.branches[branchIndex].attributes[attributeIndex].max) {
585
- item.branches[branchIndex].attributes[attributeIndex].value =
586
- item.branches[branchIndex].attributes[attributeIndex].min;
587
- if (branchIndex === 1) {
588
- item.attributes[attributeIndex].value = item.branches[branchIndex].attributes[attributeIndex].value;
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
- // Normalize main branch map attribute values
672
- if (branch === null || branch === void 0 ? void 0 : branch.perfection) {
673
- for (const attributeIndex in branch.attributes) {
674
- const attribute = branch.attributes[attributeIndex];
675
- const perfection = branch.perfection[attributeIndex];
676
- if (perfection === undefined || perfection == null) {
677
- if (attribute.value === undefined && attribute.map) {
678
- attribute.value = attribute.min;
679
- item.attributes[attributeIndex] = attribute;
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
- // Normalize branch values and perfection
686
- for (const bIndex of Object.keys(item.branches)) {
687
- const branchIndex = Number(bIndex);
688
- if (branchIndex === 1) {
689
- for (const attributeIndex in item.branches[branchIndex].attributes) {
690
- const attribute = item.branches[branchIndex].attributes[attributeIndex];
691
- if (attribute.param1.value !== undefined) {
692
- if (!item.meta.attributes[attribute.id])
693
- item.meta.attributes[attribute.id] = 0;
694
- item.meta.attributes[attribute.id] += attribute.param1.value;
695
- }
696
- }
697
- continue;
698
- }
699
- if (!item.branches[branchIndex].attributes)
700
- continue;
701
- for (const attributeIndex in item.branches[branchIndex].attributes) {
702
- if (!item.branches[1] ||
703
- !item.branches[1].perfection ||
704
- !item.branches[1].attributes ||
705
- !item.branches[branchIndex] ||
706
- !item.branches[branchIndex].attributes[attributeIndex]) {
707
- break;
708
- }
709
- const attribute = item.branches[branchIndex].attributes[attributeIndex];
710
- if (!attribute.param1) {
711
- continue;
712
- }
713
- if (Number.isFinite(attribute.param1.value)) {
714
- if (!item.meta.attributes[attribute.id])
715
- item.meta.attributes[attribute.id] = 0;
716
- item.meta.attributes[attribute.id] += attribute.param1.value;
717
- continue;
718
- }
719
- // let targetAttribute = item.branches[branchIndex].attributes[attributeIndex]
720
- let targetPerfection;
721
- // let attributePerfection
722
- if (Number.isFinite(item.branches[1].perfection[attributeIndex])) {
723
- targetPerfection =
724
- item.branches[1].perfection[attributeIndex] === item.branches[1].attributes[attributeIndex].param1.max
725
- ? (item.branches[1].attributes[attributeIndex].param1.value -
726
- item.branches[1].attributes[attributeIndex].param1.min) /
727
- (item.branches[1].attributes[attributeIndex].param1.max -
728
- item.branches[1].attributes[attributeIndex].param1.min)
729
- : 1 -
730
- (item.branches[1].attributes[attributeIndex].param1.value -
731
- item.branches[1].attributes[attributeIndex].param1.min) /
732
- (item.branches[1].attributes[attributeIndex].param1.max -
733
- item.branches[1].attributes[attributeIndex].param1.min);
734
- }
735
- else {
736
- // targetAttribute = item.branches[branchIndex].attributes[attributeIndex]
737
- targetPerfection = item.perfection; // item.branches[branchIndex].perfection[attributeIndex]
738
- }
739
- // if (targetPerfection && targetAttribute) {
740
- // attributePerfection =
741
- // targetPerfection === targetAttribute.param1.max
742
- // ? targetPerfection - targetAttribute.param1.min === 0
743
- // ? 1
744
- // : (targetAttribute.param1.value - targetAttribute.param1.min) /
745
- // (targetPerfection - targetAttribute.param1.min)
746
- // : targetAttribute.param1.max - targetPerfection === 0
747
- // ? 1
748
- // : 1 -
749
- // (targetAttribute.param1.value - targetPerfection) /
750
- // (targetAttribute.param1.max - targetPerfection)
751
- // } else {
752
- // attributePerfection = targetPerfection
753
- // }
754
- if (attribute.param1.map) {
755
- const kindofClose = Math.floor((attribute.param1.max - attribute.param1.min) * targetPerfection);
756
- const closestKey = Object.keys(attribute.param1.map).sort((a, b) => {
757
- return Math.abs(kindofClose - Number(a)) - Math.abs(kindofClose - Number(b));
758
- })[0];
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
- // Normalize shorthand
781
- if (branch === null || branch === void 0 ? void 0 : branch.perfection) {
782
- const perfection = [...branch.perfection];
783
- const attributes = branch.attributes;
784
- if (perfection.length) {
785
- const shorthand = [];
786
- // let odds = 1
787
- for (let i = 0; i < perfection.length; i++) {
788
- if (perfection[i] === undefined || perfection[i] === null || !attributes[i]) {
789
- continue;
790
- }
791
- const value = attributes[i].map ? attributes[i].map[attributes[i].value] : attributes[i].value;
792
- shorthand.push(value);
793
- // odds *= (value - attributes[i].min + 1)
794
- }
795
- // if (odds > 1) {
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
- // Normalize odds
802
- // if (item.meta && item.branches?.[1]) {
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
- // Normalize perfection
818
- if (item.perfection === undefined || item.perfection === null) {
819
- item.perfection = 1;
820
- }
821
- if (!item.tokenId) {
822
- item.tokenId = getTokenIdFromItem(item);
823
- }
824
- if (item.branches[2]) {
825
- item.branches[2].initialCharge =
826
- item.branches[2].initialCharge !== undefined ? item.branches[2].initialCharge : item.initialCharge;
827
- item.branches[2].maxCharge =
828
- item.branches[2].maxCharge !== undefined ? item.branches[2].maxCharge : item.maxCharge;
829
- const chargeMultiplier = {
830
- [items_1.ItemRarity.Magical.id]: 4,
831
- [items_1.ItemRarity.Rare.id]: 3,
832
- [items_1.ItemRarity.Epic.id]: 2,
833
- [items_1.ItemRarity.Mythic.id]: 1,
834
- };
835
- item.branches[2].initialCharge *= chargeMultiplier[item.rarity.id];
836
- item.branches[2].maxCharge *= chargeMultiplier[item.rarity.id];
837
- }
838
- item.slug = (_d = item.name) === null || _d === void 0 ? void 0 : _d.replace(/ /gi, '-').replace(/"/gi, '').toLowerCase();
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
- catch (e) {
877
- // console.log('Token is invalid', tokenId)
878
- console.log(e);
874
+ if (!item.tokenId) {
875
+ item.tokenId = getTokenIdFromItem(item)
879
876
  }
880
- setItemTokenCache(item);
881
- return item;
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
- const nn = n + '';
886
- return nn.length >= width ? nn : new Array(width - nn.length + 1).join(z) + nn;
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
- const version = 3;
890
- let attrs = '';
891
- for (let i = 0; i < 8; i++) {
892
- const attribute = item.attributes[i];
893
- if (attribute && (attribute === null || attribute === void 0 ? void 0 : attribute.id)) {
894
- attrs += '2' + pad((attribute === null || attribute === void 0 ? void 0 : attribute.id) || 0, 3) + pad((attribute === null || attribute === void 0 ? void 0 : attribute.value) || 0, 3);
895
- }
896
- else {
897
- attrs += '0' + pad((attribute === null || attribute === void 0 ? void 0 : attribute.id) || 0, 3) + pad((attribute === null || attribute === void 0 ? void 0 : attribute.value) || 0, 3);
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
- attrs += '00000';
901
- attrs += pad(rand, 3);
902
- return `1${pad(version, 3)}${pad(item.id, 5)}${pad(item.type, 2)}${attrs}`;
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