class_name QualityCalc
## Static helper for rolling an Item.Quality value at craft completion.
##
## Formula (docs/architecture.md "Quality system", Phase 6 spec):
##   roll = skill_level × 0.04 + randf() × 0.6
##
## Bucket thresholds:
##   roll < 0.10            → SHODDY
##   0.10 ≤ roll < 0.50     → NORMAL
##   0.50 ≤ roll < 0.80     → EXCELLENT
##   0.80 ≤ roll < 0.95     → MASTERWORK
##   roll ≥ 0.95            → LEGENDARY
##
## Intuition by skill level (before RNG):
##   skill  0: base 0.00; max roll ≈ 0.60 → Excellent ceiling, never Masterwork
##   skill  5: base 0.20; roll ≈ 0.20–0.80 → Excellent comfortably, Masterwork possible
##   skill 10: base 0.40; roll ≈ 0.40–1.00 → Masterwork attainable; Legendary rare (~8%)
##
## Returns an int matching Item.Quality enum values so no Item import is needed
## at call sites that only pass the int through. JobRunner logs via
## Item.Quality.keys()[quality] to get the enum name string.

static func roll(skill_level: int) -> int:
	var base: float = float(skill_level) * 0.04
	var noise: float = randf() * 0.6
	var roll_val: float = base + noise
	if roll_val < 0.10:
		return Item.Quality.SHODDY
	if roll_val < 0.50:
		return Item.Quality.NORMAL
	if roll_val < 0.80:
		return Item.Quality.EXCELLENT
	if roll_val < 0.95:
		return Item.Quality.MASTERWORK
	return Item.Quality.LEGENDARY
