﻿# Invite Other House
invite_to_house_bloc_interaction = {
	category = interaction_category_diplomacy
	use_diplomatic_range = no
	common_interaction = yes
	send_options_exclusive = no

	greeting = positive
	notification_text = INVITE_TO_HOUSE_BLOC_NOTIFICATION
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:actor.house.house_confederation }
				desc = invite_to_house_bloc_interaction_desc
			}
			desc = invite_to_house_bloc_interaction_desc_create
		}
	}

	icon = icon_invite_to_bloc

	cooldown_against_recipient = { years = 5 }

	cost = {
		influence = {
			value = 0
			if = {
				limit = { scope:actor = { government_allows = administrative } }
				add = 50
			}
		}
		prestige = {
			value = 0
			if = {
				limit = { NOT = { scope:actor = { government_allows = administrative } } }
				add = 100
			}
		}
	}

	redirect = {
		scope:recipient = {
			if = {
				limit = {
					is_house_head = no
					exists = house.house_head
				}
				house.house_head = { save_scope_as = recipient }
			}
		}
	}

	is_available = {
		government_has_flag = government_has_house_blocs
		house.house_head ?= this
		tgp_house_bloc_interaction_valid_trigger = yes
		trigger_if = {
			limit = {
				is_ai = yes
			}
			OR = {
				is_landed = yes
				tgp_is_ceremonial_liege_trigger = yes
			}
			trigger_if = {
				limit = {
					NOT = { exists = house.house_confederation } # You have no Bloc
					this != top_liege # exception for top liege
				}
				any_confederation = { # There are 4 or fewer Blocs in your realm (Japan)
					count < 5
					has_leading_house = yes
					leading_house.house_head.top_liege = root.top_liege
				}
			}
			trigger_if = {
				limit = {
					NOT = { house.house_confederation.leading_house.house_head ?= this } # I have no bloc or I'm not leading my bloc
				}
				NOT = { # No Bloc exists in my realm with the same aspiration
					any_confederation = {
						has_leading_house = yes
						leading_house.house_head.top_liege = root.top_liege
						leading_house = { has_same_house_aspiration_as = root.house }
					}
				}
			}
		}
	}

	is_shown = {
		scope:actor = {
			this != scope:recipient
			top_liege = scope:recipient.top_liege
			OR = {
				is_landed = yes
				tgp_is_ceremonial_liege_trigger = yes
			}
			trigger_if = { # Not a confederation member, or in a different confederation
				limit = { exists = house.house_confederation }
				NOT = { scope:recipient.house.house_confederation ?= house.house_confederation }
			}
		}
		scope:recipient = { tgp_house_bloc_interaction_valid_trigger = yes }
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_at_war = no
			tgp_house_bloc_interaction_valid_showing_failures_trigger = yes
			trigger_if = {
				limit = { exists = confederation }
				custom_tooltip = {
					text = invite_to_house_bloc_leader_tt
					confederation.leading_house = house
				}
			}
			trigger_else = {
				custom_tooltip = {
					text = invite_to_house_bloc_tt
					is_house_head = yes
					is_ruler = yes
				}
			}
		}
		scope:recipient = {
			is_at_war = no
			tgp_house_bloc_interaction_valid_showing_failures_trigger = yes

			custom_tooltip = {
				text = join_bloc_vassal_house_tt #Vassals cannot be asked to join blocs except by their liege.
				trigger_if = {
					limit = {
						is_independent_ruler = no
						trigger_if = {
							limit = {
								exists = scope:secondary_recipient
							}
							NOT = { #If the liege of the house head is actually our original target then we pass this check.
								scope:secondary_recipient = scope:recipient.liege
							}
						}
					}
					OR = {
						liege = scope:actor.liege #We are under the same liege
						liege = scope:actor #Actor IS my liege
						AND = { #I am a count under a duke under Actor who is a king
							liege.liege = scope:actor
							scope:actor = { highest_held_title_tier < tier_empire } #Exception: Everyone in Japan is a vassal of the Ceremonial Regent / Empire tier top liege - therefore we need an exception for their vassals
						}
						liege = { #I can still be invited even if the one asking is not my liege, or my lieges liege - if the actor is asking me to join the bloc of my liege
							house.house_confederation = scope:actor.house.house_confederation
						}
					}
				}
			}
			custom_tooltip = {
				text = join_bloc_left_cooldown_recipient_tt
				NOT = {
					house = {
						any_in_list = {
							variable = left_bloc_cooldown
							scope:actor.house.house_confederation ?= this
							save_temporary_scope_as = bloc_cooldown_temp
						}
					}
				}
			}
			custom_tooltip = { # Cannot invite bloc leaders
				text = join_bloc_bloc_leader_tt
				trigger_if = {
					limit = {
						exists = scope:recipient.house.house_confederation
					}
					NOT = { scope:recipient.house.house_confederation.leading_house.house_head ?= scope:recipient }
				}
			}
			custom_tooltip = {
				text = join_bloc_recent_house_join_tt
				NOT = { 
					scope:recipient.house = { has_variable = recently_joined_bloc }
				}
			}
			trigger_if = { # Stop landless bloc building by AI
				limit = {
					scope:actor = {
						is_ai = yes
						NOT = { exists = house.house_confederation }
					}
				}
				is_landed = yes
			}
		}
	}

	# Use gold
	send_option = {
		is_valid = { scope:actor.gold >= scope:recipient.medium_gold_value }
		flag = gold
		localization = TRADE_GOLD_FOR_BETTER_AI_ACCEPTANCE
	}
	# Use prestige
	send_option = {
		is_valid = { scope:actor.prestige >= scope:recipient.medium_prestige_value }
		flag = prestige
		localization = TRADE_PRESTIGE_FOR_BETTER_AI_ACCEPTANCE
	}
	# Use influence
	send_option = {
		is_valid = {
			scope:actor = { government_has_flag = government_has_influence }
			scope:actor.influence >= scope:recipient.medium_influence_value
		}
		flag = influence
		localization = TRADE_INFLUENCE_FOR_BETTER_AI_ACCEPTANCE
	}
	## Offer a hook
	send_option = {
		flag = offer_hook
		is_valid = {
			custom_tooltip = {
				text = offer_hook.tt.cannot_offer_both_hooks
				scope:offer_hook_strong = no
			}
			NOT = {
				scope:recipient = { has_hook = scope:actor }
			}
		}
		localization = SCHEME_AGENT_HOOK
	}
	# Offer a strong hook
	send_option = {
		flag = offer_hook_strong
		is_shown = {
			scope:actor = { has_trait_with_flag = can_offer_strong_hook_to_agents }
		}
		is_valid = {
			custom_tooltip = {
				text = offer_hook.tt.cannot_offer_both_hooks
				scope:offer_hook = no
			}
			NOT = {
				scope:recipient = { has_strong_hook = scope:actor }
			}
		}
		localization = SCHEME_AGENT_HOOK_STRONG
	}
	# Use hook
	send_option = {
		is_valid = { scope:actor = { has_usable_hook = scope:recipient } }
		flag = hook
		localization = SCHEME_HOOK
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	on_accept = {
		scope:recipient = {
			house = {
				if = { # LEAVE OLD BLOC IF NECESSARY
					limit = { exists = house_confederation }
					switch = {
						trigger = yes
						scope:hook = {
							set_variable = {
								name = bloc_leaving_reason
								value = flag:reason_bribe_hook
								days = 4
							}
						}
						scope:gold = {
							set_variable = {
								name = bloc_leaving_reason
								value = flag:reason_bribe_gold
								days = 4
							}
						}
						scope:prestige = {
							set_variable = {
								name = bloc_leaving_reason
								value = flag:reason_bribe_prestige
								days = 4
							}
						}
						scope:influence = {
							set_variable = {
								name = bloc_leaving_reason
								value = flag:reason_bribe_influence
								days = 4
							}
						}
						scope:influence = {
							set_variable = {
								name = bloc_leaving_reason
								value = flag:reason_bribe_influence
								days = 4
							}
						}
						fallback = {
							tgp_save_bloc_leaving_reason_effect = {
								LEAVING_HOUSE = scope:recipient.house
								INVITING_HOUSE = scope:actor.house
							}
						}
					}
				}
				tgp_leave_house_bloc_effect = {
					OPINION = flag:yes
					TRUCE = flag:no
				}
			}
			add_character_flag = {
				flag = invited_to_bloc_recently
				years = 2
			}
		}
		scope:actor = {
			# HOOK
			if = {
				limit = { scope:hook = yes }
				use_hook = scope:recipient
			}
			# BRIBES
			else = {
				if = {
					limit = { scope:gold = yes }
					pay_short_term_gold = {
						target = scope:recipient
						gold = scope:recipient.medium_gold_value
					}
				}
				if = {
					limit = { scope:prestige = yes }
					add_prestige = scope:recipient.medium_prestige_loss
					scope:recipient = { add_prestige = medium_prestige_value }
				}
				if = {
					limit = { scope:influence = yes }
					change_influence = scope:recipient.medium_influence_loss
					scope:recipient = { change_influence = medium_influence_gain }
				}
				if = { # Offer Hook
					limit = { scope:offer_hook = yes }
					scope:recipient = {
						add_hook = {
							type = favor_hook
							target = scope:actor
						}
					}
				}
				if = { # Offer Strong Hook
					limit = { scope:offer_hook_strong = yes }
					scope:recipient = {
						add_hook = {
							type = strong_favor_hook
							target = scope:actor
						}
					}
				}
			}
			# CREATE BLOC IF NECESSARY
			house = {
				if = {
					limit = {
						NOT = { exists = house_confederation }
					}
					tgp_create_house_bloc_effect = { TYPE = none }
				}
			}
		}
		# JOIN NEW BLOC
		scope:recipient = {
			house ?= {
				tgp_join_house_bloc_effect = {
					INVITER = scope:actor.house
					OPINION = flag:yes
				}
			}
			custom_tooltip = forced_bloc_membership_tt # You cannot leave the bloc for 10y
			add_character_flag = {
				flag = forced_bloc_membership
				years = 10
			}
		}
	}

	on_decline = {
		scope:recipient = {
			add_character_flag = {
				flag = invited_to_bloc_recently
				years = 4
			}
		}
	}

	ai_accept = {
 		base = -50
 		# Bribes
 		modifier = {
 			scope:gold = yes
 			add = 25
			desc = TRADE_GOLD_FOR_BETTER_AI_ACCEPTANCE_TT
 		}
 		modifier = {
 			scope:prestige = yes
 			add = 25
			desc = PRESTIGE_INTERACTION_ACCEPTANCE_SEND_OPTION
 		}
 		modifier = {
 			scope:influence = yes
 			add = 25
			desc = INFLUENCE_INTERACTION_ACCEPTANCE_SEND_OPTION
 		}
		modifier = {
			add = 20
			scope:offer_hook = yes
			exists = scope:recipient
			desc = SCHEME_WITH_OFFER_HOOK
		}
		modifier = {
			add = 50
			scope:offer_hook_strong = yes
			exists = scope:recipient
			desc = SCHEME_WITH_OFFER_HOOK_STRONG
		}
		# More likely to accept an invite from the e_japan holder
		modifier = {
			add = 50
			scope:actor = { has_title = title:e_japan }
			desc = TIER_REASON_EMPEROR
		}

		# Bloc
 		house_bloc_desire_to_join_modifiers = {
 			JOINER = scope:recipient
 			INVITER = scope:actor
 			MULTIPLIER = 1
 		}

 		# House Relations
 		house_relation_ai_accept_modifiers = { # House Relations
 			HOUSE_1_MEMBER = scope:actor
 			HOUSE_2_MEMBER = scope:recipient
 			MULTIPLIER = 1
 		}
	}

	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:actor
			object = scope:recipient
			scope:hook = yes
		}
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 6
		duchy = 6
		kingdom = 6
		empire = 6
		hegemony = 0
	}

	ai_targets = {
		ai_recipients = liege
		ai_recipients = top_liege
		ai_recipients = scripted_relations
	}

	ai_targets = {
		ai_recipients = peer_vassals
		ai_recipients = vassals
		max = 25
	}

	ai_will_do = {
		base = -50
		# Rating
		modifier = {
			house ?= { is_powerful_family = yes }
			add = 25
		}
		modifier = {
			house ?= { is_dominant_family = yes }
			add = 25
		}
		modifier = { # Influential Ritsuryo
			government_has_flag = government_has_influence
			add = {
				value = influence_level
				multiply = 3
			}
		}
		modifier = { # Strong Soryo
			NOT = { government_has_flag = government_has_influence }
			add = {
				value = military_power
				divide = 100
			}
		}
		modifier = { # Renowned
			add = {
				value = dynasty.dynasty_prestige_level
				multiply = 3
			}
		}
		modifier = { # Prestigious
			add = {
				value = prestige_level
				multiply = 3
			}
		}
		modifier = { # Prefer landed members
			scope:recipient = {
				top_liege = root.top_liege
				is_landed = yes
			}
			add = 100
		}
		modifier = { # Encourage large houses to form blocs
 			NOT = { exists = house.house_confederation }
			house = {
				any_house_member = { count >= 20 }
			}
			add = 75
		}
		modifier = { # Don't try to start a new bloc with weak rulers
			NOT = { exists = house.house_confederation }
			current_military_strength >= scope:recipient.current_military_strength
			add = -250
		}
 		modifier = { # Encourage bringing in vassalized member's house heads
 			is_independent_ruler = no
 			any_vassal_or_below = {
 				is_landed = yes
 				highest_held_title_tier >= tier_county
 				house = scope:recipient.house
 			}
 			add = 250
 		}
 		modifier = { # Encourage independent rulers to have a bloc
 			is_independent_ruler = yes
 			NOT = { exists = house.house_confederation }
 			add = 200
 		}
		modifier = { # Encourage inviting blocless landed rulers to your bloc
			scope:recipient = {
				is_landed = yes
				NOT = { exists = house.house_confederation }
			}
 			add = 75
 		}
		modifier = { # Cont. - specially if you are the bloc leader
			scope:recipient = {
				is_landed = yes
				NOT = { exists = house.house_confederation }
			}
			scope:actor = {
				exists = house.house_confederation
				house.house_confederation.leading_house.house_head ?= this
			}
 			add = 100
 		}
		modifier = { # Don't invite people of different House Aspiration
			scope:recipient.house ?= {
				NOT = { has_same_house_aspiration_as = scope:actor.house }
			}
 			add = -100
 		}
		modifier = { # Cont - esp. if you have low Cohesion
			exists = scope:recipient.house
			scope:actor.house ?= {
				house_confederation ?= { cohesion < 75 }
				NOT = { has_same_house_aspiration_as = scope:recipient.house }
			}
 			add = -150
 		}
		modifier = { # ...or different Government Type
			scope:actor = {
				NOT = { has_same_government = scope:recipient }
			}
 			add = -150
 		}
		modifier = { # Cont - esp. if you have low Cohesion
			scope:actor = {
				house.house_confederation ?= { cohesion < 75 }
				NOT = { has_same_government = scope:recipient }
			}
 			add = -100
 		}
		modifier = { # Encourage creation of one of each type of bloc
			NOR = {
				exists = house.house_confederation
				any_confederation = {
					has_leading_house = yes
					leading_house.house_head.top_liege = scope:actor.top_liege
					leading_house = { has_same_house_aspiration_as = scope:actor.house }
				}
			}
			add = 150
		}
		#house_bloc_desire_to_join_modifiers = { # General modifiers #Unop Commented out as it doesn't make sense
		#	INVITER = scope:actor
		#	JOINER = scope:recipient
		#	MULTIPLIER = -1
		#}
 		modifier = { # Invite houses with good relations
 			add = {
 				value = 0
 				scope:recipient.house = {
 					every_house_relation = {
 						limit = {
 							any_relation_house = {
 								NOT = { this = scope:recipient.house }
 								house_confederation = scope:actor.house.house_confederation
 							}
 						}
 						if = {
 							limit = { has_house_relation_level = cordial }
 							add = 10
 						}
 						else_if = {
 							limit = { has_house_relation_level = friendly }
 							add = 20
 						}
 						else_if = {
 							limit = { has_house_relation_level = amity }
 							add = 30
 						}
 					}
 				}
 			}
 		}
		modifier = { # Try to have a good number of blocs at all times
			NOT = { exists = house.house_confederation } #Unop Use house, as we are in a character scope
			# From someone that makes sense
			is_landed = yes
			is_house_head = yes
			NOR = {
				prestige_level <= 1
				influence_level <= 1
			}
			any_confederation = { # There are 4 or fewer Blocs in your realm (Japan)
				count < 5
				has_leading_house = yes
				leading_house.house_head.top_liege = scope:actor.top_liege
			}
			add = 250
		}
		modifier = { # Don't invite houses with many landed members - it's bad for cohesion
			scope:recipient.house = {
				any_house_member = {
					count >= 3
					is_landed = yes
					top_liege = root.top_liege
				}
			}
			add = {
				value = 0 
				scope:recipient.house = {
					every_house_member = {
						limit = {
							is_landed = yes
							top_liege = root.top_liege
						}
						add = -15
					}
				}
			}
		}
		## MUST GO AT BOTTOM
		modifier = { # Frequency
			factor = 0
			scope:recipient = { has_character_flag = invited_to_bloc_recently } #Unop Use recipient instead of joiner_temp
		}
	}
}

# Join existing Bloc
join_house_bloc_interaction = {
	category = interaction_category_diplomacy
	use_diplomatic_range = no
	common_interaction = yes
	send_options_exclusive = no

	greeting = positive
	notification_text = JOIN_HOUSE_BLOC_NOTIFICATION
	desc = join_house_bloc_interaction_desc

	icon = icon_join_bloc

	cooldown_against_recipient = { years = 5 }

	cost = {
		influence = {
			value = 0
			if = {
				limit = { scope:actor = { government_allows = administrative } }
				add = 50
			}
		}
		prestige = {
			value = 0
			if = {
				limit = { NOT = { scope:actor = { government_allows = administrative } } }
				add = 100
			}
		}
	}

	redirect = {
		scope:recipient.house.house_confederation.leading_house.house_head ?= { save_scope_as = recipient }
	}

	is_available = {
		government_has_flag = government_has_house_blocs
		house.house_head ?= this
		tgp_house_bloc_interaction_valid_trigger = yes
		NOT = { has_character_flag = recently_joined_bloc }
		trigger_if = {
			limit = {
				is_ai = yes
			}
			OR = {
				is_landed = yes
				tgp_is_ceremonial_liege_trigger = yes
			}
		}
	}

	is_shown = {
		scope:recipient != scope:actor
		scope:recipient = {
			exists = house.house_confederation
			tgp_house_bloc_interaction_valid_trigger = yes
			trigger_if = {
				limit = { exists = scope:actor.house.house_confederation }
				NOT = { house.house_confederation = scope:actor.house.house_confederation }
			}
		}
		trigger_if = {
			limit = {
				scope:actor = {
					is_ai = yes
				}
			}
			scope:recipient = {
				house.house_head ?= this
				OR = {
					is_landed = yes
					tgp_is_ceremonial_liege_trigger = yes
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			trigger_if = {
				limit = { is_at_war_with = scope:recipient }
				custom_tooltip = {
					text = join_bloc_war_tt
					any_character_war = {
						using_cb = japan_install_bloc_member_cb
						primary_attacker = scope:recipient
						primary_defender = scope:actor
					}
				}
			}
			tgp_house_bloc_interaction_valid_showing_failures_trigger = yes
			custom_tooltip = {
				text = join_bloc_left_cooldown_tt
				NOT = {
					house = {
						any_in_list = {
							variable = left_bloc_cooldown
							scope:recipient.house.house_confederation ?= this
						}
					}
				}
			}
			custom_tooltip = {
				text = join_bloc_already_leading_another_tt
				exists = house
				NOT = { confederation.leading_house ?= house }
			}
			NAND = {
				is_ai = yes
				scope:recipient = { has_character_flag = join_house_bloc_ai_send_cooldown }
			}
		}
		scope:recipient = {
			tgp_house_bloc_interaction_valid_showing_failures_trigger = yes
		}
	}

	# Use gold
	send_option = {
		is_valid = { scope:actor.gold >= scope:recipient.medium_gold_value }
		flag = gold
		localization = TRADE_GOLD_FOR_BETTER_AI_ACCEPTANCE
	}
	# Use prestige
	send_option = {
		is_valid = { scope:actor.prestige >= scope:recipient.medium_prestige_value }
		flag = prestige
		localization = TRADE_PRESTIGE_FOR_BETTER_AI_ACCEPTANCE
	}
	# Use influence
	send_option = {
		is_valid = {
			scope:actor = { government_has_flag = government_has_influence }
			scope:actor.influence >= scope:recipient.medium_influence_value
		}
		flag = influence
		localization = TRADE_INFLUENCE_FOR_BETTER_AI_ACCEPTANCE
	}
	# Use hook
	send_option = {
		is_valid = { scope:actor = { has_usable_hook = scope:recipient } }
		flag = hook
		localization = SCHEME_HOOK
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	on_send = {
		if = {
			limit = {
				scope:actor = { is_ai = yes }
			}
			scope:recipient = {
				add_character_flag = {
					flag = join_house_bloc_ai_send_cooldown
					months = 3
				}
			}
		}
		debug_log = "join_house_bloc"
		debug_log_scopes = yes
	}

	on_accept = {
		scope:actor = {
			if = {
				limit = { scope:hook = yes }
				scope:actor = { use_hook = scope:recipient }
			}
			else = {
				if = {
					limit = { scope:gold = yes }
					pay_short_term_gold = {
						target = scope:recipient
						gold = scope:recipient.medium_gold_value
					}
				}
				if = {
					limit = { scope:prestige = yes }
					add_prestige = scope:recipient.medium_prestige_loss
					scope:recipient = { add_prestige = medium_prestige_value }
				}
				if = {
					limit = { scope:influence = yes }
					change_influence = scope:recipient.medium_gold_value_negative
					scope:recipient = { change_influence = medium_gold_value }
				}
			}
			if = {
				limit = { is_confederation_member = yes }
				house = {
					tgp_save_bloc_leaving_reason_effect = {
						LEAVING_HOUSE = scope:actor.house
						INVITING_HOUSE = scope:recipient.house
					}
					tgp_leave_house_bloc_effect = {
						OPINION = flag:yes
						TRUCE = flag:no
					}
				}
			}
		}
		scope:recipient.house = {
			if = {
				limit = {
					NOT = { exists = house_confederation }
				}
				tgp_create_house_bloc_effect = { TYPE = none }
			}
		}
		scope:actor = {
			house = {
				tgp_join_house_bloc_effect ?= {
					INVITER = scope:recipient.house
					OPINION = flag:yes
				}
			}
			if = {
				limit = { scope:hook = yes }
				add_character_flag = {
					flag = forced_bloc_membership
					years = 10
				}
				custom_tooltip = forced_bloc_membership_tt
			}
		}
	}

	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:actor
			object = scope:recipient
			scope:hook = yes
		}
	}

	ai_accept = {
		base = -25
		modifier = {
 			scope:gold = yes
 			add = 25
			desc = TRADE_GOLD_FOR_BETTER_AI_ACCEPTANCE_TT
 		}
 		modifier = {
 			scope:prestige = yes
 			add = 25
			desc = PRESTIGE_INTERACTION_ACCEPTANCE_SEND_OPTION
 		}
 		modifier = {
 			scope:influence = yes
 			add = 25
			desc = INFLUENCE_INTERACTION_ACCEPTANCE_SEND_OPTION
 		}
 		opinion_modifier = { # Opinion of Joiner
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 0.5
			step = 5
			max = 50
		}
 		house_relation_ai_accept_modifiers = {
 			HOUSE_1_MEMBER = scope:recipient
 			HOUSE_2_MEMBER = scope:actor
 			MULTIPLIER = -1
 		}
 		modifier = { # Prefer landed members
			add = {
				scope:actor.house = {
					every_house_member = {
						limit = {
							top_liege = root.top_liege
							is_landed = yes
						}
						add = 25
					}
				}
			}
			desc = AI_LANDED_HOUSE_MEMBERS_REASON
		}
		modifier = { # Landless with no armies are not very apealing
			scope:actor.house.house_head = {
				is_landed = no
				current_military_strength <= 0
			}
			add = -75
			desc = AI_LANDLESS_REASON
		}
		modifier = { # Same house power
			scope:actor.house ?= { has_same_house_aspiration_as = scope:recipient.house }
			add = 25
			desc = AI_SAME_ASPIRATION_REASON
		}
		modifier = { # Different government type
			scope:actor = {
				NOT = { has_same_government = scope:recipient }
			}
			add = -250 # always bad
			desc = AI_DIFFERENT_GOVERNMENT_REASON
		}
		modifier = { # Ai wants to have the Kampaku in their bloc
			scope:actor = { has_title = title:e_japan }
			add = 200
			desc = TIER_REASON_EMPEROR
		}
		modifier = { # Distance
			scope:actor.house = {
				any_house_member = {
					is_landed = yes
					any_held_county = {
						is_landless_type_title = no
						OR = {
							any_neighboring_county = { holder.house.house_confederation = scope:recipient.house.house_confederation }
							duchy ?= {
								any_de_jure_county = { holder.house.house_confederation = scope:recipient.house.house_confederation }
							}
						}
					}
				}
			}
			add = 25
			DESC = AI_NEARBY_BLOC_REASON
		}
		modifier = { # Bloc too small
			scope:recipient.house.house_confederation ?= {
				any_confederation_member_house = { count < 8 }
			}
			add = {
				value = 25
				if = {
					limit = {
						scope:recipient.house.house_confederation ?= {
							any_confederation_member_house = { count < 4 }
						}
					}
					add = 25
				}
			}
			desc = AI_BLOC_FEW_HOUSES_REASON
		}
		modifier = { # Bloc too small
			scope:recipient.top_liege = { # any_confederation_member is not performant for house blocs
				any_sub_realm_county = {
					count < 12
					holder.house.house_confederation = scope:recipient.house.house_confederation
				}
			}
			add = {
				value = 25
				if = {
					limit = {
						scope:recipient.top_liege = { # any_confederation_member is not performant for house blocs
							any_sub_realm_county = {
								count < 6
								holder.house.house_confederation = scope:recipient.house.house_confederation
							}
						}
					}
					add = 25
				}
			}
			desc = AI_BLOC_FEW_MEMBERS_REASON
		}
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 6
		duchy = 6
		kingdom = 12
		empire = 12
		hegemony = 0
	}

	ai_targets = {
		ai_recipients = liege
		ai_recipients = top_liege
		ai_recipients = scripted_relations
	}

	ai_targets = {
		ai_recipients = peer_vassals
		ai_recipients = vassals
		max = 25
	}

	ai_will_do = {
		base = -25
		modifier = { # Prefer Ruling Regent's bloc
			scope:actor = { has_same_government = scope:recipient }
			scope:recipient = { this = scope:actor.top_liege }
			add = 75
		}
		modifier = { # Kampaku should always want to join a block
			scope:actor = {
				has_title = title:e_japan
				is_confederation_member = no
				has_same_government = scope:recipient
			}
			add = 200
		}
		modifier = { # Landed blocless rulers should want to join
			scope:actor = {
				is_landed = yes
				NOT = { exists = house.house_confederation }
			}
			add = 75
		}
		modifier = { # Don't join blocs of different government
			scope:actor = {
				NOT = { has_same_government = scope:recipient }
			}
			add = -200
		}
		modifier = { # Don't join blocs of different aspiration
			scope:actor.house = {
				NOT = { has_same_house_aspiration_as = scope:recipient.house }
			}
			add = -150
		}
		house_relation_ai_accept_confederation_member_modifiers = { MULTIPLIER = 1 }
 		house_bloc_desire_to_join_modifiers = {
 			JOINER = scope:actor
 			INVITER = scope:recipient
 			MULTIPLIER = 0.5
 		}
	}
}

# Leave current Bloc
leave_house_bloc_interaction = {
	category = interaction_category_diplomacy
	use_diplomatic_range = no
	common_interaction = yes

	desc = leave_house_bloc_interaction_desc

	icon = icon_leave_bloc

	redirect = {
		if = {
			limit = { scope:recipient.house.house_confederation.leading_house ?= scope:recipient.house }
			scope:recipient.house.house_confederation.leading_house.house_head = { save_scope_as = recipient }
		}
	}

	is_available = {
		house.house_head ?= this
		exists = house.house_confederation
		tgp_house_bloc_interaction_valid_trigger = yes
		NOT = { has_character_flag = recently_joined_bloc }
	}

	is_shown = {
		scope:actor = {
			trigger_if = {
				limit = { confederation.leading_house = house }
				scope:recipient.house = house
			}
		}
		scope:recipient.house.house_confederation ?= scope:actor.house.house_confederation # Also works on self
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_at_war = no
			tgp_house_bloc_interaction_valid_showing_failures_trigger = yes
			custom_tooltip = {
				text = not_leading_house_of_confederation
				confederation.leading_house != house
			}
			custom_tooltip = {
				text = forced_bloc_membership_showing_failures_tt
				NOT = { has_character_flag = forced_bloc_membership }
			}
			custom_tooltip = {
				text = bloc_expansion_won_forced_membership_var_tt
				house ?= { # 5y cooldown after being forced to join via Bloc Expansion CB
					NOT = { has_variable = bloc_expansion_won_forced_membership_var }
				}
			}
			custom_tooltip = {
				text = sub_vassal_forced_confederation_tt
				trigger_if = {
					limit = { is_independent_ruler = no }
					scope:actor.liege = scope:recipient.liege
					trigger_if = {
						limit = { scope:actor.liege = confederation.leading_house.house_head }
						confederation.leading_house.house_head = { is_independent_ruler = yes }
					}
				}
			}
		}
	}

	auto_accept = yes

	on_accept = {
		scope:actor.house = {
			save_scope_as = leaver
			tgp_save_bloc_leaving_reason_effect = {
				LEAVING_HOUSE = scope:actor.house
				INVITING_HOUSE = scope:actor.house
			}
			tgp_leave_house_bloc_effect = {
				OPINION = flag:yes
				TRUCE = flag:yes
			}
		}
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 24
		duchy = 24
		kingdom = 6
		empire = 6
		hegemony = 0
	}

	ai_targets = {
		ai_recipients = liege
		ai_recipients = top_liege
		ai_recipients = scripted_relations
	}

	ai_targets = {
		ai_recipients = peer_vassals
		ai_recipients = vassals
		max = 25
	}

	ai_will_do = {
		base = -75
		# Cohesion
		modifier = {
			exists = scope:actor.house.house_confederation.leading_house
			scope:actor.house.house_confederation.leading_house != scope:actor.house
			scope:actor.house.house_confederation.cohesion < 25
			add = 100
		}
		modifier = {
			exists = scope:actor.house.house_confederation.leading_house
			scope:actor.house.house_confederation.leading_house != scope:actor.house
			scope:actor.house.house_confederation.cohesion < 5
			add = 1000
		}
		modifier = {
 			exists = scope:actor.house.house_confederation
 			scope:actor.house.house_confederation.cohesion < 50
 			add = {
 				value = scope:actor.house.house_confederation.cohesion
 				add = -50
 				multiply = 1.25
 				if = {
 					limit = { scope:actor.house.house_confederation.cohesion < 25 }
 					multiply = 4
 				}
 			}
 			desc = AI_BLOC_COHESION_REASON
 		}
		#Opinions
 		opinion_modifier = {
 			trigger = {
 				NOT = { scope:actor.house.house_confederation.leading_house ?= scope:actor.house }
 			}
 			opinion_target = scope:actor.house.house_confederation.leading_house.house_head
 			multiplier = -0.5
 			step = 5
 			max = 50
 		}
 		house_relation_ai_accept_modifiers = { # House Relations
 			HOUSE_1_MEMBER = scope:actor
 			HOUSE_2_MEMBER = scope:actor.house.house_confederation.leading_house.house_head
 			MULTIPLIER = -2
 		}
		modifier = { # Different House Aspiration
			exists = scope:actor.house.house_confederation.leading_house
			scope:actor.house ?= {
				NOT = { has_same_house_aspiration_as = scope:actor.house.house_confederation.leading_house }
			}
			add = 100
		}
		modifier = { # Different government
			exists = scope:actor.house.house_confederation.leading_house.house_head
			NOT = {
				scope:actor ?= { has_same_government = scope:actor.house.house_confederation.leading_house.house_head }
			}
			add = 200
		}
		modifier = { # Bloc too large
			scope:actor = {
				exists = house.house_confederation
				any_sub_realm_county = { # any_confederation_member is not performant for house blocs
					count > 18
					holder.house.house_confederation ?= scope:actor.house.house_confederation
				}
			}
			add = 25
		}
		modifier = { # Soryo bloc is not near any other bloc members
			is_landed = yes
			NOT = { government_allows = administrative }
			NOT = {
				any_held_county = {
					is_landless_type_title = no
					OR = {
						any_neighboring_county = {
							holder != scope:actor
							holder.house.house_confederation ?= scope:actor.house.house_confederation
						}
						duchy = {
							any_de_jure_county = {
								holder != scope:actor
								holder.house.house_confederation ?= scope:actor.house.house_confederation
							}
						}
					}
				}
			}
			add = 75
			DESC = AI_DISTANT_SORYO_BLOC_REASON
		}
		modifier = { # Bloc leaders don't want to leave
			exists = scope:actor.house.house_confederation.leading_house
			scope:actor.house.house_confederation.leading_house.house_head ?= scope:actor
			factor = 0
		}
	}
}

# Remove another House from your Bloc
kick_from_house_bloc_interaction = {
	category = interaction_category_diplomacy
	use_diplomatic_range = no
	common_interaction = yes

	desc = kick_from_house_bloc_interaction_desc

	icon = icon_remove_from_bloc

	cooldown = { months = 3 }

	cost = {
		influence = {
			value = 0
			if = {
				limit = { scope:actor = { government_allows = administrative } }
				add = 50
			}
		}
		prestige = {
			value = 0
			if = {
				limit = { NOT = { scope:actor = { government_allows = administrative } } }
				add = 100
			}
		}
	}

	redirect = {
		if = {
			limit = {
				exists = scope:recipient.house.house_head
				scope:recipient = { is_house_head = no }
			}
			scope:recipient.house.house_head = { save_scope_as = recipient }
		}
	}

	is_available = {
		house.house_head ?= this
		house.house_confederation.leading_house = house
		tgp_house_bloc_interaction_valid_trigger = yes
	}

	is_shown = {
		exists = scope:actor.house
		exists = scope:recipient.house
		scope:actor.house != scope:recipient.house
		scope:recipient.house.house_confederation ?= scope:actor.house.house_confederation # Also works on self
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			tgp_house_bloc_interaction_valid_showing_failures_trigger = yes
			custom_tooltip = {
				text = must_be_leader_of_bloc_trigger
				confederation.leading_house ?= house
			}
			custom_tooltip = {
				text = must_not_be_involved_in_war_together_trigger
				NOT = {
					any_character_war = {
						any_war_participant = { this = scope:recipient }
					}
				}
			}
		}
		scope:recipient = {
			tgp_house_bloc_interaction_valid_showing_failures_trigger = yes
			NOT = { has_usable_hook = scope:actor }
		}
	}

	auto_accept = yes

	on_accept = {
		scope:recipient.house = {
			set_variable = {
				name = bloc_leaving_reason
				value = flag:reason_kicked
				days = 4
			}
			tgp_leave_house_bloc_effect = {
				OPINION = flag:no
				TRUCE = flag:yes
			}
			house_head ?={
				if = {
					limit = {
						is_ai = yes
						exists = scope:leader.house_head
					}
					add_opinion = {
						modifier = kicked_from_house_bloc_opinion
						target = scope:leader.house_head
						opinion = -25
					}
				}
			}
			change_house_relation_effect = {
				HOUSE = scope:leaver
				VALUE = house_relation_damage_major_value
				REASON = kicked_from_bloc
				CHAR = scope:actor
				TARGET_CHAR = scope:recipient
				TITLE = scope:dummy_gender
			}
		}
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 12
		duchy = 12
		kingdom = 6
		empire = 6
		hegemony = 0
	}

	ai_targets = {
		ai_recipients = confederation_house_heads
		max = 25
	}

	ai_will_do = {
		base = -75
		#Opinions
 		opinion_modifier = {
 			opinion_target = scope:recipient.house.house_head
 			multiplier = -0.5
 			step = 5
 			max = 25
 		}
 		# House Relations
 		house_relation_ai_accept_modifiers = { # House Relations
 			HOUSE_1_MEMBER = scope:actor
 			HOUSE_2_MEMBER = scope:recipient
 			MULTIPLIER = -1
 		}
 		modifier = {
 			add = {
 				value = 0
 				scope:recipient.house = {
 					every_house_relation = {
 						limit = {
 							any_relation_house = {
 								NOT = { this = scope:recipient.house }
 								house_confederation = scope:actor.house.house_confederation
 							}
 						}
 						if = {
 							limit = { has_house_relation_level = quarrel }
 							add = 10
 						}
 						else_if = {
 							limit = { has_house_relation_level = rivalry }
 							add = 20
 						}
 						else_if = {
 							limit = { has_house_relation_level = feud }
 							add = 30
 						}
 					}
 				}
 			}
 		}
		modifier = { # Kick out landless houses
			exists = scope:recipient.house
			scope:recipient = {
				is_landed = no
				NOT = {
					any_close_family_member = {
						house = scope:recipient.house
						is_landed = yes
					}
				}
			}
			add = 50
		}
		modifier = {
			exists = scope:recipient.house
			NOT = {
				scope:actor.house ?= { has_same_house_aspiration_as = scope:recipient.house }
			}
			add = 50
		}
		modifier = {
			exists = scope:recipient.house.house_head
			NOT = {
				scope:actor.house.house_head ?= { has_same_government = scope:recipient.house.house_head }
			}
			add = 75
		}
	}
}

# Have your own house become the leading house of the bloc
assume_house_bloc_leadership_interaction = {
	category = interaction_category_diplomacy
	use_diplomatic_range = no
	common_interaction = yes
	send_options_exclusive = no
	ai_maybe = no

	greeting = negative
	notification_text = ASSUME_HOUSE_BLOC_LEADERSHIP_NOTIFICATION
	desc = assume_house_bloc_leadership_interaction_desc

	icon = icon_assume_bloc_leadership

	cooldown = { months = 6 }

	cost = {
		influence = {
			value = 0
			if = {
				limit = {
					scope:actor = { government_allows = administrative }
					scope:recipient = {
						is_ai = yes
						OR = {
							is_landed = yes
							has_title = title:k_chrysanthemum_throne
						}
					}
				}
				add = 100
			}
		}
		prestige = {
			value = 0
			if = {
				limit = {
					NOT = { scope:actor = { government_allows = administrative } }
					scope:recipient = {
						is_ai = yes
						OR = {
							is_landed = yes
							has_title = title:k_chrysanthemum_throne
						}
					}
				}
				add = 200
			}
		}
	}

	redirect = {
		if = {
			limit = {
				exists = scope:actor.house.house_confederation.leading_house.house_head
				scope:recipient.house.house_confederation ?= scope:actor.house.house_confederation
				scope:recipient != scope:actor.house.house_confederation.leading_house.house_head
			}
			scope:actor.house.house_confederation.leading_house.house_head = { save_scope_as = recipient }
		}
	}

	is_available = {
		house.house_head ?= this
		exists = house.house_confederation.leading_house
		house.house_confederation.leading_house != house
		tgp_house_bloc_interaction_valid_trigger = yes
		trigger_if = {
			limit = {
				is_ai = yes
			}
			is_landed = yes
		}
	}

	is_shown = {
		scope:recipient.house.house_confederation ?= scope:actor.house.house_confederation # Also works on self
	}

	is_valid = {
		scope:actor.house.house_confederation ?= {
			leading_house.house_head = { save_temporary_scope_as = leader_temp }
			OR = {
				custom_tooltip = {
					text = assume_house_bloc_leadership_interaction_land_tt
					scope:actor = { is_landed = yes }
					scope:recipient = { is_landed = no }
				}
				custom_tooltip = {
					text = assume_house_bloc_leadership_interaction_tier_tt
					scope:actor.highest_held_title_tier > scope:leader_temp.highest_held_title_tier
				}
				custom_tooltip = {
					text = assume_house_bloc_leadership_interaction_prestige_tt
					scope:actor.assume_house_bloc_leadership_interaction_prestige_level_value > scope:leader_temp.prestige_level
				}
				custom_tooltip = {
					text = assume_house_bloc_leadership_interaction_aspiration_tt
					scope:actor.house = {
						has_same_house_aspiration_as = scope:leader_temp.house
						OR = {
							AND = {
								has_house_aspiration_parameter = aspiration_level_3
								scope:leader_temp.house = {
									OR = {
										has_house_aspiration_parameter = aspiration_level_2
										has_house_aspiration_parameter = aspiration_level_1
									}
								}
							}
							AND = {
								has_house_aspiration_parameter = aspiration_level_2
								scope:leader_temp.house = { has_house_aspiration_parameter = aspiration_level_1 }
							}
						}
					}
				}
				any_confederation_member_house = {
					percent >= 0.51
					custom_tooltip = {
						NOT = { this = scope:actor.house }
						text = assume_house_bloc_leadership_interaction_requirement_tt
						house_head ?= {
							save_temporary_scope_as = member_head_temp
							OR = {
								this = scope:actor
								is_allied_to = scope:actor
								has_relation_friend = scope:actor
								has_relation_lover = scope:actor
								house = {
									has_better_house_relation_with_target_house_than_other_trigger = {
										TARGET = scope:actor.house
										OTHER = scope:leader_temp.house
									}
								}
								trigger_if = {
									limit = {
										scope:actor = { is_independent_ruler = no }
									}
									is_vassal_or_below_of = scope:actor
								}
								scope:actor = { has_hook = scope:member_head_temp }
								has_dread_level_towards = {
									target = scope:actor
									level >= 2
								}
								dynasty.dynast ?= scope:actor #Unop Use dynasty.dynast as we are in a character scope
							}
						}
					}
				}
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_at_war = no
			tgp_house_bloc_interaction_valid_showing_failures_trigger = yes
			custom_tooltip = {
				text = assume_house_bloc_leadership_vassal_tt
				NOT = { is_vassal_or_below_of = scope:recipient }
			}
			custom_tooltip = {
				text = assume_house_bloc_recent_leader_change_tt
				NOT = {
					house.house_confederation ?= { has_variable = recent_leader_change }
				}
			}
			custom_tooltip = {
				text = sub_vassal_leadership_blocked_tt
				trigger_if = {
					limit = { is_independent_ruler = no }
					NOT = { is_vassal_or_below_of = scope:recipient }
				}
			}
			custom_tooltip = {
				text = assume_house_bloc_recent_house_join_tt
				scope:actor.house = {
					NOT = { has_variable = recently_joined_bloc }
				}
			}
		}
		scope:recipient = {
			is_at_war = no
			tgp_house_bloc_interaction_valid_showing_failures_trigger = yes
		}
	}

	# Use prestige
	send_option = {
		is_valid = { scope:actor.prestige >= scope:recipient.medium_prestige_value }
		flag = prestige
		localization = TRADE_PRESTIGE_FOR_BETTER_AI_ACCEPTANCE
	}
	# Use influence
	send_option = {
		is_valid = {
			scope:actor = { government_has_flag = government_has_influence }
			scope:actor.influence >= scope:recipient.medium_influence_value
		}
		flag = influence
		localization = TRADE_INFLUENCE_FOR_BETTER_AI_ACCEPTANCE
	}
	# Use hook
	send_option = {
		is_valid = { scope:actor = { has_usable_hook = scope:recipient } }
		flag = hook
		localization = SCHEME_HOOK
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	auto_accept = {
		trigger_if = {
			limit = {
				scope:recipient = {
					is_ai = yes
					is_landed = no
					NOT = { has_title = title:k_chrysanthemum_throne }
				}
			}
			scope:recipient = {
				is_ai = yes
				is_landed = no
				NOT = { has_title = title:k_chrysanthemum_throne }
			}
		}
		trigger_if = {
			limit = {
				scope:recipient = { is_vassal_or_below_of = scope:actor }
			}
			always = yes
		}
		trigger_else = {
			custom_description = {
				text = "spending_hook"
				subject = scope:actor
				object = scope:recipient
				scope:hook = yes
			}
		}
	}

	on_accept = {
		scope:actor = {
			if = {
				limit = { scope:hook = yes }
				use_hook = scope:recipient
			}
			else = {
				if = {
					limit = { scope:prestige = yes }
					add_prestige = scope:recipient.medium_prestige_loss
				}
				if = {
					limit = { scope:influence = yes }
					change_influence = scope:recipient.medium_influence_loss
				}
			}
			house.house_confederation = {
				tgp_set_house_bloc_leading_house_effect = { LEADER = scope:actor.house }
			}
		}
		scope:recipient ?= {
			progress_towards_rival_effect = {
				REASON = rival_assumed_bloc_leadership
				CHARACTER = scope:actor.house.house_head
				OPINION = default_rival_opinion
			}
		}
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 6
		duchy = 6
		kingdom = 6
		empire = 6
		hegemony = 0
	}

	ai_targets = {
		ai_recipients = confederation_house_heads
		ai_recipients = liege
		max = 25
	}

	ai_will_do = {
		base = -50
		#Opinions
 		opinion_modifier = {
 			opinion_target = scope:recipient.house.house_head
 			multiplier = -0.5
 			step = 5
 			max = 25
 		}
 		modifier = {
 			has_trait = content
 			add = -25
 		}
 		modifier = {
 			has_trait = generous
 			add = -25
 		}
 		modifier = {
 			has_trait = ambitious
 			add = 25
 		}
 		modifier = {
 			has_trait = greedy
 			add = 25
 		}
		modifier = { # Don't leadership away from regent
			scope:recipient = {
				has_title = title:e_japan
			}
			factor = 0
		}
		modifier = {
			scope:actor = { is_confederation_member = yes }
			scope:recipient = { is_confederation_member = yes }
			scope:actor.confederation.combined_military_strength < scope:recipient.confederation.combined_military_strength
			factor = 0
		}
		modifier = { # Take leadership away from landless, unless they're the Ten'no
			scope:actor = {
				is_landed = yes
			}
			scope:recipient = {
				is_landed = no
				NOT = { has_title = title:k_chrysanthemum_throne }
			}
			factor = 0 # First zero it out
		}
		modifier = {
			scope:actor = {
				is_landed = yes
			}
			scope:recipient = {
				is_landed = no
				NOT = { has_title = title:k_chrysanthemum_throne }
			}
			
			add = 500 # Then make it guaranteed
		}
	}

	ai_accept = {
		base = -50
 		modifier = {
			scope:actor = { government_has_flag = government_is_japan_feudal }
			scope:recipient = { government_has_flag = government_is_japan_feudal }
 			scope:actor.house != scope:recipient.house
 			add = {
 				value = 0
 				scope:actor.house = {
					every_house_member = {
						limit = {
							top_liege = scope:actor.top_liege
							tgp_house_bloc_interaction_valid_trigger = yes
						}
						add = military_power
					}
				}
				scope:recipient.house = {
					every_house_member = {
						limit = {
							top_liege = scope:recipient.top_liege
							tgp_house_bloc_interaction_valid_trigger = yes
						}
						add = {
							value = military_power
							multiply = -1
						}
					}
				}
				divide = 2000
 			}
			desc = AI_RELATIVE_HOUSE_MILITARY_POWER
 		}
 		modifier = {
 			scope:prestige = yes
 			add = 25
			desc = PRESTIGE_INTERACTION_ACCEPTANCE_SEND_OPTION
 		}
 		modifier = {
 			scope:influence = yes
 			add = 25
			desc = INFLUENCE_INTERACTION_ACCEPTANCE_SEND_OPTION
 		}
		modifier = {
			scope:actor.house.house_confederation ?= {
				any_confederation_member_house = {
					percent >= 0.51
					house_head ?= {
						save_temporary_scope_as = member_head_temp
						OR = {
							this = scope:actor
							is_allied_to = scope:actor
							has_relation_friend = scope:actor
							has_relation_lover = scope:actor
							trigger_if = {
								limit = {
									scope:actor = { is_independent_ruler = no }
								}
								is_vassal_or_below_of = scope:actor
							}
							scope:actor = { has_hook = scope:member_head_temp }
							has_dread_level_towards = {
								target = scope:actor
								level >= 2
							}
							dynasty.dynast ?= scope:actor #Unop Use dynasty.dynast as we are in a character scope
						}
					}
				}
			}
			add = 50
			desc = AI_ACCEPT_assume_house_bloc_leadership_interaction_requirement_tt
		}
 		modifier = {
 			exists = scope:actor.house
 			exists = scope:recipient.house
 			add = {
 				# Check house relations within bloc
	 			scope:actor.house = {
	 				every_house_relation = {
	 					limit = {
		 					any_relation_house = {
		 						NOR = {
		 							this = scope:actor.house
		 							this = scope:recipient.house
		 						}
		 						house_confederation = scope:actor.house.house_confederation
		 					}
		 				}
		 				if = {
		 					limit = { has_house_relation_parameter = increased_marriage_acceptance }
			 				add = 10
		 				}
		 				else_if = {
		 					limit = { has_house_relation_parameter = decreased_marriage_acceptance }
			 				add = -10
		 				}
	 				}
	 			}
	 			# Versus current leader's
 				scope:recipient.house = {
 					every_house_relation = {
	 					limit = {
		 					any_relation_house = {
		 						NOR = {
		 							this = scope:actor.house
		 							this = scope:actor.house.house_confederation.leading_house
		 						}
		 						house_confederation = scope:actor.house.house_confederation
		 					}
		 				}
		 				if = {
		 					limit = { has_house_relation_parameter = increased_marriage_acceptance }
			 				add = -5
		 				}
		 				else_if = {
		 					limit = { has_house_relation_parameter = decreased_marriage_acceptance }
			 				add = 5
		 				}
	 				}
 				}
	 		}
	 		desc = "AI_RELATIVE_BLOC_HOUSE_RELATIONS"
 		}
 		modifier = {
 			scope:actor.dynasty != scope:recipient.dynasty
 			add = {
 				value = 0
 				add = scope:actor.dynasty.dynasty_prestige_level
 				subtract = scope:recipient.dynasty.dynasty_prestige_level
 				multiply = 5
 			}
 			desc = AI_RELATIVE_DYNASTY_PRESTIGE_REASON
 		}
	}
}

# Voluntary give leadership to another house in the bloc
grant_house_bloc_leadership_interaction = {
	category = interaction_category_diplomacy
	use_diplomatic_range = no
	common_interaction = yes

	greeting = positive
	desc = grant_house_bloc_leadership_interaction_desc

	icon = icon_grant_bloc_leadership

	cooldown = { months = 6 }

	redirect = {
		scope:recipient.house.house_head ?= { save_scope_as = recipient }
	}

	is_available = {
		house.house_head ?= this
		house.house_confederation.leading_house = house
		tgp_house_bloc_interaction_valid_trigger = yes
	}

	is_shown = {
		scope:recipient = {
			house.house_confederation ?= scope:actor.house.house_confederation
			NOT = { house ?= scope:actor.house }
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_at_war = no
			tgp_house_bloc_interaction_valid_showing_failures_trigger = yes
			custom_tooltip = {
				text = assume_house_bloc_recent_leader_change_tt
				NOT = {
					house.house_confederation ?= { has_variable = recent_leader_change }
				}
			}
			custom_tooltip = {
				text = grant_house_bloc_leadership_liege_tt
				NOT = { is_liege_or_above_of = scope:recipient }
			}
		}
		scope:recipient = {
			is_at_war = no
			tgp_house_bloc_interaction_valid_showing_failures_trigger = yes
		}
	}

	on_accept = {
		scope:actor = {
			house = {
				change_house_relation_effect = {
					HOUSE = scope:recipient.house
					VALUE = house_relation_improve_medium_value
					REASON = granted_bloc_leadership
					CHAR = scope:actor
					TARGET_CHAR = scope:recipient
					TITLE = scope:dummy_gender
				}
			}
			house.house_confederation = {
				tgp_set_house_bloc_leading_house_effect = { LEADER = scope:recipient.house }
			}
		}
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 12
		duchy = 12
		kingdom = 12
		empire = 12
		hegemony = 0
	}

	ai_targets = {
		ai_recipients = confederation_house_heads
		max = 25
	}

	ai_accept = {
		base = 25
 		modifier = {
 			has_trait = content
 			add = -25
 		}
 		modifier = {
 			has_trait = generous
 			add = -25
 		}
 		modifier = {
 			has_trait = ambitious
 			add = 25
 		}
 		modifier = {
 			has_trait = greedy
 			add = 25
 		}
		modifier = {
			scope:actor = { is_confederation_member = yes }
			scope:recipient = { is_confederation_member = yes }
			add = {
 				value = scope:recipient.confederation.combined_military_strength
 				add = {
 					value = scope:actor.confederation.combined_military_strength
 					multiply = -1
 				}
 				multiply = 100
 			}
 		}
	}

	ai_will_do = {
		base = -50
		#Opinions
 		opinion_modifier = {
 			trigger = {
 				NOT = { scope:actor.house.house_confederation.leading_house ?= scope:actor.house }
 			}
 			opinion_target = scope:actor.house.house_confederation.leading_house.house_head
 			multiplier = -0.5
 			step = 5
 			max = 25
 		}
 		house_relation_ai_accept_modifiers = { # House Relations
 			HOUSE_1_MEMBER = scope:actor
 			HOUSE_2_MEMBER = scope:actor.house.house_confederation.leading_house.house_head
 			MULTIPLIER = -1
 		}
 		modifier = {
 			has_trait = content
 			add = 25
 		}
 		modifier = {
 			has_trait = generous
 			add = 25
 		}
 		modifier = {
 			has_trait = ambitious
 			add = -25
 		}
 		modifier = {
 			has_trait = greedy
 			add = -25
 		}
 		modifier = {
 			liege != top_liege
 			scope:recipient.liege = top_liege
 			liege = scope:recipient
 			add = 1000
 		}
		modifier = { # Regent never grants bloc leadership
			scope:actor = {
				has_title = title:e_japan
			}
			factor = 0
		}
 		modifier = {
			scope:actor = { is_confederation_member = yes }
			scope:recipient = { is_confederation_member = yes }
			scope:recipient.confederation.combined_military_strength <= scope:actor.confederation.combined_military_strength
			factor = 0
 		}
	}
}

# Improve House Relation Perk Interaction
improve_house_relation_in_bloc_interaction = {
	category = interaction_category_diplomacy
	use_diplomatic_range = no
	common_interaction = yes

	greeting = positive
	desc = improve_house_relation_in_bloc_interaction_desc

	icon = icon_grant_bloc_leadership

	cooldown = { months = 0 }

	redirect = {
		scope:recipient.house.house_head ?= { save_scope_as = recipient }
	}

	cost = {
		gold = scope:actor.medium_gold_value
		influence = {
			value = 0
			if = {
				limit = { scope:actor = { government_has_flag = government_has_influence } }
				add = 50
			}
		}
		prestige = {
			value = 0
			if = {
				limit = { NOT = { scope:actor = { government_has_flag = government_has_influence } } }
				add = 100
			}
		}
	}

	is_shown = {
		scope:actor = {
			dynasty ?= { has_dynasty_perk = tgp_japan_legacy_3 }
			government_is_japanese_trigger = yes
			tgp_house_bloc_interaction_valid_trigger = yes
			is_house_head = yes
			exists = confederation
			confederation.leading_house = house
		}
		scope:recipient = {
			house.house_confederation ?= scope:actor.house.house_confederation
			NOT = { house ?= scope:actor.house }
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			NOT = { is_at_war_with = scope:recipient }
			tgp_house_bloc_interaction_valid_showing_failures_trigger = yes
			custom_tooltip = {
				text = has_to_have_negative_house_relations_tt
				house = {
					any_house_relation = {
						OR = {
							has_house_relation_level = quarrel
							has_house_relation_level = rivalry
							has_house_relation_level = feud
						}
						any_relation_house = { this = scope:recipient.house }
					}
				}
			}
		}
		scope:recipient = {
			tgp_house_bloc_interaction_valid_showing_failures_trigger = yes
		}
	}

	auto_accept = yes

	on_accept = {
		scope:actor.house = {
			change_house_relation_effect = {
				HOUSE = scope:recipient.house
				VALUE = house_relation_improve_major_value
				REASON = perk_interaction
				CHAR = scope:actor
				TARGET_CHAR = scope:recipient
				TITLE = scope:dummy_gender
			}
		}
		if = {
			limit = {
				scope:actor.house = {
					any_house_relation = {
						any_relation_house = { this = scope:recipient.house }
						has_house_relation_level = quarrel
					}
				}
			}
			custom_tooltip = house_relation_perk_interaction_quarrel_effect
		}
		else_if = {
			limit = {
				scope:actor.house = { #Unop Use correct scope
					any_house_relation = {
						any_relation_house = { this = scope:recipient.house }
						has_house_relation_level = rivalry
					}
				}
			}
			custom_tooltip = house_relation_perk_interaction_rivalry_effect
		}
		else = {
			custom_tooltip = house_relation_perk_interaction_feud_effect
		}
	}

	ai_potential = {
		is_house_head = yes
		tgp_uses_house_blocs_trigger = yes
		government_is_japanese_trigger = yes
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 24
		duchy = 24
		kingdom = 12
		empire = 12
		hegemony = 0
	}

	ai_targets = {
		ai_recipients = confederation_house_heads
		max = 25
	}

	ai_will_do = {
		base = -50
		#Opinions
 		house_relation_ai_accept_modifiers = { # House Relations
 			HOUSE_1_MEMBER = scope:actor
 			HOUSE_2_MEMBER = scope:actor.house.house_confederation.leading_house.house_head
 			MULTIPLIER = -1
 		}
	}
}

# Demand Aspiration change in bloc
demand_aspiration_change_interaction = {
	category = interaction_category_diplomacy
	use_diplomatic_range = no
	common_interaction = yes
	send_options_exclusive = no

	greeting = positive
	notification_text = DEMAND_ASPIRATION_CHANGE_NOTIFICATION
	desc = demand_aspiration_change_interaction_desc

	icon = icon_invite_to_bloc

	cooldown_against_recipient = { years = 5 }

	cost = {
		influence = {
			value = 0
			if = {
				limit = { scope:actor = { government_allows = administrative } }
				add = 50
				if = {
					limit = {
						scope:actor.dynasty = scope:recipient.dynasty
					}
					multiply = 0.5
				}
			}
		}
		prestige = {
			value = 0
			if = {
				limit = {
					NOT = { scope:actor = { government_allows = administrative } }
				}
				add = 100
				if = {
					limit = {
						scope:actor.dynasty = scope:recipient.dynasty
					}
					multiply = 0.5
				}
			}
		}
	}

	redirect = {
		scope:recipient = {
			if = {
				limit = {
					is_house_head = no
					exists = house.house_head
				}
				house.house_head = { save_scope_as = recipient }
			}
		}
	}

	is_shown = {
		scope:actor = {
			this != scope:recipient
			is_house_head = yes
			top_liege = scope:recipient.top_liege
			tgp_house_bloc_interaction_valid_trigger = yes
			house.house_confederation.leading_house = house
			trigger_if = { # Same confederation
				limit = { exists = house.house_confederation }
				scope:recipient.house.house_confederation ?= house.house_confederation
			}
		}
		scope:recipient = { tgp_house_bloc_interaction_valid_trigger = yes }
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			is_at_war = no
			tgp_house_bloc_interaction_valid_showing_failures_trigger = yes
			custom_tooltip = {
				text = demand_aspiration_change_interaction_power_tt
				NOT = {
					house = { has_same_house_aspiration_as = scope:recipient.house }
				}
			}
		}
		scope:recipient = {
			is_at_war = no
			tgp_house_bloc_interaction_valid_showing_failures_trigger = yes
		}
	}

	# Use gold
	send_option = {
		is_valid = { scope:actor.gold >= scope:recipient.medium_gold_value }
		flag = gold
		localization = TRADE_GOLD_FOR_BETTER_AI_ACCEPTANCE
	}
	# Use prestige
	send_option = {
		is_valid = { scope:actor.prestige >= scope:recipient.medium_prestige_value }
		flag = prestige
		localization = TRADE_PRESTIGE_FOR_BETTER_AI_ACCEPTANCE
	}
	# Use influence
	send_option = {
		is_valid = {
			scope:actor = { government_has_flag = government_has_influence }
			scope:actor.influence >= scope:recipient.medium_influence_value
		}
		flag = influence
		localization = TRADE_INFLUENCE_FOR_BETTER_AI_ACCEPTANCE
	}
	## Offer a hook
	send_option = {
		flag = offer_hook
		is_valid = {
			custom_tooltip = {
				text = offer_hook.tt.cannot_offer_both_hooks
				scope:offer_hook_strong = no
			}
			NOT = {
				scope:recipient = { has_hook = scope:actor }
			}
		}
		localization = SCHEME_AGENT_HOOK
	}
	# Offer a strong hook
	send_option = {
		flag = offer_hook_strong
		is_shown = {
			scope:actor = { has_trait_with_flag = can_offer_strong_hook_to_agents }
		}
		is_valid = {
			custom_tooltip = {
				text = offer_hook.tt.cannot_offer_both_hooks
				scope:offer_hook = no
			}
			NOT = {
				scope:recipient = { has_strong_hook = scope:actor }
			}
		}
		localization = SCHEME_AGENT_HOOK_STRONG
	}
	# Use hook
	send_option = {
		is_valid = { scope:actor = { has_usable_hook = scope:recipient } }
		flag = hook
		localization = SCHEME_HOOK
	}
	should_use_extra_icon = {
		scope:actor = { has_usable_hook = scope:recipient }
	}
	extra_icon = "gfx/interface/icons/character_interactions/hook_icon.dds"

	on_accept = {
		scope:recipient.house = { save_scope_as = house }
		scope:actor = {
			# HOOK
			if = {
				limit = { scope:hook = yes }
				use_hook = scope:recipient
			}
			# BRIBES
			else = {
				if = {
					limit = { scope:gold = yes }
					pay_short_term_gold = {
						target = scope:recipient
						gold = scope:recipient.medium_gold_value
					}
				}
				if = {
					limit = { scope:prestige = yes }
					add_prestige = scope:recipient.medium_prestige_loss
					scope:recipient = { add_prestige = medium_prestige_value }
				}
				if = {
					limit = { scope:influence = yes }
					change_influence = scope:recipient.medium_influence_loss
					scope:recipient = { change_influence = medium_influence_gain }
				}
				if = { # Offer Hook
					limit = { scope:offer_hook = yes }
					scope:recipient = {
						add_hook = {
							type = favor_hook
							target = scope:actor
						}
					}
				}
				if = { # Offer Strong Hook
					limit = { scope:offer_hook_strong = yes }
					scope:recipient = {
						add_hook = {
							type = strong_favor_hook
							target = scope:actor
						}
					}
				}
			}
			house = {
				switch = {
					trigger = has_house_aspiration_parameter
					ceremony_cheaper_feasts = {
						scope:house = { set_house_aspiration = { type = ceremony } }
					}
					unlocks_japanese_manor_watch_house = {
						scope:house = { set_house_aspiration = { type = determination } }
					}
					unlocks_japanese_manor_shrine = {
						scope:house = { set_house_aspiration = { type = humility } }
					}
					unlocks_japanese_manor_brewery = {
						scope:house = { set_house_aspiration = { type = prosperity } }
					}
					unlocks_japanese_manor_archive = {
						scope:house = { set_house_aspiration = { type = service } }
					}
					unlocks_japanese_manor_armory = {
						scope:house = { set_house_aspiration = { type = strength } }
					}
				}
				set_variable = {
					name = recently_changed_aspiration
					years = 5
				}
			}
		}
	}

	on_decline = {
		scope:recipient = {
			add_character_flag = {
				flag = demanded_aspiration_change_recently
				years = 4
			}
		}
	}

	ai_accept = {
 		base = -20
 		opinion_modifier = {
 			who = scope:recipient
 			opinion_target = scope:actor
 			multiplier = 1
 		}
 		# They are a Cadet House of my Dynasty
 		modifier = {
 			scope:recipient.dynasty = scope:actor.dynasty
 			add = 50
			desc = AI_SAME_DYNASTY_REASON
 		}
 		# Bribes
 		modifier = {
 			scope:gold = yes
 			add = 25
			desc = TRADE_GOLD_FOR_BETTER_AI_ACCEPTANCE_TT
 		}
 		modifier = {
 			scope:prestige = yes
 			add = 25
			desc = PRESTIGE_INTERACTION_ACCEPTANCE_SEND_OPTION
 		}
 		modifier = {
 			scope:influence = yes
 			add = 25
			desc = INFLUENCE_INTERACTION_ACCEPTANCE_SEND_OPTION
 		}
		modifier = {
			add = 20
			scope:offer_hook = yes
			exists = scope:recipient
			desc = SCHEME_WITH_OFFER_HOOK
		}
		modifier = {
			add = 50
			scope:offer_hook_strong = yes
			exists = scope:recipient
			desc = SCHEME_WITH_OFFER_HOOK_STRONG
		}
	}

	auto_accept = {
		custom_description = {
			text = "spending_hook"
			subject = scope:actor
			object = scope:recipient
			scope:hook = yes
		}
	}

	ai_potential = {
		is_house_head = yes
		tgp_uses_house_blocs_trigger = yes
		house.house_confederation.leading_house ?= house
		government_is_japanese_trigger = yes
	}

	ai_frequency_by_tier = {
		barony = 0
		county = 6
		duchy = 6
		kingdom = 6
		empire = 6
		hegemony = 0
	}

	ai_targets = {
		ai_recipients = liege
		ai_recipients = top_liege
		ai_recipients = scripted_relations
	}

	ai_targets = {
		ai_recipients = peer_vassals
		ai_recipients = vassals
		max = 25
	}

	ai_will_do = {
		base = -50
		# Rating
		modifier = {
			scope:recipient.house = {
				NOT = { has_same_house_aspiration_as = scope:actor.house }
			}
			add = 100
		}
		modifier = {
			scope:actor.house.house_confederation.cohesion < 25
			add = 100
		}
		modifier = {
			scope:actor.house.house_confederation.cohesion < 50
			add = 100
		}
		modifier = { # Frequency
			factor = 0
			scope:recipient = { has_character_flag = demanded_aspiration_change_recently }
		}
	}
}
