﻿##################################################
# Generation
##################################################

## Themes
select_poem_theme_romance_effect = {
	set_variable = {
		name = poetry_theme
		value = flag:romance
	}
	# Set up a scope for gender effect checking.
	save_scope_value_as = {
		name = poetry_romance_target
		value = yes
	}
}

select_poem_theme_mourning_effect = {
	set_variable = {
		name = poetry_theme
		value = flag:mourning
	}
}

select_poem_theme_legacy_effect = {
	set_variable = {
		name = poetry_theme
		value = flag:legacy
	}
}

select_poem_theme_strife_effect = {
	set_variable = {
		name = poetry_theme
		value = flag:strife
	}
}

select_poem_theme_incompetence_effect = {
	set_variable = {
		name = poetry_theme
		value = flag:incompetence
	}
}

select_poem_theme_random_effect = {
	hidden_effect = {
		random_list = {
			# Romance
			100 = { select_poem_theme_romance_effect = yes }
			# Mourning
			100 = { select_poem_theme_mourning_effect = yes }
			# Legacy
			100 = { select_poem_theme_legacy_effect = yes }
			# Strife
			100 = { select_poem_theme_strife_effect = yes }
			# Incompetence
			100 = { select_poem_theme_incompetence_effect = yes }
		}
	}
}

## Subject
### Used to select subject genders, taking any of the following:
#### flag:specific
#### flag:woman
#### flag:man
#### flag:random
### SUBJECT_TARGET needs to be filled out regardless to prevent errors, but is inert unless you've also set flag:specific.
#### Just stick it to root or whoever if not actively using it.
select_poem_subject_gender_effect = {
	save_temporary_scope_value_as = {
		name = subject
		value = $SUBJECT$
	}
	# If we have a $CHARACTER$ designated, select that.
	if = {
		limit = { scope:subject = flag:specific }
		$SUBJECT_TARGET$ = { save_scope_as = subject }
	}
	# If we have a manually selected gender, grab that.
	else_if = {
		limit = { scope:subject = flag:woman }
		dummy_female = { save_scope_as = subject }
	}
	else_if = {
		limit = { scope:subject = flag:man }
		dummy_male = { save_scope_as = subject }
	}
	# Otherwise, generate a dummy.
	else = {
		# Is this a romantic poem?
		if = {
			limit = { exists = scope:poetry_romance_target }
			# If so, only target the correct gender for preference.
			romance_target_gender_effect = { SCOPE_NAME = subject }
		}
		# Otherwise, just a random dummy is fine.
		else = {
			random_dummy_gender_soldier_effect = { SCOPE_NAME = subject }
		}
	}
	# Finally, set this as a variable on root so that custom loc can access it.
	set_variable = {
		name = poem_subject
		value = scope:subject
	}
}

##################################################
# Cleanup
##################################################

cleanup_poem_effect = {
	# Remove the generated theme.
	remove_variable = poetry_theme
	# And designated subject.
	remove_variable = poem_subject
}

##################################################
# Send Poem Interaction Consequences
##################################################

@send_poem_rejected_prestige_cost = medium_prestige_loss
@send_poem_rejected_prestige_gain = minor_prestige_gain
@send_poem_accepted_prestige_regain = minor_prestige_gain

send_poem_romance_duel_actor_victory_effect = {
	scope:actor = {
		if = {
			limit = {
				has_trait = lifestyle_poet
			}
			add_trait_xp = {
				trait = lifestyle_poet
				value = { 5 10 }
			}
		}
	}
	# Add a good amount of opinion of scope:actor.
	scope:recipient = {
		add_opinion = {
			target = scope:actor
			modifier = sent_poem_romance_opinion
		}
		hidden_effect = {
			random = {
				chance = 25
				if = {
					limit = { can_set_relation_potential_lover_trigger = { CHARACTER = scope:actor } }
					set_relation_potential_lover = scope:actor
				}
			}
		}
	}
}
send_poem_romance_duel_actor_failure_effect = {
	# reduce their opinion of scope:recipient.
	hidden_effect = {
		scope:actor = {
			add_opinion = {
				target = scope:recipient
				modifier = sent_poem_humiliated_opinion
			}
		}
	}
	# & give prestige to scope:recipient
	scope:recipient = {
		add_opinion = {
			opinion = -20
			target = scope:actor
			modifier = sent_poem_humiliated_opinion
		}
		hidden_effect = {
			random = {
				chance = 20
				if = {
					limit = { can_set_relation_potential_rival_trigger = { CHARACTER = scope:actor } }
					set_relation_potential_rival = scope:actor
				}
			}
		}
		add_prestige = @send_poem_rejected_prestige_gain
	}
}

send_poem_mourning_duel_actor_victory_effect = {
	scope:actor = {
		if = {
			limit = {
				has_trait = lifestyle_poet
			}
			add_trait_xp = {
				trait = lifestyle_poet
				value = { 5 10 }
			}
		}
	}
	# Add a modest amount of opinion of scope:actor & some stress loss.
	scope:recipient = {
		add_opinion = {
			target = scope:actor
			modifier = sent_poem_mourning_opinion
		}
		hidden_effect = {
			random = {
				chance = 25
				if = {
					limit = { can_set_relation_potential_friend_trigger = { CHARACTER = scope:actor } }
					set_relation_potential_friend = scope:actor
				}
			}
		}
		add_stress = medium_stress_loss
	}
}
send_poem_mourning_duel_actor_failure_effect = {
	# reduce their opinion of scope:recipient.
	hidden_effect = {
		scope:actor = {
			add_opinion = {
				target = scope:recipient
				modifier = sent_poem_humiliated_opinion
			}
		}
	}
	scope:recipient = {
		add_opinion = {
			opinion = -20
			target = scope:actor
			modifier = sent_poem_humiliated_opinion
		}
		hidden_effect = {
			random = {
				chance = 20
				if = {
					limit = { can_set_relation_potential_rival_trigger = { CHARACTER = scope:actor } }
					set_relation_potential_rival = scope:actor
				}
			}
		}
		add_prestige = @send_poem_rejected_prestige_gain
	}
}

send_poem_legacy_duel_actor_victory_effect = {
	scope:actor = {
		if = {
			limit = {
				has_trait = lifestyle_poet
			}
			add_trait_xp = {
				trait = lifestyle_poet
				value = { 5 10 }
			}
		}
	}
	# Add a modest amount of opinion of scope:actor & some piety.
	scope:recipient = {
		add_opinion = {
			target = scope:actor
			modifier = sent_poem_grateful_opinion
		}
		hidden_effect = {
			random = {
				chance = 25
				if = {
					limit = { can_set_relation_potential_friend_trigger = { CHARACTER = scope:actor } }
					set_relation_potential_friend = scope:actor
				}
			}
		}
		add_piety = minor_piety_gain
	}
}
send_poem_legacy_duel_actor_failure_effect = {
	# reduce their opinion of scope:recipient.
	hidden_effect = {
		scope:actor = {
			add_opinion = {
				target = scope:recipient
				modifier = sent_poem_humiliated_opinion
			}
		}
	}
	# & give prestige to scope:recipient
	scope:recipient = {
		add_opinion = {
			opinion = -20
			target = scope:actor
			modifier = sent_poem_humiliated_opinion
		}
		hidden_effect = {
			random = {
				chance = 20
				if = {
					limit = { can_set_relation_potential_rival_trigger = { CHARACTER = scope:actor } }
					set_relation_potential_rival = scope:actor
				}
			}
		}
		add_prestige = @send_poem_rejected_prestige_gain
	}
}

send_poem_strife_duel_actor_victory_effect = {
	scope:actor = {
		if = {
			limit = {
				has_trait = lifestyle_poet
			}
			add_trait_xp = {
				trait = lifestyle_poet
				value = { 5 10 }
			}
		}
	}
	# Add a modest amount of opinion of scope:actor & some prestige.
	scope:recipient = {
		add_opinion = {
			target = scope:actor
			modifier = sent_poem_grateful_opinion
		}
		hidden_effect = {
			random = {
				chance = 25
				if = {
					limit = { can_set_relation_potential_friend_trigger = { CHARACTER = scope:actor } }
					set_relation_potential_friend = scope:actor
				}
			}
		}
		add_prestige = minor_prestige_gain
	}
}
send_poem_strife_duel_actor_failure_effect = {
	# reduce their opinion of scope:recipient.
	hidden_effect = {
		scope:actor = {
			add_opinion = {
				target = scope:recipient
				modifier = sent_poem_humiliated_opinion
			}
		}
	}
	# & give prestige to scope:recipient
	scope:recipient = {
		add_opinion = {
			opinion = -20
			target = scope:actor
			modifier = sent_poem_humiliated_opinion
		}
		hidden_effect = {
			random = {
				chance = 20
				if = {
					limit = { can_set_relation_potential_rival_trigger = { CHARACTER = scope:actor } }
					set_relation_potential_rival = scope:actor
				}
			}
		}
		add_prestige = @send_poem_rejected_prestige_gain
	}
}

send_poem_incompetence_duel_actor_victory_effect = {
	scope:actor = {
		if = {
			limit = {
				has_trait = lifestyle_poet
			}
			add_trait_xp = {
				trait = lifestyle_poet
				value = { 5 10 }
			}
		}
	}
	# Reduce opinion of scope:actor & add stress.
	scope:recipient = {
		add_opinion = {
			target = scope:actor
			modifier = sent_poem_humiliated_opinion
		}
		hidden_effect = {
			random = {
				chance = 50
				if = {
					limit = { can_set_relation_potential_rival_trigger = { CHARACTER = scope:actor } }
					set_relation_potential_rival = scope:actor
				}
			}
		}
		add_stress = major_stress_gain
	}
}
send_poem_incompetence_duel_actor_failure_effect = {
	# reduce their opinion of scope:recipient.
	hidden_effect = {
		scope:actor = {
			add_opinion = {
				target = scope:recipient
				modifier = sent_poem_humiliated_opinion
			}
		}
	}
	# & give prestige to scope:recipient
	scope:recipient = {
		add_opinion = {
			opinion = -20
			target = scope:actor
			modifier = sent_poem_humiliated_opinion
		}
		hidden_effect = {
			random = {
				chance = 20
				if = {
					limit = { can_set_relation_potential_rival_trigger = { CHARACTER = scope:actor } }
					set_relation_potential_rival = scope:actor
				}
			}
		}
		add_prestige = @send_poem_rejected_prestige_gain
	}
}

##################################################
# Send Poem Interaction Duels
##################################################

send_poem_romance_duel_victory_notification_effect = {
	# Send out toasts.
	hidden_effect = {
		# Send scope:actor-side toast
		scope:actor = {
			send_interface_toast = {
				title = send_poem_interaction.success
				left_icon = scope:recipient
				show_as_tooltip = { send_poem_romance_duel_actor_victory_effect = yes }
			}
		}
		# Send scope:recipient-side toast.
		send_interface_toast = {
			title = send_poem_interaction.success
			left_icon = scope:actor
			show_as_tooltip = { send_poem_romance_duel_actor_victory_effect = yes }
		}
	}
	# Calculate the actual effects.
	send_poem_romance_duel_actor_victory_effect = yes
}
send_poem_romance_duel_defeat_notification_effect = {
	# Send out toasts.
	hidden_effect = {
		# Send scope:actor-side toast
		scope:actor = {
			send_interface_toast = {
				title = send_poem_interaction.failure
				left_icon = scope:recipient
				show_as_tooltip = { send_poem_romance_duel_actor_failure_effect = yes }
			}
		}
		# Send scope:recipient-side toast.
		send_interface_toast = {
			title = send_poem_interaction.failure
			left_icon = scope:actor
			show_as_tooltip = { send_poem_romance_duel_actor_failure_effect = yes }
		}
	}
	# Calculate the actual effects.
	send_poem_romance_duel_actor_failure_effect = yes
}
send_poem_romance_duel_effect = {
	duel = {
		skill = diplomacy
		target = $POV_TARGET$
		# Scope:actor's words find their mark.
		50 = {
			compare_modifier = {
				value = scope:duel_value
				multiplier = -3.5
				min = -49
				max = 49
			}
			desc = send_poem_interaction.success
			# Sort notifications & output.
			send_poem_romance_duel_victory_notification_effect = yes
		}
		# Scope:recipient is able to publicly ridicule the poem.
		50 = {
			compare_modifier = {
				value = scope:duel_value
				multiplier = 3.5
				min = -49
				max = 49
			}
			desc = send_poem_interaction.failure
			# Sort notifications & output.
			send_poem_romance_duel_defeat_notification_effect = yes
		}
	}
}

send_poem_mourning_duel_victory_notification_effect = {
	# Send out toasts.
	hidden_effect = {
		# Send scope:actor-side toast
		scope:actor = {
			send_interface_toast = {
				title = send_poem_interaction.success
				left_icon = scope:recipient
				show_as_tooltip = { send_poem_mourning_duel_actor_victory_effect = yes }
			}
		}
		# Send scope:recipient-side toast.
		send_interface_toast = {
			title = send_poem_interaction.success
			left_icon = scope:actor
			show_as_tooltip = { send_poem_mourning_duel_actor_victory_effect = yes }
		}
	}
	# Calculate the actual effects.
	send_poem_mourning_duel_actor_victory_effect = yes
}
send_poem_mourning_duel_defeat_notification_effect = {
	# Send out toasts.
	hidden_effect = {
		# Send scope:actor-side toast
		scope:actor = {
			send_interface_toast = {
				title = send_poem_interaction.failure
				left_icon = scope:recipient
				show_as_tooltip = { send_poem_mourning_duel_actor_failure_effect = yes }
			}
		}
		# Send scope:recipient-side toast.
		send_interface_toast = {
			title = send_poem_interaction.failure
			left_icon = scope:actor
			show_as_tooltip = { send_poem_mourning_duel_actor_failure_effect = yes }
		}
	}
	# Calculate the actual effects.
	send_poem_mourning_duel_actor_failure_effect = yes
}
send_poem_mourning_duel_effect = {
	duel = {
		skill = diplomacy
		target = $POV_TARGET$
		# Scope:actor's words find their mark.
		50 = {
			compare_modifier = {
				value = scope:duel_value
				multiplier = -3.5
				min = -49
				max = 49
			}
			desc = send_poem_interaction.success
			# Sort notifications & output.
			send_poem_mourning_duel_victory_notification_effect = yes
		}
		# Scope:recipient is able to publicly ridicule the poem.
		50 = {
			compare_modifier = {
				value = scope:duel_value
				multiplier = 3.5
				min = -49
				max = 49
			}
			desc = send_poem_interaction.failure
			# Sort notifications & output.
			send_poem_mourning_duel_defeat_notification_effect = yes
		}
	}
}

send_poem_legacy_duel_victory_notification_effect = {
	# Send out toasts.
	hidden_effect = {
		# Send scope:actor-side toast
		scope:actor = {
			send_interface_toast = {
				title = send_poem_interaction.success
				left_icon = scope:recipient
				show_as_tooltip = { send_poem_legacy_duel_actor_victory_effect = yes }
			}
		}
		# Send scope:recipient-side toast.
		send_interface_toast = {
			title = send_poem_interaction.success
			left_icon = scope:actor
			show_as_tooltip = { send_poem_legacy_duel_actor_victory_effect = yes }
		}
	}
	# Calculate the actual effects.
	send_poem_legacy_duel_actor_victory_effect = yes
}

send_poem_legacy_duel_defeat_notification_effect = {
	# Send out toasts.
	hidden_effect = {
		# Send scope:actor-side toast
		scope:actor = {
			send_interface_toast = {
				title = send_poem_interaction.failure
				left_icon = scope:recipient
				show_as_tooltip = { send_poem_legacy_duel_actor_failure_effect = yes }
			}
		}
		# Send scope:recipient-side toast.
		send_interface_toast = {
			title = send_poem_interaction.failure
			left_icon = scope:actor
			show_as_tooltip = { send_poem_legacy_duel_actor_failure_effect = yes }
		}
	}
	# Calculate the actual effects.
	send_poem_legacy_duel_actor_failure_effect = yes
}

send_poem_legacy_duel_effect = {
	duel = {
		skill = diplomacy
		target = $POV_TARGET$
		# Scope:actor's words find their mark.
		50 = {
			compare_modifier = {
				value = scope:duel_value
				multiplier = -3.5
				min = -49
				max = 49
			}
			desc = send_poem_interaction.success
			# Sort notifications & output.
			send_poem_legacy_duel_victory_notification_effect = yes
		}
		# Scope:recipient is able to publicly ridicule the poem.
		50 = {
			compare_modifier = {
				value = scope:duel_value
				multiplier = 3.5
				min = -49
				max = 49
			}
			desc = send_poem_interaction.failure
			# Sort notifications & output.
			send_poem_legacy_duel_defeat_notification_effect = yes
		}
	}
}

send_poem_strife_duel_victory_notification_effect = {
	# Send out toasts.
	hidden_effect = {
		# Send scope:actor-side toast
		scope:actor = {
			send_interface_toast = {
				title = send_poem_interaction.success
				left_icon = scope:recipient
				show_as_tooltip = { send_poem_strife_duel_actor_victory_effect = yes }
			}
		}
		# Send scope:recipient-side toast.
		send_interface_toast = {
			title = send_poem_interaction.success
			left_icon = scope:actor
			show_as_tooltip = { send_poem_strife_duel_actor_victory_effect = yes }
		}
	}
	# Calculate the actual effects.
	send_poem_strife_duel_actor_victory_effect = yes
}

send_poem_strife_duel_defeat_notification_effect = {
	# Send out toasts.
	hidden_effect = {
		# Send scope:actor-side toast
		scope:actor = {
			send_interface_toast = {
				title = send_poem_interaction.failure
				left_icon = scope:recipient
				show_as_tooltip = { send_poem_strife_duel_actor_failure_effect = yes }
			}
		}
		# Send scope:recipient-side toast.
		send_interface_toast = {
			title = send_poem_interaction.failure
			left_icon = scope:actor
			show_as_tooltip = { send_poem_strife_duel_actor_failure_effect = yes }
		}
	}
	# Calculate the actual effects.
	send_poem_strife_duel_actor_failure_effect = yes
}

send_poem_strife_duel_effect = {
	duel = {
		skill = diplomacy
		target = $POV_TARGET$
		# Scope:actor's words find their mark.
		50 = {
			compare_modifier = {
				value = scope:duel_value
				multiplier = -3.5
				min = -49
				max = 49
			}
			desc = send_poem_interaction.success
			# Sort notifications & output.
			send_poem_strife_duel_victory_notification_effect = yes
		}
		# Scope:recipient is able to publicly ridicule the poem.
		50 = {
			compare_modifier = {
				value = scope:duel_value
				multiplier = 3.5
				min = -49
				max = 49
			}
			desc = send_poem_interaction.failure
			# Sort notifications & output.
			send_poem_strife_duel_defeat_notification_effect = yes
		}
	}
}

send_poem_incompetence_duel_victory_notification_effect = {
	# Send out toasts.
	hidden_effect = {
		# Send scope:actor-side toast
		scope:actor = {
			send_interface_toast = {
				title = send_poem_interaction.success
				left_icon = scope:recipient
				show_as_tooltip = { send_poem_incompetence_duel_actor_victory_effect = yes }
			}
		}
		# Send scope:recipient-side toast.
		send_interface_toast = {
			title = send_poem_interaction.success
			left_icon = scope:actor
			show_as_tooltip = { send_poem_incompetence_duel_actor_victory_effect = yes }
		}
	}
	# Calculate the actual effects.
	send_poem_incompetence_duel_actor_victory_effect = yes
}

send_poem_incompetence_duel_defeat_notification_effect = {
	# Send out toasts.
	hidden_effect = {
		# Send scope:actor-side toast
		scope:actor = {
			send_interface_toast = {
				title = send_poem_interaction.failure
				left_icon = scope:recipient
				show_as_tooltip = { send_poem_incompetence_duel_actor_failure_effect = yes }
			}
		}
		# Send scope:recipient-side toast.
		send_interface_toast = {
			title = send_poem_interaction.failure
			left_icon = scope:actor
			show_as_tooltip = { send_poem_incompetence_duel_actor_failure_effect = yes }
		}
	}
	# Calculate the actual effects.
	send_poem_incompetence_duel_actor_failure_effect = yes
}

send_poem_incompetence_duel_effect = {
	duel = {
		skill = diplomacy
		target = $POV_TARGET$
		# Scope:actor's words find their mark.
		50 = {
			compare_modifier = {
				value = scope:duel_value
				multiplier = -3.5
				min = -49
				max = 49
			}
			desc = send_poem_interaction.success
			# Sort notifications & output.
			send_poem_incompetence_duel_victory_notification_effect = yes
		}
		# Scope:recipient is able to publicly ridicule the poem.
		50 = {
			compare_modifier = {
				value = scope:duel_value
				multiplier = 3.5
				min = -49
				max = 49
			}
			desc = send_poem_interaction.failure
			# Sort notifications & output.
			send_poem_incompetence_duel_defeat_notification_effect = yes
		}
	}
}
