-- ************************************ Station ************************************ --
StockPillsStation = deriveLuaClass("StockPillsStation", "WorkStation")

function StockPillsStation:init(desc)
	self.workAnimationFrameTime = 100

	StockPillsStation.superInit(desc)
end


function StockPillsStation:hasWorkToDo()
	return true
end

function StockPillsStation:addToStationTask()
	if (StockPillsStation.super.addToStationTask(self)) then
		return true
	end
	self:stopFaultySelectionBlink()
	return false
end

function StockPillsStation:onWorkStart(task)
	local r = StockPillsStation.super.onWorkStart(self, task)

	local numStockToRefill = level:getStation("greenpills").maxStock - level:getStation("greenpills").stock
	numStockToRefill = numStockToRefill + level:getStation("redpills").maxStock - level:getStation("redpills").stock
	numStockToRefill = numStockToRefill + level:getStation("bluepills").maxStock - level:getStation("bluepills").stock
	task.duration = self.durationPerStock * numStockToRefill

	if (task.duration > 0) then
		hero:playAnimation(self.workAnimation, -1, "default", self.workAnimationFrameTime)
		self:playSample("SND_PILLS:sound")
		return r
	end

	return false
end

function StockPillsStation:onWorkFinish(task)
	StockPillsStation.super.onWorkFinish(self, task)

	level:getStation("greenpills"):resetStock()
	level:getStation("redpills"):resetStock()
	level:getStation("bluepills"):resetStock()
end
