﻿###################
# Claim Throne
# by Petter Vilberg
###################
claim_throne_interaction = {
	icon = icon_scheme_claim_throne
	category = interaction_category_vassal
	interface_priority = 268 # after Start Claimant Faction

	ai_targets = {
		ai_recipients = liege
	}
	
	auto_accept = yes
	use_diplomatic_range = no
	ignores_pending_interaction_block = yes


	scheme = claim_throne

	desc = claim_throne_interaction_desc
	
	is_shown = {
		exists = scope:actor.liege
		scope:recipient = scope:actor.liege
		scope:actor = {
			is_landless_adventurer = no
			highest_held_title_tier > tier_barony
			OR = {
				has_perk = meritocracy_perk
				AND = {
					is_diarch_of_target = scope:recipient
					scope:recipient = {
						NOT = { has_diarchy_parameter = can_be_instantly_dismissed }
					}
				}
				AND = {
					is_powerful_vassal_of = scope:recipient
					any_character_struggle = {
						involvement = involved
						has_struggle_phase_parameter = unlocks_claim_throne_for_powerful_vassals
						is_secondary_character_involvement_involved_trigger = {
							CHAR = scope:recipient
						}
					}
				}
				AND = {
					any_character_struggle = {
						involvement = involved
						has_struggle_phase_parameter = unlocks_claim_throne_for_all
						is_secondary_character_involvement_involved_trigger = {
							CHAR = scope:recipient
						}
					}
				}
				AND = {
					exists = title:d_sunni.holder
					is_vassal_of = title:d_sunni.holder
					any_character_struggle = {
						involvement = involved
						has_struggle_phase_parameter = unlocks_claim_throne_for_caliph_vassals
					}
				}
				has_character_flag = confederation_claim_throne
				AND = {
					government_allows = merit
					situation:dynastic_cycle ?= { situation_current_phase = situation_dynastic_cycle_phase_chaos }
					exists = top_participant_group:dynastic_cycle
				}
			}
			OR = {
				NOT = { government_allows = merit }
				government_has_flag = government_is_meritocratic
				government_has_flag = government_is_steppe_admin
				AND = {
					government_allows = merit
					situation:dynastic_cycle ?= { situation_current_phase = situation_dynastic_cycle_phase_chaos }
					exists = top_participant_group:dynastic_cycle
				}
			}
		}
		scope:recipient != scope:actor	
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_physically_able_adult = yes
			can_start_scheme = {
				target_character = scope:recipient
				type = claim_throne
			}
		}
	}

	# Scheme Starter Packages
	options_heading = schemes.t.agent_packages
	send_options_exclusive = yes
	## Balanced agents.
	send_option = {
		flag = agent_focus_balance
		current_description = claim_throne_interaction.tt.agent_focus_balance
	}
	## Focused on Success Chance.
	send_option = {
		flag = agent_focus_success
		current_description = claim_throne_interaction.tt.agent_focus_success
	}
	## Focused on Speed.
	send_option = {
		flag = agent_focus_speed
		current_description = claim_throne_interaction.tt.agent_focus_speed
	}
	## Focused on Secrecy.
	send_option = {
		flag = agent_focus_secrecy
		current_description = claim_throne_interaction.tt.agent_focus_secrecy
	}

	on_accept = {
		scope:actor = {
			stress_impact = {
				content = medium_stress_impact_gain
				just = medium_stress_impact_gain
			}
			send_interface_toast = {
				type = event_toast_effect_good
				title = claim_throne_interaction_toast
				left_icon = scope:actor
				right_icon = scope:recipient

				# Success.
				if = {
					limit = { scope:agent_focus_success ?= yes }
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = claim_throne
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Success.
						AGENT_1 = agent_diplomat
						AGENT_2 = agent_diplomat
						AGENT_3 = agent_scribe
						# Speed.
						AGENT_4 = agent_cleric
						# Secrecy.
						AGENT_5 = agent_justiciar
					}
				}
				# Speed.
				else_if = {
					limit = { scope:agent_focus_speed ?= yes }
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = claim_throne
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Speed.
						AGENT_1 = agent_cleric
						AGENT_2 = agent_socialite
						AGENT_3 = agent_gabbler
						# Success.
						AGENT_4 = agent_diplomat
						# Secrecy.
						AGENT_5 = agent_justiciar
					}
				}
				# Secrecy.
				else_if = {
					limit = { scope:agent_focus_secrecy ?= yes }
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = claim_throne
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Secrecy.
						AGENT_1 = agent_justiciar
						AGENT_2 = agent_justiciar
						AGENT_3 = agent_decoy
						# Success.
						AGENT_4 = agent_diplomat
						# Speed.
						AGENT_5 = agent_cleric
					}
				}
				# Balanced.
				else = {
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = claim_throne
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Success.
						AGENT_1 = agent_diplomat
						AGENT_2 = agent_scribe
						# Speed.
						AGENT_3 = agent_cleric
						AGENT_4 = agent_socialite
						# Secrecy.
						AGENT_5 = agent_decoy
					}
				}

				show_as_tooltip = {
					stress_impact = {
						content = medium_stress_impact_gain
						just = medium_stress_impact_gain
					}
				}
			}
		}

		# If we're a clan this interaction affects unity
		add_clan_unity_interaction_effect = {
			CHARACTER = scope:actor
			TARGET = scope:recipient
			VALUE = minor_unity_loss
			DESC = clan_unity_throne_claim.desc
			REVERSE_NON_HOUSE_TARGET = no
		}
	}
	
	ai_potential = {
		is_adult = yes
		ai_greed >= medium_positive_ai_value
		learning >= medium_skill_rating
		intrigue >= mediocre_skill_rating
		trigger_if = {
			limit = {
				liege = { save_temporary_scope_as = struggle_liege }
				any_character_struggle = {
					involvement = involved
					has_struggle_phase_parameter = unlocks_claim_throne_for_all
					is_secondary_character_involvement_involved_trigger = {
						CHAR = scope:struggle_liege
					}
				}
			}
			is_powerful_vassal = yes
		}
		NOR = {
			has_trait = content
			opinion = {
				target = liege
				value >= high_positive_opinion
			}
			any_scheme = {
				OR = {
					scheme_type = murder
					scheme_type = abduct
					scheme_type = claim_throne
					scheme_type = fabricate_hook
					scheme_type = steal_back_artifact
				}
			}
		}
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 48
		duchy = 36
		kingdom = 36
		empire = 0
		hegemony = 0
	}

	ai_will_do = {
		base = 100

		# Agenda impact
		modifier = {
			scope:actor = {
				any_character_struggle = {
					involvement = involved
					is_struggle_type = iberian_struggle
				}
			}
			add = {
				value = 0
				if = {
					limit = {
						scope:actor = {
							any_character_struggle = {
								phase_has_catalyst = catalyst_gain_claim_on_title_fp2
							}
							has_character_flag = agenda_towards_escalation
						}
					}
					add = 200
				}
				else_if = {
					limit = {
						scope:actor = {
							any_character_struggle = {
								phase_has_catalyst = catalyst_gain_claim_on_title_fp2
							}
						}
					}
					add = -100
				}
			}
		}

		modifier = {
			scope:actor = {
				any_character_struggle = {
					involvement = involved
					is_struggle_type = persian_struggle
				}
			}
			add = {
				value = 0
				if = {
					limit = {
						scope:actor = {
							any_character_struggle = {
								phase_has_catalyst = catalyst_gain_claim_on_title_fp3
							}
							has_trait = fp3_struggle_detractor
						}
					}
					add = 200
				}
				else_if = {
					limit = {
						scope:actor = {
							any_character_struggle = {
								phase_has_catalyst = catalyst_gain_claim_on_title_fp3
							}
							has_trait = fp3_struggle_supporter
						}
						scope:recipient = {
							has_trait = fp3_struggle_detractor
						}
					}
					add = 100
				}
				else_if = {
					limit = {
						scope:actor = {
							any_character_struggle = {
								phase_has_catalyst = catalyst_gain_claim_on_title_fp3
							}
						}
					}
					add = -100
				}
			}
		}

		# Unity modifiers
		evaluate_action_decreasing_house_unity = {
			VALUE = 100
		}

		start_hostile_scheme_ai_base_modifiers = yes # At the end so Cowed can block it completely
		
		ttd_minor_distance_ai_will_do_modifier = { CHARACTER_1 = scope:actor CHARACTER_2 = scope:recipient }
	}
}


###################
# Fabricate Hook
# by Petter Vilberg
###################
fabricate_hook_interaction = {
	icon = icon_scheme_fabricate_hook
	category = interaction_category_hostile

	auto_accept = yes
	ignores_pending_interaction_block = yes

	scheme = fabricate_hook

	desc = fabricate_hook_interaction_desc
	
	is_shown = {
		scope:actor = {
			OR = {
				has_perk = truth_is_relative_perk
				AND = {
					has_trait = vengeful
					has_relation_rival = scope:recipient
				}
				AND = {
					any_character_struggle = {
						involvement = involved
						has_struggle_phase_parameter = unlocks_fabricate_hooks_for_all
						is_secondary_character_involvement_either_trigger = {
							CHAR = scope:recipient
						}
					}
				}
				AND = {
					government_has_flag = government_is_clan
					is_in_same_clan_as_trigger = { CHARACTER = scope:recipient }
					house = { has_house_unity_stage = competitive }	
				}	
			}
		}
		scope:recipient != scope:actor
	}

	is_valid = {
		NOT = { scope:actor = { has_hook = scope:recipient } }
		OR = {
			scope:actor = {
				OR = {
					has_perk = truth_is_relative_perk # To display that it's available because of the Perk
					AND = {
						has_trait = vengeful
						has_relation_rival = scope:recipient
					}
					AND = {
						any_character_struggle = {
							involvement = involved
							has_struggle_phase_parameter = unlocks_fabricate_hooks_for_all
							is_secondary_character_involvement_either_trigger = {
								CHAR = scope:recipient
							}
						}
					}
					AND = {
						government_has_flag = government_is_clan
						is_in_same_clan_as_trigger = { CHARACTER = scope:recipient }
						house = { has_house_unity_stage = competitive }	
					}	
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_physically_able_adult = yes
			can_start_scheme = {
				target_character = scope:recipient
				type = fabricate_hook
			}
		}
	}

	# Scheme Starter Packages
	options_heading = schemes.t.agent_packages
	send_options_exclusive = yes
	## Balanced agents.
	send_option = {
		flag = agent_focus_balance
		current_description = fabricate_hook_interaction.tt.agent_focus_balance
	}
	## Focused on Success Chance.
	send_option = {
		flag = agent_focus_success
		current_description = fabricate_hook_interaction.tt.agent_focus_success
	}
	## Focused on Speed.
	send_option = {
		flag = agent_focus_speed
		current_description = fabricate_hook_interaction.tt.agent_focus_speed
	}
	## Focused on Secrecy.
	send_option = {
		flag = agent_focus_secrecy
		current_description = fabricate_hook_interaction.tt.agent_focus_secrecy
	}

	on_accept = {
		scope:actor = {
			stress_impact = {
				just = medium_stress_impact_gain
				honest = medium_stress_impact_gain
				compassionate = minor_stress_impact_gain
			}
			send_interface_toast = {
				type = event_toast_effect_good
				title = fabricate_hook_interaction_toast
				left_icon = scope:actor
				right_icon = scope:recipient

				# Success.
				if = {
					limit = { scope:agent_focus_success ?= yes }
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = fabricate_hook
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Success.
						AGENT_1 = agent_outcast
						AGENT_2 = agent_diplomat
						AGENT_3 = agent_thief
						# Speed.
						AGENT_4 = agent_infiltrator
						# Secrecy.
						AGENT_5 = agent_lookout
					}
				}
				# Speed.
				else_if = {
					limit = { scope:agent_focus_speed ?= yes }
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = fabricate_hook
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Speed.
						AGENT_1 = agent_infiltrator
						AGENT_2 = agent_footpad
						AGENT_3 = agent_socialite
						# Success.
						AGENT_4 = agent_outcast
						# Secrecy.
						AGENT_5 = agent_lookout
					}
				}
				# Secrecy.
				else_if = {
					limit = { scope:agent_focus_secrecy ?= yes }
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = fabricate_hook
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Secrecy.
						AGENT_1 = agent_lookout
						AGENT_2 = agent_decoy
						AGENT_3 = agent_justiciar
						# Success.
						AGENT_4 = agent_outcast
						# Speed.
						AGENT_5 = agent_footpad
					}
				}
				# Balanced.
				else = {
					begin_scheme_with_agents_effect = {
						SCHEME_TYPE = fabricate_hook
						TARGET_TYPE = target_character
						TARGET_SCOPE = scope:recipient
						# Success.
						AGENT_1 = agent_outcast
						AGENT_2 = agent_thief
						# Speed.
						AGENT_3 = agent_infiltrator
						AGENT_4 = agent_footpad
						# Secrecy.
						AGENT_5 = agent_lookout
					}
				}
			}
		}
	}

	ai_targets = {
		ai_recipients = liege
		ai_recipients = vassals
	}

	ai_targets = {
		ai_recipients = neighboring_rulers
		ai_recipients = peer_vassals
		max = 10
	}
	
	ai_targets = {
		ai_recipients = courtiers
		max = 5
	}
	
	ai_targets = {
		ai_recipients = realm_characters
		ai_recipients = top_realm_domicile_owners
		max = 30
	}
	
	ai_potential = {
		is_adult = yes
		ai_greed >= low_positive_ai_value
		intrigue >= medium_skill_rating
		NOR = {
			has_trait = content
			any_scheme = {
				OR = {
					scheme_type = murder
					scheme_type = abduct
					scheme_type = claim_throne
					scheme_type = fabricate_hook
					scheme_type = steal_back_artifact
				}
			}
		}
	}
	
	ai_target_quick_trigger = {
		adult = yes
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 60
		duchy = 12
		kingdom = 12
		empire = 12
		hegemony = 12
	}

	ai_will_do = {
		base = 10

		modifier = {
			add = {
				value = 20
				if = {
					limit = {
						exists = scope:recipient.cp:councillor_spymaster
						scope:recipient.cp:councillor_spymaster = { intrigue < 10 }
					}
					add = 50
				}
			}
			
			scope:recipient = {
				is_vassal_of = scope:actor
				vassal_contract_has_modifiable_obligations = yes
			}
		}
		
		modifier = {
			add = -50
			
			opinion = {
				target = scope:recipient
				value >= high_positive_opinion
			}
		}
		
		modifier = {
			add = -40
			
			scope:recipient = {
				is_playable_character = yes
				NOT = {
					is_vassal_of = scope:actor
				}
			}
		}
		
		modifier = {
			add = 50
			
			scope:recipient = {
				is_playable_character = no
				OR = {
					liege = scope:actor.liege
					liege = {
						OR = {
							has_relation_rival = scope:actor
							has_relation_nemesis = scope:actor
						}
					}
				}
			}
		}
		
		modifier = {
			factor = 0
			
			scope:recipient = {
				has_council_position = councillor_spymaster
			}
		}
		start_hostile_scheme_ai_base_modifiers = yes # At the end so Cowed can block it completely
		
		ttd_minor_distance_ai_will_do_modifier = { CHARACTER_1 = scope:actor CHARACTER_2 = scope:recipient }
	}
}