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;

var flRefreshInterval = 5000;

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+'}');
    });
}
		/*
		if(event.entity.type == 'farlanders:farlander' && event.entity.getFullNBT().Level == 2) {
			
			event.server.schedule(flRefreshInterval, cb => {

      event.server.runCommand('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)+'", Count: 12b}, 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(levelOneDealSell)+'", Count: 4b}, 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: "farlanders:endumium_crystal", Count: 2b}, sell: {id: "'+random(levelTwoDealSell)+'b}, 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(levelTwoDealBuy)+'b}, sell: {id: "farlanders:endumium_crystal", Count: 2b}, xp: 5, uses: 0, priceMultiplier: 0.05f, specialPrice: 0, demand: 0, rewardExp: 1b}]}, Level: '+levelTwo+'}');
	  
		})
	}
	*/
})
