-- ************************************ BabyCorner ************************************ --
BabyCorner = getClass("BabyCorner")

function BabyCorner:init(desc)
	BabyCorner.superInit(desc)
	self.activeCharacter = nil
	self.playingCharacterAnimation = false
end

function BabyCorner:hasWorkToDo()
	return true
end

function BabyCorner:addToStationTask()
	if (level.selectedObject) then
		if (self:canPlace(level.selectedObject)) then
			level.selectedObject:cancelTasks()
			self:addSelectedObjectToStationTasks()
			return true
		else
			level:cancelSelectedObject()
			return false
		end
	else
		return BabyCorner.super.addToStationTask(self)
	end
end

function BabyCorner:canPlace(character)
	if (self.occupied or not level:isIntroduced("entertain5")) then
		return false
	elseif (character.hasDiseaseStepsLeft) then
		return character.disease.currentStep.allowDetour
	end
	return true
end

function BabyCorner:onObjectDrop(character)
	BabyCorner.super.onObjectDrop(self, character)

	self:place(character);
	character:setState("idle")
	self.activeCharacter = character
	self.activeCharacter.dropHealth = false
	level:bm_incSpecialStationCount()
	return true
end

function BabyCorner:onLeave(character)
	BabyCorner.super.onLeave(self, character)
	self.activeCharacter.dropHealth = true
	self.activeCharacter = nil
	self.playingCharacterAnimation = false
end

function BabyCorner:onTick(time)
	BabyCorner.tick(self, time)
	if (self.activeCharacter) then
		if (level.selectedObject == self.activeCharacter) then
			self.playingCharacterAnimation = false
			self.activeCharacter:playDefaultAnimation()
		elseif (not self.playingCharacterAnimation) then
            self.playingCharacterAnimation = true
			self.activeCharacter:playAnimation(self.stationAnimation, -1, "stay", self.stationAnimationFrameTime)
		end
	end
end
