function random(ary){
    return ary[Math.floor(Math.random()*ary.length)];
}

var levelOneDealBuy = ['farlanders:endumium_crystal", Count: 15b}, sell: {id: "farlanders:nightfall_chestplate", Count: 1', 'farlanders:endumium_crystal", Count: 12b}, sell: {id: "farlanders:nightfall_leggings", Count: 1', 'farlanders:endumium_crystal", Count: 8b}, sell: {id: "farlanders:nightfall_helmet", Count: 1', 'farlanders:endumium_crystal", Count: 6b}, sell: {id: "farlanders:nightfall_boots", Count: 1'];

var levelTwoDealBuy = ['farlanders:endumium_crystal", Count: 8b}, sell: {id: "kubejs:golem_summoner", Count: 1', 'farlanders:endumium_crystal", Count: 12b}, sell: {id: "kubejs:unstable_endershard", Count: 1', 'farlanders:endumium_crystal", Count: 8b}, sell: {id: "kubejs:delight_builder", Count: 1', 'farlanders:endumium_crystal", Count: 8b}, sell: {id: "kubejs:delight_builder", Count: 1', 'farlanders:endumium_crystal", Count: 16b}, sell: {id: "kubejs:affixgear5", Count: 1'];

var levelThreeDealBuy = ['occultism:crushed_end_stone", Count: 16b}, sell: {id: "farlanders:endumium_crystal", Count: 4', 'quark:biotite", Count: 32b}, sell: {id: "farlanders:endumium_crystal", Count: 8'];

var levelFourDealBuy = ['farlanders:endumium_crystal", Count: 32b}, sell: {id: "xreliquary:ender_staff", Count: 1', 'farlanders:endumium_crystal", Count: 12b}, sell: {id: "charm:ender_pearl_block", Count: 1', 'farlanders:endumium_crystal", Count: 16b}, sell: {id: "minecraft:ender_chest", Count: 1', 'farlanders:endumium_crystal", Count: 6b}, sell: {id: "apotheosis:farmers_leash", Count: 1'];

var levelFiveDealBuy = ['farlanders:endumium_crystal", Count: 64b}, sell: {id: "forbidden_arcanus:eternal_stella", Count: 1'];


onEvent('entity.spawned', event => {

    if(event.entity.type == 'farlanders:wanderer') {
        
        event.server.scheduleInTicks(1, cb => {
        
        var UUID= event.entity.getFullNBT().UUID;
        var cleanUUID = '[I;'+UUID.toString().substring(1);
	  
	  event.server.runCommandSilent('data merge entity @e[nbt={UUID:'+cleanUUID+'},limit=1] {Offers: {Recipes: [{maxUses: 5, buyB: {id: "minecraft:air", Count: 1b, tag: {spell: {}}}, buy: {id: "'+random(levelOneDealBuy)+'b, tag: {Damage: 0}}, xp: 1, uses: 0, priceMultiplier: 0.05f, specialPrice: 0, demand: 0, rewardExp: 1b}, {maxUses: 12, buyB: {id: "minecraft:air", Count: 1b, tag: {spell: {}}}, buy: {id: "'+random(levelTwoDealBuy)+'b, tag: {Damage: 0}}, xp: 1, uses: 0, priceMultiplier: 0.05f, specialPrice: 0, demand: 0, rewardExp: 1b}, {maxUses: 12, buyB: {id: "minecraft:air", Count: 1b, tag: {spell: {}}}, buy: {id: "'+random(levelThreeDealBuy)+'b, tag: {Damage: 0}}, xp: 1, uses: 0, priceMultiplier: 0.05f, specialPrice: 0, demand: 0, rewardExp: 1b}, {maxUses: 12, buyB: {id: "minecraft:air", Count: 1b, tag: {spell: {}}}, buy: {id: "'+random(levelFourDealBuy)+'b, tag: {Damage: 0}}, xp: 1, uses: 0, priceMultiplier: 0.05f, specialPrice: 0, demand: 0, rewardExp: 1b}, {maxUses: 8, buyB: {id: "minecraft:air", Count: 1b, tag: {spell: {}}}, buy: {id: "'+random(levelFiveDealBuy)+'b, tag: {Damage: 0}}, xp: 1, uses: 0, priceMultiplier: 0.05f, specialPrice: 0, demand: 0, rewardExp: 1b}]}}');
    });
}
})
