-- ************************************ Station ************************************ --
MagazineStand = deriveLuaClass("MagazineStand", "Station")

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

function MagazineStand:hasWorkToDo()
	return true
end

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

function MagazineStand:canPlace(character)
	if (self.occupied) then
		return false
	elseif (character.hasDiseaseStepsLeft) then
		return character.disease.currentStep.allowDetour
	end
	return true
end

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

	self:place(character);
	character:setState("idle")
	self.activeCharacter = character
	self.activeCharacter.dropHealth = false
	self:playSample("SND_READ_MAGAZINE:sound")

	level:bm_incSpecialStationCount()

	return true
end

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

function MagazineStand:onTick(time)
	MagazineStand.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
