﻿# Openly convert all secret faith counties in your realm
secret_faith_openly_convert_all_in_realm = {
	if = {
		limit = { any_sub_realm_county = { has_variable = false_convert } }
		save_scope_value_as = { # Keeping track how many counties convert
			name = num_false_converts_counties
			value = 0
		}

		every_sub_realm_county = {
			limit = { has_variable = false_convert }
			save_temporary_scope_as = false_convert_county # Kei : var depends on scope, so we make sure the scope is right
			E_kCAFG_convert_faith_in_all_county_provinces = { # Convert them
				FACTOR = 0.7
				VARIANCE = 0.4
				FAITH = scope:false_convert_county.var:false_convert
				MAX = 0.85
			}
			remove_county_modifier = false_convert_modifier # Remove modifier too
			remove_variable = false_convert # No longer mark them as converts
			add_county_modifier = { # Everyone likes practicing their faith in the open!
				modifier = relieved_cryptos_modifier
				years = 25
			}
			save_scope_value_as = { # Updating how many counties convert
				name = num_false_converts_counties
				value = {
					value = scope:num_false_converts_counties
					add = 1
				}
			}
		}
		if = { # Include counties in the message if there are any
			limit = { scope:num_false_converts_counties > 0 }
			root = { # There is an edgecase where root has a link to realm, but is not a character themselves!
				send_interface_message = {
					type = event_religious_good_text
					title = event_false_converts.t
					desc = event_false_converts_plus_counties.desc
				}
			}
		}
	}
}

# Openly convert all secret faith counties of your faith in your realm
secret_faith_openly_convert_all_in_realm_specific = {
	if = {
		limit = {
			any_sub_realm_county = {
				has_variable = false_convert
				var:false_convert = root.faith
				NOT = { faith = root.faith } # Discount them if they've already been switched by the conversion action.
			}
		}

		save_scope_value_as = { # Keeping track how many counties convert
			name = num_false_converts_counties
			value = 0
		}

		every_sub_realm_county = {
			limit = {
				has_variable = false_convert
				var:false_convert = root.faith
				NOT = { faith = root.faith } # Discount them if they've already been switched by the conversion action.
			}
			save_temporary_scope_as = false_convert_county # Kei : var depends on scope, so we make sure the scope is right
			E_kCAFG_convert_faith_in_all_county_provinces = { # Convert them
				FACTOR = 0.7
				VARIANCE = 0.4
				FAITH = scope:false_convert_county.var:false_convert
				MAX = 0.85
			}
			remove_county_modifier = false_convert_modifier
			remove_variable = false_convert # Cleanup
			add_county_modifier = { # Everyone likes practicing their faith in the open!
				modifier = relieved_cryptos_modifier
				years = 25
			}
			save_scope_value_as = { # Updating how many counties convert
				name = num_false_converts_counties
				value = {
					value = scope:num_false_converts_counties
					add = 1
				}
			}
		}

		if = { # Include counties in the message if there are any
			limit = { scope:num_false_converts_counties > 0 }
			root = {
				send_interface_message = {
					type = event_religious_good_text
					title = event_false_converts.t
					desc = event_false_converts_plus_counties.desc
				}
			}
		}
	}
}

add_heresiarch_trait_effect = { # Flag is need to prevent trait being removed when gaining it close to conversion
	add_character_flag = {
		flag = new_heresiarch
		days = 3
	}
	if = {
		limit = {
			NOT = { has_trait = heresiarch }
		}
		add_trait = heresiarch
	}
}
