dofile("script/layouts/room3_defaults.lua")
dofile("script/shifts/shift3_2_animations.lua")

levelDesc.name = "Shift 3.2"
levelDesc.levelId = 32
levelDesc.musicMood = "4"
levelDesc.done = false
levelDesc.trigger =
{
	class = "TriggerSystem",
	triggers =
	{
		{ trigger = "spawn", delay=1, hearts=1, patient="p1", diseaseDesc = { class="Disease", steps={"TOILET", "GIVE_INJECTION", "SPATULA"} } },
		{ trigger = "spawn", delay=5000, hearts=3, patient="p3", diseaseDesc = { class="Disease", steps={"TOILET", "BANDAID",} } },
		{ trigger = "startEvent", delay=10000, },
		{ trigger = "spawn", delay=20000, hearts=1, diseaseDesc = { class="Disease", steps={"TOILET", "BANDAID", "SPATULA",} } },
		{ trigger = "spawn", delay=10000, hearts=3, patient="p2", diseaseDesc = { class="Disease", steps={"TOILET", "GIVE_INJECTION"} } },
		{ trigger = "spawn", delay=1000, hearts=3, diseaseDesc = { class="Disease", steps={"SPATULA",} } },
		{ trigger = "spawn", delay=10000, hearts=1, diseaseDesc = { class="Disease", steps={"GIVE_INJECTION", "SPATULA"} } },
		{ trigger = "spawn", delay=10000, hearts=2, patient="p4", diseaseDesc = { class="Disease", steps={"TOILET", "BANDAID"} } },
		{ trigger = "spawn", delay=15000, hearts=1, patient="p0", diseaseDesc = { class="Disease", steps={"TOILET", "BANDAID", "SPATULA"} } },
		{ trigger = "spawn", delay=25000, hearts=1, diseaseDesc = { class="Disease", steps={"GIVE_INJECTION", "SPATULA",} } },
		{ trigger = "spawn", delay=8000, hearts=2, diseaseDesc = { class="Disease", steps={"TOILET", "SPATULA",} } },
		{ trigger = "spawn", delay=8000, hearts=2, diseaseDesc = { class="Disease", steps={"TOILET", "GIVE_INJECTION",} } },
		{ trigger = "spawn", delay=20000, hearts=3, diseaseDesc = { class="Disease", steps={"SPATULA",} } },
		{ trigger = "spawn", delay=15000,  hearts=1, diseaseDesc = { class="Disease", steps={"TOILET", "BANDAID", "SPATULA"} } },
		{ trigger = "spawn", delay=10000, hearts=2, patient="p1", diseaseDesc = { class="Disease", steps={"GIVE_INJECTION", "SPATULA",} } },
		{ trigger = "spawn", delay=5000,  hearts=3, diseaseDesc = { class="Disease", steps={"BANDAID",} } },
		{ trigger = "spawn", delay=1000, hearts=3, patient="p5", diseaseDesc = { class="Disease", steps={"SPATULA",} } },
	}
}
levelDesc.patientList =
{
	p0 = { weight = 500,
		base = "boy",
	},
	p1 = { weight = 500,
		base = "boy2",
	},
	p2 = { weight = 500,
		base = "boy3",
	},
	p3 = { weight = 500,
		base = "girl",
	},
	p4 = { weight = 500,
		base = "girl2",
	},
	p5 = { weight = 500,
		base = "girl3",
	},
}

function levelDesc:onInitialized()
	local desc = {
		class = "CareCharacter",
		name="event_queue_girl",
		x = 640,
		y = 330,
		floor = -25,
		baseAnimation = "PARENTS_K",
		defaultAnimation = "HAPPY", direction="left",
		visible=false,
	}
	level:add(desc)
end

function levelDesc:onStart()
	local fixobj = level:getObject("EVENT_FIX_KID")
	local obj = level:getObject("event_queue_girl")
	obj.visible = false
	obj.alpha = 0.0
	fixobj.flipHorizontal = true
	local position = level.currentRoom.queueIn:getQueuePosition(0, 2)
	assert(position)
	obj:setQueueSpot(position)
	obj:addTask({class="SetTask", visible=false, clickable=false})
		fixobj:addTask({class="Task", duration=4225})
		fixobj:addTask({class="SetTask", visible=true, clickable=true})
    
	for _,v in pairs(level.event.items) do
		v.obj.clickable = true
		v.obj.visible = true
		hintManager:placeArrow({type="down", name="FixEvent", parent=level.dragLayer, x=v.obj.x + v.obj.width/2 - 10, y=v.obj.y})
	end

	eventBar:activate()
	level.event.hintFired = false
end

levelDesc.eventDesc =
{
	class="FixEvent",
	onStart = levelDesc.onStart,
	hideOnLose = true,
	eventBarText = "TEXT_EVENT_FIX3",
	eventBarImage = "EVENTBAR_ICON_R3_S2:icons",
	items = {
		{ obj="EVENT_FIX_KID", activate="event_queue_girl" },
	},
	scoreAllDone = 10,
}

function levelDesc:onTick(time)
	self:tick(time)
	if (not self.done and level.event:getProgress() >= 1) then
		level:getObject("event_queue_girl"):resetQueueSpot()
		level:getObject("event_queue_girl"):addTask({class="WalkToTask", target = {x = -100,y = 175}})
		self.done = true
	end
end