### Master at Arms Tasks ###
# Three tasks for master_at_arms_court_position
# Adapted for CK3 1.19 framework

# ============================================================
# TASK 1: Train the Knights
# Default task. The Master at Arms runs drills and training
# regimens, improving knight effectiveness and limit.
# ============================================================

master_at_arms_train_knights = {
	court_position_types = { master_at_arms_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 Master at Arms hones their own combat skills through constant drilling
	employee_modifier = {
		monthly_martial_lifestyle_xp_gain_mult = 0.10
		lifestyle_blademaster_xp_gain_mult = 0.05
	}

	# Employer's knight forces grow more effective
	scaling_employer_modifiers = {
		terrible = {
			knight_effectiveness_mult = 0.02
		}
		poor = {
			knight_effectiveness_mult = 0.04
		}
		average = {
			knight_effectiveness_mult = 0.06
			knight_limit = 1
		}
		good = {
			knight_effectiveness_mult = 0.10
			knight_limit = 2
		}
		excellent = {
			knight_effectiveness_mult = 0.15
			knight_limit = 2
		}
	}

	is_shown = { }
	is_valid_showing_failures_only = { }

	on_start = { }
	on_end = { }

	ai_will_do = {
		value = 50
		# Default preferred task for martial-focused rulers
		if = {
			limit = {
				has_lifestyle = martial_lifestyle
			}
			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: Oversee Army Readiness
# The Master at Arms reviews levies and military logistics,
# improving levy size and rally speed rather than knights.
# ============================================================

master_at_arms_oversee_army_readiness = {
	court_position_types = { master_at_arms_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 Master at Arms gains strategic experience from logistical work
	employee_modifier = {
		monthly_martial_lifestyle_xp_gain_mult = 0.05
		monthly_prestige = 0.25
	}

	# Employer's levies and military capacity improve
	scaling_employer_modifiers = {
		terrible = {
			levy_size = 0.02
		}
		poor = {
			levy_size = 0.03
			levy_reinforcement_rate = 0.05
		}
		average = {
			levy_size = 0.04
			levy_reinforcement_rate = 0.10
		}
		good = {
			levy_size = 0.05
			levy_reinforcement_rate = 0.10
			men_at_arms_maintenance = -0.05
			supply_limit_mult = 0.02
		}
		excellent = {
			levy_size = 0.06
			levy_reinforcement_rate = 0.15
			men_at_arms_maintenance = -0.05
			supply_limit_mult = 0.05
		}
	}

	is_shown = { }
	is_valid_showing_failures_only = { }

	on_start = { }
	on_end = { }

	ai_will_do = {
		value = 1
		# More likely when at war or preparing for war
		if = {
			limit = {
				is_at_war = yes
			}
			add = 40
		}
		# More likely for large realms with many levies
		if = {
			limit = {
				vassal_count >= 15
			}
			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
		}
	}
}

