﻿loaa_offer_protect_domain_contract_modifier = {
    modifier = {  # don't join many losing wars
        OR = {
            scope:contract_protect_domain ?= yes
        }
        save_temporary_scope_value_as = {
            name = attacker_war
            value = 2
        }
        scope:secondary_recipient = {
            any_character_war = {
                primary_attacker = scope:secondary_recipient
                attacker_war_score < 0
                save_temporary_scope_value_as = {
                    name = attacker_war
                    value = {
                        value = scope:attacker_war
                        multiply = attacker_war_score
                    }
                }
            }
        }
        add = scope:attacker_war
        desc = attacker_losisng_too_much_reason
    }
    modifier = {  # don't join many losing wars
        OR = {
            scope:contract_protect_domain ?= yes
        }
        add = scope:defender_war
        save_temporary_scope_value_as = {
            name = defender_war
            value = 2
        }
        scope:secondary_recipient = {
            any_character_war = {
                primary_defender = scope:secondary_recipient
                defender_war_score < 0
                save_temporary_scope_value_as = {
                    name = defender_war
                    value = {
                        value = scope:defender_war
                        multiply = defender_war_score
                    }
                }
            }
        }
        desc = defender_losisng_too_much_reason
    }
    modifier = {  # Refuse call against Heir
        OR = {
            scope:contract_protect_domain ?= yes
        }
        add = -1000
        exists = scope:recipient.player_heir
        scope:secondary_recipient = {
            any_character_war = {
                OR = {
                    primary_defender = scope:recipient.player_heir
                    primary_attacker = scope:recipient.player_heir
                }
            }
        }
        desc = WONT_FIGHT_HEIR_REASON
    }
    modifier = {  # Reluctant to join against children
        OR = {
            scope:contract_protect_domain ?= yes
        }
        add = -50
        scope:secondary_recipient = {
            any_character_war = {
                OR = {
                    primary_defender = {
                        is_child_of = scope:recipient
                    }
                    primary_attacker =  {
                        is_child_of = scope:recipient
                    }
                }
            }
        }
        desc = WONT_FIGHT_CHILD_REASON
    }
    modifier = {  # Refuse call against Spouse
        OR = {
            scope:contract_protect_domain ?= yes
        }
        add = -1000
        scope:secondary_recipient = {
            any_character_war = {
                OR = {
                    primary_defender = {
                        is_spouse_of = scope:recipient
                    }
                    primary_attacker =  {
                        is_spouse_of = scope:recipient
                    }
                }
            }
        }
        desc = WONT_FIGHT_SPOUSE_REASON
    }
    modifier = {  # Tends to join defensive wars
        OR = {
            scope:contract_protect_domain ?= yes
        }
        add = 50
        scope:secondary_recipient = {
            any_character_war = {
                primary_defender = scope:secondary_recipient
            }
        }
        desc = DEFENSIVE_WAR_REASON
    }
    modifier = { # Same language
        add = 5
        desc = speaks_same_language_interaction_reason
        scope:actor = {
            knows_language_of_culture = scope:recipient.culture
        }
    }
    compare_modifier = { # Likes fighting infidels
        trigger = {
            scope:contract_protect_domain ?= yes
            scope:recipient.faith = scope:secondary_recipient.faith
            OR = {
                scope:contract_protect_domain ?= yes
            }
            scope:secondary_recipient = {
                any_character_war = {
                    trigger_if = {
                        limit = {
                            primary_defender = scope:secondary_recipient
                        }
                        primary_attacker = {
                            faith = {
                                faith_hostility_level = {
                                    target = scope:secondary_recipient.faith
                                    value >= religious_cb_enabled_hostility_level
                                }
                            }
                        }
                    }
                    trigger_else_if = {
                        limit = {
                            primary_attacker = scope:secondary_recipient
                        }
                        primary_defender = {
                            faith = {
                                faith_hostility_level = {
                                    target = scope:secondary_recipient.faith
                                    value >= religious_cb_enabled_hostility_level
                                }
                            }
                        }
                    }
                    trigger_else = {
                        always = no
                    }
                }
            }
        }
        target = scope:recipient
        value = ai_zeal
        desc = "ZEAL_AGAINST_INFIDELS"
        min = 0
        multiplier = 0.5
    }
    modifier = {  # Reluctant to attack another ally
        OR = {
            scope:contract_protect_domain ?= yes
        }
        add = -50
        scope:secondary_recipient = {
            any_character_war = {
                NOT = { primary_defender = scope:secondary_recipient }
                primary_defender = {
                    is_allied_to = scope:recipient
                }
            }
        }
        desc = ATTACK_ON_ALLY_REASON
    }
    modifier = {  # Reluctant to defend against another ally
        OR = {
            scope:contract_protect_domain ?= yes
        }
        add = -25
        scope:secondary_recipient = {
            any_character_war = {
                NOT = { primary_attacker = scope:secondary_recipient }
                primary_attacker = {
                    is_allied_to = scope:recipient
                }
            }
        }
        desc = WAR_WITH_ALLY_REASON
    }
    modifier = {  # Reluctant to join wars against religious brethren.
        NOT = {
            exists = global_var:AGOT_is_loaded
        }
        OR = {
            scope:contract_protect_domain ?= yes
        }
        add = -50
        NOT = { scope:recipient.faith = scope:secondary_recipient.faith }
        scope:secondary_recipient = {
            any_character_war = {
                OR = {
                    using_cb = minor_religious_war
                    using_cb = religious_war
                    using_cb = major_religious_war
                    using_cb = undirected_great_holy_war
                    using_cb = directed_great_holy_war
                    OR = {
                        AND = {
                            NOT = { primary_attacker = scope:secondary_recipient }
                            primary_attacker.faith = scope:recipient.faith
                        }
                        AND = {
                            NOT = { primary_defender = scope:secondary_recipient }
                            primary_defender.faith = scope:recipient.faith
                        }
                    }
                }
            }
        }
        desc = WONT_ATTACK_RELIGIOUS_BRETHREN_REASON
    }
    modifier = { # Reluctant to join against Friends
        OR = {
            scope:contract_protect_domain ?= yes
        }
        add = -50
        scope:secondary_recipient = {
            any_character_war = {
                OR = {
                    AND = {
                        NOT = { primary_attacker = scope:secondary_recipient }
                        primary_attacker = {
                            has_relation_friend = scope:recipient
                        }
                    }
                    AND = {
                        NOT = { primary_defender = scope:secondary_recipient }
                        primary_defender = {
                            has_relation_friend = scope:recipient
                        }
                    }
                }
            }
        }
    }
    modifier = { # Reluctant to join against Best Friends
        add = -100
        OR = {
            scope:contract_protect_domain ?= yes
        }
        scope:secondary_recipient = {
            any_character_war = {
                OR = {
                    AND = {
                        NOT = { primary_attacker = scope:secondary_recipient }
                        primary_attacker = {
                            has_relation_best_friend = scope:recipient
                        }
                    }
                    AND = {
                        NOT = { primary_defender = scope:secondary_recipient }
                        primary_defender = {
                            has_relation_best_friend = scope:recipient
                        }
                    }
                }
            }
        }
    }
    modifier = { # Reluctant to join against Lovers
        add = -100
        OR = {
            scope:contract_protect_domain ?= yes
        }
        scope:secondary_recipient = {
            any_character_war = {
                OR = {
                    AND = {
                        NOT = { primary_attacker = scope:secondary_recipient }
                        primary_attacker = {
                            has_relation_lover = scope:recipient
                        }
                    }
                    AND = {
                        NOT = { primary_defender = scope:secondary_recipient }
                        primary_defender = {
                            has_relation_lover = scope:recipient
                        }
                    }
                }
            }
        }
    }
    modifier = { # Reluctant to join against Soul mate
        add = -200
        OR = {
            scope:contract_protect_domain ?= yes
        }
        scope:secondary_recipient = {
            any_character_war = {
                OR = {
                    AND = {
                        NOT = { primary_attacker = scope:secondary_recipient }
                        primary_attacker = {
                            has_relation_soulmate = scope:recipient
                        }
                    }
                    AND = {
                        NOT = { primary_defender = scope:secondary_recipient }
                        primary_defender = {
                            has_relation_soulmate = scope:recipient
                        }
                    }
                }
            }
        }
    }
    modifier = {  # Refuse call for hostages' safety
        OR = {
            scope:contract_protect_domain ?= yes
        }
        any_home_court_hostage = {
            warden = {
                OR = {
                    is_at_war_with = scope:secondary_recipient
                    any_ally = { is_at_war_with = scope:secondary_recipient }
                }
            }
        }
        add = {
            value = 0
            every_home_court_hostage = {
                limit = {
                    warden = {
                        OR = {
                            is_at_war_with = scope:secondary_recipient
                            any_ally = { is_at_war_with = scope:secondary_recipient }
                        }
                    }
                }
                subtract = call_to_arms_hostage_value
            }
            multiply = 0.25
        }
        desc = HOSTAGE_ENEMY_CALL_TO_ARMS_REASON
    }
}

loaa_offer_raid_contract_modifier = {
    modifier = {  # Refuse call against Heir
        OR = {
            scope:contract_raid_for_captives ?= yes
            scope:contract_pillage ?= yes
            scope:contract_support_faction ?= yes
        }
        add = -1000
        exists = scope:recipient.player_heir
        scope:secondary_recipient = scope:recipient.player_heir
        desc = WONT_FIGHT_HEIR_REASON
    }
    modifier = {  # Refuse call against Spouse
        OR = {
            scope:contract_raid_for_captives ?= yes
            scope:contract_pillage ?= yes
            scope:contract_support_faction ?= yes
        }
        add = -1000
        scope:secondary_recipient = {
            is_spouse_of = scope:recipient
        }
        desc = WONT_FIGHT_SPOUSE_REASON
    }
    compare_modifier = { # Likes fighting infidels
        trigger = {
            OR = {
                scope:contract_raid_for_captives ?= yes
                scope:contract_pillage ?= yes
            }
            NOT = { scope:recipient.faith = scope:secondary_recipient.faith }
            faith = {
                faith_hostility_level = {
                    target = scope:secondary_recipient.faith
                    value >= religious_cb_enabled_hostility_level
                }
            }
        }
        target = scope:recipient
        value = ai_zeal
        desc = "ZEAL_AGAINST_INFIDELS"
        min = 0
        multiplier = 0.5
    }
    modifier = {  # Reluctant to join against children
        OR = {
            scope:contract_raid_for_captives ?= yes
            scope:contract_pillage ?= yes
            scope:contract_support_faction ?= yes
        }
        add = -50
        scope:secondary_recipient = {
            is_child_of = scope:recipient
        }
        desc = WONT_FIGHT_CHILD_REASON
    }
    modifier = {  # Reluctant to attack another ally
        OR = {
            scope:contract_raid_for_captives ?= yes
            scope:contract_pillage ?= yes
        }
        add = -50
        scope:secondary_recipient = {
            is_allied_to = scope:recipient
        }
        desc = ATTACK_ON_ALLY_REASON
    }
    modifier = { # Reluctant to join against Friends
        OR = {
            scope:contract_raid_for_captives ?= yes
            scope:contract_pillage ?= yes
        }
        add = -50
        scope:secondary_recipient = {
            has_relation_friend = scope:recipient
        }
        desc = WONT_FIGHT_FRIEND_REASON
    }
    modifier = { # Reluctant to join against Best Friends
        add = -100
        OR = {
            scope:contract_raid_for_captives ?= yes
            scope:contract_pillage ?= yes
        }
        scope:secondary_recipient = {
            has_relation_best_friend = scope:recipient
        }
        desc = WONT_FIGHT_BEST_FRIEND_REASON
    }
    modifier = { # Reluctant to join against Lovers
        add = -100
        OR = {
            scope:contract_raid_for_captives ?= yes
            scope:contract_pillage ?= yes
        }
        scope:secondary_recipient = {
            has_relation_lover = scope:recipient
        }
        desc = WONT_FIGHT_LOVER_REASON
    }
    modifier = { # Reluctant to join against Soul mate
        add = -200
        OR = {
            scope:contract_protect_domain ?= yes
        }
        scope:secondary_recipient = {
            has_relation_soulmate = scope:recipient
        }
        desc = WONT_FIGHT_SOULMATE_REASON
    }
    modifier = {  # Refuse call for hostages' safety
        OR = {
            scope:contract_protect_domain ?= yes
        }
        any_home_court_hostage = {
            warden = scope:secondary_recipient
        }
        add = {
            value = 0
            every_home_court_hostage = {
                limit = {
                    warden = scope:secondary_recipient
                }
                subtract = call_to_arms_hostage_value
            }
            multiply = 0.25
        }
        desc = HOSTAGE_ENEMY_CALL_TO_ARMS_REASON
    }
}

loaa_fp3_struggle_resist_allied_wars_modifier = {
	modifier = {  # Opposing struggle sides don't want to join.
		add = -100
        NOT = { exists = global_var:AGOT_is_loaded }
        scope:contract_protect_domain ?= yes
		OR = {
			AND = {
				scope:secondary_recipient = { has_trait = fp3_struggle_detractor }
				scope:recipient = { has_trait = fp3_struggle_supporter }
			}
			AND = {
				scope:secondary_recipient = { has_trait = fp3_struggle_supporter }
				scope:recipient = { has_trait = fp3_struggle_detractor }
			}
		}
		desc = WONT_HELP_STRUGGLE_FOE_REASON
	}
}