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

var deal1 = ['immersiveengineering:ingot_uranium", Count: 2','mysticalworld:copper_ingot", Count: 12','mysticalworld:silver_ingot", Count: 7',,'mysticalworld:quicksilver_ingot", Count: 2','mysticalworld:lead_ingot", Count: 8','immersiveengineering:ingot_aluminum", Count: 5','immersiveengineering:ingot_nickel", Count: 3'];

var deal2 = ['botania:elementium_ingot", Count: 2','botania:manasteel_ingot", Count: 6'];

var deal3 = ['waystones:warp_scroll", Count: 4','waystones:bound_scroll", Count: 4','waystones:warp_plate", Count: 2'];

var deal4 = ['kubejs:unstable_endershard", Count: 1','kubejs:essence_druidity", Count: 2','calemiutils:link_book_location", Count: 1'];


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

    if(event.entity.type == 'farlanders:farlander' && event.entity.getFullNBT().Level == 1) {
        
        event.server.scheduleInTicks(2, cb => {
        
        var UUID = event.entity.getFullNBT().UUID;
	  
	  event.server.runCommandSilent('data merge entity @e[nbt={UUID:'+UUID+'},limit=1] {Offers: {Recipes: [{maxUses: 10, buyB: {id: "minecraft:air", Count: 1b, tag: {Damage: 0}}, buy: {id: "'+random(deal1)+'b}, sell: {id: "farlanders:endumium_crystal", Count: 1b}, xp: 2, uses: 5, priceMultiplier: 0.05f, specialPrice: 0, demand: 0, rewardExp: 1b}, {maxUses: 17, buyB: {id: "minecraft:air", Count: 1b, tag: {Damage: 0}}, buy: {id: "farlanders:endumium_crystal", Count: 2b}, sell: {id: "'+random(deal3)+'b}, xp: 3, uses: 11, priceMultiplier: 0.05f, specialPrice: 0, demand: 0, rewardExp: 1b}, {maxUses: 16, buyB: {id: "minecraft:air", Count: 1b, tag: {Damage: 0}}, buy: {id: "farlanders:endumium_crystal", Count: 2b}, sell: {id: "minecraft:ender_pearl", Count: 1b}, xp: 3, uses: 0, priceMultiplier: 0.05f, specialPrice: 0, demand: 0, rewardExp: 1b}, {maxUses: 16, buyB: {id: "minecraft:air", Count: 1b, tag: {Damage: 0}}, buy: {id: "'+random(deal2)+'b}, sell: {id: "farlanders:endumium_crystal", Count: 1b}, xp: 5, uses: 1, priceMultiplier: 0.05f, specialPrice: 0, demand: 0, rewardExp: 1b}, {maxUses: 12, buyB: {id: "minecraft:air", Count: 1b, tag: {Damage: 0}}, buy: {id: "farlanders:endumium_crystal", Count: 4b}, sell: {id: "usefulrailroads:teleport_rail", Count: 1b}, xp: 10, uses: 2, priceMultiplier: 0.05f, specialPrice: 0, demand: 0, rewardExp: 1b}, {maxUses: 12, buyB: {id: "minecraft:air", Count: 1b, tag: {Damage: 0}}, buy: {id: "quark:basalt", Count: 32b}, sell: {id: "farlanders:endumium_crystal", Count: 4b}, xp: 10, uses: 2, priceMultiplier: 0.05f, specialPrice: 0, demand: 0, rewardExp: 1b}, {maxUses: 12, buyB: {id: "minecraft:air", Count: 1b, tag: {Damage: 0}}, buy: {id: "farlanders:endumium_crystal", Count: 32b}, sell: {id: "bhc:yellow_heart", Count: 1b}, xp: 15, uses: 6, priceMultiplier: 0.05f, specialPrice: 0, demand: 0, rewardExp: 1b}, {maxUses: 12, buyB: {id: "minecraft:air", Count: 1b, tag: {Damage: 0}}, buy: {id: "farlanders:endumium_crystal", Count: 14b}, sell: {id: "'+random(deal4)+'b}, xp: 30, uses: 0, priceMultiplier: 0.05f, specialPrice: 0, demand: 0, rewardExp: 1b}, {maxUses: 12, buyB: {id: "minecraft:air", Count: 1b, tag: {Damage: 0}}, buy: {id: "farlanders:endumium_crystal", Count: 64b}, sell: {id: "mutantbeasts:endersoul_hand", Count: 1b}, xp: 30, uses: 0, priceMultiplier: 0.05f, specialPrice: 0, demand: 0, rewardExp: 1b}]}, Level: 5}');
    });
}
})
