﻿je_terakoya = {
	icon = "gfx/interface/icons/institution_icons/schools.dds"
	
	group = je_group_historical_content

	modifiers_while_active = {
		modifier_jap_terakoya
	}

	complete = {
		institution_investment_level = {
			institution = institution_schools
			value >= 3
		}
	}

	on_complete = {
		add_modifier = {
			name = modifier_legacy_of_terakoya
			months = long_modifier_time
			is_decaying = yes
		}
	}

	weight = 100
	should_be_pinned_by_default = yes
}

je_meiji_restoration = {
	icon = "gfx/interface/icons/event_icons/event_scales.dds"
	
	group = je_group_historical_content

	is_shown_when_inactive = {
		exists = c:JAP
		c:JAP = ROOT
		NOT = { has_variable = meiji_restoration_complete }
		has_law = law_type:law_monarchy
	}

	possible = {
		has_law = law_type:law_monarchy
		ig:ig_landowners = {
			is_in_government = no
		}
		OR = {
			government_legitimacy >= 50
			ig:ig_landowners = { is_marginal = yes }
			has_revolution = yes						
		}
	}

	immediate = {
		set_variable = {
			name = shogunate_var
			value = 0
		}
	}

	is_progressing = {
		meiji_completion_trigger = yes
	}

	on_monthly_pulse = {
		effect = {
			if = {
				limit = {
					meiji_completion_trigger = yes
				}
				change_variable = {
					name = shogunate_var
					add = 1
				}
			}
		}
	}

	complete = {
		# If-else clause to avoid errors because of missing variable before JE activates
		trigger_if = {
			limit = { exists = var:shogunate_var }
			OR = {
				custom_tooltip = {
					text = defeat_shogunate_civil_war_tt
					scope:journal_entry = { is_goal_complete = yes }
				}
				AND = {
					scope:journal_entry = { is_goal_complete = yes }
					meiji_completion_trigger = yes
				}	
			}
		}
		trigger_else = {
			custom_tooltip = je_meiji_restoration_goal
			OR = {
				custom_tooltip = defeat_shogunate_civil_war_tt
				meiji_completion_trigger = yes	
			}
		}
	}

	on_complete = {
		trigger_event = {
			id = meiji.1
		}
		set_variable = meiji_restoration_complete
		if = {
			limit = { has_modifier = shogun_ig_forced_to_open_market }
			remove_modifier = shogun_ig_forced_to_open_market
		}
		if = {
			limit = { has_modifier = hokkaido_colonization_modifier }
			remove_modifier = hokkaido_colonization_modifier
		}	
		s:STATE_SAKHALIN = {
			add_claim = root
		}
	}
	
	on_fail = {
		if = {
			limit = { has_modifier = shogun_ig_forced_to_open_market }
			remove_modifier = shogun_ig_forced_to_open_market
		}
		if = {
			limit = { has_law = law_type:law_monarchy }		
			add_modifier = {
				name = honorable_restoration_failed
				months = very_long_modifier_time
				is_decaying = yes
			}
		}
	}

	fail = {
		OR = {
			ig:ig_landowners = {
				is_in_government = yes
			}
			NOT = { has_law = law_type:law_monarchy }			
		}
	}

	current_value = {
		value = root.var:shogunate_var
	}

	goal_add_value = {
		value = 120
	}

	progressbar = yes

	weight = 10000
	should_be_pinned_by_default = yes
}


je_meiji_main = {
	icon = "gfx/interface/icons/event_icons/event_scales.dds"
	
	group = je_group_historical_content

	complete = {
		scope:journal_entry = {
			is_goal_complete = yes
		}
		custom_tooltip = {
			text = has_completed_meiji_army_je_tt
			has_variable = completed_je_meiji_army
		}
		custom_tooltip = {
			text = has_completed_meiji_economy_je_tt
			has_variable = completed_je_meiji_economy
		}
		custom_tooltip = {
			text = has_completed_meiji_diplomacy_je_tt
			has_variable = completed_je_meiji_diplomacy
		}
	}

	on_complete = {
		set_variable = meiji_reforms_complete_var
		trigger_event = {
			id = meiji.2
		}
	}

	on_monthly_pulse = {
		random_events = {
			100 = 0
			10 = meiji.4
			10 = meiji.5
			10 = meiji.6
		}
	}

	current_value = {
		value = var:meiji_var
	}

	goal_add_value = {
		add = 3
	}

	progressbar = yes

	weight = 10000
	should_be_pinned_by_default = yes
}

je_meiji_economy = {
	icon = "gfx/interface/icons/event_icons/event_industry.dds"
	
	group = je_group_historical_content

	complete = {
		in_default = no
		any_scope_state = {
			filter = {
				is_incorporated = yes
			}
			any_scope_building = {
				is_building_type = building_urban_center
				level >= 5
			}
			has_building = building_railway
			percent > 0.7
		}
	}

	on_complete = {
		change_variable = {
			name = meiji_var
			add = 1
		}
		set_variable = completed_je_meiji_economy
	}

	on_monthly_pulse = {
		random_events = {
			100 = 0
			10 = meiji.7
			10 = meiji.8
		}
	}

	transferable = no
	should_be_pinned_by_default = yes

	weight = 5000
}

je_meiji_army = {
	icon = "gfx/interface/icons/event_icons/event_military.dds"
	
	group = je_group_historical_content

	complete = {
		NOT = { has_law = law_type:law_serfdom }
		ig:ig_armed_forces = {
			is_in_government = no
		}
		has_technology_researched = napoleonic_warfare
		NOR = {
			any_scope_building = {
				is_building_type = building_barracks
				has_active_production_method = pm_no_organization
			}
			any_military_formation = {
				filter = {
					is_army = yes
				}
				any_combat_unit = {
					has_unit_type = unit_type:combat_unit_type_irregular_infantry
				}
				percent >= 0.25
			}
		}
	}

	on_complete = {
		change_variable = {
			name = meiji_var
			add = 1
		}
		trigger_event = {
			id = meiji.3
		}
		set_variable = completed_je_meiji_army
	}

	on_monthly_pulse = {
		random_events = {
			100 = 0
			10 = meiji.9
			10 = meiji.10
		}
	}

	transferable = no
	should_be_pinned_by_default = yes

	weight = 5000
}

je_meiji_diplomacy = {
	icon = "gfx/interface/icons/event_icons/event_trade.dds"
	
	group = je_group_historical_content

	complete = {
		NOT = { has_law = law_type:law_isolationism }
		NOT = { has_law = law_type:law_traditionalism }
		NOT = { has_law = law_type:law_closed_borders }
		is_subject = no
	}

	on_complete = {
		change_variable = {
			name = meiji_var
			add = 1
		}
		set_variable = completed_je_meiji_diplomacy
	}

	on_monthly_pulse = {
		random_events = {
			100 = 0
			10 = meiji.11
			10 = meiji.12
		}
	}

	should_be_pinned_by_default = yes
	weight = 5000
}
