Transaction

b1fae14b7f53620c8d2354e3e9ba50164b0b4916eead575a1add7026a8373dfa
( - )
177,230
2021-06-25 12:25:23
1
10,361 B

3 Outputs

Total Output:
  • jrun cryptofightsMu'{"in":0,"ref":["9125fb2bf949e8f7c6f32401c9fbe1ed724528afdb9fe93a556edc28f6c3a911_o1","5b259cd9534b3c87b7c205b7f7f62e490535f3b9aec97ae59d6289355b99df15_o1","9f0e192f744258c3484a1c19fa88ef68e46ee6cf75acc78cfe2ad5a0d2340d0e_o1","9f02902bf6bb459c633fc1266f4387938456e881d031cfc585b7c6b5ed0cae84_o1","aa2ebcab82c10e20f2f8cb0751fc5e1692252ce71fe3ba62c75a984da7d8e1f9_o1","870c20f2e1b5f421a3083f749776c059e5bf227d6b2d555f11ffda2306389c56_o1","f97d4ac2a3d6f5ed09fad4a4f341619dc5a3773d9844ff95c99c5d4f8388de2f_o1"],"out":["2f02a9044d3ecd28372e623d6dd314a99b44b25cb8d3df63075f5aab2e512150"],"del":[],"cre":["n2Bd4cWhEQK1aVjb1R7EBGV9mrw3etvSdC"],"exec":[{"op":"DEPLOY","data":["function issueRewards(dice, tier) {\n const { Affixes, ItemTypes, RatingRangePerQuality, Tiers, RequiredLevelPerQuality } = FyxClass.deepClone(Compendium);\n const { Ability, Bonus, ItemTypeNames, Bonuses } = FyxClass.deepClone(Constants);\n const QualityNames = ['Poor', 'Common', 'Uncommon', 'Rare', 'Epic', 'Legendary'];\n\n /**\n * Puts together a base_item and a set of affixes (named bonuses) to create an item\n */\n const compose = function compose_item(base_item, affix_set, drop_die) {\n expect(affix_set).toBeDefined('Affix set not initialized');\n\n const qualify = function quality_item(item) {\n expect(RatingRangePerQuality).toBeDefined();\n expect(RatingRangePerQuality.length).toBe(6);\n for (let i = 0; i < RatingRangePerQuality.length; i++) {\n const range = RatingRangePerQuality[i];\n const [lower, upper] = range;\n if (lower <= item.rating && item.rating <= upper) {\n return i;\n }\n }\n console.error(`failed to find ${item.rating}`);\n return null;\n };\n\n // Initialize the item with the data from the base_item\n let item = { ...base_item };\n let affixBonuses = affix_set.length > 0 ? affix_set.map(affix => affix.bonuses) : [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];\n\n item.bonuses = Object.keys(Bonus).map(() => 0);\n for (const affixBonus of affixBonuses) {\n for (const key of Object.keys(affixBonus)) {\n item.bonuses[Bonuses[key]] = affixBonus[key];\n }\n }\n\n expect(item.bonuses).toBeDefined('Affix set not initialized');\n\n // Name the item\n const base_item_name = ItemTypeNames[item.type].replace(/([A-Z][a-z])/g, \" $1\").slice(1);\n const base_item_classname = base_item_name.toLowerCase().replace(/\\s+/g, '-').replace(/[^0-9a-z/-]/gi, '');\n item.displayName = base_item_name;\n if (item.type == null) throw new Error(`Item has no type, tier:${tier}, drop_die: ${drop_die}, base_item: ${JSON.stringify(base_item)}`);\n if (item.displayName == null) throw new Error(`Item has no name, tier:${tier}, drop_die: ${drop_die}, item_type:${item.type}, item names: ${JSON.stringify(ItemTypeNames)}`);\n let prefixes = affix_set.filter(affix => affix.prefix);\n for (let prefix of prefixes) {\n item.displayName = `${prefix.name} ` + item.displayName;\n }\n let suffixes = affix_set.filter(affix => !affix.prefix);\n for (let i = 0; i < suffixes.length; i++) {\n item.displayName += (i == 0 ? ' of' : (i < suffixes.length - 1 ? ',' : ' and')) + ` ${suffixes[i].name}`;\n }\n\n item.className = item.displayName.toLowerCase().replace(/\\s+/g, '-').replace(/[^0-9a-z/-]/gi, '');\n\n // Calculate it's rating\n let affix_stacking_rating = affix_set.filter(affix => affix.rating > 0).length;\n item.rating += affix_set.map(affix => affix.rating).reduce((a, b) => a + b, 0) + affix_stacking_rating;\n\n // Give it a quality\n item.quality = qualify(item);\n \n expect(item).toBeDefined('Failed to generate and issue item reward');\n\n item.levelRequired = RequiredLevelPerQuality[item.quality];\n\n item.satoshis = (2 + item.rating) * 273; // adding +2 for poor items that have a min rating of -2\n item.classId = `${item.collection}:${item.className}`;\n\n item.classId = `${item.collection}:${item.className}`;\n item.collections = [item.collection];\n item.tags = ['cryptofights', item.className, item.collection];\n if(!item.tags.includes(base_item_classname)){\n item.tags.push(base_item_classname);\n }\n\n\n item.tags = item.tags.concat([QualityNames[item.quality].toLowerCase().replace(/\\s+/g, '-').replace(/[^0-9a-z/-]/gi, ''), `r${item.rating}`]);\n affix_set.forEach(affix => {\n item.tags.push(affix.name.toLowerCase().replace(/\\s+/g, '-').replace(/[^0-9a-z/-]/gi, ''));\n });\n return item;\n };\n\n // figure out how many items we're going to drop\n const n_drop_die = dice.roll(1, 100);\n const n_drops = n_drop_die < 75 ? 1 : (n_drop_die < 99 ? 2 : 1);\n // console.log(`Dropping ${n_drops} items`);\n\n // console.time('Compose Items');\n\n expect(tier).toBeLessThanOrEqualTo(Tiers.length);\n expect(Tiers[tier - 1]).toBeDefined('Undefined tier');\n const loot_table = Tiers[tier - 1].lootTable;\n expect(loot_table).toBeDefined(`Loot table for tier ${tier-1} is null`);\n\n let items = [];\n rolling:\n while (items.length < n_drops) {\n\n const drop_die = dice.roll(1, 100);\n\n const rate_accum = loot_table.map((sum => value => sum += value)(0));\n // console.log(`Drop die is ${drop_die}, table:${loot_table}, accum:${rate_accum}`);\n\n // Find index in rate_accum where drop_die is lower\n let qualityIndex = rate_accum.findIndex(rate => drop_die <= rate);\n\n if (qualityIndex < 0) {\n qualityIndex = 0;\n }\n\n let [lower_rating_range, upper_rating_range] = RatingRangePerQuality[qualityIndex];\n\n // Determine the base items that we're going to drop\n const base_item_subset = ItemTypes.filter((item) => {\n return item.rating <= upper_rating_range + 1;\n });\n\n expect(base_item_subset.length > 0).toBe(true, `All items are too powerful for rating ${upper_rating_range}`);\n\n const base_item = base_item_subset.length == 1 ? base_item_subset[0] : base_item_subset[dice.roll(1, base_item_subset.length) - 1];\n\n // console.log(`Attempting to drop a ${QualityNames[qualityIndex]} ${ItemTypeNames[base_item.type]} of rating ${lower_rating_range} to ${upper_rating_range} on tier ${tier}`);\n let affixes = [];\n let valid_affixes = Affixes.filter(affix => base_item.validAffixes.includes(affix.name));\n const affix_rating_reducer = (accumulator, affix) => {\n return accumulator + affix.rating;\n };\n\n const sortingNumbers = [0, 0, 1, 2, 4, 8, 16, 32];\n\n let rating = base_item.rating;\n let add_affixes = false;\n while (lower_rating_range > rating || rating > upper_rating_range || add_affixes) {\n let increase_rating = rating < lower_rating_range;\n\n // Filter generation\n valid_affixes = valid_affixes.filter(a => a.collection.includes('gen1'));\n\n // Filter wrong 'direction'\n valid_affixes = valid_affixes.filter(a => a.rating < 0 && !increase_rating || a.rating > 0 && increase_rating);\n\n let previous_bonuses = [];\n affixes.forEach(affix => {\n previous_bonuses.push.apply(previous_bonuses, Object.keys(affix.bonuses));\n });\n\n // Filter affixes with similar bonus or invalid affixes\n valid_affixes = valid_affixes.filter(a => {\n if( a.validAffixes.includes('*') || [...affixes].every(x=>x.name in a.validAffixes) ){\n let bonuses = Object.keys(a.bonuses);\n for (let i = 0; i < bonuses.length; i++) {\n if (previous_bonuses.includes(bonuses[i])) {\n return false;\n }\n }\n }else{\n return false;\n }\n\n return true;\n });\n if (valid_affixes.length == 0) {\n // console.log(`Re-rolling we don't have more affixes to try ${rating}, we need ${lower_rating_range}-${upper_rating_range}`);\n continue rolling;\n }\n\n let affix_index = affixes.length == 1 ? 0 : dice.roll(1, valid_affixes.length) - 1; // Random affix index\n let affix = valid_affixes.splice(affix_index, 1)[0];\n affixes.push(affix);\n\n rating = base_item.rating + affixes.reduce(affix_rating_reducer, 0)+sortingNumbers[affixes.length];\n\n add_affixes = rating > lower_rating_range && valid_affixes.length > 1 ? dice.roll(1, 2) > 1 : false;\n }\n\n if (base_item.rating + affixes.reduce(affix_rating_reducer, 0) > upper_rating_range) {\n // console.log(`Re-rolling because item is stronger than ${upper_rating_range}`);\n continue rolling;\n }\n\n const item = compose(base_item, affixes, drop_die);\n delete item.validAffixes;\n // console.log(item);\n\n // Here we have both a base_item and it's affixes that match the lower/upper rating range\n items.push(item);\n }\n // console.timeEnd('Compose Items');\n\n // console.log('Rewards Issued');\n return items.map(item => ({\n item,\n metadata: {\n name: item.displayName,\n classId: item.classId,\n imageUrl: Compendium.ItemImageUrls[item.type] || ''\n },\n satoshis: item.satoshis\n }));\n}",{"deps":{"Compendium":{"$jig":0},"Constants":{"$jig":1},"FyxClass":{"$jig":2},"FyxConfig":{"$jig":3},"FyxItem":{"$jig":4},"Sha256":{"$jig":5},"expect":{"$jig":6}},"hash":"57b0209d7790d2053e73399af13ac79865572ec6a56f0e60a7f35c3d60227308"}]}]}
    https://whatsonchain.com/tx/b1fae14b7f53620c8d2354e3e9ba50164b0b4916eead575a1add7026a8373dfa