﻿#Used for all executions
execute_prisoner_effect = {

	$VICTIM$ = {
		save_scope_as = victim
	}

	$EXECUTIONER$ = {
		save_scope_as = executioner
	}

	show_as_tooltip = {
		$VICTIM$ = {
			if = { limit = { always = scope:execution_beheaded }
				death = {
					death_reason = death_execution_beheading
					killer = $EXECUTIONER$
				}
			}
			else_if = { limit = { always = scope:execution_hanged }
				death = {
					death_reason = death_execution_hanging
					killer = $EXECUTIONER$
				}
			}
			else_if = { limit = { always = scope:execution_burned }
				death = {
					death_reason = death_execution_burning
					killer = $EXECUTIONER$
				}
			}
			else_if = { limit = { always = scope:execution_drowned }
				death = {
					death_reason = death_execution_drowning
					killer = $EXECUTIONER$
				}
			}
			else_if = { limit = { always = scope:execution_flayed }
				death = {
					death_reason = death_execution_flaying
					killer = $EXECUTIONER$
				}
			}
			else_if = { limit = { always = scope:execution_boiled }
				death = {
					death_reason = death_execution_boiling
					killer = $EXECUTIONER$
				}
			}
			else_if = { limit = { always = scope:execution_impaled }
				death = {
					death_reason = death_execution_impaling
					killer = $EXECUTIONER$
				}
			}
			else_if = { limit = { always = scope:execution_crushed }
				death = {
					death_reason = death_execution_crushing
					killer = $EXECUTIONER$
				}
			}
		}
	}

	scope:executioner = {
		if = {
			limit = {
				OR = {
					#is_spouse_of = scope:victim
					is_close_family_of = scope:victim
					scope:victim = { tier_or_related_liege_tier_greater_or_equal_trigger = { TIER = tier_kingdom } } #Kingdom & empire
				}
			}
			add_dread = major_dread_gain
		}
		else_if = {
			limit = {
				OR = {
					scope:victim = { tier_or_related_liege_tier_equal_trigger = { TIER = tier_duchy } }
					scope:victim = { tier_or_related_liege_tier_equal_trigger = { TIER = tier_county } }
				}
			}
			add_dread = medium_dread_gain
		}
		else = {
			add_dread = minor_dread_gain
		}
		# Piety loss (or gain) from executions
		if = {
			limit = {
				faith = {
					has_doctrine_parameter = human_sacrifice_active
				}
			}
			scope:victim = {
				if = {
					limit = {
						OR = {
							highest_held_title_tier >= tier_empire
							any_close_family_member = {
								highest_held_title_tier >= tier_empire
							}
						}
					}
					scope:executioner = { add_piety = massive_piety_gain }
				}
				else_if = {
					limit = {
						OR = {
							highest_held_title_tier >= tier_kingdom
							any_close_family_member = {
								highest_held_title_tier >= tier_kingdom
							}
						}
					}
					scope:executioner = { add_piety = major_piety_gain }
				}
				else_if = {
					limit = {
						OR = {
							highest_held_title_tier >= tier_duchy
							any_close_family_member = {
								highest_held_title_tier >= tier_duchy
							}
						}
					}
					scope:executioner = { add_piety = medium_piety_gain }
				}
				else_if = {
					limit = {
						OR = {
							is_ruler = yes
							is_lowborn = no
							any_close_family_member = {
								is_ruler = yes
							}
						}
					}
					scope:executioner = { add_piety = minor_piety_gain }
				}
				else = {
					scope:executioner = { add_piety = miniscule_piety_gain }
				}
			}
		}
		else_if = {
			limit = {
				faith = scope:victim.faith
				NOT = { has_perk = divine_retribution_perk }
			}
			add_piety = medium_piety_loss
		}
		# Stress loss		
		if = {
			limit = {
				has_trait = sadistic
			}
			stress_impact = {
				sadistic = medium_stress_impact_loss
			}
		}
		if = {
			limit = { #Killing infidels is relaxing
				has_trait = zealous
				NOT = { scope:executioner.faith = scope:victim.faith }
			}
			stress_impact = {
				zealous = minor_stress_impact_loss
			}
		}
		if = {
			limit = {
				has_relation_rival = scope:victim
			}
			add_prestige = medium_prestige_gain
			if = {
				limit = {
					NOR = {
						has_trait = vengeful
						has_trait = forgiving
					}
				}
				add_stress = major_stress_loss
			}
			else = {
				stress_impact = {
					vengeful = massive_stress_impact_loss
					forgiving = 0 #No stress reduction
				}
			}
			
		}
		#Kinslaying
		add_kinslayer_trait_or_nothing_effect = { VICTIM = scope:victim }

		#Tyranny
		if = {
			limit = {
				exists = scope:recipient
				has_execute_reason = scope:victim
			}
			custom_tooltip = IS_ALLOWED_TO_EXECUTE_DESC
		}
		else_if = {
			limit = {
				OR = {
					AND = {
						has_execute_reason = scope:victim
						NOT = { exists = scope:recipient }
					}
					is_at_war_with = scope:victim
				}
			}
			custom_tooltip = IS_ALLOWED_TO_EXECUTE_NO_RECIPIENT_DESC
		}
		else_if = {
			limit = {
				scope:victim = {
					OR = {
						is_landed = no
						NOT = { is_of_major_or_minor_interest_trigger = { CHARACTER = scope:executioner } }
					}
				}
	   			scope:executioner.faith = {
	  				faith_hostility_level = {
	 					target = scope:victim.faith
						value > faith_astray_level
	 				}
				}
			}
			custom_tooltip = IS_ALLOWED_TO_EXECUTE_HOSTILE_RELIGION_DESC
		}
		else_if = {
			limit = {
				scope:victim = { target_is_liege_or_above = prev }
			}
			add_tyranny = execution_tyranny_gain
		}
		else_if = {
			limit = {
				scope:victim = {
					NOT = { exists = liege }
					exists = host
				}
				any_pool_guest = { count > 0 }
			}
			every_pool_guest = {
				limit = {
					NOR = {
						this = scope:victim
						is_in_list = guest_list
					}
				}
				add_to_temporary_list = guest_list
			}
			every_in_list = {
				list = guest_list
				custom = all_your_guests
				add_opinion = {
					target = prev
					modifier = executed_guest_modifier
				}
			}
		}
		else = {
			if = {
				limit = {
					exists = scope:victim.liege
				}
				scope:victim.liege = {
					add_opinion = {
						target = prev
						modifier = executed_my_countryman_modifier
					}
				}
			}
		}
	}

	execute_opinion_effect = { VICTIM = scope:victim EXECUTIONER = scope:executioner }

	hidden_effect = {
		$VICTIM$ = {
			if = { limit = { always = scope:execution_beheaded }
				death = {
					death_reason = death_execution_beheading
					killer = $EXECUTIONER$
				}
			}
			else_if = { limit = { always = scope:execution_hanged }
				death = {
					death_reason = death_execution_hanging
					killer = $EXECUTIONER$
				}
			}
			else_if = { limit = { always = scope:execution_burned }
				death = {
					death_reason = death_execution_burning
					killer = $EXECUTIONER$
				}
			}
			else_if = { limit = { always = scope:execution_drowned }
				death = {
					death_reason = death_execution_drowning
					killer = $EXECUTIONER$
				}
			}
			else_if = { limit = { always = scope:execution_flayed }
				death = {
					death_reason = death_execution_flaying
					killer = $EXECUTIONER$
				}
			}
			else_if = { limit = { always = scope:execution_boiled }
				death = {
					death_reason = death_execution_boiling
					killer = $EXECUTIONER$
				}
			}
			else_if = { limit = { always = scope:execution_impaled }
				death = {
					death_reason = death_execution_impaling
					killer = $EXECUTIONER$
				}
			}
			else_if = { limit = { always = scope:execution_crushed }
				death = {
					death_reason = death_execution_crushing
					killer = $EXECUTIONER$
				}
			}
		}
	}
}

play_execution_sound_effect = {
	$RECIPIENT$ = {
		save_scope_as = actor_recipient
	}

	$PLAYER$ = {
		save_scope_as = actor_player
	}
	hidden_effect = {
		# Sounds
		if = {
			limit = { always = scope:execution_beheaded	}
			scope:actor_player = { play_music_cue = be_fx_beheading } # Temp
		}
		else_if = {
			limit = { always = scope:execution_hanged	}
			scope:actor_player = { play_music_cue = be_fx_hanging } # Temp
		}
		else_if = {
			limit = { always = scope:execution_burned }
			scope:actor_player = {
				if = {
					limit = {
						scope:actor_player.faith = {
							has_doctrine = doctrine_pluralism_fundamentalist
						}
					}
					add_piety = miniscule_piety_value
				}
				else = {
					if = {
						limit = {
							NOR = {
								has_trait = vengeful
								has_trait = sadistic
								has_relation_rival = scope:actor_recipient
							}
						}
						# Gain stress unless sadistic or vengeful, or unless it is a rival
						stress_impact = {
							base = minor_stress_impact_gain
							compassionate = minor_stress_impact_gain
							forgiving = minor_stress_impact_gain
						}
					}						
				}
			
				if = {
					limit = { scope:actor_recipient = { is_female = yes } }
					random_list = {
						10 = { play_music_cue = be_fx_burning_female_01 }
						10 = { play_music_cue = be_fx_burning_female_02 }
						10 = { play_music_cue = be_fx_burning_female_03 }
					}
				}
				else = {
					random_list = {
						10 = { play_music_cue = be_fx_burning_male_01 }
						10 = { play_music_cue = be_fx_burning_male_02 }
						10 = { play_music_cue = be_fx_burning_male_03 }
						10 = { play_music_cue = be_fx_burning_male_04 }
					}
				}
			} # Temp
		}
		else_if = {
			limit = { always = scope:execution_flayed	}
			scope:actor_player = {
				if = {
					limit = {
						NOR = {
							has_trait = vengeful
							has_trait = sadistic
							has_relation_rival = scope:actor_recipient
						}
					}
					# Gain stress unless sadistic or vengeful, or unless it is a rival
					stress_impact = {
						base = minor_stress_impact_gain
						compassionate = minor_stress_impact_gain
						forgiving = minor_stress_impact_gain
					}
				}
				if = {
					limit = { scope:actor_recipient = { is_female = yes } }
					random_list = {
						10 = { play_music_cue = be_fx_impaling_female_01 }
						10 = { play_music_cue = be_fx_impaling_female_02 }
						10 = { play_music_cue = be_fx_impaling_female_03 }
					}
				}
				else = {
					random_list = {
						10 = { play_music_cue = be_fx_impaling_male_01 }
						10 = { play_music_cue = be_fx_impaling_male_02 }
						10 = { play_music_cue = be_fx_impaling_male_03 }
					}
				}
			} # Temp
		}
		else_if = {
			limit = { always = scope:execution_impaled }
			scope:actor_player = {
				if = {
					limit = {
						NOR = {
							has_trait = vengeful
							has_trait = sadistic
							has_relation_rival = scope:actor_recipient
						}
					}
					# Gain stress unless sadistic or vengeful, or unless it is a rival
					stress_impact = {
						base = minor_stress_impact_gain
						compassionate = minor_stress_impact_gain
						forgiving = minor_stress_impact_gain
					}
				}
				if = {
					limit = { scope:actor_recipient = { is_female = yes } }
					random_list = {
						10 = { play_music_cue = be_fx_impaling_female_01 }
						10 = { play_music_cue = be_fx_impaling_female_02 }
						10 = { play_music_cue = be_fx_impaling_female_03 }
					}
				}
				else = {
					random_list = {
						10 = { play_music_cue = be_fx_impaling_male_01 }
						10 = { play_music_cue = be_fx_impaling_male_02 }
						10 = { play_music_cue = be_fx_impaling_male_03 }
					}
				}
			} # Temp
		}
		else_if = {
			limit = { always = scope:execution_crushed	}
			scope:actor_player = {
				if = {
					limit = {
						NOR = {
							has_trait = vengeful
							has_trait = sadistic
							has_relation_rival = scope:actor_recipient
						}
					}
					# Gain stress unless sadistic or vengeful, or unless it is a rival
					stress_impact = {
						base = minor_stress_impact_gain
						compassionate = minor_stress_impact_gain
						forgiving = minor_stress_impact_gain
					}
				}
				if = {
					limit = { scope:actor_recipient = { is_female = yes } }
					random_list = {
						10 = { play_music_cue = be_fx_crushing_female_01 }
						10 = { play_music_cue = be_fx_crushing_female_02 }
					}
				}
				else = {
					random_list = {
						10 = { play_music_cue = be_fx_crushing_male_01 }
						10 = { play_music_cue = be_fx_crushing_male_02 }
						10 = { play_music_cue = be_fx_crushing_male_03 }
					}
				}
			}
		}
		else_if = {
			limit = { always = scope:execution_boiled }
			scope:actor_player = {
				if = {
					limit = {
						NOR = {
							has_trait = vengeful
							has_trait = sadistic
							has_relation_rival = scope:actor_recipient
						}
					}
					# Gain stress unless sadistic or vengeful, or unless it is a rival
					stress_impact = {
						base = minor_stress_impact_gain
						compassionate = minor_stress_impact_gain
						forgiving = minor_stress_impact_gain
					}
				}
				if = {
					limit = { scope:actor_recipient = { is_female = yes } }
					random_list = {
						10 = { play_music_cue = be_fx_boiling_female_01 }
						10 = { play_music_cue = be_fx_boiling_female_02 }
					}
				}
				else = {
					random_list = {
						10 = { play_music_cue = be_fx_boiling_male_01 }
						10 = { play_music_cue = be_fx_boiling_male_02 }
					}
				}
			}
		}
		else_if = {
			limit = { always = scope:execution_drowned }
			scope:actor_player = {
				if = {
					limit = {
						scope:actor_player.faith = {
							has_doctrine = doctrine_pluralism_fundamentalist
						}
					}
					add_piety = miniscule_piety_value
				}
				else = {
					if = {
						limit = {
							NOR = {
								has_trait = vengeful
								has_trait = sadistic
								has_relation_rival = scope:actor_recipient
							}
						}
						# Gain stress unless sadistic or vengeful, or unless it is a rival
						stress_impact = {
							base = minor_stress_impact_gain
							compassionate = minor_stress_impact_gain
							forgiving = minor_stress_impact_gain
						}
					}
				}
				if = {
					limit = { scope:actor_recipient = { is_female = yes } }
					random_list = {
						10 = { play_music_cue = be_fx_drowning_female_01 }
						10 = { play_music_cue = be_fx_drowning_female_02 }
					}
				}
				else = {
					random_list = {
						10 = { play_music_cue = be_fx_drowning_male_01 }
					}
				}
			}
		}
	}
}