#Mandala Capital Events

namespace = tgp_east_asia_mandala_capital_events

tgp_east_asia_mandala_capital_events.1000 = {
	type = character_event
	window = big_event_window
	title = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:great_project = { great_project_type = mandala_capital_05 } 
				}
				desc = tgp_east_asia_mandala_capital_events.1000.t.final
			}
			triggered_desc = {
				trigger = {
					scope:great_project = { great_project_type = mandala_capital_04 } 
				}
				desc = tgp_east_asia_mandala_capital_events.1000.t.fourth
			}
			triggered_desc = {
				trigger = {
					scope:great_project = { great_project_type = mandala_capital_03 } 
				}
				desc = tgp_east_asia_mandala_capital_events.1000.t.third
			}
			triggered_desc = {
				trigger = {
					scope:great_project = { great_project_type = mandala_capital_02 } 
				}
				desc = tgp_east_asia_mandala_capital_events.1000.t.second
			}
			desc = tgp_east_asia_mandala_capital_events.1000.t
		}
	}
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:great_project = { great_project_type = mandala_capital_05 } 
				}
				desc = tgp_east_asia_mandala_capital_events.1000.desc.final
			}
			triggered_desc = {
				trigger = {
					scope:great_project = { great_project_type = mandala_capital_04 } 
				}
				desc = tgp_east_asia_mandala_capital_events.1000.desc.fourth
			}
			triggered_desc = {
				trigger = {
					scope:great_project = { great_project_type = mandala_capital_03 } 
				}
				desc = tgp_east_asia_mandala_capital_events.1000.desc.third
			}
			triggered_desc = {
				trigger = {
					scope:great_project = { great_project_type = mandala_capital_02 } 
				}
				desc = tgp_east_asia_mandala_capital_events.1000.desc.second
			}
			desc = tgp_east_asia_mandala_capital_events.1000.desc
		}
	}
	theme = mandala
	left_portrait = {
		character = scope:onlooker
		animation = admiration
	}
	center_portrait = {
		character = root
		animation = personality_zealous
	}
	right_portrait = {
		character = scope:onlooker_2
		camera = camera_event_scheme_vs_center_positioned_left
		animation = ecstasy
	}
	override_effect_2d = { reference = legend_glow }
	immediate = {
		mandala_owner_reward_01_effect = yes
		scope:province = { save_scope_as = project_location }
		#Grab some characters who are celebrating and excited
		random_courtier = {
			limit = { 
				is_available_adult = yes
				this != root
			}
			save_scope_as = onlooker
		}
		if = {
			limit = {
				NOT = { exists = scope:onlooker }
			}
			random_pool_character = {
				province = root.capital_province
				limit = { is_available_adult = yes }
				save_scope_as = onlooker
			}
		}
		random_courtier = {
			limit = { 
				is_available_adult = yes
				this != root
				this != scope:onlooker
			}
			save_scope_as = onlooker_2
		}
		if = {
			limit = {
				NOT = { exists = scope:onlooker_2 }
			}
			random_pool_character = {
				province = root.capital_province
				limit = { is_available_adult = yes }
				save_scope_as = onlooker_2
			}
		}	
	}
	#Run effects
	option = { 
		name = {
			text = {
				first_valid = {
					triggered_desc = {
						trigger = {
							scope:great_project = { great_project_type = mandala_capital_05 } 
						}
						desc = tgp_east_asia_mandala_capital_events.1000.a.final
					}
					triggered_desc = {
						trigger = {
							scope:great_project = { great_project_type = mandala_capital_04 } 
						}
						desc = tgp_east_asia_mandala_capital_events.1000.a.fourth
					}
					triggered_desc = {
						trigger = {
							scope:great_project = { great_project_type = mandala_capital_03 } 
						}
						desc = tgp_east_asia_mandala_capital_events.1000.a.third
					}
					triggered_desc = {
						trigger = {
							scope:great_project = { great_project_type = mandala_capital_02 } 
						}
						desc = tgp_east_asia_mandala_capital_events.1000.a.second
					}
					desc = tgp_east_asia_mandala_capital_events.1000.a
				}
			}
		}		
		#Did you contribute something?
		if = {
			limit = { 
				scope:great_project = { great_project_type = mandala_capital_01 } 
			}
			check_and_reward_contributions_01_effect = yes
		}
		if = {
			limit = { 
				scope:great_project = { great_project_type = mandala_capital_02 } 
			}
			check_and_reward_contributions_02_effect = yes
		}
		if = {
			limit = { 
				scope:great_project = { great_project_type = mandala_capital_03 } 
			}
			check_and_reward_contributions_03_effect = yes
		}
		if = {
			limit = { 
				scope:great_project = { great_project_type = mandala_capital_04 } 
			}
			check_and_reward_contributions_04_effect = yes
		}
		if = {
			limit = { 
				scope:great_project = { great_project_type = mandala_capital_05 } 
			}
			check_and_reward_contributions_05_effect = yes
		}
	}
}

tgp_east_asia_mandala_capital_events.1010 = {
	type = character_event
	window = big_event_window
	title = tgp_east_asia_mandala_capital_events.1010.t
	desc = tgp_east_asia_mandala_capital_events.1010.desc
	theme = mandala
	left_portrait = {
		character = root
		triggered_animation = {
			trigger = { ai_honor <= 0 }
			animation = scheme
		}
		animation = personality_compassionate
	}
	right_portrait = {
		character = scope:envoy
		animation = obsequious_bow
	}
	lower_right_portrait = {
		character = scope:overlord_scope
	}
	immediate = {
		scope:owner = { 
			save_scope_as = overlord_scope
			save_scope_as = value_target
		}
		scope:province = { save_scope_as = project_location }
		create_character = {
			template = travel_messenger
			location = root.location
			culture = scope:overlord_scope.location.culture
			faith = scope:overlord_scope.location.faith
			gender_female_chance = scope_value_target_soldier_female_chance
			save_scope_as = envoy
		}
	}
	#Run effects
	option = { 
		name = tgp_east_asia_mandala_capital_events.1010.a
		#Did you contribute something?
		if = {
			limit = { 
				scope:great_project = { great_project_type = mandala_capital_01 } 
			}
			check_and_reward_contributions_01_effect = yes
		}
		if = {
			limit = { 
				scope:great_project = { great_project_type = mandala_capital_02 } 
			}
			check_and_reward_contributions_02_effect = yes
		}
		if = {
			limit = { 
				scope:great_project = { great_project_type = mandala_capital_03 } 
			}
			check_and_reward_contributions_03_effect = yes
		}
		if = {
			limit = { 
				scope:great_project = { great_project_type = mandala_capital_04 } 
			}
			check_and_reward_contributions_04_effect = yes
		}
		if = {
			limit = { 
				scope:great_project = { great_project_type = mandala_capital_05 } 
			}
			check_and_reward_contributions_05_effect = yes
		}
		#Get some opinion
		if = {
			limit = {
				scope:overlord_scope = { is_ai = yes }
			}
			mandala_contributor_opinion_reward_effect = { OVERLORD = scope:overlord_scope }
		}
	}
	#Sweep, sweep
	after = {
		scope:envoy = {
			if = { # Cleanup
				limit = {
					root = { is_ai = yes }
					is_courtier = no
				}
				silent_disappearance_effect = yes
			}
		}
	}
}
