﻿weapon_inspiration = {
	gold = {
		value = basic_fund_inspiration_cost

		# If we have a cultural tradition which makes funding certain types of Inspiration more expensive, add to the cost here.
		if = {
			limit = {
				# Must always have a inspiration owner to have cost modifiers.
				exists = scope:inspiration_owner

				# Local artisans charge a fixed fee so the cost matches up with the cost listed in the "Comission Artifact" decision.
				NOT = { 
					scope:inspiration_owner = {
						has_character_flag = local_artisan
					}
				}
			}

			# If the Inspiration Owner has a cultural tradition which makes funding certain types of Inspiration more expensive, add to the cost here.
			if = {
				limit = { scope:inspiration_owner = { culture = { has_cultural_parameter = more_expensive_weapon_inspiration } } }
				add = {
					value = basic_fund_inspiration_cost
					multiply = more_expensive_inspirations_multiplier_value
				}
			}

			# Modify the cost based on the Inspiration Owner's relevant skills
			multiply = {
				# Get the squared value of our inspiration skill's averages (0 = 0, 5 = 25, 10 = 100, 20 = 400)
				value = scope:inspiration_owner.weapon_inspiration_average_skill_value
				multiply = scope:inspiration_owner.weapon_inspiration_average_skill_value

				# Reduce by a factor of 100 to get the base cost multiplier (0 = 0, 5 = 0.25, 10 = 1.00, 20 = 2.00)
				multiply = 0.01

				# Additional modifier so it's easy to tweak overall cost.
				multiply = inspiration_cost_skill_multiplier

				# Min cost cannot drop beyond 50%
				min = 0.5
			}
		}
		
		# If you used the "Comission Artifact" decision and have a relevant estate buildling, you get a discount
		if = {
			limit = {
				exists = scope:inspiration_owner
				scope:inspiration_owner = {
					has_character_flag = local_artisan
					liege.domicile ?= { has_domicile_parameter = estate_reduce_commission_artifact_cost } # We check liege specifically because scope:inspiration_sponsor does not exist yet
				}
			}
			multiply = estate_reduce_commission_artifact_cost_value
		}
		round = yes
	}
	progress_chance = 75

	on_creation = {
		hidden_effect = { #If they haven't specified what they're gonna make we decide it here
			scope:inspiration_owner = {
				if = {
					limit = {
						NOT = { has_variable = artifact_weapon_type }
					}
					set_weapon_artifact_type_effect = {
						BASE_SCOPE = scope:inspiration_owner
						NO_TYPE = yes
					}
				}
			}
			if = {
				limit = {
					scope:inspiration_owner = { has_variable = is_inspiration_for_kris_dagger }
				}
				scope:inspiration_owner = { remove_variable = is_inspiration_for_kris_dagger }
				set_variable = inspiration_for_kris_dagger
			}
		}
	}

	is_valid = {
		
	}
	is_sponsor_valid = {
		ep1_is_sponsor_valid_inspiration_basic = yes
	}
	can_sponsor = {
		ep1_can_sponsor_inspiration_basic = yes
	}

	on_monthly = {
		scope:inspiration_sponsor = {
			trigger_event = {
				on_action = inspiration_maintenance_events
			}
			trigger_event = {
				on_action = inspiration_ongoing_events
			}
		}
	}
	on_complete = {
		scope:inspiration_owner = {
			set_variable = {
				name = created_artifact_for
				value = scope:inspiration_sponsor
			}
			set_variable = {
				name = created_artifact_type
				value = flag:weapon
			}
			if = {
				limit = {
					prev = { has_variable = inspiration_for_kris_dagger }
				}
				set_variable = inspiration_for_kris_dagger
			}
			grant_inspiration_reward_effect = yes
		}
		scope:inspiration_sponsor = { #To give the right flavor for the completion event
			add_character_flag = {
				flag = trigger_weapon_completion_event
				days = 1 
			}
			trigger_event = {
				on_action = inspiration_completed_events
			}
		}
	}
	on_sponsor = {
		scope:inspiration_owner = {
			# To ensure that some time has passed before the first event
			# This flag is set on the inspiration owner since the sponsor might be sponsoring multiple inspirations at once
			add_character_flag = {
				flag = fund_weapon_inspiration_event_cooldown
				days = 60
			}
		}
		scope:inspiration_sponsor = {
			trigger_event = {
				on_action = inspiration_start_events
			}
		}
	}
	on_owner_death = {
		save_scope_value_as = {
			name = weapon_inspiration
			value = yes
		}
		if = {
			limit = { exists = scope:inspiration_sponsor }
			scope:inspiration_sponsor = {
				trigger_event = {
					on_action = inspiration_invalidated_events
				}
			}
		}
	}
	on_sponsor_invalidated = {
		save_scope_value_as = {
			name = weapon_inspiration
			value = yes
		}
		if = {
			limit = { exists = scope:inspiration_sponsor }
			scope:inspiration_sponsor = {
				trigger_event = {
					on_action = inspiration_invalidated_events
				}
			}
		}
	}
}

armor_inspiration = {
	gold = {
		value = basic_fund_inspiration_cost

		if = {
			limit = {
				# Must always have a inspiration owner to have cost modifiers.
				exists = scope:inspiration_owner

				# Local artisans charge a fixed fee so the cost matches up with the cost listed in the "Comission Artifact" decision.
				NOT = { 
					scope:inspiration_owner = {
						has_character_flag = local_artisan
					}
				}
			}

			# Modify the cost based on the inspiration owner's relevant skills
			multiply = {
				# Get the squared value of our inspiration skill's averages (0 = 0, 5 = 25, 10 = 100, 20 = 400)
				value = scope:inspiration_owner.armor_inspiration_average_skill_value
				multiply = scope:inspiration_owner.armor_inspiration_average_skill_value

				# Reduce by a factor of 100 to get the base cost multiplier (0 = 0, 5 = 0.25, 10 = 1.00, 20 = 2.00)
				multiply = 0.01

				# Additional modifier so it's easy to tweak overall cost.
				multiply = inspiration_cost_skill_multiplier

				# Min cost cannot drop beyond 50%
				min = 0.5
			}
		}
		
		# If you used the "Comission Artifact" decision and have a relevant estate buildling, you get a discount
		if = {
			limit = {
				scope:inspiration_owner ?= { has_character_flag = local_artisan }
				scope:inspiration_owner.liege.domicile ?= { has_domicile_parameter = estate_reduce_commission_artifact_cost } #Unop Use correct scope: root is inspiration
			}
			multiply = estate_reduce_commission_artifact_cost_value
		}
		round = yes
	}
	progress_chance = 75

	on_creation = {
		hidden_effect = { #If they haven't specified what they're gonna make we decide it here
			if = {
				limit = {
					scope:inspiration_owner = {
						exists = var:force_armor
						var:force_armor = flag:force_armor_true
					}
				}
				set_armor_artifact_type_effect = {
					BASE_SCOPE = inspiration_owner
					NO_TYPE = yes
				}
			}
			else = {
				random_list = {
					75 = {
						set_armor_artifact_type_effect = {
							BASE_SCOPE = inspiration_owner
							NO_TYPE = yes
						}
					}
					25 = {
						scope:inspiration_owner = {
							set_variable = {
								name = artifact_armor_type
								value = flag:armor_type_shield
							}
						}
					}
				}
			}
		}
	}

	is_valid = {
		
	}
	is_sponsor_valid = {
		ep1_is_sponsor_valid_inspiration_basic = yes
	}
	can_sponsor = {
		ep1_can_sponsor_inspiration_basic = yes
	}

	on_monthly = {
		scope:inspiration_sponsor = {
			trigger_event = {
				on_action = inspiration_maintenance_events
			}
			trigger_event = {
				on_action = inspiration_ongoing_events
			}
		}
	}
	on_complete = {
		scope:inspiration_owner = {
			set_variable = {
				name = created_artifact_for
				value = scope:inspiration_sponsor
			}
			set_variable = {
				name = created_artifact_type
				value = flag:armor
			}
			grant_inspiration_reward_effect = yes
		}
		scope:inspiration_sponsor = { #To give the right flavor for the completion event
			add_character_flag = {
				flag = trigger_armor_completion_event
				days = 1 
			}
			trigger_event = {
				on_action = inspiration_completed_events
			}
		}
	}
	on_sponsor = {
		scope:inspiration_owner = {
			# To ensure that some time has passed before the first event
			# This flag is set on the inspiration owner since the sponsor might be sponsoring multiple inspirations at once
			add_character_flag = {
				flag = fund_weapon_inspiration_event_cooldown
				days = 60
			}
		}
		scope:inspiration_sponsor = {
			trigger_event = {
				on_action = inspiration_start_events
			}
		}
	}
	on_owner_death = {
		save_scope_value_as = {
			name = armor_inspiration
			value = yes
		}
		if = {
			limit = { exists = scope:inspiration_sponsor }
			scope:inspiration_sponsor = {
				trigger_event = {
					on_action = inspiration_invalidated_events
				}
			}
		}
	}
	on_sponsor_invalidated = {
		save_scope_value_as = {
			name = armor_inspiration
			value = yes
		}
		if = {
			limit = { exists = scope:inspiration_sponsor }
			scope:inspiration_sponsor = {
				trigger_event = {
					on_action = inspiration_invalidated_events
				}
			}
		}
	}
}

book_inspiration = {
	gold = {
		value = basic_fund_inspiration_cost

		if = {
			limit = {
				# Must always have a inspiration owner to have cost modifiers.
				exists = scope:inspiration_owner

				# Local artisans charge a fixed fee so the cost matches up with the cost listed in the "Comission Artifact" decision.
				NOT = { 
					scope:inspiration_owner = {
						has_character_flag = local_artisan
					}
				}
			}
			# Increase the cost based on the inspiration owner's relevant skills
			multiply = {
				# Get the squared value of our inspiration skill's averages (0 = 0, 5 = 25, 10 = 100, 20 = 400)
				value = scope:inspiration_owner.book_inspiration_average_skill_value
				multiply = scope:inspiration_owner.book_inspiration_average_skill_value

				# Reduce by a factor of 100 to get the base cost multiplier (0 = 0, 5 = 0.25, 10 = 1.00, 20 = 2.00)
				multiply = 0.01

				# Additional modifier so it's easy to tweak overall cost.
				multiply = inspiration_cost_skill_multiplier

				# Min cost cannot drop beyond 50%
				min = 0.5
				max = 3.0 # we gotta cap this, man
			}
		}
		
		# If you used the "Comission Artifact" decision and have a relevant estate buildling, you get a discount
		if = {
			limit = {
				exists = scope:inspiration_owner
				scope:inspiration_owner = {
					has_character_flag = local_artisan
					liege.domicile ?= { has_domicile_parameter = estate_reduce_commission_artifact_cost } # We check liege specifically because scope:inspiration_sponsor does not exist yet
				}
			}
			multiply = estate_reduce_commission_artifact_cost_value
		}

		# Cheaper to produce a book if printing exists
		if = {
			limit = {
				scope:inspiration_sponsor.culture ?= { has_cultural_parameter = cheaper_book_inspiration }
			}
			multiply = 0.5
		}
		round = yes
	}
	progress_chance = 75

	on_creation = {
		set_book_subject_effect = {
			BASE_SCOPE = scope:inspiration_owner
			NO_SUBJECT = yes
		}
	}

	is_valid = {
		
	}
	is_sponsor_valid = {
		ep1_is_sponsor_valid_inspiration_basic = yes
	}
	can_sponsor = {
		ep1_can_sponsor_inspiration_basic = yes
	}

	on_monthly = {
		scope:inspiration_sponsor = {
			trigger_event = {
				on_action = inspiration_maintenance_events
			}
			trigger_event = {
				on_action = inspiration_ongoing_events
			}
		}
	}
	on_complete = {
		scope:inspiration_owner = {
			set_variable = {
				name = created_artifact_for
				value = scope:inspiration_sponsor
			}
			set_variable = {
				name = created_artifact_type
				value = flag:book
			}
			grant_inspiration_reward_effect = yes
		}
		scope:inspiration_sponsor = {
			add_character_flag = {
				flag = trigger_book_completion_event
				days = 1 
			}
			trigger_event = {
				on_action = inspiration_completed_events
			}
		}
	}
	on_sponsor = {
		scope:inspiration_owner = {
			# To ensure that some time has passed before the first event
			# This flag is set on the inspiration owner since the sponsor might be sponsoring multiple inspirations at once
			add_character_flag = {
				flag = fund_book_inspiration_event_cooldown
				days = 60
			}
		}
		scope:inspiration_sponsor = {
			trigger_event = {
				on_action = inspiration_start_events
			}
		}
	}
	on_owner_death = {
		save_scope_value_as = {
			name = book_inspiration
			value = yes
		}
		if = {
			limit = { exists = scope:inspiration_sponsor }
			scope:inspiration_sponsor = {
				trigger_event = {
					on_action = inspiration_invalidated_events
				}
			}
		}
	}
	on_sponsor_invalidated = {
		save_scope_value_as = {
			name = book_inspiration
			value = yes
		}
		if = {
			limit = { exists = scope:inspiration_sponsor }
			scope:inspiration_sponsor = {
				trigger_event = {
					on_action = inspiration_invalidated_events
				}
			}
		}
	}
}

weaver_inspiration = {
	gold = {
		value = basic_fund_inspiration_cost

		if = {
			limit = {
				# Must always have a inspiration owner to have cost modifiers.
				exists = scope:inspiration_owner

				# Local artisans charge a fixed fee so the cost matches up with the cost listed in the "Comission Artifact" decision.
				NOT = { 
					scope:inspiration_owner = {
						has_character_flag = local_artisan
					}
				}
			}
			# Modify the cost based on the inspiration owner's relevant skills
			multiply = {
				# Get the squared value of our inspiration skill's averages (0 = 0, 5 = 25, 10 = 100, 20 = 400)
				value = scope:inspiration_owner.weaver_inspiration_average_skill_value
				multiply = scope:inspiration_owner.weaver_inspiration_average_skill_value

				# Reduce by a factor of 100 to get the base cost multiplier (0 = 0, 5 = 0.25, 10 = 1.00, 20 = 2.00)
				multiply = 0.01

				# Additional modifier so it's easy to tweak overall cost.
				multiply = inspiration_cost_skill_multiplier

				# Min cost cannot drop beyond 50%
				min = 0.5
			}
		}
		
		# If you used the "Comission Artifact" decision and have a relevant estate buildling, you get a discount
		if = {
			limit = {
				exists = scope:inspiration_owner
				scope:inspiration_owner = {
					has_character_flag = local_artisan
					liege.domicile ?= { has_domicile_parameter = estate_reduce_commission_artifact_cost } # We check liege specifically because scope:inspiration_sponsor does not exist yet
				}
			}
			multiply = estate_reduce_commission_artifact_cost_value
		}
		round = yes
	}
	progress_chance = 75

	on_creation = {
		hidden_effect = { #If they haven't specified what they're gonna make we decide it here
			scope:inspiration_owner = {
				if = {
					limit = {
						NOR = {
							has_variable = banner_commission
							exists = var:artifact_tapestry_scene
						}
					}
					random_list = { #What do they want to weave?
						25 = {
							# Unspecified — sponsor gets to choose what they want.
							ai_value_modifier = {
								ai_boldness = -1 # At -50 Boldness, has a 75% chance for unspecified and a 25% chance for specific scene. At -75 Boldness, this increases to 100% unspecified.
							}
						}
						75 = {
							random_list = {						
								0 = {
									# This one isn't included in randomgen because its validity is dependent on who sponsors it.
									# As a result, it can only be selected in event fund_inspiration.0041 with an unspecified inspiration.
									#
									# set_variable = {
									# 	 name = artifact_tapestry_scene
									# 	 value = flag:battle
									# }
								}

								# Abstract, geometric, or other non-representational art. (Aniconic Preferred)
								25 = {
									trigger = { faith_is_aniconic_trigger = yes }
									ai_value_modifier = {
										ai_zeal = 0.25
									}
									set_variable = {
										name = artifact_tapestry_scene
										value = flag:geometric_patterns
									}
								}
								25 = {
									trigger = { religion = religion:islam_religion }
									ai_value_modifier = {
										ai_zeal = 0.25
									}
									set_variable = {
										name = artifact_tapestry_scene
										value = flag:calligraphic
									}
								}

								# Natural Scene - Depicts Animals (Aniconic Allowed)
								10 = {
									trigger = { NOT = { faith = { has_doctrine_parameter = pacifist_opinion_active } } }
									modifier = {
										add = 90
										has_trait = lifestyle_hunter
									}
									set_variable = {
										name = artifact_tapestry_scene
										value = flag:hunt
									}
								}
								10 = {
									set_variable = {
										name = artifact_tapestry_scene
										value = flag:animals
									}
								}
								10 = {
									modifier = {
										add = 90
										has_trait = lifestyle_gardener
									}
									set_variable = {
										name = artifact_tapestry_scene
										value = flag:garden
									}
								}

								# Historical - Depicts People
								20 = {
									trigger = {
										faith_is_aniconic_trigger = no
										culture = {
											has_cultural_tradition = tradition_seafaring
											has_cultural_tradition = tradition_fishermen
											has_cultural_tradition = tradition_maritime_mercantilism
										}
									}
									modifier = {
										add = 80
										has_trait = viking
									}
									set_variable = {
										name = artifact_tapestry_scene
										value = flag:ships
									}
								}
								10 = {
									trigger = { faith_is_aniconic_trigger = no }
									modifier = {
										add = {
											value = learning
											subtract = decent_skill_rating
										}
									}
									set_variable = {
										name = artifact_tapestry_scene
										value = flag:historical
									}
								}
								10 = {
									trigger = { faith_is_aniconic_trigger = no }
									modifier = {
										add = 40
										has_trait = ambitious
									}
									set_variable = {
										name = artifact_tapestry_scene
										value = flag:coronation
									}
								}

								# Slice-Of-Life - Depicts People
								10 = {
									trigger = { faith_is_aniconic_trigger = no }
									ai_value_modifier = {
										ai_greed = -0.05 # At +20 greed, this decreases to 0. At -20 greed, this doubles. 
									}
									set_variable = {
										name = artifact_tapestry_scene
										value = flag:bucolic
									}
								}
								10 = {
									trigger = { faith_is_aniconic_trigger = no }
									ai_value_modifier = {
										ai_greed = 0.05 # At -20 greed, this decreases to 0. At +20 greed, this doubles. 
										ai_sociability = 0.05 # At -20 sociability, this decreases to 0. At +20 greed, this doubles. 
									}
									modifier = {
										add = 10
										OR = {
											has_trait = gluttonous
											has_trait = comfort_eater
											has_trait = gregarious
										}
									}
									modifier = {
										factor = 0
										OR = {
											has_trait = shy
											has_trait = inappetetic
											has_trait = temperate
										}
									}
									set_variable = {
										name = artifact_tapestry_scene
										value = flag:banquet
									}
								}
								10 = {
									trigger = { faith_is_aniconic_trigger = no }
									modifier = {
										add = 40
										has_trait = just
									}
									modifier = {
										factor = 0
										has_trait = arbitrary
									}
									set_variable = {
										name = artifact_tapestry_scene
										value = flag:hearing
									}
								}
								10 = {
									trigger = { faith_is_aniconic_trigger = no }
									set_variable = {
										name = artifact_tapestry_scene
										value = flag:myth
									}
								}
							}
						}
					}
				}
			}
		}
	}

	is_valid = {
		
	}
	is_sponsor_valid = {
		ep1_is_sponsor_valid_inspiration_basic = yes
	}
	can_sponsor = {
		ep1_can_sponsor_inspiration_basic = yes
	}

	on_monthly = {
		scope:inspiration_sponsor = {
			trigger_event = {
				on_action = inspiration_maintenance_events
			}
			trigger_event = {
				on_action = inspiration_ongoing_events
			}
		}
	}
	on_complete = {
		scope:inspiration_owner = {
			set_variable = {
				name = created_artifact_for
				value = scope:inspiration_sponsor
			}
			set_variable = {
				name = created_artifact_type
				value = flag:weaver
			}
			grant_inspiration_reward_effect = yes
		}
		scope:inspiration_sponsor = {
			if = {
				limit = {
					NOT = {
						scope:inspiration_owner = { has_variable = banner_commission }
					}
				}
				add_character_flag = {
					flag = trigger_tapestry_completion_event
					days = 1 
				}
			}
			else = {
				add_character_flag = {
					flag = trigger_banner_completion_event
					days = 1 
				}
				scope:inspiration_owner = { remove_variable = banner_commission }
			}
			trigger_event = {
				on_action = inspiration_completed_events
			}
		}
	}
	on_sponsor = {
		scope:inspiration_owner = {
			# To ensure that some time has passed before the first event
			# This flag is set on the inspiration owner since the sponsor might be sponsoring multiple inspirations at once
			add_character_flag = {
				flag = fund_weaver_inspiration_event_cooldown
				days = 60
			}
		}
		scope:inspiration_sponsor = {
			trigger_event = {
				on_action = inspiration_start_events
			}
		}
	}
	on_owner_death = {
		save_scope_value_as = {
			name = weaver_inspiration
			value = yes
		}
		if = {
			limit = { exists = scope:inspiration_sponsor }
			scope:inspiration_sponsor = {
				trigger_event = {
					on_action = inspiration_invalidated_events
				}
			}
		}
	}
	on_sponsor_invalidated = {
		save_scope_value_as = {
			name = weaver_inspiration
			value = yes
		}
		if = {
			limit = { exists = scope:inspiration_sponsor }
			scope:inspiration_sponsor = {
				trigger_event = {
					on_action = inspiration_invalidated_events
				}
			}
		}
	}
}

adventure_inspiration = {
	gold = {
		value = basic_fund_inspiration_cost

		if = {
			limit = {
				# Must always have a inspiration owner to have cost modifiers.
				exists = scope:inspiration_owner

				# Local artisans charge a fixed fee so the cost matches up with the cost listed in the "Comission Artifact" decision.
				NOT = { 
					scope:inspiration_owner = {
						has_character_flag = local_artisan
					}
				}
			}
			# Modify the cost based on the inspiration owner's relevant skills
			multiply = {
				# Get the squared value of our inspiration skill's averages (0 = 0, 5 = 25, 10 = 100, 20 = 400)
				value = scope:inspiration_owner.adventure_inspiration_average_skill_value
				multiply = scope:inspiration_owner.adventure_inspiration_average_skill_value

				# Reduce by a factor of 100 to get the base cost multiplier (0 = 0, 5 = 0.25, 10 = 1.00, 20 = 2.00)
				multiply = 0.01

				# Additional modifier so it's easy to tweak overall cost.
				multiply = inspiration_cost_skill_multiplier

				# Min cost cannot drop beyond 50%
				min = 0.5
			}
		}

		# Cheaper to produce a book if printing exists
		if = {
			limit = {
				scope:inspiration_sponsor.culture ?= { has_cultural_parameter = cheaper_adventure_inspiration }
			}
			multiply = 0.5
		}
		round = yes
	}
	progress_chance = adventure_progress_chance_svalue

	on_creation = {
		if = {
			limit = {
				scope:inspiration_owner.adventure_inspiration_average_skill_value >= high_inspiration_skill
			}
			set_adventure_location_effect = {
				BASE_SCOPE = scope:inspiration_owner
				NO_DESTINATION = yes
			}
		}
		else = {
			set_adventure_location_effect = {
				BASE_SCOPE = scope:inspiration_owner
				NO_DESTINATION = no
			}
		}
	}

	is_valid = {
		
	}
	is_sponsor_valid = {
		ep1_is_sponsor_valid_inspiration_basic = yes
	}
	can_sponsor = {
		ep1_can_sponsor_inspiration_basic = yes
	}

	on_monthly = {
		scope:inspiration_sponsor = {
			trigger_event = {
				on_action = inspiration_maintenance_events
			}
			trigger_event = {
				on_action = inspiration_ongoing_events
			}
		}
	}

	on_progress_increased = {
		scope:inspiration_owner = { trigger_event = fund_inspiration.0053 }
	}

	on_complete = {
		scope:inspiration_owner = {
			set_variable = {
				name = created_artifact_for
				value = scope:inspiration_sponsor
			}
			if = {
				limit = { NOT = { exists = var:completed_adventure_inspirations } }
				set_variable = {
					name = completed_adventure_inspirations
					value = 0
				}
			}
			change_variable = {
				name = completed_adventure_inspirations
				add = 1
			}
			set_variable = {
				name = created_artifact_type
				value = flag:adventure
			}
			add_character_flag = {
				flag = trigger_adventure_completion_event
				days = 1 
			}
			grant_inspiration_reward_effect = yes
		}
		scope:inspiration_sponsor = {
			add_character_flag = {
				flag = trigger_adventure_completion_event
				days = 1 
			}
			trigger_event = {
				on_action = inspiration_completed_events
			}
		}
	}
	on_sponsor = {
		scope:inspiration_owner = {
			# To ensure that some time has passed before the first event
			# This flag is set on the inspiration owner since the sponsor might be sponsoring multiple inspirations at once
			add_character_flag = {
				flag = fund_adventure_inspiration_event_cooldown
				days = { 20 30 } #This one is shorter than the others to give the "pick artifact type" event in a timely fashion
			}
		}
		scope:inspiration_sponsor = {
			trigger_event = {
				on_action = inspiration_start_events
			}
		}
	}
	on_owner_death = {
		save_scope_value_as = {
			name = adventure_inspiration
			value = yes
		}
		if = {
			limit = { exists = scope:inspiration_sponsor }
			scope:inspiration_sponsor = {
				trigger_event = {
					on_action = inspiration_invalidated_events
				}
			}
		}
	}
	on_sponsor_invalidated = {
		save_scope_value_as = {
			name = adventure_inspiration
			value = yes
		}
		if = {
			limit = { exists = scope:inspiration_sponsor }
			scope:inspiration_sponsor = {
				trigger_event = {
					on_action = inspiration_invalidated_events
				}
			}
		}
	}
}

artisan_inspiration = {
	gold = {
		value = basic_fund_inspiration_cost

		if = {
			limit = {
				# Must always have a inspiration owner to have cost modifiers.
				exists = scope:inspiration_owner

				# Local artisans charge a fixed fee so the cost matches up with the cost listed in the "Comission Artifact" decision.
				NOT = { 
					scope:inspiration_owner = {
						has_character_flag = local_artisan
					}
				}
			}

			# Modify the cost based on the inspiration owner's relevant skills
			multiply = {
				# Get the squared value of our inspiration skill's averages (0 = 0, 5 = 25, 10 = 100, 20 = 400)
				value = scope:inspiration_owner.artisan_inspiration_average_skill_value
				multiply = scope:inspiration_owner.artisan_inspiration_average_skill_value

				# Reduce by a factor of 100 to get the base cost multiplier (0 = 0, 5 = 0.25, 10 = 1.00, 20 = 2.00)
				multiply = 0.01

				# Additional modifier so it's easy to tweak overall cost.
				multiply = inspiration_cost_skill_multiplier

				# Min cost cannot drop beyond 50%
				min = 0.5
			}
		}
		
		# If you used the "Comission Artifact" decision and have a relevant estate buildling, you get a discount
		if = {
			limit = {
				exists = scope:inspiration_owner
				scope:inspiration_owner = {
					has_character_flag = local_artisan
					liege.domicile ?= { has_domicile_parameter = estate_reduce_commission_artifact_cost } # We check liege specifically because scope:inspiration_sponsor does not exist yet
				}
			}
			multiply = estate_reduce_commission_artifact_cost_value
		}
		round = yes
	}
	progress_chance = 75

	on_creation = {
		hidden_effect = { #If they haven't specified what they're gonna make we decide it here
			scope:inspiration_owner = {
				if = {
					limit = {
						NOT = { exists = var:artifact_artisan_type }
					}
					random_list = {
						10 = { #Unspecified! Sponsor can choose
							modifier = {
								add = 20
								has_personality_submissive_trigger = yes
							}
							ai_value_modifier = {
								ai_boldness = -0.5
								ai_energy = -0.25
							}
						}
						90 = {
							random_list = {
								10 = {
									set_variable = {
										name = artifact_artisan_type
										value = flag:artisan_type_chest
									}
								}
								10 = {
									set_variable = {
										name = artifact_artisan_type
										value = flag:artisan_type_box
									}
								}
								10 = {
									set_variable = {
										name = artifact_artisan_type
										value = flag:artisan_type_sculpture
									}
									random_list = {
										10 = { # Stone
											modifier = {
												factor = 0.2
												AND = { # Pagans prefer wood
													NOT = { faith = faith:hellenic_pagan }
													religion = { is_in_family = rf_pagan }
												}
											}
											set_variable = {
												name = artifact_sculpture_material
												value = flag:sculpture_material_stone
											}
										}
										10 = {} # Wood
									}
								}
								10 = {
									set_variable = {
										name = artifact_artisan_type
										value = flag:artisan_type_cabinet
									}
								}
								10 = {
									set_variable = {
										name = artifact_artisan_type
										value = flag:artisan_type_throne
									}
								}
								10 = {
									set_variable = {
										name = artifact_artisan_type
										value = flag:artisan_type_urn
									}
								}
								10 = {
									trigger = {
										ep3_orthodox_faith_trigger = yes
										trigger_if = {
											limit = { exists = location.county.holder }
											location.county.holder = { faith_is_aniconic_trigger = no }
										}
										trigger_else = { 
											location = { faith_is_aniconic_trigger = no }
										}								
									}
									modifier = {
										add = 20
										trigger_if = { #Unop: inspiration_sponsor can be undefined here, so if it is, use the liege
											limit = { exists = scope:inspiration_sponsor }
											scope:inspiration_sponsor = {
												ep3_orthodox_faith_trigger = yes
											}
										}
										trigger_else = {
											liege = {
												ep3_orthodox_faith_trigger = yes
											}
										}
									}
									set_variable = {
										name = artifact_artisan_type
										value = flag:artisan_type_icon
									}
								}
							}
						}
					}
				}
			}
		}
	}

	is_valid = {
		
	}
	is_sponsor_valid = {
		ep1_is_sponsor_valid_inspiration_basic = yes
	}
	can_sponsor = {
		ep1_can_sponsor_inspiration_basic = yes
	}

	on_monthly = {
		scope:inspiration_sponsor = {
			trigger_event = {
				on_action = inspiration_maintenance_events
			}
			trigger_event = {
				on_action = inspiration_ongoing_events
			}
		}
	}
	on_complete = {
		scope:inspiration_owner = {
			set_variable = {
				name = created_artifact_for
				value = scope:inspiration_sponsor
			}
			set_variable = {
				name = created_artifact_type
				value = flag:artisan
			}
			grant_inspiration_reward_effect = yes
		}
		scope:inspiration_sponsor = { #To give the right flavor for the completion event
			add_character_flag = {
				flag = trigger_artisan_completion_event
				days = 1 
			}
			trigger_event = {
				on_action = inspiration_completed_events
			}
		}
	}
	on_sponsor = {
		scope:inspiration_owner = {
			# To ensure that some time has passed before the first event
			# This flag is set on the inspiration owner since the sponsor might be sponsoring multiple inspirations at once
			add_character_flag = {
				flag = fund_artisan_inspiration_event_cooldown
				days = 60
			}
		}
		scope:inspiration_sponsor = {
			trigger_event = {
				on_action = inspiration_start_events
			}
		}
	}
	on_owner_death = {
		save_scope_value_as = {
			name = artisan_inspiration
			value = yes
		}
		if = {
			limit = { exists = scope:inspiration_sponsor }
			scope:inspiration_sponsor = {
				trigger_event = {
					on_action = inspiration_invalidated_events
				}
			}
		}
	}
	on_sponsor_invalidated = {
		save_scope_value_as = {
			name = artisan_inspiration
			value = yes
		}
		if = {
			limit = { exists = scope:inspiration_sponsor }
			scope:inspiration_sponsor = {
				trigger_event = {
					on_action = inspiration_invalidated_events
				}
			}
		}
	}
}

smith_inspiration = {
	gold = {
		value = basic_fund_inspiration_cost

		if = {
			limit = {
				# Must always have a inspiration owner to have cost modifiers.
				exists = scope:inspiration_owner

				# Local artisans charge a fixed fee so the cost matches up with the cost listed in the "Comission Artifact" decision.
				NOT = { 
					scope:inspiration_owner = {
						has_character_flag = local_artisan
					}
				}
			}
			
			# Modify the cost based on the inspiration owner's relevant skills
			multiply = {
				# Get the squared value of our inspiration skill's averages (0 = 0, 5 = 25, 10 = 100, 20 = 400)
				value = scope:inspiration_owner.smith_inspiration_average_skill_value
				multiply = scope:inspiration_owner.smith_inspiration_average_skill_value

				# Reduce by a factor of 100 to get the base cost multiplier (0 = 0, 5 = 0.25, 10 = 1.00, 20 = 2.00)
				multiply = 0.01

				# Additional modifier so it's easy to tweak overall cost.
				multiply = inspiration_cost_skill_multiplier

				# Min cost cannot drop beyond 50%
				min = 0.5
			}
		}
		
		# If you used the "Comission Artifact" decision and have a relevant estate buildling, you get a discount
		if = {
			limit = {
				exists = scope:inspiration_owner
				scope:inspiration_owner = {
					has_character_flag = local_artisan
					liege.domicile ?= { has_domicile_parameter = estate_reduce_commission_artifact_cost } # We check liege specifically because scope:inspiration_sponsor does not exist yet
				}
			}
			multiply = estate_reduce_commission_artifact_cost_value
		}
		round = yes
	}
	progress_chance = 75

	on_creation = {
		hidden_effect = { #If they haven't specified what they're gonna make we decide it here
			scope:inspiration_owner = {
				if = {
					limit = {
						NOT = { exists = var:artifact_smith_type }
					}
					random_list = {
						10 = { #Unspecified! Sponsor can choose
							trigger = {
								trigger_if = {
									limit = {
										liege ?= {
											has_government = landless_adventurer_government
										}
									}
									liege = {
										is_landless_adventurer = no
									}
								}
								trigger_else = {
									always = yes
								}
							}
							modifier = {
								add = 20
								has_personality_submissive_trigger = yes
							}
							ai_value_modifier = {
								ai_boldness = -0.5
								ai_energy = -0.25
							}
						}
						90 = {
							random_list = {
								10 = {
									set_variable = {
										name = artifact_smith_type
										value = flag:smith_type_brooch
									}
								}
								10 = {
									set_variable = {
										name = artifact_smith_type
										value = flag:smith_type_regalia
									}
								}
								10 = {
									trigger = {
										trigger_if = {
											limit = {
												liege ?= {
													has_government = landless_adventurer_government
												}
											}
											liege = {
												is_landless_adventurer = no
											}
										}
										trigger_else = {
											always = yes
										}
									}
									set_variable = {
										name = artifact_smith_type
										value = flag:smith_type_crown
									}
								}
								10 = {
									trigger = {
										trigger_if = {
											limit = {
												liege ?= {
													has_government = landless_adventurer_government
												}
											}
											liege = {
												is_landless_adventurer = no
											}
										}
										trigger_else = {
											always = yes
										}
									}
									set_variable = {
										name = artifact_smith_type
										value = flag:smith_type_goblet
									}
								}
							}
						}
					}
				}
			}
		}
	}
	
	is_valid = {
		
	}
	is_sponsor_valid = {
		ep1_is_sponsor_valid_inspiration_basic = yes
	}
	can_sponsor = {
		ep1_can_sponsor_inspiration_basic = yes
	}

	on_monthly = {
		scope:inspiration_sponsor = {
			trigger_event = {
				on_action = inspiration_maintenance_events
			}
			trigger_event = {
				on_action = inspiration_ongoing_events
			}
		}
	}
	on_complete = {
		scope:inspiration_owner = {
			set_variable = {
				name = created_artifact_for
				value = scope:inspiration_sponsor
			}
			set_variable = {
				name = created_artifact_type
				value = flag:smith
			}
			grant_inspiration_reward_effect = yes
		}
		scope:inspiration_sponsor = { #To give the right flavor for the completion event
			add_character_flag = {
				flag = trigger_smith_completion_event
				days = 1 
			}
			trigger_event = {
				on_action = inspiration_completed_events
			}
		}
	}
	on_sponsor = {
		scope:inspiration_owner = {
			# To ensure that some time has passed before the first event
			# This flag is set on the inspiration owner since the sponsor might be sponsoring multiple inspirations at once
			add_character_flag = {
				flag = fund_smith_inspiration_event_cooldown
				days = 60
			}
		}
		scope:inspiration_sponsor = {
			trigger_event = {
				on_action = inspiration_start_events
			}
		}
	}
	on_owner_death = {
		save_scope_value_as = {
			name = smith_inspiration
			value = yes
		}
		if = {
			limit = { exists = scope:inspiration_sponsor }
			scope:inspiration_sponsor = {
				trigger_event = {
					on_action = inspiration_invalidated_events
				}
			}
		}
	}
	on_sponsor_invalidated = {
		save_scope_value_as = {
			name = smith_inspiration
			value = yes
		}
		if = {
			limit = { exists = scope:inspiration_sponsor }
			scope:inspiration_sponsor = {
				trigger_event = {
					on_action = inspiration_invalidated_events
				}
			}
		}
	}
}

alchemy_inspiration = {
	gold = {
		value = basic_fund_inspiration_cost

		if = {
			limit = {
				# Must always have a inspiration owner to have cost modifiers.
				exists = scope:inspiration_owner

				# Local artisans charge a fixed fee so the cost matches up with the cost listed in the "Comission Artifact" decision.
				NOT = { 
					scope:inspiration_owner = {
						has_character_flag = local_artisan
					}
				}
			}
			
			# Modify the cost based on the inspiration owner's relevant skills
			multiply = {
				# Get the squared value of our inspiration skill's averages (0 = 0, 5 = 25, 10 = 100, 20 = 400)
				value = scope:inspiration_owner.alchemy_inspiration_average_skill_value
				multiply = scope:inspiration_owner.alchemy_inspiration_average_skill_value

				# Reduce by a factor of 100 to get the base cost multiplier (0 = 0, 5 = 0.25, 10 = 1.00, 20 = 2.00)
				multiply = 0.01

				# Additional modifier so it's easy to tweak overall cost.
				multiply = inspiration_cost_skill_multiplier

				# Min cost cannot drop beyond 50%
				min = 0.5
			}
		}
		round = yes
	}
	progress_chance = 75

	on_creation = {
		hidden_effect = { #If they haven't specified what they're gonna make we decide it here
			set_alchemy_inspiration_type_effect = {
				BASE_SCOPE = scope:inspiration_owner
				NO_TYPE = yes
			}
		}
	}

	is_valid = {
		
	}
	is_sponsor_valid = {
		ep1_is_sponsor_valid_inspiration_basic = yes
	}
	can_sponsor = {
		ep1_can_sponsor_inspiration_basic = yes
	}

	on_monthly = {
		scope:inspiration_sponsor = {
			trigger_event = {
				on_action = inspiration_maintenance_events
			}
			trigger_event = {
				on_action = inspiration_ongoing_events
			}
		}
	}
	on_complete = {
		scope:inspiration_owner = {
			set_variable = {
				name = created_artifact_for
				value = scope:inspiration_sponsor
			}
			set_variable = {
				name = created_artifact_type
				value = flag:alchemy
			}
		}
		scope:inspiration_sponsor = { #To give the right flavor for the completion event
			add_character_flag = {
				flag = trigger_alchemy_completion_event
				days = 1 
			}
			trigger_event = {
				on_action = inspiration_completed_events
			}
		}
	}
	on_sponsor = {
		scope:inspiration_owner = {
			# To ensure that some time has passed before the first event
			# This flag is set on the inspiration owner since the sponsor might be sponsoring multiple inspirations at once
			add_character_flag = {
				flag = fund_alchemy_inspiration_event_cooldown
				days = 60
			}
		}
		scope:inspiration_sponsor = {
			trigger_event = {
				on_action = inspiration_start_events
			}
		}
	}
	on_owner_death = {
		save_scope_value_as = {
			name = alchemy_inspiration
			value = yes
		}
		if = {
			limit = { exists = scope:inspiration_sponsor }
			scope:inspiration_sponsor = {
				trigger_event = {
					on_action = inspiration_invalidated_events
				}
			}
		}
	}
	on_sponsor_invalidated = {
		save_scope_value_as = {
			name = alchemy_inspiration
			value = yes
		}
		if = {
			limit = { exists = scope:inspiration_sponsor }
			scope:inspiration_sponsor = {
				trigger_event = {
					on_action = inspiration_invalidated_events
				}
			}
		}
	}
}

research_inspiration = {
	gold = scope:inspiration_sponsor.fp3_research_base_cost #Unop: So the cost is actually correctly calculated

	progress_chance = 75

	is_valid = {
		scope:inspiration_owner = {
			# Must be court scholar of sponsor
			has_court_position = court_scholar_court_position
			trigger_if = {
				limit = { is_imprisoned = yes }
				is_imprisoned_by = scope:inspiration_owner
			}
			NOT = { has_character_flag = research_invalidated }
		}
	}

	on_monthly = {
		scope:inspiration_sponsor = {
			trigger_event = { on_action = research_ongoing_events }
		}
	}
	on_complete = {
		scope:inspiration_owner = {
			set_variable = {
				name = created_artifact_for
				value = scope:inspiration_sponsor
			}
			set_variable = {
				name = created_artifact_type
				value = flag:research
			}
		}
		scope:inspiration_sponsor = { 
			trigger_event = fp3_scholarship.8999 
		}
	}

	on_owner_death = {
		# For loc
		save_scope_value_as = {
			name = research_inspiration
			value = yes
		}
		if = {
			limit = { exists = scope:inspiration_sponsor }
			scope:inspiration_sponsor = {
				trigger_event = {
					on_action = inspiration_invalidated_events
				}
			}
		}
	}

	on_invalidated = {
		save_scope_value_as = {
			name = research_inspiration
			value = yes
		}
		if = {
			limit = {
				exists = scope:inspiration_owner
				scope:inspiration_owner = { NOT = { has_character_flag = research_invalidated } }
			}
			scope:inspiration_sponsor = {
				trigger_event = {
					on_action = inspiration_invalidated_events
				}
			}
		}
	}

	on_sponsor_invalidated = {
		save_scope_value_as = {
			name = research_inspiration
			value = yes
		}
		if = {
			limit = { exists = scope:inspiration_sponsor }
			scope:inspiration_sponsor = {
				trigger_event = {
					on_action = inspiration_invalidated_events
				}
			}
		}
	}
}

religious_inspiration = {
	gold = scope:inspiration_sponsor.medium_gold_value #Unop: So the cost is actually correctly calculated

	progress_chance = 100

	is_valid = {
	}

	on_monthly = { # No events needed; rare and always-succeeding inspiration!
		#scope:inspiration_sponsor = {
		#	trigger_event = { on_action = research_ongoing_events }
		#}
	}
	on_complete = {
		scope:inspiration_owner = {
			set_variable = {
				name = created_artifact_for
				value = scope:inspiration_sponsor
			}
			set_variable = {
				name = created_artifact_type
				value = flag:major_religious_inspiration
			}
		}
		scope:inspiration_sponsor = { 
			trigger_event = historical_char_creation_events.2
		}
	}

	on_owner_death = {
		# For loc
		save_scope_value_as = {
			name = alchemy_inspiration
			value = yes
		}
		if = {
			limit = { exists = scope:inspiration_sponsor }
			scope:inspiration_sponsor = {
				trigger_event = {
					on_action = inspiration_invalidated_events
				}
			}
		}
	}

	on_invalidated = {
		save_scope_value_as = {
			name = alchemy_inspiration
			value = yes
		}
		if = {
			limit = {
				exists = scope:inspiration_owner
			}
			scope:inspiration_sponsor = {
				trigger_event = {
					on_action = inspiration_invalidated_events
				}
			}
		}
	}

	on_sponsor_invalidated = {
		save_scope_value_as = {
			name = alchemy_inspiration
			value = yes
		}
		if = {
			limit = { exists = scope:inspiration_sponsor }
			scope:inspiration_sponsor = {
				trigger_event = {
					on_action = inspiration_invalidated_events
				}
			}
		}
	}
}

bow_inspiration = {
	gold = {
		value = basic_fund_inspiration_cost

		# If we have a cultural tradition which makes funding certain types of Inspiration more expensive, add to the cost here.
		if = {
			limit = {
				# Must always have a inspiration owner to have cost modifiers.
				exists = scope:inspiration_owner

				# Local artisans charge a fixed fee so the cost matches up with the cost listed in the "Comission Artifact" decision.
				NOT = { 
					scope:inspiration_owner = {
						has_character_flag = local_artisan
					}
				}
			}

			# Modify the cost based on the Inspiration Owner's relevant skills
			multiply = {
				# Get the squared value of our inspiration skill's averages (0 = 0, 5 = 25, 10 = 100, 20 = 400)
				value = scope:inspiration_owner.weapon_inspiration_average_skill_value # Same as normal weapon
				multiply = scope:inspiration_owner.weapon_inspiration_average_skill_value # Same as normal weapon

				# Reduce by a factor of 100 to get the base cost multiplier (0 = 0, 5 = 0.25, 10 = 1.00, 20 = 2.00)
				multiply = 0.01

				# Additional modifier so it's easy to tweak overall cost.
				multiply = inspiration_cost_skill_multiplier

				# Min cost cannot drop beyond 50%
				min = 0.5
			}
		}
		
		# If you used the "Comission Artifact" decision and have a relevant estate buildling, you get a discount
		if = {
			limit = {
				exists = scope:inspiration_owner
				scope:inspiration_owner = {
					has_character_flag = local_artisan
					liege.domicile ?= { has_domicile_parameter = estate_reduce_commission_artifact_cost } # We check liege specifically because scope:inspiration_sponsor does not exist yet
				}
			}
			multiply = estate_reduce_commission_artifact_cost_value
		}
		round = yes
	}
	progress_chance = 75

	on_creation = {
		hidden_effect = { #If they haven't specified what they're gonna make we decide it here
			set_bow_artifact_type_effect = {
				BASE_SCOPE = scope:inspiration_owner
				NO_TYPE = yes
			}
		}
	}

	is_valid = {
		
	}
	is_sponsor_valid = {
		ep1_is_sponsor_valid_inspiration_basic = yes
	}
	can_sponsor = {
		ep1_can_sponsor_inspiration_basic = yes
	}

	on_monthly = {
		scope:inspiration_sponsor = {
			trigger_event = {
				on_action = inspiration_maintenance_events
			}
			trigger_event = {
				on_action = inspiration_ongoing_events
			}
		}
	}
	on_complete = {
		scope:inspiration_owner = {
			set_variable = {
				name = created_artifact_for
				value = scope:inspiration_sponsor
			}
			set_variable = {
				name = created_artifact_type
				value = flag:bow
			}
			grant_inspiration_reward_effect = yes
		}
		scope:inspiration_sponsor = { #To give the right flavor for the completion event
			add_character_flag = {
				flag = trigger_bow_completion_event
				days = 1 
			}
			trigger_event = {
				on_action = inspiration_completed_events
			}
		}
	}
	on_sponsor = {
		scope:inspiration_owner = {
			# To ensure that some time has passed before the first event
			# This flag is set on the inspiration owner since the sponsor might be sponsoring multiple inspirations at once
			add_character_flag = {
				flag = fund_bow_inspiration_event_cooldown
				days = 60
			}
		}
		scope:inspiration_sponsor = {
			trigger_event = {
				on_action = inspiration_start_events
			}
		}
	}
	on_owner_death = {
		save_scope_value_as = {
			name = bow_inspiration
			value = yes
		}
		if = {
			limit = { exists = scope:inspiration_sponsor }
			scope:inspiration_sponsor = {
				trigger_event = {
					on_action = inspiration_invalidated_events
				}
			}
		}
	}
	on_sponsor_invalidated = {
		save_scope_value_as = {
			name = bow_inspiration
			value = yes
		}
		if = {
			limit = { exists = scope:inspiration_sponsor }
			scope:inspiration_sponsor = {
				trigger_event = {
					on_action = inspiration_invalidated_events
				}
			}
		}
	}
}
