////////////////////////////
// Run first time starting map
void OnStart()

{	
	AddUseItemCallback("", "hollow_needle_1", "mansion_2", "UsedKeyOnDoor", true);
	AddUseItemCallback("", "key_tomb_rusty_1", "castle_1", "UsedKeyOnDoor_2", true);
	AddUseItemCallback("", "key_torture_chamber_1", "mansion_4", "UsedKeyOnDoor_3", true);
	AddEntityCollideCallback("Player", "PlayerCollide", "MonsterFunction", true, 1);
	AddEntityCollideCallback("servant_grunt_1", "MonsterEnd", "MonsterEnd", true, 1);
	AddEntityCollideCallback("Player", "RoomTwoArea", "CollideRoomTwo", true, 1);
	SetEntityConnectionStateChangeCallback("lever_small01_min_1", "func_shelf");
	AddEntityCollideCallback("Player", "script_slam", "func_slam", true, 1);
	AddTimer("tmrIntro", 0.0f, "introSequence");
	AddEntityCollideCallback("Player", "Regen", "PlaySound1", true, 1);
	AddEntityCollideCallback("Player", "Stampfen", "PlaySound2", true, 1);
	AddEntityCollideCallback("Player", "Angst", "PlaySound3", true, 1);
	AddEntityCollideCallback("crowbar_joint_1", "AreaBreakBoards_1", "BreakBoards", true, 1);
	AddUseItemCallback("crowbar_1", "crowbar_1", "wooden_boards_block_1", "AttatchCrowbar", true);
	AddEntityCollideCallback("Player", "Schrank", "Schrank_1", true, 1);
	AddUseItemCallback("", "key_torture_chamber_2", "level_cistern_1", "UsedKeyOnDoor_1", true);
	AddEntityCollideCallback("Player", "Fass", "Fass", true, 1);
	PlayMusic("06_amb.ogg", true, 1.0f, 0.0f, 2, true);
	SetEntityPlayerInteractCallback("note_paper01_3", "Dolchquest", true);
}

void MonsterFunction(string &in asParent, string &in asChild, int alState)

{

	
	SetEntityActive("servant_grunt_1", true); 
	AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_2", 0, "");
	AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_3", 0, "");
	AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_4", 0, "");
	AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_5", 0, "");
	AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_6", 0, "");
	AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_7", 0, "");
	AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_8", 0, "");
	AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_10", 0, "");
	AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_11", 0, "");
	AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_12", 0, "");
	CheckPoint("", "PlayerStartArea_2", "", "", "");
	
}

void UsedKeyOnDoor(string &in asItem, string &in asEntity)

{
    SetSwingDoorLocked("mansion_2", false, true);
    PlaySoundAtEntity("", "unlock_door", "mansion_2", 0, false);
    RemoveItem("hollow_needle_1");
}


void MonsterEnd(string &in asParent, string &in asChild, int alState)

{
	SetEntityActive("servant_grunt_1", false);
}
void UsedKeyOnDoor_2(string &in asItem, string &in asEntity)

{

    SetSwingDoorLocked("castle_1", false, true);
    PlaySoundAtEntity("", "unlock_door", "castle_1", 0, false);
    RemoveItem("key_tomb_rusty_1");
}
void UsedKeyOnDoor_3(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked("mansion_4", false, true);
    PlaySoundAtEntity("", "unlock_door", "mansion_4", 0, false);
    RemoveItem("key_torture_chamber_1");
}
void CollideRoomTwo(string &in asParent, string &in asChild, int alState)
{
StartPlayerLookAt("castle_1", 7.0f, 10.0f, "");
AddTimer("", 1.0f, "stoplook");
}
void stoplook(string &in asTimer)
{
StopPlayerLookAt();
}

void func_shelf(string &in asEntity, int alState)
{
if (alState == 1)

{
SetMoveObjectState("shelf_secret_door_rot_1",1.0f);
PlaySoundAtEntity("", "quest_completed.snt", "shelf_move_1", 0, false);
return;
}
}
 
void func_slam(string &in asParent, string &in asChild, int alState)
{
SetSwingDoorClosed("castle_1", true, true);
 
PlaySoundAtEntity("", "react_breath_slow.snt", "Player", 0, false); 
 
PlaySoundAtEntity("", "react_scare", "Player", 0, false);  
PlaySoundAtEntity("", "close_door.snt", "Player", 0, false);

GiveSanityDamage(5.0f, true);
}
void introSequence(string &in asTimer)
{
	AddLocalVarInt("iIntroPart", 1); 
	float partSpeed = 0.0f;
	switch (GetLocalVarInt("iIntroPart"))
	{ 
	case 1:
			partSpeed = 14.0f; 
			FadeOut(0.0f);
			FadePlayerRollTo(90, 150, 150);
			SetPlayerActive(false);
			SetPlayerCrouching(true);
			FadeIn(40.0f);
	break;
	case 2:		
			partSpeed = 10.0f; 
			FadePlayerRollTo(0.0f, 33.0f, 33.0f); 
			SetPlayerActive(true);
			SetPlayerCrouching(false);
	break;
		
		}
		if (GetLocalVarInt("iIntroPart") <2) 
	{
		
		AddTimer("tmrIntro", partSpeed, "introSequence");
	}
}
void PlaySound1(string &in asParent, string &in asChild, int alState)
{
PlaySoundAtEntity("", "general_rain.snt", "Player", 0, false);
}
void PlaySound2(string &in asParent, string &in asChild, int alState)
{
PlaySoundAtEntity("", "scare_steps_big.snt", "Player", 0, false);
}
void PlaySound3(string &in asParent, string &in asChild, int alState)
{
PlaySoundAtEntity("", "enabled.snt", "Player", 0, false);
AddQuest("eisenquest", "eisen");
}


void AttatchCrowbar(string &in asItem, string &in asEntity)
{
SetEntityActive("crowbar_joint_1", true);

SetSwingDoorLocked("metal_1", false, true);

PlaySoundAtEntity("", "player_crouch.snt", "crowbar_joint_1", 0, false);





RemoveItem(asItem);
}

void BreakBoards(string &in asParent, string &in asChild, int alState)
{
SetEntityActive("crowbar_broken_1", true);
SetEntityActive("crowbar_joint_1", false);
CompleteQuest("eisenquest", "eisen");
PlaySoundAtEntity("", "ui_sanity_gain.snt", "Player", 0, false);
StartEffectFlash(1.0f, 1.0f, 1.0f);
SetPropHealth("wooden_boards_block_1", 0.0);
}
void Schrank_1(string &in asParent, string &in asChild, int alState)
{
AddBodyForce("cabinet_Body_2", 0, 0, 2000, "world");
AddBodyForce("cabinet_Body_1", 0, 0, 2000, "world");
PlaySoundAtEntity("", "react_scare.snt", "Player", 0, false);
PlaySoundAtEntity("", "24_iron_maiden.snt", "Player", 0, false);
GiveSanityDamage(25.0f, true);
}

void UsedKeyOnDoor_1(string &in asItem, string &in asEntity)
{
SetLevelDoorLocked("level_cistern_1", false);
PlaySoundAtEntity("", "unlock_door", "level_cistern_1", 0, false);
RemoveItem("key_torture_chamber_2");
}

void Fass(string &in asParent, string &in asChild, int alState)
{
SetEntityActive("corpsemale1", true);
AddBodyForce("corpsemale1_Body_1", 0, 0, 50000, "world");
AddBodyForce("corpsemale1_Body_13", 0, 0, 50000, "world");
AddBodyForce("corpsemale1_Body_4", 0, 0, 50000, "world");
AddBodyForce("corpsemale1_Body_8", 0, 0, 50000, "world");
AddBodyForce("corpsemale1_Body_12", 0, 0, 50000, "world");
PlaySoundAtEntity("", "24_iron_maiden.snt", "Player", 0, false);
GiveSanityDamage(25.0f, true);
}


void gehauf(string &in entity)
{
    if(GetSwingDoorLocked("mansion_4") == true)
    {
        SetMessage("Messages", "aufmachen", 0);
    }
}

void Dolchquest(string &in asEntity)
{
AddQuest("hauptquest", "hauptquestlos");
}


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

}

////////////////////////////
// Run when leaving map
void OnLeave()
{

}