﻿war_for_imprison_effect = {
	scope:recipient = {
		save_scope_value_as = {
			name = war_for_imprisonment_flavour
			value = yes
		}
		start_war = {
			casus_belli = refused_liege_demand_war
			target = scope:actor
		}
	}
	if = {
		limit = {
			scope:actor = { NOT = { has_imprisonment_reason = scope:recipient } }
		}
		scope:actor = {
			every_vassal = { #Vassals joining the rebel.
				limit = {
					NOR = {
						this = scope:recipient
						is_ai = no
						has_trait = incapable
						is_imprisoned = yes
						dread_modified_ai_boldness = { #Too scared to do anything.
							dreaded_character = scope:actor
							value <= -50
						}
						is_at_war_with = scope:recipient
						is_at_war_with = scope:actor
					}
					highest_held_title_tier >= tier_barony
					OR = {
						#Lovers and friends always back rebel (unless also lovers/friends of the liege)
						AND = {
							OR = {
								has_relation_lover = scope:recipient
								has_relation_friend = scope:recipient
							}
							NOR = {
								has_relation_lover = scope:actor
								has_relation_friend = scope:actor
							}
						}
						#Vassals that either like recipient or have high honor will rally if the liege is being tyrannical.
						AND = {
							OR = {
								ai_honor >= 25
								opinion = {
									target = scope:recipient
									value >= 40
								}
								AND = {
									has_game_rule = hard_difficulty
									scope:actor = { is_ai = no }
									opinion = {
										target = scope:recipient
										value >= 20
									}
								}
								AND = {
									has_game_rule = very_hard_difficulty
									scope:actor = { is_ai = no }
									opinion = {
										target = scope:recipient
										value >= 0
									}
								}
							}
							NOT = {
								scope:actor = {
									has_imprisonment_reason = scope:recipient
								}
							}
						}
						#And finally, vassals that really hate their liege will join regardless (provided that they also do not hate recipient).
						AND = {
							OR = {
								opinion = {
									target = scope:recipient
									value >= -25
								}
								AND = {
									has_game_rule = hard_difficulty
									scope:actor = { is_ai = no }
									opinion = {
										target = scope:recipient
										value >= -50
									}
								}
								AND = {
									has_game_rule = very_hard_difficulty
									scope:actor = { is_ai = no }
									opinion = {
										target = scope:recipient
										value >= -75
									}
								}
							}
							OR = {
								opinion = {
									target = scope:actor
									value <= -40
								}
								AND = {
									has_game_rule = hard_difficulty
									scope:actor = { is_ai = no }
									opinion = {
										target = scope:actor
										value <= -20
									}
								}
								AND = {
									has_game_rule = very_hard_difficulty
									scope:actor = { is_ai = no }
									opinion = {
										target = scope:actor
										value <= 0
									}
								}
							}
						}
					}
				}
				add_to_list = joining_vassals
			}
			every_in_list = {
				list = joining_vassals
				save_scope_as = joining_vassal
				custom_tooltip = tooltip_fellow_vassal_joins_war #The war has not started when viewing the interaction screen.
				hidden_effect = {
					scope:recipient = {
						every_character_war = {
							limit = {
								using_cb = refused_liege_demand_war
								casus_belli = {
									primary_attacker = scope:recipient
									primary_defender = scope:actor
								}
							}
								add_to_list = war_to_join
						}
					}
					every_in_list = {
						list = war_to_join
						limit = {
							NOT = { is_defender = prev }
						}
						hidden_effect = {
							set_called_to = prev
						}
						add_attacker = prev
					}
				}
				hidden_effect = {
					scope:actor = {
						add_opinion = {
							target = prev
							modifier = rebellious_vassal_opinion
						}
					}
				}
			}
			every_vassal = {
				limit = {
					is_ai = no
					NOT = { this = scope:recipient }
					is_imprisoned = no
				}
				trigger_event = char_interaction.0232
			}
		}
	}
	scope:recipient = {
		add_opinion = {
			target = scope:actor
			modifier = attempted_arrest_opinion
		}
	}
}

war_for_revoke_effect = {
	$REBEL$ = {
		save_scope_value_as = {
			name = war_for_revocation_flavour
			value = yes
		}
		start_war = {
			casus_belli = refused_liege_demand_war
			target = $LIEGE$
		}
	}
	$LIEGE$ = {
		if = {
			limit = {
				NOT = { has_revoke_title_reason = $REBEL$ }
			}
			every_vassal = { #Vassals joining the rebel.
				custom = vassals_joining_war_tt
				limit = {
					NOR = {
						this = $REBEL$
						is_ai = no
						has_trait = incapable
						is_imprisoned = yes
						dread_modified_ai_boldness = { #Too scared to do anything.
							dreaded_character = $LIEGE$
							value <= -50
						}
						opinion = { # People who really, really like you will still back you
							target = $LIEGE$
							value >= 80
						}
						is_at_war_with = $REBEL$
						is_at_war_with = $LIEGE$
					}
					highest_held_title_tier >= tier_barony
					OR = {
						#Lovers and friends always back rebel (unless also lovers/friends of the liege)
						AND = {
							OR = {
								has_relation_lover = $REBEL$
								has_relation_friend = $REBEL$
							}
							NOR = {
								has_relation_lover = $LIEGE$
								has_relation_friend = $LIEGE$
							}
						}
						#Vassals that either like recipient or have high honor will rally if the liege is being tyrannical.
						AND = {
							# If they can't join a faction against the liege they should not revolt
							NOR = {
								has_relation_lover = $LIEGE$
								has_relation_friend = $LIEGE$
								is_allied_to = $LIEGE$
								is_primary_heir_of = $LIEGE$
								$LIEGE$ = { has_strong_hook = prev }
								has_dread_level_towards = {
									target = $LIEGE$
									level = 2
								}
							}
							OR = {
								ai_honor >= 25
								opinion = {
									target = $REBEL$
									value >= 40
								}
								AND = {
									has_game_rule = hard_difficulty
									$LIEGE$ = { is_ai = no }
									opinion = {
										target = $REBEL$
										value >= 20
									}
								}
								AND = {
									has_game_rule = very_hard_difficulty
									$LIEGE$ = { is_ai = no }
									opinion = {
										target = $REBEL$
										value >= 0
									}
								}
							}
							NOR = {
								$LIEGE$ = { has_revoke_title_reason = $REBEL$ }
								trigger_if = {
									limit = { exists = scope:landed_title }
									$LIEGE$ = { has_claim_on = scope:landed_title }
								}
								faith = {
									faith_hostility_level = {
										target = $REBEL$.faith
										value >= faith_hostile_level
									}
								}
							}
						}
						#And finally, vassals that really hate their liege will join regardless (provided that they also do not hate recipient).
						AND = {
							OR = {
								opinion = {
									target = $REBEL$
									value >= -25
								}
								AND = {
									has_game_rule = hard_difficulty
									$LIEGE$ = { is_ai = no }
									opinion = {
										target = $REBEL$
										value >= -50
									}
								}
								AND = {
									has_game_rule = very_hard_difficulty
									$LIEGE$ = { is_ai = no }
									opinion = {
										target = $REBEL$
										value >= -75
									}
								}
							}
							OR = {
								#default threshold
								opinion = {
									target = $LIEGE$
									value <= -50
								}
								AND = {
									has_game_rule = hard_difficulty
									$LIEGE$ = { is_ai = no }
									opinion = {
										target = $LIEGE$
										value <= -25
									}
								}
								AND = {
									has_game_rule = very_hard_difficulty
									$LIEGE$ = { is_ai = no }
									opinion = {
										target = $LIEGE$
										value <= 0
									}
								}
								#If tyrannical, the default threshold will be reached if at this level
								AND = {
									$LIEGE$ = {
										title_revocation_is_tyrannical_trigger = { VASSAL = $REBEL$ }
									}
									OR = {
										opinion = {
											target = $LIEGE$
											value <= -30 #revoke_title_tyranny_gain adds -20
										}
										AND = {
											has_game_rule = hard_difficulty
											$LIEGE$ = { is_ai = no }
											opinion = {
												target = $LIEGE$
												value <= -10
											}
										}
										AND = {
											has_game_rule = very_hard_difficulty
											$LIEGE$ = { is_ai = no }
											opinion = {
												target = $LIEGE$
												value <= 10
											}
										}
									}
								}
							}
						}
					}
				}
				save_scope_as = joining_vassal
				custom_tooltip = tooltip_fellow_vassal_joins_war #The war has not started when viewing the interaction screen.
				hidden_effect = {
					$REBEL$ = {
						every_character_war = {
							limit = {
								using_cb = refused_liege_demand_war
								casus_belli = {
									primary_attacker = $REBEL$
									primary_defender = $LIEGE$
								}
							}
							add_to_list = war_to_join
						}
					}
					every_in_list = {
						list = war_to_join
						limit = {
							NOT = { is_defender = prev }
						}
						hidden_effect = {
							set_called_to = prev
						}
						add_attacker = prev
					}
				}
				hidden_effect = {
					$LIEGE$ = {
						add_opinion = {
							target = prev
							modifier = rebellious_vassal_opinion
						}
					}
				}
			}
			every_vassal = {
				limit = {
					is_ai = no
					NOT = { this = $REBEL$ }
					is_imprisoned = no
				}
				$REBEL$ = { save_scope_as = recipient }
				$LIEGE$ = { save_scope_as = actor }
				trigger_event = char_interaction.0232
			}
		}
	}
	$REBEL$ = {
		add_opinion = {
			target = $LIEGE$
			modifier = attempted_arrest_opinion
		}
	}
}

war_for_retraction_effect = {
	scope:recipient = {
		save_scope_value_as = {
			name = war_for_retraction_flavour
			value = yes
		}
		start_war = {
			casus_belli = refused_liege_demand_war
			target = scope:actor
		}
	}
	scope:actor = {
		every_vassal = { #Vassals joining the rebel.
			limit = {
				NOR = {
					this = scope:recipient
					is_ai = no
					has_trait = incapable
					is_imprisoned = yes
					dread_modified_ai_boldness = { #Too scared to do anything.
						dreaded_character = scope:actor
						value <= -50
					}
					is_at_war_with = scope:recipient
					is_at_war_with = scope:actor
				}
				highest_held_title_tier >= tier_barony
				OR = {
					#Lovers and friends always back rebel (unless also lovers/friends of the liege)
					AND = {
						OR = {
							has_relation_lover = scope:recipient
							has_relation_friend = scope:recipient
						}
						NOR = {
							has_relation_lover = scope:actor
							has_relation_friend = scope:actor
						}
					}
					#Vassals that either like recipient or have high honor will rally if the liege is being tyrannical (taking away de jure vassal).
					AND = {
						OR = {
							ai_honor >= 25
							opinion = {
								target = scope:recipient
								value >= 40
							}
							AND = {
								has_game_rule = hard_difficulty
								scope:actor = { is_ai = no }
								opinion = {
									target = scope:recipient
									value >= 20
								}
							}
							AND = {
								has_game_rule = very_hard_difficulty
								scope:actor = { is_ai = no }
								opinion = {
									target = scope:recipient
									value >= 0
								}
							}
						}
						scope:recipient = {
							any_held_title = {
								is_de_jure_liege_or_above_target = scope:secondary_recipient.primary_title
							}
						}
					}
					#And finally, vassals that really hate their liege will join regardless (provided that they also do not hate recipient).
					AND = {
						OR = {
							opinion = {
								target = scope:recipient
								value >= -25
							}
							AND = {
								has_game_rule = hard_difficulty
								scope:actor = { is_ai = no }
								opinion = {
									target = scope:recipient
									value >= -50
								}
							}
							AND = {
								has_game_rule = very_hard_difficulty
								scope:actor = { is_ai = no }
								opinion = {
									target = scope:recipient
									value >= -75
								}
							}
						}
						OR = {
							opinion = {
								target = scope:actor
								value <= -40
							}
							AND = {
								has_game_rule = hard_difficulty
								scope:actor = { is_ai = no }
								opinion = {
									target = scope:actor
									value <= -20
								}
							}
							AND = {
								has_game_rule = very_hard_difficulty
								scope:actor = { is_ai = no }
								opinion = {
									target = scope:actor
									value <= 0
								}
							}
						}
					}
				}
			}
			save_scope_as = joining_vassal
			custom_tooltip = tooltip_fellow_vassal_joins_war #The war has not started when viewing the interaction screen.
			hidden_effect = {
				scope:recipient = {
					every_character_war = {
						limit = {
							using_cb = refused_liege_demand_war
							casus_belli = {
								primary_attacker = scope:recipient
								primary_defender = scope:actor
							}
						}
							add_to_list = war_to_join
					}
				}
				every_in_list = {
					list = war_to_join
					limit = {
						NOT = { is_defender = prev }
					}
					hidden_effect = {
						set_called_to = prev
					}
					add_attacker = prev
				}
			}
			hidden_effect = {
				scope:actor = {
					add_opinion = {
						target = prev
						modifier = rebellious_vassal_opinion
					}
				}
			}
		}
		every_vassal = {
			limit = {
				is_ai = no
				NOT = { this = scope:recipient }
				is_imprisoned = no
			}
			trigger_event = char_interaction.0232
		}
	}
	scope:recipient = {
		add_opinion = {
			target = scope:actor
			modifier = attempted_arrest_opinion
		}
	}
}