local BlockSystem = inherited("BlockSystem", SystemMap)

function BlockSystem:new()
	local ms = instance(self)
	return ms
end

function BlockSystem:wants(ent)
	return ent.aspects.block
end

function BlockSystem:ent_added(ent)
end

function BlockSystem:ent_removed(ent)
end

function BlockSystem:step(dt)
	for ent, _ in pairs(self.ents) do
		local delay = ent.block_delay
		if delay > 0 then
			delay = delay - dt*ent.block_recovery_speed
			if delay <= 0 then
				ent.block_delay = 0
			else
				ent.block_delay = delay
			end
		else
			local block_stamina = ent.block_stamina
			local block_stamina_max = ent.block_stamina_max
			if block_stamina ~= block_stamina_max then
				block_stamina = block_stamina + dt*ent.block_stamina_regeneration
				if block_stamina >= block_stamina_max then
					ent.block_stamina = block_stamina_max
				else
					ent.block_stamina = block_stamina
				end
			end
		end
	end
end

return BlockSystem