## 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)
# 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.)
#
dynasty_vassalize = {
	name = CB_DYNASTY_VASSALIZE
	war_name = WAR_DYNASTY_VASSALIZE
	sprite = 1
	truce_days = 3650
	hostile_against_others = yes
	can_ask_to_join_war = no
	is_permanent = yes

	can_use = {
		NOT = { dynasty = none }
		ROOT = { dynasty = FROM }
		ROOT = {
			NOT = { FROM = { higher_tier_than = ROOT } }
			OR = {
				independent = yes
				liege = { NOT = { dynasty = ROOT } }
			}
			primary_title = { higher_tier_than = BARON }
			NOR = {
				pays_tribute_to = FROM
				any_liege = {
					OR = {
						pays_tribute_to = FROM
						FROM = {
							pays_tribute_to = PREV
						}
					}
				}
			}
		}
	}

	can_use_title = {
		always = yes
	}

	is_valid_title = {
		always = yes
	}

	on_success_title = {
		FROM = {
			if { 
				limit = { 
					ROOT = { tier = count } 
				}
				any_demesne_title = {
					limit = { tier = count }
					usurp_title_plus_barony_if_unlanded = { target = ROOT type = invasion }
				}
			}
			if { 
				limit = { 
					ROOT = { tier = duke } 
				}
				any_demesne_title = {
					limit = { tier = duke }
					usurp_title_plus_barony_if_unlanded = { target = ROOT type = invasion }
				}
			}
			if { 
				limit = { 
					ROOT = { tier = king } 
				}
				any_demesne_title = {
					limit = { tier = king }
					usurp_title_plus_barony_if_unlanded = { target = ROOT type = invasion }
				}
			}
			if { 
				limit = { 
					ROOT = { tier = emperor } 
				}
				any_demesne_title = {
					limit = { tier = emperor }
					usurp_title_plus_barony_if_unlanded = { target = ROOT type = invasion }
				}
			}
			set_defacto_liege = ROOT
		}
	}

	on_fail_title = {
		ROOT = {
		transfer_scaled_wealth = {
			to = FROM
			value = 4.0
		}
		}
	}

	on_reverse_demand = {
		ROOT = {
		transfer_scaled_wealth = {
			to = FROM
			value = 8.0
		}
		}
	}
	

	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
	}
}

