﻿namespace = loaa_invasion_sponsorship_events

loaa_invasion_sponsorship_events.1 = {
    type = character_event
    hidden = yes

    immediate = {
        if = {
            limit = {
                NOT = { exists = scope:invasion_target_title }
                var:adventurer_invasion_target = {
                    any_realm_de_jure_duchy = {
                        is_title_created = yes
                        holder.top_liege = prev
                    }
                }
            }
            var:adventurer_invasion_target = {
                ordered_realm_de_jure_duchy = {
                    order_by = loaa_duchy_development_level_value
                    limit = {
                        is_title_created = yes
                        holder.top_liege = prev
                        any_in_de_jure_hierarchy = {
                            count >= 1
                            tier = tier_county
                        }
                    }
                    save_scope_as = invasion_target_title
                }
                scope:invasion_target_title = {
                    random_in_de_jure_hierarchy = {
                        limit = { tier = tier_county }
                        save_scope_as = targeted_county
                    }
                }
            }
            start_war = {
                casus_belli = ep3_laamp_adventurer_duchy_invasion
                target = var:adventurer_invasion_target
                claimant = root
                target_title = scope:invasion_target_title
                target_title = scope:targeted_county
            }

        }

        if = {
            limit = { NOT = { exists  = scope:invasion_target_title } }
            var:adventurer_invasion_target = {
                ordered_realm_county = {
                    order_by = development_level
                    limit = {
                        is_title_created = yes
                        holder.top_liege = prev
                    }
                    save_scope_as = invasion_target_title
                }
            }
            start_war = {
                casus_belli = ep3_laamp_adventurer_county_invasion
                target = var:adventurer_invasion_target
                claimant = root
                target_title = scope:invasion_target_title
            }

        }

    }
}