// Sword hit sounds OnLoad
const SOUNDS = new Array(Array("sound.swordbreakable"), 										// Sounds for breakable blocks
						 Array("sound.swordmetal"),												// Sounds for metal blocks
						 Array("sound.swordmetal"),												// Sounds for stone blocks
						 Array("sound.swordwood", "sound.swordwoodb", "sound.swordwoodc"));		// Sounds for wooden blocks

const MATERIALS = new Array(Array(112, 113),																													// ID's of breakable blocks
							Array(20, 27, 28, 41, 42, 49, 57, 66, 71, 79, 89, 106, 206, 210, 216),																// ID's of metal blocks
							Array(1, 3, 4, 7, 14, 15, 16, 21, 22, 23, 24, 43, 44, 45, 48, 56, 60, 61, 62, 67, 70, 77, 87, 116, 201, 205, 211, 212, 213, 215),	// ID's of stone blocks
							Array(5, 17, 25, 47, 50, 53, 54, 58, 63, 64, 65, 68, 72, 75, 76, 84, 85, 86, 91, 96, 100, 104, 119, 122, 214, 217));				// ID's of wooden blocks
							
function PlayBlockSound(blockID, x, y, z)
{
	var found = false;
	for (var i=0; i<MATERIALS.length; i++)
	{
		for (var j=0; j<MATERIALS[i].length; j++)
		{
			if (blockID == MATERIALS[i][j])
			{
				// Play the appropriate sound. Random sound will chosen from the ones listed for this material
				var index = Math.floor(Math.random() * SOUNDS[i].length);
				sound.playSound3D(SOUNDS[i][index], x, y, z);
				
				// Exit out of this loop
				found = true;
				break;
			}
		}
		if (found)
		{
			break;
		}
	}
}

//3D Sound
ppos = player.getPosition();

// Dialogue OnLoad
var itemClear=28
script.runScript("chatLib.js");
conv = 0
effect.clearOverlay();
keyboard.bindKey(itemClear,"dialogueclose.js")

//Fake HDR
var baseLightRamp = Array();
var currentLight = 15;
var lightRampModifier = Array(0.008, 0.009, 0.011, 0.013, 0.016, 0.019, 0.023, 0.027, 0.032, 0.037, 0.043, 0.049, 0.056, 0.063, 0.071, 0.08)

effect.resetLightRampValues();
for (var i=0; i<16; i++)
{
	baseLightRamp[i] = effect.getLightRampValue(i);
}

function FakeHDR()
{
	ppos = player.getPosition();
	lightLevel = world.getLightValue(Math.floor(ppos.x), Math.floor(ppos.y), Math.floor(ppos.z));
	if (lightLevel != currentLight)
	{
		currentLight = lightLevel;
		var baseDiff = 15 - currentLight;
		for (var i=0; i<16; i++)
		{
			effect.setLightRampValue(i, baseLightRamp[i] + (lightRampModifier[i] * baseDiff));
		}
	}
}

//Vec2 Utility
script.runScript("geom2d.js");