﻿#FORGIVING INTERACTION
abandon_hook_interaction = {
	interface_priority = 120
	common_interaction = yes
	category = interaction_category_friendly
	icon = forgiving

	desc = abandon_hook_interaction_desc
	
	is_shown = {
		OR = {
			scope:actor = {
				has_trait = forgiving
			}
			#Struggle
			scope:actor = {
				any_character_struggle = {
					involvement = involved
					has_struggle_phase_parameter = unlocks_abandon_hook_for_all
					is_secondary_character_involvement_involved_trigger = {
						CHAR = scope:recipient
					}
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:recipient = { is_busy_in_events_localised = yes } 
		scope:actor = {
			has_usable_hook = scope:recipient
		}
		custom_description = {
			scope:actor = {
				NOT = {
					has_hook_of_type = {
						target = scope:recipient
						type = house_head_hook
					}
				}	
			}
			text = need_non_house_head_hook
		}
		custom_description = {
			scope:actor = {
				NOT = {
					has_hook_of_type = {
						target = scope:recipient
						type = ritual_best_friend_hook
					}
				}
			}
			text = need_non_best_friend_hook
		}
	}
	
	on_accept = {
		scope:actor = {	
			send_interface_toast = {
				type = event_toast_effect_neutral
				title =  msg_abandon_hook_interaction_title
				left_icon = scope:actor
				right_icon = scope:recipient
				
				use_hook = scope:recipient
				if = {
					limit = {
						has_strong_hook = scope:recipient
					}
					stress_impact = {
						forgiving = major_stress_impact_loss
					}
				}
				else = {
					stress_impact = {
						forgiving = medium_stress_impact_loss
					}
				}
		
				scope:recipient = {
					add_opinion = {
						target = scope:actor
						modifier = forgiven_opinion
					}
				}
			}
		}

		# 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_abandon_hook.desc
			REVERSE_NON_HOUSE_TARGET = no
		}

		hidden_effect = {
			# Struggle Catalysts
			scope:actor = {
				if = {
					limit = {
						fp3_struggle_involves_one_supporter_and_one_detractor = {
							FIRST = scope:actor
							SECOND = scope:recipient
						}
						any_character_struggle	 = {
							involvement = involved
							phase_has_catalyst = catalyst_abandon_hook_on_supporter_detractor
						}
					}
					every_character_struggle = {
						involvement = involved
						activate_struggle_catalyst = {
							catalyst = catalyst_abandon_hook_on_supporter_detractor
							character = scope:actor
						}
						log_debug_variable_for_persian_struggle_effect = { VAR = concession_catalyst_abandon_hook_on_supporter_detractor }
					}
				}
			}
		}
	}


	ai_frequency = 60

	ai_targets = {
		ai_recipients = guests
		ai_recipients = courtiers
		max = 10
	}

	ai_targets = {
		ai_recipients = liege
	}

	ai_targets = {
		ai_recipients = vassals
		max = 10
	}

	ai_target_quick_trigger = {
		adult = yes
	}
	
	ai_potential = {
		stress_level >= 1
	}

	ai_will_do = {
		base = 100
	}

	auto_accept = yes
}

#ARBITRARY INTERACTION
dismiss_strong_hook_interaction = {
	interface_priority = 120
	common_interaction = yes
	category = interaction_category_hostile
	icon = arbitrary

	cost = { 
		prestige = monumental_prestige_value
	}

	desc = dismiss_strong_hook_interaction_desc
	
	is_shown = {
		scope:actor = {
			has_trait = arbitrary
		}

		scope:recipient = {
			is_vassal_of = scope:actor 
			has_strong_hook = scope:actor
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			prestige >= monumental_prestige_value
		}
	}
	
	on_accept = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title =  msg_dismiss_hook_interaction_title
				left_icon = scope:actor
				right_icon = scope:recipient
		
				scope:recipient = {	
					remove_hook  =  { target = scope:actor }
					add_opinion = {
						target = scope:actor
						modifier = lost_strong_hook_opinion
					}
				}	

				add_tyranny = 35	
			}
		}

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

	ai_frequency = 60
	
	ai_potential = {
		dread >= 50
	}

	ai_will_do = {
		base = 100
	}

	ai_targets = {
		ai_recipients = guests
		ai_recipients = courtiers
		max = 10
	}

	ai_targets = {
		ai_recipients = liege
	}

	ai_targets = {
		ai_recipients = vassals
		max = 10
	}

	ai_target_quick_trigger = {
		adult = yes
	}

	auto_accept = yes
}

dismiss_weak_hook_interaction = {
	interface_priority = 120
	common_interaction = yes
	category = interaction_category_hostile
	icon = arbitrary

	cost = { 
		prestige = major_prestige_value
	} 

	desc = dismiss_weak_hook_interaction_desc
	
	is_shown = {
		scope:actor = {
			has_trait = arbitrary
		}

		scope:recipient = {
			is_vassal_of = scope:actor 
			has_usable_hook = scope:actor
			NOT = { has_strong_hook = scope:actor }
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			prestige >= major_prestige_value
		}
	}
	
	on_accept = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_neutral
				title =  msg_dismiss_hook_interaction_title
				left_icon = scope:actor
				right_icon = scope:recipient

				scope:recipient = {	
					remove_hook  =  { target = scope:actor }
					add_opinion = {
						target = scope:actor
						modifier = lost_weak_hook_opinion
					}
					progress_towards_rival_effect = {
						CHARACTER = scope:actor
						REASON = rival_dismissed_weak_hook
 						OPINION = default_rival_opinion
					}
				}

				add_tyranny = 15
			}
		}

		# 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_dismiss_weak_hook.desc
			REVERSE_NON_HOUSE_TARGET = no
		}
	}

	ai_targets = {
		ai_recipients = guests
		ai_recipients = courtiers
		max = 10
	}

	ai_targets = {
		ai_recipients = liege
	}

	ai_targets = {
		ai_recipients = vassals
		max = 10
	}

	ai_target_quick_trigger = {
		adult = yes
	}

	ai_frequency = 60
	
	ai_potential = {
		dread >= 50
	}

	ai_will_do = {
		base = 100
	}

	auto_accept = yes
}

#WRATHFUL DUELING
force_duel_criminals_interaction = {
	interface_priority = 30
	common_interaction = yes
	category = interaction_category_hostile
	ai_maybe = yes
	ai_max_reply_days = 0
	popup_on_receive = yes
	pause_on_receive = yes
	desc = force_duel_criminals_interaction_desc
	icon = wrathful

	greeting = negative
	notification_text = REQUEST_TRIAL_BY_COMBAT_TEXT

	is_shown = {
		#First, verify if the actor is Wrathful
		scope:actor = { has_trait = wrathful }
		#Then, look to see if this character is a criminal.
		scope:actor = {
			OR = {
				has_imprisonment_reason = scope:recipient
				has_banish_reason = scope:recipient
				has_execute_reason = scope:recipient
			}
			basic_allowed_to_imprison_character_trigger = { # And if you are allowed to imprison the target.
				CHARACTER = scope:recipient
			}
		}
		# Can't duel yourself.
		NOT = { scope:actor = scope:recipient }
	}

	is_valid_showing_failures_only = {
		# Calc some stuff that might invalidate elsewhere before the bout is sorted.
		rival_single_combat_shown_and_not_invalid_trigger = yes
		# Scope:recipient must be able to fight personally.
		scope:recipient = { can_start_single_combat_trigger = yes }
		# Scope:recipient must not be banned from single combat.
		scope:recipient = {
			custom_description = {
				text = fp1_tbc_recipient_banned_from_combat
				can_start_single_combat_banned_checks_trigger = no
			}
		}
		# 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 }
			}
		}
	}
	
	cooldown_against_recipient = { years = 10 }

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

	on_accept = {
		# Set up the bout immediately.
		#Starting with the strongest punishment in case more than one reason is valid
		if = {
			limit = {
				scope:actor = { has_execute_reason = scope:recipient }
			}
			## First inform.
			scope:actor = {
				custom_tooltip = force_duel_criminals_interaction.execute_punishment.tt
			}
			## Finally, begin.
			configure_start_single_combat_effect = {
				SC_INITIATOR = scope:actor
				SC_ATTACKER = scope:actor
				SC_DEFENDER = scope:recipient
				FATALITY = no
				FIXED = no
				LOCALE = terrain_scope
				OUTPUT_EVENT = trait_specific_interactions.0155 
				INVALIDATION_EVENT = fp1_tbc.0102
			}
		}
		else_if = {
			limit = {
				scope:actor = { has_banish_reason = scope:recipient }
			}
			## First inform.
			scope:actor = {
				custom_tooltip = force_duel_criminals_interaction.banish_punishment.tt
			}
			## Finally, begin.
			configure_start_single_combat_effect = {
				SC_INITIATOR = scope:actor
				SC_ATTACKER = scope:actor
				SC_DEFENDER = scope:recipient
				FATALITY = no
				FIXED = no
				LOCALE = terrain_scope
				OUTPUT_EVENT = trait_specific_interactions.0153
				INVALIDATION_EVENT = fp1_tbc.0102
			}
		}
		else_if = {
			limit = {
				scope:actor = { has_imprisonment_reason = scope:recipient }
			}
			scope:actor = {
				custom_tooltip = force_duel_criminals_interaction.imprison_punishment.tt
			}

			configure_start_single_combat_effect = {
				SC_INITIATOR = scope:actor
				SC_ATTACKER = scope:actor
				SC_DEFENDER = scope:recipient
				FATALITY = no
				FIXED = no
				LOCALE = terrain_scope
				OUTPUT_EVENT = trait_specific_interactions.0151
				INVALIDATION_EVENT = fp1_tbc.0102
			}
		}
		
	}

	auto_accept = yes

	# AI
	ai_potential = {
		has_trait = wrathful
		is_imprisoned = no
		can_start_single_combat_trigger = yes
	}
	
	ai_target_quick_trigger = {
		adult = yes
	}

	ai_targets = {
		ai_recipients = courtiers
		ai_recipients = guests
		max = 10
	}

	ai_targets = {
		ai_recipients = vassals
		max = 10
	}

	ai_targets = {
		ai_recipients = family
		max = 10
	}


	ai_frequency = 120

	ai_will_do = {
		base = -50
		
		# Factor for personality (excluding realism).
		modifier = {
			add = {
				value = ai_boldness
				multiply = 1
			}
		}
		modifier = { add = ai_vengefulness }
		modifier = {
			add = {
				value = ai_energy
				multiply = -0.25
			}
		}
		# Don't challenge kinslayer-counting family, unless they're your nemesis.
		modifier = {
			scope:actor = {
				murdering_character_is_kinslaying_in_faith_trigger = {
					CHARACTER = scope:recipient
					FAITH = scope:actor.faith
				}
			}
			scope:recipient = {
				NOT = { has_relation_nemesis = scope:actor }
			}
			add = -1000
		}
		# Don't challenge your spouse, unless they're your nemesis.
		modifier = {
			scope:recipient = {
				is_spouse_of = scope:actor
				NOT = { has_relation_nemesis = scope:actor }
			}
			add = -1000
		}
		# Don't challenge people hopelessly out of your league unless you're really, really not seeing things clearly.
		modifier = {
			scope:actor = {
				prowess_diff = {
					target = scope:recipient
					value <= -15
				}
				ai_rationality >= high_negative_ai_value
			}
			add = -1000
		}
	}
}

#IRRITABLE DUELING
force_duel_anyone_interaction = {
	#need to have a stress level >= 1
	interface_priority = 30
	common_interaction = yes
	category = interaction_category_hostile
	ai_maybe = yes
	ai_max_reply_days = 0
	popup_on_receive = yes
	pause_on_receive = yes
	desc = force_duel_anyone_interaction_desc
	icon = irritable

	greeting = negative
	notification_text = REQUEST_TRIAL_BY_COMBAT_TEXT

	is_shown = {
		#Just, verify if the actor is Wrathful
		scope:actor = { has_trait = irritable }
		# Can't duel yourself.
		NOT = { scope:actor = scope:recipient }
	}

	is_valid_showing_failures_only = {
		# Need to be stressed to be able to force a Duel
		scope:actor = {
			custom_description = {
				stress_level >= 1
				text = not_enough_stress
			}
		}
		# Calc some stuff that might invalidate elsewhere before the bout is sorted.
		rival_single_combat_shown_and_not_invalid_trigger = yes
		# Scope:recipient must be able to fight personally.
		scope:recipient = { can_start_single_combat_trigger = yes }
		# Scope:recipient must not be banned from single combat.
		scope:recipient = {
			custom_description = {
				text = fp1_tbc_recipient_banned_from_combat
				can_start_single_combat_banned_checks_trigger = no
			}
		}
		# 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 }
			}
		}
	}
	
	cost = { prestige = medium_prestige_value }
	cooldown_against_recipient = { years = 10 }

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

	on_accept = {
		# Set up the bout immediately.
		## First inform.
		scope:actor = {
			add_tyranny = 5
			add_dread = 5

			custom_tooltip = challenge_to_single_combat_interaction.victor_gets.tt
			custom_tooltip = challenge_to_single_combat_interaction.loser_gets.tt
		}
		## Finally, begin.
		configure_start_single_combat_effect = {
			SC_INITIATOR = scope:actor
			SC_ATTACKER = scope:actor
			SC_DEFENDER = scope:recipient
			FATALITY = no
			FIXED = no
			LOCALE = terrain_scope
			OUTPUT_EVENT = perk_interaction.0101
			INVALIDATION_EVENT = fp1_tbc.0102
		}

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

	auto_accept = yes

	# AI
	ai_potential = {
		has_trait = irritable
		stress_level >= 1
		is_imprisoned = no
		can_start_single_combat_trigger = yes
	}
	
	ai_target_quick_trigger = {
		adult = yes
	}

	ai_targets = {
		ai_recipients = prisoners
		ai_recipients = courtiers
		ai_recipients = guests
		max = 1
	}

	ai_targets = {
		ai_recipients = family
		max = 10
	}

	ai_targets = {
		ai_recipients = vassals
		max = 10
	}

	ai_frequency = 120

	ai_will_do = {
		base = -50
		
		# Factor for personality (excluding realism).
		modifier = {
			add = {
				value = ai_boldness
				multiply = 1
			}
		}
		modifier = { add = ai_vengefulness }
		modifier = {
			add = {
				value = ai_energy
				multiply = -0.25
			}
		}
		# Don't challenge kinslayer-counting family, unless they're your nemesis.
		modifier = {
			scope:actor = {
				murdering_character_is_kinslaying_in_faith_trigger = {
					CHARACTER = scope:recipient
					FAITH = scope:actor.faith
				}
			}
			scope:recipient = {
				NOT = { has_relation_nemesis = scope:actor }
			}
			add = -1000
		}
		# Don't challenge your spouse, unless they're your nemesis.
		modifier = {
			scope:recipient = {
				is_spouse_of = scope:actor
				NOT = { has_relation_nemesis = scope:actor }
			}
			add = -1000
		}
		# Don't challenge people hopelessly out of your league unless you're really, really not seeing things clearly.
		modifier = {
			scope:actor = {
				prowess_diff = {
					target = scope:recipient
					value <= -15
				}
				ai_rationality >= high_negative_ai_value
			}
			add = -1000
		}
	}
	
}
