﻿purchase_property_interaction = {
	category = interaction_category_diplomacy
	icon = powerful_family_shield

	desc = purchase_property_interaction.desc

	cooldown_against_recipient = { years = 1 }


	popup_on_receive = yes
	pause_on_receive = yes

	interface_priority = 60
	ai_min_reply_days = 4
	ai_max_reply_days = 9

	is_shown = {
		scope:recipient = {
			is_landed = yes
		}
		scope:actor = {
		   is_ruler = no
		}
		NOT = { scope:recipient = scope:actor }
	}

	is_valid_showing_failures_only = {
		scope:actor = {
		    custom_tooltip = { text = purchase_property_interaction.tt1
			OR = {
			 NOT = { dynasty = { has_dynasty_modifier = lowborn_modifier } }
			 NOT = { has_character_modifier = shop_modifier }
			}
		}}
		scope:recipient = {
		    custom_tooltip = { text = purchase_property_interaction.tt2
			is_busy_in_events_localised = yes
			is_employer_of = scope:actor
		}}
		scope:actor = { has_occupation_blocker_trigger = no }
	}

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

	send_option = {
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
		}
		flag = hook
		localization = SCHEME_HOOK
	}

	send_options_exclusive = no

	cost = {
		gold = {
			add = {
				value = 50
				desc = BASE
			}
			if = {
				limit = { scope:gold_option = yes }
				add = {
					value = 50
					desc = laamp_to_ladmin_gold_option_desc
				}
			}
		}
		prestige = {
			
				# Base cost
				add = {
					value = 30
					desc = BASE
				}
				# Gender modifiers
				if = {
					limit = {
						scope:recipient ?= {
							top_liege = { has_realm_law = male_preference_law }
						}
						scope:actor = {
							is_female = yes
						}
					}
					add = { # Increase the base cost
						value = {
							value = 600
							multiply = 0.25
						}
						desc = male_preference_law
					}
				}
				if = {
					limit = {
						scope:recipient ?= {
							top_liege = { has_realm_law = female_preference_law }
						}
						scope:actor = {
							is_male = yes
						}
					}
					add = { # Increase the base cost
						value = {
							value = 600
							multiply = 0.25
						}
						desc = female_preference_law
					}
				}
				#Brigands need to pay more to be legitimized
			
		}
	}

	is_highlighted = {
		always = yes
	}

	on_accept = {
		scope:actor = {
			purchase_property_interaction_effect = yes
			hidden_effect = { use_hook = scope:recipient }
		}
	}

	on_decline = {
		scope:actor = {
		}
	}
	send_option = {
		flag = gold_option
		is_valid = {
			scope:actor.gold >= 150
		}
		localization = laamp_to_ladmin_gold_option_desc
	}

	ai_frequency = 0

	ai_accept = {
		base = 0 # Try to make it 0 for most interactions

		opinion_modifier = { # Opinion Factor
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.1
			desc = AI_OPINION_REASON
		}
		modifier = {
			add = -10
			desc = purchase_property_interaction.lowbornopinion
			scope:actor = {
				dynasty = { has_dynasty_modifier = lowborn_modifier }
			}
		}
		modifier = {
			add = -10
			desc = PROCURE_ESTATE_GALLOWSBAIT_REASON
			scope:actor = {
				has_trait = gallowsbait
			}
		}
		#DIFFERENT FAITH FROM STATE FAITH (if recipient is state faith)
		modifier = {
			add = -5
			desc = PROCURE_ESTATE_STATE_FAITH_REASON
			scope:actor.faith = {
				NOT = {
					this = scope:recipient.top_liege.primary_title.state_faith
				}
			}
			scope:recipient.faith = {
				this = scope:recipient.top_liege.primary_title.state_faith
			}
			
		}
		#Hey you're actually a local in my capital
		modifier = {
			add = 10
			desc = PROCURE_ESTATE_SAME_CULTURE_AS_CAPITAL_REASON
			scope:recipient.capital_county.culture = {
				this = scope:actor.culture
			}
		}
		#Your dynasty is worthless
		modifier = {
			add = -10
			scope:actor.dynasty = {
				dynasty_prestige_level < 1
			}
			desc = PROCURE_ESTATE_DYNASTY_PRESTIGE_LEVEL_REASON
		}
		#Your dynasty is pretty great actually
		modifier = {
			add = 10
			scope:actor.dynasty = {
				dynasty_prestige_level >= 4
				dynasty_prestige_level < 7
			}
			desc = PROCURE_ESTATE_DYNASTY_PRESTIGE_LEVEL_REASON
		}
		#Your dynasty is pretty great actually
		modifier = {
			add = 20
			scope:actor.dynasty = {
				dynasty_prestige_level >= 7
				dynasty_prestige_level < 10
			}
			desc = PROCURE_ESTATE_DYNASTY_PRESTIGE_LEVEL_REASON
		}
		#Your dynasty is pretty great actually
		modifier = {
			add = 30
			scope:actor.dynasty = { dynasty_prestige_level >= 10 }
			desc = PROCURE_ESTATE_DYNASTY_PRESTIGE_LEVEL_REASON
		}
		#You have a criminal background
		modifier = {
			add = -5
			desc = PROCURE_ESTATE_GALLOWSBAIT_REASON
			scope:actor = {
				has_trait = gallowsbait
				NOR = {
					has_trait_xp = {
						trait = gallowsbait
						track = bandit
						value < 40
					}
					has_trait_xp = {
						trait = gallowsbait
						track = trickster
						value < 40
					}
					has_trait_xp = {
						trait = gallowsbait
						track = thief
						value < 40
					}
					has_trait_xp = {
						trait = gallowsbait
						track = poacher
						value < 40
					}
					has_trait_xp = {
						trait = gallowsbait
						track = marauder
						value < 40
					}
				}
			}
		}
		modifier = {
			add = -20
			desc = PROCURE_ESTATE_GALLOWSBAIT_REASON
			scope:actor = {
				has_trait = gallowsbait
				OR = {
					has_trait_xp = {
						trait = gallowsbait
						track = bandit
						value >= 40
					}
					has_trait_xp = {
						trait = gallowsbait
						track = trickster
						value >= 40
					}
					has_trait_xp = {
						trait = gallowsbait
						track = thief
						value >= 40
					}
					has_trait_xp = {
						trait = gallowsbait
						track = poacher
						value >= 40
					}
					has_trait_xp = {
						trait = gallowsbait
						track = marauder
						value >= 40
					}
				}
				NOR = {
					has_trait_xp = {
						trait = gallowsbait
						track = bandit
						value < 80
					}
					has_trait_xp = {
						trait = gallowsbait
						track = trickster
						value < 80
					}
					has_trait_xp = {
						trait = gallowsbait
						track = thief
						value < 80
					}
					has_trait_xp = {
						trait = gallowsbait
						track = poacher
						value < 80
					}
					has_trait_xp = {
						trait = gallowsbait
						track = marauder
						value < 80
					}
				}
			}
		}
		modifier = {
			add = -50
			desc = PROCURE_ESTATE_GALLOWSBAIT_REASON
			scope:actor = {
				has_trait = gallowsbait
				OR = {
					has_trait_xp = {
						trait = gallowsbait
						track = bandit
						value >= 80
					}
					has_trait_xp = {
						trait = gallowsbait
						track = trickster
						value >= 80
					}
					has_trait_xp = {
						trait = gallowsbait
						track = thief
						value >= 80
					}
					has_trait_xp = {
						trait = gallowsbait
						track = poacher
						value >= 80
					}
					has_trait_xp = {
						trait = gallowsbait
						track = marauder
						value >= 80
					}
				}
			}
		}
		#You have an interesting claim within my realm
		#Needs gold
		modifier = {
			add = 10
			
				scope:gold_option = yes
			
			desc = PROCURE_ESTATE_NEEDS_GOLD_REASON
		}
	}
}