﻿unlanded_purchase_land_interaction = {
	category = interaction_category_diplomacy
	icon = powerful_family_shield
	common_interaction = yes
	desc = unlanded_purchase_land_interaction.desc
	interface_priority = 80
	target_type = title
	target_filter = recipient_domain_titles
	auto_accept = no
	ai_accept = {
		base = -50 # Try to make it 0 for most interactions

		modifier = {
			scope:hook = yes
			add = 100
			desc = SCHEME_WEAK_HOOK_USED
		}
		
		modifier = {
			exists = dynasty
			dynasty.dynasty_prestige_level >= 2
			add = {
				value = dynasty.dynasty_prestige_level
				add = 5
				subtract = 5
			}
		}
		opinion_modifier = { # Opinion Factor
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 1
			desc = AI_SIMPLE_OPINION_REASON
		}
		modifier = {
			add = {
				value = scope:actor.prestige_level
				multiply = 20
			}
			scope:actor.prestige_level >= 4
			desc = PURCHASE_LAND_PRESTIGE_LEVEL_REASON
		}
		modifier = {
			add = 40
			trigger = {
				scope:actor.culture != scope:recipient.culture
				OR = {
					AND = {
						scope:target.tier = tier_county
						scope:target.culture = scope:recipient.culture
					}		
					scope:target = {
						any_de_jure_county = {
							ep3_purchase_land_valid_county_trigger = yes
							culture = scope:recipient.culture
						}
					}
				}
			}
			scope:actor.primary_spouse ?= {
				culture = scope:recipient.culture
				dynasty ?= {
					dynasty_prestige_level >= 2
				}
			}
			desc = PURCHASE_LAND_MARRIED_TO_CULTURE_NOBLE_REASON
		}
		modifier = {
			add = 40
			trigger = {
				scope:actor.faith != scope:recipient.faith
			}
			scope:actor.primary_spouse ?= {
				faith = scope:recipient.faith
				dynasty ?= {
					dynasty_prestige_level >= 2
				}
			}
			desc = PURCHASE_LAND_MARRIED_TO_FAITH_NOBLE_REASON
		}
		modifier = {
			add = 80
			scope:actor.primary_spouse ?= {
				house ?= scope:recipient.house
			}
			desc = PURCHASE_LAND_MARRIED_TO_HOUSE_REASON
		}
	
	
	}
	ai_frequency = 0
	
	
	is_shown = {
		scope:actor = {
			is_ai = no
			highest_held_title_tier < tier_county
		}
		scope:recipient = {
			is_landed = yes
			NOT = { government_has_flag = government_is_administrative }
		}
		NOT = { scope:actor = scope:recipient }
	}
	
	can_be_picked_title = {
		scope:target = {
			is_leased_out = no
			tier <= tier_county
		}
	}
	
	cost = {
		gold = {
			if = {
				limit = { scope:target.tier = tier_county }
				add = 1000
			}
            if = {
				limit = { scope:target.tier = tier_barony }
				add = 550
			}				
		}
	}
	
	can_send = {
		scope:actor = {
			is_ai = no
	    } 		
	}
	
	send_option = {
		flag = hook
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
		}
		localization = GENERIC_SPEND_A_HOOK
	}
	send_options_exclusive = no
	
	is_valid_showing_failures_only = {
	 	   
	   scope:actor = {
		custom_tooltip = { text = unlanded_purchase_land_interaction.tt2
			NOT = { dynasty = { has_dynasty_modifier = lowborn_modifier } }
			has_occupation_blocker_trigger = no
			
		  }
		  NOT = { has_trait = gallowsbait }
		 }
		 scope:recipient = {
			custom_tooltip = { text = unlanded_purchase_land_interaction.tt1

			 NAND = { highest_held_title_tier = tier_county primary_title = scope:target }
		    }
			custom_tooltip = { text = unlanded_purchase_land_interaction.tt3
			NOT = { scope:target = scope:recipient.capital_county } }
		}
		scope:actor = { 
		 custom_tooltip = { text = unlanded_purchase_land_interaction.tt4
		 is_courtier_of = scope:recipient
		 }
		} 
	 
	}
	
	
	on_accept = {
		
		scope:target = {
			add_to_list = purchased_titles
		}
		
		scope:actor = { save_scope_as = me }
        random_living_character = {
        save_scope_as = random
         }

        scope:actor = { hidden_effect = { set_player_character = scope:random } }

		
      scope:me = {
       get_title = scope:target
      }
		
		scope:me = { hidden_effect = { use_hook = scope:recipient } }
	   
        scope:random = {
		 hidden_effect = {
         set_player_character = scope:me
		 }
        }

		save_scope_value_as = {
			name = purchase_land_cost
			value = {
				every_in_list = {
					list = purchased_titles
					if = {
						limit = { tier = tier_county }
						add = 1000
					}
					else_if = {
						limit = { tier = tier_barony }
						add = 550
					}
				}
			}
		}
		scope:recipient = { add_gold = scope:purchase_land_cost }
	}
}

