#希灵帝国战斗特效

namespace = xilin_battle

# This = owner of fleet 1
# From = owner of fleet 2
# FromFrom = fleet 1
# FromFromFrom = fleet 2
# on_entering_battle 潘多拉维斯卡战斗，放出潘多拉、维斯卡
country_event = {
	id = xilin_battle.1
	hide_window = yes
	is_triggered_only = yes
	
	trigger = { #攻击方是潘多拉
	        has_country_flag = f_xilin_empire
	        FromFrom = {
	            exists = leader
	            leader = {              
	                  has_leader_flag = f_panduola	                    
			        }
			        NOT = { has_fleet_flag = f_panduola_ship }
	        }
	}

	immediate = {
	    log = "panduola battle with [FromFromFrom.GetName],xilin_battle.1 is triggered"
			FromFrom = {
			       #创建两种ftl船，系统只会留下与舰队同类ftl船,2.0只需创建一种船		   
			       create_ship = {
								name = "NAME_panduola"
								design = "NAME_panduola"
								effect = {
									set_ship_flag = f_panduola_ship
								}
			       }
			       #create_ship = {
						 #		name = "NAME_panduola"
						 # 	design = "NAME_panduola_II"
						#		effect = {
						#			set_ship_flag = f_panduola_ship
						#		}
			      # }
			       set_fleet_flag = f_panduola_ship
			}
	}
}

# This = owner of fleet 1 (combatant)
# From = owner of fleet 2 (destroyed)
# FromFrom = fleet 1
# FromFromFrom = fleet 2
#战斗结束，潘多拉返航
#country_event = {  
#	id = xilin_battle.21
#	hide_window = yes
#	is_triggered_only = yes
	
#	trigger = { #攻击方是潘多拉
#	        has_country_flag = f_xilin_empire
#	        FromFrom = {
#	            exists = leader
#	            leader = {              
#	                  has_leader_flag = f_panduola	                    
#			        }
#			        has_fleet_flag = f_panduola_ship			       
#	        }
#	}

#	immediate = {
#			FromFrom = {
#			    fleet_event = { id = xilin_battle.3  days = 1 }
#      }
#	}
#}

# This = owner of fleet 1 (destroyed)
# From = owner of fleet 2 (combatant)
# FromFrom = fleet 1
# FromFromFrom = fleet 2
#on_fleet_destroyed_victim
#战斗结束，潘多拉返航
country_event = {  
	id = xilin_battle.2
	hide_window = yes
	is_triggered_only = yes
	
	trigger = { #战场上有潘多拉
	        NOT = { has_country_flag = f_xilin_empire }
	        FromFrom = {
	        	solar_system ={
	        		any_ship_in_system = {
	              fleet = {
	                 #exists = leader
	                 #leader = {  has_leader_flag = f_panduola	 }
			             has_fleet_flag = f_panduola_ship
	              }	           
	           	}
	        	
	        	}
	        }
	}

	immediate = {
	    #log = "[FromFrom.GetName] is destroyed, xilin_battle.2 is trigger"
			FromFrom = {
				solar_system = {
					 random_fleet_in_system = {
			       limit = { has_fleet_flag = f_panduola_ship }			       
			       #fleet_event = { id = xilin_battle.10000 } #测试
			       fleet_event = { id = xilin_battle.3  days = 2 } #用1可能还处于战斗状态，用2保险
			    }
				}
      }
	}
}


fleet_event = {
  id = xilin_battle.3
	hide_window = yes
	is_triggered_only = yes
  
  trigger = {
      has_fleet_flag = f_panduola_ship
      is_in_combat = no
  }
  immediate = {
     remove_fleet_flag = f_panduola_ship
     if = {
			       limit = { 
			          any_ship = {
			             has_ship_flag = f_panduola_ship
			          }			          
			       }
			       if = {
			          limit = { 
			          		num_ships = 1
			          		exists = leader  
			          } #只剩一艘船
			          leader = {
			              unassign_leader = this 
			          }
			       }
             owner = {
                random_owned_ship = {
                   limit = { has_ship_flag = f_panduola_ship }
			             destroy_ship = this
                }
             } 
			}
  }
}

# A fleet has successfully escaped from combat, executed right before the fleet enters FTL
# This = escaping fleet
# From = system escaped from
# FromFrom = system escaping to
# on_emergency_ftl
fleet_event = {
	id = xilin_battle.4
	hide_window = yes
	is_triggered_only = yes
	
	trigger = { #潘多拉舰队
	        #exists = leader
	        #leader = {              
	        #     has_leader_flag = f_panduola	                    
			    #}
			    has_fleet_flag = f_panduola_ship       
	}

	immediate = {
			 #潘多拉返航
			remove_fleet_flag = f_panduola_ship
      if = {
			       limit = { 
			          any_ship = {
			             has_ship_flag = f_panduola_ship
			          }			          
			       }
			       if = {
			          limit = { 
			          		num_ships = 1  
			          		exists = leader 
			          } #只剩一艘船
			          leader = {
			              unassign_leader = this 
			          }
			       }
             owner = {
                random_owned_ship = {
                   limit = { has_ship_flag = f_panduola_ship }
			             destroy_ship = this
                }
             } 
			}
	}
}

# A fleet has successfully escaped from combat, executed right before the fleet enters FTL
# This = escaping fleet
# From = system escaped from
# FromFrom = system escaping to
# on_emergency_ftl
fleet_event = {
	id = xilin_battle.5
	hide_window = yes
	is_triggered_only = yes
	
	trigger = { #对手逃走
	        NOR = {
	           has_fleet_flag = f_panduola_ship
	           has_fleet_flag = f_weisika_ship 
	        }
	        From = {#潘多拉在本星系
	           any_ship_in_system = {
	              fleet = {
	                 #exists = leader
	                 #leader = {  has_leader_flag = f_panduola	 }
			             has_fleet_flag = f_panduola_ship
	              }	           
	           }
	        }      
	}

	immediate = {
			 #隔1天潘多拉返航
			 From = {
			   random_fleet_in_system = {
			     limit = { has_fleet_flag = f_panduola_ship }
			     fleet_event = { id = xilin_battle.3  days = 2 }
			   }
			 }
	}
}

#维斯卡
# This = owner of fleet 1
# From = owner of fleet 2
# FromFrom = fleet 1
# FromFromFrom = fleet 2
# on_entering_battle 维斯卡战斗，放出维斯卡
country_event = {
	id = xilin_battle.6
	hide_window = yes
	is_triggered_only = yes
	
	trigger = { #攻击方是潘多拉
	        has_country_flag = f_xilin_empire
	        FromFrom = {
	            exists = leader
	            leader = {              
	                  has_leader_flag = f_weisika	                    
			        }
			        NOT = { has_fleet_flag = f_weisika_ship }
	        }
	}

	immediate = {
			FromFrom = {
			    #创建两种ftl船，系统只会留下与舰队同类ftl船,2.0只需创建1种船		   
			    create_ship = {
								name = "NAME_weisika"
								design = "NAME_weisika"
								effect = {
									set_ship_flag = f_weisika_ship
								}
			    }
			    #create_ship = {
					#			name = "NAME_weisika"
					#			design = "NAME_weisika_II"
					#			effect = {
					#				set_ship_flag = f_weisika_ship
					#			}
			    #}
			    set_fleet_flag = f_weisika_ship
			}
	}
}

# This = owner of fleet 1 (combatant)
# From = owner of fleet 2 (destroyed)
# FromFrom = fleet 1
# FromFromFrom = fleet 2
#战斗结束，维斯卡返航
#country_event = {  
#	id = xilin_battle.71
#	hide_window = yes
#	is_triggered_only = yes
	
#	trigger = { #攻击方是维斯卡
#	        has_country_flag = f_xilin_empire
#	        FromFrom = {
#	            exists = leader
#	            leader = {              
#	                  has_leader_flag = f_weisika	                    
#			        }
#			        has_fleet_flag = f_weisika_ship			       
#	        }
#	}

#	immediate = {
#	    log = "[FromFromFrom.GetName] is destroyed, xilin_battle.7 is trigger"
#			FromFrom = {
#			    fleet_event = { id = xilin_battle.8  days = 1 }
#      }
#	}
#}

# This = owner of fleet 1 (destroyed)
# From = owner of fleet 2 (combatant)
# FromFrom = fleet 1
# FromFromFrom = fleet 2
#战斗结束，维斯卡返航
country_event = {  
	id = xilin_battle.7
	hide_window = yes
	is_triggered_only = yes
	
	trigger = { #战场上有维斯卡
	        NOT = { has_country_flag = f_xilin_empire }
	        FromFrom = {
	        	solar_system ={
	        		any_ship_in_system = {
	              fleet = {
	                 #exists = leader
	                 #leader = {  has_leader_flag = f_weisika	 }
			             has_fleet_flag = f_weisika_ship
	              }	           
	           	}
	        	
	        	}
	        }
	}

	immediate = {
	    #log = "[FromFrom.GetName] is destroyed, xilin_battle.7 is trigger"
			FromFrom = {
				solar_system = {
					 random_fleet_in_system = {
			       limit = { has_fleet_flag = f_weisika_ship }
			       fleet_event = { id = xilin_battle.8  days = 2 }
			    }
				}
      }
	}
}

fleet_event = {
  id = xilin_battle.8
	hide_window = yes
	is_triggered_only = yes
  
  trigger = {
      has_fleet_flag = f_weisika_ship
      is_in_combat = no
  }
  immediate = {
     log = "xilin_battle.8 is triggered"
     remove_fleet_flag = f_weisika_ship
     if = {
			       limit = { 
			          any_ship = {
			             has_ship_flag = f_weisika_ship
			          }			          
			       }
			       if = {
			          limit = { 
			          	num_ships = 1 
			          	exists = leader  
			          } #只剩一艘船
			          leader = {
			              unassign_leader = this 
			          }
			       }
             owner = {
                random_owned_ship = {
                   limit = { has_ship_flag = f_weisika_ship }
			             destroy_ship = this
                }
             } 
			}
  }
}

# A fleet has successfully escaped from combat, executed right before the fleet enters FTL
# This = escaping fleet
# From = system escaped from
# FromFrom = system escaping to
# on_emergency_ftl
fleet_event = {
	id = xilin_battle.9
	hide_window = yes
	is_triggered_only = yes
	
	trigger = { #维斯卡舰队
	        #exists = leader
	        #leader = {              
	        #     has_leader_flag = f_weisika	                    
			    #}
			    has_fleet_flag = f_weisika_ship       
	}

	immediate = {
			 #维斯卡返航
			remove_fleet_flag = f_weisika_ship
      if = {
			       limit = { 
			          any_ship = {
			             has_ship_flag = f_weisika_ship
			          }			          
			       }
			       if = {
			          limit = { 
			          	num_ships = 1 
			          	exists = leader  
			          } #只剩一艘船
			          leader = {
			              unassign_leader = this 
			          }
			       }
             owner = {
                random_owned_ship = {
                   limit = { has_ship_flag = f_weisika_ship }
			             destroy_ship = this
                }
             } 
			}
	}
}

# A fleet has successfully escaped from combat, executed right before the fleet enters FTL
# This = escaping fleet
# From = system escaped from
# FromFrom = system escaping to
# on_emergency_ftl
fleet_event = {
	id = xilin_battle.10
	hide_window = yes
	is_triggered_only = yes
	
	trigger = { #对手逃走
	        NOR = {
	           has_fleet_flag = f_panduola_ship
	           has_fleet_flag = f_weisika_ship 
	        }
	        From = {#维斯卡在本星系
	           any_ship_in_system = {
	              fleet = {
	                 #exists = leader
	                 #leader = {  has_leader_flag = f_weisika	 }
			             has_fleet_flag = f_weisika_ship
	              }	           
	           }
	        }      
	}

	immediate = {
			 #隔1天潘多拉返航
			 From = {
			   random_fleet_in_system = {
			     limit = { has_fleet_flag = f_weisika_ship }
			     fleet_event = { id = xilin_battle.8  days = 2 }
			   }
			 }
	}
}

#潘多拉打爆星堡撤退判断
# This = Ship
# From = Disabler Ship
#on_ship_disabled
ship_event = {
  id = xilin_battle.11
	hide_window = yes
	is_triggered_only = yes
  
  #星系中有潘多拉舰队
  trigger = { 	
  		from = {
  				fleet = {
  					solar_system ={
	        		any_ship_in_system = {
	              fleet = {
			             has_fleet_flag = f_panduola_ship
	              }	           
	           	}        	
	        	}
  				}
  		}	
  }
  immediate = {
  	 log = "[This.GetName]失效了"
  	 From = {
  	   fleet = {
				 solar_system = {
					 random_fleet_in_system = {
			       limit = { has_fleet_flag = f_panduola_ship }
			       fleet_event = { id = xilin_battle.3  days = 2 } #用1可能还处于战斗状态，用2保险
			     }
				 }
			 }
     }
  }
}

#维斯卡打爆星堡撤退判断
# This = Ship
# From = Disabler Ship
#on_ship_disabled
ship_event = {
  id = xilin_battle.12
	hide_window = yes
	is_triggered_only = yes
  
  #星系中有维斯卡舰队
  trigger = { 	
  		from = {
  				fleet = {
  					solar_system ={
	        		any_ship_in_system = {
	              fleet = {
			             has_fleet_flag = f_weisika_ship 
	              }	           
	           	}        	
	        	}
  				}
  		}	
  }
  immediate = {
  	 log = "[This.GetName]失效了"
  	 From = {
  	   fleet = {
				 solar_system = {
					 random_fleet_in_system = {
			       limit = { has_fleet_flag = f_weisika_ship }
			       fleet_event = { id = xilin_battle.8  days = 2 } #用1可能还处于战斗状态，用2保险
			     }
				 }
			 }
     }
  }
}

#对于意外没有返航的，进入其他星系则返航