### Royal Armorer Tasks ###
# Three tasks for royal_armorer_court_position
# Adapted for CK3 1.19 framework

# ============================================================
# TASK 1: Maintain the Royal Armory
# Default task. The Armorer keeps weapons, armor, and equipment
# in peak condition, providing steady combat bonuses.
# ============================================================

royal_armorer_maintain_armory = {
	court_position_types = { royal_armorer_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"
				}
			}
		}
	}

	# The Armorer refines their craft through daily work
	employee_modifier = {
		monthly_martial_lifestyle_xp_gain_mult = 0.05
		prowess = 1
	}

	# Employer's knights and artifact durability benefit
	scaling_employer_modifiers = {
		terrible = {
			knight_effectiveness_mult = 0.02
			artifact_decay_reduction_mult = -0.02
		}
		poor = {
			knight_effectiveness_mult = 0.04
			artifact_decay_reduction_mult = -0.04
		}
		average = {
			knight_effectiveness_mult = 0.06
			artifact_decay_reduction_mult = -0.06
		}
		good = {
			knight_effectiveness_mult = 0.08
			artifact_decay_reduction_mult = -0.08
		}
		excellent = {
			knight_effectiveness_mult = 0.10
			artifact_decay_reduction_mult = -0.10
		}
	}

	is_shown = { }
	is_valid_showing_failures_only = { }

	on_start = { }
	on_end = { }

	ai_will_do = {
		value = 1
		# More likely if ruler owns artifacts worth preserving
		if = {
			limit = {
				any_owned_artifact = { always = yes }
			}
			add = 20
		}
		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: Forge New Equipment
# The Armorer focuses on crafting new weapons and armor for
# the ruler's forces, improving prowess and men-at-arms quality.
# ============================================================

royal_armorer_forge_equipment = {
	court_position_types = { royal_armorer_court_position }

	# Monthly cost for the task — forging requires materials
	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"
				}
				# Forging is more expensive than maintenance
				add = {
					value = monthly_court_position_task_cost
					multiply = 0.5
					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"
				}
				add = {
					value = monthly_court_position_task_cost
					multiply = 0.5
					desc = COURT_POSITION_TASK_COST_BREAKDOWN_BASE
					format = "BASE_VALUE_FORMAT_DECIMALS_PLUS_NEGATIVE"
				}
			}
		}
	}

	# The Armorer earns prestige as a master craftsman
	employee_modifier = {
		monthly_prestige = 0.50
		prowess = 2
		tourney_participant_xp_gain_mult = 0.10
	}

	# Employer's forces gain equipment-driven combat bonuses
	scaling_employer_modifiers = {
		terrible = {
			prowess = 1
			men_at_arms_maintenance = -0.02
		}
		poor = {
			prowess = 1
			men_at_arms_maintenance = -0.03
		}
		average = {
			prowess = 1
			men_at_arms_maintenance = -0.04
			knight_effectiveness_mult = 0.03
		}
		good = {
			prowess = 2
			men_at_arms_maintenance = -0.05
			knight_effectiveness_mult = 0.05
			accolade_glory_gain_mult = 0.05
		}
		excellent = {
			prowess = 2
			men_at_arms_maintenance = -0.06
			knight_effectiveness_mult = 0.06
			accolade_glory_gain_mult = 0.10
		}
	}

	is_shown = { }
	is_valid_showing_failures_only = { }

	on_start = { }
	on_end = { }

	ai_will_do = {
		value = 1
		# Martially focused rulers want the best equipment
		if = {
			limit = {
				has_lifestyle = martial_lifestyle
			}
			add = 20
		}
		# More worthwhile when preparing for war
		if = {
			limit = {
				is_at_war = yes
			}
			add = 20
		}
		# Avoid if too expensive
		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
		}
	}
}
