﻿battlefield_duel_shared_loser_end_result_tooltip_effect = {
	if = {
		limit = { scope:victory_type = flag:skill }
		custom_tooltip = battlefield_duel_single_combat.0031.desc.result.skill
	}
	else_if = {
		limit = { scope:victory_type = flag:mistake }
		custom_tooltip = battlefield_duel_single_combat.0031.desc.result.mistake
	}
	else_if = {
		limit = { scope:victory_type = flag:sudden_death }
		custom_tooltip = battlefield_duel_single_combat.0031.desc.result.sudden_death
	}
}

battlefield_duel_shared_victor_end_result_tooltip_effect = {
	if = {
		limit = { scope:victory_type = flag:skill }
		custom_tooltip = battlefield_duel_single_combat.0041.desc.result.skill
	}
	else_if = {
		limit = { scope:victory_type = flag:mistake }
		custom_tooltip = battlefield_duel_single_combat.0041.desc.result.mistake
	}
	else_if = {
		limit = { scope:victory_type = flag:sudden_death }
		custom_tooltip = battlefield_duel_single_combat.0041.desc.result.sudden_death
	}
}

battlefield_duel_known_killer_death_consequences_effect = {
	# Every known killer uses the same Kinslayer and House Relation pass.
	save_temporary_scope_as = battlefield_duel_consequence_victim

	$KILLER$ = {
		add_kinslayer_trait_or_nothing_effect = { VICTIM = scope:battlefield_duel_consequence_victim }
	}

	if = {
		limit = {
			exists = house
			$KILLER$ = { exists = house }
		}
		house = {
			change_house_relation_effect = {
				HOUSE = $KILLER$.house
				VALUE = house_relation_damage_medium_value
				REASON = killed
				CHAR = $KILLER$
				TARGET_CHAR = scope:battlefield_duel_consequence_victim
				TITLE = scope:dummy_gender
			}
		}
	}
}

battlefield_duel_enemy_side_death_consequences_effect = {
	if = {
		limit = {
			exists = scope:combat_side.side_primary_participant
			exists = scope:combat_side.enemy_side.side_primary_participant
			exists = scope:combat_side.combat.location
		}
		save_died_in_battle_variables_effect = {
			ENEMY = scope:combat_side.side_primary_participant
			LEADER = scope:combat_side.enemy_side.side_primary_participant
			LOCATION = scope:combat_side.combat.location
		}
	}
	battlefield_duel_known_killer_death_consequences_effect = { KILLER = $KILLER$ }
}

battlefield_duel_friendly_side_death_consequences_effect = {
	if = {
		limit = {
			exists = scope:combat_side.enemy_side.side_primary_participant
			exists = scope:combat_side.side_primary_participant
			exists = scope:combat_side.combat.location
		}
		save_died_in_battle_variables_effect = {
			ENEMY = scope:combat_side.enemy_side.side_primary_participant
			LEADER = scope:combat_side.side_primary_participant
			LOCATION = scope:combat_side.combat.location
		}
	}
	battlefield_duel_known_killer_death_consequences_effect = { KILLER = $KILLER$ }
}

battlefield_duel_weapon_execution_resolution_effect = {
	# Special kill flavor still comes through the normal death, weapon, and trophy route.

	if = {
		limit = {
			scope:actor = {
				OR = {
					has_character_flag = battlefield_duel_vengeful_execution_pending
					has_character_flag = battlefield_duel_zealous_execution_pending
				}
			}
		}
		scope:actor = {
			random_equipped_character_artifact = {
				limit = { artifact_slot_type = primary_armament }
				save_scope_as = battlefield_duel_execution_weapon
			}
		}
	}

	$KILL_EFFECT$ = yes

	scope:enemy_knight = {
		battlefield_duel_enemy_side_death_consequences_effect = { KILLER = scope:actor }
		add_character_flag = { flag = agot_battlefield_duel_being_killed_in_duel days = 2 }
		battlefield_duel_transfer_equipped_artifact_effect = { TYPE = primary_armament OWNER = scope:actor }
		if = {
			limit = {
				scope:actor = { has_character_flag = battlefield_duel_vengeful_execution_pending }
			}
			if = {
				limit = { exists = scope:battlefield_duel_execution_weapon }
				death = {
					killer = scope:actor
					death_reason = death_battlefield_duel_vengeful_beheaded
					artifact = scope:battlefield_duel_execution_weapon
				}
			}
			else = {
				death = {
					killer = scope:actor
					death_reason = death_battlefield_duel_vengeful_beheaded
				}
			}
		}
		else_if = {
			limit = {
				scope:actor = { has_character_flag = battlefield_duel_zealous_execution_pending }
			}
			if = {
				limit = { exists = scope:battlefield_duel_execution_weapon }
				death = {
					killer = scope:actor
					death_reason = death_battlefield_duel_zealous_judgment
					artifact = scope:battlefield_duel_execution_weapon
				}
			}
			else = {
				death = {
					killer = scope:actor
					death_reason = death_battlefield_duel_zealous_judgment
				}
			}
		}
		else = {
			death = {
				killer = scope:actor

				death_reason = death_duel
			}
		}
	}

	scope:actor = { remove_character_flag = battlefield_duel_vengeful_execution_pending }
	scope:actor = { remove_character_flag = battlefield_duel_zealous_execution_pending }

	hidden_effect = {
		send_interface_message = {
			type = battlefield_duel_feed_martial_bad
			title = battlefield_duel_kill_notification
			desc = battlefield_duel_success_death_toast
			left_icon = root
			right_icon = scope:enemy_knight
		}
	}
}
