﻿namespace = debate_event

###################################################################################
# SYSTEM EVENTS #
## debate_event.1000 - Preparation Start
## debate_event.1010 - Debate Start (contenders)
## debate_event.1015 - Debate Start (witnesses)
## debate_event.1100 - Debate Target Invalidated
# PREPARATION EVENTS #
## debate_event.2000 - Hothead Disciple Appears
## debate_event.2010 - Recruitment Attempt by Elder from Another Movement
## debate_event.2020 - Movement Member Offers Disciple
## debate_event.2030 - The Way Diverges
# DEBATE EVENTS #
## debate_event.5000 - Debate 1st Strike
## debate_event.5010 - Debate 2nd Strike
## debate_event.5100 - Debate Conclusion
###################################################################################

# Sets debate opponent in events. Apply in _every_ immediate for events to do with being an active participant in debate.

scripted_effect set_opponent_scope_effect = {
    if = {
        limit = {
            this = scope:host
        }
        scope:activity.var:challenged_movement_leader = {
            save_scope_as = debate_opponent
        }
    }
    else = {
        scope:host = {
            save_scope_as = debate_opponent
        }
    }
}

### SYSTEM EVENTS ###

# Preparation Start
debate_event.1000 = {
    type = activity_event
    title = debate_event.1000.t
    desc = {
        first_valid = {
            triggered_desc = {
                trigger = { this = scope:host }
                desc = debate_event.1000.desc_intro_host
            }
            desc = debate_event.1000.desc_intro_fallback
        }
        desc = debate_event.1000.desc_outro
    }

    theme = debate
    override_background = { reference = tgp_chinese_city }

    left_portrait = {
        character = root
        triggered_animation = {
            trigger = { this = scope:host }
            animation = happiness
        }
        animation = holding_scrolls
    }

    option = { # Prepare while we wait
        name = debate_event.1000.a
        # Guests don't need to care about debate score.
        trigger = {
            OR = {
                this = scope:host
                this = scope:activity.var:challenged_movement_leader
            }
        }
        random = {
            chance = {
                value = 25
                if = {
                    limit = { has_trait = diligent }
                    add = 10
                }
                if = {
                    limit = { has_trait = ambitious }
                    add = 10
                }
                if = {
                    limit = { has_trait = humble }
                    add = 5
                }
                if = {
                    limit = { has_trait = fickle }
                    subtract = 5
                }
                if = {
                    limit = { has_trait = gregarious }
                    subtract = 5
                }
                if = {
                    limit = { has_trait = content }
                    subtract = 5
                }
            }
            send_interface_toast = {
                title = debate_event.1000.a.success_desc
                left_icon = root
                
                custom_tooltip = {
                    text = debate_argument_moderate_increase_desc
                    change_variable = {
                        name = tgp_debate_success_score
                        add = {
                            value = var:tgp_debate_success_score
                            multiply = 1.1
                        }
                    }
                }
            }
        }
        
        stress_impact = {
            lazy = medium_stress_impact_gain
        }
        
        ai_chance = {
            base = 10
            modifier = {
                factor = 2
                has_trait = stubborn
            }
            modifier = {
                factor = 2
                has_trait = diligent
            }
            modifier = {
                factor = 0
                has_trait = lazy
            }
        }
    }
    
    option = { # Enjoy the scenery
        name = debate_event.1000.b
        trigger = {
            location = {
                OR = {
                    has_travel_point_of_interest = poi_capitals
                    has_travel_point_of_interest = poi_special_buildings_martial
                    has_travel_point_of_interest = poi_special_buildings_learning
                    has_travel_point_of_interest = poi_special_buildings_religious
                    has_travel_point_of_interest = poi_special_buildings_diplomatic
                    has_travel_point_of_interest = poi_grand_city
                    has_travel_point_of_interest = poi_special_buildings_wonder
                    has_travel_point_of_interest = poi_special_buildings_economic
                    has_travel_point_of_interest = poi_mausoleum_at_halicarnassus
                    has_travel_point_of_interest = poi_lighthouse_of_alexandria
                    has_travel_point_of_interest = poi_natural_feature
                    has_travel_point_of_interest = poi_legend_capitals
                    has_travel_point_of_interest = poi_battles
                    has_travel_point_of_interest = poi_battles_historical
                    has_travel_point_of_interest = poi_special_buildings_stress_relief
                    has_travel_point_of_interest = poi_silk_road_node
                }
            }
        }
        
        if = {
            limit = {
                location = {
                    OR = {
                        has_travel_point_of_interest = poi_capitals
                        has_travel_point_of_interest = poi_grand_city
                        has_travel_point_of_interest = poi_special_buildings_wonder
                        has_travel_point_of_interest = poi_legend_capitals
                        has_travel_point_of_interest = poi_special_buildings_diplomatic
                    }
                }
            }
            change_influence = medium_influence_gain
        }
        else_if = {
            limit = {
                location = {
                    OR = {
                        has_travel_point_of_interest = poi_special_buildings_martial
                        has_travel_point_of_interest = poi_battles
                        has_travel_point_of_interest = poi_battles_historical
                    }
                }
            }
            add_prestige = medium_prestige_gain
        }
        else_if = {
            limit = {
                location = {
                    OR = {
                        has_travel_point_of_interest = poi_special_buildings_learning
                        has_travel_point_of_interest = poi_special_buildings_religious
                        has_travel_point_of_interest = poi_mausoleum_at_halicarnassus
                        has_travel_point_of_interest = poi_lighthouse_of_alexandria
                    }
                }
            }
            add_piety = medium_piety_gain
        }
        else_if = {
            limit = {
                location = {
                    OR = {
                        has_travel_point_of_interest = poi_special_buildings_economic
                        has_travel_point_of_interest = poi_silk_road_node
                    }
                }
            }
            add_poi_stewardship_experience_effect = yes
        }
        else_if = {
            limit = {
                location = {
                    OR = {
                        has_travel_point_of_interest = poi_natural_feature
                        has_travel_point_of_interest = poi_special_buildings_stress_relief
                    }
                }
            }
            if = {
                limit = {
                    has_trait = lifestyle_traveler
                }
                traveler_travel_xp_effect = {
                    MIN = 1
                    MAX = 4
                }
            }
            else = {
                add_trait = lifestyle_traveler
            }
        }
        
        stress_impact = {
            patient = minor_stress_impact_loss
            calm = minor_stress_impact_loss
        }
        
        ai_chance = {
            base = 10
            modifier = {
                factor = 2
                has_trait = eccentric
            }
            modifier = {
                factor = 1.5
                has_trait = gregarious
            }
        }
    }
    
    option = { # Just wait
        name = debate_event.1000.c
        
        stress_impact = {
            base = medium_stress_impact_loss
            patient = minor_stress_impact_loss
            calm = minor_stress_impact_loss
            content = minor_stress_impact_loss
            impatient = minor_stress_impact_gain
        }
        
        ai_chance = {
            base = 20
            modifier = {
                factor = 2
                has_trait = lazy
            }
            modifier = {
                factor = 1.5
                has_trait = content
            }
            modifier = {
                factor = 0
                has_trait = impatient
            }
        }
    }
}

# Debate Start (contenders)
debate_event.1010 = {
    type = activity_event
    title = debate_event.1010.t
    desc = debate_event.1010.desc
    theme = debate
    override_background = {
        trigger = {
            scope:activity = {
                has_activity_option = {
                    category = special_type
                    option = debate_type_favor
                }
            }
        }
        reference = throne_room
    }
    left_portrait = {
        character = root
        animation = war_attacker
        camera = camera_event_left_to_the_left
    }

    center_portrait = {
        character = scope:debate_opponent
        animation = happy_teacher
        camera = camera_event_right_pointing_right
    }

    right_portrait = {
        trigger = { exists = scope:debate_supporter }
        character = scope:debate_supporter
        animation = holding_scrolls
    }

    immediate = {
        set_opponent_scope_effect = yes
        scope:debate_opponent = {
            top_participant_group:dynastic_cycle ?= { 
                save_scope_as = opponent_movement
            }
        }
        scope:activity = {
            if = {
                limit = {
                    any_attending_character = {
                        has_relation_disciple = scope:debate_opponent
                    }
                }
                random_attending_character = {
                    limit = {
                        has_relation_disciple = scope:debate_opponent
                    }
                    save_scope_as = debate_supporter
                }
            }        
        }
    }

    option = { # This will be my moment!
        name = debate_event.1010.a
        add_prestige = minor_prestige_value

        ai_chance = {
            base = 100
        }
    }
}

# Debate Start (witnesses)
debate_event.1015 = {
    type = activity_event
    title = debate_event.1015.t
    desc = {
        desc = debate_event.1015.desc
        first_valid = {
            triggered_desc = {
                trigger = {
                    scope:activity = {
                        has_activity_option = {
                            category = special_type
                            option = debate_type_favor
                        }
                    }
                }
                desc = debate_event.1015.desc_favor
            }
            desc = debate_event.1015.desc_leadership
        }
    }

    theme = debate
    override_background = {
        trigger = {
            scope:activity = {
                has_activity_option = {
                    category = special_type
                    option = debate_type_favor
                }
            }
        }
        reference = tgp_asia_throne_room
    }

    left_portrait = {
        character = root
        animation = admiration
        camera = camera_event_left_pointing_right
    }
    center_portrait = {
        character = scope:debate_contender
        animation = debating
    }
    right_portrait = {
        character = scope:debate_opponent
        animation = pondering
    }

    immediate = {
        top_participant_group:dynastic_cycle ?= { 
            save_scope_as = my_movement
        }
        scope:activity.var:debate_contender = {
            save_scope_as = debate_contender
        }
        scope:activity.var:challenged_movement_leader = {
            save_scope_as = debate_opponent
        }
        scope:debate_contender = {
            top_participant_group:dynastic_cycle ?= { 
                save_scope_as = contender_movement
            }
        }
    }

    option = { # I wonder who will win
        name = debate_event.1015.a

        ai_chance = {
            base = 100
        }
    }
}

# Invalidation event
debate_event.1100 = {
    type = activity_event
    title = debate_event.1100.t
    desc = {
        first_valid = {
            triggered_desc = {
                trigger = {
                    scope:debate_opponent = { is_alive = no }
                }
                desc = debate_event.1100.desc_death
            }
        }
        desc = debate_event.1100.desc_fallback
    }
    theme = debate
    left_portrait = {
        character = root
        animation = disappointed
    }
    lower_right_portrait = scope:debate_opponent
    
    immediate = {
        set_opponent_scope_effect = yes
        # Resume travel plan and go back home
        current_travel_plan ?= {
            if = {
				limit = { can_cancel = yes }
				cancel_travel_plan = yes
			}
        }
    }
    
    option = {
        name = debate_event.1100.a
    }
    
    after = {
        # Clear any remaining variables
        debate_cleanup_effect = yes
    }
}
           
### PREPARATION EVENTS ###

# Hothead Disciple Appears
debate_event.2000 = {
    type = activity_event
    title = debate_event.2000.t
    desc = debate_event.2000.desc

    theme = debate

    left_portrait = {
        character = root
        animation = pondering
    }

    right_portrait = {
        character = scope:talent
        animation = aggressive_unarmed
    }

    cooldown = { months = 1 }

    immediate = {
        scope:activity = {
            ordered_attending_character = {
                order_by = learning
                limit = {
                    this != root
                    merit_level < root.merit_level
                    OR = {
                        top_participant_group:dynastic_cycle ?= root.top_participant_group:dynastic_cycle
                        top_participant_group:dynastic_cycle ?= { participant_group_type = undecided_movement }
                    }
                    NOR = {
                        has_relation_disciple = root
                        # Let's avoid having the player get their kids stolen.
                        any_parent = { is_ai = no }
                        # This char is rowdy
                        has_personality_levelheaded_trigger = yes
                    }
                    opinion = {
                        target = root
                        value >= 0
                    }
                }
                save_scope_as = talent
            }        
        }
    }

    trigger = {
        exists = top_participant_group:dynastic_cycle
        has_activity_intent = debate_gain_disciples_intent
        num_of_relation_disciple < disciples_limit_value
        scope:activity = {
            any_attending_character = {
                this != root
                merit_level < root.merit_level
                OR = {
                    top_participant_group:dynastic_cycle ?= root.top_participant_group:dynastic_cycle
                    top_participant_group:dynastic_cycle ?= { participant_group_type = undecided_movement }
                }
                NOR = {
                    has_relation_disciple = root
                    # Is already an Elder
                    any_relation = { type = disciple }
                    # Let's avoid having the player get their kids stolen.
                    any_parent = { is_ai = no }
                    # This char is rowdy
                    has_personality_levelheaded_trigger = yes
                    # Is disciple of a player character
                    any_relation = {
                        type = elder
                        is_ai = no
                    }
                }
                opinion = {
                    target = root
                    value >= 0
                }
            }        
        }
    }

    option = { # You are destined for great things, under my guidance.
        name = debate_event.2000.a
        set_elder_relation_effect = {
            ELDER = root
            DISCIPLE = scope:talent
            MERIT = 0
        }
        # Save them for rewards list.
        add_to_variable_list = {
            name = debate_disciples
            target = scope:talent
        }
        if = {
            limit = {
                scope:talent = {
                    top_participant_group:dynastic_cycle ?= { participant_group_type = undecided_movement }
                }
            }
            tgp_dynastic_cycle_add_to_movement_effect = { CHAR = scope:talent }
        }

        ai_chance = {
            base = 100
            ai_value_modifier = {
                ai_energy = 1
            }
            # They good
            modifier = {
                scope:talent = {
                    learning >= decent_skill_rating
                }
                add = 20
            }
            # More to gain
            modifier = {
                scope:talent = {
                    top_participant_group:dynastic_cycle ?= { participant_group_type = undecided_movement }
                }
                add = 20
            }
        }
    }

    option = { # Perhaps they have something to teach me?
        name = debate_event.2000.b
        if = {
            limit = {
                NOT = { has_trait = confucian_education }
            }
            add_trait = confucian_education
        }
        add_trait_xp = {
            trait = confucian_education
            value = lifestyle_confucian_education_xp_gain_minor_value
        }
        add_piety = medium_piety_gain
        stress_impact = {
            arrogant = medium_stress_impact_gain
        }
        ai_chance = {
            base = 100
            ai_value_modifier = {
                ai_rationality = 1
                ai_zeal = 0.5
            }
            modifier = {
                has_trait = arrogant
                factor = 0
            }
        }
    }
}

# Recruitment Attempt by Elder from Another Movement
debate_event.2010 = {
    type = activity_event
    title = debate_event.2010.t
    desc = debate_event.2010.desc

    theme = debate

    left_portrait = {
        character = root
        triggered_animation = {
            trigger = {
                OR = {
                    has_trait = content
                    has_trait = craven
                    stress_level >= 1
                }
            }
            animation = worry
        }
        animation = interested
        camera = camera_event_left_pointing_right
    }
    center_portrait = {
        character = scope:elder
        animation = debating
        camera = camera_event_center_pointing_left
    }
    right_portrait = {
        character = scope:other_member
        trigger = { exists = scope:other_member }
        animation = disapproval
        camera = camera_event_center_close_to_right
    }

    cooldown = { months = 1 }

    immediate = {
        top_participant_group:dynastic_cycle ?= { 
            save_scope_as = my_movement
        }
        scope:activity = {
            ordered_attending_character = {
                order_by = learning
                limit = {
                    is_ai = yes
                    this != root
                    merit_level > root.merit_level
                    num_of_relation_disciple < disciples_limit_value
                    NOR = {
                        top_participant_group:dynastic_cycle ?= root.top_participant_group:dynastic_cycle
                        this = root.liege
                        this = root.top_liege
                    }
                    top_participant_group:dynastic_cycle ?= {
                        NOT = { participant_group_type = undecided_movement }
                    }
                }
                save_scope_as = elder
            }
        }
        scope:elder = {
            top_participant_group:dynastic_cycle ?= {
                save_scope_as = elder_movement
            }
        }
        scope:activity = {
            if = {
                limit = {
                    any_attending_character = {
                        this != root
                        top_participant_group:dynastic_cycle ?= root.top_participant_group:dynastic_cycle
                    }
                }
                random_attending_character = {
                    limit = {
                        this != root
                        top_participant_group:dynastic_cycle ?= root.top_participant_group:dynastic_cycle
                    }
                    save_scope_as = other_member
                }
            }
        }
    }

    trigger = {
        exists = top_participant_group:dynastic_cycle
        has_activity_intent = debate_gain_elder_intent
        # We make sure that they do not have a player as their elder.
        trigger_if = {
            limit = {
                any_relation = { type = elder }
            }
            any_relation = {
                type = elder
                is_ai = yes
            }
        }
        top_participant_group:dynastic_cycle ?= {
            NOT = { participant_group_type = undecided_movement }
        }
        OR = { # You're good or a player
            AND = {
                is_ai = no
                has_any_decent_skill_rating = yes
            }
            has_any_high_skill_rating = yes
        }
        NOT = {
            # You're not an elder yourself
            any_relation = { type = disciple }
        }
        OR = { # You don't have an elder or they're pretty bad
            NOT = { any_relation = { type = elder } }
            any_relation = {
                type = elder
                OR = {
                    merit_level <= root.merit_level
                    merit_level <= merit_level_expected_empire_value
                }
            }
        }
        scope:activity = {
            any_attending_character = {
                is_ai = yes
                this != root
                merit_level > root.merit_level
                num_of_relation_disciple < disciples_limit_value
                NOR = {
                    top_participant_group:dynastic_cycle ?= root.top_participant_group:dynastic_cycle
                    this = root.liege
                    this = root.top_liege
                }
            }
        }
    }

    option = { # I choose you!
        name = debate_event.2010.a
        set_elder_relation_effect = {
            ELDER = scope:elder
            DISCIPLE = root
            MERIT = 0
        }
        set_variable = {
            name = new_elder
            value = scope:elder
        }
        stress_impact = {
            diligent = medium_stress_impact_loss
            humble = medium_stress_impact_loss
        }
        ai_chance = {
            base = 100
            ai_value_modifier = {
                ai_boldness = 1
                ai_greed = 0.5
            }
            # They good
            modifier = {
                scope:elder = {
                    learning >= high_skill_rating
                }
                add = 20
            }
            modifier = {
                OR = {
                    has_trait = diligent
                    has_trait = humble
                }
                add = 20
            }
        }
    }

    option = { # I'm sticking with my own, thanks.
        name = debate_event.2010.b
        change_influence = medium_influence_gain
         scope:activity = {
            every_attending_character = {
                limit = {
                    NOT = { this = root }
                    top_participant_group:dynastic_cycle ?= root.top_participant_group:dynastic_cycle
                }
                custom = custom.every_attending_movement_member
                add_opinion = {
                    target = root
                    modifier = pleased_opinion
                    opinion = 5
                }
            }   
        }
        stress_impact = {
            content = medium_stress_impact_loss
            loyal = medium_stress_impact_loss
        }
        ai_chance = {
            base = 100
            ai_value_modifier = {
                ai_energy = -1
            }
            modifier = {
                OR = {
                    has_trait = content
                    has_trait = loyal
                }
                factor = 2
            }
        }
    }
}

# Movement Member Offers Disciple
debate_event.2020 = {
    type = activity_event
    title = debate_event.2020.t
    desc = debate_event.2020.desc

    theme = debate

    left_portrait = {
        character = root
        animation = interested
    }

    center_portrait = {
        character = scope:movement_member
        animation = admiration
        camera = camera_event_center_pointing_left
    }

    right_portrait = {
        character = scope:disciple
        animation = gongshou
    }

    immediate = {
        top_participant_group:dynastic_cycle ?= { 
            save_scope_as = my_movement
        }
        scope:activity = {
            random_attending_character = {
                limit = {
                    this != root
                    merit_level < root.merit_level
                    trigger_if = {
                        limit = {
                            any_relation = { type = elder }
                        }
                        any_relation = {
                            type = elder
                            is_ai = yes
                        }
                    }
                    OR = {
                        top_participant_group:dynastic_cycle ?= root.top_participant_group:dynastic_cycle
                        top_participant_group:dynastic_cycle ?= { participant_group_type = undecided_movement }
                    }
                    NOR = {
                        has_relation_disciple = root
                        # Is already an Elder
                        any_relation = { type = disciple }
                        # Let's avoid having the player get their kids stolen.
                        any_parent = { is_ai = no }
                    }
                }
                assign_quirk_effect = yes
                save_scope_as = disciple
            }
            random_attending_character = {
                limit = {
                    is_ai = yes
                    this != root
                    this != scope:disciple
                    top_participant_group:dynastic_cycle ?= root.top_participant_group:dynastic_cycle
                }
                weight = {
                    base = 1
                    modifier = {
                        has_relation_potential_friend = root
                        add = 25
                    }
                    modifier = {
                        is_close_family_of = root
                        add = 10
                    }
                    modifier = {
                        is_extended_family_of = root
                        add = 5
                    }
                }
                save_scope_as = movement_member
            }
        }
    }

    trigger = {
        exists = top_participant_group:dynastic_cycle
        has_activity_intent = debate_gain_disciples_intent
        num_of_relation_disciple < disciples_limit_value
        scope:activity = {
            any_attending_character = {
                this != root
                merit_level < root.merit_level
                trigger_if = {
                    limit = {
                        any_relation = { type = elder }
                    }
                    any_relation = {
                        type = elder
                        is_ai = yes
                    }
                }
                OR = {
                    top_participant_group:dynastic_cycle ?= root.top_participant_group:dynastic_cycle
                    top_participant_group:dynastic_cycle ?= {
                        participant_group_type = undecided_movement
                    }
                }
                NOR = {
                    has_relation_disciple = root
                    # Is already an Elder
                    any_relation = { type = disciple }
                    # Let's avoid having the player get their kids stolen.
                    any_parent = { is_ai = no }
                }
                save_temporary_scope_as = temp_scope
            }
            any_attending_character = {
                is_ai = yes
                this != root
                this != scope:temp_scope
                top_participant_group:dynastic_cycle ?= root.top_participant_group:dynastic_cycle
            }
        }
    }

    option = { # I'll be their elder!
        name = debate_event.2020.a
        set_elder_relation_effect = {
            ELDER = root
            DISCIPLE = scope:disciple
            MERIT = 0
        }
        # Save them for rewards list.
        add_to_variable_list = {
            name = debate_disciples
            target = scope:disciple
        }
        ai_chance = {
            base = 100
            ai_value_modifier = {
                ai_energy = 1
            }
            # They good
            modifier = {
                scope:disciple = {
                    learning >= decent_skill_rating
                }
                add = 20
            }
        }
    }

    option = { # I care more about our friendship.
        name = debate_event.2020.b
        progress_towards_friend_effect = {
            REASON = friend_given_disciple_reason
            CHARACTER = scope:movement_member
            OPINION = default_friend_opinion
        }
        ai_chance = {
            base = 100
            modifier = {
                OR = {
                    has_trait = gregarious
                    has_trait = generous
                }
                factor = 2
            }
        }
    }
}

# The Way Diverges - Loc ported from IE
debate_event.2030 = {
    type = activity_event
    title = imperial_examination.4080.t
    desc = imperial_examination.4080.desc

    theme = debate
    override_background = { reference = corridor_day }

    left_portrait = {
        character = root
        animation = worry
    }

    center_portrait = {
        character = scope:examiner_1
        animation = anger
    }

    right_portrait = {
        character = scope:examiner_2
        animation = dismissal
    }

    cooldown = { months = 1 }

    immediate = {
        scope:activity = {
            random_attending_character = {
                limit = {
                    is_ai = yes
                    this != root
                    top_participant_group:dynastic_cycle ?= root.top_participant_group:dynastic_cycle
                }
                save_scope_as = examiner_1
            }
            random_attending_character = {
                limit = {
                    is_ai = yes
                    this != root
                    this != scope:examiner_1
                    top_participant_group:dynastic_cycle ?= root.top_participant_group:dynastic_cycle
                }
                save_scope_as = examiner_2
            }
        }
    }

    trigger = {
        exists = top_participant_group:dynastic_cycle
        scope:activity = {
            any_attending_character = {
                is_ai = yes
                this != root
                top_participant_group:dynastic_cycle ?= root.top_participant_group:dynastic_cycle
                save_temporary_scope_as = temp_scope
            }
            any_attending_character = {
                is_ai = yes
                this != root
                this != scope:temp_scope
                top_participant_group:dynastic_cycle ?= root.top_participant_group:dynastic_cycle
            }
        }
    }

    option = { # Side with examiner 1
        name = imperial_examination.4080.a
        bp2_lifestyle_xp_gain_per_type_effect = { VALUE = minor }
        if = {
            limit = {
                can_set_relation_friend_trigger = { CHARACTER = scope:examiner_1 }
            }
            progress_towards_friend_effect = {
                REASON = friend_supported_me_in_dispute
                CHARACTER = scope:examiner_1
                OPINION = default_friend_opinion
            }
        }
        if = {
            limit = {
                can_set_relation_rival_trigger = { CHARACTER = scope:examiner_2 }
            }
            progress_towards_rival_effect = {
                REASON = rival_not_supported_me_in_dispute
                CHARACTER = scope:examiner_2
                OPINION = default_rival_opinion
            }
        }
        stress_impact = {
            honest = minor_stress_impact_loss
            craven = medium_stress_impact_gain
        }
        ai_chance = {
            base = 100
            modifier = {
                add = 20
                has_trait = honest
            }
            modifier = {
                factor = 0
                has_trait = craven
            }
        }
    }

    option = { # Side with examiner 2
        name = imperial_examination.4080.b
        bp2_lifestyle_xp_gain_per_type_effect = { VALUE = minor }
        if = {
            limit = {
                can_set_relation_friend_trigger = { CHARACTER = scope:examiner_2 }
            }
            progress_towards_friend_effect = {
                REASON = friend_supported_me_in_dispute
                CHARACTER = scope:examiner_2
                OPINION = default_friend_opinion
            }
        }
        if = {
            limit = {
                can_set_relation_rival_trigger = { CHARACTER = scope:examiner_1 }
            }
            progress_towards_rival_effect = {
                REASON = rival_not_supported_me_in_dispute
                CHARACTER = scope:examiner_1
                OPINION = default_rival_opinion
            }
        }
        stress_impact = {
            honest = minor_stress_impact_loss
            craven = medium_stress_impact_gain
        }
        ai_chance = {
            base = 100
            modifier = {
                add = 20
                has_trait = honest
            }
            modifier = {
                add = -40
                has_trait = craven
            }
        }
    }

    option = { # I enjoy both in equal measure.
        name = imperial_examination.4080.c
        reverse_add_opinion = {
            target = scope:examiner_1
            modifier = ignored_opinion
            opinion = -15
        }
        reverse_add_opinion = {
            target = scope:examiner_2
            modifier = ignored_opinion
            opinion = -15
        }
        ai_chance = {
            base = 100
            modifier = {
                has_trait = lazy
                add = 50
            }
            modifier = {
                has_trait = fickle
                add = 25
            }
            ai_value_modifier = {
                ai_sociability = -1
            }
        }
    }
}

# Bond with likeminded movement member - Loc ported from IE
debate_event.2040 = {
    type = activity_event
    title = imperial_examination.4090.t
    desc = imperial_examination.4090.desc

    theme = debate
    override_background = { reference = tavern }

    cooldown = { months = 1 }

    left_portrait = {
        character = root
        triggered_animation = {
            trigger = {
                has_trait = shy
            }
            animation = worry
        }
        animation = personality_bold
    }

    right_portrait = {
        character = scope:other_entrant
        animation = happiness
    }

    trigger = {
        scope:activity = {
            has_activity_option = {
                category = special_type
                option = debate_type_leadership
            }
        }
        exists = top_participant_group:dynastic_cycle
        scope:activity = {
            any_attending_character = {
                is_ai = yes
                NOR = {
                    this = root
                    has_trait = shy
                }
                top_participant_group:dynastic_cycle ?= root.top_participant_group:dynastic_cycle
                number_of_traits_in_common = {
                    target = root
                    value >= 1
                }
            }
        }
    }

    immediate = {
        scope:activity = {
            random_attending_character = {
                limit = {
                    is_ai = yes
                    NOR = {
                        this = root
                        has_trait = shy
                    }
                    top_participant_group:dynastic_cycle ?= root.top_participant_group:dynastic_cycle
                    number_of_traits_in_common = {
                        target = root
                        value >= 1
                    }
                }
                save_scope_as = other_entrant
            }
        }
    }

    option = { # Let's hang!
        name = imperial_examination.4090.a
        change_influence = medium_influence_gain
        scope:activity = {
            every_attending_character = {
                limit = {
                    NOT = { this = root }
                    number_of_traits_in_common = {
                        target = root
                        value >= 1
                    }
                }
                custom = custom.every_activity_guest_with_trait_in_common
                add_opinion = {
                    target = root
                    modifier = friendliness_opinion
                    opinion = 20
                }
            }
        }

        stress_impact = {
            gregarious = miniscule_stress_impact_loss
            shy = minor_stress_impact_gain
        }
        ai_chance = {
            base = 100
            ai_value_modifier = {
                ai_sociability = 1
                ai_energy = 0.5
            }
            modifier = {
                add = 10
                has_trait = gregarious
            }
            modifier = {
                add = -10
                has_trait = shy
            }
        }
    }

    option = { # I have important texts to read.
        name = imperial_examination.4090.b
        custom_tooltip = imperial_examination.4090.b.tt
        change_merit = medium_merit_gain

        stress_impact = {
            gregarious = miniscule_stress_impact_gain
            shy = minor_stress_impact_loss
            diligent = medium_stress_impact_loss
        }

        ai_chance = {
            base = 100
            ai_value_modifier = {
                ai_sociability = -1
            }
            modifier = {
                add = -10
                has_trait = gregarious
            }
            modifier = {
                add = 10
                has_trait = shy
            }
            modifier = {
                add = 20
                has_trait = diligent
            }
        }
    }
}

# A potential rival appears - Loc ported from IE
debate_event.2050 = {
    type = activity_event
    title = imperial_examination.4060.t
    desc = imperial_examination.4060.desc_learning

    theme = debate
    override_background = { reference = tavern }

    left_portrait = {
        character = root
        animation = stressed_teacher
    }
    right_portrait = {
        character = scope:promising_lowborn
        animation = debating
    }

    cooldown = { months = 1 }

    immediate = {
        top_participant_group:dynastic_cycle ?= { 
            save_scope_as = my_movement
        }
        scope:activity = {  
            random_attending_character = {
                limit = {
                    is_ai = yes
                    is_lowborn = yes
                    NOT = {
                        top_participant_group:dynastic_cycle ?= root.top_participant_group:dynastic_cycle
                    }
                }
                save_scope_as = promising_lowborn
            }
        }
    }

    trigger = {
        exists = top_participant_group:dynastic_cycle
        has_activity_intent = debate_increase_movement_power_intent
        scope:activity = {
            any_attending_character = {
                is_ai = yes
                is_lowborn = yes
                NOT = {
                    top_participant_group:dynastic_cycle ?= root.top_participant_group:dynastic_cycle
                }
            }
        }
    }

    option = { # I will show them!
        name = imperial_examination.4060.a
        duel = {
            skill = learning
            target = scope:promising_lowborn
            50 = {
                compare_modifier = {
                    value = scope:duel_value
                    multiplier = 3.5
                    min = -49
                }
                desc = imperial_examination.4060.a.success
                send_interface_toast = {
                    title = imperial_examination.4060.a.success
                    left_icon = scope:promising_lowborn
                    custom_tooltip = event_increase_movement_power_medium_effect_tooltip
                    scope:my_movement = {
                        event_change_movement_power_effect = {
                            VALUE = event_increase_movement_power_medium_value
                        }
                    }
                }
            }
            50 = {
                compare_modifier = {
                    value = scope:duel_value
                    multiplier = -3.5
                    min = -49
                }
                desc = imperial_examination.4060.a.failure
                send_interface_toast = {
                    title = imperial_examination.4060.a.failure
                    left_icon = scope:promising_lowborn
                    add_prestige = minor_prestige_loss
                }
                stress_impact = {
                    base = major_stress_impact_gain
                }
            }
        }
        scope:promising_lowborn = {
            set_relation_grudge = {
                target = root
                reason = rival_stifled_my_influence
            }
        }
        ai_chance = {
            base = 100
            ai_value_modifier = {
                ai_energy = 1
            }
            modifier = {
                learning > mediocre_skill_rating
                add = 20
            }
        }
    }

    option = { # Perhaps they have something to teach me?
        name = imperial_examination.4060.b
        change_merit = medium_merit_gain
        stress_impact = {
            arrogant = medium_stress_impact_gain
            cynical = medium_stress_impact_gain
            compassionate = medium_stress_impact_loss
            calm = minor_stress_impact_loss
        }
        ai_chance = {
            base = 100
            ai_value_modifier = {
                ai_compassion = 1
                ai_sociability = 1
            }
        }
    }
}

# Debate another movement - Loc ported from IE
debate_event.2060 = {
    type = activity_event
    title = az_examination.0002.t
    desc = az_examination.0002.desc.debate

    theme = debate
    cooldown = { years = 3 }

    left_portrait = {
        character = root
        animation = anger
    }

    right_portrait = {
        character = scope:debater
        animation = debating
    }

    trigger = {
        exists = top_participant_group:dynastic_cycle
        has_activity_intent = debate_increase_movement_power_intent
        scope:activity = {
            any_attending_character = {
                is_ai = yes
                NOR = {
                    top_participant_group:dynastic_cycle ?= root.top_participant_group:dynastic_cycle
                    top_participant_group:dynastic_cycle ?= { participant_group_type = undecided_movement }
                }
            }
        }
    }

    immediate = {
        top_participant_group:dynastic_cycle ?= { 
            save_scope_as = my_movement
        }
        scope:activity = {
            random_attending_character = {
                limit = {
                    is_ai = yes
                    NOR = {
                        top_participant_group:dynastic_cycle ?= root.top_participant_group:dynastic_cycle
                        top_participant_group:dynastic_cycle ?= { participant_group_type = undecided_movement }
                    }
                }
                save_scope_as = debater
            }
        }
        scope:debater = {
            top_participant_group:dynastic_cycle ?= { 
                save_scope_as = debater_movement
            }
        }
    }

    option = {
        name = az_examination.0002.b  # Argue for the revisionist view
        duel = {
            skill = learning
            target = scope:debater
            50 = {
                compare_modifier = {
                    value = scope:duel_value
                    multiplier = 3.5
                    min = -49
                }
                desc = imperial_examination.4060.a.success
                send_interface_toast = {
                    title = imperial_examination.4060.a.success
                    left_icon = scope:debater
                    custom_tooltip = event_increase_movement_power_medium_effect_tooltip
                    scope:my_movement = {
                        event_change_movement_power_effect = {
                            VALUE = event_increase_movement_power_medium_value
                        }
                    }
                    add_learning_lifestyle_xp = medium_lifestyle_xp
                    if = {
                        limit = { has_trait = confucian_education }
                        add_trait_xp = {
                            trait = confucian_education
                            value = lifestyle_confucian_education_xp_gain_minor_value
                        }
                    }
                }
            }
            50 = {
                compare_modifier = {
                    value = scope:duel_value
                    multiplier = -3.5
                    min = -49
                }
                desc = imperial_examination.4060.a.failure
                send_interface_toast = {
                    title = imperial_examination.4060.a.failure
                    left_icon = scope:debater
                    add_prestige = minor_prestige_loss
                }
                stress_impact = {
                    base = medium_stress_impact_gain
                }
            }
        }
        scope:debater = {
            if = {
                limit = {
                    NOT = { has_relation_rival = root }
                }
                set_relation_rival = {
                    target = root
                    reason = rival_humiliated_in_debate
                }
            }
        }

        ai_chance = {
            base = 30
            ai_value_modifier = {
                ai_zeal = 1
            }
        }
    }

    option = {
        name = az_examination.0002.c  # Calm the debater

        add_diplomacy_lifestyle_xp = medium_lifestyle_xp
        change_merit = medium_merit_gain

        scope:debater = {
            add_opinion = {
                target = root
                modifier = respect_opinion
                opinion = 10
            }
        }

        stress_impact = { trusting = minor_stress_impact_loss }
        ai_chance = {
            base = 25
            modifier = {
                add = 15
                has_trait = trusting
            }
            ai_value_modifier = {
                ai_compassion = 2
            }
        }
    }

    option = {
        name = az_examination.0002.d  # Stay out of it

        add_stress = minor_stress_loss
        ai_chance = {
            base = 15
            modifier = {
                add = 20
                has_trait = shy
            }
            modifier = {
                add = 20
                has_trait = lazy
            }
            modifier = {
                add = 20
                has_trait = callous
            }
            ai_value_modifier = {
                ai_sociability = -2
            }
        }
    }
}

### DEBATE EVENTS ###

# Debate 1st Strike
debate_event.5000 = {
    type = activity_event
    title = {
        first_valid = {
            triggered_desc = {
                trigger = {
                    scope:activity = {
                        has_activity_option = {
                            category = special_type
                            option = debate_type_favor
                        }
                    }
                }
                desc = debate_event.5000.t_imperial_debate
            }
            desc = debate_event.5000.t_movement_debate
        }
    }
    desc = {
        first_valid = {
            triggered_desc = {
                trigger = {
                    scope:activity = {
                        has_activity_option = {
                            category = special_type
                            option = debate_type_favor
                        }
                    }
                }
                desc = debate_event.5000.desc_imperial
            }
            desc = debate_event.5000.desc
        }
    }
    theme = debate
    override_background = {
        trigger = {
            scope:activity = {
                has_activity_option = {
                    category = special_type
                    option = debate_type_favor
                }
            }
        }
        reference = throne_room
    }
    cooldown = { months = 1 }
    left_portrait = {
        character = root
        animation = gongshou
        camera = camera_event_very_left
    }
    right_portrait = {
        character = scope:debate_opponent
        triggered_animation = {
            trigger = {
                scope:activity = {
                    has_activity_option = {
                        category = special_type
                        option = debate_type_leadership
                    }
                }
            }
            animation = debating
        }
        animation = gongshou
    }

    trigger = {
        scope:activity = {
            has_current_phase = debate_phase_debate
        }
    }

    immediate = {
        set_opponent_scope_effect = yes
        if = {
            limit = {
                NOT = { exists = var:tgp_debate_success_score }
            }
            set_variable = {
                name = tgp_debate_success_score
                value = tgp_debate_success_score_value
            }
        }
    }

    option = { # Emphasize confucian values - Confucian trait
        name = debate_event.5000.a
        trigger = {
            has_trait = confucian_education
        }
        add_internal_flag = special
        flavor = debate_event.5000.a.flavor
        
        if = {
            limit = {
                has_trait_xp = {
                    trait = confucian_education
                    value >= 50
                }
            }
            custom_tooltip = {
                text = debate_argument_major_increase_desc
                change_variable = {
                    name = tgp_debate_success_score
                    add = {
                        value = "root.has_trait_xp(confucian_education)"
                    }
                }
            }
        }
        else = {
            custom_tooltip = {
                text = debate_argument_moderate_increase_desc
                change_variable = {
                    name = tgp_debate_success_score
                    add = {
                        value = "root.has_trait_xp(confucian_education)"
                        min = 10
                    }
                }
            }
        }
        set_variable = {
            name = debate_crowd_sentiment
            value = flag:approval
        }
        set_variable = {
            name = debate_selected_tactic
            value = flag:confucian
        }
        ai_chance = { # Characters should choose special option
            base = 200
        }
    }

    option = { # Speak about a new direction - Learning
        name = debate_event.5000.b
        
        duel = {
            skill = learning
            target = scope:debate_opponent
            50 = { # Success
                compare_modifier = {
                    value = scope:duel_value
                    multiplier = 2
                    min = -49
                }
                desc = debate_event.5000.d.success_desc
                send_interface_toast = {
                    title = debate_event.5000.d.success_desc
                    left_icon = root
                    
                    if = {
                        limit = {
                            learning >= high_skill_rating
                        }
                        custom_tooltip = {
                            text = debate_argument_major_increase_desc
                            change_variable = {
                                name = tgp_debate_success_score
                                add = {
                                    value = learning
                                    multiply = 3
                                }
                            }
                        }
                    }
                    else = {
                        custom_tooltip = {
                            text = debate_argument_moderate_increase_desc
                            change_variable = {
                                name = tgp_debate_success_score
                                add = {
                                    value = learning
                                    multiply = 1.5
                                    min = 2
                                }
                            }
                        }
                    }
                }
                set_variable = {
                    name = debate_crowd_sentiment
                    value = flag:approval
                }
            }
            50 = { # Failure
                compare_modifier = {
                    value = scope:duel_value
                    multiplier = -2
                    min = -49
                }
                desc = debate_event.5000.d.failure_desc
                send_interface_toast = {
                    title = debate_event.5000.d.failure_desc
                    left_icon = root
                    
                    if = {
                        limit = {
                            learning < high_skill_rating
                        }
                        custom_tooltip = {
                            text = debate_argument_major_decrease_desc
                            change_variable = {
                                name = tgp_debate_success_score
                                subtract = {
                                    value = 40
                                }
                            }
                        }
                    }
                    else = {
                        custom_tooltip = {
                            text = debate_argument_moderate_decrease_desc
                            change_variable = {
                                name = tgp_debate_success_score
                                subtract = {
                                    value = 30
                                    subtract = learning
                                    min = 10
                                }
                            }
                        }
                    }
                }
                set_variable = {
                    name = debate_crowd_sentiment
                    value = flag:disapproval
                }
            }
        }
        set_variable = {
            name = debate_selected_tactic
            value = flag:learning
        }

        ai_chance = {
            base = 100
            modifier = {
                learning >= high_skill_rating
                add = 50
            }
        }
    }

    option = { # Sway the crowd - Disciples
        name = debate_event.5000.c
        trigger = {
            any_relation = {
                type = disciple
                count >= 1
            }
        }
        flavor = debate_event.5000.c.flavor
        
        random = {
            chance = {
                value = 50
                every_relation = {
                    type = disciple
                    add = 5
                }
                scope:debate_opponent = {
                    every_relation = {
                        type = disciple
                        subtract = 5
                    }
                }
                min = 10
                max = 90
            }
            send_interface_toast = {
                title = debate_event.5000.d.success_desc
                left_icon = root
                
                custom_tooltip = {
                    text = debate_argument_moderate_increase_desc
                    change_variable = {
                        name = tgp_debate_success_score
                        add = {
                            value = var:tgp_debate_success_score
                            multiply = 0.2
                        }
                    }
                }
            }
            
            set_variable = {
                name = debate_crowd_sentiment
                value = flag:approval
            }
        }
        set_variable = {
            name = debate_selected_tactic
            value = flag:manipulation
        }
        ai_chance = {
            base = 100
            modifier = {
                num_of_relation_disciple >= 1
                add = 10
            }
            modifier = {
                num_of_relation_disciple = 5
                add = 50
            }
        }
    }

    option = { # Insult his character and lack of leadership - Diplomacy
        name = debate_event.5000.d
        
        duel = {
            skill = diplomacy
            target = scope:debate_opponent
            50 = { # Success
                compare_modifier = {
                    value = scope:duel_value
                    multiplier = 2
                    min = -49
                }
                desc = debate_event.5000.d.success_desc
                send_interface_toast = {
                    title = debate_event.5000.d.success_desc
                    left_icon = root
                    
                    if = {
                        limit = {
                            diplomacy >= high_skill_rating
                        }
                        custom_tooltip = {
                            text = debate_argument_major_increase_desc
                            change_variable = {
                                name = tgp_debate_success_score
                                add = {
                                    value = diplomacy
                                    multiply = 3
                                }
                            }
                        }
                    }
                    else = {
                        custom_tooltip = {
                            text = debate_argument_moderate_increase_desc
                            change_variable = {
                                name = tgp_debate_success_score
                                add = {
                                    value = diplomacy
                                    multiply = 1.5
                                    min = 2
                                }
                            }
                        }
                    }
                }
                set_variable = {
                    name = debate_crowd_sentiment
                    value = flag:approval
                }
            }
            50 = { # Failure
                compare_modifier = {
                    value = scope:duel_value
                    multiplier = -2
                    min = -49
                }
                desc = debate_event.5000.d.failure_desc
                send_interface_toast = {
                    title = debate_event.5000.d.failure_desc
                    left_icon = root
                    
                    if = {
                        limit = {
                            diplomacy < high_skill_rating
                        }
                        custom_tooltip = {
                            text = debate_argument_major_decrease_desc
                            change_variable = {
                                name = tgp_debate_success_score
                                subtract = {
                                    value = 40
                                }
                            }
                        }
                    }
                    else = {
                        custom_tooltip = {
                            text = debate_argument_moderate_decrease_desc
                            change_variable = {
                                name = tgp_debate_success_score
                                subtract = {
                                    value = 30
                                    subtract = diplomacy
                                    min = 10
                                }
                            }
                        }
                    }
                }
                set_variable = {
                    name = debate_crowd_sentiment
                    value = flag:disapproval
                }
            }
        }
        set_variable = {
            name = debate_selected_tactic
            value = flag:insult
        }
        ai_chance = {
            modifier = {
                diplomacy >= high_skill_rating
                add = 50
            }
        }
    }

    after = {
        trigger_event = debate_event.5010
    }
}

# Debate 2nd Strike
debate_event.5010 = {
    type = activity_event
    title = {
        first_valid = {
            triggered_desc = {
                trigger = {
                    has_activity_intent = debate_increase_movement_power_intent
                }
                desc = debate_event.5000.t_imperial_debate
            }
            desc = debate_event.5000.t_movement_debate
        }
    }
    desc = {
        # Main desc
        first_valid = {
            triggered_desc = {
                trigger = {
                    scope:debate_opponent = { var:debate_selected_tactic ?= flag:insult }
                }
                desc = debate_event.5010.insult_desc
            }
            triggered_desc = {
                trigger = {
                    scope:debate_opponent = { var:debate_selected_tactic ?= flag:confucian }
                }
                desc = debate_event.5010.confucian_desc
            }
            desc = debate_event.5010.desc
        }
        # Outro - Crowd sentiment
        first_valid = {
            triggered_desc = {
                trigger = {
                    scope:debate_opponent = { var:debate_crowd_sentiment ?= flag:approval }
                }
                desc = debate_event.crowd_approval_desc
            }
            desc = debate_event.crowd_disapproval_desc
        }
    }
    theme = debate
    override_background = {
        trigger = {
            scope:activity = {
                has_activity_option = {
                    category = special_type
                    option = debate_type_favor
                }
            }
        }
        reference = throne_room
    }
    cooldown = { days = 7 }
    left_portrait = {
        character = root
        animation = pondering
    }
    right_portrait = {
        character = scope:debate_opponent
        animation = debating
    }

    trigger = {
        scope:activity = {
            has_current_phase = debate_phase_debate
        }
    }

    immediate = {
        set_opponent_scope_effect = yes
    }
    
    option = { # Keep current tactic/argument
        name = debate_event.5010.a
        
        random_list = {
            40 = { # Success
                modifier = { # If the crowd approved of your previous argument, increase chance of success
                    add = 20
                    var:debate_crowd_sentiment ?= flag:approval
                }
                modifier = {
                    add = { value = "root.has_trait_xp(confucian_education)" multiply = 0.35 }
                    var:debate_selected_tactic = flag:confucian
                    has_trait = confucian_education
                }
                modifier = {
                    add = { value = learning multiply = 0.5 }
                    var:debate_selected_tactic ?= flag:learning
                }
                modifier = {
                    add = {
                        value = 0
                        every_relation = {
                            type = disciple
                            add = 3
                        }
                    }
                    var:debate_selected_tactic ?= flag:manipulation
                }
                modifier = {
                    add = { value = diplomacy multiply = 0.5 }
                    var:debate_selected_tactic ?= flag:insult
                }
                
                send_interface_toast = {
                    title = debate_event.5000.d.success_desc
                    left_icon = root
                    
                    custom_tooltip = {
                        text = debate_argument_moderate_increase_desc
                        change_variable = {
                            name = tgp_debate_success_score
                            add = {
                                value = var:tgp_debate_success_score
                                multiply = 0.2
                            }
                        }
                    }
                }
                set_variable = {
                    name = debate_crowd_sentiment
                    value = flag:approval
                }
            }
            60 = { # Failure
                modifier = {
                    add = -20
                    var:debate_crowd_sentiment ?= flag:approval
                }
                modifier = { # Repeating the same argument, if your opponent is doing the same, increases the risk of failure
                    add = 20
                    var:debate_selected_tactic ?= scope:debate_opponent.var:debate_selected_tactic
                }
                modifier = { # If your opponent is manipulating the crowd, we increase it more
                    add = 20
                    var:debate_selected_tactic ?= scope:debate_opponent.var:debate_selected_tactic
                    scope:debate_opponent = { var:debate_selected_tactic ?= flag:manipulation }
                }
                
                send_interface_toast = {
                    title = debate_event.5000.d.failure_desc
                    left_icon = root
                    
                    custom_tooltip = {
                        text = debate_argument_moderate_decrease_desc
                        change_variable = {
                            name = tgp_debate_success_score
                            subtract = {
                                value = var:tgp_debate_success_score
                                multiply = 0.2
                            }
                        }
                    }
                }
            }
        }
        
        ai_chance = {
            base = 30
            
            modifier = {
                factor = 10
                has_trait = stubborn
            }
            modifier = {
                add = 5
                has_trait = patient
            }
            modifier = {
                factor = 0
                has_trait = fickle
            }
            modifier = {
                factor = 10
                var:debate_selected_tactic ?= flag:insult
                scope:debate_opponent = { var:debate_selected_tactic ?= flag:insult }
                has_trait = vengeful
            }
        }
    }
    
    option = { # Change tactic - Confucian values
        name = debate_event.5010.b
        trigger = {
            exists = var:debate_selected_tactic
            var:debate_selected_tactic != flag:confucian
            has_trait = confucian_education
        }
        flavor = debate_event.5000.a.flavor
        
        if = {
            limit = {
                has_trait_xp = {
                    trait = confucian_education
                    value >= 60
                }
            }
            custom_tooltip = {
                text = debate_argument_major_increase_desc
                change_variable = {
                    name = tgp_debate_success_score
                    add = {
                        value = "root.has_trait_xp(confucian_education)"
                        subtract = 10
                    }
                }
            }
        }
        else = {
            custom_tooltip = {
                text = debate_argument_moderate_increase_desc
                change_variable = {
                    name = tgp_debate_success_score
                    add = {
                        value = "root.has_trait_xp(confucian_education)"
                        subtract = 10
                        min = 5
                    }
                }
            }
        }
        
        ai_chance = {
            base = 10
            
            modifier = {
                add = 5
                has_trait = patient
            }
            modifier = {
                factor = 5
                has_trait = stubborn
            }
            modifier = {
                factor = 0
                has_trait = fickle
            }
        }
    }
    
    option = { # Change tactic - Learning
        name = debate_event.5010.c
        trigger = {
            exists = var:debate_selected_tactic
            var:debate_selected_tactic != flag:learning
        }
        
        duel = {
            skill = learning
            target = scope:debate_opponent
            50 = { # Success
                compare_modifier = {
                    value = scope:duel_value
                    multiplier = 2
                    min = -49
                }
                desc = debate_event.5000.d.success_desc
                send_interface_toast = {
                    title = debate_event.5000.d.success_desc
                    left_icon = root
                    
                    if = {
                        limit = {
                            learning >= high_skill_rating
                        }
                        custom_tooltip = {
                            text = debate_argument_major_increase_desc
                            change_variable = {
                                name = tgp_debate_success_score
                                add = {
                                    value = learning
                                    multiply = 3
                                }
                            }
                        }
                    }
                    else = {
                        custom_tooltip = {
                            text = debate_argument_moderate_increase_desc
                            change_variable = {
                                name = tgp_debate_success_score
                                add = {
                                    value = learning
                                    multiply = 1.5
                                    min = 2
                                }
                            }
                        }
                    }
                }
                set_variable = {
                    name = debate_crowd_sentiment
                    value = flag:approval
                }
            }
            50 = { # Failure
                compare_modifier = {
                    value = scope:duel_value
                    multiplier = -2
                    min = -49
                }
                modifier = {
                    add = 10
                    scope:debate_opponent = { var:debate_selected_tactic ?= flag:learning }
                }
                modifier = {
                    add = 10
                    scope:debate_opponent = { var:debate_selected_tactic ?= flag:learning }
                    scope:debate_opponent = { var:debate_crowd_sentiment ?= flag:disapproval }
                }
                desc = debate_event.5000.d.failure_desc
                send_interface_toast = {
                    title = debate_event.5000.d.failure_desc
                    left_icon = root
                    
                    if = {
                        limit = {
                            learning < high_skill_rating
                        }
                        custom_tooltip = {
                            text = debate_argument_major_decrease_desc
                            change_variable = {
                                name = tgp_debate_success_score
                                subtract = {
                                    value = 40
                                }
                            }
                        }
                    }
                    else = {
                        custom_tooltip = {
                            text = debate_argument_moderate_decrease_desc
                            change_variable = {
                                name = tgp_debate_success_score
                                subtract = {
                                    value = 30
                                    subtract = learning
                                    min = 10
                                }
                            }
                        }
                    }
                }
            }
        }
        
        ai_chance = {
            base = 10
            
            modifier = {
                add = 5
                has_trait = patient
            }
            modifier = {
                factor = 5
                has_trait = stubborn
            }
            modifier = {
                factor = 0
                has_trait = fickle
            }
        }
    }
    
    option = { # Change tactic - Manipulate the crowd
        name = debate_event.5010.d
        trigger = {
            exists = var:debate_selected_tactic
            var:debate_selected_tactic != flag:manipulation
            any_relation = {
                type = disciple
                count >= 1
            }
        }
        
        random_list = {
            40 = { # Success
                modifier = {
                    add = {
                        value = 0
                        every_relation = {
                            type = disciple
                            add = 5
                        }
                        scope:debate_opponent = {
                            every_relation = {
                                type = disciple
                                subtract = 5
                            }
                        }
                    }
                    var:debate_selected_tactic ?= flag:confucian
                    has_trait = confucian_education
                }
                
                send_interface_toast = {
                    title = debate_event.5000.d.success_desc
                    left_icon = root
                    
                    custom_tooltip = {
                        text = debate_argument_moderate_increase_desc
                        change_variable = {
                            name = tgp_debate_success_score
                            add = {
                                value = 0
                                every_relation = {
                                    type = disciple
                                    add = {
                                        value = diplomacy
                                        add = intrigue
                                        multiply = 0.5
                                    }
                                }
                            }
                        }
                    }
                }
                set_variable = {
                    name = debate_crowd_sentiment
                    value = flag:approval
                }
            }
            60 = { # Failure
                modifier = { # If opponent has manipulated the crowd already
                    add = 30
                    scope:debate_opponent = { var:debate_selected_tactic ?= flag:manipulation }
                }
                modifier = {
                    add = {
                        value = 0
                        scope:debate_opponent = {
                            every_relation = {
                                type = disciple
                                add = 5
                            }
                        }
                    }
                    var:debate_selected_tactic ?= flag:confucian
                    has_trait = confucian_education
                }
                
                send_interface_toast = {
                    title = debate_event.5000.d.failure_desc
                    left_icon = root
                    
                    custom_tooltip = {
                        text = debate_argument_moderate_decrease_desc
                        change_variable = {
                            name = tgp_debate_success_score
                            subtract = {
                                value = var:tgp_debate_success_score
                                multiply = 0.2
                            }
                            subtract = {
                                value = 0
                                scope:debate_opponent = {
                                    every_relation = {
                                        type = disciple
                                        add = {
                                            value = diplomacy
                                            add = intrigue
                                            multiply = 0.5
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        stress_impact = {
            just = medium_stress_impact_gain
            honest = medium_stress_impact_gain
        }
        
        ai_chance = {
            base = 10
            
            modifier = {
                add = 5
                has_trait = deceitful
            }
            modifier = {
                add = 5
                has_trait = arrogant
            }
            modifier = {
                OR = {
                    has_trait = just
                    has_trait = honest
                }
                factor = 0
            }
            modifier = {
                add = 5
                any_relation = {
                    type = disciple
                    count > 4
                }
            }
        }
    }
    
    option = { # Change tactic - Insult your opponent
        name = debate_event.5010.e
        trigger = {
            exists = var:debate_selected_tactic
            var:debate_selected_tactic != flag:insult
        }
        
        duel = {
            skill = diplomacy
            target = scope:debate_opponent
            50 = { # Success
                compare_modifier = {
                    value = scope:duel_value
                    multiplier = 2
                    min = -49
                }
                desc = debate_event.5000.d.success_desc
                send_interface_toast = {
                    title = debate_event.5000.d.success_desc
                    left_icon = root
                    
                    if = {
                        limit = {
                            diplomacy >= high_skill_rating
                        }
                        custom_tooltip = {
                            text = debate_argument_major_increase_desc
                            change_variable = {
                                name = tgp_debate_success_score
                                add = {
                                    value = diplomacy
                                    multiply = 3
                                }
                            }
                        }
                    }
                    else = {
                        custom_tooltip = {
                            text = debate_argument_moderate_increase_desc
                            change_variable = {
                                name = tgp_debate_success_score
                                add = {
                                    value = diplomacy
                                    multiply = 1.5
                                    min = 2
                                }
                            }
                        }
                    }
                }
                set_variable = {
                    name = debate_crowd_sentiment
                    value = flag:approval
                }
            }
            50 = { # Failure
                compare_modifier = {
                    value = scope:duel_value
                    multiplier = -2
                    min = -49
                }
                modifier = {
                    add = 10
                    scope:debate_opponent = { var:debate_selected_tactic ?= flag:insult }
                }
                modifier = {
                    add = 10
                    scope:debate_opponent = { var:debate_selected_tactic ?= flag:insult }
                    scope:debate_opponent = { var:debate_crowd_sentiment ?= flag:disapproval }
                }
                desc = debate_event.5000.d.failure_desc
                send_interface_toast = {
                    title = debate_event.5000.d.failure_desc
                    left_icon = root
                    
                    if = {
                        limit = {
                            diplomacy < high_skill_rating
                        }
                        custom_tooltip = {
                            text = debate_argument_major_decrease_desc
                            change_variable = {
                                name = tgp_debate_success_score
                                subtract = {
                                    value = 40
                                }
                            }
                        }
                    }
                    else = {
                        custom_tooltip = {
                            text = debate_argument_moderate_decrease_desc
                            change_variable = {
                                name = tgp_debate_success_score
                                subtract = {
                                    value = 30
                                    subtract = diplomacy
                                    min = 10
                                }
                            }
                        }
                    }
                }
                set_variable = {
                    name = debate_crowd_sentiment
                    value = flag:disapproval
                }
            }
        }
        
        ai_chance = {
            base = 10
            modifier = {
                factor = 5
                has_trait = stubborn
            }
            modifier = {
                factor = 10
                scope:debate_opponent = { var:debate_selected_tactic ?= flag:insult }
                has_trait = vengeful
            }
        }
    }

    after = {
        if = {
            limit = {
                # Should only fire once
                this = scope:host
                scope:activity = {
                    has_activity_option = {
                        category = special_type
                        option = debate_type_favor
                    }
                }
            }
            top_liege = {
                if = {
                    limit = { involved_activity ?= scope:activity }
                    # Trigger activity event
                    trigger_event = debate_event.5111
                }
                else = {
                    # Trigger character event
                    trigger_event = debate_event.5110
                }
            }
        }
        else = {
            # The top liege is not directly involved
            trigger_event = debate_event.5100
        }
    }
}

# Debate Outcome
debate_event.5100 = {
    type = activity_event
    title = {
        desc = debate_event.5000.t_movement_debate
        first_valid = {
            triggered_desc = {
                trigger = {
                    root = scope:debate_winner
                }
                desc = debate_event.5100.t_winner
            }
            desc = debate_event.5100.t_loser
        }
    }
    desc = {
        first_valid = {
            # Special desc if winning/losing was unexpected
            triggered_desc = {
                trigger = {
                    exists = scope:debate_unexpected_win
                    root = scope:debate_winner
                }
                desc = debate_event.5100.desc_unexpected_winner
            }
            triggered_desc = {
                trigger = {
                    exists = scope:debate_unexpected_win
                    root = scope:debate_loser
                }
                desc = debate_event.5100.desc_unexpected_loser
            }
            # Regular desc
            triggered_desc = {
                trigger = {
                    root = scope:debate_winner
                }
                desc = debate_event.5100.desc_winner
            }
            desc = debate_event.5100.desc_loser
        }
    }
    theme = debate
    left_portrait = {
        character = root
        triggered_animation = {
            trigger = {
                exists = scope:debate_unexpected_win
                this = scope:debate_winner
            }
            animation = disbelief
        }
        triggered_animation = {
            trigger = {
                exists = scope:debate_unexpected_win
                this = scope:debate_loser
            }
            animation = shock
        }
        triggered_animation = {
            trigger = {
                this = scope:debate_winner
            }
            animation = ecstasy
        }
        animation = disappointed
    }
    right_portrait = {
        character = scope:debate_opponent
        triggered_animation = {
            trigger = {
                exists = scope:debate_unexpected_win
                this = scope:debate_winner
            }
            animation = disbelief
        }
        triggered_animation = {
            trigger = {
                exists = scope:debate_unexpected_win
                this = scope:debate_loser
            }
            animation = shock
        }
        triggered_animation = {
            trigger = {
                this = scope:debate_winner
            }
            animation = happiness
        }
        animation = disapproval
    }

    immediate = {
        top_participant_group:dynastic_cycle ?= { 
            save_scope_as = my_movement
        }
        set_opponent_scope_effect = yes
        debate_determine_outcome_effect = yes
    }

    trigger = {
        scope:activity = {
            has_current_phase = debate_phase_debate
        }
        this = scope:host
    }
    
    option = {
        name = {
            trigger = {
                this = scope:debate_winner
            }
            text = debate_event.5100.a
        }
        name = {
            trigger = {
                this = scope:debate_loser
            }
            text = debate_event.5100.b
        }
    }
}

# Top liege is informed of results and may pick a winner (character event)
debate_event.5110 = {
    type = character_event
    title = debate_event.5000.t_imperial_debate
    desc = debate_event.5110.desc
    theme = debate
    left_portrait = {
        character = root
        animation = pondering
    }
    lower_left_portrait = {
        character = scope:debate_loser
    }
    lower_right_portrait = {
        character = scope:debate_winner
    }
    
    immediate = {
        scope:host = {
            save_scope_as = debate_contender
        }
        set_opponent_scope_effect = yes
        # Determine the winner of the debate
        hidden_effect = {
            scope:debate_contender = {
                debate_determine_outcome_effect = yes
            }
        }
    }

    option = { # Declare the loser as the winner - Because you can
        name = debate_event.5110.b
        add_legitimacy = minor_legitimacy_loss
        scope:debate_loser = {
            show_as_tooltip = {
                if = {
                    limit = {
                        NOT = { exists = top_participant_group:dynastic_cycle.var:movement_favored }
                    }
                    situation:dynastic_cycle ?= {
                        random_participant_group = {
                            limit = {
                                participant_group_has_character = scope:debate_loser
                            }
                            make_movement_favored_effect = yes
                        }
                    }
                }
            }
            save_scope_as = declared_winner
        }
        scope:activity = {
            set_variable = {
                name = debate_winner
                value = scope:declared_winner
            }
        }
        scope:activity = {
            set_variable = {
                name = debate_loser
                value = scope:debate_winner
            }
        }
        ai_chance = {
            base = 10
            
            # Opinion
            opinion_modifier = {
                opinion_target = scope:debate_loser
                multiplier = 0.5
            }
            
            # Relation
            modifier = {
                add = 50
                is_close_family_of = scope:debate_loser
            }
            modifier = {
                add = 50
                has_relation_friend = scope:debate_loser
            }
            modifier = {
                add = 30
                is_spouse_of = scope:debate_loser
            }
            modifier = {
                add = 30
                has_relation_lover = scope:debate_loser
            }
            modifier = {
                add = 25
                has_relation_elder = scope:debate_loser
            }
            modifier = {
                add = 20
                has_relation_disciple = scope:debate_loser
            }
            modifier = {
                add = 15
                scope:debate_loser = { is_councillor_of = root }
            }
            modifier = {
                add = -50
                has_relation_disciple = scope:debate_loser
            }
            
            # Personality
            modifier = {
                add = 20
                has_trait = eccentric
            }
            modifier = {
                factor = 1.5
                has_trait = arbitrary
            }
        }
    }
    
    option = { # Confirm the winner
        name = debate_event.5110.a
        scope:debate_winner = {
            show_as_tooltip = {
                if = {
                    limit = {
                        NOT = { exists = top_participant_group:dynastic_cycle.var:movement_favored }
                    }
                    situation:dynastic_cycle ?= {
                        random_participant_group = {
                            limit = {
                                participant_group_has_character = scope:debate_winner
                            }
                            make_movement_favored_effect = yes
                        }
                    }
                }
            }
        }
        scope:activity = {
            set_variable = {
                name = debate_winner
                value = scope:debate_winner
            }
        }
        scope:activity = {
            set_variable = {
                name = debate_loser
                value = scope:debate_loser
            }
        }
        ai_chance = {
            base = 90
            
            # Opinion
            opinion_modifier = {
                opinion_target = scope:debate_winner
                multiplier = 0.5
            }
            
            # Relation
            modifier = {
                add = 100
                is_close_family_of = scope:debate_winner
            }
            modifier = {
                add = 100
                has_relation_friend = scope:debate_winner
            }
            modifier = {
                add = 60
                is_spouse_of = scope:debate_winner
            }
            modifier = {
                add = 60
                has_relation_lover = scope:debate_winner
            }
            modifier = {
                add = 50
                has_relation_elder = scope:debate_winner
            }
            modifier = {
                add = 40
                has_relation_disciple = scope:debate_winner
            }
            modifier = {
                add = 30
                scope:debate_winner = { is_councillor_of = root }
            }
            modifier = {
                add = -30
                has_relation_disciple = scope:debate_winner
            }
            
            # Personality
            modifier = {
                add = 50
                has_trait = just
            }
            modifier = {
                add = 50
                has_trait = honest
            }
        }
    }
    
    after = {
        scope:activity.var:debate_contender = { trigger_event = debate_event.5120 }
    }
}

# Top liege is informed of results and may pick a winner (activity event)
debate_event.5111 = {
    type = activity_event
    title = debate_event.5000.t_imperial_debate
    desc = debate_event.5110.desc
    theme = debate
    override_background = {
        trigger = {
            scope:activity = {
                has_activity_option = {
                    category = special_type
                    option = debate_type_favor
                }
            }
        }
        reference = throne_room
    }
    left_portrait = {
        character = root
        animation = disappointed
    }
    lower_left_portrait = {
        character = scope:activity.var:debate_contender
    }
    lower_right_portrait = {
        character = scope:activity.var:challenged_movement_leader
    }
    
    immediate = {
        scope:host = {
            save_scope_as = debate_contender
        }
        # Determine the winner of the debate
        hidden_effect = {
            scope:debate_contender = {
                set_opponent_scope_effect = yes
                debate_determine_outcome_effect = yes
            }
        }
    }
    
    option = { # Confirm the winner
        name = debate_event.5110.a
        scope:debate_winner = {
            show_as_tooltip = {
                if = {
                    limit = {
                        NOT = { exists = top_participant_group:dynastic_cycle.var:movement_favored }
                    }
                    situation:dynastic_cycle ?= {
                        random_participant_group = {
                            limit = {
                                participant_group_has_character = scope:debate_winner
                            }
                            make_movement_favored_effect = yes
                        }
                    }
                }
            }
        }
        scope:activity = {
            set_variable = {
                name = debate_winner
                value = scope:debate_winner
            }
        }
        scope:activity = {
            set_variable = {
                name = debate_loser
                value = scope:debate_loser
            }
        }
        ai_chance = {
            base = 90
            
            # Opinion
            opinion_modifier = {
                opinion_target = scope:debate_winner
                multiplier = 0.5
            }
            
            # Relation
            modifier = {
                add = 100
                is_close_family_of = scope:debate_winner
            }
            modifier = {
                add = 100
                has_relation_friend = scope:debate_winner
            }
            modifier = {
                add = 60
                is_spouse_of = scope:debate_winner
            }
            modifier = {
                add = 60
                has_relation_lover = scope:debate_winner
            }
            modifier = {
                add = 50
                has_relation_elder = scope:debate_winner
            }
            modifier = {
                add = 40
                has_relation_disciple = scope:debate_winner
            }
            modifier = {
                add = 30
                scope:debate_winner = { is_councillor_of = root }
            }
            modifier = {
                add = -30
                has_relation_disciple = scope:debate_winner
            }
            
            # Personality
            modifier = {
                add = 50
                has_trait = just
            }
            modifier = {
                add = 50
                has_trait = honest
            }
        }
    }
    
    option = { # Declare the loser as the winner - Because you can
        name = debate_event.5110.b
        add_legitimacy = minor_legitimacy_loss
        scope:debate_loser = {
            show_as_tooltip = {
                if = {
                    limit = {
                        NOT = { exists = top_participant_group:dynastic_cycle.var:movement_favored }
                    }
                    situation:dynastic_cycle ?= {
                        random_participant_group = {
                            limit = {
                                participant_group_has_character = scope:debate_loser
                            }
                            make_movement_favored_effect = yes
                        }
                    }
                }
            }
            save_scope_as = declared_winner
        }
        scope:activity = {
            set_variable = {
                name = debate_winner
                value = scope:declared_winner
            }
        }
        scope:activity = {
            set_variable = {
                name = debate_loser
                value = scope:debate_winner
            }
        }
        ai_chance = {
            base = 10
            
            # Opinion
            opinion_modifier = {
                opinion_target = scope:debate_loser
                multiplier = 0.5
            }
            
            # Relation
            modifier = {
                add = 50
                is_close_family_of = scope:debate_loser
            }
            modifier = {
                add = 50
                has_relation_friend = scope:debate_loser
            }
            modifier = {
                add = 30
                is_spouse_of = scope:debate_loser
            }
            modifier = {
                add = 30
                has_relation_lover = scope:debate_loser
            }
            modifier = {
                add = 25
                has_relation_elder = scope:debate_loser
            }
            modifier = {
                add = 20
                has_relation_disciple = scope:debate_loser
            }
            modifier = {
                add = 15
                scope:debate_loser = { is_councillor_of = root }
            }
            modifier = {
                add = -50
                has_relation_disciple = scope:debate_loser
            }
            
            # Personality
            modifier = {
                add = 20
                has_trait = eccentric
            }
            modifier = {
                factor = 1.5
                has_trait = arbitrary
            }
        }
    }
    
    after = {
        scope:debate_contender = { trigger_event = debate_event.5120 }
    }
}

# Top Liege Announces Winner
debate_event.5120 = {
    type = activity_event
    title = {
        first_valid = {
            triggered_desc = {
                trigger = {
                    has_activity_intent = debate_increase_movement_power_intent
                }
                desc = debate_event.5000.t_imperial_debate
            }
            desc = debate_event.5000.t_movement_debate
        }
        first_valid = {
            triggered_desc = {
                trigger = {
                    root = scope:debate_winner
                }
                desc = debate_event.5100.t_winner
            }
            desc = debate_event.5100.t_loser
        }
    }
    desc = {
        first_valid = {
            # Main desc
            triggered_desc = {
                trigger = {
                    root = scope:debate_winner
                }
                desc = debate_event.5120.desc_winner
            }
            desc = debate_event.5120.desc_loser
        }
        first_valid = {
            # Main desc
            triggered_desc = {
                trigger = {
                    root.top_liege = { involved_activity ?= scope:activity }
                }
                desc = debate_event.5120.bridge_hegemon_available
            }
            desc = debate_event.5120.bridge_fallback
        }
        first_valid = {
            # Main desc
            triggered_desc = {
                trigger = {
                    root.top_liege = { involved_activity ?= scope:activity }
                    exists = scope:declared_winner
                }
                desc = debate_event.5120.desc_liege_intervene
            }
            triggered_desc = {
                trigger = {
                    root.top_liege = { involved_activity ?= scope:activity }
                    NOT = { exists = scope:declared_winner }
                }
                desc = debate_event.5120.desc_liege_confirm
            }
            desc = debate_event.5120.desc_liege_confirm_fallback
        }
    }
    theme = debate
    override_background = {
        trigger = {
            scope:activity = {
                has_activity_option = {
                    category = special_type
                    option = debate_type_favor
                }
            }
        }
        reference = throne_room
    }
    left_portrait = {
        character = root
        triggered_animation = {
            trigger = {
                exists = scope:debate_unexpected_win
                this = scope:debate_winner
            }
            animation = disbelief
        }
        triggered_animation = {
            trigger = {
                exists = scope:debate_unexpected_win
                this = scope:debate_loser
            }
            animation = shock
        }
        triggered_animation = {
            trigger = {
                this = scope:debate_winner
            }
            animation = ecstasy
        }
        animation = disappointed
    }
    center_portrait = {
        trigger = {
            root.top_liege = { involved_activity ?= scope:activity }
        }
        character = root.top_liege
        animation = pondering
    }
    right_portrait = {
        character = scope:debate_opponent
        triggered_animation = {
            trigger = {
                exists = scope:debate_unexpected_win
                this = scope:debate_winner
            }
            animation = disbelief
        }
        triggered_animation = {
            trigger = {
                exists = scope:debate_unexpected_win
                this = scope:debate_loser
            }
            animation = shock
        }
        triggered_animation = {
            trigger = {
                this = scope:debate_winner
            }
            animation = happiness
        }
        animation = disapproval
    }
    lower_center_portrait = {
        trigger = {
            root.top_liege = {
                NOT = { involved_activity ?= scope:activity }
            }
        }
        character = root.top_liege
    }
    
    immediate = {
        set_opponent_scope_effect = yes
        if = {
            limit = {
                root = scope:debate_winner
            }
            top_participant_group:dynastic_cycle ?= { 
                save_scope_as = winning_movement
            }
        }
        else = {
            scope:debate_opponent = {
                top_participant_group:dynastic_cycle ?= { 
                    save_scope_as = winning_movement
                }
            }
        }
    }
    
    option = {
        name = {
            trigger = {
                this = scope:debate_winner
                NOT = { exists = scope:declared_winner }
            }
            text = debate_event.5120.a
        }
        name = {
            trigger = {
                exists = scope:declared_winner
                this = scope:declared_winner
            }
            text = debate_event.5120.b
        }
        name = {
            trigger = {
                this = scope:debate_loser
                NOT = { exists = scope:declared_winner }
            }
            text = debate_event.5120.c
        }
        
        # Apply remaining effects
        if = {
            limit = {
                OR = {
                    AND = {
                        this = scope:debate_winner
                        NOT = { exists = scope:declared_winner }
                    }
                    AND = {
                        exists = scope:declared_winner
                        this = scope:declared_winner
                    }
                }
            }
            if = {
                limit = {
                    NOT = { exists = top_participant_group:dynastic_cycle.var:movement_favored }
                }
                situation:dynastic_cycle ?= {
                    random_participant_group = {
                        limit = {
                            participant_group_has_character = scope:debate_winner
                        }
                        make_movement_favored_effect = yes
                    }
                }
            }
            change_influence = monumental_influence_gain
            add_prestige = major_prestige_gain
        }
    }
}

# Debate Outcome - Guests
debate_event.5130 = {
    type = activity_event
    title = {
        first_valid = {
            triggered_desc = {
                trigger = {
                    scope:activity = {
                        has_activity_option = {
                            category = special_type
                            option = debate_type_favor
                        }
                    }
                }
                desc = debate_event.5000.t_imperial_debate
            }
            desc = debate_event.5000.t_movement_debate
        }
    }
    desc = debate_event.5120.desc_loser

    theme = debate
    override_background = {
        trigger = {
            scope:activity = {
                has_activity_option = {
                    category = special_type
                    option = debate_type_favor
                }
            }
        }
        reference = tgp_asia_throne_room
    }

    left_portrait = {
        character = root
        animation = admiration
        camera = camera_event_left_pointing_right
    }
    center_portrait = {
        character = scope:debate_winner
        animation = war_over_win
    }
    right_portrait = {
        character = scope:debate_loser
        animation = shame
    }

    immediate = {
        scope:activity.var:debate_winner = { save_scope_as = debate_winner }
        scope:activity.var:debate_loser = { save_scope_as = debate_loser }
    }

    option = {
        #Pick what text to display
        name = { # Favor Debate - Your Movement won!
            trigger = {
                scope:activity = {
                    has_activity_option = {
                        category = special_type
                        option = debate_type_favor
                    }
                }
                scope:host = { this = scope:activity.var:debate_winner }
                is_in_same_movement_as = { TARGET = scope:host }
            }
            text = tgp_dynastic_cycle_decision_event.0082.a
        }
        name = { # Favor Debate - Your Movement lost!
            trigger = {
                scope:activity = {
                    has_activity_option = {
                        category = special_type
                        option = debate_type_favor
                    }
                }
                scope:host = { this = scope:activity.var:debate_winner }
                exists = top_participant_group:dynastic_cycle
                top_participant_group:dynastic_cycle != scope:host.top_participant_group:dynastic_cycle
            }
            text = debate_event.5120.c
        }
        name = {
            trigger = {
                scope:activity = {
                    has_activity_option = {
                        category = special_type
                        option = debate_type_leadership
                    }
                }
            }
            text = hunt.2500.a
        }
        change_merit = medium_merit_gain
        ai_chance = {
            base = 100
        }
    }
}