namespace = mpo_flavor_events_settled

# mpo_flavor_events_settled.0001 - You hear of a Havsarsan Zud
# mpo_flavor_events_settled.0010 - Horse Lord at your door

#######################
# You hear of a Havsarsan Zud
#######################
mpo_flavor_events_settled.0001 = {
	type = character_event
	title = mpo_flavor_events_settled.0001.t
	desc = mpo_flavor_events_settled.0001.desc
	theme = nomads
	override_background = { reference = ep3_city_gate }
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				OR = {
					has_trait = callous
					has_trait = sadistic
				}
			}
			animation = schadenfreude
		}
		triggered_animation = {
			trigger = {
				OR = {
					has_trait = brave
					has_trait = arrogant
				}
			}
			animation = dismissal
		}
		animation = worry
	}
	right_portrait = {
		character = scope:nomad
		animation = horse_exhausted
		camera = camera_event_horse_right
	}
	widget = {
		gui = "event_window_widget_vfx_snowstorm"
		container = "foreground_shader_vfx_container"
	}
	cooldown = { years = 10 }
	
	trigger = {
		has_mpo_dlc_trigger = yes
		NOT = { government_has_flag = government_is_nomadic }
		OR = {
			any_character_situation = { # You are a settled ruler in the Great Steppe
				any_participant_group = {
					participant_group_type = settled_rulers
					participant_group_has_character = root
				}
				any_situation_sub_region = {
					sub_region_current_phase = situation_steppe_havsarsan_zud_season
				}
			}
			any_sub_realm_county = { # You are neighbouring the Great Steppe
				any_neighboring_county = {
					holder != root
					any_county_situation = {
						situation:the_great_steppe ?= this
						any_situation_sub_region = {
							sub_region_current_phase = situation_steppe_havsarsan_zud_season
						}
					}
				}
			}
		}
	}

	immediate = {
		if = {
			limit = {
				any_neighboring_top_liege_realm_owner = {
					government_has_flag = government_is_nomadic
				}
			}
			random_neighboring_top_liege_realm_owner = {
				limit = { government_has_flag = government_is_nomadic }
				save_scope_as = nomad_lord
			}
		}
		else = {
			random_ruler = {
				limit = {
					in_diplomatic_range = root
					government_has_flag = government_is_nomadic
				}
				save_scope_as = nomad_lord
			}
		}
		create_character = {
			location = root.location
			template = nomadic_hunter_template
			faith = scope:nomad_lord.faith
			culture = scope:nomad_lord.culture
			save_scope_as = nomad
		}
		scope:nomad = { add_trait = nomadic_philosophy }
	}
	
	option = { # Get out
		name = mpo_flavor_events_settled.0001.aa
		reason = faith
		add_internal_flag = special
		trigger = {
			faith = {
				trait_is_virtue = callous
			}
		}
		add_piety = medium_piety_gain
		stress_impact = {
			callous = major_stress_impact_loss
			generous = medium_stress_impact_gain
			paranoid = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 2
				has_trait = callous
			}
			modifier = {
				factor = 0
				OR = {
					has_trait = generous
					has_trait = paranoid
				}
			}
		}
	}

	option = { # Let's prepare
		name = mpo_flavor_events_settled.0001.a
		remove_short_term_gold = medium_gold_value
		every_sub_realm_county = {
			limit = { holder = root }
			add_county_modifier = {
				modifier = mpo_settled_preparations_war_county_modifier
				years = 15
			}
		}
		stress_impact = {
			wrathful = medium_stress_impact_loss
			brave = medium_stress_impact_loss
			craven = medium_stress_impact_gain
			greedy = medium_stress_impact_gain
			avaricious = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
			modifier = {
				OR = {
					has_trait = wrathful
					has_trait = brave
				}
				factor = 0
			}
			modifier = {
				OR = {
					short_term_gold <= major_gold_value
					has_trait = greedy
					has_trait = avaricious
					has_trait = craven
				}
				factor = 0
			}
		}
	}

	option = { # We should focus on building
		name = mpo_flavor_events_settled.0001.b
		every_sub_realm_county = {
			limit = { holder = root }
			add_county_modifier = {
				modifier = mpo_settled_preparations_building_county_modifier
				years = 10
			}
		}
		stress_impact = {
			compassionate = major_stress_impact_loss
			greedy = medium_stress_impact_gain
			avaricious = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
		}
	}

	option = { # Recruit this guy
		name = mpo_flavor_events_settled.0001.c
		trigger = {
			NOT = {
				faith = {
					trait_is_virtue = callous
				}
			}
		}
		add_courtier = scope:nomad
		if = {
			limit = {
				faith = { trait_is_virtue = compassionate }
			}
			add_piety = major_piety_gain
		}
		else = {
			add_piety = medium_piety_gain
		}
		stress_impact = {
			compassionate = major_stress_impact_loss
			callous = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
		}
	}
	
	after = {
		custom_tooltip = mpo_flavor_events_settled.0001.tt
		if = {
			limit = { is_ai = yes }
			scope:nomad = { silent_disappearance_effect = yes }
		}
	}
}

#######################
# Horse Lord at your door
#######################
scripted_trigger mpo_flavor_events_settled_0010_valid_nomad_lord_trigger = {
	government_has_flag = government_is_nomadic
	NOR = {
		is_close_family_of = root
		is_vassal_of = root
		is_tributary_of = root
		this = root.liege
		this = root.suzerain
	}
	any_character_situation = {
		situation:the_great_steppe ?= this
	}
}

mpo_flavor_events_settled.0010 = {
	type = character_event
	title = mpo_flavor_events_settled.0010.t
	desc = mpo_flavor_events_settled.0010.desc
	theme = nomads
	override_background = { reference = ep3_city_gate }
	left_portrait = {
		character = root
		animation = anger
	}
	right_portrait = {
		character = scope:nomad
		animation = horse_conversing_left
		camera = camera_event_horse_right
	}
	lower_right_portrait = scope:nomad_lord
	cooldown = { years = 10 }
	
	trigger = {
		has_mpo_dlc_trigger = yes
		NOT = { government_has_flag = government_is_nomadic }
		any_neighboring_top_liege_realm_owner = {
			mpo_flavor_events_settled_0010_valid_nomad_lord_trigger = yes 
		}
	}
	
	weight_multiplier = {
		base = 1
		modifier = {
			any_neighboring_top_liege_realm_owner = {
				government_has_flag = government_is_nomadic
				highest_held_title_tier >= tier_kingdom
			}
			factor = 2
		}
	}

	immediate = {
		random_neighboring_top_liege_realm_owner = {
			limit = { mpo_flavor_events_settled_0010_valid_nomad_lord_trigger = yes }
			weight = {
				base = 1
				modifier = {
					highest_held_title_tier >= tier_kingdom
					add = 5
				}
			}
			save_scope_as = nomad_lord
		}
		create_character = {
			location = root.location
			template = nomadic_commander_template
			faith = scope:nomad_lord.faith
			culture = scope:nomad_lord.culture
			save_scope_as = nomad
		}
		hidden_effect = {
			scope:nomad = { add_trait = nomadic_philosophy }
			scope:nomad_lord = { add_courtier = scope:nomad }
		}
	}

	option = { # Pay tribute
		name = mpo_flavor_events_settled.0010.a
		trigger = {
			OR = {
				scope:nomad_lord.primary_title.tier > root.primary_title.tier
				scope:nomad_lord.current_military_strength > root.current_military_strength
			}
		}
		start_tributary_interaction_effect = {
			TRIBUTARY = root
			SUZERAIN = scope:nomad_lord
		}
		scope:nomad_lord = {
			add_opinion = {
				target = root 
				modifier = pleased_opinion
				opinion = 25
			}
		}
		add_prestige = medium_prestige_gain
		stress_impact = {
			vengeful = major_stress_impact_loss
			compassionate = medium_stress_impact_gain
		}

		ai_chance = {
			base = 0
		}
	}

	option = { # Pay to get truce
		name = mpo_flavor_events_settled.0010.b
		trigger = {
			NOR = {
				scope:nomad_lord.primary_title.tier > root.primary_title.tier
				scope:nomad_lord.current_military_strength > root.current_military_strength
			}
		}
		if = {
			limit = {
				has_perk = defensive_measures_perk
			}
			custom_tooltip = mpo_flavor_events_settled.0010.b_perk_tt
			pay_short_term_gold = {
				target = scope:nomad_lord
				gold = root.purchase_truce_interaction_small_sum
			}
			add_truce_both_ways = {
				character = scope:nomad_lord
				days = purchase_truce_interaction_truce_days_medium_value
				name = TRUCE_PURCHASED
			}
		}
		else = {
			pay_short_term_gold = {
				target = scope:nomad_lord
				gold = root.purchase_truce_interaction_medium_sum
			}
			add_truce_both_ways = {
				character = scope:nomad_lord
				days = purchase_truce_interaction_truce_days_medium_value
				name = TRUCE_PURCHASED
			}
		}
		stress_impact = {
			brave = medium_stress_impact_gain
			ambitious = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
		}

		ai_chance = {
			base = 50
			modifier = {
				OR = {
					has_trait = content
					has_trait = craven
				}
				factor = 2
			}
			modifier = {
				OR = {
					has_trait = brave
					has_trait = ambitious
					has_trait = arrogant
					has_trait = greedy
					gold <= root.purchase_truce_interaction_major_sum
				}
				factor = 0
			}
		}
	}

	option = { # Offend them
		name = mpo_flavor_events_settled.0010.c
		add_dread = medium_dread_value
		scope:nomad_lord = {
			progress_towards_rival_effect = {
				CHARACTER = root
				OPINION = -40
				REASON = rival_disrespected_envoy
			}
		}
		stress_impact = {
			callous = major_stress_impact_loss
			craven = major_stress_impact_gain
			vengeful = major_stress_impact_gain
		}
		ai_chance = {
			base = 0
			modifier = {
				add = 150
				has_trait = callous
				current_military_strength > scope:nomad_lord.current_military_strength
			}
		}
	}
	
	option = { # Let's just be friends
		name = mpo_flavor_events_settled.0010.d
		add_diplomacy_lifestyle_xp = minor_lifestyle_xp
		scope:nomad_lord = {
			add_opinion = {
				target = root 
				modifier = pleased_opinion
				opinion = 5
			}
		}
		stress_impact = {
			gregarious = medium_stress_impact_loss
		}
		ai_chance = {
			base = 200
		}
	}
	
	after = {
		if = {
			limit = { is_ai = yes }
			scope:nomad = { silent_disappearance_effect = yes }
		}
	}
}