﻿
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
			}
		}
		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
							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_jewelry
									}
								}
								10 = {
									set_variable = {
										name = artifact_smith_type
										value = flag:smith_type_regalia
									}
								}
								10 = {
									set_variable = {
										name = artifact_smith_type
										value = flag:smith_type_crown
									}
								}
								10 = {
									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
				}
			}
		}
	}
}

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
			}
		}
		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.
							}
						}
						25 = {
							set_variable = banner_commission
						}
						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
				}
			}
		}
	}
}
