﻿qing_htool_realm_capital_move = {
    scope = character
    saved_scopes = { gui_holding }

    is_shown = {
        scope:gui_holding = {
            exists = province_owner
            province_owner = root
            is_county_capital = yes
            county = {
                NOT = { this = root.capital_county }
            }
        }
    }

        is_valid = {
        scope:gui_holding = {
            has_ongoing_construction = no
        }
        trigger_if = {
            limit = { qing_htool_realm_capital_move_cooldown_value > 0 }
            root = {
                NOT = { has_character_modifier = qing_htool_realm_capital_move_cooldown_modifier }
            }
        }
        # 金钱检查
        trigger_if = {
            limit = { qing_htool_realm_capital_move_cost_value > 0 }
            trigger_if = {
                limit = { has_game_rule = qing_htool_main_pay_method_gold }
                root.gold >= qing_htool_realm_capital_move_cost_value
            }
            trigger_else_if = {
                limit = { has_game_rule = qing_htool_main_pay_method_treasury }
                trigger_if = {
                    limit = { root = { has_treasury = yes } }
                    root.treasury >= qing_htool_realm_capital_move_cost_value
                }
                trigger_else = {
                    root.gold >= qing_htool_realm_capital_move_cost_value
                }
            }
            trigger_else_if = {
                limit = { has_game_rule = qing_htool_main_pay_method_gold_first }
                trigger_if = {
                    limit = { root = { has_treasury = yes } }
                    custom_tooltip = {
                        text = "qing_htool_realm_capital_move_pay_method_gold_first_has_treasury_error"
                        OR = {
                            root.gold >= qing_htool_realm_capital_move_cost_value
                            root.treasury >= qing_htool_realm_capital_move_cost_value
                        }
                    }
                }
                trigger_else = {
                    custom_tooltip = {
                        text = "qing_htool_realm_capital_move_pay_method_gold_first_no_treasury_error"
                        root.gold >= qing_htool_realm_capital_move_cost_value
                    }
                }
            }
            trigger_else_if = {
                limit = { has_game_rule = qing_htool_main_pay_method_treasury_first }
                custom_tooltip = {
                    text = "qing_htool_realm_capital_move_pay_method_treasury_first_error"
                    OR = {
                        AND = {
                            root = { has_treasury = yes }
                            root.treasury >= qing_htool_realm_capital_move_cost_value
                        }
                        root.gold >= qing_htool_realm_capital_move_cost_value
                    }
                }
            }
        }
    }

    effect = {
        hidden_effect = {
            scope:gui_holding = {
                county = {
                    save_scope_as = new_capital
                    root = { set_realm_capital = prev }
                }
            }
        }
        custom_tooltip = qing_htool_realm_capital_move_tip
        # 冷却
        if = {
            limit = { qing_htool_realm_capital_move_cooldown_value > 0 }
            root = {
                add_character_modifier = {
                    modifier = qing_htool_realm_capital_move_cooldown_modifier
                    months = qing_htool_realm_capital_move_cooldown_value
                }
            }
        }
        # 负面修正
        if = {
            limit = { has_game_rule = qing_htool_realm_capital_move_influence_low }
            root = {
                add_character_modifier = {
                    modifier = qing_htool_realm_capital_move_influence_low_modifier
                    years = 1
                }
            }
        }
        else_if = {
            limit = { has_game_rule = qing_htool_realm_capital_move_influence_medium }
            root = {
                add_character_modifier = {
                    modifier = qing_htool_realm_capital_move_influence_medium_modifier
                    years = 1
                }
            }
        }
        else_if = {
            limit = { has_game_rule = qing_htool_realm_capital_move_influence_high }
            root = {
                add_character_modifier = {
                    modifier = qing_htool_realm_capital_move_influence_high_modifier
                    years = 1
                }
            }
        }
        # 花费
        if = {
            limit = { qing_htool_realm_capital_move_cost_value > 0 }
            if = {
                limit = { has_game_rule = qing_htool_main_pay_method_gold }
                root = { remove_long_term_gold = qing_htool_realm_capital_move_cost_value }
            }
            else_if = {
                limit = { has_game_rule = qing_htool_main_pay_method_treasury }
                if = {
                    limit = { root = { has_treasury = yes } }
                    root = { remove_treasury = qing_htool_realm_capital_move_cost_value }
                }
                else = {
                    root = { remove_long_term_gold = qing_htool_realm_capital_move_cost_value }
                }
            }
            else_if = {
                limit = { has_game_rule = qing_htool_main_pay_method_gold_first }
                if = {
                    limit = { root.gold >= qing_htool_realm_capital_move_cost_value }
                    root = { remove_long_term_gold = qing_htool_realm_capital_move_cost_value }
                }
                else_if = {
                    limit = {
                        root = { has_treasury = yes }
                        root.treasury >= qing_htool_realm_capital_move_cost_value
                    }
                    root = { remove_treasury = qing_htool_realm_capital_move_cost_value }
                }
                else = {
                    root = { remove_long_term_gold = qing_htool_realm_capital_move_cost_value }
                }
            }
            else_if = {
                limit = { has_game_rule = qing_htool_main_pay_method_treasury_first }
                if = {
                    limit = { root = { has_treasury = yes } }
                    root = { remove_treasury = qing_htool_realm_capital_move_cost_value }
                }
                else = {
                    root = { remove_long_term_gold = qing_htool_realm_capital_move_cost_value }
                }
            }
        }
    }
}

