////////////////////////////
// Run when entering map
void OnStart()
{
	AddEntityCollideCallback("PlatformPuzzle_1", "ScriptArea_1", "Puzzle_1", true, 1);
	AddEntityCollideCallback("Player", "ScriptArea_2", "FallWine", true, 1);
	AddEntityCollideCallback("Player", "ScriptArea_4", "FallNote", true, 1);
	SetEntityPlayerInteractCallback("cellar_wood01_slow_1", "Scare_1", true);
	AddUseItemCallback("", "stone_hammer_1", "padlock_1", "BreakLock", true);
	SetEntityPlayerInteractCallback("stone_hammer_1", "ScareB_2", true);
}
void OnEnter()
{
	PlayMusic("Wait_for_the_Combustion.ogg", true, 0.4, 5, 1, false);

}

void ScareB_2(string &in asEntity)
{
	SetEntityActive("corpse_bloody_1", false); 
	SetEntityActive("butcher_knife_1", false); 

}
void BreakLock(string &in asItem, string &in asEntity)
{
	SetPropHealth("padlock_1", 0.0f);
	SetEntityActive("padlock_broken_1", true);
	SetEntityActive("padlock_1", false);
	PlaySoundAtEntity("", "pickaxe_hit.snt", "ScriptArea_5", 0, false);
}

void FallNote(string &in asParent, string &in asChild, int alState)
{
	SetPropStaticPhysics("note_paper01_1", false);
	StartScreenShake(0.5f, 0.01f, 0.1f, 0.02f);
	GiveSanityDamage(15.0f, true);
	PlaySoundAtEntity("", "enemy_hallucination_dissapear.snt", "Player", 0.1f, false);
	
}
void FallWine(string &in asParent, string &in asChild, int alState)
{
	AddPropImpulse("wine02_11", 0, 0, -0.8f, "world");
}

void Scare_1(string &in asEntity)
{
	AddTimer("", 4, "Scare_2");
	AddTimer("", 2, "LightKiller");

}
void LightKiller(string &in asTimer)
{
	CreateParticleSystemAtEntity("", "ps_dust_whirl.ps", "ScriptArea_3", false);
	PlaySoundAtEntity("", "scare_ghost.snt", "ScriptArea_3", 0.3f, false);
	SetLampLit("hanging_lantern_ceiling_1", false, true);
	SetLampLit("hanging_lantern_ceiling_2", false, true);
	SetLampLit("hanging_lantern_ceiling_3", false, true);
	AddPropImpulse("hanging_lantern_ceiling_1", 0.8f, 0, 0.8f, "world");
	AddPropImpulse("hanging_lantern_ceiling_2", 0.8f, 0, 0.8f, "world");
	AddPropImpulse("hanging_lantern_ceiling_3", 0.8f, 0, 0.8f, "world");
}
void Scare_2(string &in asTimer)
{
	SetPropStaticPhysics("PlatformPuzzle_1", false);
	AddPropImpulse("PlatformPuzzle_1", 0, 0, 0.8f, "world");
}

void Puzzle_1(string &in asParent, string &in asChild, int alState) 
{
	SetEntityActive("PlatformPuzzle_2", true);
	SetEntityActive("PlatformPuzzle_1", false);
	PlaySoundAtEntity("", "impact_wood_heavy_high.snt", "ScriptArea_1", 0, false);	
}
////////////////////////////
// Run when leaving map
void OnLeave()
{
	StopMusic(3, 1);
}