#####################################
# Odnowa junaków
# Iść do Junaków
# Utwórz kaganat ruski
# Zrób sobie saqaliba
#####################################

decisions = {
	junaki_decyzja = {
		is_high_prio = yes
		potential = {
			is_ruler = yes
			age = 30
			
			has_global_flag = byzsla_slavic_junaki_fall
			capital_scope = {
				region = world_europe_south_east
			}
			tier = duke
		}
		allow = {
			wealth = 300
			prestige = 300
			OR = {
				owns = 505
				any_realm_lord = {
					owns = 505
				}
			}
			505 = { is_slav_religion = yes }
		}
		effect = {
			prestige = -300
			wealth = -300
			activate_title = { title = d_junacy_band status = yes }
			hidden_tooltip = {
				create_character = {
					random_traits = yes
					dynasty = random
					religion = ROOT
					culture = serbian
					female = no
					age = 34
					trait = skilled_tactician
				}
				new_character = {
					d_junacy_band = {
						grant_title = PREV
					}
					set_defacto_liege = ROOT
				}
			}
		}
		ai_will_do = {
			factor = 1	
		}
	}

# Utwórz kaganat ruski

	form_kaganat_rus = {
		only_playable = yes
		is_high_prio = yes
		potential = {
			is_playable = yes
			culture_group = east_slavic
			is_tribal = yes
			has_dlc = "Horse Lords"
			k_rus = {
				has_holder = no
			}
			k_ruthenia = {
				has_holder = no
			}
		}
		allow = {
			war = no
			completely_controls = d_novgorod
			OR = {
				completely_controls = d_beloozero
				completely_controls = d_pskov
				completely_controls = d_rostov
				completely_controls = d_tver
			}
			OR = {
				completely_controls = d_yaroslavl
				completely_controls = d_vladimir
				completely_controls = d_moskva
			}
			OR = {
				AND = {
					diplomacy = 12
					any_spouse = {
						stewardship = 12
					}
				}
				AND = {
					diplomacy = 12
					stewardship = 12
				}
				AND = {
					stewardship = 12
					any_spouse = {
						diplomacy = 12
					}
				}
			}
		}
		effect = {
			custom_tooltip = {
				text = byzsla_slav_ruski_kaganat
			}
			hidden_tooltip = {
				narrative_event = { id = byzsla_slavic_event_spec.11 }
				if = {
					limit = { has_nickname = no }
					give_nickname = nick_the_great
				}
				prestige = 1000
				capital_scope = {
					ROOT = {
						spawn_unit = {
							province = PREV
							owner = THIS
							troops = {
								knights = { 30 30 }
								horse_archers = { 180 180 }
								light_cavalry = { 420 420 }
							}
							attrition = 0.5
						}
						spawn_unit = {
							province = PREV
							owner = THIS
							troops = {
								heavy_infantry = { 180 180 }
								pikemen = { 180 180 }
								light_infantry = { 1200 1200 }
								archers = { 600 600 }
							}
							attrition = 0.5
						}
					}
				}
			}
		}
		ai_will_do = {
			factor = 1	
		}
	}
}

targetted_decisions = {
	join_to_junaks = {
		is_high_prio = yes
		filter = dynasty
		ai_target_filter = dynasty
		from_potential = {
			is_alive = yes
			is_adult = yes
			controls_religion = no
			holy_order = no
			mercenary = no
			is_female = no
			is_landed = no
			is_slav_religion = yes
			NOT = { has_character_flag = byzsla_junaki_flaga_1 }
			NOT = { has_character_flag = byzsla_junaki_flaga_2 }
			OR = {
				martial = 12
				OR = {
					trait = misguided_warrior
					trait = tough_soldier
					trait = skilled_tactician
					trait = brilliant_strategist
				}
			}
		}
		potential = {
			is_alive = yes
			controls_religion = no
			holy_order = no
			mercenary = no
			is_father = FROM
			is_slav_religion = yes
			is_ruler = yes
			is_title_active = d_junacy_band
		}
		allow = {
		}
		effect = {
			ROOT = { character_event = { id = byzsla_slavic_event_junaki.3 } }
			FROM = { 
				set_character_flag = byzsla_junaki_flaga_1
				character_event = { id = byzsla_slavic_event_junaki.4 }
			}
		}
		ai_will_do = {
			factor = 0.2
			modifier = {
				factor = 5
				ai_ambition = 20
			}
			modifier = {
				factor = 5
				is_primary_heir = no
			}
			modifier = {
				factor = 10
				NOT = { prestige = 0 }
			}
		}
	}

	tworz_saqaliba = {
		filter = court
		ai_target_filter = court
		from_potential = {
			is_playable = yes
			is_landed = yes
			mercenary = no
			holy_order = no
			has_dlc = "Zeus"
			religion_group = muslim
			OR = {
				ai = no
				any_war = {
					OR = {
						any_defender = {
							character = ROOT
							is_primary_war_defender = yes
						}
						any_attacker = {
							character = ROOT
							is_primary_war_attacker = yes
						}
					}
				}
			}
		}
		potential = {
			prisoner = yes
			is_ruler = no
			is_adult = yes
			is_female = no
			NOT = { trait = incapable }
			NOT = { is_inaccessible_trigger = yes }
			NOT = { trait = monk }
			OR = {
				culture_group = east_slavic
				culture_group = west_slavic
				culture_group = south_slavic
			}
		}
		allow = {
			can_be_mercenary_leader_allow_trigger = yes
			FROM = {
				NOT = { has_mercenary_band = yes }
				wealth = 150
			}
		}
		effect = {
			prisoner = no
			FROM = {
				wealth = -150
				custom_tooltip = {
					hidden_tooltip = {
						primary_title = {
							create_title = {
								tier = DUKE
								name = DYNAMIC_SAQALIBA_BYZSLA
								landless = yes
								temporary = yes
								adventurer = yes
								custom_created = yes
								culture = ROOT
								holder = ROOT
								base_title = THIS
								mercenary = yes
								replace_captain_on_death = no
								ruler = "HIGH_CHIEF"
								ruler_female = "HIGH_CHIEF"
								foa = "HIGH_CHIEF_FOA"
								change_mercenary_composition = {
									type = light_infantry
									change = 200
								}
								change_mercenary_composition = {
									type = archers
									change = 150
								}
								change_mercenary_composition = {
									type = light_cavalry
									change = 100
								}
							}
						}
						ROOT = {
							set_defacto_liege = THIS
						}
					}
				}
			}
		}
		revoke_allowed = {
			always = no
		}
		ai_will_do = {
			factor = 0.03
			
			modifier = { 
				factor = 5
				controls_religion = yes
			}
		}
	}
}
