﻿# Poetry

###################
# Send a Poem
# by Ewan Cowhig Croft & Alexander Oltner
###################
send_poem_interaction = {
	interface_priority = 30
	common_interaction = yes
	category = interaction_category_friendly
	popup_on_receive = yes
	pause_on_receive = yes
	desc = send_poem_interaction_desc

	is_shown = {
		# Must be a poet.
		scope:actor = {
			OR = { 
				has_trait = poet
				employs_court_position = master_bard_camp_officer
				employs_court_position = laureate_camp_officer
			}
		}
		# Cannot send self fan-poetry. Egoist.
		NOT = { scope:actor = scope:recipient }
		# May only write for adults.
		scope:recipient = { is_adult = yes }
	}

	is_valid_showing_failures_only = {
		# Neither of the characters can be imprisoned.
		scope:actor = { is_imprisoned = no }
		scope:recipient = { is_imprisoned = no }
	}

	can_send = {
		scope:actor = {
			custom_description = {
				text = "character_interactions_hostile_actions_disabled_delay"
				NOT = { has_character_flag = flag_hostile_actions_disabled_delay }
			}
		}
    }

    send_options_exclusive = yes

	cost = { prestige = minor_prestige_value }

	cooldown = { years = 3 }
	cooldown_against_recipient = { years = send_poem_cooldown_years_value }

	on_send = {
		scope:actor = {
			add_character_flag = {
				flag = flag_hostile_actions_disabled_delay
				days = 10
			}
		}
	}

	on_accept = {
		# Set up the poem subject.
		scope:actor = {
			# Set up a subject gender.
			select_poem_subject_gender_effect = {
				SUBJECT = flag:specific
				SUBJECT_TARGET = scope:recipient
			}
		}
		# Theme Effects
		## Romantic
		if = {
			limit = { always = scope:poem_theme_romance }
			# As this is a positive poem, inform scope:actor that scope:recipient may simply accept it.
			custom_tooltip = send_poem_interaction.positive_auto_accept.tt
			# Show the potential duel.
			show_as_tooltip = {
				scope:recipient = {
					send_poem_romance_duel_effect = { POV_TARGET = scope:actor }
				}
			}
			# Set up the theme.
			scope:actor = { select_poem_theme_romance_effect = yes }
			# Send the response event to scope:recipient.
			scope:recipient = { trigger_event = trait_specific_interactions.0001 }
		}
		## Mourning
		else_if = {
			limit = { always = scope:poem_theme_mourning }
			# As this is a positive poem, inform scope:actor that scope:recipient may simply accept it.
			custom_tooltip = send_poem_interaction.positive_auto_accept.tt
			# Show the potential duel.
			show_as_tooltip = {
				scope:recipient = {
					send_poem_mourning_duel_effect = { POV_TARGET = scope:actor }
				}
			}
			# Set up the theme.
			scope:actor = { select_poem_theme_mourning_effect = yes }
			# Send the response event to scope:recipient.
			scope:recipient = { trigger_event = trait_specific_interactions.0011 }
		}
		## Legacy
		else_if = {
			limit = { always = scope:poem_theme_legacy }
			# As this is a positive poem, inform scope:actor that scope:recipient may simply accept it.
			custom_tooltip = send_poem_interaction.positive_auto_accept.tt
			# Show the potential duel.
			show_as_tooltip = {
				scope:recipient = {
					send_poem_legacy_duel_effect = { POV_TARGET = scope:actor }
				}
			}
			# Set up the theme.
			scope:actor = { select_poem_theme_legacy_effect = yes }
			# Send the response event to scope:recipient.
			scope:recipient = { trigger_event = trait_specific_interactions.0021 }
		}
		## Strife
		else_if = {
			limit = { always = scope:poem_theme_strife }
			# As this is a positive poem, inform scope:actor that scope:recipient may simply accept it.
			custom_tooltip = send_poem_interaction.positive_auto_accept.tt
			# Show the potential duel.
			show_as_tooltip = {
				scope:recipient = {
					send_poem_strife_duel_effect = { POV_TARGET = scope:actor }
				}
			}
			# Set up the theme.
			scope:actor = { select_poem_theme_strife_effect = yes }
			# Send the response event to scope:recipient.
			scope:recipient = { trigger_event = trait_specific_interactions.0031 }
		}
		## Incompetence
		else_if = {
			limit = { always = scope:poem_theme_incompetence }
			# Show the potential duel.
			show_as_tooltip = {
				scope:recipient = {
					send_poem_incompetence_duel_effect = { POV_TARGET = scope:actor }
				}
			}
			# Set up the theme.
			scope:actor = { select_poem_theme_incompetence_effect = yes }
			# Send the response event to scope:recipient.
			scope:recipient = { trigger_event = trait_specific_interactions.0041 }
		}
		# Make sure the AI doesn't spam players
		scope:recipient = {
			if = {
				limit = {
					is_ai = no
				}
				add_character_flag = {
					flag = ai_poem_block
					years = 5
				}
			}
		}
		# Clear up hostile actions flag.
		if = {
			limit = {
				scope:actor = { has_character_flag = flag_hostile_actions_disabled_delay }
			}
			scope:actor = { remove_character_flag = flag_hostile_actions_disabled_delay }
		}

		# If we're a clan this interaction affects unity
		add_clan_unity_interaction_effect = {
			CHARACTER = scope:actor
			TARGET = scope:recipient
			VALUE = minor_unity_gain
			DESC = clan_unity_poetry.desc
			REVERSE_NON_HOUSE_TARGET = no
		}
	}

	# SEND OPTIONS
	## Send a romantic poem.
	send_option = {
		is_shown = {
			# Only available if they'd be attracted to you.
			scope:recipient = { is_attracted_to_gender_of = scope:actor }
			# And the romance would be acceptable to both parties.
			accepts_incest_with_each_other_trigger = {
				CHARACTER_1 = scope:actor
				CHARACTER_2 = scope:recipient
			}
			scope:recipient = {
				freely_accepts_sodomy_with_trigger = { CHARACTER = scope:actor }
			}
			# Plus not if either of you have a soulmate, unless you're each other's soulmates.
			scope:actor = {
				OR = {
					any_relation = {
						type = soulmate
						count = 0
					}
					has_relation_soulmate = scope:recipient
					faith = { has_doctrine_parameter = no_unfaithfulness_penalty_active }
				}
			}
			scope:recipient = {
				OR = {
					any_relation = {
						type = soulmate
						count = 0
					}
					has_relation_soulmate = scope:actor
					faith = { has_doctrine_parameter = no_unfaithfulness_penalty_active }
				}
			}
			# As this is a positive option, we restrict it to non-rivals and players.
			scope:actor = { send_poem_positive_poem_lock_trigger = yes }
		}
		flag = poem_theme_romance
		localization = "SEND_POEM_ROMANCE"
	}
	## Send a poem about legacy.
	send_option = {
		is_shown = {
			# Scope:recipient must be a ruler & at least _potentially_ concerned.
			scope:recipient = {
				is_ruler = yes
				NOT = { has_trait = humble }
			}
			# As this is a positive option, we restrict it to non-rivals and players.
			scope:actor = { send_poem_positive_poem_lock_trigger = yes }
		}
		flag = poem_theme_legacy
		localization = "SEND_POEM_LEGACY"
	}
	## Send a mourning poem.
	send_option = {
		# Scope:recipient must have at least one dead close family member.
		is_shown = {
			scope:recipient = {
				any_close_family_member = {
					even_if_dead = yes
					is_alive = no
					NOT = { # It's quite natural
						is_grandparent_of = scope:recipient
					}
				}
			}
		}
		flag = poem_theme_mourning
		localization = "SEND_POEM_MOURNING"
	}
	## Send a poem about strife.
	send_option = {
		is_shown = {
			# Scope:recipient must be a ruler & at least _potentially_ concerned.
			scope:recipient = {
				is_ruler = yes
				NOT = { has_trait = humble }
			}
			# As this is a positive option, we restrict it to non-rivals and players.
			scope:actor = { send_poem_positive_poem_lock_trigger = yes }
		}
		flag = poem_theme_strife
		localization = "SEND_POEM_STRIFE"
	}
	## Send a poem about incompetence.
	send_option = {
		is_shown = {
			# As this is a negative option, we restrict it to rivals and players.
			scope:actor = { send_poem_negative_poem_lock_trigger = yes }
		}
		flag = poem_theme_incompetence
		localization = "SEND_POEM_INCOMPETENCE"
	}

	auto_accept = yes

	# AI
	ai_potential = {
		has_trait = poet
		is_imprisoned = no
		prestige >= 150
		is_at_war = no
	}
	ai_target_quick_trigger = { adult = yes }
	ai_targets = {
		ai_recipients = scripted_relations
	}
	ai_targets = {
		ai_recipients = liege
	}
	ai_targets = {
		ai_recipients = neighboring_rulers
		ai_recipients = peer_vassals
		ai_recipients = top_realm_domicile_owners
		max = 10
	}
	ai_targets = {
		ai_recipients = vassals
		max = 10
	}
	ai_frequency = 60
	ai_will_do = {
		base = 50
		
		# Lustful characters prefer romance poems
		modifier = {
			add = 50
			OR = {
				has_trait = lustful
				has_focus = intrigue_temptation_focus
			}
			scope:poem_theme_romance = yes
		}
		
		# Arrogant characters are prone to actually interact via public poetry publishing.
		modifier = {
			add = 20
			scope:actor = { has_trait = arrogant }
		}
		
		# Certain personality types skew towards specific poem types
		modifier = {
			add = 10
			scope:actor = {
				has_trait_benevolent_trigger = yes
			}
			scope:poem_theme_mourning = yes
		}
		modifier = {
			add = 10
			scope:actor = {
				has_trait_submissive_trigger = yes
			}
			scope:poem_theme_legacy = yes
		}
		modifier = {
			add = 10
			scope:actor = {
				has_trait_malicious_trigger = yes
			}
			scope:poem_theme_strife = yes
		}
		
		## Insult people you don't like
		modifier = {
			add = 50
			scope:poem_theme_incompetence = yes
			scope:actor = {
				OR = {
					has_personality_malicious_trigger = yes
					has_relation_potential_rival = scope:recipient
					has_relation_rival = scope:recipient
				}
			}
		}
		## Players enjoy receiving poetry!
		modifier = {
			add = 50
			scope:recipient = {
				is_ai = no
			}
		}

		# Unity modifiers
		evaluate_action_increasing_house_unity = {
			VALUE = 100
		}
		
		# Characters who are not lustful don't send romantic poems to just anyone
		modifier = {
			factor = 0
			NOR = {
				has_trait = lustful
				has_focus = intrigue_temptation_focus
			}
			scope:recipient = {
				NOR = {
					has_relation_lover = scope:actor
					is_consort_of = scope:actor
				}
			}
			scope:poem_theme_romance = yes
		}
		
		## Don't use insulting poems willy-nilly
		modifier = {
			factor = 0
			scope:poem_theme_incompetence = yes
			scope:actor = {
				NOR = {
					has_trait = arbitrary
					has_trait = lunatic
					has_relation_potential_rival = scope:recipient
					has_relation_rival = scope:recipient
					opinion = {
						target = scope:recipient
						value <= medium_negative_opinion
					}
				}
			}
		}
		
		## Don't spam players while at war
		modifier = {
			factor = 0
			scope:recipient = {
				is_ai = no
				is_at_war = yes
			}
		}
		
		## Don't spam players when the poetry block is active
		modifier = {
			factor = 0
			scope:recipient = {
				has_character_flag = ai_poem_block
			}
		}
	}
}
