﻿on_travel_plan_movement = { 
	on_actions = {
		ttk_travel_event_duel
	}
}

on_travel_plan_complete = {
	on_actions = {
		ttk_travel_event_duel_clear
		}
}
	
ttk_travel_event_duel = {
	trigger = {
		is_ai = no
		is_adult = yes
		any_relation = {
			type = rival
			exists = this
		}
		is_alive = yes
		is_incapable = no
		NOT = { has_trait = infirm }
		is_travelling = yes
		NOT = { has_character_flag = ttk_duel_can_pass }
		OR = {
			location.county ?= {
				any_county_province = {
					any_character_in_location = { 
						NOT = { this = root }
						is_travelling = yes
						is_ai = yes
						is_adult = yes
						is_alive = yes						
						has_relation_rival = root
						OR = {
							is_travel_entourage_character = yes
							is_ruler = yes
						}
						NOT = { is_courtier_of = root }						
					}
				}
			}
			location.county ?= {
				any_county_province = {
					any_neighboring_province = {
						any_character_in_location = { 
							NOT = { this = root }
							is_travelling = yes
							is_ai = yes	
							is_ai = yes
							is_adult = yes
							is_alive = yes	
							has_relation_rival = root
							OR = {
								is_travel_entourage_character = yes
								is_ruler = yes
							}
							NOT = { is_courtier_of = root }						
						}
					}
				}
			}
		}
	}		
	effect = {
		save_scope_as = ttk_duel_init
		location = { save_scope_as = background_terrain_scope }
		location.county = {
			every_county_province = {
				random_character_in_location = { 
					limit = {
						NOT = { this = scope:ttk_duel_init }
						is_travelling = yes
						is_ai = yes
						has_relation_rival = scope:ttk_duel_init
						OR = {
							is_travel_entourage_character = yes
							is_ruler = yes
						}
						NOT = { is_courtier_of = scope:ttk_duel_init }		
					}
					save_scope_as = ttk_duel_target					
				}
			}
		}
		location.county = {
			every_county_province = {
				every_neighboring_province = {
					random_character_in_location = { 
						limit = {
							NOT = { this = scope:ttk_duel_init }
							is_travelling = yes
							is_ai = yes
							has_relation_rival = scope:ttk_duel_init
							OR = {
								is_travel_entourage_character = yes
								is_ruler = yes
							}
							NOT = { is_courtier_of = scope:ttk_duel_init }	
							NOT = { exists = scope:ttk_duel_target }
						}
						save_scope_as = ttk_duel_target
					}
				}
			}
		}
		random = {
			chance = 15
			scope:ttk_duel_init = {
				trigger_event = ttk_travel_event_duel.0001
			}
		}
	}
}

ttk_travel_event_duel_clear = {
	trigger = {
		is_ai = no
		has_character_flag = ttk_duel_can_pass
	}
	effect = {
		remove_character_flag = ttk_duel_can_pass
	}
}