﻿mass_convert_mode_is_faith = {
	scope = character
	is_shown = {
		has_character_flag = mass_convert_targeted_religion
	}
}
mass_convert_mode_is_culture = {
	scope = character
	is_shown = {
		has_character_flag = mass_convert_targeted_culture
	}
}
sg_mc_toggle_faith_county = {
	scope = character
	saved_scopes = {
		target_county
	}
	effect = {
		scope:target_county = {
			if = {
				limit = { has_variable = mc_selected_faith }
				remove_variable = mc_selected_faith
				root = { change_variable = { name = mc_total_cost_faith subtract = 100 } }
			}
			else = {
				set_variable = mc_selected_faith
				root = { change_variable = { name = mc_total_cost_faith add = 100 } }
			}
		}
	}
}
sg_mc_toggle_all_faith_counties = {
	scope = character
	effect = {
		if = {
			limit = {
				any_in_list = {
					variable = mc_potential_counties_faith
					NOT = { has_variable = mc_selected_faith }
				}
			}
			every_in_list = {
				variable = mc_potential_counties_faith
				set_variable = mc_selected_faith
			}
			root = {
				set_variable = { name = mc_dummy_count value = 0 }
				every_in_list = {
					variable = mc_potential_counties_faith
					root = { change_variable = { name = mc_dummy_count add = 1 } }
				}
				set_variable = { name = mc_total_cost_faith value = var:mc_dummy_count }
				change_variable = { name = mc_total_cost_faith multiply = 100 }
				remove_variable = mc_dummy_count
			}
		}
		else = {
			every_in_list = {
				variable = mc_potential_counties_faith
				remove_variable = mc_selected_faith
			}
			root = {
				set_variable = { name = mc_total_cost_faith value = 0 }
			}
		}
	}
}
sg_mc_confirm_faith = {
	scope = character
	is_valid = {
		custom_description = {
			text = "mass_convert_must_select_one"
			subject = root
			any_in_list = {
				variable = mc_potential_counties_faith
				has_variable = mc_selected_faith
			}
		}
		custom_description = {
			text = "mass_convert_cannot_afford_desc"
			subject = root
			piety >= var:mc_total_cost_faith
		}
	}
	effect = {
		add_piety = { value = var:mc_total_cost_faith multiply = -1 }
		every_in_list = {
			variable = mc_potential_counties_faith
			limit = { has_variable = mc_selected_faith }
			set_county_faith = root.faith
			remove_variable = mc_selected_faith
		}
		clear_variable_list = mc_potential_counties_faith
		remove_character_flag = mass_convert_targeted_religion
		remove_variable = show_mass_convert_faith_window
		
		every_sub_realm_county = {
			limit = {
				OR = {
					has_variable = mc_selected_faith
					has_variable = mass_convert_potential
					has_variable = mass_convert_sub_realm
				}
			}
			if = {
				limit = { has_variable = mc_selected_faith }
				remove_variable = mc_selected_faith
			}
			remove_variable = mass_convert_potential
			remove_variable = mass_convert_sub_realm
		}
		if = {
			limit = { var:mc_total_cost_faith = 100 }
			send_interface_message = {
				type = event_generic_good_text
				title = mass_convert_targeted_success_title_singular_faith
				desc = mass_convert_targeted_success_desc_singular_faith
				left_icon = root
			}
		}
		else = {
			send_interface_message = {
				type = event_generic_good_text
				title = mass_convert_targeted_success_title_faith
				desc = mass_convert_targeted_success_desc_faith
				left_icon = root
			}
		}
	}
}
sg_mc_close_faith = {
	scope = character
	effect = {
		remove_character_flag = mass_convert_targeted_religion
		clear_variable_list = mc_potential_counties_faith
		remove_variable = show_mass_convert_faith_window
		
		every_sub_realm_county = {
			limit = {
				OR = {
					has_variable = mc_selected_faith
					has_variable = mass_convert_potential
					has_variable = mass_convert_sub_realm
				}
			}
			if = {
				limit = { has_variable = mc_selected_faith }
				remove_variable = mc_selected_faith
			}
			remove_variable = mass_convert_potential
			remove_variable = mass_convert_sub_realm
		}
	}
}
sg_mc_toggle_culture_county = {
	scope = character
	saved_scopes = {
		target_county
	}
	effect = {
		scope:target_county = {
			if = {
				limit = { has_variable = mc_selected_culture }
				remove_variable = mc_selected_culture
				root = { change_variable = { name = mc_total_cost_culture subtract = 100 } }
			}
			else = {
				set_variable = mc_selected_culture
				root = { change_variable = { name = mc_total_cost_culture add = 100 } }
			}
		}
	}
}
sg_mc_toggle_all_culture_counties = {
	scope = character
	effect = {
		if = {
			limit = {
				any_in_list = {
					variable = mc_potential_counties_culture
					NOT = { has_variable = mc_selected_culture }
				}
			}
			every_in_list = {
				variable = mc_potential_counties_culture
				set_variable = mc_selected_culture
			}
			root = {
				set_variable = { name = mc_dummy_count value = 0 }
				every_in_list = {
					variable = mc_potential_counties_culture
					root = { change_variable = { name = mc_dummy_count add = 1 } }
				}
				set_variable = { name = mc_total_cost_culture value = var:mc_dummy_count }
				change_variable = { name = mc_total_cost_culture multiply = 100 }
				remove_variable = mc_dummy_count
			}
		}
		else = {
			every_in_list = {
				variable = mc_potential_counties_culture
				remove_variable = mc_selected_culture
			}
			root = {
				set_variable = { name = mc_total_cost_culture value = 0 }
			}
		}
	}
}
sg_mc_confirm_culture = {
	scope = character
	is_valid = {
		custom_description = {
			text = "mass_convert_must_select_one"
			subject = root
			any_in_list = {
				variable = mc_potential_counties_culture
				has_variable = mc_selected_culture
			}
		}
		OR = {
			AND = {
				has_treasury = yes
				custom_description = {
					text = "mass_convert_not_enough_treasury_desc"
					subject = root
					treasury >= var:mc_total_cost_culture
				}
			}
			AND = {
				has_treasury = no
				custom_description = {
					text = "mass_convert_cannot_afford_desc"
					subject = root
					gold >= var:mc_total_cost_culture
				}
			}
		}
	}
	effect = {
		if = {
			limit = {
				has_treasury = yes
			}
			remove_treasury = var:mc_total_cost_culture
		}
		else = {
			remove_short_term_gold = var:mc_total_cost_culture
		}
		
		every_in_list = {
			variable = mc_potential_counties_culture
			limit = { has_variable = mc_selected_culture }
			set_county_culture = root.culture
			remove_variable = mc_selected_culture
		}
		clear_variable_list = mc_potential_counties_culture
		remove_character_flag = mass_convert_targeted_culture
		remove_variable = show_mass_convert_culture_window
		
		every_sub_realm_county = {
			limit = {
				OR = {
					has_variable = mc_selected_culture
					has_variable = mass_convert_potential
					has_variable = mass_convert_sub_realm
				}
			}
			if = {
				limit = { has_variable = mc_selected_culture }
				remove_variable = mc_selected_culture
			}
			remove_variable = mass_convert_potential
			remove_variable = mass_convert_sub_realm
		}
		if = {
			limit = { var:mc_total_cost_culture = 100 }
			send_interface_message = {
				type = event_generic_good_text
				title = mass_convert_targeted_success_title_singular_culture
				desc = mass_convert_targeted_success_desc_singular_culture
				left_icon = root
			}
		}
		else = {
			send_interface_message = {
				type = event_generic_good_text
				title = mass_convert_targeted_success_title_culture
				desc = mass_convert_targeted_success_desc_culture
				left_icon = root
			}
		}
	}
}
sg_mc_close_culture = {
	scope = character
	effect = {
		remove_character_flag = mass_convert_targeted_culture
		clear_variable_list = mc_potential_counties_culture
		remove_variable = show_mass_convert_culture_window
		
		every_sub_realm_county = {
			limit = {
				OR = {
					has_variable = mc_selected_culture
					has_variable = mass_convert_potential
					has_variable = mass_convert_sub_realm
				}
			}
			if = {
				limit = { has_variable = mc_selected_culture }
				remove_variable = mc_selected_culture
			}
			remove_variable = mass_convert_potential
			remove_variable = mass_convert_sub_realm
		}
	}
}
sg_mc_is_all_faith_selected = {
	scope = character
	is_valid = {
		NOT = {
			any_in_list = {
				variable = mc_potential_counties_faith
				NOT = { has_variable = mc_selected_faith }
			}
		}
		any_in_list = {
			variable = mc_potential_counties_faith
			always = yes
		}
	}
}
sg_mc_is_all_culture_selected = {
	scope = character
	is_valid = {
		NOT = {
			any_in_list = {
				variable = mc_potential_counties_culture
				NOT = { has_variable = mc_selected_culture }
			}
		}
		any_in_list = {
			variable = mc_potential_counties_culture
			always = yes
		}
	}
}
sg_mc_has_treasury = {
	scope = character
	is_valid = {
		has_treasury = yes
	}
}
