#################################
# Embellish Capital 			#
# By Ola Jentzsch 				#
# Reworked by Chad Uhl 			#
#################################

### Embellish Capital ###
fp3_embellish_capital_decision = {
	title = fp3_embellish_capital_decision_name
	picture = {
		trigger = {
			culture = { has_graphical_japanese_culture_group_trigger = yes }
		}
		reference = "gfx/interface/illustrations/event_scenes/tgp_japanese_city.dds"
	}
	picture = {
		trigger = {
			culture = { has_graphical_east_asia_culture_group_trigger = yes }
		}
		reference = "gfx/interface/illustrations/decisions/tgp_great_project.dds"
	}
	picture = {
		reference = "gfx/interface/illustrations/decisions/decision_golden_age.dds"
	}
	desc = fp3_embellish_capital_decision.desc
	selection_tooltip = fp3_embellish_capital_decision_tooltip 
	cooldown = { years = 30 }
	sort_order = 150

	is_shown = {
		dynasty ?= {
			has_dynasty_perk = fp3_khvarenah_legacy_5
		}
		exists = capital_county
	}

	is_valid = {
		OR = {
			custom_tooltip = {
				text = recently_conquered_land_tooltip	
				any_held_county = {
					this != this.holder.top_liege.capital_county 
					recent_history = {
						type = conquest
						years = 10
					}
				}
			}
			short_term_gold >= embellish_capital_gold_cost
		}
	}

	is_valid_showing_failures_only = {
		is_available_at_peace_adult = yes
		OR = {
			# At least one of the decision options is available 
			employs_court_position = royal_architect_court_position
			any_consort = { fp3_embellish_capital_decision_character_trigger = yes }
			any_courtier = { fp3_embellish_capital_decision_character_trigger = yes }
			cp:councillor_court_chaplain ?= { fp3_embellish_capital_decision_character_trigger = yes }
		}
	}

	cost = {
		gold = {
			value = 0
			if = {
				limit = {
					NOR = {
						has_treasury = yes
						any_held_county = {
							NOT = { this = this.holder.top_liege.capital_county } 
							recent_history = {
								type = conquest
								years = 10
							}
						}
					}
				}
				add = embellish_capital_gold_cost
			}
		}
		treasury = {
			value = 0
			if = {
				limit = {
					has_treasury = yes
					NOT = {
						any_held_county = {
							NOT = { this = this.holder.top_liege.capital_county } 
							recent_history = {
								type = conquest
								years = 10
							}
						}
					}
				}
				add = embellish_capital_gold_cost
			}
		}
	}

	widget = {
		gui = "decision_view_widget_option_list_generic"
		controller = decision_option_list_controller
		decision_to_second_step_button = "CHOOSE_ARCHITECT_DECISION_NEXT_STEP_BUTTON"

		### Royal Architect 
		# Mausoleum
		# Refurbish Residence
		# Baths and Fountains
		item = {
			value = embellish_capital_royal_architect
			is_valid = {
				employs_court_position = royal_architect_court_position
				trigger_if = {
					limit = { employs_court_position = royal_architect_court_position }
					court_position:royal_architect_court_position = {
						fp3_embellish_capital_decision_character_trigger = yes
					}
				}
			}
			localization = embellish_capital_option_royal_architect
			icon = "gfx/interface/icons/message_feed/building.dds"
			ai_chance = {
				value = 100
			}
		}

		#### Courtier
		# Hammam 
		# Temple 
		# Palace
		item = {
			value = embellish_capital_consort_courtier
			is_valid = {
				OR = {
					any_consort = {
						fp3_embellish_capital_decision_character_trigger = yes
						NOR = {
							trigger_if = {
								limit = {
									root = { employs_court_position = royal_architect_court_position }
								}
								has_court_position = royal_architect_court_position
							}
							is_councillor_of = root
						}
					}
					any_courtier = {
						fp3_embellish_capital_decision_character_trigger = yes
						NOR = {
							trigger_if = {
								limit = {
									root = { employs_court_position = royal_architect_court_position }
								}
								has_court_position = royal_architect_court_position
							}
							is_councillor_of = root
						}
					}
				}
			}
			localization = embellish_capital_option_consort_courtier
			icon = "gfx/interface/icons/message_feed/council.dds"
			ai_chance = {
				value = 90
			}
		}
		
		#### Chaplain 
		# Temple
		# Dakhma
		# Madrasa 
		# Fresco
		item = {
			value = embellish_capital_chaplain
			is_valid = {
				cp:councillor_court_chaplain ?= { fp3_embellish_capital_decision_character_trigger = yes }
			}
			localization = embellish_capital_option_chaplain
			icon = "gfx/interface/icons/message_feed/religious.dds"
			ai_chance = {
				value = 70
				if = {
					limit = {
						has_trait = zealous
					}
					add = 30
				}
			}
		}

		#### Me
		# Monument to myself
		item = {
			value = embellish_capital_me
			is_valid = {
				is_available_adult = yes 
			}
			localization = embellish_capital_option_me
			icon = "gfx/interface/icons/character_interactions/icon_scheme_claim_throne.dds"
			ai_chance = {
				value = 60
				if = {
					limit = {
						has_trait = arrogant
					}
					add = 50
				}
			}
		}
	}

	effect = {
		custom_tooltip = fp3_embellish_capital_decision_effects.tt
		hidden_effect = {
			save_scope_as = root_scope # For custom tooltips within the event chain
			capital_county = { save_scope_as = capital_county }
			capital_province = { save_scope_as = capital_province }
			if = { # Case: You don't have the gold but you do have the recently conquered county
				limit = {
					any_held_county = {
						this != this.holder.top_liege.capital_county 
						recent_history = {
							type = conquest
							years = 10
						}
					}
					NOT = {
						short_term_gold >= embellish_capital_gold_cost
					}
				}
				random_held_county = {
					limit = {
						this != this.holder.top_liege.capital_county
						recent_history = {
							type = conquest 
							years = 10
						}
					}
					save_scope_as = target_county 
				}
				# Fire the event based on the option selected
				if = { # Royal Architect
					limit = { scope:embellish_capital_royal_architect = yes }
					random_court_position_holder = {
						type = royal_architect_court_position
						limit = { fp3_embellish_capital_decision_character_trigger = yes }
						save_scope_as = chosen_architect
					}
					trigger_event = {
						id = fp3_dynasty_decision.0004
						days = { 3 10 }
					}
				}
				else_if = { # Consort or Courtier
					limit = { scope:embellish_capital_consort_courtier = yes }
					random_list = {
						1 = {
							trigger = {
								any_consort = {
									count >= 1
									fp3_embellish_capital_decision_character_trigger = yes
									NOR = {
										has_court_position = royal_architect_court_position
										is_councillor_of = root
									}
								}
							}
							random_consort = {
								limit = {
									fp3_embellish_capital_decision_character_trigger = yes
									NOR = {
										has_court_position = royal_architect_court_position
										is_councillor_of = root
									}
								}
								weight = {
									base = 1
									compare_modifier = {
										value = stewardship
										multiplier = 0.25
									}
									modifier = {
										has_trait = lazy 
										add = -50	
									}

									modifier = {
										OR = {
											has_trait = administrator 
											has_trait = architect
											has_trait = scholar 
											has_trait = lifestyle_gardener 
											has_trait = overseer
										}
										add = 50
									}
								}
								save_scope_as = chosen_architect
							}
						}
						1 = {
							trigger = {
								any_courtier = {
									count >= 1
									fp3_embellish_capital_decision_character_trigger = yes
									NOR = {
										has_court_position = royal_architect_court_position
										is_councillor_of = root
									}
								}
							}
							random_courtier = {
								limit = {
									fp3_embellish_capital_decision_character_trigger = yes
									NOR = {
										has_court_position = royal_architect_court_position
										is_councillor_of = root
									}
								}
								weight = {
									base = 1
									compare_modifier = {
										value = stewardship
										multiplier = 0.25
									}
									modifier = {
										has_trait = lazy 
										add = -50	
									}

									modifier = {
										OR = {
											has_trait = administrator 
											has_trait = architect
											has_trait = scholar 
											has_trait = lifestyle_gardener 
											has_trait = overseer
										}
										add = 50
									}
								}
								save_scope_as = chosen_architect
							}
						}
					}
					trigger_event = {
						id = fp3_dynasty_decision.0005
						days = { 3 10 }
					}
				}
				else_if = { # Court Chaplain
					limit = { scope:embellish_capital_chaplain = yes }
					cp:councillor_court_chaplain = { save_scope_as = chosen_architect }
					trigger_event = {
						id = fp3_dynasty_decision.0007
						days = { 3 10 }
					}
				}
				else_if = { # Me
					limit = { scope:embellish_capital_me = yes }
					save_scope_as = chosen_architect 
					trigger_event = {
						id = fp3_dynasty_decision.0008
						days = { 3 10 }
					}
				}
			}
			else_if = { # Case: you have the gold but not the recently conquered county 
				limit = {
					short_term_gold >= embellish_capital_gold_cost
					NOT = {
						any_held_county = {
							this != this.holder.top_liege.capital_county 
							recent_history = {
								type = conquest
								years = 10
							}
						}
					}
				}
				set_variable = {
					name = embellish_capital_cost
					value = embellish_capital_gold_cost
				}
				# Fire the event based on the option selected
				if = { # Royal Architect
					limit = { scope:embellish_capital_royal_architect = yes }
					random_court_position_holder = {
						type = royal_architect_court_position
						limit = { fp3_embellish_capital_decision_character_trigger = yes }
						save_scope_as = chosen_architect
					}
					trigger_event = {
						id = fp3_dynasty_decision.0004
						days = { 3 10 }
					}
				}
				else_if = { # Consort or Courtier
					limit = { scope:embellish_capital_consort_courtier = yes }
					random_list = {
						1 = {
							trigger = {
								any_consort = {
									count >= 1
									fp3_embellish_capital_decision_character_trigger = yes
									NOR = {
										has_court_position = royal_architect_court_position
										is_councillor_of = root
									}
								}
							}
							random_consort = {
								limit = {
									fp3_embellish_capital_decision_character_trigger = yes
									NOR = {
										has_court_position = royal_architect_court_position
										is_councillor_of = root
									}
								}
								weight = {
									base = 1
									compare_modifier = {
										value = stewardship
										multiplier = 0.25
									}
									modifier = {
										has_trait = lazy 
										add = -50	
									}

									modifier = {
										OR = {
											has_trait = administrator 
											has_trait = architect
											has_trait = scholar 
											has_trait = lifestyle_gardener 
											has_trait = overseer
										}
										add = 50
									}
								}
								save_scope_as = chosen_architect
							}
						}
						1 = {
							trigger = {
								any_courtier = {
									count >= 1
									fp3_embellish_capital_decision_character_trigger = yes
									NOR = {
										has_court_position = royal_architect_court_position
										is_councillor_of = root
									}
								}
							}
							random_courtier = {
								limit = {
									fp3_embellish_capital_decision_character_trigger = yes
									NOR = {
										has_court_position = royal_architect_court_position
										is_councillor_of = root
									}
								}
								weight = {
									base = 1
									compare_modifier = {
										value = stewardship
										multiplier = 0.25
									}
									modifier = {
										has_trait = lazy 
										add = -50	
									}

									modifier = {
										OR = {
											has_trait = administrator 
											has_trait = architect
											has_trait = scholar 
											has_trait = lifestyle_gardener 
											has_trait = overseer
										}
										add = 50
									}
								}
								save_scope_as = chosen_architect
							}
						}
					}
					trigger_event = {
						id = fp3_dynasty_decision.0005
						days = { 3 10 }
					}
				}
				else_if = { # Court Chaplain
					limit = { scope:embellish_capital_chaplain = yes }
					cp:councillor_court_chaplain = { save_scope_as = chosen_architect }
					trigger_event = {
						id = fp3_dynasty_decision.0007
						days = { 3 10 }
					}
				}
				else_if = { # Me
					limit = { scope:embellish_capital_me = yes }
					save_scope_as = chosen_architect 
					trigger_event = {
						id = fp3_dynasty_decision.0008
						days = { 3 10 }
					}
				}
				scope:chosen_architect = {
						add_opinion = {
							target = root
							modifier = trusted_me_opinion
							opinion = 10
						}
					}
			}
			else = { # Case: You have both the gold and the recently conquered county, so we let you choose how to pay
				# Save the gold value for refund purposes. Deleted later if you choose to pay by pillaging the recently conquered county
				set_variable = {
					name = embellish_capital_cost
					value = embellish_capital_gold_cost
				}
				# Save architect scope and give opinion
				if = { # Royal Architect
					limit = { scope:embellish_capital_royal_architect = yes }
					random_court_position_holder = {
						type = royal_architect_court_position
						limit = { fp3_embellish_capital_decision_character_trigger = yes }
						save_scope_as = chosen_architect
					}
				}
				else_if = { # Consort or Courtier
					limit = { scope:embellish_capital_consort_courtier = yes }
					random_list = {
						1 = {
							trigger = {
								any_consort = {
									count >= 1
									fp3_embellish_capital_decision_character_trigger = yes
								}
							}
							random_consort = {
								limit = { fp3_embellish_capital_decision_character_trigger = yes }
								save_scope_as = chosen_architect
							}
						}
						1 = {
							trigger = {
								any_courtier = {
									count >= 1
									fp3_embellish_capital_decision_character_trigger = yes
								}
							}
							random_courtier = {
								limit = { fp3_embellish_capital_decision_character_trigger = yes }
								save_scope_as = chosen_architect
							}
						}
					}
				}
				else_if = { # Court Chaplain
					limit = { scope:embellish_capital_chaplain = yes }
					cp:councillor_court_chaplain = { save_scope_as = chosen_architect }
				}
				else_if = { # Me
					limit = { scope:embellish_capital_me = yes }
					save_scope_as = chosen_architect 
				}
				random_held_county = {
					limit = {
						this != this.holder.top_liege.capital_county
						recent_history = {
							type = conquest 
							years = 10
						}
					}
					save_scope_as = target_county 
				}
				trigger_event = fp3_dynasty_decision.0003
			}
		}
	}

	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 0
		kingdom = 120
		empire = 120
		hegemony = 120
	}

	ai_potential = {}

	ai_will_do = { base = 100 }
}
