void OnStart()
{


PreloadSound("locked_door.snt");
PreloadSound("scare_wall_stomp.snt");
PreloadParticleSystem("ps_hit_wood.ps");

SetPlayerMoveSpeedMul(1.0);


  	if(ScriptDebugOn())
	{
		
		GiveItemFromFile("lantern", "lantern.ent");
		for(int i=0;i<10;i++) GiveItemFromFile("tinderbox_"+i, "tinderbox.ent");
		
		GiveItem("stone_hammer_chipper", "Puzzle", "stone_hammer_chipper", "stone_hammer_chipper.tga", 0);	
		GiveItem("stone_hammer", "Puzzle", "stone_hammer", "stone_hammer.tga", 0);	
	}
	
	PlaySoundAtEntity("waterflow1", "20_water_stream_med.snt", "AreaWaterFlow_1", 0, true);

	SetEntityConnectionStateChangeCallback("valve_1", "WaterFlow");
     
	AddEntityCollideCallback("Player", "spawn_monster", "monsterspawn", true, 1);
	
	 
//pre-monster scare
AddEntityCollideCallback("Player", "door_jiggle", "doorjiggle1", true, 1);
AddEntityCollideCallback("Player", "door_jiggle_2", "doorjiggle2", true, 1);

//Transition
AddEntityCollideCallback("Player", "to_01", "to01", false, 1);
AddEntityCollideCallback("Player", "to_01b", "to01b", false, 1);

//Monster
AddEnemyPatrolNode("monster_1", "PathNodeArea_1", 1.0f, "");
AddEnemyPatrolNode("monster_1", "PathNodeArea_2", 1.0f, "");
AddEnemyPatrolNode("monster_1", "PathNodeArea_3", 1.0f, "");
AddEnemyPatrolNode("monster_1", "PathNodeArea_4", 1.0f, "");
AddEnemyPatrolNode("monster_1", "PathNodeArea_5", 1.0f, "");
AddEnemyPatrolNode("monster_1", "PathNodeArea_6", 1.0f, "");
AddEnemyPatrolNode("monster_1", "PathNodeArea_7", 1.0f, "");
AddEnemyPatrolNode("monster_1", "PathNodeArea_8", 1.0f, "");
AddEnemyPatrolNode("monster_1", "PathNodeArea_9", 1.0f, "");
AddEnemyPatrolNode("monster_1", "PathNodeArea_10", 1.0f, "");
AddEnemyPatrolNode("monster_1", "PathNodeArea_11", 1.0f, "");
AddEnemyPatrolNode("monster_1", "PathNodeArea_12", 1.0f, "");
AddEnemyPatrolNode("monster_1", "PathNodeArea_13", 1.0f, "");

//PigScare
SetEntityPlayerInteractCallback("pig_scare", "pigscare", true);

//Lock Puzzle


//ROCK PUZZLE
AddEntityCollideCallback("Player", "rockwall_quest", "rockwall_quest_1", false, 1);
AddUseItemCallback("hammerchipperuse1", "stone_hammer_chipper", "break_rock_4", "BeginHammer", true);
}

void WaterFlow(string &in asEntity, int alState)
{
    if(alState == 1) {
	StopSound("waterflow1", 5.0);
	SetWheelStuckState("valve_1", 1, false);
	PlaySoundAtEntity("waterflow2", "20_water_stream_med.snt", "AreaWaterFlow_2", 5.0, true);
	
	AddDebugMessage("Stopped wheel, Monster active", false);
	
	SetEntityActive("spawn_monster", true);
	SetEntityActive("to_01b", true);
	SetEntityActive("to_01", false);
	SetupLoadScreen("LoadingText", "monster", 0, "screen3.jpg");
	SetLevelDoorLocked("to_sewer", true);
	SetLevelDoorLockedText("to_sewer", "Locked", "Barred");
	SetLevelDoorLocked("to_pumps", true);
	SetLevelDoorLockedText("to_pumps", "Locked", "Barred");


	
	}
	
}	


///---HAMMER AND CHIPPER PUZZLE---///


void BeginHammer(string &in asItem, string &in asEntity)
{
SetEntityActive("stone_hammer_move_1", true);
SetEntityActive("stone_chipper_move_1", true);

SetMoveObjectState("stone_hammer_move_1", 0.40f);

//First Hit
AddTimer("hammer1", 0.40f, "Hit");
AddTimer("chipper1", 0.60f, "Hit");
AddTimer("hammerback1", 1.0f, "Hit");
AddTimer("chipperback1", 1.0f, "Hit");

//Second Hit
AddTimer("hammer2", 1.40f, "Hit");
AddTimer("chipper2", 1.60f, "Hit");
AddTimer("hammerback2", 2.0f, "Hit");
AddTimer("chipperback2", 2.0f, "Hit");

//Third Hit
AddTimer("hammer3", 2.40f, "Hit");
AddTimer("chipper3", 2.60f, "Hit");
AddTimer("hammerback3", 3.0f, "Hit");
AddTimer("chipperback3", 3.0f, "Hit");

//Fourth Hit
AddTimer("hammer4", 3.40f, "Hit");
AddTimer("chipper4", 3.60f, "Hit");

//End
AddTimer("EndChipperPuzzle", 3.70f, "Hit");
}

void Hit(string &in asTimer)
{

 //FIRST HIT
 if(asTimer == "hammer1") {
 PlaySoundAtEntity("place", "player_crouch.snt", "Player", 0, false);
 SetPlayerActive(false);
 FadeLightTo("HintLight_1", 0, 0, 0, 0, 0, 0);
 StartPlayerLookAt("stone_chipper_move_1", 2, 2, "");
 SetMoveObjectState("stone_hammer_move_1", 0);
 }

 else if(asTimer == "chipper1") {
 CreateParticleSystemAtEntity("impact1", "ps_hit_rock.ps", "stone_chipper_move_1", false);
 PlaySoundAtEntity("impact1", "15_hammer.snt", "stone_hammer_move_1", 0, false);
 SetMoveObjectState("stone_chipper_move_1", 1);
 }
 
 else if(asTimer == "hammerback1") {
 SetMoveObjectState("stone_hammer_move_1", 0.40f);
 }
 
 else if(asTimer == "chipperback1") {
 SetMoveObjectState("stone_chipper_move_1", 0);
 }
 //FIRST HIT
 
 //SECOND HIT
 else if(asTimer == "hammer2") {
 SetMoveObjectState("stone_hammer_move_1", 0);
 }
 
 else if(asTimer == "chipper2") {
 CreateParticleSystemAtEntity("impact2", "ps_hit_rock.ps", "stone_chipper_move_1", false);
 PlaySoundAtEntity("impact2", "15_hammer.snt", "stone_hammer_move_1", 0, false);
 SetMoveObjectState("stone_chipper_move_1", 1);
 }
 
 else if(asTimer == "hammerback2") {
 SetMoveObjectState("stone_hammer_move_1", 0.40f);
 }
 
 else if(asTimer == "chipperback2") {
 SetMoveObjectState("stone_chipper_move_1", 0);
 }
 //SECOND HIT
 
 //THIRD HIT
  else if(asTimer == "hammer3") {
 SetMoveObjectState("stone_hammer_move_1", 0);
 }
 
 else if(asTimer == "chipper3") {
 CreateParticleSystemAtEntity("impact3", "ps_hit_rock.ps", "stone_chipper_move_1", false);
 PlaySoundAtEntity("impact3", "15_hammer.snt", "stone_hammer_move_1", 0, false);
 SetMoveObjectState("stone_chipper_move_1", 1);
 }
 
  else if(asTimer == "hammerback3") {
 SetMoveObjectState("stone_hammer_move_1", 0.40f);
 }
 
 else if(asTimer == "chipperback3") {
 SetMoveObjectState("stone_chipper_move_1", 0);
 }
  //THIRD HIT
  
  //FOURTH HIT
 else if(asTimer == "hammer4") {
 SetMoveObjectState("stone_hammer_move_1", 0);
 }
 
 else if(asTimer == "chipper4") {
 CreateParticleSystemAtEntity("impact3", "ps_hit_rock.ps", "stone_chipper_move_1", false);
 PlaySoundAtEntity("impact3", "15_hammer.snt", "stone_hammer_move_1", 0, false);
 SetMoveObjectState("stone_chipper_move_1", 1);
 }
 //FOURTH HIT
 
 //END
 else if(asTimer == "EndChipperPuzzle") {
 SetEntityActive("break_rock_*", false);
 SetEntityActive("stone_hammer_move_1", false);
 SetEntityActive("stone_chipper_move_1", false);
 SetEntityActive("broken_rock_*", true);
 
 PlaySoundAtEntity("break1", "03_break_wall.snt", "AreaBreak_1", 0, false);
 
 CreateParticleSystemAtEntity("breakdust1", "ps_break_mansionbase_wall.ps", "AreaBreak_1", false);
 CreateParticleSystemAtEntity("breakdust1", "ps_break_mansionbase_wall.ps", "AreaBreak_2", false);
 CreateParticleSystemAtEntity("breakdust1", "ps_break_mansionbase_wall.ps", "AreaBreak_3", false);
 
 GiveSanityBoost();
 
 StopPlayerLookAt();
 SetPlayerActive(true);
 CompleteQuest("rockwall", "RockwallQuest");
 }
 //END
  
}

///---HAMMER AND CHIPPER PUZZLE---///
              //END//

//Level Transition
void to01(string &in asParent, string &in asChild, int alState)
{
ChangeMap("01a_aztec.map", "from_02", "", ""); 
}

void to01b(string &in asParent, string &in asChild, int alState)
{
ChangeMap("01b_aztec.map", "from_02", "", ""); 
}


//SCARY STUFF
void doorjiggle1(string &in asParent, string &in asChild, int alState)
{
PlaySoundAtEntity("", "locked_door.snt", "monster_door", 0.0, false);
PlaySoundAtEntity("", "scare_wall_stomp.snt", "monster_door", 0.0, false);
}

void doorjiggle2(string &in asParent, string &in asChild, int alState)
{
PlaySoundAtEntity("", "locked_door.snt", "monster_door", 0.0, false);
PlaySoundAtEntity("", "scare_wall_stomp.snt", "monster_door", 0.0, false);
CreateParticleSystemAtEntity("particle22", "ps_hit_wood.ps", "monster_door", false);
}

void monsterspawn(string &in asParent, string &in asChild, int alState)
{
SetEntityActive("monster1", true);
SetPropHealth("monster_door", 0.0);
ShowEnemyPlayerPosition("monster1");
AddTimer("monsterpatrol", 2.0f, "MonsterTimer");
}

void MonsterTimer(string &in asTimer)
{
AddEnemyPatrolNode("monster1", "PathNodeArea_1", 1.0f, "");
AddEnemyPatrolNode("monster1", "PathNodeArea_2", 1.0f, "");
AddEnemyPatrolNode("monster1", "PathNodeArea_3", 1.0f, "");
AddEnemyPatrolNode("monster1", "PathNodeArea_4", 1.0f, "");
}


void rockwall_quest_1(string &in asParent, string &in asChild, int alState)
{
AddQuest("rockwall", "RockwallQuest");
}

void pigscare(string &in asEntity)
{
PlaySoundAtEntity("", "pig.snt", "Player", 0.0, false);
GiveSanityDamage(25.0, true);
}


//Rock Puzzle


///---PADLOCK BREAK---///

void breaklock(string &in asItem, string &in asEntity)
{
SetEntityActive("stone_hammer_move_2", true);

SetMoveObjectState("stone_hammer_move_2", 0.40f);

StartPlayerLookAt("stone_hammer_move_2", 2, 2, "");

SetPlayerActive(false);

AddTimer("breaklock1", 0.5f, "Hit2");
AddTimer("breaklock2", 1.0f, "Hit2");
AddTimer("breaklock3", 1.5f, "Hit2");
AddTimer("breaklock4", 2.0f, "Hit2");
AddTimer("breaklock5", 2.5f, "Hit2");
AddTimer("BrokenPadlock", 2.75f, "Hit2");
}

void Hit2(string &in asTimer)
{

  if(asTimer == "breaklock2") {
  SetMoveObjectState("stone_hammer_move_2", 0.40f);
  }
  
  else if(asTimer == "breaklock3") {
  SetMoveObjectState("stone_hammer_move_2", 0);
  CreateParticleSystemAtEntity("spark1", "ps_hit_metal.ps", "padlock_acid_1", false);
  PlaySoundAtEntity("Player", "impact_metal_high.snt", "Player", 0, false);
  }

  else if(asTimer == "breaklock1") {
  SetMoveObjectState("stone_hammer_move_2", 0);
  CreateParticleSystemAtEntity("spark1", "ps_hit_metal.ps", "padlock_acid_1", false);
  PlaySoundAtEntity("Player", "impact_metal_high.snt", "Player", 0, false);
  }
  
  else if(asTimer == "breaklock4") {
  SetMoveObjectState("stone_hammer_move_2", 0.40f);
  }
  
  else if(asTimer == "breaklock5") {
  SetMoveObjectState("stone_hammer_move_2", 0);
  CreateParticleSystemAtEntity("spark1", "ps_hit_metal.ps", "padlock_acid_1", false);
  PlaySoundAtEntity("Player", "impact_metal_high.snt", "Player", 0, false);
  }
  
  else if(asTimer == "BrokenPadlock") {
  GiveSanityBoostSmall();
  SetPlayerActive(true);
  StopPlayerLookAt();
  
  CreateParticleSystemAtEntity("brokenpaddust", "ps_break_wood_small.ps", "padlock_acid_1", false);
  
  PlaySoundAtEntity("brokepadlock", "pickaxe_hit.snt", "padlock_acid_1", 0, false);
  PlaySoundAtEntity("brokepadlock1", "unlock_door.snt", "to_pumps", 0, false);
  SetupLoadScreen("LoadingText", "tower1", 0, "screen2.jpg");
  
  SetLevelDoorLocked("to_pumps", false);
  
  SetEntityActive("padlock_acid_1", false);
  SetEntityActive("padlock_broken_1", true);
  
  AddTimer("removehammer2", 0.5f, "Hit2");
  }
  
  else if(asTimer == "removehammer2") {
  SetEntityActive("stone_hammer_move_2", false);
  }


}

///---PADLOCK BREAK END---///




void OnEnter()
{

PlayMusic("06_amb.ogg", true, 1.0, 0.5, 0, true);
AddUseItemCallback("", "stone_hammer", "padlock_acid_1", "breaklock", true);
}
