
# Have a look at _court_positions.info for documentation

# COURT POSITIONS
# mistress_court_position # MISTRESS MOD

mistress_court_position = {
	sort_order = {
		value = 0
		if = {
			limit = {
				NOT = { employs_court_position = mistress_court_position }
				num_of_relation_lover > 0
			}
			add = 250
		}
	}
	skill = diplomacy
	max_available_positions = 1
	minimum_rank = kingdom # Only Monarchs may have official mistresses
	
	court_position_asset = {
		animation = throne_room_conversation_1
		background = "gfx/interface/illustrations/event_scenes/bedchamber.dds"
	}
	
	opinion = {
		value = mistress_court_position_opinion
	}
	
	# How high the aptitude has to be to reach the 5 different modifier levels
	aptitude_level_breakpoints = { 20 40 60 80 }

	# How good is this character in this position? root scope is the holder of the court position
	aptitude = {
		value = 20
		add = {
			value = diplomacy
			multiply = 1.5
			max = 50
			desc = court_position_skill_diplomacy
		}
		if = {
			limit = {
				has_trait = gregarious
			}
			add = {
				value = 20
				desc = court_position_gregarious_trait
			}
		}
		if = {
            limit = {
                has_trait = lustful
            }
            add = {
                value = 10
                desc = mistress_position_lustful_trait
            }
        }
		if = {
			limit = {
				has_trait = honest
			}
			add = {
				value = 10
				desc = court_position_honest_trait
			}
		}
        if = {
            limit = {
                has_trait = beauty_good_3
            }
            add = {
                value = 40
                desc =  mistress_position_beauty_good_3_trait
            }
        }
        else_if = {
            limit = {
                has_trait = beauty_good_2
            }
            add = {
                value = 20
                desc =  mistress_position_beauty_good_2_trait
            }
        }
        else_if = {
            limit = {
                has_trait = beauty_good_1
            }
            add = {
                value = 10
                desc =  mistress_position_beauty_good_1_trait
            }
        }

        if = {
            limit = {
                has_trait = intellect_good_3
            }
            add = {
                value = 40
                desc = court_position_intellect_good_3_trait
            }
        }
        else_if = {
            limit = {
                has_trait = intellect_good_2
            }
            add = {
                value = 20
                desc = court_position_intellect_good_2_trait
            }
        }
        else_if = {
            limit = {
                has_trait = intellect_good_1
            }
            add = {
                value = 10
                desc = court_position_intellect_good_1_trait
            }
        }
        else_if = {
            limit = {
                OR = {
                    has_trait = shrewd
                }
            }
            add = {
                value = 15
                desc = court_position_shrewd_trait
            }
        }
        if = {
            limit = {
                has_trait = chaste
            }
            add = {
                value = -10
                desc =  mistress_position_chaste_trait
            }
        }
        if = {
            limit = {
                has_trait = shy
            }
            add = {
                value = -20
                desc = court_position_shy_trait
            }
        }
        if = {
            limit = {
                has_trait = reclusive
            }
            add = {
                value = -30
                desc = court_position_reclusive_trait
            }
        }
		
		if = {
			limit = {
				is_ruler = yes
			}
			add = {
				value = 30
				desc = court_position_reclusive_trait #TODO:prestigious mistress
			}
		}
		
		if = {
			limit = {
				is_lowborn = no
			}
			add = {
				value = 10
				desc = court_position_reclusive_trait #TODO:prestigious mistress
			}
		}
		
		add = court_position_aptitude_traveling_friends_value
		add = court_position_aptitude_family_business_value
		add = court_position_aptitude_low_penalty_value
		add = mistress_court_position_scandal_value
	}

	valid_position = {
		highest_held_title_tier >= tier_kingdom
		OR = {
            faith = {
                NAND = {
                    has_doctrine = doctrine_adultery_women_crime
                    has_doctrine = doctrine_adultery_men_crime
                }
            }
            has_trait = lustful
            has_trait = arbitrary
            has_trait = brave
            has_trait = adulterer
            has_trait = fornicator
		}
		NOR = {
		    has_trait = honest
		    has_trait = chaste
		}
	}
	
	is_shown = {
		is_landed_or_landless_administrative = yes
		NOT = { government_has_flag = government_is_nomadic }
		trigger_if = {
			limit = {
				is_ai = yes
				highest_held_title_tier <= tier_county
			}
			always = no
		}
	}
	
	is_shown_character = {
		scope:employee = {
		    OR = {
		        is_courtier_of = scope:liege
				is_vassal_of = scope:liege
				top_liege = scope:liege
			}
		}
	}

	valid_character = {
		scope:employee = {
			is_imprisoned = no
            NOT = { is_consort_of = scope:liege }

            OR = {
                has_relation_lover = scope:liege
                has_relation_soulmate = scope:liege
            }

            trigger_if = {
                limit = {
                    sex_same_as = scope:liege
                    scope:liege = {
                        faith = { NOT = { has_doctrine_parameter = homosexuality_accepted } }
                    }
                }
                scope:liege = {
                    OR = {
                        has_trait = arbitrary
                        has_trait = lustful
                        has_trait = brave
                        has_trait = lunatic
                    }
                }
            }
		}
	}

	revoke_cost = {
		prestige = medium_court_position_prestige_revoke_cost
	}

	salary = {
		round = no
		# You can't be stingy. No discounts!! That's just embarrassing...
		gold = medium_court_position_salary
		prestige = medium_court_position_prestige_salary
	}

	# These modifiers are employed based on what level the aptitude reaches (levels are defined as breakpoints) 
	scaling_employer_modifiers = {
		terrible = {
			stress_loss_mult = 0.10
			enemy_hostile_scheme_phase_duration_add = 1
		}
		poor = {
            court_grandeur_baseline_add = 1
			monthly_court_grandeur_change_mult = 0.1
			stress_loss_mult = 0.15
			enemy_hostile_scheme_phase_duration_add = 2
		}
		average = {
			court_grandeur_baseline_add = 1
            monthly_court_grandeur_change_mult = 0.15
			stress_loss_mult = 0.15
			enemy_hostile_scheme_phase_duration_add = 5
		}
		good = {
            court_grandeur_baseline_add = 2
            monthly_court_grandeur_change_mult = 0.15
			stress_loss_mult = 0.15
			enemy_hostile_scheme_phase_duration_add = 7
		}
		excellent = {
            court_grandeur_baseline_add = 2
            monthly_court_grandeur_change_mult = 0.20
			stress_loss_mult = 0.20
			enemy_hostile_scheme_phase_duration_add = 10
		}
	}

	custom_employer_modifier_description = mistress_custom_effect_description
	
	modifier = {
		owned_hostile_scheme_success_chance_add = 5
		liege_opinion = 25
		monthly_diplomacy_lifestyle_xp_gain_mult = 0.15
	}

	on_court_position_received = {
        make_mistress_effect = yes
    }

    on_court_position_revoked = {
        if = {
            limit = {
                OR = {
                    has_relation_lover = scope:liege
                    has_relation_soulmate = scope:liege
                }
            }
            basic_revoked_court_position_effect = yes # Only angry if they're still lovers
        }
		
		if = {
			limit = {
				is_married = yes
			}
			# Moves to pool after 1 day
			# Moving them directly here would invalidate the court position too early
			trigger_event = {
				id = courtier_guest_management.0999
				days = 1
			}
		}

        if = {
            limit = {
                scope:liege = {
                    has_character_modifier = scandalous_mistress
                }
            }
            scope:liege = {
                remove_character_modifier = scandalous_mistress
            }
        }

        if = {
            limit = {
                scope:liege = {
                    has_character_modifier = bad_mistress
                }
            }
            scope:liege = {
                remove_character_modifier = bad_mistress
            }
        }
    }

    on_court_position_invalidated = {
        basic_invalidated_court_position_effect = yes
        if = {
            limit = {
                scope:liege = {
                    has_character_modifier = scandalous_mistress
                }
            }
            scope:liege = {
                remove_character_modifier = scandalous_mistress
            }
        }

        if = {
            limit = {
                scope:liege = {
                    has_character_modifier = bad_mistress
                }
            }
            scope:liege = {
                remove_character_modifier = bad_mistress
            }
        }
    }
	
	on_court_position_vacated = {
		court_position_vacated_event_effect = {
			COURT_POSITION_TYPE = mistress_court_position
		}
		if = {
			limit = {
				scope:liege = {
					has_character_modifier = scandalous_mistress
				}
			}
			scope:liege = {
				remove_character_modifier = scandalous_mistress
			}
		}
		
		if = {
			limit = {
				scope:liege = {
					has_character_modifier = bad_mistress
				}
			}
			scope:liege = {
				remove_character_modifier = bad_mistress
			}
		}
	}
	
	
	# Scripted value to determine whether an AI will hire/fire a position or not. Hires over 0, fires under -50. Look in _court_positions.info for more extensive documentation!
	candidate_score = {
		value = 50
		add = scope:base_value
		add = court_position_candidate_score_base_value 
		add = court_position_candidate_aptitude_value

		scope:liege = {
			# If they have a lover, most likely they'll become a mistress
			if = {
				limit = {
					has_relation_lover = scope:employee
				}
				add = 20
			}
            # More likely for lustful characters
            if = {
                limit = {
                    has_trait = lustful
                }
                add = 30
            }

            if = {
                limit = {
                    has_trait = chaste
                }
                add = -50
            }

            if = {
                limit = {
                    has_trait = celibate
                }
                add = -1000
            }
        }
		if = { # To stop petitioned positions immediately being fired by the AI
			limit = {
				court_position_petition_ai_weight_trigger = { ROLE = mistress }
			}
			add = 1000
		}
		add = court_position_debt_considerations_value
	}
}
