﻿
##################
# Foreign Affairs
##################

# Foreign Affairs opinion base modifier
chancellor_foreign_affairs_opinion_base = {
	add = diplomacy
	divide = 2
}

# Bonus to opinion from Adaptive Traditions
chancellor_foreign_affairs_opinion_max_perk_bonus_modifier = {
	add = chancellor_foreign_affairs_opinion_base
	multiply = {
		add = adaptive_traditions_perk_impact_percent
		divide = 100
	}
}

#chancellor_foreign_affairs_opinion_max_perk_bonus_modifier = {
#	value = 0
#	if = {
#		limit = {
#			scope:councillor_liege = { has_perk = adaptive_traditions_perk }
#		}
#		add = chancellor_foreign_affairs_opinion_base
#		multiply = {
#			add = adaptive_traditions_perk_impact_percent
#			divide = 100
#		}
#	}
#}

# Bonus to opinion from Bureaucrats
chancellor_foreign_affairs_opinion_max_erudition_modifier = {
	add = chancellor_foreign_affairs_opinion_base
	multiply = {
		add = erudition_legacy_5_percentage
		divide = 100
	}
}

# Bonus to opinion from Family Business
chancellor_foreign_affairs_opinion_max_family_business_modifier = {
	add = chancellor_foreign_affairs_opinion_base
	multiply = {
		add = family_business_councillors_percentage
		divide = 100
	}
}

# Calculated max opinion
chancellor_foreign_affairs_opinion_max = {
	add = chancellor_foreign_affairs_opinion_base
	# Add bonus from Clerical Justification:
	if = {
		limit = {
			scope:councillor_liege = { has_perk = adaptive_traditions_perk }
		}
		add = chancellor_foreign_affairs_opinion_max_perk_bonus_modifier
	}
	# Add bonus from Bureaucrats
	if = {
		limit = {
			councillor_liege_has_erudition_legacy_5_perk = yes
		}
		add = chancellor_foreign_affairs_opinion_max_erudition_modifier
	}
	# Add bonus from Family Business
	if = {
		limit = {
			councillor_liege_has_family_business_bonus = yes
		}
		add = chancellor_foreign_affairs_opinion_max_family_business_modifier
	}
}

# Set to max for AI, or gradual scale for players
chancellor_foreign_affairs_realm_opinion_scale = {
	add = 0
	if = {
		limit = {
			is_ai = yes
			scope:councillor_liege = { is_independent_ruler = no }
		}
		add = chancellor_foreign_affairs_opinion_max
	}
	else_if = {
		limit = {
			has_variable = chancellor_foreign_affairs_opinion_value
			scope:councillor_liege = { is_independent_ruler = no }
		}
		add = liege.var:chancellor_foreign_affairs_opinion_value
	}
}

chancellor_foreign_affairs_independent_opinion_scale = {
	add = 0
	if = {
		limit = {
			scope:councillor_liege = {
				is_ai = yes
				is_independent_ruler = yes
			}
		}
		add = chancellor_foreign_affairs_opinion_max
	}
	else_if = {
		limit = {
			scope:councillor_liege = {
				is_independent_ruler = yes
				has_variable = chancellor_foreign_affairs_opinion_value
			}
		}
		add = liege.var:chancellor_foreign_affairs_opinion_value
	}
}

# Calculate monthly increase
chancellor_foreign_affairs_monthly_increase = {
	add = chancellor_foreign_affairs_opinion_max
	divide = 24
}

### Prestige gain

# Base prestige gain scale
chancellor_foreign_affairs_prestige_gain_base = {
	add = diplomacy
	divide = 20
}

# Adaptive Traditions bonus
chancellor_foreign_affairs_prestige_gain_perk_bonus_scale = {
	if = {
		limit = { scope:councillor_liege = { has_perk = adaptive_traditions_perk } }
		add = chancellor_foreign_affairs_prestige_gain_base
		multiply = {
			value = adaptive_traditions_perk_impact_percent
			divide = 100
		}
	}
}

# Bureaucrats bonus
chancellor_foreign_affairs_prestige_gain_erudition_modifier = {
	if = {
		limit = {
			councillor_liege_has_erudition_legacy_5_perk = yes
		}
		add = chancellor_foreign_affairs_prestige_gain_base
		multiply = {
			add = erudition_legacy_5_percentage
			divide = 100
		}
	}
}

# Family Business bonus
chancellor_foreign_affairs_prestige_gain_family_business_modifier = {
	if = {
		limit = {
			councillor_liege_has_family_business_bonus = yes
		}
		add = chancellor_foreign_affairs_prestige_gain_base
		multiply = {
			add = family_business_councillors_percentage
			divide = 100
		}
	}
}

# Final calculation (used for tooltips only)
chancellor_foreign_affairs_prestige_calculation = {
	add = {
		value = chancellor_foreign_affairs_prestige_gain_base
		desc = "Base value"
	}
	add = {
		value = chancellor_foreign_affairs_prestige_gain_perk_bonus_scale
		desc = "Perk bonus"
	}
	add = {
		value = chancellor_foreign_affairs_prestige_gain_erudition_modifier
		desc = "Legacy bonus"
	}
	add = {
		value = chancellor_foreign_affairs_prestige_gain_family_business_modifier
		desc =  FAMILY_BUSINESS_BONUS_VALUE
	}
}



####################
# Domestic Affairs
####################
chancellor_domestic_affairs_opinion_base = {
	add = diplomacy
	divide = 2
}

chancellor_domestic_affairs_opinion_chains_of_loyalty_bonus = {
	add = chancellor_domestic_affairs_opinion_base
	multiply = {
		add = chains_of_loyalty_percentage
		divide = 100
	}
}

chancellor_domestic_affairs_opinion_erudition_bonus = {
	add = chancellor_domestic_affairs_opinion_base
	multiply = {
		add = erudition_legacy_5_percentage
		divide = 100
	}
}

chancellor_domestic_affairs_opinion_family_business_bonus = {
	add = chancellor_domestic_affairs_opinion_base
	multiply = {
		add = family_business_councillors_percentage
		divide = 100
	}
}

chancellor_domestic_affairs_opinion_max = {
	add = chancellor_domestic_affairs_opinion_base
	if = {
		limit = {
			scope:councillor_liege = { has_perk = chains_of_loyalty_perk }
		}
		add = chancellor_domestic_affairs_opinion_chains_of_loyalty_bonus
	}
	if = {
		limit = {
			councillor_liege_has_erudition_legacy_5_perk = yes
		}
		add = chancellor_domestic_affairs_opinion_erudition_bonus
	}
	if = {
		limit = {
			councillor_liege_has_family_business_bonus = yes
		}
		add = chancellor_domestic_affairs_opinion_family_business_bonus
	}
}

chancellor_domestic_affairs_opinion_scale = {
	value = 0
	if = {
		limit = {
		    scope:councillor_liege = {
		        is_ai = yes
		        is_independent_ruler = yes
		    }
		}
		add = chancellor_domestic_affairs_opinion_max
	}
	else_if = {
		limit = {
			scope:councillor_liege = { has_variable = chancellor_domestic_affairs_opinion_value }
		}
		add = scope:councillor_liege.var:chancellor_domestic_affairs_opinion_value
	}
}

chancellor_domestic_affairs_monthly_increase = {
	add = chancellor_domestic_affairs_opinion_max
	divide = 24
}

chancellor_domestic_affairs_tyranny_base = {
	add = diplomacy
	#multiply = 2
	min = 1
}

chancellor_domestic_affairs_tyranny_chains_of_loyalty_bonus = {
	value = 0
	if = {
		limit = {
			scope:councillor_liege = { has_perk = chains_of_loyalty_perk }
		}
		add = {
			value = chancellor_domestic_affairs_tyranny_base
			multiply = {
				add = chains_of_loyalty_percentage
				divide = 100
			}
		}
	}
}

chancellor_domestic_affairs_tyranny_erudition_bonus = {
	value = 0
	if = {
		limit = {
			councillor_liege_has_erudition_legacy_5_perk = yes
		}
		add = {
			value = chancellor_domestic_affairs_tyranny_base
			multiply = {
				add = erudition_legacy_5_percentage
				divide = 100
			}
		}
	}
}

chancellor_domestic_affairs_tyranny_family_business_bonus = {
	value = 0
	if = {
		limit = {
			councillor_liege_has_family_business_bonus = yes
		}
		add = {
			value = chancellor_domestic_affairs_tyranny_base
			multiply = {
				add = family_business_councillors_percentage
				divide = 100
			}
		}
	}
}

chancellor_domestic_affairs_tyranny_total = {
	add = chancellor_domestic_affairs_tyranny_base
	add = chancellor_domestic_affairs_tyranny_chains_of_loyalty_bonus
	add = chancellor_domestic_affairs_tyranny_erudition_bonus
	add = chancellor_domestic_affairs_tyranny_family_business_bonus
}

#####################
# Integrate Title
#####################

chancellor_integrate_title_current_progress = {
	value = 0
	if = {
		limit = { exists = scope:county }
		add = scope:county.active_de_jure_drift_progress
	}
}

chancellor_integrate_title_progress_gain = {
	add = diplomacy
	multiply = 0.35
}

chancellor_integrate_title_erudition_bonus = {
	add = chancellor_integrate_title_progress_gain
	multiply = family_business_councillors_percentage
	divide = 100
}

chancellor_integrate_title_family_business_bonus = {
	add = chancellor_integrate_title_progress_gain
	multiply = family_business_councillors_percentage
	divide = 100
}


# Relation impact
chancellor_integrate_title_monthly_increase_friend_bonus = {
	value = chancellor_integrate_title_progress_gain
	multiply = {
		add = council_friend_impact_percentage
		divide = 100
	}
}
chancellor_integrate_title_monthly_increase_best_friend_bonus = {
	value = chancellor_integrate_title_progress_gain
	multiply = {
		add = council_best_friend_impact_percentage
		divide = 100
	}
}
chancellor_integrate_title_monthly_increase_rival_bonus = {
	value = chancellor_integrate_title_progress_gain
	multiply = {
		add = council_rival_impact_percentage
		divide = 100
	}
}
chancellor_integrate_title_monthly_increase_nemesis_bonus = {
	value = chancellor_integrate_title_progress_gain
	multiply = {
		add = council_nemesis_impact_percentage
		divide = 100
	}
}


#####################
# Bestow Royal Favor
#####################

chancellor_bestow_royal_favor_base = 5

chancellor_bestow_royal_favor_monthly_change = {
	value = {
		add = scope:councillor.diplomacy
	}
}

chancellor_bestow_royal_favor_progress_gain = {
	add = diplomacy
	multiply = 0.5
}

chancellor_bestow_royal_favor_opinion_increase_per_success = {
	add = chancellor_bestow_royal_favor_opinion_increase_per_success_base
	add = chancellor_bestow_royal_favor_opinion_increase_per_success_grandeur
}

chancellor_bestow_royal_favor_opinion_increase_per_success_base = {
	add = {
		value = scope:councillor.diplomacy
		multiply = 0.3
		min = 1
		max = 10
		ceiling = yes
	}
}

chancellor_bestow_royal_favor_opinion_increase_per_success_grandeur = {
	add = {
		value = scope:councillor_liege.court_grandeur_current
		multiply = 0.05
		min = 1
		max = 10
		ceiling = yes
	}
}

# Base prestige gain scale
chancellor_bestow_royal_favor_prestige_gain_base = {
	add = scope:councillor.diplomacy
	divide = 5
	ceiling = yes
	divide = 10
}

# Vassal's base prestige gain scale (static so we can add a character modifier)
chancellor_bestow_royal_favor_prestige_gain_base_vassal = {
	add = 0.5
}

# Relation impact
chancellor_bestow_royal_favor_base_total = {
	add = chancellor_bestow_royal_favor_base
	add = chancellor_bestow_royal_favor_monthly_change
}

chancellor_bestow_royal_favor_monthly_increase_friend_bonus = {
	value = chancellor_bestow_royal_favor_base_total
	multiply = {
		add = council_friend_impact_percentage
		divide = 100
	}
}
chancellor_bestow_royal_favor_monthly_increase_best_friend_bonus = {
	value = chancellor_bestow_royal_favor_base_total
	multiply = {
		add = council_best_friend_impact_percentage
		divide = 100
	}
}
chancellor_bestow_royal_favor_monthly_increase_rival_bonus = {
	value = chancellor_bestow_royal_favor_base_total
	multiply = {
		add = council_rival_impact_percentage
		divide = 100
	}
}
chancellor_bestow_royal_favor_monthly_increase_nemesis_bonus = {
	value = chancellor_bestow_royal_favor_base_total
	multiply = {
		add = council_nemesis_impact_percentage
		divide = 100
	}
}




### Learn on the Job modifier
chancellor_learn_on_the_job_scale = {
	value = 0
	if = {
		limit = {
			liege = { has_perk = learn_on_the_job_perk }
		}
		add = diplomacy
		multiply = {
			add = learn_on_the_job_percentage
			divide = 100
		}
		floor = yes
		min = 1
	}
}

### Reliable House modifier
chancellor_reliable_house_scale = {
	value = 0
	if = {
		limit = {
			exists = liege.dynasty
			liege.dynasty = { has_dynasty_perk = fp2_coterie_legacy_2 }
			house = liege.house
		}
		add = diplomacy
		multiply = {
			add = council_reliable_house_percentage
			divide = 100
		}
		floor = yes
		min = 1
	}
}
