﻿ennoblement_interaction = {
	icon = court_poet_court_position
	category = interaction_category_friendly
 #	common_interaction = yes
	interface_priority = 200
	desc = ennoblement_interaction_desc

	ai_targets = {
		ai_recipients = scripted_relations
	}
	ai_target_quick_trigger = {
		adult = yes
	}
	ai_frequency = 65

 	cooldown = { years = 2 }

	is_shown = {
		has_game_rule = GPT_interactions_enabled
		NOT = { scope:recipient = scope:actor }

		scope:actor = {
			is_landed = yes
		 #	government_has_flag = government_is_feudal
		}

		scope:recipient = {
			is_lowborn = yes
			is_courtier_of = scope:actor
			NOT = { has_trait = devoted }
			NOT = { has_trait = order_member }
			NOT = { #Not your bishop
				scope:actor = {
					cp:councillor_court_chaplain = scope:recipient
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:actor.gold >= 50
		scope:actor.prestige >= 150
	 #	scope:actor.renown >= 25
	 	scope:actor = { NOT = { has_trait = shy } }
		scope:actor = { NOT = { has_trait = lazy } }
		scope:recipient = { basic_is_available_ai = yes }
	}

	cost = {
		prestige = 150
		gold = 50
	 #	renown = 25
	}

	auto_accept = yes

	on_accept = {

		random_list = {
			10 = {
				desc = gpt_ennoblement.success
				modifier = {
					add = {
						value = scope:actor.diplomacy
						multiply = 2
					}
				}
				modifier = {
					add = {
						value = scope:actor.learning
						multiply = 2
					}
				}
				modifier = {
					add = {
						value = scope:recipient.average_of_all_skills
						multiply = 2
					}
				}
				hidden_effect = {
					scope:recipient = {
						add_character_flag = becoming_nobility
						create_dynamic_title = {
							tier = duchy
							name = ennoblement_title_name
						}
						create_title_and_vassal_change = {
							type = created
							save_scope_as = change
							add_claim_on_loss = no
						}
						scope:new_title = {
							set_capital_county = scope:actor.capital_county
							set_landless_title = yes
							set_destroy_on_gain_same_tier = yes
							set_no_automatic_claims = yes
							set_can_be_named_after_dynasty = no
							change_title_holder = {
								holder = prev
								change = scope:change
							}
						}
						resolve_title_and_vassal_change = scope:change
						scope:new_title = {
							generate_coa = yes
						}
						destroy_title = scope:new_title

					}
					scope:actor = {
						add_courtier = scope:recipient
					}
				}
				scope:recipient = {
					custom_tooltip = ennoblement_tt

					add_opinion = {
						target = scope:actor
						opinion = 30
						modifier = ennoblement_opinion
					}
					create_character_memory = {
						type = ennoblement_memory
					}
				}
				scope:actor = {
					if = {
						limit = {
							scope:recipient.ai_honor >= 75
							can_add_hook = {
								target = scope:recipient
								type = loyalty_hook
							}
						}
						add_hook = {
							type = loyalty_hook
							target = scope:recipient
						}
					}
					if = {
						limit = {
							scope:recipient.ai_honor >= 0
							scope:recipient.ai_honor < 75
							can_add_hook = {
								target = scope:recipient
								type = favor_hook
							}
						}
						add_hook = {
							type = favor_hook
							target = scope:recipient
						}
					}
				}
			}
			50 = {
				desc = gpt_ennoblement.failure
				scope:actor = {
					hidden_effect = {
						add_legitimacy = -50
						scope:recipient = {
							add_opinion = {
								target = scope:actor
								modifier = disappointed_opinion
								opinion = -10
							}
						}
					}
					send_interface_toast = {
						type = event_toast_effect_bad
						title = gpt_ennoblement_failure_tt
						left_icon = scope:recipient
					 #	right_icon = scope:recipient

						show_as_tooltip = {
							scope:actor = {
								add_legitimacy = -50
							}
							scope:recipient = {
								add_opinion = {
									target = scope:actor
									modifier = disappointed_opinion
									opinion = -10
								}
							}
						}
					}
				}
			}
		}
	}

	ai_potential = {
		always = no
	 #	highest_held_title_tier >= 3
	 #	is_available_at_peace_ai_adult = yes
	 #	short_term_gold >= medium_gold_value
	 #	prestige > 250
	}

	ai_will_do = {
		base = 0

		modifier = {
			add = 10
			scope:recipient = {
				OR = {
					has_secret_relation_lover = scope:actor
					has_relation_lover = scope:actor
					has_relation_soulmate = scope:actor
					has_relation_friend = scope:actor
					has_relation_best_friend = scope:actor
				}
			}
		}
	}
}
