###################################
#
# The Rising Sun Empire Events
#
# Id 270919 - 270927 are reserved
#
###################################

## Echoes of the Rising Sun Empire
narrative_event = {
	id = 270919
	title = EVTNAME270919
	desc = EVTDESC270919
	major = yes
	
	picture = "GFX_evt_rising_sun"
	border = "GFX_event_narrative_frame_war"
	
	only_playable = yes
	
	trigger = {
		OR = {
			AND = {
				has_game_rule = {
					name = RISING_SUN_INVASION
					value = yes_rising_sun_invasion
				}
				year = 1492
				OR = {
					has_global_flag = timur_spawned
					has_global_flag = timur_spawned_by_event
				}
			}
			AND = {
				has_game_rule = {
					name = RISING_SUN_INVASION
					value = yes_early_rising_sun_timurids
				}
				year = 1242
				OR = {
					has_global_flag = timur_spawned
					has_global_flag = timur_spawned_by_event
				}
			}
			AND = {
				has_game_rule = {
					name = RISING_SUN_INVASION
					value = yes_early_rising_sun_invasion
				}
				year = 1242
			}
		}
		has_global_flag = mongol_empire_arrival # To make sure the Rising Sun events happens AFTER the Mongol Horde
		NOT = { has_global_flag = rising_sun_empire_echoes }
	}
	
	mean_time_to_happen = {
		months = 240
	}
	
	immediate = {
		set_global_flag = rising_sun_empire_echoes
		activate_title = { title = k_guandong status = yes }
		set_title_landless = {
			title = k_guandong
			status = yes
		}
		create_random_soldier = {
			random_traits = no
			dynasty = 1900279 # ID pour Umezu
			name = "Yoshijiro"
			culture = japanese
			religion = hakko-ichiu
			age = 57
			attributes = {
				martial = 9
				diplomacy = 3
				stewardship = 6
				intrigue = 5
				learning = 3
			}
			health = 11
			fertility = 0.5
			trait = brilliant_strategist
			trait = wroth
			trait = cruel
			trait = proud
			trait = zealous
		}
		new_character = {
			k_guandong = {
				grant_title = PREV
			}
			set_character_flag = rising_sun_invasion_operation
			set_defacto_liege = THIS
			save_event_target_as = rising_sun_commander
			spawn_unit = {
				province = 1514 # Ejin
				troops = {
					light_infantry = { 500 500 }
				}
			}
		}
	}
	
	option = {
		name = "EVTOPTA270919"
		trigger = {
			character = ROOT
		}
		set_character_flag = refused_kwantung_proposal
		
		hidden_tooltip = {
			random_player = {
				limit = {
					NOT = { has_character_flag = refused_kwantung_proposal }
				}
				character_event = { id = 270922 }
			}
		}
	}
	option = {
		name = "EVTOPTB270919"
		trigger = {
			AND = {
				ai = no
				character = ROOT
			}
		}
		tooltip_info = yes

    	custom_tooltip = {
    		text = player_character_dynamic_rising_sun_commander_TT
    		if = {
    			limit = {
    				event_target:rising_sun_commander = {
    					is_alive = yes
    					ai = yes
    				}
    			}
    			set_player_character = event_target:rising_sun_commander
    		}
    	}
	}
	option = {
		name = "EVTOPTC270919"
		trigger = {
			NOT = { character = ROOT }
		}
	}
}

## Arrival of the Guandong Army
narrative_event = {
	id = 270920
	title = "EVTNAME270920"
	desc = "EVTDESC270920"
	major = yes
	hide_new = yes
	
	picture = "GFX_evt_mukden_incident"
	border = "GFX_event_narrative_frame_war"
	
	only_playable = yes
	
	trigger = {
		has_landed_title = k_guandong
		has_character_flag = rising_sun_invasion_operation
		NOT = { has_global_flag = guandong_army_arrival }
		war = no
	}
	
	mean_time_to_happen = {
		months = 6
	}
	
	immediate = {
		set_global_flag = guandong_army_arrival
	}
	
	option = {
		name = "OK"
		trigger = {
			has_landed_title = k_guandong
		}
		1514 = { # Ejin
			top_liege = {
				ROOT = {
					war = {
						casus_belli = rising_sun_invasion
						target = PREVPREV # The top liege of the owner
						thirdparty_title = d_juyan # The de jure kingdom
					}
				}
			}
		}
		wealth = 75000
			create_character = {
				random_traits = yes
				dynasty = random
				religion = hakko-ichiu
				culture = ROOT
				female = no
				age = 52
				attributes = {
					martial = 12
				}
				trait = brilliant_strategist
			}
			create_character = {
				random_traits = yes
				dynasty = random
				religion = hakko-ichiu
				culture = ROOT
				female = no
				age = 54
				attributes = {
					martial = 12
				}
				trait = brilliant_strategist
			}
			spawn_unit = {
				province = 1514 # Ejin
				troops = {
					light_infantry = { 2700 2700 }
					heavy_infantry = { 1600 1600 }
					horse_archers = { 541 541 }
					light_cavalry = { 300 300 }
					knights = { 100 100 }
				}
			}
			spawn_unit = {
				province = 1514 # Ejin
				troops = {
					light_infantry = { 2700 2700 }
					heavy_infantry = { 1600 1600 }
					horse_archers = { 541 541 }
					light_cavalry = { 300 300 }
					knights = { 100 100 }
				}
			}
			spawn_unit = {
				province = 1514 # Ejin
				troops = {
					light_infantry = { 2700 2700 }
					heavy_infantry = { 1600 1600 }
					horse_archers = { 541 541 }
					light_cavalry = { 300 300 }
					knights = { 100 100 }
				}
			}
			spawn_unit = {
				province = 1514 # Ejin
				troops = {
					light_infantry = { 2700 2700 }
					heavy_infantry = { 1600 1600 }
					horse_archers = { 541 541 }
					light_cavalry = { 300 300 }
					knights = { 100 100 }
				}
			}
			create_character = {
				random_traits = yes
				dynasty = random
				religion = hakko-ichiu
				culture = ROOT
				female = no
				age = 39
				attributes = {
					martial = 12
				}
				trait = brilliant_strategist
			}
			spawn_unit = {
				province = 1514 # Ejin
				troops = {
					light_infantry = { 2700 2700 }
					heavy_infantry = { 1600 1600 }
					horse_archers = { 541 541 }
					light_cavalry = { 300 300 }
					knights = { 100 100 }
				}
			}
			create_character = {
				random_traits = yes
				dynasty = random
				religion = hakko-ichiu
				culture = ROOT
				female = no
				age = 35
				attributes = {
					martial = 12
				}
				trait = brilliant_strategist
			}
			spawn_unit = {
				province = 1514 # Ejin
				troops = {
					light_infantry = { 2700 2700 }
					heavy_infantry = { 1600 1600 }
					horse_archers = { 541 541 }
					light_cavalry = { 300 300 }
					knights = { 100 100 }
				}
			}
			create_character = {
				random_traits = yes
				dynasty = random
				religion = hakko-ichiu
				culture = ROOT
				female = no
				age = 39
				attributes = {
					martial = 12
				}
				trait = brilliant_strategist
			}
			spawn_unit = {
				province = 1514 # Ejin
				troops = {
					light_infantry = { 2700 2700 }
					heavy_infantry = { 1600 1600 }
					horse_archers = { 541 541 }
					light_cavalry = { 300 300 }
					knights = { 100 100 }
				}
			}
			create_character = {
				random_traits = yes
				dynasty = random
				religion = hakko-ichiu
				culture = mongol
				female = no
				age = 30
				attributes = {
					martial = 12
				}
				trait = brilliant_strategist
			}
			spawn_unit = {
				province = 1514 # Ejin
				troops = {
					light_infantry = { 2700 2700 }
					heavy_infantry = { 1600 1600 }
					horse_archers = { 541 541 }
					light_cavalry = { 300 300 }
					knights = { 100 100 }
				}
			}
			spawn_unit = {
				province = 1514 # Ejin
				troops = {
					light_infantry = { 2700 2700 }
					heavy_infantry = { 1600 1600 }
					horse_archers = { 541 541 }
					light_cavalry = { 300 300 }
					knights = { 100 100 }
				}
			}
			spawn_unit = {
				province = 1514 # Ejin
				troops = {
					light_infantry = { 2700 2700 }
					heavy_infantry = { 1600 1600 }
					horse_archers = { 541 541 }
					light_cavalry = { 300 300 }
					knights = { 100 100 }
				}
			}
			spawn_unit = {
				province = 1514 # Ejin
				troops = {
					light_infantry = { 2700 2700 }
					heavy_infantry = { 1600 1600 }
					horse_archers = { 541 541 }
					light_cavalry = { 300 300 }
					knights = { 100 100 }
				}
			}
			spawn_unit = {
				province = 1514 # Ejin
				troops = {
					light_infantry = { 2700 2700 }
					heavy_infantry = { 1600 1600 }
					horse_archers = { 541 541 }
					light_cavalry = { 300 300 }
					knights = { 100 100 }
				}
			}
			create_character = {
				random_traits = yes
				dynasty = random
				religion = hakko-ichiu
				culture = mongol
				female = no
				age = 39
				attributes = {
					martial = 12
				}
				trait = brilliant_strategist
			}
			spawn_unit = {
				province = 1514 # Ejin
				troops = {
					light_infantry = { 2700 2700 }
					heavy_infantry = { 1600 1600 }
					horse_archers = { 541 541 }
					light_cavalry = { 300 300 }
					knights = { 100 100 }
				}
			}
			spawn_unit = {
				province = 1514 # Ejin
				troops = {
					light_infantry = { 2700 2700 }
					heavy_infantry = { 1600 1600 }
					horse_archers = { 541 541 }
					light_cavalry = { 300 300 }
					knights = { 100 100 }
				}
			}
			spawn_unit = {
				province = 1514 # Ejin
				troops = {
					light_infantry = { 2700 2700 }
					heavy_infantry = { 1600 1600 }
					horse_archers = { 541 541 }
					light_cavalry = { 300 300 }
					knights = { 100 100 }
				}
			}
			create_character = {
				random_traits = yes
				dynasty = random
				religion = hakko-ichiu
				culture = mongol
				female = no
				age = 39
				attributes = {
					martial = 12
				}
				trait = brilliant_strategist
			}
			spawn_unit = {
				province = 1514 # Ejin
				troops = {
					light_infantry = { 2700 2700 }
					heavy_infantry = { 1600 1600 }
					horse_archers = { 541 541 }
					light_cavalry = { 300 300 }
					knights = { 100 100 }
				}
			}
			
			create_character = {
				random_traits = yes
				dynasty = random
				religion = hakko-ichiu
				culture = ROOT
				female = no
				age = 30
				attributes = {
					martial = 12
				}
				trait = brilliant_strategist
			}
			spawn_unit = {
				province = 1514 # Ejin
				troops = {
					light_infantry = { 2700 2700 }
					heavy_infantry = { 1600 1600 }
					horse_archers = { 541 541 }
					light_cavalry = { 300 300 }
					knights = { 100 100 }
				}
			}
			create_character = {
				random_traits = yes
				dynasty = random
				religion = hakko-ichiu
				culture = jurchen
				female = no
				age = 35
				attributes = {
					martial = 12
				}
				trait = brilliant_strategist
			}
			spawn_unit = {
				province = 1514 # Ejin
				troops = {
					light_infantry = { 2700 2700 }
					heavy_infantry = { 1600 1600 }
					horse_archers = { 541 541 }
					light_cavalry = { 300 300 }
					knights = { 100 100 }
				}
			}
			create_character = {
				random_traits = yes
				dynasty = random
				religion = hakko-ichiu
				culture = ROOT
				female = no
				age = 39
				attributes = {
					martial = 12
				}
				trait = brilliant_strategist
			}
			spawn_unit = {
				province = 1514 # Ejin
				troops = {
					light_infantry = { 2700 2700 }
					heavy_infantry = { 1600 1600 }
					horse_archers = { 541 541 }
					light_cavalry = { 300 300 }
					knights = { 100 100 }
				}
			}
			create_character = {
					random_traits = yes
					dynasty = random
					religion = hakko-ichiu
					culture = jurchen
					female = no
					age = 30
					attributes = {
						martial = 12
					}
					trait = brilliant_strategist
				}
			spawn_unit = {
					province = 1514 # Ejin
					troops = {
						light_infantry = { 2700 2700 }
						heavy_infantry = { 1600 1600 }
						horse_archers = { 541 541 }
						light_cavalry = { 300 300 }
						knights = { 100 100 }
					}
				}
			create_character = {
					random_traits = yes
					dynasty = random
					religion = hakko-ichiu
					culture = jurchen
					female = no
					age = 35
					attributes = {
						martial = 12
					}
					trait = brilliant_strategist
				}
			spawn_unit = {
					province = 1514 # Ejin
					troops = {
						light_infantry = { 2700 2700 }
						heavy_infantry = { 1600 1600 }
						horse_archers = { 541 541 }
						light_cavalry = { 300 300 }
						knights = { 100 100 }
					}
				}
			create_character = {
					random_traits = yes
					dynasty = random
					religion = hakko-ichiu
					culture = ROOT
					female = no
					age = 39
					attributes = {
						martial = 12
					}
					trait = brilliant_strategist
				}
			spawn_unit = {
					province = 1514 # Ejin
					troops = {
						light_infantry = { 2700 2700 }
						heavy_infantry = { 1600 1600 }
						horse_archers = { 541 541 }
						light_cavalry = { 300 300 }
						knights = { 100 100 }
					}
				}
			spawn_unit = {
					province = 1514 # Ejin
					troops = {
						light_infantry = { 2700 2700 }
						heavy_infantry = { 1600 1600 }
						horse_archers = { 541 541 }
						light_cavalry = { 300 300 }
						knights = { 100 100 }
					}
				}
			spawn_unit = {
					province = 1514 # Ejin
					troops = {
						light_infantry = { 2700 2700 }
						heavy_infantry = { 1600 1600 }
						horse_archers = { 541 541 }
						light_cavalry = { 300 300 }
						knights = { 100 100 }
					}
				}
			spawn_unit = {
					province = 1514 # Ejin
					troops = {
						light_infantry = { 2700 2700 }
						heavy_infantry = { 1600 1600 }
						horse_archers = { 541 541 }
						light_cavalry = { 300 300 }
						knights = { 100 100 }
					}
			}
			
		# Some extra courtiers
		create_character = {
				random_traits = yes
				dynasty = random
				religion = hakko-ichiu
				culture = ROOT
				female = no
				age = 25
		}
		create_character = {
				random_traits = yes
				dynasty = random
				religion = hakko-ichiu
				culture = ROOT
				female = no
				age = 26
		}
		create_character = {
				random_traits = yes
				dynasty = random
				religion = hakko-ichiu
				culture = ROOT
				female = no
				age = 28
		}
	}
	option = {
		name = "EVTOPTB270920" # Good
		trigger = {
			NOT = { has_landed_title = k_guandong }
			religion = hakko-ichiu
		}
	}
	option = {
		name = "EVTOPTC270920" # BAD
		trigger = {
			NOT = { has_landed_title = k_guandong }
			NOT = { religion = hakko-ichiu }
		}
	}
}

character_event = { # To be sure the Rising Sun Operation happens even if first commander dies
    id = 270921
    
	hide_window = yes 
	
	trigger = {
		has_landed_title = k_guandong
		NOT = { has_character_flag = rising_sun_invasion_operation }
		NOT = { has_global_flag = guandong_army_arrival }
		war = no
	}
	
	immediate = {
		set_character_flag = rising_sun_invasion_operation
	}
}

character_event = { # Kwantung option for multiplayer
    id = 270922
	title = EVTNAME_270922
	desc = EVTDESC_270922
    is_triggered_only = yes
	
	option = {
		name = "EVTOPTA270922"
		set_character_flag = refused_kwantung_proposal
		
		hidden_tooltip = {
			random_player = {
				limit = {
					NOT = { has_character_flag = refused_kwantung_proposal }
				}
				character_event = { id = 270922 }
			}
		}
	}
	option = {
		name = "EVTOPTB270919"
		trigger = {
			character = ROOT
		}
		tooltip_info = yes

    	custom_tooltip = {
    		text = player_character_dynamic_rising_sun_commander_TT
    		if = {
    			limit = {
    				event_target:rising_sun_commander = {
    					is_alive = yes
    					ai = yes
    				}
    			}
    			set_player_character = event_target:rising_sun_commander
    		}
    	}
	}
}

#News Event: Kwantung Army declares invasion of China
narrative_event = {
	id = 270923
	title = NEWS_FROM_CHINA
	picture = GFX_evt_china_civil_war
	portrait = offmap_china
	window = EventWindowOffmap
	background = GFX_event_window_news_from_china
	is_triggered_only = yes

	desc = {
		text = EVTDESC_270923_A
		trigger = { event_target:invasion_of_china_attacker = { character = ROOT } }
	}
	desc = {
		text = EVTDESC_270923_B
		trigger = { NOT = { event_target:invasion_of_china_attacker = { character = ROOT } } }
	}

	has_dlc = "Jade Dragon"

	option = {
		name = {
			text = EVT_OPTA_270923
			trigger = { event_target:invasion_of_china_attacker = { character = ROOT } }
		}
		name = {
			text = EVT_OPTB_270923
			trigger = { NOT = { event_target:invasion_of_china_attacker = { character = ROOT } } }
		}
		show_portrait = event_target:invasion_of_china_attacker
	}
}

#News Event: Kwantung Army wins invasion of China
narrative_event = {
	id = 270924
	title = NEWS_FROM_CHINA
	desc = EVTDESC_270924
	picture = GFX_evt_china_civil_war
	portrait = offmap_china
	window = EventWindowOffmap
	background = GFX_event_window_news_from_china
	is_triggered_only = yes

	has_dlc = "Jade Dragon"

	immediate = { 
		offmap_china = {
			set_offmap_flag = no_policy_news
			set_policy = china_open
			log = "-------------------------------------"
			log = "China Policy Logging:"
			log = "Chinas new Policy is now OPEN"
			log = "-------------------------------------"
			clr_offmap_flag = no_policy_news
		}
	}

	option = {
		name = EVT_OPT_270924
	}
}

#News Event: Kwantung Army loses invasion of China
narrative_event = {
	id = 270925
    title = NEWS_FROM_CHINA
	desc = EVTDESC_270925
	picture = GFX_evt_china_civil_war
	portrait = offmap_china
	window = EventWindowOffmap
	background = GFX_event_window_news_from_china
	is_triggered_only = yes

	has_dlc = "Jade Dragon"

	option = {
		name = EVT_OPT_270925
		show_portrait = event_target:invasion_of_china_attacker
	}
}

#News Event: Rising Sun Empire has to stop the invasion of China
narrative_event = {
	id = 270926
    title = NEWS_FROM_CHINA
    desc = EVTDESC_270926
	picture = GFX_evt_china_civil_war
	portrait = offmap_china
	window = EventWindowOffmap
	background = GFX_event_window_news_from_china
	is_triggered_only = yes

	has_dlc = "Jade Dragon"
	
	option = {
		name = EVT_OPTA_270926
		trigger = {
			NOT = { FROM = { character = ROOT } }
		}
		show_portrait = event_target:invasion_of_china_attacker
	}
	option = {
		name = EVT_OPTB_270926
		trigger = {
			FROM = { character = ROOT }
		}
		show_portrait = event_target:invasion_of_china_attacker
	}
}

## Reinforcements for the Guandong Army
narrative_event = {
	id = 270927
	title = "EVTNAME270927"
	desc = "EVTDESC270927"
	
	picture = "GFX_evt_japan_reinforcements"
	border = "GFX_event_narrative_frame_war"
	
	only_playable = yes
	
	trigger = {
		has_landed_title = k_guandong
		NOT = { has_character_flag = reinforcements_from_home }
		any_war = { using_cb = invasion_of_china_hakko_ichiu_cb }
	}
	
	mean_time_to_happen = {
		months = 2
	}
	
	option = {
		name = "OK"
		set_character_flag = reinforcements_from_home
		create_character = {
			random_traits = yes
			dynasty = random
			religion = hakko-ichiu
			culture = ROOT
			female = no
			age = 52
			attributes = {
				martial = 12
			}
			trait = brilliant_strategist
		}
		create_character = {
			random_traits = yes
			dynasty = random
			religion = hakko-ichiu
			culture = ROOT
			female = no
			age = 54
			attributes = {
				martial = 12
			}
			trait = brilliant_strategist
		}
		spawn_unit = {
			owner = FROM
			province = capital_scope
			troops = {
				light_infantry = { 2700 2700 }
				heavy_infantry = { 1600 1600 }
				horse_archers = { 541 541 }
				light_cavalry = { 300 300 }
				knights = { 100 100 }
			}
		}
		spawn_unit = {
			owner = FROM
			province = capital_scope
			troops = {
				light_infantry = { 2700 2700 }
				heavy_infantry = { 1600 1600 }
				horse_archers = { 541 541 }
				light_cavalry = { 300 300 }
				knights = { 100 100 }
			}
		}
		spawn_unit = {
			owner = FROM
			province = capital_scope
			troops = {
				light_infantry = { 2700 2700 }
				heavy_infantry = { 1600 1600 }
				horse_archers = { 541 541 }
				light_cavalry = { 300 300 }
				knights = { 100 100 }
			}
		}
		spawn_unit = {
			owner = FROM
			province = capital_scope
			troops = {
				light_infantry = { 2700 2700 }
				heavy_infantry = { 1600 1600 }
				horse_archers = { 541 541 }
				light_cavalry = { 300 300 }
				knights = { 100 100 }
			}
		}
		spawn_unit = {
			owner = FROM
			province = capital_scope
			troops = {
				light_infantry = { 2700 2700 }
				heavy_infantry = { 1600 1600 }
				horse_archers = { 541 541 }
				light_cavalry = { 300 300 }
				knights = { 100 100 }
			}
		}
	}
}

## Guandong Army lost contact with the Empire
character_event = { # Timer to regain territory
    id = 270928
	title = EVTNAME_270928
	desc = EVTDESC_270928
	
	trigger = {
		has_landed_title = k_guandong
		NOT = {
			any_realm_province = {
				region = custom_eastern_edge_of_map
			}
		}
		NOT = { has_character_flag = try_to_reconnect_rising_sun }
		has_global_flag = guandong_army_arrival
	}
	
	mean_time_to_happen = {
		days = 1
	}
	
	option = {
		name = "EVTOPTA270928"
		set_character_flag = try_to_reconnect_rising_sun
		
		hidden_tooltip = {
			add_character_modifier = {
				name = lost_contact_rising_sun
				duration = 1825
				hidden = yes
			}
		}
	}
}

character_event = { # Kwantung Army become Partisans of the Imperial Way
    id = 270929
	title = EVTNAME_270929
	desc = EVTDESC_270929
	
	trigger = {
		has_landed_title = k_guandong
		NOT = {
			any_realm_province = {
				region = custom_eastern_edge_of_map
			}
		}
		has_character_flag = try_to_reconnect_rising_sun
		NOT = { has_character_modifier = lost_contact_rising_sun }
		has_global_flag = guandong_army_arrival
	}
	
	immediate = { 
		clr_character_flag = try_to_reconnect_rising_sun
		activate_title = { title = k_imperial_way status = yes }
		k_imperial_way = {
			grant_title = FROM
		}
	}
	
	option = {
		name = "EVTOPTA270929"
		
		unsafe_destroy_landed_title = k_guandong
		activate_title = { title = k_guandong status = no }
		hidden_effect = { 
			any_player = {
				limit = {
					OR = {
						AND = {
							has_offmap_news_enabled = offmap_china
							is_within_diplo_range = FROM
						}
						liege = { character = ROOT }
					}
				}
				narrative_event = { id = 270925 }
			}
		}
	}
}

character_event = { # If you manage to reconnect with the Empire
    id = 270930
    
	hide_window = yes 
	
	trigger = {
		has_landed_title = k_guandong
		OR = {
			is_landed = no
			any_realm_province = {
				region = custom_eastern_edge_of_map
			}
		}
		has_character_flag = try_to_reconnect_rising_sun
		has_global_flag = guandong_army_arrival
	}
	
	immediate = {
		clr_character_flag = try_to_reconnect_rising_sun
		clr_character_modifier = lost_contact_rising_sun
	}
}

character_event = { # You're informed that the Kwantung Army has reinforcements 
    id = 270931
	title = EVTNAME_270931
	desc = EVTDESC_270931
	
	is_triggered_only = yes
	
	option = {
		name = OK
	}
}