﻿# Ceremony Options on_start
COR_ceremony_normal_option_effect = {
	scope:host = {
		if = {
			limit = {
				any_vassal = {
					OR = {
						has_vassal_stance = parochial
						has_vassal_stance = zealot
					}
				}
			}
			every_vassal = {
				limit = {
					OR = {
						has_vassal_stance = parochial
						has_vassal_stance = zealot
					}
				}
				add_opinion = {
					target = scope:host
					modifier = COR_ceremony_balanced_option_opinion
				}
			}
		}
	}
}

COR_ceremony_good_option_effect = {
	scope:host = {
		if = {
			limit = {
				any_vassal = {
					OR = {
						has_vassal_stance = courtly
						has_vassal_stance = glory_hound
					}
				}
			}
			every_vassal = {
				limit = {
					OR = {
						has_vassal_stance = courtly
						has_vassal_stance = glory_hound
					}
				}
				add_opinion = {
					target = scope:host
					modifier = COR_ceremony_good_option_opinion
				}
			}
		}
	}
}

# Log Entry
COR_ceremony_completed_log_entry_effect = {
	scope:activity = {
		add_activity_log_entry = {
			key = COR_ceremony_completed_log
			tags = { completed }
			# this line below adds the entry to the Effects section of the conclusion UI
			show_in_conclusion = yes
			character = root
			custom_tooltip = COR_ceremony_result_gained_piety
			custom_tooltip = COR_ceremony_result_gained_prestige
			custom_tooltip = COR_ceremony_result_gained_dynasty_prestige
			show_as_tooltip = {
				every_attending_character = {
					limit = { NOT = { this = scope:host } }
					custom = EVERY_ACTIVITY_PARTICIPANT_EFFECT
					custom_tooltip = COR_ceremony_result_gained_piety
					custom_tooltip = COR_ceremony_result_gained_prestige
				}
			}
		}
	}
}

# Activity Rewards
COR_tooltip_disburse_ceremony_host_activity_rewards = {
	scope:activity = {
		### Rewards based on Options
		# Gain nothing for private ceremony
		if = {
			limit = {
				NOT = {
					OR = {
						AND = {
							has_activity_type = COR_activity_coronation_ceremony
							has_activity_option = {
								category = COR_ceremony_type
								option = COR_ceremony_type_private
							}
						}
						AND = {
							has_activity_type = COR_activity_coronation_ceremony_hof
							has_activity_option = {
								category = COR_ceremony_type
								option = COR_ceremony_type_private
							}
						}
					}
				}
			}
			# Entertainment
			if = {
				limit = {
					has_activity_option = {
						category = COR_ceremony_option_entertainment
						option = COR_ceremony_entertainment_good
					}
				}
				root = { add_prestige = 600 }
				every_attending_character = {
					limit = {
						NOT = { this = scope:host }
					}
					custom = custom.every_activity_guest
					add_prestige = medium_prestige_gain
				}
			}
			else_if = {
				limit = {
					has_activity_option = {
						category = COR_ceremony_option_entertainment
						option = COR_ceremony_entertainment_normal
					}
				}
				root = { add_prestige = 400 }
				every_attending_character = {
					limit = {
						NOT = { this = scope:host }
					}
					custom = custom.every_activity_guest
					add_prestige = minor_prestige_gain
				}
			}
			else_if = {
				limit = {
					has_activity_option = {
						category = COR_ceremony_option_entertainment
						option = COR_ceremony_entertainment_bad
					}
				}
				root = { add_prestige = 200 }
			}
			if = {
				limit = {
					has_activity_option = {
						category = COR_ceremony_option_food
						option = COR_ceremony_food_good
					}
				}
				every_attending_character = {
					limit = { NOT = { this = root } }
					custom = custom.every_activity_guest
					add_opinion = {
						target = root
						modifier = impressed_opinion
						opinion = 10
					}
				}
			}
			else_if = {
				limit = {
					has_activity_option = {
						category = COR_ceremony_option_food
						option = COR_ceremony_food_normal
					}
				}
				every_attending_character = {
					limit = { NOT = { this = root } }
					custom = custom.every_activity_guest
					add_opinion = {
						target = root
						modifier = impressed_opinion
						opinion = 5
					}
				}
			}
			if = {
				limit = {
					has_activity_option = {
						category = COR_ceremony_option_decoration
						option = COR_ceremony_decoration_good
					}
				}
				root = {
					add_character_modifier = {
						modifier = COR_ceremony_magnificent_host_modifier
						years = 10
					}
					if = {
						limit = {
							any_vassal = {
								has_vassal_stance = courtly
							}
						}
						every_vassal = {
							limit = { has_vassal_stance = courtly }
							custom = COR_every_courtly_vassal
							add_opinion = {
								modifier = COR_hosted_ceremony_opinion
								target = root
								opinion = 10
							}
						}
					}
				}
			}
			else_if = {
				limit = {
					has_activity_option = {
						category = COR_ceremony_option_decoration
						option = COR_ceremony_decoration_normal
					}
				}
				root = {
					add_character_modifier = {
						modifier = COR_ceremony_gracious_host_modifier
						years = 5
					}
					if = {
						limit = {
							any_vassal = {
								has_vassal_stance = courtly
							}
						}
						every_vassal = {
							limit = { has_vassal_stance = courtly }
							custom = COR_every_courtly_vassal
							add_opinion = {
								modifier = COR_hosted_ceremony_opinion
								target = root
								opinion = 5
							}
						}
					}
				}
			}
		}
		if = {
			limit = {
				scope:COR_ceremony_venue = {
					barony = title:b_roma
				}
			}		
			root = {
				add_piety = major_piety_gain
			}
		}
		else_if = {
			limit = {
				scope:COR_ceremony_venue = {
					OR = {
						COR_location_has_cathedral_trigger = yes
						barony = { is_holy_site_of = scope:host.faith }
					}
				}
			}	
			root = {
				add_piety = medium_piety_gain
			}
		}

		# HRT_italienzug
		if = {
			limit = {
				has_activity_type = activity_HRT_italienzug
			}
			if = {
				limit = {
					has_activity_option = {
						category = HRT_italienzug_expedition_type
						option = HRT_italienzug_expedition_type_grand
					}
				}
				root = {
					add_prestige = 600
					add_piety = 300
					dynasty = { add_dynasty_prestige = major_dynasty_prestige_gain }
				}
			}
			else_if = {
				limit = {
					has_activity_option = {
						category = HRT_italienzug_expedition_type
						option = HRT_italienzug_expedition_type_normal
					}
				}
				root = {
					add_prestige = 400
					add_piety = 200
					dynasty = { add_dynasty_prestige = medium_dynasty_prestige_gain }
				}
			}
			else_if = {
				limit = {
					has_activity_option = {
						category = HRT_italienzug_expedition_type
						option = HRT_italienzug_expedition_type_small
					}
				}
				root = {
					add_prestige = 200
					add_piety = 100
					dynasty = { add_dynasty_prestige = minor_dynasty_prestige_gain }
				}
			}

			#Intents
			if = {
				limit = {
					has_activity_intent = HRT_glory_intent
				}
				add_prestige = major_prestige_gain
				stress_impact = {
					zealous = minor_stress_impact_loss
					humble = minor_stress_impact_loss
				}
			}
			else_if = {
				limit = {
					has_activity_intent = HRT_submission_intent
				}
				add_piety = major_piety_gain
				stress_impact = {
					arrogant = minor_stress_impact_loss
					ambitious = minor_stress_impact_loss
				}
			}
		}
	}
	root.dynasty ?= { add_dynasty_prestige = minor_dynasty_prestige_gain }
	# If character had the reduce stress intent, give them stress loss
	root = { disburse_activity_stress_loss = yes }
	scope:activity = {
		every_attending_character = {
			limit = {
				NOT = { this = scope:host }
			}
			custom = custom.every_activity_guest
			disburse_activity_stress_loss = yes
		}
	}

	# Accolade glory gain
	every_attending_character = {
		limit = {
			is_knight_of = root
			is_acclaimed = yes
		}
		accolade = { add_glory = minor_glory_gain }
	}
}

COR_uncrowned_legitimacy_effect = {
	if = {
		limit = {
			is_ai = no
			is_valid_for_legitimacy_change = yes
		}
		if = {
			limit = { var:COR_years_reigned = 5 }
			send_interface_toast = {
				type = event_toast_effect_bad
				title = legitimacy_loss_toast
				left_icon = root
				add_legitimacy = miniscule_legitimacy_loss
				custom_tooltip = COR_uncrowned_legitimacy_effect.toast
			}
		}
		else_if = {
			limit = {
				OR = {
					var:COR_years_reigned = 10
					var:COR_years_reigned = 15
				}
			}
			send_interface_toast = {
				type = event_toast_effect_bad
				title = legitimacy_loss_toast
				left_icon = root
				add_legitimacy = minor_legitimacy_loss
				custom_tooltip = COR_uncrowned_legitimacy_effect.toast
			}
		}
		else_if = {
			limit = {
				OR = {
					var:COR_years_reigned = 20
					var:COR_years_reigned = 25
				}
			}
			send_interface_toast = {
				type = event_toast_effect_bad
				title = legitimacy_loss_toast
				left_icon = root
				add_legitimacy = medium_legitimacy_loss
				custom_tooltip = COR_uncrowned_legitimacy_effect.toast
			}
		}
		else_if = {
			limit = { var:COR_years_reigned = 30 }
			send_interface_toast = {
				type = event_toast_effect_bad
				title = legitimacy_loss_toast
				left_icon = root
				add_legitimacy = major_legitimacy_loss
				custom_tooltip = COR_uncrowned_legitimacy_effect.toast
			}
		}
	}
}