﻿trade_interaction_2 = {
	icon = icon_gold
	category = interaction_category_diplomacy
	ai_min_reply_days = 4
	ai_max_reply_days = 9
	use_diplomatic_range = yes
	interface_priority = 70
	use_diplomatic_range = yes

	desc = trade_agreement_desc_2

	is_shown = {
		has_game_rule = GPT_interactions_enabled
		always = no
			
		scope:recipient = {
			highest_held_title_tier >= 2
			NOT = { this = scope:actor }
			NOT = { is_allied_to = scope:actor }
			NOT = { has_character_modifier = trade_agrrement }
			NOT = { has_truce = scope:actor }
			is_adult = yes
			is_ruler = yes
			is_independent_ruler = yes
		}

		scope:actor = {
				highest_held_title_tier >= 2
				NOT = {is_at_war_with = scope:recipient}
				NOT = {has_character_modifier = trade_agrrement }
				is_adult = yes
				is_ruler = yes
		}
	}

	is_valid_showing_failures_only = {
		
		scope:recipient = {
			NOT = { has_relation_rival = scope:actor }
			NOT = { has_relation_nemesis = scope:actor }
			is_imprisoned = no
			is_at_war = no
			prestige_level >= 2
			highest_held_title_tier >= 4
		}

		scope:actor = {
			is_imprisoned = no
			is_at_war = no
			highest_held_title_tier >= 4
			prestige_level >= 2
		 #	stewardship >= 25
		 	gold >= 125
		}
	}

	on_auto_accept = {
		scope:recipient = {
			trigger_event = char_interaction.0234
		}
	}

	#Use hook
	send_option = {
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
		}
		flag = hook	
		localization = GENERIC_SPEND_A_HOOK
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	send_options_exclusive = no

	on_accept = {

		scope:actor = { add_truce_both_ways = { character = scope:recipient years = 5 override = yes name = TRUCE_ENFORCE_TRUCE } }
		
	 #	scope:actor = { trigger_event = char_interaction.0235 }

		scope:actor = {

			if = {
				limit = {
					is_ai = no
				}
				add_stress = 20
			}

			remove_short_term_gold = 100
			add_character_modifier = {
				modifier = trade_agrrement
				years = 5
			}
			hidden_effect = {
				send_interface_toast = {
					title = trade_agrrement_notification_2

					left_icon = scope:actor					
					right_icon = scope:recipient
					custom_tooltip = trade_agrrement_notification_tooltip_2
				}
			}
		}
		
		scope:recipient = {
			add_gold = 100
			add_character_modifier = {
				modifier = trade_agrrement
				years = 5
			}
		
		}
		
	}

	on_decline = {
	 #	scope:actor = {	trigger_event = char_interaction.0236 }
		scope:actor = {
			add_opinion = {
				modifier = refused_trade_opinion
				target = scope:recipient
			}
		}
	}

	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:actor
			object = scope:recipient
			scope:hook = yes
		}
	}

	ai_accept = {
		base = -50
		
		opinion_modifier = { # Opinion Factor
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.6
			desc = AI_OPINION_REASON
		}

		modifier = {
			add = { 
				value = scope:recipient.ai_greed
				multiply = 0.5
		 		min = -25
				max = 50
			}	
			desc = AI_GREEDY
		}

		modifier = {
			add = { 
				value = scope:recipient.ai_rationality
				multiply = 0.25
		 		min = -25
				max = 25
			}	
			desc = AI_RATIONAL
		}

		modifier = {
		 	desc = IS_NOT_NEIGHBOR
			NOT = { 
				scope:recipient = {
					any_sub_realm_county = {
						is_neighbor_to_realm = scope:actor	
					}
				}
			}
			add = -50
		}

		modifier = {
		 	desc = BOTH_ARE_INDEPENDENT 
			scope:recipient = {
				is_independent_ruler = yes
			}
			scope:actor = {
				is_independent_ruler = yes
			}
			add = -25
		}

		modifier = { #Faith compatibility
			scope:recipient.faith = {
				faith_hostility_level = {
					target = scope:actor.faith
					value > faith_fully_accepted_level
				}
			}
			add = {
				value = 0
				if = {
					limit = {
						scope:recipient.faith = {
							faith_hostility_level = {
								target = scope:actor.faith
								value >= faith_astray_level
							}
						}
					}
					subtract = 10
				}
				if = {
					limit = {
						scope:recipient.faith = {
							faith_hostility_level = {
								target = scope:actor.faith
								value >= faith_hostile_level
							}
						}
					}
					subtract = 10
				}
				if = {
					limit = {
						scope:recipient.faith = {
							faith_hostility_level = {
								target = scope:actor.faith
								value >= faith_evil_level
							}
						}
					}
					subtract = 10
				}
			}
			desc = MARRY_DIFFERENT_FAITH_REASON
		}

		modifier = { # Shared Court Language (non-spoken)
			add = 15
			desc = foreign_realm_court_language_non_spoken_interaction_reason
			trigger = {
				scope:actor = {
					has_royal_court = yes
					NOT = { knows_court_language_of = this }
				}
				NOT = {
					scope:actor.top_liege = scope:recipient.top_liege
				}
				OR = {
					AND = {
						scope:recipient = {
							has_royal_court = yes
						}
						scope:actor = { # You share Court Language
							has_same_court_language = scope:recipient
						}
					}
					
					scope:recipient = { # The recipient doesn't have a royal court, but their liege does
						is_independent_ruler = no
						has_royal_court = no
						liege = {
							has_royal_court = yes
							has_same_court_language = scope:actor
						}
					}
					scope:recipient = { # The recipient doesn't have a royal court, but their liege's liege does, while their liege doesn't have a royal court
						is_independent_ruler = no
						has_royal_court = no
						exists = liege.liege
						liege = {
							is_independent_ruler = no
							has_royal_court = no
						}
						liege.liege = {
							has_royal_court = yes
							has_same_court_language = scope:actor
						}
					}
					scope:recipient = { # The recipient doesn't have a royal court, but their liege's liege's liege does, while their liege doesn't have a royal court
						is_independent_ruler = no
						has_royal_court = no
						exists = liege.liege
						exists = liege.liege.liege
						liege = {
							is_independent_ruler = no
							has_royal_court = no
						}
						liege.liege = {
							is_independent_ruler = no
							has_royal_court = no
						}
						liege.liege.liege = {
							has_royal_court = yes
							has_same_court_language = scope:actor
						}
					}
					scope:recipient = { # The recipient doesn't have a royal court, but their liege's liege's liege's liege does, while their liege doesn't have a royal court
						is_independent_ruler = no
						has_royal_court = no
						exists = liege.liege
						exists = liege.liege.liege
						exists = liege.liege.liege.liege
						liege = {
							is_independent_ruler = no
							has_royal_court = no
						}
						liege.liege = {
							is_independent_ruler = no
							has_royal_court = no
						}
						liege.liege.liege = {
							is_independent_ruler = no
							has_royal_court = no
						}
						liege.liege.liege.liege = {
							has_royal_court = yes
							has_same_court_language = scope:actor
						}
					}
				}
			}
		}
		
		modifier = { # Shared Court Language (spoken)
			add = 30
			desc = foreign_realm_court_language_spoken_interaction_reason
			trigger = {
				scope:actor = {
					has_royal_court = yes
					knows_court_language_of = this
				}
				NOT = {
					scope:actor.top_liege = scope:recipient.top_liege
				}
				OR = {
					AND = {
						scope:recipient = {
							has_royal_court = yes
						}
						scope:actor = { # You share Court Language
							has_same_court_language = scope:recipient
						}
					}
					
					scope:recipient = { # The recipient doesn't have a royal court, but their liege does
						is_independent_ruler = no
						has_royal_court = no
						liege = {
							has_royal_court = yes
							has_same_court_language = scope:actor
						}
					}
					scope:recipient = { # The recipient doesn't have a royal court, but their liege's liege does, while their liege doesn't have a royal court
						is_independent_ruler = no
						has_royal_court = no
						exists = liege.liege
						liege = {
							is_independent_ruler = no
							has_royal_court = no
						}
						liege.liege = {
							has_royal_court = yes
							has_same_court_language = scope:actor
						}
					}
					scope:recipient = { # The recipient doesn't have a royal court, but their liege's liege's liege does, while their liege doesn't have a royal court
						is_independent_ruler = no
						has_royal_court = no
						exists = liege.liege
						exists = liege.liege.liege
						liege = {
							is_independent_ruler = no
							has_royal_court = no
						}
						liege.liege = {
							is_independent_ruler = no
							has_royal_court = no
						}
						liege.liege.liege = {
							has_royal_court = yes
							has_same_court_language = scope:actor
						}
					}
					scope:recipient = { # The recipient doesn't have a royal court, but their liege's liege's liege's liege does, while their liege doesn't have a royal court
						is_independent_ruler = no
						has_royal_court = no
						exists = liege.liege
						exists = liege.liege.liege
						exists = liege.liege.liege.liege
						liege = {
							is_independent_ruler = no
							has_royal_court = no
						}
						liege.liege = {
							is_independent_ruler = no
							has_royal_court = no
						}
						liege.liege.liege = {
							is_independent_ruler = no
							has_royal_court = no
						}
						liege.liege.liege.liege = {
							has_royal_court = yes
							has_same_court_language = scope:actor
						}
					}
				}
			}
		}
	}

	ai_potential = {
		always = no
	}

	ai_targets = {
 		ai_recipients = neighboring_rulers
 	}

	cooldown = { years = 5 }

	ai_frequency = 0

	ai_will_do = { 
		base = 0
	 #	modifier = {
	 #		add = {
	 #			value = 0
	 # 			add = scope:actor.ai_rationality
	 #			add = scope:actor.ai_compassion
	 #		}
	 #	}
	}
}