# Player-Like AI Effects

# ============================================================
# INTRIGUE & SCHEMES
# ============================================================

qyv_playerlike_scheme_murder = {
    scope:murder_target = {
        start_scheme = { scheme = scheme_murder target = root }
    }
    root = { add_stress = 10 }
}

qyv_playerlike_scheme_abduct = {
    scope:abduct_target = {
        start_scheme = { scheme = scheme_abduct target = root }
    }
    root = { add_stress = 15 }
}

qyv_playerlike_sway = {
    scope:sway_target = {
        start_scheme = { scheme = scheme_sway target = root }
    }
}

qyv_playerlike_blackmail = {
    scope:blackmail_target = {
        expose_secret = { target = root }
    }
}

qyv_playerlike_fabricate_hook = {
    scope:hook_target = {
        start_scheme = { scheme = scheme_fabricate_hook target = root }
    }
}

qyv_playerlike_use_hook = {
    if = {
        limit = {
            scope:hooked_vassal = { is_vassal_of = root }
        }
        scope:hooked_vassal = {
            enforce_hook = {
                target = root
                demand_council_position = yes
            }
        }
    }
    else = {
        scope:hooked_vassal = {
            enforce_hook = {
                target = root
                demand_gold = 200
            }
        }
    }
}

# ============================================================
# COUNCIL MANAGEMENT
# ============================================================

qyv_playerlike_appoint_council = {
    scope:council_candidate = {
        add_to_council = { position = steward }
    }
}

qyv_playerlike_replace_councilor = {
    scope:council_candidate = {
        add_to_council = { position = steward }
    }
}

qyv_playerlike_powerful_vassals_council = {
    scope:council_candidate = {
        add_to_council = { position = steward }
    }
}

# ============================================================
# VASSAL CONTRACT OPTIMIZATION
# ============================================================

qyv_playerlike_renegotiate_contract = {
    scope:renegotiate_target = {
        if = {
            limit = { contract_has = levies_high }
            set_vassal_contract = { taxes = high levies = low }
        }
        else_if = {
            limit = { contract_has = taxes_high }
            set_vassal_contract = { taxes = low levies = high }
        }
        else = {
            set_vassal_contract = { taxes = high levies = normal }
        }
    }
}

qyv_playerlike_offer_special_contract = {
    scope:special_contract_target = {
        set_vassal_contract = { special = march }
    }
}

qyv_playerlike_revoke_privileges = {
    scope:revoke_target = {
        set_vassal_contract = { special = none }
        add_opinion = { target = root modifier = revoked_privileges years = 10 }
    }
}

# ============================================================
# MERCENARY & MILITARY TACTICS
# ============================================================

qyv_playerlike_hire_mercs = {
    if = {
        limit = {
            any_mercenary_company = {
                employer = root
                available = yes
                cost <= root.gold * 0.5
            }
        }
        hire_mercenary_company = { company = scope:mercenary_company }
        set_character_flag = mercs_hired_this_war
    }
}

qyv_playerlike_disband_mercs = {
    any_mercenary_company = {
        employer = root
        disband_mercenary_company = yes
    }
}

qyv_playerlike_raise_levies = {
    raise_all_levies = yes
}

qyv_playerlike_siege_equipment = {
    any_army = {
        limit = {
            leader = { is_ruler = root }
            location = { is_besieging = yes }
            NOT = { has_siege_equipment = yes }
        }
        add_siege_equipment = yes
    }
}

qyv_playerlike_retreat = {
    any_army = {
        limit = {
            leader = { is_ruler = root }
            location = { is_in_combat = yes }
        }
        retreat = yes
    }
}

# ============================================================
# CHARACTER FOCUS & LIFESTYLE
# ============================================================

qyv_playerlike_pick_focus = {
    if = {
        limit = { martial >= 14 }
        set_focus = martial_focus
    }
    else_if = {
        limit = { stewardship >= 14 }
        set_focus = stewardship_focus
    }
    else_if = {
        limit = { diplomacy >= 14 }
        set_focus = diplomacy_focus
    }
    else_if = {
        limit = { intrigue >= 14 }
        set_focus = intrigue_focus
    }
    else_if = {
        limit = { learning >= 14 }
        set_focus = learning_focus
    }
}

qyv_playerlike_pick_lifestyle = {
    if = {
        limit = { martial >= 14 }
        set_lifestyle = martial_lifestyle
    }
    else_if = {
        limit = { stewardship >= 14 }
        set_lifestyle = stewardship_lifestyle
    }
    else_if = {
        limit = { diplomacy >= 14 }
        set_lifestyle = diplomacy_lifestyle
    }
    else_if = {
        limit = { intrigue >= 14 }
        set_lifestyle = intrigue_lifestyle
    }
    else_if = {
        limit = { learning >= 14 }
        set_lifestyle = learning_lifestyle
    }
}

qyv_playerlike_pick_perk = {
    any_lifestyle_perk = {
        limit = { can_pick = yes }
        pick_lifestyle_perk = yes
    }
}

qyv_playerlike_manage_stress = {
    if = {
        limit = {
            any_trait = { stressed anxious melancholic }
        }
        add_coping_mechanism = { random = yes }
    }
    else = {
        add_coping_mechanism = { random = yes }
    }
}

# ============================================================
# WAR STRATEGY
# ============================================================

qyv_playerlike_call_allies = {
    any_ally = {
        limit = {
            military_strength > 2000
            NOT = { is_at_war = yes }
        }
        call_ally = { target = root }
    }
}

qyv_playerlike_choose_cb = {
    if = {
        limit = {
            any_neighbor_independent_ruler = {
                limit = {
                    has_claim_on = root
                    military_strength < root.military_strength * 1.2
                }
            }
        }
        declare_war = { target = scope:claimant cb = claim }
    }
    else_if = {
        limit = {
            any_neighbor_independent_ruler = {
                limit = {
                    faith != root.faith
                    military_strength < root.military_strength * 1.3
                }
            }
        }
        declare_war = { target = scope:infidel cb = holy_war }
    }
    else_if = {
        limit = {
            any_neighbor_independent_ruler = {
                limit = {
                    de_jure_liege = root
                    military_strength < root.military_strength * 1.2
                }
            }
        }
        declare_war = { target = scope:de_jure cb = de_jure }
    }
}

qyv_playerlike_white_peace = {
    war = {
        attacker = { is_ruler = root }
        send_white_peace = yes
    }
}

qyv_playerlike_sue_for_peace = {
    war = {
        defender = { is_ruler = root }
        surrender = yes
    }
}

# ============================================================
# DYNASTY & HOUSE MANAGEMENT
# ============================================================

qyv_playerlike_legitimize = {
    scope:legitimize_target = {
        legitimize_bastard = yes
        add_opinion = { target = root modifier = legitimized_bastard years = 5 }
    }
}

qyv_playerlike_create_cadet_branch = {
    create_cadet_branch = {
        name = "[dynasty.GetName] of [capital_province.GetName]"
        motto = "Fortune favors the bold"
    }
}

qyv_playerlike_use_house_head = {
    scope:imprisoned_member = {
        house_head_action = { action = ransom_prisoner }
    }
}

# ============================================================
# RELIGIOUS & CULTURAL
# ============================================================

qyv_playerlike_convert_faith = {
    convert_faith = { faith = scope:neighbor.faith }
}

qyv_playerlike_reform_faith = {
    reform_faith = {
        name = "[faith.GetName] Reformed"
        tenet_1 = communion
        tenet_2 = lay_clergy
        tenet_3 = religious_head
        doctrine_1 = gender_equality
    }
}

qyv_playerlike_convert_culture = {
    convert_culture = { culture = scope:province.culture }
}

qyv_playerlike_promote_culture = {
    any_owned_province = {
        limit = {
            culture = root.culture
            development < 15
        }
        promote_culture = yes
    }
}

# ============================================================
# ECONOMIC OPTIMIZATION
# ============================================================

qyv_playerlike_loan_money = {
    take_loan = { amount = 500 }
}

qyv_playerlike_repay_loans = {
    repay_loan = { amount = 500 }
}

qyv_playerlike_invest_in_buildings = {
    random_owned_province = {
        limit = { holding = { can_build = yes } }
        holding = { build_random_building = yes }
    }
}

qyv_playerlike_optimize_tax_levy = {
    any_vassal = {
        limit = {
            contract_has = taxes_normal
            contract_has = levies_normal
            opinion_of_self >= 30
        }
        set_vassal_contract = { taxes = high levies = normal }
    }
}