namespace = FEE_Pangasinan_Events

#Lim Hong's Invasion
country_event = {
	id = FEE_Pangasinan_Events.1
	title = FEE_Pangasinan_Events.1.T
	desc = FEE_Pangasinan_Events.1.D
	picture = BARBARY_PIRATES_eventPicture

	fire_only_once = yes

	trigger = {
		has_dlc = "Golden Century"
		owns_core_province = 2698
		is_year = 1560
		NOT = { is_year = 1580 }
	}

	mean_time_to_happen = {
		months = 90
	}

	option = {
		name = FEE_Pangasinan_Events.1.OPT1 #Sure why not.
		trigger = {
			tag = PGS
			is_free_or_tributary_trigger = yes
			NOT = { has_reform = pirate_republic_reform }
		}
		ai_chance = { factor = 20 }

		add_stability = -1
		if = {
			limit = {
				has_dlc = "Dharma"
			}
			change_government = republic
			add_government_reform = pirate_republic_reform
		}
		else = {
			set_legacy_government = pirate_republic
		}
		define_ruler = {
			name = "Lim"
			dynasty = "Hong"
			culture = hakka
			religion = confucianism
			male = yes
			adm = 2
			dip = 5
			mil = 3
		}
	}

	option = {
		name = FEE_Pangasinan_Events.1.OPT2 #Crush him.
		trigger = {
			OR = {
				exists = PGS
				capital = 2698
			}
		}
		ai_chance = { factor = 95 }

		2698 = {
			spawn_rebels = {
				type = pretender_rebels
				size = 2
				leader = "Lim Hong"
			}
		}
	}

	option = {
		name = FEE_Pangasinan_Events.1.OPT3 #Refuse him the offer.
		trigger = {
			NOT = { exists = PGS }
			NOT = { capital = 2698 }
		}

		ai_chance = { factor = 90 }

		2698 = {
			cede_province = PGS
		}
		PGS = {
			if = {
				limit = {
					has_dlc = "Dharma"
					is_subject = no
				}
				change_government = republic
				add_government_reform = pirate_republic_reform
			}
			else = {
				set_legacy_government = pirate_republic
			}
			define_ruler = {
				name = "Lim Hong"
				culture = hakka
				religion = confucianism
				male = yes
				adm = 2
				dip = 5
				mil = 3
			}
			declare_war_with_cb = {
				who = ROOT
				casus_belli = cb_independence_war
			}
		}
		hidden_effect = {
			2698 = {
				build_to_forcelimit = {
					infantry = 0.9
					cavalry = 0.1
				}
				heavy_ship = PGS
				light_ship = PGS
				light_ship = PGS
				light_ship = PGS
				light_ship = PGS
				light_ship = PGS
				light_ship = PGS
				light_ship = PGS
				light_ship = PGS
				transport = PGS
				transport = PGS
				transport = PGS
			}
		}
	}

	option = {
		name = FEE_Pangasinan_Events.1.OPT4 #Give the land to him.
		trigger = {
			NOT = { exists = PGS }
			NOT = { capital = 2698 }
		}

		ai_chance = { factor = 5 }
		2698 = {
			cede_province = PGS
		}
		PGS = {
			if = {
				limit = {
					has_dlc = "Dharma"
					is_subject = no
				}
				change_government = republic
				add_government_reform = pirate_republic_reform
			}
			else = {
				set_legacy_government = pirate_republic
			}
			define_ruler = {
				name = "Lim Hong"
				culture = hakka
				religion = confucianism
				male = yes
			}
		}
		southern_luzon_area = {
			limit = {
				NOT = { is_core = PGS }
				NOT = { is_claim = PGS }
			}
			add_claim = PGS
		}
		visayas_area = {
			limit = {
				NOT = { is_core = PGS }
				NOT = { is_claim = PGS }
			}
			add_claim = PGS
		}
		hidden_effect = {
			2698 = {
				build_to_forcelimit = {
					infantry = 0.9
					cavalry = 0.1
				}
				heavy_ship = PGS
				light_ship = PGS
				light_ship = PGS
				light_ship = PGS
				light_ship = PGS
				light_ship = PGS
				light_ship = PGS
				light_ship = PGS
				light_ship = PGS
				transport = PGS
				transport = PGS
				transport = PGS
			}
		}
	}

	option = {
		name = FEE_Pangasinan_Events.1.OPT5 #Offer him a position in our court.
		trigger = {
			has_reform = pirate_republic_reform
		}

		define_advisor = {
			type = spymaster
			name = "Lim Hong"
			skill = 1
			culture = hakka
			religion = confucianism
		}
	}
}