﻿######################################################################
# ONGOING EFFECTS
######################################################################

#Milestone should be 1 or 2, outcome should be success or failure
fascinare_ongoing_add_scheme_modifier_effect = {
	scope:scheme = {
		add_scheme_modifier = {
			type = fascinare_$OUTCOME$_$MILESTONE$_modifier
		}
	}
}

fascinare_ongoing_possible_outcomes_tooltip_effect = {
	show_as_tooltip = {
		random_list = {
			1 = {
				desc = fascinare_ongoing_possible_outcomes_tooltip_effect.success.desc
				show_chance = no
				fascinare_ongoing_add_scheme_modifier_effect = { MILESTONE = $MILESTONE$ OUTCOME = success }
			}
			1 = {
				desc = fascinare_ongoing_possible_outcomes_tooltip_effect.failure.desc
				show_chance = no
				fascinare_ongoing_add_scheme_modifier_effect = { MILESTONE = $MILESTONE$ OUTCOME = failure }
			}
		}
	}
}

######################################################################
# OUTCOME EFFECTS
######################################################################

fascinare_block_character_effect = {
	if = {
		limit = { root = scope:target }
		custom_tooltip = fascinare_outcome.permanent_block

		hidden_effect = {
			add_opinion = {
				target = $CHARACTER$
				modifier = fascinare_permanent_blocker_opinion
			}
		}
	}
	else = {
		add_opinion = {
			target = $CHARACTER$
			modifier = fascinare_permanent_blocker_opinion
		}
	}
}

fascinare_cooldown_for_character_effect = {
	if = {
		limit = { root = scope:target }
		custom_tooltip = fascinare_outcome.cooldown

		hidden_effect = {
			add_opinion = {
				target = $CHARACTER$
				modifier = fascinare_regular_cooldown_opinion
			}
		}
	}
	else = {
		add_opinion = {
			target = $CHARACTER$
			modifier = fascinare_regular_cooldown_opinion
		}
	}
}

fascinare_outcome_publicised_attempted_crimes_or_nothing_effect = {
	$TARGET$ = {
		#Grab everyone relevant who might be interested in the attempt.
		every_close_family_member = { add_to_list = relevant_parties }
		every_consort = {
			limit = {
				NOT = { is_in_list = relevant_parties }
			}
			add_to_list = relevant_parties
		}
		if = {
			limit = {
				exists = liege
				liege = {
					NOT = { is_in_list = relevant_parties }
				}
			}
			add_to_list = relevant_parties
		}
		if = {
			limit = {
				exists = court_owner
				court_owner = {
					NOT = { is_in_list = relevant_parties }
				}
			}
			add_to_list = relevant_parties
		}
		every_vassal = {
			limit = {
				NOT = { is_in_list = relevant_parties }
			}
			add_to_list = relevant_parties
		}
		every_relation = {
			type = friend
			limit = {
				NOT = { is_in_list = relevant_parties }
			}
			add_to_list = relevant_parties
		}
		every_relation = {
			type = lover
			limit = {
				NOT = { is_in_list = relevant_parties }
			}
			add_to_list = relevant_parties
		}
		$OWNER$ = {
			every_close_family_member = {
				limit = {
					NOT = { is_in_list = relevant_parties }
				}
				add_to_list = relevant_parties
			}
		}
	}
}

# Main Fascinare effect
# Does the following
# 1. Add Mulsa Trait and sets their faith to the Magisters faith (also adds 10 year flag that they were forcefully converted)
# 2. +1 to Fascinare Tally goal
# 3. Infecta Virus check
# Scope should be the charmed character
fascinare_success_effect = {

	# Add trait and set faith
	add_trait = mulsa
	convert_to_regula_openly_or_secretly_effect = {
		FAITH = global_var:magister_character.faith
	}
	hidden_effect = { # No take-backs.
		add_character_flag = {
			flag = converted_by_forced_conversion_interaction
			years = 10
		}
	}

	# +1 to Tally goal
	change_global_variable = {
		name = regula_fascinare_tally
		add = 1
	}

	# Infecta virus trigger
	if = {
		limit = { # Scope is the target  ### UPDATE - Add code restricting it to the magister.
			# Check if Magister has Regula Virus Holy Site
			$CHARACTER$ = {
				has_trait = magister_trait_group
				character_has_regula_holy_effect_regula_virus = yes
			}
		}

		add_trait = regula_virus
		save_scope_as = regula_patient_zero

		global_var:magister_character = {
			create_story = story_regula_infecta_chain
			random_owned_story = {
				limit = {
					story_type = story_regula_infecta_chain
					NOT = { has_variable = patient_zero }
				}
				set_variable = {
					name = patient_zero
					value = scope:regula_patient_zero
				}
				add_to_variable_list = {
					name = new_converts
					target = scope:regula_patient_zero
				}
			}
		}

		trigger_event = {
			id = regula_virus.1000
			days = { regula_infecta_virus_min_days_event regula_infecta_virus_max_days_event }
		}
	}

	# Remove all sinful traits if we have Willing Famuli dynasty legacy
	if = {
		limit = {
			global_var:magister_character.dynasty ?= {
				has_dynasty_perk = regula_legacy_2
			}
		}
		regula_remove_sinful_personality_traits_all_effect = yes
	}
}

# Extra effects if ward, add tally and give Dynasty prestige if the ward is not part of your dynasty, (based on their highest title)
# Scope should be the ward character
ward_enslavement_success_effect = {
	change_global_variable = {
		name = regula_obedience_tally
		add = 1
	}
	if = {
		limit = {
			NOT = { global_var:magister_character.dynasty = dynasty }
		}
		if = {
			limit = {
				is_ruler = yes
			}
			global_var:magister_character.dynasty = {
				add_dynasty_prestige = scope:teen.regula_ward_highest_title_to_dynasty_prestige
			}
		}
	}
}

# This effect is when a mulsa/tropaeum tries to enslave a ward when they turn to adult
# Outcomes are Good (charm), bad (nothing happens) and backfire (ward hates Guardian/Magister)
# Note this this requires scope:teen (ward) and scope:regula_guardian (guardian) to be set
# This also handles sending the message to player
regula_guardian_try_enslave_ward_effect = {
	random_list = {
		# Charm successful
		50 = {
			desc = teen_fascinare_success_effect.desc

			# How much does ward like Magister?
			opinion_modifier = {
				who = scope:teen
				opinion_target = global_var:magister_character
				multiplier = 0.25
				step = 5
			}

			# Modifiers based on guardian/ward traits
			# Each virtue makes it easier to charm
			modifier = {
				scope:regula_guardian = { has_trait = lustful }
				add = 50
			}
			modifier = {
				scope:regula_guardian = { has_trait = humble }
				add = 30
			}
			modifier = {
				scope:regula_guardian = { has_trait = zealous }
				add = 30
			}
			modifier = {
				scope:regula_guardian = { has_trait = trusting }
				add = 30
			}
			modifier = {
				scope:regula_guardian = { has_trait = fecund }
				add = 30
			}

			modifier = {
				scope:teen = { has_trait = lustful }
				add = 50
			}
			modifier = {
				scope:teen = { has_trait = humble }
				add = 30
			}
			modifier = {
				scope:teen = { has_trait = zealous }
				add = 30
			}
			modifier = {
				scope:teen = { has_trait = trusting }
				add = 30
			}
			modifier = {
				scope:teen = { has_trait = fecund }
				add = 30
			}

			# Big bonus if ward is already in Regula religion
			modifier = {
				scope:teen = { is_regula_trigger = yes }
				add = 100
			}

			# Bonus if ward is in Magisters court
			modifier = {
				scope:teen = {
					is_in_the_same_court_as = global_var:magister_character
				}
				add = 50
			}

			# Deviant bonus
			modifier = {
				scope:regula_guardian = {
					has_trait = deviant
				}
				add = 20
			}
			modifier = {
				scope:teen = { has_trait = deviant }
				add = 40
			}

			send_interface_message = {
				type = regula_fascinare_ward_charm_success
				title = teen_fascinare_success_effect.desc
				left_icon = scope:teen
				right_icon = scope:regula_guardian
				scope:teen = {
					fascinare_success_effect = { CHARACTER = root }
					create_memory_convert_ward_assistant = { CHARACTER = scope:regula_guardian}
					ward_enslavement_success_effect = yes
				}
			}
		}
		# Charm failure
		35 = {
			desc = teen_fascinare_failure_effect.desc

			# How much does ward like Magister?
			opinion_modifier = {
				who = scope:teen
				opinion_target = global_var:magister_character
				multiplier = -0.25
				step = 5
			}

			# Sins make charming harder
			modifier = {
				scope:regula_guardian = { has_trait = chaste }
				add = 50
			}
			modifier = {
				scope:regula_guardian = { has_trait = cynical }
				add = 30
			}
			modifier = {
				scope:regula_guardian = { has_trait = sadistic }
				add = 30
			}
			modifier = {
				scope:regula_guardian = { has_trait = vengeful }
				add = 30
			}

			modifier = {
				scope:teen = { has_trait = chaste }
				add = 100
			}
			modifier = {
				scope:teen = { has_trait = cynical }
				add = 30
			}
			modifier = {
				scope:teen = { has_trait = sadistic }
				add = 30
			}
			modifier = {
				scope:teen = { has_trait = vengeful }
				add = 30
			}

			# Extra effects
			modifier = {
				scope:teen = { has_sexuality = homosexual }
				add = 50
			}
			modifier = {
				scope:teen = { has_trait = stubborn }
				add = 30
			}

			# Harder to resist if in Magisters court
			modifier = {
				scope:teen = {
					is_in_the_same_court_as = global_var:magister_character
				}
				add = -50
			}

			send_interface_message = {
				type = regula_fascinare_ward_charm_failure
				title = teen_fascinare_failure_effect.desc
				left_icon = scope:teen
				right_icon = scope:regula_guardian
			}
		}
		# Charm critical Failure
		15 = {
			desc = teen_fascinare_critical_failure_effect.desc

			# How much does ward like Magister?
			opinion_modifier = {
				who = scope:teen
				opinion_target = global_var:magister_character
				multiplier = -0.25
				step = 5
			}

			modifier = {
				scope:teen = { has_trait = celibate }
				add = 150
			}
			modifier = {
				scope:teen = { has_sexuality = asexual }
				add = 150
			}

			send_interface_message = {
				type = regula_fascinare_ward_charm_failure
				title = teen_fascinare_critical_failure_effect.desc
				left_icon = scope:teen
				right_icon = scope:regula_guardian
				scope:teen = {
					add_opinion = {
						target = global_var:magister_character
						modifier = hate_opinion
						opinion = -30
					}
					add_opinion = {
						target = scope:regula_guardian
						modifier = hate_opinion
						opinion = -30
					}
				}
			}
		}
	}
}