﻿je_donghak_movement = {
	should_be_pinned_by_default = yes
	icon = "gfx/interface/icons/event_icons/event_protest.dds"

	group = je_group_historical_content

	modifiers_while_active = {
		modifier_donghak_movement
	}

	is_shown_when_inactive = {
		country_has_primary_culture = cu:korean
		has_technology_researched = egalitarianism
		has_dlc_feature = ep1_content
	}

	possible = {
		has_technology_researched = human_rights
		NOT = {
			has_law = law_type:law_isolationism
		}
		any_power_bloc = {
			power_bloc_leader = {
				country_is_in_europe = yes
			}
			leverage_advantage = { target = ROOT value > 0 }
		}
		radical_fraction = {
			value >= 0.1
		}
	}

	immediate = {
		ig:ig_rural_folk = {
			save_scope_as = donghak_ig
		}
		trigger_event = { id = gg_korea.1 popup = yes }
	}

	on_monthly_pulse = {
		random_events = {
			100 = 0
			10 = gg_korea.4
		}
	}

	complete = {
		OR = {
			radical_fraction = {
				value <= 0.05
			}
			custom_tooltip = {
				text = donghak_petition_complete_tt
				has_variable = donghak_petition_complete
			}
		}
	}

	on_complete = {
		show_as_tooltip = {
			remove_modifier = modifier_donghak_movement
		}
	}

	fail = {
		any_political_movement = {
			is_insurrectionary = yes
			any_influenced_interest_group = {
				is_interest_group_type = ig_rural_folk
			}
		}
	}

	on_fail = {
		trigger_event = { id = gg_korea.2 popup = yes }
	}

	weight = 1000
}

je_gyojo_shinwon = {
	should_be_pinned_by_default = yes
	icon = "gfx/interface/icons/event_icons/event_scales.dds"

	group = je_group_crises

	# Added by event

	timeout = 3650

	modifiers_while_active = {
		modifier_donghak_petition_accepted
	}

	immediate = {
		ig:ig_rural_folk = {
			save_scope_as = donghak_ig
		}
		ig:ig_landowners = {
			save_scope_as = yangban_ig
		}
		random_law = {
			limit = {
				type = law_type:law_isolationism
			}
			save_scope_as = donghak_desired_law_1
		}
		random_law = {
			limit = {
				type = law_type:law_freedom_of_conscience
			}
			save_scope_as = donghak_desired_law_2
		}
		random_law = {
			limit = {
				type = law_type:law_total_separation
			}
			save_scope_as = donghak_desired_law_3
		}
	}

	complete = {
		has_law = law_type:law_isolationism
		NOT = {
			has_law = law_type:law_state_religion
		}
		ig:ig_landowners = {
			is_powerful = no
			is_in_government = no
		}
	}

	on_complete = {
		trigger_event = { id = gg_korea.5 popup = yes }
        hidden_effect = {
            set_variable = hermit_kingdom_achievement
        }
	}

	fail = {
		any_political_movement = {
			is_insurrectionary = yes
			any_influenced_interest_group = {
				is_interest_group_type = ig_rural_folk
			}
		}
	}

	on_timeout = {
		trigger_event = { id = gg_korea.6 popup = yes }
	}

	weight = 1000
}

je_korean_rebellion = {
	should_be_pinned_by_default = yes
	icon = "gfx/interface/icons/event_icons/event_fire.dds"

	group = je_group_crises

	# Added by event

	immediate = {
		c:KOR = {
			save_scope_as = korea_scope
			ruler = {
				save_scope_as = korea_ruler_scope
			}
		}
		random_country = {
			limit = {
				civil_war_origin_country = scope:korea_scope
			}
			save_scope_as = korea_rebellion_scope
		}
	}

	complete = {
		trigger_if = {
			limit = {
				has_variable = sided_with_korean_gov
			}
			scope:korea_scope = {
				has_revolution = no
				custom_tooltip = {
					text = korean_ruler_retained_tt
					scope:korea_ruler_scope = {
						is_ruler = yes
					}
				}
			}
		}
		trigger_if = {
			limit = {
				has_variable = sided_with_korean_rebels
			}
			scope:korea_scope = {
				has_revolution = no
				custom_tooltip = {
					text = korean_ruler_deposed_tt
					NOT = {
						scope:korea_ruler_scope ?= {
							is_ruler = yes
						}
					}
				}
			}
		}
	}

	on_complete = {
		if = {
			limit = {
				c:JAP ?= this
				c:KOR ?= {
					is_subject = yes
					overlord ?= {
						OR = {
							country_has_primary_culture = cu:han
							country_has_primary_culture = cu:manchu
						}
					}
				}
			}
			custom_tooltip = {
				text = japan_demands_korea_tt
				trigger_event = { id = gg_korea.8 days = 7 popup = yes}
			}
		}
		add_modifier = {
			name = modifier_victory_in_korean_intervention
			months = long_modifier_time
		}
	}

	fail = {
		trigger_if = {
			limit = {
				has_variable = sided_with_korean_gov
				scope:korea_scope = {
					has_revolution = yes
				}
			}
			scope:korea_rebellion_scope = {
				custom_tooltip = {
					text = korea_fail_condition_war_tt
					has_war_with = scope:korea_scope
				}
				custom_tooltip = {
					text = korea_fail_condition_gov_tt
					NOT = {
						is_diplomatic_play_enemy_of = ROOT
					}
				}
			}
		}
		trigger_if = {
			limit = {
				has_variable = sided_with_korean_rebels
				scope:korea_scope = {
					has_revolution = yes
				}
			}
			scope:korea_scope = {
				custom_tooltip = {
					text = korea_fail_condition_war_tt
					has_war_with = scope:korea_rebellion_scope
				}
				custom_tooltip = {
					text = korea_fail_condition_rebels_tt
					NOT = {
						is_diplomatic_play_enemy_of = ROOT
					}
				}
			}
		}
		trigger_if = {
			limit = {
				has_variable = sided_with_korean_gov
				scope:korea_scope = {
					has_revolution = no
				}
			}
			scope:korea_scope = {
				has_revolution = no
				custom_tooltip = {
					text = korean_ruler_deposed_tt
					NOT = {
						scope:korea_ruler_scope ?= {
							is_ruler = yes
						}
					}
				}
			}
		}
		trigger_if = {
			limit = {
				has_variable = sided_with_korean_rebels
				scope:korea_scope = {
					has_revolution = no
				}
			}
			scope:korea_scope = {
				has_revolution = no
				custom_tooltip = {
					text = korean_ruler_retained_tt
					scope:korea_ruler_scope ?= {
						is_ruler = yes
					}
				}
			}
		}
	}

	on_fail = {
		add_modifier = {
			name = modifier_failed_korean_intervention
			months = normal_modifier_time
		}
	}

	weight = 1000
}
