


##Mandala Capital Great Project Contribution Rewards
mandala_owner_reward_01_effect = {
	add_prestige = major_prestige_value
	dynasty = { add_dynasty_prestige = major_dynasty_prestige_gain }
	add_legitimacy = medium_legitimacy_gain
}

mandala_contributor_reward_effect = {
	add_prestige = major_prestige_value
	add_legitimacy = miniscule_legitimacy_gain
}

mandala_contributor_opinion_reward_effect = {
	$OVERLORD$ = { save_scope_as = overlord_scope }
	add_prestige = major_prestige_value
	add_legitimacy = miniscule_legitimacy_gain
}

gather_contributors_in_list_effect = {
	every_contribution = {
		limit = { contribution_is_funded = yes }
		contributor = {
			if = {
				limit = {
					scope:great_project = {
						trigger_if = {
							limit = { has_variable = plundered_contributors }
							NOT = { 
								is_target_in_variable_list = {
									name = plundered_contributors 
									target = prev
								}
							}
						}
					}
				}
				add_to_list = contributors_to_reward
			}
		}
	}
}

determine_if_contributed_and_save_scope_effect = {
	scope:great_project = {
		if = {
			limit = {
				any_contribution = {
					contribution_id = $CONTRIBUTION$
					contribution_is_funded = yes
				}
			}
			every_contribution = {
				limit = {
					contribution_id = $CONTRIBUTION$
					contribution_is_funded = yes
				}
				contributor = {
					if = {
						limit = {
							is_alive = no
							house = scope:owner.house
						}
						scope:owner = { save_scope_as = contributed_$CONTRIBUTION$ }
					}
					else = {
						save_scope_as = contributed_$CONTRIBUTION$
					}
				}
			}
		}
	}
}


### Capital 01 Breakdown Effects ###
mandala_contributor_minor_rite_reward_effect = {
	add_legitimacy = mandala_contribution_minor_legitimacy_reward
	add_piety_experience = mandala_contribution_medium_dynasty_reward
}
contributed_rites_of_worthiness_effect = {
	custom_description_no_bullet = { text = contributed_rite_of_worthiness }
	mandala_contributor_minor_rite_reward_effect = yes
}

mandala_contributor_slabs_of_sandstone_reward_effect = { add_prestige = mandala_contribution_major_prestige_reward }
contributed_slabs_of_sandstone_effect = {
	custom_description_no_bullet = { text = contributed_slabs_of_sandstone }
	mandala_contributor_slabs_of_sandstone_reward_effect = yes
}

mandala_contributor_laterite_blocks_reward_effect = {
	add_prestige = mandala_contribution_medium_prestige_reward
	add_piety_experience = medium_piety_value
}
contributed_laterite_blocks_effect = {
	custom_description_no_bullet = { text = contributed_laterite_blocks }
	mandala_contributor_laterite_blocks_reward_effect = yes
}

mandala_contributor_timber_reward_effect = { add_prestige_experience = mandala_contribution_minor_prestige_reward }
contributed_timber_effect = {
	custom_description_no_bullet = { text = contributed_timber }
	mandala_contributor_timber_reward_effect = yes
}

mandala_contributor_work_force_reward_effect = { 
	add_character_modifier = { 
		modifier = mandala_strong_workers_modifier
		years = 15
	}
}
contributed_work_force_effect = {
	custom_description_no_bullet = { text = contributed_work_force }
	mandala_contributor_work_force_reward_effect = yes
}

mandala_contributor_woodcarvings_reward_effect = { 
	add_legitimacy = {
		value = {
			add = mandala_contribution_minor_legitimacy_reward 
			multiply = 1.5
			#Rounds up to the closest number divisible by 5
			divide = 5
			ceiling = yes
			multiply = 5
		}
	}
}
contributed_woodcarvings_effect = {
	custom_description_no_bullet = { text = contributed_woodcarvings }
	mandala_contributor_woodcarvings_reward_effect = yes
}

mandala_contributor_sanctified_domes_reward_effect = {
	custom_tooltip = mandala_contributor_sanctified_domes_reward_effect_tt
	if = {
		limit = { this != scope:owner }
		add_prestige = {
			value = {
				add = mandala_contribution_medium_prestige_reward
				multiply = 1.5
				#Rounds up to the closest number divisible by 5
				divide = 5
				ceiling = yes
				multiply = 5
			}
		}	
	}
	hidden_effect = {
		scope:owner.dynasty = {
			add_dynasty_modifier = { modifier = mandala_sanctified_domes_dynasty_modifier }
		}
	}
}
contributed_sanctified_domes_effect = {
	custom_description_no_bullet = { text = contributed_sanctified_domes }
	mandala_contributor_sanctified_domes_reward_effect = yes
}

mandala_contributor_ornate_reliefs_reward_effect = {
	if = {
		limit = { this = scope:owner }
		if = {
			limit = { exists = scope:province }
			scope:province = {
				add_province_modifier = { modifier = mandala_ornate_reliefs_tax_province_modifier }
			}
		}
		else = {
			scope:owner.capital_province = {
				add_province_modifier = { modifier = mandala_ornate_reliefs_tax_province_modifier }
			}
		}
	}
	else = {
		add_character_modifier = {
			modifier = mandala_ornate_reliefs_tax_modifier
			years = 10
		}
	}
}
contributed_ornate_reliefs_effect = {
	custom_description_no_bullet = { text = contributed_ornate_reliefs }
	mandala_contributor_ornate_reliefs_reward_effect = yes
}

mandala_contributor_family_shrine_reward_effect = {
	dynasty ?= { add_dynasty_prestige = medium_dynasty_prestige_value }
	player_heir ?= { add_piety_experience = medium_piety_value }
}
contributed_family_shrine_effect = {
	custom_description_no_bullet = { text = contributed_family_shrine }
	mandala_contributor_family_shrine_reward_effect = yes
}

#The actual effect
check_and_reward_contributions_01_effect = {
	if = {
		limit = { scope:contributed_rite_of_worthiness ?= root }
		contributed_rites_of_worthiness_effect = yes	
	}
	if = {
		limit = { scope:contributed_slabs_of_sandstone ?= root }
		contributed_slabs_of_sandstone_effect = yes	
	}
	if = {
		limit = { scope:contributed_laterite_blocks ?= root }
		contributed_laterite_blocks_effect = yes	
	}
	if = {
		limit = { scope:contributed_timber ?= root }
		contributed_timber_effect = yes	
	}
	if = {
		limit = { scope:contributed_work_force ?= root }
		contributed_work_force_effect = yes	
	}
	if = {
		limit = { scope:contributed_woodcarvings ?= root }
		contributed_woodcarvings_effect = yes	
	}
	if = {
		limit = { scope:contributed_sanctified_domes ?= root }
		contributed_sanctified_domes_effect = yes	
	}
	if = {
		limit = { scope:contributed_ornate_reliefs ?= root }
		contributed_ornate_reliefs_effect = yes	
	}
	if = {
		limit = { scope:contributed_family_shrine ?= root }
		contributed_family_shrine_effect = yes	
	}
}


### Capital 02 Breakdown Effects ###

#mandala_contributor_minor_rite_reward_effect Reused from Capital 01
#contributed_rites_of_worthiness_effect Reused from Capital 01

mandala_contributor_brick_reward_effect = { add_prestige = mandala_contribution_major_prestige_reward }
contributed_brick_effect = {
	custom_description_no_bullet = { text = contributed_brick }
	mandala_contributor_brick_reward_effect = yes
}

mandala_contributor_tiles_reward_effect = { 
	add_prestige = {
		value = {
			add = mandala_contribution_medium_prestige_reward
			multiply = 1.5
			#Rounds up to the closest number divisible by 5
			divide = 5
			ceiling = yes
			multiply = 5
		}
	}
	add_piety_experience = mandala_contribution_medium_dynasty_reward
}
contributed_tiles_effect = {
	custom_description_no_bullet = { text = contributed_tiles }
	mandala_contributor_tiles_reward_effect = yes
}

mandala_contributor_shallow_pools_reward_effect = { 
	if = {
		limit = { this != scope:owner }
		add_prestige = {
			value = {
				add = mandala_contribution_medium_prestige_reward
				multiply = 1.5
			}
		}	
	}
	if = {
		limit = { exists = scope:province }
		custom_tooltip = mandala_contributor_shallow_pools_reward_province_effect_tt
		hidden_effect = {
			scope:province = {
				add_province_modifier = { modifier = mandala_shallow_pools_defense_modifier }
			}
		}
	}
	else = {
		custom_tooltip = mandala_contributor_shallow_pools_reward_effect_tt
		hidden_effect = {
			scope:owner.capital_province = {
				add_province_modifier = { modifier = mandala_shallow_pools_defense_modifier }
			}
		}	
	}
}
contributed_shallow_pools_effect = {
	custom_description_no_bullet = { text = contributed_shallow_pools }
	mandala_contributor_shallow_pools_reward_effect = yes
}

#mandala_contributor_work_force_reward_effect Reused from Capital 01
#contributed_work_force_effect Reused from Capital 01

mandala_contributor_decorative_tiles_reward_effect = {
	add_legitimacy = {
		value = {
			add = mandala_contribution_minor_legitimacy_reward 
			multiply = 1.5
			#Rounds up to the closest number divisible by 5
			divide = 5
			ceiling = yes
			multiply = 5
		}
	}
}
contributed_decorative_tiles_effect = {
	custom_description_no_bullet = { text = contributed_decorative_tiles }
	mandala_contributor_decorative_tiles_reward_effect = yes
}

mandala_contributor_decorated_domes_reward_effect = {
	if = {
		limit = { this != scope:owner }
		add_prestige = mandala_contribution_major_prestige_reward
	}
	scope:owner.dynasty = {
		if = {
			limit = { has_dynasty_modifier = mandala_sanctified_domes_dynasty_modifier }
			scope:owner = { custom_tooltip = mandala_contributor_decorated_domes_reward_effect_tt_replaced }
			hidden_effect = {
				remove_dynasty_modifier = mandala_sanctified_domes_dynasty_modifier
				add_dynasty_modifier = { modifier = mandala_decorated_domes_dynasty_modifier }
			}
		}
		else = {
			scope:owner = { custom_tooltip = mandala_contributor_decorated_domes_reward_effect_tt }
			hidden_effect = {
				add_dynasty_modifier = { modifier = mandala_decorated_domes_dynasty_modifier }
			}
		}
	}	
}
contributed_decorated_domes_effect = {
	custom_description_no_bullet = { text = contributed_decorated_domes }
	mandala_contributor_decorated_domes_reward_effect = yes
}

mandala_contributor_family_statues_reward_effect = { 
	dynasty ?= { add_dynasty_prestige = major_dynasty_prestige_value }
	player_heir ?= {
		add_piety_experience = major_piety_value
	}
}
contributed_family_statues_effect = {
	custom_description_no_bullet = { text = contributed_family_statues }
	mandala_contributor_family_statues_reward_effect = yes
}

#The actual effect
check_and_reward_contributions_02_effect = {
	if = {
		limit = { scope:contributed_rite_of_worthiness ?= root }
		contributed_rites_of_worthiness_effect = yes	
	}
	if = {
		limit = { scope:contributed_brick ?= root }
		contributed_brick_effect = yes	
	}
	if = {
		limit = { scope:contributed_tiles ?= root }
		contributed_tiles_effect = yes	
	}
	if = {
		limit = { scope:contributed_shallow_pools ?= root }
		contributed_shallow_pools_effect = yes	
	}
	if = {
		limit = { scope:contributed_work_force ?= root }
		contributed_work_force_effect = yes	
	}
	if = {
		limit = { scope:contributed_decorative_tiles ?= root }
		contributed_decorative_tiles_effect = yes	
	}
	if = {
		limit = { scope:contributed_decorated_domes ?= root }
		contributed_decorated_domes_effect = yes	
	}
	if = {
		limit = { scope:contributed_family_statues ?= root }
		contributed_family_statues_effect = yes	
	}
}


### Capital 03 Breakdown Effects ###
mandala_contributor_medium_rite_reward_effect = {
	add_legitimacy = mandala_contribution_medium_legitimacy_reward
	add_piety_experience = mandala_contribution_major_dynasty_reward
}
contributed_rites_of_worthiness_02_effect = {
	custom_description_no_bullet = { text = contributed_rite_of_worthiness }
	mandala_contributor_medium_rite_reward_effect = yes
}

mandala_contributor_volcanic_stone_reward_effect = { 
	add_prestige = {
		value = {
			add = mandala_contribution_major_prestige_reward
			multiply = 1.25
			#Rounds up to the closest number divisible by 5
			divide = 5
			ceiling = yes
			multiply = 5
		}
	}
}
contributed_volcanic_stone_effect = {
	custom_description_no_bullet = { text = contributed_volcanic_stone }
	mandala_contributor_volcanic_stone_reward_effect = yes
}

mandala_contributor_corbel_gateways_reward_effect = { 
	add_prestige = {
		value = {
			add = mandala_contribution_medium_prestige_reward
			multiply = 1.75
			#Rounds up to the closest number divisible by 5
			divide = 5
			ceiling = yes
			multiply = 5
		}
	}
	add_piety_experience = {
		value = {
			add = mandala_contribution_medium_dynasty_reward
			multiply = 1.75
			#Rounds up to the closest number divisible by 5
			divide = 5
			ceiling = yes
			multiply = 5
		}
	}
}
contributed_corbel_gateways_effect = {
	custom_description_no_bullet = { text = contributed_corbel_gateways }
	mandala_contributor_corbel_gateways_reward_effect = yes
}

mandala_contributor_divine_statues_reward_effect = { 
	if = {
		limit = { this != scope:owner }
		add_prestige = {
			value = {
				add = mandala_contribution_medium_prestige_reward
				multiply = 1.5
			}
		}
		add_piety_experience = mandala_contribution_medium_dynasty_reward
	}
	if = {
		limit = { exists = scope:province }
		custom_tooltip = mandala_contributor_divine_statues_reward_province_effect_tt
		hidden_effect = {
			scope:province = {
				add_province_modifier = { modifier = mandala_divine_statues_province_modifier }
			}
		}
	}
	else = {
		custom_tooltip = mandala_contributor_divine_statues_reward_effect_tt
		hidden_effect = {
			scope:owner.capital_province = {
				add_province_modifier = { modifier = mandala_divine_statues_province_modifier }
			}
		}	
	}
}
contributed_divine_statues_effect = {
	custom_description_no_bullet = { text = contributed_divine_statues }
	mandala_contributor_divine_statues_reward_effect = yes
}

#mandala_contributor_work_force_reward_effect Reused from Capital 01
#contributed_work_force_effect Reused from Capital 01

mandala_contributor_creation_aspect_reward_effect = {
	add_stewardship_skill = 1
	if = {
		limit = { exists = scope:province }
		custom_tooltip = mandala_contributor_creation_aspect_statues_reward_province_effect_tt
		hidden_effect = {
			scope:province = {
				add_province_modifier = { modifier = mandala_creation_aspect_statues_modifier }
			}
		}
	}
	else = {
		custom_tooltip = mandala_contributor_creation_aspect_statues_reward_effect_tt
		hidden_effect = {
			scope:owner.capital_province = {
				add_province_modifier = { modifier = mandala_creation_aspect_statues_modifier }
			}
		}	
	}
}
contributed_creation_aspect_effect = {
	custom_description_no_bullet = { text = contributed_creation_aspect }
	mandala_contributor_creation_aspect_reward_effect = yes
}

mandala_contributor_serenity_aspect_reward_effect = { 
	add_diplomacy_skill = 1
	if = {
		limit = { exists = scope:province }
		custom_tooltip = mandala_contributor_serenity_aspect_statues_reward_province_effect_tt
		hidden_effect = {
			scope:province = {
				add_province_modifier = { modifier = mandala_serenity_aspect_statues_modifier }
			}
		}
	}
	else = {
		custom_tooltip = mandala_contributor_serenity_aspect_statues_reward_effect_tt
		hidden_effect = {
			scope:owner.capital_province = {
				add_province_modifier = { modifier = mandala_serenity_aspect_statues_modifier }
			}
		}	
	}
}
contributed_serenity_aspect_effect = {
	custom_description_no_bullet = { text = contributed_serenity_aspect }
	mandala_contributor_serenity_aspect_reward_effect = yes
}

mandala_contributor_destruction_aspect_reward_effect = {
	add_martial_skill = 1
	if = {
		limit = { exists = scope:province }
		custom_tooltip = mandala_contributor_destruction_aspect_statues_reward_province_effect_tt
		hidden_effect = {
			scope:province = {
				add_province_modifier = { modifier = mandala_destruction_aspect_statues_modifier }
			}
		}
	}
	else = {
		custom_tooltip = mandala_contributor_destruction_aspect_statues_reward_effect_tt
		hidden_effect = {
			scope:owner.capital_province = {
				add_province_modifier = { modifier = mandala_destruction_aspect_statues_modifier }
			}
		}	
	}
}
contributed_destruction_aspect_effect = {
	custom_description_no_bullet = { text = contributed_destruction_aspect }
	mandala_contributor_destruction_aspect_reward_effect = yes
}

mandala_contributor_trickery_aspect_reward_effect = { 
	add_intrigue_skill = 1
	if = {
		limit = { exists = scope:province }
		custom_tooltip = mandala_contributor_trickery_aspect_statues_reward_province_effect_tt
		hidden_effect = {
			scope:province = {
				add_province_modifier = { modifier = mandala_trickery_aspect_statues_modifier }
			}
		}
	}
	else = {
		custom_tooltip = mandala_contributor_trickery_aspect_statues_reward_effect_tt
		hidden_effect = {
			scope:owner.capital_province = {
				add_province_modifier = { modifier = mandala_trickery_aspect_statues_modifier }
			}
		}	
	}
}
contributed_trickery_aspect_effect = {
	custom_description_no_bullet = { text = contributed_trickery_aspect }
	mandala_contributor_trickery_aspect_reward_effect = yes
}

mandala_contributor_gilded_domes_reward_effect = {
	if = {
		limit = { this != scope:owner }
		add_prestige = mandala_contribution_major_prestige_reward
	}
	scope:owner.dynasty = {
		if = {
			limit = { has_dynasty_modifier = mandala_sanctified_domes_dynasty_modifier }
			scope:owner = { custom_tooltip = mandala_contributor_sanctified_gilded_domes_reward_effect_tt_replaced }
			hidden_effect = {
				remove_dynasty_modifier = mandala_sanctified_domes_dynasty_modifier
				add_dynasty_modifier = { modifier = mandala_gilded_domes_dynasty_modifier }
			}
		}
		else_if = {
			limit = { has_dynasty_modifier = mandala_decorated_domes_dynasty_modifier }
			scope:owner = { custom_tooltip = mandala_contributor_decorated_gilded_domes_reward_effect_tt_replaced }
			hidden_effect = {
				remove_dynasty_modifier = mandala_decorated_domes_dynasty_modifier
				add_dynasty_modifier = { modifier = mandala_gilded_domes_dynasty_modifier }
			}
		}
		else = {
			scope:owner = { custom_tooltip = mandala_contributor_gilded_domes_reward_effect_tt }
			hidden_effect = {
				add_dynasty_modifier = { modifier = mandala_gilded_domes_dynasty_modifier }
			}
		}
	}
}
contributed_gilded_domes_effect = {
	custom_description_no_bullet = { text = contributed_gilded_domes }
	mandala_contributor_gilded_domes_reward_effect = yes
}

mandala_contributor_family_temple_compound_reward_effect = { 
	dynasty ?= { add_dynasty_prestige = major_dynasty_prestige_value }
	player_heir ?= {
		add_piety_experience = massive_piety_value
	}
}
contributed_family_temple_compound_effect = {
	custom_description_no_bullet = { text = contributed_family_temple_compound }
	mandala_contributor_family_temple_compound_reward_effect = yes
}

#The actual effect
check_and_reward_contributions_03_effect = {
	if = {
		limit = { scope:contributed_rite_of_worthiness ?= root }
		contributed_rites_of_worthiness_02_effect = yes	
	}
	if = {
		limit = { scope:contributed_volcanic_stone ?= root }
		contributed_volcanic_stone_effect = yes	
	}
	if = {
		limit = { scope:contributed_corbel_gateways ?= root }
		contributed_corbel_gateways_effect = yes	
	}
	if = {
		limit = { scope:contributed_divine_statues ?= root }
		contributed_divine_statues_effect = yes	
	}
	if = {
		limit = { scope:contributed_work_force ?= root }
		contributed_work_force_effect = yes	
	}
	if = {
		limit = { scope:contributed_creation_aspect ?= root }
		contributed_creation_aspect_effect = yes	
	}
	if = {
		limit = { scope:contributed_serenity_aspect ?= root }
		contributed_serenity_aspect_effect = yes	
	}
	if = {
		limit = { scope:contributed_destruction_aspect ?= root }
		contributed_destruction_aspect_effect = yes	
	}
	if = {
		limit = { scope:contributed_trickery_aspect ?= root }
		contributed_trickery_aspect_effect = yes	
	}
	if = {
		limit = { scope:contributed_gilded_domes ?= root }
		contributed_gilded_domes_effect = yes	
	}
	if = {
		limit = { scope:contributed_family_temple_compound ?= root }
		contributed_family_temple_compound_effect = yes	
	}
}


### Capital 04 Breakdown Effects ###

#mandala_contributor_medium_rite_reward_effect Reused from Capital 03
#contributed_rites_of_worthiness_02_effect Reused from Capital 03

mandala_contributor_slabs_of_granite_reward_effect = { 
	add_prestige = {
		value = {
			add = mandala_contribution_major_prestige_reward
			multiply = 1.25
			#Rounds up to the closest number divisible by 5
			divide = 5
			ceiling = yes
			multiply = 5
		}
	}
}
contributed_slabs_of_granite_effect = {
	custom_description_no_bullet = { text = contributed_slabs_of_granite }
	mandala_contributor_slabs_of_granite_reward_effect = yes
}

mandala_contributor_zaungdans_reward_effect = { 
	add_prestige = {
		value = {
			add = mandala_contribution_medium_prestige_reward
			multiply = 1.75
			#Rounds up to the closest number divisible by 5
			divide = 5
			ceiling = yes
			multiply = 5
		}
	}
	add_piety_experience = {
		value = {
			add = mandala_contribution_medium_dynasty_reward
			multiply = 1.75
			#Rounds up to the closest number divisible by 5
			divide = 5
			ceiling = yes
			multiply = 5
		}
	}
}
contributed_zaungdans_effect = {
	custom_description_no_bullet = { text = contributed_zaungdans }
	mandala_contributor_zaungdans_reward_effect = yes
}

mandala_contributor_gilded_shrines_reward_effect = { 
	if = {
		limit = { this != scope:owner }
		add_prestige = {
			value = {
				add = mandala_contribution_medium_prestige_reward
				multiply = 1.5
			}
		}
		add_piety_experience = mandala_contribution_medium_dynasty_reward
	}
	if = {
		limit = { exists = scope:province }
		custom_tooltip = mandala_contributor_gilded_shrines_reward_province_effect_tt
		hidden_effect = {
			scope:province = {
				add_province_modifier = { modifier = mandala_gilded_shrines_province_modifier }
			}
		}
	}
	else = {
		custom_tooltip = mandala_contributor_gilded_shrines_reward_effect_tt
		hidden_effect = {
			scope:owner.capital_province = {
				add_province_modifier = { modifier = mandala_gilded_shrines_province_modifier }
			}
		}	
	}
}
contributed_gilded_shrines_effect = {
	custom_description_no_bullet = { text = contributed_gilded_shrines }
	mandala_contributor_gilded_shrines_reward_effect = yes
}

#mandala_contributor_work_force_reward_effect Reused from Capital 01
#contributed_work_force_effect Reused from Capital 01

mandala_contributor_bell_stupas_reward_effect = { 
	add_character_modifier = { modifier = mandala_bell_stupas_modifier }
}
contributed_bell_stupas_effect = {
	custom_description_no_bullet = { text = contributed_bell_stupas }
	mandala_contributor_bell_stupas_reward_effect = yes
}

mandala_contributor_bejeweled_domes_reward_effect = { 
	if = {
		limit = { this != scope:owner }
		add_prestige = mandala_contribution_major_prestige_reward
	}
	scope:owner.dynasty = {
		if = {
			limit = { has_dynasty_modifier = mandala_sanctified_domes_dynasty_modifier }
			scope:owner = { custom_tooltip = mandala_contributor_sanctified_bejeweled_domes_reward_effect_tt_replaced }
			hidden_effect = {
				remove_dynasty_modifier = mandala_sanctified_domes_dynasty_modifier
				add_dynasty_modifier = { modifier = mandala_bejeweled_domes_dynasty_modifier }
			}
		}
		else_if = {
			limit = { has_dynasty_modifier = mandala_decorated_domes_dynasty_modifier }
			scope:owner = { custom_tooltip = mandala_contributor_decorated_bejeweled_domes_reward_effect_tt_replaced }
			hidden_effect = {
				remove_dynasty_modifier = mandala_decorated_domes_dynasty_modifier
				add_dynasty_modifier = { modifier = mandala_bejeweled_domes_dynasty_modifier }
			}
		}
		else_if = {
			limit = { has_dynasty_modifier = mandala_gilded_domes_dynasty_modifier }
			scope:owner = { custom_tooltip = mandala_contributor_gilded_bejeweled_domes_reward_effect_tt_replaced }
			hidden_effect = {
				remove_dynasty_modifier = mandala_gilded_domes_dynasty_modifier
				add_dynasty_modifier = { modifier = mandala_bejeweled_domes_dynasty_modifier }
			}
		}
		else = {
			scope:owner = { custom_tooltip = mandala_contributor_bejeweled_domes_reward_effect_tt }
			hidden_effect = {
				add_dynasty_modifier = { modifier = mandala_bejeweled_domes_dynasty_modifier }
			}
		}
	}
}
contributed_bejeweled_domes_effect = {
	custom_description_no_bullet = { text = contributed_bejeweled_domes }
	mandala_contributor_bejeweled_domes_reward_effect = yes
}

mandala_contributor_family_temple_complex_reward_effect = { 
	dynasty = { add_dynasty_prestige = monumental_dynasty_prestige_value }
	player_heir ?= {
		add_piety_experience = monumental_piety_value
	}
}
contributed_family_temple_complex_effect = {
	custom_description_no_bullet = { text = contributed_family_temple_complex }
	mandala_contributor_family_temple_complex_reward_effect = yes
}


#The actual effect
check_and_reward_contributions_04_effect = {
	if = {
		limit = { scope:contributed_rite_of_worthiness ?= root }
		contributed_rites_of_worthiness_02_effect = yes	
	}
	if = {
		limit = { scope:contributed_slabs_of_granite ?= root }
		contributed_slabs_of_granite_effect = yes	
	}
	if = {
		limit = { scope:contributed_zaungdans ?= root }
		contributed_zaungdans_effect = yes	
	}
	if = {
		limit = { scope:contributed_gilded_shrines ?= root }
		contributed_gilded_shrines_effect = yes	
	}
	if = {
		limit = { scope:contributed_work_force ?= root }
		contributed_work_force_effect = yes	
	}
	if = {
		limit = { scope:contributed_bell_stupas ?= root }
		contributed_bell_stupas_effect = yes	
	}
	if = {
		limit = { scope:contributed_bejeweled_domes ?= root }
		contributed_bejeweled_domes_effect = yes	
	}
	if = {
		limit = { scope:contributed_family_temple_complex ?= root }
		contributed_family_temple_complex_effect = yes	
	}
}


### Capital 05 Breakdown Effects ###

#mandala_contributor_medium_rite_reward_effect Reused from Capital 03
#contributed_rites_of_worthiness_02_effect Reused from Capital 03

mandala_contributor_marble_foundation_reward_effect = { 
	add_prestige = {
		value = {
			add = mandala_contribution_major_prestige_reward
			multiply = 1.5
			#Rounds up to the closest number divisible by 5
			divide = 5
			ceiling = yes
			multiply = 5
		}
	}
	add_piety_experience = {
		value = {
			add = mandala_contribution_medium_dynasty_reward
			multiply = 1.5
			#Rounds up to the closest number divisible by 5
			divide = 5
			ceiling = yes
			multiply = 5
		}
	}
	add_legitimacy = mandala_contribution_medium_legitimacy_reward
}
contributed_marble_foundation_effect = {
	custom_description_no_bullet = { text = contributed_marble_foundation }
	mandala_contributor_marble_foundation_reward_effect = yes
}

mandala_contributor_divine_barays_reward_effect = { 
	if = {
		limit = { this != scope:owner }
		add_prestige = {
			value = {
				add = mandala_contribution_medium_prestige_reward
				multiply = 1.5
			}
		}	
	}
	if = {
		limit = { exists = scope:province }
		custom_tooltip = mandala_contributor_divine_barays_reward_province_effect_tt
		hidden_effect = {
			scope:province = {
				add_province_modifier = { modifier = mandala_divine_barays_defense_modifier }
			}
		}
	}
	else = {
		custom_tooltip = mandala_contributor_divine_barays_reward_effect_tt
		hidden_effect = {
			scope:owner.capital_province = {
				add_province_modifier = { modifier = mandala_divine_barays_defense_modifier }
			}
		}	
	}
}
contributed_divine_barays_effect = {
	custom_description_no_bullet = { text = contributed_divine_barays }
	mandala_contributor_divine_barays_reward_effect = yes
}

#mandala_contributor_work_force_reward_effect Reused from Capital 01
#contributed_work_force_effect Reused from Capital 01

mandala_contributor_bejeweled_reliefs_reward_effect = {
	#Before Planning has started
	if = {
		limit = {
			scope:owner ?= {
				any_character_artifact = { has_variable = mandala_capital_05_unconfirmed_talisman }
			}
		}
		scope:owner = {
			random_character_artifact = {
				limit = { has_variable = mandala_capital_05_unconfirmed_talisman }
				save_scope_as = target_talisman
			}
		}
		if = {
			limit = {
				scope:owner = { 
					house ?= { has_house_aspiration_parameter = aspect_of_creation }
				}
			}
			custom_tooltip = mandala_contributor_bejeweled_reliefs_creator_reward_artifact_effect_tt
			#Set the modifiers
			hidden_effect = {
				scope:target_talisman = {
					set_artifact_description = mandala_capital_05_creation_talisman_desc
					add_artifact_modifier = artifact_health_gain_2_modifier
					add_artifact_modifier = artifact_fertility_gain_2_modifier
				}
			}
		}
		else_if = {
			limit = {
				scope:owner = { 
					house ?= { has_house_aspiration_parameter = aspect_of_serenity }
				}
			}
			custom_tooltip = mandala_contributor_bejeweled_reliefs_serenity_reward_artifact_effect_tt
			#Set the modifiers
			hidden_effect = {
				scope:target_talisman = { 
					set_artifact_description = mandala_capital_05_serenity_talisman_desc
					add_artifact_modifier = artifact_vassal_limit_1_modifier
					add_artifact_modifier = artifact_short_reign_duration_mult_3_modifier
				}
			}
		}
		else_if = {
			limit = {
				scope:owner = { 
					house ?= { has_house_aspiration_parameter = aspect_of_destruction }
				}
			}
			custom_tooltip = mandala_contributor_bejeweled_reliefs_destruction_reward_artifact_effect_tt
			#Set the modifiers
			hidden_effect = {
				scope:target_talisman = {
					set_artifact_description = mandala_capital_05_destruction_talisman_desc
					add_artifact_modifier = artifact_dread_baseline_add_2_modifier
					add_artifact_modifier = artifact_pursue_efficiency_2_modifier
					add_artifact_modifier = artifact_controlled_province_advantage_5_modifier
				}
			}
		}
		else_if = {
			limit = {
				scope:owner = { 
					house ?= { has_house_aspiration_parameter = aspect_of_trickery }
				}
			}
			custom_tooltip = mandala_contributor_bejeweled_reliefs_trickery_reward_artifact_effect_tt
			#Set the modifiers
			hidden_effect = {
				scope:target_talisman = {
					set_artifact_description = mandala_capital_05_trickery_talisman_desc
					add_artifact_modifier = artifact_negate_health_penalty_add_2_modifier
					add_artifact_modifier = artifact_scheme_resistance_add_3_modifier
				}
			}
		}
		scope:target_talisman = { 
			remove_variable = mandala_capital_05_unconfirmed_talisman
			set_variable = mandala_capital_05_talisman
			if = {
				limit = { has_variable = mandala_capital_05_talisman }
				#To prevent 'unused except in loc' errors :catto:
			}
			hidden_effect = {
				set_artifact_rarity = famed
				remove_artifact_modifier = artifact_monthly_piety_gain_mult_1_modifier
				add_artifact_modifier = artifact_monthly_piety_gain_mult_5_modifier
			}
		}
	}
	#After planning has started
	else_if = {
		limit = { 
			this = { 
				house ?= { has_house_aspiration_parameter = aspect_of_creation }
			}
		}
		custom_tooltip = mandala_contributor_bejeweled_reliefs_creator_reward_pre_artifact_effect_tt
	}
	else_if = {
		limit = {
			this = { 
				house ?= { has_house_aspiration_parameter = aspect_of_serenity }
			}
		}
		custom_tooltip = mandala_contributor_bejeweled_reliefs_serenity_reward_pre_artifact_effect_tt
	}
	else_if = {
		limit = {
			this = { 
				house ?= { has_house_aspiration_parameter = aspect_of_destruction }
			}
		}
		custom_tooltip = mandala_contributor_bejeweled_reliefs_destruction_reward_pre_artifact_effect_tt
	}
	else_if = {
		limit = {
			this = { 
				house ?= { has_house_aspiration_parameter = aspect_of_trickery }
			}
		}
		custom_tooltip = mandala_contributor_bejeweled_reliefs_trickery_reward_pre_artifact_effect_tt
	}
	else = { custom_tooltip = mandala_contributor_bejeweled_reliefs_reward_artifact_effect_none_tt }
	
	#And set the owner, if the project owner neglected to do this Contribution
	if = {
		limit = {
			NOT = { this = scope:owner }
			exists = scope:target_talisman
		}
		if = {
			limit = { exists = scope:target_talisman }
			scope:target_talisman = { set_owner = prev }
		}
		else = { custom_tooltip = mandala_contributor_bejeweled_reliefs_reward_gain_artifact_effect_tt }
	}
	
}
contributed_bejeweled_reliefs_effect = {
	custom_description_no_bullet = { text = contributed_bejeweled_reliefs }
	mandala_contributor_bejeweled_reliefs_reward_effect = yes
}

mandala_contributor_bunga_mas_forest_reward_effect = { 
	if = {
		limit = { this != scope:owner }
		add_prestige_experience = mandala_contribution_major_prestige_reward
		if = {
			limit = { 
				can_add_hook = {
					target = scope:owner
					type = strong_contribution_hook
				}
			}
			add_hook = {
				target = scope:owner
				type = strong_contribution_hook
			}
		}
	}
	custom_tooltip = mandala_contributor_bunga_mas_forest_reward_effect_tt
	hidden_effect = {
		scope:owner.dynasty = {
			add_dynasty_modifier = { modifier = mandala_forest_of_bunga_mas_modifier }
		}
	}
}
contributed_bunga_mas_forest_effect = {
	custom_description_no_bullet = { text = contributed_bunga_mas_forest }
	mandala_contributor_bunga_mas_forest_reward_effect = yes
}

mandala_contributor_dynastic_temple_complex_reward_effect = { 
	dynasty = { add_dynasty_prestige = monumental_dynasty_prestige_value }
	player_heir ?= {
		add_piety_experience = {
			value = monumental_piety_value
			add = massive_piety_value
		}
	}
}
contributed_dynastic_temple_complex_effect = {
	custom_description_no_bullet = { text = contributed_family_temple_complex }
	mandala_contributor_family_temple_complex_reward_effect = yes
}

#The actual effect
check_and_reward_contributions_05_effect = {
	if = {
		limit = { scope:contributed_rite_of_worthiness ?= root }
		contributed_rites_of_worthiness_02_effect = yes	
	}
	if = {
		limit = { scope:contributed_marble_foundation ?= root }
		contributed_marble_foundation_effect = yes	
	}
	if = {
		limit = { scope:contributed_divine_barays ?= root }
		contributed_divine_barays_effect = yes	
	}
	if = {
		limit = { scope:contributed_work_force ?= root }
		contributed_work_force_effect = yes	
	}
	if = {
		limit = { scope:contributed_bejeweled_reliefs ?= root }
		contributed_bejeweled_reliefs_effect = yes	
	}
	if = {
		limit = { scope:contributed_bunga_mas_forest ?= root }
		contributed_bunga_mas_forest_effect = yes	
	}
	if = {
		limit = { scope:contributed_dynastic_temple_complex ?= root }
		contributed_dynastic_temple_complex_effect = yes	
	}
}





##War Effects
mandala_war_victory_effects = {
	scope:attacker = {
		if = {
			limit = { has_realm_law_flag = piety_devotion_from_offensive_wars }
			add_piety = {
				value = medium_piety_value
				multiply = scope:defender.primary_title.tier
			}
		}
	}
	scope:defender = {
		if = {
			limit = { has_realm_law_flag = piety_devotion_from_defensive_wars }
			add_piety_experience = medium_piety_loss
		}
	}	
}

mandala_war_defeat_effects = {
	scope:attacker = {
		if = {
			limit = { has_realm_law_flag = piety_devotion_from_offensive_wars }
			add_piety_experience = medium_piety_loss
		}
	}
	scope:defender = {
		if = {
			limit = { has_realm_law_flag = piety_devotion_from_defensive_wars }
			add_piety_experience = {
				value = minor_piety_value
				multiply = scope:defender.primary_title.tier
			}
		}
	}	
}

mandala_rebel_attacker_independency_effect = {
	create_title_and_vassal_change = {
		type = independency
		save_scope_as = change
	}
	becomes_independent = { change = scope:change }
	resolve_title_and_vassal_change = scope:change
}

mandala_not_quite_depose_effect = {
	#Your piety
	add_piety_level = remove_piety_levels_value
	add_piety = -5000
	#Your tributaries
	if = {
		limit = { number_of_tributaries > 0 }
		custom_tooltip = {
			text = mandala_depose_war_leaving_tributaries.tt
			every_tributary = { end_tributary = yes }
		}
	}
	#Your radiance
	add_character_modifier = {
		modifier = recently_tarnished_mandala_modifier
		years = 10
	}
}

mandala_peacemaker_perk_serenity_effect = {
	if = {
		limit = {
			government_has_flag = government_is_mandala
			house ?= { has_house_aspiration_parameter = aspect_of_serenity }
			is_house_head = yes
			has_perk = peacemaker_perk
		}
		add_piety_experience = mandala_peacemaker_perk_piety_value
	}
}


##Change to Mandala Government effects
change_to_mandala_government_effect = {
	change_government = mandala_government
	change_to_mandala_government_decree_effect = yes
	save_scope_as = root_scope
	primary_title.title_province = {
		if = {
			limit = { geographical_region = geographical_region:mpo_region_permafrost }
			scope:root_scope = {
				every_realm_county = {
					if = {
						limit = { has_county_modifier = mpo_siberian_permafrost_modifier }
						remove_county_modifier = mpo_siberian_permafrost_modifier
					}
					else_if = {
						limit = { has_county_modifier = mpo_siberian_permafrost_modifier_bad }
						remove_county_modifier = mpo_siberian_permafrost_modifier_bad
					}
				}
			}
		}
	}
}

change_to_mandala_government_and_citadel_effect = {
	if = {
		limit = { government_has_flag = government_is_tribal }
		change_tribal_holdings_to_citadels_effect = yes #Includes change_to_mandala_government_effect
	}
	else = {
		change_capital_holding_to_citadel_effect = yes #Includes change_to_mandala_government_effect
	}
	show_as_tooltip = { change_to_mandala_government_effect = yes }
}

change_capital_holding_to_citadel_effect = {
	custom_tooltip = realm_capital_will_change_to_citadel
	save_scope_as = current_holder
	hidden_effect_new_object = {
		capital_province = {
			if = {
				limit = { has_holding_type = temple_citadel_holding }
				scope:current_holder = {
					if = {
						limit = {
							NOT = { government_has_flag = government_is_mandala }
						}
						change_to_mandala_government_effect = yes
					}
				}
			}
			else = {
				set_variable = {
					name = generic_to_mandala_building_level
					value = combined_building_level
					days = 1
				}
				set_holding_type = temple_citadel_holding
				#Did any buildings invalidate? Calculate!
				set_variable = {
					name = new_generic_to_mandala_building_level
					value = combined_building_level
					days = 1
				}
				if = {
					limit = { var:new_generic_to_mandala_building_level < var:generic_to_mandala_building_level }
					change_variable = {
						name = generic_to_mandala_building_level
						subtract = var:new_generic_to_mandala_building_level
					}
				}
				#We need to set the holding type BEFORE we can change to the government, lest it invalidates
				scope:current_holder = {
					if = {
						limit = {
							NOT = { government_has_flag = government_is_mandala }
						}
						change_to_mandala_government_effect = yes
					}
				}
				#We need to set the government type BEFORE we generate buildings, otherwise basically none are valid
				while = {
					limit = { var:generic_to_mandala_building_level > 0 }
					generate_building = yes
					change_variable = {
						name = generic_to_mandala_building_level
						subtract = 1
					}
				}
				remove_variable = generic_to_mandala_building_level
				remove_variable = new_generic_to_mandala_building_level
			}
		}
	}
}

change_tribal_holdings_to_citadels_effect = {
	custom_tooltip = all_tribal_holdings_will_change_to_citadels
	save_scope_as = current_tribal_holder
	if = {
		limit = {
			any_directly_owned_province = {
				has_holding_type = tribal_holding
				count >= 1
			}
		}
		hidden_effect_new_object = {
			every_directly_owned_province = {
				limit = { has_holding_type = tribal_holding }
				set_variable = {
					name = tribal_to_mandala_building_level
					value = combined_building_level
					days = 1
				}
				set_holding_type = temple_citadel_holding
				#We need to set the holding type BEFORE we can change to the government, lest it invalidates
				scope:current_tribal_holder = {
					if = {
						limit = {
							NOT = { government_has_flag = government_is_mandala }
						}
						change_to_mandala_government_effect = yes
					}
				}	
				#We need to set the government type BEFORE we generate buildings, otherwise basically none are valid
				while = {
					limit = { var:tribal_to_mandala_building_level > 0 }
					generate_building = yes
					change_variable = {
						name = tribal_to_mandala_building_level
						subtract = 1
					}
				}
				remove_variable = tribal_to_mandala_building_level
			}
		}
	}
	#You're somehow a tribal with all your holdings being Temple Citadels? Good for you.
	else = {
		scope:current_tribal_holder = {
			if = {
				limit = {
					NOT = { government_has_flag = government_is_mandala }
				}
				change_to_mandala_government_effect = yes
			}
		}
	}	
}

mandala_nuke_realm_laws_effect = {
	hidden_effect = {
		#Tribal
		if = {
			limit = { has_realm_law = tribal_authority_0 }
			remove_realm_law = tribal_authority_0
		}
		if = {
			limit = { has_realm_law = tribal_authority_1 }
			remove_realm_law = tribal_authority_1
		}
		if = {
			limit = { has_realm_law = tribal_authority_2 }
			remove_realm_law = tribal_authority_2
		}
		if = {
			limit = { has_realm_law = tribal_authority_3 }
			remove_realm_law = tribal_authority_3
		}
		#Feudal
		if = {
			limit = { has_realm_law = crown_authority_0 }
			remove_realm_law = crown_authority_0
		}
		if = {
			limit = { has_realm_law = crown_authority_1 }
			remove_realm_law = crown_authority_1
		}
		if = {
			limit = { has_realm_law = crown_authority_2 }
			remove_realm_law = crown_authority_2
		}
		if = {
			limit = { has_realm_law = crown_authority_3 }
			remove_realm_law = crown_authority_3
		}
		#Admin
		if = {
			limit = { has_realm_law = imperial_bureaucracy_0 }
			remove_realm_law = imperial_bureaucracy_0
		}
		if = {
			limit = { has_realm_law = imperial_bureaucracy_1 }
			remove_realm_law = imperial_bureaucracy_1
		}
		if = {
			limit = { has_realm_law = imperial_bureaucracy_2 }
			remove_realm_law = imperial_bureaucracy_2
		}
		if = {
			limit = { has_realm_law = imperial_bureaucracy_3 }
			remove_realm_law = imperial_bureaucracy_3
		}
		#Nomads
		if = {
			limit = { has_realm_law = nomadic_authority_1 }
			remove_realm_law = nomadic_authority_1
		}
		if = {
			limit = { has_realm_law = nomadic_authority_2 }
			remove_realm_law = nomadic_authority_2
		}
		if = {
			limit = { has_realm_law = nomadic_authority_3 }
			remove_realm_law = nomadic_authority_3
		}
		if = {
			limit = { has_realm_law = nomadic_authority_4 }
			remove_realm_law = nomadic_authority_4
		}
		if = {
			limit = { has_realm_law = nomadic_authority_5 }
			remove_realm_law = nomadic_authority_5
		}
		#Celestial
		if = {
			limit = { has_realm_law = celestial_bureaucracy_0 }
			remove_realm_law = celestial_bureaucracy_0
		}
		if = {
			limit = { has_realm_law = celestial_bureaucracy_1 }
			remove_realm_law = celestial_bureaucracy_1
		}
		if = {
			limit = { has_realm_law = celestial_bureaucracy_2 }
			remove_realm_law = celestial_bureaucracy_2
		}
		if = {
			limit = { has_realm_law = celestial_bureaucracy_3 }
			remove_realm_law = celestial_bureaucracy_3
		}
		#Confucian
		if = {
			limit = { has_realm_law = meritocratic_bureaucracy_0 }
			remove_realm_law = meritocratic_bureaucracy_0
		}
		if = {
			limit = { has_realm_law = meritocratic_bureaucracy_1 }
			remove_realm_law = meritocratic_bureaucracy_1
		}
		if = {
			limit = { has_realm_law = meritocratic_bureaucracy_2 }
			remove_realm_law = meritocratic_bureaucracy_2
		}
		if = {
			limit = { has_realm_law = meritocratic_bureaucracy_3 }
			remove_realm_law = meritocratic_bureaucracy_3
		}
		#Japanese
		if = {
			limit = { has_realm_law = japanese_bureaucracy_0 }
			remove_realm_law = japanese_bureaucracy_0
		}
		if = {
			limit = { has_realm_law = japanese_bureaucracy_1 }
			remove_realm_law = japanese_bureaucracy_1
		}
		if = {
			limit = { has_realm_law = japanese_bureaucracy_2 }
			remove_realm_law = japanese_bureaucracy_2
		}
		if = {
			limit = { has_realm_law = japanese_bureaucracy_3 }
			remove_realm_law = japanese_bureaucracy_3
		}
	}
}

mandala_nuke_mandala_decrees_effect = {
	hidden_effect = {
		if = {
			limit = { has_realm_law = mandala_decree_prosperity }
			remove_realm_law = mandala_decree_prosperity
		}
		if = {
			limit = { has_realm_law = mandala_decree_expansion }
			remove_realm_law = mandala_decree_expansion
		}
		if = {
			limit = { has_realm_law = mandala_decree_reverence }
			remove_realm_law = mandala_decree_reverence
		}
	}
}

change_to_mandala_government_decree_effect = {
	#Nuke all laws
	mandala_nuke_realm_laws_effect = yes
	if = {
		limit = {
			NOT = { has_realm_law = mandala_decree_none }
		}
		add_realm_law_skip_effects = mandala_decree_none
	}
}

divine_happenstance_adopt_mandala_effect = {
	send_interface_message = {
		type = msg_mandala_good_with_text
		title = divine_happenstance_fulfilled
		desc = divine_happenstance_fulfilled_desc
		left_icon = root
		add_piety = {
			value = major_piety_value
			multiply = 1.5
		}
		if = {
			limit = { government_has_flag = government_is_mandala }
			add_legitimacy_effect = { LEGITIMACY = major_legitimacy_gain }
		}
		else = {
			#Add legitimacy sans displaying levels (only for show, we shouldn't end up here outside of show_as_tooltip)
			add_major_legitimacy_no_tier_effect = yes
		}
	}
	if = {
		limit = { has_variable = vying_for_mandala_divinity }
		create_character_memory = { type = ascended_as_divined_mandala_devaraja_memory }
	}
	else = {
		create_character_memory = { type = ascended_as_mandala_devaraja_memory }
	}
}

mandala_adopt_clan_government_effect = {
	#Remove Mandala Decrees
	mandala_nuke_mandala_decrees_effect = yes
	#Check if capital holding is castle or temple citadel otherwise convert
	hidden_effect = {
		capital_province = {
			if = {
				limit = {
					NOR = { 
						has_holding_type = temple_citadel_holding
						has_holding_type = castle_holding 
					}
				}
				custom_tooltip = realm_capital_will_change_to_castle
				set_holding_type = castle_holding
			}
		}
	}
	change_government = clan_government
	#Start off crown authorities
	hidden_effect = {
		if = {
			limit = {
				NOT = { has_realm_law = crown_authority_0 }
			}
			add_realm_law_skip_effects = crown_authority_0
		}
	}
	#All muslim vassals swap to Clan
	if = {
		limit = {
			any_vassal = {
				primary_title = {
					target_is_de_jure_liege_or_above = root.primary_title #We only auto convert de jure vassals
				}
				NOR = {
					government_has_flag = government_is_theocracy
					government_has_flag = government_is_republic
					government_has_flag = government_is_landless_adventurer
					government_has_flag = government_is_tribal
					government_has_flag = government_is_clan
					government_has_flag = government_is_nomadic
					government_has_flag = government_is_herder
				}
				faith.religion = religion:islam_religion
			} 
		}
		custom_tooltip = all_muslim_vassals_change_to_clan
		hidden_effect = {
			every_vassal_or_below = {
				limit = {
					primary_title = {
						target_is_de_jure_liege_or_above = root.primary_title #We only auto convert de jure vassals
					}
					NOR = {
						government_has_flag = government_is_theocracy
						government_has_flag = government_is_republic
						government_has_flag = government_is_landless_adventurer
						government_has_flag = government_is_tribal
						government_has_flag = government_is_clan
						government_has_flag = government_is_nomadic
						government_has_flag = government_is_herder
					}
					faith.religion = religion:islam_religion
				}
				if = {
					limit = {
						capital_province = {
							NOR = { 
								has_holding_type = temple_citadel_holding
								has_holding_type = castle_holding
							}
						}
					}
					capital_province = { set_holding_type = castle_holding }
				}
				change_government = clan_government
				#Nuke all laws
				mandala_nuke_realm_laws_effect = yes
				#Remove Mandala Decrees
				mandala_nuke_mandala_decrees_effect = yes
				#Start off crown authorities
				if = {
					limit = {
						NOT = { has_realm_law = crown_authority_0 }
					}
					add_realm_law_skip_effects = crown_authority_0
				}
				#Notify them of what just happened
				if = {
					limit = { is_ai = no }
					trigger_event = tgp_east_asia_decision_events.0030
				}
				set_variable = {
					name = changed_government_recently
					years = 5
				}
			}
		}	
	}
	set_variable = {
		name = changed_government_recently
		years = 5
	}
}



##Conversion Effects
mandala_converter_piety_effect = {
	#Mandala conversion!
	if = {
		limit = { government_has_flag = government_is_mandala }
		if = {
			limit = { has_realm_law = mandala_decree_reverence }
			add_piety = {
				add = medium_piety_gain
				multiply = 1.5
			}
		}
		else = { add_piety = medium_piety_gain }
	}
}

mandala_assimilation_effect = {
	overlord = {		
		send_interface_message = {
			type = event_conversion_good
			title = subject_assimilated_under_your_rule_msg
			left_icon = root
			right_icon = overlord
			show_as_tooltip = { 
				root = {
					if = {
						limit = {
							NOT = { has_government = mandala_government }
						}
						change_government = mandala_government 
					}
					if = {
						limit = {
							NOR = { 
								faith = overlord.faith 
								faith.religious_head ?= root
							}
						}
						set_character_faith = overlord.faith
					}
				}
			}
			if = {
				limit = { has_realm_law = mandala_decree_reverence }
				mandala_converter_piety_effect = yes
			}
		}
	}
	#The Decree
	show_as_tooltip = { change_to_mandala_government_decree_effect = yes }
}

mandala_clean_up_variables_effect = {
	remove_variable = mandala_assimilation_devaraja
	remove_variable = mandala_assimilation_devaraja_piety_level
	remove_character_flag = assimilation_payout_t1
	remove_character_flag = assimilation_payout_t2
	remove_character_flag = assimilation_payout_t3
}



##Building Effects
mandala_built_piety_building_effect = {
	if = {
		limit = {
			NOT = { exists = scope:character }
		}
		county.holder = { save_scope_as = character }
	}
	scope:character = {
		#Liege paid for the building
		if = {
			limit = {
				root.county.holder = { is_independent_ruler = no }
				this = scope:character
				government_has_flag = government_is_mandala
			}
			add_piety = {
				value = minor_piety_value
				multiply = 1.5
			}
			root.county.holder = {
				if = {
					limit = { government_has_flag = government_is_mandala }
				}
				add_piety = {
					value = miniscule_piety_value
					multiply = 1.5
				}
			}
		}
		#Vassal paid for the building
		else_if = {
			limit = { 
				government_has_flag = government_is_mandala
				is_alive = yes
			}
			add_piety = {
				value = minor_piety_value
				multiply = 1.5
			}
		}
	}
}

mandala_built_piety_duchy_building_t1_effect = {
	if = {
		limit = {
			NOT = { exists = scope:character }
		}
		county.holder = { save_scope_as = character }
	}
	scope:character = {
	#Liege paid for the building
		if = {
			limit = {
				root.county.holder = { is_independent_ruler = no }
				this = scope:character
				government_has_flag = government_is_mandala
			}
			add_piety = {
				value = medium_piety_value
				multiply = 1.5
			}
			root.county.holder = {
				if = {
					limit = { government_has_flag = government_is_mandala }
				}
				add_piety = {
					value = minor_piety_value
					multiply = 1.5
				}
			}
		}
		#Vassal paid for the building
		else_if = {
			limit = { government_has_flag = government_is_mandala }
			add_piety = {
				value = medium_piety_value
				multiply = 1.5
			}
		}
	}
}

mandala_built_piety_duchy_building_t2_effect = {
	if = {
		limit = {
			NOT = { exists = scope:character }
		}
		county.holder = { save_scope_as = character }
	}
	scope:character = {
		#Liege paid for the building
		if = {
			limit = {
				root.county.holder = { is_independent_ruler = no }
				this = scope:character
				government_has_flag = government_is_mandala
			}
			add_piety = {
				value = major_piety_value
				multiply = 1.5
			}
			root.county.holder = {
				if = {
					limit = { government_has_flag = government_is_mandala }
				}
				add_piety = {
					value = medium_piety_value
					multiply = 1.5
				}
			}
		}
		#Vassal paid for the building
		else_if = {
			limit = { government_has_flag = government_is_mandala }
			add_piety = {
				value = major_piety_value
				multiply = 1.5
			}
		}
	}
}

mandala_built_piety_duchy_building_t3_effect = {
	if = {
		limit = {
			NOT = { exists = scope:character }
		}
		county.holder = { save_scope_as = character }
	}
	scope:character = {
		#Liege paid for the building
		if = {
			limit = {
				root.county.holder = { is_independent_ruler = no }
				this = scope:character
				government_has_flag = government_is_mandala
			}
			add_piety = {
				value = massive_piety_value
				multiply = 1.5
			}
			root.county.holder = {
				if = {
					limit = { government_has_flag = government_is_mandala }
				}
				add_piety = {
					value = major_piety_value
					multiply = 1.5
				}
			}
		}
		#Vassal paid for the building
		else_if = {
			limit = { government_has_flag = government_is_mandala }
			add_piety = {
				value = massive_piety_value
				multiply = 1.5
			}
		}
	}
}

mandala_built_temple_holding_effect = {
	if = {
		limit = {
			NOT = { exists = scope:character }
		}
		save_scope_as = character
	}
	scope:character = {
		#Liege paid for the holding
		if = {
			limit = {
				root.county.holder = { is_independent_ruler = no }
				this = scope:character
				government_has_flag = government_is_mandala
			}
			add_piety = {
				value = massive_piety_value
				multiply = {
					value = 1.5
				}
				if = {
					limit = {
						culture = { has_cultural_parameter = founding_temple_citadels_gives_more_piety }
					}
					multiply = 2
				}
			}
			root.county.holder = {
				if = {
					limit = { government_has_flag = government_is_mandala }
				}
				add_piety = {
					value = major_piety_value
					multiply = 1.5
				}
			}
		}
		#Vassal paid for the holding
		else_if = {
			limit = { government_has_flag = government_is_mandala }
			add_piety = {
				value = massive_piety_value
				multiply = {
					value = 1.5
				}
				if = {
					limit = {
						culture = { has_cultural_parameter = founding_temple_citadels_gives_more_piety }
					}
					multiply = 2
				}
			}
		}
	}
}

mandala_upgraded_temple_holding_effect = {
	if = {
		limit = {
			NOT = { exists = scope:character }
		}
		county.holder = { save_scope_as = character }
	}
	scope:character = {
		#Liege paid for the holding
		if = {
			limit = {
				root.county.holder = { is_independent_ruler = no }
				this = scope:character
				government_has_flag = government_is_mandala
			}
			add_piety = {
				value = medium_piety_value
				multiply = 1.5
			}
			root.county.holder = {
				if = {
					limit = { government_has_flag = government_is_mandala }
				}
				add_piety = {
					value = minor_piety_value
					multiply = 1.5
				}
			}
		}
		#Vassal paid for the holding
		else_if = {
			limit = { government_has_flag = government_is_mandala }
			add_piety = {
				value = medium_piety_value
				multiply = 1.5
			}
		}
	}
}


creator_mandala_built_regular_building_piety_effect = {
	if = {
		limit = {
			NOT = { exists = scope:character }
		}
		county.holder = { save_scope_as = character }
	}
	scope:character = {
		if = {
			limit = {
				government_has_flag = government_is_mandala
				house ?= { has_house_aspiration_parameter = aspect_of_creation }
				is_house_head = yes
			}
			add_piety = {
				value = minor_piety_value
				multiply = { value = creator_mandala_piety_gain_scale }
			}
		}
	}
}

creator_mandala_built_regular_duchy_building_t1_piety_effect = {
	if = {
		limit = {
			NOT = { exists = scope:character }
		}
		county.holder = { save_scope_as = character }
	}
	scope:character = {
		if = {
			limit = {
				government_has_flag = government_is_mandala
				house ?= { has_house_aspiration_parameter = aspect_of_creation }
				is_house_head = yes
			}
			add_piety = {
				value = medium_piety_value
				multiply = { value = creator_mandala_piety_gain_scale }
			}
		}
	}
}

creator_mandala_built_regular_duchy_building_t2_piety_effect = {
	if = {
		limit = {
			NOT = { exists = scope:character }
		}
		county.holder = { save_scope_as = character }
	}
	scope:character = {
		if = {
			limit = {
				government_has_flag = government_is_mandala
				house ?= { has_house_aspiration_parameter = aspect_of_creation }
				is_house_head = yes
			}
			add_piety = {
				value = major_piety_value
				multiply = { value = creator_mandala_piety_gain_scale }
			}
		}
	}
}

creator_mandala_built_regular_duchy_building_t3_piety_effect = {
	if = {
		limit = {
			NOT = { exists = scope:character }
		}
		county.holder = { save_scope_as = character }
	}
	scope:character = {
		if = {
			limit = {
				government_has_flag = government_is_mandala
				house ?= { has_house_aspiration_parameter = aspect_of_creation }
				is_house_head = yes
			}
			add_piety = {
				value = massive_piety_value
				multiply = { value = creator_mandala_piety_gain_scale }
			}
		}
	}
}

creator_mandala_built_regular_holding_piety_effect = {
	if = {
		limit = {
			NOT = { exists = scope:character }
		}
		county.holder = { save_scope_as = character }
	}
	scope:character = {
		if = {
			limit = {
				government_has_flag = government_is_mandala
				house ?= { has_house_aspiration_parameter = aspect_of_creation }
				is_house_head = yes
			}
			add_piety = {
				value = massive_piety_value
				multiply = { value = creator_mandala_piety_gain_scale }
			}
		}
	}
}

creator_mandala_upgraded_regular_holding_piety_effect = {
	if = {
		limit = {
			NOT = { exists = scope:character }
		}
		county.holder = { save_scope_as = character }
	}
	scope:character = {
		if = {
			limit = {
				government_has_flag = government_is_mandala
				house ?= { has_house_aspiration_parameter = aspect_of_creation }
				is_house_head = yes
			}
			add_piety = {
				value = medium_piety_value
				multiply = { value = creator_mandala_piety_gain_scale }
			}
		}
	}
}



##Interaction Effects
mandala_end_tributary_with_notification_effect = {
	save_scope_as = leaving_tributary
	suzerain = { trigger_event = tgp_east_asia_interaction_events.0010 }
	end_tributary = yes
}

mandala_embrace_tributary_effect = {
	scope:recipient = {
		add_opinion = {
			modifier = accepted_tributary_status_opinion # this opinion also acts as a built-in cooldown
			target = scope:actor
			opinion = 20
		}
	}
	start_tributary_interaction_effect = {
		TRIBUTARY = scope:recipient
		SUZERAIN = scope:actor
	}
	scope:actor = {
		trigger_event = char_interaction.0362
	}
	consume_all_criminal_reasons_effect = {
		LIEGE = scope:actor
		CRIMINAL = scope:recipient
	}
}

decommission_temple_accept_effect = {
	custom_tooltip = {
		text = decommission_mandala_temple_effect_tt
		capital_province = {
			if = {
				limit = { has_building_with_flag = mandala_capital_building }
				ruin_great_building = yes
			}
		}
	}
	if = {
		limit = { has_character_flag = devaraja_flag }
		remove_character_flag = devaraja_flag
	}
	if = {
		limit = { has_character_modifier = mandala_rise_from_the_ashes_modifier }
		remove_character_modifier = mandala_rise_from_the_ashes_modifier
	}
	add_opinion = {
		target = scope:actor
		modifier = ruined_my_temple_opinion
		opinion = -50
	}
}

decommission_temple_decline_effect = {
	if = {
		limit = { is_vassaL_of = scope:actor }
		start_war = {
			casus_belli = independence_war
			target = scope:actor
		}
	}
	else = {
		mandala_end_tributary_with_notification_effect = yes
	}
	progress_towards_rival_effect = {
		REASON = rival_ruined_temple_building
		CHARACTER = scope:actor
		OPINION = -100
	}
}



##Aspect Effects
mandala_apply_10_year_modifier = {
	add_character_modifier = { 
		modifier = mandala_creator_modifier
		years = 10
	}
	trigger_event = {
		id = tgp_east_asia_mandala_events.0010
		days = 3651 # 10 years and 1 day
	}
}

mandala_apply_20_year_modifier = {
	add_character_modifier = { 
		modifier = mandala_creator_modifier
		years = 20
	}
	trigger_event = {
		id = tgp_east_asia_mandala_events.0010
		days = 7301 # 20 years and 1 day
	}
}

mandala_apply_30_year_modifier = {
	add_character_modifier = { 
		modifier = mandala_creator_modifier
		years = 30
	}
	trigger_event = {
		id = tgp_east_asia_mandala_events.0010
		days = 10951 # 30 years and 1 day
	}
}

mandala_upgrade_creator_effect = {
	if = { 
		limit = { has_variable = mandala_house_power_accumulated_creator }
		#Save what we gained so far so we can add it to the refreshed variable
		save_temporary_scope_value_as = {
			name = accumulated_creator_increments
			value = var:mandala_house_power_accumulated_creator
		}
		remove_variable = mandala_house_power_accumulated_creator
		#Clean up any existing modifier
		hidden_effect = {
			if = {
				limit = { has_character_modifier = mandala_creator_modifier }
				remove_character_modifier = mandala_creator_modifier
			}
		}
		#What cadence are we on?
		if = {
			limit = {
				house = { has_house_head_parameter = creator_30_year_modifier }
			}
			set_variable = {
				name = mandala_house_power_accumulated_creator
				value = {
					value = 1
					add = scope:accumulated_creator_increments
				}
				years = 30
			}
			hidden_effect = {
				send_interface_message = {
					type = msg_mandala_good_with_text
					title = mandala_creator_streak_accumulated
					desc = mandala_creator_streak_accumulated_desc
					left_icon = root
					mandala_apply_30_year_modifier = yes
				}
			}
		}
		else_if = {
			limit = {
				house = { house_has_creator_20_years_trigger = yes }
			}
			set_variable = {
				name = mandala_house_power_accumulated_creator
				value = {
					value = 1
					add = scope:accumulated_creator_increments
				}
				years = 20
			}
			hidden_effect = {
				send_interface_message = {
					type = msg_mandala_good_with_text
					title = mandala_creator_streak_accumulated
					desc = mandala_creator_streak_accumulated_desc
					left_icon = root
					mandala_apply_20_year_modifier = yes
				}
			}
		}
		else_if = {
			limit = { 
				house = { house_has_creator_10_years_trigger = yes } #This is just to stop some scope errors
			}
			set_variable = {
				name = mandala_house_power_accumulated_creator
				value = {
					value = 1
					add = scope:accumulated_creator_increments
				}
				years = 10
			}
			hidden_effect = {	
				send_interface_message = {
					type = msg_mandala_good_with_text
					title = mandala_creator_streak_accumulated
					desc = mandala_creator_streak_accumulated_desc
					left_icon = root
					mandala_apply_10_year_modifier = yes
				}
			}
		}
	}
	else = {
		#Clean up any existing modifier
		hidden_effect = {
			if = {
				limit = { has_character_modifier = mandala_creator_modifier }
				remove_character_modifier = mandala_creator_modifier
			}
		}
		#Start from the beginning
		if = {
			limit = {
				house = { has_house_head_parameter = creator_30_year_modifier }
			}
			set_variable = {
				name = mandala_house_power_accumulated_creator
				value = 1
				years = 30
			}
			hidden_effect = {
				send_interface_message = {
					type = msg_mandala_good_with_text
					title = mandala_creator_streak_accumulated
					desc = mandala_creator_streak_accumulated_desc
					left_icon = root
					mandala_apply_30_year_modifier = yes
				}
			}
		}
		else_if = {
			limit = {
				house = { house_has_creator_20_years_trigger = yes }
			}
			set_variable = {
				name = mandala_house_power_accumulated_creator
				value = 1
				years = 20
			}
			hidden_effect = {
				send_interface_message = {
					type = msg_mandala_good_with_text
					title = mandala_creator_streak_accumulated
					desc = mandala_creator_streak_accumulated_desc
					left_icon = root
					mandala_apply_20_year_modifier = yes
				}
			}
		}
		else = {
			set_variable = {
				name = mandala_house_power_accumulated_creator
				value = 1
				years = 10
			}
			hidden_effect = {
				send_interface_message = {
					type = msg_mandala_good_with_text
					title = mandala_creator_streak_accumulated
					desc = mandala_creator_streak_accumulated_desc
					left_icon = root
					mandala_apply_10_year_modifier = yes
				}
			}
		}
	}
}


mandala_upgrade_increment_of_peace_effect = {
	if = { 
		limit = { has_variable = mandala_house_power_accumulated_increments_of_peace }
		change_variable = {
			name = mandala_house_power_accumulated_increments_of_peace
			add = 1
		}
		hidden_effect = {
			remove_character_modifier = mandala_increments_of_peace_modifier
			send_interface_message = {
				type = msg_mandala_good_with_text
				title = mandala_increments_of_peace_accumulated
				desc = mandala_increments_of_peace_accumulated_desc
				left_icon = root
				add_character_modifier = { modifier = mandala_increments_of_peace_modifier }
			}
		}
	}
}

mandala_reset_increment_of_peace_effect = {
	remove_variable = mandala_house_power_accumulated_increments_of_peace
	set_variable = {
		name = mandala_house_power_accumulated_increments_of_peace
		value = 1
	}
	hidden_effect = {
		send_interface_message = {
			type = msg_mandala_bad_with_text
			title = mandala_increments_of_peace_broken
			desc = mandala_increments_of_peace_broken_desc
			left_icon = root
			remove_character_modifier = mandala_increments_of_peace_modifier
			remove_variable = mandala_house_power_accumulated_increments_of_peace
		}
		add_character_modifier = mandala_increments_of_peace_modifier
	}
}

mandala_remove_increment_of_peace_effect = {
	send_interface_message = {
		type = msg_mandala_neutral_with_text
		title = mandala_increments_of_peace_invalid
		desc = mandala_increments_of_peace_invalid_desc
		left_icon = root
		remove_character_modifier = mandala_increments_of_peace_modifier
		remove_variable = mandala_house_power_accumulated_increments_of_peace
	}
}


mandala_change_between_aspects_effect = {
	if = {
		limit = {
			NOT = { 
				house = { has_default_house_aspiration = yes }
			}
		}
		if = {
			limit = { has_variable = changed_aspect_once }
			add_piety_level = -1
		}
		else = { 
			custom_tooltip = {
				text = change_aspect_once_per_lifetime.tt
				set_variable = changed_aspect_once
			} 
		}
		if = {
			limit = {
				NOT = { has_character_flag = devaraja_flag }
			}
			add_character_flag = devaraja_flag
		}
	}
}


##Reverence Decree Effects
mandala_piety_gain_effect = {
	if = {
		limit = { has_realm_law = mandala_decree_reverence }
		add_piety = {
			add = $PIETY_AMOUNT$
			multiply = 1.5
		}
	}
	else = { add_piety = $PIETY_AMOUNT$ }
}


mandala_trickster_increment_successful_schemes_effect = {
	if = {
		limit = {
			government_has_flag = government_is_mandala
			house ?= { has_house_aspiration_parameter = aspect_of_trickery }
		}
		increment_variable_effect = {
			VAR = num_successful_schemes
			VAL = 1
		}
	}
}

mandala_trickster_increment_gold_ransomed_effect = {
	if = {
		limit = {
			government_has_flag = government_is_mandala
			house ?= { has_house_aspiration_parameter = aspect_of_trickery }
		}
		increment_variable_effect = {
			VAR = amount_of_gold_ransomed
			VAL = $GOLD_AMOUNT$
		}
	}
}


##Task Contracts
# Select the Contract Tier (somewhat randomized, based on your Radiance)
spawn_mandala_realm_task_contract_effect = {
	save_scope_as = mandala_ruler
	# Select which contract to create
	trigger_event = {
		on_action = spawn_mandala_realm_contract_on_action
	}

}

manage_new_mandala_contract_effect = {
	if = {
		limit = { exists = scope:target_province }
		send_interface_message = {
			type = msg_mandala_contracts_text_neutral
			title = msg_mandala_realm_contract_appear.t
			desc = msg_mandala_realm_contract_appear.desc
			right_icon = scope:target_province.county
		}
	}
	if = {
		limit = {
			is_ai = yes
			exists = scope:new_mandala_visit
		}
		accept_task_contract = scope:new_mandala_visit
	}

	#play_sound_effect = "event:/DLC/EP3/SFX/Stingers/Byzantine_Flavor/ep3_mx_sting_byzantineflavor_become_governor"
}

mandala_travel_to_contract_location_effect = {
	save_scope_as = court_owner
	random_courtier = {
		limit = {
			is_available = yes
			NOT = { has_court_position = travel_leader_court_position }
		}
		weight = {
			base = 1
			modifier = {
				add = 100
				scope:court_owner.house = {
					has_house_aspiration_parameter = aspect_of_creation
				}
				OR = {
					is_child_of = scope:court_owner
					is_grandchild_of = scope:court_owner
					is_great_grandchild_of = scope:court_owner
					is_consort_of = scope:court_owner
				}
			}
			modifier = {
				add = 10
				scope:court_owner.house = {
					has_house_aspiration_parameter = aspect_of_creation
				}
				is_close_or_extended_family_of = scope:court_owner
			}
			modifier = {
				add = diplomacy
				scope:court_owner.house = {
					has_house_aspiration_parameter = aspect_of_serenity
				}
			}
			modifier = {
				add = prowess
				scope:court_owner.house = {
					has_house_aspiration_parameter = aspect_of_destruction
				}
			}
			modifier = {
				add = intrigue
				scope:court_owner.house = {
					has_house_aspiration_parameter = aspect_of_trickery
				}
			}
			modifier = {
				add = 1000
				has_court_position = court_physician_court_position
			}
		}
		save_scope_as = follower_1
	}
	if = {
		limit = {
			exists = scope:follower_1
		}
		random_courtier = {
			limit = {
				is_available = yes
				this != scope:follower_1
				NOT = { has_court_position = travel_leader_court_position }
			}
			weight = {
				base = 1
				modifier = {
					add = 100
					scope:court_owner.house = {
						has_house_aspiration_parameter = aspect_of_creation
					}
					OR = {
						is_child_of = scope:court_owner
						is_grandchild_of = scope:court_owner
						is_great_grandchild_of = scope:court_owner
						is_consort_of = scope:court_owner
					}
				}
				modifier = {
					add = 10
					scope:court_owner.house = {
						has_house_aspiration_parameter = aspect_of_creation
					}
					is_close_or_extended_family_of = scope:court_owner
				}
				modifier = {
					add = diplomacy
					scope:court_owner.house = {
						has_house_aspiration_parameter = aspect_of_serenity
					}
				}
				modifier = {
					add = prowess
					scope:court_owner.house = {
						has_house_aspiration_parameter = aspect_of_destruction
					}
				}
				modifier = {
					add = intrigue
					scope:court_owner.house = {
						has_house_aspiration_parameter = aspect_of_trickery
					}
				}
			}
			save_scope_as = follower_2
		}
	}
	if = {
		limit = {
			exists = scope:follower_2
		}
		random_courtier = {
			limit = {
				is_available = yes
				this != scope:follower_1
				this != scope:follower_2
				NOT = { has_court_position = travel_leader_court_position }
			}
			weight = {
				base = 1
				modifier = {
					add = 100
					scope:court_owner.house = {
						has_house_aspiration_parameter = aspect_of_creation
					}
					OR = {
						is_child_of = scope:court_owner
						is_grandchild_of = scope:court_owner
						is_great_grandchild_of = scope:court_owner
						is_consort_of = scope:court_owner
					}
				}
				modifier = {
					add = 10
					scope:court_owner.house = {
						has_house_aspiration_parameter = aspect_of_creation
					}
					is_close_or_extended_family_of = scope:court_owner
				}
				modifier = {
					add = diplomacy
					scope:court_owner.house = {
						has_house_aspiration_parameter = aspect_of_serenity
					}
				}
				modifier = {
					add = prowess
					scope:court_owner.house = {
						has_house_aspiration_parameter = aspect_of_destruction
					}
				}
				modifier = {
					add = intrigue
					scope:court_owner.house = {
						has_house_aspiration_parameter = aspect_of_trickery
					}
				}
			}
			save_scope_as = follower_3
		}
	}
	if = {
		limit = {
			exists = scope:follower_3
		}
		random_courtier = {
			limit = {
				is_available = yes
				this != scope:follower_1
				this != scope:follower_2
				this != scope:follower_3
				NOT = { has_court_position = travel_leader_court_position }
			}
			weight = {
				base = 1
				modifier = {
					add = 100
					scope:court_owner.house = {
						has_house_aspiration_parameter = aspect_of_creation
					}
					OR = {
						is_child_of = scope:court_owner
						is_grandchild_of = scope:court_owner
						is_great_grandchild_of = scope:court_owner
						is_consort_of = scope:court_owner
					}
				}
				modifier = {
					add = 10
					scope:court_owner.house = {
						has_house_aspiration_parameter = aspect_of_creation
					}
					is_close_or_extended_family_of = scope:court_owner
				}
				modifier = {
					add = diplomacy
					scope:court_owner.house = {
						has_house_aspiration_parameter = aspect_of_serenity
					}
				}
				modifier = {
					add = prowess
					scope:court_owner.house = {
						has_house_aspiration_parameter = aspect_of_destruction
					}
				}
				modifier = {
					add = intrigue
					scope:court_owner.house = {
						has_house_aspiration_parameter = aspect_of_trickery
					}
				}
			}
			save_scope_as = follower_4
		}
	}
	if = {
		limit = {
			exists = scope:follower_4
		}
		random_courtier = {
			limit = {
				is_available = yes
				this != scope:follower_1
				this != scope:follower_2
				this != scope:follower_3
				this != scope:follower_4
				NOT = { has_court_position = travel_leader_court_position }
			}
			weight = {
				base = 1
				modifier = {
					add = 100
					scope:court_owner.house = {
						has_house_aspiration_parameter = aspect_of_creation
					}
					OR = {
						is_child_of = scope:court_owner
						is_grandchild_of = scope:court_owner
						is_great_grandchild_of = scope:court_owner
						is_consort_of = scope:court_owner
					}
				}
				modifier = {
					add = 10
					scope:court_owner.house = {
						has_house_aspiration_parameter = aspect_of_creation
					}
					is_close_or_extended_family_of = scope:court_owner
				}
				modifier = {
					add = diplomacy
					scope:court_owner.house = {
						has_house_aspiration_parameter = aspect_of_serenity
					}
				}
				modifier = {
					add = prowess
					scope:court_owner.house = {
						has_house_aspiration_parameter = aspect_of_destruction
					}
				}
				modifier = {
					add = intrigue
					scope:court_owner.house = {
						has_house_aspiration_parameter = aspect_of_trickery
					}
				}
			}
			save_scope_as = follower_5
		}
	}
	if = {
		limit = {
			exists = scope:follower_1
			exists = scope:follower_2
			exists = scope:follower_3
			exists = scope:follower_4
			exists = scope:follower_5
		}
		start_travel_plan = {
			destination = $DESTINATION$
			on_arrival_event = $ARRIVAL_EVENT$
			companion = scope:follower_1
			companion = scope:follower_2
			companion = scope:follower_3
			companion = scope:follower_4
			companion = scope:follower_5
			on_travel_planner_cancel_event = tgp_east_asia_mandala_task_contract_events.0990
			on_arrival_destinations = all_but_last
		}
	}
	else_if = {
		limit = {
			exists = scope:follower_1
			exists = scope:follower_2
			exists = scope:follower_3
			exists = scope:follower_4
		}
		start_travel_plan = {
			destination = $DESTINATION$
			on_arrival_event = $ARRIVAL_EVENT$
			companion = scope:follower_1
			companion = scope:follower_2
			companion = scope:follower_3
			companion = scope:follower_4
			on_travel_planner_cancel_event = tgp_east_asia_mandala_task_contract_events.0990
			on_arrival_destinations = all_but_last
		}
	}
	else_if = {
		limit = {
			exists = scope:follower_1
			exists = scope:follower_2
			exists = scope:follower_3
		}
		start_travel_plan = {
			destination = $DESTINATION$
			on_arrival_event = $ARRIVAL_EVENT$
			companion = scope:follower_1
			companion = scope:follower_2
			companion = scope:follower_3
			on_travel_planner_cancel_event = tgp_east_asia_mandala_task_contract_events.0990
			on_arrival_destinations = all_but_last
		}
	}
	else_if = {
		limit = {
			exists = scope:follower_1
			exists = scope:follower_2
		}
		start_travel_plan = {
			destination = $DESTINATION$
			on_arrival_event = $ARRIVAL_EVENT$
			companion = scope:follower_1
			companion = scope:follower_2
			on_travel_planner_cancel_event = tgp_east_asia_mandala_task_contract_events.0990
			on_arrival_destinations = all_but_last
		}
	}
	else_if = {
		limit = {
			exists = scope:follower_1
		}
		start_travel_plan = {
			destination = $DESTINATION$
			on_arrival_event = $ARRIVAL_EVENT$
			companion = scope:follower_1
			on_travel_planner_cancel_event = tgp_east_asia_mandala_task_contract_events.0990
			on_arrival_destinations = all_but_last
		}
	}
	else = {
		start_travel_plan = {
			destination = $DESTINATION$
			on_arrival_event = $ARRIVAL_EVENT$
			on_travel_planner_cancel_event = tgp_east_asia_mandala_task_contract_events.0990
			on_arrival_destinations = all_but_last
		}
	}
}

mandala_contract_clean_up_location_effect = {
	task_contract_location = {
		remove_variable = requested_mandala_ritual
	}
	task_contract_taker = {
		increment_variable_remove_at_zero_effect = {
			VAR = available_mandala_rituals
			VALUE = -1
		}
	}
}

mandala_invalidate_contracts_effect = {
	if = {
		limit = {
			any_character_active_contract = { is_a_mandala_contract_trigger = yes }
		}
		random_character_active_contract = {
			limit = { is_a_mandala_contract_trigger = yes }
			save_scope_as = invalidating_task_contract
			task_contract_taker = {
				save_scope_as = task_contract_character
				send_interface_message = {
					type = event_generic_bad_with_text
					title = mandala_contract_invalidated_title
					left_icon = scope:task_contract_character
					desc = mandala_contract_invalidated_desc
				}
				scope:invalidating_task_contract = { invalidate_contract = yes }
			}
		}
	}
	if = {
		limit = { has_character_flag = recently_completed_mandala_contract }
		remove_character_flag = recently_completed_mandala_contract
	}
}

mandala_contract_complete_contract_effect = {
	hidden_effect = {
		scope:task_contract = { complete_task_contract = common_mandala }
		current_travel_plan ?= {
			if = {
				limit = { is_paused = yes }
				resume_travel_plan = yes 
			}	
		}
	}
	add_character_flag = recently_completed_mandala_contract
}

mandala_contract_piety_reward_display_effect = {
	save_scope_as = task_contract
	task_contract_taker = {
		if = {
			limit = { contract_is_tier_3_contract_trigger = yes }
			custom_tooltip = mandala_realm_contract_piety_high_reward_tt
		}
		else_if = {
			limit = { contract_is_tier_2_contract_trigger = yes }
			custom_tooltip = mandala_realm_contract_piety_mid_reward_tt
		}
		else = {
			custom_tooltip = mandala_realm_contract_piety_reward_tt
		}
	}
	
}

mandala_contract_legitimacy_reward_display_effect = {
	save_scope_as = task_contract
	task_contract_taker = { 
		if = {
			limit = { scope:task_contract.task_contract_tier = define:NTaskContract|HIGH_TASK_CONTRACT_TIER }
			custom_tooltip = mandala_realm_contract_legitimacy_high_reward_tt
		}
		else_if = {
			limit = { scope:task_contract.task_contract_tier = define:NTaskContract|MEDIUM_TASK_CONTRACT_TIER }
			custom_tooltip = mandala_realm_contract_legitimacy_mid_reward_tt
		}
		else = {
			custom_tooltip = mandala_realm_contract_legitimacy_reward_tt
		}
	}
}

add_all_valid_mandala_contract_provinces_to_list_effect = {
	save_scope_as = mandala_ruler
	every_sub_realm_county = {
		every_county_province = {
			limit = {
				has_holding = yes
				is_occupied = no
				NOR = {
					this = scope:mandala_ruler.capital_province
					has_variable = requested_mandala_ritual
					has_variable = mandala_ritual_cooldown
				}
			}
			add_to_list = valid_target_provinces
		}
	}
	every_tributary = {
		every_sub_realm_county = {
			every_county_province = {
				limit = {
					has_holding = yes
					is_occupied = no
					NOR = {
						this = scope:mandala_ruler.capital_province
						has_variable = requested_mandala_ritual
						has_variable = mandala_ritual_cooldown
					}
				}
				add_to_list = valid_target_provinces
			}
		}
	}
}

add_all_valid_mandala_contract_provinces_with_crocodiles_to_list_effect = {
	save_scope_as = mandala_ruler
	every_sub_realm_county = {
		every_county_province = {
			limit = {
				has_holding = yes
				is_occupied = no
				hunt_animal_crocodile_trigger = yes
				NOR = {
					this = scope:mandala_ruler.capital_province
					has_variable = requested_mandala_ritual
					has_variable = mandala_ritual_cooldown
				}
			}
			add_to_list = valid_target_provinces
		}
	}
	every_tributary = {
		every_sub_realm_county = {
			every_county_province = {
				limit = {
					has_holding = yes
					is_occupied = no
					hunt_animal_crocodile_trigger = yes
					NOR = {
						this = scope:mandala_ruler.capital_province
						has_variable = requested_mandala_ritual
						has_variable = mandala_ritual_cooldown
					}
				}
				add_to_list = valid_target_provinces
			}
		}
	}
}

add_all_valid_mandala_contract_provinces_with_neighbor_to_list_effect = {
	save_scope_as = mandala_ruler
	every_sub_realm_county = {
		limit = {
			any_neighboring_county = {
				holder = {
					is_ai = yes
				}
				title_province = {
					has_holding = yes
				}
			}
		}
		every_county_province = {
			limit = {
				has_holding = yes
				is_occupied = no
				NOR = {
					this = scope:mandala_ruler.capital_province
					has_variable = requested_mandala_ritual
					has_variable = mandala_ritual_cooldown
				}
			}
			add_to_list = valid_target_provinces
		}
	}
	every_tributary = {
		every_sub_realm_county = {
			limit = {
				any_neighboring_county = {
					holder = {
						is_ai = yes
					}
					title_province = {
						has_holding = yes
					}
				}
			}
			every_county_province = {
				limit = {
					has_holding = yes
					is_occupied = no
					NOR = {
						this = scope:mandala_ruler.capital_province
						has_variable = requested_mandala_ritual
						has_variable = mandala_ritual_cooldown
					}
				}
				add_to_list = valid_target_provinces
			}
		}
	}
}

add_all_valid_mandala_contract_provinces_no_holding_to_list_effect = {
	save_scope_as = mandala_ruler
	every_sub_realm_county = {
		every_county_province = {
			limit = {
				has_holding = no
				is_occupied = no
				NOR = {
					this = scope:mandala_ruler.capital_province
					has_variable = requested_mandala_ritual
					has_variable = mandala_ritual_cooldown
				}
			}
			add_to_list = valid_target_provinces
		}
	}
	every_tributary = {
		every_sub_realm_county = {
			every_county_province = {
				limit = {
					has_holding = no
					is_occupied = no
					NOR = {
						this = scope:mandala_ruler.capital_province
						has_variable = requested_mandala_ritual
						has_variable = mandala_ritual_cooldown
					}
				}
				add_to_list = valid_target_provinces
			}
		}
	}
}

set_mandala_contract_tier_effect = {
	#Consider county_opinion as a factor
	random_list = {
		30 = {
			save_scope_value_as = {
				name = mandala_task_contract_tier
				value = define:NTaskContract|LOW_TASK_CONTRACT_TIER
			}
		}
		10 = {
			save_scope_value_as = {
				name = mandala_task_contract_tier
				value = define:NTaskContract|MEDIUM_TASK_CONTRACT_TIER
			}

			modifier = {
				add = 10
				scope:target_province.county.county_opinion >= 10
			}
			modifier = {
				add = 10
				scope:target_province.county.county_opinion >= 20
			}
		}
		5 = {
			save_scope_value_as = {
				name = mandala_task_contract_tier
				value = define:NTaskContract|HIGH_TASK_CONTRACT_TIER
			}

			modifier = {
				add = 10
				scope:target_province.county.county_opinion >= 40
			}
			modifier = {
				add = 10
				scope:target_province.county.county_opinion >= 60
			}
			modifier = {
				add = 10
				scope:target_province.county.county_opinion >= 80
			}
			modifier = {
				add = 10
				scope:target_province.county.county_opinion >= 100
			}
		}
	}
}

choose_address_mandala_effect = {
	random_list = {
		1 = { 
			set_variable = {
				name = loc_compliment
				value = flag:holy_compliment_almighty
			}
		}
		1 = { 
			set_variable = {
				name = loc_compliment
				value = flag:holy_compliment_most_omnipotent
			}
		}
		1 = { 
			set_variable = {
				name = loc_compliment
				value = flag:holy_compliment_divine
			}
		}
		1 = { 
			set_variable = {
				name = loc_compliment
				value = flag:holy_compliment_venerable
			} 
		}
		1 = { 
			set_variable = {
				name = loc_compliment
				value = flag:holy_compliment_reverent
			}
		}
	}
	#Error suppression
	if = {
		limit = {
			OR = {
				var:loc_desc ?= flag:mandala_provincial_ritual_desc_01
				var:loc_desc ?= flag:mandala_provincial_ritual_desc_02
				var:loc_compliment ?= flag:holy_compliment_almighty
				var:loc_compliment ?= flag:holy_compliment_most_omnipotent
				var:loc_compliment ?= flag:holy_compliment_divine
				var:loc_compliment ?= flag:holy_compliment_venerable
				var:loc_compliment ?= flag:holy_compliment_reverent
			}
		}
	}
}

mandala_set_ritual_variables_effect = {
	task_contract_location = {
		set_variable = requested_mandala_ritual
		set_variable = {
			name = mandala_ritual_cooldown
			years = mandala_ritual_cooldown_years
		}
	}
	task_contract_taker = {
		increment_variable_effect = {
			VAR = available_mandala_rituals
			VAL = 1
		}
	}
}

big_mandala_piety_reward_effect = {
	add_piety = {
		value = mandala_contract_piety
		if = {
			limit = { contract_is_tier_3_contract_trigger = yes }
			multiply = 1.5
		}
		else_if = {
			limit = { contract_is_tier_2_contract_trigger = yes }
			multiply = 1.25
		}
		multiply = 1.5
	}
}

mandala_piety_reward_effect = {
	add_piety = {
		value = mandala_contract_piety
		if = {
			limit = { contract_is_tier_3_contract_trigger = yes }
			multiply = 1.5
		}
		else_if = {
			limit = { contract_is_tier_2_contract_trigger = yes }
			multiply = 1.25
		}
		multiply = 0.75
	}
}

small_mandala_piety_reward_effect = {
	add_piety = {
		value = mandala_contract_piety
		if = {
			limit = { contract_is_tier_3_contract_trigger = yes }
			multiply = 2
		}
		else_if = {
			limit = { contract_is_tier_2_contract_trigger = yes }
			multiply = 1.5
		}
		multiply = 0.25
	}
}

big_mandala_legitimacy_reward_effect = {
	add_legitimacy = {
		value = mandala_contract_legitimacy
		if = {
			limit = { contract_is_tier_3_contract_trigger = yes }
			multiply = 2
		}
		else_if = {
			limit = { contract_is_tier_2_contract_trigger = yes }
			multiply = 1.5
		}
		multiply = 2
	}
}

mandala_legitimacy_reward_effect = {
	add_legitimacy = {
		value = mandala_contract_legitimacy
		if = {
			limit = { contract_is_tier_3_contract_trigger = yes }
			multiply = 2
		}
		else_if = {
			limit = { contract_is_tier_2_contract_trigger = yes }
			multiply = 1.5
		}
	}
}

small_mandala_legitimacy_reward_effect = {
	add_legitimacy = {
		value = mandala_contract_legitimacy
		if = {
			limit = { contract_is_tier_3_contract_trigger = yes }
			multiply = 2
		}
		else_if = {
			limit = { contract_is_tier_2_contract_trigger = yes }
			multiply = 1.5
		}
		multiply = 0.25
	}
}

mandala_contract_failure_standard_reward_effect = {
	if = {
		limit = { is_ai = no }
		add_piety = {
			value = mandala_contract_piety
			multiply = -1.5
		}
		add_piety_experience = {
			value = mandala_contract_piety
			multiply = -1.5
		}
		add_legitimacy = {
			value = mandala_contract_legitimacy
			multiply = -1.5
		}
	}
}


change_to_mandala_interaction_effect = {
	scope:actor = {
		pay_short_term_gold = {
			target = scope:recipient
			gold = {
				value = 50
				scope:recipient = {
					if = {
						limit = { highest_held_title_tier >= tier_kingdom }
						multiply = 10
					}
					else_if = {
						limit = { highest_held_title_tier >= tier_duchy }
						multiply = 6
					}
					else_if = {
						limit = { highest_held_title_tier >= tier_county }
						multiply = 3
					}
				}
				if = {
					limit = { scope:gold ?= yes }
					add = scope:actor.medium_gold_value
				}
			}
		}
	}
	scope:recipient = { change_to_mandala_government_and_citadel_effect = yes }
	if = {
		limit = {
			scope:hook = yes
			scope:actor = { has_usable_hook = scope:recipient }
		}
		scope:actor = { use_hook = scope:recipient }
	}
	if = {
		limit = { scope:piety = yes }
		scope:actor = {
			add_piety = {
				value = {
					subtract = piety_bribe_value
				}
			}
		}
	}
}


mandala_no_longer_polytheist_effect = {
	if = {
		limit = { 
			government_has_flag = government_is_mandala
			faith = { 
				NOT = { has_doctrine = doctrine_polytheist }
			}
		}
		convert_whole_realm_to_feudalism_effect = yes
		hidden_effect = {
			every_vassal = {
				trigger_event = {
					id = major_decisions.0002
					days = 3
				}
			}
		}
		every_tributary = { end_tributary = yes }
	}
}


#Remember to set wealth and quality beforehand
create_bunga_mas_artifact_effect = {
	hidden_effect_new_object = {
		create_artifact = {
			name = bunga_mas
			description = common_bunga_mas_desc
			modifier = artifact_placeholder_modifier
			wealth = scope:wealth
			quality = scope:quality
			type = pedestal
			visuals = bunga_mas
			save_scope_as = newly_created_bunga_mas
		}
	}
}


### STORY CYCLE
mandala_story_go_on_pilgrimage_effect = {
	if = {
		limit = { can_host_activity = activity_pilgrimage }
		ai_attempt_to_host_activity = activity_pilgrimage
	}
	else = {
		move_budget_gold = { gold = short_term_gold from = budget_war_chest to = budget_short_term }
		move_budget_gold = { gold = long_term_gold from = budget_long_term to = budget_short_term }
	}
}

mandala_story_creation_aspect_get_kids_effect = {
	if = {
		limit = {
			is_adult = yes
			is_available = yes 
		}
		if = {
			limit = { is_female = no }
			if = {
				limit = {
					any_consort = {
						is_adult = yes
						is_available = yes	
						fertility > 0
						is_pregnant = no
					}
				}
				random_consort = {
					limit = {
						is_adult = yes
						is_available = yes	
						fertility > 0
						is_pregnant = no
					}
					make_pregnant = { father = scope:root_scope }
				}
			}
		}
		if = {
			limit = { is_female = yes }
			if = {
				limit = {
					is_pregnant = no
					any_consort = { 
						is_adult = yes
						is_available = yes
						fertility > 0
					}
				}
				random_consort = {
					limit = {
						is_adult = yes
						is_available = yes
						fertility > 0
					}
					scope:root_scope = { 
						make_pregnant = { father = prev }
					}
				}
			}
		}
	}
}

mandala_story_serenity_aspect_befriend_effect = {
	if = {
		limit = {
			any_courtier = {
				can_set_relation_friend_trigger = { CHARACTER = scope:root_scope }
			}
			any_vassal = {
				can_set_relation_friend_trigger = { CHARACTER = scope:root_scope }
			}
		}
		every_courtier = {
			limit = {
				can_set_relation_friend_trigger = { CHARACTER = scope:root_scope }
			}
			add_to_list = serenity_potential_friends
		}
		every_vassal = {
			limit = {
				can_set_relation_friend_trigger = { CHARACTER = scope:root_scope }
			}
			add_to_list = serenity_potential_friends
		}
		ordered_in_list = {
			list = serenity_potential_friends
			order_by = "opinion(scope:root_scope)"
			random = {
				chance = 10
				set_relation_friend = scope:root_scope
			}
		}
	}
	else = {
		mandala_story_befriend_scheme_effect = yes
	}
}

mandala_story_befriend_scheme_effect = {
	if = {
		limit = {
			OR = {
				house = { has_house_head_parameter = unlock_befriend_scheme }
				has_perk = befriend_perk
			}
			OR = {
				NOT = {
					any_scheme = {
						OR = {
							scheme_type = befriend
							scheme_type = sway
							scheme_type = seduce
							scheme_type = courting
							scheme_type = elope
							scheme_type = learn_language
						}
					}
				}
				AND = {
					OR = {
						dynasty ?= { has_dynasty_perk = glory_legacy_5 }
						AND = {
							has_royal_court = yes
							has_dlc_feature = royal_court
							has_court_type = court_diplomatic
							court_grandeur_current_level >= 10
						}
					}
					any_scheme = {
						count < 2
						OR = {
							scheme_type = befriend
							scheme_type = sway
							scheme_type = seduce
							scheme_type = courting
							scheme_type = elope
							scheme_type = learn_language
						}
					}
				}
				AND = {
					dynasty ?= { has_dynasty_perk = glory_legacy_5 }
					has_royal_court = yes
					has_dlc_feature = royal_court
					has_court_type = court_diplomatic
					court_grandeur_current_level >= 10
					any_scheme = {
						count < 3
						OR = {
							scheme_type = befriend
							scheme_type = sway
							scheme_type = seduce
							scheme_type = courting
							scheme_type = elope
							scheme_type = learn_language
						}
					}
				}
			}
		}
		every_courtier = {
			limit = {
				has_council_position = councillor_spymaster
				opinion = {
					target = scope:root_scope
					value < 100
				}
				save_temporary_scope_as = courtier_check
				scope:root_scope = {
					can_start_scheme = {
						type = befriend
						target_character = scope:courtier_check
					}
				}
			}
			add_to_list = befriend_targets
		}
		every_tributary = {
			limit = {
				opinion = {
					target = scope:root_scope
					value < 100
				}
				save_temporary_scope_as = tributary_check
				scope:root_scope = {
					can_start_scheme = {
						type = befriend
						target_character = scope:tributary_check
					}
				}
			}
			add_to_list = befriend_targets
		}
		every_vassal = {
			limit = {
				highest_held_title_tier >= tier_county
				opinion = {
					target = scope:root_scope
					value < 100
				}
				save_temporary_scope_as = vassal_check
				scope:root_scope = {
					can_start_scheme = {
						type = befriend
						target_character = scope:vassal_check
					}
				}
			}
			add_to_list = befriend_targets
		}
		every_neighboring_and_across_water_top_liege_realm_owner = {
			limit = {
				highest_held_title_tier >= tier_county
				opinion = {
					target = scope:root_scope
					value < 100
				}
				save_temporary_scope_as = ruler_check
				scope:root_scope = {
					can_start_scheme = {
						type = befriend
						target_character = scope:ruler_check
					}
				}
			}
			every_tributary = {
				limit = {
					highest_held_title_tier >= tier_county
					opinion = {
						target = scope:root_scope
						value < 100
					}
					save_temporary_scope_as = ruler_tributary_check
					scope:root_scope = {
						can_start_scheme = {
							type = befriend
							target_character = scope:ruler_tributary_check
						}
					}
				}
				add_to_list = befriend_targets
			}
			add_to_list = befriend_targets
		}
		random_in_list = {
			list = befriend_targets
			limit = {
				save_temporary_scope_as = befriend_check
				NOT = {
					scope:root_scope = {
						any_scheme = {
							is_hostile = yes
							scheme_target_character = scope:befriend_check
						}
					}
				}
			}
			weight = {
				base = 1
				modifier = {
					add = 10
					opinion = {
						target = scope:root_scope
						value < 100
					}
				}
				modifier = {
					is_tributary = no
					add = 150
				}
				modifier = {
					OR = {
						realm_size <= scope:root_scope.realm_size
						primary_title.tier <= scope:root_scope.primary_title.tier
					}
					add = 250
				}
				modifier = {
					primary_title ?= { is_neighbor_to_realm = scope:root_scope }
					add = 250
				}
				modifier = {
					scope:root_scope = {
						is_character_interaction_potentially_accepted = {
							recipient = prev
							interaction = offer_tributary_status_interaction
							ai_accept = -30
						}
					}
					add = 1000
				}
			}
			save_scope_as = befriend_target
		}
		if = {
			limit = { exists = scope:befriend_target }
			start_scheme = {
				type = befriend
				target_character = scope:befriend_target
			}
		}
	}
}

mandala_story_destruction_aspect_declare_war_effect = {
	if = {
		limit = {
			is_at_war = no
			war_chest_gold >= war_chest_gold_maximum
		}
		add_stress = major_stress_loss
		ai_start_best_war = {
			cb = { 
				make_tributary_cb
				mandala_raze_capital_structure_cb
			}
			is_valid = {
				scope:target_character = {
					current_military_strength < root.current_military_strength
					OR = {
						gold < root.gold
						current_military_strength <= root.fifty_percent_of_current_military_strength
					}
				}
			}
		}
	}	
}

mandala_story_destruction_aspect_buff_skill_effect = {
	random = {
		chance = 30
		add_$SKILL$_skill = 1
	}
}
