###########################################
#
# Plot Events
#
# ID 9000-9499 is reserved
#
###########################################
#
# Written by Niklas Strid


###########################################
# Blackmail attempt 9000-9025

# Master of the guard finds out about a neighbouring clan's plot
# Plot: Gain title
character_event = {
	id = 9000
	desc = "EVTDESC9000"
	
	trigger = {
		is_ruler = yes
		any_independent_neighbor = {
			has_objective = plot_attack_title
			NOT = { any_plot_backer = { character = ROOT } }
			ROOT = { NOT = { is_plot_target_of = PREV } }
			ROOT = { NOT = { opinion = { who = PREV value = 0 } } }
		}
		any_courtier = { has_job_title = master_of_the_guard }
	}
	
	mean_time_to_happen = {
		months = 240
		
		modifier = {
			factor = 0.9
			any_courtier = {
				has_job_title = master_of_the_guard
				intrigue = 7
			}
		}
		modifier = {
			factor = 0.9
			any_courtier = {
				has_job_title = master_of_the_guard
				intrigue = 8
			}
		}
		modifier = {
			factor = 0.9
			any_courtier = {
				has_job_title = master_of_the_guard
				intrigue = 9
			}
		}
		modifier = {
			factor = 0.9
			any_courtier = {
				has_job_title = master_of_the_guard
				intrigue = 10
			}
		}
	}
	
	option = {
		name = "EVTOPTA9000"
		ai_chance = {
			factor = 50
			modifier = {
				factor = 2
				OR = {
					trait = amateurish_plotter
					trait = flamboyant_schemer
					trait = intricate_webweaver
					trait = elusive_shadow
				}
			}
		}
		random_independent_neighbor = {
			limit = {
				has_objective = plot_attack_title
				NOT = { any_plot_backer = { character = ROOT } }
				ROOT = { NOT = { is_plot_target_of = PREV } }
				ROOT = { NOT = { opinion = { who = PREV value = 0 } } }
			}
			ROOT = {
				PREV = {
					letter_event = {
						id = 9015
						days = 3
						tooltip = "PREVLETTERTOOLTIP"
					}
				}
			}
		}
		hidden_tooltip = {
			add_character_modifier = {
				name = blackmail_timer
				duration = 365
				hidden = yes
			}
		}
	}
	option = {
		name = "EVTOPTB9000"
		ai_chance = {
			factor = 50
			modifier = {
				factor = 0.1
				trait = content
			}
		}
		hidden_tooltip = {
			add_character_modifier = {
				name = blackmail_timer
				duration = 180
				hidden = yes
			}
		}
	}
}


# Master of the guard finds out about a neighbouring clan's plot
# Plot: Break free of clan
character_event = {
	id = 9005
	desc = "EVTDESC9005"	
	
	trigger = {
		is_ruler = yes
		any_neighbor = {
			independent = no
			has_objective = plot_form_clan
			NOT = { any_plot_backer = { character = ROOT } }
			ROOT = { NOT = { is_plot_target_of = PREV } }
			ROOT = { NOT = { opinion = { who = PREV value = 0 } } }
		}
		any_courtier = { has_job_title = master_of_the_guard }
	}
	
	mean_time_to_happen = {
		months = 240
		
		modifier = {
			factor = 0.9
			any_courtier = {
				has_job_title = master_of_the_guard
				intrigue = 7
			}
		}
		modifier = {
			factor = 0.9
			any_courtier = {
				has_job_title = master_of_the_guard
				intrigue = 8
			}
		}
		modifier = {
			factor = 0.9
			any_courtier = {
				has_job_title = master_of_the_guard
				intrigue = 9
			}
		}
		modifier = {
			factor = 0.9
			any_courtier = {
				has_job_title = master_of_the_guard
				intrigue = 10
			}
		}
	}
	
	option = {
		name = "EVTOPTA9005"
		ai_chance = {
			factor = 50
			modifier = {
				factor = 2
				OR = {
					trait = amateurish_plotter
					trait = flamboyant_schemer
					trait = intricate_webweaver
					trait = elusive_shadow
				}
			}
		}
		random_neighbor = {
			limit = {
				independent = no
				has_objective = plot_form_clan
				NOT = { any_plot_backer = { character = ROOT } }
				ROOT = { NOT = { is_plot_target_of = PREV } }
				ROOT = { NOT = { opinion = { who = PREV value = 0 } } }
			}
			ROOT = {
				PREV = {
					letter_event = {
						id = 9015
						days = 3
						tooltip = "PREVLETTERTOOLTIP"
					}
				}
			}
		}
		hidden_tooltip = {
			add_character_modifier = {
				name = blackmail_timer
				duration = 365
				hidden = yes
			}
		}
	}
	option = {
		name = "EVTOPTB9005"
		ai_chance = {
			factor = 50
			modifier = {
				factor = 0.1
				trait = content
			}
		}
		hidden_tooltip = {
			add_character_modifier = {
				name = blackmail_timer
				duration = 180
				hidden = yes
			}
		}
	}
}


# Master of the guard finds out about a neighbouring clan's plot
# Plot: Usurp clan leadership
character_event = {
	id = 9010
	desc = "EVTDESC9010"
	
	trigger = {
		is_ruler = yes
		any_neighbor = {
			independent = no
			has_objective = plot_take_over_clan
			NOT = { any_plot_backer = { character = ROOT } }
			ROOT = { NOT = { is_plot_target_of = PREV } }
			ROOT = { NOT = { opinion = { who = PREV value = 0 } } }
		}
		any_courtier = { has_job_title = master_of_the_guard }
	}
	
	mean_time_to_happen = {
		months = 240
		
		modifier = {
			factor = 0.9
			any_courtier = {
				has_job_title = master_of_the_guard
				intrigue = 7
			}
		}
		modifier = {
			factor = 0.9
			any_courtier = {
				has_job_title = master_of_the_guard
				intrigue = 8
			}
		}
		modifier = {
			factor = 0.9
			any_courtier = {
				has_job_title = master_of_the_guard
				intrigue = 9
			}
		}
		modifier = {
			factor = 0.9
			any_courtier = {
				has_job_title = master_of_the_guard
				intrigue = 10
			}
		}
	}
	
	option = {
		name = "EVTOPTA9010"
		ai_chance = {
			factor = 50
			modifier = {
				factor = 2
				OR = {
					trait = amateurish_plotter
					trait = flamboyant_schemer
					trait = intricate_webweaver
					trait = elusive_shadow
				}
			}
		}
		random_neighbor = {
			limit = {
				independent = no
				has_objective = plot_take_over_clan
				NOT = { any_plot_backer = { character = ROOT } }
				ROOT = { NOT = { is_plot_target_of = PREV } }
				ROOT = { NOT = { opinion = { who = PREV value = 0 } } }
			}
			ROOT = {
				PREV = {
					letter_event = {
						id = 9015
						days = 3
						tooltip = "PREVLETTERTOOLTIP"
					}
				}
			}
		}
		hidden_tooltip = {
			add_character_modifier = {
				name = blackmail_timer
				duration = 365
				hidden = yes
			}
		}
	}
	option = {
		name = "EVTOPTB9010"
		ai_chance = { 
			factor = 50
			modifier = {
				factor = 0.1
				trait = content
			}
		}
		hidden_tooltip = {
			add_character_modifier = {
				name = blackmail_timer
				duration = 180
				hidden = yes
			}
		}
	}
}


# Plotter answers to blackmail attempt
letter_event = {
	id = 9015
	desc = "EVTDESC9015"
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA9015"
		ai_chance = { 
			factor = 25
			modifier = {
				factor = 1.25
				OR = {
					trait = proud
					trait = wroth
				}
			}
		}
		reveal_plot = yes
		FROM = {
			letter_event = {
				id = 9020
				days = 3
				tooltip = "FROMLETTERTOOLTIP"
			}
		}
	}
	option = {
		name = "EVTOPTB9015"
		ai_chance = { factor = 75	}
		wealth = -50
		FROM = {
			letter_event = {
				id = 9025
				days = 3
				tooltip = "FROMLETTERTOOLTIP"
			}
		}
	}
}


# Plotter's answer: refused to pay
letter_event = {
	id = 9020
	desc = "EVTDESC9020"
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA9020"
		honor = -5
	}
}


# Plotter's answer: decided to pay
letter_event = {
	id = 9025
	desc = "EVTDESC9025"
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA9025"
		wealth = 50
	}
}


###########################################
# Warned about plot 9050-9065

# Courtier warns sibling about plot
# Plot: Gain title
character_event = {
	id = 9050
	desc = "EVTDESC9050"
	
	trigger = {
		is_landed = no
		liege = {
			has_objective = plot_attack_title
			NOT = { any_plot_backer = { character = ROOT } }
			plot_target_char = {
				any_sibling = {
					character = ROOT
					opinion = { who = PREV value = 0 }
				}
			}
		}
	}
	
	mean_time_to_happen = {
		months = 240
	}
	
	option = {
		name = "EVTOPTA9050"
		ai_chance = { factor = 100 }
		liege = {
			plot_target_char = {
				letter_event = {
					id = 9055
					days = 1
				}
			}
		}
		add_character_modifier = {
			name = plot_whistle_blower
			duration = 180
			hidden = yes
		}
	}
	option = {
		name = "EVTOPTB9050"
		ai_chance = { factor = 0 }
	}
}


# Letter arrives from sibling
letter_event = {
	id = 9055
	desc = "EVTDESC9055"
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA9055"
		FROM = {
			liege = { reveal_plot = yes }
			hidden_tooltip = {
				random = {
					25 = {
						liege = {
							letter_event = {
								id = 9070
								days = 10
							}
						}
					}
				}
			}
		}
	}
}


# Courtier warns child about plot
# Plot: Gain title
character_event = {
	id = 9060
	desc = "EVTDESC9060"
	
	trigger = {
		is_ruler = no
		liege = {
			has_objective = plot_attack_title
			NOT = { any_plot_backer = { character = ROOT } }
			plot_target_char = {
				OR = {
					is_father = ROOT
					is_mother = ROOT
				}
				ROOT  = { NOT = { opinion = { who = PREV value = 0 } } }
			}
		}
	}
	
	mean_time_to_happen = {
		months = 240
	}
	
	option = {
		name = "EVTOPTA9060"
		ai_chance = { factor = 100 }
		liege = {
			plot_target_char = {
				letter_event = {
					id = 9065
					days = 1
				}
			}
		}
		add_character_modifier = {
			name = plot_whistle_blower
			duration = 180
			hidden = yes
		}
	}
	option = {
		name = "EVTOPTB9060"
		ai_chance = { factor = 0 }
	}
}


# Letter arrives from mother/father
letter_event = {
	id = 9065
	desc = "EVTDESC9065"
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA9065"
		FROM = { 
			liege = { reveal_plot = yes }
			hidden_tooltip = {
				random = {
					25 = {
						liege = {
							letter_event = {
								id = 9070
								days = 10
							}
						}
					}
				}
			}
		}
	}
}


# The courtier's warning is exposed
character_event = {
	id = 9070
	desc = "EVTDESC9070"

	is_triggered_only = yes
	
	trigger = {
		has_objective = plot_attack_title
		any_courtier = {
			has_character_modifier = plot_whistle_blower
			NOT = { has_job_title = master_of_the_guard }
		}
		plot_target_char = {
			character = FROM
			OR = {
				any_sibling = {
					has_character_modifier = plot_whistle_blower
					liege = { character = ROOT }
				}
				father = {
					has_character_modifier = plot_whistle_blower
					liege = { character = ROOT }
				}
				mother = {
					has_character_modifier = plot_whistle_blower
					liege = { character = ROOT }
				}
			}
		}
		any_courtier = { has_job_title = master_of_the_guard }
	}
	
	option = {
		name = "EVTOPTA9070"
		ai_chance = {
			factor = 75
			modifier = {
				factor = 2
				OR = {
					trait = wroth
					trait = ruthless
					trait = paranoid
				}
			}
		}
		random_courtier = {
			limit = {
				has_character_modifier = plot_whistle_blower
				NOT = { has_job_title = master_of_the_guard }
			}
			hidden_tooltip = {
				random = {
					50 = {
						liege = { plot_target_char = { set_character_flag = warned_about_plot } }
						letter_event = {
							id = 9075
							days = 1
						}
					}
				}
			}
			death = yes
		}
	}
	option = {
		name = "EVTOPTB9070"
		ai_chance = {
			factor = 25
			modifier = {
				factor = 4
				OR = {
					trait = kind
					trait = bushi
					trait = just
				}
			}
		}
		honor = 5
	}
}


# A witness to the murder...
character_event = {
	id = 9075
	desc = "EVTDESC9075"
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA9075"
		ai_chance = { factor = 100 }
		random_sibling = {
			limit = { has_character_flag = warned_about_plot }
			clr_character_flag = warned_about_plot
			letter_event = {
				id = 9080
				days = 10
			}
		}
		random_child = {
			limit = { has_character_flag = warned_about_plot }
			clr_character_flag = warned_about_plot
			letter_event = {
				id = 9080
				days = 10
			}
		}
		remove_character_modifier = plot_whistle_blower
	}
}


# An anonymous letter arrives...
letter_event = {
	id = 9080
	desc = "EVTDESC9080"
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA9080"
	}
}


###########################################
# Plot exposed: 9100-9150

# Plotter informed
character_event = {
	id = 9100
	desc = "EVTDESC9100"
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA9100"
		honor = -10
		hidden_tooltip = {
			any_plot_backer = {
				letter_event = { id = 9110 }
			}
		}
	}
}

# Backers informed
letter_event = {
	id = 9110
	desc = "EVTDESC9110"
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA9110"
		honor = -5
	}
}
