### GRACE INTERACTION DECISIONS FOR CHINA ###

# Add the decisions in a nice order which will make sense in the menu! For example, ranked by cost/reward.


# PAYING TRIBUTE DECISIONS (GAIN GRACE)
offmap_decisions = {

	chinese_grace_send_gift = {
		button_name = offmap_gifts

		ai_check_interval = 120

		only_playable = yes

		from_potential = {
			has_dlc = "Jade Dragon"
			is_landed = yes
			mercenary = no
			holy_order = no
		}

		potential = {
			is_offmap_tag = offmap_china
		}

		allow = {
			show_only_failed_conditions = yes

			FROM = {
				show_scope_change = no

				scaled_wealth = {
					value = 4
					min = 500
				}

				custom_tooltip = {
					text = chinese_grace_send_gift_allow_tt
					NOT = { has_character_modifier = chinese_grace_send_gift_timer }
				}

				prisoner = no
				is_incapable = no
				is_inaccessible_trigger = no
			}

			# china_offmap_decisions_enabled_trigger = yes # leave in please, to be used if the tooltip for china_offmap_tribute_decisions_enabled_trigger changes and we need to reference things uniquely again
			china_offmap_tribute_decisions_enabled_trigger = yes
		}

		effect = {
			FROM = {
				show_scope_change = no

				sound_effect = china_grace_gain

				# If this changes the ai chances should probably be adjusted
				scaled_wealth = {
					value = -4
					min = -500
				}

				add_character_modifier = {
					name = chinese_grace_send_gift_timer
					years = 15 # Change chinese_grace_send_gift_allow_tt if this number changes
					hidden = yes
				}

				tooltip = {
					if = {
						limit = {
							liked_by_offmap = {
								type = offmap_china
								context = wealth
							}
						}

						if = {
							limit = {
								disliked_by_offmap = {
									type = offmap_china
									context = wealth
								}
							}

							add_offmap_currency = {
								offmap = offmap_china
								value = 300
							}

							custom_tooltip = { text = chinese_emperor_has_ambiguous_feelings_of_THIS_tt }
						}
						else = {
							add_offmap_currency = {
								offmap = offmap_china
								value = 450
							}

							custom_tooltip = { text = chinese_emperor_likes_THIS_tt }
						}
					}
					else_if = {
						limit = {
							disliked_by_offmap = {
								type = offmap_china
								context = wealth
							}
						}

						add_offmap_currency = {
							offmap = offmap_china
							value = 150
						}

						custom_tooltip = { text = chinese_emperor_dislikes_THIS_tt }
					}
					else = {
						add_offmap_currency = {
							offmap = offmap_china
							value = 300
						}
					}
				}

				letter_event = { id = JD.20024 }
			}
		}

		ai_will_do = {
			factor = 0.66

			mult_modifier = {
				factor = 0.1
				# I.e. it would take more than 4 years to collect the 500 gold
				FROM = { yearly_income < 125 }
			}
		}
	}

	# Offering to become tributary
	chinese_grace_become_tributary = {
		button_name = offmap_gifts

		ai = no

		from_potential = {
			has_dlc = "Jade Dragon"
			independent = yes
		}

		potential = {
			is_offmap_tag = offmap_china
		}

		allow = {
			show_only_failed_conditions = yes

			FROM = {
				show_scope_change = no

				war = no

				OR = {
					custom_tooltip = { # Borders the Western Governate
						text = chinese_grace_become_tributary_allow_governor_neighbor_tt

						any_neighbor_independent_ruler = {
							has_landed_title = e_china_west_governor
						}
					}

					custom_tooltip = { # Borders a Chinese tributary
						text = chinese_grace_become_tributary_allow_tributary_neighbor_tt

						any_neighbor_independent_ruler = {
							suzerain = {
								has_landed_title = e_china_west_governor
							}
						}
					}

					custom_tooltip = { # Borders the eastern edge of the map
						text = chinese_grace_become_tributary_allow_chinese_influence_tt

						any_realm_province = {
							region = custom_chinese_invasion_target_region
							held_under_PREV = yes
						}
					}

					custom_tooltip = { # Within diplo range of China and has a port in India
						text = chinese_grace_become_tributary_allow_india_tt

						any_realm_province = {
							is_coastal = yes
							region = world_india
							held_under_PREV = yes
						}
					}
				}

				custom_tooltip = {
					text = chinese_grace_become_tributary_allow_suzerain_tt
					is_tributary = no
				}

				custom_tooltip = {
					text = chinese_tribute_become_tributary_cooldown_tt
					NOT = { has_character_modifier = chinese_grace_tributary_timer }
				}

				NOT = { real_tier = EMPEROR }
				prisoner = no
				is_incapable = no
				is_inaccessible_trigger = no
				NOT = { has_character_flag = asked_to_become_tributary } # TODO: Shows nothing in tooltip
			}

			# china_offmap_decisions_enabled_trigger = yes # leave in please, to be used if the tooltip for china_offmap_tribute_decisions_enabled_trigger changes and we need to reference things uniquely again
			china_offmap_tribute_decisions_enabled_trigger = yes
		}

		effect = {
			log = "---------------------"
			log = "China Logging:"
			log = "[From.GetTitledName] has voluntarily become a tributary of the [offmap_china.GetFullname]"
			log = "---------------------"

			make_tributary = {
				who = FROM
				tributary_type = offmap
			}

			custom_tooltip = { text = chinese_grace_become_tributary_effect_TT }

			FROM = {
				show_scope_change = no

				sound_effect = china_grace_gain

				tooltip = {
					if = {
						limit = {
							liked_by_offmap = {
								type = offmap_china
								context = tributary
							}
						}

						if = {
							limit = {
								disliked_by_offmap = {
									type = offmap_china
									context = tributary
								}
							}

							add_offmap_currency = {
								offmap = offmap_china
								value = 200
							}

							custom_tooltip = { text = chinese_emperor_has_ambiguous_feelings_of_THIS_tt }
						}
						else = {
							add_offmap_currency = {
								offmap = offmap_china
								value = 400
							}

							custom_tooltip = { text = chinese_emperor_likes_THIS_tt }
						}
					}
					else_if = {
						limit = {
							disliked_by_offmap = {
								type = offmap_china
								context = tributary
							}
						}

						add_offmap_currency = {
							offmap = offmap_china
							value = 100
						}

						custom_tooltip = { text = chinese_emperor_dislikes_THIS_tt }
					}
					else = {
						add_offmap_currency = {
							offmap = offmap_china
							value = 200
						}
					}
				}

				letter_event = { id = JD.20028 }
			}
		}

		ai_will_do = {
			factor = 0
		}
	}

	chinese_grace_supply_horses = {
		button_name = offmap_gifts

		ai_check_interval = 36

		only_playable = yes

		from_potential = {
			has_dlc = "Jade Dragon"
			is_nomadic = yes
			is_landed = yes
			mercenary = no
			holy_order = no
		}

		potential = {
			is_offmap_tag = offmap_china
		}

		allow = {
			show_only_failed_conditions = yes

			FROM = {
				show_scope_change = no

				war = no

				custom_tooltip = {
					text = chinese_grace_supply_horses_not_already_supplying_tt
					NOT = { has_character_modifier = china_supply_horses }
				}

				custom_tooltip = {
					text = chinese_grace_supply_horses_stopped_supplying_tt
					NOT = { has_character_flag = stopped_supplying_horses }
				}

				OR = {
					custom_tooltip = { # Borders the Western Governate
						text = chinese_grace_become_tributary_allow_governor_neighbor_tt

						any_neighbor_independent_ruler = {
							has_landed_title = e_china_west_governor
						}
					}

					custom_tooltip = { # Borders a Chinese tributary
						text = chinese_grace_become_tributary_allow_tributary_neighbor_tt

						any_neighbor_independent_ruler = {
							suzerain = {
								has_landed_title = e_china_west_governor
							}
						}
					}

					custom_tooltip = { # Borders the eastern edge of the map
						text = chinese_grace_become_tributary_allow_chinese_influence_tt

						any_realm_province = {
							region = custom_chinese_invasion_target_region
							held_under_PREV = yes
						}
					}
				}

				prisoner = no
				is_incapable = no
				is_inaccessible_trigger = no
			}

			# china_offmap_decisions_enabled_trigger = yes # leave in please, to be used if the tooltip for china_offmap_tribute_decisions_enabled_trigger changes and we need to reference things uniquely again
			china_offmap_tribute_decisions_enabled_trigger = yes
		}

		effect = {
			FROM = {
				show_scope_change = no

				sound_effect = china_grace_gain

				tooltip = {
					add_character_modifier = {
						name = china_supply_horses
						duration = -1
						inherit = yes
					}

					if = {
						limit = {
							liked_by_offmap = {
								type = offmap_china
								context = tributary
							}
						}

						if = {
							limit = {
								disliked_by_offmap = {
									type = offmap_china
									context = tributary
								}
							}

							add_offmap_currency = {
								offmap = offmap_china
								value = 100
							}

							custom_tooltip = { text = chinese_emperor_has_ambiguous_feelings_of_THIS_tt }
						}
						else = {
							add_offmap_currency = {
								offmap = offmap_china
								value = 150
							}

							custom_tooltip = { text = chinese_emperor_likes_THIS_tt }
						}
					}
					else_if = {
						limit = {
							disliked_by_offmap = {
								type = offmap_china
								context = tributary
							}
						}

						add_offmap_currency = {
							offmap = offmap_china
							value = 50
						}

						custom_tooltip = { text = chinese_emperor_dislikes_THIS_tt }
					}
					else = {
						add_offmap_currency = {
							offmap = offmap_china
							value = 100
						}
					}
				}

				letter_event = { id = JD.3041 }
			}
		}

		ai_will_do = {
			factor = 1

			trigger = {
				FROM = {
					OR = {
						trait = humble
						trait = shy
						trait = craven
					}

					NOR = {
						trait = ambitious
						trait = proud
					}

					primary_title = {
						NOT = { title = e_mongol_empire }
					}
				}
			}
		}
	}

	chinese_grace_stop_supply_horses = {
		button_name = offmap_gifts

		ai_check_interval = 36

		only_playable = yes

		from_potential = {
			has_dlc = "Jade Dragon"
			has_character_modifier = china_supply_horses
			is_landed = yes
			mercenary = no
			holy_order = no
		}

		potential = {
			is_offmap_tag = offmap_china
		}

		allow = {
			# show_only_failed_conditions = yes

			FROM = {
				show_scope_change = no

				has_character_modifier = china_supply_horses
			}

			# china_offmap_decisions_enabled_trigger = yes # leave in please, to be used if the tooltip for china_offmap_tribute_decisions_enabled_trigger changes and we need to reference things uniquely again
			# china_offmap_tribute_decisions_enabled_trigger = yes
		}

		effect = {
			FROM = {
				sound_effect = china_angered_emperor
				set_character_flag = stopped_supplying_horses
				remove_character_modifier = china_supply_horses

				if = {
					limit = {
						liked_by_offmap = {
							type = offmap_china
						}
					}

					if = {
						limit = {
							disliked_by_offmap = {
								type = offmap_china
							}
						}

						add_offmap_currency = {
							offmap = offmap_china
							value = -100
						}

						custom_tooltip = { text = chinese_emperor_has_ambiguous_feelings_of_THIS_tt }
					}
					else = {
						add_offmap_currency = {
							offmap = offmap_china
							value = -150
						}

						custom_tooltip = { text = chinese_emperor_likes_THIS_tt }
					}
				}
				else_if = {
					limit = {
						disliked_by_offmap = {
							type = offmap_china
						}
					}

					add_offmap_currency = {
						offmap = offmap_china
						value = -50
					}

					custom_tooltip = { text = chinese_emperor_dislikes_THIS_tt }
				}
				else = {
					add_offmap_currency = {
						offmap = offmap_china
						value = -100
					}
				}
			}
		}

		ai_will_do = {
			factor = 1

			trigger = {
				FROM = {
					OR = {
						trait = ambitious
						trait = proud
						trait = brave
					}

					NOR = {
						trait = humble
						trait = shy
						trait = craven
					}
				}
			}
		}
	}

	chinese_grace_offer_eunuch = {
		button_name = offmap_gifts

		third_party_filter = home_court
		ai_third_party_filter = home_court
		third_party = FROM
		ai_check_interval = 36

		show_third_party_potential = yes

		only_playable = yes

		from_potential = {
			has_dlc = "Jade Dragon"
			is_landed = yes
			mercenary = no
			holy_order = no
		}

		potential = {
			is_offmap_tag = offmap_china

			trigger_if = {
				limit = { ai = yes }

				# Allow is checked for each valid 3rd party, so it is cheaper to check it here for the AI
				china_offmap_tribute_decisions_enabled_trigger = yes
			}
		}

		allow = {
			show_only_failed_conditions = yes

			FROM = {
				show_scope_change = no

				custom_tooltip = {
					text = china_tribute_send_eunuch_cooldown_tt
					NOT = { has_character_modifier = chinese_grace_send_eunuch_timer }
				}

				prisoner = no
				is_incapable = no
				is_inaccessible_trigger = no
			}

			# china_offmap_decisions_enabled_trigger = yes # leave in please, to be used if the tooltip for china_offmap_tribute_decisions_enabled_trigger changes and we need to reference things uniquely again

			trigger_if  = {
				limit = { ai = no }

				# AI has already checked this in the potential
				china_offmap_tribute_decisions_enabled_trigger = yes
			}
		}

		third_party_potential = {
			# show_only_failed_conditions = yes

			FROMFROM = {
				show_scope_change = no

				custom_tooltip = {
					text = is_landless_male_tt

					is_landed = no
					is_ruler = no
					is_female = no
					is_patrician = no
				}

				custom_tooltip = {
					text = adult_or_close_relative_of_12_years_tt

					trigger_if = {
						limit = { is_adult = no }

						is_close_relative = ROOT_FROM
						age >= 12
					}
				}

				is_heir = no

				custom_tooltip = {
					text = not_married_or_getting_married_tt

					is_betrothed = no
					is_married = no
				}

				custom_tooltip = { # can't be from China
					text = is_not_from_china_tt

					NOT = { has_character_flag = eunuch_gift }
					courtier_from_china_trigger = no
				}

				custom_tooltip = {
					text = is_not_incapable_inbred_or_imbecile_tt

					is_incapable = no

					NOR = {
						trait = inbred
						trait = imbecile
					}
				}

				custom_tooltip = {
					text = is_not_maimed_or_infirm_tt

					NOR = {
						trait = maimed
						trait = infirm
					}
				}

				custom_tooltip = {
					text = is_not_wounded_severely_injured_tt

					NOR = {
						trait = wounded
						trait = severely_injured
					}
				}

				custom_tooltip = {
					text = is_not_one_eyed_handed_legged_disfigured_or_mangled_tt

					NOR = {
						trait = one_eyed
						trait = one_handed
						trait = one_legged
						trait = disfigured
						trait = mangled
					}
				}

				OR = {
					custom_tooltip = {
						text = is_close_relative_tt
						is_close_relative = ROOT_FROM
					}

					custom_tooltip = {
						text = china_tribute_send_eunuch_stats_tt

						OR = {
							diplomacy >= 20
							martial >= 20
							stewardship >= 20
							intrigue >= 20
							learning >= 20
						}
					}

					custom_tooltip = {
						text = china_tribute_send_eunuch_congenital_tt

						OR = {
							trait = strong
							trait = genius
							trait = quick
							trait = attractive
						}
					}

					custom_tooltip = {
						text = china_tribute_send_eunuch_non_inherit_congenital_tt

						OR = {
							trait = brawny
							trait = shrewd
						}
					}

					custom_tooltip = {
						text = has_the_right_eunuch_traits_tt

						OR = {
							trait = architect
							trait = administrator
							trait = strategist
							trait = scholar
							trait = faqih
						}
					}
				}
			}
		}

		third_party_allow = {
			show_only_failed_conditions = yes

			FROMFROM = {
				show_scope_change = no

				prisoner = no
				is_ill = no
				is_inaccessible_trigger = no
			}
		}

		third_party_score = {
			factor = 100

			additive_modifier = {
				value = 20

				FROMFROM = {
					show_scope_change = no

					diplomacy >= 8

					hidden_trigger = {
						diplomacy < 12
					}
				}
			}

			additive_modifier = {
				value = 40

				FROMFROM = {
					show_scope_change = no

					diplomacy >= 12

					hidden_trigger = {
						diplomacy < 16
					}
				}
			}

			additive_modifier = {
				value = 75

				FROMFROM = {
					show_scope_change = no

					diplomacy >= 16

					hidden_trigger = {
						diplomacy < 20
					}
				}
			}

			additive_modifier = {
				value = 120

				FROMFROM = {
					show_scope_change = no

					diplomacy >= 20
				}
			}

			additive_modifier = {
				value = 20

				FROMFROM = {
					show_scope_change = no

					martial >= 8

					hidden_trigger = {
						martial < 12
					}
				}
			}

			additive_modifier = {
				value = 40

				FROMFROM = {
					show_scope_change = no

					martial >= 12

					hidden_trigger = {
						martial < 16
					}
				}
			}

			additive_modifier = {
				value = 75

				FROMFROM = {
					show_scope_change = no

					martial >= 16

					hidden_trigger = {
						martial < 20
					}
				}
			}

			additive_modifier = {
				value = 120

				FROMFROM = {
					show_scope_change = no

					martial >= 20
				}
			}

			additive_modifier = {
				value = 20

				FROMFROM = {
					show_scope_change = no

					stewardship >= 8

					hidden_trigger = {
						stewardship < 12
					}
				}
			}

			additive_modifier = {
				value = 40

				FROMFROM = {
					show_scope_change = no

					stewardship >= 12

					hidden_trigger = {
						stewardship < 16
					}
				}
			}

			additive_modifier = {
				value = 75

				FROMFROM = {
					show_scope_change = no

					stewardship >= 16

					hidden_trigger = {
						stewardship < 20
					}
				}
			}

			additive_modifier = {
				value = 120

				FROMFROM = {
					show_scope_change = no

					stewardship >= 20
				}
			}

			additive_modifier = {
				value = 20

				FROMFROM = {
					show_scope_change = no

					intrigue >= 8

					hidden_trigger = {
						intrigue < 12
					}
				}
			}

			additive_modifier = {
				value = 40

				FROMFROM = {
					show_scope_change = no

					intrigue >= 12

					hidden_trigger = {
						intrigue < 16
					}
				}
			}

			additive_modifier = {
				value = 75

				FROMFROM = {
					show_scope_change = no

					intrigue >= 16

					hidden_trigger = {
						intrigue < 20
					}
				}
			}

			additive_modifier = {
				value = 120

				FROMFROM = {
					show_scope_change = no

					intrigue >= 20
				}
			}

			additive_modifier = {
				value = 20

				FROMFROM = {
					show_scope_change = no

					learning >= 8

					hidden_trigger = {
						learning < 12
					}
				}
			}

			additive_modifier = {
				value = 40

				FROMFROM = {
					show_scope_change = no

					learning >= 12

					hidden_trigger = {
						learning < 16
					}
				}
			}

			additive_modifier = {
				value = 75

				FROMFROM = {
					show_scope_change = no

					learning >= 16

					hidden_trigger = {
						learning < 20
					}
				}
			}

			additive_modifier = {
				value = 120

				FROMFROM = {
					show_scope_change = no

					learning = 20
				}
			}

			additive_modifier = {
				value = 40

				FROMFROM = {
					show_scope_change = no

					trait = attractive
				}
			}

			additive_modifier = {
				value = 20

				FROMFROM = {
					show_scope_change = no

					trait = groomed
				}
			}

			additive_modifier = {
				value = 40

				FROMFROM = {
					show_scope_change = no

					trait = genius
				}
			}

			additive_modifier = {
				value = 30

				FROMFROM = {
					show_scope_change = no

					trait = quick
				}
			}

			additive_modifier = {
				value = 20

				FROMFROM = {
					show_scope_change = no

					trait = strong
				}
			}

			additive_modifier = {
				value = 20

				FROMFROM = {
					show_scope_change = no

					trait = brawny
				}
			}

			additive_modifier = {
				value = 30

				FROMFROM = {
					show_scope_change = no

					trait = shrewd
				}
			}

			additive_modifier = {
				value = 40

				FROMFROM = {
					show_scope_change = no

					trait = architect
				}
			}

			additive_modifier = {
				value = 60

				FROMFROM = {
					show_scope_change = no

					trait = administrator
				}
			}

			additive_modifier = {
				value = 40

				FROMFROM = {
					show_scope_change = no

					trait = strategist
				}
			}

			additive_modifier = {
				value = 40

				FROMFROM = {
					show_scope_change = no

					trait = scholar
				}
			}

			additive_modifier = {
				value = 40

				FROMFROM = {
					show_scope_change = no

					trait = faqih
				}
			}

			additive_modifier = {
				value = 25

				custom_tooltip = {
					text = tribute_interaction_level3_education_tt

					FROMFROM = {
						has_3rd_tier_education_trait_trigger = yes
					}
				}
			}

			additive_modifier = {
				value = 50

				custom_tooltip = {
					text = tribute_interaction_level4_education_tt

					FROMFROM = {
						has_top_tier_education_trait_trigger = yes
					}
				}
			}

			additive_modifier = {
				value = 60

				FROMFROM = {
					show_scope_change = no

					is_adult = no
				}
			}

			mult_modifier = {
				factor = 2.0

				offmap_china = {
					show_scope_change = no

					offmap_has_like = likes_eunuchs
				}
			}

			mult_modifier = {
				factor = 2.0

				FROMFROM = {
					show_scope_change = no

					liked_by_offmap = {
						type = offmap_china
					}
				}
			}

			mult_modifier = {
				factor = 0.5

				offmap_china = {
					show_scope_change = no

					offmap_has_dislike = likes_eunuchs
				}
			}

			mult_modifier = {
				factor = 0.5

				FROMFROM = {
					show_scope_change = no

					disliked_by_offmap = {
						type = offmap_china
					}
				}
			}

			mult_modifier = {
				factor = 1.5

				FROM = {
					show_scope_change = no

					liked_by_offmap = {
						type = offmap_china
					}
				}
			}

			mult_modifier = {
				factor = 0.66

				FROM = {
					show_scope_change = no

					disliked_by_offmap = {
						type = offmap_china
					}
				}
			}
		}

		effect = {
			FROM = {
				show_scope_change = no

				sound_effect = china_grace_gain
			#	save_event_target_as = target_tribute_sender

				add_offmap_currency = {
					offmap = offmap_china
					value = local_third_party_score
				}

				if = {
					limit = {
						ai = no
						is_ironman = yes
					}

					set_character_flag = achievement_snipped_off_to_china
				}
			}

			# Like/Dislike effect description
			#################################

			if = {
				limit = {
					OR = {
						FROM = {
							liked_by_offmap = {
								type = offmap_china
								context = eunuch
							}
						}

						FROMFROM = {
							liked_by_offmap = {
								type = offmap_china
								context = eunuch
							}
						}
					}
				}

				if = {
					limit = {
						OR = {
							FROM = {
								disliked_by_offmap = {
									type = offmap_china
									context = eunuch
								}
							}

							FROMFROM = {
								disliked_by_offmap = {
									type = offmap_china
									context = eunuch
								}
							}
						}
					}

					custom_tooltip = { text = chinese_emperor_has_ambiguous_feelings_of_THIS_tt }
				}
				else = {
					custom_tooltip = { text = chinese_emperor_likes_THIS_tt }
				}
			}
			else_if = {
				limit = {
					OR = {
						FROM = {
							disliked_by_offmap = {
								type = offmap_china
								context = eunuch
							}
						}

						FROMFROM = {
							disliked_by_offmap = {
								type = offmap_china
								context = eunuch
							}
						}
					}
				}

				custom_tooltip = { text = chinese_emperor_dislikes_THIS_tt }
			}

			#################################

			FROMFROM = {
				show_scope_change = no

				save_event_target_as = person_sent_as_tribute

				hidden_effect = {
					if = {
						limit = {
							NOT = { trait = eunuch }
						}

						add_trait = eunuch
					}
				}

				leave_court_for_china_effect = yes
			}

			FROM = {
				add_character_modifier = {
					name = chinese_grace_send_eunuch_timer
					years = 20
					hidden = yes
				}

				if = {
					limit = { local_third_party_score_low_trigger = yes }
					set_character_flag = sent_bad_tribute
				}
				else_if = {
					limit = { local_third_party_score_medium_trigger = yes }
					set_character_flag = sent_decent_tribute
				}
				else_if = {
					limit = { local_third_party_score_great_trigger = yes }
					set_character_flag = sent_great_tribute
				}

				set_character_flag = sent_eunuch_tribute

				letter_event = {
					id = JD.10050
					days = 5
					random = 2
				}
			}
		}

		ai_will_do = {
			factor = 0.3
		}
	}

	chinese_grace_offer_concubine = {
		button_name = offmap_gifts

		third_party_filter = home_court
		ai_third_party_filter = home_court
		third_party = FROM
		ai_check_interval = 20

		show_third_party_potential = yes

		only_playable = yes

		from_potential = {
			has_dlc = "Jade Dragon"
			mercenary = no
			holy_order = no
			is_landed = yes
		}

		potential = {
			is_offmap_tag = offmap_china

			trigger_if = {
				limit = { ai = yes }

				# Allow is checked for each valid 3rd party, so it is cheaper to check it here for the AI
				china_offmap_tribute_decisions_enabled_trigger = yes
			}
		}

		allow = {
			show_only_failed_conditions = yes

			FROM = {
				show_scope_change = no

				custom_tooltip = {
					text = china_tribute_send_concubine_cooldown_tt
					NOT = { has_character_modifier = chinese_grace_send_concubine_timer }
				}

				prisoner = no
				is_incapable = no
				is_inaccessible_trigger = no
			}

			# china_offmap_decisions_enabled_trigger = yes # leave in please, to be used if the tooltip for china_offmap_tribute_decisions_enabled_trigger changes and we need to reference things uniquely again

			trigger_if = {
				limit = { ai = no }

				# AI has already checked this in the potential
				china_offmap_tribute_decisions_enabled_trigger = yes
			}
		}

		third_party_potential = {
			# show_only_failed_conditions = yes

			custom_tooltip = {
				text = china_tribute_send_concubine_preference_tt

				offmap_china = {
					offmap_ruler = {
						is_opposite_sex = FROMFROM
					}
				}
			}

			FROMFROM = {
				show_scope_change = no

				custom_tooltip = {
					text = is_close_relative_or_same_dynasty_tt

					OR = {
						is_close_relative = ROOT_FROM
						dynasty = ROOT_FROM
					}
				}

				custom_tooltip = {
					text = is_adult_under_45_tt

					is_adult = yes
					practical_age < 45
				}

				is_ruler = no
				is_heir = no

				custom_tooltip = {
					text = not_married_or_getting_married_tt

					is_betrothed = no
					is_married = no
				}

				custom_tooltip = {
					text = is_not_from_china_tt

					courtier_from_china_trigger = no
				}

				custom_tooltip = {
					text = is_not_incapable_inbred_or_imbecile_tt

					is_incapable = no

					NOR = {
						trait = inbred
						trait = imbecile
					}
				}

				custom_tooltip = {
					text = is_not_maimed_or_infirm_tt

					NOR = {
						trait = maimed
						trait = infirm
					}
				}

				custom_tooltip = {
					text = is_not_wounded_severely_injured_tt

					NOR = {
						trait = wounded
						trait = severely_injured
					}
				}

				custom_tooltip = {
					text = is_not_one_eyed_handed_legged_disfigured_or_mangled_tt

					NOR = {
						trait = one_eyed
						trait = one_handed
						trait = one_legged
						trait = disfigured
						trait = mangled
					}
				}

				custom_tooltip = {
					text = is_not_ascetic_or_celibate_tt

					is_ascetic_trigger = no
					NOT = { trait = celibate }
				}
			}
		}

		third_party_allow = {
			show_only_failed_conditions = yes

			FROMFROM = {
				show_scope_change = no

				prisoner = no
				is_ill = no
				is_inaccessible_trigger = no
			}
		}

		third_party_score = {
			factor = 100

			additive_modifier = {
				value = 20

				FROMFROM = {
					show_scope_change = no

					diplomacy >= 8

					hidden_trigger = {
						diplomacy < 12
					}
				}
			}

			additive_modifier = {
				value = 40

				FROMFROM = {
					show_scope_change = no

					diplomacy >= 12

					hidden_trigger = {
						diplomacy < 16
					}
				}
			}

			additive_modifier = {
				value = 75

				FROMFROM = {
					show_scope_change = no

					diplomacy >= 16

					hidden_trigger = {
						diplomacy < 20
					}
				}
			}

			additive_modifier = {
				value = 120

				FROMFROM = {
					show_scope_change = no

					diplomacy >= 20
				}
			}

			additive_modifier = {
				value = 20

				FROMFROM = {
					show_scope_change = no

					martial >= 8

					hidden_trigger = {
						martial < 12
					}
				}
			}

			additive_modifier = {
				value = 40

				FROMFROM = {
					show_scope_change = no

					martial >= 12

					hidden_trigger = {
						martial < 16
					}
				}
			}

			additive_modifier = {
				value = 75

				FROMFROM = {
					show_scope_change = no

					martial >= 16

					hidden_trigger = {
						martial < 20
					}
				}
			}

			additive_modifier = {
				value = 120

				FROMFROM = {
					show_scope_change = no

					martial >= 20
				}
			}

			additive_modifier = {
				value = 20

				FROMFROM = {
					show_scope_change = no

					stewardship >= 8

					hidden_trigger = {
						stewardship < 12
					}
				}
			}

			additive_modifier = {
				value = 40

				FROMFROM = {
					show_scope_change = no

					stewardship >= 12

					hidden_trigger = {
						stewardship < 16
					}
				}
			}

			additive_modifier = {
				value = 75
				FROMFROM = {
					show_scope_change = no

					stewardship >= 16

					hidden_trigger = {
						stewardship < 20
					}
				}
			}

			additive_modifier = {
				value = 120

				FROMFROM = {
					show_scope_change = no

					stewardship >= 20
				}
			}

			additive_modifier = {
				value = 20

				FROMFROM = {
					show_scope_change = no

					intrigue >= 8

					hidden_trigger = {
						intrigue < 12
					}
				}
			}

			additive_modifier = {
				value = 40

				FROMFROM = {
					show_scope_change = no

					intrigue >= 12

					hidden_trigger = {
						intrigue < 16
					}
				}
			}

			additive_modifier = {
				value = 75

				FROMFROM = {
					show_scope_change = no

					intrigue >= 16

					hidden_trigger = {
						intrigue < 20
					}
				}
			}

			additive_modifier = {
				value = 120

				FROMFROM = {
					show_scope_change = no

					intrigue >= 20
				}
			}

			additive_modifier = {
				value = 20

				FROMFROM = {
					show_scope_change = no

					learning >= 8

					hidden_trigger = {
						learning < 12
					}
				}
			}

			additive_modifier = {
				value = 40

				FROMFROM = {
					show_scope_change = no

					learning >= 12

					hidden_trigger = {
						learning < 16
					}
				}
			}

			additive_modifier = {
				value = 75

				FROMFROM = {
					show_scope_change = no

					learning >= 16

					hidden_trigger = {
						learning < 20
					}
				}
			}

			additive_modifier = {
				value = 120

				FROMFROM = {
					show_scope_change = no

					learning >= 20
				}
			}

			additive_modifier = {
				value = 80

				FROMFROM = {
					show_scope_change = no

					trait = attractive
				}
			}

			additive_modifier = {
				value = 40

				FROMFROM = {
					show_scope_change = no

					trait = groomed
				}
			}

			additive_modifier = {
				value = -80

				FROMFROM = {
					show_scope_change = no

					trait = ugly
				}
			}

			additive_modifier = {
				value = -40

				FROMFROM = {
					show_scope_change = no

					trait = uncouth
				}
			}

			additive_modifier = {
				value = 40

				FROMFROM = {
					show_scope_change = no

					trait = genius
				}
			}

			additive_modifier = {
				value = 30

				FROMFROM = {
					show_scope_change = no

					trait = quick
				}
			}

			additive_modifier = {
				value = 40

				FROMFROM = {
					show_scope_change = no

					trait = strong
				}
			}

			additive_modifier = {
				value = 30

				FROMFROM = {
					show_scope_change = no

					trait = brawny
				}
			}

			additive_modifier = {
				value = 30

				FROMFROM = {
					show_scope_change = no

					trait = shrewd
				}
			}

			additive_modifier = {
				value = 30

				FROMFROM = {
					show_scope_change = no

					trait = charitable
				}
			}

			additive_modifier = {
				value = 30

				FROMFROM = {
					show_scope_change = no

					trait = gregarious
				}
			}

			additive_modifier = {
				value = 30

				FROMFROM = {
					show_scope_change = no

					trait = kind
				}
			}

			additive_modifier = {
				value = -50

				FROMFROM = {
					show_scope_change = no

					trait = lunatic
				}
			}

			additive_modifier = {
				value = 25

				custom_tooltip = {
					text = tribute_interaction_level3_education_tt

					FROMFROM = {
						has_3rd_tier_education_trait_trigger = yes
					}
				}
			}

			additive_modifier = {
				value = 50

				custom_tooltip = {
					text = tribute_interaction_level4_education_tt

					FROMFROM = {
						has_top_tier_education_trait_trigger = yes
					}
				}
			}

			mult_modifier = {
				factor = 2.0

				offmap_china = {
					show_scope_change = no

					offmap_has_like = likes_concubines
				}
			}

			mult_modifier = {
				factor = 2.0

				FROMFROM = {
					show_scope_change = no

					liked_by_offmap = {
						type = offmap_china
					}
				}
			}

			mult_modifier = {
				factor = 0.5

				offmap_china = {
					show_scope_change = no

					offmap_has_dislike = likes_concubines
				}
			}

			mult_modifier = {
				factor = 0.5

				FROMFROM = {
					show_scope_change = no

					disliked_by_offmap = {
						type = offmap_china
					}
				}
			}

			mult_modifier = {
				factor = 1.5

				FROM = {
					show_scope_change = no

					liked_by_offmap = {
						type = offmap_china
					}
				}
			}

			mult_modifier = {
				factor = 0.66

				FROM = {
					show_scope_change = no

					disliked_by_offmap = {
						type = offmap_china
					}
				}
			}
		}

		effect = {
			FROM = {
				show_scope_change = no

				sound_effect = china_grace_gain
			#	save_event_target_as = target_tribute_sender

				add_offmap_currency = {
					offmap = offmap_china
					value = local_third_party_score
				}
			}

			# Like/Dislike effect description
			#################################

			if = {
				limit = {
					OR = {
						FROM = {
							liked_by_offmap = {
								type = offmap_china
								context = concubine
							}
						}

						FROMFROM = {
							liked_by_offmap = {
								type = offmap_china
								context = concubine
							}
						}
					}
				}

				if = {
					limit = {
						OR = {
							FROM = {
								disliked_by_offmap = {
									type = offmap_china
									context = concubine
								}
							}

							FROMFROM = {
								disliked_by_offmap = {
									type = offmap_china
									context = concubine
								}
							}
						}
					}

					custom_tooltip = { text = chinese_emperor_has_ambiguous_feelings_of_THIS_tt }
				}
				else = {
					custom_tooltip = { text = chinese_emperor_likes_THIS_tt }
				}
			}
			else_if = {
				limit = {
					OR = {
						FROM = {
							disliked_by_offmap = {
								type = offmap_china
								context = concubine
							}
						}

						FROMFROM = {
							disliked_by_offmap = {
								type = offmap_china
								context = concubine
							}
						}
					}
				}

				custom_tooltip = { text = chinese_emperor_dislikes_THIS_tt }
			}

			#################################

			FROMFROM = {
				show_scope_change = no

				save_event_target_as = person_sent_as_tribute
				leave_court_for_china_effect = yes
			}

			FROM = {
				add_character_modifier = {
					name = chinese_grace_send_concubine_timer
					years = 20
					hidden = yes
				}

				if = {
					limit = { local_third_party_score_low_trigger = yes }
					set_character_flag = sent_bad_tribute
				}
				else_if = {
					limit = { local_third_party_score_medium_trigger = yes }
					set_character_flag = sent_decent_tribute
				}
				else_if = {
					limit = { local_third_party_score_great_trigger = yes }
					set_character_flag = sent_great_tribute
				}

				set_character_flag = sent_concubine_tribute

				letter_event = {
					id = JD.10050
					days = 5
					random = 2
				}
			}
		}

		ai_will_do = {
			factor = 0.3
		}
	}

	chinese_grace_offer_commander = {
		button_name = offmap_gifts

		third_party_filter = home_court
		ai_third_party_filter = home_court
		third_party = FROM
		ai_check_interval = 36

		show_third_party_potential = yes

		only_playable = yes

		from_potential = {
			has_dlc = "Jade Dragon"
			is_landed = yes
			mercenary = no
			holy_order = no
		}

		potential = {
			is_offmap_tag = offmap_china

			offmap_china = {
				OR = {
					has_status = china_unrest
					has_status = china_civil_war
					has_status = china_mongol_invasion
					has_status = china_jurchen_invasion
				}
			}

			trigger_if = {
				limit = { ai = yes }

				# Allow is checked for each valid 3rd party, so it is cheaper to check it here for the AI
				china_offmap_tribute_decisions_enabled_trigger = yes
			}
		}

		allow = {
			show_only_failed_conditions = yes

			trigger_if = {
				limit = { ai = no } # No need to check again, AI doesn't see tooltips

				offmap_china = {
					OR = {
						has_status = china_unrest
						has_status = china_civil_war
						has_status = china_mongol_invasion
						has_status = china_jurchen_invasion
					}
				}

				# AI has already checked this in the potential
				china_offmap_tribute_decisions_enabled_trigger = yes
			}

			# china_offmap_decisions_enabled_trigger = yes # leave in please, to be used if the tooltip for china_offmap_tribute_decisions_enabled_trigger changes and we need to reference things uniquely again

			FROM = {
				show_scope_change = no

				custom_tooltip = {
					text = china_tribute_send_commander_cooldown_tt
					NOT = { has_character_modifier = chinese_grace_send_commander_timer }
				}

				prisoner = no
				is_incapable = no
				is_inaccessible_trigger = no
			}
		}

		third_party_potential = {
			# show_only_failed_conditions = yes

			FROMFROM = {
				show_scope_change = no

				is_adult = yes
				martial >= 12
				is_heir = no
				is_ruler = no

				custom_tooltip = {
					text = not_married_or_getting_married_tt

					is_betrothed = no
					is_married = no
				}

				custom_tooltip = {
					text = is_not_from_china_tt

					courtier_from_china_trigger = no
				}

				custom_tooltip = {
					text = is_not_incapable_inbred_or_imbecile_tt

					is_incapable = no

					NOR = {
						trait = inbred
						trait = imbecile
					}
				}

				custom_tooltip = {
					text = is_not_maimed_or_infirm_tt

					NOR = {
						trait = maimed
						trait = infirm
					}
				}

				OR = {
					is_female = no
					has_minor_title = title_commander
					has_gender_equal_game_rule_trigger = yes
				}
			}
		}

		third_party_allow = {
			show_only_failed_conditions = yes

			FROMFROM = {
				show_scope_change = no

				prisoner = no
				is_ill = no

				custom_tooltip = {
					text = is_not_wounded_severely_injured_tt

					NOR = {
						trait = wounded
						trait = severely_injured
					}
				}

				is_inaccessible_trigger = no
			}
		}

		third_party_score = {
			factor = 100

			additive_modifier = {
				value = 20

				FROMFROM = {
					show_scope_change = no

					martial >= 12

					hidden_trigger = {
						martial < 14
					}
				}
			}

			additive_modifier = {
				value = 40

				FROMFROM = {
					show_scope_change = no

					martial >= 14

					hidden_trigger = {
						martial < 16
					}
				}
			}

			additive_modifier = {
				value = 60

				FROMFROM = {
					show_scope_change = no

					martial >= 16
					hidden_trigger = {
						martial < 18
					}
				}
			}

			additive_modifier = {
				value = 80

				FROMFROM = {
					show_scope_change = no

					martial = 18

					hidden_trigger = {
						martial < 20
					}
				}
			}

			additive_modifier = {
				value = 100

				FROMFROM = {
					show_scope_change = no

					martial >= 20

					hidden_trigger = {
						martial < 22
					}
				}
			}

			additive_modifier = {
				value = 120

				FROMFROM = {
					show_scope_change = no

					martial >= 22

					hidden_trigger = {
						 martial < 24
					}
				}
			}

			additive_modifier = {
				value = 140

				FROMFROM = {
					show_scope_change = no

					martial >= 24
				}
			}

			additive_modifier = {
				value = 40

				FROMFROM = {
					show_scope_change = no

					trait = genius
				}
			}

			additive_modifier = {
				value = 30

				FROMFROM = {
					show_scope_change = no

					trait = quick
				}
			}

			additive_modifier = {
				value = 40

				FROMFROM = {
					show_scope_change = no

					trait = strong
				}
			}

			additive_modifier = {
				value = 30

				FROMFROM = {
					show_scope_change = no

					trait = brawny
				}
			}

			additive_modifier = {
				value = 30

				FROMFROM = {
					show_scope_change = no

					trait = shrewd
				}
			}

			additive_modifier = {
				value = 40

				FROMFROM = {
					show_scope_change = no

					trait = strategist
				}
			}

			additive_modifier = {
				value = 40

				FROMFROM = {
					show_scope_change = no

					trait = duelist
				}
			}

			additive_modifier = {
				value = 20

				FROMFROM = {
					show_scope_change = no

					trait = hunter
				}
			}

			additive_modifier = {
				value = 100

				FROMFROM = {
					show_scope_change = no

					trait = berserker
				}
			}

			additive_modifier = {
				value = 40

				FROMFROM = {
					show_scope_change = no

					trait = adventurer
				}
			}

			additive_modifier = {
				value = 20

				FROMFROM = {
					show_scope_change = no

					trait = patient
				}
			}

			additive_modifier = {
				value = 20

				FROMFROM = {
					show_scope_change = no

					trait = brave
				}
			}

			additive_modifier = {
				value = 20

				FROMFROM = {
					show_scope_change = no

					trait = diligent
				}
			}

			additive_modifier = {
				value = 40

				FROMFROM = {
					show_scope_change = no

					trait = shieldmaiden
				}
			}

			additive_modifier = {
				value = 50

				FROMFROM = {
					show_scope_change = no
					trait = sapper
				}
			}

			additive_modifier = {
				value = 50

				FROMFROM = {
					show_scope_change = no

					trait = master_of_flame
				}
			}

			additive_modifier = {
				value = 50

				FROMFROM = {
					show_scope_change = no

					trait = logistics_expert
				}
			}

			additive_modifier = {
				value = 50

				FROMFROM = {
					show_scope_change = no

					trait = levy_coordinator
				}
			}

			additive_modifier = {
				value = 40

				FROMFROM = {
					show_scope_change = no

					trait = light_foot_leader
				}
			}

			additive_modifier = {
				value = 40

				FROMFROM = {
					show_scope_change = no

					trait = heavy_infantry_leader
				}
			}

			additive_modifier = {
				value = 40

				FROMFROM = {
					show_scope_change = no

					trait = cavalry_leader
				}
			}

			additive_modifier = {
				value = 40

				FROMFROM = {
					show_scope_change = no

					trait = inspiring_leader
				}
			}

			additive_modifier = {
				value = 40

				FROMFROM = {
					show_scope_change = no

					trait = trickster
				}
			}

			additive_modifier = {
				value = 40

				FROMFROM = {
					show_scope_change = no

					trait = organizer
				}
			}

			additive_modifier = {
				value = 40

				FROMFROM = {
					show_scope_change = no

					trait = defensive_leader
				}
			}

			additive_modifier = {
				value = 40

				FROMFROM = {
					show_scope_change = no

					trait = direct_leader
				}
			}

			additive_modifier = {
				value = 40

				FROMFROM = {
					show_scope_change = no

					trait = flanker
				}
			}

			additive_modifier = {
				value = 40

				FROMFROM = {
					show_scope_change = no

					trait = aggressive_leader
				}
			}

			additive_modifier = {
				value = 40

				FROMFROM = {
					show_scope_change = no

					trait = siege_leader
				}
			}

			additive_modifier = {
				value = 25

				custom_tooltip = {
					text = tribute_interaction_level3_education_tt

					FROMFROM = {
						trait = skilled_tactician
					}
				}
			}

			additive_modifier = {
				value = 50

				custom_tooltip = {
					text = tribute_interaction_level4_education_tt

					FROMFROM = {
						trait = brilliant_strategist
					}
				}
			}

			mult_modifier = {
				factor = 2.0

				FROMFROM = {
					show_scope_change = no

					liked_by_offmap = {
						type = offmap_china
					}
				}
			}

			mult_modifier = {
				factor = 0.5

				FROMFROM = {
					show_scope_change = no

					disliked_by_offmap = {
						type = offmap_china
					}
				}
			}

			mult_modifier = {
				factor = 1.5

				FROM = {
					show_scope_change = no

					liked_by_offmap = {
						type = offmap_china
					}
				}
			}

			mult_modifier = {
				factor = 0.66

				FROM = {
					show_scope_change = no

					disliked_by_offmap = {
						type = offmap_china
					}
				}
			}
		}

		effect = {
			FROM = {
				show_scope_change = no

				sound_effect = china_grace_gain
			#	save_event_target_as = target_tribute_sender

				add_offmap_currency = {
					offmap = offmap_china
					value = local_third_party_score
				}
			}

			# Like/Dislike effect description
			#################################

			if = {
				limit = {
					OR = {
						FROM = {
							liked_by_offmap = {
								type = offmap_china
							}
						}

						FROMFROM = {
							liked_by_offmap = {
								type = offmap_china
							}
						}
					}
				}

				if = {
					limit = {
						OR = {
							FROM = {
								disliked_by_offmap = {
									type = offmap_china
								}
							}

							FROMFROM = {
								disliked_by_offmap = {
									type = offmap_china
								}
							}
						}
					}

					custom_tooltip = { text = chinese_emperor_has_ambiguous_feelings_of_THIS_tt }
				}
				else = {
					custom_tooltip = { text = chinese_emperor_likes_THIS_tt }
				}
			}
			else_if = {
				limit = {
					OR = {
						FROM = {
							disliked_by_offmap = {
								type = offmap_china
							}
						}

						FROMFROM = {
							disliked_by_offmap = {
								type = offmap_china
							}
						}
					}
				}

				custom_tooltip = { text = chinese_emperor_dislikes_THIS_tt }
			}

			#################################

			FROMFROM = {
				show_scope_change = no

				save_event_target_as = person_sent_as_tribute
				leave_court_for_china_effect = yes
			}

			FROM = {
				add_character_modifier = {
					name = chinese_grace_send_commander_timer
					years = 20
					hidden = yes
				}

				if = {
					limit = { local_third_party_score_low_trigger = yes }
					set_character_flag = sent_bad_tribute
				}
				else_if = {
					limit = { local_third_party_score_medium_trigger = yes }
					set_character_flag = sent_decent_tribute
				}
				else_if = {
					limit = { local_third_party_score_great_trigger = yes }
					set_character_flag = sent_great_tribute
				}

				letter_event = {
					id = JD.10050
					days = 5
					random = 2
				}
			}
		}

		ai_will_do = {
			factor = 0.3
		}
	}

	chinese_grace_offer_physician = {
		button_name = offmap_gifts

		third_party_filter = all
		ai_third_party_filter = home_court
		third_party = FROM
		ai_check_interval = 36

		show_third_party_potential = yes

		only_playable = yes

		from_potential = {
			has_dlc = "Jade Dragon"
			is_landed = yes
			mercenary = no
			holy_order = no
		}

		potential = {
			is_offmap_tag = offmap_china

			offmap_china = {
				has_status = china_plague
			}

			trigger_if = {
				limit = { ai = yes }

				# Allow is checked for each valid 3rd party, so it is cheaper to check it here for the AI
				china_offmap_tribute_decisions_enabled_trigger = yes
			}
		}

		allow = {
			show_only_failed_conditions = yes

			FROM = {
				show_scope_change = no

				custom_tooltip = {
					text = china_tribute_send_physician_tt
					NOT = { has_character_flag = chinese_grace_physician_sent }
				}

				prisoner = no
				is_incapable = no
				is_inaccessible_trigger = no
			}

			trigger_if = {
				limit = { ai = no }

				# AI has already checked this in the potential
				china_offmap_tribute_decisions_enabled_trigger = yes
			}

			# china_offmap_decisions_enabled_trigger = yes # leave in please, to be used if the tooltip for china_offmap_tribute_decisions_enabled_trigger changes and we need to reference things uniquely again
		}

		third_party_potential = {
			# show_only_failed_conditions = yes

			FROMFROM = {
				show_scope_change = no

				hidden_trigger = {
					vassal_of = ROOT_FROM
				}

				is_ruler = no
				is_adult = yes
				is_heir = no

				custom_tooltip = {
					text = not_married_or_getting_married_tt

					is_betrothed = no
					is_married = no
				}

				custom_tooltip = {
					text = is_not_from_china_tt

					courtier_from_china_trigger = no
				}

				custom_tooltip = {
					text = is_not_incapable_inbred_or_imbecile_tt

					is_incapable = no

					NOR = {
						trait = inbred
						trait = imbecile
					}
				}

				custom_tooltip = {
					text = is_not_maimed_or_infirm_tt

					NOR = {
						trait = maimed
						trait = infirm
					}
				}

				OR = {
					trigger_if = {
						limit = { has_dlc = Reapers }
						has_minor_title = title_court_physician
					}

					trait = physician
					trait = scholar
					trait = mystic
				}
			}
		}

		third_party_allow = {
			show_only_failed_conditions = yes

			FROMFROM = {
				is_ill = no

				custom_tooltip = {
					text = is_not_wounded_severely_injured_tt

					NOR = {
						trait = wounded
						trait = severely_injured
					}
				}

				is_inaccessible_trigger = no
			}
		}

		third_party_score = {
			factor = 100

			additive_modifier = {
				value = -50

				FROMFROM = {
					show_scope_change = no

					learning < 8
				}
			}

			additive_modifier = {
				value = 40

				FROMFROM = {
					show_scope_change = no

					learning >= 8

					hidden_trigger = {
						learning < 12
					}
				}
			}

			additive_modifier = {
				value = 60

				FROMFROM = {
					show_scope_change = no

					learning >= 12

					hidden_trigger = {
						learning < 16
					}
				}
			}

			additive_modifier = {
				value = 100

				FROMFROM = {
					show_scope_change = no

					learning >= 16

					hidden_trigger = {
						learning < 20
					}
				}
			}

			additive_modifier = {
				value = 140

				FROMFROM = {
					show_scope_change = no

					learning >= 20

					hidden_trigger = {
						learning < 24
					}
				}
			}

			additive_modifier = {
				value = 180

				FROMFROM = {
					show_scope_change = no

					learning >= 24

					hidden_trigger = {
						learning < 28
					}
				}
			}

			additive_modifier = {
				value = 220

				FROMFROM = {
					show_scope_change = no

					learning >= 28

					hidden_trigger = {
						learning < 32
					}
				}
			}

			additive_modifier = {
				value = 260

				FROMFROM = {
					show_scope_change = no

					learning >= 32
				}
			}

			additive_modifier = {
				value = 100

				FROMFROM = {
					show_scope_change = no

					trait = genius
				}
			}

			additive_modifier = {
				value = 50

				FROMFROM = {
					show_scope_change = no

					trait = quick
				}
			}

			additive_modifier = {
				value = 50

				FROMFROM = {
					show_scope_change = no

					trait = shrewd
				}
			}

			additive_modifier = {
				value = 150

				FROMFROM = {
					show_scope_change = no

					trait = physician
				}
			}

			additive_modifier = {
				value = 50

				FROMFROM = {
					show_scope_change = no

					trait = mystic
				}
			}

			additive_modifier = {
				value = 50

				FROMFROM = {
					show_scope_change = no

					trait = scholar
				}
			}

			additive_modifier = {
				value = 25
				trait = scholarly_theologian
			}

			additive_modifier = {
				value = 50
				trait = mastermind_theologian
			}

			additive_modifier = {
				value = 25
				trait = patient
			}

			additive_modifier = {
				value = 25
				trait = diligent
			}

			mult_modifier = {
				factor = 1.5

				FROM = {
					show_scope_change = no

					liked_by_offmap = {
						type = offmap_china
					}
				}
			}

			mult_modifier = {
				factor = 0.66

				FROM = {
					show_scope_change = no

					disliked_by_offmap = {
						type = offmap_china
					}
				}
			}
		}

		effect = {
			FROM = {
				show_scope_change = no

				sound_effect = china_grace_gain
			#	save_event_target_as = target_tribute_sender

				add_offmap_currency = {
					offmap = offmap_china
					value = local_third_party_score
				}
			}

			FROMFROM = {
				show_scope_change = no

				save_event_target_as = person_sent_as_tribute
				leave_court_for_china_effect = yes
			}

			FROM = {
				set_character_flag = chinese_grace_physician_sent

				if = {
					limit = { local_third_party_score_low_trigger = yes }
					set_character_flag = sent_bad_tribute
				}
				else_if = {
					limit = { local_third_party_score_medium_trigger = yes }
					set_character_flag = sent_decent_tribute
				}
				else_if = {
					limit = { local_third_party_score_great_trigger = yes }
					set_character_flag = sent_great_tribute
				}

				letter_event = {
					id = JD.10050
					days = 5
					random = 2
				}
			}
		}

		ai_will_do = {
			factor = 0.3
		}
	}

	chinese_grace_send_relief = {
		button_name = offmap_gifts

		ai_check_interval = 60

		only_playable = yes

		from_potential = {
			has_dlc = "Jade Dragon"
			is_landed = yes
			mercenary = no
			holy_order = no
		}

		potential = {
			is_offmap_tag = offmap_china

			offmap_china = {
				has_status = china_famine
			}
		}

		allow = {
			show_only_failed_conditions = yes

			FROM = {
				show_scope_change = no

				is_nomadic = no
				is_tribal = no
				NOT = { has_character_modifier = china_send_relief }
				prisoner = no
				is_incapable = no
				is_inaccessible_trigger = no
			}

			# china_offmap_decisions_enabled_trigger = yes # leave in please, to be used if the tooltip for china_offmap_tribute_decisions_enabled_trigger changes and we need to reference things uniquely again
			china_offmap_tribute_decisions_enabled_trigger = yes
		}

		effect = {
			FROM = {
				show_scope_change = no

				sound_effect = china_grace_gain

				add_character_modifier = {
					name = china_send_relief
					years = 10
					inherit = yes
				}

				if = {
					limit = {
						liked_by_offmap = {
							type = offmap_china
						}
					}

					if = {
						limit = {
							disliked_by_offmap = {
								type = offmap_china
							}
						}

						add_offmap_currency = {
							offmap = offmap_china
							value = 500
						}

						custom_tooltip = { text = chinese_emperor_has_ambiguous_feelings_of_THIS_tt }
					}
					else = {
						add_offmap_currency = {
							offmap = offmap_china
							value = 750
						}

						custom_tooltip = { text = chinese_emperor_likes_THIS_tt }
					}
				}
				else_if = {
					limit = {
						disliked_by_offmap = {
							type = offmap_china
						}
					}

					add_offmap_currency = {
						offmap = offmap_china
						value = 250
					}

					custom_tooltip = { text = chinese_emperor_dislikes_THIS_tt }
				}
				else = {
					add_offmap_currency = {
						offmap = offmap_china
						value = 500
					}
				}

				letter_event = { id = JD.3011 }
			}
		}

		ai_will_do = {
			factor = 1

			trigger = {
				FROM = {
					independent = yes
					war = no
				}
			}
		}
	}

	chinese_grace_offer_artifact = {
		button_name = offmap_gifts

		third_party_filter = artifacts
		ai_third_party_filter = artifacts
		third_party = FROM
		ai_check_interval = 60

		show_third_party_potential = yes

		only_playable = yes

		from_potential = {
			has_dlc = "Jade Dragon"
			is_landed = yes
			mercenary = no
			holy_order = no
		}

		potential = {
			is_offmap_tag = offmap_china

			trigger_if = {
				limit = { ai = yes }

				# Allow is checked for each valid 3rd party, so it is cheaper to check it here for the AI
				china_offmap_tribute_decisions_enabled_trigger = yes
			}
		}

		allow = {
			show_only_failed_conditions = yes

			FROM = {
				show_scope_change = no

				prisoner = no
				is_incapable = no
				is_inaccessible_trigger = no
			}

			trigger_if = {
				limit = { ai = no }

				# AI has already checked this in the potential
				china_offmap_tribute_decisions_enabled_trigger = yes
			}

			# china_offmap_decisions_enabled_trigger = yes # leave in please, to be used if the tooltip for china_offmap_tribute_decisions_enabled_trigger changes and we need to reference things uniquely again
			china_offmap_tribute_decisions_enabled_trigger = yes
		}

		third_party_potential = {
			# show_only_failed_conditions = yes

			FROMFROM = {
				show_scope_change = no

				custom_tooltip = {
					text = send_artifact_potential_tt

					quality > 2

					NOR = {
						has_artifact_flag = flag_considering_donation
						has_artifact_flag = curse
						has_artifact_flag = chinese
						artifact_type = crown_hre
						artifact_type = crown_byzantine
						artifact_type = crown_fylkir
						artifact_type = crown_tengri_fylkir
						artifact_type = crown_slavic_fylkir
						artifact_type = crown_romuva_fylkir
						artifact_type = crown_finnish_fylkir
						artifact_type = crown_west_african_fylkir
						artifact_type = crown_zun_fylkir
						artifact_type = scepter_hellenic_fylkir
						artifact_type = scepter_bon_fylkir
						artifact_type = crown_aztec_fylkir
						artifact_type = crown_pahlavi
					}
				}
			}
		}

		third_party_allow = {
		}

		third_party_score = {
			factor = 500

			additive_modifier = {
				value = 4500

				FROMFROM = {
					quality == 4
				}
			}

			additive_modifier = {
				value = 9500

				FROMFROM = {
					quality == 5
				}
			}

			additive_modifier = {
				value = -200

				FROMFROM = {
					quality < 4
					has_artifact_flag = lore # Magnum Opus book
				}
			}

			additive_modifier = {
				value = -3000

				FROMFROM = {
					quality == 4
					has_artifact_flag = lore # Magnum Opus book
				}
			}

			additive_modifier = {
				value = -250

				FROMFROM = {
					quality < 4
					has_artifact_flag = created
				}
			}

			additive_modifier = {
				value = -3500

				FROMFROM = {
					quality == 4
					has_artifact_flag = created
				}
			}

			mult_modifier = {
				factor = 1.5

				offmap_china = {
					show_scope_change = no

					offmap_has_like = likes_wealth
				}
			}

			mult_modifier = {
				factor = 0.5

				offmap_china = {
					show_scope_change = no

					offmap_has_dislike = likes_wealth
				}
			}

			mult_modifier = {
				factor = 1.5

				FROM = {
					show_scope_change = no

					liked_by_offmap = {
						type = offmap_china
					}
				}
			}

			mult_modifier = {
				factor = 0.5

				FROM = {
					show_scope_change = no

					disliked_by_offmap = {
						type = offmap_china
					}
				}
			}
		}

		effect = {
			FROM = {
				show_scope_change = no

				add_offmap_currency = {
					offmap = offmap_china
					value = local_third_party_score
				}
			}

			# Like/Dislike effect description
			#################################

			if = {
				limit = {
					OR = {
						FROM = {
							liked_by_offmap = {
								type = offmap_china
							}
						}

						offmap_china = {
							offmap_has_like = likes_wealth
						}
					}
				}

				if = {
					limit = {
						OR = {
							FROM = {
								disliked_by_offmap = {
									type = offmap_china
								}
							}

							offmap_china = {
								offmap_has_dislike = likes_wealth
							}
						}
					}

					custom_tooltip = { text = chinese_emperor_has_ambiguous_feelings_of_THIS_tt }
				}
				else = {
					custom_tooltip = { text = chinese_emperor_likes_THIS_tt }
				}
			}
			else_if = {
				limit = {
					OR = {
						FROM = {
							disliked_by_offmap = {
								type = offmap_china
							}
						}

						offmap_china = {
							offmap_has_dislike = likes_wealth
						}
					}
				}

				custom_tooltip = { text = chinese_emperor_dislikes_THIS_tt }
			}

			#################################

			FROM = {
				set_character_flag = jd_gifting_artifact
				sound_effect = china_grace_gain
			#	save_event_target_as = target_tribute_sender

				if = {
					limit = {
						ai = no
						is_ironman = yes

						ROOT_FROMFROM = {
							quality > 3
						}
					}

					set_character_flag = achievement_a_curious_trinket
				}

				letter_event = { id = JD.20024 }
			}

			hidden_effect = { # To reduce cluttered tooltip (effect already heavily implied...)
				# offmap_china = {
				# 	offmap_ruler = {
				#		ROOT_FROMFROM = {
				#			show_scope_change = no
				#
				#			tooltip = {
				#			 	transfer_artifact = {
				#			 		to = PREV
				#			 		from = ROOT_FROM
				#			 	}
				#			}
				#
				#			unsafe_destroy_artifact = yes
				#		}
				#	}
				# }

				FROMFROM = {
					unsafe_destroy_artifact = yes
				}
			}
		}


		ai_will_do = {
			factor = 0.1

			trigger = {
				FROMFROM = {
					quality < 4
				}
			}
		}
	}

	chinese_kow_tow_pilgrimage = {
		button_name = offmap_gifts

		ai_check_interval = 120

		only_playable = yes

		potential = {
			is_offmap_tag = offmap_china
		}

		allow = {
			show_only_failed_conditions = yes

			FROM = {
				show_scope_change = no

				war = no

				block_general_event_trigger = no

				NOT = {
					custom_tooltip = {
						text = kow_tow_tooltip_already_went

						has_character_flag = went_on_kow_tow_pilgrimage
					}
				}

				is_healthy_for_travel_trigger = yes

				higher_real_tier_than = COUNT

				trigger_if = {
					limit = {
						OR = {
							real_tier = DUKE
							is_nomadic = yes
						}
					}

					prestige >= 250
				}
				trigger_else_if = {
					limit = {
						real_tier = KING
						is_nomadic = no
					}

					prestige >= 500
				}
				trigger_else_if = {
					limit = {
						real_tier = EMPEROR
						is_nomadic = no
					}

					prestige >= 1000
				}

				trigger_if = {
					limit = { has_character_flag = awaiting_imperial_wedding }

					custom_tooltip = {
						text = not_awaiting_your_spouse_tt
						always = no
					}
				}
			}

			# china_offmap_decisions_enabled_trigger = yes # leave in please, to be used if the tooltip for china_offmap_tribute_decisions_enabled_trigger changes and we need to reference things uniquely again
			china_offmap_tribute_decisions_enabled_trigger = yes
		}

		effect = {
			FROM = {
				save_event_target_as = kow_tow_traveler
				set_character_flag = went_on_kow_tow_pilgrimage
				set_character_flag = do_not_disturb
				character_event = { id = JD.32000 }
			}
		}

		ai_will_do = {
			factor = 0.01
		}
	}
}

# REQUESTING BOON DECISIONS (SPENDING GRACE)
offmap_decisions = {

	# If your grace decisions will spawn a character then give them an appropriate flag eg: is_chinese_administrator and add them to the JD.60310 trigger switch to refund grace if they die early

	# Get a peace deal
	chinese_grace_peace_deal = {
		button_name = offmap_boons

		ai_check_interval = 12

		only_playable = yes

		from_potential = {
			has_dlc = "Jade Dragon"
			is_landed = yes
			mercenary = no
			holy_order = no
		}

		potential = {
			is_offmap_tag = offmap_china
		}

		allow = {
			show_only_failed_conditions = yes

			FROM = {
				show_scope_change = no

				in_revolt = no
				independent = yes
				NOT = { pays_tribute_to = ROOT }

				has_offmap_currency = {
					offmap = offmap_china
					value >= 350
				}

				custom_tooltip = {
					text = chinese_grace_peace_deal_allow_tt
					NOT = { has_character_modifier = peace_deal_with_china }
				}

				prisoner = no
				is_incapable = no
				is_inaccessible_trigger = no
			}

			offmap_china = {
				NOT = { has_policy = china_expansionist }
			}

			china_offmap_boon_decisions_enabled_trigger = yes
		}

		effect = {
			FROM = {
				show_scope_change = no

				sound_effect = china_grace_spend

				add_offmap_currency = {
					offmap = offmap_china
					value = -350
				}

				custom_tooltip = { text = chinese_grace_peace_deal_effect_tt }

				set_china_boon_cd_effect = yes
				letter_event = { id = JD.20026 }
			}
		}

		ai_will_do = {
			factor = 0.1

			trigger = {
				FROM = {
					independent = yes
					shares_realm_border_with = ROOT
					in_revolt = no

					capital_scope = {
						OR = {
							region = world_india_deccan
							region = world_india_bengal
							region = world_steppe_east
							region = world_himalayas
						}
					}

					offmap_china = {
						NOT = { has_policy = china_isolationist }
					}
				}
			}

			mult_modifier = {
				factor = 1.5

				realm_levy_diff = {
					who = FROM
					value >= 2000
				}
			}

			mult_modifier = {
				factor = 3

				realm_levy_diff = {
					who = FROM
					value = 5000
				}
			}

			mult_modifier = {
				factor = 0.1

				FROM = { has_grace_major_trigger = no }
			}
		}
	}

	# Get a Chinese doctor
	chinese_grace_doctor = {
		button_name = offmap_boons

		ai = no

		from_potential = {
			has_dlc = "Jade Dragon"
			has_dlc = "Reapers"
			is_landed = yes
			mercenary = no
			holy_order = no
		}

		potential = {
			is_offmap_tag = offmap_china
		}

		allow = {
			show_only_failed_conditions = yes

			FROM = {
				show_scope_change = no

				has_offmap_currency = {
					offmap = offmap_china
					value >= 350
				}

				custom_tooltip = {
					text = chinese_grace_doctor_allow_tt

					NOT = { has_assigned_minor_title = title_court_physician }
				}

				prisoner = no
				is_incapable = no
				is_inaccessible_trigger = no
			}

			china_offmap_boon_decisions_enabled_trigger = yes
		}

		effect = {
			FROM = {
				show_scope_change = no

				sound_effect = china_grace_spend

				add_offmap_currency = {
					offmap = offmap_china
					value = -250
				}

				set_china_boon_cd_effect = yes
				letter_event = { id = JD.20022 }
			}

		}

		ai_will_do = {
			factor = 0

		#	factor = 0.1
		#
		#	mult_modifier = {
		#		factor = 1.5
		#		FROM = {
		#			NOT = {
		#				any_courtier = {
		#					learning >= 15
		#				}
		#			}
		#		}
		#	}
		#
		#	mult_modifier = {
		#		factor = 10
		#		FROM = {
		#			NOT = {
		#				any_courtier = {
		#					learning >= 15
		#				}
		#			}
		#
		#			OR = {
		#				health < 3
		#				character_disease_trigger = yes
		#				has_symptom_trigger = yes
		#			}
		#		}
		#	}
		#
		#	mult_modifier = {
		#		factor = 0.1
		#		FROM = {
		#			NOT = { has_grace_medium_trigger = yes }
		#		}
		#	}
		}
	}

	# Chinese Artifact
	chinese_artifact = {
		button_name = offmap_boons

		ai_check_interval = 60

		only_playable = yes

		from_potential = {
			has_dlc = "Jade Dragon"
			is_landed = yes
			mercenary = no
			holy_order = no
		}

		potential = {
			is_offmap_tag = offmap_china
		}

		allow = {
			show_only_failed_conditions = yes

			FROM = {
				show_scope_change = no

				has_grace_major_trigger = yes
				prisoner = no
				is_incapable = no
				is_inaccessible_trigger = no
			}

			china_offmap_boon_decisions_enabled_trigger = yes

			custom_tooltip = {
				text = chinese_artifact_has_all_tt

				FROM = {
					NAND = {
						has_artifact = chinese_artwork
						has_artifact = chinese_calligraphy
						has_artifact = chinese_sculpture
						has_artifact = chinese_ceremonial_robes
						has_artifact = chinese_arm_protector
						has_artifact = chinese_serpent_spear
						has_artifact = chinese_ji
						has_artifact = chinese_crossbow
						has_artifact = chinese_bronze_sculpture
						has_artifact = chinese_book_health
						has_artifact = chinese_book_law
						has_artifact = chinese_book_history
						has_artifact = chinese_book_economy
						has_artifact = chinese_painting_of_glitterhoof
						has_artifact = chinese_tapestry
						has_artifact = chinese_tapestry_grand

						trigger_if = {
							limit = {
								offmap_china = {
									offmap_prev_ruler = { always = yes }
								}
							}

							has_artifact = chinese_prev_emperor_sculpture
						}
					}
				}
			}
		}

		effect = {
			FROM = {
				show_scope_change = no

				sound_effect = china_grace_spend
				detract_grace_major_effect = yes
				custom_tooltip = { text = chinese_artifact_effect_tt }
				set_china_boon_cd_effect = yes
				letter_event = { id = JD.3031 }
			}
		}

		ai_will_do = {
			factor = 0.1

			mult_modifier = {
				factor = 0.1
				NOT = { trait = greedy }
			}
		}
	}

	# Siege Engineers
	chinese_siege_engineers = {
		button_name = offmap_boons

		ai = no

		from_potential = {
			has_dlc = "Jade Dragon"
			mercenary = no
			holy_order = no
		}

		potential = {
			is_offmap_tag = offmap_china
		}

		allow = {
			show_only_failed_conditions = yes

			FROM = {
				show_scope_change = no

				has_offmap_currency = {
					offmap = offmap_china
					value >= 750
				}

				prisoner = no
				is_incapable = no
				is_inaccessible_trigger = no
			}

			china_offmap_boon_decisions_enabled_trigger = yes
		}

		effect = {
			FROM = {
				show_scope_change = no

				sound_effect = china_grace_spend

				add_offmap_currency = {
					offmap = offmap_china
					value = -750
				}

				custom_tooltip = { text = chinese_siege_engineers_effect_tt }

				set_china_boon_cd_effect = yes
				letter_event = { id = JD.3001 }
			}

		}

		ai_will_do = {
			factor = 0
		}
	}

	# Strategist
	chinese_strategist = {
		button_name = offmap_boons

		ai_check_interval = 60

		only_playable = yes

		from_potential = {
			has_dlc = "Jade Dragon"
			is_landed = yes
			mercenary = no
			holy_order = no
		}

		potential = {
			is_offmap_tag = offmap_china
		}

		allow = {
			show_only_failed_conditions = yes

			FROM = {
				show_scope_change = no

				has_offmap_currency = {
					offmap = offmap_china
					value >= 1050
				}

				prisoner = no
				is_incapable = no
				is_inaccessible_trigger = no
			}

			china_offmap_boon_decisions_enabled_trigger = yes
		}

		effect = {
			FROM = {
				show_scope_change = no

				sound_effect = china_grace_spend

				add_offmap_currency = {
					offmap = offmap_china
					value = -1050
				}

				if = {
					limit = { has_assigned_minor_title = title_strategist }
					custom_tooltip = { text = chinese_strategist_effect_2_tt }
				}
				else = {
					custom_tooltip = { text = chinese_strategist_effect_tt }
				}

				set_china_boon_cd_effect = yes
				letter_event = { id = JD.20040 }
			}
		}

		ai_will_do = {
			factor = 0.1

			trigger = {
				FROM = {
					is_nomadic = no
					NOT = { has_assigned_minor_title = title_strategist }
				}
			}

			# TODO: is useless. Do we want to set some threshold?
			# mult_modifier = {
			#	factor = 0.1
			#	FROM = { has_grace_major_trigger = no }
			# }
		}
	}

	# Request Scholar-Bureaucrat
	chinese_administrator = {
		button_name = offmap_boons

		ai_check_interval = 60

		only_playable = yes

		from_potential = {
			has_dlc = "Jade Dragon"
			is_landed = yes
			mercenary = no
			holy_order = no
		}

		potential = {
			is_offmap_tag = offmap_china
		}

		allow = {
			show_only_failed_conditions = yes

			FROM = {
				show_scope_change = no

				has_grace_massive_trigger = yes

				custom_tooltip = {
					text = chinese_administrator_allow_tt
					NOT = { has_assigned_minor_title = title_administrator }
				}

				prisoner = no
				is_incapable = no
				is_inaccessible_trigger = no
			}

			china_offmap_boon_decisions_enabled_trigger = yes
		}

		effect = {
			FROM = {
				show_scope_change = no

				sound_effect = china_grace_spend
				detract_grace_massive_effect = yes
				custom_tooltip = { text = chinese_administrator_effect_tt }

				tooltip = {
					if = {
						limit = {
							offmap_china = { has_status = china_golden_age }
						}

						add_character_modifier = {
							name = employing_jd_administrator_golden_age
							duration = -1
						}
					}
					else = {
						add_character_modifier = {
							name = employing_jd_administrator
							duration = -1
						}
					}
				}

				set_china_boon_cd_effect = yes
				letter_event = { id = JD.20030 }
			}
		}

		ai_will_do = {
			factor = 0.5

			trigger = {
				FROM = {
					is_tribal = no
					is_nomadic = no
				}
			}

			# TODO: is useless. Do we want to set some threshold?
			# modifier = {
			#	factor = 0.1
			#	FROM = { has_grace_major_trigger = no }
			# }
		}
	}

	# Request Master Engineer
	chinese_master_engineer = {
		button_name = offmap_boons

		ai_check_interval = 60

		only_playable = yes

		from_potential = {
			has_dlc = "Jade Dragon"
			is_landed = yes
			mercenary = no
			holy_order = no
		}

		potential = {
			is_offmap_tag = offmap_china
		}

		allow = {
			show_only_failed_conditions = yes

			FROM = {
				show_scope_change = no

				higher_tier_than = COUNT
				has_grace_massive_trigger = yes

				custom_tooltip = {
					text = chinese_master_engineer_allow_tt

					NOT = { has_assigned_minor_title = title_master_engineer }
				}

				prisoner = no
				is_incapable = no
				is_inaccessible_trigger = no
			}

			china_offmap_boon_decisions_enabled_trigger = yes
		}

		effect = {
			FROM = {
				show_scope_change = no

				sound_effect = china_grace_spend
				detract_grace_massive_effect = yes
				custom_tooltip = { text = chinese_master_engineer_effect_tt }
				set_china_boon_cd_effect = yes
				letter_event = { id = JD.20032 }
			}
		}

		ai_will_do = {
			factor = 0.1

			trigger = {
				FROM = {
					is_nomadic = no
					is_tribal = no
				}
			}

			# TODO: is useless. Do we want to set some threshold?
			# mult_modifier = {
			#	factor = 0.1
			#	FROM = { has_grace_major_trigger = no }
			# }
		}
	}

	chinese_silk_road_favored_status = {
		button_name = offmap_boons
		ai_check_interval = 36

		only_playable = yes

		from_potential = {
			has_dlc = "Jade Dragon"
			is_landed = yes
			mercenary = no
			holy_order = no
		}

		potential = {
			is_offmap_tag = offmap_china
		}

		allow = {
			show_only_failed_conditions = yes

			FROM = {
				show_scope_change = no

				has_offmap_currency = {
					offmap = offmap_china
					value >= 2000
				}

				NOT = { has_character_modifier = chinese_imperial_trade_contract }
				NOT = { has_character_modifier = chinese_favored_in_trade }

				custom_tooltip = {
					text = tooltip_silk_road_required

					any_realm_province = {
						trade_route = silk_road
						held_under_PREV = yes
					}
				}

				prisoner = no
				is_incapable = no
				is_inaccessible_trigger = no
			}

			china_offmap_boon_decisions_enabled_trigger = yes
		}

		effect = {
			FROM = {
				show_scope_change = no

				sound_effect = china_grace_spend

				add_offmap_currency = {
					offmap = offmap_china
					value = -2000
				}

				custom_tooltip = {
					text = chinese_silk_road_favored_status_modifier_tt

					add_character_modifier = {
						name = chinese_imperial_trade_contract
						years = 25
						inherit = yes
					}
				}

				set_china_boon_cd_effect = yes
				letter_event = { id = JD.30014 }
			}
		}

		ai_will_do = {
			factor = 0.1

			trigger = {
				FROM = {
					any_demesne_province = {
						trade_route = silk_road
						has_trade_post = yes
						owned_by = PREV
					}
				}
			}
		}
	}

	chinese_imperial_marriage = {
		button_name = offmap_boons

		third_party_filter = realm_including_me
		ai_third_party_filter = court
		third_party = FROM
		ai_check_interval = 12

		show_third_party_potential = yes

		only_playable = yes

		from_potential = {
			has_dlc = "Jade Dragon"
			is_landed = yes
			mercenary = no
			holy_order = no
		}

		potential = {
			is_offmap_tag = offmap_china
		}

		allow = {
			show_only_failed_conditions = yes

			FROM = {
				show_scope_change = no

				trigger_if = {
					limit = { has_character_modifier = peace_deal_with_china }

					has_offmap_currency = {
						offmap = offmap_china
						value >= 1050
					}
				}
				trigger_else = {
					has_offmap_currency = {
						offmap = offmap_china
						value >= 1400
					}
				}

				OR = {
					custom_tooltip = {
						text = can_marry_chinese_royal_tt

						is_adult = yes
						is_married = no
					}

					custom_tooltip = {
						text = has_courtier_eligible_for_marriage_tt

						OR = {
							any_dynasty_member = {
								is_adult = yes
								is_married = no
								vassal_of = ROOT_FROM
							}

							any_close_relative = {
								is_adult = yes
								is_married = no
								vassal_of = ROOT_FROM
							}
						}
					}
				}

				prisoner = no
				is_incapable = no
				is_inaccessible_trigger = no
			}

			china_offmap_boon_decisions_enabled_trigger = yes
		}

		third_party_potential = {
			# show_only_failed_conditions = yes

			FROMFROM = {
				show_scope_change = no

				OR = {
					dynasty = ROOT_FROM
					is_close_relative = ROOT_FROM
				}

				custom_tooltip = {
					text = vassal_of_ROOT_FROM_tt # TODO: add loc

					OR = {
						character = ROOT_FROM

						AND = {
							vassal_of = ROOT_FROM
							ai = yes
						}
					}
				}

				is_adult = yes

				custom_tooltip = {
					text = can_marry_chinese_royal_tt
					can_marry = yes
				}
			}
		}

		third_party_allow = {
		}

		effect = {
			hidden_effect = {
				FROMFROM = {
					add_trait = cannot_marry
					set_character_flag = awaiting_imperial_wedding
				}
			}

			FROM = {
				show_scope_change = no

				sound_effect = china_grace_spend

				if = {
					limit = { has_character_modifier = peace_deal_with_china }

					add_offmap_currency = {
						offmap = offmap_china
						value = -1050
					}
				}
				else = {
					add_offmap_currency = {
						offmap = offmap_china
						value = -1400
					}

					custom_tooltip = { text = chinese_imperial_marriage_peace_deal_tt }
				}

				set_china_boon_cd_effect = yes

				if = {
					limit = {
						ai = no
						is_ironman = yes
					}
					set_character_flag = achievement_imperial_marriage
				}

				letter_event = { id = JD.20046 }
			}

			if = {
				limit = { FROMFROM = { is_female = yes } }
				custom_tooltip = { text = chinese_imperial_marriage_prince_effect_tt }
			}
			else = {
				custom_tooltip = { text = chinese_imperial_marriage_princess_effect_tt }
			}
		}

		ai_will_do = {
			factor = 0.05

			mult_modifier = {
				factor = 0.5
				FROM = { lower_real_tier_than = KING }
			}

			mult_modifier = {
				factor = 0.75
				FROM = { independent = no }
			}
		}
	}

	chinese_request_invasion = {
		button_name = offmap_boons

		third_party_filter = independent_rulers
		third_party = FROM

		show_third_party_potential = yes

		ai = no

		from_potential = {
			has_dlc = "Jade Dragon"
			is_landed = yes
			mercenary = no
			holy_order = no
		}

		potential = {
			is_offmap_tag = offmap_china
		}

		allow = {
			show_only_failed_conditions = yes

			FROM = {
				show_scope_change = no

				has_offmap_currency = {
					offmap = offmap_china
					value >= 5000
				}

				prisoner = no
				is_incapable = no
				is_inaccessible_trigger = no
			}

			offmap_china = {
				governor = {
					show_scope_change = no

					war = no
				}

				OR = {
					has_status = china_stable
					has_status = china_golden_age
				}

				NOT = { has_policy = china_expansionist }
			}

			china_offmap_boon_decisions_enabled_trigger = yes
		}

		third_party_potential = {
			# show_only_failed_conditions = yes

			FROMFROM = {
				show_scope_change = no

				hidden_trigger = {
					NOT = { character = ROOT }
				}

				OR = {
					real_tier = EMPEROR
					real_tier = KING
				}

				num_of_count_titles_in_realm >= 40
				is_within_diplo_range = ROOT

				custom_tooltip = {
					text = chinese_request_invasion_rel_head_tt

					NOT = {
						any_demesne_title = {
							higher_real_tier_than = DUKE
							controls_religion = yes
						}
					}
				}

				custom_tooltip = {
					text = chinese_request_invasion_defeated_china_tt

					NOT = { has_character_flag = defeated_china }
				}
			}
		}

		third_party_allow = {
			show_only_failed_conditions = yes

			FROMFROM = {
				show_scope_change = no

				in_revolt = no

				NOR = {
					has_non_aggression_pact_with = ROOT
					is_allied_with = ROOT
					pays_tribute_to = ROOT
					has_character_modifier = peace_deal_with_china

					liked_by_offmap = {
						type = offmap_china
					}
				}
			}
		}

		effect = {
			FROMFROM = {
				save_event_target_as = chinese_invasion_target
			}

			hidden_effect = {
				offmap_china = {
					governor = {
						save_event_target_as = invasion_governor

						war = {
							target = FROMFROM
							casus_belli = destabilization_china_cb
						}
					}
				}
			}

			FROM = {
				show_scope_change = no

				sound_effect = china_grace_spend

				add_offmap_currency = {
					offmap = offmap_china
					value = -5000
				}

				save_event_target_as = chinese_invasion_instigator

				letter_event = { id = JD.3021 }
			}

			# Send news of invasion to interested player parties...
			any_player = {
				limit = {
					has_offmap_news_enabled = offmap_china
					is_within_diplo_range = ROOT
				}

				narrative_event = {
					id = JD.3022
					days = 1
				}
			}
		}

		ai_will_do = {
			factor = 0
		}
	}
}

# HOSTILE DECISIONS (ATTACKING CHINA)
offmap_decisions = {

	china_raid = {
		button_name = offmap_hostility

		ai_check_interval = 36

		only_playable = yes

		from_potential = {
			has_dlc = "Jade Dragon"
			is_landed = yes
			NOT = { has_character_modifier = china_raid_active }
			mercenary = no
			holy_order = no
		}

		potential = {
			is_offmap_tag = offmap_china
		}

		allow = {
			show_only_failed_conditions = yes

			FROM = {
				show_scope_change = no

				independent = yes
				is_allowed_to_loot = yes

				NOT = {
					is_tributary = {
						type = offmap
						suzerain = ROOT
					}
				}

				NOT = { has_character_modifier = peace_deal_with_china }

				custom_tooltip = {
					text = chinese_grace_supply_horses_not_already_supplying_tt

					NOT = { has_character_modifier = china_supply_horses }
				}

				custom_tooltip = { # Borders the eastern edge of the map
					text = chinese_grace_become_tributary_allow_chinese_influence_tt

					any_realm_province = {
						region = custom_chinese_invasion_target_region
						held_under_PREV = yes
					}
				}

				custom_tooltip = {
					text = china_offmap_boon_decisions_enabled_trigger_raiding_tt

					NOT = { has_character_modifier = china_raid_grace_cd }
				}

				prisoner = no
				is_incapable = no
				is_inaccessible_trigger = no
			}

			china_offmap_hostile_decisions_enabled_trigger = yes
		}

		effect = {
			FROM = {
				show_scope_change = no

				sound_effect = china_angered_emperor

				detract_grace_major_effect = yes

				hidden_effect = {
					add_character_modifier = {
						name = china_raid_active
						duration = -1
						inherit = yes
					}
				}

				letter_event = { id = JD.3051 }
			}
		}

		ai_will_do = {
			factor = 0.1

			trigger = {
				FROM = {
					has_grace_medium_trigger = no

					NOR = {
						trait = shy
						trait = content
						trait = craven
					}
				}

				offmap_china = {
					offmap_ruler = {
						NOT = { dynasty = FROM }
					}
				}
			}
		}
	}

	china_stop_raid = {
		button_name = offmap_hostility

		ai_check_interval = 36

		only_playable = yes

		from_potential = {
			has_dlc = "Jade Dragon"
			has_character_modifier = china_raid_active
			is_landed = yes
			mercenary = no
			holy_order = no
		}

		potential = {
			is_offmap_tag = offmap_china
		}

		allow = {
			# show_only_failed_conditions = yes

			FROM = {
				show_scope_change = no

				has_character_modifier = china_raid_active
			}
		}

		effect = {
			FROM = {
				show_scope_change = no

				sound_effect = china_grace_gain
				remove_character_modifier = china_raid_active

				add_character_modifier = {
					name = china_raid_grace_cd
					years = 5
					hidden = yes
				}
			}
		}

		ai_will_do = {
			factor = 0.1

			trigger = {
				trigger_if = {
					limit = {
						offmap_china = {
							offmap_ruler = {
								NOT = { dynasty = FROM }
							}
						}
					}

					OR = {
						trait = shy
						trait = content
						trait = craven
					}
				}
			}

			mult_modifier = {
				factor = 10

				offmap_china = {
					offmap_ruler = {
						dynasty = FROM
					}
				}
			}
		}
	}

	china_force_to_open = {
		button_name = offmap_hostility

		ai = no

		from_potential = {
			has_dlc = "Jade Dragon"
			mercenary = no
			holy_order = no
		}

		potential = {
			is_offmap_tag = offmap_china
		}

		allow = {
			show_only_failed_conditions = yes

			FROM = {
				show_scope_change = no

				independent = yes

				NOT = {
					is_tributary = {
						type = offmap
						suzerain = ROOT
					}
				}

				custom_tooltip = {
					text = force_china_open_cooldown_tt

					NOT = { has_character_modifier = china_force_open_cooldown }
				}

				OR = {
					custom_tooltip = { # Borders the Western Protectorate
						text = chinese_grace_become_tributary_allow_governor_neighbor_tt

						any_neighbor_independent_ruler = {
							has_landed_title = e_china_west_governor
						}
					}

					custom_tooltip = { # Borders a Chinese tributary
						text = chinese_grace_become_tributary_allow_tributary_neighbor_tt

						any_neighbor_independent_ruler = {
							suzerain = {
								has_landed_title = e_china_west_governor
							}
						}
					}

					custom_tooltip = { # Borders the eastern edge of the map
						text = chinese_grace_become_tributary_allow_chinese_influence_tt

						any_realm_province = {
							region = custom_chinese_invasion_target_region
							held_under_PREV = yes
						}
					}

					custom_tooltip = { # Within diplo range of China and has a port in India
						text = chinese_grace_become_tributary_allow_india_tt

						any_realm_province = {
							is_coastal = yes
							region = world_india
							held_under_PREV = yes
						}
					}
				}

				prisoner = no
				is_incapable = no
				is_inaccessible_trigger = no
			}

			offmap_china = {
				has_policy = china_isolationist
			}

			offmap_china = {
				custom_tooltip = {
					text = already_at_war_tt

					governor = {
						NOT = {
							any_war = {
								using_cb = force_open_china_cb
							}
						}
					}
				}
			}

			china_offmap_hostile_decisions_enabled_trigger = yes
		}

		effect = {
			offmap_china = {
				set_offmap_tmp_flag = china_force_open_in_progress
			}

			FROM = {
				show_scope_change = no

				sound_effect = china_angered_emperor

				add_character_modifier = {
					name = china_force_open_cooldown
					years = 15
					hidden = yes
				}

				character_event = {
					id = JD.60301
					tooltip = force_open_china_start_tt
				}
			}
		}

		ai_will_do = {
			factor = 0
		}
	}

	china_tributary_break_free = {
		button_name = offmap_hostility

		ai = no

		from_potential = {
			has_dlc = "Jade Dragon"
			mercenary = no
			holy_order = no
		}

		potential = {
			is_offmap_tag = offmap_china

			FROM = {
				is_tributary = {
					type = offmap
					suzerain = ROOT
				}
			}
		}

		allow = {
			show_only_failed_conditions = yes

			FROM = {
				show_scope_change = yes

				is_tributary = {
					type = offmap
					suzerain = ROOT
				}

				can_use_cb = {
					target = ROOT
					casus_belli = free_tributary_cb
				}

				NOT = { is_decision_allowed = tributary_independence_china }
				prisoner = no
				is_incapable = no
				is_inaccessible_trigger = no
			}

			china_offmap_hostile_decisions_enabled_trigger = yes
		}

		effect = {
			FROM = {
				show_scope_change = no

				sound_effect = china_angered_emperor

				war = {
					target = ROOT
					casus_belli = free_tributary_cb
				}
			}
		}

		ai_will_do = {
			factor = 0
		}
	}

	china_invade_dragon_throne = {
		button_name = offmap_hostility

		third_party_filter = home_court
		third_party = FROM

		show_third_party_potential = yes

		ai = no

		from_potential = {
			has_dlc = "Jade Dragon"
			mercenary = no
			holy_order = no
		}

		potential = {
			is_offmap_tag = offmap_china

			offmap_ruler = {
				NOT = { dynasty = FROM }
			}
		}

		allow = {
			show_only_failed_conditions = yes

			FROM = {
				show_scope_change = no

				independent = yes
				in_revolt = no

				NOT = {
					is_tributary = {
						type = offmap
						suzerain = ROOT
					}
				}

				OR = {
					custom_tooltip = { # Borders the Western Protectorate
						text = chinese_grace_become_tributary_allow_governor_neighbor_tt

						any_neighbor_independent_ruler = {
							has_landed_title = e_china_west_governor
						}
					}

					custom_tooltip = { # Borders the eastern edge of the map
						text = china_invade_dragon_throne_eastern_edge_tt

						any_realm_province = {
							region = custom_eastern_edge_of_map
							held_under_PREV = yes
						}
					}
				}

				custom_tooltip = {
					text = china_invade_dragon_throne_failed_tt

					NOT = { has_character_modifier = failed_invasion_of_china }
				}

				can_use_cb = {
					target = ROOT
					casus_belli = invasion_of_china_cb
					only_check_triggers = yes
				}

				NOT = { has_raised_levies = THIS }

				custom_tooltip = {
					text = china_invade_dragon_throne_levies_tt

					NOT = {
						any_vassal = {
							ROOT_FROM = {
								has_raised_levies = PREV
							}
						}
					}
				}

				NOT = { has_truce = ROOT }
				real_tier = EMPEROR

				trigger_if = {
					limit = { is_nomadic = yes }
					num_of_count_titles_in_realm >= 50
				}
				trigger_else = {
					realm_size >= 300
				}

				prisoner = no
				is_incapable = no
				is_inaccessible_trigger = no
			}

			china_offmap_hostile_decisions_enabled_trigger = yes

			offmap_china = {
				OR = {
					has_status = china_stable
					has_status = china_golden_age
				}

				ROOT = {
					show_scope_change = no

					custom_tooltip = {
						text = china_invade_dragon_throne_war_tt

						NOT = {
							any_war = {
								using_cb = invasion_of_china_cb
							}
						}
					}
				}
			}
		}

		third_party_potential = {
			# show_only_failed_conditions = yes

			FROMFROM = {
				show_scope_change = no

				dynasty = ROOT_FROM
				is_adult = yes
				is_primary_heir = no
				is_landed = no

				custom_tooltip = {
					text = is_not_from_china_tt
					courtier_from_china_trigger = no
				}

				has_inheritance_blocker = no

				custom_tooltip = {
					text = is_not_incapable_inbred_or_imbecile_tt

					is_incapable = no

					NOR = {
						trait = inbred
						trait = imbecile
					}
				}

				NOT = { trait = celibate }
			}
		}

		third_party_allow = {
			show_only_failed_conditions = yes

			FROMFROM = {
				show_scope_change = no

				prisoner = no
				is_ill = no
				is_inaccessible_trigger = no
			}
		}

		effect = {
			hidden_effect = {
				FROMFROM = { # Stop them from moving, marrying or being diplomatically dealt with
					set_character_flag = invasion_china_claimant
					set_character_flag = no_court_invites
					add_trait = cannot_marry
					diplomatic_immunity = yes
					save_global_event_target_as = invasion_of_china_claimant
				}

				ROOT = { # Set amount of troops
					set_offmap_tmp_flag = china_war_variables_set
				#	save_event_target_as = invasion_of_china_govenor

					set_variable = {
						which = china_war_troop_quantity
						value = 15
						# 15 regiments of ~500 units
					}

					set_variable = {
						which = china_war_target_match_mult
						value = 2
					}

					set_variable = {
						which = china_war_troop_quality
						value = 6
						# Value between 1-7
					}

					set_variable = {
						which = china_war_minimum_commander_martial
						value = 16
					}

					set_variable = { # Minimum 80k
						which = china_war_troop_quantity_override
						value = 160
					}
				}
			}

			FROM = {
				show_scope_change = no

				sound_effect = china_angered_emperor
				save_event_target_as = invasion_of_china_attacker

				custom_tooltip = {
					text = china_invade_dragon_throne_modifiers_tt

					set_offmap_currency = {
						offmap = offmap_china
						value = 0
					}

					remove_character_modifier = peace_deal_with_china
					remove_character_modifier = chinese_grace_send_gift_timer
					remove_character_modifier = chinese_grace_send_eunuch_timer
					remove_character_modifier = chinese_grace_send_concubine_timer
					remove_character_modifier = chinese_grace_tributary_timer
					remove_character_modifier = jd_china_boon_cd
					remove_character_modifier = china_force_open_cooldown
					remove_character_modifier = angered_china_modifier
					remove_character_modifier = chinese_imperial_trade_contract
				}

				hidden_effect = {
					add_character_modifier = {
						name = war_with_china_modifier
						duration = -1
						inherit = yes
					}

					war = {
						target = ROOT
						casus_belli = invasion_of_china_cb
					}
				}
			}

			any_player = {
				limit = {
					has_offmap_news_enabled = offmap_china
					is_within_diplo_range = ROOT
				}

				narrative_event = { id = JD.60400 }
			}
		}

		ai_will_do = {
			factor = 0
		}
	}
}