﻿namespace = mpo_temujin_flavor

# mpo_temujin_flavor.0001 - Become Blood Brothers with Jamukha
# mpo_temujin_flavor.0010 - Jamukha stops being your vassal
# mpo_temujin_flavor.0020 - Jamukha becomes your rival
# mpo_temujin_flavor.0030 - Borte announces she's pregnant

#######################
# Become Blood Brothers with Jamukha
#######################

mpo_temujin_flavor.0001 = {
	type = character_event
	title = mpo_temujin_flavor.0001.t
	desc = mpo_temujin_flavor.0001.desc
	theme = nomads
	override_background = {
		reference = mpo_campfire_steppe
	}
	left_portrait = {
		character = root
		animation = aggressive_dagger
	}
	right_portrait = {
		character = scope:jamukha
		animation = celebrate_dagger
	}
	
	trigger = {
		NOR = {
			has_variable = had_mpo_temujin_flavor_0001
			has_variable = had_mpo_temujin_flavor_0010
			has_variable = had_mpo_temujin_flavor_0020
		}
		is_physically_able = yes
		character:mpo_mongol_1 = {
			is_alive = yes
			is_physically_able = yes
			NOR = {
				has_relation_blood_brother = root
				has_relation_rival = root
			}
		}
	}

	immediate = {
		play_music_cue = "mx_cue_touching_moment"
		set_variable = had_mpo_temujin_flavor_0001
		character:mpo_mongol_1 = {
			save_scope_as = jamukha
			save_scope_as = blood_bro
		}
	}

	option = { # Yay
		name = mpo_temujin_flavor.0001.a
		
		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_tt
			custom_tooltip = jamukha_warhorse_tt
			if = {
				limit = {
					scope:jamukha = {
						is_ai = yes
					}
				}
				hidden_effect = {
					start_warhorse_story_cycle_effect = yes
				}
			}
			if = {
				limit = {
					scope:jamukha = {
						is_ai = yes
					}
				}
				hidden_effect = {
					scope:jamukha = {
						start_warhorse_story_cycle_effect = yes
					}
				}
			}
		}
		if = {
			limit = {
				scope:jamukha = {
					is_ai = yes
				}
			}
			set_relation_blood_brother = {
				target = scope:jamukha
				reason = blood_brother_temujin_jamukha
			}
			add_character_modifier = blood_brother_warrior_modifier
			scope:jamukha = {
				add_character_modifier = blood_brother_warrior_modifier
			}
		}
		else = {
			custom_tooltip = jamukha_choose_blood_brother_tt
			save_scope_as = temujin
			scope:jamukha = {
				trigger_event = mpo_jamukha_flavor.0001
			}
			show_as_tooltip = {
				add_character_modifier = blood_brother_warrior_modifier
				scope:jamukha = {
					add_character_modifier = blood_brother_warrior_modifier
				}
			}
		}
		custom_tooltip = blood_brother_gains_hook_tt
		custom_tooltip = blood_brother_gains_hook_other_tt
		
		stress_impact = {
			gregarious = medium_stress_impact_loss
			callous = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
		}
	}

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

		ai_chance = {
			base = 0
		}
	}
	
	after = {
		hidden_effect = {
			scope:jamukha = {
				trigger_event = {
					days = { 180 360 }
					id = mpo_jamukha_flavor.0010
				}
			}
			
		}
	}
}

#######################
# Jamukha stops being your vassal
#######################

scripted_effect mpo_temujin_flavor_0010_jamukha_leaving_effect = {
	if = {
		limit = { scope:jamukha = { is_vassal_of = root } }
		scope:jamukha = {
			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 = {
		scope:jamukha = { end_tributary = yes }
	}
	add_truce_both_ways = {
		character = scope:jamukha
		years = 5
		name = temujin_jamukha_truce
	}
	hidden_effect = { # This will put him closer to Temujin
		scope:jamukha = {
			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
		}
		scope:jamukha = {
			custom_tooltip = negotiate_togrul_alliance_effect_tooltip
			create_alliance = {
				target = scope:togrul
				allied_through_owner = scope:jamukha
				allied_through_target = scope:togrul
			}
			hidden_effect = {
				scope:togrul = {
					add_opinion = {
						target = scope:jamukha
						modifier = event_negotiated_alliance_opinion
					}
				}
			}
		}
	}
}

mpo_temujin_flavor.0010 = {
	type = character_event
	title = mpo_temujin_flavor.0010.t
	desc = {
		desc = mpo_temujin_flavor.0010.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = { has_variable = rejected_jamukha_var }
				desc = mpo_temujin_flavor.0010.desc.rejected
			}
			triggered_desc = {
				trigger = { has_relation_blood_brother = scope:jamukha }
				desc = mpo_temujin_flavor.0010.desc.blood_brothers
			}
			desc = mpo_temujin_flavor.0010.desc.fallback
		}
	}
	theme = nomads
	override_background = {
		reference = mpo_campfire_steppe
	}
	left_portrait = {
		character = root
		animation = personality_vengeful
	}
	right_portrait = {
		character = scope:jamukha
		animation = schadenfreude
	}
	lower_right_portrait = scope:togrul
	
	trigger = {
		has_variable = had_mpo_temujin_flavor_0001
		NOR = {
			has_variable = had_mpo_temujin_flavor_0010
			has_variable = had_mpo_temujin_flavor_0020
		}
		is_alive = yes
		is_ruler = yes
		character:mpo_mongol_1 = {
			is_alive = yes
			OR = {
				is_vassal_of = root
				is_tributary_of = root
			}
		}
	}

	immediate = {
		set_variable = {
			name = had_mpo_temujin_flavor_0010
			value = character:mpo_mongol_1
		}
		character:mpo_mongol_1 = {
			save_scope_as = jamukha
		}
		mpo_temujin_flavor_0010_jamukha_leaving_effect = yes
	}
	
	option = { # I will kill you
		name = mpo_temujin_flavor.0010.aa
		trigger = { dread >= 100 }
		if = {
			limit = {
				has_relation_blood_brother = scope:jamukha
			}
			custom_tooltip = {
				text = mpo_temujin_flavor.0010.aa_remove_blood_brother
				remove_relation_blood_brother = scope:jamukha
			}
		}
		scope:jamukha = {
			add_dread = major_dread_loss
			add_prestige = medium_prestige_loss
		}
		every_vassal = {
			limit = {
				has_vassal_stance = belligerent
				is_obedient = no
			}
			custom = every_belligerent_vassal
			add_opinion = {
				modifier = obedience_opinion
				target = root
			}
		}
		every_courtier = {
			limit = {
				is_obedient = no
				NOR = {
					has_trait = brave
					has_trait = compassionate
				}
			}
			custom = every_non_brave_compassionate_courtier
			add_opinion = {
				modifier = obedience_opinion
				target = root
			}
		}
		stress_impact = {
			gregarious = medium_stress_impact_loss
			callous = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
		}
	}

	option = { # Look at this clown
		name = mpo_temujin_flavor.0010.a
		duel = {
			skill = diplomacy
			target = scope:jamukha
			50 = { # Your people are impressed
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				min = 5
				desc = mpo_temujin_flavor.0010.a.tt.success
				send_interface_toast = {
					title = mpo_temujin_flavor.0010.a.tt.success
					left_icon = root
					right_icon = scope:jamukha
					add_prestige = medium_prestige_gain
					scope:jamukha = { add_prestige = medium_prestige_loss }
				}
			}
			50 = { # No one is impressed
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				min = 5
				desc = mpo_temujin_flavor.0010.a.tt.failure
				send_interface_toast = {
					title = mpo_temujin_flavor.0010.a.tt.failure
					left_icon = root
					add_prestige = minor_prestige_loss
				}
			}
		}
		stress_impact = {
			gregarious = medium_stress_impact_loss
			callous = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
		}
	}

	option = { # Try to force him to stay
		name = mpo_temujin_flavor.0010.b
		add_dread = minor_dread_gain
		scope:jamukha = {
			add_opinion = {
				target = root
				modifier = hurt_opinion
				opinion = -30
			}
		}
		stress_impact = {
			callous = medium_stress_impact_loss
			gregarious = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
		}
	}
	
	option = { # Let him go
		name = mpo_temujin_flavor.0010.c
		scope:jamukha = {
			add_opinion = {
				target = root
				modifier = grateful_opinion
				opinion = 20
			}
		}
		stress_impact = {
			generous = medium_stress_impact_loss
			callous = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
		}
	}
	
	after = {
		hidden_effect = {
			trigger_event = {
				days = { 360 420 }
				id = mpo_temujin_flavor.0020
			}
		}
	}
}

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

mpo_temujin_flavor.0020 = {
	type = character_event
	title = mpo_temujin_flavor.0020.t
	desc = {
		desc = mpo_temujin_flavor.0020.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = { has_relation_blood_brother = scope:jamukha }
				desc = mpo_temujin_flavor.0020.desc.blood_brothers
			}
			triggered_desc = {
				trigger = { has_relation_friend = scope:jamukha }
				desc = mpo_temujin_flavor.0020.desc.friend
			}
			triggered_desc = {
				trigger = { has_relation_rival = scope:jamukha }
				desc = mpo_temujin_flavor.0020.desc.rival
			}
			desc = mpo_temujin_flavor.0020.desc.fallback
		}
		desc = mpo_temujin_flavor.0020.desc.outro
	}
	theme = nomads
	override_background = {
		reference = mpo_campfire_steppe
	}
	left_portrait = {
		character = root
		animation = anger
		outfit_tags = { nightgown }
		camera = camera_event_very_left
	}
	right_portrait = {
		character = scope:jamukha
		animation = horse_conversing_left
		camera = camera_event_horse_right
	}
	window = scheme_successful_event_no_text
	
	trigger = {
		NOT = { has_variable = had_mpo_temujin_flavor_0020 }
		OR = {
			has_variable = had_mpo_temujin_flavor_0010
			AND = {
				NOT = { has_variable = had_mpo_temujin_flavor_0010 }
				character:mpo_mongol_1 = {
					NOR = {
						is_vassal_of = root
						is_tributary = root
					}
				}
			}
		}
		is_alive = yes
		is_ruler = yes
		character:mpo_mongol_1 = {
			is_alive = yes
			in_diplomatic_range = root
			is_ruler = yes
		}
	}

	immediate = {
		save_scope_as = temujin
		play_music_cue = "mx_cue_murder"
		set_variable = {
			name = had_mpo_temujin_flavor_0020
			value = character:mpo_mongol_1
		}
		character:mpo_mongol_1 = {
			save_scope_as = jamukha
		}
		if = {
			limit = {
				current_military_strength < scope:jamukha.current_military_strength
			}
			domicile ?= {
				change_herd = {
					value = scope:jamukha.domicile.herd
					multiply = 1.5
				}
			}
			add_prestige = major_prestige_gain # For MAA maintenance, mainly
			custom_tooltip = temujin_gain_from_defectors_tt
		}
		if = {
			limit = {
				has_relation_blood_brother = scope:jamukha
			}
			scope:jamukha = {
				add_character_flag = {
					flag = was_temujins_bro
					years = 30
				}
			}
		}
	}

	option = { # You who I once called brother
		name = mpo_temujin_flavor.0020.a
		reason = blood_brother
		add_internal_flag = special
		trigger = { has_relation_blood_brother = scope:jamukha }
		custom_tooltip = {
			text = mpo_temujin_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_temujin_flavor.0020.b
		custom_tooltip = {
			text = mpo_temujin_flavor.0020.b_murder
			set_variable = {
				name = temujin_jamukha_murder_var
				value = scope:jamukha
			}
		}
		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_temujin_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
		}
	}
	
	after = {
		if = { # Remove hooks
			limit = {
				scope:jamukha = {
					has_hook = root
				}
			}
			scope:jamukha = { remove_hook = { target = root } }
		}
		if = {
			limit = {
				has_hook = scope:jamukha
			}
			remove_hook = { target = scope:jamukha }
		}
		if = { # Remove Truce
			limit = {
				any_truce_target = { this = scope:jamukha }
			}
			cancel_truce_both_ways = scope:jamukha
		}
		custom_tooltip = mpo_temujin_flavor.0020.jamukha_gok_requirement
		if = {
			limit = { has_relation_blood_brother = scope:jamukha }
			custom_tooltip = {
				text = mpo_temujin_flavor.0010.aa_remove_blood_brother
				remove_relation_blood_brother = scope:jamukha
			}
		}
		else_if = {
			limit = { has_relation_friend = scope:jamukha }
			custom_tooltip = {
				text = mpo_temujin_flavor.0020.remove_friend
				remove_relation_friend = scope:jamukha
			}
		}
		if = {
			limit = { NOT = { has_relation_rival = scope:jamukha } }
			set_relation_rival = {
				target = scope:jamukha
				reason = rival_temujin_jamukha
			}
		}
		else_if = {
			limit = { has_relation_rival = scope:jamukha }
			set_relation_nemesis = {
				target = scope:jamukha
				reason = rival_temujin_jamukha
			}
		}
		else = {
			add_opinion = {
				target = root 
				modifier = hate_opinion
				opinion = -100
			}
		}
		custom_tooltip = {
			text = mpo_temujin_flavor.0020.cb.tt
			add_to_variable_list = {
				name = retaliation_cb_var_list
				target = scope:jamukha
			}
			scope:jamukha = {
				add_to_variable_list = {
					name = retaliation_cb_var_list
					target = root
				}
			}
		}
		scope:jamukha = {
			trigger_event = mpo_jamukha_flavor.0020
		}
	}
}

#######################
# Borte announces she's pregnant
#######################
mpo_temujin_flavor.0030 = {
	type = character_event
	title = mpo_temujin_flavor.0030.t
	desc = mpo_temujin_flavor.0030.desc
	theme = pregnancy
	left_portrait = {
		character = root
		animation = anger
	}
	right_portrait = {
		character = scope:borte
		animation = worry
	}
	lower_right_portrait = scope:mergid
	
	trigger = {
		NOT = { has_variable = had_mpo_temujin_flavor_0030 } # To make sure it triggers even if you migrate straight away and lose the event time window
		character:172004 = {
			is_alive = yes
			is_spouse_of = root
			is_pregnant = no
		}
		any_neighboring_top_liege_realm_owner = {
			NOT = { has_relation_rival = root }
		}
	}

	immediate = {
		play_music_cue = "mx_cue_personal_negative"
		set_variable = had_mpo_temujin_flavor_0030
		character:172004 = {
			save_scope_as = borte
		}
		if = {
			limit = {
				character:303116 = {
					is_alive = yes
					NOT = { has_relation_rival = root }
				}
			}
			character:303116 = {
				save_scope_as = mergid
			}
		}
		else_if = {
			limit = {
				any_ruler = {
					dynasty = dynasty:2001144
					NOT = { has_relation_rival = root }
				}
			}
			random_ruler = {
				limit = {
					dynasty = dynasty:2001144
					NOT = { has_relation_rival = root }
				}
				save_scope_as = mergid
			}
		}
		else = {
			random_neighboring_top_liege_realm_owner = {
				limit = { NOT = { has_relation_rival = root } }
				save_scope_as = mergid
			}
		}
		scope:borte = {
			custom_tooltip = mpo_temujin_flavor.0030.pregnancy_tt
			hidden_effect = {
				make_pregnant = {
					father = scope:mergid
				}
			}
			set_variable = borte_first_child_var
		}
	}

	option = { # I hate those guys
		name = mpo_temujin_flavor.0030.a
		set_relation_rival = {
			target = scope:mergid
			reason = rival_temujin_mergid
		}
		custom_tooltip = {
			text = mpo_temujin_flavor.0030.a.tt
			add_to_variable_list = {
				name = retaliation_cb_var_list
				target = scope:mergid
			}
		}
		add_dread = medium_dread_gain
		stress_impact = {
			vengeful = major_stress_impact_loss
			compassionate = medium_stress_impact_gain
		}

		ai_chance = {
			base = 0 # To prevent AI Temüjin from being murdered immediately
		}
	}

	option = { # Let's forget about that, you are more important
		name = mpo_temujin_flavor.0030.b
		if = {
			limit = {
				NOT = { has_relation_lover = scope:borte }
			}
			set_relation_lover = {
				target = scope:borte
				reason = lover_temujin_borte
			}
		}
		else = {
			scope:borte = {
				add_opinion = {
					target = root
					modifier = grateful_opinion
					opinion = 20
				}
			}
		}
		set_relation_wedding_very_good_fertility = scope:borte
		stress_impact = {
			compassionate = major_stress_impact_loss
			vengeful = medium_stress_impact_gain
		}

		ai_chance = {
			base = 100
		}
	}

	option = { # I could not care less
		name = mpo_temujin_flavor.0030.c
		scope:borte = {
			add_opinion = {
				target = root
				modifier = upset_opinion
				opinion = -25
			}
		}
		stress_impact = {
			callous = major_stress_impact_loss
			compassionate = major_stress_impact_gain
			vengeful = major_stress_impact_gain
		}
		ai_chance = {
			base = 0
		}
	}
}

