﻿
#####################################################################
# EFFECT LIST
#####################################################################
# !!! Remember to add all new effects with a short description here !!!

# - increases a friendships by "one level"

#####################################################################
# EFFECTS
#####################################################################




##vanilla overrides

revocation_tyranny_effect = {
	if = {
		limit = {
			title_revocation_is_tyrannical_trigger = yes
		}
		add_tyranny = revoke_title_tyranny_gain
	}
	else = {
		if = { ##Imperial Mod
			limit = { scope:recipient = { has_government = military_command } } 
			custom_tooltip = IS_ALLOWED_TO_REVOKE_MILITARY_TITLE_DESC
		}
		else_if = {
			limit = {
				has_claim_on = scope:landed_title
			}
			custom_tooltip = IS_ALLOWED_TO_REVOKE_TITLE_FOR_CLAIM_DESC
		}
		else_if = {
			limit = {
				has_revoke_title_reason = scope:recipient
			}
			custom_tooltip = IS_ALLOWED_TO_REVOKE_TITLE_DESC
		}
		else_if = {
			limit = {
				faith = {
					OR = {
						has_doctrine_parameter = pluralism_righteous_revocation_tyranny_reduced
						has_doctrine_parameter = pluralism_fundamentalist_revocation_tyranny_minimal
					}
					faith_hostility_level = {
						target = scope:recipient.faith
						value >= faith_hostile_level
					}
				}
			}
			if = {
				limit = {
					faith = {
						has_doctrine_parameter = pluralism_fundamentalist_revocation_tyranny_minimal 								
						faith_hostility_level = {
							target = scope:recipient.faith
							value = faith_hostile_level
						}
					}
				}
				custom_tooltip = IS_ALLOWED_TO_REVOKE_HOSTILE_INFIDEL_TITLE
			}
			else = {
				custom_tooltip = IS_ALLOWED_TO_REVOKE_EVIL_INFIDEL_TITLE
			}						
			every_vassal = {
				limit = {
					faith = scope:recipient.faith
				}
				custom = INFIDEL_REVOCATION_OPINION
				add_opinion = {
					modifier = angry_opinion
					target = scope:actor
					opinion = {
						value = revoke_title_tyranny_gain
						multiply = -1
					}
				}
			}
		}
	}	
}

war_for_revoke_effect = {
	scope:recipient = {
		save_scope_value_as = {
			name = war_for_revocation_flavour
			value = yes
		}
		start_war = {
			casus_belli = refused_liege_demand_war
			target = scope:actor
		}
	}
	if = {
		limit = {
			scope:actor = { NOT = { has_revoke_title_reason = scope:recipient } }
		}
		scope:actor = {
			every_vassal = { #Vassals joining the rebel.
				limit = {
					NOR = {
						this = scope:recipient
						is_ai = no
						has_trait = incapable
						is_imprisoned = yes
						dread_modified_ai_boldness = { #Too scared to do anything.
							dreaded_character = scope:actor
							value <= -50
						}
						is_at_war_with = scope:recipient
						is_at_war_with = scope:actor
					}
					highest_held_title_tier > tier_barony
					OR = {
						#Lovers and friends always back rebel (unless also lovers/friends of the liege)
						AND = {
							OR = {
								has_relation_lover = scope:recipient
								has_relation_friend = scope:recipient
							}
							NOR = {
								has_relation_lover = scope:actor
								has_relation_friend = scope:actor
							}
						}
						#Vassals that either like recipient or have high honor will rally if the liege is being tyrannical.
						AND = {
							OR = {
								ai_honor >= 25
								opinion = {
									target = scope:recipient
									value >= 40
								}
							}
							NOR = {
								scope:actor = {
									has_revoke_title_reason = scope:recipient
								}
								scope:actor = {
									has_claim_on = scope:landed_title
								}
								faith = {								
									faith_hostility_level = {
										target = scope:recipient.faith
										value >= faith_hostile_level
									}
								}
								scope:recipient = {  ###imperial mod
									has_government = military_command 
								} 
							}

						}
						#And finally, vassals that really hate their liege will join regardless (provided that they also do not hate recipient).
						AND = {
							opinion = {
								target = scope:recipient
								value >= -25
							}
							opinion = {
								target = scope:actor
								value <= -50
							}
						}
					}
				}
				save_scope_as = joining_vassal
				custom_tooltip = tooltip_fellow_vassal_joins_war #The war has not started when viewing the interaction screen.
				hidden_effect = {
					scope:recipient = {
						every_character_war = {
							limit = {
								using_cb = refused_liege_demand_war
								casus_belli = {
									primary_attacker = scope:recipient
									primary_defender = scope:actor
								}
							}
								add_to_list = war_to_join
						}
					}
					every_in_list = {
						list = war_to_join
						limit = {
							NOT = { is_defender = prev }
						}
						hidden_effect = {
							set_called_to = prev
						}
						add_attacker = prev
					}
				}
				hidden_effect = {
					scope:actor = {
						add_opinion = {
							target = prev
							modifier = rebellious_vassal_opinion
						}
					}
				}
			}
			every_vassal = {
				limit = {
					is_ai = no
					NOT = { this = scope:recipient }
					is_imprisoned = no
				}
				trigger_event = char_interaction.0232
			}
		}
	}
	scope:recipient = {
		add_opinion = {
			target = scope:actor
			modifier = attempted_arrest_opinion
		}
	}
}
send_child_to_holy_order_effect = {
	scope:recipient = {
		add_trait = order_member
		add_piety_level = 1
		if = {
			limit = { is_ruler = yes }
			depose_effect = yes ###Imperial mod
		}
		if = {
			limit = {
				NOT = { faith = scope:$GRANDMASTER$.faith }
			}
			set_character_faith = scope:$GRANDMASTER$.faith
		}
	}
	if = { # No piety gain for asking random people to take the vows
		limit = {
			scope:recipient = {
				is_close_family_of = scope:actor
			}
		}
		add_piety = medium_piety_gain
		scope:$GRANDMASTER$ = {
			add_courtier = scope:recipient
			add_opinion = {
				target = scope:actor
				modifier = pleased_opinion
				opinion = 20
			}
		}
	}
}
send_child_to_clergy_effect = {
	scope:recipient = {
		add_opinion = {
			modifier = demanded_taking_vows
			target = scope:actor
		}
		add_trait = devoted
		add_piety_level = 1
		if = {
			limit = { is_ruler = yes }
			depose_effect = yes ###Imperial mod
		}
	}
	if = { # No piety gain for asking random people to take the vows
		limit = {
			scope:recipient = {
				is_close_family_of = scope:actor
			}
		}
		add_piety = minor_piety_gain
	}
}

###

imperial_government_initialise_effect = {
	save_scope_as = the_emperor

	every_vassal = { #Ensure vassals are military commands
		limit = { 
			OR = {
				has_government = feudal_government
				has_government = clan_government
			}
		}
		check_for_starting_military_command_effect = yes
		every_vassal = {
			limit = { 
				OR = {
					has_government = feudal_government
					has_government = clan_government
				}
			}
			check_for_starting_military_command_effect = yes
			every_vassal = {
				limit = { 
					OR = {
						has_government = feudal_government
						has_government = clan_government
					}
				}
				check_for_starting_military_command_effect = yes
			}
		}
	}
	trigger_event = imperial.9999 #create patricians (has to be after game start)
}
check_for_starting_military_command_effect = {
	if = { #only same culture/religion vassals
		limit = { 	
			trigger_if = {
				limit = { scope:the_emperor.faith = { has_doctrine = tenet_tax_nonbelievers } } #religious tolerance
				faith.religion = { is_in_family = rf_abrahamic }
			}	
			trigger_else = {
				culture = scope:the_emperor.culture 
			}
		}
		change_government = military_command
		# every_held_title = {
			# limit = { 
				# this = holder.primary_title
			# }
			# add_title_law = military_appointment_succession_law
		# }
	}	
	else = {
		add_character_flag = imperial_autonomy_override
		vassal_contract_set_obligation_level = { type = imperial_autonomy level = 1 }
	}
}


military_faction_grant_title_effect = {
	if = {
		limit = {
			scope:actor = {
				any_targeting_faction = {
					faction_is_type = military_faction
				}
			}
		}		
		scope:actor = {
			random_targeting_faction = {
				limit = { faction_is_type = military_faction }
				save_scope_as = military_faction
			}
			hidden_effect = {
				if = {
					limit = { NOT = { var:military_candidate_ignored_count > 0 } }
					set_variable = { name = military_candidate_ignored_count value = 0 }
				}
			}
			if = { #Title given to candidate
				limit = {
					any_targeting_faction = {
						faction_is_type = military_faction
						special_character = { this = scope:recipient }
					}
				}
				hidden_effect = {
					remove_variable = military_candidate_ignored_count		
					add_character_flag = { flag = recently_granted_candidate_a_title days = 100 }
				}
				if = { #If thhe faction actually wants target to get duchy, then give warning
					limit = {
						NOT = {
							any_in_list = {
								list = titles_to_grant
								tier >= tier_duchy
							}
						}
						any_targeting_faction = {
							faction_is_type = military_faction
							special_character = { 
								this = scope:recipient 
								military_faction_duke_promotion_candidate_trigger = { FACTION_TARGET = scope:actor }
							}
						}					
					}
					custom_tooltip = grant_title_military_faction_candidate_duchy_WARNING
				}
				else = {
					hidden_effect = {		
						random_targeting_faction = {
							limit = { faction_is_type = military_faction }
							remove_special_character = yes
							remove_special_character = special_character
							every_faction_member = {
								send_interface_toast = {
									title = military_faction_CANDIDATE_GIVEN_TITLE
									left_icon = scope:recipient 
									
									custom_tooltip = military_faction_CANDIDATE_GIVEN_TITLE_DESC
								}
							}
						}						
					}
				}
				
				if = {
					limit = {
						any_in_list = {
							list = target_titles
							tier = tier_kingdom
						}
					}
					custom_tooltip = grant_title_modifier_military_faction_candidate_kingdom
					hidden_effect = { 
						random_targeting_faction = {
							limit = { faction_is_type = military_faction }
							add_faction_discontent = -50 
						} 
					}
				}
				else_if = {
					limit = {
						any_in_list = {
							list = titles_to_grant
							tier = tier_duchy
						}
					}
					custom_tooltip = grant_title_modifier_military_faction_candidate_duchy
					hidden_effect = { 
						random_targeting_faction = {
							limit = { faction_is_type = military_faction }
							add_faction_discontent = -25
						} 
					}
				}
				else = {
					custom_tooltip = grant_title_modifier_military_faction_candidate_other
					hidden_effect = { 
						random_targeting_faction = {
							limit = { faction_is_type = military_faction }
							add_faction_discontent = -15
						} 
					}
				}
			}
			else_if = { #Dislikes nepotism
				limit = {
					house = scope:recipient.house					
				}
				if = {
					limit = { var:military_candidate_ignored_count >= 2 }
					custom_tooltip = grant_title_modifier_military_faction_candidate_ignored
				}
				hidden_effect = {
					change_variable = { name = military_candidate_ignored_count add = 1 }
					random_targeting_faction = {
						limit = { faction_is_type = military_faction }
						every_faction_member = {
							send_interface_toast = {
								title = military_faction_INFORM_NEPOTISM
								left_icon = scope:recipient 
								custom_tooltip = military_faction_INFORM_NEPOTISM_DESC
							}
						}
					}						
				}
				if = {
					limit = {
						any_in_list = {
							list = target_titles
							tier = tier_kingdom
						}
					}
					custom_tooltip = grant_title_modifier_military_faction_nepotism_kingdom
					hidden_effect = { 
						random_targeting_faction = {
							limit = { faction_is_type = military_faction }
							add_faction_discontent = 50 
						} 
					}
				}
				else_if = {
					limit = {
						any_in_list = {
							list = titles_to_grant
							tier = tier_duchy
						}
					}
					custom_tooltip = grant_title_modifier_military_faction_nepotism_duchy
					hidden_effect = { 
						random_targeting_faction = {
							limit = { faction_is_type = military_faction }
							add_faction_discontent = 25
						} 
					}
				}
				else = {
					custom_tooltip = grant_title_modifier_military_faction_nepotism_other
					hidden_effect = { 
						random_targeting_faction = {
							limit = { faction_is_type = military_faction }
							add_faction_discontent = 15
						} 
					}
				}
			}
			else_if = { 
				limit = { 
					NOT = { has_character_flag = recently_granted_candidate_a_title } 
					any_targeting_faction = {
						faction_is_type = military_faction
						exists = special_character #there actually is a candidate
					}
				}
				if = { #faction gets annoyed if candidate ignored 3 times
					limit = { var:military_candidate_ignored_count >= 2 }
					custom_tooltip = grant_title_modifier_military_faction_candidate_ignored
				}
				hidden_effect = {
					change_variable = { name = military_candidate_ignored_count add = 1 }
				}
			}
		}
	}
}
depose_effect = {
	trigger_event = imperial.0001 #Imperial succession maintenance
	trigger_event = imperial.0003 #Military succession maintenance
	trigger_event = imperial.9001
	depose = yes	
}

new_patrician_setup_effect = {
	$LIEGE$ = { capital_county = { save_scope_as = liege_capital_county } }
	save_scope_as = new_patrician
	create_dynamic_title = {
		tier = duchy
		name = PATRICIAN_TITLE
	}
	create_title_and_vassal_change = change
	scope:change = {
		set_title_and_vassal_change_type = created
	}
	scope:new_title = {
		set_destroy_if_invalid_heir = yes
		set_always_follows_primary_heir = yes
		set_variable = { name = patrician_house value = 1 }
		generate_coa = yes
		set_capital_county = scope:liege_capital_county
		
		set_landless_title = yes
		set_delete_on_destroy = yes
		set_no_automatic_claims = yes
		change_title_holder = {
			holder = scope:new_patrician
			change = scope:change
		}
	}
	change_liege = {
		liege = $LIEGE$
		change = scope:change
	}	
	if = { #Give player a random county to avoid game over
		limit = { 
			OR = {	
				is_ai = no
				$PREDECESSOR$ = { is_ai = no } 
			}	
		}
		#First try predecessor's counties
		if = {
			limit = { 
				NOT = { scope:new_patrician = $PREDECESSOR$ }
				$PREDECESSOR$.top_liege = $LIEGE$
			}
			$PREDECESSOR$ = {
				random_held_title = {
					limit = {
						tier = tier_county
						NOT = { this = holder.capital_county }
						NOT = { this = scope:target } #title being revoked
					}
					set_variable = { name = protect_title value = yes days = 5 }
					scope:new_patrician = { add_character_flag = { flag = patrician_land_found days = 7 } }
					if = {
						limit = { #If this a title I'd inherit anyway then just wait for it
							NAND = {
								scope:new_patrician = { has_character_flag = inheriting_patrician_status }
								current_heir = scope:new_patrician
							}	
						}
						change_title_holder = {
							holder = scope:new_patrician
							change = scope:change	
						}
					}
				}
			}
		}
		if = {
			limit = { scope:new_patrician = { NOT = { has_character_flag = patrician_land_found } } }
			$LIEGE$ = {
				random_sub_realm_title = {
					limit = {
						tier = tier_county
						OR = {
							holder = { 
								highest_held_title_tier = tier_county
								is_ai = yes
							}
							NOT = { this = holder.capital_county }
						}
						NOT = { this = scope:target } #title being revoked
					}
					weight = {
						base = 0

						modifier = { #liege county
							$LIEGE$ = { is_ai = yes }
							holder = $LIEGE$
							add = 25
						}
						modifier = { 
							NOT = { this = holder.capital_county }
							add = 1000
						}
						modifier = { #risk of dejure war
							duchy.holder = {
								NOT = { this = $LIEGE$ }
								NOT = { this = $PREDECESSOR$ }
								OR = {
									vassal_contract_has_flag = vassal_contract_war_override
									NOR = { 
										has_government = military_command 
										has_government = patrician_government
									}
								}
							}
							add = -500
						}
						modifier = { #risk of dejure war
							kingdom.holder = {
								NOT = { this = $LIEGE$ }
								NOT = { this = $PREDECESSOR$ }
								OR = {
									vassal_contract_has_flag = vassal_contract_war_override
									NOR = { 
										has_government = military_command 
										has_government = patrician_government
									}
								}
							}
							add = -500
						}
						modifier = { #Try to keep richer provinces
							add = {
								title_province = {
									value = monthly_income
								}					
								multiply = -10
							}						
						}
						modifier = { #Try and match cultures
							add = 50
							culture = scope:new_patrician.culture
						}
						modifier = { #Try and match cultures
							add = 50
							culture_group = scope:new_patrician.culture_group
						}
					}
					set_variable = { name = protect_title value = yes days = 5 }
					change_title_holder = {
						holder = scope:new_patrician
						change = scope:change	
					}
				}
			}
		}	
	}	

	resolve_title_and_vassal_change = scope:change
	scope:new_patrician = {
		change_government = patrician_government
		add_realm_law_skip_effects = single_heir_succession_law
	}
	
	every_spouse = {
		limit = { is_ruler = no }
		scope:new_patrician = { recruit_courtier = prev }
	}
	if = {
		limit = { NOT = { this = $PREDECESSOR$ } }
		every_close_or_extended_family_member = {
			limit = { 
				is_ruler = no 
				NOT = { is_spouse_of = liege }
				OR = {
					NOT = { is_close_or_extended_family_of = liege }
					AND = {
						is_child_of = scope:new_patrician
						NOT = { is_child_of = liege }
					}
					AND = {
						is_close_family_of = scope:new_patrician
						NOT = { is_close_family_of = liege }
					}
				}
				NAND = {
					is_councillor = yes
					OR = {
						opinion = { target = scope:new_patrician value >= 25 }
						opinion = { target = liege value < -25 }
					}
				}
				NOR = {
					has_trait = devoted
					has_trait = order_member
				}
			}
			scope:new_patrician = { recruit_courtier = prev }
		}
	}	
}
gain_one_estate_level_effect = {
	if = {
		limit = { has_character_modifier = patrician_estate_modifier_6 }
		#Max level
	}
	else_if = {
		limit = { has_character_modifier = patrician_estate_modifier_5 }
		hidden_effect = { remove_character_modifier = patrician_estate_modifier_5 }
		add_character_modifier = patrician_estate_modifier_6
	}
	else_if = {
		limit = { has_character_modifier = patrician_estate_modifier_4 }
		hidden_effect = { remove_character_modifier = patrician_estate_modifier_4 }
		add_character_modifier = patrician_estate_modifier_5
	}
	else_if = {
		limit = { has_character_modifier = patrician_estate_modifier_3 }
		hidden_effect = { remove_character_modifier = patrician_estate_modifier_3 }
		add_character_modifier = patrician_estate_modifier_4
	}
	else_if = {
		limit = { has_character_modifier = patrician_estate_modifier_2 }
		hidden_effect = { remove_character_modifier = patrician_estate_modifier_2 }
		add_character_modifier = patrician_estate_modifier_3
	}
	else_if = {
		limit = { has_character_modifier = patrician_estate_modifier_1 }
		hidden_effect = { remove_character_modifier = patrician_estate_modifier_1 }
		add_character_modifier = patrician_estate_modifier_2
	}
	else = {
		add_character_modifier = patrician_estate_modifier_1
	}
}
lose_one_estate_level_effect = {
	if = {	
		limit = { has_character_modifier = patrician_estate_modifier_6 }
		remove_character_modifier = patrician_estate_modifier_6
		add_character_modifier = patrician_estate_modifier_5
	}
	else_if = {
		limit = { has_character_modifier = patrician_estate_modifier_5 }
		remove_character_modifier = patrician_estate_modifier_5
		add_character_modifier = patrician_estate_modifier_4
	}
	else_if = {
		limit = { has_character_modifier = patrician_estate_modifier_4 }
		remove_character_modifier = patrician_estate_modifier_4
		add_character_modifier = patrician_estate_modifier_3
	}
	else_if = {
		limit = { has_character_modifier = patrician_estate_modifier_3 }
		remove_character_modifier = patrician_estate_modifier_3
		add_character_modifier = patrician_estate_modifier_2
	}
	else_if = {
		limit = { has_character_modifier = patrician_estate_modifier_2 }
		remove_character_modifier = patrician_estate_modifier_2
		add_character_modifier = patrician_estate_modifier_1
	}
	else_if = {
		limit = { has_character_modifier = patrician_estate_modifier_1 }
		remove_character_modifier = patrician_estate_modifier_1
	}
}
retire_effect = {
	save_scope_as = retiree
	
	trigger_event = imperial.9001
	trigger_event = imperial.0001 #Imperial succession maintenance
	trigger_event = imperial.0003 #Military succession maintenance

	player_heir = { save_scope_as = new_player_char }
	create_title_and_vassal_change = change
	scope:change = {
		set_title_and_vassal_change_type = abdication
	}
	every_held_title = {
		limit = { 
			NAND = { 
				holder = { highest_held_title_tier > tier_barony }
				this = scope:retiree.capital_barony 
			}
		}
		current_heir = { 
			save_scope_as = title_heir 
			add_to_list = title_heirs
		}
		change_title_holder = {
			holder = scope:title_heir
			change = scope:change
		}
	}
	resolve_title_and_vassal_change = scope:change
	if = {
		limit = { is_ai = no }
		random_in_list = {
			list = title_heirs
			limit = { house = scope:retiree.house }
			weight = {
				base = 10
				modifier = {
					add = 1000
					this = scope:new_player_char
				}
			}
			save_scope_as = new_player_char
		}
		set_player_character = scope:new_player_char
	}
}
inherit_estates_effect = {
	$ESTATE_HEIR$ = { #record current estates
		set_variable = { name = total_estates value = 0 days = 2 }
		if = {
			limit = { has_estates_trigger = yes }
			if = {
				limit = { has_character_modifier = patrician_estate_modifier_6 }
				change_variable = { name = total_estates add = 6 }
			}
			else_if = {
				limit = { has_character_modifier = patrician_estate_modifier_5 }
				change_variable = { name = total_estates add = 5 }
			}
			else_if = {
				limit = { has_character_modifier = patrician_estate_modifier_4 }
				change_variable = { name = total_estates add = 4 }
			}
			else_if = {
				limit = { has_character_modifier = patrician_estate_modifier_3 }
				change_variable = { name = total_estates add = 3 }
			}
			else_if = {
				limit = { has_character_modifier = patrician_estate_modifier_2 }
				change_variable = { name = total_estates add = 2 }
			}
			else_if = {
				limit = { has_character_modifier = patrician_estate_modifier_1 }
				change_variable = { name = total_estates add = 1 }
			}
		}
	}
	if = {
		limit = { has_character_modifier = patrician_estate_modifier_6 }
		$ESTATE_HEIR$ = { 
			change_variable = { name = total_estates add = 6 }
		}
	}	
	else_if = {
		limit = { has_character_modifier = patrician_estate_modifier_5 }
		$ESTATE_HEIR$ = { 
			change_variable = { name = total_estates add = 5 }
		}
	}
	else_if = {
		limit = { has_character_modifier = patrician_estate_modifier_4 }
		$ESTATE_HEIR$ = { 
			change_variable = { name = total_estates add = 4 }
		}
	}
	else_if = {
		limit = { has_character_modifier = patrician_estate_modifier_3 }
		$ESTATE_HEIR$ = { 
			change_variable = { name = total_estates add = 3 }
		}
	}
	else_if = {
		limit = { has_character_modifier = patrician_estate_modifier_2 }
		$ESTATE_HEIR$ = { 
			change_variable = { name = total_estates add = 2 }
		}
	}
	else_if = {
		limit = { has_character_modifier = patrician_estate_modifier_1 }
		$ESTATE_HEIR$ = { 
			change_variable = { name = total_estates add = 1 }
		}
	}
	$ESTATE_HEIR$ = {
		while = { #gain cash for estates above limit
			limit = { var:total_estates > 6 }
			add_gold = estate_sell_value
			change_variable = { name = total_estates add = -1 }
		}
		if = {
			limit = { var:total_estates >= 6 }
			add_character_modifier = patrician_estate_modifier_6
		}
		else_if = {
			limit = { var:total_estates = 5 }
			add_character_modifier = patrician_estate_modifier_5
		}
		else_if = {
			limit = { var:total_estates = 4 }
			add_character_modifier = patrician_estate_modifier_4
		}
		else_if = {
			limit = { var:total_estates = 3 }
			add_character_modifier = patrician_estate_modifier_3
		}
		else_if = {
			limit = { var:total_estates = 2 }
			add_character_modifier = patrician_estate_modifier_2
		}
		else_if = {
			limit = { var:total_estates = 1 }
			add_character_modifier = patrician_estate_modifier_1
		}
	}
	remove_character_modifier = patrician_estate_modifier_1
	remove_character_modifier = patrician_estate_modifier_2
	remove_character_modifier = patrician_estate_modifier_3
	remove_character_modifier = patrician_estate_modifier_4
	remove_character_modifier = patrician_estate_modifier_5
	remove_character_modifier = patrician_estate_modifier_6	
}
military_faction_title_grant_check_effect = {
	if = { #if go over domain limit try and give title to the military candidate first
		limit = {
			highest_held_title_tier >= tier_kingdom
			is_ai = yes
			domain_limit_available < 0			
			any_targeting_faction = {
				faction_is_type = military_faction
				special_character = { 
					eligible_for_military_appointment_trigger = { APPOINTEE = $GRANTEE$ }
					any_liege_or_above = { this = $GRANTEE$ }
					NAND = {
						is_ruler = yes
						NOT = { liege = $GRANTEE$ }
					}
					is_imprisoned = no
				}
			}
		}
		random_targeting_faction = {
			limit = { faction_is_type = military_faction }
			save_scope_as = faction_update
		}
		if = {
			limit = {
				NOT = { has_character_flag =  military_title_grant_check }
				is_character_interaction_valid = {
					recipient = scope:faction_update.special_character
					interaction = grant_titles_interaction
				}
				OR = {
					AND = {
						opinion = { target = scope:faction_update.special_character value > -20 }
						reverse_opinion = { target = scope:faction_update.special_character value > -20 }
					}	
					scope:faction_update = { #faction is very discontent
						faction_discontent >= 80
						faction_power >= 75
					}
					domain_limit_available < -3 #may as well
				}				
			}
			add_character_flag = { flag = military_title_grant_check days = 30 }
			trigger_event = imperial.0030
		}
	}
}

