////////////////////////////
// Run when entering map
void OnStart()
{
	AddEntityCollideCallback("Player", "ScriptArea_1", "Scare", true, 1);
	AddEntityCollideCallback("Player", "ScriptArea_2", "Darkness", true, 1);
	AddEntityCollideCallback("Player", "ScriptArea_12", "Monster", true, 1);
	AddEntityCollideCallback("Player", "ScriptArea_13", "Blast", true, 1);
	AddEntityCollideCallback("Player", "ScriptArea_16", "Blast_02", true, 1);
	AddEntityCollideCallback("Player", "ScriptArea_5", "Transit", false, 1);
	AddEntityCollideCallback("servant_grunt_1", "ScriptArea_11", "RipApart", true, 1);
	SetEntityPlayerInteractCallback("lantern_1", "Trap1", true);
	AddEntityCollideCallback("Player", "ScriptArea_10", "Trap2", false, 1);
	AddEntityCollideCallback("Player", "FlashBackArea_1", "FlashBack_1", true, 1);

}

void FlashBack_1(string &in asParent, string &in asChild, int alState)
{StartEffectFlash(1, 1.0, 1); PlaySoundAtEntity("", "flashback_flash.snt", "Player", 0.1f, false); FadeImageTrailTo(3, 0.1f); FadeSepiaColorTo(5, 0.1f); SetPlayerMoveSpeedMul(0.5); AddTimer("", 2, "FlashBack_2"); SetEntityInteractionDisabled("level_wood_1", true);}
void FlashBack_2(string &in asTimer)
{SetMessage("Flashbacks", "FlashbackSebastian_01", 3); AddTimer("", 3, "FlashBack_3");}
void FlashBack_3(string &in asTimer)
{SetMessage("Flashbacks", "FlashbackSebastian_02", 4); AddTimer("", 4, "FlashBack_4");}
void FlashBack_4(string &in asTimer)
{SetMessage("Flashbacks", "FlashbackSebastian_03", 6); AddTimer("", 6, "FlashBack_5");}
void FlashBack_5(string &in asTimer)
{SetMessage("Flashbacks", "FlashbackSebastian_04", 4); AddTimer("", 4, "FlashBack_6");}
void FlashBack_6(string &in asTimer)
{SetMessage("Flashbacks", "FlashbackSebastian_05", 6); AddTimer("", 6, "FlashBack_End");}
void FlashBack_End(string &in asTimer)
{StartEffectFlash(1, 1.0, 1); PlaySoundAtEntity("", "flashback_flash.snt", "Player", 0.1f, false); FadeImageTrailTo(0, 1.0f); FadeSepiaColorTo(0, 1.0f); SetPlayerMoveSpeedMul(1); SetEntityInteractionDisabled("level_wood_1", false);}

void OnEnter()
{
	PlayMusic("29_amb.ogg", true, 0.2, 5, 1, false);

}


void Trap1(string &in asEntity)
{
	SetSwingDoorLocked("hatch_ceiling_1", false, true);
	SetEntityActive("cellar_wood01_3", false); 
	SetEntityActive("cellar_wood01_4", true); 
	SetEntityActive("ScriptArea_10", true);
	SetEntityActive("block_box_1", false); 
	SetEntityActive("ScriptArea_2", false); 
	SetEntityActive("block_box_2", false); 
	SetEntityActive("ScriptArea_12", false); 

}



void Trap2(string &in asParent, string &in asChild, int alState)
{
	PlaySoundAtEntity("", "Monster_far.snt", "ScriptArea_3", 0, false);
	AddTimer("Approach_1", 3, "Approaching_1");
	AddTimer("Wubwub", 0.5, "Warning");
	SetEntityActive("ScriptArea_10", false); 
	CheckPoint("Revive_1", "PlayerStartArea_2", "HellAgain", "", "");
	SetSwingDoorLocked("hatch_ceiling_1", false, true);
	SetPropStaticPhysics("hatch_ceiling_1", false);
}

void HellAgain(string &in asName, int alCount)
{
	SetEntityActive("ScriptArea_10", true);
	SetPlayerActive(true);
	
}

void Warning(string &in asTimer)
{
	SetMessage("Messages", "Approacher", 2);
}

void Approaching_1(string &in asTimer)
{
	PlaySoundAtEntity("", "Monster_close.snt", "ScriptArea_3", 0, false);
	AddTimer("Approach_2", 2.75f, "Approaching_2");
}

void Approaching_2(string &in asTimer)
{
	PlaySoundAtEntity("", "Monster_close.snt", "ScriptArea_4", 0, false);
	AddTimer("Approach_3", 2.75f, "Approaching_3");
}

void Approaching_3(string &in asTimer)
{
	PlaySoundAtEntity("", "Monster_close.snt", "ScriptArea_6", 0, false);
	AddTimer("Approach_4", 2.75f, "Approaching_4");
}

void Approaching_4(string &in asTimer)
{
	PlaySoundAtEntity("", "Monster_close.snt", "ScriptArea_7", 0, false);
	AddTimer("Approach_5", 2.75f, "Approaching_5");
}

void Approaching_5(string &in asTimer)
{
	PlaySoundAtEntity("", "Monster_close.snt", "ScriptArea_8", 0, false);
	AddTimer("Approach_6", 2.75f, "Approaching_6");
}

void Approaching_6(string &in asTimer)
{
	PlaySoundAtEntity("", "Monster_close.snt", "ScriptArea_8", 0, false);
	AddTimer("Approach_7", 2.75f, "Approaching_7");
}

void Approaching_7(string &in asTimer)
{
	PlaySoundAtEntity("", "hit_wood.snt", "ScriptArea_8", 0, false);
	CreateParticleSystemAtEntity("", "ps_door_damage_wood.ps", "cellar_wood01_4", false);
	AddPropImpulse("cellar_wood01_4", 0, 0, -20, "world");

	AddTimer("Approach_8", 1, "Approaching_8");

}

void Approaching_8(string &in asTimer)
{
	PlaySoundAtEntity("", "hit_wood.snt", "ScriptArea_8", 0, false);
	CreateParticleSystemAtEntity("", "ps_door_damage_wood.ps", "cellar_wood01_4", false);
	AddPropImpulse("cellar_wood01_4", 0, 0, -20, "world");

	AddTimer("Approach_9", 1, "Approaching_9");
}

void Approaching_9(string &in asTimer)
{
	PlaySoundAtEntity("", "break_wood.snt", "ScriptArea_8", 0, false);
	CreateParticleSystemAtEntity("", "ps_door_damage_wood.ps", "cellar_wood01_4", false);
	CreateParticleSystemAtEntity("", "ps_break_mansionbase_wall.ps", "cellar_wood01_4", false);
	AddPropImpulse("cellar_wood01_4", 0, 0, -30, "world");

	SetPlayerActive(false);
	FadeOut(0.5);
	AddTimer("Murderer_1", 1, "Murder_1");
}

void Murder_1(string &in asTimer)
{
	PlaySoundAtEntity("", "Monster_scream.snt", "ScriptArea_8", 0, false);
	AddTimer("Murderer_2", 0.8, "Murder_2");
}

void Murder_2(string &in asTimer)
{
	PlaySoundAtEntity("", "react_pant.snt", "Player", 0, false);
	AddTimer("Murderer_3", 0.2, "Murder_3");
}

void Murder_3(string &in asTimer)
{
	PlaySoundAtEntity("", "Damage.snt", "Player", 0, false);
	AddTimer("Murderer_4", 0.2, "Murder_4");
}

void Murder_4(string &in asTimer)
{
	PlaySoundAtEntity("", "26_squeeze_gland.snt", "ScriptArea_8", 0, false);

	GivePlayerDamage(100, "Claws", false, true);
}

void Scare(string &in asParent, string &in asChild, int alState)
{
	SetEntityActive("servant_grunt_1", true); 
	AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_1", 0, "");
	SetPlayerMoveSpeedMul(0.1);
	PlaySoundAtEntity("", "enemy_hallucination_disappear.snt", "Player", 0.1f, false);
}

void RipApart(string &in asParent, string &in asChild, int alState)
{
	SetEntityActive("servant_grunt_1", false);
	PlaySoundAtEntity("", "Monster_scream.snt", "ScriptArea_11", 0.1f, false);
	AddTimer("Rippings_1", 1.2f, "RipApart_1");
}

void RipApart_1(string &in asTimer)
{
	PlaySoundAtEntity("", "Grunt_pain.snt", "ScriptArea_11", 0.1f, false);
	AddTimer("Rippings_2", 0.6f, "RipApart_2");
	AddTimer("Rippager", 0.8f, "Rippage_1");
}

void Rippage_1(string &in asTimer)
{
	PlaySoundAtEntity("", "Damage.snt", "ScriptArea_11", 0.1f, false);
}

void RipApart_2(string &in asTimer)
{
	PlaySoundAtEntity("", "Monster_frenzy.snt", "ScriptArea_11", 0.1f, false);
	AddTimer("Rippings_3", 1.2f, "RipApart_3");
}

void RipApart_3(string &in asTimer)
{
	PlaySoundAtEntity("", "26_squeeze_gland.snt", "ScriptArea_11", 0.1f, false);
	SetPlayerMoveSpeedMul(1);
}

void ScaryStuff(string &in asEntity, int alState)
{
	StartScreenShake(0.5f, 0.01f, 0.1f, 0.02f);
	GiveSanityDamage(10.0f, true);
	PlaySoundAtEntity("", "react_scare", "Player", 0, false);
}

void Transit(string &in asParent, string &in asChild, int alState)
{
	RemoveTimer("Approach_1");
	RemoveTimer("Approach_2");
	RemoveTimer("Approach_3");
	RemoveTimer("Approach_4");
	RemoveTimer("Approach_5");
	RemoveTimer("Approach_6");
	RemoveTimer("Approach_7");
	RemoveTimer("Approach_8");
	RemoveTimer("Approach_9");
	RemoveTimer("Murderer_1");
	RemoveTimer("Murderer_2");
	RemoveTimer("Murderer_3");
	RemoveTimer("Murderer_4");
	SetEntityActive("cellar_wood01_4", false);
	ChangeMap("distillery.map", "PlayerStartArea_2", "", "react_pant");
}

void Darkness(string &in asParent, string &in asChild, int alState) 
{
SetMessage("Messages", "Dark", 0);
}

void Blast(string &in asParent, string &in asChild, int alState) 
{
	AddPropImpulse("wood_box01_16", 0, 0, 10.0f, "world");
	AddPropImpulse("wood_box01_15", 0, 0, 10.0f, "world");
	AddPropImpulse("wood_box01_13", 0, 0, 10.0f, "world");
	AddPropImpulse("wood_box03_5", 0, 0, 10.0f, "world");
	AddPropImpulse("wood_box02_14", 0, 0, 10.0f, "world");
	AddPropImpulse("wood_box01_12", 0, 0, 10.0f, "world");
	PlaySoundAtEntity("", "Monster_frenzy.snt", "ScriptArea_14", 0, false);
}

void Blast_02(string &in asParent, string &in asChild, int alState) 
{
	AddPropImpulse("wood_box01_22", -1.0f, 0, 0, "world");
}

void Monster(string &in asParent, string &in asChild, int alState) 
{
SetMessage("Messages", "Monster", 0);
}
////////////////////////////
// Run when leaving map
void OnLeave()
{
	StopMusic(3, 1);
}