namespace = xilin_ai

#ϣ۹aiʱai

#ϣai
# No scope, like on_game_start
#on_monthly_pulse = {
event = {
	id = xilin_ai.1
	hide_window = yes
	is_triggered_only = yes
	
	trigger = {
			any_country = {
					has_authority = auth_xilin_mind
					is_ai = yes
			}
	}

	immediate = {
		random_country = {
			limit = { 
					has_authority = auth_xilin_mind
					is_ai = yes
			}
			country_event = { id = xilin_ai.2 }
		}
	}
}
#ϣai⽻˼·
#Ҫҿű߾
country_event = {
	id = xilin_ai.2
	hide_window = yes
  is_triggered_only = yes
  
  trigger = {
			has_authority = auth_xilin_mind
			is_ai = yes
	}

	immediate = {
	   		#1쿼Ҫaiű߾
	  		if = {
	  				limit = {
	  						any_country ={
	  								has_communications = prev
	  								has_closed_borders = prev
	  								is_country_type = default
	  								OR = {
			    							relative_power = { who = prev  category = fleet  value = equivalent }
			    							relative_power = { who = event_target:Dip_Country  category = fleet  value = inferior }
			    							relative_power = { who = event_target:Dip_Country  category = fleet  value = pathetic }
			    					}
			    					NOT = { has_country_flag  = f_refuse_open_border_to_xilin	}
	  						}
	  						#ûڽе⽻Ի
	  						NOT = { has_country_flag  = more_diplomacy_engaged	}
	  				}
	  				random_country = {
	  						limit = {
	  								has_communications = prev
	  								has_closed_borders = prev
	  								is_country_type = default
	  								OR = {	  										
			    							relative_power = { who = prev  category = fleet  value = equivalent }
			    							relative_power = { who = event_target:Dip_Country  category = fleet  value = inferior }
			    							relative_power = { who = event_target:Dip_Country  category = fleet  value = pathetic }
			    					}
			    					NOT = { has_country_flag  = f_refuse_open_border_to_xilin	}  						
	  						}
	  						save_event_target_as = Dip_More_OP_Country
	  				}
	  				#Ҫ󿪷ű߾Ի
	  				set_country_flag = more_diplomacy_engaged
	  				country_event = { id = xilin_diplo_dlg.2 }
	  		}
	   		#2쿼һ
	      country_event = { id = xilin_ai.3   days = 2   random = 1 }
	}	
}

#ʹӹ
country_event = {
	id = xilin_ai.3
	hide_window = yes
  is_triggered_only = yes
  
  trigger = {
			has_authority = auth_xilin_mind
			is_ai = yes
	}

	immediate = {
	   		#3쿼ʹӹ,ܽ
	  		if = {
	  				limit = {
	  						any_country ={
	  								is_subject = yes
	  								is_subject_type = xilin_servant
			       				exists = overlord
			       				overlord = { is_same_empire = prev }
			       				is_loyal_to = prev
	  								NOT = { has_country_flag = f_new_vassal }	  								
	  						}
	  						#ûڽе⽻Ի
	  						NOT = { has_country_flag  = more_diplomacy_engaged	}
	  				}
	  				random_country = {
	  						limit = {
	  								is_subject = yes
	  								is_subject_type = xilin_servant
			       				exists = overlord
			       				overlord = { is_same_empire = prev }
			       				is_loyal_to = prev
	  								NOT = { has_country_flag = f_new_vassal }	 						
	  						}
	  						save_event_target_as = Dip_More_OP_Country
	  				}
	  				#ʹӹ
	  				set_country_flag = more_diplomacy_engaged
	  				country_event = { id = xilin_diplo_dlg.4 }
	  		}
	   		#2쿼һ
	      country_event = { id = xilin_ai.4   days = 2   random = 1 }	   
	}	
}

#ǶԸӹĿƼԮ
country_event = {
	id = xilin_ai.4
	hide_window = yes
  is_triggered_only = yes
  
  trigger = {
			has_authority = auth_xilin_mind
			is_ai = yes
	}

	immediate = {
	   		#6쿼ǶԸӹĿƼԮ
	  		if = {
	  				limit = {
	  						any_country ={
	  								is_subject = yes
			       				exists = overlord
			       				overlord = { is_same_empire = prev }
			       				is_loyal_to = prev
			       				NOT = { 
			       					is_subject_type = xilin_discipline
										}
										NOT = {
											tech_unlocked_ratio = {
												who = root
												ratio > 0.8
											}
										}
										has_country_flag = f_get_tech_lib
	  								NOT = { has_modifier = m_xilin_tech_assistance  } 
	  						}
	  						#ûڽе⽻Ի
	  						NOT = { has_country_flag  = more_diplomacy_engaged	}
	  				}
	  				random_country = {
	  						limit = {
	  								is_subject = yes
			       				exists = overlord
			       				overlord = { is_same_empire = prev }
			       				is_loyal_to = prev
			       				NOT = { 
			       					is_subject_type = xilin_discipline
										}
										NOT = {
											tech_unlocked_ratio = {
												who = root
												ratio > 0.8
											}
										}
										has_country_flag = f_get_tech_lib
	  								NOT = { has_modifier = m_xilin_tech_assistance  } 			
	  						}
	  						save_event_target_as = Dip_More_OP_Country
	  				}
	  				#ƼԮ
	  				set_country_flag = more_diplomacy_engaged
	  				country_event = { id = xilin_diplo_dlg.6 }
	  		}
	   		#2쿼һ
	      country_event = { id = xilin_ai.5   days = 2   random = 1 }	   
	   
	}	
}

#ҪӿƼݿ
country_event = {
	id = xilin_ai.5
	hide_window = yes
  is_triggered_only = yes
  
  trigger = {
			has_authority = auth_xilin_mind
			is_ai = yes
	}

	immediate = {
	   		#9쿼ҪӿƼݿ
	  		if = {
	  				limit = {
	  						any_country ={
	  								AND = {
			       						is_subject = yes
			       						exists = overlord
			       						overlord = { is_same_empire = root }
			    					}
			    					NOT = { has_country_flag = f_get_tech_lib }
	  						}
	  						#ûڽе⽻Ի
	  						NOT = { has_country_flag  = more_diplomacy_engaged	}
	  				}
	  				random_country = {
	  						limit = {
	  								AND = {
			       						is_subject = yes
			       						exists = overlord
			       						overlord = { is_same_empire = root }
			    					}
			    					NOT = { has_country_flag = f_get_tech_lib }	
	  						}
	  						save_event_target_as = Dip_More_OP_Country
	  				}
	  				#ݿ
	  				set_country_flag = more_diplomacy_engaged
	  				country_event = { id = xilin_diplo_dlg.21 }
	  		}
	   		#2쿼һ
	      country_event = { id = xilin_ai.6   days = 2   random = 1 }		   
	}	
}

#Ҫϣ
country_event = {
	id = xilin_ai.6
	hide_window = yes
  is_triggered_only = yes
  
  trigger = {
			has_authority = auth_xilin_mind
			is_ai = yes
	}

	immediate = {
	   		#12쿼Ҫϣ
	  		if = {
	  				limit = {
	  						any_country ={
	  								has_claim = ROOT
			    					NOR = { 
			    							has_country_flag = f_refuse_destroy_claim 
					 							has_country_flag = f_agree_destroy_claim 					  
										}
										#ϣĵ
										is_xilin_enemy = no
	  						}
	  						#ûڽе⽻Ի
	  						NOT = { has_country_flag  = more_diplomacy_engaged	}
	  				}
	  				random_country = {
	  						limit = {
	  								has_claim = ROOT
			    					NOR = { 
			    							has_country_flag = f_refuse_destroy_claim 
					 							has_country_flag = f_agree_destroy_claim 					  
										}
										#ϣĵ
										is_xilin_enemy = no
	  						}
	  						save_event_target_as = Dip_More_OP_Country
	  				}
	  				#Ҫ
	  				set_country_flag = more_diplomacy_engaged
	  				country_event = { id = xilin_diplo_dlg.19 }
	  		}
	   		#2쿼һ
	      country_event = { id = xilin_ai.7   days = 2   random = 1 }		   
	}	
}

#Ҫӹĸ
country_event = {
	id = xilin_ai.7
	hide_window = yes
  is_triggered_only = yes
  
  trigger = {
			has_authority = auth_xilin_mind
			is_ai = yes
	}

	immediate = {
	   		#15쿼Ҫӹĸ
	  		if = {
	  				limit = {
	  						influence > 100
								unity > 1000
	  						any_country ={
	  								AND = {
			       					is_subject = yes
			       					exists = overlord
			       					overlord = { is_same_empire = root }
			    					}
			    					NOT = { 
					  					is_subject_type = xilin_discipline
										}
										subject_need_rebuild_gov = yes
										is_loyal_to = root
	  						}
	  						#ûڽе⽻Ի
	  						NOT = { has_country_flag  = more_diplomacy_engaged	}
	  				}
	  				random_country = {
	  						limit = {
	  								AND = {
			       					is_subject = yes
			       					exists = overlord
			       					overlord = { is_same_empire = root }
			    					}
			   	 					NOT = { 
					  					is_subject_type = xilin_discipline
										}
										subject_need_rebuild_gov = yes
										is_loyal_to = root
	  						}
	  						save_event_target_as = Dip_More_OP_Country
	  				}
	  				#Ҫӹĸ
	  				set_country_flag = more_diplomacy_engaged
	  				country_event = { id = xilin_diplo_dlg.7 }
	  		}
	   
	   
	}	
}