﻿namespace = travel_events_mpo
############################
# MPO Travel Events
############################
# travel_events_mpo.0001 - The Golden Flock
# travel_events_mpo.0010 - Upon a White Camel

scripted_effect travel_events_mpo_0001_success_effect = {
    add_prestige = medium_prestige_gain
    start_eagle_story_cycle_effect = yes
    add_trait_xp = {
        trait = lifestyle_hunter
        track = falconer
        value = 5
    }
}
scripted_effect travel_events_mpo_0001_attempt_effect = {
    current_travel_plan = {
        delay_travel_plan = { days = 5 }
    }
    switch = {
        trigger = scope:bird_catching_method
        flag:normal = {
            duel = {
                skill = prowess
                value = decent_skill_rating
                desc = travel_events_mpo.0001.a_tt
                60 = {
                    desc = travel_events_mpo.0001_win
                    compare_modifier = {
                        value = scope:duel_value
                        multiplier = 3.5
                        min = -59
                    }
                    modifier = {
                        factor = 1.2
                        has_trait = lifestyle_hunter
                    }
                    send_interface_toast = {
                        type = event_toast_effect_good
                        title = travel_events_mpo.0001_win
                        travel_events_mpo_0001_success_effect = yes
                        left_icon = root
                    }
                }
                40 = {
                    desc = travel_events_mpo.0001_lose
                    compare_modifier = {
                        value = scope:duel_value
                        multiplier = -3.5
                        min = -39
                    }
                    send_interface_toast = {
                        type = event_toast_effect_bad
                        title = travel_events_mpo.0001_lose
                        stress_impact = {
                            base = miniscule_stress_impact_gain
                            ambitious = miniscule_stress_impact_gain
                            diligent = miniscule_stress_impact_gain
                        }
                        left_icon = root
                    }
                }
            }
        }
        flag:supplies = {
            duel = {
                skill = stewardship
                value = decent_skill_rating
                desc = travel_events_mpo.0001.b_tt
                70 = {
                    desc = travel_events_mpo.0001_win
                    compare_modifier = {
                        value = scope:duel_value
                        multiplier = 3.5
                        min = -69
                    }
                    modifier = {
                        factor = 1.2
                        has_trait = lifestyle_hunter
                    }
                    send_interface_toast = {
                        type = event_toast_effect_good
                        title = travel_events_mpo.0001_win
                        travel_events_mpo_0001_success_effect = yes
                        left_icon = root
                    }
                }
                30 = {
                    desc = travel_events_mpo.0001_lose
                    compare_modifier = {
                        value = scope:duel_value
                        multiplier = -3.5
                        min = -29
                    }
                    send_interface_toast = {
                        type = event_toast_effect_bad
                        title = travel_events_mpo.0001_lose
                        stress_impact = {
                            base = miniscule_stress_impact_gain
                            ambitious = miniscule_stress_impact_gain
                            diligent = miniscule_stress_impact_gain
                            greedy = minor_stress_impact_gain # we wasted money / supplies on this
                        }
                        left_icon = root
                    }
                }
            }
        }
        flag:huntsmaster = {
            if = {
                limit = {
                    exists = scope:huntsmaster
                }
                scope:huntsmaster = {
                    duel = {
                        skill = prowess
                        value = decent_skill_rating
                        desc = travel_events_mpo.0001.c_tt
                        70 = {
                            desc = travel_events_mpo.0001_win
                            compare_modifier = {
                                value = scope:duel_value
                                multiplier = 3.5
                                min = -69
                            }
                            modifier = {
                                factor = 1.2
                                has_trait = lifestyle_hunter
                            }
                            root = {
                                send_interface_toast = {
                                    type = event_toast_effect_good
                                    title = travel_events_mpo.0001_win
                                    travel_events_mpo_0001_success_effect = yes
                                    scope:huntsmaster = {
                                        add_trait_xp = {
                                            trait = lifestyle_hunter
                                            track = falconer
                                            value = 5
                                        }
                                    }
                                    left_icon = root
                                    right_icon = scope:huntsmaster
                                }
                            }
                        }
                        30 = {
                            desc = travel_events_mpo.0001_lose
                            compare_modifier = {
                                value = scope:duel_value
                                multiplier = -3.5
                                min = -29
                            }
                            stress_impact = {
                                base = miniscule_stress_impact_gain
                                ambitious = miniscule_stress_impact_gain
                                diligent = miniscule_stress_impact_gain
                            }
                            root = {
                                send_interface_toast = {
                                    type = event_toast_effect_bad
                                    title = travel_events_mpo.0001_lose
                                    scope:huntsmaster = {
                                        stress_impact = {
                                            base = miniscule_stress_impact_gain
                                            ambitious = miniscule_stress_impact_gain
                                            diligent = miniscule_stress_impact_gain
                                        }
                                    }
                                    add_opinion = {
                                        target = scope:huntsmaster
                                        modifier = disappointed_opinion
                                        opinion = -15
                                    }
                                    left_icon = root
                                    right_icon = scope:huntsmaster
                                }
                            }
                        }
                    }
                }
            }
        }
        flag:childhood_event = { 
            send_interface_toast = {
                type = event_toast_effect_good
                title = travel_events_mpo.0001_win
                travel_events_mpo_0001_success_effect = yes
                left_icon = root
            }
        }
    }
}

# You spot Eagles circling the sky
travel_events_mpo.0001 = { # By Ariana 
    type = character_event
    title = travel_events_mpo.0001.t
    desc = travel_events_mpo.0001.desc
    theme = migration

    left_portrait = {
        character = root
        animation = personality_rational
    }

    right_portrait = {
        character = scope:eagle_noticer
        animation = storyteller
    }

    lower_center_portrait = {
        trigger = {
            exists = scope:eagle_childhood_teacher
        }
        character = scope:eagle_childhood_teacher
    }

    cooldown = { years = 15 }

    trigger = {
        static_group_filter = {
			group = travel_events_mpo.0001
			match = 0.5
		}
        is_available_travelling_adult = yes
        is_location_valid_for_travel_event_on_land = yes
        location = { geographical_region = world_steppe } 
        government_has_flag = government_is_nomadic
        NOT = { has_eagle_trigger = yes }
        current_travel_plan = { any_entourage_character = { count > 2 } }
    }

    weight_multiplier = {
        base = 1
        modifier = {
            add = 100
            exists = var:eagle_childhood_teacher
        }
        modifier = { # well, we're going to a hunt anyways..
            add = 10
            involved_activity ?= { has_activity_type = activity_hunt }
        }
        modifier = {
            add = 1
            NOT = {
                current_season_trigger = {
                    SEASON = winter
                }
            }
        }
    }

    immediate = {
        current_travel_plan = {
            ordered_entourage_character = {
                limit = {
                    NOT = { this = root }
                    is_adult = yes
                }
                order_by = {
                    value = 1
                    if = {
                        limit = {
                            OR = {
                                has_court_position = master_of_hunt_court_position
                                has_court_position = huntperson_camp_officer
                            }
                        }
                        add = 10
                    }
                    if = {
                        limit = {
                            has_trait = lifestyle_hunter
                        }
                        add = 10
                    }
                }
                save_scope_as = eagle_noticer
            }
        }

        if = {
            limit = {
                is_ai = no # So AI don't spam add modifiers
            }
            if = {
                limit = {
                    location.county = { NOT = { has_county_modifier = hunt_sighting_falconry_modifier } }
                }
                location.county = { add_county_modifier = hunt_sighting_falconry_modifier }
            }
        }

        var:eagle_childhood_teacher ?= { save_scope_as = eagle_childhood_teacher } 

        if = {
            limit = {
                exists = court_position:master_of_hunt_court_position
                current_travel_plan = {
                    any_entourage_character = {
                        this = root.court_position:master_of_hunt_court_position
                    }
                }
            }
            court_position:master_of_hunt_court_position = { save_scope_as = huntsmaster }
        }
        else_if = {
            limit = {
                exists = court_position:huntperson_camp_officer
                current_travel_plan = {
                    any_entourage_character = {
                        this = root.court_position:huntperson_camp_officer
                    }
                }
            }
            court_position:huntperson_camp_officer = { save_scope_as = huntsmaster }
        }
    }

    option = {  # I can catch one
        name = travel_events_mpo.0001.a
        save_scope_value_as = {
            name = bird_catching_method
            value = flag:normal
        }
        travel_events_mpo_0001_attempt_effect = yes
        ai_chance = {
            base = 10
            ai_value_modifier = {
                ai_boldness = 1
            }
            modifier = {
                has_trait = brave
                add = 10
            }
            modifier = {
                has_trait = lifestyle_hunter
                add = 10
            }
            modifier = {
                has_trait = arrogant
                add = 10
            }
        }
    }

    option = { # Use some supplies as bait to increase succcess chance
        name = travel_events_mpo.0001.b
        if = {
            limit = {
                is_landless_adventurer = no
            }
            remove_short_term_gold = minor_gold_value
        }
        else = {
            domicile ?= {
                change_provisions = minor_provisions_loss
            }
        }
        save_scope_value_as = {
            name = bird_catching_method
            value = flag:supplies
        }
        travel_events_mpo_0001_attempt_effect = yes
        stress_impact = {
            greedy = minor_stress_impact_gain
            profligate = minor_stress_impact_loss
        }
        ai_chance = {
            base = 10
            ai_value_modifier = {
                ai_rationality = 1.5
            }
            modifier = {
                has_trait = greedy
                add = -10
            }
            modifier = {
                gold <= medium_gold_value
                factor = 0
            }
        }
    }

    option = { # Have your huntsmaster do it
        name = {
            text = {
                first_valid = {
                    triggered_desc = {
                        trigger = {
                            exists = scope:huntsmaster
                            scope:huntsmaster = scope:eagle_noticer
                        }
                        desc = travel_events_mpo.0001.c_noticer
                    }
                    triggered_desc = {
                        trigger = {
                            exists = scope:huntsmaster
                        }
                        desc = travel_events_mpo.0001.c_huntsmaster
                    }
                    desc = travel_events_mpo.0001.c
                }
            }
        }
        trigger = {
            custom_tooltip = {
                text = travel_events_mpo.0001.c_not
                exists = scope:huntsmaster
            }
        }
        show_as_unavailable = {
            always = yes
        }
        save_scope_value_as = {
            name = bird_catching_method
            value = flag:huntsmaster
        }
        travel_events_mpo_0001_attempt_effect = yes
        ai_chance = {
            base = 10
            ai_value_modifier = {
                ai_rationality = 1
                ai_boldness = 0.8
            }
        }
    }

    option = { # Wait, my father/mother/mentor told me how to do this already
        name = travel_events_mpo.0001.d
        trigger = {
            exists = scope:eagle_childhood_teacher
        }
        save_scope_value_as = {
            name = bird_catching_method
            value = flag:childhood_event
        }
        travel_events_mpo_0001_attempt_effect = yes
        stress_impact = {
            base = minor_stress_impact_loss
        }
        ai_chance = {
            base = 1000
        }
    }

    option = { # Not interested
        name = travel_events_mpo.0001.e
        scope:eagle_noticer = {
            add_opinion = {
                target = root
                modifier = disappointed_opinion
                opinion = -15
            }
        }
        ai_chance = {
            base = 5
            ai_value_modifier = {
                ai_energy = 0.3
            }
            modifier = {
                OR = {
                    has_trait = lazy
                    has_trait = craven
                }
                add = 5
            }
        }
    }
}

# You encounter a muslim trader, riding a white camel
travel_events_mpo.0010 = { # By Ariana 
    type = character_event
    title = travel_events_mpo.0010.t
    desc = travel_events_mpo.0010.desc
    theme = migration

    left_portrait = {
        character = root
        animation = personality_rational
    }

    right_portrait = {
        character = scope:camel_rider
        animation = storyteller
    }

    cooldown = { years = 15 }

    trigger = {
        static_group_filter = {
			group = travel_events_mpo.0010
			match = 0.5
		}
        is_ai = no # For performance because of distance checks
        is_available_travelling_adult = yes
        is_location_valid_for_travel_event_on_land = yes
        location = {    
            geographical_region = world_steppe
        }
        government_has_flag = government_is_nomadic
        #religion:islam_religion = { any_faith = { num_county_followers >= 10 } }
        #any_culture_global = {
        #    exists = culture_head
        #    OR = {
        #        has_cultural_pillar = heritage_arabic 
        #        has_cultural_pillar = heritage_iranian 
        #        has_cultural_pillar = heritage_turkic 
        #        has_cultural_pillar = heritage_berber 
        #    }
        #}
    }

    weight_multiplier = {
        base = 1
        modifier = {
            add = 5
            has_trait = cynical
        }
    }

    immediate = {
        #religion:islam_religion = {
        #    random_faith = {
        #        limit = { 
        #            num_county_followers >= 10
        #        }
        #        save_scope_as = trader_faith
        #    }
        #}
        #random_culture_global = {
        #    limit = {
        #        exists = culture_head
        #        OR = {
        #            has_cultural_pillar = heritage_arabic 
        #            has_cultural_pillar = heritage_iranian 
        #            has_cultural_pillar = heritage_turkic 
        #            has_cultural_pillar = heritage_berber 
        #        }
        #    }
        #    save_scope_as = trader_culture
        #}
        create_character = {
            template = merchant_template
            location = root.location
            #faith = scope:trader_faith
            #culture = scope:trader_culture
            prowess = {
                min_template_decent_skill
                max_template_decent_skill
            }
            save_scope_as = camel_rider
        }
    }

    # Get some herd
    option = {
        name = travel_events_mpo.0010.a
        trigger = {
            domicile ?= { herd <= max_herd }
        }
        flavor = travel_events_mpo.0010.a_flavor
        domicile ?= {
            change_herd = minor_herd_gain
        }
        pay_short_term_gold = {
            target = scope:camel_rider
            gold = medium_gold_value  
        }
        stress_impact = {
            greedy = minor_stress_impact_gain
        }
        ai_chance = {
            base = 100
            ai_value_modifier = {
                ai_greed = -0.5
                ai_rationality = 1
            }
            modifier = {
                gold <= major_gold_value
                factor = 0
            }
        }
    }

    # conversion cheaper or gain piety
    option = {
        name = {
            #EK DISABLED
            #trigger = {
            #    NOT = { faith = { religion_tag = islam_religion } }
            #}
            text = travel_events_mpo.0010.b
        }
        #EK DISABLED
        #name = {
        #    trigger = {
        #        faith = { religion_tag = islam_religion }
        #    }
        #    text = travel_events_mpo.0010.b_islamic
        #}
        flavor = travel_events_mpo.0010.b_flavor
        if = {
            limit = {
                always = no
                #faith = { religion_tag = islam_religion } #EK DISABLED
            }
            add_piety = medium_piety_gain
            stress_impact = {
                zealous = minor_stress_impact_loss
                cynical = minor_stress_impact_gain
            }
        }
        else = {
            add_character_modifier = {
                modifier = mpo_islam_conversion_modifier
                years = 5
            }
            stress_impact = {
                zealous = minor_stress_impact_gain
                cynical = minor_stress_impact_gain
                fickle = minor_stress_impact_loss
            }
        }
        
        ai_chance = {
            base = 75
            #EK DISABLED
            #modifier = {
            #    factor = 1.2
            #    AND = {
            #        faith = { religion_tag = islam_religion }
            #        has_trait = zealous
            #    }
            #}
            modifier = {
                factor = 0
                has_trait = cynical
            }
        }
    }

    # rob him
    option = {
        name = travel_events_mpo.0010.c
        duel = {
            skill = prowess
            target = scope:camel_rider
            desc = travel_events_mpo.0010.c_tt
            40 = {
                desc = travel_events_mpo.0010_win
                compare_modifier = {
                    value = scope:duel_value
                    multiplier = 3.5
                    min = -39
                }
                send_interface_toast = {
                    type = event_toast_effect_good
                    title = travel_events_mpo.0010_win
                    left_icon = root
                    right_icon = scope:camel_rider
                    domicile ?= { change_herd = medium_herd_gain }
                    add_short_term_gold = medium_gold_value
                    scope:camel_rider = {
                        random = {
                            chance = 25
                            increase_wounds_effect = {
                                REASON = fight
                            }
                        }
                    }
                }
            }
            60 = {
                desc = travel_events_mpo.0010_lose
                compare_modifier = {
                    value = scope:duel_value
                    multiplier = -3.5
                    min = -59
                }
                send_interface_toast = {
                    type = event_toast_effect_bad
                    title = travel_events_mpo.0010_lose
                    left_icon = root
                    right_icon = scope:camel_rider
                    add_prestige = minor_prestige_loss
                    random = {
                        chance = 25
                        increase_wounds_effect = {
                            REASON = fight
                        }
                    }
                }
            }
        }
        stress_impact = {
            callous = major_stress_impact_loss
            just = minor_stress_impact_gain
            compassionate = major_stress_impact_gain
            temperate = minor_stress_impact_gain
        }
        ai_chance = {
            base = 60
            ai_value_modifier = {
                ai_compassion = -1.5
            }
            modifier = {
                factor = 1.5
                has_trait = greedy
            }
        }
    }
}