@juice789/tf2items 1.0.0

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.
@@ -0,0 +1,359 @@
1
+ const {
2
+ compose,
3
+ includes,
4
+ prop,
5
+ propOr,
6
+ find,
7
+ flip,
8
+ map,
9
+ when,
10
+ unary,
11
+ allPass,
12
+ propEq,
13
+ uncurryN,
14
+ chain,
15
+ __,
16
+ ifElse,
17
+ has,
18
+ always,
19
+ curry,
20
+ applyTo,
21
+ assoc,
22
+ pathOr,
23
+ invertObj,
24
+ mergeRight,
25
+ values,
26
+ replace,
27
+ trim,
28
+ reduce,
29
+ nth,
30
+ split,
31
+ propSatisfies,
32
+ pathEq,
33
+ complement,
34
+ either,
35
+ concat,
36
+ of,
37
+ path,
38
+ equals,
39
+ pick
40
+ } = require('ramda')
41
+
42
+ const { safeItems: items } = require('./schemaItems.js')
43
+ const { particleEffects, textures } = require('./schema.json')
44
+ const { qualityNames, wears } = require('./schemaHelper.json')
45
+ const { skuFromItem } = require('./sku.js')
46
+ const { renameKeys } = require('ramda-adjunct')
47
+
48
+ const marketHashIncludes = curry((string, { market_hash_name }) => market_hash_name.indexOf(string) !== -1)
49
+
50
+ const removeStrings = curry((string, strings) => compose(
51
+ trim,
52
+ replace(/\s\s+/g, ' '),
53
+ reduce((all, curr) => replace(curr, '', all), string || '')
54
+ )(strings))
55
+
56
+ const findTag = uncurryN(2, (tagName) => compose(
57
+ prop('name'),
58
+ find(propEq('category_name', tagName)),
59
+ map(renameKeys({
60
+ localized_category_name: 'category_name',
61
+ localized_tag_name: 'name'
62
+ })),
63
+ propOr([], 'tags')
64
+ ))
65
+
66
+ const old_id = ifElse(
67
+ has('new_assetid'),
68
+ prop('assetid'),
69
+ always(null)
70
+ )
71
+
72
+ const id = chain(
73
+ propOr(__, 'new_assetid'),
74
+ prop('assetid')
75
+ )
76
+
77
+ const recipe = compose(
78
+ find(__, ['Fabricator', 'Strangifier Chemistry Set', 'Chemistry Set']),
79
+ flip(marketHashIncludes),
80
+ )
81
+
82
+
83
+ const series = ifElse(
84
+ compose(equals('Crate'), findTag('Type')),
85
+ ifElse(
86
+ marketHashIncludes('#'),
87
+ compose(
88
+ nth(1),
89
+ split('#'),
90
+ prop('market_hash_name')
91
+ ),
92
+ compose(
93
+ nth(0),
94
+ propOr([], 'series'),
95
+ prop(__, items),
96
+ path(['app_data', 'def_index'])
97
+ )
98
+ ),
99
+ always(null)
100
+ )
101
+
102
+ const craft = ifElse(
103
+ allPass([
104
+ propSatisfies(includes('#'), 'name'),
105
+ propSatisfies(complement(includes)('#'), 'market_hash_name'),
106
+ ]),
107
+ compose(
108
+ nth(1),
109
+ split('#'),
110
+ prop('name')
111
+ ),
112
+ always(null)
113
+ )
114
+
115
+ const australium = allPass([
116
+ pathEq(['app_data', 'quality'], '11'),
117
+ marketHashIncludes('Australium')
118
+ ])
119
+
120
+ const wear = compose(
121
+ prop(__, invertObj(wears)),
122
+ removeStrings(__, ['(', ')']),
123
+ findTag('Exterior')
124
+ )
125
+
126
+ const texture = ifElse(
127
+ findTag('Exterior'),
128
+ compose(
129
+ propOr('-1', __, invertObj(textures)),
130
+ ({ app_data, market_hash_name }) => removeStrings(market_hash_name, [
131
+ 'Specialized Killstreak',
132
+ 'Professional Killstreak',
133
+ 'Killstreak',
134
+ '(Field-Tested)',
135
+ '(Well-Worn)',
136
+ '(Battle Scarred)',
137
+ '(Minimal Wear)',
138
+ '(Factory New)',
139
+ 'Festivized',
140
+ 'Strange',
141
+ qualityNames[app_data.quality],
142
+ items[app_data.def_index].item_name
143
+ ])
144
+ ),
145
+ always(null)
146
+ )
147
+
148
+ const festivized = marketHashIncludes('Festivized')
149
+
150
+ const killstreakTier = compose(
151
+ prop(__, { 'Professional Killstreak': '3', 'Specialized Killstreak': '2', 'Killstreak': '1' }),
152
+ find(__, ['Professional Killstreak', 'Specialized Killstreak', 'Killstreak']),
153
+ flip(marketHashIncludes)
154
+ )
155
+
156
+ const effect = ifElse(
157
+ allPass([
158
+ pathEq(['app_data', 'quality'], '5'),
159
+ compose(
160
+ find(propEq('color', 'ffd700')),
161
+ propOr([], 'descriptions')
162
+ )
163
+ ]),
164
+ compose(
165
+ propOr('-1', __, invertObj(particleEffects)),
166
+ replace('★ Unusual Effect: ', ''),
167
+ prop('value'),
168
+ find(propEq('color', 'ffd700')),
169
+ propOr([], 'descriptions')
170
+ ),
171
+ always(null)
172
+ )
173
+
174
+ const elevated = allPass([
175
+ complement(pathEq)(['app_data', 'quality'], '11'),
176
+ compose(
177
+ includes('Strange'),
178
+ ({ app_data, market_hash_name }) => replace(items[app_data.def_index].item_name, '', market_hash_name)
179
+ )
180
+ ])
181
+
182
+ const uncraftable = compose(
183
+ Boolean,
184
+ find(propEq('value', '( Not Usable in Crafting )')),
185
+ propOr([], 'descriptions')
186
+ )
187
+
188
+ const market_hash_name = prop('market_hash_name')
189
+
190
+ const quality = pathOr('-1', ['app_data', 'quality'])
191
+
192
+ const defindex = pathOr('-1', ['app_data', 'def_index'])
193
+
194
+ const propsTf2_1 = {
195
+ defindex,
196
+ quality,
197
+ market_hash_name,
198
+ uncraftable,
199
+ elevated,
200
+ effect,
201
+ killstreakTier,
202
+ festivized,
203
+ texture,
204
+ wear,
205
+ australium,
206
+ series,
207
+ craft,
208
+ recipe,
209
+ id,
210
+ old_id
211
+ }
212
+
213
+ const isTarget = either(
214
+ compose(
215
+ find(__, ['Strangifier', 'Fabricator', 'Strangifier Chemistry Set', 'Unusualifier']),
216
+ flip(marketHashIncludes),
217
+ ),
218
+ allPass([
219
+ marketHashIncludes('Kit'),
220
+ marketHashIncludes('Killstreak')
221
+ ])
222
+ )
223
+
224
+ const target = ifElse(
225
+ isTarget,
226
+ compose(
227
+ propOr('-1', 'defindex'),
228
+ find(__, values(items)),
229
+ allPass,
230
+ concat([propSatisfies(complement(includes)(__, [0, 15]), 'item_quality')]),
231
+ of,
232
+ propEq('item_name'),
233
+ ({ market_hash_name, defindex }) => removeStrings(market_hash_name, [
234
+ 'Strangifier',
235
+ 'Unusual',
236
+ 'Unusualifier',
237
+ items[defindex].item_name,
238
+ 'Specialized Killstreak',
239
+ 'Professional Killstreak',
240
+ 'Killstreak',
241
+ "Collector's",
242
+ 'Series',
243
+ 'Kit',
244
+ 'Fabricator',
245
+ 'Chemistry Set',
246
+ '#1',
247
+ '#2',
248
+ '#3'
249
+ ])
250
+ ),
251
+ always(null)
252
+ )
253
+
254
+ const output = ({ recipe, market_hash_name, killstreakTier }) => {
255
+ switch (recipe) {
256
+ case 'Fabricator':
257
+ const ktMap = {
258
+ '2': '6523',
259
+ '3': '6526'
260
+ }
261
+ return ktMap[killstreakTier]
262
+ case 'Strangifier Chemistry Set':
263
+ return '6522'
264
+ case 'Chemistry Set':
265
+ return compose(
266
+ propOr('-1', 'defindex'),
267
+ find(__, values(items)),
268
+ allPass,
269
+ concat([propSatisfies(complement(includes)(__, [0, 15]), 'item_quality')]),
270
+ of,
271
+ propEq('item_name'),
272
+ removeStrings(__, ['Chemistry Set', "Collector's"])
273
+ )(market_hash_name)
274
+ default:
275
+ return null
276
+ }
277
+ }
278
+
279
+ const oq = ({ market_hash_name, recipe }) => recipe
280
+ ? includes("Collector's", market_hash_name) ? '14' : '6'
281
+ : null
282
+
283
+ const propsTf2_2 = {
284
+ target,
285
+ output,
286
+ oq
287
+ }
288
+
289
+ const propsOtherGame = {
290
+ sku: market_hash_name,
291
+ id,
292
+ old_id
293
+ }
294
+
295
+ const keyRemap = when(
296
+ compose(
297
+ includes(__, ['5021', '5049', '5067', '5072', '5073', '5079', '5081', '5628', '5631', '5632', '5713', '5716', '5717', '5762', '5791', '5792']), //old keys that turned into regular keys
298
+ String,
299
+ prop('defindex')
300
+ ),
301
+ compose(
302
+ assoc('defindex', '5021'),
303
+ assoc('uncraftable', false)
304
+ )
305
+ )
306
+
307
+ const kitRemap = when(
308
+ compose(
309
+ includes('Killstreakifier Basic'),
310
+ propOr('', 'name'),
311
+ prop(__, items),
312
+ prop('defindex')
313
+ ),
314
+ assoc('defindex', '6527')
315
+ )
316
+
317
+ const otherIndex = {
318
+ 5844: '5710', //fall acorns key
319
+ 5845: '5720', //strongbox key
320
+ 5846: '5740', //stockpile key
321
+ 5847: '5827', //gargoyle key
322
+ 5738: '5737', //stockpile crate
323
+ }
324
+
325
+ const otherRemap = when(
326
+ compose(has(__, otherIndex), prop('defindex')),
327
+ chain(assoc('defindex'), compose(prop(__, otherIndex), prop('defindex')))
328
+ )
329
+
330
+ const remaps = compose(
331
+ kitRemap,
332
+ keyRemap,
333
+ otherRemap
334
+ )
335
+
336
+ const fromEconItem440 = compose(
337
+ pick(['sku', 'id', 'old_id']),
338
+ chain(assoc('sku'), skuFromItem),
339
+ remaps,
340
+ chain(mergeRight, compose(map(__, propsTf2_2), applyTo)),
341
+ map(__, propsTf2_1),
342
+ unary(applyTo)
343
+ )
344
+
345
+ const fromEconItemOther = compose(
346
+ map(__, propsOtherGame),
347
+ unary(applyTo)
348
+ )
349
+
350
+ const fromEconItem = ifElse(
351
+ propEq('appid', 440),
352
+ fromEconItem440,
353
+ fromEconItemOther
354
+ )
355
+
356
+ module.exports = {
357
+ fromEconItem,
358
+ kitRemap
359
+ }
@@ -0,0 +1,374 @@
1
+ const {
2
+ compose,
3
+ complement,
4
+ propEq,
5
+ hasPath,
6
+ F,
7
+ prop,
8
+ chain,
9
+ assoc,
10
+ map,
11
+ __,
12
+ applyTo,
13
+ cond,
14
+ identity,
15
+ T,
16
+ flatten,
17
+ toPairs,
18
+ pathOr,
19
+ pickBy,
20
+ indexBy,
21
+ propOr,
22
+ path,
23
+ find,
24
+ includes,
25
+ values,
26
+ nth,
27
+ has,
28
+ when,
29
+ allPass,
30
+ converge,
31
+ or,
32
+ take,
33
+ uncurryN
34
+ } = require('ramda')
35
+
36
+ const { safeItems: items } = require('./schemaItems.js')
37
+ const { textures } = require('./schema.json')
38
+ const { skuFromItem } = require('./sku.js')
39
+
40
+ const {
41
+ kitRemap
42
+ } = require('./fromEconItem.js')
43
+
44
+ const findValue = uncurryN(2, (fns) => compose(
45
+ find(Boolean),
46
+ map(__, fns),
47
+ applyTo
48
+ ))
49
+
50
+ const isWeaponEffect = compose(includes(__, ['701', '702', '703', '704']), String)
51
+
52
+ const defindex = prop('defindex')
53
+
54
+ const quality = prop('quality')
55
+
56
+ const uncraftable = compose(Boolean, prop('flag_cannot_craft'))
57
+
58
+ const effectOptions = [
59
+ path(['attributes', '134', 'float_value']),
60
+ path(['attributes', '2041', 'value']),
61
+ ]
62
+
63
+ const effect = findValue(effectOptions)
64
+
65
+ const elevated = cond(
66
+ [
67
+ [complement(propEq)('quality', 11), hasPath(['attributes', '214'])],
68
+ [propEq('quality', 11), compose(isWeaponEffect, effect)],
69
+ [T, F]
70
+ ]
71
+ )
72
+
73
+ const ktRemap = {
74
+ '6527': '1',
75
+ '6523': '2',
76
+ '6526': '3',
77
+ '20002': '2',
78
+ '20003': '3'
79
+ }
80
+
81
+ const ktOptions = [
82
+ path(['attributes', '2025', 'float_value']),
83
+ compose(prop(__, ktRemap), prop('defindex'))
84
+ ]
85
+
86
+ const killstreakTier = findValue(ktOptions)
87
+
88
+ const festivized = hasPath(['attributes', '2053'])
89
+
90
+ const texture = path(['attributes', '834', 'value'])
91
+
92
+ const wears = {
93
+ '0': null,
94
+ '0.2': '1',
95
+ '0.4': '2',
96
+ '0.6': '3',
97
+ '0.8': '4',
98
+ '1': '5'
99
+ }
100
+
101
+ const wear = compose(
102
+ prop(__, wears),
103
+ take(3),
104
+ String,
105
+ pathOr('0', ['attributes', '725', 'float_value'])
106
+ )
107
+
108
+ const australium = hasPath(['attributes', '2027'])
109
+
110
+ const series = path(['attributes', '187', 'float_value'])
111
+
112
+ const findOutput = compose(
113
+ find(compose(includes(__, [true, 'true']), prop('is_output'))),
114
+ values,
115
+ propOr({}, 'attributes')
116
+ )
117
+
118
+ const findRecipeTarget = compose(
119
+ prop('float_value'),
120
+ find(compose(includes(__, ['2012', 2012]), prop('defindex'))),
121
+ propOr([], 'attributes'),
122
+ findOutput
123
+ )
124
+
125
+ const targetOptions = [
126
+ path(['attributes', '2012', 'float_value']),
127
+ findRecipeTarget
128
+ ]
129
+
130
+ const target = findValue(targetOptions)
131
+
132
+ const output = compose(
133
+ prop('itemdef'),
134
+ findOutput
135
+ )
136
+
137
+ const oq = compose(
138
+ prop('quality'),
139
+ findOutput
140
+ )
141
+
142
+ const fns = {
143
+ defindex,
144
+ quality,
145
+ uncraftable,
146
+ elevated,
147
+ effect,
148
+ killstreakTier,
149
+ festivized,
150
+ texture,
151
+ wear,
152
+ australium,
153
+ series,
154
+ target,
155
+ output,
156
+ oq
157
+ }
158
+
159
+ const remap = (fn1, fn2) => when(
160
+ fn1,
161
+ chain(
162
+ assoc('defindex'),
163
+ converge(
164
+ or,
165
+ [
166
+ fn2,
167
+ prop('defindex')
168
+ ]
169
+ )
170
+ )
171
+ )
172
+
173
+ const remapStrangifier = remap(
174
+ compose(
175
+ propEq('item_name', 'Strangifier'),
176
+ prop(__, items),
177
+ prop('defindex')
178
+ ),
179
+ compose(
180
+ prop('defindex'),
181
+ nth(0),
182
+ values,
183
+ (listingTarget) => pickBy(
184
+ compose(
185
+ includes(listingTarget.toString()),
186
+ propOr([], 'target')
187
+ ),
188
+ items
189
+ ),
190
+ prop('target')
191
+ )
192
+ )
193
+
194
+ const strangifierSets = pickBy(allPass([
195
+ has('td'),
196
+ propEq('item_name', 'Chemistry Set')
197
+ ]), items)
198
+
199
+ const remapStrangifierSet = remap(
200
+ allPass([
201
+ propEq('defindex', 20001),
202
+ prop('output'),
203
+ prop('target')
204
+ ]),
205
+ compose(
206
+ prop('defindex'),
207
+ nth(0),
208
+ values,
209
+ (listingTarget) => pickBy(
210
+ compose(
211
+ includes(listingTarget.toString()),
212
+ prop('td')
213
+ ),
214
+ strangifierSets
215
+ ),
216
+ prop('target'),
217
+ )
218
+ )
219
+
220
+ const collectorSets = pickBy(allPass([
221
+ complement(prop)('td'),
222
+ prop('od'),
223
+ propEq('item_name', 'Chemistry Set'),
224
+ ]), items)
225
+
226
+ const remapCollectorSet = remap(
227
+ allPass([
228
+ propEq('defindex', 20001),
229
+ complement(prop)('target')
230
+ ]),
231
+ compose(
232
+ prop('defindex'),
233
+ nth(0),
234
+ values,
235
+ (listingOutput) => pickBy(
236
+ compose(
237
+ includes(listingOutput.toString()),
238
+ prop('od')
239
+ ),
240
+ collectorSets
241
+ ),
242
+ prop('output')
243
+ )
244
+ )
245
+
246
+
247
+ const weaponIndex = {
248
+ "0": 190,
249
+ "1": 191,
250
+ "13": 200,
251
+ "14": 201,
252
+ "15": 202,
253
+ "16": 203,
254
+ "17": 204,
255
+ "18": 205,
256
+ "19": 206,
257
+ "2": 192,
258
+ "20": 207,
259
+ "21": 208,
260
+ "22": 209,
261
+ "23": 209,
262
+ "24": 210,
263
+ "25": 737,
264
+ "29": 211,
265
+ "3": 193,
266
+ "30": 212,
267
+ "4": 194,
268
+ "5": 195,
269
+ "6": 196,
270
+ "7": 197,
271
+ "735": 736,
272
+ "8": 198,
273
+ "9": 199,
274
+ "10": 199,
275
+ "11": 199,
276
+ "12": 199
277
+ }
278
+
279
+ const remapWeapon = when(
280
+ compose(has(__, weaponIndex), prop('defindex')),
281
+ chain(assoc('defindex'), compose(prop(__, weaponIndex), prop('defindex')))
282
+ )
283
+
284
+ const decodeSkinQuality = cond([
285
+ [allPass([propEq('quality', 15), compose(isWeaponEffect, prop('effect'))]), assoc('quality', 5)], //decorated + effect = unusual
286
+ [allPass([propEq('quality', 11), compose(isWeaponEffect, prop('effect'))]), assoc('quality', 5)], //strange + effect = unusual
287
+ [allPass([propEq('quality', 15), complement(prop)('effect'), prop('elevated')]), assoc('quality', 11)], //decorated + elevated = strange
288
+ [T, identity]
289
+ ])
290
+
291
+ const unboxedSkins = map(
292
+ (item) => assoc('item_name', textures[item.texture] + ' ' + item.item_name, item),
293
+ pickBy(propEq('item_quality', 15), items)
294
+ )
295
+
296
+ const unboxSkinsRemap = remap(
297
+ prop('texture'),
298
+ compose(
299
+ nth(0),
300
+ flatten,
301
+ toPairs,
302
+ ({ defindex, texture }) => pickBy(
303
+ propEq('item_name', textures[texture] + ' ' + items[defindex].item_name),
304
+ unboxedSkins
305
+ )
306
+ )
307
+ )
308
+
309
+ const remapCrateSeries = remap(
310
+ prop('series'),
311
+ compose(
312
+ prop('defindex'),
313
+ find(
314
+ __,
315
+ values(items)
316
+ ),
317
+ (s) => compose(
318
+ includes(s),
319
+ propOr([], 'series')
320
+ ),
321
+ String,
322
+ prop('series')
323
+ )
324
+ )
325
+
326
+ const promoIndex = {
327
+ "30720": "30740",
328
+ "30721": "30741",
329
+ "30724": "30739",
330
+ "810": "831",
331
+ "811": "832",
332
+ "812": "833",
333
+ "813": "834",
334
+ "814": "835",
335
+ "815": "836",
336
+ "816": "837",
337
+ "817": "838"
338
+ }
339
+
340
+ const promoRemap = when(
341
+ allPass([
342
+ compose(has(__, promoIndex), prop('defindex')),
343
+ propEq('quality', 1)
344
+ ]),
345
+ chain(assoc('defindex'), compose(prop(__, promoIndex), prop('defindex')))
346
+ )
347
+
348
+ const remaps = compose(
349
+ remapCrateSeries,
350
+ unboxSkinsRemap,
351
+ kitRemap,
352
+ promoRemap,
353
+ decodeSkinQuality,
354
+ remapWeapon,
355
+ remapCollectorSet,
356
+ remapStrangifierSet,
357
+ remapStrangifier
358
+ )
359
+
360
+ const fromListingV1 = compose(
361
+ skuFromItem,
362
+ remaps,
363
+ map(__, fns),
364
+ applyTo,
365
+ chain(
366
+ assoc('attributes'),
367
+ compose(
368
+ indexBy(prop('defindex')),
369
+ propOr([], 'attributes')
370
+ )
371
+ )
372
+ )
373
+
374
+ module.exports = { fromListingV1, remaps }