estate_scholars_develop_x_agenda = {
	selection_weight = {
		factor = 1
	}
	can_select = {
		capital_scope = {
			is_state_core = root
		}
	}
	pre_effect = {
		random_list = {
			1 = {
				random_owned_province = {
					limit = {
						is_state_core = root
						area_for_scope_province = {
							is_capital_of = root
						}
					}
					save_event_target_as = agenda_province
				}
			}
			2 = {
				trigger = {
					any_owned_province = {
						is_state_core = root
						OR = {
							AND = {
								religion = root
								OR = {
									culture = root
									has_owner_accepted_culture = yes
								}
							}
						}
						region_for_scope_province = {
							is_capital_of = root
						}
					}
				}
				random_owned_province = {
					limit = {
						is_state_core = root
						OR = {
							AND = {
								religion = root
								OR = {
									culture = root
									has_owner_accepted_culture = yes
								}
							}
						}
						region_for_scope_province = {
							is_capital_of = root
						}
					}
					save_event_target_as = agenda_province
				}
			}
			1 = {
				random_owned_province = {
					limit = {
						is_state_core = root
					}
					save_event_target_as = agenda_province
				}
			}
		}
		event_target:agenda_province = {
			if = {
				limit = {
					check_variable = {
						which = province_dip_var
						value = 1
					}
				}
				set_variable = {
					which = province_dip_var
					value = 0
				}
			}
			export_to_variable = {
				which = province_dip_var
				value = trigger_value:base_production
			}
			change_variable = {
				which = province_dip_var
				value = 2
			}
		}
	}
	provinces_to_highlight = {
		province_id = event_target:agenda_province
	}
	fail_if = {
		event_target:agenda_province = {
			NOT = { owned_by = root }
		}
	}
	task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_scholars
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_scholars
			}
		}
		else = {
			event_target:agenda_province = {
				base_production = "province_dip_var"
			}
		}
    }
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_scholars
		}
		add_estate_loyalty = {
			estate = estate_scholars
			loyalty = 10
		}
		add_years_of_income = 0.3
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		event_target:agenda_province = {
			if = {
				limit = { owned_by = root }
				add_named_unrest = {
					name = local_scholars_displeased
					value = 5
				}
			}
		}
        add_estate_loyalty_modifier = {
            estate = estate_scholars
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_scholars_have_x_decree_agenda = {
	selection_weight = {
		factor = 1
	}
	can_select = {
		NOT = { meritocracy = 50 }  
		is_emperor_of_china = yes 
		has_dlc = "Mandate of Heaven"
	}
	task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_scholars
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_scholars
			}
		}
		else = {
			meritocracy = 90 
		}
	}
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_scholars
		}
		if = { 
			limit = { 
				national_focus = ADM
			} 
			add_country_modifier = {
				name = mng_tranquil_adm_modifier
				duration = 5475
			}
		}
		else_if = { 
			limit = { 
				national_focus = DIP
			} 
			add_country_modifier = {
				name = mng_tranquil_dip_modifier
				duration = 5475
			}
		}
		else = { 
			add_country_modifier = {
				name = mng_tranquil_mil_modifier
				duration = 5475
			}
		}
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		add_country_modifier = {
			name = mng_palatial_disorganization_modifier
			duration = 3650
		}
		add_estate_loyalty_modifier = {
            estate = estate_scholars
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_scholars_monthly_adm_agenda = {
	selection_weight = {
		factor = 1
	}
	can_select = {
		is_emperor_of_china = yes 
		OR = { 
			if = {
				limit = { has_dlc = "Cradle of Civilization" } 
				NOT = { monthly_adm = 10 }
			}
			else = { 
				NOT = { monthly_adm = 7 } 
			}
			
		}	
	}
	task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_scholars
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_scholars
			}
		}
		else = {
			if = { 
				limit = { has_dlc = "Cradle of Civilization" } 
				monthly_adm = 12
			}
			else = { monthly_adm = 8 }
		} 
	}
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_scholars
		}
		add_estate_loyalty = {
			estate = estate_scholars
			loyalty = 10
		}
		add_country_modifier = {
			name = mng_efficient_governance_modifier
			duration = 5475
		}
		add_corruption = -1
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		add_country_modifier = {
			name = mng_inefficient_governance_modifier
			duration = 3650
		}
        add_estate_loyalty_modifier = {
            estate = estate_scholars
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_scholars_recover_meritocracy_agenda = {
	selection_weight = { factor = 1 }
	can_select = {
		is_emperor_of_china = yes 
		has_dlc = "Mandate of Heaven" 
		NOT = { meritocracy = 25 } 
	}
	task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_scholars
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_scholars
			}
		}
		else = {
			meritocracy = 80 
		} 
	}
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_scholars
		}
		add_estate_loyalty = {
			estate = estate_scholars
			loyalty = 10
		}
		add_country_modifier = {
			name = mng_restored_meritocratic_procedures_modifier
			duration = 5475
		}
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		add_country_modifier = {
			name = mng_fall_of_meritocracy_modifier
			duration = 3650
		}
        add_estate_loyalty_modifier = {
            estate = estate_scholars
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_scholars_improve_imperial_mandate_agenda = {
	selection_weight = { factor = 1 }
	can_select = {
		is_emperor_of_china = yes 
		has_dlc = "Mandate of Heaven" 
		NOT = { imperial_mandate = 40 } 
	}
	task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_scholars
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_scholars
			}
		}
		else = {
			imperial_mandate = 90
		} 
	}
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_scholars
		}
		add_estate_loyalty = {
			estate = estate_scholars
			loyalty = 10
		}
		add_country_modifier = {
			name = mng_heavens_favor_modifier
			duration = 5475
		}
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
		add_country_modifier = {
			name = mng_imperial_fall_from_grace_modifier
			duration = 3650
		}
        add_estate_loyalty_modifier = {
            estate = estate_scholars
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
    }
}

estate_scholars_hire_advisor_agenda = {
	selection_weight = {
		factor = 1
	}
	can_select = {
		NOT = {
			employed_advisor = {
				category = ADM
			}
		}
	}
	task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_scholars
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_scholars
			}
		}
		else = {
			employed_advisor = {
				category = ADM
			}
			is_in_deficit = no
		}
	}
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_scholars
		}
		add_estate_loyalty = {
			estate = estate_scholars
			loyalty = 10
		}
		add_corruption = -0.5
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
        add_estate_loyalty_modifier = {
            estate = estate_scholars
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
		add_corruption = 0.5
    }
}

estate_scholars_fire_advisor_agenda = {
	selection_weight = {
		factor = 1
		modifier = {
			factor = 0.5
			always = yes
		}
	}
	can_select = {
		employed_advisor = {
			category = ADM
		}
	}
	immediate_effect = {
		hidden_effect = {
			set_country_flag = need_to_fire_dip_advisor
		}
	}
	on_invalid = {
		clr_country_flag = need_to_fire_dip_advisor
	}
	task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_scholars
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_scholars
			}
		}
		else = {
			custom_trigger_tooltip = {
				tooltip = fire_dip_advisor_tooltip
				has_country_flag = just_fired_dip_advisor
			}
		}
	}
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_scholars
		}
		add_estate_loyalty = {
			estate = estate_scholars
			loyalty = 10
		}
		clr_country_flag = just_fired_dip_advisor
		clr_country_flag = need_to_fire_dip_advisor
	}
	invalid_trigger = {
		NOT = {
			employed_advisor = {
				category = ADM
			}
		}
		NOT = { has_country_flag = just_fired_dip_advisor }
	}
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
        add_estate_loyalty_modifier = {
            estate = estate_scholars
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
		clr_country_flag = need_to_fire_dip_advisor
    }
}

estate_scholars_harmonization_agenda = {
	selection_weight = {
		factor = 1
	}
	can_select = {
		has_dlc = "Mandate of Heaven" 
		religion = confucianism
		NOT = { harmony = 50 }
		harmonization_progress = 60 
	}
	task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_scholars
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_scholars
			}
		}
		else = {
			harmony = 85
		}
	}
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_scholars
		}
		add_estate_loyalty = {
			estate = estate_scholars
			loyalty = 10
		}
		add_estate_loyalty = {
			estate = estate_church 
			loyalty = 10 
		}
		add_corruption = -0.5
		if = { 
			limit = { is_emperor_of_china = yes } 
			add_mandate = 5 
		}
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
        add_estate_loyalty_modifier = {
            estate = estate_scholars
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
		 add_estate_loyalty_modifier = {
            estate = estate_church
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
		add_corruption = 0.5
		if = { 
			limit = { is_emperor_of_china = yes } 
			add_mandate = -5 
		}
    }
}

estate_scholars_subject_gifts_agenda = {
	selection_weight = {
		factor = 1
	}
	can_select = {
		calc_true_if = {
			all_subject_country = {
				OR = { 
					is_subject_of_type = tributary_state 
					is_subject_of_type = march 
					is_subject_of_type = vassal 
				}
			}
			amount = 3
		}
	}
	task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_scholars
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_scholars
			}
		}
		else = {
			calc_true_if = {
				all_subject_country = {
					OR = { 
						is_subject_of_type = tributary_state
						is_subject_of_type = march 
						is_subject_of_type = vassal 
					}
					OR = {
						has_opinion_modifier = {
							who = ROOT 
							modifier = sent_gift
						}
						has_liberty_desire_modifier = bestowed_gifts  
					}
				}
				amount = 3
			}
		}
	}
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_scholars
		}
		custom_tooltip = mng_reduce_all_subjects_we_interacted_with_ld_tt
		hidden_effect = {
			every_subject_country = {
				limit = { 
					is_subject_of = ROOT 
					OR = {
						has_opinion_modifier = {
							who = ROOT 
							modifier = sent_gift
						}
						has_liberty_desire_modifier = bestowed_gifts  
					}
				}
				add_liberty_desire = -10
				add_trust = {
					who = ROOT 
					value = 10 
					mutual = yes 
				}
			}
		}
		add_estate_loyalty = {
			estate = estate_scholars 
			loyalty = 10 
		}
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
        add_estate_loyalty_modifier = {
            estate = estate_scholars
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
		custom_tooltip = mng_worsen_ld_subjects_tt
		hidden_effect = {
			every_subject_country = {
				limit = { is_subject_of = ROOT } 
				add_liberty_desire = 20
			}
		}
    }
}

estate_scholars_forbidden_city_agenda = {
	selection_weight = {
		factor = 1
	}
	can_select = {
		owns = 1816 
		if = { 
			limit = { 
				NOT = { has_dlc = "Leviathan" } 
			}
			OR = {
				tag = MCH
				tag = MNG
				tag = QNG
				has_reform = celestial_empire
			}
			normal_or_historical_nations = yes
			NOT = { has_country_modifier = the_forbidden_city } 
		}
		else = {
			1816 = { 
				has_great_project = {
					type = forbidden_city
					tier = 3 
				}
				NOT = { 
					has_great_project = {
						type = forbidden_city
						tier = 3 
					}
				}
			}
		}
	}
	task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_scholars
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_scholars
			}
		}
		else = {
			if = { 
				limit = { 
					has_dlc = "Leviathan" 
				}
				1816 = {
					has_great_project = {
						type = forbidden_city 
						tier = 3 
					}
				}
			}
			else_if = {
				limit = { NOT = { has_dlc = "Leviathan" } }
				custom_trigger_tooltip = {
					tooltip = has_built_forbidden_city_tt
					has_country_modifier = the_forbidden_city
				}
			}
		}
	}
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_scholars
		}
		add_estate_loyalty = {
			estate = estate_scholars
			loyalty = 10
		}
		add_power_projection = {
			type = mission_rewards_power_projection
			amount = 30
		}
		add_mandate = 15
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
        add_estate_loyalty_modifier = {
            estate = estate_scholars
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
		add_power_projection = {
			type = mission_rewards_power_projection
			amount = -30
		}
		add_mandate = -15
    }
}

estate_scholars_porcelain_tower_agenda = {
	selection_weight = {
		factor = 1
	}
	can_select = {
		owns = 1821
		if = {
			limit = { has_dlc = "Leviathan" }
			NOT = {
				1821 = { 
					has_great_project = {
						type = porcelain_tower_nanjing
						tier = 3 
					}
				}
			}
			1821 = { 
				has_great_project = {
					type = porcelain_tower_nanjing
					tier = 2
				}
				NOT = {
					has_great_project = {
						type = porcelain_tower_nanjing
						tier = 3
					}
				}
			}
		}
		else = { 
			1821 = { 
				OR = {
					NOT = { has_building = university } 
					NOT = { development = 40 }
				}
			}
		}
	}
	task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_scholars
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_scholars
			}
		}
		else_if = {
			limit = { 
				has_dlc = "Leviathan"
			}
			1821 = {
				has_great_project = {
					type = porcelain_tower_nanjing
					tier = 3 
				}
			}
		}
		else = { 
			1821 = { 
				OR = {
					NOT = { has_building = university } 
					NOT = { development = 40 }
				}
			}
		}
		is_at_war = no 
	}
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_scholars
		}
		add_estate_loyalty = {
			estate = estate_scholars
			loyalty = 10
		}
		if = { 
			limit = { 
				NOT = { has_country_flag = mng_glory_of_porcelain_tower_flag }
			}
			country_event = { id = flavor_mng.41 }
		}
		else_if = {
			limit = { in_golden_age = yes }
			extend_golden_age = 120
		}
		else = { 
			add_adm_power = 50
			add_dip_power = 50
			add_mil_power = 50
			change_ruler_stat = {
				type = adm
				amount = 1
			}
		}
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
        add_estate_loyalty_modifier = {
            estate = estate_scholars
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
		add_corruption = 2 
    }
}

estate_scholars_subsidize_subjects_agenda = {
	can_select = {
		calc_true_if = {
			all_subject_country = {
				OR = { 
					is_subject_of_type = tributary_state
					is_subject_of_type = march 
					is_subject_of_type = vassal 
				}
			}
			amount = 5
		}
	}
	task_requirements = {
		if = {
			limit = {
				has_estate_agenda_auto_completion = {
					estate = estate_scholars
				}
			}
			has_estate_agenda_auto_completion = {
				estate = estate_scholars
			}
		}
		else = {
			calc_true_if = {
				all_subject_country = {
					OR = { 
						is_subject_of_type = tributary_state 
						is_subject_of_type = march 
						is_subject_of_type = vassal 
					}
					subsidised_percent_amount = { 
						value = 0.1
					}
				}
				amount = 5
			}
			is_in_deficit = no 
		}
	}
    task_completed_effect = {
		on_completed_agenda_effect = {
			estate = estate_scholars
		}
		add_country_modifier = {
			name = mng_the_puppetmaster_modifier
			duration = 5475
		}
		add_estate_loyalty = {
			estate = estate_scholars 
			loyalty = 10 
		}
    }
    failing_effect = {
		on_failed_agenda_effect = yes
		clr_auto_complete_flag = yes
        add_estate_loyalty_modifier = {
            estate = estate_scholars
			desc = EST_VAL_AGENDA_DENIED
			loyalty = -5
			duration = 7300
        }
		custom_tooltip = mng_worsen_ld_subjects_tt
		hidden_effect = {
			every_subject_country = {
				limit = { is_subject_of = ROOT } 
				add_liberty_desire = 20
			}
		}
    }
}