namespace = martial_authority

##################################################

#Martial Authority Lifestyle events

	# 5000		- You visit some baronies or go partying.
	# 8000		- Your child joins a tourney
##################################################

##################################################
# Touring the Backwaters
# by Ewan Cowhig Croft
# 5000
##################################################

scripted_trigger martial_authority_5000_minor_barons = {
	is_available = yes
	highest_held_title_tier = tier_barony
	is_powerful_vassal = no
}

scripted_trigger martial_authority_5000_powerful_vassal = {
	is_available = yes
	is_at_war = no
	NOT = { has_relation_rival = root }
}

#You visit some baronies or go partying with an important vassal.
	#by Ewan Cowhig Croft
martial_authority.5000 = {
	type = character_event
	title = martial_authority.5000.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					OR = {
						faith = { religion_tag = christianity_religion }
						faith = { religion_tag = dualism_religion }
						faith = { religion_tag = islam_religion }
						faith = { religion_tag = hellenism_religion }
						faith = { religion_tag = judaism_religion }
						faith = { religion_tag = zoroastrianism_religion }
						faith = { religion_tag = zunism_religion }
						faith = { religion_tag = hinduism_religion }
					}
				}
				desc = martial_authority.5000.authoritative_religion.desc
			}
			desc = martial_authority.5000.relaxed_religion.desc
		}
	}
	theme = martial_authority_focus
	left_portrait = {
		character = root
		animation = stress
	}
	right_portrait = {
		character = scope:party_vassal
		animation = beg
	}
	lower_left_portrait = scope:baron_1
	lower_center_portrait = scope:baron_2
	lower_right_portrait = scope:baron_3

	trigger = {
		is_at_war = no
		NOT = { has_character_flag = had_event_martial_control_5000 }
		any_vassal = {
			martial_authority_5000_minor_barons = yes
			save_temporary_scope_as = tmp_baron_1
		}
		any_vassal = {
			martial_authority_5000_minor_barons = yes
			primary_title.county != scope:tmp_baron_1.primary_title.county
			save_temporary_scope_as = tmp_baron_2
		}
		any_vassal = {
			martial_authority_5000_minor_barons = yes
			NOR = {
				primary_title.county = scope:tmp_baron_1.primary_title.county
				primary_title.county = scope:tmp_baron_2.primary_title.county
			}
		}
		any_powerful_vassal = { martial_authority_5000_powerful_vassal = yes }
	}

	weight_multiplier = {
		base = 1
		upweight_for_focus_modifier = { FOCUS = martial_authority_focus }
		downweight_for_focus_modifier = { FOCUS = martial_chivalry_focus }
		downweight_for_focus_modifier = { FOCUS = martial_strategy_focus }
	}

	immediate = {
		add_character_flag = {
			flag = had_event_martial_control_5000
			days = 1825
		}
		every_vassal = {
			limit = {martial_authority_5000_minor_barons = yes }
			add_to_list = baron_initial_list
		}
		random_in_list = {
			list = baron_initial_list
			limit = { primary_title.county.county_control < full_county_control }
			alternative_limit = { always = yes }
			weight = {
				base = 1
				modifier = {
					add = {
						value = 120
						subtract = primary_title.county.county_control
					}
				}
			}
			save_scope_as = baron_1
			scope:baron_1 = {
				primary_title.county = { save_scope_as = baron_1_lands }
			}
			add_to_list = baron_final_list
		}
		random_in_list = {
			list = baron_initial_list
			limit = {
				NOR = {
					this = scope:baron_1
					primary_title.county = scope:baron_1.primary_title.county
				}
				primary_title.county.county_control < full_county_control
			}
			alternative_limit = {
				this != scope:baron_1
			}
			weight = {
				base = 1
				modifier = {
					add = {
						value = 120
						subtract = primary_title.county.county_control
					}
				}
			}
			save_scope_as = baron_2
			scope:baron_2 = {
				primary_title.county = { save_scope_as = baron_2_lands }
			}
			add_to_list = baron_final_list
		}
		random_in_list = {
			list = baron_initial_list
			limit = {
				NOR = {
					this = scope:baron_1
					primary_title.county = scope:baron_1.primary_title.county
					this = scope:baron_2
					primary_title.county = scope:baron_2.primary_title.county
				}
				primary_title.county.county_control < full_county_control
			}
			alternative_limit = {
				NOR = {
					this = scope:baron_1
					this = scope:baron_2
				}
			}
			weight = {
				base = 1
				modifier = {
					add = {
						value = 120
						subtract = primary_title.county.county_control
					}
				}
			}
			save_scope_as = baron_3
			scope:baron_3 = {
				primary_title.county = { save_scope_as = baron_3_lands }
			}
			add_to_list = baron_final_list
		}
		random_powerful_vassal = {
			limit = {
				martial_authority_5000_powerful_vassal = yes
				has_relation_potential_friend = root
				NOR = {
					this = scope:baron_1
					this = scope:baron_2
					this = scope:baron_3
				}
			}
			alternative_limit = {
				martial_authority_5000_powerful_vassal = yes
				NOR = {
					this = scope:baron_1
					this = scope:baron_2
					this = scope:baron_3
				}
			}
			save_scope_as = party_vassal
		}
	}

	option = {
		name = martial_authority.5000.a
		every_in_list = {
			list = baron_final_list
			custom = martial_authority.5000.a.characters_baron_final_list
			add_opinion = {
				modifier = pleased_opinion
				opinion = 30
				target = root
			}
		}
		#Effects separated for purely aesthetic reasons.
		every_in_list = {
			list = baron_final_list
			custom = martial_authority.5000.a.land_baron_final_list
			primary_title.county = {
				change_county_control = 30
				add_county_modifier = {
					modifier = authority_central_control_modifier
					years = 15
				}
			}
		}
		stress_impact = { lazy = medium_stress_impact_gain }
		ai_chance = {
			base = 100
			ai_energy_target_modifier = { VALUE = 100 }
			ai_honor_target_modifier = { VALUE = 50 }
		}
	}
	option = {
		name = martial_authority.5000.b
		progress_towards_friend_effect = {
			CHARACTER = scope:party_vassal
			OPINION = 0
			REASON = friend_attended_party
		}
		scope:party_vassal = {
			add_opinion = {
				modifier = pleased_opinion
				opinion = 20
				target = root
			}
		}
		every_in_list = {
			list = baron_final_list
			custom = martial_authority.5000.a.characters_baron_final_list
			add_opinion = {
				modifier = insult_opinion
				opinion = -30
				target = root
			}
		}
		stress_impact = {
			shy = medium_stress_impact_gain
			temperate = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_energy_target_modifier = { VALUE = -100 }
			ai_honor_target_modifier = { VALUE = -50 }
		}
	}
}

##################################################
# Child Tourney
# by Isabella Welch
# 8000
##################################################

martial_authority.8000 = {
	type = character_event
	title = martial_authority.8000.t
	desc = martial_authority.8000.desc
	theme = martial_authority_focus
	left_portrait = {
		character = root
		animation = dismissal
	}
	right_portrait = {
		character = player_heir
		animation = personality_bold
	}
	override_background = {
		reference = army_camp
	}
	
	trigger = {
		NOR = {
			has_character_flag = had_event_martial_authority_8000
			has_dlc_feature = tours_and_tournaments
		}
		exists = player_heir
		root = { is_parent_of = player_heir }
		player_heir = {
			age > 4
			age < 13
			NOR = {
				has_trait = humble
				has_trait = shy
				has_trait = craven
				has_trait = compassionate
				has_trait = disfigured
				has_trait = one_legged
				has_trait = incapable
				AND = {
					has_trait = brave
					has_trait = arrogant
					has_trait = wrathful
				}
			}
			is_ai = yes
			number_of_personality_traits < personality_trait_limit
		}
		any_knight = {
			count > 2
			is_ai = yes
		}
		exists = cp:councillor_marshal
		cp:councillor_marshal = {
			is_ai = yes
			is_available = yes
		}
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		root = {
			add_character_flag = had_event_martial_authority_8000
		}
		cp:councillor_marshal = {
			save_scope_as = marshal
		}
		player_heir = {
			save_scope_as = fighting_child
		}
	}

	option = { #Order your warriors to pull their punches
		name = martial_authority.8000.a
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 1
				ai_boldness = 2
			}
		}
		random_list = {
			60 = {
				scope:fighting_child = {
					random_list = {
						10 = {
							trigger = { NOT = { has_trait = brave} }
							root = {
								send_interface_toast = {
									left_icon = scope:fighting_child
									title = martial_authority_child_trait_gain
									scope:fighting_child = { add_trait = brave }
								}
							}
							#hidden_effect = {
							#	root = {
							#		send_interface_toast = {
							#			left_icon = scope:fighting_child
							#			title = martial_authority_child_t#rait_gain#
							#			show_as_t#ooltip = { scope:#fighting_#child = { add_tra#it = #brave } }#
							#		}#
							#	}
							#}
							#add_trait = brave
						}
						10 = {
							trigger = { NOT = { has_trait = arrogant } }
							root = {
								send_interface_toast = {
									left_icon = scope:fighting_child
									title = martial_authority_child_trait_gain
									scope:fighting_child = { add_trait = arrogant }
								}
							}
						}
						10 = {
							trigger = { NOT = { has_trait = wrathful }	}
							root = {
								send_interface_toast = {
									left_icon = scope:fighting_child
									title = martial_authority_child_trait_gain
									scope:fighting_child = { add_trait = wrathful }
								}
							}
						}
					}
				}
			}
			40 = {
				desc = martial_authority.8000.tt
				custom_tooltip = martial_authority.8000.a.tt
				trigger_event = {
					id = martial_authority.8100
					days = { 3 4 }
				}
			}
		}
	}

	option = {
		name = martial_authority.8000.b
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = -2
				ai_boldness = 2
			}
		}
		random_list = {
			10 = {
				desc = martial_authority.8000.tt
				modifier = {
					factor = 2
					scope:fighting_child = {
						has_trait = brave
					}
				}
				scope:fighting_child = {
					add_martial_skill = 2
				}
				trigger_event = {
					id = martial_authority.8100
					days = { 3 4 }
				}
			}
			30 = {
				desc = martial_authority.8000.tt.failure
				modifier = {
					factor = 2
					scope:fighting_child = {
						OR = {
							has_trait = clubfooted
							has_trait = hunchbacked
							has_trait = dwarf
							has_trait = incapable
							has_trait = blind
							has_trait = one_eyed
							has_trait = disfigured
						}
					}
				}
				scope:fighting_child = {
					custom_tooltip = martial_authority.8000_injury
					hidden_effect = {
						random_list = {
							10 = {
								trigger = { NOT = { has_trait = one_eyed }	}
								add_trait = one_eyed
								hidden_effect = {
									root = {
										send_interface_toast = {
											left_icon = scope:fighting_child
											title = martial_authority_one_eyed_child_title
											custom_tooltip = martial_authority_one_eyed_child
										}
									}
								}
							}
		
							10 = {
								trigger = { NOT = { has_trait = disfigured } }
								add_trait = disfigured
								hidden_effect = {
									root = {
										send_interface_toast = {
											left_icon = scope:fighting_child
											title = martial_authority_disfigured_child_title
											custom_tooltip = martial_authority_disfigured_child
										}
									}
								}
							}
						}
					}
				}
			}
			30 = {
				desc = martial_authority.8000.tt.failure
				custom_tooltip = martial_authority_unremarkable_child
				hidden_effect = {
					send_interface_toast = {
						left_icon = scope:fighting_child
						title = martial_authority_unremarkable_child_title
						custom_tooltip = martial_authority_unremarkable_child
					}
				}
			}
		}
	}
	option = {
		name = martial_authority.8000.c
		trigger = {
			scope:fighting_child = { can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root } }
		}
		scope:fighting_child = {
			add_opinion = {
				target = root
				opinion = -15
				modifier = neglected_opinion
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 0.5
			}
		}
	}
	option = {
		name = martial_authority.8000.d
		trigger = {
			scope:fighting_child = { NOT = { can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root } } }
		}
		scope:fighting_child = {
			add_opinion = {
				target = root
				opinion = -15
				modifier = neglected_opinion
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 0.5
			}
		}
	}
}

martial_authority.8100 = { # Your heir kills one of your knights
	type = character_event
	title = martial_authority.8000.t
	desc = martial_authority.8100.desc
	theme = martial_authority_focus
	left_portrait = {
		character = scope:marshal
		animation = worry
	}
	right_portrait = {
		character = scope:fighting_child
		animation = happiness
	}
	lower_left_portrait = {
		character = scope:murdered_knight
	}
	override_background = {
		reference = army_camp
	}
	trigger = {
		any_knight = { 
			is_available = yes
			is_ai = yes
			this != scope:marshal
		}
		scope:marshal = { is_available = yes }
		scope:fighting_child = { is_available = yes }
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		random_knight = {
			limit = {
				is_available = yes
				is_ai = yes
				this != scope:marshal
			}
			weight = {
				base = 1
				modifier = {
					add = 8
					prowess <15
				}
				modifier = {
					add = 20
					prowess <10
				}
			}
			save_scope_as = murdered_knight
		}
		player_heir = {
			add_trait = lifestyle_blademaster
			if = {
				limit = {
					NOR = {
						has_trait = wrathful
						has_trait = sadistic
					}
				}
				add_stress = major_stress_gain
			}
		}
		scope:murdered_knight = {
			death = { 
				killer = scope:fighting_child 
				death_reason = death_duel
			}
		}
		every_knight = {
			custom = custom.every_knight
			add_opinion = {
				target = scope:fighting_child
				opinion = -40
				modifier = hate_opinion
			}
		}
		scope:marshal = {
			add_opinion = {
				target = scope:fighting_child
				opinion = -40
				modifier = hate_opinion
			}
		}
	}

	option = { #Good work!
		name = martial_authority.8100.a
		add_dread = medium_dread_gain
		scope:fighting_child = {
			add_opinion = {
				target = root
				opinion = 30
				modifier = supportive_parent
			} 
		}
		scope:marshal = {
			add_opinion = {
				target = root
				opinion = -10
				modifier = insult_opinion
			}
		}
		every_knight = {
			custom = custom.every_knight
			add_opinion = {
				target = root
				opinion = -20
				modifier = insult_opinion
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 0.5
			}
		}
	}

	option = { #Good god!
		name = martial_authority.8100.c
		add_dread = medium_dread_loss
		scope:marshal = {
			add_opinion = {
				target = root
				opinion = 5
				modifier = respect_opinion
			}
		}
		every_knight = {
			custom = custom.every_knight
			add_opinion = {
				target = root
				opinion = 5
				modifier = respect_opinion
			}
		}
		scope:fighting_child = {
			add_opinion = {
				target = root
				opinion = -15
				modifier = insult_opinion
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 3
			}
		}
	}
}
