namespace = ani_plus

### moving on_chronicle_start events here for multiplayer purpose
# set of events made for multiplayer purpose

# event 258
character_event = {
    id =  ani_plus.258
    hide_window = yes

    only_playable = yes

    trigger = {
        NOT = { has_global_flag = animals_chronicle_start_events }
    }

    mean_time_to_happen = {
        days = 1
    }

    immediate = {
        set_global_flag = animals_chronicle_start_events

        random_player = {
            character_event = { id = ani_plus.003 } # setting bear family bonuses at game start
            character_event = { id = ani_plus.157 } # creating new cat societies's grandmaster (as on_society_failed_to_find_new_leader doesn't trigger on game launch or multiplayer).
            character_event = { id = ani_plus.197 } # initializing caste trait for horse ruler (on game start)
            character_event = { id = ani_plus.201 } # forcing religion on dragon character and provinces
            character_event = { id = ani_plus.200 } # setting dragon's holy site
        }
    }
}

### to avoid to much animal alive making game lag on long game at each first of month, killing character not in court
# event 259
character_event = {
    id = ani_plus.259

    hide_window = yes

    trigger = {
        Is_really_animal_trigger = yes
        OR = {
            adventurer = yes
            liege = {
                adventurer = yes
            }
        }
    }

    mean_time_to_happen = {
        months = 12
    }

    immediate = {
        death = yes
    }
}

# event 260 - killing incapable dragon (uncapable of staying alive)
character_event = {
    id = ani_plus.260

    border = GFX_event_normal_frame_diplomacy
    picture = GFX_evt_council

    desc = DESC_ANI_260

    culture_group = dragon_group

    trigger = {
        culture_group = dragon_group
        NOT = { culture = dragon_culture }
        OR = {
            AND = {
                is_ruler = yes
                has_assigned_minor_title = title_dragon_alternate_space_master
            }
            AND = {
                is_ruler = no
                liege = {
                    has_assigned_minor_title = title_dragon_alternate_space_master
                }
            }
        }
        is_incapable = yes
    }

    mean_time_to_happen = {
        years = 2
    }

    option = {
        name = OPTA_ANI_260
        ai_chance = {
            factor = 1000

            modifier = {
                factor = 0.05

                NOT = { trait = incapable }
            }
        }

        custom_tooltip = {
            text = TT_dragon_sent_to_space_death

            random_list = {
                50 = {}
                20 = { wealth = 10 }
                15 = { wealth = 50 }
                10 = { wealth = 100 }
                5 = { wealth = 150 }
                1 = { wealth = 500 }
            }
            death = {
                death_reason = death_suicide
                killer = ROOT
            }
        }
    }
    option = {
        name = OPTB_ANI_260
        ai_chance = {
            factor = 500

            modifier = {
                factor = 0.25

                trait = incapable
            }
        }

        add_trait = depressed
    }
}

# event 261 - creating fort on previously assieged province
# after a dragon hunt
character_event = {
    id = ani_plus.261

    hide_window = yes
    is_triggered_only = yes
    trigger = {
        higher_tier_than = BARON
    }

    immediate = {
        
        any_demesne_title = {
            limit = {
                tier = COUNT
            }

            set_variable = {
                which = local_influence
                value = 0
            }

            any_de_jure_vassal_title = {
                limit = {
                    controller = {
                        culture_group = dragon_group
                    }
                    holding_raisable_levy_percent < 0.001
                }
                PREV = {
                    change_variable = {
                        which = local_influence
                        value = 1
                    }
                }
                while = {
                    limit = {
                        OR = {
                            has_building = ca_wall_q_1
                            has_building = ca_wall_1
                            has_building = ca_special_fortifications_1
                            has_building = ca_ani_castle_tower_01
                            has_building = ca_ani_fort_1
                            has_building = ca_duck_fortification_01
                            has_building = ca_hedge_fortification_01
                            has_building = ct_wall_q_1
                            has_building = ct_wall_1
                            has_building = ct_rep_arsenal_1
                            has_building = no_camp_fortifications_1
                            has_building = tb_hillfort_1
                            has_building = tb_defensive_fortifications_1
                            has_building = tb_ani_tribal_tower_1
                            has_building = tb_drg_slave_worker_1
                            has_building = tb_drg_slave_fighter_1
                            has_building = tb_hedge_fortification_1
                            has_building = tb_ani_fort_1
                            has_building = tp_wall_q_1
                            has_building = tp_wall_1
                            has_building = tp_shrine_ephaestus
                        }
                    }
                    destroy_random_building = yes
                    event_target:target_looter = {
                        wealth = 100
                    }
                }
            }

            if = {
                limit = {
                    location = {
                        controller = {
                            culture_group = dragon_group
                        }
                    }
                    holding_raisable_levy_percent < 0.001
                }
                change_variable = {
                    which = local_influence
                    value = 1
                }
                location = {
                    capital_holding = {
                        while = {
                            limit = {
                                OR = {
                                    has_building = ca_wall_q_1
                                    has_building = ca_wall_1
                                    has_building = ca_special_fortifications_1
                                    has_building = ca_ani_castle_tower_01
                                    has_building = ca_ani_fort_1
                                    has_building = ca_duck_fortification_01
                                    has_building = ca_hedge_fortification_01
                                    has_building = ct_wall_q_1
                                    has_building = ct_wall_1
                                    has_building = ct_rep_arsenal_1
                                    has_building = no_camp_fortifications_1
                                    has_building = tb_hillfort_1
                                    has_building = tb_defensive_fortifications_1
                                    has_building = tb_ani_tribal_tower_1
                                    has_building = tb_drg_slave_worker_1
                                    has_building = tb_drg_slave_fighter_1
                                    has_building = tb_hedge_fortification_1
                                    has_building = tb_ani_fort_1
                                    has_building = tp_wall_q_1
                                    has_building = tp_wall_1
                                    has_building = tp_shrine_ephaestus
                                }
                            }
                            destroy_random_building = yes
                            event_target:target_looter = {
                                wealth = 100
                            }
                        }
                    }
                }
            }

            if = {
                limit = {
                    check_variable = {
                        which = local_influence
                        value = 1
                    }
                }
                create_fort = location
                location = {
                    add_to_extra_holding = {
                        type = fort
                        building = fo_drg_guardian_01
                    }
                }
            }
            if = {
                limit = {
                    check_variable = {
                        which = local_influence
                        value = 2
                    }
                }
                location = {
                    add_to_extra_holding = {
                        type = fort
                        building = fo_drg_guardian_02
                    }
                }
            }
            if = {
                limit = {
                    check_variable = {
                        which = local_influence
                        value = 3
                    }
                }
                location = {
                    add_to_extra_holding = {
                        type = fort
                        building = fo_drg_guardian_03
                    }
                }
            }
            if = {
                limit = {
                    check_variable = {
                        which = local_influence
                        value = 4
                    }
                }
                location = {
                    add_to_extra_holding = {
                        type = fort
                        building = fo_drg_guardian_04
                    }
                }
            }
            if = {
                limit = {
                    check_variable = {
                        which = local_influence
                        value = 5
                    }
                }
                location = {
                    add_to_extra_holding = {
                        type = fort
                        building = fo_drg_guardian_05
                    }
                }
            }
            if = {
                limit = {
                    check_variable = {
                        which = local_influence
                        value = 6
                    }
                }
                location = {
                    add_to_extra_holding = {
                        type = fort
                        building = fo_drg_guardian_06
                    }
                }
            }
            if = {
                limit = {
                    check_variable = {
                        which = local_influence
                        value = 7
                    }
                }
                location = {
                    add_to_extra_holding = {
                        type = fort
                        building = fo_drg_guardian_07
                    }
                }
            }
        }
        any_vassal = {
            character_event = { id = ani_plus.261 }
        }
    }
}

# event 262 - multiplayer event to allow other player to join an hunting war
narrative_event = {
    id = ani_plus.262

    is_triggered_only = yes

    border = GFX_event_narrative_frame_war
    picture = GFX_evt_garden
    title = TITLE_ANI_262

    desc = DESC_ANI_262

    option = {
        trigger = {
            NOR = {
                character = FROM
                character = FROMFROM
            }
        }
        name = OPTA_ANI_262

        join_attacker_wars = FROM
    }
    option = {
        trigger = {
            NOR = {
                character = FROM
                character = FROMFROM
            }
        }
        name = OPTB_ANI_262

        join_defender_wars = FROMFROM
    }
    option = {
        trigger = {
            NOR = {
                character = FROM
                character = FROMFROM
            }
        }
        name = OPTC_ANI_262
    }
    option = { # attacker
        trigger = {
            character = FROM
        }
        name = OPTD_ANI_262
    }
    option = { # defender
        trigger = {
            character = FROMFROM
        }
        name = OPTE_ANI_262
    }
}