# Ask to Promote your Legend
ce1_ask_to_promote_legend_interaction = {
	icon = icon_contract_modification_single
	category = interaction_category_diplomacy
	popup_on_receive = yes
	pause_on_receive = yes
	can_send_despite_rejection = yes
	ai_maybe = yes
	interface_priority = 5
	desc = ce1_ask_to_promote_legend_interaction_desc

	greeting = positive
	notification_text = PROMOTE_LEGEND_NOTIFICATION
	
	is_shown = {
		scope:actor.promoted_legend.legend_owner ?= scope:actor
		scope:actor != scope:recipient
		scope:recipient = {
			is_landed = yes
			age >= 12
			is_physically_able = yes
			NOT = { government_has_flag = government_is_true_herder }
		}
	}

	is_valid_showing_failures_only = {
		scope:recipient = {
			custom_tooltip = {
				text = recipient_already_promoting_legend_tt
				NOT = { exists = promoted_legend }
			}
		}
		custom_tooltip = {
			text = recipient_close_or_neighbor_tt
			OR = {
				scope:recipient.dynasty = scope:actor.dynasty
				scope:recipient = { knows_language_of_culture = scope:actor.culture }
				scope:actor = {
					has_any_moderate_good_relationship_with_character_trigger = { CHARACTER = scope:recipient }
				}
				scope:recipient = {
					any_character_to_title_neighboring_county = {
						any_county_province = {
							any_province_legend = {
								this = scope:actor.promoted_legend
							}
						}
					}
				}
			}
		}
	}

	cooldown_against_recipient = { years = 5 }

	ai_min_reply_days = 2
	ai_max_reply_days = 7
	
	ai_accept = {
		base = -10
		## Tier
		modifier = {
			add = -5
			scope:recipient.primary_title = {
				tier = 2
			}
			desc = TIER_REASON_COUNT
		}
		modifier = {
			add = -10
			scope:recipient.primary_title = {
				tier = 3
			}
			desc = TIER_REASON_DUKE
		}
		modifier = {
			add = -20
			scope:recipient.primary_title = {
				tier = 4
			}
			desc = TIER_REASON_KING
		}
		modifier = {
			add = -30
			scope:recipient.primary_title = {
				tier = 5
			}
			desc = TIER_REASON_EMPEROR
		}
		##	Legend
		# How cool is the legend?
		modifier = {
			add = 10
			desc = REASON_ILLUSTRIOUS_LEGEND
			scope:actor = {
				promoted_legend = {
					legend_quality = illustrious
				}
			}
		}
		modifier = {
			add = 20
			desc = REASON_MYTHICAL_LEGEND
			scope:actor = {
				promoted_legend = {
					legend_quality = mythical
				}
			}
		}
		# Are you using a hook?
		modifier = {
			trigger = {
				scope:hook ?= yes
			}
			add = 100
			desc = LEGEND_HOOK_USED
		}
		# Are you using Gold?
		modifier = {
			trigger = {
				scope:gold_cost ?= yes
			}
			add = 40
			desc = TRADE_GOLD_FOR_BETTER_AI_ACCEPTANCE_TT
		}
		## Opinion
		# Do they like you?
		opinion_modifier = {
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 1
			desc = AI_OPINION_REASON
		}
		## Personality
		# Are they ambitious?
		modifier = {
			desc = DEMAND_SUBMISSION_RECIPIENT_IS_AMBITIOUS #re-using these
			add = -15
			scope:recipient = {
				has_trait = ambitious
			}
		}
		# Are they content?
		modifier = {
			desc = DEMAND_SUBMISSION_RECIPIENT_IS_CONTENT
			add = 5
			scope:recipient = { has_trait = content }
		}
		# Are they stubborn?
		modifier = {
			desc = DEMAND_SUBMISSION_RECIPIENT_IS_STUBBORN
			add = -10
			scope:recipient = { has_trait = stubborn }
		}
		# Are they arrogant?
		modifier = {
			desc = DEMAND_SUBMISSION_RECIPIENT_IS_ARROGANT
			add = -10
			scope:recipient = { has_trait = arrogant }
		}
		# Are they humble?
		modifier = {
			desc = DEMAND_SUBMISSION_RECIPIENT_IS_HUMBLE
			add = 10
			scope:recipient = { has_trait = humble }
		}
		# Are they trusting?
		modifier = {
			desc = DEMAND_SUBMISSION_RECIPIENT_IS_TRUSTING
			add = 15
			scope:recipient = { has_trait = trusting }
		}
		# Are they paranoid?
		modifier = {
			desc = DEMAND_SUBMISSION_RECIPIENT_IS_PARANOID
			add = -10
			scope:recipient = { has_trait = paranoid }
		}
		## Dread
		modifier = {
			add = intimidated_halved_reason_value
			scope:recipient = {
				has_dread_level_towards = {
					target = scope:actor
					level = 1
				}
			}
			desc = INTIMIDATED_REASON
		}
		modifier = {
			add = cowed_halved_reason_value
			scope:recipient = {
				has_dread_level_towards = {
					target = scope:actor
					level = 2
				}
			}
			desc = COWED_REASON
		}
		## War
		modifier = {
			add = -50
			scope:recipient = {
				is_at_war = yes
			}
			desc = HOSTAGE_AT_WAR_REASON
		}
		## Low Gold
		modifier = {
			add = -100
			scope:actor.promoted_legend = {
				legend_quality = famed
			}
			scope:recipient = {
				monthly_character_income < famed_legend_promoter_cost
			}
			desc = TOO_HIGH_PROMOTER_MAINTENANCE_REASON
		}
		modifier = {
			add = -100
			scope:actor.promoted_legend = {
				legend_quality = illustrious
			}
			scope:recipient = {
				monthly_character_income < illustrious_legend_promoter_cost
			}
			desc = TOO_HIGH_PROMOTER_MAINTENANCE_REASON
		}
		modifier = {
			add = -100
			scope:actor.promoted_legend = {
				legend_quality = mythical
			}
			scope:recipient = {
				monthly_character_income < mythical_legend_promoter_cost
			}
			desc = TOO_HIGH_PROMOTER_MAINTENANCE_REASON
		}
		modifier = {
			add = 25
			scope:recipient = {
				is_contact_of = scope:actor
			}
			desc = IS_CONTACT_REASON
		}
	}

	on_accept = {
		scope:actor.promoted_legend = {
			save_scope_as = promoted_legend
		}
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_good
				title = ce1_ask_to_promote_legend_acceptance_tt
				left_icon = scope:actor
				right_icon = scope:recipient

				if = {
					limit = { scope:hook = yes }
					use_hook = scope:recipient
				}
				if = {
					limit = { scope:gold_cost = yes }
					pay_short_term_gold = {
						target = scope:recipient
						gold = medium_gold_value
					}
					promoted_legend = { # To prevent gold exploits
						add_to_variable_list = {
							name = accepted_promote_legend_var
							target = scope:recipient
							years = 10
						}
					}
				}
				scope:recipient = {
					set_promoted_legend = scope:actor.promoted_legend
				}
			}
		}
	}

	on_decline = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_bad
				title = ce1_ask_to_promote_legend_decline_tt
				left_icon = scope:actor
				right_icon = scope:recipient
			}
		}
	}

	# Use gold to increase acceptance
	send_option = {
		flag = gold_cost
		localization = TRADE_GOLD_FOR_BETTER_AI_ACCEPTANCE
	}
	send_option = {
		flag = hook
		is_valid = {
			scope:actor = {
				has_usable_hook = scope:recipient
			}
		}
		localization = GENERIC_SPEND_A_HOOK
	}
	send_options_exclusive = no

	ai_potential = {
		is_physically_able = yes
	}

	ai_targets = {
		ai_recipients = neighboring_rulers
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 72
		duchy = 36
		kingdom = 12
		empire = 12
		hegemony = 12
	}
	
	# Very similar to ai_accept, but ignores effects that are < 10 in value for brevity's sake
	ai_will_do = {
		base = 0
		## Legends
		modifier = {
			add = 25
			exists = promoted_legend
		}
		modifier = {
			add = 25
			promoted_legend = {
				legend_quality = mythical
			}
		}
		## Gold
		modifier = {
			add = -100
			debt_level >= 0
		}
		modifier = {
			add = -50
			gold <= major_gold_value
		}
		## Personality
		modifier = {
			add = 25
			has_trait = arrogant
		}
	}
}
