﻿
start_disbelieve_mandala_interaction = {
	icon = icon_scheme_disbelieve_mandala
	category = interaction_category_hostile
	common_interaction = yes

	send_name = START_SCHEME

	interface_priority = 75

	scheme = disbelieve_mandala
	ignores_pending_interaction_block = yes

	ai_targets = {
		ai_recipients = liege
		ai_recipients = suzerain
		ai_recipients = neighboring_rulers
		max = 10
	}
	ai_targets = {
		ai_recipients = vassals
		ai_recipients = peer_vassals
		max = 10
	}
	ai_targets = {
		ai_recipients = tributaries
		max = 5
	}
	ai_frequency_by_tier = {
		barony = 0
		county = 60
		duchy = 12
		kingdom = 12
		empire = 12
		hegemony = 12
	}

	is_shown = {
		scope:actor = {
			this != scope:recipient
			government_has_flag = government_is_mandala	
		}
		scope:recipient = { 
			government_has_flag = government_is_mandala
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			can_start_scheme = {
				type = disbelieve_mandala
				target_character = scope:recipient
			}
			is_house_head = yes
		}
		scope:recipient = {
			NOT = { has_strong_hook = scope:actor }
		}
	}

	desc = scheme_interaction_tt_disbelieve_mandala

	on_accept = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = disbelieve_mandala_interaction_notification
				left_icon = scope:actor					
				right_icon = scope:recipient
				begin_scheme_basic_effect = {
					SCHEME_TYPE = disbelieve_mandala
					TARGET_TYPE = target_character
					TARGET_SCOPE = scope:recipient
				}
			}
		}
	}
	
	ai_potential = {
		house ?= { has_house_head_parameter = unlock_disbelieve_mandala_scheme }
		is_house_head = yes
		primary_title.tier >= tier_county
		NOT = {
			any_scheme = { is_scheme_category = hostile }
		}
	}
	
	auto_accept = yes
	
	ai_will_do = {
		base = 10
		
		# Relationships
			modifier = {
				add = 25
				has_any_mild_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
			}
			modifier = {
				add = 50
				has_any_moderate_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
			}
			modifier = {
				add = 100
				has_any_worst_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
			}
			modifier = {
				add = -25
				has_any_mild_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
			}
			modifier = {
				add = -50
				has_any_moderate_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
			}
			modifier = {
				factor = 0
				has_any_best_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
			}

		#They're the same tier or above us
		modifier = {
			add = 20
			scope:actor.primary_title.tier <= scope:recipient.primary_title.tier
		}

		#They're more radiant than us
		modifier = {
			add = 50
			scope:actor.mandala_radiance_value <= scope:recipient.mandala_radiance_value
		}

		#They're larger than us
		modifier = {
			add = 25
			scope:actor.realm_size <= scope:recipient.realm_size
		}

		#Beat down any rebellious vassals
			modifier = {
				add = 10
				scope:recipient = {
					number_of_tributaries > 0
					joined_faction ?= {
						faction_target = scope:actor
						faction_is_type = liberty_faction
						faction_is_at_war = no
					}
				}
			}
			modifier = {
				add = 20
				scope:recipient = {
					number_of_tributaries > 0
					joined_faction ?= {
						faction_target = scope:actor
						faction_is_type = claimant_faction
						faction_is_at_war = no
					}
				}
			}
			modifier = {
				add = 30
				scope:recipient = {
					number_of_tributaries > 0
					joined_faction ?= {
						faction_target = scope:actor
						faction_is_type = independence_faction
						faction_is_at_war = no
					}
				}
			}
			modifier = {
				factor = 2
				scope:recipient = {
					number_of_tributaries > 0
					is_a_faction_leader = yes 
					is_vassal_of = scope:actor
				}
			}

		#We dislike them
		opinion_modifier = { # Less likely to accept if Recipient dislikes the Actor
			who = scope:actor
			opinion_target = scope:recipient
			multiplier = 1
			max = 0
			desc = AI_OPINION_REASON
		}
		
		ttd_medium_distance_ai_will_do_modifier = { CHARACTER_1 = scope:actor CHARACTER_2 = scope:recipient }

	}
}

start_coerce_tributary_interaction = {
	icon = icon_scheme_coerce_tributary
	category = interaction_category_vassal
	common_interaction = yes

	send_name = START_SCHEME

	interface_priority = 75

	scheme = coerce_tributary
	ignores_pending_interaction_block = yes

	ai_targets = {
		ai_recipients = liege
		ai_recipients = suzerain
		ai_recipients = neighboring_rulers
		max = 10
	}
	ai_targets = {
		ai_recipients = vassals
		ai_recipients = peer_vassals
		max = 10
	}
	ai_targets = {
		ai_recipients = tributaries
		max = 5
	}
	ai_frequency_by_tier = {
		barony = 0
		county = 60
		duchy = 12
		kingdom = 12
		empire = 12
		hegemony = 12
	}

	is_shown = {
		scope:actor = {
			this != scope:recipient
			government_has_flag = government_is_mandala
		}
		scope:recipient = { 
			is_independent_ruler = yes
			is_landed = yes
			is_ai = yes
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			can_start_scheme = {
				type = coerce_tributary
				target_character = scope:recipient
			}
			custom_tooltip = {
				text = recipient_is_your_suzerain.tt
				NOT = { overlord = scope:recipient }
			}
			trigger_if = {
				limit = {
					house ?= { has_house_head_parameter = unlock_coerce_against_higher_tier }
					is_house_head = yes
				}
				always = yes
			}
			trigger_else = {
				primary_title = { tier >= scope:recipient.primary_title.tier }
			}	
		}
		trigger_if = {
			limit = {
				scope:recipient = { is_tributary = yes }
			}
			scope:recipient.suzerain = {
				NOT = { has_strong_hook = scope:actor }
			}
			scope:actor = {
				custom_tooltip = {
					text = you_share_suzerain.tt
					NOT = { is_tributary_of = scope:recipient.suzerain }
				}
			}
		}
		custom_tooltip = {
			text = was_betrayed_after_being_coerced.tt
			scope:recipient = {
				NOT = { var:was_betrayed_after_being_coerced ?= scope:actor }
			}
		}
	}

	desc = scheme_interaction_tt_coerce_tributary

	on_accept = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = coerce_tributary_interaction_notification
				left_icon = scope:actor					
				right_icon = scope:recipient
				begin_scheme_basic_effect = {
					SCHEME_TYPE = coerce_tributary
					TARGET_TYPE = target_character
					TARGET_SCOPE = scope:recipient
				}
			}
		}
	}
	
	ai_potential = {
		government_has_flag = government_is_mandala
		primary_title.tier >= tier_county
		NOT = {
			any_scheme = { is_scheme_category = personal }
		}
	}
	
	auto_accept = yes
	
	ai_will_do = {
		base = 10
		
		# Relationships
			modifier = {
				add = 25
				has_any_mild_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
			}
			modifier = {
				add = 50
				has_any_moderate_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
			}
			modifier = {
				add = 100
				has_any_worst_bad_relationship_with_character_trigger = { CHARACTER = scope:recipient }
			}
			modifier = {
				add = -25
				has_any_mild_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
			}
			modifier = {
				add = -50
				has_any_moderate_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
			}
			modifier = {
				factor = 0
				has_any_best_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
			}

		#They're the same tier or below us
		modifier = {
			add = 20
			scope:actor.primary_title.tier >= scope:recipient.primary_title.tier
		}

		#They're smaller than us
		modifier = {
			add = 30
			scope:actor.realm_size >= scope:recipient.realm_size
		}

		#They're higher tier than us
		modifier = {
			add = -25
			scope:actor.primary_title.tier < scope:recipient.primary_title.tier
		}

		#They're larger than us
		modifier = {
			add = -25
			scope:actor.realm_size <= scope:recipient.realm_size
		}

		#We like their suzerain
		modifier = {
			add = -10
			exists = scope:recipient.suzerain
			opinion = {
				target = scope:recipient.suzerain
				value > 0
			}
		}
		#We dislike the Suzerain
		opinion_modifier = {
			trigger = { exists = scope:recipient.suzerain }
			who = scope:actor
			opinion_target = scope:recipient.suzerain
			multiplier = 1
			max = 0
		}

		ttd_medium_distance_ai_will_do_modifier = { CHARACTER_1 = scope:actor CHARACTER_2 = scope:recipient }
	}
}

start_leverage_contribution_interaction = {
	icon = icon_scheme_leverage_contribution
	category = interaction_category_vassal
	common_interaction = yes
	
	send_name = START_SCHEME 

	interface_priority = 50

	scheme = leverage_contribution
	ignores_pending_interaction_block = yes 

	ai_targets = { 
		ai_recipients = vassals
		ai_recipients = tributaries
	}
	ai_frequency_by_tier = {
		barony = 0
		county = 60
		duchy = 60
		kingdom = 30
		empire = 12
		hegemony = 6
	}

	desc = scheme_interaction_tt_leverage_contribution

	is_shown = {
		scope:actor = {
			this != scope:recipient
			government_has_flag = government_is_mandala
		}
		scope:recipient = { 
			is_landed = yes
			is_ai = yes
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_house_head = yes
			can_start_scheme = {
				type = leverage_contribution
				target_character = scope:recipient
			}
			#Does the recipient have an OK amount of gold?
			trigger_if = {
				limit = {
					house = { has_house_head_parameter = unlock_leverage_contribution_scheme }
					is_house_head = yes
				}
				trigger_if = {
					limit = {
						any_great_project = {
							great_project_owner = scope:actor
							OR = {
								great_project_type = mandala_capital_05
								great_project_type = mandala_capital_04
								great_project_type = mandala_capital_03
								great_project_type = mandala_capital_02
								great_project_type = mandala_capital_01
							}
							great_project_construction_phase_is = planned
							any_contribution = { contribution_is_funded = no }
						}			
					}
					trigger_if = {
						limit = {
							any_great_project = { 
								great_project_owner = scope:actor
								great_project_type = mandala_capital_05
							}
						}
						custom_tooltip = {
							text = recipient_is_unable_to_afford_contributions.tt
							scope:recipient = { gold >= mandala_contribution_high_gold_cost }
						}
					}
					trigger_else_if = {
						limit = {
							any_great_project = {
								great_project_owner = scope:actor
								OR = {
									great_project_type = mandala_capital_04
									great_project_type = mandala_capital_03
								}
							}
						}
						custom_tooltip = {
							text = recipient_is_unable_to_afford_contributions.tt
							scope:recipient = { gold >= mandala_contribution_mid_gold_cost }
						}

					}
					trigger_else = {
						custom_tooltip = {
							text = recipient_is_unable_to_afford_contributions.tt
							scope:recipient = { gold >= mandala_contribution_low_gold_cost }
						}
					}
				}
			}		
		}
		scope:recipient = {
			in_diplomatic_range = scope:actor
			NOT = { has_character_modifier = insusceptible_to_leverage_contribution_modifier }
		}
	}

	# Scheme Starter Packages
	options_heading = schemes.t.agent_packages
	send_options_exclusive = yes
	## Focused on Success Chance.
	send_option = {
		flag = agent_focus_success
		current_description = start_coerce_contribution_interaction.tt.agent_focus_success
	}
	## Focused on Speed.
	send_option = {
		flag = agent_focus_speed
		current_description = start_coerce_contribution_interaction.tt.agent_focus_speed
	}

	on_accept = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title = leverage_contribution_interaction_notification
				left_icon = scope:recipient					
				right_icon = scope:target
				scope:actor = {
					# Success.
					if = {
						limit = { scope:agent_focus_success ?= yes }
						begin_scheme_with_agents_effect = {
							SCHEME_TYPE = leverage_contribution
							TARGET_TYPE = target_character
							TARGET_SCOPE = scope:recipient
							# Success.
							AGENT_1 = agent_thug
							AGENT_2 = agent_devotee
							AGENT_3 = agent_devotee
							# Speed.
							AGENT_4 = agent_cleric
							AGENT_5 = agent_herald
						}
					}
					# Speed.
					else = {
						begin_scheme_with_agents_effect = {
							SCHEME_TYPE = leverage_contribution
							TARGET_TYPE = target_character
							TARGET_SCOPE = scope:recipient
							# Success.
							AGENT_1 = agent_thug
							AGENT_2 = agent_devotee
							# Speed.
							AGENT_3 = agent_cleric
							AGENT_4 = agent_cleric
							AGENT_5 = agent_herald
						}
					}
				}
			}
		}
	}

	ai_potential = {
		government_has_flag = government_is_mandala
		has_unfunded_contribution_in_planned_mandala_capital_trigger = yes
		piety > mandala_scheme_minor_piety_cost_value
		NOT = {
			any_scheme = { is_scheme_category = political }
		}
	}
	
	auto_accept = yes

	ai_will_do = {
		base = 25

		#Personality
		modifier = {
			has_trait = ambitious
			add = 15
		}
		modifier = {
			has_trait = content
			add = -15
		}

		modifier = { add = stewardship }

		#More common at the beginning of your journey
		modifier = {
			primary_title.tier >= tier_kingdom
			add = -15
		}
		modifier = {
			primary_title.tier >= tier_empire
			add = -15
		}
		modifier = {
			has_mandala_capital_trigger = yes
			add = {
				value = mandala_radiance_value
				multiply = -1
			}
		}
		
		ttd_minor_distance_ai_will_do_modifier = { CHARACTER_1 = scope:actor CHARACTER_2 = scope:recipient }
	}
}