﻿namespace = domcom_communion

# Deepen Communion now chooses a real shared activity. The activity itself is played through CK3's
# board-game or single-combat systems; the partner's personality can make one activity more rewarding.
domcom_communion.100 = {
    type = character_event
    title = domcom_communion.100.t
    desc = domcom_communion.100.desc
    theme = seduction
    trigger = {
        has_variable = domcom_communion_event_target
        var:domcom_communion_event_target = { is_alive = yes }
    }
    immediate = {
        hidden_effect = {
     var:domcom_communion_event_target = { save_scope_as = domcom_communion_target } 
        }
    }
    left_portrait = { character = root animation = personality_rational }
    right_portrait = { character = scope:domcom_communion_target animation = flirtation_left }

    option = {
        name = domcom_communion.100.a
        trigger = {
            has_fp2_dlc_trigger = yes
            bg_can_start_board_game_trigger = yes
            can_start_board_game_eligibility_checks_trigger = yes
            bg_can_start_board_game_is_scope_banned_checks_trigger = no
            scope:domcom_communion_target = {
                can_start_board_game_eligibility_checks_trigger = yes
                bg_can_start_board_game_is_scope_banned_checks_trigger = no
            }
        }
        custom_tooltip = domcom_communion.100.a.tt
        configure_start_board_game_effect = {
            BG_INITIATOR = root
            BG_ATTACKER = root
            BG_DEFENDER = scope:domcom_communion_target
            SYSTEM = chess
            LOCALE = random_nice_day
            OUTPUT_EVENT = domcom_communion.140
            INVALIDATION_EVENT = domcom_communion.190
        }
    }

    option = {
        name = domcom_communion.100.b
        trigger = {
            is_imprisoned = no
            can_start_single_combat_trigger = yes
            can_start_single_combat_banned_checks_trigger = no
            scope:domcom_communion_target = {
                is_imprisoned = no
                can_start_single_combat_trigger = yes
                can_start_single_combat_banned_checks_trigger = no
            }
        }
        custom_tooltip = domcom_communion.100.b.tt
        configure_start_single_combat_effect = {
            SC_INITIATOR = root
            SC_ATTACKER = root
            SC_DEFENDER = scope:domcom_communion_target
            FATALITY = no
            FIXED = no
            LOCALE = terrain_scope
            OUTPUT_EVENT = domcom_communion.150
            INVALIDATION_EVENT = domcom_communion.190
        }
    }

    option = {
        name = domcom_communion.100.c
        custom_tooltip = domcom_communion.100.c.tt
        hidden_effect = {
            scope:domcom_communion_target = {
                if = { limit = { NOT = { has_variable = domcom_obedience } } set_variable = { name = domcom_obedience value = 0 } }
                change_variable = { name = domcom_obedience add = 55 }
                if = { limit = { OR = { has_trait = compassionate has_trait = calm has_trait = content has_trait = gregarious has_trait = lustful } } change_variable = { name = domcom_obedience add = 25 } }
                if = { limit = { has_relation_soulmate = root } change_variable = { name = domcom_obedience add = 20 } }
                if = { limit = { var:domcom_obedience > 1000 } set_variable = { name = domcom_obedience value = 1000 } }
                add_opinion = { target = root modifier = domcom_deepen_communion_good_opinion }
                domcom_refresh_obedience_stage_effect = yes
            }
            domcom_cleanup_communion_event_effect = yes
        }
    }

    option = {
        name = domcom_communion.100.d
        custom_tooltip = domcom_communion.100.d.tt
        hidden_effect = {
            root = {
                remove_interaction_cooldown_against = {
                    interaction = domcom_deepen_communion_interaction
                    target = scope:domcom_communion_target
                }
            }
            domcom_cleanup_communion_event_effect = yes
        }
    }
}

# Real board-game result. Both outcomes deepen the relationship; winning earns more, while a partner who
# enjoys strategy and a Soulmate bond add explicit bonuses.
domcom_communion.140 = {
    hidden = yes
    immediate = {
        if = {
            limit = { scope:bg_victor = root }
            scope:bg_loser = { save_scope_as = domcom_communion_target }
        }
        else = {
            scope:bg_victor = { save_scope_as = domcom_communion_target }
        }
        scope:domcom_communion_target = {
            if = { limit = { NOT = { has_variable = domcom_obedience } } set_variable = { name = domcom_obedience value = 0 } }
            if = { limit = { scope:bg_victor = root } change_variable = { name = domcom_obedience add = 120 } }
            else = { change_variable = { name = domcom_obedience add = 90 } }
            if = { limit = { OR = { has_trait = patient has_trait = diligent has_trait = shrewd has_trait = deceitful } } change_variable = { name = domcom_obedience add = 25 } }
            if = { limit = { has_relation_soulmate = root } change_variable = { name = domcom_obedience add = 20 } }
            if = { limit = { var:domcom_obedience > 1000 } set_variable = { name = domcom_obedience value = 1000 } }
            add_opinion = { target = root modifier = domcom_deepen_communion_good_opinion }
            domcom_refresh_obedience_stage_effect = yes
        }
        domcom_cleanup_communion_event_effect = yes
    }
}

# Real nonfatal sparring result. The contest outcome matters, and martial/bold partners enjoy the choice
# more regardless of who wins.
domcom_communion.150 = {
    hidden = yes
    immediate = {
        if = {
            limit = { scope:sc_victor = root }
            scope:sc_loser = { save_scope_as = domcom_communion_target }
        }
        else = {
            scope:sc_victor = { save_scope_as = domcom_communion_target }
        }
        scope:domcom_communion_target = {
            if = { limit = { NOT = { has_variable = domcom_obedience } } set_variable = { name = domcom_obedience value = 0 } }
            if = { limit = { scope:sc_victor = root } change_variable = { name = domcom_obedience add = 130 } }
            else = { change_variable = { name = domcom_obedience add = 100 } }
            if = { limit = { OR = { has_trait = brave has_trait = wrathful has_trait = athletic has_trait = ambitious } } change_variable = { name = domcom_obedience add = 25 } }
            if = { limit = { has_relation_soulmate = root } change_variable = { name = domcom_obedience add = 20 } }
            if = { limit = { var:domcom_obedience > 1000 } set_variable = { name = domcom_obedience value = 1000 } }
            add_opinion = { target = root modifier = domcom_deepen_communion_good_opinion }
            domcom_refresh_obedience_stage_effect = yes
        }
        domcom_cleanup_communion_event_effect = yes
    }
}

# Contest invalidation cleanup.
domcom_communion.190 = {
    hidden = yes
    immediate = { domcom_cleanup_communion_event_effect = yes }
}

# Test Devotion.
domcom_communion.200 = {
    type = character_event
    title = domcom_communion.200.t
    desc = domcom_communion.200.desc
    theme = intrigue
    trigger = {
        has_variable = domcom_communion_event_target
        var:domcom_communion_event_target = { is_alive = yes }
    }
    immediate = {
        hidden_effect = {
     var:domcom_communion_event_target = { save_scope_as = domcom_communion_target } 
        }
    }
    left_portrait = { character = root animation = personality_rational }
    right_portrait = { character = scope:domcom_communion_target animation = personality_rational }

    option = {
        name = domcom_communion.200.a
        custom_tooltip = domcom_communion.200.a.tt
        show_as_tooltip = {
            random_list = {
                0 = { modifier = { add = domcom_test_devotion_chance_value } custom_tooltip = domcom_test_devotion_tt_success }
                0 = { modifier = { add = domcom_test_devotion_failure_weight_value } custom_tooltip = domcom_test_devotion_tt_failure }
            }
        }
        hidden_effect = {
            random = { chance = domcom_test_devotion_chance_value add_character_flag = domcom_devotion_test_passed }
            if = {
                limit = { has_character_flag = domcom_devotion_test_passed }
                remove_character_flag = domcom_devotion_test_passed
                scope:domcom_communion_target = {
                    every_secret = { reveal_to = root }
                    every_spouse = { every_secret = { reveal_to = root } }
                    change_variable = { name = domcom_obedience add = 75 }
                    if = { limit = { var:domcom_obedience > 1000 } set_variable = { name = domcom_obedience value = 1000 } }
                    domcom_refresh_obedience_stage_effect = yes
                }
                trigger_event = { id = domcom_communion.210 }
            }
            else = {
                scope:domcom_communion_target = {
                    change_variable = { name = domcom_obedience subtract = 75 }
                    if = { limit = { var:domcom_obedience < 0 } set_variable = { name = domcom_obedience value = 0 } }
                    domcom_refresh_obedience_stage_effect = yes
                    add_opinion = { target = root modifier = domcom_deepen_communion_bad_opinion }
                }
                trigger_event = { id = domcom_communion.211 }
            }
        }
    }
    option = {
        name = domcom_communion.200.b
        trigger = {
            scope:domcom_communion_target = {
                any_spouse = {
                    has_character_flag = domcom_cucked
                    OR = {
                        AND = { has_variable = domcom_cuck_patron var:domcom_cuck_patron = root }
                        AND = { has_variable = domcom_patron var:domcom_patron = root }
                        any_in_list = { variable = domcom_cuck_patrons this = root }
                    }
                }
            }
        }
        custom_tooltip = domcom_communion.200.b.tt
        show_as_tooltip = {
            random_list = {
                0 = { modifier = { add = domcom_test_devotion_chance_value } custom_tooltip = domcom_test_devotion_tt_success }
                0 = { modifier = { add = domcom_test_devotion_failure_weight_value } custom_tooltip = domcom_test_devotion_tt_failure }
            }
        }
        hidden_effect = {
            random = { chance = domcom_test_devotion_chance_value add_character_flag = domcom_devotion_test_passed }
            if = {
                limit = { has_character_flag = domcom_devotion_test_passed }
                remove_character_flag = domcom_devotion_test_passed
                scope:domcom_communion_target = {
                    every_spouse = {
                        limit = {
                            has_character_flag = domcom_cucked
                            OR = {
                                AND = { has_variable = domcom_cuck_patron var:domcom_cuck_patron = root }
                                AND = { has_variable = domcom_patron var:domcom_patron = root }
                                any_in_list = { variable = domcom_cuck_patrons this = root }
                            }
                        }
                        if = { limit = { NOT = { has_variable = domcom_cuck_xp } } set_variable = { name = domcom_cuck_xp value = 100 } }
                        change_variable = { name = domcom_cuck_xp add = 100 }
                        if = { limit = { var:domcom_cuck_xp > 1000 } set_variable = { name = domcom_cuck_xp value = 1000 } }
                        domcom_refresh_cuck_stage_effect = yes
                        domcom_check_final_collapse_effect = yes
                    }
                    change_variable = { name = domcom_obedience add = 100 }
                    if = { limit = { var:domcom_obedience > 1000 } set_variable = { name = domcom_obedience value = 1000 } }
                    domcom_refresh_obedience_stage_effect = yes
                }
                trigger_event = { id = domcom_communion.210 }
            }
            else = {
                scope:domcom_communion_target = {
                    change_variable = { name = domcom_obedience subtract = 100 }
                    if = { limit = { var:domcom_obedience < 0 } set_variable = { name = domcom_obedience value = 0 } }
                    domcom_refresh_obedience_stage_effect = yes
                    add_opinion = { target = root modifier = domcom_deepen_communion_bad_opinion }
                }
                trigger_event = { id = domcom_communion.211 }
            }
        }
    }
    option = {
        name = domcom_communion.200.c
        custom_tooltip = domcom_communion.200.c.tt
        show_as_tooltip = {
            random_list = {
                0 = { modifier = { add = domcom_test_devotion_chance_value } custom_tooltip = domcom_test_devotion_tt_success }
                0 = { modifier = { add = domcom_test_devotion_failure_weight_value } custom_tooltip = domcom_test_devotion_tt_failure }
            }
        }
        hidden_effect = {
            random = { chance = domcom_test_devotion_chance_value add_character_flag = domcom_devotion_test_passed }
            if = {
                limit = { has_character_flag = domcom_devotion_test_passed }
                remove_character_flag = domcom_devotion_test_passed
                if = { limit = { has_character_modifier = domcom_devotion_proven_support_modifier } remove_character_modifier = domcom_devotion_proven_support_modifier }
                add_character_modifier = { modifier = domcom_devotion_proven_support_modifier years = 2 }
                scope:domcom_communion_target = {
                    change_variable = { name = domcom_obedience add = 75 }
                    if = { limit = { var:domcom_obedience > 1000 } set_variable = { name = domcom_obedience value = 1000 } }
                    domcom_refresh_obedience_stage_effect = yes
                }
                trigger_event = { id = domcom_communion.210 }
            }
            else = {
                scope:domcom_communion_target = {
                    change_variable = { name = domcom_obedience subtract = 75 }
                    if = { limit = { var:domcom_obedience < 0 } set_variable = { name = domcom_obedience value = 0 } }
                    domcom_refresh_obedience_stage_effect = yes
                    add_opinion = { target = root modifier = domcom_deepen_communion_bad_opinion }
                }
                trigger_event = { id = domcom_communion.211 }
            }
        }
    }
    option = {
        name = domcom_communion.200.d
        scope:domcom_communion_target = {
            change_variable = { name = domcom_obedience add = 40 }
            if = { limit = { var:domcom_obedience > 1000 } set_variable = { name = domcom_obedience value = 1000 } }
            domcom_refresh_obedience_stage_effect = yes
        }
        trigger_event = { id = domcom_communion.210 }
    }
}

domcom_communion.210 = {
    type = character_event
    title = domcom_communion.210.t
    desc = domcom_communion.210.desc
    theme = seduction
    trigger = { has_variable = domcom_communion_event_target }
    immediate = {
        hidden_effect = {
     var:domcom_communion_event_target = { save_scope_as = domcom_communion_target } 
        }
    }
    option = { name = domcom_communion.210.a hidden_effect = { domcom_cleanup_communion_event_effect = yes } }
}

domcom_communion.211 = {
    type = character_event
    title = domcom_communion.211.t
    desc = domcom_communion.211.desc
    theme = rival_relation
    trigger = { has_variable = domcom_communion_event_target }
    immediate = {
        hidden_effect = {
     var:domcom_communion_event_target = { save_scope_as = domcom_communion_target } 
        }
    }
    option = { name = domcom_communion.211.a hidden_effect = { domcom_cleanup_communion_event_effect = yes } }
}

# Claim as Pet.
domcom_communion.300 = {
    type = character_event
    title = domcom_communion.300.t
    desc = domcom_communion.300.desc
    theme = seduction
    trigger = {
        has_variable = domcom_communion_event_target
        var:domcom_communion_event_target = { is_alive = yes }
    }
    immediate = {
        hidden_effect = {
     var:domcom_communion_event_target = { save_scope_as = domcom_communion_target } 
        }
    }
    left_portrait = { character = root animation = personality_rational }
    right_portrait = { character = scope:domcom_communion_target animation = personality_rational }

    option = {
        name = domcom_communion.300.a
        show_as_tooltip = {
            random_list = {
                0 = { modifier = { add = domcom_claim_pet_chance_value } custom_tooltip = domcom_claim_pet_tt_success }
                0 = { modifier = { add = domcom_claim_pet_failure_weight_value } custom_tooltip = domcom_claim_pet_tt_failure }
            }
        }
        hidden_effect = {
            random = { chance = domcom_claim_pet_chance_value add_character_flag = domcom_pet_claim_accepted }
            if = {
                limit = { has_character_flag = domcom_pet_claim_accepted }
                remove_character_flag = domcom_pet_claim_accepted
                save_scope_as = domcom_tantalize_patron
                scope:domcom_communion_target = {
                    domcom_create_pet_effect = yes
                    remove_character_flag = domcom_new_pet_created
                }
                trigger_event = { id = domcom_communion.310 }
            }
            else = {
                scope:domcom_communion_target = {
                    set_variable = { name = domcom_obedience value = 850 }
                    domcom_refresh_obedience_stage_effect = yes
                    add_opinion = { target = root modifier = domcom_pet_claim_rejected_opinion }
                }
                trigger_event = { id = domcom_communion.311 }
            }
        }
    }
    option = {
        name = domcom_communion.300.b
        hidden_effect = {
            root = {
                remove_interaction_cooldown_against = {
                    interaction = domcom_claim_as_pet_interaction
                    target = scope:domcom_communion_target
                }
            }
            domcom_cleanup_communion_event_effect = yes
        }
    }
}

domcom_communion.310 = {
    type = character_event
    title = domcom_communion.310.t
    desc = domcom_communion.310.desc
    theme = seduction
    trigger = { has_variable = domcom_communion_event_target }
    immediate = {
        hidden_effect = {
     var:domcom_communion_event_target = { save_scope_as = domcom_communion_target } 
        }
    }
    option = { name = domcom_communion.310.a hidden_effect = { domcom_cleanup_communion_event_effect = yes } }
}

domcom_communion.311 = {
    type = character_event
    title = domcom_communion.311.t
    desc = domcom_communion.311.desc
    theme = rival_relation
    trigger = { has_variable = domcom_communion_event_target }
    immediate = {
        hidden_effect = {
     var:domcom_communion_event_target = { save_scope_as = domcom_communion_target } 
        }
    }
    option = { name = domcom_communion.311.a hidden_effect = { domcom_cleanup_communion_event_effect = yes } }
}
