###################################
#
# Events for Arquebuses
#
# Id 9750-9899 is reserved
#
###################################
#
# Written by Niklas Strid


### First Encounter ###

# Shipwreck
province_event = {
	id = 9750
	desc = "EVTDESC9750"
	
	trigger = {
		year = 1520
		western_active = no
		NOT = { has_global_flag = portuguese_traders_arrived }
		port = yes
		NOT = { has_global_flag = event_9750 }
	}
	
	mean_time_to_happen = {
		months = 10000
		
		modifier = {
			factor = 0.8
			year = 1530
		}
		modifier = {
			factor = 0.8
			year = 1540
		}
		modifier = {
			factor = 0.8
			year = 1543
		}
		modifier = {
			factor = 0.5
			year = 1550
		}
		modifier = {
			factor = 0.5
			has_global_flag = western_influence_refused
		}
	}

	immediate = { set_global_flag = event_9750 }
	
	option = {
		name = "EVTOPTA9750"
		ai_chance = {
			factor = 75
		}
		clr_global_flag = western_influence_refused
		set_global_flag = portuguese_traders_arrived
		owner = {
			character_event = {
				id = 9751
				days = 10
				tooltip = "EVTTOOLTIPA9750"
			}
		}
		clr_global_flag = event_9750
	}
	option = {
		name = "EVTOPTB9750"
		ai_chance = {
			factor = 25
			modifier = {
				factor = 10
				owner = { trait = content }
			}
		}
		set_global_flag = western_influence_refused
		owner = { honor = 3 }
		clr_global_flag = event_9750
	}
}

# Portuguese visitors at court
character_event = {
	id = 9751
	desc = "EVTDESC9751"
	
	is_triggered_only = yes

	immediate = {
		hidden_tooltip = {
			random_list = {
				25 = {
					set_character_flag = option_a
				}
				50 = {
					set_character_flag = option_b
				}
				25 = {
					set_character_flag = option_c
				}
			}
		}
	}
	
	option = {
		name = "EVTOPTA9751"
		ai_chance = { factor = 75 }
		trigger = { has_character_flag = option_a }
		FROM = {
			add_province_modifier = {
				name = swordsmith_research_arquebus
				duration = 90
			}
			hidden_tooltip = {
				random_list = {
					75 = {
						province_event = {
							id = 9752
							days = 90
						}
					}
					25 = {
						province_event = {
							id = 9762
							days = 90
						}
					}
				}
			}
		}
		clr_character_flag = option_a
	}
	option = {
		name = "EVTOPTA9751"
		ai_chance = { factor = 75 }
		trigger = { has_character_flag = option_b }
		FROM = {
			add_province_modifier = {
				name = swordsmith_research_arquebus
				duration = 180
			}
			hidden_tooltip = {
				random_list = {
					75 = {
						province_event = {
							id = 9752
							days = 180
						}
					}
					25 = {
						province_event = {
							id = 9762
							days = 180
						}
					}
				}
			}
		}
		clr_character_flag = option_b
	}
	option = {
		name = "EVTOPTA9751"
		ai_chance = { factor = 75 }
		trigger = { has_character_flag = option_c }
		FROM = {
			add_province_modifier = {
				name = swordsmith_research_arquebus
				duration = 270
			}
			hidden_tooltip = {
				random_list = {
					75 = {
						province_event = {
							id = 9752
							days = 270
						}
					}
					25 = {
						province_event = {
							id = 9762
							days = 270
						}
					}
				}
			}
		}
		clr_character_flag = option_c
	}
	option = {
		name = "EVTOPTB9751"
		ai_chance = {
			factor = 25
			modifier = {
				factor = 10
				trait = content
			}
		}
		clr_global_flag = portuguese_traders_arrived
		set_global_flag = western_influence_refused
		clr_character_flag = option_a
		clr_character_flag = option_b
		clr_character_flag = option_c
		honor = 3
	}
}

# Swordsmith fails
province_event = {
	id = 9762
	desc = "EVTDESC9762"

	is_triggered_only = yes
	
	immediate = {
		hidden_tooltip = {
			random_list = {
				25 = {
					set_province_flag = option_a
				}
				50 = {
					set_province_flag = option_b
				}
				25 = {
					set_province_flag = option_c
				}
			}
		}
	}

	option = {
		name = "EVTOPTA9762"
		ai_chance = { factor = 75 }
		trigger = { has_province_flag = option_a }
		add_province_modifier = {
			name = swordsmith_research_arquebus
			duration = 90
		}
		hidden_tooltip = {
			ROOT = {
				random_list = {
					75 = {
						province_event = {
							id = 9752
							days = 90
						}
					}
					25 = {
						province_event = {
							id = 9762
							days = 90
						}
					}
				}
			}
		}
		clr_province_flag = option_a
	}
	option = {
		name = "EVTOPTA9762"
		ai_chance = { factor = 75 }
		trigger = { has_province_flag = option_b }
		add_province_modifier = {
			name = swordsmith_research_arquebus
			duration = 180
		}
		hidden_tooltip = {
			ROOT = {
				random_list = {
					75 = {
						province_event = {
							id = 9752
							days = 180
						}
					}
					25 = {
						province_event = {
							id = 9762
							days = 180
						}
					}
				}
			}
		}
		clr_province_flag = option_b
	}
	option = {
		name = "EVTOPTA9762"
		ai_chance = { factor = 75 }
		trigger = { has_province_flag = option_c }
		add_province_modifier = {
			name = swordsmith_research_arquebus
			duration = 270
		}
		hidden_tooltip = {
			ROOT = {
				random_list = {
					75 = {
						province_event = {
							id = 9752
							days = 270
						}
					}
					25 = {
						province_event = {
							id = 9762
							days = 270
						}
					}
				}
			}
		}
		clr_province_flag = option_c
	}
	option = {
		name = "EVTOPTB9762"
		ai_chance = { factor = 25 }
		clr_global_flag = portuguese_traders_arrived
		set_global_flag = western_influence_refused
		clr_province_flag = option_a
		clr_province_flag = option_b
		clr_province_flag = option_c
	}
}

# Swordsmith succeds
province_event = {
	id = 9752
	desc = "EVTDESC9752"
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA9752"
		western = yes
		hidden_tooltip = {
			any_character = {
				limit = {
					ai = no
					NOT = { character = ROOT }
				}
				character_event = {
					id = 9753
					days = 10
				}
			}
		}
	}
}

# The news spreads throughout Japan
character_event = {
	id = 9753
	desc = "EVTDESC9753"

	is_triggered_only = yes

	option = {
		name = "EVTOPTA9753"
	}
}


### Spread Events ###

# Portuguese ship arrive
province_event = {
	id = 9754
	desc = "EVTDESC9754"
	
	trigger = {
		western_active = yes
		western_complete = no
		western = no
		port = yes
		NOT = {
			owner = {
				any_demesne_province = {
					has_province_flag = portuguese_ship_arrive
				}
			}
		}
	}
	
	mean_time_to_happen = {
		months = 600
		
		modifier = {
			factor = 0.8
			year = 1530
		}
		modifier = {
			factor = 0.8
			year = 1540
		}
		modifier = {
			factor = 0.8
			year = 1543
		}
		modifier = {
			factor = 0.5
			year = 1550
		}
	}

	immediate = {
		hidden_tooltip = {
			set_province_flag = portuguese_ship_arrive
			random_list = {
				25 = {
					set_province_flag = option_a
				}
				50 = {
					set_province_flag = option_b
				}
				25 = {
					set_province_flag = option_c
				}
			}
		}
	}

	option = {
		name = "EVTOPTA9754"
		ai_chance = { factor = 75 }
		trigger = { has_province_flag = option_a }
		add_province_modifier = {
			name = swordsmith_research_arquebus
			duration = 60
		}
		hidden_tooltip = {
			owner = { 
				ROOT = {
					random_list = {
						75 = {
							province_event = {
								id = 9764
								days = 60
							}
						}
						25 = {
							province_event = {
								id = 9763
								days = 60
							}
						}
					}
				}
			}
		}
		clr_province_flag = option_a
	}
	option = {
		name = "EVTOPTA9754"
		ai_chance = { factor = 75 }
		trigger = { has_province_flag = option_b }
		add_province_modifier = {
			name = swordsmith_research_arquebus
			duration = 120
		}
		hidden_tooltip = {
			owner = {
				ROOT = {
					random_list = {
						75 = {
							province_event = {
								id = 9764
								days = 120
							}
						}
						25 = {
							province_event = {
								id = 9763
								days = 120
							}
						}
					}
				}
			}
		}
		clr_province_flag = option_b
	}
	option = {
		name = "EVTOPTA9754"
		ai_chance = { factor = 75 }
		trigger = { has_province_flag = option_c }
		add_province_modifier = {
			name = swordsmith_research_arquebus
			duration = 180
		}
		hidden_tooltip = {
			owner = {
				ROOT = {
					random_list = {
						75 = {
							province_event = {
								id = 9764
								days = 180
							}
						}
						25 = {
							province_event = {
								id = 9763
								days = 180
							}
						}
					}
				}
			}
		}
		clr_province_flag = option_c
	}
	option = {
		name = "EVTOPTB9754"
		ai_chance = { factor = 25 }
		clr_province_flag = option_a
		clr_province_flag = option_b
		clr_province_flag = option_c
		owner = { honor = 3 }
	}
}

# Swordsmith fails
province_event = {
	id = 9763
	desc = "EVTDESC9763"

	is_triggered_only = yes
	
	immediate = {
		hidden_tooltip = {
			random_list = {
				25 = {
					set_province_flag = option_a
				}
				50 = {
					set_province_flag = option_b
				}
				25 = {
					set_province_flag = option_c
				}
			}
		}
	}

	option = {
		name = "EVTOPTA9763"
		ai_chance = { factor = 75 }
		trigger = { has_province_flag = option_a }
		add_province_modifier = {
			name = swordsmith_research_arquebus
			duration = 60
		}
		hidden_tooltip = {
			owner = {
				ROOT = {
					random_list = {
						75 = {
							province_event = {
								id = 9764
								days = 60
							}
						}
						25 = {
							province_event = {
								id = 9763
								days = 60
							}
						}
					}
				}
			}
		}
		clr_province_flag = option_a
	}
	option = {
		name = "EVTOPTA9763"
		ai_chance = { factor = 75 }
		trigger = { has_province_flag = option_b }
		add_province_modifier = {
			name = swordsmith_research_arquebus
			duration = 120
		}
		hidden_tooltip = {
			owner = {
				ROOT = {
					random_list = {
						75 = {
							province_event = {
								id = 9764
								days = 120
							}
						}
						25 = {
							province_event = {
								id = 9763
								days = 120
							}
						}
					}
				}
			}
		}
		clr_province_flag = option_b
	}
	option = {
		name = "EVTOPTA9763"
		ai_chance = { factor = 75 }
		trigger = { has_province_flag = option_c }
		add_province_modifier = {
			name = swordsmith_research_arquebus
			duration = 180
		}
		hidden_tooltip = {
			owner = {
				ROOT = {
					random_list = {
						75 = {
							province_event = {
								id = 9764
								days = 180
							}
						}
						25 = {
							province_event = {
								id = 9763
								days = 180
							}
						}
					}
				}
			}
		}
		clr_province_flag = option_c
	}
	option = {
		name = "EVTOPTB9763"
		ai_chance = { factor = 25 }
		clr_province_flag = option_a
		clr_province_flag = option_b
		clr_province_flag = option_c
	}
}

# Swordsmith succeds
province_event = {
	id = 9764
	desc = "EVTDESC9764"
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA9764"
		western = yes
	}
}

# A visit to another province
province_event = {
	id = 9756
	desc = "EVTDESC9756"
	
	trigger = {
		western_active = yes
		western_complete = no
		western = no
		OR = {
			any_neighbor_province = {
				western = yes
				NOT = { owned_by = ROOT }
			}
			any_neighbor_province = {
				NOT = { owned_by = ROOT }
				any_neighbor_province = {
					western = yes
					NOT = { owned_by = ROOT }
				}
			}
			any_neighbor_province = {
				NOT = { owned_by = ROOT }
				any_neighbor_province = {
					NOT = { owned_by = ROOT }
					any_neighbor_province = {
						western = yes
						NOT = { owned_by = ROOT }
					}
				}
			}
		}
		owner = {
			any_courtier = {
				has_job_title = job_master_of_ceremonies
			}
		}
	}
	
	mean_time_to_happen = {
		months = 180
		
		modifier = {
			factor = 0.8
			any_neighbor_province = {
				NOT = { owned_by = ROOT }
				any_neighbor_province = {
					western = yes
					NOT = { owned_by = ROOT }
				}
			}
		}
		modifier = {
			factor = 0.5
			any_neighbor_province = {
				western = yes
				NOT = { owned_by = ROOT }
			}
		}
		modifier = {
			factor = 0.8
			year = 1530
		}
		modifier = {
			factor = 0.8
			year = 1540
		}
		modifier = {
			factor = 0.8
			year = 1543
		}
		modifier = {
			factor = 0.5
			year = 1550
		}
	}
	
	option = {
		name = "EVTOPTA9756"
		western = yes
	}
}

# Spreads within the demesne
province_event = {
	id = 9761
	desc = "EVTDESC9761"
	
	trigger = {
		western_active = yes
		western_complete = no
		western = no
		owner = {
			any_demesne_province = {
				western = yes
			}
		}
	}
	
	mean_time_to_happen = {
		months = 12
		
		modifier = {
			factor = 0.8
			year = 1530
		}
		modifier = {
			factor = 0.8
			year = 1540
		}
		modifier = {
			factor = 0.8
			year = 1543
		}
		modifier = {
			factor = 0.5
			year = 1550
		}
		modifier = {
			factor = 0.5
			any_neighbor_province = {
				owned_by = ROOT
				western = yes
			}
		}
	}
	
	option = {
		name = "EVTOPTA9761"
		western = yes
	}
}

# Vassal informs his liege
province_event = {
	id = 9757
	desc = "EVTDESC9757"
	
	trigger = {
		western_active = yes
		western_complete = no
		western = yes
		owner = {
			independent = no
		}
	}
	
	mean_time_to_happen = {
		months = 120
		
		modifier = {
			factor = 0.8
			year = 1530
		}
		modifier = {
			factor = 0.8
			year = 1540
		}
		modifier = {
			factor = 0.8
			year = 1543
		}
		modifier = {
			factor = 0.5
			year = 1550
		}
	}
	
	option = {
		name = "EVTOPTA9757"
		owner = {
		honor = 10
			liege = {
				capital_scope = {
					province_event = {
						id = 9758
						days = 10
					}
				}
			}
		}
	}
	option = {
		name = "EVTOPTB9757"
	}
}

# Liege informed by vassal
province_event = {
	id = 9758
	desc = "EVTDESC9758"
	
	is_triggered_only = yes	
	
	option = {
		name = "EVTOPTA9758"
		ai_chance = {
			factor = 50
		}
		western = yes
		owner = {
			honor = 5
			any_direct_vassal = {
				capital_scope = {
					province_event = {
						id = 9759
						days = 10
						tooltip = "EVTTOOLTIP9759"
					}			
				}
			}
		}
	}
	option = {
		name = "EVTOPTB9758"
		ai_chance = {
			factor = 50
		}
		western = yes
	}
}

# Vassal informed by liege
province_event = {
	id = 9759
	desc = "EVTDESC9759"
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA9759"
		ai_chance = {
			factor = 75
		}
		western = yes
	}
	option = {
		name = "EVTOPTB9759"
		ai_chance = {
			factor = 25
		}
	}
}

# Arquebuses become common knowledge
character_event = {
	id = 9760
	desc = "EVTDESC9760"
	
	trigger = {
		western_complete = yes
		NOT = { has_global_flag = western_complete }
	}
	
	mean_time_to_happen = {
		months = 1
	}
	
	immediate = { set_global_flag = western_complete }
	
	option = {
		name = "EVTOPTA9760"
		hidden_tooltip = {
			any_character = {
				limit = {
					ai = no
					NOT = { character = ROOT }
				}
				character_event = {
					id = 9765
				}
			}
		}
	}
}

# Arquebuses become common knowledge
character_event = {
	id = 9765
	desc = "EVTDESC9760"
	
	is_triggered_only = yes
	
	option = {
		name = "EVTOPTA9760"
	}
}

# Portuguese traders sell arquebuses
province_event = {
	id = 9766
	desc = "EVTDESC9766"
	
	trigger  = {
		has_building = christian_church
		owner = {
			christian_relation = 25
			NOT = { arquebus = 10000 }
			wealth = 20
		}
		has_siege = no
	}
	
	mean_time_to_happen = {
		months = 2500
		
		modifier = {
			factor = 0.9
			owner = { NOT = { arquebus = 1000 } }
		}
		modifier = {
			factor = 0.9
			owner = { NOT = { arquebus = 2000 } }
		}
	}
	
	option = {
		name = "EVTOPTA9766"
		ai_chance = {
			factor = 100
			modifier = {
				factor = 0.5
				owner = { wealth = 40 }
			}
		}
		owner = {
			wealth = 10
			arquebus = 250
		}
	}
	option = {
		name = "EVTOPTB9766"
		ai_chance = {
			factor = 100
		}
		trigger = { owner = { wealth = 40 } }
		owner = {
			wealth = 20
			arquebus = 500
		}
	}
	option = {
		name = "EVTOPTC9766"
		ai_chance = { factor = 0 }
	}
}
