### Court Herbalist Tasks ###
# Three tasks for court_herbalist_court_position
# Adapted for CK3 1.19 framework

# ============================================================
# TASK 1: Tend the Physic Garden
# Default task. The Herbalist maintains the court's herb garden
# and stores of remedies, providing passive health benefits.
# ============================================================

court_herbalist_tend_garden = {
	court_position_types = { court_herbalist_court_position }

	# Monthly cost for the task
	cost = {
		round = no
		gold = {
			value = 0
			if = {
				limit = {
					scope:liege = {
						has_treasury = no
					}
				}
				add = {
					value = monthly_court_position_task_cost
					desc = COURT_POSITION_TASK_COST_BREAKDOWN_BASE
					format = "BASE_VALUE_FORMAT_DECIMALS_PLUS_NEGATIVE"
				}
			}
		}
		treasury = {
			value = 0
			if = {
				limit = {
					scope:liege = {
						has_treasury = yes
					}
				}
				add = {
					value = monthly_court_position_task_cost
					desc = COURT_POSITION_TASK_COST_BREAKDOWN_BASE
					format = "BASE_VALUE_FORMAT_DECIMALS_PLUS_NEGATIVE"
				}
			}
		}
	}

	# Herbalist deepens their own botanical knowledge
	employee_modifier = {
		monthly_learning_lifestyle_xp_gain_mult = 0.10
	}

	# Employer gains health benefits scaled to aptitude
	scaling_employer_modifiers = {
		terrible = {
			negate_health_penalty_add = 0.05
		}
		poor = {
			negate_health_penalty_add = 0.05
		}
		average = {
			negate_health_penalty_add = 0.05
			life_expectancy = 1
		}
		good = {
			negate_health_penalty_add = 0.10
			life_expectancy = 2
		}
		excellent = {
			negate_health_penalty_add = 0.10
			life_expectancy = 3
			court_grandeur_baseline_add = 1
		}
	}

	is_shown = { }
	is_valid_showing_failures_only = { }

	on_start = { }
	on_end = { }

	ai_will_do = {
		value = 1
		# More likely if the ruler has poor health
		if = {
			limit = {
				health <= 4
			}
			add = 25
		}
		if = {
			limit = {
				has_treasury = no
				monthly_character_income < monthly_court_position_task_cost_double
			}
			add = -1000
		}
		else_if = {
			limit = {
				has_treasury = yes
				monthly_character_treasury_income < monthly_court_position_task_cost_double
			}
			add = -1000
		}
	}
}

# ============================================================
# TASK 2: Brew Remedies for the Court
# The Herbalist prepares medicines and tonics for the wider
# court, improving the wellbeing of courtiers and family.
# ============================================================

court_herbalist_brew_remedies = {
	court_position_types = { court_herbalist_court_position }

	# Monthly cost for the task
	cost = {
		round = no
		gold = {
			value = 0
			if = {
				limit = {
					scope:liege = {
						has_treasury = no
					}
				}
				add = {
					value = monthly_court_position_task_cost
					desc = COURT_POSITION_TASK_COST_BREAKDOWN_BASE
					format = "BASE_VALUE_FORMAT_DECIMALS_PLUS_NEGATIVE"
				}
			}
		}
		treasury = {
			value = 0
			if = {
				limit = {
					scope:liege = {
						has_treasury = yes
					}
				}
				add = {
					value = monthly_court_position_task_cost
					desc = COURT_POSITION_TASK_COST_BREAKDOWN_BASE
					format = "BASE_VALUE_FORMAT_DECIMALS_PLUS_NEGATIVE"
				}
			}
		}
	}

	# Herbalist gains prestige as a valued healer
	employee_modifier = {
		monthly_prestige = 0.25
		learning = 1
	}

	# Employer's family and court members benefit
	scaling_employer_modifiers = {
		terrible = {
			child_health = 0.05
		}
		poor = {
			child_health = 0.10
			negate_health_penalty_add = 0.05
		}
		average = {
			child_health = 0.10
			negate_health_penalty_add = 0.10
			diplomacy = 1
		}
		good = {
			child_health = 0.15
			negate_health_penalty_add = 0.10
			diplomacy = 1
			monthly_prestige_gain_mult = 0.05
		}
		excellent = {
			child_health = 0.15
			negate_health_penalty_add = 0.10
			diplomacy = 2
			monthly_prestige_gain_mult = 0.10
		}
	}

	is_shown = { }
	is_valid_showing_failures_only = { }

	on_start = { }
	on_end = { }

	ai_will_do = {
		value = 1
		# More likely for rulers with young children
		if = {
			limit = {
				any_child = {
					age <= 10
				}
			}
			add = 30
		}
		if = {
			limit = {
				has_treasury = no
				monthly_character_income < monthly_court_position_task_cost_double
			}
			add = -1000
		}
		else_if = {
			limit = {
				has_treasury = yes
				monthly_character_treasury_income < monthly_court_position_task_cost_double
			}
			add = -1000
		}
	}
}

# ============================================================
# TASK 3: Study Forbidden Lore
# The Herbalist delves into occult and esoteric knowledge,
# providing the ruler with intrigue and scheme bonuses at the
# risk of attracting unwanted attention.
# Only available if the court's faith permits such practices.
# ============================================================

court_herbalist_study_forbidden_lore = {
	court_position_types = { court_herbalist_court_position }

	# Monthly cost — piety spent as the ruler dabbles in the arcane
	cost = {
		round = no
		piety = {
			add = {
				value = monthly_court_position_task_cost
				desc = COURT_POSITION_TASK_COST_BREAKDOWN_BASE
				format = "BASE_VALUE_FORMAT_DECIMALS_PLUS_NEGATIVE"
			}
		}
	}

	# The Herbalist themselves grows more secretive and capable
	employee_modifier = {
		hostile_scheme_power_add = 2
		monthly_learning_lifestyle_xp_gain_mult = 0.15
	}

	# Employer gains scheme and intrigue advantages
	scaling_employer_modifiers = {
		terrible = {
			hostile_scheme_power_add = 1
			hostile_scheme_resistance_add = 1
		}
		poor = {
			hostile_scheme_power_add = 2
			hostile_scheme_resistance_add = 2
		}
		average = {
			hostile_scheme_power_add = 3
			hostile_scheme_resistance_add = 3
			dread_baseline_add = 2
		}
		good = {
			hostile_scheme_power_add = 5
			hostile_scheme_resistance_add = 5
			dread_baseline_add = 4
		}
		excellent = {
			hostile_scheme_power_add = 7
			hostile_scheme_resistance_add = 7
			dread_baseline_add = 6
		}
	}

	is_shown = {}

	# Only valid if the herbalist themselves is a witch or mystic
	is_valid_showing_failures_only = {
		custom_tooltip = {
			text = court_herbalist_study_forbidden_lore_requires_witch_tt
			OR = {
				is_witch_trigger = yes
				has_trait = lifestyle_mystic
			}
		}
	}

	on_start = { }
	on_end = { }

	ai_will_do = {
		value = 1
		# AI more likely if ruler is cynical or has mystic traits
		if = {
			limit = {
				has_trait = cynical
			}
			add = 20
		}
		if = {
			limit = {
				has_trait = curious
			}
			add = 15
		}
		# AI avoids if very zealous
		if = {
			limit = {
				has_trait = zealous
			}
			multiply = 0
		}
		# AI avoids if piety is thin
		if = {
			limit = {
				piety_level <= 1
			}
			add = -30
		}
	}
}
