namespace = ach_yearly_events

ach_yearly_events.1001 = {
	type = character_event
	title = ach_yearly_events.1001.t
	desc = ach_yearly_events.1001.desc
	theme = stewardship
	left_portrait = {
		character = root
		animation = happy_teacher
	}
	right_portrait = {
		character = scope:liege
		animation = thinking
	}

	trigger = {
		#Standard checks
		basic_is_valid_for_yearly_events_trigger = yes
		is_adult = yes
		is_councillor = yes
		has_council_position = councillor_steward
		liege = {
			is_available_ai = yes
			age >= 10
		}
		stewardship > liege.stewardship
		stewardship >= decent_skill_rating
	}

	immediate = {
		liege = {
			save_scope_as = liege
		}
	}

	weight_multiplier = {
		modifier = {
			factor = 0.1
			is_ai = yes
		}
	}

	cooldown = { years = 20 }

	# Well, you could always give it to me to use...
	option = {
		name = ach_yearly_events.1001.a

		trigger = {
			OR = {
				has_trait = deceitful
				intrigue >= high_skill_rating
			}
			NOR = {
				has_trait = just
				has_trait = honest
			}
			scope:liege = {
				is_ai = yes
			}
		}

		duel = {
			skill = intrigue
			target = scope:liege
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
				desc = ach_yearly_events.1001.a.success
				modifier = {
					add = 20
					scope:liege = {
						has_trait = trusting
					}
				}
				send_interface_toast = {
					title = ach_yearly_events.1001.a.success
					left_icon = root
					right_icon = scope:liege

					scope:liege = {
						pay_short_term_gold = {
							target = root
							gold = minor_gold_value
						}
					}
				}
			}
			50 = {
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
				}
				desc = ach_yearly_events.1001.a.failure
				modifier = {
					add = 10
					scope:liege = {
						has_trait = paranoid
					}
				}
				send_interface_toast = {
					title = ach_yearly_events.1001.a.failure
					left_icon = root
					right_icon = scope:liege

					reverse_add_opinion = {
						modifier = suspicion_opinion
						target = scope:liege
						opinion = -25
					}
				}
			}
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_honor = -0.5
				ai_boldness = 0.5
				ai_greed = 1
			}
		}
	}

	# Being cautious is useful for a rainy day
	option = {
		name = ach_yearly_events.1001.b

		add_character_modifier = {
			modifier = ach_spending_advice_modifier
			years = 10
		}

		if = {
			limit = {
				scope:liege = {
					is_ai = yes
				}
			}
			scope:liege = {
				add_character_modifier = {
					modifier = ach_cautious_spender_modifier
					years = 10
				}
			}
		}

		stress_impact = {
			lazy = minor_stress_impact_gain
			impatient = minor_stress_impact_gain
			patient = minor_stress_impact_loss
			diligent = minor_stress_impact_loss
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = -1
				ai_greed = -0.5
			}
		}
	}

	# You're the king, go crazy bro!
	option = {
		name = ach_yearly_events.1001.c

		add_character_modifier = {
			modifier = ach_spending_advice_modifier
			years = 10
		}

		if = {
			limit = {
				scope:liege = {
					is_ai = yes
				}
			}
			scope:liege = {
				add_character_modifier = {
					modifier = ach_extravagant_spender_modifier
					years = 10
				}
			}
		}

		stress_impact = {
			lazy = minor_stress_impact_gain
			impatient = minor_stress_impact_gain
			patient = minor_stress_impact_loss
			diligent = minor_stress_impact_loss
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 1
				ai_greed = 0.5
			}
		}
	}

	# Perhaps a balanced approach?
	option = {
		name = ach_yearly_events.1001.d

		duel = {
			skill = diplomacy
			target = scope:liege

			50 = { #Your liege is impressed
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
				}
				desc = ach_yearly_events.1001.d.success
				modifier = {
					add = 20
					scope:liege = {
						has_trait = ambitious
					}
				}
				send_interface_toast = {
					title = ach_yearly_events.1001.d.success
					left_icon = root
					right_icon = scope:liege

					add_prestige = medium_prestige_gain

					add_character_modifier = {
						modifier = ach_budgeting_mentor_modifier
						years = 10
					}

					if = {
						limit = {
							scope:liege = {
								is_ai = yes
							}
						}
						scope:liege = {
							add_character_modifier = {
								modifier = ach_balanced_budget_modifier
								years = 10
							}
						}
					}
				}
			}
			50 = { #Your liege is unimpressed
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
				}
				desc = ach_yearly_events.1001.d.failure
				modifier = {
					add = 10
					scope:liege = {
						has_trait = content
					}
				}
				send_interface_toast = {
					title = ach_yearly_events.1001.d.failure
					left_icon = root
					right_icon = scope:liege

					add_prestige = minor_prestige_loss

					add_character_modifier = {
						modifier = ach_fence_sitter_modifier
						years = 10
					}
				}
			}
		}

		stress_impact = {
			content = minor_stress_impact_loss
			ambitious = minor_stress_impact_gain
		}

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

scripted_trigger ach_yearly_events_1002_non_joined_trigger = {
	NOR = {
		scope:faction = {
			any_faction_member = {
				this = scope:temp_vassal
			}
		}
		this = root
	}
	can_join_faction = scope:faction
	is_incapable = no
	opinion = {
		target = liege
		value <= 30
	}
	is_ai = yes
}

#You're the Chancellor and your liege has a faction
ach_yearly_events.1002 = {
	type = character_event
	title = ach_yearly_events.1002.t
	desc = ach_yearly_events.1002.desc
			
	theme = diplomacy
	override_background = {
		reference = ep3_relaxing_tent
	}
	left_portrait = {
		character = scope:unjoined_vassal
		animation = scheme
	}
	right_portrait = {
		character = scope:faction_member
		animation = bribing
	}
	lower_center_portrait = scope:liege

	cooldown = { years = 10 }

	trigger = {
		is_independent_ruler = no
		liege = {
			cp:councillor_chancellor ?= {
				this = root
			}
			any_targeting_faction = {
				NOT = {
					any_faction_member = {
						this = root
					}	
				}
				any_faction_member = {
					count >= 2
				}
				any_faction_member = {
					is_ai = yes
					is_a_faction_leader = no
				}
				save_temporary_scope_as = temp_faction
			}
			any_vassal = {
				save_temporary_scope_as = temp_vassal
				NOR = {
					scope:temp_faction = {
						any_faction_member = {
							this = scope:temp_vassal
						}
					}
					this = root
				}
				can_join_faction = scope:temp_faction
				is_incapable = no
				opinion = {
					target = liege
					value <= 30
				}
				is_ai = yes
			}
			NOT = {
				has_character_flag = had_ach_yearly_events_1002
			}
		}
		basic_is_valid_for_yearly_events_trigger = yes
	}
	immediate = {
		liege = {
			save_scope_as = liege
			add_character_flag = {
				flag = had_ach_yearly_events_1002
				years = 10
			}
			random_targeting_faction = {
				limit = {
					NOT = {
						any_faction_member = {
							this = root
						}
					}
					any_faction_member = {
						count >= 2
					}
				}
				save_scope_as = faction
				random_faction_member = {
					limit = {
						is_a_faction_leader = no
						is_ai = yes
					}
					save_scope_as = faction_member
				}
			}
			random_vassal = {
				limit = {
					scope:faction = {
						OR = {
							faction_is_type = independence_faction
							faction_is_type = nation_fracturing_faction
						}
					}
					save_temporary_scope_as = temp_vassal
					primary_title = {
						NOT = {
							target_is_de_jure_liege_or_above = scope:liege.primary_title
						}
					}
					is_powerful_vassal_of = scope:liege
					ach_yearly_events_1002_non_joined_trigger = yes
					opinion = {
						target = liege
						value < 0
					}
				}
				alternative_limit = {
					scope:faction = {
						OR = {
							faction_is_type = independence_faction
							faction_is_type = nation_fracturing_faction
						}
					}
					save_temporary_scope_as = temp_vassal
					primary_title = {
						NOT = {
							target_is_de_jure_liege_or_above = scope:liege.primary_title
						}
					}
					is_powerful_vassal_of = scope:liege
					ach_yearly_events_1002_non_joined_trigger = yes
				}
				alternative_limit = {
					scope:faction = {
						OR = {
							faction_is_type = independence_faction
							faction_is_type = nation_fracturing_faction
						}
					}
					save_temporary_scope_as = temp_vassal
					primary_title = {
						NOT = {
							target_is_de_jure_liege_or_above = scope:liege.primary_title
						}
					}
					ach_yearly_events_1002_non_joined_trigger = yes
					opinion = {
						target = liege
						value < 0
					}
				}
				alternative_limit = {
					scope:faction = {
						OR = {
							faction_is_type = independence_faction
							faction_is_type = nation_fracturing_faction
						}
					}
					save_temporary_scope_as = temp_vassal
					primary_title = {
						NOT = {
							target_is_de_jure_liege_or_above = scope:liege.primary_title
						}
					}
					ach_yearly_events_1002_non_joined_trigger = yes
				}
				alternative_limit = {
					save_temporary_scope_as = temp_vassal
					is_powerful_vassal_of = scope:liege
					opinion = {
						target = liege
						value <= -50
					}
					ach_yearly_events_1002_non_joined_trigger = yes
				}
				alternative_limit = {
					save_temporary_scope_as = temp_vassal
					is_powerful_vassal_of = scope:liege
					opinion = {
						target = liege
						value < 0
					}
					ach_yearly_events_1002_non_joined_trigger = yes
				}
				alternative_limit = {
					save_temporary_scope_as = temp_vassal
					opinion = {
						target = liege
						value <= -50
					}
					ach_yearly_events_1002_non_joined_trigger = yes
				}
				alternative_limit = {
					save_temporary_scope_as = temp_vassal
					ach_yearly_events_1002_non_joined_trigger = yes
					opinion = {
						target = liege
						value < 0
					}
				}
				alternative_limit = {
					save_temporary_scope_as = temp_vassal
					ach_yearly_events_1002_non_joined_trigger = yes
				}
				save_scope_as = unjoined_vassal
			}
		}
	}
	#You're such a seasoned chancellor, you can stop other players from joining
	option = {
		name = ach_yearly_events.1002.a
		trigger = { diplomacy >= very_high_skill_rating }
		add_diplomacy_lifestyle_xp = medium_lifestyle_xp
		scope:liege = {
			send_interface_message = {
				type = msg_chancellor_task_good
				title = chancellor_isolates_factions_title
				desc = chancellor_isolates_factions_desc
				left_icon = root
				
				add_character_modifier = {
					modifier = ach_chancellor_isolating_factions_modifier
					years = 5
				}
				scope:unjoined_vassal = {
					add_opinion = {
						modifier = loyalty_opinion
						target = scope:liege
						opinion = 40
					}
				}
			}
		}
		stress_impact = {
			impatient = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_sociability = 0.5
				ai_energy = -0.5
			}
			modifier = {
				add = -50
				has_trait = impatient
			}
		}
	}
	#Try to stop other characters from joining
	option = {
		name = ach_yearly_events.1002.b
		trigger = { diplomacy < very_high_skill_rating }
		add_diplomacy_lifestyle_xp = medium_lifestyle_xp
		duel = {
			skill = diplomacy
			value = medium_skill_rating
			50 = { #You reorganize the administration and plan for the future
				desc = ach_yearly_events.1002.b.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				
				send_interface_toast = {
					type = event_toast_effect_good
					title = ach_yearly_events.1002.b.success
					left_icon = root
					right_icon = scope:liege
					
					scope:liege = {
						send_interface_message = {
							type = msg_chancellor_task_good
							title = chancellor_isolates_factions_title
							desc = chancellor_isolates_factions_desc
							left_icon = root
							
							add_character_modifier = {
								modifier = ach_chancellor_isolating_factions_modifier
								years = 5
							}
							scope:unjoined_vassal = {
								add_opinion = {
									modifier = loyalty_opinion
									target = scope:liege
									opinion = 40
								}
							}
						}
					}
				}
			}
			50 = { #You fail so bad you drive the character into the faction
				desc = ach_yearly_events.1002.b.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				send_interface_toast = {
					type = event_toast_effect_bad
					title = ach_yearly_events.1002.b.failure
					left_icon = root
					right_icon = scope:liege
					add_stress = minor_stress_gain
					scope:unjoined_vassal = {
						join_faction = scope:faction
					}
				}
			}
		}
		stress_impact = {
			impatient = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_sociability = 0.5
				ai_energy = -0.5
			}
			modifier = {
				add = -50
				has_trait = impatient
			}
			modifier = {
				add = 50
				diplomacy > high_skill_rating
			}
			modifier = {
				add = 50
				diplomacy >= extremely_high_skill_rating
			}
			modifier = {
				add = -50
				diplomacy < medium_skill_rating
			}
			modifier = {
				factor = 0
				diplomacy <= low_skill_rating
			}
		}
	}
	#They have a point...
	option = {
		name = ach_yearly_events.1002.c
		flavor = ach_yearly_events.1002.c.flavor
		trigger = {
			can_join_faction = scope:faction
			OR = {
				NOT = {
					scope:faction = {
						OR = {
							faction_is_type = independence_faction
							faction_is_type = nation_fracturing_faction
						}
					}
				}
				OR = {
					has_trait = ambitious
					has_trait = greedy
					has_trait = arrogant
					has_trait = arbitrary
					has_trait = fickle
					has_trait = eccentric
					has_trait = disloyal
					primary_title = {
						NOT = {
							target_is_de_jure_liege_or_above = scope:liege.primary_title
						}
					}
				}
			}
		}
		add_internal_flag = dangerous
		join_faction = scope:faction
		scope:unjoined_vassal = {
			join_faction = scope:faction
		}
		reverse_add_opinion = {
			modifier = betrayal_opinion
			target = scope:liege
			opinion = -30
		}
		
		add_joined_faction_discontent = 20
		stress_impact = {
			arrogant = miniscule_stress_impact_loss
			loyal = minor_stress_impact_gain
			trusting = medium_stress_impact_gain
			just = medium_stress_impact_gain
			content = medium_stress_impact_gain
			humble = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_honor = -1
				ai_greed = 1
			}
			modifier = {
				add = -75
				scope:faction = {
					OR = {
						faction_is_type = independence_faction
						faction_is_type = nation_fracturing_faction
					}
				}
				primary_title = {
					target_is_de_jure_liege_or_above = scope:liege.primary_title
				}
			}
			modifier = {
				add = 100
				scope:faction = {
					OR = {
						faction_is_type = independence_faction
						faction_is_type = nation_fracturing_faction
					}
				}
				primary_title = {
					NOT = {
						target_is_de_jure_liege_or_above = scope:liege.primary_title
					}
				}
			}
			modifier = {
				add = 50
				has_trait = disloyal
			}
			modifier = {
				add = -50
				has_trait = loyal
			}
			modifier = {
				factor = 0
				OR = {
					has_trait = trusting
					has_trait = just
					has_trait = content
					has_trait = humble
				}
			}
		}
	}
	#Remove existing faction member
	option = {
		name = ach_yearly_events.1002.d
		flavor = ach_yearly_events.1002.d.flavor
		reverse_add_opinion = {
			target = scope:liege
			modifier = grateful_opinion
			opinion = 30
		}
		scope:liege = {
			send_interface_message = {
				type = msg_chancellor_task_good
				title = chancellor_removes_faction_member_title
				desc = chancellor_removes_faction_member_desc
				left_icon = root
				
				scope:faction_member = {
					leave_faction = scope:faction
				}
			}
		}
		#Modifier that applies effect which makes vassals less likely to join factions
		if = {
			limit = {
				scope:faction = {
					any_faction_member = {
						NOT = {
							this = scope:faction_member
						}
					}
				}
			}
			scope:faction = {
				every_faction_member = {
					custom = custom.every_scope_faction_member
					limit = {
						NOT = {
							this = scope:faction_member
						}
					}
					add_opinion = {
						modifier = angry_opinion
						target = root
						opinion = -20
					}
				}
			}
		}
		stress_impact = {
			patient = minor_stress_impact_gain
			craven = minor_stress_impact_gain
			gregarious = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_sociability = -0.5
				ai_energy = 0.5
			}
			modifier = {
				add = -50
				OR = {
					has_trait = patient
					has_trait = craven
					has_trait = gregarious
				}
			}
		}
	}
}

#You're the marshal and your liege just lost a big battle
ach_yearly_events.1003 = {
	type = character_event
	title = ach_yearly_events.1003.t
	desc = ach_yearly_events.1003.desc
			
	theme = martial
	override_background = {
		reference = battlefield
	}
	override_effect_2d = {
		trigger = {
			NOR = {
				scope:battle_province = {
					terrain = desert
				}
				scope:battle_province = {
					terrain = desert_mountains
				}
				scope:battle_province = {
					terrain = drylands
				}
				scope:battle_province = {
					terrain = oasis
				}
				scope:battle_province = {
					location_has_harsh_winter_trigger = yes
				}
			}
		}
		reference = rain	
	}
	left_portrait = {
		character = scope:commander
		triggered_animation = {
			trigger = {
				scope:commander = {
					NOT = { this = scope:liege }
				}
			}
			animation = sword_yield_start
		}
		triggered_animation = {
			trigger = {
				scope:commander = {
					this = scope:liege
				}
			}
			animation = war_over_loss
		}
	}
	lower_right_portrait = scope:foe
	lower_left_portrait = scope:show_liege

	trigger = {
		basic_is_valid_for_yearly_events_trigger = yes
		is_at_war = no
		liege = { is_landed = yes }
		has_council_position = councillor_marshal
	}
	immediate = {
		liege ?= {
			save_scope_as = liege
			add_character_flag = {
				flag = had_ach_yearly_events_1003
				years = 10
			}
		}
		if = {
			limit = {
				OR = {
					NOT = {
						exists = scope:commander
					}
					scope:commander = scope:liege
					scope:commander = root
				}
			}
			liege = {
				save_scope_as = commander
			}
		}
		else = {
			liege = {
				save_scope_as = show_liege
			}
		}	
	}
	cooldown = { years = 10 }

	#I AM GOOD MARSHAL AND CAN SORT THIS
	option = {
		name = ach_yearly_events.1003.a
		trigger = {
			martial >= very_high_skill_rating
		}
		add_martial_lifestyle_xp = medium_lifestyle_xp
		scope:liege = {
			send_interface_message = {
				type = msg_marshal_task_good
				title = marshal_aids_troop_recovery_title
				desc = marshal_aids_troop_recovery_desc
				left_icon = root
				add_character_modifier = {
					modifier = ach_marshal_reconstituting_army_modifier
					years = 2
				}
			}
		}
		stress_impact = {
			lazy = minor_stress_impact_gain
			fickle = minor_stress_impact_gain
		}
		ai_chance = {
			base = 200
			ai_value_modifier = {
				ai_energy = 1
				ai_honor = 0.5
				ai_rationality = 0.5
			}
			modifier = {
				opinion = {
					target = liege
					value < -50
				}
				add = -50
			}
			modifier = {
				opinion = {
					target = liege
					value < 0
				}
				add = -25
			}
			modifier = {
				opinion = {
					target = liege
					value >= 50
				}
				add = 25
			}
			modifier = {
				opinion = {
					target = liege
					value > 75
				}
				add = 50
			}
			modifier = {
				OR = {
					has_trait = lazy 
					has_trait = fickle
				}
				add = -50
			}
			modifier = {
				opinion = {
					target = liege
					value < -80
				}
				factor = 0
			}
		}
	}
	#I AM HONORABLE AND WILL FIGHT TOO
	option = {
		name = ach_yearly_events.1003.b
		save_scope_as = marshal
		scope:liege = {
			send_interface_message = {
				type = msg_marshal_task_good
				title = marshal_joins_war_title
				desc = marshal_joins_war_desc
				left_icon = root
				scope:liege_war = {
					if = {
						limit = {
							primary_attacker = scope:liege
						}
						add_attacker = root
					}
					else = {
						add_defender = root
					}
				}
			}
			every_vassal = {
				custom = custom.every_fellow_vassal
				limit = {
					NOT = {
						this = root
					}
				}
				add_opinion = {
					target = root
					modifier = impressed_opinion
					opinion = 10
				}
			}
		}
		reverse_add_opinion = {
			modifier = grateful_opinion
			target = scope:liege
			opinion = 25
		}

		if = {
			limit = {
				OR = {
					NOT = { has_trait = loyal }
					AND = {
						NOT = { has_trait = unyielding_defender }
						scope:liege_war = {
							primary_defender = scope:liege
						}
					}
					AND = {
						NOT = { has_trait = aggressive_attacker }
						scope:liege_war = {
							primary_attacker = scope:liege
						}
					}
				}
			}
			random_list = {
				10 = {
					trigger = {
						NOT = { has_trait = unyielding_defender }
						scope:liege_war = {
							primary_defender = scope:liege
						}
					}
					add_trait = unyielding_defender
				}
				10 = {
					trigger = {
						NOT = { has_trait = aggressive_attacker }
						scope:liege_war = {
							primary_attacker = scope:liege
						}
					}
					add_trait = aggressive_attacker
				}
				20 = {
					trigger = {
						NOT = { has_trait = loyal }
					}
					add_trait = loyal
				}
				70 = {}
			}
		}
		else = {
			add_prestige = minor_prestige_gain
		}
		stress_impact = {
			arbitrary = major_stress_impact_gain
			craven = major_stress_impact_gain
			lazy = medium_stress_impact_gain
			calm = minor_stress_impact_gain
			paranoid = minor_stress_impact_gain
			fickle = minor_stress_impact_gain
		}
		ai_chance = {
			base = 0
			ai_value_modifier = {
				ai_honor = 1
				ai_compassion = 1
				ai_boldness = 1
			}
			modifier = {
				opinion = {
					target = liege
					value < -50
				}
				add = -100
			}
			modifier = {
				opinion = {
					target = liege
					value < 0
				}
				add = -50
			}
			modifier = {
				opinion = {
					target = liege
					value >= 50
				}
				add = 50
			}
			modifier = {
				opinion = {
					target = liege
					value >= 75
				}
				add = 50
			}
			modifier = {
				OR = {
					has_trait = calm
					has_trait = paranoid
					has_trait = fickle
				}
				add = -50
			}
			modifier = {
				OR = {
					has_trait = arbitrary
					has_trait = craven
					has_trait = lazy
					opinion = {
						target = liege
						value < -50
					}
				}
			}
		}
	}
	#I'll try to help him recover... although I'm not great at marshaling
	option = {
		name = ach_yearly_events.1003.c
		trigger = {
			martial < very_high_skill_rating
		}
		show_unlock_reason = no
		add_martial_lifestyle_xp = medium_lifestyle_xp
		duel = {
			skill = martial
			value = medium_skill_rating
			50 = { #The army is restored
				desc = ach_yearly_events.1003.c.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				send_interface_toast = {
					type = event_toast_effect_good
					title = ach_yearly_events.1003.c.success
					left_icon = root
					right_icon = scope:liege
					scope:liege = {
						send_interface_message = {
							type = msg_marshal_task_good
							title = marshal_aids_troop_recovery_title
							desc = marshal_aids_troop_recovery_desc
							left_icon = root
							add_character_modifier = {
								modifier = ach_marshal_reconstituting_army_modifier
								years = 2
							}
						}
					}
				}
			}
			50 = { #Everything remains in shambles
				desc = ach_yearly_events.1003.c.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				send_interface_toast = {
					type = event_toast_effect_bad
					title = ach_yearly_events.1003.c.failure
					left_icon = root
					right_icon = scope:liege
					add_prestige = minor_prestige_loss
				}
			}
		}
		stress_impact = {
			lazy = minor_stress_impact_gain
			fickle = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_energy = 1
				ai_honor = 0.5
				ai_rationality = 0.5
			}
			modifier = {
				opinion = {
					target = liege
					value < -50
				}
				add = -50
			}
			modifier = {
				opinion = {
					target = liege
					value < 0
				}
				add = -25
			}
			modifier = {
				opinion = {
					target = liege
					value >= 50
				}
				add = 25
			}
			modifier = {
				opinion = {
					target = liege
					value > 75
				}
				add = 50
			}
			modifier = {
				OR = {
					has_trait = lazy 
					has_trait = fickle
				}
				add = -50
			}
			modifier = {
				opinion = {
					target = liege
					value < -80
				}
				factor = 0
			}
		}
	}
	#My liege deserves this mess and so do his terrible troops
	option = {
		name = ach_yearly_events.1003.d
		flavor = ach_yearly_events.1003.d.flavor
		add_dread = minor_dread_gain
		reverse_add_opinion = {
			modifier = frustrated_opinion
			target = scope:liege
			opinion = -10
		}
		stress_impact = {
			compassionate = medium_stress_impact_gain
			generous = minor_stress_impact_gain
			diligent = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = -1
				ai_energy = -1
			}
			modifier = {
				add = -50
				OR = {
					has_trait = generous
				}
			}
			modifier = {
				factor = 0
				OR = {
					has_trait = diligent
					has_trait = compassionate
				}
			}
		}
	}
	after = {
		if = {
			limit = {
				exists = scope:foe
				is_at_war_with = scope:foe
			}
			scope:foe = {
				send_interface_message = {
					type = msg_marshal_task_bad
					title = marshal_joins_war_title_foe
					desc = marshal_joins_war_desc_foe
					left_icon = root
				}
			}
		}
	}
}

#You're the steward and your liege is broke
ach_yearly_events.1004 = {
	type = character_event
	title = ach_yearly_events.1004.t
	desc = {
		desc = ach_yearly_events.1004.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:liege = {
						OR = {
							has_trait = humble
							has_trait = patient
							has_trait = temperate
							has_trait = compassionate
							has_trait = calm
							has_trait = forgiving
						}
					}
				}
				desc = ach_yearly_events.1004.desc_end
			}
			desc = ach_yearly_events.1004.desc_harsh
		}
	} 
			
	theme = stewardship
	override_background = {
		trigger = {
			liege = {
				culture = {
					OR = {
						has_graphical_mediterranean_culture_group_trigger = yes
						has_graphical_mena_culture_group_trigger = yes
						has_graphical_african_culture_group_trigger = yes
					}
				}
				NOT = { government_has_flag = government_is_tribal }
			}
		}
		reference = ep3_city_gate
	}
	override_background = {
		trigger = {
			liege = {
				OR = {
					culture = {
						NOR = {
							has_graphical_mediterranean_culture_group_trigger = yes
							has_graphical_mena_culture_group_trigger = yes
							has_graphical_african_culture_group_trigger = yes
						}
					}
					government_has_flag = government_is_tribal
				}
			}
			
		}
		reference = market
	}
	left_portrait = {
		character = root
		animation = debating
		camera = camera_event_left_away_3_4
	}
	right_portrait = {
		character = scope:liege
		animation = jockey_wave
		camera = camera_event_horse_right
	}

	cooldown = { years = 10 }

	trigger = {
		is_independent_ruler = no
		liege ?= {
			age >= 10
			cp:councillor_steward ?= {
				this = root
			}
			
			OR = {
				gold < 0
				AND = {
					monthly_character_income < 0
					is_at_war = no
					gold <= medium_gold_value
				}
			}
			NOT = {
				has_character_flag = had_ach_yearly_1004
			}
			basic_is_available_ai = yes
			NOT = { exists = involved_activity }
			is_travelling = no
		}
		basic_is_valid_for_yearly_events_trigger = yes
	}
	immediate = {
		liege = {
			save_scope_as = liege
			add_character_flag = {
				flag = had_ach_yearly_1004
				years = 10
			}
		}
	}
	#A quick cash injection, by any means!
	option = {
		name = ach_yearly_events.1004.a
		flavor = ach_yearly_events.1004.a.flavor
		trigger = {
			liege = {
				any_powerful_vassal = {
					is_ai = yes
					NOT = { this = root }
					NOT = { is_at_war_with = scope:liege }
				}
			}
		}
		reverse_add_opinion = {
			target = scope:liege
			modifier = grateful_opinion
			opinion = 40
		}
		pay_short_term_gold = {
			target = scope:liege
			gold = minor_gold_value
		}
		scope:liege = {
			every_powerful_vassal = {
				custom = custom.every_liege_lending_vassal
				limit = {
					is_ai = yes
					NOT = { this = root }
					NOT = { is_at_war_with = scope:liege }
				}
				pay_short_term_gold = {
					target = scope:liege
					gold = scope:liege.minor_gold_value
				}
				add_opinion = {
					target = root
					modifier = irritated_opinion
					opinion = -25
				}
			}
		}
		hidden_effect = {
			scope:liege = {
				send_interface_message = {
					type = msg_steward_task_good
					title = steward_gathers_emergency_tithe_title
					desc = steward_gathers_emergency_tithe_desc
					left_icon = root
					
					show_as_tooltip = {
						add_gold = major_gold_value
					}
				}
			}
		}
		stress_impact = {
			greedy = medium_stress_impact_gain
			paranoid = medium_stress_impact_gain
			arrogant = major_stress_impact_gain
			vengeful = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -1
				ai_compassion = 1
			}
			modifier = {
				add = -50
				opinion = {
					target = scope:liege
					value < 0
				}
			}
			modifier = {
				add = 50
				opinion = {
					target = scope:liege
					value > 50
				}
			}
			modifier = {
				add = -50
				OR = {
					gold < major_gold_value
					has_trait = vengeful
				}
			}
			modifier = {
				factor = 0
				OR = {
					gold < medium_gold_value
					opinion = {
						target = scope:liege
						value < -50
					}
					has_trait = greedy
					has_trait = paranoid
					has_trait = arrogant
				}
			}
		}
	}
	#My liege needs steady income coming in, not cash now
	option = {
		name = ach_yearly_events.1004.b
		trigger = {
			stewardship < very_high_skill_rating
		}
		add_stewardship_lifestyle_xp = medium_lifestyle_xp
		duel = {
			skill = stewardship
			value = average_skill_rating
			50 = { #You reorganize the administration and plan for the future
				desc = ach_yearly_events.1004.b.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				send_interface_toast = {
					type = event_toast_effect_good
					title = ach_yearly_events.1004.b.success
					left_icon = root
					right_icon = scope:liege
					scope:liege = {
						#Only shown because of custom loc making it look right
						show_as_tooltip = {
							every_held_title = {
								custom = custom.every_liege_domain_county
								limit = {
									tier = tier_county
									NOT = {
										any_county_province = {
											is_occupied = yes
										}
									}
								}
								add_county_modifier = {
									modifier = ach_stewardship_bankruptcy_modifier
									years = 10
								}
							}
						}
						send_interface_message = {
							type = msg_steward_task_good
							title = steward_aids_financial_recovery_title
							desc = steward_aids_financial_recovery_desc
							left_icon = root
							
							#hidden because of custom loc making it look right
							hidden_effect = {
								every_held_title = {
									custom = custom.every_domain_county
									limit = {
										tier = tier_county
										NOT = {
											any_county_province = {
												is_occupied = yes
											}
										}
									}
									add_county_modifier = {
										modifier = ach_stewardship_bankruptcy_modifier
										years = 10
									}
								}
							}
						}
					}
				}
			}
			50 = { #You fail so bad you doubt your abilities
				desc = ach_yearly_events.1004.b.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				send_interface_toast = {
					type = event_toast_effect_bad
					title = ach_yearly_events.1004.b.failure
					left_icon = root
					right_icon = scope:liege

					add_stress = medium_stress_gain
				}
			}
		}
		stress_impact = {
			diligent = miniscule_stress_impact_loss
			lazy = medium_stress_impact_gain
			impatient = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_rationality = 1
				ai_energy = 1
			}
			modifier = {
				add = -50
				opinion = {
					target = scope:liege
					value < -50
				}
			}
			modifier = {
				add = -25
				opinion = {
					target = scope:liege
					value < 0
				}
			}
			modifier = {
				add = 25
				opinion = {
					target = scope:liege
					value > 50
				}
			}
			modifier = {
				add = -50
				stewardship <= average_skill_rating
			}
			modifier = {
				factor = 0
				OR = {
					stewardship < low_skill_rating
					has_trait = lazy
					has_trait = impatient
				}
			}
		}
	}
	#I am the god-tier steward that can easily reform the realm to get more tax
	option = {
		name = ach_yearly_events.1004.c
		trigger = {
			stewardship >= very_high_skill_rating
		}
		add_stewardship_lifestyle_xp = medium_lifestyle_xp
		scope:liege = {
			#Only shown because of custom loc making it look right
			show_as_tooltip = {
				every_held_title = {
					custom = custom.every_liege_domain_county
					limit = {
						tier = tier_county
						NOT = {
							any_county_province = {
								is_occupied = yes
							}
						}
					}
					add_county_modifier = {
						modifier = ach_stewardship_bankruptcy_modifier
						years = 10
					}
				}
			}
			
			send_interface_message = {
				type = msg_steward_task_good
				title = steward_aids_financial_recovery_title
				desc = steward_aids_financial_recovery_desc
				left_icon = root
				#hidden because of custom loc making it look right
				hidden_effect = {
					every_held_title = {
						custom = custom.every_domain_county
						limit = {
							tier = tier_county
							NOT = {
								any_county_province = {
									is_occupied = yes
								}
							}
						}
						add_county_modifier = {
							modifier = ach_stewardship_bankruptcy_modifier
							years = 10
						}
					}
				}
				
			}
		}
		stress_impact = {
			diligent = miniscule_stress_impact_loss
			lazy = medium_stress_impact_gain
			impatient = major_stress_impact_gain
		}
		ai_chance = {
			base = 150
			ai_value_modifier = {
				ai_rationality = 1
				ai_energy = 1
			}
			modifier = {
				add = -50
				opinion = {
					target = scope:liege
					value < -50
				}
			}
			modifier = {
				add = -25
				opinion = {
					target = scope:liege
					value < 0
				}
			}
			modifier = {
				add = 25
				opinion = {
					target = scope:liege
					value > 50
				}
			}
			modifier = {
				factor = 0
				OR = {
					stewardship < low_skill_rating
					has_trait = lazy
					has_trait = impatient
				}
			}
		}
	}
	#I can just welcome his creditors and the impoverished into my domain
	option = {
		name = ach_yearly_events.1004.d
		flavor = ach_yearly_events.1004.d.flavor
		capital_county = {
			add_county_modifier = {
				modifier = ach_welcoming_lieges_creditors_modifier
				years = 10
			}
		}
		reverse_add_opinion = {
			target = scope:liege
			modifier = insult_opinion
			opinion = -25
		}
		stress_impact = {
			forgiving = medium_stress_impact_gain
			generous = major_stress_impact_gain
			diligent = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_vengefulness = 1
				ai_greed = 1
			}
			modifier = {
				add = -50
				opinion = {
					target = scope:liege
					value > 50
				}
			}
			modifier = {
				add = -25
				opinion = {
					target = scope:liege
					value > 0
				}
			}
			modifier = {
				add = 50
				opinion = {
					target = scope:liege
					value < -50
				}
			}
			modifier = {
				factor = 0
				OR = {
					has_trait = forgiving
					has_trait = generous
					has_trait = diligent
				}
			}
		}
	}
}

ach_yearly_events.1005 = { #Coronation call to action if player forgetii
	type = character_event

	title = ach_yearly_events.1005.t
	desc = ach_yearly_events.1005.desc

	theme = coronation

	left_portrait = {
		character = root
		animation = personality_bold
	}

	trigger = {
		has_ach_dlc_trigger = yes
		is_ai = no
		primary_title.tier >= tier_kingdom
		has_realm_law = uncrowned
		NOR = {
			has_character_flag = had_coronation_reminder
			any_sponsored_inspiration = { has_inspiration_type = smith_inspiration }
		}
		is_available_adult = yes	
	}

	on_trigger_fail = {
		if = {
			limit = {
				primary_title.tier >= tier_kingdom
				has_realm_law = uncrowned
				NOT = { has_character_flag = had_coronation_reminder }
			}
			trigger_event = {
				id = ach_yearly_events.1005
				years = 1
			}
		}
	}

	immediate = {
		add_character_flag = had_coronation_reminder
		if = {
			limit = {
				exists = cp:councillor_chancellor
			}
			cp:councillor_chancellor = { save_scope_as = messenger }
		}
		else_if = {
			limit = {
				any_councillor = {
					is_kurultai_trigger = yes
				}
			}
			random_councillor = {
				limit = {
					is_kurultai_trigger = yes
				}
				save_scope_as = messenger
			}
		}
		else = {
			random_vassal = { save_scope_as = messenger }
		}
	}

	option = { #Get me a crown worthy of GetPrimaryTitle.GetName!
		name = ach_yearly_events.1005.a
		trigger = { coronation_has_proper_artifact_trigger = no }
		custom_tooltip = court_maintenance.0011.coronation.tooltip
		create_proper_coronation_artifact = yes
	}

	option = { #Ye, let's have it
		name = ach_yearly_events.1005.b
		trigger = { coronation_has_proper_artifact_trigger = yes }
		custom_tooltip = fund_inspiration.1001.b.coronation_ready
		open_view_data = {
			view = activity_list_detail_host_window
			data = activity_type:activity_coronation
			player = root
		}
	}

	option = {
		name = ach_yearly_events.1005.c
		custom_tooltip = court_maintenance.0011.b.tooltip.ach
	}

}

scripted_trigger ach_yearly_events_1010_fawner_trigger = {
	is_alive = yes
	is_imprisoned = no
	is_incapable = no
	has_contagious_deadly_disease_trigger = no
	is_adult = yes
	NOT = {
		has_any_bad_relationship_with_character_trigger = { CHARACTER = root }
	}
	opinion = {
		target = root
		value > 0
	}
	NOR = {
		is_consort_of = root
		is_close_family_of = root
	}
}

#Emperor+ becoming uncrowned again
ach_yearly_events.1010 = { #Coronation call to action if player forgetii
	type = character_event

	title = ach_yearly_events.1010.t
	desc = {
		desc = ach_yearly_events.1010.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:vassal_title_2
				}
				desc = ach_yearly_events.1010.desc_vassals
			}
			desc = ach_yearly_events.1010.desc_no_vassals
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					coronation_proper_artifact_regalia_trigger = yes
				}
				desc = ach_yearly_events.1010.desc_outro_regalia
			}
			desc = ach_yearly_events.1010.desc_outro_crown
		}
	}
	window = big_event_window
	theme = coronation

	override_background = {
		reference = holy_site_unique
	}
	left_portrait = {
		character = scope:fawner_2
		animation = throne_room_cheer_1
		camera = camera_event_left_away_3_4
	}
	center_portrait = {
		character = root
		triggered_animation = {
			trigger = {
				OR = {
					has_trait = eccentric
					has_trait = lunatic_1
					has_trait = lunatic_genetic
					ai_rationality <= high_negative_ai_value
				}
				ai_greed > low_positive_ai_value
			}
			animation = manic
		}
		triggered_animation = {
			trigger = {
				ai_compassion > low_positive_ai_value
				NOR = {
					has_trait = depressed
					has_trait = temperate
					has_trait = cynical
					has_trait = callous
					has_trait = sadistic
					has_trait = vengeful
					has_trait = just
					has_trait = arrogant
					has_trait = ambitious
					has_trait = paranoid
					dread >= 20
				}
			}
			animation = personality_compassionate
		}
		triggered_animation = {
			trigger = {
				has_lifestyle = martial_lifestyle
			}
			animation = marshal
		}
		animation = war_over_win
	}
	right_portrait = {
		character = scope:fawner
		animation = throne_room_cheer_2
		camera = camera_event_right_away_3_4
	}
	override_effect_2d = {
		reference = legend_glow
	}

	immediate = {
		#Sorry dawg
		show_as_tooltip = { add_realm_law = uncrowned }
		custom_tooltip = ach_coronation_suggestion_tt
		primary_title = {
			save_scope_as = new_title
			random_direct_de_jure_vassal_title = {
				limit = {
					OR = {
						holder.top_liege = root
						holder.suzerain = root
						NOR = {
							exists = holder
							this = scope:title
						}
					}	
				}
				save_scope_as = vassal_title_1
			}
			random_direct_de_jure_vassal_title = {
				limit = {
					OR = {
						holder.top_liege = root
						holder.suzerain = root
						NOR = {
							exists = holder
							this = scope:title
						}
					}
					NOT = {
						this = scope:vassal_title_1
					}	
				}
				save_scope_as = vassal_title_2
			}
		}
		ordered_councillor = {
			order_by = "opinion(root)"
			limit = {
				ach_yearly_events_1010_fawner_trigger = yes
				NOR = {
					is_at_war_with = root
					is_a_faction_member = yes
				}
			}
			save_scope_as = fawner
		}
		if = {
			limit = {
				NOT = {
					exists = scope:fawner
				}
			}
			ordered_vassal = {
				order_by = "opinion(root)"
				limit = {
					ach_yearly_events_1010_fawner_trigger = yes
					NOR = {
						is_at_war_with = root
						is_a_faction_member = yes
					}
				}
				save_scope_as = fawner
			}
		}
		if = {
			limit = {
				NOT = {
					exists = scope:fawner
				}
			}
			ordered_courtier = {
				order_by = "opinion(root)"
				limit = {
					ach_yearly_events_1010_fawner_trigger = yes
				}
				alternative_limit = {
					is_alive = yes
					is_imprisoned = no
					age >= 12
					NOT = {
						has_any_bad_relationship_with_character_trigger = { CHARACTER = root }
					}
				}
				save_scope_as = fawner
			}
		}
		if = {
			limit = {
				NOT = {
					exists = scope:fawner
				}
			}
			ordered_courtier = {
				order_by = "opinion(root)"
				save_scope_as = fawner
			}
		}
		if = {
			limit = {
				NOT = {
					exists = scope:fawner
				}
			}
			ordered_pool_guest = {
				order_by = "opinion(root)"
				limit = {
					is_alive = yes
					is_imprisoned = no
					age >= 12
					NOT = {
						has_any_bad_relationship_with_character_trigger = { CHARACTER = root }
					}
				}
				save_scope_as = fawner
			}
		}
		#SAVE ANOTHER
		ordered_councillor = {
			order_by = "opinion(root)"
			limit = {
				ach_yearly_events_1010_fawner_trigger = yes
				NOR = {
					is_at_war_with = root
					is_a_faction_member = yes
					this = scope:fawner
				}
			}
			save_scope_as = fawner_2
		}
		if = {
			limit = {
				NOT = {
					exists = scope:fawner_2
				}
			}
			ordered_vassal = {
				order_by = "opinion(root)"
				limit = {
					ach_yearly_events_1010_fawner_trigger = yes
					NOR = {
						is_at_war_with = root
						is_a_faction_member = yes
						this = scope:fawner
					}
				}
				save_scope_as = fawner_2
			}
		}
		if = {
			limit = {
				NOT = {
					exists = scope:fawner_2
				}
			}
			ordered_courtier = {
				order_by = "opinion(root)"
				limit = {
					ach_yearly_events_1010_fawner_trigger = yes
					NOT = {
						this = scope:fawner
					}
				}
				alternative_limit = {
					is_alive = yes
					is_imprisoned = no
					age >= 12
					NOR = {
						has_any_bad_relationship_with_character_trigger = { CHARACTER = root }
						this = scope:fawner
					}
				}
				save_scope_as = fawner_2
			}
		}
		if = {
			limit = {
				NOT = {
					exists = scope:fawner_2
				}
			}
			ordered_pool_guest = {
				order_by = "opinion(root)"
				limit = {
					is_alive = yes
					is_imprisoned = no
					age >= 12
					NOT = {
						has_any_bad_relationship_with_character_trigger = { CHARACTER = root }
						this = scope:fawner
					}
				}
				save_scope_as = fawner_2
			}
		}
	}
	option = {
		name = ach_yearly_events.1010.a
	}
}
