dofile("script/layouts/room1_defaults.lua")
dofile("script/shifts/shift1_3_animations.lua")

levelDesc.name = "Shift 1.3"
levelDesc.levelId = 13
levelDesc.musicMood = "3"
levelDesc.trigger =
{
	class = "TriggerSystem",
	triggers =
	{
		{ trigger = "spawn", delay=1000, hearts=2, diseaseDesc = { class="Disease", steps={"DRESSING_ROOM", "MEASURE_BLOOD_PRESSURE", } } },
		{ trigger = "spawn", delay=20000, hearts=3, diseaseDesc = { class="Disease", steps={"STETHOSCOPE"} } },
		{ trigger = "spawn", delay=15000, hearts=3, diseaseDesc = { class="Disease", steps={"PUT_ON_BANDAID"} } },
		{ trigger = "spawn", delay=10000, hearts=3, diseaseDesc = { class="Disease", steps={"FIND_SORE_SPOT"} } },
		{ trigger = "startEvent", delay=8000, },
		{ trigger = "spawn", delay=10000, hearts=3, diseaseDesc = { class="Disease", steps={"PUT_ON_BANDAID"} } },
		{ trigger = "spawn", delay=7000, hearts=2, diseaseDesc = { class="Disease", steps={"DRESSING_ROOM", "STETHOSCOPE", "CHECK_UP"} } },
		{ trigger = "spawn", delay=25000, hearts=3, diseaseDesc = { class="Disease", steps={"MEASURE_BLOOD_PRESSURE"} } },
		{ trigger = "spawn", delay=15000, hearts=3, diseaseDesc = { class="Disease", steps={"PUT_ON_BANDAID"} } },
		{ trigger = "spawn", delay=5000, hearts=3, diseaseDesc = { class="Disease", steps={"CHECK_UP"} } },
		{ trigger = "spawn", delay=25000, hearts=3, diseaseDesc = { class="Disease", steps={"FIND_SORE_SPOT"} } },
		{ trigger = "spawn", delay=7000, hearts=3, diseaseDesc = { class="Disease", steps={"DRESSING_ROOM", "MEASURE_BLOOD_PRESSURE"} } },
		{ trigger = "spawn", delay=15000, hearts=3, diseaseDesc = { class="Disease", steps={"CHECK_UP"} } },
	}
}

levelDesc.patientList =
{
	p0 = { weight = 50,
		base = "local_male",
	},
	p1 = { weight = 50,
		base = "lady",
	},
	p2 = { weight = 25,
		base = "boy",
	},
	p3 = { weight = 25,
		base = "teen",
	},
	p1 = { weight = 50,
		base = "mother",
	},
}

function levelDesc.checkPreconditions(event)
	local obj = level:getChild("researchtable_2")
	if (obj) then
		if (not obj.occupied) then
			levelDesc.swapTable(self)
			return true
		end
	else
		obj = level:getChild("event_table")
		if (obj)then
			levelDesc.swapTable(self)
			return true
		end
	end
	return false
end

function levelDesc.eventFinished(event)
--print("finish")
	local rTable2 = level:getObject("researchtable_2")
	if (rTable2) then
		rTable2:setMaxOccupants(1)
		rTable2:setVisible(true)
		level:getObject("event_table").visible = false
	end

	local staph = level:getObject("staph")
	staph.floor = 60
	staph.y = staph.y + 75
	if (isTable(taskSystem:getAnimationDesc("eventWon"))) then
		return taskSystem:createAnimation("eventWon")
	end
end

levelDesc.eventDesc =
{
	class="GestureEvent",
	eventBarImage = "EVENTBAR_ICON_GESTURE:icons",
	gestureLocation = {x=500, y=500},
	doGestureObject = "event_table",
	checkPreconditions = levelDesc.checkPreconditions,
	eventFinished = levelDesc.eventFinished,
	gestures = {
		{desc=5, objectId="hero", animation="CREAM", gestureLocation={x=90, y=500}, timeBeforeStart=100},
		{desc=17, drainSpeed = 30, growSpeed=20, objectId="hero", animation="APPLYCREAM", gestureLocation={x=90, y=500}, timeBeforeStart=0},
		{desc=8, objectId="hero", animation="PLACEBANDAGE", gestureLocation={x=90, y=500}, timeBeforeStart=25000},
		{desc=5, objectId="hero", animation="WINDBANDAGE", gestureLocation={x=90, y=500}, timeBeforeStart=0},
		{desc=5, objectId="hero", animation="WINDBANDAGE", gestureLocation={x=90, y=500}, timeBeforeStart=0},
		{desc=5, objectId="hero", animation="WINDBANDAGE", gestureLocation={x=90, y=500}, timeBeforeStart=0},
		{desc=10, objectId="hero", animation="TAPEDOWN", gestureLocation={x=90, y=500}, timeBeforeStart=0},
	},
	scoreOneDone=1,
	scoreAllDone=1,
	hintTip = "bottomleft",
 }

function levelDesc:onInitialized(desc)
	CareLevel.onInitialized(self, desc)
	
	-- Create stretcher if there is no 2nd bed
	local desc = {
		class = "DoGestureObject",
		name="event_table",
		x=0,
		y = 529,
		floor = -106,
		baseAnimation = "ROOM1_EVENT_STRETCHER",
		workPos = {x=295, y=661},
		checkBoxPos= {x=35, y=127},
		visible=false,
		obstructs = {{x=5, y=7}, {x=6, y=7}, {x=7, y=7}, {x=8, y=7}, {x=9, y=7}, {x=10, y=7}, {x=11, y=7}, {x=12, y=7}, {x=13, y=7}, {x=14, y=7}, {x=15, y=7}, {x=16, y=7}, {x=17, y=7}, {x=18, y=7}, {x=19, y=7}, {x=20, y=7}, {x=21, y=7}, {x=22, y=7}, {x=23, y=7}, {x=24, y=7}, {x=25, y=7}, {x=26, y=7}, {x=27, y=7},
			{x=5, y=12}, {x=6, y=12}, {x=7, y=12}, {x=8, y=12}, {x=9, y=12}, {x=10, y=12}, {x=11, y=12}, {x=12, y=12}, {x=13, y=12}, {x=14, y=12}, {x=15, y=12}, {x=16, y=12}, {x=17, y=12}, {x=18, y=12}, {x=19, y=12}, {x=20, y=12}, {x=21, y=12}, {x=22, y=12}, {x=23, y=12}, {x=24, y=12}, {x=25, y=12}, {x=26, y=12}, {x=27, y=12}},
      }
	local obj = level:add(desc)

	if (level:getObject("researchtable_2") == nil) then
		obj.visible = true
	end
end


function levelDesc:swapTable()
	-- No table present, spawn a stretcher

	local rTable2 = level:getObject("researchtable_2")
	-- Remove original table
	if (rTable2) then
		-- Table present, set to occupied while patient is there
		rTable2:setMaxOccupants(0)
		rTable2:setVisible(false)
		local obj = level:getObject("event_table")
		obj.baseAnimation = rTable2.baseAnimation
		obj.visible = true
	end
end
