﻿namespace = hire_tutor_event

scripted_effect set_court_tutor = {
	hidden_effect = { add_courtier = $teacher$ }
    if = {
        limit = { can_employ_court_position_type = court_tutor_court_position }
        appoint_court_position = {
            recipient = $teacher$
            court_position = court_tutor_court_position
        }
    }
    else_if = {
        limit = { exists = court_position:court_tutor_court_position }
        court_position:court_tutor_court_position = {
            add_opinion = {
                target = root
                modifier = disappointed_opinion
                opinion = -5
            }
        }
        replace_court_position = {
            recipient = $teacher$
            holder = court_position:court_tutor_court_position
            court_position = court_tutor_court_position
        }
    }
}

hire_tutor_event.0001 = {
	type = character_event
	title = hire_tutor_event_title
	desc = hire_tutor_event_desc
	theme = learning_scholarship_focus
	
    right_portrait = root
    left_portrait = scope:tutor_high
	lower_left_portrait = scope:tutor_low
    lower_center_portrait = scope:tutor_medium

	trigger = { exists = capital_province }

    immediate = {
        hidden_effect = {
            # AI
            if = {
                limit = {is_ai = yes}
                random_pool_character = {
                    province = capital_province
                    limit = {
                    	is_adult = yes
                        is_imprisoned = no
                        is_alive = yes
                        is_claimant = no
                        aptitude:court_tutor_court_position >= 3
                    }
                    weight = {
                        base = 10
                        modifier = {
                            faith = root.faith
                            add = 10
                        }
                        modifier = {
                            factor = aptitude:court_tutor_court_position
                        }
                    }
                    save_scope_as = tutor_low
                }
                if = {
                    limit = {has_trait = scholar}
                    scope:tutor_low ?= {
                        if = {
                            limit = { NOT = { has_trait = shrewd}}
                            add_trait = shrewd
                        }
                    }
                }
                if = {
                    limit = {NOT = {exists = scope:tutor_low}}
                    create_character = {
                        location = root.capital_province
                        template = tutor_medium_skill_template
                        save_scope_as = tutor_low
                    }
                }
            }
            # Player
            else = {
                # High
                random = {
                    chance = 5

                    modifier = {
                        has_trait = scholar
                        add = 45
                    }

                    modifier = {
                        add = {
                            value = root.prestige_level
                            add = root.piety_level
                            add = root.dynasty.dynasty_prestige_level
                            add = root.primary_title.tier
                        }
                    }

                    create_character = {
                        location = root.capital_province
                        template = tutor_high_skill_template
                        save_scope_as = tutor_high
                    }
                }
    
                # Medium
                create_character = {
                    location = root.capital_province
                    template = tutor_medium_skill_template
                    save_scope_as = tutor_medium
                }

                # Low
                create_character = {
                    location = root.capital_province
                    template = tutor_low_skill_template
                    save_scope_as = tutor_low
                }
            }
        }
    }

    # High
	option = {
		trigger = { exists = scope:tutor_high }
		name = hire_tutor_event_option_high
        add_internal_flag = special

        pay_short_term_gold = {
            target = scope:tutor_high
            gold = high_skill_court_physician_cost
        }

        custom_tooltip = hire_tutor_event_high_apt
		set_court_tutor = {teacher = scope:tutor_high}
        ai_chance = { base = 0 }
	}

    # Medium
	option = {
		trigger = { exists = scope:tutor_medium }
		name = hire_tutor_event_option_medium

        pay_short_term_gold = {
            target = scope:tutor_medium
            gold = high_skill_court_physician_cost
        }

        custom_tooltip = hire_tutor_event_medium_apt
        set_court_tutor = {teacher = scope:tutor_medium}
		ai_chance = { base = 0 }
	}

    # Low
	option = {
		trigger = { exists = scope:tutor_low }
		name = hire_tutor_event_option_low

        pay_short_term_gold = {
            target = scope:tutor_low
            gold = low_skill_court_physician_cost
        }

        custom_tooltip = hire_tutor_event_low_apt
		set_court_tutor = { teacher = scope:tutor_low}
		ai_chance = {
            base = 100
            modifier = {
				short_term_gold < low_skill_court_physician_cost
				factor = 0
			}
        }
	}

    # None
	option = {
        name = hire_tutor_event_option_none
		custom_tooltip = hire_tutor_event_option_none_tooltip
		ai_chance = { base = 10 }
	}
}