﻿@esr_friends_in_high_places_tier_duchy = 10
@esr_friends_in_high_places_tier_kingdom = 20
@esr_friends_in_high_places_tier_empire = 30

esr_friends_in_high_places_exp_value = {

	#Scope to the other party! ex. scope:target = {... value = root.esr_friends_in_high_places_exp_value}
	value = 0

	if = {
		limit = {
			OR = {
				highest_held_title_tier = tier_empire
				any_spouse = {
					highest_held_title_tier = tier_empire
				}
			}
		}
		add = {
			value = @esr_friends_in_high_places_tier_empire
		}
	}
	else_if = {
		limit = {
			OR = {
				highest_held_title_tier = tier_kingdom
				any_spouse = {
					highest_held_title_tier = tier_kingdom
				}
			}
		}
		add = {
			value = @esr_friends_in_high_places_tier_kingdom
		}
	}
	else_if = {
		limit = {
			OR = {
				highest_held_title_tier = tier_duchy
				any_spouse = {
					highest_held_title_tier = tier_duchy
				}
			}
		}
		add = {
			value = @esr_friends_in_high_places_tier_duchy
		}
	}

	max = 50
	min = 0
}

esr_friends_in_high_places_rank_change_value = {
	# scope to either root or root's spouse whichever has higher rank
	value = 0

	if = {
		limit = {
			exists = scope:esr_old_highest_title
			scope:esr_old_highest_title.tier = tier_duchy
		}
		subtract = {
			value = @esr_friends_in_high_places_tier_duchy
		}
	}

	else_if = {
		limit = {
			exists = scope:esr_old_highest_title
			scope:esr_old_highest_title.tier = tier_kingdom
		}
		subtract = {
			value = @esr_friends_in_high_places_tier_kingdom
		}
	}

	else_if = {
		limit = {
			exists = scope:esr_old_highest_title
			scope:esr_old_highest_title.tier = tier_empire
		}
		subtract = {
			value = @esr_friends_in_high_places_tier_empire
		}		
	}

	if = {
		limit = {
			highest_held_title_tier = tier_duchy
		}
		add = {
			value = @esr_friends_in_high_places_tier_duchy
		}
	}

	else_if = {
		limit = {
			highest_held_title_tier = tier_kingdom
		}
		add = {
			value = @esr_friends_in_high_places_tier_kingdom
		}
	}

	else_if = {
		limit = {
			highest_held_title_tier = tier_empire
		}
		add = {
			value = @esr_friends_in_high_places_tier_empire
		}
	}
}

esr_friends_in_high_places_marriage_value = {
	value = 0

	if = {
		limit = {
			scope:esr_low_spouse.highest_held_title_tier = tier_duchy
		}
		subtract = {
			value = @esr_friends_in_high_places_tier_duchy
		}
	}

	else_if = {
		limit = {
			scope:esr_low_spouse.highest_held_title_tier = tier_kingdom
		}
		subtract = {
			value = @esr_friends_in_high_places_tier_kingdom
		}
	}

	else_if = {
		limit = {
			scope:esr_low_spouse.highest_held_title_tier = tier_empire
		}
		subtract = {
			value = @esr_friends_in_high_places_tier_empire
		}
	}

	if = {
		limit = {
			scope:esr_high_spouse.highest_held_title_tier = tier_duchy
		}
		add = {
			value = @esr_friends_in_high_places_tier_duchy
		}
	}

	else_if = {
		limit = {
			scope:esr_high_spouse.highest_held_title_tier = tier_kingdom
		}
		add = {
			value = @esr_friends_in_high_places_tier_kingdom
		}
	}

	else_if = {
		limit = {
			scope:esr_high_spouse.highest_held_title_tier = tier_empire
		}
		add = {
			value = @esr_friends_in_high_places_tier_empire
		}
	}

	if = {
		limit = {
			OR = {
				scope:esr_action_type = flag:divorce
				scope:esr_action_type = flag:spouse_death
			}
		}
		multiply = -1
	}
}

esr_well_connected_rank_lost_value = {
	# scope to either root or root's spouse whichever has higher rank
	value = 0

	if = {
		limit = {
			exists = scope:title
			scope:title.tier >= tier_county
		}
		subtract = {
			value = 3
		}
	}

	if = {
		limit = {
			highest_held_title_tier >= tier_county
		}
		add = {
			value = 3
		}
	}
}

esr_well_connected_marriage_value = {
	value = 0

	if = {
		limit = {
			scope:esr_low_spouse.highest_held_title_tier < tier_county
			scope:esr_high_spouse.highest_held_title_tier >= tier_county
		}
		add = {
			value = 3
		}
	}

	if = {
		limit = {
			OR = {
				scope:esr_action_type = flag:divorce
				scope:esr_action_type = flag:spouse_death
			}
		}
		multiply = -1
	}
}

esr_popular_among_peers_exp_value = {
	value = 0

	if = {
		limit = {
			exists = scope:esr_perspective_char.liege
			is_vassal_of = scope:esr_perspective_char.liege
		}
		if = {
			limit ={liege.vassal_count > 5}
			add = {
				value = 125
			}
			divide = {
				value = liege.vassal_count
				min = 5
				max = 12
			}
		}
		else = {
			add = {
				value = 25
			}
		}
	}
	else_if = {
		limit = {
			exists = scope:esr_perspective_char.top_liege
			is_vassal_or_below_of = scope:esr_perspective_char.top_liege
			NOR = {
				is_vassal_of = scope:esr_perspective_char
				scope:esr_perspective_char = {
					is_vassal_of = prev
				}
			}
		}
		if = {
			limit ={top_liege.vassal_count > 5}
			add = {
				value = 75
			}
			divide = {
				value = top_liege.vassal_count
				min = 5
				max = 12
			}
		}
		else = {
			add = {
				value = 15
			}
		}
	}

	max = 50
	min = 0
}

esr_lost_friends_in_high_places_exp_value = {

	#Scope to the other party! ex. scope:target = {... value = root.this_value}

	value = esr_friends_in_high_places_exp_value
	multiply = -1

	max = 0
	min = -50
}

esr_lost_popular_among_peers_exp_value = {
	#Scope to the other party! ex. scope:target = {... value = root.this_value}

	value = esr_popular_among_peers_exp_value
	multiply = -1

	max = 0
	min = -50
}

esr_social_pariah_exp_value = {
	#Scope to the other party! ex. scope:target = {... value = root.this_value}
	value = esr_friends_in_high_places_exp_value
}

esr_social_pariah_rank_change_value = {
	#Scope to the other party! ex. scope:target = {... value = root.this_value}
	value = esr_friends_in_high_places_rank_change_value	
}

esr_social_pariah_marriage_value = {
	value = esr_friends_in_high_places_marriage_value
}

esr_lost_social_pariah_exp_value = {
	#Scope to the other party! ex. scope:target = {... value = root.this_value}

	value = esr_social_pariah_exp_value
	multiply = -1

	max = 0
	min = -50
}