namespace = court_position

################################
# FLAVOR EVENTS
# 1001 - 8999
################################



#############################
# MURDER SAVE EVENTS
# 9001 - 9199
# by Linnéa Thimrén
#############################

###############
# SAVED BY FOOD TASTER

# FOR MURDERER: Saved from poisoned food by food taster
# by Linnéa Thimrén
court_position.9001 = {
	type = character_event
	window = scheme_failed_event
	title = court_position.9001.t
	desc = {
		desc = court_position.9001.desc
		triggered_desc = {
			trigger = { exists = local_var:food_taster_dies }
			desc = court_position.9001.food_taster_dies
		}
	}
	theme = murder_scheme
	left_portrait = {
		character = scope:owner
		triggered_animation = {
			trigger = { exists = scope:scheme_discovered }
			animation = fear
		}
		animation = stress
	}
	center_portrait = {
		character = scope:food_taster
		animation = poison
	}
	right_portrait = {
		character = scope:target
		triggered_animation = {
			trigger = { exists = scope:scheme_discovered }
			animation = rage
		}
		animation = paranoia
	}
	override_background = { reference = feast }
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}
	
	trigger = {
		scope:target = {
			employs_court_position = food_taster_court_position
			any_court_position_holder = {
				type = food_taster_court_position
				foodtaster_will_actually_do_job_trigger = yes
			}
		}
	}

	immediate = {
		scope:target = {
			random_court_position_holder = {
				type = food_taster_court_position
				limit = { is_physically_able = yes }
				save_scope_as = food_taster
			}
		}
		murder_failure_effect = yes
		hidden_effect = {
			random = {
				chance = 75
				set_local_variable = {
					name = food_taster_dies
					value = yes
				}
			}
		}
	}

	option = {
		name = murder_save.0001.a
		scope:scheme = { end_scheme = yes }
	}

	option = {
		name = murder_save.0001.b
		restart_murder_scheme_effect = yes
	}

	after = {
		# Fire the rest of the outcome.
		scope:target = { trigger_event = court_position.9002 }
		if = {
			limit = { exists = local_var:food_taster_dies }
			show_as_tooltip = {
				murder_interception_handle_extra_deaths_effect = {
					VICTIM = scope:food_taster
					REASON = death_poison
				}
			}
		}
	}
}

# FOR TARGET: Food taster dies to poison
court_position.9002 = {
	type = character_event
	window = scheme_conclusion_event_no_header
	title = court_position.9001.t
	desc = {
		desc = court_position.9002.desc
		triggered_desc = {
			trigger = { exists = local_var:food_taster_dies }
			desc = court_position.9002.food_taster_dies
		}
		triggered_desc = {
			trigger = { exists = scope:scheme_discovered }
			desc = court_position.9002.owner_discovered
		}
	}
	theme = murder_scheme
	left_portrait = {
		character = scope:target
		triggered_animation = {
			trigger = { exists = scope:scheme_discovered }
			animation = rage
		}
		animation = paranoia
	}
	center_portrait = {
		character = scope:food_taster
		animation = poison
	}
	right_portrait = {
		character = scope:owner_to_reveal
		triggered_animation = {
			trigger = { exists = scope:scheme_discovered }
			animation = fear
		}
		animation = stress
	}

	immediate = {
		set_variable = {
			name = block_death_event_from
			value = scope:food_taster
			days = 3
		}
		# Handle the death of the food taster, if necessary
		if = {
			limit = { exists = local_var:food_taster_dies }
			murder_interception_handle_extra_deaths_effect = {
				VICTIM = scope:food_taster
				REASON = death_poison
			}
		}
	}

	# Who could do such a thing?
	option = {
		name = murder_save.1001.a
		trigger = {
			NOT = { exists = scope:scheme_discovered }
		}
		custom_tooltip = murder_save.failure_unknown_owner_tt
	}

	# Vengeance!
	option = {
		name = murder_save.1001.b
		trigger = { exists = scope:scheme_discovered }
		custom_tooltip = murder_save.failure_known_owner_tt
	}

	after = {
		add_character_modifier = {
			modifier = watchful_modifier
			days = watchful_modifier_duration
		}
	}
}


###############
# SAVED BY CUP-BEARER

# FOR MURDERER: Saved from poisoned drink by cup-bearer
# by Linnéa Thimrén
court_position.9011 = {
	type = character_event
	window = scheme_failed_event
	title = court_position.9011.t
	desc = {
		desc = court_position.9011.desc
		triggered_desc = {
			trigger = { exists = local_var:cupbearer_dies }
			desc = court_position.9011.cupbearer_dies
		}
	}
	theme = murder_scheme
	left_portrait = {
		character = scope:owner
		triggered_animation = {
			trigger = { exists = scope:scheme_discovered }
			animation = fear
		}
		animation = stress
	}
	center_portrait = {
		character = scope:food_taster
		animation = poison
	}
	right_portrait = {
		character = scope:target
		triggered_animation = {
			trigger = { exists = scope:scheme_discovered }
			animation = rage
		}
		animation = paranoia
	}
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}
	
	trigger = {
		scope:target = {
			employs_court_position = cupbearer_court_position
			any_court_position_holder = {
				type = cupbearer_court_position
				cupbearer_will_actually_do_job_trigger = yes
			}
		}
	}

	immediate = {
		scope:target = {
			random_court_position_holder = {
				type = cupbearer_court_position
				limit = { is_physically_able = yes }
				save_scope_as = cupbearer
			}
		}
		murder_failure_effect = yes
		hidden_effect = {
			random = {
				chance = 75
				set_local_variable = {
					name = cupbearer_dies
					value = yes
				}
			}
		}
	}

	option = {
		name = murder_save.0001.a
		scope:scheme = { end_scheme = yes }
	}

	option = {
		name = murder_save.0001.b
		restart_murder_scheme_effect = yes
	}

	after = {
		# Fire the rest of the outcome.
		scope:target = { trigger_event = court_position.9012 }
		if = {
			limit = { exists = local_var:cupbearer_dies }
			show_as_tooltip = {
				murder_interception_handle_extra_deaths_effect = {
					VICTIM = scope:cupbearer
					REASON = death_poison
				}
			}
		}
	}
}


# FOR TARGET: Cup-bearer dies to poison
court_position.9012 = {
	type = character_event
	window = scheme_conclusion_event_no_header
	title = court_position.9011.t
	desc = {
		desc = court_position.9012.desc
		triggered_desc = {
			trigger = { exists = local_var:cupbearer_dies }
			desc = court_position.9012.cupbearer_dies
		}
		triggered_desc = {
			trigger = { exists = scope:scheme_discovered }
			desc = court_position.9002.owner_discovered
		}
	}
	theme = murder_scheme
	left_portrait = {
		character = scope:target
		triggered_animation = {
			trigger = { exists = scope:scheme_discovered }
			animation = rage
		}
		animation = paranoia
	}
	center_portrait = {
		character = scope:food_taster
		animation = poison
	}
	right_portrait = {
		character = scope:owner_to_reveal
		triggered_animation = {
			trigger = { exists = scope:scheme_discovered }
			animation = fear
		}
		animation = stress
	}

	immediate = {
		set_variable = {
			name = block_death_event_from
			value = scope:cupbearer
			days = 3
		}
		# Handle the death of the cupbearer, if necessary
		if = {
			limit = { exists = local_var:cupbearer_dies }
			murder_interception_handle_extra_deaths_effect = {
				VICTIM = scope:cupbearer
				REASON = death_poison
			}
		}
	}

	# Who could do such a thing?
	option = {
		name = murder_save.1001.a
		trigger = {
			NOT = { exists = scope:scheme_discovered }
		}
		custom_tooltip = murder_save.failure_unknown_owner_tt
	}

	# Vengeance!
	option = {
		name = murder_save.1001.b
		trigger = { exists = scope:scheme_discovered }
		custom_tooltip = murder_save.failure_known_owner_tt
	}

	after = {
		add_character_modifier = {
			modifier = watchful_modifier
			days = watchful_modifier_duration
		}
	}
}


###############
# SAVED BY BODYGUARD

# FOR MURDERER: Saved from assassin by bodyguard
# by Linnéa Thimrén
court_position.9021 = {
	type = character_event
	window = scheme_failed_event
	title = court_position.9021.t
	desc = {
		desc = court_position.9021.desc
		triggered_desc = {
			trigger = { exists = local_var:bodyguard_dies }
			desc = court_position.9021.bodyguard_dies
		}
	}
	theme = murder_scheme
	left_portrait = {
		character = scope:owner
		triggered_animation = {
			trigger = { exists = scope:scheme_discovered }
			animation = fear
		}
		animation = stress
	}
	center_portrait = {
		character = scope:bodyguard
		triggered_animation = {
			trigger = { is_alive = no }
			animation = map_fear
		}
		animation = random_weapon_aggressive
		camera = camera_event_center_pointing_left
	}
	right_portrait = {
		character = scope:target
		triggered_animation = {
			trigger = { exists = scope:scheme_discovered }
			animation = rage
		}
		animation = paranoia
	}
	widget = {
		gui = "event_window_widget_scheme"
		container = "custom_widgets_container"
	}
	
	trigger = {
		scope:target = {
			employs_court_position = bodyguard_court_position
			any_court_position_holder = {
				type = bodyguard_court_position
				bodyguard_will_actually_do_job_trigger = yes
			}
		}
	}

	immediate = {
		scope:target = {
			random_court_position_holder = {
				type = bodyguard_court_position
				limit = { is_physically_able = yes }
				save_scope_as = bodyguard
			}
		}
		murder_failure_effect = yes
		hidden_effect = {
			random = {
				chance = 75
				set_local_variable = {
					name = bodyguard_dies
					value = yes
				}
			}
		}
	}

	option = {
		name = murder_save.0001.a
		scope:scheme = { end_scheme = yes }
	}

	option = {
		name = murder_save.0001.b
		restart_murder_scheme_effect = yes
	}

	after = {
		# Fire the rest of the outcome.
		scope:target = { trigger_event = court_position.9022 }
		if = {
			limit = { exists = local_var:bodyguard_dies }
			show_as_tooltip = {
				murder_interception_handle_extra_deaths_effect = {
					VICTIM = scope:bodyguard
					REASON = death_murder
				}
			}
		}
	}
}

# FOR TARGET: Bodyguard dies to assassin
court_position.9022 = {
	type = character_event
	window = scheme_conclusion_event_no_header
	title = court_position.9021.t
	desc = {
		desc = court_position.9022.desc
		triggered_desc = {
			trigger = { exists = local_var:bodyguard_dies }
			desc = court_position.9022.bodyguard_dies
		}
		triggered_desc = {
			trigger = { exists = scope:scheme_discovered }
			desc = court_position.9002.owner_discovered
		}
	}
	theme = murder_scheme
	left_portrait = {
		character = scope:target
		triggered_animation = {
			trigger = { exists = scope:scheme_discovered }
			animation = rage
		}
		animation = paranoia
	}
	center_portrait = {
		character = scope:bodyguard
		triggered_animation = {
			trigger = { is_alive = no }
			animation = map_fear
		}
		animation = random_weapon_aggressive
	}
	right_portrait = {
		character = scope:owner_to_reveal
		triggered_animation = {
			trigger = { exists = scope:scheme_discovered }
			animation = fear
		}
		animation = stress
	}

	immediate = {
		set_variable = {
			name = block_death_event_from
			value = scope:bodyguard
			days = 3
		}
		# Handle the death of the bodyguard, if necessary
		if = {
			limit = { exists = local_var:bodyguard_dies }
			murder_interception_handle_extra_deaths_effect = {
				VICTIM = scope:bodyguard
				REASON = death_murder
			}
		}
	}

	# Who could do such a thing?
	option = {
		name = murder_save.1001.a
		trigger = {
			NOT = { exists = scope:scheme_discovered }
		}
		custom_tooltip = murder_save.failure_unknown_owner_tt
	}

	# Vengeance!
	option = {
		name = murder_save.1001.b
		trigger = { exists = scope:scheme_discovered }
		custom_tooltip = murder_save.failure_known_owner_tt
	}

	after = {
		add_character_modifier = {
			modifier = watchful_modifier
			days = watchful_modifier_duration
		}
	}
}
