namespace = fp3_frontier_story_cycle

fp3_frontier_story_cycle.0001 = {
	type = letter_event
	opening = fp3_frontier_story_cycle.0001_opening
	desc = fp3_frontier_story_cycle.0001_letter
	sender = scope:upset_vassal

	trigger = {

		NOR = {
			has_character_flag = had_event_fp3_frontier_story_cycle.0001
			has_character_flag = had_event_fp3_frontier_story_cycle.0002
		}

		exists = scope:story.var:upset_vassal

		exists = scope:story.var:turkic_leader

		scope:story = {
			var:upset_vassal = {
				is_alive = yes
				is_imprisoned = no
				NOT = {
					has_trait = forgiving
				}
			}
		}
	}

	immediate = {

		add_character_flag = {
			flag = had_event_fp3_frontier_story_cycle.0001
		}
		scope:story = {
			var:upset_vassal = {
				save_scope_as = upset_vassal
			}
			var:turkic_leader = {
				save_scope_as = turkic_leader
			}
		}
	}

	option = {
		name = fp3_frontier_story_cycle.0001.a

		custom_tooltip = children_arriving_shortly.tt

		trigger_event = {
			id = fp3_frontier_story_cycle.0004
			days = { 5 30 }
		}
	}
}

fp3_frontier_story_cycle.0002 = {
	type = letter_event
	opening = fp3_frontier_story_cycle.0002_opening
	desc = fp3_frontier_story_cycle.0002_letter
	sender = scope:upset_vassal

	trigger = {

		NOT = { has_character_flag = had_event_fp3_frontier_story_cycle.0002 }


		exists = scope:story.var:upset_vassal

		exists = scope:story.var:nomads_county

		scope:story = {
			var:upset_vassal = {
				is_alive = yes
				is_imprisoned = no
				is_vassal_of = root
				NOT = { has_relation_rival = root }
				OR = {
					ai_vengefulness < medium_positive_ai_value
					has_trait = craven
					has_trait = forgiving
					root = {
						has_dread_level_towards = {
  							target = scope:story.var:upset_vassal
   							level = 2
   						}
					}
				}
			}
			var:nomads_county = {
				NOT = { has_county_modifier = fp3_nomad_friction_county_modifier }
			}
		}
	}

	immediate = {

		add_character_flag = {
			flag = had_event_fp3_frontier_story_cycle.0002
		}
		scope:story = {
			var:upset_vassal = {
				save_scope_as = upset_vassal
			}
			var:nomads_county = {
				save_scope_as = nomads_county
			}
		}

		scope:upset_vassal = {
			pay_short_term_gold = {
  				gold = 50
				target = root
			}
		}
	}

	option = {
		name = fp3_frontier_story_cycle.0002.a

		scope:upset_vassal = {
			add_opinion = {
				target = root
				opinion = 20
				modifier = grateful_opinion
			}
		}

		stress_impact = {
   			forgiving = medium_stress_impact_loss
   			vengeful = medium_stress_impact_gain
   		}

   		ai_chance = {
        	base = 100
        	ai_value_modifier = {
            	ai_vengefulness = -1
            	ai_honor = 0.7
            	ai_greed = 0.5
            	ai_compassion = 0.7
        	}
   		}
	}


	option = {
		name = fp3_frontier_story_cycle.0002.b

		pay_short_term_gold = {
  			gold = 50
			target = scope:upset_vassal
		}

		add_dread = minor_dread_gain

		scope:upset_vassal = {
			add_opinion = {
				target = root
				opinion = -20
				modifier = scared_opinion
			}
		}

		stress_impact = {
   			vengeful = medium_stress_impact_loss
   			greedy = medium_stress_impact_gain
   		}

   		ai_chance = {
        	base = 100
        	ai_value_modifier = {
            	ai_vengefulness = 1
            	ai_greed = -0.5
            	ai_compassion = -0.5
        	}
   		}
	}
}

fp3_frontier_story_cycle.0003 = { #Nomads story cycle
	type = character_event
	title = fp3_frontier_story_cycle.0003.t
	desc = {
		desc = fp3_frontier_story_cycle.0003_beginning
		first_valid = {
			triggered_desc = {
				trigger = {
					has_religion = religion:islam_religion
				}
				desc =  fp3_frontier_story_cycle.0003_jizya
			}
			desc = fp3_frontier_story_cycle.0003_not_jizya
		}
		desc =  fp3_frontier_story_cycle.0003_ending
	}

	theme = vassal
	left_portrait = {
		character = scope:turkic_leader
		animation = dismissal
	}
	right_portrait = {
		character = scope:greedy_chaplain
		animation = personality_dishonorable
		triggered_animation = {
			trigger = {
				ai_greed > medium_positive_ai_value
			}
			animation = personality_greedy
		}
	}
	lower_left_portrait = {
		character = root
	}

	trigger = {
		#standard checks
		is_available_adult = yes
		NOT = {	has_character_flag = had_event_fp3_frontier_story_cycle.0003 }
		#event fluff triggers
		faith = {
			NOR = {
				has_doctrine_parameter = unreformed
				has_doctrine = pagan_hostility_doctrine
			}
		}
		any_held_title = { is_head_of_faith = no }
		exists = scope:story.var:turkic_leader
		exists = scope:story.var:nomads_new_county 
		exists = cp:councillor_court_chaplain
		cp:councillor_court_chaplain = {
			NOT = { has_trait = generous }
			is_ai = yes
		}
	}

	immediate = {
		cp:councillor_court_chaplain = { save_scope_as = greedy_chaplain }	
		add_character_flag = {
			flag = had_event_fp3_frontier_story_cycle.0003
		}
		scope:story = {
			var:turkic_leader = {
				save_scope_as = turkic_leader
			}
			var:nomads_new_county = {
				save_scope_as = nomads_new_county
			}
		}
	}

	option = {
		name = fp3_frontier_story_cycle.0003.a
		trigger = {
			OR = {
				has_trait = greedy
				has_trait = arbitrary
				gold < 0
			}
		}
		if = {
			limit = {
				faith = { has_doctrine = doctrine_theocracy_temporal }
			}
			add_treasury_or_gold = medium_treasury_or_gold_value 
			scope:greedy_chaplain = { add_treasury_or_gold = major_treasury_or_gold_value }
		}
		else = { add_treasury_or_gold = major_treasury_or_gold_value }
		if = {
			limit = {
				scope:turkic_leader = {
					NOT = {
						has_relation_rival = root
						has_relation_nemesis = root
					}
				}
			}
			root = {
				progress_towards_rival_effect = {
					CHARACTER = scope:turkic_leader
					REASON = rival_brutal_taxation
					OPINION = -20
				}
			}
		}
		else = {
			scope:turkic_leader = {
				add_opinion = {
					target = root
					opinion = -40
					modifier = hate_opinion
				}
			}
		}
		scope:nomads_new_county = {
			add_county_modifier = {
				modifier = fp3_resentful_nomads_county_modifier
				years = 20
			}
		}
		stress_impact = { 
   			generous = medium_stress_impact_gain 
   			just = medium_stress_impact_gain 
   			humble = medium_stress_impact_gain
   			arrogant = minor_stress_impact_loss
   			greedy = major_stress_impact_loss
   		}
   		ai_chance = { 
        	base = 100
        	ai_value_modifier = {
            	ai_vengefulness = 0.5
            	ai_boldness = 1
            	ai_greed = 1
            	ai_compassion = -0.5
        	}
   		}
	}

	option = {
		name = fp3_frontier_story_cycle.0003.b

		if = {
			limit = {
				faith = { has_doctrine = doctrine_theocracy_temporal }
			}
			add_treasury_or_gold = minor_treasury_or_gold_value 
			scope:greedy_chaplain = { add_treasury_or_gold = medium_treasury_or_gold_value }
		}
		else = { add_treasury_or_gold = medium_treasury_or_gold_value }

		scope:turkic_leader = {
			add_opinion = {
				target = root
				opinion = -20
				modifier = fp3_resentful_opinion
			}
		}

		random = {
			chance = 50
			send_interface_toast = {
				left_icon = root
				right_icon = scope:turkic_leader
				title = resentful_nomads.toast

				scope:nomads_new_county = {
					add_county_modifier = {
						modifier = fp3_resentful_nomads_county_modifier
						years = 20
					}
				}
			}
		}

		stress_impact = {
   			generous = medium_stress_impact_gain
   			just = minor_stress_impact_gain
   			cynical = minor_stress_impact_gain
   			arbitrary = minor_stress_impact_loss
   			greedy = medium_stress_impact_loss
   		}

   		ai_chance = {
        	base = 100
        	ai_value_modifier = {
            	ai_vengefulness = 0.5
            	ai_greed = 1
            	ai_compassion = -0.3
        	}
   		}
	}

	option = {
		name = fp3_frontier_story_cycle.0003.c


		scope:greedy_chaplain = {
			add_opinion = {
				target = root
				opinion = -20
				modifier = disappointed_opinion
			}
		}

		add_hook = {
			type = favor_hook
   			target = scope:turkic_leader
    	}

    	stress_impact = {
   			greedy = medium_stress_impact_gain
   		}

   		ai_chance = {
        	base = 100
        	ai_value_modifier = {
            	ai_greed = -0.7
            	ai_rationality = 1
            	ai_compassion = 0.5
        	}
   		}
	}
}


fp3_frontier_story_cycle.0004 = { #Nomads story cycle
	type = character_event
	title = fp3_frontier_story_cycle.0004.t
	desc = fp3_frontier_story_cycle.0004.desc
	theme = bastardy
	left_portrait = {
		character = scope:orphan_girl
		animation = worry
	}
	right_portrait = {
		character = scope:orphan_boy
		animation = sick
	}
	lower_left_portrait = {
		character = root
	}
	lower_center_portrait = {
		character = scope:upset_vassal
	}
	lower_right_portrait = {
		character = scope:turkic_leader
	}

	trigger = {

		#event fluff triggers

		exists = scope:story.var:turkic_leader

		exists = scope:story.var:upset_vassal
	}

	immediate = {

		scope:story = {
			var:turkic_leader = {
				save_scope_as = turkic_leader
			}
			var:upset_vassal = {
				save_scope_as = upset_vassal
			}
		}

		create_character = {
			age = { 35 40 }
			gender = male
			dynasty = none
			faith = scope:upset_vassal.faith
			culture = scope:upset_vassal.culture
			location = scope:upset_vassal.capital_province
			template = peasant_character
			save_scope_as = orphan_baby_daddy

			after_creation = {
 				death = {
					death_reason = death_starved
				}
			}
		}

		create_character = {
			age = { 30 33 }
			gender = female
			dynasty = none
			faith = scope:upset_vassal.faith
			culture = scope:upset_vassal.culture
			location = scope:upset_vassal.capital_province
			template = peasant_character
			save_scope_as = orphan_baby_momma

			after_creation = {
 				death = {
					death_reason = death_starved
				}
			}
		}

		create_character = {
			age = { 11 13 }
			gender = female
			dynasty = none
			father = scope:orphan_baby_daddy
			mother = scope:orphan_baby_momma
			faith = scope:upset_vassal.faith
			culture = scope:upset_vassal.culture
			location = root.capital_province
			template = fp3_adorable_orphan
			save_scope_as = orphan_girl
		}

		create_character = {
			age = { 6 8 }
			gender = male
			dynasty = none
			father = scope:orphan_baby_daddy
			mother = scope:orphan_baby_momma
			faith = scope:upset_vassal.faith
			culture = scope:upset_vassal.culture
			location = root.capital_province
			template = fp3_adorable_orphan
			save_scope_as = orphan_boy

			after_creation = {
 				increase_wounds_effect = { REASON = attacked }
			}
		}
	}

	option = {
		name = fp3_frontier_story_cycle.0004.a
		flavor = fp3_pay_for_upkeep_flavor

		add_courtier = scope:orphan_girl
		add_courtier = scope:orphan_boy

		remove_short_term_gold = minor_gold_value

		hidden_effect = {
			reverse_add_opinion = {
				target = scope:orphan_girl
				modifier = grateful_opinion
				opinion = 30
			}
			add_hook = {
				target = scope:orphan_girl
				type = loyalty_hook
			}
			reverse_add_opinion = {
				target = scope:orphan_boy
				modifier = grateful_opinion
				opinion = 30
			}
			add_hook = {
				target = scope:orphan_boy
				type = loyalty_hook
			}
		}

		if = {
			limit = {
				faith = {
					OR = {
						trait_is_virtue = compassionate
						trait_is_virtue = generous
					}
				}
			}
			add_piety = medium_piety_gain
		}
		else = {
			add_prestige = minor_prestige_gain
		}

		stress_impact = {
			ambitious = minor_stress_impact_loss #You can mold them to awesomeness
			compassionate = massive_stress_impact_loss #Yay, a kid!
			gregarious = medium_stress_impact_loss #The more the merrier!
			arrogant = medium_stress_impact_gain #why would I?
			callous = major_stress_impact_gain #ew, no
			paranoid = major_stress_impact_gain #wat, no more strangers in my court
		}
		ai_chance = {
			base = 30
			modifier = {
				add = 50
				has_trait = generous
			}
			modifier = {
				add = 50
				has_trait = compassionate
			}
			modifier = {	#Weight down for stress.
				add = -20
				has_trait = paranoid
			}
			modifier = {
				add = -100
				has_trait = callous
			}
			modifier = {
				add = -100
				has_trait = arrogant
			}
		}
	}

	option = {
		name = fp3_frontier_story_cycle.0004.b

		#One shiny new child for you!
		scope:turkic_leader = {
			if = {
				limit = { is_female = yes }
					scope:orphan_girl = { set_mother = scope:turkic_leader }
					scope:orphan_boy = { set_mother = scope:turkic_leader }
			}
			else = {
				scope:orphan_girl = { set_father = scope:turkic_leader }
				scope:orphan_boy = { set_father = scope:turkic_leader }
			}
		}

		if = {
			limit = {
				scope:turkic_leader = {
					OR = {
						has_relation_friend = root
						ai_boldness < low_positive_ai_value
						ai_compassion > medium_positive_ai_value
					}
				}
			}
			scope:turkic_leader = {
				add_opinion = {
					target = root
					opinion = -20
					modifier = unfair_expectations_opinion
				}
			}
		}
		else = {
			scope:turkic_leader = {
				add_opinion = {
					target = root
					opinion = -40
					modifier = fp3_unjust_burden_opinion
				}
			}
		}

		scope:upset_vassal = {
			add_opinion = {
				target = root
				opinion = 20
				modifier = pleased_opinion
			}
		}

		hidden_effect = {
			#We take care of the sundries in a hidden effect so as not to put too much into the tooltip.
			scope:orphan_girl = {
				set_house = scope:turkic_leader.house
				add_trait = disputed_heritage
			}
			scope:orphan_boy = {
				set_house = scope:turkic_leader.house
				add_trait = disputed_heritage
			}
			add_courtier = scope:orphan_girl
			add_courtier = scope:orphan_boy

			#And they're pretty happy about being stepping up in life.
			reverse_add_opinion = {
				target = scope:orphan_girl
				modifier = grateful_opinion
				opinion = 30
			}
			reverse_add_opinion = {
				target = scope:orphan_boy
				modifier = grateful_opinion
				opinion = 30
			}
			scope:turkic_leader = {
				every_consort = {
					custom = custom.every_opposite_sex_consort
					limit = {
						sex_opposite_of = scope:turkic_leader
					}
					add_opinion = {
						modifier = ep1_disagreed_with_lowborn_adoption_opinion
						target = scope:turkic_leader
						opinion = -60
					}
				}
			}
		}


		stress_impact = {
			vengeful = minor_stress_impact_loss
			lazy = medium_stress_impact_loss
			just = medium_stress_impact_loss #the accusations might be true, after all?
			trusting = medium_stress_impact_gain
			craven = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			modifier = {	#Weight up for stress.
				add = 20
				has_trait = just
			}
			modifier = {
				add = 50
				has_trait = craven
			}
			modifier = {	#Weight down for stress.
				add = -20
				has_trait = trusting
			}
			modifier = {	#We favour the other trait specific options for callous & sadistic
				add = -100
				has_trait = callous
			}
		}
	}

	option = {
		name = fp3_frontier_story_cycle.0004.c
		flavor = fp3_pay_for_upkeep_flavor


		trigger = {
			OR =  {
				faith = {
					has_doctrine = tenet_monasticism
				}
				has_religion = religion:buddhism_religion #far from all buddhist religions have monastics, but this option would still make sense
			}
		}

		remove_short_term_gold = minor_gold_value

		if = {
			limit = {
				faith = {
					OR = {
						trait_is_virtue = compassionate
						trait_is_virtue = generous
					}
				}
			}
			add_piety = major_piety_gain
		}
		else = {
			add_prestige = medium_piety_gain
		}

		scope:orphan_girl = {
  			select_and_move_to_pool_effect = yes
  			add_trait = devoted
 		}
 		scope:orphan_boy = {
  			select_and_move_to_pool_effect = yes
  			add_trait = devoted
 		}

		stress_impact = {
   			zealous = minor_stress_impact_loss
   			cynical = minor_stress_impact_gain
   		}

   		ai_chance = {
        	base = 100
        	ai_value_modifier = {
            	ai_zeal = 0.9
            	ai_rationality = 0.5
            	ai_compassion = -0.5
        	}
   		}
	}

	option = {
		name = fp3_frontier_story_cycle.0004.d

		if = {
			limit = {
				faith = {
					OR = {
						trait_is_virtue = compassionate
						trait_is_virtue = generous
					}
				}
			}
			add_piety = minor_piety_loss
		}

		scope:orphan_girl = {
  			select_and_move_to_pool_effect = yes
 		}
 		scope:orphan_boy = {
  			select_and_move_to_pool_effect = yes
 		}

    	stress_impact = { #many chances for stress loss here, to make this "opting out" option potentially more worthwile
   			compassionate = major_stress_impact_gain
   			generous = major_stress_impact_gain
   			callous = minor_stress_impact_loss
   			arrogant = minor_stress_impact_loss
   			arbitrary = minor_stress_impact_loss
   			cynical = medium_stress_impact_loss
   			lazy = medium_stress_impact_loss
   			paranoid = medium_stress_impact_loss
   		}

   		ai_chance = {
        	base = 100
        	ai_value_modifier = {
            	ai_rationality = 0.3
            	ai_compassion = -0.9
        	}
   		}
	}
}


fp3_frontier_story_cycle.0005 = { #Nomads story cycle
	type = character_event
	title = fp3_frontier_story_cycle.0005.t
	desc = fp3_frontier_story_cycle.0005.desc
	theme = war
	left_portrait = {
		character = scope:turkic_leader
		animation = war_over_loss
		triggered_animation = {
			trigger = {
				ai_boldness > medium_positive_ai_value
			}
			animation = personality_bold
		}
	}
	right_portrait = {
		character = root
		animation = stress
		triggered_animation = {
			trigger = {
				OR = {
					has_trait = brave
					has_trait = wrathful
					has_trait = vengeful
					has_trait = organizer
					has_trait = strategist
				}
			}
			animation = scheme
		}
	}


	trigger = {

		#event fluff triggers

		NOT = {	has_character_flag = had_event_fp3_frontier_story_cycle.0005 }

		exists = scope:story.var:turkic_leader

		NOT = {
			scope:story.var:turkic_leader = { has_hook = root }
		}

		is_at_war = yes
	}

	immediate = {

		add_character_flag = {
			flag = had_event_fp3_frontier_story_cycle.0005
		}

		scope:story = {
			var:turkic_leader = {
				save_scope_as = turkic_leader
			}
		}
	}

	option = {
		name = fp3_frontier_story_cycle.0005.a

		scope:turkic_leader = {
			add_hook = {
  				type = favor_hook
   				target = root
   			}
    	}

    	scope:turkic_leader = {
			add_opinion = {
				target = root
				opinion = 20
				modifier = pleased_opinion
			}
		}

		spawn_army = {
			men_at_arms = {
				type = horse_archers
				stacks = 2
			}
			location = root.capital_province
			war_keep_on_attacker_victory = no
			uses_supply = yes
  	 		inheritable = no
			save_scope_as = new_horsemen_army
			name = turkic_tribal_event_troops
		}

		stress_impact = {
   			craven = medium_stress_impact_loss
   			arrogant = medium_stress_impact_gain
   			paranoid = medium_stress_impact_gain
   		}

   		ai_chance = {
        	base = 100
        	ai_value_modifier = {
            	ai_rationality = 0.7
            	ai_sociability = 0.2
            	ai_vengefulness = -0.5
        	}
   		}
	}

	option = {
		name = fp3_frontier_story_cycle.0005.b

		trigger = {
			OR = {
				has_trait = arrogant
				has_trait = callous
				has_trait = wrathful
				has_trait = stubborn
			}
		}

		scope:turkic_leader = {
			add_opinion = {
				target = root
				opinion = -40
				modifier = hurt_opinion
			}
		}

		stress_impact = {
   			humble = medium_stress_impact_gain
   			compassionate = medium_stress_impact_gain
   			calm = medium_stress_impact_gain
   		}

   		ai_chance = {
        	base = 100
        	ai_value_modifier = {
            	ai_vengefulness = 1
            	ai_compassion = -1
        	}
   		}
	}

	option = {
		name = fp3_frontier_story_cycle.0005.c

		scope:turkic_leader = {
			add_opinion = {
				target = root
				opinion = -20
				modifier = disappointed_opinion
			}
		}

		stress_impact = {
   			ambitious = medium_stress_impact_gain
   			craven = medium_stress_impact_gain
   			trusting = medium_stress_impact_gain
   			paranoid = medium_stress_impact_loss
   		}

   		ai_chance = {
        	base = 100
        	ai_value_modifier = {
            	ai_vengefulness = 1
            	ai_compassion = -1
        	}
   		}
	}
}

scripted_trigger suitable_one_eyed_child_trigger = {
	NOT = { has_trait = wounded_3 }
	OR = {
		has_trait = rowdy
		has_trait = curious
	}
	age >= 6
	is_adult = no
	is_courtier_of = root
	is_available = yes
	NOR = {
		has_trait = blind
		has_trait = one_eyed
	}
}

fp3_frontier_story_cycle.0006 = { #Nomads story cycle
	type = character_event
	title = fp3_frontier_story_cycle.0006.t
	desc = {
		desc = fp3_frontier_story_cycle.0006_beginning
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:scoped_physician
				}
				desc =  fp3_frontier_story_cycle.0006_has_court_physician
			}
			desc = fp3_frontier_story_cycle.0006_no_court_physician
		}
		desc =  fp3_frontier_story_cycle.0006_ending
	}
	theme = family
	left_portrait = {
		character = scope:turkic_leader
		animation = beg
		triggered_animation = {
			trigger = {
				ai_boldness > medium_positive_ai_value
			}
			animation = worry
		}
	}
	right_portrait = {
		character = scope:one_eyed_child
		animation = sadness
		triggered_animation = {
			trigger = {
				ai_vengefulness > medium_positive_ai_value
			}
			animation = personality_vengeful
		}
	}
	lower_left_portrait = root

	lower_right_portrait = scope:scoped_physician #this is your court physician if you have one


	trigger = {

		#event fluff triggers

		NOT = {	has_character_flag = had_event_fp3_frontier_story_cycle.0006 }

		exists = scope:story.var:turkic_leader

		any_close_family_member = { suitable_one_eyed_child_trigger = yes }
	}

	immediate = {

		add_character_flag = {
			flag = had_event_fp3_frontier_story_cycle.0006
		}

		scope:story = {
			var:turkic_leader = {
				save_scope_as = turkic_leader
			}
		}

		random_close_family_member = {
			limit = {
				suitable_one_eyed_child_trigger = yes
				is_primary_heir_of = root
			}
			alternative_limit = {
				suitable_one_eyed_child_trigger = yes
				is_child_of = root
			}
			alternative_limit = {
				suitable_one_eyed_child_trigger = yes
			}
			save_scope_as = one_eyed_child
		}

		scope:one_eyed_child = {
			increase_wounds_effect = { REASON = archery_accident }
			add_trait = one_eyed
			add_character_flag = {	flag = had_event_fp3_frontier_story_cycle.0006	} #this is to make sure that the child cannot trigger this event themselves in the unlikely case that they become the story_owner of the same story cycle in the future, since it'd feel too weird
		}

		if = { #if you have a court physician, he has a stake in this!
		 	limit = {
			 	court_physician_available_trigger = yes
		 	}
		 	save_court_physician_as_effect = { SCOPE_NAME = scoped_physician }
	 	}
	}

	option = {
		name = fp3_frontier_story_cycle.0006.a

		add_dread = medium_dread_gain

		scope:turkic_leader = {
			imprison_character_effect = {
				TARGET = this
				IMPRISONER = root
			}
		}

		if = {
			limit = {
				scope:one_eyed_child = {
					ai_vengefulness > low_positive_ai_value
				}
			}
			scope:one_eyed_child = {
				add_opinion = {
					target = root
					opinion = 20
					modifier = pleased_opinion
				}
				if = {
					limit = {
						NOT = { has_trait = vengeful }
						number_of_personality_traits < personality_trait_limit
						root = { is_ai = no }
					}
					random = {
						chance = 25
						add_trait = vengeful
					}
				}
			}
		}
		else = {
			scope:one_eyed_child = {
				add_opinion = {
					target = root
					opinion = -10
					modifier = fp3_mildly_terrified_opinion
				}
			}
		}

		stress_impact = {
   			vengeful = medium_stress_impact_loss
   			wrathful = medium_stress_impact_loss
   			forgiving = major_stress_impact_gain
   			calm = minor_stress_impact_gain
   			trusting = medium_stress_impact_gain
   		}

   		ai_chance = {
        	base = 100
        	ai_value_modifier = {
            	ai_vengefulness = 1
            	ai_compassion = -1
            	ai_rationality = 0.2
        	}
   		}
	}

	option = {
		name = fp3_frontier_story_cycle.0006.b

		add_prestige = medium_prestige_gain

		add_character_modifier = {
			modifier = fp3_banning_archery_modifier
		}

		scope:turkic_leader = {
			add_opinion = {
				target = root
				opinion = -20
				modifier = disappointed_opinion
			}
		}

		if = {
			limit = { exists = scope:scoped_physician }
			scope:scoped_physician = {
				add_opinion = {
					target = root
					opinion = 30
					modifier = took_my_advice_opinion
				}
			}
		}

		if = {
			limit = {
				scope:one_eyed_child = {
					ai_vengefulness > medium_positive_ai_value
				}
			}
			scope:one_eyed_child = {
				add_opinion = {
					target = root
					opinion = -20
					modifier = disappointed_opinion
				}
				if = {
					limit = {
						NOT = { has_trait = vengeful }
						number_of_personality_traits < personality_trait_limit
						root = { is_ai = no }
					}
					random = {
						chance = 25
						add_trait = vengeful
					}
				}
			}
		}
		else = {
			scope:one_eyed_child = {
				add_opinion = {
					target = root
					opinion = 20
					modifier = relieved_opinion
				}
			}
		}

		stress_impact = {
   			ambitious = medium_stress_impact_gain
   			craven = medium_stress_impact_gain
   			trusting = medium_stress_impact_gain
   			paranoid = medium_stress_impact_loss
   		}

   		ai_chance = {
        	base = 100
        	ai_value_modifier = {
            	ai_vengefulness = 1
            	ai_compassion = -1
        	}
   		}
	}

	option = {
		name = fp3_frontier_story_cycle.0006.c

		scope:turkic_leader = {
			add_opinion = {
				target = root
				opinion = 20
				modifier = grateful_opinion
			}
		}

		if = {
			limit = {
				scope:one_eyed_child = {
					ai_vengefulness > medium_positive_ai_value
				}
			}
			scope:one_eyed_child = {
				add_opinion = {
					target = scope:turkic_leader
					opinion = -30
					modifier = hate_opinion
				}
				add_opinion = {
					target = root
					opinion = -20
					modifier = hurt_opinion
				}
				if = {
					limit = {
						NOT = { has_trait = vengeful }
						number_of_personality_traits < personality_trait_limit
						root = { is_ai = no }
					}
					random = {
						chance = 50
						add_trait = vengeful
					}
				}
			}
		}
		else = {
			scope:one_eyed_child = {
				add_opinion = {
					target = root
					opinion = -10
					modifier = neglected_opinion
				}
			}
		}

		stress_impact = {
   			humble = medium_stress_impact_loss
   			vengeful = major_stress_impact_gain
   			wrathful = medium_stress_impact_gain
   			arrogant = medium_stress_impact_gain
   			cynical = minor_stress_impact_gain

   		}

   		ai_chance = {
        	base = 100
        	ai_value_modifier = {
            	ai_zeal = 0.5
            	ai_compassion = 0.5
        	}
   		}
	}
}

scripted_trigger suitable_turk_rival_councillor_trigger = {
	is_ai = yes
	NOT = {
		has_trait = craven
	}
	opinion = {
		target = scope:story.var:turkic_leader
		value < 0
	}
}

scripted_trigger bandit_infested_county_trigger = {
	NOR = {
		has_county_modifier = fp3_nomad_friction_county_modifier
		has_county_modifier = fp3_vengeful_nomads_county_modifier
		this = scope:story.var:nomads_new_county
	}
}


fp3_frontier_story_cycle.0007 = { #Nomads story cycle
	type = character_event
	title = fp3_frontier_story_cycle.0007.t
	desc = fp3_frontier_story_cycle.0007.desc
	theme = realm
	left_portrait = {
		character = scope:turkic_leader
		animation = personality_bold
		triggered_animation = {
			trigger = {
				ai_greed > medium_positive_ai_value
			}
			animation = personality_callous
		}
	}
	right_portrait = {
		character = scope:warmonger_councillor
		animation = personality_bold
		triggered_animation = {
			trigger = {
				OR = {
					has_trait = paranoid
					has_trait = wrathful
					has_trait = vengeful
					has_trait = organizer
					has_trait = strategist
				}
			}
			animation = disapproval
		}
	}

	trigger = {

		#event fluff triggers

		NOT = {	has_character_flag = had_event_fp3_frontier_story_cycle.0007 }

		exists = scope:story.var:turkic_leader

		scope:story.var:turkic_leader = {
			NOR = {
				has_trait = content
				has_trait = lazy
			}
		}

		any_councillor = { suitable_turk_rival_councillor_trigger = yes }

		any_held_county = { bandit_infested_county_trigger = yes }
	}

	immediate = {

		add_character_flag = {
			flag = had_event_fp3_frontier_story_cycle.0007
		}

		scope:story = {
			var:turkic_leader = {
				save_scope_as = turkic_leader
			}
		}

		random_councillor = {
			limit = {
				suitable_turk_rival_councillor_trigger = yes
				has_council_position = councillor_marshal
			}
			alternative_limit = {
				suitable_turk_rival_councillor_trigger = yes
				has_lifestyle = martial_lifestyle
			}
			alternative_limit = {
				suitable_turk_rival_councillor_trigger = yes
				OR = {
					has_trait = ambitious
					ai_boldness >= high_positive_ai_value
				}
			}
			alternative_limit = {
				suitable_turk_rival_councillor_trigger = yes
				opinion = {
					target = scope:turkic_leader
					value < -25
				}
			}
			alternative_limit = { suitable_turk_rival_councillor_trigger = yes }
			save_scope_as = warmonger_councillor
		}

		random_held_county = {
			limit = { #finding the most suitable county for the story!
				bandit_infested_county_trigger = yes
				has_county_corruption_trigger = yes
			}
			alternative_limit = {
				bandit_infested_county_trigger = yes
				county_control < medium_county_control
			}
			alternative_limit = {
				bandit_infested_county_trigger = yes
				county_control < full_county_control
				any_county_province = { geographical_region = dlc_fp3_eastern_persian_frontier_regions }
			}
			alternative_limit = {
				bandit_infested_county_trigger = yes
				any_county_province = { geographical_region = dlc_fp3_eastern_persian_frontier_regions }
			}
			alternative_limit = {
				bandit_infested_county_trigger = yes
				county_control < full_county_control
			}
			alternative_limit = {
				bandit_infested_county_trigger = yes
			}
			save_scope_as = bandits_county
		}

		scope:bandits_county = {
			add_county_modifier = {
				modifier = fp3_nomad_attacks_county_modifier
				years = 20
			}
		}
	}

	option = {
		name = fp3_frontier_story_cycle.0007.a

		scope:bandits_county = {
			add_county_modifier = {
				modifier = fp3_nomad_friction_county_modifier
				years = 30
			}
		}

		scope:bandits_county = {
			remove_county_modifier = fp3_nomad_attacks_county_modifier
			add_county_modifier = {
				modifier = fp3_silk_road_secure_county_modifier
				years = 40
			}
		}

		scope:turkic_leader = {
			add_opinion = {
				target = root
				opinion = 30
				modifier = fp3_supports_my_tribe_opinion
			}
		}

		scope:warmonger_councillor = {
			add_opinion = {
				target = root
				opinion = -20
				modifier = ignored_opinion
			}
		}

		stress_impact = {
   			ambitious = medium_stress_impact_loss
   			content = medium_stress_impact_gain
   			paranoid = medium_stress_impact_gain
   		}

   		ai_chance = {
        	base = 100
        	ai_value_modifier = {
            	ai_greed = 0.6
            	ai_boldness = 1
            	ai_compassion = -0.2
        	}
   		}
	}

	option = {
		name = fp3_frontier_story_cycle.0007.b

		scope:warmonger_councillor = {
			add_opinion = {
				target = root
				opinion = 20
				modifier = trusted_me_opinion
			}
		}

		scope:turkic_leader = {
			add_opinion = {
				target = root
				opinion = -20
				modifier = disappointed_opinion
			}
		}

		scope:warmonger_councillor = {
			duel = {
			skill = martial
			value = high_skill_rating

				20 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = 2
					}
					root = {
						custom_tooltip = fp3_investigating_attacks_successful
						send_interface_toast = {
							title = fp3_investigating_attacks_toast_successful
							left_icon = scope:warmonger_councillor

							scope:bandits_county = {
								remove_county_modifier = fp3_nomad_attacks_county_modifier
							}

							scope:warmonger_councillor = {
								add_martial_skill = 1
								add_intrigue_skill = 1
							}
						}
					}
				}
				20 = {
					compare_modifier = {
						value = scope:duel_value
						multiplier = -1
					}
					root = {
						custom_tooltip = fp3_investigating_attacks_dismal_failure
						send_interface_toast = {
							title = fp3_investigating_attacks_toast_dismal_failure
							left_icon = scope:possibly_capable_marshal

							scope:warmonger_councillor = {
								add_character_modifier = {
									modifier = fp3_crushed_by_failure_modifier
									years = 20
								}
							}
						}
					}
				}
			}
		}

		stress_impact = {
   			trusting = medium_stress_impact_loss
   			ambitious = medium_stress_impact_gain
   			arrogant = medium_stress_impact_gain
   		}

   		ai_chance = {
        	base = 100
        	ai_value_modifier = {
            	ai_boldness = -0.5
            	ai_compassion = 0.5
        	}
   		}
	}

	option = {
		name = fp3_frontier_story_cycle.0007.c

		random = {
			chance = 25
			send_interface_toast = {
				left_icon = root
				title = attacks_abated.toast

				scope:bandits_county = {
					remove_county_modifier = fp3_nomad_attacks_county_modifier
				}
			}
		}

		stress_impact = {
   			content = medium_stress_impact_loss
   			ambitious = medium_stress_impact_gain
   			just = medium_stress_impact_gain
   			impatient = medium_stress_impact_gain
   			diligent = medium_stress_impact_gain
   		}

   		ai_chance = {
        	base = 100
        	ai_value_modifier = {
            	ai_energy = -1
        	}
   		}
	}
}


fp3_frontier_story_cycle.0099 = { #Nomads story cycle
	type = character_event
	title = fp3_frontier_story_cycle.0099.t
	desc = fp3_frontier_story_cycle.0099.desc
	theme = realm
	left_portrait = {
		character = scope:turkic_leader
		animation = marshal
		triggered_animation = {
			trigger = {
				ai_greed > medium_positive_ai_value
			}
			animation = schadenfreude
		}
	}
	right_portrait = {
		character = root
		animation = personality_rational
		triggered_animation = {
			trigger = {
				OR = {
					has_trait = paranoid
					has_trait = craven
					has_trait = shy
				}
			}
			animation = disbelief
		}
		triggered_animation = {
			trigger = {
				OR = {
					has_trait = greedy
					has_trait = stubborn
					has_trait = callous
				}
			}
			animation = personality_cynical
		}
	}

	trigger = {

		exists = scope:story.var:turkic_leader

		scope:story.var:turkic_leader = { is_landed = no }

		has_character_flag = turkic_tribe_story_end

		any_held_title = {
			title_tier = county
			is_landless_type_title = no
			this != root.capital_county
		}

		domain_size > 4
	}

	immediate = {

		scope:story = {
			var:turkic_leader = {
				save_scope_as = turkic_leader
			}
		}

		random_held_title = {
			title_tier = county
			limit = {
				is_landless_type_title = no
				this != root.capital_county
				has_county_modifier = fp3_nomad_friction_county_modifier
			}
			alternative_limit = {
				is_landless_type_title = no
				this != root.capital_county
				development_level <= bad_development_level
			}
			alternative_limit = {
				is_landless_type_title = no
				this != root.capital_county
				development_level <= medium_development_level
			}
			alternative_limit = {
				is_landless_type_title = no
				this != root.capital_county
			}
			save_scope_as = title_to_grant
		}

		if = {
			limit = {
				any_held_title = {
					title_tier = county
					is_landless_type_title = no
					NOR = {
						this = root.capital_county
						this = scope:title_to_grant
					}
				}
			}
			random_held_title = {
				title_tier = county
				limit = {
					is_landless_type_title = no
					NOR = {
						this = root.capital_county
						this = scope:title_to_grant
					}
					has_county_modifier = fp3_nomad_friction_county_modifier
				}
				alternative_limit = {
					tier = tier_county
					is_landless_type_title = no
					NOR = {
						this = root.capital_county
						this = scope:title_to_grant
					}
					development_level <= bad_development_level
				}
				alternative_limit = {
					tier = tier_county
					is_landless_type_title = no
					NOR = {
						this = root.capital_county
						this = scope:title_to_grant
					}
					development_level <= medium_development_level
				}
				alternative_limit = {
					tier = tier_county
					is_landless_type_title = no
					NOR = {
						this = root.capital_county
						this = scope:title_to_grant
					}
				}
				save_scope_as = extra_title_to_grant
			}
		}

		if = {
			limit = {
				any_held_title = {
					title_tier = county
					is_landless_type_title = no
					NOR = {
						this = root.capital_county
						this = scope:title_to_grant
						this = scope:extra_title_to_grant
					}
				}
			}
			random_held_title = {
				title_tier = county
				limit = {
					is_landless_type_title = no
					NOR = {
						this = root.capital_county
						this = scope:title_to_grant
						this = scope:extra_title_to_grant
					}
					has_county_modifier = fp3_nomad_friction_county_modifier
				}
				alternative_limit = {
					tier = tier_county
					is_landless_type_title = no
					NOR = {
						this = root.capital_county
						this = scope:title_to_grant
						this = scope:extra_title_to_grant
					}
					development_level <= bad_development_level
				}
				alternative_limit = {
					tier = tier_county
					is_landless_type_title = no
					NOR = {
						this = root.capital_county
						this = scope:title_to_grant
						this = scope:extra_title_to_grant
					}
					development_level <= medium_development_level
				}
				alternative_limit = {
					tier = tier_county
					is_landless_type_title = no
					NOR = {
						this = root.capital_county
						this = scope:title_to_grant
						this = scope:extra_title_to_grant
					}
				}
				save_scope_as = extra_extra_title_to_grant
			}
		}
	}

	option = {
		name = fp3_frontier_story_cycle.0099.a

		dynasty = {
			add_dynasty_modifier = {
				modifier = fp3_nomad_recruits_modifier
				years = 150
			}
		}

		create_title_and_vassal_change = {
			type = granted
			save_scope_as = change
		}
		scope:title_to_grant = {
			change_title_holder = {
				holder = scope:turkic_leader
				change = scope:change
			}
		}
		resolve_title_and_vassal_change = scope:change
		if = {
			limit = {
				NOT = { has_relation_friend = scope:turkic_leader }
			}
			progress_towards_friend_effect = {
				REASON = friend_landed
				CHARACTER = scope:turkic_leader
				OPINION = default_friend_opinion
			}
		}
		else = {
			scope:turkic_leader = {
				add_opinion = {
					target = root
					modifier = friendliness_opinion
					opinion = 30
				}
			}
		}
		stress_impact = {
			generous = major_stress_impact_loss
			trusting = medium_stress_impact_loss
			arrogant = medium_stress_impact_gain
			greedy = massive_stress_impact_gain
		}

		ai_chance = {
        	base = 100 #the dynasty modifier is intended to be pretty good, so the AI could feasibly do this
        	ai_value_modifier = {
            	ai_greed = -1
            	ai_vengefulness = -0.5
            	ai_rationality = 0.5
            	ai_boldness = 0.5
        	}
   		}
	}

	option = {
		name = fp3_frontier_story_cycle.0099.b

		trigger = {
			exists = scope:extra_title_to_grant
		}

		dynasty = {
			add_dynasty_modifier = {
				modifier = fp3_nomad_recruits_modifier
				years = 150
			}
		}

		create_title_and_vassal_change = {
			type = granted
			save_scope_as = change
		}
		scope:extra_title_to_grant = {
			change_title_holder = {
				holder = scope:turkic_leader
				change = scope:change
			}
		}
		resolve_title_and_vassal_change = scope:change
		if = {
			limit = {
				NOT = { has_relation_friend = scope:turkic_leader }
			}
			progress_towards_friend_effect = {
				REASON = friend_landed
				CHARACTER = scope:turkic_leader
				OPINION = default_friend_opinion
			}
		}
		else = {
			scope:turkic_leader = {
				add_opinion = {
					target = root
					modifier = friendliness_opinion
					opinion = 30
				}
			}
		}
		stress_impact = {
			generous = major_stress_impact_loss
			trusting = medium_stress_impact_loss
			arrogant = medium_stress_impact_gain
			greedy = massive_stress_impact_gain
		}

		ai_chance = {
        	base = 100 #the dynasty modifier is intended to be pretty good, so the AI could feasibly do this
        	ai_value_modifier = {
            	ai_greed = -1
            	ai_vengefulness = -0.5
            	ai_rationality = 0.5
            	ai_boldness = 0.5
        	}
   		}
	}

	option = {
		name = fp3_frontier_story_cycle.0099.c

		trigger = {
			exists = scope:extra_extra_title_to_grant
		}

		dynasty = {
			add_dynasty_modifier = {
				modifier = fp3_nomad_recruits_modifier
				years = 150
			}
		}

		create_title_and_vassal_change = {
			type = granted
			save_scope_as = change
		}
		scope:extra_extra_title_to_grant = {
			change_title_holder = {
				holder = scope:turkic_leader
				change = scope:change
			}
		}
		resolve_title_and_vassal_change = scope:change
		if = {
			limit = {
				NOT = { has_relation_friend = scope:turkic_leader }
			}
			progress_towards_friend_effect = {
				REASON = friend_landed
				CHARACTER = scope:turkic_leader
				OPINION = default_friend_opinion
			}
		}
		else = {
			scope:turkic_leader = {
				add_opinion = {
					target = root
					modifier = friendliness_opinion
					opinion = 30
				}
			}
		}
		stress_impact = {
			generous = major_stress_impact_loss
			trusting = medium_stress_impact_loss
			arrogant = medium_stress_impact_gain
			greedy = massive_stress_impact_gain
		}

		ai_chance = {
        	base = 100 #the dynasty modifier is intended to be pretty good, so the AI could feasibly do this
        	ai_value_modifier = {
            	ai_greed = -1
            	ai_vengefulness = -0.5
            	ai_rationality = 0.5
            	ai_boldness = 0.5
        	}
   		}
	}

	option = {
		name = fp3_frontier_story_cycle.0099.d

		scope:turkic_leader = {
			add_opinion = {
				target = root
				modifier = spurned_opinion
				opinion = -40
			}
		}

		if = {
			limit = { is_ai = yes }
			scope:turkic_leader = {
  				silent_disappearance_effect = yes
 			}
		}
		else = {
			scope:turkic_leader = {
  				select_and_move_to_pool_effect = yes
 			}
		}

		every_sub_realm_county = {
			if = {
				limit = { has_county_modifier = fp3_nomad_friction_county_modifier }
				remove_county_modifier = fp3_nomad_friction_county_modifier
			}
		}

		every_sub_realm_county = {
			if = {
				limit = { has_county_modifier = fp3_vengeful_nomads_county_modifier }
				remove_county_modifier = fp3_vengeful_nomads_county_modifier
			}
		}

		stress_impact = {
			stubborn = medium_stress_impact_loss
			trusting = medium_stress_impact_gain
			generous = medium_stress_impact_gain
			craven = medium_stress_impact_gain
		}

		ai_chance = {
        	base = 100 #the dynasty modifier is intended to be pretty good, so the AI could feasibly do this
        	ai_value_modifier = {
            	ai_greed = 1
            	ai_sociability = -0.5
            	ai_boldness = 0.5
        	}
   		}
	}
}



