namespace = mpo_jamukha_flavor

#######################
# Become Blood Brothers with Temujin
#######################

mpo_jamukha_flavor.0001 = {
	type = character_event
	title = mpo_jamukha_flavor.0001.t
	desc = mpo_jamukha_flavor.0001.desc
	theme = nomads
	override_background = {
		reference = mpo_campfire_steppe
	}
	left_portrait = {
		character = root
		animation = happiness
		camera = camera_event_very_left
	}
	right_portrait = {
		character = scope:temujin
		animation = inspect_weapon
	}
	
	trigger = {
		scope:temujin = {
			is_alive = yes
			NOR = {
				has_relation_blood_brother = root
				has_relation_rival = root
			}
		}
		is_alive = yes
	}

	immediate = {
		play_music_cue = "mx_cue_touching_moment"
		scope:temujin = {
			save_scope_as = blood_bro
		}
	}

	option = { # Yay
		name = mpo_jamukha_flavor.0001.a
		name = mpo_jamukha_flavor.0001.a.tt
		scope:temujin = {
			set_relation_blood_brother = {
				target = scope:jamukha
				reason = blood_brother_temujin_jamukha
			}
		}
		
		if = {
			limit = {
				NOR = {
					has_character_flag = had_warhorse_story
					any_owned_story = {
						story_type = story_cycle_martial_lifestyle_warhorse
						exists = var:story_cycle_horse_name
					}
				}
				scope:jamukha = {
					NOR = {
						has_character_flag = had_warhorse_story
						any_owned_story = {
							story_type = story_cycle_martial_lifestyle_warhorse
							exists = var:story_cycle_horse_name
						}
					}
				}
			}
			custom_tooltip = temujin_warhorse_jamukha_tt
			custom_tooltip = jamukha_warhorse_jamukha_tt
			hidden_effect = {
				start_warhorse_story_cycle_effect = yes
				scope:temujin = {
					start_warhorse_story_cycle_effect = yes
				}
			}
		}
		custom_tooltip = blood_brother_gains_hook_tt
		custom_tooltip = blood_brother_gains_hook_other_tt
		
		add_character_modifier = blood_brother_warrior_modifier
		scope:temujin = {
			add_character_modifier = blood_brother_warrior_modifier
		}

		stress_impact = {
			gregarious = medium_stress_impact_loss
			callous = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
		}
	}

	option = { # Not a chance
		name = mpo_jamukha_flavor.0001.b
		add_dread = minor_dread_gain
		add_prestige = minor_prestige_gain
		scope:temujin = {
			add_opinion = {
				target = root
				modifier = disappointed_opinion
				opinion = -25
			}
		}
		stress_impact = {
			base = minor_stress_impact_gain
			callous = medium_stress_impact_loss
			gregarious = medium_stress_impact_gain
		}

		ai_chance = {
			base = 0
		}
	}
}

#######################
# You consider breaking free from Temujin
#######################

scripted_effect mpo_jamukha_flavor_0010_jamukha_leaving_effect = {
	if = {
		limit = { is_vassal_of = scope:temujin }
		create_title_and_vassal_change = {
			type = independency
			save_scope_as = change
			add_claim_on_loss = no
		}
		becomes_independent = {
			change = scope:change
		}
		resolve_title_and_vassal_change = scope:change
	}
	else = {
		end_tributary = yes
	}
	add_truce_both_ways = {
		character = scope:temujin
		years = 5
		name = temujin_jamukha_truce
	}
	if = {
		limit = {
			current_military_strength < scope:temujin.current_military_strength
		}
		domicile ?= {
			change_herd = {
				value = scope:temujin.domicile.herd
				multiply = 0.5
			}
		}
	}
	if = {
		limit = {
			exists = scope:togrul
		}
		show_as_tooltip = {
			custom_tooltip = negotiate_togrul_alliance_effect_tooltip
			create_alliance = {
				target = scope:togrul
				allied_through_owner = root
				allied_through_target = scope:togrul
			}
			scope:togrul = {
				add_opinion = {
					target = scope:jamukha
					modifier = event_negotiated_alliance_opinion
				}
			}
		}
	}
	custom_tooltip = jamukha_temujin_response_warning_tt
}

scripted_trigger mpo_jamukha_flavor_0010_togrul_trigger = {
	is_ai = yes
	is_at_war = no
	is_alive = yes
	is_ruler = yes
	NOR = {
		is_at_war_with = root
		has_relation_rival = root
		is_vassal_of = scope:temujin
	}
	in_diplomatic_range = root
	NOT = {
		government_has_flag = government_is_herder
	}
}

mpo_jamukha_flavor.0010 = {
	type = character_event
	title = mpo_jamukha_flavor.0010.t
	desc = {
		desc = mpo_jamukha_flavor.0010.desc
		triggered_desc = {
			trigger = {
				exists = scope:togrul
			}
			desc = mpo_jamukha_flavor.0010.desc_togrul
		}
	}
	theme = nomads
	override_background = {
		reference = mpo_steppe_evening
	}
	left_portrait = {
		character = root
		animation = war_attacker
		camera = camera_event_very_left
	}
	right_portrait = {
		character = scope:temujin
		animation = dismissal
		camera = camera_event_very_right
	}
	lower_right_portrait = scope:togrul
	
	trigger = {
		character:125501 = {
			has_variable = had_mpo_temujin_flavor_0001
		}
		is_alive = yes
		is_ruler = yes
		character:125501 = {
			is_alive = yes
			is_available = yes
		}
		OR = {
			is_vassal_of = character:125501
			is_tributary_of = character:125501
		}
		NOT = {
			is_at_war_with = character:125501
		}
	}

	immediate = {
		save_scope_as = jamukha
		character:125501 = {
			save_scope_as = temujin
		}
		if = {
			limit = {
				character:303211 = {
					mpo_jamukha_flavor_0010_togrul_trigger = yes
				}
			}
			character:303211 = {
				save_scope_as = togrul
			}
		}
		else_if = {
			limit = {
				character:303211.house ?= {
					any_house_member = {
						mpo_jamukha_flavor_0010_togrul_trigger = yes
					}
				}
			}
			character:303211.house ?= {
				ordered_house_member = {
					order_by = current_military_strength
					limit = {
						mpo_jamukha_flavor_0010_togrul_trigger = yes
					}
					save_scope_as = togrul
				}
			}
		}
		else = {
			capital_county.empire ?= {
				ordered_de_jure_county_holder = {
					order_by = current_military_strength
					limit = {
						highest_held_title_tier <= tier_duchy
						mpo_jamukha_flavor_0010_togrul_trigger = yes
					}
					save_scope_as = togrul
				}
			}
		}
	}

	#I want to leave Temujin and take Togrul as an ally
	option = {
		name = mpo_jamukha_flavor.0010.a
		show_as_tooltip = {
			mpo_jamukha_flavor_0010_jamukha_leaving_effect = yes
		}
		scope:temujin = {
			trigger_event = mpo_temujin_flavor.0010
			add_opinion = {
				target = root
				modifier = betrayal_opinion
				opinion = -40
			}
		}
		ai_chance = {
			base = 100
		}
	}

	#I want to stay with Temujin and be friends forever
	option = {
		name = mpo_jamukha_flavor.0010.b
		add_character_modifier = {
			modifier = jamukha_chose_loyalty_modifier
			years = 5
		}
		scope:temujin = {
			add_opinion = {
				target = root
				modifier = loyalty_opinion
				opinion = 30
			}
		}
		stress_impact = {
			base = miniscule_stress_impact_gain
		}
		ai_chance = {
			base = 0
		}
	}
	
	on_trigger_fail = { # Jamukha becomes your rival anyways if you've migrated away
		if = {
			limit = {
				is_independent_ruler = yes
				NOT = { is_tributary_of = scope:temujin }
			}
			hidden_effect = {
				scope:temujin = {
					trigger_event = {
						days = { 360 420 }
						id = mpo_temujin_flavor.0020
					}
				}
			}
		}
	}
}

#######################
# Temujin becomes your rival -- now you must kill him
#######################

mpo_jamukha_flavor.0020 = {
	type = character_event
	title = mpo_jamukha_flavor.0020.t
	desc = mpo_jamukha_flavor.0020.desc
	theme = nomads
	override_background = {
		reference = mpo_campfire_steppe
	}
	left_portrait = {
		character = root
		animation = threatening
		camera = camera_event_very_left
	}
	right_portrait = {
		character = scope:temujin
		animation = aggressive_sword
		outfit_tags = { nightgown }
		camera = camera_event_very_right
	}
	window = scheme_conclusion_event_no_header
	
	immediate = {
		play_music_cue = "mx_cue_murder"
		custom_tooltip = jamukha_temujin_no_more_positive_tt
		custom_tooltip = jamukha_temujin_rivals_tt
		custom_tooltip = mpo_temujin_flavor.0020.cb.tt
		if = {
			limit = {
				current_military_strength < scope:temujin.current_military_strength
			}
			domicile ?= {
				change_herd = {
					value = scope:temujin.domicile.herd
					multiply = 1.5
				}
			}
			add_prestige = major_prestige_gain # For MAA maintenance, mainly
			custom_tooltip = jamukha_gain_from_defectors_tt
		}
	}

	option = { # You who I once called brother
		name = mpo_jamukha_flavor.0020.a
		reason = blood_brother
		add_internal_flag = special
		trigger = { has_character_flag = was_temujins_bro }
		custom_tooltip = {
			text = mpo_jamukha_flavor.0020.a_war_win
			set_variable = temujin_jamukha_war_var
		}
		add_character_modifier = {
			modifier = temujin_jamukha_war_modifier
			years = 5
		}
		stress_impact = {
			base = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
		}
	}

	option = { # Murderrrrrrr
		name = mpo_jamukha_flavor.0020.b
		custom_tooltip = {
			text = mpo_jamukha_flavor.0020.b_murder
			set_variable = {
				name = temujin_jamukha_murder_var
				value = scope:temujin
			}
		}
		stress_impact = {
			deceitful = massive_stress_impact_loss
			sadistic = massive_stress_impact_loss
		}
		ai_chance = {
			base = 0
		}
	}
	
	option = { # I'm going to crush your skull
		name = mpo_jamukha_flavor.0020.c
		trigger = {
			NOT = { has_relation_blood_brother = scope:jamukha }
		}
		add_character_modifier = {
			modifier = temujin_jamukha_war_smaller_modifier
			years = 5
		}
		stress_impact = {
			wrathful = massive_stress_impact_loss
			vengeful = massive_stress_impact_loss
		}
		ai_chance = {
			base = 100
		}
	}
}
