﻿
# War to install Bloc member -- Bloc Expansion
japan_install_bloc_member_cb = {
	icon = bloc
	group = subjugation
	combine_into_one = yes
	should_show_war_goal_subview = yes
	allow_hostages = no
	ai_only_against_neighbors = yes

	target_titles = all
	target_title_tier = county
	ignore_effect = change_title_holder

	# scope:attacker
	allowed_for_character = {
		has_tgp_dlc_trigger = yes
		is_landed = yes
		highest_held_title_tier >= tier_county
		tgp_soryo_or_bushido_trigger = yes # Soryo
		exists = house.house_confederation # In a Bloc
	}

	# scope:defender
	allowed_against_character = {
		is_landed = yes
		highest_held_title_tier >= tier_county
		top_liege = scope:attacker.top_liege # Same realm
		NOT = { this = scope:attacker.top_liege } # Not top liege
		government_is_japanese_trigger = yes # Soryo or Ritsuryo
		trigger_if = { # Not in same Bloc
			limit = { exists = house.house_confederation }
			house.house_confederation != scope:attacker.house.house_confederation
		}
	}

	valid_to_start = {
		scope:target ?= { is_landless_type_title = no }
	}
	
	mutually_exclusive_titles = { always = yes }

	cost = {
		prestige = {
			add = {
				value = 100
				desc = CB_BASE_COST
			}
			multiply = common_cb_prestige_cost_multiplier
		}
	}

	should_invalidate = {
		OR = {
			scope:attacker = { tgp_soryo_or_bushido_trigger = no }
			scope:defender.house.house_confederation ?= scope:attacker.house.house_confederation # Same bloc already
			NOT = { exists = scope:attacker.house.house_confederation } # Bloc destroyed
		}
	}

	on_invalidated_desc = {
		desc = japan_install_bloc_member_cb_ended_invalid.desc
	}

	on_declaration = {
		on_declared_war = yes
		if = {
			limit = { tgp_japan_internal_soryo_war_is_crime_trigger = yes }
			scope:attacker = {
				# Message for attacker
				send_interface_toast = {
					type = event_war_bad
					title = tgp_japan_soryo_war_is_crime_title
					left_icon = scope:defender
					right_icon = top_liege
					top_liege = {
						send_interface_toast = {
							type = event_war_bad
							title = tgp_japan_soryo_war_is_crime_kampaku_title
							left_icon = scope:attacker
							right_icon = scope:defender
							add_opinion = {
								target = scope:attacker
								modifier = admin_soryo_conquest_crime
							}
						}
					}
				}
			}
		}
	}

	on_victory_desc = {
		desc = {
			desc = japan_install_bloc_member_cb_victory_desc
			triggered_desc = {
				trigger = { tgp_japan_internal_soryo_war_is_crime_trigger = yes }
				desc = japan_soryo_conquest_cb_admin_warning
			}
		}
	}

	on_victory = {

		scope:attacker = { show_pow_release_message_effect = yes }

		scope:attacker.house.house_confederation = {
			leading_house.house_head = {
				if = {
					limit = {
						is_ai = yes
						NOT = { this = scope:attacker}
					}
					add_opinion = {
						target = scope:attacker
						modifier = respect_opinion
						opinion = 25
					}
				}
			}
		}
		
		# Legitimacy
		add_legitimacy_attacker_victory_effect = yes

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

		scope:attacker = {
			switch = {
				trigger = scope:defender.primary_title.tier
				tier_county = { add_prestige = minor_prestige_gain }
				tier_duchy = { add_prestige = medium_prestige_gain }
				tier_kingdom = { add_prestige = major_prestige_gain }
				tier_empire = { add_prestige = massive_prestige_gain }
				tier_hegemony = { add_prestige = monumental_prestige_gain }
			}
		}

		scope:defender = {
			switch = {
				trigger = primary_title.tier
				tier_county = { add_prestige = minor_prestige_loss }
				tier_duchy = { add_prestige = medium_prestige_loss }
				tier_kingdom = { add_prestige = major_prestige_loss }
				tier_empire = { add_prestige = massive_prestige_loss }
				tier_hegemony = { add_prestige = monumental_prestige_loss }
			}
		}

		scope:attacker = { 
			trigger_event = {
				id = tgp_japan_general.8800 
				days = 1 
			}
		}

		# EP3 Laamp possibility warning
		scope:defender = { ep3_war_loss_adventurer_tt_effect = yes }

		# 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 = 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 = {
		desc = {
			desc = japan_install_bloc_member_cb_white_peace_desc
			triggered_desc = {
				trigger = { tgp_japan_internal_soryo_war_is_crime_trigger = yes }
				desc = japan_soryo_conquest_cb_admin_warning
			}
		}
	}

	on_white_peace = {
		scope:attacker = { 
			show_pow_release_message_effect = yes
			stress_impact = {
				ambitious = medium_stress_impact_gain
				arrogant = medium_stress_impact_gain
			}
			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:attacker # not important as the scales are identical
			FAME_BASE = major_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_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_defeat_desc = {
		desc = {
			desc = japan_install_bloc_member_cb_defeat_desc
			triggered_desc = {
				trigger = { tgp_japan_internal_soryo_war_is_crime_trigger = yes }
				desc = japan_soryo_conquest_cb_admin_warning
			}
		}
	}

	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
		}

		scope:attacker = {
			switch = {
				trigger = primary_title.tier
				tier_county = { add_prestige = minor_prestige_loss }
				tier_duchy = { add_prestige = medium_prestige_loss }
				tier_kingdom = { add_prestige = major_prestige_loss }
				tier_empire = { add_prestige = massive_prestige_loss }
				tier_hegemony = { add_prestige = monumental_prestige_loss }
			}
		}

		scope:defender = {
			switch = {
				trigger = primary_title.tier
				tier_county = { add_prestige = minor_prestige_gain }
				tier_duchy = { add_prestige = medium_prestige_gain }
				tier_kingdom = { add_prestige = major_prestige_gain }
				tier_empire = { add_prestige = massive_prestige_gain }
				tier_hegemony = { add_prestige = monumental_prestige_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:defender
			FAME_BASE = major_prestige_value
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}

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

	on_primary_attacker_death = inherit
	on_primary_defender_death = inherit

	attacker_allies_inherit = yes
	defender_allies_inherit = yes

	war_name = "JAPAN_INSTALL_BLOC_MEMBER_WAR_NAME"
	war_name_base = "JAPAN_INSTALL_BLOC_MEMBER_WAR_NAME_BASE"
	cb_name = "JAPAN_INSTALL_BLOC_MEMBER_CB_NAME"
	interface_priority = 100

	ticking_war_score_targets_entire_realm = no
	attacker_ticking_warscore = 0.01
	attacker_wargoal_percentage = 0.01
	attacker_score_from_occupation_scale = 100
	defender_score_from_occupation_scale = 100
	attacker_score_from_battles_scale = 100
	defender_score_from_battles_scale = 100

	max_attacker_score_from_battles = 100
	max_defender_score_from_battles = 100
	
	max_defender_score_from_occupation = 100
	max_attacker_score_from_occupation = 100

	max_ai_diplo_distance_to_title = 500
	
	ai_score = {
		value = japan_install_bloc_member_ai_score_value
	}

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

# War for landless feudal to take land
japan_soryo_conquest_county_landless_cb = {
	icon = soryo
	group = conquest
	combine_into_one = yes
	should_show_war_goal_subview = yes
	ai_only_against_neighbors = no
	allow_hostages = no
	target_titles = all
	target_title_tier = county
	target_de_jure_regions_above = yes
	ignore_effect = change_title_holder

	mutually_exclusive_titles = {
		NOT = {
			trigger_if = {
				scope:attacker = {
						is_ai = no
				}
			}
		}
	}

	# scope:attacker
	allowed_for_character = {
		has_tgp_dlc_trigger = yes
		is_landed = no
		government_is_japanese_trigger = yes
		tgp_soryo_or_bushido_trigger = yes
	}

	# scope:defender
	allowed_against_character = {
		is_landed = yes
		highest_held_title_tier >= tier_county
		government_is_japanese_trigger = yes
		top_liege = {
			# Must be part of same realm
			this = scope:attacker.top_liege
			# But defender must not be liege
			NOT = { this = scope:attacker }
		}
	}

	cost = {
		prestige = {
			add = {
				value = 100
				desc = CB_BASE_COST
			}
			multiply = common_cb_prestige_cost_multiplier
		}
	}

	valid_to_start = {
		scope:target = {
			is_landless_type_title = no
			# Also make sure you can't war for, like, the Papal States
			trigger_if = {
				limit = { holder.faith ?= root.faith }
				NOT = {
					holder ?= { is_theocratic_lessee = yes }
				}
			}
		}
	}

	should_invalidate = {
		ep3_adventurer_landless_should_invalidate_trigger = yes
	}

	on_invalidated_desc = {
		desc = japan_soryo_conquest_cb_ended_invalid.desc
	}

	on_declaration = {
		on_declared_war = yes
		if = {
			limit = { tgp_japan_internal_soryo_war_is_crime_trigger = yes }
			scope:attacker = {
				# Message for attacker
				send_interface_toast = {
					type = event_war_bad
					title = tgp_japan_soryo_war_is_crime_title
					left_icon = scope:defender
					right_icon = top_liege
					top_liege = {
						send_interface_toast = {
							type = event_war_bad
							title = tgp_japan_soryo_war_is_crime_kampaku_title
							left_icon = scope:attacker
							right_icon = scope:defender
							add_opinion = {
								target = scope:attacker
								modifier = admin_soryo_conquest_crime
							}
						}
					}
				}
			}
		}
	}

	on_victory_desc = {
		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
			}
			triggered_desc = {
				trigger = { tgp_japan_internal_soryo_war_is_crime_trigger = yes }
				desc = japan_soryo_conquest_cb_admin_warning
			}
		}
	}

	on_victory = {
		scope:attacker = { show_pow_release_message_effect = yes }
		
		# Legitimacy
		add_legitimacy_attacker_victory_effect = yes

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

		scope:attacker = {
			switch = {
				trigger = scope:defender.primary_title.tier
				tier_county = { add_prestige = minor_prestige_gain }
				tier_duchy = { add_prestige = medium_prestige_gain }
				tier_kingdom = { add_prestige = major_prestige_gain }
				tier_empire = { add_prestige = massive_prestige_gain }
				tier_hegemony = { add_prestige = monumental_prestige_gain }
			}
		}

		scope:defender = {
			switch = {
				trigger = primary_title.tier
				tier_county = { add_prestige = minor_prestige_loss }
				tier_duchy = { add_prestige = medium_prestige_loss }
				tier_kingdom = { add_prestige = major_prestige_loss }
				tier_empire = { add_prestige = massive_prestige_loss }
				tier_hegemony = { add_prestige = monumental_prestige_loss }
			}
		}

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

		# EP3 Laamp possibility warning
		scope:defender = { ep3_war_loss_adventurer_tt_effect = yes }

		#As this is just a county conquest, simply 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 = 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 = {
		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
			}
			triggered_desc = {
				trigger = { tgp_japan_internal_soryo_war_is_crime_trigger = yes }
				desc = japan_soryo_conquest_cb_admin_warning
			}
		}
	}

	on_white_peace = {
		scope:attacker = { 
			show_pow_release_message_effect = yes
			stress_impact = {
				ambitious = medium_stress_impact_gain
				arrogant = medium_stress_impact_gain
			}
			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:attacker # not important as the scales are identical
			FAME_BASE = major_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_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_defeat_desc = {
		desc = {
			first_valid = {
				triggered_desc = {
					trigger = { scope:attacker = { is_local_player = yes } }
					desc = county_conquest_cb_defeat_desc_attacker
				}
				desc = county_conquest_cb_defeat_desc
			}
			triggered_desc = {
				trigger = { tgp_japan_internal_soryo_war_is_crime_trigger = yes }
				desc = japan_soryo_conquest_cb_admin_warning
			}
		}
	}

	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
		}

		scope:attacker = {
			switch = {
				trigger = primary_title.tier
				tier_county = { add_prestige = minor_prestige_loss }
				tier_duchy = { add_prestige = medium_prestige_loss }
				tier_kingdom = { add_prestige = major_prestige_loss }
				tier_empire = { add_prestige = massive_prestige_loss }
				tier_hegemony = { add_prestige = monumental_prestige_loss }
			}
		}

		scope:defender = {
			switch = {
				trigger = primary_title.tier
				tier_county = { add_prestige = minor_prestige_gain }
				tier_duchy = { add_prestige = medium_prestige_gain }
				tier_kingdom = { add_prestige = major_prestige_gain }
				tier_empire = { add_prestige = massive_prestige_gain }
				tier_hegemony = { add_prestige = monumental_prestige_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:defender
			FAME_BASE = major_prestige_value
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}

		# Truce
		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

	interface_priority = 79

	use_de_jure_wargoal_only = yes

	attacker_wargoal_percentage = 0.8
	
	max_attacker_score_from_battles = 75

	max_defender_score_from_occupation = 150
	max_attacker_score_from_occupation = 150

	war_name = "JAPAN_SORYO_CONQUEST_LANDLESS_WAR_NAME"
	war_name_base = "JAPAN_SORYO_CONQUEST_LANDLESS_WAR_NAME_BASE"
	cb_name = "JAPAN_SORYO_CONQUEST_LANDLESS_COUNTY_CB_NAME"

	ai_score_mult = {
		value = 1
		add = frankokratia_leader_protection_value #Set back to 0. Declaring war on the frankokratia leader can really ruin the whole thing
		if = {
			limit = {
				current_military_strength < 400
			}
			multiply = 0
		}
	}
}

# War for feudal to take land
japan_soryo_conquest_county_cb = {
	icon = soryo
	group = conquest
	combine_into_one = yes
	ai_only_against_neighbors = yes
	allow_hostages = yes
	should_show_war_goal_subview = yes

	target_titles = neighbor_land_or_water
	target_title_tier = county
	ignore_effect = change_title_holder
	
	mutually_exclusive_titles = {
		NOT = {
			trigger_if = {
				scope:attacker = {
						is_ai = no
				}
			}
		}
	}

	# scope:attacker
	allowed_for_character = {
		has_tgp_dlc_trigger = yes
		is_landed = yes
		# Attacker must be Japanese Feudal, or have the Bushido tradition
		tgp_soryo_or_bushido_trigger = yes
	}

	# scope:defender
	allowed_against_character = {
		top_liege ?= {
			# Must be part of same realm
			this = scope:attacker.top_liege
			# But defender must not be liege
			NOT = { this = scope:attacker }
		}
	}

	cost = {
		prestige = {
			add = {
				value = 100
				desc = CB_BASE_COST
			}
			multiply = common_cb_prestige_cost_multiplier
		}
	}

	should_invalidate = {
		OR = {
			NOT = {
				scope:attacker = { tgp_soryo_or_bushido_trigger = yes }
			}
			scope:defender = {
				top_liege != scope:attacker.top_liege
			}
		}
	}

	on_invalidated_desc = {
		desc = japan_soryo_conquest_cb_ended_invalid.desc
	}

	on_declaration = {
		on_declared_war = yes
		if = {
			limit = { tgp_japan_internal_soryo_war_is_crime_trigger = yes }
			scope:attacker = {
				# Message for attacker
				send_interface_toast = {
					type = event_war_bad
					title = tgp_japan_soryo_war_is_crime_title
					left_icon = scope:defender
					right_icon = top_liege
					top_liege = {
						send_interface_toast = {
							type = event_war_bad
							title = tgp_japan_soryo_war_is_crime_kampaku_title
							left_icon = scope:attacker
							right_icon = scope:defender
							add_opinion = {
								target = scope:attacker
								modifier = admin_soryo_conquest_crime
							}
						}
					}
				}
			}
		}
	}

	on_victory_desc = {
		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
			}
			triggered_desc = {
				trigger = { tgp_japan_internal_soryo_war_is_crime_trigger = yes }
				desc = japan_soryo_conquest_cb_admin_warning
			}
		}
	}

	on_victory = {
		scope:attacker = { show_pow_release_message_effect = yes }
		
		# Legitimacy
		add_legitimacy_attacker_victory_effect = yes

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

		scope:attacker = {
			switch = {
				trigger = scope:defender.primary_title.tier
				tier_county = { add_prestige = minor_prestige_gain }
				tier_duchy = { add_prestige = medium_prestige_gain }
				tier_kingdom = { add_prestige = major_prestige_gain }
				tier_empire = { add_prestige = massive_prestige_gain }
				tier_hegemony = { add_prestige = monumental_prestige_gain }
			}
		}

		scope:defender = {
			switch = {
				trigger = primary_title.tier
				tier_county = { add_prestige = minor_prestige_loss }
				tier_duchy = { add_prestige = medium_prestige_loss }
				tier_kingdom = { add_prestige = major_prestige_loss }
				tier_empire = { add_prestige = massive_prestige_loss }
				tier_hegemony = { add_prestige = monumental_prestige_loss }
			}
		}

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

		# EP3 Laamp possibility warning
		scope:defender = { ep3_war_loss_adventurer_tt_effect = yes }

		#As this is just a county conquest, simply 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 = 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 = {
		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
			}
			triggered_desc = {
				trigger = { tgp_japan_internal_soryo_war_is_crime_trigger = yes }
				desc = japan_soryo_conquest_cb_admin_warning
			}
		}
	}

	on_white_peace = {
		scope:attacker = { 
			show_pow_release_message_effect = yes
			stress_impact = {
				ambitious = medium_stress_impact_gain
				arrogant = medium_stress_impact_gain
			}
			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:attacker # not important as the scales are identical
			FAME_BASE = major_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_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_defeat_desc = {
		desc = {
			first_valid = {
				triggered_desc = {
					trigger = { scope:attacker = { is_local_player = yes } }
					desc = county_conquest_cb_defeat_desc_attacker
				}
				desc = county_conquest_cb_defeat_desc
			}
			triggered_desc = {
				trigger = { tgp_japan_internal_soryo_war_is_crime_trigger = yes }
				desc = japan_soryo_conquest_cb_admin_warning
			}
		}
	}

	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
		}

		scope:attacker = {
			switch = {
				trigger = primary_title.tier
				tier_county = { add_prestige = minor_prestige_loss }
				tier_duchy = { add_prestige = medium_prestige_loss }
				tier_kingdom = { add_prestige = major_prestige_loss }
				tier_empire = { add_prestige = massive_prestige_loss }
				tier_hegemony = { add_prestige = monumental_prestige_loss }
			}
		}

		scope:defender = {
			switch = {
				trigger = primary_title.tier
				tier_county = { add_prestige = minor_prestige_gain }
				tier_duchy = { add_prestige = medium_prestige_gain }
				tier_kingdom = { add_prestige = major_prestige_gain }
				tier_empire = { add_prestige = massive_prestige_gain }
				tier_hegemony = { add_prestige = monumental_prestige_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:defender
			FAME_BASE = major_prestige_value
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}

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

	on_primary_attacker_death = inherit
	on_primary_defender_death = inherit

	attacker_allies_inherit = yes
	defender_allies_inherit = yes

	war_name = "JAPAN_SORYO_CONQUEST_WAR_NAME"
	war_name_base = "JAPAN_SORYO_CONQUEST_WAR_NAME_BASE"
	cb_name = "JAPAN_SORYO_CONQUEST_COUNTY_CB_NAME"
	interface_priority = 80

	ticking_war_score_targets_entire_realm = yes
	attacker_ticking_warscore = 0.01
	attacker_wargoal_percentage = 0.01
	attacker_score_from_occupation_scale = 50
	defender_score_from_occupation_scale = 50
	attacker_score_from_battles_scale = 250
	defender_score_from_battles_scale = 250

	max_attacker_score_from_battles = 200
	max_defender_score_from_battles = 200
	
	max_defender_score_from_occupation = 50
	max_attacker_score_from_occupation = 50

	max_ai_diplo_distance_to_title = 500

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

# War to enforce return to Administrative
japan_demand_administrative_cb = {
	icon = ritsuryo
	group = subjugation
	allow_hostages = no
	ai_only_against_neighbors = yes
	should_show_war_goal_subview = yes

	# scope:attacker
	allowed_for_character = {
		government_has_flag = government_is_japan_administrative
		top_liege = { government_has_flag = government_is_japan_administrative } # Cannot enforce admin in a Soryo realm
		tgp_is_ceremonial_liege_trigger = no
	}

	# scope:defender
	allowed_against_character = {
		is_landed = yes
		government_has_flag = government_is_japan_feudal
		top_liege = scope:attacker.top_liege
		NOT = { is_liege_or_above_of = scope:attacker }
	}

	# root = scope:attacker, scope:defender, scope:target
	valid_to_start = {
	}

	cost = {
		prestige = {
			add = {
				value = 100
				desc = CB_BASE_COST
			}
			multiply = common_cb_prestige_cost_multiplier
		}
	}

	should_invalidate = {
		OR = {
			NOT = {
				scope:attacker = {
					government_has_flag = government_is_japan_administrative
					tgp_is_ceremonial_liege_trigger = no
				}
			}
			NOT = {
				scope:defender = {
					government_has_flag = government_is_japan_feudal
					top_liege = scope:attacker.top_liege
					NOT = { is_liege_or_above_of = scope:attacker }
				}
			}
			scope:defender = { is_landed = no }
		}
	}

	on_invalidated_desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					NOT = {
						scope:attacker = {
							government_has_flag = government_is_japan_administrative
							tgp_is_ceremonial_liege_trigger = no
						}
					}
				}
				desc = japan_demand_administrative_cb_ended_invalid.desc.attacker
			}
			desc = japan_demand_administrative_cb_ended_invalid.desc
		}
	}

	on_declaration = {
		on_declared_war = yes
	}

	on_victory_desc = {
		desc = {
			desc = japan_demand_administrative_cb_victory_desc
			triggered_desc = {
				trigger = {
					scope:attacker = { is_independent_ruler = no }
				}
				desc = japan_demand_administrative_cb_victory_vassal_desc
			}
		}
	}

	on_victory = {
		scope:attacker = { show_pow_release_message_effect = yes }
		
		# Legitimacy
		add_legitimacy_attacker_victory_effect = yes

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

		# Appreciation for re-integration
		scope:attacker = { 
			if = {
				limit = { is_independent_ruler = no }
				reverse_add_opinion = {
					target = scope:attacker.top_liege
					modifier = enforced_administrative_opinion
				}
			}
		}

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

		# EP3 Laamp possibility warning
		scope:defender = { ep3_war_loss_adventurer_tt_effect = yes }

		scope:defender = {
			every_held_title = {
				limit = {
					is_landless_type_title = no
					is_noble_family_title = no
					tier >= tier_county
				}
				# Return land to top liege
				change_title_holder = {
					holder = scope:attacker.top_liege
					change = scope:change
				}
			}
		}

		# Influence/Fame reward
		scope:attacker = {
			if = {
				limit = { is_independent_ruler = no }
				if = {
					limit = { government_allows = administrative }
					change_influence = japan_demand_administrative_war_influence_value
				}
				else = { add_prestige_experience = japan_demand_administrative_war_prestige_value }
			}
		}

		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 = 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 = {
		desc = japan_demand_administrative_cb_white_peace_desc
	}

	on_white_peace = {
		scope:attacker = { 
			show_pow_release_message_effect = yes
			stress_impact = {
				ambitious = medium_stress_impact_gain
				arrogant = medium_stress_impact_gain
			}
			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:attacker # not important as the scales are identical
			FAME_BASE = major_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_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_defeat_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:attacker = scope:defender.top_liege }
				desc = japan_demand_administrative_cb_defeat_desc_independence
			}
			desc = japan_demand_administrative_cb_defeat_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
		}

		# If Regent themselves failed to assert authority
		if = {
			limit = { scope:attacker = scope:defender.top_liege }
			scope:attacker = {
				add_prestige = major_prestige_loss
				switch = {
					trigger = has_realm_law
					japanese_bureaucracy_3 = { add_realm_law = japanese_bureaucracy_2 }
					japanese_bureaucracy_2 = { add_realm_law = japanese_bureaucracy_1 }
					japanese_bureaucracy_1 = { add_realm_law = japanese_bureaucracy_0 }
					fallback = { force_step_down_landed_titles = yes }
				}
			}
		}

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

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

	on_primary_attacker_death = inherit
	on_primary_defender_death = inherit

	attacker_allies_inherit = yes
	defender_allies_inherit = yes

	war_name = "JAPAN_DEMAND_ADMINISTRATIVE_WAR_NAME"
	war_name_base = "JAPAN_DEMAND_ADMINISTRATIVE_WAR_NAME_BASE"
	cb_name = "JAPAN_DEMAND_ADMINISTRATIVE_CB_NAME"
	interface_priority = 80

	ticking_war_score_targets_entire_realm = yes
	attacker_ticking_warscore = 0.01
	attacker_wargoal_percentage = 0.01
	attacker_score_from_occupation_scale = 50
	defender_score_from_occupation_scale = 50
	attacker_score_from_battles_scale = 250
	defender_score_from_battles_scale = 250

	max_attacker_score_from_battles = 200
	max_defender_score_from_battles = 200
	
	max_defender_score_from_occupation = 50
	max_attacker_score_from_occupation = 50

	max_ai_diplo_distance_to_title = 500
	
	ai_score = {
		value = japan_demand_administrative_ai_score_value
	}

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

# War to conquer Japan
japan_imperial_expansion_cb = {
	icon = ritsuryo_government
	group = conquest
	combine_into_one = yes
	ai_only_against_neighbors = yes
	allow_hostages = no
	should_show_war_goal_subview = yes

	target_titles = all
	target_title_tier = county
	ignore_effect = change_title_holder
	
	mutually_exclusive_titles = {
		NOT = {
			trigger_if = {
				scope:attacker = {
						is_ai = no
				}
			}
		}
	}

	cost = {
		prestige = {
			add = {
				value = 100
				desc = CB_BASE_COST
			}
			multiply = common_cb_prestige_cost_multiplier
		}
	}

	# root = scope:attacker
	allowed_for_character = {
		japan_imperial_expansion_cb_allowed_for_character_trigger = yes
	}

	# root = scope:attacker
	allowed_for_character_display_regardless = {
		# Required Policy
		top_liege = { has_realm_law = imperial_expansion_law }
	}

	# root = scope:defender, scope:attacker
	allowed_against_character = {
		japan_imperial_expansion_cb_allowed_against_character_trigger = yes
	}

	# root = scope:defender, scope:attacker
	allowed_against_character_display_regardless = {
		# Must be neighbours, but we want to show casus belli in list regardless
		custom_tooltip = {
			text = japan_imperial_expansion_cb_neighbour_tt
			any_sub_realm_county = {
				any_title_to_title_neighboring_and_across_water_county = { holder.top_liege = scope:attacker.top_liege }
			}
		}
	}

	# root = scope:attacker, scope:defender, scope:target
	valid_to_start_display_regardless = {
		custom_tooltip = {
			text = tgp_japan_pacification_war_valid_empire_tt
			NOT = { scope:target.empire ?= title:e_japan }
		}
		custom_tooltip = {
			text = tgp_japan_pacification_war_valid_region_tt
			scope:target.title_province ?= {
				OR = {
					geographical_region = world_asia_japan
					geographical_region = world_asia_sakhalin_hokkaido
				}
			}
		}
	}
	valid_to_start = {
		scope:target = {
			is_landless_type_title = no
		}
	}

	should_invalidate = {
		OR = {
			scope:attacker = { japan_imperial_expansion_cb_allowed_for_character_trigger = no }
			scope:defender = { japan_imperial_expansion_cb_allowed_against_character_trigger = no }
		}
	}

	on_invalidated_desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:attacker = { japan_imperial_expansion_cb_allowed_for_character_trigger = no }
				}
				desc = japan_imperial_expansion_cb_ended_invalid.desc.attacker
			}
			desc = japan_imperial_expansion_cb_ended_invalid.desc
		}
	}

	on_declaration = {
		on_declared_war = yes
	}

	on_victory_desc = {
		desc = {
			first_valid = {
				triggered_desc = {
					trigger = {
						scope:attacker = {
							is_local_player = yes
							is_independent_ruler = yes
						}
					}
					desc = japan_imperial_expansion_cb_victory_desc_attacker
				}
				desc = japan_imperial_expansion_cb_victory_desc
			}
			triggered_desc = {
				trigger = {
					scope:attacker = { is_independent_ruler = no }
				}
				desc = japan_demand_administrative_cb_victory_vassal_desc
			}
		}
	}

	on_victory = {
		scope:attacker = { show_pow_release_message_effect = yes }
		
		# Legitimacy
		add_legitimacy_attacker_victory_effect = yes

		#EP2 Accolade glory gain from 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
		}

		# EP3 Laamp possibility warning
		scope:defender = { ep3_war_loss_adventurer_tt_effect = yes }

		#As this is just a county conquest, simply grab the designated county.
		every_in_list = {
			list = target_titles
			change_title_holder = {
				holder = scope:attacker.top_liege # For the top liege
				change = scope:change
			}
		}

		resolve_title_and_vassal_change = scope:change

		# Appreciation for the Attacker, if relevant
		scope:attacker = { 
			if = {
				limit = { is_independent_ruler = no }
				reverse_add_opinion = {
					target = scope:attacker.top_liege
					modifier = enforced_pacification_opinion
				}
			}
		}

		# Influence/Prestige Progress for the Attacker
		scope:attacker = {
			if = {
				limit = { is_independent_ruler = no }
				if = {
					limit = { government_allows = administrative }
					change_influence = japan_imperial_expansion_war_influence_value
				}
				else = { add_prestige_experience = japan_imperial_expansion_war_prestige_value }
			}
			else = {
				# 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 }

		if = { # Warning that only counties are changing hands
			limit = {
				any_in_list = {
					list = target_titles
					tier = tier_duchy
				}
			}
			random_in_list = {
				list = target_titles
				limit = { tier = tier_duchy }
				save_scope_as = de_jure_target
			}
		}

		# 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 = {
		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

		#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 = {
		desc = {
			first_valid = {
				triggered_desc = {
					trigger = { scope:attacker = { is_local_player = 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

		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
		}

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

	on_primary_attacker_death = inherit
	on_primary_defender_death = inherit

	attacker_allies_inherit = yes
	defender_allies_inherit = yes

	war_name = "JAPAN_IMPERIAL_EXPANSION_WAR_NAME"
	war_name_base = "JAPAN_IMPERIAL_EXPANSION_WAR_NAME_BASE"
	cb_name = "JAPAN_IMPERIAL_EXPANSION_CB_NAME"
	interface_priority = 80

	ticking_war_score_targets_entire_realm = yes
	attacker_ticking_warscore = 0.01
	attacker_wargoal_percentage = 0.01
	attacker_score_from_occupation_scale = 50
	defender_score_from_occupation_scale = 50
	attacker_score_from_battles_scale = 250
	defender_score_from_battles_scale = 250

	max_attacker_score_from_battles = 200
	max_defender_score_from_battles = 200
	
	max_defender_score_from_occupation = 50
	max_attacker_score_from_occupation = 50

	max_ai_diplo_distance_to_title = 500
	
	ai_score = {
		value = japan_imperial_expansion_ai_score_value
	}

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

# War to reconquer Japan
japan_imperial_reconquest_cb = {
	icon = ritsuryo_government
	group = de_jure

	war_name = "JAPAN_IMPERIAL_RECONQUEST_WAR_NAME"
	war_name_base = "JAPAN_IMPERIAL_RECONQUEST_WAR_NAME_BASE"
	cb_name = "JAPAN_IMPERIAL_RECONQUEST_CB_NAME"
	interface_priority = 80

	combine_into_one = yes
	should_show_war_goal_subview = yes
   	mutually_exclusive_titles = {
		NOT = {
			trigger_if = {
				scope:attacker = {
						is_ai = no
				}
			}
		}
	}

	cost = {
		prestige = {
			scope:defender = {
				every_sub_realm_county = {
					limit = { empire = title:e_japan }
					add = {
						value = 50
						desc = japan_imperial_reconquest_cb_cost_tt
					}
				}
			}
			multiply = common_cb_prestige_cost_multiplier
		}
	}
   	
	allow_hostages = no

	target_titles = all
	target_title_tier = all
	target_de_jure_regions_above = yes
	ignore_effect = change_title_holder
	ai_only_against_neighbors = yes

	# root = scope:attacker
	allowed_for_character = {
		japan_imperial_reconquest_cb_allowed_for_character_trigger = yes
	}

	# root = scope:attacker
	allowed_for_character_display_regardless = {
		top_liege = { has_realm_law = defense_mobilization_law }
	}

	# root = scope:defender, scope:attacker
	allowed_against_character = {
		japan_imperial_reconquest_cb_allowed_against_character_trigger = yes
	}

	valid_to_start = {
		scope:target = {
			tier = tier_duchy
			empire = title:e_japan
		}
	}

	# root = scope:attacker, scope:defender, scope:target
	valid_to_start_display_regardless = {
		custom_tooltip = {
			text = tgp_japan_reconquest_war_valid_de_jure_tt
			scope:target.empire ?= title:e_japan
		}
	}

	should_invalidate = {
		OR = {
			scope:attacker = { japan_imperial_reconquest_cb_allowed_for_character_trigger = no }
			scope:defender = { japan_imperial_reconquest_cb_allowed_against_character_trigger = no }
		}
	}

	on_invalidated_desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:attacker = { japan_imperial_reconquest_cb_allowed_for_character_trigger = no }
				}
				desc = japan_imperial_reconquest_cb_ended_invalid.desc.attacker
			}
			desc = japan_imperial_reconquest_cb_ended_invalid.desc
		}
	}

	on_declaration = {
		on_declared_war = yes
	}

	on_victory_desc = {
		desc = {
			first_valid = {
				triggered_desc = {
					trigger = { scope:attacker = { is_local_player = yes } }
					desc = de_jure_cb_victory_desc_attacker
				}
				desc = japan_imperial_reconquest_cb_victory_desc
			}
			triggered_desc = {
				trigger = {
					scope:attacker = { is_independent_ruler = no }
				}
				desc = japan_demand_administrative_cb_victory_vassal_desc
			}
		}
	}

	on_victory = {
		scope:attacker = { show_pow_release_message_effect = yes }
		
		# Legitimacy
		add_legitimacy_attacker_victory_effect = yes

		#EP2 Accolade glory gain from winning against higher ranked enemy
		scope:attacker = { accolade_attacker_war_end_glory_gain_low_effect = yes }
		
		# Influence/Prestige Progress reward for Attacker
		scope:attacker = {
			if = {
				limit = { is_independent_ruler = no }
				if = {
					limit = { government_allows = administrative }
					change_influence = japan_imperial_reconquest_war_influence_value
				}
				else = { add_prestige_experience = japan_imperial_reconquest_war_prestige_value }
			}
		}

		# EP3 Laamp possibility warning
		scope:defender = { ep3_war_loss_adventurer_tt_effect = yes }

		create_title_and_vassal_change = {
			type = conquest
			save_scope_as = change
			add_claim_on_loss = yes
		}
		
		every_in_list = {
			list = target_titles
			save_temporary_scope_as = target
		}
		
		setup_de_jure_cb = {
			attacker = scope:attacker
			defender = scope:defender
			change = scope:change
			title = scope:target
		}
		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 = 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 = {
		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 }

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

		setup_de_jure_cb = {
			attacker = scope:attacker
			defender = scope:defender
			victory = no
			title = scope:target
		}

		# 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_defeat_desc = {
		desc = {
			first_valid = {
				triggered_desc = {
					trigger = { scope:attacker = { is_local_player = 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

		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
		}
	
		scope:attacker = {
			pay_short_term_gold_reparations_effect = {
				GOLD_VALUE = 10
			}
		}

		setup_de_jure_cb = {
			attacker = scope:attacker
			defender = scope:defender
			victory = no
			title = scope:target
		}

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

	on_primary_attacker_death = inherit
	on_primary_defender_death = inherit

	attacker_allies_inherit = yes
	defender_allies_inherit = 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 = {
		value = japan_imperial_reconquest_ai_score_value
	}

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

# War to reimpose Ritsuryo
japan_refused_ritsuryo_cb = {
	icon = dissolution_war
	group = civil_war
	ai_only_against_liege = yes
	allow_hostages = no
	allowed_for_character = {
		scope:attacker = {
			liege = scope:defender
			NOT = { government_has_flag = government_is_japan_administrative }
		}
	}

	allowed_against_character = {
		scope:attacker = {
			liege = scope:defender
		}
	}

	target_de_jure_regions_above = yes

	valid_to_start = {
	}

	should_invalidate = {
		OR = {
			scope:attacker = {
				NOT = {
					any_liege_or_above = { this = scope:defender }
				}
			}
			scope:defender = { is_landed = no }
		}
	}

	on_declaration = {
		# save the initial target and their tier for conditioning the depose effect
		if = {
			limit = { NOT = { exists = scope:attacker.var:initial_target } }
			scope:attacker = {
				set_variable = {
					name = initial_target
					value = scope:defender
				}
				set_variable = {
					name = target_tier
					value = scope:defender.primary_title.tier
				}
			}
		}
	}

	on_victory_desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:defender = { is_local_player = yes }
					OR = {
						NOT = { exists = scope:attacker.var:initial_target }
						scope:defender = scope:attacker.var:initial_target
						scope:defender.primary_title.tier <= scope:attacker.var:target_tier
					}
				}
				desc = japan_refused_ritsuryo_cb_victory_desc_defender
			}
			triggered_desc = {
				trigger = {
					OR = {
						NOT = { exists = scope:attacker.var:initial_target }
						scope:defender = scope:attacker.var:initial_target
						scope:defender.primary_title.tier <= scope:attacker.var:target_tier
					}
				}
				desc = japan_refused_ritsuryo_cb_victory_desc
			}
		}
	}

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

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

		scope:defender = {

			# If we win the rebellion, our liege loses any legal right to imprison us/banish us/revoke our titles.
			consume_all_criminal_reasons_effect = {
				LIEGE = scope:defender
				CRIMINAL = scope:attacker
			}

			add_prestige = -500

			# JAPAN - liege is replaced by the attacker
			create_title_and_vassal_change = {
				type = conquest
				save_scope_as = title_change
			}
			title:c_yamashiro ?= {
				if = {
					limit = { holder = scope:defender }
					change_title_holder_include_vassals = {
						holder = scope:attacker
						change = scope:title_change
					}
				}
			}
			scope:defender = {
				every_held_title = {
					limit = { tier >= tier_empire }
					change_title_holder_include_vassals = {
						holder = scope:attacker
						change = scope:title_change
					}
				}
			}
			resolve_title_and_vassal_change = scope:title_change
		}

		# LEGITIMACY FROM LOSING FACTION WAR
		faction_war_end_defeat_legitimacy_effect = yes

		hidden_effect = {
			scope:attacker = {
				add_truce_both_ways = {
					character = scope:defender
					days = 1825
					war = root.war
					result = victory
				}
			}
		}

		#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 = japan_refused_ritsuryo_cb_white_peace_desc_defender
			}
			desc = japan_refused_ritsuryo_cb_white_peace_desc
		}

	}

	on_white_peace = {
		scope:attacker = {
			show_pow_release_message_effect = yes
			stress_impact = {
 				ambitious = medium_stress_impact_gain
 				arrogant = medium_stress_impact_gain
 			}
		}

		scope:defender = {
			stress_impact = {
 				arrogant = medium_stress_impact_gain
 			}
		}
		hidden_effect = {
			scope:attacker = {
				add_truce_both_ways = {
					character = scope:defender
					days = 1825
					war = root.war
					result = white_peace
				}
			}
		}
		on_white_peace_request_revolt_war = yes
	}

	on_defeat_desc = {
		first_valid = {
			triggered_desc = {
				trigger = { scope:defender = { is_local_player = yes } }
				desc = japan_refused_ritsuryo_cb_defeat_desc_defender
			}
			desc = japan_refused_ritsuryo_cb_defeat_desc
		}

	}

	on_defeat = {
		scope:attacker = { show_pow_release_message_effect = yes }
		scope:defender = {
			add_character_flag = {
				flag = recent_liberty_faction_war
				years = 10
			}
			add_dread = medium_dread_gain

			# LEGITIMACY FROM WINNING FACTION WAR
			faction_war_end_victory_legitimacy_effect = yes
		}

		# For revoking titles of character's imprisoned abroad who have lost a revocation war
		hidden_effect = {
			if = {
				limit = {
					scope:attacker = {
						is_imprisoned = yes
						NOT = { is_imprisoned_by = scope:defender }
					}
				}
				scope:defender = {
					add_opinion = {
						target = scope:attacker
						modifier = foreign_prison_revocation_opinion
					}
				}
			}
		}
		
		on_lost_request_revolt_war = yes

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

	on_invalidated_desc = msg_invalidate_war_title

	check_attacker_inheritance_validity = no

	on_primary_attacker_death = invalidate
	on_primary_defender_death = inherit

	transfer_behavior = transfer

	attacker_allies_inherit = yes
	defender_allies_inherit = yes

	war_name = "JAPAN_REFUSED_RITSURYO_WAR_NAME"

	interface_priority = 80

	use_de_jure_wargoal_only = yes

	attacker_wargoal_percentage = 0.8

	max_attacker_score_from_battles = 100
	max_defender_score_from_battles = 50
	
	max_defender_score_from_occupation = 150
	max_attacker_score_from_occupation = 150

	max_ai_diplo_distance_to_title = 500
}

# Eradicate Rival House
eradicate_house_cb = {
	icon = execute
	group = subjugation
	combine_into_one = yes
	ai_only_against_neighbors = yes
	allow_hostages = no
	should_show_war_goal_subview = no

	# scope:attacker
	allowed_for_character = {
		#Display so once a player has bad house relations they can be tempted to make them worse to validate cb
		trigger_if = {
			limit = {
				is_ai = yes
			}
			house ?= {
				any_house_relation = {
					has_house_relation_level = feud 
				}
			}
		}
		trigger_else = {
			house ?= {
				any_house_relation = {
					OR = {
						has_house_relation_level = quarrel
						has_house_relation_level = rivalry
						has_house_relation_level = feud
					}
				}
			}
		}
	}

	# scope:defender
	allowed_against_character = {
		is_landed = yes
		#Can't be the attacker's top liege
		NOR = {
			is_vassal_or_below_of = scope:attacker 
			is_liege_or_above_of = scope:attacker
		}
	}

	valid_to_start = {
		#We need the worst house relations
		tgp_has_house_relation_level_trigger = {
			HOUSE_1_MEMBER = scope:attacker
			HOUSE_2_MEMBER = scope:defender
			LEVEL = feud
		}
	}

	cost = {
		prestige = {
			add = {
				value = 100
				desc = CB_BASE_COST
			}
			multiply = common_cb_prestige_cost_multiplier
		}
	}

	should_invalidate = {
		#cancel if they become friendly
		OR = {
			NOT = { 
				tgp_has_house_relation_level_trigger = {
					HOUSE_1_MEMBER = scope:attacker
					HOUSE_2_MEMBER = scope:defender
					LEVEL = feud
				}
			}
			scope:defender = { is_landed = no }
		}
	}

	on_invalidated_desc = {
		desc = eradicate_house_cb_ended_invalid.desc
	}

	on_declaration = {
		on_declared_war = yes
	}

	on_victory_desc = {
		desc = eradicate_house_cb_victory_desc
	}

	on_victory = {
		scope:attacker = {
			if = {
				limit = {
					is_ai = no
				}
				add_achievement_global_variable_effect = {
					VARIABLE = finished_ep4_07_cut_off_the_head_and_the_body_will_follow_achievement
					VALUE = yes
				}
			}
		}
		
		scope:attacker = { show_pow_release_message_effect = yes }
		
		# Legitimacy
		add_legitimacy_attacker_victory_effect = yes

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

		scope:attacker = {
			switch = {
				trigger = scope:defender.primary_title.tier
				tier_county = { add_prestige = minor_prestige_gain }
				tier_duchy = { add_prestige = medium_prestige_gain }
				tier_kingdom = { add_prestige = major_prestige_gain }
				tier_empire = { add_prestige = massive_prestige_gain }
				tier_hegemony = { add_prestige = monumental_prestige_gain }
			}
		}

		scope:defender = {
			switch = {
				trigger = primary_title.tier
				tier_county = { add_prestige = minor_prestige_loss }
				tier_duchy = { add_prestige = medium_prestige_loss }
				tier_kingdom = { add_prestige = major_prestige_loss }
				tier_empire = { add_prestige = massive_prestige_loss }
				tier_hegemony = { add_prestige = monumental_prestige_loss }
			}
		}
		#Show land transfer
		show_as_tooltip = {
			#loser/winner scopes are only being set here to correctly display the effects of tgp_japan_soryo_eradicate_cb_transfer_effect in the tooltip!
			scope:defender = {
				save_scope_as = loser
			}
			scope:attacker = {
				save_scope_as = winner
			}
			tgp_japan_soryo_eradicate_cb_transfer_effect = yes	
		}
		#show death
		show_as_tooltip = {
			scope:defender = {
				death = {
					death_reason = death_eradicated
					killer = scope:attacker
				}
			}
			scope:defender = {
				every_courtier = {
					custom = every_close_family_house_member_in_court_cb_win_desc 
					limit = {
						house = scope:defender.house
						NOT = {
							scope:defender.primary_heir ?= this
						} 
					}
					death = {
						death_reason = death_eradicated
						killer = scope:attacker 
					}
				}
			}
		}
		
		# 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

		#Eradicate House follow up event
		scope:defender = {
			trigger_event = tgp_japan_general.9550
		}
	}

	on_white_peace_desc = {
		desc = eradicate_house_cb_white_peace_desc
	}
	on_white_peace = {
		scope:attacker = { 
			show_pow_release_message_effect = yes
			stress_impact = {
				ambitious = medium_stress_impact_gain
				arrogant = medium_stress_impact_gain
			}
			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:attacker # not important as the scales are identical
			FAME_BASE = major_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_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_defeat_desc = {
		desc = eradicate_house_cb_defeat_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
		}

		scope:attacker = {
			switch = {
				trigger = primary_title.tier
				tier_county = { add_prestige = minor_prestige_loss }
				tier_duchy = { add_prestige = medium_prestige_loss }
				tier_kingdom = { add_prestige = major_prestige_loss }
				tier_empire = { add_prestige = massive_prestige_loss }
				tier_hegemony = { add_prestige = monumental_prestige_loss }
			}
		}
		scope:defender = {
			switch = {
				trigger = primary_title.tier
				tier_county = { add_prestige = minor_prestige_gain }
				tier_duchy = { add_prestige = medium_prestige_gain }
				tier_kingdom = { add_prestige = major_prestige_gain }
				tier_empire = { add_prestige = massive_prestige_gain }
				tier_hegemony = { add_prestige = monumental_prestige_gain }
			}
		}
		#Show land transfer
		show_as_tooltip = {
			#loser/winner scopes are only being set here to correctly display the effects of tgp_japan_soryo_eradicate_cb_transfer_effect in the tooltip!
			scope:defender = {
				save_scope_as = winner
			}
			scope:attacker = {
				save_scope_as = loser
			}
			tgp_japan_soryo_eradicate_cb_transfer_effect = yes
		}
		#Show killing
		show_as_tooltip = {
			
			scope:attacker = {
				death = {
					death_reason = death_eradicated
					killer = scope:defender
				}
			}
			scope:attacker = {
				every_courtier = {
					custom = every_close_family_house_member_in_court_cb_lose_desc 
					limit = {
						house = scope:attacker.house
						NOT = {
							this = scope:attacker.primary_heir  
						} 
					}
					death = {
						death_reason = death_eradicated
						killer = scope:defender 
					}
				}
			}
		}
		# 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
		}

		# Truce
		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
		#Eradicate House follow up event
		scope:attacker = {
			trigger_event = tgp_japan_general.9550
		}
	}

	on_primary_attacker_death = inherit
	on_primary_defender_death = inherit

	attacker_allies_inherit = yes
	defender_allies_inherit = yes

	war_name = "ERADICATE_HOUSE_WAR_NAME"
	war_name_base = "ERADICATE_HOUSE_WAR_NAME_BASE"
	cb_name = "ERADICATE_HOUSE_CB_NAME"
	interface_priority = 80

	ticking_war_score_targets_entire_realm = yes
	attacker_ticking_warscore = 0.01
	attacker_wargoal_percentage = 0.01
	attacker_score_from_occupation_scale = 100
	defender_score_from_occupation_scale = 100
	attacker_score_from_battles_scale = 150
	defender_score_from_battles_scale = 150

	max_attacker_score_from_battles = 200
	max_defender_score_from_battles = 200
	
	max_defender_score_from_occupation = 50
	max_attacker_score_from_occupation = 50

	max_ai_diplo_distance_to_title = 500

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

# War to become Soryo as Kampaku
japan_establish_soryo_administration_cb = {
	icon = soryo
	group = subjugation
	combine_into_one = yes
	allow_hostages = no
	should_show_war_goal_subview = no

	# scope:attacker
	allowed_for_character = {
		has_tgp_dlc_trigger = yes
		always = no # Started by script
	}

	should_invalidate = {
		scope:defender = { government_has_flag = government_is_japan_feudal }
	}

	on_invalidated_desc = {
		desc = japan_establish_soryo_administration_cb_ended_invalid.desc
	}

	on_victory_desc = {
		desc = japan_establish_soryo_administration_cb_victory_desc
	}

	on_victory = {
		scope:attacker = {
			show_pow_release_message_effect = yes
			save_scope_as = leader
		}
		scope:defender = {
			save_scope_as = daijo_daijin
		}
		
		# Legitimacy
		add_legitimacy_attacker_victory_effect = yes

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

		scope:attacker = {
			switch = {
				trigger = scope:defender.primary_title.tier
				tier_county = { add_prestige = minor_prestige_gain }
				tier_duchy = { add_prestige = medium_prestige_gain }
				tier_kingdom = { add_prestige = major_prestige_gain }
				tier_empire = { add_prestige = massive_prestige_gain }
				tier_hegemony = { add_prestige = monumental_prestige_gain }
			}
		}

		scope:defender = {
			switch = {
				trigger = primary_title.tier
				tier_county = { add_prestige = minor_prestige_loss }
				tier_duchy = { add_prestige = medium_prestige_loss }
				tier_kingdom = { add_prestige = major_prestige_loss }
				tier_empire = { add_prestige = massive_prestige_loss }
				tier_hegemony = { add_prestige = monumental_prestige_loss }
			}
		}

		scope:defender = {
			faction_demand_regent_transfer_effect = {
				NEW_REGENT = scope:attacker
				REASON = conquest
			}
		}

		# 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 = major_prestige_value
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}

		# Truce
		add_truce_attacker_victory_effect = yes

		scope:defender = {
			every_character_war = {
				limit = { is_attacker = scope:attacker }
				every_war_defender = {
					limit = { is_imprisoned = no }
					hidden_effect = {
						hard_imprison_character_effect = {
							TARGET = this
							IMPRISONER = scope:attacker
						}
						reverse_add_opinion = {
							target = scope:attacker
							modifier = vassal_lost_faction_revolt_war
						}
					}
				}
			}
		}

		# 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 = {
		desc = japan_establish_soryo_administration_cb_white_peace_desc
	}

	on_white_peace = {
		scope:attacker = { 
			show_pow_release_message_effect = yes
			stress_impact = {
				ambitious = medium_stress_impact_gain
				arrogant = medium_stress_impact_gain
			}
			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:attacker # not important as the scales are identical
			FAME_BASE = major_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_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_defeat_desc = {
		desc = japan_establish_soryo_administration_cb_defeat_desc
	}

	on_defeat = {
		scope:attacker = {
			show_pow_release_message_effect = yes
			save_scope_as = leader
		}
		scope:defender = {
			save_scope_as = daijo_daijin
			show_as_tooltip = { japanese_establish_soryo_administration_reward_effect = yes }
			trigger_event = tgp_japan_decision.9606
		}

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

		scope:attacker = {
			switch = {
				trigger = primary_title.tier
				tier_county = { add_prestige = minor_prestige_loss }
				tier_duchy = { add_prestige = medium_prestige_loss }
				tier_kingdom = { add_prestige = major_prestige_loss }
				tier_empire = { add_prestige = massive_prestige_loss }
				tier_hegemony = { add_prestige = monumental_prestige_loss }
			}
		}

		scope:defender = {
			switch = {
				trigger = primary_title.tier
				tier_county = { add_prestige = minor_prestige_gain }
				tier_duchy = { add_prestige = medium_prestige_gain }
				tier_kingdom = { add_prestige = major_prestige_gain }
				tier_empire = { add_prestige = massive_prestige_gain }
				tier_hegemony = { add_prestige = monumental_prestige_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:defender
			FAME_BASE = major_prestige_value
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}

		# Truce
		add_truce_attacker_defeat_effect = yes

		scope:attacker = {
			every_character_war = {
				limit = { is_defender = scope:defender }
				every_war_attacker = {
					limit = { is_imprisoned = no }
					hidden_effect = {
						hard_imprison_character_effect = {
							TARGET = this
							IMPRISONER = scope:defender
						}
						reverse_add_opinion = {
							target = scope:defender
							modifier = vassal_lost_faction_revolt_war
						}
					}
				}
			}
		}

		# 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 = "JAPAN_ESTABLISH_SORYO_ADMINISTRATION_WAR_NAME"
	war_name_base = "JAPAN_ESTABLISH_SORYO_ADMINISTRATION_WAR_NAME_BASE"
	cb_name = "JAPAN_ESTABLISH_SORYO_ADMINISTRATION_CB_NAME"
	interface_priority = 80

	ticking_war_score_targets_entire_realm = yes
	attacker_ticking_warscore = 0.01
	attacker_wargoal_percentage = 0.01
	attacker_score_from_occupation_scale = 50
	defender_score_from_occupation_scale = 50
	attacker_score_from_battles_scale = 250
	defender_score_from_battles_scale = 250

	max_attacker_score_from_battles = 200
	max_defender_score_from_battles = 200
	
	max_defender_score_from_occupation = 50
	max_attacker_score_from_occupation = 50
}

# War to disrupt Bloc
japan_bloc_war_cb = {
	icon = bloc
	group = subjugation
	combine_into_one = yes
	ai_only_against_neighbors = yes
	allow_hostages = yes
	should_show_war_goal_subview = no

	# scope:attacker
	allowed_for_character = {
		has_tgp_dlc_trigger = yes
		# Soryo Bloc leader checks
		tgp_soryo_or_bushido_trigger = yes
		is_house_head = yes
		house.house_confederation.leading_house ?= house
		any_held_title = { is_noble_family_title = yes }
	}

	allowed_for_character_display_regardless = {
		custom_tooltip = {
			text = japan_bloc_war_cb_cohesion_requirement_tt
			house.house_confederation.cohesion >= 25
		}
	}

	# scope:defender
	allowed_against_character = {
		tgp_soryo_or_bushido_trigger = yes
		is_house_head = yes
		house.house_confederation.leading_house ?= house
		NOR = {
			# Must be different Bloc
			AND = {
				exists = scope:attacker.house.house_confederation
				house.house_confederation ?= scope:attacker.house.house_confederation
			}
			# Not any ongoing bloc war
			any_character_war = {
				using_cb = japan_bloc_war_cb
				save_temporary_scope_as = war_temp
				scope:attacker = { is_participant_in_war = scope:war_temp }
			}
		}
		# Must be house head
		any_held_title = { is_noble_family_title = yes }
	}

	should_invalidate = {
		OR = {
			scope:attacker = { tgp_soryo_or_bushido_trigger = no }
			scope:defender = {
				OR = {
					tgp_soryo_or_bushido_trigger = no
					NOT = { exists = house.house_confederation } # Left bloc
					house.house_confederation ?= scope:attacker.house.house_confederation # Same bloc
					is_landed = no
				}
			}
		}
	}

	cost = {
		prestige = {
			add = {
				value = 100
				desc = CB_BASE_COST
			}
			multiply = common_cb_prestige_cost_multiplier
		}
	}

	on_invalidated_desc = {
		desc = japan_bloc_war_cb_ended_invalid.desc
	}

	on_declaration = {
		on_declared_war = yes
		add_attacker_bloc_members_on_declared_effect = yes
	}

	on_victory_desc = {
		desc = japan_bloc_war_cb_victory_desc
	}

	on_victory = {
		scope:attacker = {
			save_scope_as = winner
			house.house_confederation = {
				tgp_bloc_change_cohesion_effect = {
					VALUE = tgp_bloc_war_defeat_cohesion_victory_value
					ICON = scope:defender
					REASON = bloc_war_victory
				}
			}
		}

		scope:defender = {
			save_scope_as = loser
			house.house_confederation = {
				tgp_bloc_change_cohesion_effect = {
					VALUE = tgp_bloc_war_defeat_cohesion_defeat_value
					ICON = scope:defender
					REASON = bloc_war_defeat
				}
			}
		}

		tgp_bloc_war_defeat_member_effect = {
			WINNER = scope:winner
			LOSER = scope:loser
		}

		scope:attacker = { show_pow_release_message_effect = yes }
		
		# Legitimacy
		add_legitimacy_attacker_victory_effect = yes

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

		scope:attacker = {
			switch = {
				trigger = scope:defender.primary_title.tier
				tier_county = { add_prestige = minor_prestige_gain }
				tier_duchy = { add_prestige = medium_prestige_gain }
				tier_kingdom = { add_prestige = major_prestige_gain }
				tier_empire = { add_prestige = massive_prestige_gain }
				tier_hegemony = { add_prestige = monumental_prestige_gain }
			}
		}

		scope:defender = {
			switch = {
				trigger = primary_title.tier
				tier_county = { add_prestige = minor_prestige_loss }
				tier_duchy = { add_prestige = medium_prestige_loss }
				tier_kingdom = { add_prestige = major_prestige_loss }
				tier_empire = { add_prestige = massive_prestige_loss }
				tier_hegemony = { add_prestige = monumental_prestige_loss }
			}
		}

		# 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 = 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 = {
		desc = japan_bloc_war_cb_white_peace_desc
	}

	on_white_peace = {
		scope:attacker = { 
			show_pow_release_message_effect = yes
			stress_impact = {
				ambitious = medium_stress_impact_gain
				arrogant = medium_stress_impact_gain
			}
			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:attacker # not important as the scales are identical
			FAME_BASE = major_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_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_defeat_desc = {
		desc = japan_bloc_war_cb_defeat_desc
	}

	on_defeat = {
		scope:defender = {
			save_scope_as = winner
			house.house_confederation = {
				tgp_bloc_change_cohesion_effect = {
					VALUE = tgp_bloc_war_defeat_cohesion_victory_value
					ICON = scope:attacker
					REASON = bloc_war_victory
				}
			}
		}

		scope:attacker = {
			save_scope_as = loser
			house.house_confederation = {
				tgp_bloc_change_cohesion_effect = {
					VALUE = tgp_bloc_war_defeat_cohesion_defeat_value
					ICON = scope:defender
					REASON = bloc_war_defeat
				}
			}
		}

		tgp_bloc_war_defeat_member_effect = {
			WINNER = scope:winner
			LOSER = scope:loser
		}

		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
		}

		scope:attacker = {
			switch = {
				trigger = primary_title.tier
				tier_county = { add_prestige = minor_prestige_loss }
				tier_duchy = { add_prestige = medium_prestige_loss }
				tier_kingdom = { add_prestige = major_prestige_loss }
				tier_empire = { add_prestige = massive_prestige_loss }
				tier_hegemony = { add_prestige = monumental_prestige_loss }
			}
		}

		scope:defender = {
			switch = {
				trigger = primary_title.tier
				tier_county = { add_prestige = minor_prestige_gain }
				tier_duchy = { add_prestige = medium_prestige_gain }
				tier_kingdom = { add_prestige = major_prestige_gain }
				tier_empire = { add_prestige = massive_prestige_gain }
				tier_hegemony = { add_prestige = monumental_prestige_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:defender
			FAME_BASE = major_prestige_value
			IS_RELIGIOUS_WAR = no
			WINNER_ALLY_FAME_SCALE = 1
			LOSER_ALLY_FAME_SCALE = 1
		}

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

	on_primary_attacker_death = inherit
	on_primary_defender_death = inherit

	attacker_allies_inherit = yes
	defender_allies_inherit = yes

	war_name = "JAPAN_BLOC_WAR_NAME"
	war_name_base = "JAPAN_BLOC_WAR_NAME_BASE"
	cb_name = "JAPAN_BLOC_WAR_CB_NAME"
	interface_priority = 80

	ticking_war_score_targets_entire_realm = yes
	attacker_ticking_warscore = 0.01
	attacker_wargoal_percentage = 0.01
	attacker_score_from_occupation_scale = 100
	defender_score_from_occupation_scale = 100
	attacker_score_from_battles_scale = 150
	defender_score_from_battles_scale = 150

	max_attacker_score_from_battles = 100
	max_defender_score_from_battles = 100
	
	max_defender_score_from_occupation = 100
	max_attacker_score_from_occupation = 100

	max_ai_diplo_distance_to_title = 500
	
	ai_score = {
		value = japan_bloc_war_ai_score_value
	}

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