﻿# Rota Fortunae — character interactions.

# Join (or found) the coalition against a menacing ruler.
rf_join_coalition_interaction = {
	category = interaction_category_diplomacy
	icon = request_alliance
	interface_priority = 55
	desc = rf_join_coalition_interaction_desc
	auto_accept = yes

	is_shown = {
		rf_coalitions_enabled_trigger = yes
		scope:actor = {
			is_ai = no
			rf_is_realm_trigger = yes
		}
		scope:recipient = {
			this != scope:actor
			rf_is_realm_trigger = yes
			rf_menace_value >= 50
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			custom_description = {
				text = rf_already_in_coalition_tt
				NOT = { exists = primary_title.var:rf_coalition_against }
			}
			custom_description = {
				text = rf_allied_to_target_tt
				NOT = { is_allied_to = scope:recipient }
			}
			NOT = { is_tributary_of = scope:recipient }
			custom_description = {
				text = rf_out_of_reach_tt
				rf_in_coalition_range_trigger = { THREAT = scope:recipient }
			}
			custom_description = {
				text = rf_friend_of_target_tt
				NOR = {
					has_relation_friend = scope:recipient
					has_relation_best_friend = scope:recipient
					has_relation_lover = scope:recipient
					has_relation_soulmate = scope:recipient
					opinion = { target = scope:recipient value >= 60 }
				}
			}
		}
		scope:recipient = {
			custom_description = {
				text = rf_coalition_cooldown_tt
				NOT = { exists = primary_title.var:rf_coalition_cooldown }
			}
			NOT = { is_tributary_of = scope:actor }
		}
	}

	on_accept = {
		custom_tooltip = rf_join_coalition_interaction_effect_tt
		hidden_effect = {
			scope:actor = {
				rf_join_coalition_effect = { THREAT = scope:recipient }
			}
		}
	}

	ai_will_do = { base = 0 }
}

# The coalition's target buys a member's withdrawal.
rf_buy_defection_interaction = {
	category = interaction_category_diplomacy
	icon = icon_gold
	interface_priority = 54
	desc = rf_buy_defection_interaction_desc
	ai_min_reply_days = 3
	ai_max_reply_days = 7
	greeting = positive

	is_shown = {
		scope:recipient = {
			rf_in_coalition_against_trigger = { THREAT = scope:actor }
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			gold >= scope:recipient.rf_defection_gold_value
			NOT = { is_at_war_with = scope:recipient }
		}
	}

	on_accept = {
		scope:actor = {
			pay_short_term_gold = {
				target = scope:recipient
				gold = scope:recipient.rf_defection_gold_value
			}
		}
		scope:recipient = {
			save_scope_as = rf_turncoat
			add_opinion = { target = scope:actor modifier = rf_bought_neutrality_opinion }
			rf_leave_coalition_effect = yes
		}
		scope:actor.primary_title = {
			every_in_list = {
				variable = rf_coalition
				limit = { exists = holder }
				holder = {
					add_opinion = { target = scope:rf_turncoat modifier = rf_betrayed_coalition_opinion }
				}
			}
		}
	}

	ai_accept = {
		base = -10
		modifier = {
			add = 30
			desc = rf_ai_greedy_tt
			scope:recipient = { has_trait = greedy }
		}
		modifier = {
			add = 20
			desc = rf_ai_poor_tt
			scope:recipient = { gold < 50 }
		}
		modifier = {
			add = -30
			desc = rf_ai_vengeful_tt
			scope:recipient = { has_trait = vengeful }
		}
		modifier = {
			add = -25
			desc = rf_ai_lost_land_tt
			scope:recipient = {
				exists = var:rf_lost_land_to
				var:rf_lost_land_to = scope:actor.primary_title
			}
		}
		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.5
		}
	}

	ai_will_do = {
		base = 0
		modifier = {
			add = 40
			scope:actor = { rf_coalition_ratio_value >= 70 }
		}
	}
	ai_frequency = 24
	ai_potential = {
		rf_has_coalition_against_trigger = yes
		gold >= 100
	}
	ai_targets = {
		ai_recipients = neighboring_rulers
	}
}
