﻿#Events notifying about prison status changes

namespace = prison_notification

#I have been imprisoned!
prison_notification.0001 = {
	type = character_event
	title = prison_notification.0001.t
	desc = prison_notification.0001.desc
	theme = prison
	left_portrait = {
		character = scope:prisoner
		triggered_animation = {
			trigger = { is_in_prison_type = house_arrest }
			animation = prisonhouse
		}
		triggered_animation = {
			trigger = { is_in_prison_type = dungeon }
			animation = prisondungeon
		}
		override_imprisonment_visuals = yes
	}
	right_portrait = {
		character = scope:imprisoner
		animation = war_over_win
	}
	override_background = {
		trigger = {
			is_in_prison_type = house_arrest
			scope:bg_override_char = { is_landless_adventurer = no }
		}
		reference = relaxing_room
	}

	trigger = {
		NOT = {
			has_character_flag = was_abducted_block_notification_event
		}
	}

	on_trigger_fail = {
		if = {
			limit = {
				has_character_flag = was_abducted_block_notification_event
			}
			remove_character_flag = was_abducted_block_notification_event
		}
	}

	immediate = {
		play_music_cue = "mx_cue_prison"
		save_scope_as = prisoner
		imprisoner = {
			save_scope_as = imprisoner
			save_scope_as = bg_override_char
		}
		# Figure out who needs to be notified about this character being imprisoned.
		every_player = {
			save_scope_as = this_player
			if = { # If prisoner is a player's heir or spouse, send them a full pop-up event.
				limit = {
					OR = {
						player_heir ?= scope:prisoner
						primary_heir ?= scope:prisoner
						is_consort_of = scope:prisoner
					}
				}
				trigger_event = prison_notification.0002
			}
			else_if = { # Otherwise, if they are of interest to a player, send the player a notification
				limit = {
					scope:prisoner = {
						has_any_relation_trigger = { CHARACTER = scope:this_player }
					}
				}
				trigger_event = prison_notification.0003
			}
		}
		show_as_tooltip = {
			scope:imprisoner = {
				imprison = {
					target = root
					type = dungeon
				}
			}
			if = {
				limit = { is_in_prison_type = house_arrest }
				change_prison_type = house_arrest
			}
			else = { change_prison_type = dungeon }
		}
	}
	
	option = {
		name = prison_notification.0001.a
	}
}

#My significant relation has been imprisoned!
prison_notification.0002 = {
	type = character_event
	title = prison_notification.0002.t
	desc = prison_notification.0002.desc
	theme = prison
	left_portrait = {
		character = scope:prisoner
		triggered_animation = {
			trigger = { is_in_prison_type = house_arrest }
			animation = prisonhouse
		}
		triggered_animation = {
			trigger = { is_in_prison_type = dungeon }
			animation = prisondungeon
		}
		override_imprisonment_visuals = yes
	}
	right_portrait = {
		character = scope:imprisoner
		animation = war_over_win
	}
	override_background = {
		trigger = {
			scope:prisoner = { is_in_prison_type = house_arrest }
			scope:bg_override_char = { is_landless_adventurer = no }
		}
		reference = relaxing_room
	}

	trigger = {
		scope:imprisoner != root
		NOT = { scope:prisoner = { has_character_flag = block_imprisonment_event } }
		NOT = { scope:prisoner = { has_character_flag = bp1_yearly_2020_block_imprisonment_event } }
	}

	on_trigger_fail = {
		if = {
			limit = {
				has_character_flag = bp1_yearly_2020_block_imprisonment_event
			}
			remove_character_flag = bp1_yearly_2020_block_imprisonment_event
		}
	}
	
	immediate = {
		show_as_tooltip = {
			scope:imprisoner = {
				imprison = {
					target = scope:prisoner
					type = dungeon
				}
			}
			scope:prisoner = {
				if = {
					limit = { is_in_prison_type = house_arrest }
					change_prison_type = house_arrest
				}
				else = { change_prison_type = dungeon }
			}
		}
	}

	option = {
		name = prison_notification.0002.a
	}
}

#My less-significant relation has been imprisoned!
prison_notification.0003 = {
	hidden = yes

	trigger = {
		scope:imprisoner != root
		NOT = { scope:prisoner = { has_character_flag = block_imprisonment_event } }
	}

	immediate = {
		send_interface_message = {
			type = event_prison_neutral
			title = prison_notification.0003.message
			
			left_icon = scope:prisoner
			right_icon = scope:imprisoner

			show_as_tooltip = {
				scope:imprisoner = {
					imprison = {
						target = scope:prisoner
						type = dungeon
					}
				}
				scope:prisoner = {
					if = {
						limit = { is_in_prison_type = house_arrest }
						change_prison_type = house_arrest
					}
					else = { change_prison_type = dungeon }
				}
			}
		}
	}
}

#I have been moved to the dungeon!
prison_notification.1001 = {
	type = character_event
	title = prison_notification.1001.t
	desc = prison_notification.1001.desc
	theme = prison
	left_portrait = {
		character = root
		animation = prisondungeon
		override_imprisonment_visuals = yes
	}
	right_portrait = {
		character = scope:bg_override_char
		animation = schadenfreude
	}

	immediate = {
		imprisoner = { save_scope_as = bg_override_char }
		show_as_tooltip = {
			change_prison_type = dungeon
		}
	}
	
	option = {
		name = prison_notification.1001.a
		custom_tooltip = prison_notification.1001.a.tt
	}
}

#I have been moved to house arrest!
prison_notification.1002 = {
	type = character_event
	title = prison_notification.1002.t
	desc = prison_notification.1002.desc
	theme = prison
	left_portrait = {
		character = root
		animation = prisonhouse
		override_imprisonment_visuals = yes
	}
	right_portrait = {
		character = scope:bg_override_char
		animation = schadenfreude
	}
	override_background = {
		trigger = {
			scope:bg_override_char = { is_landless_adventurer = no }
		}
		reference = relaxing_room
	}

	immediate = {
		imprisoner = { save_scope_as = bg_override_char }
		show_as_tooltip = {
			change_prison_type = house_arrest
		}
	}
	
	option = {
		name = prison_notification.1002.a
		custom_tooltip = prison_notification.1002.a.tt
	}
}


#I have been released!
prison_notification.2001 = {
	type = character_event
	title = prison_notification.2001.t
	desc = prison_notification.2001.desc
	theme = prison
	override_background = {
		reference = sitting_room
	}
	left_portrait = {
		character = root
		animation = happiness
	}
	lower_right_portrait = scope:imprisoner
	override_background = {
		trigger = {
			scope:bg_override_char = { is_landless_adventurer = no }
		}
		reference = relaxing_room
	}

	trigger = { NOT = { has_character_flag = block_for_prison_release_notification } }

	immediate = {
		save_scope_as = prisoner
		scope:imprisoner = { save_scope_as = bg_override_char }
		# Figure out who needs to be notified about this character being released.
		every_player = {
			save_scope_as = this_player
			
			if = { # If prisoner is a player's heir or spouse, send them a full pop-up event.
				limit = {
					OR = {
						player_heir ?= scope:prisoner
						primary_heir ?= scope:prisoner
						is_consort_of = scope:prisoner
					}
				}
				trigger_event = prison_notification.2002
			}
			else_if = { # Otherwise, if they are of interest to a player, send the player a notification
				limit = {
					scope:prisoner = {
						has_any_relation_trigger = { CHARACTER = scope:this_player }
					}
				}
				trigger_event = prison_notification.2003
			}
		}
		show_as_tooltip = { release_from_prison = yes }
	}
	
	option = {
		name = prison_notification.2001.a
	}
}

#My significant relation has been released!
prison_notification.2002 = {
	type = character_event
	title = prison_notification.2002.t
	desc = prison_notification.2002.desc
	theme = prison
	override_background = {
		reference = sitting_room
	}
	left_portrait = {
		character = scope:prisoner
		animation = happiness
	}
	lower_right_portrait = scope:imprisoner
	override_background = {
		trigger = {
			scope:bg_override_char = { is_landless_adventurer = no }
		}
		reference = relaxing_room
	}

	trigger = {
		scope:imprisoner != root
		NOT = { scope:prisoner = { has_character_flag = block_release_from_prison_event } }
		scope:prisoner = {
			is_alive = yes
		}
	}
	
	immediate = {
		scope:imprisoner = { save_scope_as = bg_override_char }
		show_as_tooltip = {
			scope:prisoner = {
				release_from_prison = yes
			}
		}	
	}

	option = {
		name = prison_notification.2002.a
	}
}

#My less-significant relation has been released!
prison_notification.2003 = {
	hidden = yes

	trigger = {
		scope:imprisoner != root
		NOT = { scope:prisoner = { has_character_flag = block_release_from_prison_event } }
		scope:prisoner = {
			is_alive = yes
		}
	}

	immediate = {
		send_interface_message = {
			type = event_prison_neutral
			title = prison_notification.2003.message
			
			left_icon = scope:prisoner
			right_icon = scope:imprisoner

			show_as_tooltip = {
				scope:prisoner = {
					release_from_prison = yes
				}
			}
		}
	}
}
