void OnStart()
{
PreloadSound("enabled.snt");
PreloadSound("general_rock_rumble.snt");



    AddEnemyPatrolNode("grunt_1", "PathNodeArea_8", 0, "");

    
	SetEntityPlayerInteractCallback("stone_chipper", "LimbScare", true);
	
	SetEntityPlayerLookAtCallback("grunt_1", "SanDamage", true);
	
    AddEntityCollideCallback("grunt_1", "AreaNoGrunt_1", "SpawnGrunt", true, 1);
    AddEntityCollideCallback("Player", "AreaKillPlayer_1", "PlayerDead", false, 1);
    AddEntityCollideCallback("Player", "AreaCheckPoint_1", "CheckPoint1", true, 1);
    AddEntityCollideCallback("Player", "AreaGruntTrigger_1", "SpawnGrunt", true, 1);
    AddEntityCollideCallback("Player", "AreaBeginRumble_1", "Rumble", true, 1);
    AddEntityCollideCallback("rock_1", "AreaBreakRock_1", "SmashSewer", true, 1);
    AddEntityCollideCallback("torso_1", "AreaScareLook_1", "SanDamageCol", true, 1);
	AddEntityCollideCallback("Player", "AreaRest", "AreaResetSpeed1", false, 0);

	FadeLightTo("Light_chipper", 0, 0, 0, 0, -1, 0);

     if(ScriptDebugOn()) {
   GiveItemFromFile("lantern", "lantern.ent");
 
   for(int i=0;i<10;i++) GiveItemFromFile("tinderbox_"+i, "tinderbox.ent");
   } 

}

void CheckPoint1(string &in asParent, string &in asChild, int alState)
{

CheckPoint("check1", "PlayerStartArea_2", "", "", "");

}


void PlayerDead(string &in asParent, string &in asChild, int alState)
{

GivePlayerDamage(200.0, "BloodSplat", true, true);

}

///---SMASH PUZZLE---///

void SmashSewer(string &in asParent, string &in asChild, int alState)
{

SetEntityActive("sewer_grate", false);
SetEntityActive("AreaGruntTrigger_1", true);
SetEntityActive("sewer_grate_broken", true);

FadeLightTo("Light_chipper", 0.6, 0.4, 0.6, 1, -1, 1.0f);

SetEntityActive("stone_chipper", true);
SetEntityActive("stone_chipper_fake", false);
SetEntityActive("stone_1", true);
SetEntityActive("stone_2", true);
SetEntityActive("stone_3", true);

CreateParticleSystemAtEntity("dust", "ps_break_mansionbase_wall.ps", "AreaCrashBoom_1", false);

PlaySoundAtEntity("smash", "break_wood_metal.snt", "AreaCrashBoom_1", 0, false);

GiveSanityBoostSmall();

}

///---SMASH PUZZLE END---///

///---SCARES---///

void SpawnGrunt(string &in asParent, string &in asChild, int alState)
{

  if(asChild == "AreaGruntTrigger_1") {
  SetEntityActive("grunt_1", true);
  SetEntityActive("blood_1", true);
  SetEntityActive("blood_2", true);
  SetEntityActive("blood_3", true);
  SetEntityActive("blood_4", true);
  SetEntityActive("arm_1", true); 
  

  }
  
  else if(asChild == "AreaNoGrunt_1") {
  SetEntityActive("grunt_1", false);
  
  SetPlayerMoveSpeedMul(1.0f);
  }
  
}  

void LimbScare(string &in asEntity)
{
	GiveSanityBoostSmall();

	FadeLightTo("Light_chipper", 0, 0, 0, 0, -1, 0);
	
    SetEntityActive("torso_1", true);
	SetEntityActive("leg_1", true);
	SetEntityActive("arm_2", true);	
	SetEntityActive("AreaBeginRumble_1", true);
}	

void SanDamage(string &in entity, int alState)
{
   
   if(entity == "grunt_1") {
   
   GiveSanityDamage(5.0, true);
   
   PlaySoundAtEntity("scare", "react_scare.snt", "Player", 0, false);
   }  
   
}   

void SanDamageCol(string &in asParent, string &in asChild, int alState)
{
   GiveSanityDamage(5.0, true);
   
   SetEntityActive("blood_5", true);
   SetEntityActive("blood_6", true);
   
   CreateParticleSystemAtEntity("blood", "ps_blood_drop.ps", "AreaBloodDrip_1", true);
   CreateParticleSystemAtEntity("blood2", "ps_blood_drop.ps", "AreaBloodDrip_2", true);
   CreateParticleSystemAtEntity("blood3", "ps_blood_drop.ps", "AreaBloodDrip_3", true);
   CreateParticleSystemAtEntity("blood4", "ps_blood_drop.ps", "AreaBloodDrip_4", true);
   
   PlaySoundAtEntity("scare2", "react_scare.snt", "Player", 0, false);
   
   PlayMusic("15_event_prisoner", false, 1.0, 0.5, 0, false);
   
   AddTimer("rawr", 1.5, "Moan");
   AddTimer("MusicReset", 14.0, "Moan");
  
}

void Moan(string &in asTimer)
{

    if(asTimer == "rawr") {
	PlaySoundAtEntity("moan", "enabled.snt", "AreaMoan_1", 0, false);
    }
	
	else if(asTimer == "MusicReset") {
	PlayMusic("18_amb.ogg", true, 1.0, 0.5, 0, true);
	}
	
	else if(asTimer == "stoprumble") {
	StopSound("rumble", 1.0);
	}
	
	else if(asTimer == "resetspeed") {
	SetPlayerMoveSpeedMul(1.0f);
	}
	
	else if(asTimer == "rubble1") {
	SetEntityActive("rubble_1", true);
	AddPropImpulse("rubble_1", 0, -5, 0, "world");
	}
	
	else if(asTimer == "rubble2") {
	SetEntityActive("rubble_2", true);
	AddPropImpulse("rubble_2", 0, -5, 0, "world");
	}
	
	else if(asTimer == "rubble3") {
	SetEntityActive("rubble_3", true);
	AddPropImpulse("rubble_3", 0, -5, 0, "world");
	}
	
	else if(asTimer == "rubble4") {
	SetEntityActive("rubble_4", true);
	AddPropImpulse("rubble_4", 0, -5, 0, "world");
	}

}

void Rumble(string &in asParent, string &in asChild, int alState)
{

PlaySoundAtEntity("rumble", "general_rock_rumble.snt", "AreaRumbleSound_1", 1.0, false);

CreateParticleSystemAtEntity("dustrumble1", "ps_dust_falling_rumble.ps", "AreaRumble_1", false);
CreateParticleSystemAtEntity("dustrumble2", "ps_dust_falling_rumble.ps", "AreaRumble_2", false);
CreateParticleSystemAtEntity("dustrumble3", "ps_dust_falling_rumble.ps", "AreaRumble_3", false);
CreateParticleSystemAtEntity("dustrumble4", "ps_dust_falling_rumble.ps", "AreaRumble_4", false);


StartScreenShake(0.08f, 10.0, 1.5, 1.0);

AddTimer("stoprumble", 10.0, "Moan");
AddTimer("resetspeed", 10.0, "Moan");

AddTimer("rubble1", 3.5, "Moan");
AddTimer("rubble2", 4.5, "Moan");
AddTimer("rubble3", 1.5, "Moan");
AddTimer("rubble4", 2.0, "Moan");
}

///---SCARES END---///


void OnEnter()
{

PlayMusic("18_amb.ogg", true, 1.0, 0, 0, true);

}

void AreaResetSpeed(string &in asParent, string &in asChild, int alState)
{
SetPlayerMoveSpeedMul(1.0f);
}

void OnLeave()
{
SetPlayerMoveSpeedMul(1.0);
SetupLoadScreen("LoadingText", "tower2", 0, "screen1.jpg");
}