﻿blackmail_interaction = {
	category = interaction_category_hostile
	common_interaction = yes
	interface = blackmail
	popup_on_receive = yes
	icon = secret

	ai_maybe = yes

	desc = blackmail_interaction_desc

	on_decline_summary = blackmail_decline_summary

	is_shown = {
		scope:recipient = {
			NOT = { this = scope:actor }
			age > 10
		}
		scope:recipient = {
			any_secret = {
				is_known_by = scope:actor
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:recipient = {
			is_busy_in_events_localised = yes
		}
		#Not at war with them
		NOT = {
			scope:actor = { is_at_war_with = scope:recipient }
		}
		#Already have a strong hook
		custom_description = {
			text = "already_strong_hook"
			subject = scope:actor
			object = scope:recipient
			NOT = { 
				scope:actor = { has_strong_hook = scope:recipient } 
			}
		}
		#No appropriate secret
		custom_description = {
			scope:recipient = {
				any_secret = {
					is_blackmailable_secret_trigger = { 
						BLACKMAILER = scope:actor 
						PARTICIPANT = scope:recipient 
					}
				}
			}
			text = "no_blackmailable_secret"
		}
	}

	is_highlighted = {
		scope:recipient = {
			any_secret = {
				is_known_by = scope:actor
				is_blackmailable_secret_trigger = { BLACKMAILER = scope:actor PARTICIPANT = scope:recipient }
			}
		}
		scope:actor = {
			NOR = {
				has_hook_of_type = {
					target = scope:recipient
					type = weak_blackmail_hook
				}
				has_hook_of_type = {
					target = scope:recipient
					type = strong_blackmail_hook
				}
			}
		}
	}

	has_valid_target_showing_failures_only = {
		exists = scope:target
		scope:target = {
			is_known_by = scope:actor
			is_blackmailable_secret_trigger = { BLACKMAILER = scope:actor PARTICIPANT = scope:recipient }
		}
	}


	can_send = {
		custom_description = { # Exploit prevention
			text = "has_sent_interaction_already"
			subject = scope:recipient
			scope:actor = {
				NOT = { exists = var:currently_blackmailing }
			}
		}
	}

	on_send = {
		hidden_effect = {
			# Block sending another interaction while rejection event is active
			scope:actor = {
				set_variable = {
					name = currently_blackmailing
					value = scope:recipient
					days = 30
				}
			}
			scope:target = {
				if = {
					limit = {
						exists = secret_target
					}
					secret_target = {
						save_scope_as = secret_target
					}
				}
				if = {
					limit = {
						secret_type = secret_disputed_heritage
					}
					secret_target.father = {
						save_scope_as = father
					}
					secret_target.real_father = {
						save_scope_as = real_father
					}
				}
				if = {
					limit = {
						scope:target = {
							secret_type = secret_disputed_heritage
						}
					}
					secret_target.father = {
						save_scope_as = father
					}
					secret_target.real_father = {
						save_scope_as = real_father
					}
				}
			}
		}
	}

	on_accept = {
		scope:actor = {
			remove_variable = currently_blackmailing
			play_music_cue = mx_cue_murder
		}
		blackmail_interaction_effect = yes #Adds strong or weak hook + opinion penalty

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

	on_decline = {
		#Return event about exposing the secret
		#AI will always expose
		if = {
			limit = {
				scope:actor = { is_ai = no }
			}
			scope:recipient = {
				custom_tooltip = BLACKMAIL_INTERACTION_HUMAN_TT
			}
		}
		show_as_tooltip = {
			if = {
				limit = { exists = scope:secret }
				scope:secret = {
					expose_secret = scope:actor
				}
			}
			if = {
				limit = { exists = scope:target }
				scope:target = {
					expose_secret = scope:actor
				}
			}
		}
		scope:actor = { trigger_event = blackmail.0001 }

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

	on_blocked_effect = {
		scope:actor = { remove_variable = currently_blackmailing }
	}

	ai_accept = {
		base = 0
		modifier = {
			add = 80
			desc = BLACKMAIL_INTERACTION_BASE_ACCEPTANCE
		}
		modifier = {
			add = -20
			scope:recipient = {
				has_trait = brave
			}
			desc = BLACKMAIL_INTERACTION_BRAVE_ACCEPTANCE
		}
		modifier = {
			add = -20
			scope:recipient = {
				has_trait = arrogant
			}
			desc = BLACKMAIL_INTERACTION_ARROGANT_ACCEPTANCE
		}
		modifier = {
			add = 10
			scope:recipient = {
				has_trait = craven
			}
			desc = BLACKMAIL_INTERACTION_CRAVEN_ACCEPTANCE
		}
		modifier = {
			add = 50
			scope:recipient = {
				has_trait = paranoid
			}
			desc = BLACKMAIL_INTERACTION_PARANOID_ACCEPTANCE
		}
		# Unity modifiers
		evaluate_action_decreasing_house_unity = {
			VALUE = 25
		}

		opinion_modifier = {
			trigger = {
				scope:recipient = {
					opinion = {
						target = scope:actor
						value < 0
					}
				}
			}
			opinion_target = scope:recipient
			who = scope:actor
			multiplier = 0.3
			desc = BLACKMAIL_INTERACTION_OPINION_ACCEPTANCE
		}
		modifier = {
			add = -20
			scope:recipient = {
				has_opinion_modifier = {
					target = scope:actor
					modifier = trust_opinion
					value < 0
				}
			}
			desc = BLACKMAIL_INTERACTION_DISTRUST_ACCEPTANCE
		}
		modifier = {
			add = 30
			any_secret = {
				is_known_by = scope:actor
				is_criminal_for = scope:recipient
			}
			desc = BLACKMAIL_MAJOR_SECRET_ACCEPTANCE
		}
		
		
		modifier = {
			add = intimidated_reason_value
			scope:recipient = {
				has_dread_level_towards = {
					target = scope:actor
					level = 1
				}
			}
			desc = INTIMIDATED_REASON
		}
		modifier = {
			add = cowed_reason_value
			scope:recipient = {
				has_dread_level_towards = {
					target = scope:actor
					level = 2
				}
			}
			desc = COWED_REASON
		}
	}

	ai_min_reply_days = 1
	ai_max_reply_days = 5

	notification_text = {
		triggered_desc = {
			trigger = {
				scope:actor = {
					opinion = {
						target = scope:recipient
						value > 0	
					}
				}
			}
			desc = BLACKMAIL_NOTIFICATION_OPENING
		}
		first_valid = {
			triggered_desc = {
				trigger = { scope:target = { secret_type = secret_deviant } }
				desc = BLACKMAIL_NOTIFICATION_SECRET_DEVIANT
			}
			triggered_desc = {
				trigger = { scope:target = { secret_type = secret_homosexual } }
				desc = BLACKMAIL_NOTIFICATION_SECRET_HOMOSEXUAL
			}
			triggered_desc = {
				trigger = { scope:target = { secret_type = secret_murder } }
				desc = BLACKMAIL_NOTIFICATION_SECRET_MURDER
			}
			triggered_desc = {
				trigger = { scope:target = { secret_type = secret_murder_attempt } }
				desc = BLACKMAIL_NOTIFICATION_SECRET_MURDER_ATTEMPT
			}
			triggered_desc = {
				trigger = { scope:target = { secret_type = secret_cannibal } }
				desc = BLACKMAIL_NOTIFICATION_SECRET_CANNIBAL
			}
			triggered_desc = {
				trigger = { scope:target = { secret_type = secret_lover } }
				desc = BLACKMAIL_NOTIFICATION_SECRET_LOVER
			}
			triggered_desc = {
				trigger = { scope:target = { secret_type = secret_non_believer } }
				desc = BLACKMAIL_NOTIFICATION_SECRET_NON_BELIEVER
			}
			triggered_desc = {
				trigger = { scope:target = { secret_type = secret_incest } }
				desc = BLACKMAIL_NOTIFICATION_SECRET_INCEST
			}
			triggered_desc = {
				trigger = { scope:target = { secret_type = secret_witch } }
				desc = BLACKMAIL_NOTIFICATION_SECRET_WITCH
			}
			triggered_desc = {
				trigger = { scope:target = { secret_type = secret_crypto_religionist } }
				desc = BLACKMAIL_NOTIFICATION_SECRET_CRYPTO_RELIGIONIST
			}
			triggered_desc = {
				trigger = {
					scope:target = {
						secret_type = secret_disputed_heritage
						secret_target.real_father = scope:actor
						secret_target.mother = scope:recipient
					}
				}
				desc = BLACKMAIL_NOTIFICATION_SECRET_ILLEGITIMATE_CHILD_ACTOR
			}
			triggered_desc = {
				trigger = {
					scope:target = {
						secret_type = secret_disputed_heritage
						secret_target.mother = scope:recipient
					}
				}
				desc = BLACKMAIL_NOTIFICATION_SECRET_ILLEGITIMATE_CHILD_OTHER
			}
			triggered_desc = {
				trigger = {
					scope:target = {
						secret_type = secret_disputed_heritage
						secret_target.real_father = scope:actor
						secret_target = {
							OR = {
								this = scope:recipient
								is_twin_of = scope:recipient
							}
						}
					}
				}
				desc = BLACKMAIL_NOTIFICATION_SECRET_ILLEGITIMATE_CHILD_TARGET_ACTOR
			}
			triggered_desc = {
				trigger = {
					scope:target = {
						secret_type = secret_disputed_heritage
						secret_target = {
							OR = {
								this = scope:recipient
								is_twin_of = scope:recipient
							}
						}
					}
				}
				desc = BLACKMAIL_NOTIFICATION_SECRET_ILLEGITIMATE_CHILD_TARGET_OTHER
			}
			triggered_desc = {
				trigger = {
					scope:target = {
						secret_type = secret_unmarried_illegitimate_child
						secret_target.real_father = scope:actor
						secret_target.mother = scope:recipient
					}
				}
				desc = BLACKMAIL_NOTIFICATION_SECRET_UNMARRIED_ILLEGITIMATE_CHILD_ACTOR
			}
			triggered_desc = {
				trigger = {
					scope:target = {
						secret_type = secret_unmarried_illegitimate_child
						secret_target.mother = scope:recipient
					}
				}
				desc = BLACKMAIL_NOTIFICATION_SECRET_UNMARRIED_ILLEGITIMATE_CHILD_OTHER
			}
			triggered_desc = {
				trigger = {
					scope:target = {
						secret_type = secret_unmarried_illegitimate_child
						secret_target.real_father = scope:actor
						secret_target = {
							OR = {
								this = scope:recipient
								is_twin_of = scope:recipient
							}
						}
					}
				}
				desc = BLACKMAIL_NOTIFICATION_SECRET_UNMARRIED_ILLEGITIMATE_CHILD_TARGET_ACTOR
			}
			triggered_desc = {
				trigger = {
					scope:target = {
						secret_type = secret_unmarried_illegitimate_child
						secret_target = {
							OR = {
								this = scope:recipient
								is_twin_of = scope:recipient
							}
						}
					}
				}
				desc = BLACKMAIL_NOTIFICATION_SECRET_UNMARRIED_ILLEGITIMATE_CHILD_TARGET_OTHER
			}

			desc = BLACKMAIL_NOTIFICATION_SECRET_FALLBACK
		}
		desc = BLACKMAIL_NOTIFICATION_THREAT
	}
	
	# AI
	
	ai_targets = {
		ai_recipients = known_secrets
	}
	
	ai_target_quick_trigger = {
		adult = yes
	}
	
	ai_frequency = 6
	
	ai_will_do = {
		base = 100

		# Unity modifiers
		evaluate_action_decreasing_house_unity = {
			VALUE = 100
		}
		
		modifier = {
			factor = 0
			scope:actor.ai_honor >= 75
		}
		
		modifier = {
			factor = 0.1
			scope:actor.ai_honor >= 30
		}
		
		modifier = {
			factor = 0
			scope:actor.ai_honor >= -30
			scope:recipient = {
				has_relation_lover = scope:actor
			}
		}
		
		modifier = {
			factor = 0
			scope:recipient = {
				OR = {
					has_relation_friend = scope:actor
					has_relation_best_friend = scope:actor
					has_relation_soulmate = scope:actor
				}
			}
		}
	}

	ai_set_target = {
		scope:recipient = {
			random_secret = {
				limit = {
					is_known_by = scope:actor
					is_blackmailable_secret_trigger = { BLACKMAILER = scope:actor PARTICIPANT = scope:recipient }
				}
				save_scope_as = target
			}
		}
	}
}

