# Vassal CB made available when China is in the corruption dynastic cycle phase.
china_seize_county_cb = {
	icon = county_conquest_cb
	group = celestial

	combine_into_one = yes
	should_show_war_goal_subview = yes
	mutually_exclusive_titles = { always = yes }

	allowed_for_character = {
		is_independent_ruler = no
		top_liege = {
			has_title = title:h_china
		}
		top_participant_group:dynastic_cycle ?= {
			OR = {
				AND = {
					has_participant_group_parameter = dynastic_cycle_vassal_internal_wars_allowed
					root = {
						NOT = {
							government_has_flag = government_is_celestial
						}
					}
				}
				AND = {
					has_participant_group_parameter = dynastic_cycle_vassal_seize_cb
					root = {
						OR = {
							NOT = {
								government_has_flag = government_is_celestial
							}
							vassal_contract_has_flag = celestial_military_appointment
						}
					}
				}
			}
		}
	}

	allowed_against_character = {
		scope:attacker = {
			trigger_if = {
				limit = {
					government_has_flag = government_is_celestial
				}
				scope:attacker.top_overlord != scope:defender.top_overlord # Must NOT be peer-vassals or tributaries
			}
			trigger_else = {
				scope:attacker.top_overlord = scope:defender.top_overlord # Must be peer-vassals or tributaries
			}
		}
	}

	target_titles = neighbor_land
	target_title_tier = county
	ignore_effect = change_title_holder

	attacker_score_from_occupation_scale = 150
	attacker_score_from_battles_scale = 150
	defender_score_from_battles_scale = 150

	ai_only_against_neighbors = yes

	ai_score_mult = {
		# As a feudal gov, do not attack owner of tribal holdings  if you have a tribal holding to convert already
		add = {
			every_in_list = {
				list = target_titles
				if = {
					limit = { feudal_clan_tribal_conquest_constraints = yes }
					add = -1000
				}
			}
		}

		# AI in struggles act insularly for wars that don't have a familial or legal basis.
		multiply = struggle_wars_prioritise_struggle_targets_value
	}

	valid_to_start = {
	}

	allowed_for_character_display_regardless = {
	}

	should_invalidate = {
		NOT = {
			any_in_list = {
				list = target_titles
				any_in_de_jure_hierarchy = {
					tier = tier_county
					holder = {
						OR = {
							this = scope:defender
							target_is_liege_or_above = scope:defender
						}
					}
				}
			}
		}
	}

	on_invalidated_desc = msg_county_conquest_war_invalidated_message
	on_invalidated = {}

	cost = {
		prestige = {
			add = {
				value = 50
				desc = CB_BASE_COST
			}
			add = {
				value = 2.5
				multiply = scope:attacker.realm_size
				desc = CB_REALM_SIZE_COST
				max = 150
			}
			multiply = common_cb_prestige_cost_multiplier
		}
	}

	on_declaration = {
		on_declared_war = yes
		# When this war is started, the Chinese emperor loses legitimacy
		scope:attacker = {
			top_liege = {
				add_legitimacy_effect = { LEGITIMACY = miniscule_legitimacy_loss }
			}
		}
	}

	on_victory_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:attacker = { is_local_player = yes } }
				desc = county_conquest_cb_victory_desc_attacker
			}
			desc = county_conquest_cb_victory_desc
		}
	}

	on_victory = {
		scope:attacker = { show_pow_release_message_effect = yes }

		# Legitimacy
		add_legitimacy_attacker_victory_effect = yes

		# Influence
		add_influence_attacker_victory_effect = yes

		# EP2 accolade glory gain for winning against higher ranked enemy
		scope:attacker = { accolade_attacker_war_end_glory_gain_low_effect = yes }

		create_title_and_vassal_change = {
			type = conquest
			save_scope_as = change
			add_claim_on_loss = yes
		}
		# Grab the designated county.
		every_in_list = {
			list = target_titles
			change_title_holder = {
				holder = scope:attacker
				change = scope:change
			}
		}
		resolve_title_and_vassal_change = scope:change

		# Prestige Progress for the Attacker
		every_in_list = {
			list = target_titles
			scope:attacker = {
				add_prestige_experience = minor_prestige_value
			}
		}

		# Allies on both sides get full prestige value for helping in the war, based on their war participation.
		modify_allies_of_participants_fame_values = {
			WINNER = scope:attacker
			FAME_BASE = minor_prestige_value
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}

		# Truce
		add_truce_attacker_victory_effect = yes

		# FP1: note the victory for future memorialisation via stele (if applicable).
		scope:attacker = { fp1_remember_recent_conquest_victory_effect = yes }

		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
		laamp_as_mercenary_payout_tooltip_effect = yes
	}

	on_white_peace_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = county_conquest_cb_white_peace_desc_defender
			}
			desc = county_conquest_cb_white_peace_desc
		}
	}

	on_white_peace = {
		scope:attacker = { show_pow_release_message_effect = yes }
		# Prestige loss for the attacker
		scope:attacker = {
			add_prestige = {
				value = minor_prestige_value
				multiply = -1.0
			}
			stress_impact = {
 				ambitious = medium_stress_impact_gain
 				arrogant = medium_stress_impact_gain
 			}
		}

		# Allies on both sides get full prestige value for helping in the war, based on their war participation.
		modify_allies_of_participants_fame_values = {
			WINNER = scope:attacker # Not important as the scales are identical
			FAME_BASE = minor_prestige_value
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}

		scope:defender = {
			stress_impact = {
 				arrogant = medium_stress_impact_gain
 			}
		}

		add_truce_white_peace_effect = yes

		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
		laamp_as_mercenary_payout_tooltip_effect = yes
	}

	on_defeat_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = county_conquest_cb_defeat_desc_defender
			}
			triggered_desc = {
				trigger = {
					scope:attacker = {
						is_local_player = yes
						has_targeting_faction = yes
					}
				}
				desc = county_conquest_cb_defeat_desc_attacker
			}
			desc = county_conquest_cb_defeat_desc
		}
	}

	on_defeat = {
		scope:attacker = { show_pow_release_message_effect = yes }

		# Legitimacy
		add_legitimacy_attacker_defeat_effect = yes

		# Influence
		add_influence_attacker_defeat_effect = yes

		scope:defender = { 
			mandala_peacemaker_perk_serenity_effect = yes
			#EP2 accolade glory gain for winning against higher ranked enemy
			accolade_defender_war_end_glory_gain_high_effect = yes
			# Prestige for Defender
			add_prestige_war_defender_effect = {
				PRESTIGE_VALUE = medium_prestige_value
			}
		}

		# Prestige loss for the attacker
		scope:attacker = {
			pay_short_term_gold_reparations_effect = {
				GOLD_VALUE = 2
			}
			add_prestige = medium_prestige_loss
		}

		# Allies on both sides get full prestige value for helping in the war, based on their war participation.
		modify_allies_of_participants_fame_values = {
			WINNER = scope:defender
			FAME_BASE = minor_prestige_value
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}

		add_truce_attacker_defeat_effect = yes

		scope:attacker = {
			save_temporary_scope_as = loser
		}
		on_lost_aggression_war_discontent_loss = yes

		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
		laamp_as_mercenary_payout_tooltip_effect = yes
	}

	transfer_behavior = transfer

	on_primary_attacker_death = inherit
	on_primary_defender_death = inherit

	attacker_allies_inherit = yes
	defender_allies_inherit = yes

	war_name = "CHINA_SEIZE_COUNTY_WAR_NAME"
	war_name_base = "CHINA_SEIZE_COUNTY_WAR_NAME_BASE"
	cb_name = "CHINA_SEIZE_COUNTY_CB_NAME"

	interface_priority = 83

	use_de_jure_wargoal_only = yes

	attacker_wargoal_percentage = 0.8

	max_defender_score_from_occupation = 150
	max_attacker_score_from_occupation = 150
}

china_hegemon_seize_county_cb = {
	icon = county_conquest_cb
	group = celestial

	combine_into_one = yes
	should_show_war_goal_subview = yes
	mutually_exclusive_titles = { always = yes }

	allowed_for_character = {
		OR = {
			has_title = title:h_china
			has_title = title:e_minister_grand_marshal
		}
		situation:dynastic_cycle ?= {
			has_situation_top_phase_parameter = dynastic_cycle_hegemon_unlocks_external_casus_belli
		}
	}

	allowed_for_character_display_regardless = {
		tgp_dynastic_cycle_offensive_wars_ban_trigger = yes
	}

	allowed_against_character = {
		scope:defender = {
			NOR = {
				government_has_flag = government_is_landless_adventurer
				government_has_flag = government_is_herder
			}
		}
	}

	target_titles = all
	target_title_tier = county
	ignore_effect = change_title_holder

	attacker_score_from_occupation_scale = 150
	attacker_score_from_battles_scale = 150
	defender_score_from_battles_scale = 150

	ai_only_against_neighbors = yes

	ai_score_mult = {
		# As a feudal gov, do not attack owner of tribal holdings  if you have a tribal holding to convert already
		add = {
			every_in_list = {
				list = target_titles
				if = {
					limit = { feudal_clan_tribal_conquest_constraints = yes }
					add = -1000
				}
			}
		}
	}

	valid_to_start = {
		scope:target ?= {
			is_neighbor_to_realm = scope:attacker.top_liege
		}
	}

	should_invalidate = {
		NOT = {
			any_in_list = {
				list = target_titles
				any_in_de_jure_hierarchy = {
					tier = tier_county
					holder = {
						OR = {
							this = scope:defender
							target_is_liege_or_above = scope:defender
						}
					}
				}
			}
		}
	}

	on_invalidated_desc = msg_county_conquest_war_invalidated_message
	on_invalidated = {}

	cost = {
		prestige = {
			add = {
				value = 50
				desc = CB_BASE_COST
			}
			add = {
				value = 2.5
				multiply = scope:attacker.realm_size
				desc = CB_REALM_SIZE_COST
				max = 150
			}
			multiply = common_cb_prestige_cost_multiplier
		}
	}

	on_declaration = {
		on_declared_war = yes

		# When this war is started, the chinese emperor loses legitimacy
		scope:attacker = {
			top_liege = {
				add_legitimacy_effect = { LEGITIMACY = miniscule_legitimacy_loss }
			}
		}
	}

	on_victory_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:attacker = { is_local_player = yes } }
				desc = county_conquest_cb_victory_desc_attacker
			}
			desc = county_conquest_cb_victory_desc
		}
	}

	on_victory = {
		scope:attacker = { show_pow_release_message_effect = yes }

		# Legitimacy
		add_legitimacy_attacker_victory_effect = yes

		# Influence
		add_influence_attacker_victory_effect = yes

		# EP2 accolade glory gain for winning against higher ranked enemy
		scope:attacker = { accolade_attacker_war_end_glory_gain_low_effect = yes }

		create_title_and_vassal_change = {
			type = conquest
			save_scope_as = change
			add_claim_on_loss = yes
		}
		if = {
			limit = {
				scope:attacker = {
					has_title = title:e_minister_grand_marshal
				}
			}
			# Grab the designated county.
			every_in_list = {
				list = target_titles
				change_title_holder = {
					holder = scope:attacker.top_liege
					change = scope:change
				}
			}
		}
		else = {
			# Grab the designated county.
			every_in_list = {
				list = target_titles
				change_title_holder = {
					holder = scope:attacker
					change = scope:change
				}
			}
		}
		resolve_title_and_vassal_change = scope:change

		# Prestige Progress for the Attacker
		every_in_list = {
			list = target_titles
			scope:attacker = {
				add_prestige_experience = minor_prestige_value
			}
		}

		# Allies on both sides get full prestige value for helping in the war, based on their war participation.
		modify_allies_of_participants_fame_values = {
			WINNER = scope:attacker
			FAME_BASE = minor_prestige_value
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}

		# Truce
		add_truce_attacker_victory_effect = yes

		# FP1: note the victory for future memorialisation via stele (if applicable).
		scope:attacker = { fp1_remember_recent_conquest_victory_effect = yes }

		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
		laamp_as_mercenary_payout_tooltip_effect = yes
	}

	on_white_peace_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = county_conquest_cb_white_peace_desc_defender
			}
			desc = county_conquest_cb_white_peace_desc
		}
	}

	on_white_peace = {
		scope:attacker = { show_pow_release_message_effect = yes }
		# Prestige loss for the attacker
		scope:attacker = {
			add_prestige = {
				value = minor_prestige_value
				multiply = -1.0
			}
			stress_impact = {
 				ambitious = medium_stress_impact_gain
 				arrogant = medium_stress_impact_gain
 			}
		}

		# Allies on both sides get full prestige value for helping in the war, based on their war participation.
		modify_allies_of_participants_fame_values = {
			WINNER = scope:attacker # Not important as the scales are identical
			FAME_BASE = minor_prestige_value
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}

		scope:defender = {
			stress_impact = {
 				arrogant = medium_stress_impact_gain
 			}
		}

		add_truce_white_peace_effect = yes

		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
		laamp_as_mercenary_payout_tooltip_effect = yes
	}

	on_defeat_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = county_conquest_cb_defeat_desc_defender
			}
			triggered_desc = {
				trigger = {
					scope:attacker = {
						is_local_player = yes
						has_targeting_faction = yes
					}
				}
				desc = county_conquest_cb_defeat_desc_attacker
			}
			desc = county_conquest_cb_defeat_desc
		}
	}

	on_defeat = {
		scope:attacker = { show_pow_release_message_effect = yes }

		# Legitimacy
		add_legitimacy_attacker_defeat_effect = yes

		# Influence
		add_influence_attacker_defeat_effect = yes

		scope:defender = { 
			mandala_peacemaker_perk_serenity_effect = yes
			#EP2 accolade glory gain for winning against higher ranked enemy
			accolade_defender_war_end_glory_gain_high_effect = yes
			# Prestige for Defender
			add_prestige_war_defender_effect = {
				PRESTIGE_VALUE = medium_prestige_value
			}
		}

		# Prestige loss for the attacker
		scope:attacker = {
			pay_short_term_gold_reparations_effect = {
				GOLD_VALUE = 2
			}
			add_prestige = medium_prestige_loss
		}

		# Allies on both sides get full prestige value for helping in the war, based on their war participation.
		modify_allies_of_participants_fame_values = {
			WINNER = scope:defender
			FAME_BASE = minor_prestige_value
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}

		add_truce_attacker_defeat_effect = yes

		scope:attacker = {
			save_temporary_scope_as = loser
		}
		on_lost_aggression_war_discontent_loss = yes

		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
		laamp_as_mercenary_payout_tooltip_effect = yes
	}

	transfer_behavior = transfer

	on_primary_attacker_death = inherit
	on_primary_defender_death = inherit

	attacker_allies_inherit = yes
	defender_allies_inherit = yes

	war_name = "CHINA_SEIZE_COUNTY_WAR_NAME"
	war_name_base = "CHINA_SEIZE_COUNTY_WAR_NAME_BASE"
	cb_name = "CHINA_SEIZE_COUNTY_CB_NAME"

	interface_priority = 83

	use_de_jure_wargoal_only = yes

	attacker_wargoal_percentage = 0.8

	max_defender_score_from_occupation = 150
	max_attacker_score_from_occupation = 150
}
# Same as above, but for targeting Duchies
china_seize_duchy_cb = {
	icon = duchy_conquest_cb
	group = celestial

	combine_into_one = yes
	should_show_war_goal_subview = yes
	mutually_exclusive_titles = { always = yes }

	allowed_for_character = {
		is_independent_ruler = no
		top_liege = {
			has_title = title:h_china
		}
		top_participant_group:dynastic_cycle ?= {
			OR = {
				AND = {
					has_participant_group_parameter = dynastic_cycle_vassal_internal_wars_allowed
					root = {
						NOT = {
							government_has_flag = government_is_celestial
						}
					}
				}
				AND = {
					has_participant_group_parameter = dynastic_cycle_vassal_seize_cb
					root = {
						OR = {
							NOT = {
								government_has_flag = government_is_celestial
							}
							vassal_contract_has_flag = celestial_military_appointment
						}
					}
				}
			}
		}
	}

	allowed_against_character = {
		scope:attacker = {
			trigger_if = {
				limit = {
					government_has_flag = government_is_celestial
				}
				scope:attacker.top_overlord != scope:defender.top_overlord # Must NOT be peer-vassals or tributaries
			}
			trigger_else = {
				scope:attacker.top_overlord = scope:defender.top_overlord # Must be peer-vassals or tributaries
			}
		}
	}

	target_titles = neighbor_land
	target_title_tier = duchy
	ignore_effect = change_title_holder

	attacker_score_from_occupation_scale = 150
	attacker_score_from_battles_scale = 150
	defender_score_from_battles_scale = 150

	ai_only_against_neighbors = yes

	ai_score_mult = {
		# As a feudal gov, do not attack owner of tribal holdings  if you have a tribal holding to convert already
		add = {
			every_in_list = {
				list = target_titles
				if = {
					limit = { feudal_clan_tribal_conquest_constraints = yes }
					add = -1000
				}
			}
		}

		# AI in struggles act insularly for wars that don't have a familial or legal basis.
		multiply = struggle_wars_prioritise_struggle_targets_value
	}

	valid_to_start = {
	}

	allowed_for_character_display_regardless = {
	}

	should_invalidate = {
		NOT = {
			any_in_list = {
				list = target_titles
				any_in_de_jure_hierarchy = {
					tier = tier_county
					holder = {
						OR = {
							this = scope:defender
							target_is_liege_or_above = scope:defender
						}
					}
				}
			}
		}
	}

	on_invalidated_desc = msg_duchy_conquest_war_invalidated_message
	on_invalidated = {}

	cost = {
		prestige = {
			add = {
				value = 50
				desc = CB_BASE_COST
			}
			add = {
				value = 2.5
				multiply = scope:attacker.realm_size
				desc = CB_REALM_SIZE_COST
				max = 150
			}
			multiply = common_cb_prestige_cost_multiplier
		}
	}

	on_declaration = {
		on_declared_war = yes

		# When this war is started, the Chinese emperor loses legitimacy
		scope:attacker = {
			top_liege = {
				add_legitimacy_effect = { LEGITIMACY = miniscule_legitimacy_loss }
			}
		}
	}

	on_victory_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:attacker = { is_local_player = yes } }
				desc = county_conquest_cb_victory_desc_attacker
			}
			desc = county_conquest_cb_victory_desc
		}
	}

	on_victory = {
		scope:attacker = { show_pow_release_message_effect = yes }

		# Legitimacy
		add_legitimacy_attacker_victory_effect = yes

		# Influence
		add_influence_attacker_victory_effect = yes

		# EP2 accolade glory gain for winning against higher ranked enemy
		scope:attacker = { accolade_attacker_war_end_glory_gain_low_effect = yes }

		create_title_and_vassal_change = {
			type = conquest
			save_scope_as = change
			add_claim_on_loss = yes
		}
		every_in_list = {
			list = target_titles
			# Grab the designated Duchy and it's vassals
			change_title_holder_include_vassals = {
				holder = scope:attacker
				change = scope:change
				take_baronies = no
			}
			every_de_jure_county = {
				limit = {
					holder = {
						OR = {
							this = scope:defender
							is_vassal_or_below_of = scope:defender
						}
					}
				}
				# Grab the Counties held directly by the Defender
				change_title_holder = {
					holder = scope:attacker
					change = scope:change
					take_baronies = no
				}
			}
		}
		resolve_title_and_vassal_change = scope:change

		# Prestige Progress for the Attacker
		every_in_list = {
			list = target_titles
			scope:attacker = {
				add_prestige_experience = minor_prestige_value
			}
		}

		# Allies on both sides get full prestige value for helping in the war, based on their war participation.
		modify_allies_of_participants_fame_values = {
			WINNER = scope:attacker
			FAME_BASE = minor_prestige_value
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}

		# Truce
		add_truce_attacker_victory_effect = yes

		# FP1: note the victory for future memorialisation via stele (if applicable).
		scope:attacker = { fp1_remember_recent_conquest_victory_effect = yes }

		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
		laamp_as_mercenary_payout_tooltip_effect = yes
	}

	on_white_peace_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = county_conquest_cb_white_peace_desc_defender
			}
			desc = county_conquest_cb_white_peace_desc
		}
	}

	on_white_peace = {
		scope:attacker = { show_pow_release_message_effect = yes }
		# Prestige loss for the attacker
		scope:attacker = {
			add_prestige = {
				value = minor_prestige_value
				multiply = -1.0
			}
			stress_impact = {
 				ambitious = medium_stress_impact_gain
 				arrogant = medium_stress_impact_gain
 			}
		}

		# Allies on both sides get full prestige value for helping in the war, based on their war participation.
		modify_allies_of_participants_fame_values = {
			WINNER = scope:attacker # Not important as the scales are identical
			FAME_BASE = minor_prestige_value
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}

		scope:defender = {
			stress_impact = {
 				arrogant = medium_stress_impact_gain
 			}
		}

		add_truce_white_peace_effect = yes

		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
		laamp_as_mercenary_payout_tooltip_effect = yes
	}

	on_defeat_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = county_conquest_cb_defeat_desc_defender
			}
			triggered_desc = {
				trigger = {
					scope:attacker = {
						is_local_player = yes
						has_targeting_faction = yes
					}
				}
				desc = county_conquest_cb_defeat_desc_attacker
			}
			desc = county_conquest_cb_defeat_desc
		}
	}

	on_defeat = {
		scope:attacker = { show_pow_release_message_effect = yes }

		# Legitimacy
		add_legitimacy_attacker_defeat_effect = yes

		# Influence
		add_influence_attacker_defeat_effect = yes

		scope:defender = { 
			mandala_peacemaker_perk_serenity_effect = yes
			#EP2 accolade glory gain for winning against higher ranked enemy
			accolade_defender_war_end_glory_gain_high_effect = yes
			# Prestige for Defender
			add_prestige_war_defender_effect = {
				PRESTIGE_VALUE = medium_prestige_value
			}
		}

		# Prestige loss for the attacker
		scope:attacker = {
			pay_short_term_gold_reparations_effect = {
				GOLD_VALUE = 2
			}
			add_prestige = medium_prestige_loss
		}

		# Allies on both sides get full prestige value for helping in the war, based on their war participation.
		modify_allies_of_participants_fame_values = {
			WINNER = scope:defender
			FAME_BASE = minor_prestige_value
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}

		add_truce_attacker_defeat_effect = yes

		scope:attacker = {
			save_temporary_scope_as = loser
		}
		on_lost_aggression_war_discontent_loss = yes

		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
		laamp_as_mercenary_payout_tooltip_effect = yes
	}

	transfer_behavior = transfer

	on_primary_attacker_death = inherit
	on_primary_defender_death = inherit

	attacker_allies_inherit = yes
	defender_allies_inherit = yes

	war_name = "CHINA_SEIZE_DUCHY_WAR_NAME"
	war_name_base = "CHINA_SEIZE_DUCHY_WAR_NAME_BASE"
	cb_name = "CHINA_SEIZE_DUCHY_CB_NAME"

	interface_priority = 83

	use_de_jure_wargoal_only = yes

	attacker_wargoal_percentage = 0.8

	max_defender_score_from_occupation = 150
	max_attacker_score_from_occupation = 150
}

china_hegemon_seize_duchy_cb = {
	icon = duchy_conquest_cb
	group = celestial

	combine_into_one = yes
	should_show_war_goal_subview = yes
	mutually_exclusive_titles = { always = yes }

	allowed_for_character = {
		OR = {
			has_title = title:h_china
			has_title = title:e_minister_grand_marshal
		}
		situation:dynastic_cycle ?= {
			has_situation_top_phase_parameter = dynastic_cycle_hegemon_unlocks_external_casus_belli
		}
	}

	allowed_for_character_display_regardless = {
		tgp_dynastic_cycle_offensive_wars_ban_trigger = yes
	}

	allowed_against_character = {
		scope:defender = {
			NOR = {
				government_has_flag = government_is_landless_adventurer
				government_has_flag = government_is_herder
			}
		}
	}

	target_titles = all
	target_title_tier = duchy
	ignore_effect = change_title_holder

	attacker_score_from_occupation_scale = 150
	attacker_score_from_battles_scale = 150
	defender_score_from_battles_scale = 150

	ai_only_against_neighbors = yes

	ai_score_mult = {
		# As a feudal gov, do not attack owner of tribal holdings  if you have a tribal holding to convert already
		add = {
			every_in_list = {
				list = target_titles
				if = {
					limit = { feudal_clan_tribal_conquest_constraints = yes }
					add = -1000
				}
			}
		}
	}

	valid_to_start = {
		scope:target ?= {
			is_neighbor_to_realm = scope:attacker.top_liege
		}
	}

	should_invalidate = {
		NOT = {
			any_in_list = {
				list = target_titles
				any_in_de_jure_hierarchy = {
					tier = tier_county
					holder = {
						OR = {
							this = scope:defender
							target_is_liege_or_above = scope:defender
						}
					}
				}
			}
		}
	}

	on_invalidated_desc = msg_duchy_conquest_war_invalidated_message
	on_invalidated = {}

	cost = {
		prestige = {
			add = {
				value = 50
				desc = CB_BASE_COST
			}
			add = {
				value = 2.5
				multiply = scope:attacker.realm_size
				desc = CB_REALM_SIZE_COST
				max = 150
			}
			multiply = common_cb_prestige_cost_multiplier
		}
	}

	on_declaration = {
		on_declared_war = yes

		# When this war is started, the chinese emperor loses legitimacy
		scope:attacker = {
			top_liege = {
				add_legitimacy_effect = { LEGITIMACY = miniscule_legitimacy_loss }
			}
		}
	}

	on_victory_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:attacker = { is_local_player = yes } }
				desc = county_conquest_cb_victory_desc_attacker
			}
			desc = county_conquest_cb_victory_desc
		}
	}

	on_victory = {
		scope:attacker = { show_pow_release_message_effect = yes }

		# Legitimacy
		add_legitimacy_attacker_victory_effect = yes

		# Influence
		add_influence_attacker_victory_effect = yes

		# EP2 accolade glory gain for winning against higher ranked enemy
		scope:attacker = { accolade_attacker_war_end_glory_gain_low_effect = yes }

		create_title_and_vassal_change = {
			type = conquest
			save_scope_as = change
			add_claim_on_loss = yes
		}
		# Give land to the Hegemon
		if = {
			limit = {
				scope:attacker = {
					has_title = title:e_minister_grand_marshal
				}
			}
			every_in_list = {
				list = target_titles
				# Grab the designated Duchy and it's vassals
				change_title_holder_include_vassals = {
					holder = scope:attacker.top_liege
					change = scope:change
					take_baronies = no
				}
				every_de_jure_county = {
					limit = {
						holder = {
							OR = {
								this = scope:defender
								is_vassal_or_below_of = scope:defender
							}
						}
					}
					# Grab the Counties held directly by the Defender
					change_title_holder = {
						holder = scope:attacker.top_liege
						change = scope:change
						take_baronies = no
					}
				}
			}
		}
		else = {
			every_in_list = {
				list = target_titles
				change_title_holder_include_vassals = {
					holder = scope:attacker
					change = scope:change
					take_baronies = no
				}
				every_de_jure_county = {
					limit = {
						holder = scope:defender
					}
					change_title_holder = {
						holder = scope:attacker
						change = scope:change
						take_baronies = no
					}
				}
			}
		}
		resolve_title_and_vassal_change = scope:change

		# Prestige Progress for the Attacker
		every_in_list = {
			list = target_titles
			scope:attacker = {
				add_prestige_experience = minor_prestige_value
			}
		}

		# Allies on both sides get full prestige value for helping in the war, based on their war participation.
		modify_allies_of_participants_fame_values = {
			WINNER = scope:attacker
			FAME_BASE = minor_prestige_value
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}

		# Truce
		add_truce_attacker_victory_effect = yes

		# FP1: note the victory for future memorialisation via stele (if applicable).
		scope:attacker = { fp1_remember_recent_conquest_victory_effect = yes }

		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
		laamp_as_mercenary_payout_tooltip_effect = yes
	}

	on_white_peace_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = county_conquest_cb_white_peace_desc_defender
			}
			desc = county_conquest_cb_white_peace_desc
		}
	}

	on_white_peace = {
		scope:attacker = { show_pow_release_message_effect = yes }
		# Prestige loss for the attacker
		scope:attacker = {
			add_prestige = {
				value = minor_prestige_value
				multiply = -1.0
			}
			stress_impact = {
 				ambitious = medium_stress_impact_gain
 				arrogant = medium_stress_impact_gain
 			}
		}

		# Allies on both sides get full prestige value for helping in the war, based on their war participation.
		modify_allies_of_participants_fame_values = {
			WINNER = scope:attacker # Not important as the scales are identical
			FAME_BASE = minor_prestige_value
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}

		scope:defender = {
			stress_impact = {
 				arrogant = medium_stress_impact_gain
 			}
		}

		add_truce_white_peace_effect = yes

		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
		laamp_as_mercenary_payout_tooltip_effect = yes
	}

	on_defeat_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = county_conquest_cb_defeat_desc_defender
			}
			triggered_desc = {
				trigger = {
					scope:attacker = {
						is_local_player = yes
						has_targeting_faction = yes
					}
				}
				desc = county_conquest_cb_defeat_desc_attacker
			}
			desc = county_conquest_cb_defeat_desc
		}
	}

	on_defeat = {
		scope:attacker = { show_pow_release_message_effect = yes }

		# Legitimacy
		add_legitimacy_attacker_defeat_effect = yes

		# Influence
		add_influence_attacker_defeat_effect = yes

		scope:defender = { 
			mandala_peacemaker_perk_serenity_effect = yes
			#EP2 accolade glory gain for winning against higher ranked enemy
			accolade_defender_war_end_glory_gain_high_effect = yes
			# Prestige for Defender
			add_prestige_war_defender_effect = {
				PRESTIGE_VALUE = medium_prestige_value
			}
		}

		# Prestige loss for the attacker
		scope:attacker = {
			pay_short_term_gold_reparations_effect = {
				GOLD_VALUE = 2
			}
			add_prestige = medium_prestige_loss
		}

		# Allies on both sides get full prestige value for helping in the war, based on their war participation.
		modify_allies_of_participants_fame_values = {
			WINNER = scope:defender
			FAME_BASE = minor_prestige_value
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}

		add_truce_attacker_defeat_effect = yes

		scope:attacker = {
			save_temporary_scope_as = loser
		}
		on_lost_aggression_war_discontent_loss = yes

		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
		laamp_as_mercenary_payout_tooltip_effect = yes
	}

	transfer_behavior = transfer

	on_primary_attacker_death = inherit
	on_primary_defender_death = inherit

	attacker_allies_inherit = yes
	defender_allies_inherit = yes

	war_name = "CHINA_SEIZE_DUCHY_WAR_NAME"
	war_name_base = "CHINA_SEIZE_DUCHY_WAR_NAME_BASE"
	cb_name = "CHINA_SEIZE_DUCHY_CB_NAME"

	interface_priority = 83

	use_de_jure_wargoal_only = yes

	attacker_wargoal_percentage = 0.8

	max_defender_score_from_occupation = 150
	max_attacker_score_from_occupation = 150
}

# Allow other rulers to invade China and take the mandate away from them, only in instability phase
claim_the_mandate_cb = {
	icon = celestial
	group = celestial
	ai_only_against_neighbors = yes

	allowed_for_character = {
		is_independent_ruler = yes
		any_neighboring_top_liege_realm_owner = {
			has_title = title:h_china
		}
		NAND = {
			is_ai = yes
			any_owned_story = {
				story_type = story_mongol_invasion
			} 
		}
	}
	allowed_for_character_display_regardless = {
		custom_tooltip = {
			text = has_gok_story_tt
			NOT = {
				any_owned_story = {
					story_type = story_greatest_of_khans
				}
			}
		}
	}

	allowed_against_character = {
		has_title = title:h_china
	}

	allowed_against_character_display_regardless = {
		custom_tooltip = {
			text = dynastic_cycle_not_corruption_phase_desc
			situation:dynastic_cycle ?= {
				situation_current_phase = situation_dynastic_cycle_phase_instability
			}
		}
	}

	cost = {
		piety = {
			value = 0
			add = common_cb_impious_piety_cost
		}
		prestige = {
			add = {
				value = 2000
				desc = CB_BASE_COST
			}
			multiply = common_cb_prestige_cost_multiplier

			# Target's legitimacy level affects cost - Lower levels make it cheaper
			scope:defender = {
				if = {
					limit = { legitimacy_level < 5 }
					multiply = {
						value = {
							switch = {
								trigger = scope:defender.legitimacy_level
								4 = { value = 0.9 }
								3 = { value = 0.75 }
								2 = { value = 0.6 }
								1 = { value = 0.45 }
								0 = { value = 0.3 }
							}
						}
						desc = dynastic_cycle_hegemon_legitimacy_level_cost_desc
					}
				}
			}

			# LEGITIMACY AFFECTS COST
			multiply = {
				value = {
					value = 0
					scope:attacker = {
						if = {
							limit = { has_legitimacy_flag = reduced_claim_cb_cost }
							add = 0.5
						}
						else_if = {
							limit = { has_legitimacy_flag = very_reduced_claim_cb_cost }
							add = 0.25
						}
						else_if = {
							limit = { has_legitimacy_flag = extra_reduced_claim_cb_cost }
							add = 0.15
						}
						else = {
							add = 1
						}
					}
				}
				desc = legitimacy_high_modifier_tt
			}
			multiply = {
				value = {
					value = 0
					scope:attacker = {
						if = {
							limit = { has_legitimacy_flag = massively_increased_claim_cb_cost }
							add = 2.5
						}
						else_if = {
							limit = { has_legitimacy_flag = very_increased_claim_cb_cost }
							add = 2
						}
						else_if = {
							limit = { has_legitimacy_flag = increased_claim_cb_cost }
							add = 1.5
						}
						else = {
							add = 1
						}
					}
				}
				desc = legitimacy_low_modifier_tt
			}
		}
	}

	target_titles = none

	on_declaration = {
		on_declared_war = yes
	}

	should_invalidate = {
		scope:defender = {
			is_independent_ruler = no
		}
	}

	on_invalidated_desc = msg_subjugation_war_invalidated_message

	on_invalidated = {
	}

	on_victory_desc = {
		desc = {
			first_valid = {
				triggered_desc = {
					trigger = { scope:attacker = { is_local_player = yes } }
					desc = tribal_subjugation_cb_victory_desc_equal_tier_attacker
				}
				triggered_desc = {
					trigger = { scope:defender = { is_local_player = yes } }
					desc = tribal_subjugation_cb_victory_desc_equal_tier_defender
				}
				desc = tribal_subjugation_cb_victory_desc_equal_tier
			}
		}
	}

	on_victory = {
		# Dynastic cycle will shift through the on_title_gain on action
		scope:attacker = { show_pow_release_message_effect = yes }

		# Legitimacy
		add_legitimacy_attacker_victory_effect = yes

		# Influence
		add_influence_attacker_victory_effect = yes

		#EP2 Accolade glory gain from winning against higher ranked enemy
		scope:attacker = { accolade_attacker_war_end_glory_gain_med_effect = yes }

		scope:attacker = {
			tgp_claim_mandate_of_heaven_effect = yes
			# Hand over the direct holding of the former Hegemon
			create_title_and_vassal_change = {
				type = conquest
				save_scope_as = change_capital_and_direct_holdings
				add_claim_on_loss = yes
			}
			scope:defender = {
				every_held_title = {
					title_tier > barony
					limit = {
						is_noble_family_title = no
						is_landless_type_title = no
					}
					change_title_holder = {
						holder = scope:attacker
						change = scope:change_capital_and_direct_holdings
					}
				}
			}

			# Hand over the capital - Unless it's a player holding
			if = {
				limit = {
					# or your capital already inside h_china - that means you keep old capital.
					capital_county.hegemony != title:h_china
					title:h_china.title_capital_county.holder = {
						is_ai = yes
						this != scope:defender
					}
				}
				title:h_china.title_capital_county = {
					change_title_holder = {
						holder = scope:attacker
						change = scope:change_capital_and_direct_holdings
					}
				}
			}
			resolve_title_and_vassal_change = scope:change_capital_and_direct_holdings
		}

		# Prestige loss for the defender
		scope:defender = {
			add_prestige = {
				value = major_prestige_value
				multiply = -1.0
			}
		}

		# Allies on both sides get full prestige value for helping in the war, based on their war participation.
		modify_allies_of_participants_fame_values = {
			WINNER = scope:attacker
			FAME_BASE = major_prestige_value
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}

		# truce
		add_truce_attacker_victory_effect = yes

		# FP1: note the victory for future memorialisation via stele (if applicable).
		scope:attacker = { fp1_remember_recent_conquest_victory_effect = yes }

		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
		laamp_as_mercenary_payout_tooltip_effect = yes
	}

	on_white_peace_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = tribal_subjugation_cb_white_peace_desc_defender
			}
			desc = tribal_subjugation_cb_white_peace_desc
		}
	}

	on_white_peace = {
		scope:attacker = { show_pow_release_message_effect = yes }

		#EP2 accolade glory gain for doing ok against higher ranked enemy
		scope:attacker = { accolade_attacker_war_end_glory_gain_low_effect = yes }
		scope:defender = { accolade_defender_war_end_glory_gain_med_effect = yes }

		# Prestige loss for the attacker
		scope:attacker = {
			add_prestige = {
				value = medium_prestige_value
				multiply = -1.0
			}
			stress_impact = {
				ambitious = medium_stress_impact_gain
				arrogant = medium_stress_impact_gain
			}
		}

		# Allies on both sides get full prestige value for helping in the war, based on their war participation.
		modify_allies_of_participants_fame_values = {
			WINNER = scope:attacker # Not important as the scales are identical
			FAME_BASE = medium_prestige_value
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}

		scope:defender = {
			stress_impact = {
				arrogant = medium_stress_impact_gain
			}
		}

		add_truce_white_peace_effect = yes

		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
		laamp_as_mercenary_payout_tooltip_effect = yes
	}

	on_defeat_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = tribal_subjugation_cb_white_peace_desc_defender
			}
			triggered_desc = {
				trigger = {
					scope:attacker = {
						is_local_player = yes
						has_targeting_faction = yes
					}
				}
				desc = tribal_subjugation_cb_defeat_desc_attacker
			}
			desc = tribal_subjugation_cb_white_peace_desc
		}
	}

	on_defeat = {
		scope:attacker = { show_pow_release_message_effect = yes }

		# Legitimacy
		add_legitimacy_attacker_defeat_effect = yes

		scope:defender = { 
			mandala_peacemaker_perk_serenity_effect = yes
			#EP2 accolade glory gain for winning against higher ranked enemy
			accolade_defender_war_end_glory_gain_high_effect = yes
			# Prestige for Defender
			add_prestige_war_defender_effect = {
				PRESTIGE_VALUE = medium_prestige_value
			}
		}

		# Prestige and gold loss for the attacker
		scope:attacker = {
			pay_short_term_gold_reparations_effect = {
				GOLD_VALUE = 3
			}
			add_prestige = {
				value = major_prestige_value
				multiply = -1.0
			}
		}

		# Allies on both sides get full prestige value for helping in the war, based on their war participation.
		modify_allies_of_participants_fame_values = {
			WINNER = scope:defender
			FAME_BASE = major_prestige_value
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}

		scope:attacker = {
			save_temporary_scope_as = loser
		}

		# Truce
		add_truce_attacker_defeat_effect = yes

		on_lost_aggression_war_discontent_loss = yes

		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
		laamp_as_mercenary_payout_tooltip_effect = yes
	}

	on_primary_attacker_death = inherit
	on_primary_defender_death = inherit

	transfer_behavior = transfer

	attacker_allies_inherit = yes
	defender_allies_inherit = yes

	war_name = "CLAIM_THE_MANDATE_NAME"
	war_name_base = "CLAIM_THE_MANDATE_NAME_BASE"
	cb_name = "CLAIM_THE_MANDATE_CB_NAME"
	interface_priority = 100

	ticking_war_score_targets_entire_realm = yes
	attacker_wargoal_percentage = 0.8

	max_defender_score_from_occupation = 150
	max_attacker_score_from_occupation = 150

	max_ai_diplo_distance_to_title = 500

	ai_score_mult = {
	}
}

chinese_consolidation_cb = {
	icon = celestial
	group = celestial

	combine_into_one = yes
	should_show_war_goal_subview = no

	allowed_for_character = {
		situation:dynastic_cycle ?= {
			situation_current_phase = situation_dynastic_cycle_phase_chaos
		}
		NAND = {
			is_ai = yes
			any_owned_story = {
				story_type = story_mongol_invasion
			}
		}
		trigger_if = { # Pace foreign invasions into Chaos-era China a bit
			limit = {
				is_ai = yes
				NOR = {
					exists = top_participant_group:dynastic_cycle
					any_owned_story = {
						story_type = story_take_mandate_of_heaven
					}
				}
			}
			OR = {
				has_variable = conqueror
				culture = { has_cultural_pillar = heritage_chinese }
				AND = {
					OR = {
						government_has_flag = government_is_nomadic
						government_has_flag = government_is_steppe_admin
					}
					static_group_filter = {
						group = wants_to_conquer_china
						match = 0.3
					}
				}
				AND = {
					static_group_filter = {
						group = wants_to_conquer_china
						match = 0.05
					}
					ai_has_warlike_personality = yes
				}
			}
		}
		any_character_to_title_neighboring_and_across_water_empire = {
			hegemony ?= title:h_china
		}
	}
	allowed_for_character_display_regardless = {
		tgp_dynastic_cycle_offensive_wars_ban_trigger = yes
		custom_tooltip = {
			text = has_gok_story_tt
			NOT = {
				any_owned_story = {
					story_type = story_greatest_of_khans
				}
			}
		}
	}
	allowed_against_character = {
		#Must be within Dynastic Cycle
		exists = top_participant_group:dynastic_cycle
	}

	target_titles = neighbor_land_or_water
	target_de_jure_regions_above = yes
	ignore_effect = change_title_holder
	ai_only_against_neighbors = yes

	ai_score_mult = {
		value = chinese_consolidation_ai_score_value #basic values
		add = 1
		if = {
			limit = {
				scope:attacker.primary_title.tier >= tier_kingdom
			}
			multiply = 2
		}
		if = {
			limit = {
				scope:defender = {
					primary_title = title:h_china
				}
			}
			multiply = 3
		}
	}

	should_invalidate = {
		NOT = {
			any_in_list = {
				list = target_titles
				any_in_de_jure_hierarchy = {
					tier = tier_county
					holder = {
						OR = {
							this = scope:defender
							target_is_liege_or_above = scope:defender
						}
					}
				}
			}
		}
	}

	on_invalidated_desc = msg_religious_war_invalidation_region_message

	cost = {
		piety = {
			add = common_cb_impious_piety_cost
			if = {
				limit = {
					scope:defender.faith = scope:attacker.faith
				}
				add = {
					value = 100
					desc = CB_SAME_FAITH_COST
				}
				add = {
					value = 10
					multiply = scope:attacker.realm_size
					desc = CB_REALM_SIZE_COST
					max = 800
				}
			}
			multiply = common_cb_piety_cost_multiplier
		}
		prestige = {
			value = 0
			if = {
				limit = {
					NOT = { scope:defender.faith = scope:attacker.faith }
				}
				add = {
					value = 150
					desc = CB_COST_DIFFERENT_FAITH
				}
				add = {
					value = 10
					multiply = scope:attacker.realm_size
					desc = CB_REALM_SIZE_COST
					max = 800
				}
			}
			multiply = common_cb_prestige_cost_multiplier
		}
	}

	on_declaration = {
		on_declared_war = yes
	}

	on_victory_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:attacker = { is_local_player = yes } }
				desc = chinese_consolidation_cb_victory_desc_attacker
			}
			desc = chinese_consolidation_cb_victory_desc
		}
	}

	on_victory = {
		scope:attacker = { show_pow_release_message_effect = yes }

		# Legitimacy
		add_legitimacy_attacker_victory_effect = yes

		#EP2 accolade glory gain for winning against higher ranked enemy
		scope:attacker = { accolade_attacker_war_end_glory_gain_med_effect = yes }

		create_title_and_vassal_change = {
			type = conquest
			save_scope_as = change
			add_claim_on_loss = yes
		}

		# vassalize or take titles and vassals
		scope:defender = {
			# take the relevant titles of same tier or higher and vassalize the rest
			every_held_title = {
				limit = {
					hegemony = title:h_china
				}
				add_to_list = titles_taken
			}
			every_vassal = {
				limit = {
					primary_title.hegemony = title:h_china
				}
				if = {
					limit = {
						highest_held_title_tier >= scope:attacker.highest_held_title_tier
					}
					add_to_list = titles_taken
				}
				else = {
					add_to_list = vassals_taken
				}
			}
			every_vassal_or_below = {
				limit = {
					primary_title.hegemony = title:h_china
						liege = {
							NOT = {
								is_in_list = vassals_taken
							}
						}
				}
				if = {
					limit = {
						highest_held_title_tier >= scope:attacker.highest_held_title_tier
					}
					add_to_list = titles_taken
				}
				else = {
					add_to_list = vassals_taken
				}
			}
		}
		every_in_list = {
			list = titles_taken
			change_title_holder_include_vassals = {
				holder = scope:attacker
				change = scope:change
				take_baronies = no
			}
		}
		every_in_list = {
			list = vassals_taken
			change_liege = {
				liege = scope:attacker
				change = scope:change
			}
		}

		resolve_title_and_vassal_change = scope:change
		# if the attacker didn't want to unify China, make them want it
		scope:attacker = {
			if = {
				limit = {
					NOT = {
						any_owned_story = {
							story_type = story_take_mandate_of_heaven
						}
					}
					is_ai = yes
				}
				create_story = story_take_mandate_of_heaven
			}
		}
		# Prestige Progress for the Attacker
		every_in_list = {
			list = target_titles
			scope:attacker = {
				add_prestige_experience = medium_prestige_value
			}
		}

		# Allies on both sides get full prestige value for helping in the war, based on their war participation.
		modify_allies_of_participants_fame_values = {
			WINNER = scope:attacker
			FAME_BASE = medium_prestige_value
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}

		# Truce
		add_truce_attacker_victory_effect = yes

		# FP1: note the victory for future memorialisation via stele (if applicable).
		scope:attacker = { fp1_remember_recent_conquest_victory_effect = yes }

		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
		laamp_as_mercenary_payout_tooltip_effect = yes
	}

	on_white_peace_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = de_jure_cb_white_peace_desc_defender
			}
			desc = de_jure_cb_white_peace_desc
		}
	}

	on_white_peace = {
		scope:attacker = { show_pow_release_message_effect = yes }
		# Prestige loss for the attacker

		#EP2 accolade glory gain for doing pretty good against higher ranked enemy
		scope:defender = { accolade_defender_war_end_glory_gain_low_effect = yes }

		scope:attacker = {
			add_prestige = {
				value = minor_prestige_value
				multiply = -1.0
			}
		}

		# Allies on both sides get full prestige value for helping in the war, based on their war participation.
		modify_allies_of_participants_fame_values = {
			WINNER = scope:attacker # not impactful as the scale are identical
			FAME_BASE = medium_prestige_value
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}


		add_truce_white_peace_effect = yes

		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
		laamp_as_mercenary_payout_tooltip_effect = yes
	}

	on_defeat_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = de_jure_cb_white_peace_desc_defender
			}
			desc = de_jure_cb_white_peace_desc
		}
	}

	on_defeat = {
		scope:attacker = { show_pow_release_message_effect = yes }

		# Legitimacy
		add_legitimacy_attacker_defeat_effect = yes

		scope:defender = { 
			mandala_peacemaker_perk_serenity_effect = yes
			#EP2 accolade glory gain for winning against higher ranked enemy
			accolade_defender_war_end_glory_gain_high_effect = yes
			# Prestige for Defender
			add_prestige_war_defender_effect = {
				PRESTIGE_VALUE = medium_prestige_value
			}
		}

		# Prestige loss for the attacker
		scope:attacker = {
			pay_short_term_gold_reparations_effect = {
				GOLD_VALUE = 3
			}
			add_prestige = {
				value = major_prestige_value
				multiply = -1.0
			}
		}

		# Allies on both sides get full prestige value for helping in the war, based on their war participation.
		modify_allies_of_participants_fame_values = {
			WINNER = scope:defender
			FAME_BASE = medium_prestige_value
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}

		add_truce_attacker_defeat_effect = yes

		scope:attacker = {
			save_temporary_scope_as = loser
		}
		on_lost_aggression_war_discontent_loss = yes

		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
		laamp_as_mercenary_payout_tooltip_effect = yes
	}

	transfer_behavior = transfer

	on_primary_attacker_death = inherit
	on_primary_defender_death = inherit

	attacker_allies_inherit = yes
	defender_allies_inherit = yes

	war_name = "CHINESE_CONSOLIDATION_WAR_NAME"
	war_name_base = "CHINESE_CONSOLIDATION_WAR_NAME_BASE"
	cb_name = "CHINESE_CONSOLIDATION_CB_NAME"

	interface_priority = 120

	use_de_jure_wargoal_only = yes

	attacker_wargoal_percentage = 0.5
	defender_ticking_warscore = 0.05
	attacker_ticking_warscore = 0.05
	defender_ticking_warscore_delay = { months = 24 }

	attacker_score_from_occupation_scale = 150
	attacker_score_from_battles_scale = 150
	defender_score_from_battles_scale = 150
	
	max_defender_score_from_battles = 100
	max_attacker_score_from_battles = 100

	max_defender_score_from_occupation = 150
	max_attacker_score_from_occupation = 150
}

chinese_reunification_cb = {
	icon = celestial
	group = celestial

	combine_into_one = yes
	should_show_war_goal_subview = yes
	mutually_exclusive_titles = { always = yes }

	allowed_for_character = {
		situation:dynastic_cycle ?= {
			NOT = { situation_current_phase = situation_dynastic_cycle_phase_chaos }
		}
		top_participant_group:dynastic_cycle ?= {
			participant_group_type = hegemon_ruler
		}
	}
	allowed_against_character = {
		exists = top_participant_group:dynastic_cycle
	}

	target_title_tier = kingdom
	target_titles = neighbor_land_or_water
	target_de_jure_regions_above = yes
	ignore_effect = change_title_holder
	ai_only_against_neighbors = yes

	ai_score_mult = {
		value = chinese_consolidation_ai_score_value #basic values
		add = 1
		if = {
			limit = {
				scope:attacker.primary_title.tier >= tier_kingdom
			}
			multiply = 2
		}
		if = {
			limit = {
				scope:defender = {
					primary_title = title:h_china
				}
			}
			multiply = 3
		}
	}

	valid_to_start = {
		scope:target.hegemony ?= title:h_china
		scope:target = {
			# can only target those encircled in China, not for border.
			any_title_to_title_neighboring_and_across_water_kingdom = {
				percent >= 0.6
				hegemony ?= title:h_china
			}
		}
	}

	should_invalidate = {
		OR = {
			scope:attacker = {
				top_participant_group:dynastic_cycle ?= {
					NOT = {
						participant_group_type = hegemon_ruler
					}
				}
			}
			NOT = {
				any_in_list = {
					list = target_titles
					any_in_de_jure_hierarchy = {
						tier = tier_county
						holder = {
							OR = {
								this = scope:defender
								target_is_liege_or_above = scope:defender
							}
						}
					}
				}
			}
		}
	}

	on_invalidated_desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:attacker = {
						top_participant_group:dynastic_cycle ?= {
							NOT = {
								participant_group_type = hegemon_ruler
							}
						}
					}
				}
				desc = msg_celestial_war_invalidation_no_longer_son_of_heaven
			}
			desc = msg_religious_war_invalidation_region_message
		}
	}

	cost = {
		piety = {
			add = common_cb_impious_piety_cost
			if = {
				limit = {
					scope:defender.faith = scope:attacker.faith
				}
				add = {
					value = 100
					desc = CB_SAME_FAITH_COST
				}
				add = {
					value = 10
					multiply = scope:attacker.realm_size
					desc = CB_REALM_SIZE_COST
					max = 800
				}
			}
			multiply = common_cb_piety_cost_multiplier
		}
		prestige = {
			value = 0
			if = {
				limit = {
					NOT = { scope:defender.faith = scope:attacker.faith }
				}
				add = {
					value = 150
					desc = CB_COST_DIFFERENT_FAITH
				}
				add = {
					value = 10
					multiply = scope:attacker.realm_size
					desc = CB_REALM_SIZE_COST
					max = 800
				}
			}
			multiply = common_cb_prestige_cost_multiplier
		}
	}

	on_declaration = {
		on_declared_war = yes
	}

	on_victory_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:attacker = { is_local_player = yes } }
				desc = invasion_war_victory_desc_attacker
			}
			desc = invasion_war_victory_desc
		}
	}
	
	on_victory = {
		scope:attacker = { show_pow_release_message_effect = yes }
		
		# Legitimacy
		add_legitimacy_attacker_victory_effect = yes

		# Influence
		add_influence_attacker_victory_effect = yes

		#EP2 accolade glory gain for winning against higher ranked enemy
		scope:attacker = { accolade_attacker_war_end_glory_gain_high_effect = yes }

		create_title_and_vassal_change = {
			type = conquest
			save_scope_as = change
			add_claim_on_loss = yes
		}

		show_as_tooltip = {
			every_in_list = {
				list = target_titles
				custom_tooltip = invasion_title_transfer_tt
				custom_tooltip = invasion_title_transfer_2_tt
				every_in_de_jure_hierarchy = {
					limit = { holder.top_liege = scope:defender }
					change_title_holder = {
						holder = scope:attacker
						change = scope:change
					}
				}
			}
			scope:defender = {
				every_sub_realm_county = {
					limit = {
						county_controller = scope:attacker
					}
					change_title_holder = {
						holder = scope:attacker
						change = scope:change
					}
				}
			}
		}
		
		hidden_effect = {
			setup_invasion_cb = {
				titles = target_titles
				attacker = scope:attacker
				defender = scope:defender
				change = scope:change
				take_occupied = yes
			}
			resolve_title_and_vassal_change = scope:change
		}

		# Attacker gets Prestige Experience, Defender loses Prestige, all other participants gain Prestige based on their war contribution.
		modify_all_participants_fame_values = {
			WINNER = scope:attacker
			LOSER = scope:defender
			FAME_BASE = scope:cb_prestige_factor # Set by 'setup_invasion_cb'
			IS_RELIGIOUS_WAR = no
			WINNER_FAME_SCALE = 10
			LOSER_FAME_SCALE = -10
			WINNER_ALLY_FAME_SCALE = 10
			LOSER_ALLY_FAME_SCALE = 10
		}

		# Truce
		add_truce_attacker_victory_effect = yes

		# FP1: note the victory for future memorialisation via stele (if applicable).
		scope:attacker = { fp1_remember_recent_conquest_victory_effect = yes }

		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
		laamp_as_mercenary_payout_tooltip_effect = yes

		#Mandalas gain or lose piety/devotion depending on Decree
		mandala_war_victory_effects = yes
	}

	on_white_peace_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = de_jure_cb_white_peace_desc_defender
			}
			desc = de_jure_cb_white_peace_desc
		}
	}

	on_white_peace = {
		scope:attacker = { show_pow_release_message_effect = yes }
		# Prestige loss for the attacker

		#EP2 accolade glory gain for doing pretty good against higher ranked enemy
		scope:defender = { accolade_defender_war_end_glory_gain_low_effect = yes }

		scope:attacker = {
			add_prestige = {
				value = minor_prestige_value
				multiply = -1.0
			}
		}

		# Allies on both sides get full prestige value for helping in the war, based on their war participation.
		modify_allies_of_participants_fame_values = {
			WINNER = scope:attacker # not impactful as the scale are identical
			FAME_BASE = medium_prestige_value
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}


		add_truce_white_peace_effect = yes

		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
		laamp_as_mercenary_payout_tooltip_effect = yes
	}

	on_defeat_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = de_jure_cb_white_peace_desc_defender
			}
			desc = de_jure_cb_white_peace_desc
		}
	}

	on_defeat = {
		scope:attacker = { show_pow_release_message_effect = yes }

		# Legitimacy
		add_legitimacy_attacker_defeat_effect = yes

		scope:defender = { 
			mandala_peacemaker_perk_serenity_effect = yes
			#EP2 accolade glory gain for winning against higher ranked enemy
			accolade_defender_war_end_glory_gain_high_effect = yes
			# Prestige for Defender
			add_prestige_war_defender_effect = {
				PRESTIGE_VALUE = medium_prestige_value
			}
		}

		# Prestige loss for the attacker
		scope:attacker = {
			pay_short_term_gold_reparations_effect = {
				GOLD_VALUE = 3
			}
			add_prestige = {
				value = major_prestige_value
				multiply = -1.0
			}
		}

		# Allies on both sides get full prestige value for helping in the war, based on their war participation.
		modify_allies_of_participants_fame_values = {
			WINNER = scope:defender
			FAME_BASE = medium_prestige_value
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}

		add_truce_attacker_defeat_effect = yes

		scope:attacker = {
			save_temporary_scope_as = loser
		}
		on_lost_aggression_war_discontent_loss = yes

		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
		laamp_as_mercenary_payout_tooltip_effect = yes
	}

	transfer_behavior = transfer

	on_primary_attacker_death = inherit
	on_primary_defender_death = inherit

	attacker_allies_inherit = yes
	defender_allies_inherit = yes

	war_name = "CHINESE_CONSOLIDATION_WAR_NAME"
	war_name_base = "CHINESE_CONSOLIDATION_WAR_NAME_BASE"
	cb_name = "CHINESE_CONSOLIDATION_CB_NAME"

	interface_priority = 120

	use_de_jure_wargoal_only = yes

	attacker_wargoal_percentage = 0.5
	defender_ticking_warscore = 0.05
	attacker_ticking_warscore = 0.05
	defender_ticking_warscore_delay = { months = 24 }

	attacker_score_from_occupation_scale = 150
	attacker_score_from_battles_scale = 150
	defender_score_from_battles_scale = 150
	
	max_defender_score_from_battles = 100
	max_attacker_score_from_battles = 100

	max_defender_score_from_occupation = 150
	max_attacker_score_from_occupation = 150
}

silk_road_vassalization_cb = {
	icon = vassalization
	group = vassalization
	ai_only_against_neighbors = yes

	attacker_score_from_occupation_scale = 150
	attacker_score_from_battles_scale = 150
	defender_score_from_battles_scale = 150

	allowed_for_character = {
		has_tgp_dlc_trigger = yes
		title:h_china.holder ?= root
		top_participant_group:dynastic_cycle ?= {
			has_participant_group_parameter = dynastic_cycle_hegemon_unlocks_external_casus_belli
		}
	}

	allowed_against_character_display_regardless = {
		tgp_japan_offensive_wars_ban_trigger = yes
	}

	allowed_against_character = {
		#Must be involved in the Silk Road
		scope:defender = {
			any_character_situation = {
				situation_type = silk_road_situation
			}
			NOR = {
				government_has_flag = government_is_landless_adventurer
				government_has_flag = government_is_herder
			}
		}
	}

	cost = {
		piety = {
			value = 0
			add = common_cb_impious_piety_cost
		}
		prestige = {
			value = 0
			add = {
				desc = CB_SIZE_OF_TARGET_REALM_COST
				scope:defender = {
					every_sub_realm_county = {
						add = {
							value = 125
						}
					}
				}
			}
			if = {
				limit = {
					scope:defender.primary_title = {
						tier = tier_kingdom
					}
				}
				multiply = {
					value = 2
					desc = CB_VASSALIZING_KING
				}
			}
			if = {
				limit = {
					scope:defender.primary_title = {
						tier = tier_empire
					}
				}
				multiply = {
					value = 4
					desc = CB_VASSALIZING_EMPEROR
				}
			}

			multiply = common_cb_prestige_cost_multiplier
		}
	}

	should_invalidate = {
		OR = {
			scope:defender = {
				is_independent_ruler = no
			}
			scope:defender.primary_title.tier >= scope:attacker.primary_title.tier
		}
	}

	on_declaration = {
		on_declared_war = yes
	}

	on_invalidated_desc = msg_vassalization_war_invalidated_message

	on_invalidated = {}

	on_victory_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:attacker = { is_local_player = yes } }
				desc = vassalization_cb_victory_desc_attacker
			}
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = vassalization_cb_victory_desc_defender
			}
			desc = vassalization_cb_victory_desc
		}
	}

	on_victory = {
		scope:attacker = { show_pow_release_message_effect = yes }

		create_title_and_vassal_change = {
			type = swear_fealty
			save_scope_as = change
			add_claim_on_loss = no
		}
		scope:defender = {
			change_liege = {
				liege = scope:attacker
				change = scope:change
			}
			resolve_title_and_vassal_change = scope:change
		}


		# Prestige level progress for the attacker
		scope:attacker = {
			add_prestige_experience = {
				value = medium_prestige_value
			}
		}

		# Prestige loss for the defender
		scope:defender = {
			add_prestige = {
				value = medium_prestige_value
				multiply = -1.0
			}
		}

		# Allies on both sides get full prestige value for helping in the war, based on their war participation.
		modify_allies_of_participants_fame_values = {
			WINNER = scope:attacker
			FAME_BASE = major_prestige_value
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}

		# Truce
		add_truce_attacker_victory_effect = yes

		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
		laamp_as_mercenary_payout_tooltip_effect = yes
	}

	on_white_peace_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = vassalization_cb_white_peace_desc_defender
			}
			desc = vassalization_cb_white_peace_desc
		}
	}

	on_white_peace = {
		scope:attacker = { show_pow_release_message_effect = yes }

		#EP2 accolade glory gain for doing ok against higher ranked enemy
		scope:defender = { accolade_defender_war_end_glory_gain_low_effect = yes }

		# Prestige loss for the attacker
		scope:attacker = {
			add_prestige = {
				value = minor_prestige_value
				multiply = -1.0
			}
			stress_impact = {
				ambitious = medium_stress_impact_gain
				arrogant = medium_stress_impact_gain
			}
		}

		# Allies on both sides get full prestige value for helping in the war, based on their war participation.
		modify_allies_of_participants_fame_values = {
			WINNER = scope:attacker # Not important as the scales are identical
			FAME_BASE = minor_prestige_value
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}

		scope:defender = {
			stress_impact = {
				arrogant = medium_stress_impact_gain
			}
		}

		# Truce
		add_truce_white_peace_effect = yes

		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
		laamp_as_mercenary_payout_tooltip_effect = yes
	}

	on_defeat_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = vassalization_cb_white_peace_desc_defender
			}
			triggered_desc = {
				trigger = {
					scope:attacker = {
						is_local_player = yes
						has_targeting_faction = yes
					}
				}
				desc = vassalization_cb_defeat_desc_attacker
			}
			desc = vassalization_cb_white_peace_desc
		}
	}

	on_defeat = {
		scope:attacker = { show_pow_release_message_effect = yes }

		scope:defender = { 
			mandala_peacemaker_perk_serenity_effect = yes
			#EP2 accolade glory gain for winning against higher ranked enemy
			accolade_defender_war_end_glory_gain_high_effect = yes
			# Prestige for Defender
			add_prestige_war_defender_effect = {
				PRESTIGE_VALUE = medium_prestige_value
			}
		}

		# Prestige loss for the attacker
		scope:attacker = {
			pay_short_term_gold_reparations_effect = {
				GOLD_VALUE = 3
			}
			add_prestige = {
				value = major_prestige_value
				multiply = -1.0
			}
		}

		# Allies on both sides get full prestige value for helping in the war, based on their war participation.
		modify_allies_of_participants_fame_values = {
			WINNER = scope:defender
			FAME_BASE = major_prestige_value
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}

		scope:attacker = {
			save_temporary_scope_as = loser
		}

		# Truce
		add_truce_attacker_defeat_effect = yes

		on_lost_aggression_war_discontent_loss = yes

		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
		laamp_as_mercenary_payout_tooltip_effect = yes
	}

	on_primary_attacker_death = inherit
	on_primary_defender_death = inherit

	attacker_allies_inherit = yes
	defender_allies_inherit = yes

	war_name = "SILK_ROAD_VASSALIZATION_WAR_NAME"
	war_name_base = "SILK_ROAD_VASSALIZATION_WAR_NAME_BASE"
	cb_name = "SILK_ROAD_VASSALIZATION_CB_NAME"
	interface_priority = 59

	ticking_war_score_targets_entire_realm = yes
	max_defender_score_from_occupation = 150
	max_attacker_score_from_occupation = 150
	attacker_ticking_warscore = 0
	attacker_wargoal_percentage = 0.8

	max_ai_diplo_distance_to_title = 500

	ai_score_mult = {
		value = 1
		# As a feudal gov never attack tribal for vassalization
		add = {
			if = {
				limit = {
					scope:attacker = {
						NOT = { government_has_flag = government_is_tribal }
					}
					scope:defender = {
						government_has_flag = government_is_tribal
					}
				}
				add = -1000
			}
		}
		# HOUSE RELATIONS
		add = house_relation_ai_score_value
		# Tell the Romans to stop going adventuring into the steppe for no gods-damned reason.
		multiply = byzantium_conquests_ai_score_value

		add = frankokratia_leader_protection_value #Set back to 0. Declaring war on the frankokratia leader can really ruin the whole thing

		# If the Silk Road is doing well, absolutely attack it
		if = {
			limit = {
				has_tgp_dlc_trigger = yes
				situation:silk_road_situation ?= {
					any_situation_sub_region = {
						sub_region_current_phase = phase_exceptional_bounty
						any_situation_sub_region_participant_group = { participant_group_has_character = scope:defender }
					}
				}
			}
			add = 100
		}
	}
}

# Kingdom tier cb used by the Grand Campaign Great Project
grand_campaign_kingdom_invasion_cb = {
	icon = duchy_conquest_cb
	group = celestial

	combine_into_one = yes
	should_show_war_goal_subview = yes
	mutually_exclusive_titles = { always = yes }
	allow_hostages = no

	allowed_for_character = {
		title:h_china.holder ?= {
			OR = {
				this = root.top_liege
				this = root
			}
		}
		any_great_project = {
			great_project_type = grand_campaign_project
			great_project_owner = root.top_liege
			OR = {
				any_contribution = {
					contributor = root
				}
				root = {
					has_title = title:e_minister_grand_marshal
				}
			}
		}
	}

	allowed_against_character = {
		any_great_project = {
			great_project_type = grand_campaign_project
			great_project_owner = title:h_china.holder
       		any_in_list = {
                variable = grand_campaign_titles
                holder ?= {
					OR = {
						this = scope:defender
						any_liege_or_above = {
							this = scope:defender
						}
					}
                	this != title:h_china.holder
                	top_overlord != title:h_china.holder
                }
            }
		}
	}
	valid_to_start = {
		any_great_project = {
			great_project_type = grand_campaign_project
			great_project_owner = root.top_liege
			var:grand_campaign_target_kingdom ?= scope:target
		}
	}

	target_titles = all
	ignore_effect = change_title_holder
	target_de_jure_regions_above = yes

	attacker_score_from_occupation_scale = 150
	attacker_score_from_battles_scale = 150
	defender_score_from_battles_scale = 150

	ai_only_against_neighbors = yes

	ai_score_mult = {
		# As a feudal gov, do not attack owner of tribal holdings  if you have a tribal holding to convert already
		add = {
			every_in_list = {
				list = target_titles
				if = {
					limit = { feudal_clan_tribal_conquest_constraints = yes }
					add = -1000
				}
			}
		}
		# Use this war if you are the Grand Marshal
		if = {
			limit = {
				has_title = title:e_minister_grand_marshal
			}
			add = 1000
		}
		add = {
			every_in_list = {
				list = target_titles
				if = {
					limit = { feudal_clan_tribal_conquest_constraints = yes }
					add = -1000
				}
			}
		}

		# AI in struggles act insularly for wars that don't have a familial or legal basis.
		multiply = struggle_wars_prioritise_struggle_targets_value
	}

	should_invalidate = {
		OR = {
			NOT = {
				any_in_list = {
					list = target_titles
					any_in_de_jure_hierarchy = {
						tier = tier_county
						holder = {
							OR = {
								this = scope:defender
								target_is_liege_or_above = scope:defender
							}
						}
					}
				}
			}
			#invalidate when China gets into Chaos
			NOT = { exists = title:h_china.holder }
		}
	}

	on_invalidated_desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					NOT = { exists = title:h_china.holder }
				}
				desc = msg_celestial_war_invalidation_chaos
			}
			desc = msg_religious_war_invalidation_region_message
		}
	}
	on_invalidated = {}

	cost = {
		prestige = {
			add = {
				value = 50
				desc = CB_BASE_COST
			}
			add = {
				value = 2.5
				multiply = scope:attacker.realm_size
				desc = CB_REALM_SIZE_COST
				max = 150
			}
			multiply = common_cb_prestige_cost_multiplier
		}
	}

	on_declaration = {
		on_declared_war = yes
		if = {
			limit = {
				NOT = {
					any_great_project = {
						great_project_type = grand_campaign_project
						great_project_owner = scope:attacker.top_liege
						exists = var:grand_campaign_war
					}
				}
			}
			scope:defender = {
				save_scope_as = title_holder
			}
			scope:war ?= {
				save_scope_as = grand_campaign_war
			}
			random_great_project = {
				limit = {
					great_project_type = grand_campaign_project
					great_project_owner = scope:attacker.top_liege
				}
				save_scope_as = great_project
				great_project_owner = {
					save_scope_as = owner
				}
				# only update if previous war ended
				if = {
					limit = {
						NOT = { exists = var:grand_campaign_war }
					}
					set_variable = {
						name = grand_campaign_war
						value = scope:grand_campaign_war
					}
				}
				random_in_list = {
					variable = grand_campaign_titles
					limit = {
						holder = {
							OR = {
								this = scope:defender
								target_is_liege_or_above = scope:defender
							}
							top_overlord != scope:attacker.top_overlord
						}
					}
					save_scope_as = target_title
				}
				scope:attacker = {
					save_scope_as = contributor
					trigger_event = tgp_china_ministry.0004
				}
			}
			scope:war ?= {
				set_variable = {
					name = grand_campaign_project
					value = scope:great_project
				}
			}
		}
	}

	on_victory_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:attacker = { is_local_player = yes } }
				desc = grand_campaign_kingdom_invasion_cb_victory_desc_attacker
			}
			desc = grand_campaign_kingdom_invasion_cb_victory_desc
		}
	}

	on_victory = {
		scope:attacker = { show_pow_release_message_effect = yes }

		# Legitimacy
		add_legitimacy_attacker_victory_effect = yes

		# Influence
		add_influence_attacker_victory_effect = yes

		# EP2 accolade glory gain for winning against higher ranked enemy
		scope:attacker = { accolade_attacker_war_end_glory_gain_low_effect = yes }

		if = {
			limit = {
				exists = war.var:grand_campaign_project
			}
			war.var:grand_campaign_project = {
				every_in_list = {
					variable = grand_campaign_titles
					add_to_list = target_titles
				}
				save_scope_as = great_project
				great_project_owner = {
					save_scope_as = hegemon
				}
			}
		}
		else = {
			random_great_project = {
				limit = {
					great_project_type = grand_campaign_project
					great_project_owner = scope:attacker.top_liege
				}
				every_in_list = {
					variable = grand_campaign_titles
					add_to_list = target_titles
				}
				save_scope_as = great_project
				great_project_owner = {
					save_scope_as = hegemon
				}				
			}
		}
		# Take the titles and hand them to the Hegemon
		create_title_and_vassal_change = {
			type = conquest
			save_scope_as = change
			add_claim_on_loss = yes
		}
		every_in_list = {
			list = target_titles
			every_in_de_jure_hierarchy = {
				continue = {
					tier <= tier_duchy
					tier >= tier_county
				}
				limit = {
					holder.top_overlord != scope:hegemon
					tier >= tier_county					
				}
                change_title_holder = {
			        holder = scope:hegemon
			        change = scope:change
			        take_baronies = no
				}
			}
		}
		resolve_title_and_vassal_change = scope:change

		if = {
			limit = {
				NOT = { exists = scope:cb_prestige_factor }
			}
			save_scope_value_as = {
				name = cb_prestige_factor
				value = {
					every_in_list = {
						list = target_titles
						add = 50
					}
				}
			}
		}

		# Attacker gets Prestige Experience, Defender loses Prestige, all other participants gain Prestige based on their war contribution.
		modify_all_participants_fame_values = {
			WINNER = scope:attacker
			LOSER = scope:defender
			FAME_BASE = scope:cb_prestige_factor # Set by 'setup_invasion_cb'
			IS_RELIGIOUS_WAR = no
			WINNER_FAME_SCALE = 10
			LOSER_FAME_SCALE = -10
			WINNER_ALLY_FAME_SCALE = 10
			LOSER_ALLY_FAME_SCALE = 10
		}
		# FP1: note the victory for future memorialisation via stele (if applicable).
		scope:attacker = { fp1_remember_recent_conquest_victory_effect = yes }

		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
		laamp_as_mercenary_payout_tooltip_effect = yes

		# Inform Hegemon about the outcome
		scope:hegemon = {
			trigger_event = tgp_china_ministry.0002
		}
		# There is no truce on purpose, you should be able to attack multiple times to succeed the project
	}

	on_white_peace_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = county_conquest_cb_white_peace_desc_defender
			}
			desc = county_conquest_cb_white_peace_desc
		}
	}

	on_white_peace = {
		scope:attacker = { show_pow_release_message_effect = yes }
		# Prestige loss for the attacker
		scope:attacker = {
			add_prestige = {
				value = minor_prestige_value
				multiply = -1.0
			}
			stress_impact = {
 				ambitious = medium_stress_impact_gain
 				arrogant = medium_stress_impact_gain
 			}
		}
		war.var:grand_campaign_project ?= {
			every_in_list = {
				variable = grand_campaign_titles
				add_to_list = target_titles
			}
			save_scope_as = great_project
			great_project_owner = {
				save_scope_as = hegemon
			}
		}

		# Allies on both sides get full prestige value for helping in the war, based on their war participation.
		modify_allies_of_participants_fame_values = {
			WINNER = scope:attacker # Not important as the scales are identical
			FAME_BASE = minor_prestige_value
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}

		scope:defender = {
			stress_impact = {
 				arrogant = medium_stress_impact_gain
 			}
		}
		# Inform Hegemon about the outcome
		scope:hegemon = {
			trigger_event = tgp_china_ministry.0003
		}

		#there is no truce on purpose, you should be able to attack multiple times to succeed the project

		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
		laamp_as_mercenary_payout_tooltip_effect = yes
	}

	on_defeat_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = county_conquest_cb_defeat_desc_defender
			}
			triggered_desc = {
				trigger = {
					scope:attacker = {
						is_local_player = yes
						has_targeting_faction = yes
					}
				}
				desc = county_conquest_cb_defeat_desc_attacker
			}
			desc = county_conquest_cb_defeat_desc
		}
	}

	on_defeat = {
		scope:attacker = { show_pow_release_message_effect = yes }

		# Legitimacy
		add_legitimacy_attacker_defeat_effect = yes

		# Influence
		add_influence_attacker_defeat_effect = yes

		scope:defender = { 
			mandala_peacemaker_perk_serenity_effect = yes
			#EP2 accolade glory gain for winning against higher ranked enemy
			accolade_defender_war_end_glory_gain_high_effect = yes
			# Prestige for Defender
			add_prestige_war_defender_effect = {
				PRESTIGE_VALUE = medium_prestige_value
			}
		}

		# Prestige loss for the attacker
		scope:attacker = {
			pay_short_term_gold_reparations_effect = {
				GOLD_VALUE = 2
			}
			add_prestige = medium_prestige_loss
		}

		war.var:grand_campaign_project ?= {
			every_in_list = {
				variable = grand_campaign_titles
				add_to_list = target_titles
			}
			save_scope_as = great_project
			great_project_owner = {
				save_scope_as = hegemon
			}
		}
		# Inform Hegemon about the outcome
		scope:hegemon = {
			trigger_event = tgp_china_ministry.0003
		}

		# Allies on both sides get full prestige value for helping in the war, based on their war participation.
		modify_allies_of_participants_fame_values = {
			WINNER = scope:defender
			FAME_BASE = minor_prestige_value
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}

		scope:attacker = {
			save_temporary_scope_as = loser
		}
		on_lost_aggression_war_discontent_loss = yes

		# EP3: note gold gained from military assistance/join war contracts and their war contribution threshold
		laamp_as_mercenary_payout_tooltip_effect = yes

		# There is no truce on purpose, you should be able to attack multiple times to succeed the project
	}

	transfer_behavior = transfer

	on_primary_attacker_death = inherit
	on_primary_defender_death = inherit

	attacker_allies_inherit = yes
	defender_allies_inherit = yes

	war_name = "GP_KINGDOM_INVASION_WAR_NAME"
	war_name_base = "GP_KINGDOM_INVASION_WAR_NAME_BASE"
	cb_name = "GP_KINGDOM_INVASION_CB_NAME"

	interface_priority = 83

	use_de_jure_wargoal_only = yes

	attacker_wargoal_percentage = 0.8

	max_defender_score_from_occupation = 150
	max_attacker_score_from_occupation = 150
}
