﻿riseandfall_puppet_master_court_position = {
	sort_order = 390
	max_available_positions = 1
	skill = intrigue

	court_position_asset = {
		animation = scheme
		background = "gfx/interface/illustrations/event_scenes/throneroom_mediterranean.dds"
	}

	opinion = {
		value = 25
	}

	aptitude_level_breakpoints = { 20 40 60 80 }

	aptitude = {
		value = 1
		add = {
			value = intrigue
			multiply = 2
			max = 100
			desc = court_position_skill_intrigue
		}
	}

	# Keep the office container present through the brief inactive/type-less gap
	# while a dead Puppet Master is replaced. The persistent marker is cleared
	# only when the puppet regency intentionally ends.
	is_shown = {
		OR = {
			has_diarchy_type = puppet_regency
			has_character_flag = rf_puppet_regency_persistent
		}
	}

	valid_position = {
		OR = {
			has_diarchy_type = puppet_regency
			has_character_flag = rf_puppet_regency_persistent
		}
	}

	# This position is script-driven; only the active diarch is a valid candidate.
	is_shown_character = {
		OR = {
			scope:employee = {
				has_court_position = riseandfall_puppet_master_court_position
			}
			scope:liege = {
				has_diarchy_type = puppet_regency
				has_active_diarchy = yes
				exists = diarch
				diarch ?= scope:employee
			}
		}
	}

	valid_character = {
		scope:employee = {
			is_alive = yes
		}
		scope:liege = {
			has_diarchy_type = puppet_regency
			has_active_diarchy = yes
			exists = diarch
			diarch ?= scope:employee
		}
	}

	revoke_cost = {
		gold = {
			value = 0
		}
	}

	# The liege pays 5% of monthly revenue as salary.
	salary = {
		gold = {
			value = 0
			if = {
				limit = {
					exists = scope:liege
					scope:liege = {
						has_treasury = no
					}
				}
				add = riseandfall_puppet_master_salary_value
			}
		}
		treasury = {
			value = 0
			if = {
				limit = {
					exists = scope:liege
					scope:liege = {
						has_treasury = yes
					}
				}
				add = riseandfall_puppet_master_treasury_salary_value
			}
		}
		round = no
	}

	received_salary = {
		gold = {
			value = 0
			if = {
				limit = {
					exists = scope:liege
					scope:liege = {
						has_treasury = no
					}
				}
				add = riseandfall_puppet_master_salary_value
			}
			if = {
				limit = {
					exists = scope:liege
					scope:liege = {
						has_treasury = yes
					}
				}
				add = riseandfall_puppet_master_treasury_salary_value
			}
		}
		round = no
	}

	on_court_position_revoked = {
		# Revoked, invalidated, and vacated can overlap during teardown; queue one
		# delayed resync instead of allowing each callback to recreate the office.
		scope:liege = {
			riseandfall_queue_puppet_master_court_position_resync_se = yes
		}
	}

	on_court_position_vacated = {
		scope:liege = {
			riseandfall_queue_puppet_master_court_position_resync_se = yes
		}
	}

	on_court_position_invalidated = {
		scope:liege = {
			riseandfall_queue_puppet_master_court_position_resync_se = yes
		}
	}

	ai_position_score = {
		# Script owns appointment. Keep this below the vanilla hire threshold so
		# the automatic court-position AI cannot race the succession resync.
		value = -1000
	}

	ai_candidate_score = {
		value = 1000
		if = {
			limit = { exists = scope:firing_court_position }
			add = 10000
		}
	}
}
