﻿revocation_tyranny_effect = {
	if = {
		limit = {
			title_revocation_is_tyrannical_trigger = yes
			dynasty = scope:recipient.dynasty
		}
		add_tyranny = revoke_title_tyranny_gain
	}
	else = {
		if = {
			limit = {
				has_claim_on = scope:landed_title
			}
			custom_tooltip = IS_ALLOWED_TO_REVOKE_TITLE_FOR_CLAIM_DESC
		}
		else_if = {
			limit = {
				has_revoke_title_reason = scope:recipient
			}
			custom_tooltip = IS_ALLOWED_TO_REVOKE_TITLE_DESC
		}
		else_if = {
			limit = {
				faith = {
					OR = {
						has_doctrine_parameter = pluralism_righteous_revocation_tyranny_reduced
						has_doctrine_parameter = pluralism_fundamentalist_revocation_tyranny_minimal
					}
					faith_hostility_level = {
						target = scope:recipient.faith
						value >= faith_hostile_level
					}
				}
			}
			if = {
				limit = {
					faith = {
						has_doctrine_parameter = pluralism_fundamentalist_revocation_tyranny_minimal 								
						faith_hostility_level = {
							target = scope:recipient.faith
							value = faith_hostile_level
						}
					}
				}
				custom_tooltip = IS_ALLOWED_TO_REVOKE_HOSTILE_INFIDEL_TITLE
			}
			else = {
				custom_tooltip = IS_ALLOWED_TO_REVOKE_EVIL_INFIDEL_TITLE
			}						
			every_vassal = {
				limit = {
					faith = scope:recipient.faith
				}
				custom = INFIDEL_REVOCATION_OPINION
				add_opinion = {
					modifier = angry_opinion
					target = scope:actor
					opinion = {
						value = revoke_title_tyranny_gain
						multiply = -1
					}
				}
			}
		}
		else_if = {
			limit = {
				NOT = { dynasty = scope:recipient.dynasty }
			}
			custom_tooltip = IS_ALLOWED_TO_REVOKE_TITLE_DYNASTY_DESC

			every_vassal = {
				limit = {
					NOR = {
						this = scope:recipient
						dynasty = scope:actor.dynasty
						is_ai = no
					}
					highest_held_title_tier > tier_barony
					is_landed = yes
				}

				custom = ALL_NON_DYNASTY_VASSALS

				add_opinion = {
					modifier = angry_opinion
					target = scope:actor
					opinion = {
						value = revoke_title_tyranny_gain
						multiply = -1
					}
				}
			}
		}
	}
}

war_for_revoke_effect = {
	scope:recipient = {
		save_scope_value_as = {
			name = war_for_revocation_flavour
			value = yes
		}
		start_war = {
			casus_belli = refused_liege_demand_war
			target = scope:actor
		}
	}
	if = {
		limit = {
			scope:actor = { NOT = { has_revoke_title_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 = {
						scope:recipient.dynasty = scope:actor.dynasty
						NOT = { dynasty = scope:actor.dynasty }
					}
					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
								}
							}
							NOR = {
								scope:actor = {
									has_revoke_title_reason = scope:recipient
								}
								scope:actor = {
									has_claim_on = scope:landed_title
								}
								faith = {								
									faith_hostility_level = {
										target = scope:recipient.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 = {
							opinion = {
								target = scope:recipient
								value >= -25
							}
							opinion = {
								target = scope:actor
								value <= -50
							}
						}
					}
				}
				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
		}
	}
}