###########################################
#
# Hermetics decisions for Monks and Mystics
#
###########################################

targeted_decisions = {

	brew_happiness_potion = {
		filter = sub_realm_including_me
		ai_target_filter = sub_realm_including_me
		ai_check_interval = 24

		is_in_society = yes

		from_potential = {
			has_dlc = "Mystics"

			society_rank = {
				society = hermetics
				rank >= 2
			}
		}

		potential = {
			OR = {
				trait = stressed
				trait = depressed
			}

			trigger_if = {
				limit = {
					FROM = { ai = yes }
				}

				OR = {
					character = FROM
					is_close_relative = FROM
					is_friend = FROM
					is_lover = FROM
				}
			}
		}

		allow = {
			OR = {
				trait = stressed
				trait = depressed
			}

			FROM = {
				has_society_currency_minor_trigger = yes

				custom_tooltip = {
					text = must_have_ingredients_tt

					any_artifact = {
						count >= 2
						has_artifact_flag = ingredient
					}
				}

				custom_tooltip = {
					text = must_not_already_be_preparing_potion_tt

					NOT = { has_character_flag = preparing_potion }
				}
			}
		}

		effect = {
			FROM = {
				show_scope_change = no

				detract_society_currency_minor_effect = yes
				set_character_flag = preparing_potion
			}

			if = {
				limit = { character = FROM } # Making yourself a potion

				custom_tooltip = {
					text = brew_happiness_potion_effect_self

					set_character_flag = potion_target_is_self
					character_event = { id = MNM.5115 }
				}
			}
			else = { # Making someone else a potion
				save_event_target_as = potion_target

				custom_tooltip = {
					text = brew_happiness_potion_effect_other

					FROM = {
						character_event = { id = MNM.5115 }
					}
				}
			}

			tooltip = {
				remove_trait_silently_stressed_effect = yes
				remove_trait_silently_depressed_effect = yes

				if = {
					limit = { has_character_modifier = apathetic }
					remove_character_modifier = apathetic
				}
			}
		}

		ai_will_do = {
			factor = 0.01

			mult_modifier = {
				factor = 100
				character = FROM
			}

			mult_modifier = {
				factor = 10

				reverse_opinion = {
					who = FROM
					value >= 30
				}
			}
		}
	}

	hermetics_perform_scrying = {
		filter = self
		ai_target_filter = self
		ai_check_interval = 10

		is_in_society = yes

		potential = {
			has_dlc = "Mystics"

			society_rank = {
				society = hermetics
				rank >= 2
			}
		}

		allow = {
			has_society_currency_minor_trigger = yes

			custom_tooltip = {
				text = hermetics_scrying_cooldown_tooltip

				has_an_omen_modifier_trigger = no
				NOT = { has_character_modifier = scrying_cooldown }
			}
		}

		effect = {
			detract_society_currency_minor_effect = yes

			add_character_modifier = {
				name = scrying_cooldown
				years = 1
				hidden = yes
			}

			character_event = {
				id = MNM.1200
				days = 1
			}
		}

		ai_will_do = {
			factor = 0.5

			mult_modifier = {
				factor = 0.5
				is_dumb_trigger = yes
			}

			mult_modifier = {
				factor = 0.5
				trait = content
			}

			mult_modifier = {
				factor = 0.5
				trait = cynical
			}

			mult_modifier = {
				factor = 1.5
				trait = ambitious
			}

			mult_modifier = {
				factor = 1.5
				trait = trusting
			}
		}
	}

	hermetics_make_horoscope = {
		ai_target_filter = court
		ai_check_interval = 10

		is_in_society = yes

		from_potential = {
			has_dlc = "Mystics"

			society_rank = {
				society = hermetics
				rank >= 3
			}
		}

		potential = {
			is_child_of = FROM
		}

		allow = {
			is_adult = no

			custom_tooltip = {
				text = hermetics_horoscope_cooldown_tooltip

				NOT = { has_character_modifier = horoscope_cooldown }
			}

			FROM = { has_society_currency_medium_trigger = yes }
		}

		effect = {
			save_event_target_as = horoscope_child

			add_character_modifier = {
				name = horoscope_cooldown
				duration = -1 # not actually a cooldown, but blocks decision until cleared (which does happen, promise)
				hidden = yes
			}

			FROM = {
				show_scope_change = no

				detract_society_currency_medium_effect = yes

				character_event = {
					id = MNM.1250
					days = 5
				}
			}
		}

		ai_will_do = {
			factor = 0.05

			mult_modifier = {
				factor = 1.5
				is_dumb_trigger = yes
			}

			mult_modifier = {
				factor = 1.5
				is_smart_trigger = yes
			}

			mult_modifier = {
				factor = 10
				is_primary_heir = FROM
			}

			mult_modifier = {
				factor = 1.5
				FROM = { trait = trusting }
			}

			mult_modifier = {
				factor = 0.5
				FROM = { trait = cynical }
			}
		}
	}

	choose_hermetic_art = {
		filter = self
		ai_target_filter = self
		ai_check_interval = 3

		is_in_society = yes
		only_playable = yes

		potential = {
			has_dlc = "Mystics"

			society_rank = {
				society = hermetics
				rank == 4
			}
		}

		allow = {
			custom_tooltip = {
				text = choose_hermetic_art_allow_tooltip

				NOT = { has_character_flag = choosing_hermetic_art }
			}

			OR = {
				lifestyle_traits < 1
				trait = scholar
				trait = mystic
				trait = theologian
			}

			has_society_currency_minor_trigger = yes
		}

		effect = {
			detract_society_currency_minor_effect = yes
			set_character_flag = choosing_hermetic_art

			hidden_effect = {
				if = {
					limit = {
						OR = {
							trait = scholar
							trait = mystic
							trait = theologian
						}
					}

					character_event = { id = MNM.1901 }
				}
				else = {
					character_event = { id = MNM.1900 }
				}
			}
		}

		ai_will_do = {
			factor = 1

			trigger = {
				lifestyle_traits < 1
			}
		}
	}

	# Power: write Magnum Opus
	hermetics_write_magnum_opus = {
		filter = self
		ai_target_filter = self
		ai_check_interval = 12

		is_in_society = yes

		potential = {
			society_rank = {
				society = hermetics
				rank == 4
			}

			prisoner = no
			is_incapable = no
		}

		allow = {
			FROM = {
				show_scope_change = no

				has_society_currency_major_trigger = yes

				custom_tooltip = {
					text = hermetics_wrote_magnum_opus_cd_tooltip

					NOT = { has_character_flag = wrote_magnum_opus }
				}

				custom_tooltip = {
					text = hermetics_wrote_magnum_opus_duplicate

					OR = {
						NOR = {
							has_artifact = magnum_opus_theurgy_ritual_1
							has_artifact = magnum_opus_theurgy_ritual_2
							has_artifact = magnum_opus_theurgy_ritual_3
							has_artifact = magnum_opus_theurgy_ritual_4
						}

						NOR = {
							has_artifact = magnum_opus_theurgy_contemplation_1
							has_artifact = magnum_opus_theurgy_contemplation_2
							has_artifact = magnum_opus_theurgy_contemplation_3
							has_artifact = magnum_opus_theurgy_contemplation_4
						}

						NOR = {
							has_artifact = magnum_opus_astrology_stars_1
							has_artifact = magnum_opus_astrology_stars_2
							has_artifact = magnum_opus_astrology_stars_3
							has_artifact = magnum_opus_astrology_stars_4
						}

						NOR = {
							has_artifact = magnum_opus_astrology_planets_1
							has_artifact = magnum_opus_astrology_planets_2
							has_artifact = magnum_opus_astrology_planets_3
							has_artifact = magnum_opus_astrology_planets_4
						}

						NOR = {
							has_artifact = magnum_opus_alchemy_panacea_1
							has_artifact = magnum_opus_alchemy_panacea_2
							has_artifact = magnum_opus_alchemy_panacea_3
							has_artifact = magnum_opus_alchemy_panacea_4
						}

						NOR = {
							has_artifact = magnum_opus_alchemy_transmutation_1
							has_artifact = magnum_opus_alchemy_transmutation_2
							has_artifact = magnum_opus_alchemy_transmutation_3
							has_artifact = magnum_opus_alchemy_transmutation_4
						}
					}
				}
			}
		}

		effect = {
			detract_society_currency_major_effect = yes

			set_character_flag = wrote_magnum_opus

			character_event = {
				id = MNM.1610
				days = 1
			}
		}
	}

	invite_hermetic_to_stargazing = {
		filter = society
		ai_target_filter = society
		ai_check_interval = 36

		is_in_society = yes
		only_playable = yes

		from_potential = {
			has_dlc = "Mystics"
			society_member_of = hermetics
			prisoner = no
		}

		potential = {
			is_within_diplo_range = FROM
			prisoner = no
		}

		allow = {
			ROOT = {
				war = no
				is_incapable = no
				is_inaccessible_trigger = no
				NOT = { trait = blinded }
			}

			FROM = {
				war = no
				is_incapable = no
				is_inaccessible_trigger = no
				NOT = { trait = blinded }

				custom_tooltip = {
					text = has_not_recently_performed_stargazing

					NOR = {
						has_character_modifier = stargazing_timer
						has_character_modifier = inviting_to_stargazing
					}
				}
			}
		}

		effect = {
			FROM = {
				set_character_flag = do_not_disturb

				if = {
					limit = {
						NOT = { has_character_modifier = inviting_to_stargazing }
					}

					set_character_flag = inviting_guests_to_stargazing_timer

					add_character_modifier = {
						name = inviting_to_stargazing
						months = 6
						hidden = yes
					}
				}
			}

			letter_event = {
				id = MNM.1920 # Invitation
				days = 7
			}
		}

		ai_will_do = {
			factor = 0.01

			trigger = {
				has_epidemic_disease_trigger = no

				NOR = {
					is_rival = FROM
					trait = leper
				}
			}
		}
	}

}

society_decisions = {

	build_laboratory = {
		ai_check_interval = 36

		is_high_prio = yes

		only_playable = yes

		potential = {
			society_member_of = hermetics
			has_quest = quest_hermetics_build_laboratory
			block_general_event_trigger = no

			NOR = {
				has_character_flag = building_laboratory
				has_character_flag = built_laboratory
			}
		}

		allow = {
			wealth >= 50
		}

		effect = {
			wealth = -50

			custom_tooltip = {
				text = start_constructing_laboratory_tooltip

				set_character_flag = building_laboratory
				character_event = { id = MNM.1100 }
			}
		}

		ai_will_do = {
			factor = 1

			trigger = {
				wealth >= 75
			}

			mult_modifier = {
				factor = 0.1
				age < 30
			}
		}
	}

	hermetics_acquire_ingredients_decision = {
		ai_check_interval = 24

		potential = {
			society_member_of = hermetics
		}

		allow = {
			custom_tooltip = {
				text = tooltip_not_busy

				block_general_event_trigger = no
			}

			custom_tooltip = {
				text = acquire_ingredients_decision_cooldown_timer_tt

				NOT = { has_character_modifier = acquire_ingredients_decision_cooldown_timer }
			}

			custom_tooltip = {
				text = acquire_ingredients_decision_apprentice_requirement

				has_assigned_minor_title = title_hermetics_apprentice
			}

			custom_tooltip = {
				text = acquire_ingredients_decision_too_many_ingredients

				NOT = {
					any_artifact = {
						count >= 5
						has_artifact_flag = ingredient
					}
				}
			}
		}

		effect = {
			custom_tooltip = { text = acquire_ingredients_effect_tooltip }

			add_character_modifier = {
				name = acquire_ingredients_decision_cooldown_timer
				years = 5
				hidden = yes
			}

			character_event = { id = MNM.1800 }
		}

		ai_will_do = {
			factor = 0.01

			trigger = {
				# Already have ingredients
				NOT = {
					any_artifact = {
						has_artifact_flag = ingredient
					}
				}
			}
		}
	}

	# Write a Theorem Paper
	hermetics_write_theory_paper = {
		ai_check_interval = 24

		potential = {
			society_member_of = hermetics
		}

		allow = {
			is_not_in_regency_trigger = yes
			is_inaccessible_trigger = no

			custom_tooltip = {
				text = write_theory_paper_decision_cooldown_timer_tt

				NOT = { has_character_modifier = write_theory_paper_decision_cooldown_timer	}
			}
		}

		effect = {
			custom_tooltip = {
				text = write_theory_paper_decision_effect_tt

				add_character_modifier = {
					name = write_theory_paper_decision_cooldown_timer
					years = 5
					hidden = yes
				}

				character_event = { id = MNM.1630 }
			}
		}

		ai_will_do = {
			factor = 0.01
		}
	}

	hermetic_grand_debate = {
		ai_check_interval = 24

		is_high_prio = yes

		only_playable = yes

		potential = {
			has_dlc = "Mystics"

			society_rank = {
				society = hermetics
				rank == 4
			}
		}

		allow = {
			wealth >= 100
			prestige >= 400
			is_inaccessible_trigger = no
			is_not_in_regency_trigger = yes

			custom_tooltip = {
				text = GRAND_DEBATE_HOLDING_TOOLTIP

				trigger_if = {
					limit = { has_global_flag = holding_grand_debate }

					had_global_flag = {
						flag = holding_grand_debate
						days >= 150
					}
				}
			}

			custom_tooltip = {
				text = GRAND_DEBATE_COOLDOWN_TOOLTIP

				trigger_if = {
					limit = { has_global_flag = held_grand_debate }

					had_global_flag = {
						flag = held_grand_debate
						years >= 10
					}
				}
			}
		}

		effect = {
			wealth = -100

			clr_character_flag = grand_debate_has_ended
			set_character_flag = do_not_disturb
			set_global_flag = holding_grand_debate

			character_event = {
				id = MNM.1982 # Safety catch flag clearing
				days = 300
			}

			character_event = {
				id = MNM.1980
				tooltip = GRAND_DEBATE_INVITE_TOOLTIP
			}
		}

		ai_will_do = {
			factor = 0.01
		}
	}

}