﻿court_chaplain_conversion_contextual_bonuses = {
	#Perk Bonus
	if = {
		limit = {
			scope:councillor_liege = { has_perk = zealous_proselytizer_perk }
		}
		add = {
			value = scope:councillor.court_chaplain_conversion_monthly_increase_perk_bonus
			desc = CONVERSION_PERK_BONUS_VALUE
		}
	}
	if = {
		limit = {
			councillor_liege_has_erudition_legacy_5_perk = yes
		}
		add = {
			value = scope:councillor.court_chaplain_conversion_monthly_increase_dynasty_perk_bonus
			desc = CONVERSION_DYNASTY_PERK_BONUS_VALUE
		}
	}
	if = {
		limit = {
			councillor_liege_has_family_business_bonus = yes
		}
		add = {
			value = scope:councillor.court_chaplain_conversion_monthly_increase_family_business_bonus
			desc = FAMILY_BUSINESS_BONUS_VALUE
		}
	}
	if = {
		limit = {
			councillor_liege_has_consulted_house_bonus = yes
		}
		add = {
			value = scope:councillor.court_chaplain_conversion_monthly_increase_consulted_house_bonus
			desc = CONSULTED_HOUSE_BONUS_VALUE
		}
	}
	# Relation Bonuses/Penalties
	if = { # Friend
		limit = {
			scope:councillor_liege = {
				has_relation_friend = scope:councillor
				NOT = { has_relation_best_friend = scope:councillor }
			}
		}
		add = {
			value = scope:councillor.court_chaplain_conversion_monthly_increase_friend_bonus
			desc = COUNCILLOR_IS_YOUR_FRIEND
		}
	}
	if = { # Best Friend
		limit = {
			scope:councillor_liege = {
				has_relation_best_friend = scope:councillor
			}
		}
		add = {
			value = scope:councillor.court_chaplain_conversion_monthly_increase_best_friend_bonus
			desc = COUNCILLOR_IS_YOUR_BEST_FRIEND
		}
	}
	if = { # Rival
		limit = {
			scope:councillor_liege = {
				has_relation_rival = scope:councillor
				NOT = { has_relation_nemesis = scope:councillor }
			}
		}
		add = {
			value = scope:councillor.court_chaplain_conversion_monthly_increase_rival_bonus
			desc = COUNCILLOR_IS_YOUR_RIVAL
		}
	}
	if = { # Nemesis
		limit = {
			scope:councillor_liege = {
				has_relation_nemesis = scope:councillor
			}
		}
		add = {
			value = scope:councillor.court_chaplain_conversion_monthly_increase_nemesis_bonus
			desc = COUNCILLOR_IS_YOUR_NEMESIS
		}
	}
	#Conversion modifiers from where the Faith is on the Pluralism spectrum.
	if = {
		limit = {
			scope:councillor.faith = {
				has_doctrine_parameter = pluralism_fundamentalist_proselytization_bonus
			}
		}
		add = {
			value = scope:councillor.conversion_fundamentalist_faith_bonus
			desc = COURT_CHAPLAIN_CONVERSION_FUNDAMENTALIST_FAITH_BONUS
		}
	}
	if = {
		limit = {
			scope:councillor.faith = {
				has_doctrine_parameter = pluralism_pluralistic_proselytization_penalty
			}
		}
		add = {
			value = scope:councillor.conversion_pluralistic_faith_penalty
			desc = COURT_CHAPLAIN_CONVERSION_PLURALISTIC_FAITH_PENALTY
		}
	}
	
	#Conversion penalties for County Faith Tenets
	if = {
		limit = {
			exists = scope:county
			scope:county.faith = {
				has_doctrine = tenet_false_conversion_sanction
			}
		}
		add = {
			value = scope:councillor.conversion_false_conversion_sanction_resistance
			desc = COURT_CHAPLAIN_CONVERSION_FALSE_CONVERSION_MODIFIER
		}
	}
	if = {
		limit = {
			exists = scope:county
			scope:county.faith = {
				has_doctrine = tenet_reincarnation
			}
		}
		add = {
			value = scope:councillor.conversion_reincarnation_resistance
			desc = COURT_CHAPLAIN_CONVERSION_REINCARNATION_MODIFIER
		}
	}
	if = {
		limit = {
			exists = scope:county
			scope:county.faith = {
				has_doctrine = tenet_dharmic_pacifism
			}
		}
		add = {
			value = scope:councillor.conversion_dharmic_pacifism_resistance
			desc = COURT_CHAPLAIN_CONVERSION_DHARMIC_PACIFISM_MODIFIER
		}
	}
	if = {
		limit = {
			exists = scope:county
			scope:county.faith = {
				has_doctrine_parameter = tenet_adaptive_conversion_resistance
			}
		}
		add = {
			value = scope:councillor.conversion_adaptive_resistance
			desc = COURT_CHAPLAIN_CONVERSION_ADAPTIVE_MODIFIER
		}
	}
	if = {
		limit = {
			exists = scope:county
			scope:county.faith = {
				has_doctrine = tenet_pastoral_isolation
			}
		}
		add = {
			value = scope:councillor.conversion_pastoral_isolation_resistance
			desc = COURT_CHAPLAIN_CONVERSION_PASTORAL_ISOLATION_MODIFIER
		}
	}
	if = {
		limit = {
			scope:councillor.liege.faith = { has_doctrine = tenet_communal_identity }
			exists = scope:county
			NOT = { scope:county.culture = scope:councillor.liege.culture }
		}
		add = {
			value = scope:councillor.conversion_communal_identity_resistance
			desc = COURT_CHAPLAIN_CONVERSION_COMMUNAL_IDENTITY_PENALTY_MODIFIER
		}
	}

	# Tenet Modifiers
	## Bonuses
	### Mendicant Preachers
	if = {
		limit = {
			scope:councillor.faith = {
				has_doctrine_parameter = mendicant_preachers_conversion_active
			}
		}
		add = {
			value = scope:councillor.conversion_mendicant_preachers_bonus
			desc = COURT_CHAPLAIN_CONVERSION_MENDICANT_PREACHERS_MODIFIER
		}
	}
	### Communal Identity
	if = {
		limit = {
			exists = scope:county
			scope:councillor.faith = {
				has_doctrine_parameter = same_culture_conversion_bonus_active
			}
			scope:county.culture = scope:councillor.liege.culture
		}
		add = {
			value = scope:councillor.conversion_communal_identity_bonus
			desc = COURT_CHAPLAIN_CONVERSION_COMMUNAL_IDENTITY_BONUS_MODIFIER
		}
	}
	### GHW sans HoF buffs
	if = {
		limit = {
			exists = scope:county
			scope:councillor.faith = {
				has_doctrine_parameter = ghw_no_hof_conversion_buffs_active
				OR = {
					has_doctrine_parameter = no_head_of_faith
					NOT = { exists = religious_head }
				}
				holy_sites_controlled >= 1
			}
		}
		add = {
			value = scope:councillor.conversion_ghw_tenet_no_hof_bonus
			desc = COURT_CHAPLAIN_CONVERSION_GHW_TENET_NO_HOF_MODIFIER
		}
	}
	### Chthonic Redoubts
	if = {
		limit = {
			exists = scope:county
			scope:councillor.faith = { has_doctrine_parameter = easier_to_convert_faith_in_mountains }
			scope:county = {
				# We check any province and not just title province, to be generous.
				any_county_province = {
					OR = {
						terrain = mountains
						terrain = desert_mountains
					}
				}
			}
		}
		add = {
			value = scope:councillor.easier_to_convert_faith_in_mountains_bonus
			desc = COURT_CHAPLAIN_CONVERSION_EASIER_TO_CONVERT_FAITH_IN_MOUNTAINS_BONUS_MODIFIER
		}
	}
	## Maluses
	### Chthonic Redoubts
	if = {
		limit = {
			exists = scope:county
			scope:county = {
				faith = { has_doctrine_parameter = harder_to_convert_faith_away_in_mountains }
				# We check any province and not just title province, to be generous.
				any_county_province = {
					OR = {
						terrain = mountains
						terrain = desert_mountains
					}
				}
			}
		}
		add = {
			value = scope:councillor.harder_to_convert_faith_away_in_mountains_malus
			desc = COURT_CHAPLAIN_CONVERSION_HARDER_TO_CONVERT_FAITH_AWAY_IN_MOUNTAINS_MALUS_MODIFIER
		}
	}
	### Syncretics
	#### Syncretic tenets aim to allow a faith and a separate religion/family to coexist without one eating the other. Accordingly, we make it harder for you to syncretise with a faith *then* wipe it out.
	if = {
		limit = {
			exists = scope:county
			scope:councillor.faith = { has_doctrine_parameter = unreformed_syncretic_actor_opinion_active }
			scope:county.faith = { has_doctrine_parameter = unreformed}
		}
		add = {
			value = scope:councillor.conversion_syncretic_with_religion_malus
			desc = COURT_CHAPLAIN_CONVERSION_SYNCRETIC_WITH_RELIGION_MODIFIER
		}
	}
	if = {
		limit = {
			exists = scope:county
			scope:councillor.faith = { has_doctrine_parameter = christian_syncretic_actor_opinion_active }
			scope:county.faith = { religion_tag = christianity_religion }
		}
		add = {
			value = scope:councillor.conversion_syncretic_with_religion_malus
			desc = COURT_CHAPLAIN_CONVERSION_SYNCRETIC_WITH_RELIGION_MODIFIER
		}
	}
	if = {
		limit = {
			exists = scope:county
			scope:councillor.faith = { has_doctrine_parameter = islamic_syncretic_actor_opinion_active }
			scope:county.faith = { religion_tag = islam_religion }
		}
		add = {
			value = scope:councillor.conversion_syncretic_with_religion_malus
			desc = COURT_CHAPLAIN_CONVERSION_SYNCRETIC_WITH_RELIGION_MODIFIER
		}
	}
	if = {
		limit = {
			exists = scope:county
			scope:councillor.faith = { has_doctrine_parameter = jewish_syncretic_actor_opinion_active }
			scope:county.faith = { religion_tag = judaism_religion }
		}
		add = {
			value = scope:councillor.conversion_syncretic_with_religion_malus
			desc = COURT_CHAPLAIN_CONVERSION_SYNCRETIC_WITH_RELIGION_MODIFIER
		}
	}

	#Various Modifier Penalties
	if = {
		limit = {
			exists = scope:county
			scope:county = { has_county_modifier = governance_1074_local_faith_respected_modifier }
		}
		add = {
			value = scope:councillor.local_faith_respected_modifier_value
			desc = COURT_CHAPLAIN_CONVERSION_LOCAL_COUNTY_MODIFIERS
		}
	}
	if = {
		limit = {
			exists = scope:county
			scope:county = { has_county_modifier = governance_1074_population_fled_persecution_modifier }
		}
		add = {
			value = scope:councillor.population_fled_persecution_modifier_value
			desc = COURT_CHAPLAIN_CONVERSION_LOCAL_COUNTY_MODIFIERS
		}
	}
	if = {
		limit = {
			scope:councillor.liege = {
				OR = {
					has_character_modifier = defiant_high_king_conversion_boost_modifier
					has_character_modifier = defiant_high_queen_conversion_boost_modifier
				}
				religion = religion:germanic_religion
			}
			scope:county.faith = {
				NOT = { has_doctrine_parameter = unreformed }
			}
		}
		add = {
			value = scope:councillor.defiant_high_monarch_conversion_boost_value
			desc = COURT_CHAPLAIN_CONVERSION_LIEGE_IS_DEFIANT_HIGH_MONARCH
		}
	}
	if = {
		limit = {
			exists = scope:county
			scope:county = { has_county_modifier = court_6090_almoners_county_modifier }
		}
		add = {
			value = scope:councillor.court_6090_almoners_modifier_value
			desc = COURT_CHAPLAIN_CONVERSION_LOCAL_COUNTY_MODIFIERS
		}
	}
	if = {
		limit = {
			exists = scope:county
			scope:county = { has_county_modifier = hold_court_8200_vassal_modifier }
		}
		add = {
			value = scope:councillor.court_8200_vassal_modifier_value
			desc = COURT_CHAPLAIN_CONVERSION_LOCAL_COUNTY_MODIFIERS
		}
	}	
	if = {
		limit = {
			exists = scope:county
			scope:county = { has_county_modifier = petition_liege_county_control_modifier }
		}
		add = {
			value = scope:councillor.petition_liege_county_convert_modifier_value
			desc = COURT_CHAPLAIN_CONVERSION_LOCAL_COUNTY_MODIFIERS
		}
	}

	#Conversion bonuses from certain Holy Sites.
	if = {
		limit = {
			scope:councillor.faith = {
				controls_holy_site = jerusalem
			}
			title:b_jerusalem = {
				is_holy_site_of = scope:councillor.faith
			}
		}
		add = {
			value = scope:councillor.conversion_holy_site_jerusalem
			desc = COURT_CHAPLAIN_CONVERSION_HOLY_SITE_JERUSALEM
		}
	}
	if = {
		limit = {
			scope:councillor.faith = {
				controls_holy_site = kerala
			}
			title:b_honnore = {
				is_holy_site_of = scope:councillor.faith
			}
		}
		add = {
			value = scope:councillor.conversion_holy_site_kerala
			desc = COURT_CHAPLAIN_CONVERSION_HOLY_SITE_KERALA
		}
	}
	if = {
		limit = {
			exists = scope:county
			scope:councillor.faith = {
				controls_holy_site = iona
			}
			title:b_islay = {
				is_holy_site_of = scope:councillor.faith
			}
			scope:county.title_province = {
				geographical_region = world_europe_west_britannia
			}
		}
		add = {
			value = scope:councillor.conversion_holy_site_iona
			desc = COURT_CHAPLAIN_CONVERSION_HOLY_SITE_IONA
		}
	}
	if = {
		limit = {
			exists = scope:county
			scope:county.faith = {
				controls_holy_site = wadi_el_milk
			}
			title:b_wadi_el-milk = {
				is_holy_site_of = scope:councillor.faith
			}
		}
		add = {
			value = scope:councillor.conversion_holy_site_wadi_el_milk
			desc = COURT_CHAPLAIN_CONVERSION_HOLY_SITE_WADI_EL_MILK
		}
	}
	if = {
		limit = {
			scope:councillor.faith = {
				controls_holy_site = cordoba
			}
			title:b_cordoba = {
				is_holy_site_of = scope:councillor.faith
			}
		}
		add = {
			value = scope:councillor.conversion_holy_site_cordoba
			desc = COURT_CHAPLAIN_CONVERSION_HOLY_SITE_CORDOBA
		}
	}
	if = {
		limit = {
			exists = scope:county
			scope:county.faith = {
				controls_holy_site = visoki
			}
			title:b_visoki = {
				is_holy_site_of = scope:councillor.faith
			}
		}
		add = {
			value = scope:councillor.conversion_holy_site_visoki
			desc = COURT_CHAPLAIN_CONVERSION_HOLY_SITE_VISOKI
		}
	}

	#Tradition modifiers
	if = {
		limit = {
			exists = scope:county
			scope:county.culture = {
				has_cultural_parameter = more_easily_converted
			}
		}
		add = {
			value = conversion_culture_more_easily_converted
			desc = TRADITION_RELIGION_BLENDING_CONVERSION_MODIFIER
		}
	}
	if = {
		limit = {
			exists = scope:county
			scope:county.culture = {
				has_cultural_parameter = harder_to_convert_county_faith
			}
		}
		add = {
			value = conversion_culture_harder_to_convert
			desc = TRADITION_HARDER_TO_CONVERT_CONVERSION_MODIFIER
		}
	}

	# Struggle Bonuses/Penalties
	## Boost conversion in some phases.
	if = {
		limit = {
			exists = scope:county
			scope:county = {
				any_county_struggle = { has_struggle_phase_parameter = county_faith_conversion_in_region_proceeds_faster }
			}
		}
		add = {
			value = scope:councillor.boost_county_conversion_phase_bonus_value
			desc = CHAPLAIN_CONVERT_COUNTY_STRUGGLE_BONUS
		}
	}
	## Reduce it in others.
	if = {
		limit = {
			exists = scope:county
			scope:county = {
				any_county_struggle = {
					has_struggle_phase_parameter = county_faith_conversion_in_region_proceeds_slower
				}
			}
		}
		add = {
			value = scope:councillor.boost_county_conversion_phase_malus_value
			desc = CHAPLAIN_CONVERT_COUNTY_STRUGGLE_PENALTY
		}
	}

	# FP3 ending
	if = {
		limit = {
			exists = global_var:fp3_struggle_ending
			global_var:fp3_struggle_ending = flag:fp3_struggle_shia_caliphate_ending
			scope:councillor.faith = {
				has_doctrine = muhammad_succession_shia_doctrine
			}
		}
		add = {
			value = scope:councillor.court_chaplain_shia_promotion
			desc = CONVERSION_FP3_STRUGGLE_ENDING_BONUS
		}
	}
	else_if = {
		limit = {
			exists = global_var:fp3_struggle_ending
			global_var:fp3_struggle_ending = flag:fp3_struggle_strengthen_caliphate_ending
			scope:councillor.faith = {
				has_doctrine = muhammad_succession_sunni_doctrine
			}
		}
		add = {
			value = scope:councillor.court_chaplain_sunni_promotion
			desc = CONVERSION_FP3_STRUGGLE_ENDING_BONUS
		}
	}

	#Other
	if = {
		limit = {
			scope:councillor.liege = {
				has_trait = savior
			}
		}
		add = {
			value = scope:councillor.conversion_savior_liege
			desc = COURT_CHAPLAIN_CONVERSION_LIEGE_IS_SAVIOR
		}
	}
	if = {
		limit = {
			scope:councillor.liege = {
				has_trait = divine_blood
			}
		}
		add = {
			value = scope:councillor.conversion_divine_blood_liege
			desc = COURT_CHAPLAIN_CONVERSION_LIEGE_IS_DIVINE_BLOOD
		}
	}
	if = {
		limit = {
			exists = scope:county
			scope:county = {
				has_variable = learning_encouraged_conversion
			}
		}
		add = {
			value = scope:councillor.conversion_learning_theology
			desc = COURT_CHAPLAIN_CONVERSION_LEARNING_THEOLOGY
		}
	}
	#Foreign-raised reformer is enforcing uniform faith
	if = {
		limit = {
			scope:councillor.liege = {
				has_character_flag = reformer_conversion
			}
		}
		add = {
			value = scope:councillor.court_chaplain_conversion_monthly_increase_perk_bonus
			desc = CONVERSION_REFORMER_BONUS_VALUE
		}
	}
	### Regula Reaver Coastal Bonus
	if = {
		limit = {
			exists = scope:county
			scope:councillor_liege ?= {
				culture ?= {
					has_cultural_parameter = culture_regula_coastal_conversion
				}
			}
			scope:county = {
				# We check any province and not just title province, to be generous.
				any_county_province = {
					is_coastal = yes
				}
			}
		}
		add = {
			value = scope:councillor.regula_easier_to_convert_faith_coastal_bonus
			desc = REGULA_COURT_CHAPLAIN_CONVERSION_EASIER_TO_CONVERT_COASTAL_BONUS_MODIFIER
		}
	}
	## Regula Reaver Coastal Malus
	if = {
		limit = {
			exists = scope:county
			scope:councillor_liege ?= {
				culture ?= {
					has_cultural_parameter = culture_regula_coastal_conversion
				}
			}
			scope:county = {
				NOT = {
					any_county_province = {	is_coastal = yes }
				}
			}
		}
		add = {
			value = scope:councillor.regula_harder_to_convert_faith_coastal_malus
			desc = REGULA_COURT_CHAPLAIN_CONVERSION_HARDER_TO_CONVERT_COASTAL_MALUS_MODIFIER
		}
	}
}


regula_easier_to_convert_faith_coastal_bonus_root_value = 0.5 

regula_easier_to_convert_faith_coastal_bonus_loc_control = {
	value = regula_easier_to_convert_faith_coastal_bonus_root_value
	multiply = 100
}

regula_easier_to_convert_faith_coastal_bonus = {
	value = court_chaplain_conversion_base_total
	multiply = regula_easier_to_convert_faith_coastal_bonus_root_value
}

regula_harder_to_convert_faith_coastal_malus_root_value = -0.75

regula_harder_to_convert_faith_coastal_malus_loc_control = {
	value = regula_harder_to_convert_faith_coastal_malus_root_value
	multiply = 100
}

regula_harder_to_convert_faith_coastal_malus = {
	value = court_chaplain_conversion_base_total
	multiply = regula_harder_to_convert_faith_coastal_malus_root_value
}