﻿keeper_of_the_harem_court_position_task_maintain_decorum = {
	court_position_types = { keeper_of_the_harem_court_position }

	# Monthly cost for the task
	cost = {
		round = no
		gold = {
			value = 0
			if = {
				limit = {
					scope:liege = {
						has_treasury = no
					}
				}
				add = {
					value = monthly_court_position_task_cost
					multiply = 2
					desc = COURT_POSITION_TASK_COST_BREAKDOWN_BASE
					format = "BASE_VALUE_FORMAT_DECIMALS_PLUS_NEGATIVE"
				}
			}
		}
		treasury = {
			value = 0
			if = {
				limit = {
					scope:liege = {
						has_treasury = yes
					}
				}
				add = {
					value = monthly_court_position_task_cost
					multiply = 2
					desc = COURT_POSITION_TASK_COST_BREAKDOWN_BASE
					format = "BASE_VALUE_FORMAT_DECIMALS_PLUS_NEGATIVE"
				}
			}
		}
	}

	scaling_employer_modifiers = {
		terrible = {
			enemy_scheme_secrecy_add = -1
		}
		poor = {
			enemy_scheme_secrecy_add = -3
		}
		average = {
			enemy_scheme_secrecy_add = -5
		}
		good = {
			enemy_scheme_secrecy_add = -7
		}
		excellent = {
			enemy_scheme_secrecy_add = -10
		}
	}

	on_start = {
		custom_tooltip = keeper_of_the_harem_maintaining_decorum.tt
		scope:liege = {
			add_character_flag = keeper_of_the_harem_maintaining_decorum
		}
	}

	on_end = {
		scope:liege = {
			remove_character_flag = keeper_of_the_harem_maintaining_decorum
		}
	}

	ai_will_do = {
		value = 50
		if = {
			limit = {
				has_trait = paranoid
			}
			add = 50
		}
	}
}

keeper_of_the_harem_court_position_task_attend_to_wellness = {
	court_position_types = { keeper_of_the_harem_court_position }

	# Monthly cost for the task
	cost = {
		round = no
		gold = {
			value = 0
			if = {
				limit = {
					scope:liege = {
						has_treasury = no
					}
				}
				add = {
					value = monthly_court_position_task_cost
					multiply = 2
					desc = COURT_POSITION_TASK_COST_BREAKDOWN_BASE
					format = "BASE_VALUE_FORMAT_DECIMALS_PLUS_NEGATIVE"
				}
			}
		}
		treasury = {
			value = 0
			if = {
				limit = {
					scope:liege = {
						has_treasury = yes
					}
				}
				add = {
					value = monthly_court_position_task_cost
					multiply = 2
					desc = COURT_POSITION_TASK_COST_BREAKDOWN_BASE
					format = "BASE_VALUE_FORMAT_DECIMALS_PLUS_NEGATIVE"
				}
			}
		}
	}

	scaling_employer_modifiers = {
		terrible = {
			epidemic_resistance = 1
		}
		poor = {
			epidemic_resistance = 3
		}
		average = {
			epidemic_resistance = 5
		}
		good = {
			epidemic_resistance = 7
		}
		excellent = {
			epidemic_resistance = 9
		}
	}

	on_monthly = {
		scope:liege = {
			if = {
				limit = {
					any_consort = {
						health <= poor_health
						NOT = {
							has_character_modifier = tgp_harem_medical_treatment_modifier
						}
					}
				}
				random_consort = {
					limit = {
						health <= poor_health
						has_character_modifier = tgp_harem_medical_treatment_modifier
					}
					save_scope_as = ailing_consort
				}
			}
		}
		if = {
			limit = {
				exists = scope:ailing_consort
			}
			scope:ailing_consort = {
				add_stress = minor_stress_loss
				add_character_modifier = {
					modifier = tgp_harem_medical_treatment_modifier
					years = 1
				}
			}
		}
	}

	on_start = {
		custom_tooltip = keeper_of_the_harem_attend_to_wellness.tt
	}

	ai_will_do = {
		value = 50
	}
}

keeper_of_the_harem_court_position_task_select_palace_beauties = {
	court_position_types = { keeper_of_the_harem_court_position }

	# Monthly cost for the task
	cost = {
		round = no
		gold = {
			value = 0
			if = {
				limit = {
					scope:liege = {
						has_treasury = no
					}
				}
				add = {
					value = monthly_court_position_task_cost
					multiply = 2
					desc = COURT_POSITION_TASK_COST_BREAKDOWN_BASE
					format = "BASE_VALUE_FORMAT_DECIMALS_PLUS_NEGATIVE"
				}
			}
		}
		treasury = {
			value = 0
			if = {
				limit = {
					scope:liege = {
						has_treasury = yes
					}
				}
				add = {
					value = monthly_court_position_task_cost
					multiply = 2
					desc = COURT_POSITION_TASK_COST_BREAKDOWN_BASE
					format = "BASE_VALUE_FORMAT_DECIMALS_PLUS_NEGATIVE"
				}
			}
		}
	}

	scaling_employer_modifiers = {
		terrible = {
			stress_loss_mult = 0.10
			stress_gain_mult = -0.01
		}
		poor = {
			stress_loss_mult = 0.12
			stress_gain_mult = -0.02
		}
		average = {
			stress_loss_mult = 0.15
			stress_gain_mult = -0.03
		}
		good = {
			stress_loss_mult = 0.20
			stress_gain_mult = -0.05
		}
		excellent = {
			stress_loss_mult = 0.25
			stress_gain_mult = -0.08
		}
	}

	on_yearly = {	#Unop: Making it the same to the original loc description and reducing the rates of new concubines.
		scope:liege = {
			if = {
				limit = {
					number_of_fertile_concubines < max_number_of_concubines
					any_concubine = {	#Unop: changing to concubine from consorts
						is_ai = yes
						is_designated_diarch = no
						OR = {
							AND = {
								is_female = yes
								age > define:NChildbirth|MAX_FEMALE_REPRODUCTION_AGE
							}
							AND = {
								is_male = yes
								age > define:NCharacter|MALE_ATTRACTION_CUTOFF_AGE
							}
						}
						NOR = {
							any_child = {
								exists = this #Unop exists = yes doesn't work
							}
							has_relation_best_friend = scope:liege
							has_relation_friend = scope:liege
							has_relation_lover = scope:liege
							has_relation_soulmate = scope:liege
						}
					}
				}
				random_concubine = {	#Unop: changing to concubine from consorts
					limit = {			#Unop: reworking the block, so it respects previous limits.
						is_ai = yes
						is_designated_diarch = no
						OR = {
							AND = {
								is_female = yes
								age > define:NChildbirth|MAX_FEMALE_REPRODUCTION_AGE
							}
							AND = {
								is_male = yes
								age > define:NCharacter|MALE_ATTRACTION_CUTOFF_AGE
							}
						}
						NOR = {
							any_child = {
								exists = this #Unop exists = yes doesn't work
							}
							has_relation_best_friend = scope:liege
							has_relation_friend = scope:liege
							has_relation_lover = scope:liege
							has_relation_soulmate = scope:liege
						}
					}
					save_scope_as = aging_concubine
				}
				remove_concubine = scope:aging_concubine
			}
			if = {
				limit = {
					allowed_more_concubines = yes
				}
				create_character = {
					template = tgp_concubine_template
					location = root.location
					save_scope_as = new_concubine
				}
				make_concubine = scope:new_concubine
			}
		}
	}

	on_start = {
		custom_tooltip = keeper_of_the_harem_select_palace_beauties.tt
	}

	ai_will_do = {
		value = 0 # we handle this somewhere else for the AI, instead
	}
}
