settlement_decisions = {

	hs_convert_chaoxue = {
		only_playable = yes
		filter = owned
		ai_target_filter = owned
		is_high_prio = yes
		ai_check_interval = 12
		
		from_potential = {
			OR = {
				has_landed_title = e_nieluoyi
				has_landed_title = e_hs_monster_rance
			}
		}
		
		potential = {
			holder_scope = {
				character = FROM
			}
			is_capital = yes
			location = {
				num_of_settlements = 5
				NOT = {
					has_province_modifier = hs_madked_chaoxue
				}
			}
		}
		allow = {
			FROM = {
				prestige = 3000
				wealth = 1000
			}
		}
		effect = {
			if = {
				limit = {
					FROM = {
						ai = no
					}
				}
				FROM = {
					prestige = -1000
					wealth = 1000
				}
			}
			else = {
				FROM = {
					prestige = -500
					wealth = 1000
				}
			}
			
			location = {
				add_province_modifier = {		
					name = hs_madked_chaoxue
					duration = 7000
				}
				set_variable = { which = prosperity_value value = 0 }
				province_event = { id = hstls.103 days = 1 } 
			}
		
		}
		
		revoke_allowed = {
			always = no
		}
		
		ai_will_do = {
			factor = 1
		}
	}
	hs_chaoxue_army = {
		only_playable = yes
		filter = owned
		ai_target_filter = owned
		is_high_prio = yes
		ai_check_interval = 18
		
		from_potential = {
			OR = {
				has_landed_title = e_nieluoyi
				has_landed_title = e_hs_monster_rance
			}
			
		}
		
		potential = {
			holder_scope = {
				character = FROM
			}
			is_capital = yes
			location = {
				has_province_modifier = hs_madked_chaoxue
			}
		}
		allow = {
			FROM = {
				prestige = 3000
			}
		}
		effect = {
			FROM = {
				prestige = -1000
				create_random_soldier = {
					dynasty = none 
					age = 16
					female = yes
					fertility = 0
					random_traits = yes
					attributes = { martial = 20 }
					
					trait = hs_bakemono
				}
				new_character = {
					opinion = {	modifier = opinion_loyal_servant who = ROOT }
					random_list = {
						10 = {
							trigger = {has_landed_title = e_nieluoyi}
							random_list = {
								1 = {add_trait = yl_nieluoyi}
								1 = {add_trait = yl_nieluoyi2}
								1 = {add_trait = yl_nieluoyi3}
								1 = {add_trait = yl_nieluoyi4}
							}
						}
						10 = {
							trigger = {has_landed_title = e_hs_monster_rance}
							random_list = {
								1 = {add_trait = yl_rancesub1}
								1 = {add_trait = yl_rancesub2}
								1 = {add_trait = yl_rancesub3}
							}
						}
						
					}
					will_not_marry_effect = yes
				}
				
			}
			FROM = {
				capital_scope = {
					FROM = {
						spawn_unit = {							
							owner = FROM
							home = PREV
							province = PREV
							troops = {
								hs_aliens = { 1000 1000 }
								light_cavalry = { 1200 1200 }
								knights = { 450 1050 }
								horse_archers = { 300 300 }
							}
							disband_on_peace = no
							reinforces = yes
							reinforce_rate_multiplier = 0.3
							merge = yes
							attrition = 0
							cannot_inherit = no
							maintenance_multiplier = 0
						}
					}
				}	
			}
		}
		
		revoke_allowed = {
			always = no
		}
		
		ai_will_do = {
			factor = 1
		}
	}
}
offmap_decisions = {


	hs_chinese_master_hero = {
		only_playable = yes
		button_name = offmap_boons
		ai_check_interval = 600

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

		potential = {
			is_offmap_tag = offmap_china
			hs_summoned_all_chinese_hero_trigger = no
			
		}
	
		allow = {
			show_only_failed_conditions = yes
			FROM = {
				show_scope_change = no
				higher_tier_than = COUNT
				has_offmap_currency = { offmap = offmap_china value = 5000 }
				prisoner = no
				NOT = { trait = incapable }
				is_inaccessible_trigger = no
			}
			FROM = {
				custom_tooltip = {
					text = hs_has_remains_tooltip
					any_artifact = {
						has_artifact_flag = remainsture 
					}
				}								
			}
			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 = -5000
				}
				random_artifact = {
					limit = { has_artifact_flag = remainsture }
					destroy_artifact = yes 
				}
			}
			hidden_effect = { offmap_china = { governor = { character_event = { id = yl_summon.200 } } } }
			hidden_effect = { FROM = { set_china_boon_cd_effect = yes } }
		}

		revoke_allowed = {
			always = no
		}

		ai_will_do = {
			factor = 1
			modifier = {
				FROM = {
					NOT = { has_grace_major_trigger = yes }
				}
				factor = 0.1
			}
			modifier = {
				factor = 0
				FROM = {	
					OR = {
						is_nomadic = yes
						is_tribal = yes
					}
				}
			}
		}
	}









}
decisions = {
	yl_summon = {
		ai_check_interval = 12
		only_playable = yes
		potential = {
			is_landed = yes
			OR = {
				AND = {
					has_game_rule = {
						   name = hs_summon_gamerules
						   value = YES
					}
					ai = yes
				}
				ai = no
			}
			NOT = {
				OR = {
					trait = incapable
					trait = imbecile
				}
			}
			NOT = {hs_summoned_allhero_trigger = yes}
		}
		allow = {
			higher_tier_than = COUNT
			custom_tooltip = {
				text = hs_has_remains_tooltip
				any_artifact = {
					has_artifact_flag = hs_flag_saintremains 
				}
			}
			OR = {
				any_courtier_or_vassal  = {
					trait = hs_summoner
				}
				trait = hs_summoner
			}
			NOT = {has_character_modifier = jinxingzhaohuan}
			piety = 300
			prestige = 1500
			prisoner = no
			NOT = {
				has_character_modifier = in_seclusion
			}
		}
		effect = {
			#if = {
			#	limit = { ai = yes }
			#	add_character_modifier = {
			#		name = jinxingzhaohuan
			#		years = 10
			#	}
			#}
			#narrative_event = { id = yl_summon.1 }
			
			
			if = {
				limit = { ai = no }
				if = {
					limit = {
						has_game_rule = {
							name = hs_connectsummon_gamerules
							value = YES
						}
					}
					scaled_wealth = {
						value = -1.3
						min = -600
						max = -3500
					}
					piety = -600
					prestige = -750
					add_character_modifier = {
						name = jinxingzhaohuan
						years = 3
					}
				}
				else ={
					scaled_wealth = {
						value = -0.7
						min = -300
						max = -1500
					}
					piety = -400
					prestige = -450
					add_character_modifier = {
						name = jinxingzhaohuan
						years = 2
					}
				}
				
				
				
			}
			if = {
				limit = { 
					any_artifact = {
						has_artifact_flag = remainsture 
					} 
				}
				narrative_event = { id = yl_summon.1 }
				random_artifact = {
					limit = { has_artifact_flag = remainsture }
					destroy_artifact = yes 
				}
				set_character_flag = hs_success_summon
				break = yes				
			}
			if = {
				limit = { 
					any_artifact = {
						has_artifact_flag = remainsfake 
					} 
				}
				narrative_event = { id = yl_summon.6 }
				random_artifact = {
					limit = { has_artifact_flag = remainsfake }
					destroy_artifact = yes 
				} 
			}
			hidden_effect = { hs_iodltimes_effect = yes }

		}
		ai_will_do = {
			factor = 1
		}
	}
	yl_summon_opening = {
		ai_check_interval = 3000
		only_playable = yes
		ai = no
		is_high_prio = yes
		potential = {
			NOT = {has_global_flag = yl_summoned_opening}
			NOT = {
				has_game_rule = {
					   name = hs_summon_opening_gamerules
					   value = NO
				}
			}
			NOT = {hs_summoned_allhero_trigger = yes}
		}
		allow = {
			always = yes
		}
		effect = {
			set_global_flag = yl_summoned_opening
			hidden_tooltip = {
				if = {
					limit = {
						has_game_rule = {
						   name = hs_summon_opening_gamerules
						   value = one
						}
					}
					set_variable = { which = hscount value = 1 }
				}
				if = {
					limit = {
						has_game_rule = {
						   name = hs_summon_opening_gamerules
						   value = two
						}
					}
					set_variable = { which = hscount value = 2 }
				}
				if = {
					limit = {
						has_game_rule = {
						   name = hs_summon_opening_gamerules
						   value = three
						}
					}
					set_variable = { which = hscount value = 3 }
				}
				
				while = {
					limit = {
						check_variable = {
							which = hscount
							value = 1
						}
					}    
					subtract_variable = {
						which = hscount
						value = 1
					}
					hidden_tooltip = {hs_summonhero_effect = yes}
				}
				set_variable = { which = hscount value = 0 }
			}
		}
		ai_will_do = {
			factor = 1
		}
	}
	hs_hold_the_budoukai  = {
		only_independent = yes
		is_high_prio = yes
		ai_check_interval = 60
		only_playable = yes
		potential = {
			is_playable = yes
			#NOR = {
			#	has_character_modifier = epic_tournament
			#	has_character_flag = epic_tournament
			#}
			#OR = {
			#	religion_group = christian
			#	religion_group = jewish_group
			#	religion_group = zoroastrian_group
			#}
			independent = yes
			NOT = { is_nomadic = yes }			
			OR = {
				tier = king
				tier = emperor 
			}			
			location = {
				owner = { character = ROOT }
			}
		}
		allow = {
			war = no
			prisoner = no
			in_command = no
			NOT = { is_inaccessible_trigger = yes }
			age = 16
			prestige = 3500			
			custom_tooltip = {
				text = hs_hold_the_budoukai_tooltip
				hidden_tooltip = { 
					OR = {
						NOT = { has_global_flag = hs_holding_budoukai }
						had_global_flag = { flag = hs_holding_budoukai years = 10 }
						#had_global_flag = { flag = hs_holding_budoukai days = 35 }
					} 
				}
			}
			custom_tooltip = {
				text = is_not_busy_trigger_tooltip
				hidden_tooltip = { NOT = { has_character_flag = do_not_disturb } }
			}
		}
		effect = {
			#add_character_modifier = {
			#	name = epic_tournament
			#	years = 100
			#	hidden = yes
			#}
			clr_global_flag = hs_holding_budoukai			
			set_global_flag = hs_holding_budoukai
			#hidden_tooltip = { character_event = { id = 70999 days = 10 } } # Safety catch flag clearing
			if = {
				limit = {ai = no}
				scaled_wealth = {
					value = -3
					min = -1500
					max = -10000
				}
			}
			save_event_target_as = hs_target_budoukai_holder
			prestige = 500
			any_independent_ruler = {
				limit = {
					higher_real_tier_than = BARON
					ai = yes
				}
				character_event = {
					 id = hstls.201 
				}
			}
			any_player = {character_event = {id = hstls.202}}
			
			any_player = { narrative_event = { id = hstls.200 days = 3} }
			hidden_tooltip = {
				any_independent_ruler = {
					limit = { 
						prisoner = no
						in_command = no
						is_incapable = no
						age = 12
						ai = yes
						NOT = {
							has_character_flag = hs_attend_budoukai_member
						}
						OR = {
							combat_rating = 50
							trait = brave
						}
					}
					set_character_flag = hs_attend_budoukai_member
					opinion = { modifier = opinion_hs_attend_budaokai who = event_target:hs_target_budoukai_holder }
					reverse_opinion = {
						who = event_target:hs_target_budoukai_holder
						modifier = opinion_hs_attend_budaokai
					}
					character_event = {id = hstls.299 days = 15}
				}
			}
			custom_tooltip = {
				text = realm_prospers_custom_tooltip
				hidden_tooltip = {
					any_realm_province = {
						limit = {
							any_province_holding = {
								OR = {
									holding_type = city
									holding_type = castle
									holding_type = tribal
								}
							}
							NOR = {
								has_province_modifier = depopulated_1
								has_province_modifier = depopulated_2
								has_province_modifier = depopulated_3
							}
						}
						change_variable = { which = prosperity_value value = 25 }
					}
				}
			}
		}
		ai_will_do = {
			factor = 1
		}
	}
}

decisions = {
	hs_become_summoner = {
		ai = no
		ai_check_interval = 1000
		
		potential = {
			has_game_rule = {
			   name = hs_summoner_eazy_gamerules
			   value = NO
			}
			higher_tier_than = COUNT
			NOT = {
				trait = hs_summoner
			}
			NOT = {
				OR = {
					trait = incapable
					trait = imbecile
				}
			}
		}
		allow = {
			OR = {
				trait = cynical
				trait = erudite
				trait = scholar
				trait = mystic
				trait = quick
				trait = genius
			}
			learning = 15
			any_courtier_or_vassal  = {
				trait = hs_summoner
			}
		}
		effect = {
			piety = -200
			wealth = -250
			add_trait = hs_summoner
		}
		ai_will_do = {
			factor = 0
		}
	}
}
decisions = {
	hs_become_summoner_2 = {
		ai_check_interval = 120
		
		potential = {
			has_game_rule = {
			   name = hs_summoner_eazy_gamerules
			   value = YES
			}
			higher_tier_than = COUNT
			NOT = {
				trait = hs_summoner
			}
			NOT = {
				OR = {
					trait = incapable
					trait = imbecile
				}
			}
		}
		allow = {
			OR = {
				trait = cynical
				trait = erudite
				trait = scholar
				trait = mystic
				trait = quick
				trait = genius
				learning = 20
			}
			learning = 15
		}
		effect = {
			piety = -200
			wealth = -250
			add_trait = hs_summoner
		}
		ai_will_do = {
			factor = 1
		}
	}
}
targetted_decisions = {
	yl_idenfiyremains = {	
		filter = self
		ai_target_filter = self
		ai_check_interval = 60
		is_high_prio = yes
		potential = {
			any_artifact = {
				OR ={
					artifact_type = bj_saintremains 
					artifact_type = bj_saintremainsfake
				} 
			}
			NOT = {
				OR = {
					trait = incapable
					trait = imbecile
				}
			}			
			is_inaccessible_trigger  = no
			is_adult = yes
		}
		allow = {
			OR = {
				learning = 20
				trait = hs_summoner
			}
		}
		effect = {		
			wealth = -5
			hidden_tooltip = {
				any_artifact = {
					limit = { artifact_type = bj_saintremainsfake }
					destroy_artifact = yes 
				}
				random_artifact = {
					limit = { artifact_type = bj_saintremains }
					destroy_artifact = yes 
					ROOT = {add_artifact = bj_tureremains}
				} 
			}
		}
		ai_will_do = {
			factor = 1
		}
	}
	yl_exchangehero = {	
		ai_target_filter = none
		ai = no
		from_potential = {
			has_global_flag = hs_exchange_hero_enable			
			ai = no
		}
		potential = {
			trait = hs_trait_shouzhao
		}
		allow = {
			always = yes
		}
		effect = {
			ROOT = {
				clear_focus = yes
				cancel_ambition = yes
			}
			FROM = {
				set_player_character = ROOT
			}
			clr_global_flag = hs_exchange_hero_enable
		}
		ai_will_do = {
			factor = 0
		}
	}
	yl_takesaintremains = {
		
		filter = home_court 
		ai_target_filter = "home_court"
		ai_check_interval = 60
		third_party_filter = artifacts
		third_party = ROOT
		
		potential = {
			is_within_diplo_range = FROM
				ROOT = {
					num_of_artifacts = 1
					any_artifact = {
						has_artifact_flag = hs_flag_saintremains 
					}
				}			
		}
		third_party_potential = {
			FROMFROM = {
				show_scope_change = no
				has_artifact_flag = hs_flag_saintremains
			}
		}
		allow = {
			FROM = {
				prestige = 1500
			}
			ROOT = {
				#is_landed = no
				prisoner = yes
			}		
		}
			
		effect = {
			FROM = {
				prestige = -100
				piety = -50
				save_event_target_as = hs_target_character
			}
			hidden_tooltip = {
				FROMFROM = {
					show_scope_change = no
					transfer_artifact = {
						from = ROOT
						to = event_target:hs_target_character
					}
				}
			}
			clear_event_target = hs_target_character
		}
		ai_will_do = {
			factor = 1
		}
	}
	yl_affordsaintremains = {
		
		ai_target_filter = realm
		ai_check_interval = 48
		third_party_filter = artifacts
		third_party = ROOT
		
		potential = {
			is_within_diplo_range = FROM
				ROOT = {
					num_of_artifacts = 1
					any_artifact = {
						has_artifact_flag = hs_flag_saintremains 
					}
				}			
		}
		third_party_potential = {
			FROMFROM = {
				show_scope_change = no
				has_artifact_flag = hs_flag_saintremains
			}
		}
		allow = {
			FROM = {
				prestige = 2500
			}		
		}
			
		effect = {
			if = {
				limit = {
					FROMFROM = {quality = 5}
				}
				if = {
					limit = {
						FROM = {
							is_close_relative = ROOT
						}
					}
					FROM = {
						transfer_scaled_wealth = {
							to = ROOT 
							value = 0.25
							min = 400
						}
					}
				}
				else = {
					FROM = {
						transfer_scaled_wealth = {
							to = ROOT 
							value = 0.5
							min = 800
						}
					}
				}
			}
			else = {
				if = {
					limit = {
						FROM = {
							is_close_relative = ROOT
						}
					}
					FROM = {
						transfer_scaled_wealth = {
							to = ROOT 
							value = 0.15
							min = 200
						}
					}
				}
				else = {
					FROM = {
						transfer_scaled_wealth = {
							to = ROOT 
							value = 0.3
							min = 400
						}
					}
				}
			}
			
			
			
			FROM = {				
				save_event_target_as = hs_target_character
			}
			hidden_tooltip = {
				FROMFROM = {
					show_scope_change = no
					transfer_artifact = {
						from = ROOT
						to = event_target:hs_target_character
					}
				}
			}
			clear_event_target = hs_target_character
		}
		ai_acceptance = {
			factor = -10 # The base score
			show_maybe_for_human = no #Whether to always show "maybe" for human targets (defined as ROOT being controlled by a player). Defaults to "yes"
			additive_modifier = {
				value = 50
				localisation_key = "rm_reason_prestige"
				FROM = {prestige = 10000}
			}
			additive_modifier = {
				value = 30
				localisation_key = "rm_reason_prestige"
				AND = {
					FROM = {prestige < 10000}
					FROM = {prestige = 5000}
				}
			}
			additive_modifier = {
				value = 10
				localisation_key = "rm_reason_prestige"
				AND = {
					FROM = {prestige < 5000}
					FROM = {prestige = 2000}
				}
			}
			additive_modifier = {
				value = -50
				localisation_key = "rm_reason_prestige2"
				ROOT = {prestige = 5000}
			}
			additive_modifier = {
				value = -30
				localisation_key = "rm_reason_prestige2"
				AND = {
					ROOT = {prestige < 5000}
					ROOT = {prestige = 2000}
				}
			}
			additive_modifier = {
				value = -10
				localisation_key = "rm_reason_prestige2"
				AND = {
					ROOT = {prestige < 2000}
					ROOT = {prestige = 500}
				}
			}
			additive_modifier = {
				value = 100
				ROOT = {is_liege_or_above = FROM}
			}
			additive_modifier = {
				value = -100
				trait = hs_summoner
			}
			additive_modifier = {
				value = 30
				trait = greedy
			}
			additive_modifier = {
				value = -1000
				is_rival = FROM
			}
			additive_modifier = {
				value = -50
				NOT = {religion = FROM }
			}
			
			
			additive_modifier = {
				value = -50
				localisation_key = "rm_reason_wealth"
				wealth = 10000
			}
			additive_modifier = {
				value = -30
				localisation_key = "rm_reason_wealth"
				AND = {
					wealth < 10000
					wealth = 5000
				}
			}
			additive_modifier = {
				value = -10
				localisation_key = "rm_reason_wealth"
				AND = {
					wealth < 5000
					wealth = 2000
				}
			}
			additive_modifier = {
				value = 15
				localisation_key = "rm_reason_wealth"
				wealth < 0
				is_ruler = yes
			}
			additive_modifier = {
				value = -20
				NOT = { opinion = { who = FROM value = -90 } }
			}
			additive_modifier = {
				value = -20
				NOT = { opinion = { who = FROM value = -50 } }
			}
			additive_modifier = {
				value = -20
				NOT = { opinion = { who = FROM value = 0 } }
			}
			additive_modifier = {
				value = 15
				opinion = { who = FROM value = 60 } 
			}
			additive_modifier = {
				value = 15
				opinion = { who = FROM value = 80 } 
			}
			additive_modifier = {
				value = 15
				opinion = { who = FROM value = 100 } 
			}
			additive_modifier = {
				value = 50
				is_lover = FROM
			}
			additive_modifier = {
				value = 30
				is_friend = FROM
			}	
			additive_modifier = {
				value = 30
				is_allied_with = FROM
			}	
			additive_modifier = {
				value = 100				
				ROOT = {has_opinion_modifier = { who = FROM modifier = opinion_loyal_servant }}
			}			
		}
		ai_will_do = {
			factor = 1
		}
	}
}