﻿### Orgy Pulse Actions
# Have all Orgy Specific Pulse Actions here

## Spouse Pulse Actions - Similar to vanilla, except allows any spouse, not just primary
	regula_spouse_gives_host_prestige = {
		icon = marriage
		is_valid = {
			is_current_phase_active = yes
			scope:host = {
				any_consort = {
					involved_activity ?= scope:activity
					is_physically_able_ai_adult = yes
					likes_character_trigger = { CHARACTER = scope:host }
					OR = {
						diplomacy >= 12
						has_trait = diplomat
					}
					location = scope:province
					save_temporary_scope_as = first
				}
			}
			any_attending_character = {
				NOT = { this = scope:host }
				NOT = { this = scope:first }
				OR = {
					is_ruler = yes
					is_councillor = yes
				}
				is_physically_able_ai_adult = yes
				location = scope:province
			}
		}

		weight = {
			value = 1
			if = {
				limit = {
					scope:first ?= {
						diplomacy >= 16
					}
				}
				add = 0.5
			}
			if = {
				limit = {
					scope:first ?= {
						has_personality_introverted_trigger = yes
					}
				}
				add = -0.75
			}
		}

		effect = {
			scope:host = {
				random_consort = {
					limit = {
						involved_activity ?= scope:activity
						is_physically_able_ai_adult = yes
						likes_character_trigger = { CHARACTER = scope:host }
						OR = {
							diplomacy >= 12
							has_trait = diplomat
						}
						location = scope:province
					}
					save_scope_as = first
				}
			}

			random_attending_character = {
				limit = {
					NOT = { this = scope:host }
					NOT = { this = scope:first }
					OR = {
						is_ruler = yes
						is_councillor = yes
					}
					is_physically_able_ai_adult = yes
					location = scope:province
				}
				save_scope_as = second
			}

			add_activity_log_entry = {
				key = spouse_gives_host_prestige
				tags = { pulse_action }
				character = scope:first
				target = scope:second

				scope:host = {
					add_prestige = medium_prestige_gain
				}
				scope:second = {
					add_opinion = {
						modifier = impressed_opinion
						target = scope:host
						opinion = 10
					}
				}
			}
		}
	}

	regula_spouse_manages_orgy_splendidly = {
		icon = marriage
		is_valid = {
			is_current_phase_active = yes
			scope:host = {
				any_consort = {
					involved_activity ?= scope:activity
					is_physically_able_ai_adult = yes
					likes_character_trigger = { CHARACTER = scope:host }
					OR = {
						stewardship >= 12
						has_trait = architect
					}
					location = scope:province
				}
			}
		}

		weight = {
			value = 1
			if = {
				limit = {
					scope:first ?= {
						stewardship >= 16
					}
				}
				add = 0.5
			}
			if = {
				limit = {
					scope:first ?= {
						has_personality_submissive_trigger = yes
					}
				}
				add = -0.75
			}
		}

		effect = {
			scope:host = {
				random_consort = {
					limit = {
						involved_activity ?= scope:activity
						is_physically_able_ai_adult = yes
						likes_character_trigger = { CHARACTER = scope:host }
						OR = {
							stewardship >= 12
							has_trait = architect
						}
						location = scope:province
					}
					save_scope_as = first
				}
			}

			add_activity_log_entry = {
				key = spouse_manages_feast_splendidly
				tags = { pulse_action }
				character = scope:first

				scope:province.county = {
					change_development_progress_with_overflow = 20
				}
				scope:host = {
					if = {
						limit = {
							any_vassal = {
								has_vassal_stance = parochial
							}
						}
						every_vassal = {
							custom = every_parochial_vassal_no_count
							add_opinion = {
								modifier = impressed_opinion
								opinion = 5
								target = scope:host
							}
						}
					}
				}
			}
		}
	}

	regula_spouse_impresses_clergy = {
		icon = marriage
		is_valid = {
			is_current_phase_active = yes
			scope:host = {
				any_consort = {
					involved_activity ?= scope:activity
					is_physically_able_ai_adult = yes
					likes_character_trigger = { CHARACTER = scope:host }
					OR = {
						learning >= 12
						has_trait = theologian
					}

					# Look for clergy member to impress
					scope:activity = {
						any_attending_character = {
							NOT = { this = scope:host }
							NOT = { this = this }
							OR = {
								is_clergy = yes
								has_council_position = councillor_court_chaplain
							}
							is_physically_able_ai_adult = yes
						}
					}
				}
			}
		}

		weight = {
			value = 1
			if = {
				limit = {
					scope:first ?= {
						learning >= 16
					}
				}
				add = 0.5
			}
			if = {
				limit = {
					scope:first ?= {
						has_personality_extroverted_trigger = yes
					}
				}
				add = -0.75
			}
		}

		effect = {

			scope:host = {
				random_consort = {
					limit = {
						involved_activity ?= scope:activity
						is_physically_able_ai_adult = yes
						likes_character_trigger = { CHARACTER = scope:host }
						OR = {
							learning >= 12
							has_trait = theologian
						}
						location = scope:province
					}
					save_scope_as = first
				}
			}

			random_attending_character = {
				limit = {
					NOT = { this = scope:host }
					NOT = { this = scope:first }
					OR = {
						is_clergy = yes
						has_council_position = councillor_court_chaplain
					}
					is_physically_able_ai_adult = yes
					location = scope:province
				}
				save_scope_as = second
			}

			add_activity_log_entry = {
				key = spouse_impresses_clergy
				tags = { pulse_action }
				character = scope:first
				target = scope:second

				scope:host = {
					add_piety = minor_piety_gain
				}
				scope:second = {
					add_opinion = {
						modifier = impressed_opinion
						target = scope:host
						opinion = 20
					}
				}
			}
		}
	}

	regula_spouse_gives_hook = {
		icon = marriage
		is_valid = {
			is_current_phase_active = yes
			scope:host = {
				any_consort = {
					involved_activity ?= scope:activity
					is_physically_able_ai_adult = yes
					likes_character_trigger = { CHARACTER = scope:host }
					OR = {
						intrigue >= 12
						has_trait = schemer
					}
					scope:activity = {
						any_attending_character = {
							NOT = { this = scope:host }
							NOT = { this = this }
							is_ruler = yes
							primary_title.tier > tier_barony
							intrigue < scope:first.intrigue
							is_physically_able_ai_adult = yes
							scope:host = {
								can_add_hook = {
									target = prev
									type = manipulation_hook
								}
							}
						}
					}
				}
			}
		}

		weight = {
			value = 1
			if = {
				limit = {
					scope:first ?= {
						intrigue >= 16
					}
				}
				add = 0.5
			}
			if = {
				limit = {
					scope:first ?= {
						has_personality_benevolent_trigger = yes
					}
				}
				add = -0.75
			}
		}

		effect = {
			scope:host={
				random_consort = {
					limit = {
						involved_activity ?= scope:activity
						is_physically_able_ai_adult = yes
						likes_character_trigger = { CHARACTER = scope:host }
						OR = {
							intrigue >= 12
							has_trait = schemer
						}
						location = scope:province
					}
					save_scope_as = first
				}
			}

			random_attending_character = {
				limit = {
					NOT = { this = scope:host }
					NOT = { this = scope:first }
					is_ruler = yes
					primary_title.tier > tier_barony
					intrigue < scope:first.intrigue
					is_physically_able_ai_adult = yes
					location = scope:province
					scope:host = {
						can_add_hook = {
							target = prev
							type = manipulation_hook
						}
					}
				}
				save_scope_as = second
			}

			add_activity_log_entry = {
				key = spouse_gives_hook
				tags = { pulse_action }
				character = scope:first
				target = scope:second

				scope:host = {
					add_hook = {
						type = manipulation_hook
						target = scope:second
					}
				}
				scope:second = {
					add_opinion = {
						modifier = suspicion_opinion
						target = scope:first
						opinion = -10
					}
				}
			}
		}
	}

	# Domina charms a non-devoted guest
	regula_domina_charms_guest = {
		icon = regula
		is_valid = {
			is_current_phase_active = yes
			scope:host = {
				character_has_regula_holy_effect_mulsa_fascinare = yes
				any_consort = {
					has_trait = domina
					involved_activity ?= scope:activity
					location = scope:province
					is_physically_able_ai_adult = yes
					NOT = { has_character_flag = regula_domina_charms_guest }
				}
			}
			any_attending_character = {
				NOT = { this = scope:host }
				NOT = { has_trait = devoted_trait_group }
				is_physically_able_ai_adult = yes
				location = scope:province
				is_female = yes
				is_adult = yes
			}
		}

		weight = {
			value = 1
		}

		effect = {
			scope:host = {
				random_consort = {
					limit = {
						has_trait = domina
						involved_activity ?= scope:activity
						location = scope:province
						is_physically_able_ai_adult = yes
						NOT = { has_character_flag = regula_domina_charms_guest }
					}
					save_scope_as = first
				}
			}

			scope:first = {
				add_character_flag = {
					flag = regula_domina_charms_guest
					days = 730
				}
			}

			random_attending_character = {
				limit = {
					NOT = { this = scope:host }
					NOT = { has_trait = devoted_trait_group }
					is_physically_able_ai_adult = yes
					location = scope:province
					is_female = yes
					is_adult = yes
				}
				save_scope_as = second
			}

			add_activity_log_entry = {
				key = regula_domina_charms_guest
				tags = { pulse_action }
				character = scope:first
				target = scope:second

				scope:second = {
					fascinare_success_effect = { CHARACTER = scope:first }
					create_memory_fascinare_default = { CHARACTER = scope:first }
				}
			}
		}
	}

	# Devoted (Domina/Paelex) befriends another Devoted
	regula_devoted_befriends_devoted = {
		icon = friend

		# Do we have two devoted who aren't yet friends?
		# Also they have not already taken part in this pulse action
		is_valid = {
			is_current_phase_active = yes
			scope:host = {
				any_consort = {
					is_regula_leader_devoted_trigger = yes
					involved_activity ?= scope:activity
					location = scope:province
					is_physically_able_ai_adult = yes
					NOT = { has_character_flag = regula_devoted_befriends_devoted }
					save_temporary_scope_as = first
				}
				any_consort = {
					NOT = { this = scope:first }
					NOT = { has_relation_friend = scope:first }
					is_regula_leader_devoted_trigger = yes
					involved_activity ?= scope:activity
					location = scope:province
					is_physically_able_ai_adult = yes
					NOT = { has_character_flag = regula_devoted_befriends_devoted }
				}
			}
		}

		weight = {
			value = 1
		}

		effect = {

			# Get our two Devoted who will befriend each other
			scope:host = {
				random_consort = {
					limit = {
						is_regula_leader_devoted_trigger = yes
						involved_activity ?= scope:activity
						location = scope:province
						is_physically_able_ai_adult = yes
						NOT = { has_character_flag = regula_devoted_befriends_devoted }
					}
					save_scope_as = first
				}
				random_consort = {
					limit = {
						NOT = { this = scope:first }
						NOT = { has_relation_friend = scope:first }
						is_regula_leader_devoted_trigger = yes
						involved_activity ?= scope:activity
						location = scope:province
						is_physically_able_ai_adult = yes
						NOT = { has_character_flag = regula_devoted_befriends_devoted }
					}
					save_scope_as = second
				}
			}

			# Flag them so this cant happen again during the same Orgy
			scope:first = {
				add_character_flag = {
					flag = regula_devoted_befriends_devoted
					days = 730
				}
			}

			scope:second = {
				add_character_flag = {
					flag = regula_devoted_befriends_devoted
					days = 730
				}
			}

			add_activity_log_entry = {
				key = regula_devoted_befriends_devoted
				tags = { pulse_action }
				character = scope:first
				target = scope:second

				scope:first = {
					set_relation_friend = scope:second
				}
			}
		}
	}

## Host Pulse Actions

	# Gain Martial XP - Host (You) drills guards
	regula_host_gains_martial_xp = {
		icon = martial
		is_valid = {
			is_current_phase_active = yes
			scope:host = {
				has_lifestyle = martial_lifestyle
				location = scope:province
			}
		}

		weight = {
			value = 1
		}

		effect = {
			scope:host = {
				save_scope_as = first
			}

			add_activity_log_entry = {
				key = regula_host_gains_martial_xp
				tags = { pulse_action }
				character = scope:first

				scope:first = {
					add_martial_lifestyle_xp = medium_lifestyle_xp
				}
			}
		}
	}

	# Gain Learning XP - Host (You) practice magic
	regula_host_gains_learning_xp = {
		icon = learning
		is_valid = {
			is_current_phase_active = yes
			scope:host = {
				has_lifestyle = learning_lifestyle
				location = scope:province
			}
		}

		weight = {
			value = 1
		}

		effect = {
			scope:host = {
				save_scope_as = first
			}

			add_activity_log_entry = {
				key = regula_host_gains_learning_xp
				tags = { pulse_action }
				character = scope:first

				scope:first = {
					add_learning_lifestyle_xp = medium_lifestyle_xp
				}
			}
		}
	}

	# Extract piety from a devoted follower (Mulsa)
	regula_host_extracts_piety = {
		icon = regula

		is_valid = {
			is_current_phase_active = yes
			any_attending_character = {
				NOT = { this = scope:host }
				has_trait = devoted_trait_group
				is_physically_able_ai_adult = yes
				is_pregnant = no
				is_visibly_fertile = yes
				location = scope:province
			}
		}

		weight = {
			value = 1
		}

		effect = {
			scope:host = {
				save_scope_as = first
			}

			random_attending_character = {
				limit = {
					NOT = { this = scope:host }
					has_trait = devoted_trait_group
					is_physically_able_ai_adult = yes
					is_pregnant = no
					is_visibly_fertile = yes
					location = scope:province
				}
				save_scope_as = second
			}

			add_activity_log_entry = {
				key = regula_host_extracts_piety
				tags = { pulse_action }
				character = scope:first
				target = scope:second

				scope:host = {
					add_piety = medium_piety_gain
					regula_sex_with_target_normal = { TARGET = scope:second }
				}
			}
		}
	}

	# Host is caught by non-devoted character doing something naughty
	regula_host_is_caught_by_non_regula = {
		icon = public

		is_valid = {
			is_current_phase_active = yes
			any_attending_character = {
				NOT = { this = scope:host }
				NOT = { has_trait = devoted_trait_group }
				is_physically_able_ai_adult = yes
				location = scope:province
			}
		}

		weight = {
			value = 1
		}

		effect = {
			random_attending_character = {
				limit = {
					NOT = { this = scope:host }
					NOT = { has_trait = devoted_trait_group }
					is_physically_able_ai_adult = yes
					location = scope:province
				}
				save_scope_as = first
			}

			add_activity_log_entry = {
				key = regula_host_is_caught_by_non_regula
				tags = { pulse_action }
				character = scope:first

				scope:host = {
					add_prestige = minor_prestige_loss
				}
				scope:first = {
					remove_from_activity = scope:activity
				}
			}
		}
	}

## Guest Pulse Actions

	# Ridiculed Servants
	regula_ridiculed_servants = {
		icon = public
		is_valid = {
			is_current_phase_active = yes
			OR = {
				AND = {
					has_activity_type = activity_regula_orgy
					has_activity_option = {
						category = orgy_option_servant
						option = orgy_servants_few
					}
				}
				AND = {
					has_activity_type = activity_regula_orgy
					has_activity_option = {
						category = orgy_option_servant
						option = orgy_servants_normal
					}
				}
			}
			any_attending_character = {
				NOT = { this = scope:host }
				is_physically_able_ai_adult = yes
				location = scope:province
				NOR = {
					has_trait = temperate
					has_trait = loyal
				}
			}
		}

		weight = {
			value = 1
			# if = {
			# 	limit = {
			# 		scope:activity = {
			# 			has_activity_type = activity_regula_orgy
			# 			has_activity_option = {
			# 				category = orgy_option_servant
			# 				option = orgy_servants_normal
			# 			}
			# 		}
			# 	}
			# 	add = -0.75
			# }
		}

		effect = {
			random_attending_character = {
				limit = {
					NOT = { this = scope:host }
					is_physically_able_ai_adult = yes
					location = scope:province
					NOR = {
						has_trait = temperate
						has_trait = loyal
					}
				}
				save_scope_as = first
			}

			add_activity_log_entry = {
				key = regula_ridiculed_servants
				tags = { pulse_action }
				character = scope:first

				scope:host = {
					add_prestige = minor_prestige_loss
				}
				scope:first = {
					add_opinion = {
						modifier = disappointed_opinion
						target = scope:host
						opinion = -10
					}
				}
			}
		}
	}

	# Lauded Servants
	regula_lauded_servants = {
		icon = public
		is_valid = {
			is_current_phase_active = yes
			OR = {
				AND = {
					has_activity_type = activity_regula_orgy
					has_activity_option = {
						category = orgy_option_servant
						option = orgy_servants_normal
					}
				}
				AND = {
					has_activity_type = activity_regula_orgy
					has_activity_option = {
						category = orgy_option_servant
						option = orgy_servants_many
					}
				}
				AND = {
					has_activity_type = activity_regula_orgy
					has_activity_option = {
						category = orgy_option_servant
						option = orgy_servants_charmed
					}
				}
			}
			any_attending_character = {
				NOT = { this = scope:host }
				is_physically_able_ai_adult = yes
				location = scope:province
				likes_character_trigger = { CHARACTER = scope:host }
			}
		}

		weight = {
			value = 1
			if = {
				limit = {
					scope:activity = {
						has_activity_type = activity_regula_orgy
						has_activity_option = {
							category = orgy_option_servant
							option = orgy_servants_normal
						}
					}
				}
				add = -0.5
			}
			if = {
				limit = {
					scope:activity = {
						has_activity_type = activity_regula_orgy
						has_activity_option = {
							category = orgy_option_servant
							option = orgy_servants_many
						}
					}
				}
				add = 0.5
			}
			if = {
				limit = {
					scope:activity = {
						has_activity_type = activity_regula_orgy
						has_activity_option = {
							category = orgy_option_servant
							option = orgy_servants_charmed
						}
					}
				}
				add = 1
			}
		}

		effect = {
			random_attending_character = {
				limit = {
					NOT = { this = scope:host }
					is_physically_able_ai_adult = yes
					location = scope:province
					likes_character_trigger = { CHARACTER = scope:host }
				}
				save_scope_as = first
			}

			add_activity_log_entry = {
				key = regula_lauded_servants
				tags = { pulse_action }
				character = scope:first

				scope:host = {
					add_prestige = minor_prestige_gain
				}
				scope:first = {
					add_opinion = {
						modifier = impressed_opinion
						target = scope:host
						opinion = 5
					}
				}
			}
		}
	}
