namespace = bp3_court_position

# Court Brewmaster upkeep event
bp3_court_position.100 = {
	type = character_event
	hidden = yes

	trigger = {
		NOT = { has_variable = experimental_brew_cooldown }
		exists = court_position:court_brewmaster_court_position
		has_variable = active_experimental_brew
	}

	immediate = {
		# Set a cooldown, so it can only happen once every 6 months
		set_variable = {
			name = experimental_brew_cooldown
			days = 179
		}

		set_variable = {
			name = experimental_brew_creator
			value = court_position:court_brewmaster_court_position
		}

		# Find what kind of drink it is (see 00_court_position_modifiers for a list of modifiers)
		random_list = {
			3 = { # Negative Drinks
				add_character_flag = experimental_brew_negative				
			}
			1 = { # Childish Drinks
				trigger = {
					any_child = {
						count >= 1
						is_adult = no
						age >= 6
					}
				}
				add_character_flag = experimental_brew_childish
				random_child = {
					limit = {
						is_adult = no
						age >= 6
					}
					root = {
						set_variable = {
							name = experimental_brew_child
							value = prev
						}
					}
				}
			}
			10 = { # Positive Drinks
				add_character_flag = experimental_brew_positive
			}
			3 = { # Very Positive Drinks
				add_character_flag = experimental_brew_very_positive
			}
		}

		# Assign modifier and name
		switch = {
			trigger = has_character_flag
			experimental_brew_negative = {
				random_list = {
					1 = { # Health
						court_brewmaster_assign_modifier_positive_effect = { 
							MODIFIER = small_health_negative 
						}
					}
					1 = { # Courtier and Guest Opinion
						court_brewmaster_assign_modifier_positive_effect = {
							MODIFIER = court_guest_opinion_negative
						}
					}
					1 = { # Negative Prestige
						court_brewmaster_assign_modifier_positive_effect = {
							MODIFIER = prestige_negative
						}
					}
					1 = { # Negative Piety
						court_brewmaster_assign_modifier_positive_effect = {
							MODIFIER = piety_negative
						}
					}
				}
			}
			experimental_brew_childish = {
				# Child Opinion
				court_brewmaster_assign_modifier_positive_effect = {
					MODIFIER = child_opinion
				}
			}
			experimental_brew_positive = {
				random_list = {
					1 = { # Diplomacy
						court_brewmaster_assign_modifier_positive_effect = {
							MODIFIER = diplomacy
						}
					}
					1 = { # Martial
						court_brewmaster_assign_modifier_positive_effect = {
							MODIFIER = martial
						}
					}
					1 = { # Stewardship
						court_brewmaster_assign_modifier_positive_effect = {
							MODIFIER = stewardship
						}
					}
					1 = { # Intrigue
						court_brewmaster_assign_modifier_positive_effect = {
							MODIFIER = intrigue
						}
					}
					1 = { # Learning
						court_brewmaster_assign_modifier_positive_effect = {
							MODIFIER = learning
						}
					}
					1 = { # Prowess
						court_brewmaster_assign_modifier_positive_effect = {
							MODIFIER = prowess
						}
					}
					1 = { # Courtier and Guest Opinion
						court_brewmaster_assign_modifier_positive_effect = {
							MODIFIER = court_guest_opinion_positive
						}
					}
					1 = { # Courtly Opinion
						court_brewmaster_assign_modifier_positive_effect = {
							MODIFIER = courtly_opinion
						}
					}
					1 = { # Prestige
						court_brewmaster_assign_modifier_positive_effect = {
							MODIFIER = prestige_positive
						}
					}
					1 = { # Piety
						court_brewmaster_assign_modifier_positive_effect = {
							MODIFIER = piety_positive
						}
					}
					1 = { # Attraction Opinion
						court_brewmaster_assign_modifier_positive_effect = {
							MODIFIER = attraction_opinion
						}
					}
					1 = { # Fertility
						court_brewmaster_assign_modifier_positive_effect = {
							MODIFIER = fertility
						}
					}
				}
			}
			experimental_brew_very_positive = {
				random_list = {
					1 = { # General Opinion
						court_brewmaster_assign_modifier_positive_effect = {
							MODIFIER = general_opinion
						}
					}
					1 = { # Stress Loss
						court_brewmaster_assign_modifier_positive_effect = {
							MODIFIER = stress_loss
						}
					}
					1 = { # Renown
						court_brewmaster_assign_modifier_positive_effect = {
							MODIFIER = renown
						}
					}
					1 = { # Fascination
						trigger = {
							root.culture.culture_head = root
						}
						court_brewmaster_assign_modifier_positive_effect = {
							MODIFIER = fascination
						}
					}
					1 = { # Monthly Income
						court_brewmaster_assign_modifier_positive_effect = {
							MODIFIER = monthly_income
						}
					}
					1 = { # Health
						court_brewmaster_assign_modifier_positive_effect = {
							MODIFIER = small_health_positive
						}
					}
				}
			}
		}

		### Clean up
		remove_character_flag = experimental_brew_negative
		remove_character_flag = experimental_brew_childish
		remove_character_flag = experimental_brew_positive
		remove_character_flag = experimental_brew_very_positive
		remove_variable = experimental_brew_child
		remove_variable = experimental_brew_creator

		trigger_event = {
			id = bp3_court_position.100
			months = 6
		}
	}
}
