///////////////////
//KIANDRA'S ROOMS//
///////////////////
void func_unlock(string &in asEntity, int alState)
{
if (alState == 1)
{
    SetSwingDoorLocked("castle_arched01_1", true, true);
    SetSwingDoorClosed("castle_arched01_1", true, true);
}
if (alState == -1)
{
    SetSwingDoorLocked("castle_arched01_1", false, true);
    SetSwingDoorDisableAutoClose("castle_arched01_1", true);
    AddPropForce("castle_arched01_1", 0.0f, 0.0f, -1000.0f, "World");
}
}
//////////////////////
//Romulator's Map(s)//
//////////////////////
void turnphono(string &in asEntity, int alState)
{
    SetWheelInteractionDisablesStuck(asEntity, false);
    SetWheelStuckState(asEntity, alState, false);
    //PlayPhono(1, 1, 4, asEntity);
    PlayMusic("09_amb_safe.ogg", false, 35.0f, 7.0f, 7, false);
    SetEntityActive("ScrStopMusic", true);
}
    
void stop_the_music(string &in asParent, string &in asChild, int alState)
{
    StopMusic(10.0f, 7);
}
    
    
///////////////////
//Nikson's Rooms//
///////////////////
void func_secret_door(string &in asEntity, int alState)
{
    if (alState == 0)
   {
        SetMoveObjectState("castlebase_secret_door_1", 1);
        SetLeverStuckState(asEntity, 1, true);
   }
}
    
void func_mus(string &in asParent, string &in asChild, int alState)
{
    PlayMusic("09_amb_safe.ogg", false, 10.0f, 5.0f, 0, false);
}
///////////////////
//Flawless' Rooms//
///////////////////
void FlawlessStopMusic(string &in asParent, string &in asChild, int alState)
{
    StopMusic(3, 0);
}
    
void FlawlessNonSuspiciousScare(string &in asParent, string &in asChild, int alState)
{
    AddTimer("SlowPlayer_1", 1.0f, "NonSuspiciousTimer");
    AddTimer("SlowPlayer_2", 1.5f, "NonSuspiciousTimer");
    AddTimer("SlowPlayer_3", 2.0f, "NonSuspiciousTimer");
    
    AddTimer("HeartBeat_1", 1.0f, "NonSuspiciousTimer");
    AddTimer("HeartBeat_1", 2.0f, "NonSuspiciousTimer");
    AddTimer("HeartBeat_1", 3.0f, "NonSuspiciousTimer");
    AddTimer("HeartBeat_1", 4.0f, "NonSuspiciousTimer");
    AddTimer("HeartBeat_1", 5.0f, "NonSuspiciousTimer");
    AddTimer("HeartBeat_1", 6.0f, "NonSuspiciousTimer");
    
    AddTimer("Fade", 8.0f, "NonSuspiciousTimer");
    AddTimer("ClearAndFadeOut", 9.0f, "NonSuspiciousTimer");
    AddTimer("SetPlayerActive", 10.0f, "NonSuspiciousTimer");
    
    AddTimer("ZoomScare", 7.0f, "NonSuspiciousTimer");
    
    AddTimer("StopThescaaaawycreaks", 5.0f, "NonSuspiciousTimer");
    
    FadePlayerFOVMulTo(2.0f, 0.5f);
    
    SetPlayerLookSpeedMul(0.3f);
    StartPlayerLookAt("LookAtThisGuy", 2, 3, "");
    
    PlaySoundAtEntity("Heartbeat", "sanity_heartbeat.snt", "Player", 0.0f, false);
    
    PlayMusic("20_event_darkness.ogg", false, 5, 4, 0, false);
    
}
void NonSuspiciousTimer(string &in asTimer)
{
    if(asTimer == "SlowPlayer_1")
    {
        SetPlayerMoveSpeedMul(0.75f);
        CreateParticleSystemAtEntity("Dust_1", "ps_dust_falling_rumble.ps", "AreaDust_1", false);
    }
    
    if(asTimer == "SlowPlayer_2")
    {
        SetPlayerMoveSpeedMul(0.5f);
        CreateParticleSystemAtEntity("Dust_2", "ps_dust_falling_rumble.ps", "AreaDust_2", false);
    }
    
    if(asTimer == "SlowPlayer_3")
    {
        SetPlayerMoveSpeedMul(0.25f);
        StartScreenShake(0.075f, 0, 2, 2);
        PlaySoundAtEntity("Scaaaawycreaks", "00_creak.snt", "Player", 2.0f, false);
    }
    
    if(asTimer == "StopThescaaaawycreaks")
    {
        StopSound("Scaaaawycreaks", 2.0f);
    }
    if(asTimer == "ZoomScare")
    {
        SetPlayerActive(false);
        FadePlayerFOVMulTo(0.0001f, 4.0f);
        SetPropActiveAndFade("ThisGuy", true, 1);
        PlaySoundAtEntity("WallStomp", "scare_wall_stomp.snt", "Player", 0.0f, false);
        FadeImageTrailTo(3.0f, 10.0f);
    }
    
    if(asTimer == "HeartBeat_1")
    {
        PlaySoundAtEntity("Heartbeat", "sanity_heartbeat.snt", "Player", 0.0f, false);
    }
    
    if(asTimer == "Fade")
    {
        AddDebugMessage("FADE", false);
        FadeImageTrailTo(10.0f, 10.0f);
    }
    
    if(asTimer == "ClearAndFadeOut")
    {
        StopPlayerLookAt();
        SetEntityActive("ThisGuy", false);
        AddDebugMessage("CLEAR", false);
        FadePlayerFOVMulTo(1.0f, 10.0f);
        SetPlayerMoveSpeedMul(1.0f);
        FadeImageTrailTo(0.0f, 1.0f);
        SetPlayerLookSpeedMul(1.0f);
    }
    
    if(asTimer == "SetPlayerActive")
    {
        AddDebugMessage("ACTIVE", false);
        SetPlayerActive(true);
    }
}
void PlayerInteractSecretPassage(string &in asEntity)
{
    AddLocalVarInt("PassageHitCount", 1);
    AddTimer("TimerDecreaseHitCount", 0.5f, "TimerDecreaseHitCount");    
    
    if(GetTimerTimeLeft("PassageBreakMessagePaused")==0)
    {
        PlayGuiSound("impact_rock_low3.ogg", 1.0f);
        PlayGuiSound("15_rock_break", 0.7f);
    }
    
    int lInteractedCount = GetLocalVarInt("PassageHitCount");
    
    int lDebrisArea = RandInt(1, 4);
    CreateParticleSystemAtEntity("PSPassageDebris"+lDebrisArea, "ps_dust_impact.ps", "PassageInteractDebris_"+lDebrisArea, false);
    
    AddDebugMessage("Adding debris PS to PassageInteractDebris_"+lDebrisArea, false);
    
    if(lInteractedCount==3)
    {
        SetPropHealth("mansionbase_secret_passage_1", 0);
    }
}
void TimerDecreaseHitCount(string &in asTimer)
{
    AddLocalVarInt("PassageHitCount", -1);
}
    
    
void OnStart()
{
    ///////////////////
    //KIANDRA'S ROOMS//
    ///////////////////
    SetEntityConnectionStateChangeCallback("lever_small01_1", "func_unlock");
    SetEntityConnectionStateChangeCallback("lever_simple01_1", "func_unlock");
    SetEntityConnectionStateChangeCallback("lever_small01_2", "func_unlock");
    
    //////////////////////
    //Romulator's Map(s)//
    //////////////////////
    AddEntityCollideCallback("Player", "ScrStopMusic", "stop_the_music", false, 1);
    
    ///////////////////
    //Nikson's Rooms//
    ///////////////////
    AddEntityCollideCallback("Player", "ScrMus", "func_mus", false, 1);
    SetEntityConnectionStateChangeCallback("lever_simple01_2","func_secret_door");
    ///////////////////
    //Flawless' Rooms//
    ///////////////////
    AddEntityCollideCallback("Player", "AreaStopMusic_1", "FlawlessStopMusic", true, 1);
    AddEntityCollideCallback("Player", "AreaNotScareAtAll_1", "FlawlessNonSuspiciousScare", true, 1);
    for(int i=1;i<=7;i++) AddEntityCollideCallback("rock_small_"+i, "mansionbase_secret_passage_1", "CollideHint", true, 1);
}
void Intro()
{
}
void OnEnter()
{
    
}
void OnLeave()
{
    //////////////////////
    //Romulator's Map(s)//
    //////////////////////
    
    //Just in case someone leaves while the music is playing
    
    //Because there will be a time where someone flips their table, screams "ALRIGHT, I'M OUT!!!", and then leaves... -Flawless
    StopMusic(5.0f, 7);    
}