////////////////////////////
// Run when entering map
void OnStart()
{
	SetEntityPlayerInteractCallback("key_torture_chamber_1", "Herp", true);
	AddEntityCollideCallback("Player", "ScriptArea_1", "Derp", true, 1);
	SetEntityPlayerInteractCallback("mansion_3", "Monster", true);
	AddUseItemCallback("", "stone_hammer_1", "work_desk_door_worn_1", "BreakDesk", true);
	SetEntityPlayerInteractCallback("work_desk_door_worn_1", "DeskLockedMessage", true);
	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", "FlashbackSickness_01", 3); AddTimer("", 3, "FlashBack_3");}
void FlashBack_3(string &in asTimer)
{SetMessage("Flashbacks", "FlashbackSickness_02", 4); AddTimer("", 4, "FlashBack_4");}
void FlashBack_4(string &in asTimer)
{SetMessage("Flashbacks", "FlashbackSickness_03", 4); AddTimer("", 4, "FlashBack_5");}
void FlashBack_5(string &in asTimer)
{SetMessage("Flashbacks", "FlashbackSickness_04", 4); AddTimer("", 4, "FlashBack_6");}
void FlashBack_6(string &in asTimer)
{SetMessage("Flashbacks", "FlashbackSickness_05", 4); AddTimer("", 4, "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("16_amb.ogg", true, 0.5, 5, 1, false);

}

void DeskLockedMessage(string &in asEntity) 

{
GetSwingDoorLocked("work_desk_door_worn_1");
if(GetSwingDoorLocked("work_desk_door_worn_1") == true)
{
SetMessage("Messages", "DeskDoor2", 0);
}
}
 
void BreakDesk(string &in asItem, string &in asEntity)
{
	CreateParticleSystemAtEntity("", "ps_dust_impact.ps", "work_desk_door_worn_1", false);
	CreateParticleSystemAtEntity("", "ps_door_damage_wood.ps", "work_desk_door_worn_1", false);
	PlaySoundAtEntity("", "break_wood.snt", "work_desk_door_worn_1", 0, false);
	SetEntityActive("work_desk_door_worn_1", false);
	
}
 
 void Herp(string &in asEntity)
{
	SetEntityActive("ScriptArea_1", true);
}

void Derp(string &in asParent, string &in asChild, int alState)
{
	PlaySoundAtEntity("", "door_level_wood_close.snt", "level_wood_1", 0, false);
	SetEntityActive("servant_grunt_1", true); 
	AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_2", 0, "");
	AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_22", 3, "");
	AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_24", 0, "");
	AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_32", 0, "");
	AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_28", 0, "");
	AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_25", 0, "");
	AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_20", 0, "");
	AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_18", 0, "");

}


////////////////////////////
// Run when leaving map
void OnLeave()
{
	StopMusic(3, 1);

}