local STAT_BONUS_QUALITY_FACTOR = {
	range = 0.05,
	damage = 0.25,
	rate = 0.05,
	muzzle = 0.05,
	pierce = 0.25,
	armor = 0.25,
	speed = 0.25,
	heal = 0.25,
}



local STAT_BONUS_FACTOR = {
	range = 0.01,
	damage = 0.1,
	rate = 0.01,
	muzzle = 0.005,
	pierce = 0.1,
	armor = 0.1,
	speed = 0.05,
	heal = 0.1,
}

local standard_rarity_factors = {
	legendary = 100,
	epic = 25,
	rare = 10,
	uncommon = 3,
	common = 1,
	low = 0.75,
	junk = 0.5,
}

local quality_rarity_factors = {
	legendary = 2,
	epic = 1.75,
	rare = 1.5,
	uncommon = 1.25,
	common = 1,
	low = 0.9,
	junk = 0.75,
}

local crafting_stack = {
	base = 0.25,
	factor_min = 0.1,
	factor_max = 0.25,
	rarity_factor = standard_rarity_factors,
}

local hard_materials = {
	wood = true,
	stone = true,
	bone = true,
	copper = true,
	dark_wood = true,
	obsidian = true,
	iron = true,
	cothra = true,
	dragonscale = true,
}

local armor_materials = {
	leather = true,
	bone = true,
	copper = true,	
	iron = true,
	cothra = true,	
	dragonscale = true,
}

local elastic_materials = {
	wood = true,	
	iron = true,
	cothra = true,
	starfibre = true,
	dark_wood = true,
}

local soft_materials = {
	leather = true,
	fur = true,
	silk = true,
	starfibre = true,
	dragonscale = true,
}

local food_materials = {
	rotten = true,
	stale = true,
	fresh = true,
	artisan = true,
}

local potion_materials = {
	leather = true,
	bone = true,
	starfibre = true,
	cothra = true,
}

local RULE_ITEMS = {
	categories = {
		gold = {
			item_slot = "gold",
			auto_pickup = true,
			name = "Gold",
			price = 1,
			stack_def = {
				base = 1,
				factor_min = 0.5,
				factor_max = 1.5,
				rarity_factor = standard_rarity_factors,
			},
			filters = {
				gold = true,
				general = true,
			},
			sprite_category = "resource",
			sprite_id = "20",
		},
		punch = {
			name = "Punch",
			effect = "hurt",
			stats = {
				range = 0, --bullet range
				damage = 1, --damage related
				rate = 0, --attacks per second stuff
				muzzle = 0, --speed of bullet
				pierce = 0, --armor pierce
				shots = 1, --spread shots
				push = 0,
			},
			attack_type = "projectile",
			sprite_category = "attack",
			sprite_id = "01",
		},
		knock = {
			name = "Knock",
			effect = "hurt",
			stats = {
				range = 0, --bullet range
				damage = 1, --damage related
				rate = 0, --attacks per second stuff
				muzzle = -1, --speed of bullet
				pierce = 0, --armor pierce
				shots = 2, --spread shots
				push = 3,
			},
			attack_type = "projectile",
			sprite_category = "attack",
			sprite_id = "02",
		},
		bite = {
			name = "Bite",
			effect = "hurt",
			stats = {
				range = 0, --bullet range
				damage = 2, --damage related
				rate = -1, --attacks per second stuff
				muzzle = 0, --speed of bullet
				pierce = 1, --armor pierce
				shots = 1, --spread shots
			},
			attack_type = "projectile",
			sprite_category = "attack",
			sprite_id = "03",
		},
		whip = {
			name = "Whip",
			effect = "hurt",
			stats = {
				range = 3, --bullet range
				damage = 1, --damage related
				rate = -2, --attacks per second stuff
				muzzle = 1, --speed of bullet
				pierce = 0, --armor pierce
				shots = 1, --spread shots
			},
			attack_type = "projectile",
			sprite_category = "attack",
			sprite_id = "04",
		},
		mental = {
			name = "Mental",
			effect = "hurt",
			stats = {
				range = 5, --bullet range
				damage = 1, --damage related
				rate = -3, --attacks per second stuff
				muzzle = -1, --speed of bullet
				pierce = 0, --armor pierce
				shots = 1, --spread shots
			},
			attack_type = "projectile",
			sprite_category = "attack",
			sprite_id = "05",
		},
		thorn = {
			name = "Thorn",
			effect = "hurt",
			stats = {
				range = 1, --bullet range
				damage = 1, --damage related
				rate = -1, --attacks per second stuff
				muzzle = 0, --speed of bullet
				pierce = 0, --armor pierce
				shots = 1, --spread shots
			},
			attack_type = "projectile",
			sprite_category = "attack",
			sprite_id = "06",
		},
		pincer = {
			name = "Pincer",
			effect = "hurt",
			stats = {
				range = 1, --bullet range
				damage = 1, --damage related
				rate = 0, --attacks per second stuff
				muzzle = -1, --speed of bullet
				pierce = 0, --armor pierce
				shots = 3, --spread shots
			},
			attack_type = "projectile",
			sprite_category = "attack",
			sprite_id = "07",
		},
		sting = {
			name = "Sting",
			effect = "hurt",
			stats = {
				range = 3, --bullet range
				damage = 2, --damage related
				rate = -3, --attacks per second stuff
				muzzle = 1, --speed of bullet
				pierce = 0, --armor pierce
				shots = 1, --spread shots
			},
			attack_type = "projectile",
			sprite_category = "attack",
			sprite_id = "08",
		},
		dagger = {
			name = "Dagger",
			item_slot = "primary",
			effect = "hurt",
			attack_type = "projectile",
			power_stat = "melee",
			sprite_category = "weapon",
			sprite_id = "01",
			level_offset = 0,
			level_range_factor = 0.33,
			rarity_factor = quality_rarity_factors,
			stats = {
				range = 1, --bullet range
				damage = 1, --damage related
				rate = 3, --attacks per second stuff
				muzzle = 4, --speed of bullet
				pierce = 0, --armor pierce
				shots = 1, --spread shots
			},
			materials = hard_materials,
			filters = {
				melee = true,
				weapon = true,
				combat = true,
			},
		},
		short_sword = {
			name = "Short Sword",
			item_slot = "primary",
			effect = "hurt",
			attack_type = "projectile",
			power_stat = "melee",
			sprite_category = "weapon",
			sprite_id = "02",
			level_offset = 0,
			level_peak_factor = 0.5,
			level_range_factor = 0.33,
			rarity_factor = quality_rarity_factors,
			stats = {
				range = 2, --bullet range
				damage = 2, --damage related
				rate = 2, --attacks per second stuff
				muzzle = 2, --speed of bullet
				pierce = 1, --armor pierce
				shots = 1, --spread shots				
			},
			materials = hard_materials,
			filters = {
				melee = true,
				weapon = true,
				combat = true,
			},
		},
		falchion = {
			name = "Falchion",
			item_slot = "primary",
			effect = "hurt",
			attack_type = "projectile",
			power_stat = "melee",
			sprite_category = "weapon",
			sprite_id = "03",
			level_peak_factor = 0.25,
			level_offset = 5,
			level_range_factor = 0.33,
			rarity_factor = quality_rarity_factors,
			stats = {
				range = 1.5, --bullet range
				damage = 3.5, --damage related
				rate = 2, --attacks per second stuff
				muzzle = 2, --speed of bullet
				pierce = 0, --armor pierce
				shots = 1, --spread shots				
			},
			materials = hard_materials,
			filters = {
				melee = true,
				weapon = true,
				combat = true,
			},
		},
		hatchet = {
			name = "Hatchet",
			item_slot = "primary",
			effect = "hurt",
			attack_type = "projectile",
			power_stat = "melee",
			sprite_category = "weapon",
			sprite_id = "04",
			level_offset = 1,
			level_range_factor = 0.33,
			rarity_factor = quality_rarity_factors,
			stats = {
				range = 1, --bullet range
				damage = 1.5, --damage related
				rate = 2.5, --attacks per second stuff
				muzzle = 3.5, --speed of bullet
				pierce = 0.5, --armor pierce
				shots = 1, --spread shots				
			},
			materials = hard_materials,
			filters = {
				melee = true,
				weapon = true,
				combat = true,				
			},
		},
		spiked_battle_club = {
			name = "Spiked Battle Club",
			item_slot = "primary",
			effect = "hurt",
			attack_type = "projectile",
			power_stat = "melee",
			sprite_category = "weapon",
			sprite_id = "05",
			level_offset = 5,
			level_peak_factor = 0.75,
			level_range_factor = 0.33,
			rarity_factor = quality_rarity_factors,
			stats = {
				range = 1.5, --bullet range
				damage = 3, --damage related
				rate = 1.5, --attacks per second stuff
				muzzle = 1, --speed of bullet
				pierce = 2, --armor pierce
				shots = 1, --spread shots				
			},
			materials = hard_materials,
			filters = {
				melee = true,
				weapon = true,
				combat = true,
			},
		},
		hammer = {
			name = "Hammer",
			item_slot = "primary",
			effect = "hurt",
			attack_type = "projectile",
			power_stat = "melee",
			sprite_category = "weapon",
			sprite_id = "06",
			level_offset = 3,
			level_range_factor = 0.33,
			rarity_factor = quality_rarity_factors,
			stats = {
				range = 1, --bullet range
				damage = 3.5, --damage related
				rate = 0.5, --attacks per second stuff
				muzzle = 1, --speed of bullet
				pierce = 3, --armor pierce
				shots = 1, --spread shots				
			},
			materials = hard_materials,
			filters = {
				melee = true,
				weapon = true,
				combat = true,
			},
		},
		mace = {
			name = "Mace",
			item_slot = "primary",
			effect = "hurt",
			attack_type = "projectile",
			power_stat = "melee",
			sprite_category = "weapon",
			sprite_id = "07",
			level_offset = 2,
			level_range_factor = 0.33,
			rarity_factor = quality_rarity_factors,
			stats = {
				range = 1, --bullet range
				damage = 3.5, --damage related
				rate = 1.5, --attacks per second stuff
				muzzle = 1, --speed of bullet
				pierce = 2, --armor pierce
				shots = 1, --spread shots				
			},
			materials = hard_materials,
			filters = {
				melee = true,
				weapon = true,
				combat = true,
			},
		},
		cleaver = {
			name = "Cleaver",
			item_slot = "primary",
			effect = "hurt",
			attack_type = "projectile",
			power_stat = "melee",
			sprite_category = "weapon",
			sprite_id = "08",
			level_offset = 4,
			level_peak_factor = 0.75,
			level_range_factor = 0.33,
			rarity_factor = quality_rarity_factors,
			stats = {
				range = 0.5, --bullet range
				damage = 5, --damage related
				rate = 1.5, --attacks per second stuff
				muzzle = 1.5, --speed of bullet
				pierce = 0.5, --armor pierce
				shots = 1, --spread shots				
			},
			materials = hard_materials,
			filters = {
				melee = true,
				weapon = true,
				combat = true,
			},
		},
		sickle = {
			name = "Sickle",
			level_offset = 10,
			level_peak_factor = 0.25,
			level_range_factor = 0.33,
			item_slot = "primary",
			effect = "hurt",
			attack_type = "projectile",
			power_stat = "melee",
			sprite_category = "weapon",
			sprite_id = "09",
			rarity_factor = quality_rarity_factors,
			stats = {
				range = 0.5, --bullet range
				damage = 2.5, --damage related
				rate = 2, --attacks per second stuff
				muzzle = 4, --speed of bullet
				pierce = 0, --armor pierce
				shots = 1, --spread shots				
			},
			materials = hard_materials,
			filters = {
				melee = true,
				weapon = true,
				combat = true,
			},
		},
		club = {
			name = "Club",
			level_offset = 1,
			level_range_factor = 0.33,
			item_slot = "primary",
			effect = "hurt",
			attack_type = "projectile",
			power_stat = "melee",
			sprite_category = "weapon",
			sprite_id = "10",
			rarity_factor = quality_rarity_factors,
			stats = {
				range = 1, --bullet range
				damage = 4.5, --damage related
				rate = 1.5, --attacks per second stuff
				muzzle = 1, --speed of bullet
				pierce = 0.5, --armor pierce
				shots = 1, --spread shots				
			},
			materials = hard_materials,
			filters = {
				melee = true,
				weapon = true,
				combat = true,
			},
		},
		broad_axe = {
			name = "Broad Axe",
			level_offset = 6,
			level_range_factor = 0.33,
			item_slot = "primary",
			effect = "hurt",
			attack_type = "projectile",
			power_stat = "melee",
			sprite_category = "weapon",
			sprite_id = "11",
			rarity_factor = quality_rarity_factors,
			stats = {
				range = 1.5, --bullet range
				damage = 5, --damage related
				rate = 0.5, --attacks per second stuff
				muzzle = 0.5, --speed of bullet
				pierce = 0.5, --armor pierce
				shots = 2, --spread shots				
			},
			materials = hard_materials,
			filters = {
				melee = true,
				weapon = true,
				combat = true,
			},
		},
		bearded_axe = {
			level_offset = 7,
			level_peak_factor = 0.75,
			level_range_factor = 0.33,
			name = "Bearded Axe",
			item_slot = "primary",
			effect = "hurt",
			attack_type = "projectile",
			power_stat = "melee",
			sprite_category = "weapon",
			sprite_id = "12",
			rarity_factor = quality_rarity_factors,
			stats = {
				range = 1, --bullet range
				damage = 4.5, --damage related
				rate = 0.5, --attacks per second stuff
				muzzle = 1, --speed of bullet
				pierce = 1, --armor pierce
				shots = 2, --spread shots				
			},
			materials = hard_materials,
			filters = {
				melee = true,
				weapon = true,
				combat = true,
			},
		},
		partism = {
			level_offset = 8,
			level_peak_factor = 0.75,
			level_range_factor = 0.33,
			name = "Partism",
			item_slot = "primary",
			effect = "hurt",
			attack_type = "projectile",
			power_stat = "melee",
			sprite_category = "weapon",
			sprite_id = "13",
			rarity_factor = quality_rarity_factors,
			stats = {
				range = 4, --bullet range
				damage = 2, --damage related
				rate = 0.5, --attacks per second stuff
				muzzle = 1.5, --speed of bullet
				pierce = 1, --armor pierce
				shots = 1, --spread shots				
			},
			materials = hard_materials,
			filters = {
				melee = true,
				weapon = true,
				combat = true,
			},
		},
		halberd = {
			level_offset = 3,
			level_range_factor = 0.33,
			name = "Halberd",
			item_slot = "primary",
			effect = "hurt",
			attack_type = "projectile",
			power_stat = "melee",
			sprite_category = "weapon",
			sprite_id = "14",
			rarity_factor = quality_rarity_factors,
			stats = {
				range = 4, --bullet range
				damage = 3, --damage related
				rate = 0.5, --attacks per second stuff
				muzzle = 1, --speed of bullet
				pierce = 0.5, --armor pierce
				shots = 1, --spread shots				
			},
			materials = hard_materials,
			filters = {
				melee = true,
				weapon = true,
				combat = true,
			},
		},
		pole_axe = {
			level_offset = 4,
			level_range_factor = 0.33,
			name = "Pole Axe",
			item_slot = "primary",
			effect = "hurt",
			attack_type = "projectile",
			power_stat = "melee",
			sprite_category = "weapon",
			sprite_id = "15",
			rarity_factor = quality_rarity_factors,
			stats = {
				range = 4, --bullet range
				damage = 2.5, --damage related
				rate = 0.5, --attacks per second stuff
				muzzle = 1, --speed of bullet
				pierce = 1, --armor pierce
				shots = 1, --spread shots				
			},
			materials = hard_materials,
			filters = {
				melee = true,
				weapon = true,
				combat = true,
			},
		},
		long_sword = {
			level_offset = 7,
			level_peak_factor = 0.75,
			level_range_factor = 0.33,
			name = "Long Sword",
			item_slot = "primary",
			effect = "hurt",
			attack_type = "projectile",
			power_stat = "melee",
			sprite_category = "weapon",
			sprite_id = "16",
			rarity_factor = quality_rarity_factors,
			stats = {
				range = 3, --bullet range
				damage = 2.5, --damage related
				rate = 1.5, --attacks per second stuff
				muzzle = 1, --speed of bullet
				pierce = 1, --armor pierce
				shots = 1, --spread shots				
			},
			materials = hard_materials,
			filters = {
				melee = true,
				weapon = true,
				combat = true,
			},
		},
		sledge = {
			level_offset = 9,
			level_peak_factor = 0.5,
			level_range_factor = 0.33,
			name = "Sledge",
			item_slot = "primary",
			effect = "hurt",
			attack_type = "projectile",
			power_stat = "melee",
			sprite_category = "weapon",
			sprite_id = "17",
			rarity_factor = quality_rarity_factors,
			stats = {
				range = 1.5, --bullet range
				damage = 4, --damage related
				rate = 0.5, --attacks per second stuff
				muzzle = 0.5, --speed of bullet
				pierce = 2.5, --armor pierce
				shots = 1, --spread shots				
			},
			materials = hard_materials,
			filters = {
				melee = true,
				weapon = true,
				combat = true,
			},
		},
		dirk = {
			level_offset = 6,
			level_peak_factor = 0.50,
			level_range_factor = 0.33,
			name = "Dirk",
			item_slot = "primary",
			effect = "hurt",
			attack_type = "projectile",
			power_stat = "melee",
			sprite_category = "weapon",
			sprite_id = "18",
			rarity_factor = quality_rarity_factors,
			stats = {
				range = 1.5, --bullet range
				damage = 1.5, --damage related
				rate = 2.5, --attacks per second stuff
				muzzle = 3.5, --speed of bullet
				pierce = 0, --armor pierce
				shots = 1, --spread shots				
			},
			materials = hard_materials,
			filters = {
				melee = true,
				weapon = true,
				combat = true,
			},
		},
		zwei_hander = {
			level_offset = 10,
			level_peak_factor = 0.25,
			level_range_factor = 0.33,
			name = "Zwei Hander",
			item_slot = "primary",
			effect = "hurt",
			attack_type = "projectile",
			power_stat = "melee",
			sprite_category = "weapon",
			sprite_id = "19",
			rarity_factor = quality_rarity_factors,
			stats = {
				range = 3, --bullet range
				damage = 3, --damage related
				rate = 1, --attacks per second stuff
				muzzle = 1, --speed of bullet
				pierce = 0, --armor pierce
				shots = 2, --spread shots				
			},
			materials = hard_materials,
			filters = {
				melee = true,
				weapon = true,
				combat = true,
			},
		},
		voulge = {
			name = "Voulge",
			level_offset = 6,
			level_range_factor = 0.33,
			item_slot = "primary",
			effect = "hurt",
			attack_type = "projectile",
			power_stat = "melee",
			sprite_category = "weapon",
			sprite_id = "20",
			rarity_factor = quality_rarity_factors,
			stats = {
				range = 3.5, --bullet range
				damage = 3, --damage related
				rate = 1, --attacks per second stuff
				muzzle = 1, --speed of bullet
				pierce = 0.5, --armor pierce
				shots = 1, --spread shots				
			},
			materials = hard_materials,
			filters = {
				melee = true,
				weapon = true,
				combat = true,
			},
		},
		ranseur = {
			name = "Ranseur",
			level_offset = 8,
			level_peak_factor = 0.75,
			level_range_factor = 0.33,
			item_slot = "primary",
			effect = "hurt",
			attack_type = "projectile",
			power_stat = "melee",
			sprite_category = "weapon",
			sprite_id = "21",
			rarity_factor = quality_rarity_factors,
			stats = {
				range = 4, --bullet range
				damage = 2, --damage related
				rate = 0.5, --attacks per second stuff
				muzzle = 2, --speed of bullet
				pierce = 0.5, --armor pierce
				shots = 1, --spread shots				
			},
			materials = hard_materials,
			filters = {
				melee = true,
				weapon = true,
				combat = true,
			},
		},
		spear = {
			name = "Spear",
			level_offset = 3,
			level_range_factor = 0.33,
			item_slot = "primary",
			effect = "hurt",
			attack_type = "projectile",
			power_stat = "melee",
			sprite_category = "weapon",
			sprite_id = "22",
			rarity_factor = quality_rarity_factors,
			stats = {
				range = 4.5, --bullet range
				damage = 1.5, --damage related
				rate = 1, --attacks per second stuff
				muzzle = 3, --speed of bullet
				pierce = 0, --armor pierce
				shots = 1, --spread shots				
			},
			materials = hard_materials,
			filters = {
				melee = true,
				weapon = true,
				combat = true,
			},
		},
		spiked_club = {
			name = "Spiked Club",
			level_offset = 2,
			level_range_factor = 0.33,
			item_slot = "primary",
			effect = "hurt",
			attack_type = "projectile",
			power_stat = "melee",
			sprite_category = "weapon",
			sprite_id = "23",
			rarity_factor = quality_rarity_factors,
			stats = {
				range = 1.5, --bullet range
				damage = 2.5, --damage related
				rate = 1.5, --attacks per second stuff
				muzzle = 0.5, --speed of bullet
				pierce = 3, --armor pierce
				shots = 1, --spread shots				
			},
			materials = hard_materials,
			filters = {
				melee = true,
				weapon = true,
				combat = true,
			},
		},
		axe = {
			name = "Axe",
			level_offset = 4,
			level_range_factor = 0.33,
			item_slot = "primary",
			effect = "hurt",
			attack_type = "projectile",
			power_stat = "melee",
			sprite_category = "weapon",
			sprite_id = "24",
			rarity_factor = quality_rarity_factors,
			stats = {
				range = 3, --bullet range
				damage = 4, --damage related
				rate = 1, --attacks per second stuff
				muzzle = 0, --speed of bullet
				pierce = 1, --armor pierce
				shots = 1, --spread shots				
			},
			materials = hard_materials,
			filters = {
				melee = true,
				weapon = true,
				combat = true,
			},
		},
		zanbato = {
			name = "Zanbato",
			level_offset = 11,
			level_peak_factor = 0.05,
			level_range_factor = 0.33,
			item_slot = "primary",
			effect = "hurt",
			attack_type = "projectile",
			power_stat = "melee",
			sprite_category = "weapon",
			sprite_id = "25",
			rarity_factor = quality_rarity_factors,
			stats = {
				range = 1, --bullet range
				damage = 8, --damage related
				rate = 0, --attacks per second stuff
				muzzle = 0, --speed of bullet
				pierce = 0, --armor pierce
				shots = 1, --spread shots				
			},
			materials = hard_materials,
			filters = {
				melee = true,
				weapon = true,
				combat = true,
			},
		},
		lance = {
			name = "Lance",
			level_offset = 11,
			level_peak_factor = 0.33,
			level_range_factor = 0.33,
			item_slot = "primary",
			effect = "hurt",
			attack_type = "projectile",
			power_stat = "melee",
			sprite_category = "weapon",
			sprite_id = "26",
			rarity_factor = quality_rarity_factors,
			stats = {
				range = 5, --bullet range
				damage = 1, --damage related
				rate = 0, --attacks per second stuff
				muzzle = 4, --speed of bullet
				pierce = 0, --armor pierce
				shots = 1, --spread shots				
			},
			materials = hard_materials,
			filters = {
				melee = true,
				weapon = true,
				combat = true,
			},
		},
		katana = {
			name = "Katana",
			level_offset = 12,
			level_peak_factor = 0.15,
			level_range_factor = 0.33,
			item_slot = "primary",
			effect = "hurt",
			attack_type = "projectile",
			power_stat = "melee",
			sprite_category = "weapon",
			sprite_id = "27",
			rarity_factor = quality_rarity_factors,
			stats = {
				range = 2.5, --bullet range
				damage = 2, --damage related
				rate = 2.5, --attacks per second stuff
				muzzle = 2, --speed of bullet
				pierce = 0, --armor pierce
				shots = 1, --spread shots				
			},
			materials = hard_materials,
			filters = {
				melee = true,
				weapon = true,
				combat = true,
			},
		},
		sai = {
			name = "Sai",
			level_offset = 5,
			level_peak_factor = 0.5,
			level_range_factor = 0.33,
			item_slot = "primary",
			effect = "hurt",
			attack_type = "projectile",
			power_stat = "melee",
			sprite_category = "weapon",
			sprite_id = "28",
			rarity_factor = quality_rarity_factors,
			stats = {
				range = 1.5, --bullet range
				damage = 1.5, --damage related
				rate = 2, --attacks per second stuff
				muzzle = 1, --speed of bullet
				pierce = 0, --armor pierce
				shots = 3, --spread shots				
			},
			materials = hard_materials,
			filters = {
				melee = true,
				weapon = true,
				combat = true,
			},
		},
		compound_bow = {
			name = "Compound Bow",
			level_offset = 9,
			level_range_factor = 0.33,
			level_peak_factor = 0.75,
			item_slot = "secondary",
			effect = "hurt",
			attack_type = "projectile",
			power_stat = "ranged",
			sprite_category = "weapon",
			sprite_id = "29",
			rarity_factor = quality_rarity_factors,
			stats = {
				range = 8, --bullet range
				damage = 4, --damage related
				rate = -9, --attacks per second stuff
				muzzle = 6, --speed of bullet
				pierce = 2, --armor pierce
				shots = 1, --spread shots				
			},
			materials = elastic_materials,
			filters = {
				ranged = true,
				weapon = true,
				combat = true,
			},
		},
		recurve_bow = {
			name = "Recurve Bow",
			level_offset = 6,
			level_range_factor = 0.33,
			level_peak_factor = 0.5,
			item_slot = "secondary",
			effect = "hurt",
			attack_type = "projectile",
			power_stat = "ranged",
			sprite_category = "weapon",
			sprite_id = "30",
			projectile_sprite_id = "36",
			rarity_factor = quality_rarity_factors,
			stats = {
				range = 8, --bullet range
				damage = 4, --damage related
				rate = -8, --attacks per second stuff
				muzzle = 4, --speed of bullet
				pierce = 1, --armor pierce
				shots = 1, --spread shots				
			},
			materials = elastic_materials,
			filters = {
				ranged = true,
				weapon = true,
				combat = true,
			},
		},
		angular_bow = {
			name = "Angular Bow",
			level_offset = 4,
			level_range_factor = 0.33,
			level_peak_factor = 0.5,
			item_slot = "secondary",
			effect = "hurt",
			attack_type = "projectile",
			power_stat = "ranged",
			sprite_category = "weapon",
			sprite_id = "31",
			projectile_sprite_id = "36",
			rarity_factor = quality_rarity_factors,
			stats = {
				range = 8, --bullet range
				damage = 4, --damage related
				rate = -8, --attacks per second stuff
				muzzle = 5, --speed of bullet
				pierce = 0, --armor pierce
				shots = 1, --spread shots				
			},
			materials = elastic_materials,
			filters = {
				ranged = true,
				weapon = true,
				combat = true,
			},
		},
		long_bow = {
			name = "Long Bow",
			level_offset = 8,
			level_range_factor = 0.33,
			level_peak_factor = 0.25,
			item_slot = "secondary",
			effect = "hurt",
			attack_type = "projectile",
			power_stat = "ranged",
			sprite_category = "weapon",
			sprite_id = "32",
			projectile_sprite_id = "39",
			rarity_factor = quality_rarity_factors,
			stats = {
				range = 11, --bullet range
				damage = 6, --damage related
				rate = -13, --attacks per second stuff
				muzzle = 4, --speed of bullet
				pierce = 1, --armor pierce
				shots = 1, --spread shots				
			},
			materials = elastic_materials,
			filters = {
				ranged = true,
				weapon = true,
				combat = true,
			},
		},
		short_bow = {
			name = "Short Bow",
			level_offset = 0,--2,
			level_range_factor = 0.33,
			item_slot = "secondary",
			effect = "hurt",
			attack_type = "projectile",
			power_stat = "ranged",
			sprite_category = "weapon",
			sprite_id = "33",
			projectile_sprite_id = "36",
			rarity_factor = quality_rarity_factors,
			stats = {
				range = 7, --bullet range
				damage = 3, --damage related
				rate = -3, --attacks per second stuff
				muzzle = 2, --speed of bullet
				pierce = 0, --armor pierce
				shots = 1, --spread shots				
			},
			materials = elastic_materials,
			filters = {
				ranged = true,
				weapon = true,
				combat = true,
			},
		},
		crossbow = {
			name = "Crossbow",
			level_offset = 3,
			level_range_factor = 0.33,
			level_peak_factor = 0.5,
			item_slot = "secondary",
			effect = "hurt",
			attack_type = "projectile",
			power_stat = "ranged",
			sprite_category = "weapon",
			sprite_id = "34",
			projectile_sprite_id = "38",
			rarity_factor = quality_rarity_factors,
			stats = {
				range = 9, --bullet range
				damage = 9, --damage related
				rate = -17, --attacks per second stuff
				muzzle = 5, --speed of bullet
				pierce = 3, --armor pierce
				shots = 1, --spread shots				
			},
			materials = elastic_materials,
			filters = {
				ranged = true,
				weapon = true,
				combat = true,
			},
		},
		arbalest = {
			name = "Arbalest",
			level_offset = 7,
			level_range_factor = 0.33,
			level_peak_factor = 0.25,
			item_slot = "secondary",
			effect = "hurt",
			attack_type = "projectile",
			power_stat = "ranged",
			sprite_category = "weapon",
			sprite_id = "35",
			projectile_sprite_id = "37",
			rarity_factor = quality_rarity_factors,
			stats = {
				range = 10, --bullet range
				damage = 14, --damage related
				rate = -26, --attacks per second stuff
				muzzle = 6, --speed of bullet
				pierce = 5, --armor pierce
				shots = 1, --spread shots				
			},
			materials = elastic_materials,
			filters = {
				ranged = true,
				weapon = true,
				combat = true,
			},
		},
		hat = {
			name = "Hat",
			item_slot = "head",
			materials = soft_materials,
			level_offset = 0,
			level_range_factor = 0.33,
			sprite_category = "equipment",
			sprite_id = "0004",
			stats = {
				armor = 1, --armor rating
				speed = 4,
				resistance = 0,
				size = 0,
			},
			filters = {
				clothes = true,
				combat = true,
			},
		},
		horned_hat = {
			name = "Horned Hat",
			item_slot = "head",
			level_offset = 5,
			level_range_factor = 0.33,
			sprite_category = "equipment",
			sprite_id = "0002",
			stats = {
				armor = 2, --armor rating
				speed = 2,
				resistance = 1,
				size = 0,
			},
			materials = soft_materials,
			filters = {
				armor = true,
				combat = true,
			},
		},
		wizards_hat = {
			name = "Wizards Hat",
			item_slot = "head",
			level_offset = 5,
			level_range_factor = 0.20,
			sprite_category = "equipment",
			sprite_id = "0003",
			stats = {
				armor = 1, --armor rating
				speed = 2,
				resistance = 3,
				size = 0,
			},
			materials = soft_materials,
			filters = {
				armor = true,
				combat = true,
			},
		},
		spangen = {
			name = "Spangen",
			item_slot = "head",
			level_offset = 2,
			level_range_factor = 0.45,
			sprite_category = "equipment",
			sprite_id = "0005",
			stats = {
				armor = 3, --armor rating
				speed = 1,
				resistance = 0,
				size = 1,
			},
			materials = armor_materials,
			filters = {
				armor = true,
				combat = true,
			},
		},
		morion = {
			name = "Morion",
			item_slot = "head",
			level_offset = 3,
			level_range_factor = 0.33,
			sprite_category = "equipment",
			sprite_id = "0006",
			stats = {
				armor = 2, --armor rating
				speed = 2,
				resistance = 0,
				size = 1,
			},
			materials = armor_materials,
			filters = {
				armor = true,
				combat = true,
			},
		},
		norman = {
			name = "Norman",
			item_slot = "head",
			level_offset = 9,
			level_range_factor = 0.23,
			sprite_category = "equipment",
			sprite_id = "0007",
			stats = {
				armor = 2, --armor rating
				speed = 3,
				resistance = 0,
				size = 0,
			},
			materials = armor_materials,
			filters = {
				armor = true,
				combat = true,
			},
		},
		helm = {
			name = "Helm",
			item_slot = "head",
			level_offset = 12,
			level_range_factor = 0.18,
			sprite_category = "equipment",
			sprite_id = "0008",
			stats = {
				armor = 4, --armor rating
				speed = -3,
				resistance = 2,
				size = 2,
			},
			materials = armor_materials,
			filters = {
				armor = true,
				combat = true,
			},
		},
		ranger_hat = {
			name = "Ranger Hat",
			item_slot = "head",
			level_offset = 5,
			level_range_factor = 0.42,
			sprite_category = "equipment",
			sprite_id = "0009",
			stats = {
				armor = 1, --armor rating
				speed = 4,
				resistance = 1,
				size = -1,
			},
			materials = soft_materials,
			filters = {
				armor = true,
				combat = true,
			},
		},
		robe = {
			name = "Robe",
			item_slot = "torso",
			level_offset = 1,
			level_range_factor = 0.33,
			sprite_category = "equipment",
			sprite_id = "0011",
			level_peak_factor = 0.5,
			stats = {
				armor = 0, --armor rating
				speed = 2,
				resistance = 3,
				size = 0,
			},
			materials = soft_materials,
			filters = {
				wizard = true,
				combat = true,
			},
		},
		shirt = {
			name = "Shirt",
			item_slot = "torso",
			level_offset = 1,
			level_range_factor = 0.33,
			sprite_category = "equipment",
			sprite_id = "0010",
			level_peak_factor = 0.5,
			stats = {
				armor = 1, --armor rating
				speed = 4,
				resistance = 0,
				size = 0,
			},
			materials = soft_materials,
			filters = {
				clothes = true,
				combat = true,
				civilian = true,
			},
		},
		heavy_shirt = {
			name = "Heavy Shirt",
			item_slot = "torso",
			level_offset = 1,
			level_range_factor = 0.33,
			sprite_category = "equipment",
			sprite_id = "0011",
			level_peak_factor = 0.5,
			stats = {
				armor = 1, --armor rating
				speed = 4,
				resistance = 0,
				size = 0,
			},
			materials = soft_materials,
			filters = {
				clothes = true,
				combat = true,
				civilian = true,
			},
		},
		chainmail_torso = {
			name = "Chainmail Torso",
			item_slot = "torso",
			level_offset = 5,
			stats = {
				armor = 2, --armor rating
				speed = 2,
				resistance = 0,
				size = 1,
			},
			level_range_factor = 0.33,
			sprite_category = "equipment",
			sprite_id = "0013",
			materials = armor_materials,
			filters = {
				armor = true,
				combat = true,
			},
		},
		half_plate = {
			name = "Half Plate",
			item_slot = "torso",
			level_offset = 10,
			level_peak_factor = 0.55,
			stats = {
				armor = 3, --armor rating
				speed = 0,
				resistance = 0,
				size = 2,
			},
			level_range_factor = 0.33,
			sprite_category = "equipment",
			sprite_id = "0014",
			materials = armor_materials,
			filters = {
				armor = true,
				combat = true,
			},
		},
		darian_torso = {
			name = "Darian Torso",
			item_slot = "torso",
			level_offset = 9,
			level_peak_factor = 0.80,
			stats = {
				armor = 4, --armor rating
				speed = -2,
				resistance = 0,
				size = 3,
			},
			level_range_factor = 0.33,
			sprite_category = "equipment",
			sprite_id = "0015",
			materials = armor_materials,
			filters = {
				armor = true,
				combat = true,
			},
		},
		norman_torso = {
			name = "Norman Torso",
			item_slot = "torso",
			level_offset = 14,
			level_peak_factor = 0.25,
			stats = {
				armor = 3, --armor rating
				speed = 3,
				resistance = -3,
				size = 2,
			},
			level_range_factor = 0.33,
			sprite_category = "equipment",
			sprite_id = "0016",
			materials = armor_materials,
			filters = {
				armor = true,
				combat = true,
			},
		},
		knight_torso = {
			name = "Knight Torso",
			item_slot = "torso",
			level_offset = 25,
			level_peak_factor = 0.33,
			stats = {
				armor = 5, --armor rating
				speed = -4,
				resistance = 1,
				size = 3,
			},
			level_range_factor = 0.33,
			sprite_category = "equipment",
			sprite_id = "0016",
			materials = armor_materials,
			filters = {
				armor = true,
				combat = true,
			},
		},
		ranger_jacket = {
			name = "Ranger Jacket",
			item_slot = "torso",
			level_offset = 5,
			level_peak_factor = 0.33,
			stats = {
				armor = 2, --armor rating
				speed = 3,
				resistance = -1,
				size = 1,
			},
			level_range_factor = 0.33,
			sprite_category = "equipment",
			sprite_id = "0017",
			materials = soft_materials,
			filters = {
				armor = true,
				combat = true,
			},
		},
		pants = {
			name = "Pants",
			item_slot = "legs",
			level_offset = 2,
			stats = {
				armor = 1, --armor rating
				speed = 4,
				resistance = 0,
				size = 0,
			},
			level_range_factor = 0.33,
			sprite_category = "equipment",
			sprite_id = "0019",
			materials = soft_materials,
			filters = {
				clothes = true,
				combat = true,
				civilian = true,
			},
		},
		skirt = {
			name = "Skirt",
			item_slot = "legs",
			level_offset = 2,
			stats = {
				armor = 0, --armor rating
				speed = 4,
				resistance = 1,
				size = 0,
			},
			level_range_factor = 0.33,
			sprite_category = "equipment",
			sprite_id = "0020",
			materials = soft_materials,
			filters = {
				clothes = true,
				combat = true,
				civilian = true,
			},
		},
		loose_legs = {
			name = "Loose Legs",
			item_slot = "legs",
			level_offset = 14,
			stats = {
				armor = 0, --armor rating
				speed = 3,
				resistance = 2,
				size = 0,
			},
			level_range_factor = 0.33,
			sprite_category = "equipment",
			sprite_id = "0021",
			materials = soft_materials,
			filters = {
				armor = true,
				combat = true,
			},
		},
		chainmail_legs = {
			name = "Chainmail legs",
			item_slot = "legs",
			level_offset = 8,
			level_peak_factor = 0.75,
			stats = {
				armor = 2, --armor rating
				speed = 2,
				resistance = 0,
				size = 1,
			},
			level_range_factor = 0.33,
			sprite_category = "equipment",
			sprite_id = "0022",
			materials = armor_materials,
			filters = {
				armor = true,
				combat = true,
			},
		},
		halfplate_legs = {
			name = "Halfplate Legs",
			item_slot = "legs",
			level_offset = 16,
			level_peak_factor = 0.55,
			stats = {
				armor = 3, --armor rating
				speed = 0,
				resistance = 0,
				size = 2,
			},
			level_range_factor = 0.33,
			sprite_category = "equipment",
			sprite_id = "0023",
			materials = armor_materials,
			filters = {
				armor = true,
				combat = true,
			},
		},
		darian_legs = {
			name = "Darian Legs",
			item_slot = "legs",
			level_offset = 9,
			level_peak_factor = 0.80,
			stats = {
				armor = 4, --armor rating
				speed = -2,
				resistance = 0,
				size = 3,
			},
			level_range_factor = 0.33,
			sprite_category = "equipment",
			sprite_id = "0024",
			materials = armor_materials,
			filters = {
				armor = true,
				combat = true,
			},
		},
		norman_legs = {
			name = "Norman Legs",
			item_slot = "legs",
			level_offset = 14,
			level_peak_factor = 0.25,
			stats = {
				armor = 3, --armor rating
				speed = 3,
				resistance = -3,
				size = 2,
			},
			level_range_factor = 0.33,
			sprite_category = "equipment",
			sprite_id = "0025",
			materials = armor_materials,
			filters = {
				armor = true,
				combat = true,
			},
		},
		knight_legs = {
			name = "Knight Legs",
			item_slot = "legs",
			level_offset = 28,
			level_peak_factor = 0.33,
			stats = {
				armor = 5, --armor rating
				speed = -4,
				resistance = 1,
				size = 3,
			},
			level_range_factor = 0.33,
			sprite_category = "equipment",
			sprite_id = "0026",
			materials = armor_materials,
			filters = {
				armor = true,
				combat = true,
			},
		},
		ranger_pants = {
			name = "Ranger Pants",
			item_slot = "legs",
			level_offset = 5,
			level_peak_factor = 0.33,
			stats = {
				armor = 2, --armor rating
				speed = 3,
				resistance = -1,
				size = 1,
			},
			level_range_factor = 0.33,
			sprite_category = "equipment",
			sprite_id = "0027",
			materials = soft_materials,
			filters = {
				armor = true,
				combat = true,
			},
		},
		sandals = {
			name = "Sandals",
			item_slot = "feet",
			level_offset = 3,
			level_peak_factor = 0.5,
			stats = {
				armor = 0, --armor rating
				speed = 5,
				resistance = 2,
				size = -2,
			},
			level_range_factor = 0.33,
			sprite_category = "equipment",
			sprite_id = "0029",
			materials = soft_materials,
			filters = {
				clothes = true,
				combat = true,
			},
		},
		shoes = {
			name = "Shoes",
			item_slot = "feet",
			level_offset = 6,
			stats = {
				armor = 1, --armor rating
				speed = 3,
				resistance = 0,
				size = 1,
			},
			level_range_factor = 0.33,
			sprite_category = "equipment",
			sprite_id = "0029",
			materials = soft_materials,
			filters = {
				clothes = true,
				combat = true,
				civilian = true,
			},
		},
		sabatons = {
			name = "Sabatons",
			item_slot = "feet",
			level_offset = 9,
			level_peak_factor = 0.75,
			stats = {
				armor = 3, --armor rating
				speed = -1,
				resistance = 1,
				size = 2,
			},
			level_range_factor = 0.33,
			sprite_category = "equipment",
			sprite_id = "0031",
			materials = armor_materials,
			filters = {
				armor = true,
				combat = true,
			},
		},
		gloves = {
			name = "Gloves",
			item_slot = "hands",
			level_offset = 1,
			stats = {
				armor = 0, --armor rating
				speed = 5,
				resistance = 0,
				size = 0,
			},
			level_range_factor = 0.33,
			sprite_category = "equipment",
			sprite_id = "0028",
			materials = soft_materials,
			filters = {
				clothes = true,
				combat = true,
				civilian = true,
			},
		},
		bracers = {
			name = "Bracers",
			item_slot = "hands",
			level_offset = 3,
			stats = {
				armor = 3, --armor rating
				speed = 1,
				resistance = 0,
				size = 1,
			},
			level_range_factor = 0.33,
			sprite_category = "equipment",
			sprite_id = "0028",
			materials = armor_materials,
			filters = {
				armor = true,
				combat = true,
			},
		},
		gauntlets = {
			name = "Gauntlets",
			item_slot = "hands",
			level_offset = 7,
			level_peak_factor = 0.75,
			stats = {
				armor = 4, --armor rating
				speed = -2,
				resistance = 0,
				size = 3,
			},
			level_range_factor = 0.33,
			sprite_category = "equipment",
			sprite_id = "0030",
			materials = armor_materials,
			filters = {
				armor = true,
				combat = true,
			},
		},
		amulett = {
			name = "Amulett",
			item_slot = "neck",
			level_offset = 10,
			level_peak_factor = 0.1,
			level_range_factor = 0.33,
			sprite_category = "resource",
			sprite_id = "16",
			materials = hard_materials,
			filters = {
				jewlery = true,
			},
		},
		ring = {
			name = "Ring",
			item_slot = "finger",
			level_offset = 5,
			level_peak_factor = 0.1,
			level_range_factor = 0.33,
			sprite_category = "resource",
			sprite_id = "16",
			materials = hard_materials,
			filters = {
				jewlery = true,
			},
		},
		belt = {
			name = "Belt",
			item_slot = "belt",
			level_offset = 4,
			level_peak_factor = 0.75,
			stats = {
				armor = 0, --armor rating
				speed = 3,
				resistance = 1,
				size = 1,
			},
			level_range_factor = 0.33,
			sprite_category = "equipment",
			sprite_id = "0033",
			materials = soft_materials,
			filters = {
				clothes = true,
				civilian = true,
			},
		},
		rope = {
			name = "Rope",
			item_slot = "belt",
			level_offset = 4,
			level_peak_factor = 0.75,
			stats = {
				armor = -1, --armor rating
				speed = 3,
				resistance = 4,
				size = -1,
			},
			level_range_factor = 0.33,
			sprite_category = "equipment",
			sprite_id = "0032",
			materials = soft_materials,
			filters = {
				clothes = true,
				civilian = true,
			},
		},
		health_potion = {
			name = "Health potion",
			item_slot = "hotbar",
			level_offset = 0,
			materials = potion_materials,
			sprite_category = "resource",
			effect = "heal",
			stats = {
				heal = 20,
			},
			sprite_id = "16",
			filters = {
				potion = true,				
			},
		},
		--effect_potion = {
		--	name = "Effect potion",
		--	item_slot = "hotbar",
		--	sprite_category = "resource",
		--	sprite_id = "15",
		--	filters = {
		--		potion = true,
		--	},
		--},
		bread = {
			name = "Bread",
			item_slot = "hotbar",
			sprite_category = "resource",
			sprite_id = "14",
			effect = "heal",
			stats = {
				heal = 10,
			},
			level_offset = 0,
			materials = food_materials,
			filters = {
				food = true,
				general = true,
			},
		},
		--enchantment_scroll = {
		--	name = "Enchantment scroll",
		--	item_slot = "stash",
		--	filters = {
		--		scroll = true,
		--	},
		--},
		wood = {
			auto_pickup = true,
			name = "Wood",
			prefix = "Wooden",
			stack_def = crafting_stack,
			item_slot = "stash",
			sprite_category = "resource",
			sprite_id = "01",
			craft_container = "craft_wood",
			stat_bonus = 0,
			material_price_factor = 1,
			level_peak = 1,
			level_range = 15,
			material_tint = FloatColor:new(1, 0.9, 0.65, 0.55),
			crafting = {},
			filters = {
				crafting = true,
				constructed_materials = true,
				natural_materials = true,
				general = true,
				hard_materials = true,
				elastic_materials = true,
			},
		},
		leather = {
			auto_pickup = true,
			name = "Leather",
			stack_def = crafting_stack,
			item_slot = "stash",
			sprite_category = "resource",
			sprite_id = "10",
			stat_bonus = 1,
			craft_container = "craft_leather",
			material_price_factor = 2,
			level_peak = 5,
			level_range = 25,
			material_tint = FloatColor:new(1, 0.85, 0.55, 0.44),
			crafting = {},
			filters = {
				crafting = true,
				natural_materials = true,
				general = true,
				armor_materials = true,
				potion_materials = true,
			},
		},
		stone = {
			auto_pickup = true,
			name = "Stone",
			stack_def = crafting_stack,
			item_slot = "stash",
			sprite_category = "resource",
			sprite_id = "02",
			stat_bonus = 2,
			craft_container = "craft_stone",
			material_price_factor = 4,
			level_peak = 10,
			level_range = 20,
			material_tint = FloatColor:new(1, 0.45, 0.55, 0.6),
			crafting = {},
			filters = {
				crafting = true,
				constructed_materials = true,
				natural_materials = true,
				general = true,
				hard_materials = true,
			},
		},
		bone = {
			auto_pickup = true,
			name = "Bone",
			stack_def = crafting_stack,
			item_slot = "stash",
			sprite_category = "resource",
			sprite_id = "03",
			stat_bonus = 3,
			craft_container = "craft_bone",
			material_price_factor = 9,
			level_peak = 20,
			level_range = 25,
			material_tint = FloatColor:new(1, 0.89, 1, 0.95),
			crafting = {},
			filters = {
				crafting = true,
				natural_materials = true,
				general = true,
				armor_materials = true,
				hard_materials = true,
				potion_materials = true,
			},
		},
		dark_wood = {
			auto_pickup = true,
			name = "Dark Wood",
			stack_def = crafting_stack,
			item_slot = "stash",
			sprite_category = "resource",
			sprite_id = "05",
			stat_bonus = 4,
			craft_container = "craft_dark_wood",
			material_price_factor = 16,
			level_peak_factor = 0.5,
			level_peak = 35,
			level_range = 40,
			material_tint = FloatColor:new(1, 0.7, 0.32, 0.22),
			crafting = {},
			filters = {
				crafting = true,
				natural_materials = true,
				general = true,
				elastic_materials = true,
			},
		},
		copper = {
			auto_pickup = true,
			name = "Copper",
			stack_def = crafting_stack,
			item_slot = "stash",
			sprite_category = "resource",
			sprite_id = "04",
			stat_bonus = 5,
			craft_container = "craft_copper",
			material_price_factor = 25,
			level_peak = 45,
			level_range = 35,
			material_tint = FloatColor:new(1, 0.95, 0.79, 0.33),
			crafting = {},
			filters = {
				crafting = true,
				constructed_materials = true,
				general = true,
				armor_materials = true,
				hard_materials = true,
			},
		},
		obsidian = {
			auto_pickup = true,
			name = "Obsidian",
			stack_def = crafting_stack,
			item_slot = "stash",
			sprite_category = "resource",
			sprite_id = "06",
			stat_bonus = 6,
			craft_container = "craft_obsidian",
			material_price_factor = 36,
			level_peak_factor = 0.75,
			level_peak = 60,
			level_range = 60,
			material_tint = FloatColor:new(1, 0.2, 0.1, 0.35),
			crafting = {},
			filters = {
				crafting = true,
				natural_materials = true,
				general = true,
				hard_materials = true,
			},
		},
		iron = {
			auto_pickup = true,
			name = "Iron",
			stack_def = crafting_stack,
			item_slot = "stash",
			sprite_category = "resource",
			sprite_id = "07",
			stat_bonus = 7,
			craft_container = "craft_iron",
			material_price_factor = 49,
			level_peak = 75,
			level_range = 80,
			material_tint = FloatColor:new(1, 0.79, 0.85, 1),
			crafting = {},
			filters = {
				crafting = true,
				constructed_materials = true,
				general = true,
				armor_materials = true,
				hard_materials = true,
				elastic_materials = true,
			},
		},
		cothra = {
			auto_pickup = true,
			name = "Cothra",
			stack_def = crafting_stack,
			item_slot = "stash",
			sprite_category = "resource",
			sprite_id = "08",
			stat_bonus = 8,
			craft_container = "craft_cothra",
			material_price_factor = 64,
			level_peak_factor = 0.25,
			level_peak = 90,
			level_range = 95,
			material_tint = FloatColor:new(1, 0.72, 1, 0.85),
			crafting = {},
			filters = {
				crafting = true,
				natural_materials = true,
				general = true,
				armor_materials = true,
				hard_materials = true,
				elastic_materials = true,
				potion_materials = true,
			},
		},
		fur = {
			auto_pickup = true,
			name = "Fur",
			stack_def = crafting_stack,
			item_slot = "stash",
			sprite_category = "resource",
			sprite_id = "13",
			stat_bonus = 0,
			craft_container = "craft_fur",
			material_price_factor = 1,
			level_peak = 1,
			level_range = 30,
			material_tint = FloatColor:new(1, 1, 1, 0.85),
			crafting = {},
			filters = {
				crafting = true,
				natural_materials = true,
				general = true,
			},
		},
		silk = {
			auto_pickup = true,
			name = "Silk",
			stack_def = crafting_stack,
			item_slot = "stash",
			sprite_category = "resource",
			sprite_id = "12",
			stat_bonus = 3,
			craft_container = "craft_silk",
			material_price_factor = 9,
			level_peak_factor = 0.75,
			level_peak = 30,
			level_range = 40,
			material_tint = FloatColor:new(1, 1, 0.7, 0.95),
			crafting = {},
			filters = {
				crafting = true,
				natural_materials = true,
				general = true,
			},
		},
		starfibre = {
			auto_pickup = true,
			name = "Star Fibre",
			stack_def = crafting_stack,
			item_slot = "stash",
			sprite_category = "resource",
			sprite_id = "11",
			stat_bonus = 6,
			craft_container = "craft_starfibre",
			material_price_factor = 36,
			level_peak_factor = 0.25,
			level_peak = 60,
			level_range = 55,
			material_tint = FloatColor:new(1, 0.72, 0.72, 0.9),
			crafting = {},
			filters = {
				crafting = true,
				natural_materials = true,
				general = true,
				elastic_materials = true,
				potion_materials = true,
			},
		},
		dragonscale = {
			auto_pickup = true,
			name = "Dragon Scale",
			stack_def = crafting_stack,
			item_slot = "stash",
			sprite_category = "resource",
			sprite_id = "09",
			stat_bonus = 10,
			craft_container = "craft_dragonscale",
			material_price_factor = 100,
			level_peak_factor = 0.1,
			level_peak = 100,
			level_range = 50,
			material_tint = FloatColor:new(1, 1, 0.6, 0.3),
			crafting = {},
			filters = {
				crafting = true,
				natural_materials = true,
				general = true,
				armor_materials = true,
				hard_materials = true,
			},
		},


		rotten = {
			name = "Rotten",
			stat_bonus = 0,
			material_price_factor = 1,
			level_peak = 1,
			level_range = 15,
			material_tint = FloatColor:new(1, 0.77, 0.9, 0.84),
			filters = {},
		},
		stale = {
			name = "Stale",
			stat_bonus = 3,
			material_price_factor = 5,
			level_peak = 30,
			level_range = 30,
			material_tint = FloatColor:new(1, 0.8, 1, 0.97),
			filters = {},
		},
		fresh = {
			name = "Fresh",
			stat_bonus = 6,
			material_price_factor = 15,
			level_peak = 60,
			level_range = 50,
			material_tint = FloatColor:new(1, 1, 0.95, 0.89),
			filters = {},
		},
		artisan = {
			name = "Artisan",
			stat_bonus = 9,
			material_price_factor = 48,
			level_peak = 90,
			level_range = 70,
			material_tint = FloatColor:new(1, 1, 1, 1),
			filters = {},
		},
	},
	generate = function(rules, def, level, index, rarity)
		local rarity = rarity or "common"
		local rdef = RARITY_DEFS[rarity or "common"]
		local item_level = rdef.level_offset + level		
		local item = Item:new(def, level, index)
		item:set_display_name(def.name)
		item:set_name_color(rdef.color)

		local stack_def = def.stack_def
		if def.stack_def then
			local factor = 1
			if stack_def.rarity_factor then
				factor = factor*stack_def.rarity_factor[rarity]
			end
			local stack = math.round(stack_def.base*factor + math.random(item_level*stack_def.factor_min*factor, item_level*stack_def.factor_max*factor))
			item:set_stack(math.max(1,stack))	
		else	
			item:set_rarity(rarity)
		end

		if def.tint then
			item:set_tints(def.tint, def.outline_tint)
		end


		local stats
		if def.stats then
			stats = {}
			local rarity_quality = quality_rarity_factors[rarity]
			for stat, amt in pairs(def.stats) do
				local new_amt = amt
				local spread = STAT_BONUS_QUALITY_FACTOR[stat]
				if spread then
					local roll = math.random()*rarity_quality-math.random()/rarity_quality
					local diff = new_amt*roll*spread					
					if diff ~= 0 then
						new_amt = math.round((new_amt + diff)*10)/10
					end
				end
				stats[stat] = new_amt
			end
			item:set_stats(stats)			
		end

		if def.effect then
			local effect = rules:generate_instance("effect", def.effect, level)
			assert(stats)
			effect:init_stats(stats)			
			item:set_effect(effect)
		end

		
		if def.price then
			item:set_price(def.price)
		else
			local price = (math.max(1,item_level)*(def.price_factor or 1)*quality_rarity_factors[rarity])
			item:set_price(math.ceil(price))
		end


		if def.sprite_name then
			local spr, out = SPRITES[def.sprite_name], SPRITES[def.outline_name] 
			assert(spr, index)
			assert(out, index)
			item:set_sprites(spr, out)
		end
		
		if def.projectile_sprite_name then				
			item:set_projectile_sprites(SPRITES[def.projectile_sprite_name], SPRITES[def.projectile_outline_name])
		elseif def.sprite_name then
			item:set_projectile_sprites(SPRITES[def.sprite_name], SPRITES[def.outline_name])
		end
		return item
	end,
}

items = {}


local MATERIAL_BONUS_MUL = 5
local LEVEL_OFFSET_STAT_BONUS_FACTOR = 0.1

local sprite_bases = {
	weapon = {
		sprite_prefix = "weapons_",
		outline_prefix = "weapons_outline_",
	},
	resource = {
		sprite_prefix = "resource_",
		outline_prefix = "resource_outline_",
	},
	attack = {
		sprite_prefix = "attack_",
		outline_prefix = "attack_outline_",
	},
	equipment = {
		sprite_suffix = "-equipment",
		outline_suffix = "-equipment_outline",
	},
}

function items.init_rules()
	local new_defs = {}
	local peaks = {}
	for index, def in pairs(RULE_ITEMS.categories) do
		if def.effect then
			assert(def.stats, "no stats!", index)
		end
		if def.sprite_id then
			local base = sprite_bases[def.sprite_category]
			def.sprite_name = (base.sprite_prefix or "")..def.sprite_id..(base.sprite_suffix or "")
			def.outline_name = (base.outline_prefix or "")..def.sprite_id..(base.outline_suffix or "")
		end
		if def.projectile_sprite_id then
			local base = sprite_bases[def.sprite_category]
			def.projectile_sprite_name = base.sprite_prefix..def.projectile_sprite_id
			def.projectile_outline_name = base.outline_prefix..def.projectile_sprite_id
		end
		if def.materials then
			peaks[def.level_offset] = (peaks[def.level_offset] or 0) +1
			for mat,_ in pairs(def.materials) do
				local new_index = mat.."_"..index
				local new_def = table.shallowCopy(def)
				assert(new_def.filters, index)
				new_def.filters = table.shallowCopy(def.filters)
				new_def.filters["crafted_by_"..mat] = true

				local mat_def = RULE_ITEMS.categories[mat]

				new_def.name = (mat_def.prefix or mat_def.name).." "..assert(def.name, index, "missing name")
				new_def.level_peak = mat_def.level_peak + (def.level_offset or 0)
				new_def.level_range = mat_def.level_range*(def.level_range_factor or 1)
				new_def.level_peak_factor = (mat_def.level_peak_factor or 1)* (def.level_peak_factor or 1)
				new_def.materials = nil
				new_def.material = mat
				local base_price_factor = (def.price_factor or 1)
				new_def.price_factor = base_price_factor + (base_price_factor*mat_def.material_price_factor or 0) + def.level_offset
				if def.stats then
					local stats = {}
					local stat_bonus = mat_def.stat_bonus + def.level_offset*LEVEL_OFFSET_STAT_BONUS_FACTOR
					for stat, amt in pairs(def.stats) do
						local bonus_factor = (STAT_BONUS_FACTOR[stat] or 0)
						local new_amt = amt
						if bonus_factor ~= 0 then
							new_amt = new_amt + math.abs(amt)*bonus_factor*stat_bonus*MATERIAL_BONUS_MUL
						end
						stats[stat] = math.round(new_amt*10)/10
					end
					new_def.stats = stats
				end

				new_def.tint = mat_def.material_tint
				new_defs[new_index] = new_def

				if mat_def.crafting then
					table.insert(mat_def.crafting, new_index)
				end
				--print("generated", new_index," at level peak", new_def.level_peak)
			end
			RULE_ITEMS.categories[index] = nil
		end
	end
	--printtable(peaks)
	for index, new_def in pairs(new_defs) do
		RULE_ITEMS.categories[index] = new_def
	end
end


return RULE_ITEMS
