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

var levelOneDealBuy = ['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 levelTwoDealBuy = ['botania:elementium_ingot", Count: 2','botania:manasteel_ingot", Count: 6'];
var levelThreeDealBuy = 'minecraft:stone';
var levelFourDealBuy = 'minecraft:stone';
var levelFiveDealBuy = 'minecraft:stone';

var levelOneDealSell = ['waystones:warp_scroll", Count: 4','waystones:bound_scroll", Count: 4'];
var levelTwoDealSell = 'minecraft:stone';
var levelThreeDealSell = 'minecraft:stone';
var levelFourDealSell = 'minecraft:stone';
var levelFiveDealSell = 'minecraft:stone';

var levelOne = 1;
var levelTwo = 2;
var levelThree = 3;
var levelFour = 4;
var levelFive = 5;


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

    if(event.entity.type == 'farlanders:farlander' && event.entity.getFullNBT().Level == 1) {
        
        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: 10, buyB: {id: "minecraft:air", Count: 1b, tag: {Damage: 0}}, buy: {id: "'+random(levelOneDealBuy)+'b}, sell: {id: "farlanders:endumium_crystal", Count: 1b}, xp: 2, uses: 0, 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(levelOneDealSell)+'b}, xp: 3, uses: 0, priceMultiplier: 0.05f, specialPrice: 0, demand: 0, rewardExp: 1b}]}, Level: '+levelOne+'}');
    });
}
})
