﻿#确认劫掠军队
mytm_on_raid_loot_delivered = {
    if = {
        limit = { raid_loot > 0 }
        save_scope_as = raiding_army
        hidden_effect = {
            if = {
                limit = { army_commander = scope:raider }
                scope:raider = {
                    add_character_flag = {
                        flag = has_recently_performed_raid
                        years = 3
                    }
                }
            }
        }
        army_commander = { save_scope_as = army_commander }
        location = {
            county = { save_scope_as = county }
            barony = { save_scope_as = barony }
        }
        save_scope_value_as = {
            name = raid_loot
            value = raid_loot
        }
        mytm_effect_get_raid_loot = yes
    }
}
#返回领地上交战利品
mytm_effect_get_raid_loot_return = {
    if = {
        limit = {
            domicile ?= { is_domicile_type = yurt }
        }
        add_gold = { value = scope:raid_loot multiply = 1 }
        domicile = { change_herd = { value = scope:raid_loot multiply = 3 } }
    }
    else_if = {
        limit = { domicile ?= { is_domicile_type = camp } }
        add_gold = scope:raid_loot
        add_prestige = scope:raid_loot
        domicile = { change_provisions = { value = scope:raid_loot multiply = 20 } }
    }
    else = {
        add_gold = scope:raid_loot
        add_prestige = scope:raid_loot
    }
}
#自动上交战利品
mytm_effect_get_raid_loot = {
    scope:raider = {
        send_interface_message = {
            type = mytm_msg_get_raid_loot
            title = mytm_tooltip_army_delivered_title
            left_icon = scope:army_commander
            right_icon = scope:barony
            # custom_tooltip = mytm_tooltip_army_delivered_effect
            mytm_effect_get_raid_loot_return = yes
            hidden_effect = {
                scope:raiding_army = {
                    add_supply = scope:raid_loot
                }
            }
            if = {
                limit = {
                    culture = { can_get_innovation_from = scope:county.culture }
                }
                random = {
                    chance = {
                        value = scope:raid_loot
                        divide = 20
                        round = yes
                    }
                    scope:raider.culture = { get_random_innovation_from = scope:county.culture }
                }
            }
        }
    }
    hidden_effect = { add_loot = { value = scope:raid_loot multiply = -1 } }
}