﻿##################################################
# Rise and Fall � Puppet Master interactions
# Note: Some tokens here are placeholders pending your scripted effects/triggers; adjust as needed.

# Interaction: Steal Gold

riseandfall_steal_gold_interaction = {
	interface_priority = 100
	common_interaction = yes
	category = interaction_riseandfall
	icon = icon_riseandfall
	show_effects_in_notification = yes
	desc = riseandfall_steal_gold_interaction_desc
	diarch_interaction = yes

	# Show only to the active diarch targeting their liege while a puppet regency is active
	is_shown = {
		# Show to AI actors always, and to human players only when Lite Mode is disabled
		OR = {
			scope:actor = { is_ai = yes }
			AND = {
				scope:actor = { is_ai = no }
				has_game_rule = riseandfall_lite_mode_disabled
			}
		}

		scope:recipient = {
			has_diarchy_type = puppet_regency
			is_independent_ruler = yes
		}
		# Only the diarch of that recipient should see/send this interaction
		scope:actor = { is_diarch_of_target = scope:recipient }
	}

	# Basic validity (no additional UI failures)
	is_valid_showing_failures_only = {
		# Only allow if the actor is the active diarch of the recipient
		scope:actor = { is_diarch_of_target = scope:recipient }
		scope:recipient = {
			is_independent_ruler = yes
			riseandfall_liege_has_gold = yes
		}
		riseandfall_liege_stability_below_50 = yes
	}

	# Auto-accept: this is a unilateral diarch action
	auto_accept = yes

	# Can send (AI and players)
	can_send = {
		# Ensure we have something to steal � leave precise value check to effect
		always = yes
	}
	# Allow AI to consider this interaction
	ai_potential = { exists = this is_alive = yes }
	# Immediate execution (hidden)
	on_accept = {
		custom_tooltip = { text = riseandfall_steal_gold_interaction_desc }
		hidden_effect = {
			riseandfall_steal_gold_effect = yes
			scope:recipient = {
				send_interface_popup = {
					type = send_interface_message_bad
					title = riseandfall_steal_gold_popup_title
					custom_tooltip = riseandfall_steal_gold_popup_desc
					left_icon = scope:actor
				}
				every_vassal = {
					send_interface_message = {
						type = send_interface_message_bad
						title = riseandfall_steal_gold_vassal_notification_title
						custom_tooltip = riseandfall_steal_gold_vassal_notification_desc
						left_icon = scope:actor
					}
				}
			}
		}
	}

	# AI should always consider using it when available
	# How often AI considers this by top-title tier (months)
	ai_frequency = 12

	# Interaction cooldowns (use built-in cooldowns instead of a custom variable)
	cooldown = { years = 1 }
	cooldown_against_recipient = { years = 1 }

    ai_targets = {
		ai_recipients = liege
		max = 1
	}

	ai_will_do = {
		# Opportunistic: steal gold from a liege. Prefer greedy / deceitful actors and disliked/weak lieges.
		base = 40
		modifier = { scope:actor = { has_trait = greedy } add = 40 }
		modifier = { scope:actor = { has_trait = deceitful } add = 30 }
		modifier = { scope:actor = { has_trait = ambitious } add = 20 }
		modifier = { scope:actor = { has_trait = honest } add = -30 }

		# Trait-driven behavior: cruel/arbitrary actors are more likely to destabilize; just actors avoid it
		modifier = { scope:actor = { has_trait = callous } add = 30 }
		modifier = { scope:actor = { has_trait = arbitrary } add = 25 }
		modifier = { scope:actor = { has_trait = just } add = -50 }

		modifier = { scope:recipient = { opinion = { target = scope:actor value < 0 } } add = 40 }
		modifier = { scope:actor = { is_at_war = yes } add = -30 }

		# Power-preserving actors become cautious once the realm starts slipping.
		modifier = {
			scope:recipient = {
				has_variable = riseandfall_realm_stability_score
				NOT = { var:riseandfall_realm_stability_score >= 55 }
			}
			add = -20
		}
		modifier = {
			scope:actor = {
				OR = {
					has_trait = diligent
					has_trait = patient
					has_trait = temperate
					has_trait = calm
					has_trait = just
				}
			}
			scope:recipient = {
				has_variable = riseandfall_realm_stability_score
				NOT = { var:riseandfall_realm_stability_score >= 55 }
			}
			add = -25
		}
		modifier = {
			scope:actor = {
				OR = {
					has_trait = callous
					has_trait = arbitrary
					has_trait = greedy
					has_trait = deceitful
				}
			}
			scope:recipient = {
				has_variable = riseandfall_realm_stability_score
				NOT = { var:riseandfall_realm_stability_score >= 55 }
			}
			add = 20
		}
		modifier = {
			scope:recipient = {
				has_variable = riseandfall_realm_stability_score
				NOT = { var:riseandfall_realm_stability_score >= 30 }
			}
			add = -45
		}
		modifier = {
			scope:actor = { has_trait = ambitious }
			scope:recipient = {
				has_variable = riseandfall_realm_stability_score
				NOT = { var:riseandfall_realm_stability_score >= 30 }
			}
			add = -20
		}
		# Keep some puppet stability mana in reserve unless the actor is especially reckless.
		modifier = {
			scope:recipient = {
				has_variable = riseandfall_rs_puppet_stability_bonus
				NOT = { var:riseandfall_rs_puppet_stability_bonus >= 25 }
			}
			add = -15
		}
		modifier = {
			scope:actor = {
				OR = {
					has_trait = diligent
					has_trait = patient
					has_trait = temperate
					has_trait = just
				}
			}
			scope:recipient = {
				has_variable = riseandfall_rs_puppet_stability_bonus
				NOT = { var:riseandfall_rs_puppet_stability_bonus >= 25 }
			}
			add = -25
		}
		modifier = {
			scope:recipient = {
				has_variable = riseandfall_rs_puppet_stability_bonus
				NOT = { var:riseandfall_rs_puppet_stability_bonus >= 0 }
			}
			add = -40
		}
		modifier = {
			scope:actor = {
				OR = {
					has_trait = callous
					has_trait = arbitrary
					has_trait = greedy
					has_trait = deceitful
				}
			}
			scope:recipient = {
				has_variable = riseandfall_rs_puppet_stability_bonus
				NOT = { var:riseandfall_rs_puppet_stability_bonus >= 0 }
			}
			add = 30
		}
	}
}
# Interaction: Curry Favor (gain a strong favor hook)
riseandfall_curry_favor_interaction = {
	interface_priority = 90
	common_interaction = yes
	category = interaction_riseandfall
	icon = icon_riseandfall
	show_effects_in_notification = yes
	desc = riseandfall_curry_favor_interaction_desc
	diarch_interaction = yes

	is_shown = {
		OR = {
			scope:actor = { is_ai = yes }
			AND = {
				scope:actor = { is_ai = no }
				has_game_rule = riseandfall_lite_mode_disabled
			}
		}

		scope:recipient = {
			has_diarchy_type = puppet_regency
			is_independent_ruler = yes
		}
		# Actor must be the diarch of this recipient
		scope:actor = { is_diarch_of_target = scope:recipient }
	}

	is_valid_showing_failures_only = { 
		# Only the diarch of the recipient may use this
		scope:actor = { is_diarch_of_target = scope:recipient }
		# Disallow curry favor if actor already has a strong favor hook on the recipient
		scope:actor = { NOT = { has_hook_of_type = { target = scope:recipient type = strong_favor_hook } } }
		scope:recipient = {
			is_independent_ruler = yes
		}
	}

	auto_accept = yes

	on_accept = {
		custom_tooltip = { text = riseandfall_curry_favor_interaction_desc }
		hidden_effect = {
			riseandfall_curry_favor_effect = yes
			scope:recipient = {
				send_interface_popup = {
					type = send_interface_message_bad
					title = riseandfall_curry_favor_popup_title
					custom_tooltip = riseandfall_curry_favor_popup_desc
					left_icon = scope:actor
				}
				every_vassal = {
					send_interface_message = {
						type = send_interface_message_bad
						title = riseandfall_curry_favor_vassal_notification_title
						custom_tooltip = riseandfall_curry_favor_vassal_notification_desc
						left_icon = scope:actor
					}
				}
			}
		}
	}

	# How often AI considers this by top-title tier (months)
	ai_frequency = 12

	# Interaction cooldowns (use built-in cooldowns instead of a custom variable)
	cooldown = { years = 1 }
	cooldown_against_recipient = { years = 1 }

	# Allow AI to consider this interaction
	ai_potential = { exists = this is_alive = yes }

	ai_targets = {
		ai_recipients = liege
		max = 1
	}

	ai_will_do = {
		# Curry favor: manipulation to gain hooks. Preferred by ambitious/deceitful actors; penalize honest/just actors.
		base = 40

		modifier = { scope:actor = { has_trait = ambitious } add = 30 }
		modifier = { scope:actor = { has_trait = deceitful } add = 30 }
		modifier = { scope:actor = { has_trait = greedy } add = 20 }
		modifier = { scope:actor = { has_trait = honest } add = -30 }
		modifier = { scope:actor = { has_trait = just } add = -50 }

		# Trait-driven behavior: cruel/arbitrary actors are more likely to destabilize; just actors avoid it
		modifier = { scope:actor = { has_trait = callous } add = 30 }
		modifier = { scope:actor = { has_trait = arbitrary } add = 25 }

		# If the liege already likes the diarch, easier to curry favor; otherwise it's harder.
		modifier = { scope:recipient = { opinion = { target = scope:actor value >= 30 } } add = 20 }
		modifier = { scope:recipient = { opinion = { target = scope:actor value <= -20 } } add = -20 }

		modifier = { scope:actor = { is_at_war = yes } add = -30 }

		# Power-preserving actors become cautious once the realm starts slipping.
		modifier = {
			scope:recipient = {
				has_variable = riseandfall_realm_stability_score
				NOT = { var:riseandfall_realm_stability_score >= 55 }
			}
			add = -20
		}
		modifier = {
			scope:actor = {
				OR = {
					has_trait = diligent
					has_trait = patient
					has_trait = temperate
					has_trait = calm
					has_trait = just
				}
			}
			scope:recipient = {
				has_variable = riseandfall_realm_stability_score
				NOT = { var:riseandfall_realm_stability_score >= 55 }
			}
			add = -25
		}
		modifier = {
			scope:actor = {
				OR = {
					has_trait = callous
					has_trait = arbitrary
					has_trait = greedy
					has_trait = deceitful
				}
			}
			scope:recipient = {
				has_variable = riseandfall_realm_stability_score
				NOT = { var:riseandfall_realm_stability_score >= 55 }
			}
			add = 20
		}
		modifier = {
			scope:recipient = {
				has_variable = riseandfall_realm_stability_score
				NOT = { var:riseandfall_realm_stability_score >= 30 }
			}
			add = -45
		}
		modifier = {
			scope:actor = { has_trait = ambitious }
			scope:recipient = {
				has_variable = riseandfall_realm_stability_score
				NOT = { var:riseandfall_realm_stability_score >= 30 }
			}
			add = -20
		}
		# Keep some puppet stability mana in reserve unless the actor is especially reckless.
		modifier = {
			scope:recipient = {
				has_variable = riseandfall_rs_puppet_stability_bonus
				NOT = { var:riseandfall_rs_puppet_stability_bonus >= 25 }
			}
			add = -15
		}
		modifier = {
			scope:actor = {
				OR = {
					has_trait = diligent
					has_trait = patient
					has_trait = temperate
					has_trait = just
				}
			}
			scope:recipient = {
				has_variable = riseandfall_rs_puppet_stability_bonus
				NOT = { var:riseandfall_rs_puppet_stability_bonus >= 25 }
			}
			add = -25
		}
		modifier = {
			scope:recipient = {
				has_variable = riseandfall_rs_puppet_stability_bonus
				NOT = { var:riseandfall_rs_puppet_stability_bonus >= 0 }
			}
			add = -40
		}
		modifier = {
			scope:actor = {
				OR = {
					has_trait = callous
					has_trait = arbitrary
					has_trait = greedy
					has_trait = deceitful
				}
			}
			scope:recipient = {
				has_variable = riseandfall_rs_puppet_stability_bonus
				NOT = { var:riseandfall_rs_puppet_stability_bonus >= 0 }
			}
			add = 30
		}
	}
}

# Interaction: Seize Liege Land (take one smart de jure bundle from the puppet ruler)
riseandfall_seize_liege_land_interaction = {
	interface_priority = 88
	common_interaction = yes
	category = interaction_riseandfall
	icon = icon_riseandfall
	show_effects_in_notification = yes
	desc = riseandfall_seize_liege_land_interaction_desc
	diarch_interaction = yes

	is_shown = {
		OR = {
			scope:actor = { is_ai = yes }
			AND = {
				scope:actor = { is_ai = no }
				has_game_rule = riseandfall_lite_mode_disabled
			}
		}

		scope:recipient = {
			has_diarchy_type = puppet_regency
			is_independent_ruler = yes
			is_landed = yes
			is_landless_ruler = no
			NOT = { has_government = landless_adventurer_government }
		}
		scope:actor = { is_diarch_of_target = scope:recipient }
	}

	is_valid_showing_failures_only = {
		custom_tooltip = {
			text = riseandfall_puppet_master_diarch_only
			scope:actor = { is_diarch_of_target = scope:recipient }
		}
		scope:recipient = {
			is_independent_ruler = yes
			is_landed = yes
			is_landless_ruler = no
			NOT = { has_government = landless_adventurer_government }
		}
		riseandfall_puppet_master_has_seizable_liege_land = yes
	}

	auto_accept = yes

	can_send = { always = yes }

	on_accept = {
		custom_tooltip = { text = riseandfall_seize_liege_land_interaction_desc }
		hidden_effect = {
			riseandfall_seize_liege_land_effect = yes
			scope:recipient = {
				send_interface_popup = {
					type = send_interface_message_bad
					title = riseandfall_seize_liege_land_popup_title
					custom_tooltip = riseandfall_seize_liege_land_popup_desc
					left_icon = scope:actor
				}
				every_vassal = {
					send_interface_message = {
						type = send_interface_message_bad
						title = riseandfall_seize_liege_land_vassal_notification_title
						custom_tooltip = riseandfall_seize_liege_land_vassal_notification_desc
						left_icon = scope:actor
					}
				}
			}
		}
	}

	ai_frequency = 24
	cooldown = { years = 5 }
	cooldown_against_recipient = { years = 5 }

	ai_potential = { exists = this is_alive = yes }

	ai_targets = {
		ai_recipients = liege
		max = 1
	}

	ai_will_do = {
		base = 10

		modifier = { scope:actor = { has_trait = ambitious } add = 50 }
		modifier = { scope:actor = { has_trait = greedy } add = 35 }
		modifier = { scope:actor = { has_trait = deceitful } add = 25 }
		modifier = { scope:actor = { has_trait = callous } add = 25 }
		modifier = { scope:actor = { has_trait = vengeful } add = 20 }
		modifier = { scope:actor = { has_trait = arbitrary } add = 15 }

		modifier = { scope:actor = { has_trait = just } add = -60 }
		modifier = { scope:actor = { has_trait = honest } add = -45 }
		modifier = { scope:actor = { has_trait = calm } add = -25 }
		modifier = { scope:actor = { has_trait = content } add = -25 }

		# Puppet masters are more willing to seize land when the liege dislikes them
		# or when the realm is already visibly unstable.
		modifier = { scope:recipient = { opinion = { target = scope:actor value < 0 } } add = 20 }
		modifier = { scope:recipient = { opinion = { target = scope:actor value <= -50 } } add = 20 }
		modifier = {
			scope:recipient = {
				has_variable = riseandfall_realm_stability_score
				NOT = { var:riseandfall_realm_stability_score >= 45 }
			}
			add = 20
		}

		# Avoid pushing a puppet regime that is already running negative mana,
		# unless the actor is especially predatory.
		modifier = {
			scope:recipient = {
				has_variable = riseandfall_rs_puppet_stability_bonus
				NOT = { var:riseandfall_rs_puppet_stability_bonus >= 0 }
			}
			add = -45
		}
		modifier = {
			scope:actor = {
				OR = {
					has_trait = ambitious
					has_trait = greedy
					has_trait = callous
					has_trait = arbitrary
				}
			}
			scope:recipient = {
				has_variable = riseandfall_rs_puppet_stability_bonus
				NOT = { var:riseandfall_rs_puppet_stability_bonus >= 0 }
			}
			add = 35
		}
	}
}

# Interaction: Overthrow Liege (transfer all titles to diarch)
riseandfall_overthrow_liege_interaction = {
	interface_priority = 80
	common_interaction = no
	category = interaction_riseandfall
	icon = icon_riseandfall
	show_effects_in_notification = yes
	desc = riseandfall_overthrow_liege_interaction_desc
	diarch_interaction = yes

	is_shown = {
		OR = {
			scope:actor = { is_ai = yes }
			AND = {
				scope:actor = { is_ai = no }
				has_game_rule = riseandfall_lite_mode_disabled
			}
		}

		scope:recipient = {
			has_diarchy_type = puppet_regency
			is_independent_ruler = yes
		}
		# Restrict this to the recipient's active diarch
		scope:actor = { is_diarch_of_target = scope:recipient }
	}

	# Gate on stability < 30
	is_valid_showing_failures_only = {
		# Only allow the active diarch to perform this
		scope:actor = {
			is_diarch_of_target = scope:recipient
			# Characters barred from marriage cannot be legitimate power-seizing puppet masters.
			NOT = { has_trait_with_flag = can_not_marry }
			can_marry_trigger = yes
		}
		scope:recipient = {
			is_independent_ruler = yes
		}
		riseandfall_liege_stability_below_30 = yes
		riseandfall_puppet_regency_years_at_least_5 = yes
	}

	auto_accept = yes

	on_accept = {
		custom_tooltip = { text = riseandfall_overthrow_liege_interaction_desc }
		hidden_effect = {
			riseandfall_overthrow_liege_effect = yes
			scope:recipient = {
				send_interface_popup = {
					type = send_interface_message_bad
					title = riseandfall_overthrow_liege_popup_title
					custom_tooltip = riseandfall_overthrow_liege_popup_desc
					left_icon = scope:actor
				}
				every_vassal = {
					send_interface_message = {
						type = send_interface_message_bad
						title = riseandfall_overthrow_liege_vassal_notification_title
						custom_tooltip = riseandfall_overthrow_liege_vassal_notification_desc
						left_icon = scope:actor
					}
				}
			}
		}
	}
	# How often AI considers this by top-title tier (months)
	ai_frequency = 6

	# Interaction cooldowns (use built-in cooldowns instead of a custom variable)
	cooldown = { years = 1 }
	cooldown_against_recipient = { years = 1 }

	# Allow AI to consider this interaction
	ai_potential = { exists = this is_alive = yes }

    ai_targets = {
		ai_recipients = liege
		max = 1
	}

	# Rare/conditional � rebalanced to make overthrow achievable under clear conditions
	ai_will_do = {
		# Overthrow: major action � still rare, but more likely when stability, tenure, opinion or wartime conditions favor the actor
		base = -40

		# Traits
		modifier = { scope:actor = { has_trait = ambitious } add = 80 }
		modifier = { scope:actor = { has_trait = greedy } add = 50 }
		modifier = { scope:actor = { has_trait = vengeful } add = 40 }
		modifier = { scope:actor = { has_trait = deceitful } add = 30 }
		modifier = { scope:actor = { has_trait = honest } add = -60 }
		# Trait-driven behavior: cruel/arbitrary actors are more willing to seize power; just actors avoid upheaval
		modifier = { scope:actor = { has_trait = callous } add = 20 }
		modifier = { scope:actor = { has_trait = arbitrary } add = 15 }
		modifier = { scope:actor = { has_trait = just } add = -40 }

		# Opinion tiers � stronger incentive when relations are poor
		modifier = { scope:recipient = { opinion = { target = scope:actor value < 0 } } add = 60 }
		modifier = { scope:recipient = { opinion = { target = scope:actor value <= -50 } } add = 40 }

		# Stability & tenure make overthrow easier
		modifier = { scope:recipient = { riseandfall_liege_stability_below_30 = yes } add = 40 }
		modifier = { scope:recipient = { has_variable = riseandfall_puppet_regency_years var:riseandfall_puppet_regency_years >= 10 } add = 40 }
		modifier = { scope:recipient = { riseandfall_puppet_regency_years_at_least_5 = yes } add = 20 }

		# Liege distracted / vulnerable
		modifier = { scope:recipient = { is_at_war = yes } add = 30 }

		# Actor advantages
		modifier = { scope:actor = { has_hook_of_type = { target = scope:recipient type = strong_favor_hook } } add = 20 }
		modifier = { scope:actor = { is_at_war = yes } add = -30 }

		# Prefer not to overthrow if the realm is stable � the puppet master benefits from stability too
		modifier = {
			scope:recipient = {
				has_variable = riseandfall_realm_stability_score
				var:riseandfall_realm_stability_score >= 60
			}
			add = -30
		}
		# Cruel/arbitrary actors may ignore the stability restraint
		modifier = {
			scope:actor = { has_trait = callous }
			scope:recipient = {
				has_variable = riseandfall_realm_stability_score
				var:riseandfall_realm_stability_score >= 60
			}
			add = 30
		}
		modifier = {
			scope:actor = { has_trait = arbitrary }
			scope:recipient = {
				has_variable = riseandfall_realm_stability_score
				var:riseandfall_realm_stability_score >= 60
			}
			add = 25
		}
		# More eager to cash out once the puppet stability reserve is already underwater.
		modifier = {
			scope:recipient = {
				has_variable = riseandfall_rs_puppet_stability_bonus
				NOT = { var:riseandfall_rs_puppet_stability_bonus >= 0 }
			}
			add = 30
		}
		modifier = {
			scope:actor = { has_trait = ambitious }
			scope:recipient = {
				has_variable = riseandfall_rs_puppet_stability_bonus
				NOT = { var:riseandfall_rs_puppet_stability_bonus >= 0 }
			}
			add = 15
		}
	}
}

# Interaction: Claim Puppet Master Office (gain the official court position)
riseandfall_claim_puppet_master_office_interaction = {
	interface_priority = 84
	common_interaction = yes
	category = interaction_riseandfall
	icon = icon_riseandfall
	show_effects_in_notification = yes
	desc = riseandfall_claim_puppet_master_office_interaction_desc
	diarch_interaction = yes

	is_shown = {
		OR = {
			scope:actor = { is_ai = yes }
			AND = {
				scope:actor = { is_ai = no }
				has_game_rule = riseandfall_lite_mode_disabled
			}
		}

		scope:recipient = {
			has_diarchy_type = puppet_regency
			is_independent_ruler = yes
		}
		# Only visible to the recipient's active diarch who is not already the puppet master position holder
		scope:actor = {
			is_diarch_of_target = scope:recipient
			NOT = { has_court_position = riseandfall_puppet_master_court_position }
		}
	}

	is_valid_showing_failures_only = {
		custom_tooltip = {
			text = riseandfall_claim_puppet_master_office_diarch_only
			scope:actor = { is_diarch_of_target = scope:recipient }
		}
		custom_tooltip = {
			text = riseandfall_claim_puppet_master_office_not_hired
			scope:actor = { NOT = { has_court_position = riseandfall_puppet_master_court_position } }
		}
		scope:recipient = {
			is_independent_ruler = yes
		}
	}

	auto_accept = yes

	on_accept = {
		custom_tooltip = { text = riseandfall_claim_puppet_master_office_interaction_desc }
		hidden_effect = {
			riseandfall_claim_puppet_master_office_effect = yes
			scope:recipient = {
				send_interface_popup = {
					type = send_interface_message_bad
					title = riseandfall_claim_puppet_master_office_popup_title
					custom_tooltip = riseandfall_claim_puppet_master_office_popup_desc
					left_icon = scope:actor
				}
				every_vassal = {
					send_interface_message = {
						type = send_interface_message_bad
						title = riseandfall_claim_puppet_master_office_vassal_notification_title
						custom_tooltip = riseandfall_claim_puppet_master_office_vassal_notification_desc
						left_icon = scope:actor
					}
				}
			}
		}
	}

	# How often AI considers this by top-title tier (months)
	ai_frequency = 1
	ai_potential = { exists = this is_alive = yes }
	ai_targets = { ai_recipients = liege max = 1 }
	ai_will_do = {
		base = 100
	}
}

# Interaction: Become a five-year legacy Rebel Warlord without starting a crisis
riseandfall_puppet_master_become_warlord_interaction = {
	interface_priority = 82
	common_interaction = yes
	category = interaction_riseandfall
	icon = icon_riseandfall
	show_effects_in_notification = yes
	desc = riseandfall_puppet_master_become_warlord_interaction_desc
	diarch_interaction = yes

	is_shown = {
		OR = {
			scope:actor = { is_ai = yes }
			AND = {
				scope:actor = { is_ai = no }
				has_game_rule = riseandfall_lite_mode_disabled
			}
		}
		scope:recipient = {
			has_diarchy_type = puppet_regency
			is_independent_ruler = yes
		}
		scope:actor = { is_diarch_of_target = scope:recipient }
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_diarch_of_target = scope:recipient
			is_landed = yes
			NOT = { riseandfall_is_any_warlord_trigger = yes }
		}
		scope:recipient = {
			has_diarchy_type = puppet_regency
			is_independent_ruler = yes
		}
	}

	auto_accept = yes
	can_send = { always = yes }

	on_accept = {
		custom_tooltip = { text = riseandfall_puppet_master_become_warlord_interaction_desc }
		hidden_effect = {
			scope:actor = { riseandfall_warlord_become_legacy_rebel = yes }
			scope:recipient = {
				send_interface_popup = {
					type = send_interface_message_bad
					title = riseandfall_puppet_master_become_warlord_popup_title
					custom_tooltip = riseandfall_puppet_master_become_warlord_popup_desc
					left_icon = scope:actor
				}
			}
		}
	}

	ai_frequency = 24
	cooldown = { years = 5 }
	cooldown_against_recipient = { years = 5 }
	ai_potential = { exists = this is_alive = yes }
	ai_targets = { ai_recipients = liege max = 1 }
	ai_will_do = {
		base = 5
		modifier = { scope:actor = { has_trait = ambitious } add = 50 }
		modifier = { scope:actor = { has_trait = brave } add = 20 }
		modifier = { scope:actor = { has_trait = content } add = -40 }
		modifier = { scope:actor = { has_trait = craven } add = -25 }
	}
}

# Selection is restricted to the existing diarch's ruler; this grants no new coup route.
riseandfall_assume_ruler_puppet_interaction = {
	category = interaction_riseandfall
	icon = icon_riseandfall
	interface_priority = 50
	desc = riseandfall_assume_ruler_puppet_interaction_desc
	is_available = {
		is_ai = no
		has_pam_dlc_trigger = yes
		is_adult = yes
		is_incapable = no
	}
	is_shown = {
		scope:recipient = {
			is_ai = yes
			has_active_diarchy = yes
			has_diarchy_type = puppet_regency
			diarch ?= scope:actor
			# Commands use the target interaction menu's puppet tab; this only establishes the link.
			NOT = { is_puppet_of_type = riseandfall_ruler_puppet }
		}
	}
	is_valid_showing_failures_only = {
		custom_tooltip = {
			text = riseandfall_native_puppet_other_master_tt
			scope:recipient = { NOT = { exists = puppeteer } }
		}
		custom_tooltip = {
			text = riseandfall_native_puppet_master_eligible_tt
			scope:actor = { can_have_puppets_trigger = yes }
		}
		custom_tooltip = {
			text = riseandfall_native_puppet_slot_occupied_tt
			scope:actor = { NOT = { exists = puppet:riseandfall_ruler_puppet } }
		}
	}
	on_accept = {
		hidden_effect = {
			scope:recipient = { riseandfall_sync_native_ruler_puppet_se = yes }
		}
	}
	auto_accept = yes
	ai_frequency = 0
	ai_targets = { ai_recipients = liege }
	ai_target_quick_trigger = { adult = yes }
	ai_will_do = { base = 0 }
}
