﻿# Returns the skill level of the high priestess on a scale from
# 0 (min skill) to 1 (most skill). In terms of learning level
# this translates to (10, 50).
# scope:councillor = councillor_high_priestess
high_priestess_skill_factor = {
	scope:councillor = {
		value = learning
		subtract = 10
		divide = 40
		min = 0
		max = 1
	}
}

# The monthly lifestyle xp multiplier applied by task_divine_inspiration.
# Range: [0.05, 0.25] (aka 5% to 25%)
task_divine_inspiration_lifestyle_mult = {
	value = 0.05
	add = {
		value = 0.2
		multiply = high_priestess_skill_factor
	}
}

# The fascination progress multiplier applied by task_divine_inspiration.
# Range: [0.05, 0.25] (aka 5% to 25%)
task_divine_inspiration_fascination_mult = {
	value = 0.05
	add = {
		value = 0.2
		multiply = high_priestess_skill_factor
	}
}

# The amount of county opinion added by task_generous_welcome.
# Range: [5, 25]
task_generous_welcome_county_opinion = {
	value = 5
	add = {
		value = 20
		multiply = high_priestess_skill_factor
	}
	floor = yes
}

# The amount of monthly control added by task_generous_welcome.
# Range: [0.1, 0.5]
task_generous_welcome_monthly_county_control = {
	value = 0.1
	add = {
		value = 0.4
		multiply = high_priestess_skill_factor
	}
}

# The chance of an event occuring as part of task_generous_welcome.
# Range: [5%, 20%] (aka, an event roughly every 20 to 5 months based on
# councillor skill).
task_generous_welcome_monthly_event_chance = {
	value = 5
	add = {
		value = 15
		multiply = high_priestess_skill_factor
	}
	floor = yes
}

# Calculates the expected frequence of task_generous_welcome events for
# the current high priestess in months.
task_generous_welcome_approx_event_frequency_months = {
	value = 100
	divide = task_generous_welcome_monthly_event_chance
}

# The factor applied to the effect & speed of task_dispatch_missionaries
# due to having the regula fascinare holy site controlled.
task_dispatch_missionaries_holy_site_factor = {
	value = 1
	if = {
		limit = {
			scope:councillor_liege = {
				character_has_regula_holy_effect_mulsa_fascinare = yes
			}
		}
		value = 2
	}
}

# The amount of monthly control removed by task_dispatch_missionaries.
# No control will be removed if the county liege is of the Magister's faith.
# Range: [-1.0, -0.2]
# With Holy Site: [-2.0, -0.4]
task_dispatch_missionaries_monthly_county_control = {
	if = {
		limit = {
			# If county liege is magister faith, don't decrease control.
			exists = scope:county
			exists = scope:county.holder
			scope:county.holder.faith = scope:councillor_liege.faith
		}
		value = 0
	}
	else = {
		value = -0.2
		add = {
			value = -0.8
			multiply = high_priestess_skill_factor
		}
		multiply = task_dispatch_missionaries_holy_site_factor
	}
}

# Calculates the amount of progress on task_dispatch_missionaries which the
# councillor should make per 30 days. 1/30th of this value will be applied
# daily, and once the value reaches 100, the task is completed.
# Base Range: [1, 5] aka duration of 3000d to 600d.
# With Holy Site: [2, 10] aka duration of 1500d to 300d.
# Contested Range: [0.5, 5] aka duration of 6000d to 600d.
# Contested Range With Holy Site : [0.5, 10] aka duration of 6000d to 300d.
task_dispatch_missionaries_monthly_progress = {
	value = {
		value = 1
		desc = regula_council_base_progress
	}

	add = {
		value = 4
		multiply = high_priestess_skill_factor
		desc = regula_high_priestess_skill
	}

	multiply = {
		value = task_dispatch_missionaries_holy_site_factor
		desc = task_dispatch_missionaries_holy_site_desc
	}

	if = {
		limit = {
			exists = scope:county
			exists = scope:county.faith
		}

		add = {
			value = {
				value = scope:councillor_liege.faith.fervor
				subtract = scope:county.faith.fervor
				multiply = 0.05
			}
			desc = task_dispatch_missionaries_fervor_desc
		}
	}

	if = {
		limit = {
				councillor_liege_has_erudition_legacy_5_perk = yes
		}
		multiply = {
			value = 1.1
			desc = ERUDITION_DYNASTY_PERK_BONUS_VALUE
		}
	}

	if = {
		limit = {
			councillor_liege_has_family_business_bonus = yes
		}
		multiply = {
			value = 1.1
			desc = FAMILY_BUSINESS_BONUS_VALUE
		}
	}

	# If we have a target, and the target liege is opposed, apply resistance.
	if = {
		limit = {
			exists = scope:county
			exists = scope:county.holder
			NOR = { 
				scope:county.holder.faith = scope:councillor_liege.faith
				scope:county.holder.secret_faith ?= scope:councillor_liege.faith
			}
		}

		subtract = {
			value = 3
			multiply = scope:county.holder.character_intrigue_skill_factor
			desc = regula_council_target_intrigue_skill
		}

		if = {
			limit = {
				exists = scope:county.holder.cp:councillor_spymaster
				NOR = {
					scope:county.holder.cp:councillor_spymaster = scope:councillor_liege
					scope:county.holder.cp:councillor_spymaster.faith = scope:councillor_liege.faith
					scope:county.holder.cp:councillor_spymaster.secret_faith ?= scope:councillor_liege.faith
				}
				scope:county.holder.cp:councillor_spymaster = {
					is_performing_council_task = task_disrupt_schemes
				}
			}
			multiply = {
				value = scope:county.holder.cp:councillor_spymaster.spymaster_find_secrets_disrupt_schemes_modifier_factor
				desc = TARGET_SPYMASTER_disrupt_schemes
			}
		}

		if = {
			limit = {
				target_is_liege_or_above = scope:county.holder
			}
			multiply = {
				value = 0.5
				desc = TARGET_IS_LIEGE_penalty
			}
		}
			### 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
		}
	}
	}

	max = {
		value = {
			value = 5
			multiply = task_dispatch_missionaries_holy_site_factor
		}
		desc = regula_council_max_progress
	}

	# Conversion speed game rules
	# Game rules are allowed to push us above normal max progress
	# but not below min progress.
	if = {
		limit = {
			has_game_rule = slower_faith_conversion_speed
		}
		multiply = {
			value = slower_game_rule_value
			desc = GAME_RULE_SLOWER_REASON
		}
	}
	if = {
		limit = {
			has_game_rule = significantly_slower_faith_conversion_speed
		}
		multiply = {
			value = significantly_slower_game_rule_value
			desc = GAME_RULE_SIGNIFICANTLY_SLOWER_REASON
		}
	}
	if = {
		limit = {
			has_game_rule = faster_faith_conversion_speed
		}
		multiply = {
			value = faster_game_rule_value
			desc = GAME_RULE_FASTER_REASON
		}
	}
	if = {
		limit = {
			has_game_rule = significantly_faster_faith_conversion_speed
		}
		multiply = {
			value = significantly_faster_game_rule_value
			desc = GAME_RULE_SIGNIFICANTLY_FASTER_REASON
		}
	}

	min = {
		value = 0.5
		desc = regula_council_min_progress
	}
}

# Calculates the expected duration of task_dispatch_missionaries for the
# current high priestess in months.
task_dispatch_missionaries_duration_months = {
	value = 100
	divide = task_dispatch_missionaries_monthly_progress
}
