## normal scopes(including posttitle scopes) ##
# ROOT = receiver
# FROM = giver
# <no scope change> = attacker or receiver
## title scopes ##
# ROOT = receiver
# FROM = giver
# <no scope change> = thirdparty landed title	
#
# the following effects/triggers exists (example execution order: on_success->on_success_title->on_success_posttitle):
# is_valid, is_valid_title, on_add, on_add_title, on_add_posttitle, on_success, on_success_title, on_success_posttitle, on_fail, on_fail_title, on_fail_posttitle, on_reverse_demand, on_reverse_demand_title, on_reverse_demand_posttitle
#
# Added on_attacker_leader_death, on_defender_leader_death and on_thirdparty_death, which all trigger when corresponding character dies
# These three all have war scopes, which currently has the following scope changes: 
# attacker, defender, thirdparty(only valid if thirdparty character is involved), thirdparty_title(only valid if thirdparty title is involved)
#
# ai_will_do: modifies value AI places on the CB compared to other CBs (default: 1) Note: is in title scope
# can_use_gui: If otherwise valid, the CB is listed in the Diplo View, but you can't declare war unless 'can_use_gui' is also valid (also shows a trigger tooltip.)
#

# The CB used by "Undead revolter" characters
undead_revolt = {
	name = CB_NAME_UNDEAD_REVOLT
	war_name = WAR_NAME_UNDEAD_REVOLT
	sprite = 16
	truce_days = 365
	hostile_against_others = yes
	
	#is_revolt_cb = yes
	can_call_vassals = yes
	major_revolt = yes
	attacker_can_call_allies = no
	can_ask_to_join_war = no
	
	is_independence = yes
	
	can_use = {
		ROOT = {
			primary_title = { temporary = yes } # Revolter or adventurer trigger
			war = no
			NOT = { is_liege_or_above = FROM }
			mercenary = no
			#culture_group = undead
		}
	}

	can_use_title = {
		tier = count
	}

	is_valid_title = {
		OR = {
			FROM = {
				has_landed_title = PREV
			}
			holder_scope = {
				is_liege_or_above = FROM
			}
		}
	}

	on_success_title = {
		FROM = {
			prestige = -500
			abdicate = yes
		}
		ROOT = {
			hidden_tooltip = {
				clear_wealth = yes
				any_courtier_or_vassal = {
					limit = { culture_group = undead }
					death = { death_reason = death_missing }
				}
				death = { death_reason = death_missing }
			}
		}
	}

	on_fail_title = {
		FROM = {
			prestige = 50
			add_character_modifier = { 
				name = recent_undead_revolt
				days = 730
			}
		}
		ROOT = {
			hidden_tooltip = {
				clear_wealth = yes
				any_courtier_or_vassal = {
					limit = { culture_group = undead }
					death = { death_reason = death_missing }
				}
				death = { death_reason = death_missing }
			}
		}
	}

	on_reverse_demand = {
		FROM = {
			prestige = 100
				add_character_modifier = { 
				name = recent_undead_revolt
				days = 365
			}
		}
		ROOT = {
			hidden_tooltip = {
				any_courtier_or_vassal = {
					limit = { culture_group = undead }
					death = { death_reason = death_missing }
				}
				death = { death_reason = death_missing }
			}
		}
	}

	attacker_ai_victory_worth = {
		factor = -1 # always accept
	}
	
	attacker_ai_defeat_worth = {
		factor = 100
	}

	defender_ai_victory_worth = {
		factor = -1 # always accept
	}
	
	defender_ai_defeat_worth = {
		factor = 100
	}
}

# Witchhunters can subjugate supernatural characters
supernatural_subjugation = {
	name = CB_NAME_WITCH_SUBJUGATION
	war_name = WAR_NAME_WITCH_SUBJUGATION
	sprite = 9
	truce_days = 365
	is_permanent = yes
	can_ask_to_join_war = yes
	allowed_to_target_tributaries = no
	
	can_use = {
		ROOT = {
			OR = {
				religion_group = christian
				religion_group = jewish_group
				religion = hellenic_pagan
				religion = hellenic_pagan_reformed
				religion_group = pagan_group
				religion_group = mythical_religion_group
				religion_group = muslim
			}
			OR = {
				any_demesne_title = { title = d_dawnguard_company }
				AND = {
					society_member_of = witchhunters
					society_rank > 3
				}
			}
			OR = {
				any_demesne_title = { title = d_dawnguard_company }
				AND = {
					NOT = { same_realm = FROM }
					NOT = { is_liege_or_above = FROM }
					OR = {
						AND = {
							has_dlc = "Horse Lords"
							is_nomadic = no
						}
						AND = {
							NOT = { has_dlc = "Horse Lords" }
							has_horde_culture = no # Should use tribal invasion instead
						}
					}
				}
			}
			OR = {
				any_demesne_title = { title = d_dawnguard_company }
				realm_size = 3
			}
		}
		
		FROM = {
			in_revolt = no
			is_within_diplo_range = ROOT
			NOT = { is_offmap_governor = yes }
			OR = {
				AND = {
					NOT = { has_global_flag = magical_age_restored }
					trait = wizard
					OR = {
						trait = cynical
						trait = cruel
						trait = lunatic
						trait = possessed
					}
					NOT = { trait = zealous }
				}
				AND = {
					NOT = { has_global_flag = magical_age_restored }
					trait = sorcerer
					NOT = { trait = zealous }
				}
				
				AND = {
					has_global_flag = magical_age_restored
					trait = vampire
				}
				AND = {
					NOT = { has_global_flag = magical_age_restored }
					has_character_modifier = known_vampire
				}
				AND = {
					has_global_flag = magical_age_restored
					trait = werewolf
				}
				AND = {
					NOT = { has_global_flag = magical_age_restored }
					has_character_modifier = known_werewolf
				}
				
				AND = {
					NOT = { has_global_flag = magical_age_restored }
					culture_group = elven
				}
				AND = {
					NOT = { has_global_flag = magical_age_restored }
					culture_group = draconian
				}
				AND = {
					NOT = { has_global_flag = magical_age_restored }
					culture_group = ork
				}
				culture_group = undead
				has_character_modifier = lycanthropy
				has_character_modifier = wolf_child
				has_character_modifier = wolf_blood
				has_character_modifier = demon_child_non_pagan
				has_character_modifier = known_witch
			}
		}
	}
	
	on_add = {
		if = {
			limit = { defender = { is_offmap_governor = offmap_china } }
			attacker = {  
				sound_effect = china_angered_emperor
				detract_grace_super_huge_effect = yes 
			}
		}
	}

	on_success = {
		ROOT = {
			piety = 150
			participation_scaled_prestige = 150
			add_society_currency_major_effect = yes
		}
		any_attacker = {
			limit = { NOT = { character = ROOT } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
		FROM = {
			death = { death_reason = death_dungeon killer = ROOT }
			
			custom_tooltip = {
				text = tribal_subjugation_tip
			}
				
			hidden_tooltip = {
				if = {
					limit = { NOT = { has_global_flag = magical_age_restored } }
					any_courtier_or_vassal = {
						limit = {
							OR = {
								trait = wizard
								trait = sorcerer
								culture_group = elven
								culture_group = draconian
								culture_group = ork
							}
						}
						banish = yes
					}
				}
				any_courtier_or_vassal = {
					limit = {
						OR = {
							AND = {
								has_global_flag = magical_age_restored
								trait = vampire
							}
							AND = {
								NOT = { has_global_flag = magical_age_restored }
								has_character_modifier = known_vampire
							}
							AND = {
								has_global_flag = magical_age_restored
								trait = werewolf
							}
							AND = {
								NOT = { has_global_flag = magical_age_restored }
								has_character_modifier = known_werewolf
							}
							culture_group = undead
							has_character_modifier = lycanthropy
							has_character_modifier = wolf_child
							has_character_modifier = wolf_blood
							has_character_modifier = demon_child_non_pagan
							has_character_modifier = known_witch
						}
					}
					death = { death_reason = death_dungeon killer = ROOT }
				}
				any_demesne_title = {
					limit = {
						higher_tier_than = ROOT
					}
					ROOT = { usurp_title = { target = PREV type = invasion } }
					add_pressed_claim = PREV
				}
				any_demesne_title = {
					limit = {
						tier = ROOT
					}
					ROOT = { usurp_title = { target = PREV type = invasion } }
					add_pressed_claim = PREV
				}
				set_defacto_liege = ROOT
			}
		}
	}
	
	on_fail = {
		FROM = {
			piety = 50
			participation_scaled_prestige = 50
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 50 }
		}
		ROOT = {
			piety = -200
		}
	}

	on_reverse_demand = {
		ROOT = {
			piety = -400
			detract_society_currency_medium_effect = yes
			transfer_scaled_wealth = {
				to = FROM
				value = 2.0
			}
		}
		FROM = {
			piety = 100
			participation_scaled_prestige = 200
		}
		any_defender = {
			limit = { NOT = { character = FROM } }
			hidden_tooltip = { participation_scaled_prestige = 100 }
		}
	}

	attacker_ai_victory_worth = {
		factor = -1 # always accept
	}
	
	attacker_ai_defeat_worth = {
		factor = 100
	}

	defender_ai_victory_worth = {
		factor = -1 # always accept
	}
	
	defender_ai_defeat_worth = {
		factor = 100
	}
	
	ai_will_do = { 
		factor = 1
	}
}