﻿# Given a prisoner, turn them into a lover and do the following
# TARGET - The target to charm and turn into lover
# CHARMER - The person charming the target
# Effects are:
# 1. Charm and create charm memory
# 2. Have sexy times
# 3. Removing existing marriage/betrothal/lovers/soulmate for target, if they have any
# 4. Remove rival relations with actor
# 5. Turn into our lover
regula_prisoner_love_charm_effect = {

	# Only charm if we need to, costs extra
	if = {
		limit = {
			$TARGET$ = {
				NOT = {
					has_trait = devoted_trait_group
				}
			}
		}
		$TARGET$ = {
			fascinare_success_effect = { CHARACTER = $CHARMER$ }
			create_memory_enchanted_in_prison = { CHARACTER = $CHARMER$ }
		}
		$CHARMER$ = {
			add_piety = regula_prisoner_lover_charm_cost_negated
		}
	}
	else = {
		$CHARMER$ = {
			add_piety = regula_prisoner_lover_charm_devoted_cost_negated
		}
	}

	# Plap Plap Plap
	$CHARMER$ = {
		regula_sex_with_target_normal = { TARGET = $TARGET$ }
	}
	
	# Remove existing marriages
	if = {
		# If married, divorce
		limit = {
			$TARGET$ = {
				is_married = yes
				NOT = {
					is_consort_of = $CHARMER$
				}
			}
		}
		$TARGET$.primary_spouse = {
			save_scope_as = old_lover
		}
		$TARGET$ = {
			divorce = this.primary_spouse
		}
	}

	if = {
		# If betrothed, remove betrothal
		limit = {
			$TARGET$ = {
				is_betrothed = yes
			}
		}
		$TARGET$ = {
			break_betrothal = betrothed
		}
	}

	# If have any lovers, remove all lovers
	# Note this also breaks soulmate relation
	# We shoudn't need to check Charmer relation here because they shoudn't already be lovers with target (hopefully?)
	if = {
		limit = {
			$TARGET$ = {
				num_of_relation_lover >= 1
			}
		}

		# We save this if we don't yet have a lover
		if = {
			limit = { NOT = { exists = scope:old_lover } }
			$TARGET$ = {
				random_relation = {
					type = lover
					save_scope_as = old_lover
				}
			}
		}
		# If have lover, remove all lovers
		$TARGET$ = {
			every_relation = {
				type = lover
				lover_breakup_effect = {
					BREAKER = $TARGET$
					LOVER = this
				}
			}
		}
	}

	# Break Rival/Nemesis relation with Charmer
	if = {
		limit = {
			$TARGET$ = {
				NOT = {
					has_relation_nemesis = $CHARMER$
				}
				has_relation_rival = $CHARMER$
			}
		}
		$TARGET$ = {
			remove_relation_rival = $CHARMER$
		}
	}
	else_if = {
		limit = {
			$TARGET$ = {
				has_relation_nemesis = $CHARMER$
			}
		}
		$TARGET$ = {
			remove_relation_nemesis = $CHARMER$
		}
	}

	# They will then become our lover
	$CHARMER$ = {
		set_relation_lover = $TARGET$
	}
}