////////////////////////////
// Run when entering map
void OnStart()
{

	SetEntityPlayerInteractCallback("work_desk_door_1", "DeskLockedMessage", true);
	AddUseItemCallback("", "deskkey", "work_desk_door_1", "KeyOnDoor", true);
	AddEntityCollideCallback("Player", "ScriptArea_1", "BreakDoor", true, 1);
	SetEntityPlayerInteractCallback("GlassJarBlood", "ScaredyCat_1", 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", "FlashbackGuest_01", 3); AddTimer("", 3, "FlashBack_3");}
void FlashBack_3(string &in asTimer)
{SetMessage("Flashbacks", "FlashbackGuest_02", 3); AddTimer("", 3, "FlashBack_4");}
void FlashBack_4(string &in asTimer)
{SetMessage("Flashbacks", "FlashbackGuest_03", 3); AddTimer("", 3, "FlashBack_5");}
void FlashBack_5(string &in asTimer)
{SetMessage("Flashbacks", "FlashbackGuest_04", 3); AddTimer("", 3, "FlashBack_6");}
void FlashBack_6(string &in asTimer)
{SetMessage("Flashbacks", "FlashbackGuest_05", 2); AddTimer("", 2, "FlashBack_7");}
void FlashBack_7(string &in asTimer)
{SetMessage("Flashbacks", "FlashbackGuest_06", 3); AddTimer("", 3, "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("06_amb.ogg", true, 0.5, 5, 1, false);

}

void ScaredyCat_1(string &in asEntity)
{
	SetEntityActive("ScriptArea_1", true);
}

void DeskLockedMessage(string &in asEntity) 

{
GetSwingDoorLocked("work_desk_door_1");
if(GetSwingDoorLocked("work_desk_door_1") == true)
{
SetMessage("Messages", "DeskDoor", 0);
}
}
 
void KeyOnDoor(string &in asItem, string &in asEntity)
{
	SetSwingDoorLocked("work_desk_door_1", false, true);
	PlaySoundAtEntity("", "door_mansion_open", "work_desk_door_1", 0, false);
	RemoveItem("deskkey");
} 


void BreakDoor(string &in asParent, string &in asChild, int alState)
{
	CreateParticleSystemAtEntity("", "ps_break_mansionbase_wall.ps", "mansion_1", false);
	PlaySoundAtEntity("", "break_wood.snt", "mansion_1", 0, false);
	SetSwingDoorClosed("mansion_1", false, true);
	AddPropImpulse("mansion_1", 0, 0, -20, "world");
	AddTimer("BreakDoor", 0.2, "BreakDoor_2");
	SetSwingDoorLocked("mansion_1", false, true);
	SetSwingDoorClosed("mansion_1", false, true);

}

void BreakDoor_2(string &in asTimer)
{
	PlaySoundAtEntity("", "react_pant.snt", "Player", 0, false);
	PlaySoundAtEntity("", "break_wood.snt", "mansion_1", 0, false);
	AddPropImpulse("mansion_1", 0, 0, -30, "world");
	StartScreenShake(0.5f, 0.01f, 0.1f, 0.02f);
	GiveSanityDamage(10.0f, true);
	PlaySoundAtEntity("", "react_scare", "Player", 0, false);
}

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

}