﻿# Grand Consort position effects #
#Basic effect for gaining a court position
grand_consort_gained_court_position_effect = {
	scope:liege = {
		save_scope_as = actor
		primary_spouse ?= {
			save_scope_as = liege_actor_primary_spouse
		}
		scope:employee = {
			save_scope_as = grand_consort
		}
		hidden_effect = {
			# Shared effects
			every_courtier = {
				limit = {
					this != scope:employee
					is_active_harem_member_trigger = {
						LIEGE = scope:liege
					}
				}
				add_to_list = harem_members_list
			}
			every_in_list = {
				list = harem_members_list
				send_interface_toast = {
					type = event_generic_bad
					title = grand_consort_promotion_toast
					right_icon = scope:grand_consort
					left_icon = scope:liege
					custom_tooltip = grand_consort_promotion_toast_desc_hp
					
					if = {
						limit = {
							scope:grand_consort = {
								NOT = {
									has_demoted_or_divorced_as_ps_opinion_trigger = {
										TARGET = scope:liege
									}
								}
							}
						}
						# Update their opinion
						if = {
							limit = {
								NOR = {
									has_relation_best_friend = scope:employee
									has_relation_friend = scope:employee
									has_relation_soulmate = scope:employee
									has_relation_lover = scope:employee

									has_relation_soulmate = scope:liege
								}
								opinion = {
									target = scope:employee
									value <= low_positive_opinion
								}
							}
							# Update the head of the harem's opinion on the Grand Consort
							if = {
								limit = {
									is_head_of_the_harem_trigger = {
										LIEGE = scope:liege
									}
									OR = {
										has_trait = craven
										has_trait = paranoid
										has_trait = shy
	
										harem_politics_evil_consort_trigger = yes
	
										has_relation_rival = scope:employee
										has_relation_nemesis = scope:employee
									}
									NOT = { has_trait = trusting }
								}
								add_opinion = {
									target = scope:employee
									modifier = threatening_consort_opinion
								}
								add_opinion = { #Feeling the pressure
									modifier = respect_opinion
									opinion = -10
									target = scope:liege
								}
							}
							# Others will also update their opinion
							else_if = {
								limit = {
									harem_politics_evil_consort_trigger = yes
									trigger_if = {
										limit = {
											hp_accepts_harems = no
										}
										OR = {
											has_trait = ambitious
											has_trait = arrogant
											has_trait = greedy
										}
									}
									trigger_else = {
										hp_accepts_harems = yes
									}
									NOR = {
										is_head_of_the_harem_trigger = {
											LIEGE = scope:liege
										}
										has_relation_rival = scope:liege
										has_relation_nemesis = scope:liege
									}
								}
								if = {
									limit = {
										is_consort_of = scope:liege
										NOR = {
											has_opinion_modifier = {
												target = scope:employee
												modifier = envy_consort_opinion
											}
											has_demoted_or_divorced_as_ps_opinion_trigger = {
												TARGET = scope:liege
											}
										}
									}
									add_opinion = {
										target = scope:employee
										modifier = envy_consort_opinion
									}
								}
								if = { # Your other relatives don't like you surpassing their authority
									limit = {
										NOT = {
											is_consort_of = scope:liege
										}
									}
									add_opinion = {
										modifier = respect_opinion
										opinion = -10
										target = scope:liege
									}
									add_opinion = {
										target = scope:employee
										modifier = threatening_consort_opinion
										opinion = -5
									}
								}
							}
						}
						if = {
							limit = {
								scope:employee = {
									harem_politics_evil_consort_trigger = yes
								}
								is_consort_of = scope:liege
							}
							stress_impact = {
								craven = minor_stress_impact_gain
								shy = minor_stress_impact_gain
								paranoid = miniscule_stress_impact_gain
							}
						}
					}
				}
			}
		}

		# Shared effects
		if = {
			limit = { 
				has_trait = just
				has_imprisonment_reason = scope:employee
			}
			stress_impact = {
				just = minor_stress_impact_gain
			}
		}
	}
	scope:employee = {
		# Shared effects
		if = { # They're not a demoted PS
			limit = {
				NOT = {
					has_demoted_or_divorced_as_ps_opinion_trigger = {
						TARGET = scope:liege
					}
				}
			}
			clear_negative_consort_modifiers_effect = yes # They're no longer unfavored
			if = { # They weren't forced into concubinage or previously demoted
				limit = {
					NOR = {
						has_opinion_modifier = {
							target = scope:liege
							modifier = forced_me_concubine_marriage_opinion
						}
						has_demoted_or_divorced_opinion_trigger = {
							TARGET = scope:liege
						}
					}
				}
				if = {
					limit = {
						OR = {
							has_trait = ambitious
							has_trait = arrogant
							has_trait = greedy
							hp_accepts_harems = yes
						}
					}
					add_opinion = {
						target = scope:liege
						modifier = thankful_consort_opinion
					}
				}
				# Effects for a secondary consort
				if = {
					limit = {
						trigger_if = {
							limit = {
								exists = scope:liege.primary_spouse
							}
							scope:liege.primary_spouse != scope:employee
						}
						trigger_else = {
							NOT = { exists = scope:liege.primary_spouse }
						}
					}
					hidden_effect = {
						every_close_family_member = {
							limit = {
								NOR = {
									has_opinion_modifier = {
										target = scope:liege
										modifier = forced_family_concubine_marriage_opinion
									}
									this = scope:liege
									has_opinion_modifier = {
										target = scope:liege
										modifier = thankful_consort_relative_opinion
									}
								}
								hp_accepts_harems = yes
							}
							add_opinion = {
								target = scope:liege
								modifier = thankful_consort_relative_opinion
							}
						}
					}
				}
			}
		}

		# Effects for a secondary consort who isn't a demoted PS
		if = {
			limit = {
				trigger_if = {
					limit = {
						exists = scope:liege.primary_spouse
					}
					scope:liege.primary_spouse != scope:employee
				}
				trigger_else = {
					NOT = { exists = scope:liege.primary_spouse }
				}
				NOT = {
					has_demoted_or_divorced_as_ps_opinion_trigger = {
						TARGET = scope:liege
					}
				}
			}
			# Notify relatives
			every_close_family_member = {
				limit = { this != scope:liege }
				hidden_effect = {
					send_interface_message = {
						type = event_generic_good_text 
						title = grand_consort_promotion_t 
						right_icon = scope:employee
						left_icon = scope:liege
						desc = grand_consort_promotion_desc 
					}
				}
			}

			if = { # Newly appointed GC (true promotion)
				limit = {
					NOT = {
						has_demoted_or_divorced_opinion_trigger = {
							TARGET = scope:liege
						}
					}
				}
				# Clan unity
				add_clan_unity_interaction_effect = {
					CHARACTER = scope:liege
					TARGET = scope:employee
					VALUE = medium_unity_gain
					DESC = clan_unity_promotion.desc
					REVERSE_NON_HOUSE_TARGET = no
				}
				# House relations
				calyver_house_relations_effect = {
					ACTOR = scope:liege
					RECIPIENT = scope:employee
					VALUE = house_relation_improve_minor_value
					REASON = harem_promoted_increase
					TITLE = scope:dummy_gender
				}
				# Favor
				calyver_favor_huge_gain_effect = yes
				# Prestige
				if = {
					limit = { scope:liege.primary_title.tier = tier_kingdom }
					add_prestige = { value = minor_prestige_gain }
				}
				else_if = {
					limit = { scope:liege.primary_title.tier >= tier_empire }
					add_prestige = { value = medium_prestige_gain }
				}
				high_consort_event_appointment_effect = yes
			}
			else_if = { # Reinstatement (for previously demoted GC/SS)
				limit = {
					OR = {
						has_opinion_modifier = {
							modifier = demoted_me_as_gc
							target = scope:liege
						}
						has_opinion_modifier = {
							modifier = demoted_me_as_hc
							target = scope:liege
						}
						has_opinion_modifier = {
							modifier = demoted_me_as_ss
							target = scope:liege
						}

						has_opinion_modifier = {
							modifier = divorced_me_as_gc
							target = scope:liege
						}
						has_opinion_modifier = {
							modifier = divorced_me_as_hc
							target = scope:liege
						}
						has_opinion_modifier = {
							modifier = divorced_me_as_ss
							target = scope:liege
						}
					}
				}
				if = { # From HC to GC is a quasi-promotion
					limit = {
						OR = {
							has_opinion_modifier = {
								modifier = demoted_me_as_hc
								target = scope:liege
							}
							has_opinion_modifier = {
								modifier = divorced_me_as_hc
								target = scope:liege
							}
						}
					}
					save_scope_value_as = {
						name = opinion
						value = -5
					}
				}
				consort_reinstatement_effect = {
					REINSTATOR = scope:liege
					REINSTATED = scope:employee
				}
			}
		}
		else_if = { # Effects for the primary spouse
			limit = {
				scope:liege.primary_spouse ?= scope:employee
			}
			calyver_favor_medium_gain_effect = yes
		}
	}
}

#Basic effect for losing a court position
grand_consort_revoked_court_position_effect = {
	scope:employee = {
		if = {
			limit = { # Cannot lose more favor if they had been demoted before
				NOT = {
					has_demoted_or_divorced_as_ps_opinion_trigger = {
						TARGET = scope:liege
					}
				}
			}
			# Shared effects
			# No more favored modifiers
			clear_positive_consort_modifiers_effect = yes
			# No more positive opinion
			clear_consort_opinions_effect = {
				TARGET = scope:liege
			}
			# Harem members will be notified
			hidden_effect = {
				scope:liege = {
					every_courtier = {
						limit = {
							this != scope:employee
							is_active_harem_member_trigger = {
								LIEGE = scope:liege
							}
						}
						send_interface_message = {
							type = event_generic_good_text
							title = punished_consort_t
							right_icon = scope:employee
							left_icon = scope:liege
							desc = demoted_grand_consort_interface_desc

							if = { #The primary spouse is relieved
								limit = {
									has_opinion_modifier = {
										target = scope:employee
										modifier = threatening_consort_opinion
									}
								}
								remove_opinion = {
									target = scope:employee
									modifier = threatening_consort_opinion
								}
							}
							if = { #Other consorts don't feel jealous
								limit = {
									has_opinion_modifier = {
										target = scope:employee
										modifier = envy_consort_opinion
									}
								}
								remove_opinion = {
									target = scope:employee
									modifier = envy_consort_opinion
								}
							}
							if = { #Craven consorts don't feel threatened by a despot
								limit = {
									scope:employee = {
										harem_politics_evil_consort_trigger = yes
									}
									is_consort_of = scope:liege
								}
								stress_impact = {
									craven = minor_stress_impact_loss
									shy = minor_stress_impact_loss
									paranoid = minor_stress_impact_loss
								}
							}
						}
					}
				}
			}
			# Stress impact
			scope:liege = {
				stress_impact = {
					compassionate = minor_stress_impact_gain
					forgiving = minor_stress_impact_gain
				}
				if = {
					limit = { 
						AND = {
							has_trait = just
							NOT = { has_imprisonment_reason = scope:employee }
						}
					}
					stress_impact = {
						just = minor_stress_impact_gain
					}
				}
				else_if = {
					limit = { 
						has_trait = just
						has_imprisonment_reason = scope:employee
					}
					stress_impact = {
						just = minor_stress_impact_loss
					}
				}
			}

			# Effects for a secondary consort
			if = {
				limit = {
					trigger_if = {
						limit = {
							exists = scope:liege.primary_spouse
						}
						NOT = {
							this = scope:liege.primary_spouse
						}
					}
					trigger_else = {
						NOT = { exists = scope:liege.primary_spouse }
					}
				}
				# If we're a clan this interaction affects unity
				add_clan_unity_interaction_effect = {
					CHARACTER = scope:liege
					TARGET = scope:employee
					VALUE = medium_unity_loss
					DESC = clan_unity_demotion.desc
					REVERSE_NON_HOUSE_TARGET = no
				}
				calyver_house_relations_effect = {
					ACTOR = scope:liege
					RECIPIENT = scope:employee
					VALUE = house_relation_damage_minor_value
					REASON = harem_demoted_decrease
					TITLE = scope:dummy_gender
				}
				
				# Victim is naturally angry for being demoted.
				add_opinion = {
					target = scope:liege
					modifier = demoted_me_as_gc
				}
				# Favor impact
				if = {
					limit = {
						NOT = {
							has_character_flag = block_favor_progress_effect_flag
						}
					}	
					calyver_favor_big_loss_effect = yes
				}
				# Demoted modifier
				add_character_modifier = {
					modifier = demoted_spouse_modifier
				}
				if = {
					limit = {
						has_character_flag = block_favor_progress_effect_flag
					}
					remove_character_flag = block_favor_progress_effect_flag
				}
				#Progress towards rivals
				if = {
					limit = {
						can_set_relation_rival_trigger = { CHARACTER = scope:liege }
						NOT = {
							has_character_flag = block_rival_progress_effect_flag
						}
					}
					progress_towards_rival_effect = {
						REASON = demoted_me_reason
						CHARACTER = scope:liege
						OPINION = default_rival_opinion
					}
				}
				else_if = {
					limit = {
						has_character_flag = block_rival_progress_effect_flag
					}
					remove_character_flag = block_rival_progress_effect_flag
				}

				#Relatives lose opinion and are notified
				every_close_family_member = {
					limit = { NOT = { this = scope:liege } } # don't hate yourself just because of demotion
					custom = all_close_family_members
					if = {
						limit = {
							hp_accepts_harems = yes
						}
						add_opinion = {
							modifier = demoted_concubine_marriage_opinion
							target = scope:liege
						}
					}
					hidden_effect = {
						if = {
							limit = {
								has_opinion_modifier = {
									target = scope:liege
									modifier = thankful_consort_relative_opinion
								}
							}
							remove_opinion = {
								target = scope:liege
								modifier = thankful_consort_relative_opinion
							}
						}
						if = {
							limit = {
								has_opinion_modifier = {
									target = scope:liege
									modifier = reinstated_relative_marriage_opinion
								}
							}
							remove_opinion = {
								modifier = reinstated_relative_marriage_opinion
								target = scope:liege
							}
						}
						send_interface_message = {
							type = event_generic_bad_text
							title = demoted_grand_consort_t
							right_icon = scope:employee
							left_icon = scope:liege
							desc = demoted_grand_consort_interface_desc
						}
					}
				}
				# Prestige loss
				if = {
					limit = { scope:liege.primary_title.tier = tier_kingdom }
					add_prestige = { value = minor_prestige_loss }
				}
				else_if = {
					limit = { scope:liege.primary_title.tier >= tier_empire }
					add_prestige = { value = medium_prestige_loss }
				}
			}
			else_if = { # Effects for the primary spouse
				limit = {
					scope:liege.primary_spouse ?= scope:employee
				}
				# Favor loss
				calyver_favor_medium_loss_effect = yes
				if = {
					limit = {
						NOT = {
							has_opinion_modifier = {
								modifier = hate_opinion
								target = scope:liege
							}
						}
					}
					add_opinion = {
						modifier = hate_opinion
						target = scope:liege
						opinion = -15
					}
				}
			}
		}
	}
}

#Invalidated position
grand_consort_invalidated_court_position_effect = {
}

# Other Four Consorts effects
high_consort_gained_court_position_effect = {
	scope:liege = {
		save_scope_as = actor
		primary_spouse ?= {
			save_scope_as = liege_actor_primary_spouse
		}
		scope:employee = {
			save_scope_as = grand_consort
		}
		hidden_effect = {
			# Shared effects
			every_courtier = {
				limit = {
					this != scope:employee
					is_active_harem_member_trigger = {
						LIEGE = scope:liege
					}
				}
				add_to_list = harem_members_list
			}
			every_in_list = {
				list = harem_members_list
				send_interface_toast = {
					type = event_generic_bad
					title = grand_consort_promotion_toast
					right_icon = scope:grand_consort
					left_icon = scope:liege
					custom_tooltip = $TITLE$_consort_promotion_toast_desc_hp

					if = {
						limit = {
							scope:grand_consort = {
								NOT = {
									has_demoted_or_divorced_as_ps_opinion_trigger = {
										TARGET = scope:liege
									}
								}
							}
						}
						# Update their opinion
						if = {
							limit = {
								NOR = {
									has_relation_best_friend = scope:employee
									has_relation_friend = scope:employee
									has_relation_soulmate = scope:employee
									has_relation_lover = scope:employee

									has_relation_soulmate = scope:liege

									has_demoted_or_divorced_as_ps_opinion_trigger = {
										TARGET = scope:liege
									}
								}
								opinion = {
									target = scope:employee
									value <= low_positive_opinion
								}
							}
							# Update the head of the harem's opinion on the Grand Consort
							if = {
								limit = {
									OR = {
										is_head_of_the_harem_trigger = {
											LIEGE = scope:liege
										}
										is_high_consort_trigger = {
											LIEGE = scope:liege
										}
										scope:liege.primary_spouse ?= this
										AND = {
											NOT = { is_consort_of = scope:liege }
											harem_politics_evil_consort_trigger = yes
											trigger_if = {
												limit = {
													hp_accepts_harems = no
												}
												OR = {
													has_trait = ambitious
													has_trait = arrogant
													has_trait = greedy
												}
											}
											trigger_else = {
												hp_accepts_harems = yes
											}
										}
									}
									OR = {
										has_trait = craven
										has_trait = paranoid
										has_trait = shy
	
										harem_politics_evil_consort_trigger = yes
	
										has_relation_rival = scope:employee
										has_relation_nemesis = scope:employee
									}
									NOT = { has_trait = trusting }
								}
								if = {
									limit = {
										scope:employee = {
											OR = {
												has_relation_lover = scope:liege
												has_relation_soulmate = scope:liege

												has_character_modifier = favored_consort_modifier
												has_character_modifier = beloved_consort_modifier
												has_character_modifier = favor_boost_modifier
											}
										}
									}
									add_opinion = {
										target = scope:employee
										modifier = threatening_consort_opinion
										opinion = -10
									}
								}
								else = {
									add_opinion = {
										target = scope:employee
										modifier = threatening_consort_opinion
										opinion = -5
									}
								}
							}
							# Others will also update their opinion
							else_if = {
								limit = {
									is_consort_of = scope:liege
									harem_politics_evil_consort_trigger = yes
									trigger_if = {
										limit = {
											hp_accepts_harems = no
										}
										OR = {
											has_trait = ambitious
											has_trait = arrogant
											has_trait = greedy
										}
									}
									trigger_else = {
										hp_accepts_harems = yes
									}
									NOR = {
										is_head_of_the_harem_trigger = {
											LIEGE = scope:liege
										}
										is_high_consort_trigger = {
											LIEGE = scope:liege
										}
										has_opinion_modifier = {
											target = scope:employee
											modifier = envy_consort_opinion
										}
										has_opinion_modifier = {
											target = scope:employee
											modifier = threatening_consort_opinion
										}
										has_relation_rival = scope:liege
										has_relation_nemesis = scope:liege
									}
								}
								add_opinion = {
									target = scope:employee
									modifier = envy_consort_opinion
								}
							}
						}
						if = {
							limit = {
								scope:employee = {
									harem_politics_evil_consort_trigger = yes
								}
								is_consort_of = scope:liege
								NOR = {
									is_head_of_the_harem_trigger = {
										LIEGE = scope:liege
									}
									is_high_consort_trigger = {
										LIEGE = scope:liege
									}
								}
							}
							stress_impact = {
								craven = minor_stress_impact_gain
								shy = minor_stress_impact_gain
								paranoid = miniscule_stress_impact_gain
							}
						}
					}
				}
			}
		}

		if = {
			limit = { 
				has_trait = just
				has_imprisonment_reason = scope:employee
			}
			stress_impact = {
				just = minor_stress_impact_gain
			}
		}
	}
	scope:employee = {
		if = { # They're not a demoted PS
			limit = {
				NOT = {
					has_demoted_or_divorced_as_ps_opinion_trigger = {
						TARGET = scope:liege
					}
				}
			}
			clear_negative_consort_modifiers_effect = yes # They're no longer unfavored
			if = { # Newly appointed HC (true promotion)
				limit = {
					NOT = {
						has_demoted_or_divorced_opinion_trigger = {
							TARGET = scope:liege
						}
					}
				}
				if = { # They weren't forced into concubinage
					limit = {
						NOT = {
							has_opinion_modifier = {
								target = scope:liege
								modifier = forced_me_concubine_marriage_opinion
							}
						}
					}
					if = {
						limit = {
							OR = {
								has_trait = ambitious
								has_trait = arrogant
								has_trait = greedy
								hp_accepts_harems = yes
							}
						}
						add_opinion = {
							target = scope:liege
							modifier = thankful_consort_opinion
						}
					}

					hidden_effect = { # Notify relatives
						every_close_family_member = {
							limit = {
								this != scope:liege
							}
							if = {
								limit = {
									NOR = {
										has_opinion_modifier = {
											target = scope:liege
											modifier = forced_family_concubine_marriage_opinion
										}
										has_opinion_modifier = {
											target = scope:liege
											modifier = thankful_consort_relative_opinion
										}
									}
									hp_accepts_harems = yes
								}
								add_opinion = {
									target = scope:liege
									modifier = thankful_consort_relative_opinion
								}
							}
							send_interface_message = {
								type = event_generic_good_text 
								title = grand_consort_promotion_t 
								right_icon = scope:employee
								left_icon = scope:liege
								custom_tooltip = $TITLE$_consort_promotion_toast_desc_hp
							}
						}
					}
				}
				# Clan unity
				add_clan_unity_interaction_effect = {
					CHARACTER = scope:liege
					TARGET = scope:employee
					VALUE = minor_unity_gain
					DESC = clan_unity_promotion.desc
					REVERSE_NON_HOUSE_TARGET = no
				}
				# House relations
				calyver_house_relations_effect = {
					ACTOR = scope:liege
					RECIPIENT = scope:employee
					VALUE = house_relation_improve_minor_value
					REASON = harem_promoted_increase
					TITLE = scope:dummy_gender
				}
				# Favor
				calyver_favor_huge_gain_effect = yes
				# Prestige
				add_prestige = { value = minor_prestige_gain }
				high_consort_event_appointment_effect = yes
			}
			else_if = { # Reinstatement (for previously demoted HC)
				limit = {
					has_demoted_or_divorced_opinion_trigger = {
						TARGET = scope:liege
					}
				}
				if = { # From GC to HC is a quasi-demotion
					limit = {
						OR = {
							has_opinion_modifier = {
								modifier = demoted_me_as_gc
								target = scope:liege
							}
							has_opinion_modifier = {
								modifier = divorced_me_as_gc
								target = scope:liege
							}
						}
					}
					save_scope_value_as = {
						name = opinion
						value = -15
					}
				}
				consort_reinstatement_effect = {
					REINSTATOR = scope:liege
					REINSTATED = scope:employee
				}
			}
		}
	}
}
high_consort_revoked_court_position_effect = {
	scope:employee = {
		if = {
			limit = { # Cannot lose more favor if they had been demoted before
				NOT = {
					has_demoted_or_divorced_as_ps_opinion_trigger = {
						TARGET = scope:liege
					}
				}
			}
			# Shared effects
			# No more favored modifiers
			clear_positive_consort_modifiers_effect = yes
			# No more positive opinion
			clear_consort_opinions_effect = {
				TARGET = scope:liege
			}
			# Harem members will be notified
			hidden_effect = {
				scope:liege = {
					every_courtier = {
						limit = {
							this != scope:employee
							is_active_harem_member_trigger = {
								LIEGE = scope:liege
							}
						}
						send_interface_message = {
							type = event_generic_good_text
							title = punished_consort_t
							right_icon = scope:employee
							left_icon = scope:liege
							desc = demoted_$TITLE$_consort_interface_desc

							if = { #The primary spouse is relieved
								limit = {
									has_opinion_modifier = {
										target = scope:employee
										modifier = threatening_consort_opinion
									}
								}
								remove_opinion = {
									target = scope:employee
									modifier = threatening_consort_opinion
								}
							}
							if = { #Other consorts don't feel jealous
								limit = {
									has_opinion_modifier = {
										target = scope:employee
										modifier = envy_consort_opinion
									}
								}
								remove_opinion = {
									target = scope:employee
									modifier = envy_consort_opinion
								}
							}
							if = { #Craven consorts don't feel threatened by a despot
								limit = {
									scope:employee = {
										harem_politics_evil_consort_trigger = yes
									}
									is_consort_of = scope:liege
									NOR = {
										is_head_of_the_harem_trigger = {
											LIEGE = scope:liege
										}
										is_high_consort_trigger = {
											LIEGE = scope:liege
										}
									}
								}
								stress_impact = {
									craven = minor_stress_impact_loss
									shy = minor_stress_impact_loss
									paranoid = minor_stress_impact_loss
								}
							}
						}
					}
				}
			}
			# Stress impact
			scope:liege = {
				stress_impact = {
					compassionate = minor_stress_impact_gain
					forgiving = minor_stress_impact_gain
				}
				if = {
					limit = { 
						AND = {
							has_trait = just
							NOT = { has_imprisonment_reason = scope:employee }
						}
					}
					stress_impact = {
						just = minor_stress_impact_gain
					}
				}
				else_if = {
					limit = { 
						has_trait = just
						has_imprisonment_reason = scope:employee
					}
					stress_impact = {
						just = minor_stress_impact_loss
					}
				}
			}

			# If we're a clan this interaction affects unity
			add_clan_unity_interaction_effect = {
				CHARACTER = scope:liege
				TARGET = scope:employee
				VALUE = medium_unity_loss
				DESC = clan_unity_demotion.desc
				REVERSE_NON_HOUSE_TARGET = no
			}
			calyver_house_relations_effect = {
				ACTOR = scope:liege
				RECIPIENT = scope:employee
				VALUE = house_relation_damage_minor_value
				REASON = harem_demoted_decrease
				TITLE = scope:dummy_gender
			}
			
			# Victim is naturally angry for being demoted.
			add_opinion = {
				target = scope:liege
				modifier = demoted_me_as_hc
			}
			# Favor impact
			if = {
				limit = {
					NOT = {
						has_character_flag = block_favor_progress_effect_flag
					}
				}	
				calyver_favor_big_loss_effect = yes
			}
			# Demoted modifier
			add_character_modifier = {
				modifier = demoted_spouse_modifier
			}
			if = {
				limit = {
					has_character_flag = block_favor_progress_effect_flag
				}
				remove_character_flag = block_favor_progress_effect_flag
			}
			#Progress towards rivals
			if = {
				limit = {
					can_set_relation_rival_trigger = { CHARACTER = scope:liege }
					NOT = {
						has_character_flag = block_rival_progress_effect_flag
					}
				}
				progress_towards_rival_effect = {
					REASON = demoted_me_reason
					CHARACTER = scope:liege
					OPINION = default_rival_opinion
				}
			}
			else_if = {
				limit = {
					has_character_flag = block_rival_progress_effect_flag
				}
				remove_character_flag = block_rival_progress_effect_flag
			}

			#Relatives lose opinion and are notified
			every_close_family_member = {
				limit = { this != scope:liege } # don't hate yourself just because of demotion
				custom = all_close_family_members
				if = {
					limit = {
						hp_accepts_harems = yes
					}
					add_opinion = {
						modifier = demoted_concubine_marriage_opinion
						target = scope:liege
					}
				}
				hidden_effect = {
					if = {
						limit = {
							has_opinion_modifier = {
								target = scope:liege
								modifier = thankful_consort_relative_opinion
							}
						}
						remove_opinion = {
							target = scope:liege
							modifier = thankful_consort_relative_opinion
						}
					}
					if = {
						limit = {
							has_opinion_modifier = {
								target = scope:liege
								modifier = reinstated_relative_marriage_opinion
							}
						}
						remove_opinion = {
							modifier = reinstated_relative_marriage_opinion
							target = scope:liege
						}
					}
					send_interface_message = {
						type = event_generic_bad_text
						title = demoted_grand_consort_t
						right_icon = scope:employee
						left_icon = scope:liege
						desc = demoted_$TITLE$_consort_interface_desc
					}
				}
			}
			# Prestige loss
			add_prestige = { value = minor_prestige_loss }
		}
	}
}
high_consort_invalidated_court_position_effect = {
}
high_consort_event_appointment_effect = {
	hidden_effect = {
		if = {
			limit = {
				scope:liege = {
					can_have_four_consorts_trigger = yes
				}
				scope:employee = {
					NOR = {
						has_relation_rival = scope:liege
						has_relation_nemesis = scope:liege
						has_demoted_or_divorced_opinion_trigger = {
							TARGET = scope:liege
						}
						has_opinion_modifier = {
							modifier = reinstated_me_opinion
							target = scope:liege
						}
						has_trait_with_flag = illness
					}
					trigger_if = {
						limit = {
							hp_accepts_harems = no
						}
						OR = {
							has_trait = ambitious
							has_trait = greedy
							has_trait = arrogant
							has_relation_lover = scope:liege
							has_relation_soulmate = scope:liege
							has_relation_best_friend = scope:liege
							has_relation_friend = scope:liege
						}
					}
					is_high_consort_trigger = {
						LIEGE = scope:liege
					}
				}
			}
			scope:liege = {
				random_list = {
					# Consort Jia dances for the Emperor
					1 = {
						trigger = {
							scope:employee = {
								NOR = {
									has_trait = shy
									has_trait = chaste
									has_trait = pregnant
								}
								age <= 50
							}
							NOR = {
								has_trait = eunuch
								has_trait = celibate
								has_trait = devoted
							}
						}
						modifier = { # Diplomacy
							add = {
								value = scope:employee.diplomacy
								multiply = 0.1
							}					
						}
						modifier = { #Traits
							add = 1
							scope:employee = {
								has_trait = seducer
							}
						}
						modifier = { #Traits
							add = 1
							scope:employee = {
								has_trait = lustful
							}
						}
						modifier = { #Traits
							add = -1
							scope:employee = {
								has_trait = craven
							}
						}
						trigger_event = {
							id = consort_events.2001
							days = { 4 8 }
						}
					}
					# Tea and poems
					1 = {
						trigger = {
							scope:employee.learning >= decent_skill_rating
						}
						modifier = { # Learning
							add = {
								value = scope:employee.learning
								multiply = 0.1
							}					
						}
						modifier = { # Learning
							scope:employee = {
								has_court_position = virtuous_consort_court_position
							}
							add = 1
						}
						modifier = { #Traits
							add = 1
							scope:employee = {
								has_trait = lifestyle_poet
							}
						}
						modifier = { #Traits
							add = -1
							scope:employee = {
								has_trait = shy
							}
						}
						modifier = { #Traits
							add = 1
							scope:employee = {
								has_trait = chaste
							}
						}
						modifier = {
							has_trait = chaste
							add = 3
						}
						trigger_event = {
							id = consort_events.2002
							days = { 4 8 }
						}
					}
					# The Huaqing Pools
					1 = {
						trigger = {
							scope:employee = {
								NOR = {
									has_trait = shy
									has_trait = chaste
									has_trait = pregnant
								}
							}
							NOR = {
								has_trait = eunuch
								has_trait = celibate
								has_trait = devoted
							}
						}
						modifier = { #Traits
							add = 2
							scope:employee = {
								harem_politics_evil_consort_trigger = yes
							}
						}
						modifier = { #Traits
							add = 1
							scope:employee = {
								has_trait = seducer
							}
						}
						modifier = { #Traits
							add = 1
							scope:employee = {
								has_trait = lustful
							}
						}
						modifier = { #Traits
							add = -1
							scope:employee = {
								has_trait = craven
							}
						}
						trigger_event = {
							id = consort_events.2003
							days = { 4 8 }
						}
					}
					# Noble Consort Hua shows her greed
					1 = {
						trigger = {
							scope:employee = {
								NOR = {
									has_trait = shy
									has_trait = chaste
									has_trait = pregnant
									has_trait = humble
								}
								OR = {
									has_trait = ambitious
									has_trait = greedy
									has_trait = arrogant
								}
							}
							NOR = {
								has_trait = eunuch
								has_trait = celibate
								has_trait = devoted
							}
						}
						modifier = { #Traits
							add = 1
							scope:employee = {
								harem_politics_evil_consort_trigger = yes
							}
						}
						modifier = { #Traits
							add = 1
							scope:employee = {
								has_court_position = grand_consort_court_position
							}
						}
						modifier = { #Traits
							add = 1
							scope:employee = {
								has_trait = greedy
							}
						}
						modifier = { #Traits
							add = 1
							scope:employee = {
								has_trait = ambitious
							}
						}
						modifier = { #Traits
							add = 1
							scope:employee = {
								has_trait = arrogant
							}
						}
						trigger_event = {
							id = consort_events.2004
							days = { 4 8 }
						}
					}
					# Nothing
					7 = {
						modifier = {
							has_character_flag = appointed_hc_event_flag
							add = -2
						}
						modifier = {
							scope:employee = {
								has_trait = shy
							}
							add = 1
						}
						modifier = { #Traits
							add = 1
							scope:employee = {
								has_trait = craven
							}
						}
						modifier = {
							scope:employee = {
								has_trait = chaste
							}
							add = 2
						}
						modifier = {
							scope:employee = {
								hp_accepts_harems = no
								NOR = {
									has_trait = ambitious
									has_trait = greedy
									has_trait = arrogant
									has_relation_lover = scope:actor
									has_relation_soulmate = scope:actor
									has_relation_best_friend = scope:actor
									has_relation_friend = scope:actor
								}
							}
							add = 2
						}
						modifier = {
							scope:employee = {
								has_opinion_modifier = {
									modifier = forced_family_concubine_marriage_opinion
									target = scope:actor
								}
							}
							add = 7
						}
						modifier = {
							has_trait = chaste
							add = 3
						}
					}
				}
			}
		}
	}
}
# Task effects #
# Grand Consort tasks effects#
grand_consort_improve_relationship_effect = {
	if = {
		limit = { 
			NOT = { this = $TARGET$ }
		}
		#Nemesis -> Rival
		if = {
			limit = {
				has_relation_nemesis = $TARGET$
			}
			remove_relation_nemesis = $TARGET$
			hidden_effect = {
				set_relation_rival = {
					target = $TARGET$
					reason = $REASON$
				}
			}
			add_opinion = {
				target = $TARGET$
				modifier = friendliness_opinion
				opinion = 15
			}
			reverse_add_opinion = {
				target = $TARGET$
				modifier = friendliness_opinion
				opinion = 15
			}
		}
		#Rival -> Potential Rival
		else_if = {
			limit = {
				has_relation_rival = $TARGET$
			}
			remove_relation_rival = $TARGET$
			hidden_effect = { set_relation_potential_rival = $TARGET$ }
			add_opinion = {
				target = $TARGET$
				modifier = friendliness_opinion
				opinion = 15
			}
			reverse_add_opinion = {
				target = $TARGET$
				modifier = friendliness_opinion
				opinion = 15
			}
		}
		#Potential Rival -> Potential Friend
		else_if = {
			limit = {
				has_relation_potential_rival = $TARGET$
			}
			remove_relation_potential_rival = $TARGET$
			hidden_effect = { set_relation_potential_friend = $TARGET$ }
			add_opinion = {
				target = $TARGET$
				modifier = friendliness_opinion
				opinion = 15
			}
			reverse_add_opinion = {
				target = $TARGET$
				modifier = friendliness_opinion
				opinion = 15
			}
		}
		#Potential Friend -> Friend
		else_if = {
			limit = {
				has_relation_potential_friend = $TARGET$
			}
			set_relation_friend = { 
				target = $TARGET$
				reason = $REASON$ 
			}
			add_opinion = {
				target = $TARGET$
				modifier = friendliness_opinion
				opinion = 30
			}
			reverse_add_opinion = {
				target = $TARGET$
				modifier = friendliness_opinion
				opinion = 30
			}
		}
		#Friend -> Best Friend
		else_if = {
			limit = {
				has_relation_friend = $TARGET$
				can_set_relation_best_friend_trigger = { CHARACTER = $TARGET$ }
			}
			set_relation_best_friend = { 
				target = $TARGET$
				reason = $REASON$  
			}
			add_opinion = {
				target = $TARGET$
				modifier = friendliness_opinion
				opinion = 50
			}
			reverse_add_opinion = {
				target = $TARGET$
				modifier = friendliness_opinion
				opinion = 50
			}
		}
		#Nothing -> Potential Friend
		else = {
			set_relation_potential_friend = $TARGET$
			add_opinion = {
				target = $TARGET$
				modifier = friendliness_opinion
				opinion = 15
			}
			reverse_add_opinion = {
				target = $TARGET$
				modifier = friendliness_opinion
				opinion = 15
			}
		}
	}
}

grand_consort_worsen_relationship_effect = {
	if = {
		limit = { 
			NOT = { this = $TARGET$ }
		}
		#Best Friend -> Friend
		if = {
			limit = {
				has_relation_best_friend = $TARGET$
			}
			remove_relation_best_friend = $TARGET$
			hidden_effect = { 
				set_relation_friend = { 
					target = $TARGET$
					reason = $REASON$
				} 
			}
			add_opinion = {
				target = $TARGET$
				modifier = unfriendly_opinion
				opinion = -15
			}
			reverse_add_opinion = {
				target = $TARGET$
				modifier = unfriendly_opinion
				opinion = -15
			}
		}
		#Friend -> Potential Friend
		else_if = {
			limit = {
				has_relation_friend = $TARGET$
			}
			remove_relation_friend = $TARGET$
			hidden_effect = { set_relation_potential_friend = $TARGET$ }
			add_opinion = {
				target = $TARGET$
				modifier = unfriendly_opinion
				opinion = -15
			}
			reverse_add_opinion = {
				target = $TARGET$
				modifier = unfriendly_opinion
				opinion = -15
			}
		}
		#Potential Friend -> Potential Rival
		else_if = {
			limit = {
				has_relation_potential_friend = $TARGET$
				NOT = { has_relation_potential_rival = $TARGET$ }
			}
			remove_relation_potential_friend = $TARGET$
			set_relation_potential_rival = $TARGET$
			add_opinion = {
				target = $TARGET$
				modifier = unfriendly_opinion
				opinion = -15
			}
			reverse_add_opinion = {
				target = $TARGET$
				modifier = unfriendly_opinion
				opinion = -15
			}
		}
		#Potential Rival -> Rival
		else_if = {
			limit = {
				has_relation_potential_rival = $TARGET$
			}
			set_relation_rival = {
				target = $TARGET$
				reason = $REASON$
			}
			add_opinion = {
				target = $TARGET$
				modifier = unfriendly_opinion
				opinion = -30
			}
			reverse_add_opinion = {
				target = $TARGET$
				modifier = unfriendly_opinion
				opinion = -30
			}
		}
		#Rival -> Nemesis
		else_if = {
			limit = {
				has_relation_rival = $TARGET$
				can_set_relation_nemesis_trigger = { CHARACTER = $TARGET$ }
			}
			set_relation_nemesis = {
				target = $TARGET$
				reason = $REASON$
			}
			add_opinion = {
				target = $TARGET$
				modifier = hate_opinion
				opinion = -50
			}
			reverse_add_opinion = {
				target = $TARGET$
				modifier = hate_opinion
				opinion = -50
			}
		}
		#Nothing -> Potential Rival
		else = {
			set_relation_potential_rival = $TARGET$
			add_opinion = {
				target = $TARGET$
				modifier = unfriendly_opinion
				opinion = -15
			}
			reverse_add_opinion = {
				target = $TARGET$
				modifier = unfriendly_opinion
				opinion = -15
			}
		}
	}
}