#######################################
# Order of the Sacred Magdalene
# Brothel Decisions
#
# Uses the Order's own House of Mercy buildings.
# Christianity Mod prostitution traits and selected
# consequence events remain where useful, but GGSM
# owns access, selection, flags, and scenes.
#######################################

decisions = {

	#######################################
	# WORK AS A PROSTITUTE
	#######################################

	ggsm_work_whore = {
		potential = {
			is_female = yes
			is_adult = yes
			religion = catholic
			society_member_of = ggsm_order_sacred_magdalene
			has_character_flag = ggsm_sacred_prostitute
			NOT = { practical_age >= 50 }

			# The sister must physically be at a House of Mercy.
			location = {
				any_province_holding = {
					OR = {
						has_building = tb_ggsm_magdalene_house_1
						has_building = tb_ggsm_magdalene_house_2
						has_building = tb_ggsm_magdalene_house_3
						has_building = tb_ggsm_magdalene_house_4
						has_building = tb_ggsm_magdalene_house_5
						has_building = ca_ggsm_magdalene_house_1
						has_building = ca_ggsm_magdalene_house_2
						has_building = ca_ggsm_magdalene_house_3
						has_building = ca_ggsm_magdalene_house_4
						has_building = ca_ggsm_magdalene_house_5
						has_building = ct_ggsm_magdalene_house_1
						has_building = ct_ggsm_magdalene_house_2
						has_building = ct_ggsm_magdalene_house_3
						has_building = ct_ggsm_magdalene_house_4
						has_building = ct_ggsm_magdalene_house_5
					}
				}
			}
		}

		allow = {
			is_marriage_adult = yes

			NOR = {
				trait = incapable
				trait = chaste
				trait = celibate
				trait = excommunicated
				is_inaccessible_trigger = yes
				prisoner = yes
				in_command = yes
			}

			custom_tooltip = {
				text = ggsm_not_working
				NOT = { has_character_modifier = ggsm_house_rest }
			}
		}

		effect = {


			#######################################
			# APPLY HOUSE REST BEFORE .700
			#
			# House Rest is the only availability lock.
			# It is applied before the visible chain
			# and expires automatically after thirty days.
			#######################################


			add_character_modifier = {
				name = ggsm_house_rest
				duration = 30
			}

			#######################################
			# DETERMINE EARNING BRACKET
			#######################################

			hidden_tooltip = {
				set_variable = {
					which = wealth_temp
					value = 3
				}
			}

			if = {
				limit = { trait = bombshell }
				hidden_tooltip = {
					change_variable = {
						which = wealth_temp
						value = 2
					}
				}
			}

			if = {
				limit = { trait = fair }
				hidden_tooltip = {
					change_variable = {
						which = wealth_temp
						value = 2
					}
				}
			}

			if = {
				limit = {
					NOT = { practical_age >= 30 }
				}
				hidden_tooltip = {
					change_variable = {
						which = wealth_temp
						value = 2
					}
				}
			}

			if = {
				limit = {
					NOT = { practical_age >= 40 }
				}
				hidden_tooltip = {
					change_variable = {
						which = wealth_temp
						value = 2
					}
				}
			}

			if = {
				limit = { trait = lustful }
				hidden_tooltip = {
					change_variable = {
						which = wealth_temp
						value = 2
					}
				}
			}

			if = {
				limit = {
					check_variable = {
						which = breast_size
						value = 4
					}
					NOT = {
						check_variable = {
							which = breast_size
							value = 6
						}
					}
				}
				hidden_tooltip = {
					change_variable = {
						which = wealth_temp
						value = 2
					}
				}
			}

			if = {
				limit = {
					check_variable = {
						which = breast_size
						value = 6
					}
				}
				hidden_tooltip = {
					change_variable = {
						which = wealth_temp
						value = 3
					}
				}
			}


			#######################################
			# CHRISTIANITY MOD PROSTITUTION TRAITS
			#######################################

			hidden_tooltip = {
				if = {
					limit = {
						trait = experienced_whore
					}
					random = {
						chance = 5
						add_trait = exclusive_whore

						character_event = { id = christ.15 }
					}
				}

				if = {
					limit = {
						trait = cheap_whore
					}
					random = {
						chance = 10
						add_trait = experienced_whore
					}
				}

				if = {
					limit = {
						NOT = {
							trait = cheap_whore
							trait = experienced_whore
							trait = exclusive_whore
						}
					}
					add_trait = cheap_whore
				}
			}


			#######################################
			# BEGIN THE WORK ENCOUNTER
			#
			# The decision has already applied the
			# thirty-day House Rest modifier.
			# ggsm.700 selects and saves the client
			# before its visible window is displayed.
			#######################################

			long_character_event = { id = ggsm.700 }
		}

		revoke_allowed = {
			always = no
		}

		ai_will_do = {
			factor = 1

			modifier = {
				factor = 2
				trait = lustful
			}

			modifier = {
				factor = 3
				trait = nymphomaniac
			}

			modifier = {
				factor = 5
				trait = hedonist
			}

			modifier = {
				factor = 0
				has_character_modifier = ggsm_house_rest
			}

		}
	}


	#######################################
	# VISIT A BROTHEL
	#######################################

	ggsm_visit_brothel = {
		potential = {
			is_adult = yes
			is_female = no
			religion = catholic

			# He must actually be in a province with a House of Mercy.
			location = {
				any_province_holding = {
					OR = {
						has_building = tb_ggsm_magdalene_house_1
						has_building = tb_ggsm_magdalene_house_2
						has_building = tb_ggsm_magdalene_house_3
						has_building = tb_ggsm_magdalene_house_4
						has_building = tb_ggsm_magdalene_house_5
						has_building = ca_ggsm_magdalene_house_1
						has_building = ca_ggsm_magdalene_house_2
						has_building = ca_ggsm_magdalene_house_3
						has_building = ca_ggsm_magdalene_house_4
						has_building = ca_ggsm_magdalene_house_5
						has_building = ct_ggsm_magdalene_house_1
						has_building = ct_ggsm_magdalene_house_2
						has_building = ct_ggsm_magdalene_house_3
						has_building = ct_ggsm_magdalene_house_4
						has_building = ct_ggsm_magdalene_house_5
					}
				}
			}
		}

		allow = {
			# A vowed Magdalene sister must actually be present and
			# available in the House province.
			location = {
				any_province_character = {
					society_member_of = ggsm_order_sacred_magdalene
					has_character_flag = ggsm_sacred_prostitute
					is_female = yes
					is_adult = yes
					religion = catholic
					prisoner = no
					in_command = no
					is_inaccessible_trigger = no
					NOR = {
						trait = incapable
						trait = excommunicated
						practical_age >= 50
					}
					NOT = { has_character_modifier = ggsm_house_rest }
				}
			}

			NOR = {
				trait = incapable
				trait = excommunicated
				practical_age >= 50
				is_inaccessible_trigger = yes
				prisoner = yes
				in_command = yes
			}

			wealth = 10
		}

		effect = {
			# Select only a vowed Catholic Magdalene sister who is
			# physically present in this House province.
			location = {
				random_province_character = {
					limit = {
						# Re-check the exact same availability trigger
						# at actual selection time. This closes the
						# same-tick queue hole.
						society_member_of = ggsm_order_sacred_magdalene
						has_character_flag = ggsm_sacred_prostitute
						is_female = yes
						is_adult = yes
						religion = catholic
						prisoner = no
						in_command = no
						is_inaccessible_trigger = no
						NOR = {
							trait = incapable
							trait = excommunicated
							practical_age >= 50
						}
						NOT = { has_character_modifier = ggsm_house_rest }
					}

					save_event_target_as = ggsm_whore
				}
			}

			# Never fire kin handling or the visible scene with
			# a blank / nonexistent sister target.
			if = {
				limit = {
					event_target:ggsm_whore = {
						always = yes
					}
				}

				#######################################
				# APPLY HOUSE REST AT THE DOOR
				#
				#     occupied by this encounter now.
				#
				# ggsm_house_rest:
				#     timed thirty-day balance lockout,
				#     whether the visitor buys service,
				#     leaves, or is stopped by kin.
				#
				# The modifier owns its own expiration.
				# There is no delayed clear event.
				#######################################
				event_target:ggsm_whore = {

					add_character_modifier = {
						name = ggsm_house_rest
						duration = 30
					}
				}

				# GGSM-owned male House of Mercy visit scene.
				long_character_event = { id = ggsm.720 }
			}
		}

		revoke_allowed = {
			always = no
		}

		ai_will_do = {
			factor = 1

			modifier = {
				factor = 0

				NOT = {
					OR = {
						wealth = 30
						trait = lustful
						trait = shy
					}
				}
			}
		}
	}
}