﻿# Events for handling the Hunt activity

namespace = hunt

#######################
#	You walk in (out?) on lovers
#	by Linnéa Thimrén
#######################

scripted_trigger hunt_4015_basic_check_trigger = {
	NOR = {
		this = root
		is_consort_of = root
		has_trait = chaste
		has_trait = celibate
	}
	is_adult = yes
	is_ai = yes
	might_cheat_on_every_partner_trigger = yes
}

scripted_trigger hunt_4015_secret_trigger = {
	this != root
	any_secret = {
		type = secret_lover
		NOT = { is_known_by = root }
		secret_target = {
			this != root
			is_participant_in_activity = scope:activity
		}
	}
}

scripted_trigger hunt_4015_lover_basic_trigger = {
	NOR = {
		has_sexuality = asexual
		has_trait = infirm
		is_malformed_trigger = yes
		has_any_debilitating_illness = yes
		is_involved_in_any_romantic_scheme = yes
	}
	OR = {
		age <= 45
		is_deviant_trigger = yes
		has_focus = intrigue_temptation_focus
		rite = { rite_has_tenet = tenet_carnal_exaltation }
	}
	trigger_if = {
		limit = {
			OR = {
				is_clergy = yes
				has_trait = devoted
			}
		}
		OR = {
			rite = { rite_has_tenet = tenet_carnal_exaltation }
			rite = { rite_has_doctrine = doctrine_clerical_marriage_allowed }
			is_deviant_trigger = yes
			has_trait = lustful
			ai_zeal <= medium_negative_ai_value
		}
	}
	ai_boldness >= medium_negative_ai_value
}

hunt.4015 = {
	type = activity_event
	title = hunt.4015.t
	desc = hunt.4015.desc
	id_override_priority = 100
	theme = hunt_activity
	left_portrait = {
		character = scope:lover_participant
		animation = flirtation
	}
	right_portrait = {
		character = scope:second_lover_participant
		animation = happiness
	}
	
	trigger = {
		scope:activity = {
			OR = { #Either two that are already lovers, or a lustful one that can pick someone up
				any_attending_character = {
					hunt_4015_secret_trigger = yes
				}
				any_attending_character = {
					hunt_4015_basic_check_trigger = yes
					likely_to_take_lover_trigger = yes
					hunt_4015_lover_basic_trigger = yes
					num_of_relation_lover < 1
					save_temporary_scope_as = lover_check
					scope:activity = {
						any_attending_character = {
							hunt_4015_basic_check_trigger = yes
							NOT = { this = scope:lover_check }
							matching_gender_and_sexuality_trigger = { CHARACTER_1 = this CHARACTER_2 = scope:lover_check }
							can_set_relation_lover_trigger = { CHARACTER = scope:lover_check }
							hunt_4015_lover_basic_trigger = yes
							num_of_relation_lover < 1
							willing_to_take_character_as_lover = { LOVER = scope:lover_check }
							trigger_if = {
								limit = { scope:lover_check = { ai_boldness < 20 } }
								NOR = {
									primary_spouse ?= { is_liege_or_above_of = scope:lover_check }
									any_parent = { is_liege_or_above_of = scope:lover_check }
								}
							}
							trigger_if = {
								limit = { scope:lover_check = { ai_honor > 0 } }
								is_married = no
							}
							trigger_if = {
								limit = {
									scope:lover_check = {
										is_female = yes
										age < 25
									}
								}
								age <= scope:lover_check.age_plus_25
								age >= scope:lover_check.age_minus_10
							}
							trigger_else_if = {
								limit = {
									scope:lover_check = {
										is_female = yes
										age >= 25
									}
								}
								age <= scope:lover_check.age_plus_10
								age >= scope:lover_check.age_minus_10
							}
							trigger_else = {
								age <= scope:lover_check.age
								age >= scope:lover_check.age_minus_25
							}
						}
					}
				}
			}
		}
	}

	weight_multiplier = {
		base = 0.75
		modifier = { #more likely to fire if two participants already are lovers
			add = 0.5
			scope:activity = {
				any_attending_character = {
					hunt_4015_secret_trigger = yes
				}
			}
		}
	}

	immediate = {
		scope:activity = {
			if = { #They're already lovers
				limit = {
					any_attending_character = {
						hunt_4015_secret_trigger = yes
					}
				}
				random_attending_character = { #Find your vassal
					limit = { #They are already lovers
						hunt_4015_secret_trigger = yes
					}
					save_scope_as = lover_participant
				}
				random_attending_character = {
					limit = { #They are already lovers
						NOT = { this = scope:lover_participant }
						any_secret = {
							type = secret_lover
							NOT = { is_known_by = root }
							secret_target = { this = scope:lover_participant }
						}
					}
					save_scope_as = second_lover_participant

					#To save the secret's scope
					if = {
						limit = {
							any_secret = {
								type = secret_lover
								secret_target = { this = scope:lover_participant }
								NOT = { is_known_by = root }
							}
						}
						random_secret = {
							type = secret_lover
							limit = {
								secret_target = { this = scope:lover_participant }
								NOT = { is_known_by = root }
							}
							save_scope_as = secret
						}
					}
				}
			}
			else = { #We make em lovers
				random_attending_character = { #Find your vassal
					limit = {
						hunt_4015_basic_check_trigger = yes
						likely_to_take_lover_trigger = yes
						hunt_4015_lover_basic_trigger = yes
						num_of_relation_lover < 1
						save_temporary_scope_as = lover_check
						scope:activity = {
							any_attending_character = {
								hunt_4015_basic_check_trigger = yes
								NOT = { this = scope:lover_check }
								matching_gender_and_sexuality_trigger = { CHARACTER_1 = this CHARACTER_2 = scope:lover_check }
								can_set_relation_lover_trigger = { CHARACTER = scope:lover_check }
								hunt_4015_lover_basic_trigger = yes
								num_of_relation_lover < 1
								willing_to_take_character_as_lover = { LOVER = scope:lover_check }
								trigger_if = {
									limit = { scope:lover_check = { ai_boldness < 20 } }
									NOR = {
										primary_spouse ?= { is_liege_or_above_of = scope:lover_check }
										any_parent = { is_liege_or_above_of = scope:lover_check }
									}
								}
								trigger_if = {
									limit = { scope:lover_check = { ai_honor > 0 } }
									is_married = no
								}
								trigger_if = {
									limit = {
										scope:lover_check = {
											is_female = yes
											age < 25
										}
									}
									age <= scope:lover_check.age_plus_25
									age >= scope:lover_check.age_minus_10
								}
								trigger_else_if = {
									limit = {
										scope:lover_check = {
											is_female = yes
											age >= 25
										}
									}
									age <= scope:lover_check.age_plus_10
									age >= scope:lover_check.age_minus_10
								}
								trigger_else = {
									age <= scope:lover_check.age
									age >= scope:lover_check.age_minus_25
								}
							}
						}
					}
					weight = {
						base = 1
						modifier = {
							add = -1
							is_unattractive_trigger = yes
						}
						modifier = {
							add = 1
							is_attractive_trigger = yes
						}
						modifier = {
							add = 1
							is_male = yes
							has_sexuality = homosexual
						}
					}
					save_scope_as = lover_participant
				}
				random_attending_character = {
					limit = {
						hunt_4015_basic_check_trigger = yes
						NOT = { this = scope:lover_participant }
						matching_gender_and_sexuality_trigger = { CHARACTER_1 = this CHARACTER_2 = scope:lover_participant }
						can_set_relation_lover_trigger = { CHARACTER = scope:lover_participant }
						hunt_4015_lover_basic_trigger = yes
						num_of_relation_lover < 1
						willing_to_take_character_as_lover = { LOVER = scope:lover_participant }
						trigger_if = {
							limit = { scope:lover_participant = { ai_boldness < 20 } }
							NOR = {
								primary_spouse ?= { is_liege_or_above_of = scope:lover_participant }
								any_parent = { is_liege_or_above_of = scope:lover_participant }
							}
						}
						trigger_if = {
							limit = { scope:lover_participant = { ai_honor > 0 } }
							is_married = no
						}
						trigger_if = {
							limit = {
								scope:lover_participant = {
									is_female = yes
									age < 25
								}
							}
							age <= scope:lover_participant.age_plus_25
							age >= scope:lover_participant.age_minus_10
						}
						trigger_else_if = {
							limit = {
								scope:lover_participant = {
									is_female = yes
									age >= 25
								}
							}
							age <= scope:lover_participant.age_plus_10
							age >= scope:lover_participant.age_minus_10
						}
						trigger_else = {
							age <= scope:lover_participant.age
							age >= scope:lover_participant.age_minus_25
						}
					}
					weight = {
						base = 1
						modifier = {
							add = -1
							is_unattractive_trigger = yes
						}
						modifier = {
							add = 1
							is_attractive_trigger = yes
						}
						modifier = {
							add = 2
							likely_to_take_lover_trigger = yes
						}
						modifier = {
							add = 2
							OR = {
								has_relation_potential_lover = scope:lover_participant
								has_relation_crush = scope:lover_participant
							}
						}
					}
					save_scope_as = second_lover_participant

					#To make them lovers
					hidden_effect = { set_relation_lover = scope:lover_participant }
					
					#To save the secret's scope
					if = {
						limit = {
							any_secret = {
								type = secret_lover
								secret_target = { this = scope:lover_participant }
								NOT = { is_known_by = root }
							}
						}
						random_secret = {
							type = secret_lover
							limit = {
								secret_target = { this = scope:lover_participant }
								NOT = { is_known_by = root }
							}
							save_scope_as = secret
						}
					}
				}
			}
		}
		scope:activity = {
			add_activity_log_entry = {
				key = hunt_lover_secret_log
				score = 25
				tags = { random social neutral }
				character = scope:lover_participant
				target = scope:second_lover_participant

				# Effect
				show_as_tooltip = {
					scope:secret = { reveal_to = root }
				}
			}
		}
		if = {
			limit = {
				exists = scope:secret
				scope:secret = {
					NOT = { is_known_by = root }
				}
			}
			scope:secret = {
				reveal_to_without_events_effect = {
					CHARACTER = root
				}
			}
		}
	}

	option = { #Keep the secret
		name = hunt.4015.a
		scope:activity = {
			add_activity_log_entry = {
				key = hunt_lover_secret_log
				score = 25
				tags = { random social neutral }
				character = scope:lover_participant
				target = scope:second_lover_participant

				# Effect
				root = {
					reverse_add_opinion = {
						target = scope:lover_participant
						modifier = grateful_opinion
						opinion = 15
					}
					reverse_add_opinion = {
						target = scope:second_lover_participant
						modifier = grateful_opinion
						opinion = 15
					}
					stress_and_fulfillment_impact = {
						honest = minor_stress_impact_gain
						contrite = minor_stress_impact_gain
					}
				}
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_compassion = 0.5
			}
			modifier = {
				add = 20
				OR = {
					has_relation_lover = scope:lover_participant
					has_relation_lover = scope:second_lover_participant
				}
			}
		}
	}

	option = { #Expose the secret
		name = hunt.4015.b
		trigger = { exists = scope:secret } # Chance of Secret invalidating
		scope:activity = {
			add_activity_log_entry = {
				key = hunt_lover_secret_log
				score = 25
				tags = { random social neutral }
				character = scope:lover_participant
				target = scope:second_lover_participant
				
				#Effect
				scope:secret = {
					expose_secret = root
				}
				root = {
					stress_and_fulfillment_impact = {
						honest = minor_stress_impact_loss
						just = minor_stress_impact_loss
						contrite = minor_stress_impact_loss
					}
				}
			}
		}
		ai_chance = {
			base = 50
			modifier = {
				add = 30
				OR = {
					has_trait = just
					has_trait = zealous
					has_trait = celibate
				}
			}
			ai_value_modifier = {
				ai_honor = 0.25
				ai_vengefulness = 0.25
			}
		}
	}

	option = { #Join in - relationship or seducer trait
		name = {
			trigger = {
				has_relation_lover = scope:lover_participant
				has_relation_lover = scope:second_lover_participant
			}
			text = hunt.4015.c_4
		}
		name = {
			trigger = {
				has_relation_lover = scope:lover_participant
			}
			text = hunt.4015.c_1
		}
		name = {
			trigger = {
				has_relation_lover = scope:second_lover_participant
			}
			text = hunt.4015.c_2
		}
		name = {
			trigger = {
				NOR = {
					has_relation_lover = scope:lover_participant
					has_relation_lover = scope:second_lover_participant
				}
			}
			text = hunt.4015.c_3
		}
		trigger = {
			OR = {
				AND = { #you only feel ok about it if you're lustful
					OR = {
						has_relation_lover = scope:lover_participant
						has_relation_lover = scope:second_lover_participant
					}
					has_trait = lustful
				}
				has_trait = seducer
			}
		}
		trait = seducer
		scope:activity = {
			add_activity_log_entry = {
				key = hunt_lover_secret_join_log
				score = 25
				tags = { random social neutral }
				character = scope:lover_participant
				target = scope:second_lover_participant
				
				#Effect
				root = {
					if = {
						limit = {
							has_relation_potential_lover = scope:lover_participant
							can_set_relation_lover_trigger = { CHARACTER = scope:lover_participant }
						}
						set_relation_lover = scope:lover_participant
					}
					else_if = {
						limit = { has_relation_lover = scope:lover_participant }
						scope:lover_participant = {
							add_opinion = {
								modifier = pleased_opinion
								target = root
								opinion = 20
							}
						}
					}
					else = { set_relation_potential_lover = scope:lover_participant }
					if = {
						limit = {
							has_relation_potential_lover = scope:second_lover_participant
							can_set_relation_potential_lover_trigger = { CHARACTER = scope:second_lover_participant }
						}
						set_relation_lover = scope:second_lover_participant
					}
					else_if = {
						limit = { has_relation_lover = scope:second_lover_participant }
						scope:second_lover_participant = {
							add_opinion = {
								modifier = pleased_opinion
								target = root
								opinion = 20
							}
						}
					}
					else = { set_relation_potential_lover = scope:second_lover_participant }
					hunt_activity_success_change_effect = { CHANGE = decrease_minor }
					stress_and_fulfillment_impact = {
						base = minor_stress_impact_loss
						rakish = minor_stress_impact_loss
						lustful = minor_stress_impact_loss
					}
				}
			}
		}
		ai_chance = {
			base = 75
			modifier = {
				add = 30
				has_trait = lustful
			}
		}
	}

	option = { #Betrayed!!
		name = {
			trigger = {
				OR = {
					AND = {
						has_relation_lover = scope:second_lover_participant
						opinion = {
							target = scope:second_lover_participant
							value >= 70
						}
						NOT = { has_trait = lustful }
					}
					has_relation_soulmate = scope:second_lover_participant
				}
			}
			text = hunt.4015.d
		}
		name = {
			trigger = {
				OR = {
					AND = {
						has_relation_lover = scope:lover_participant
						opinion = {
							target = scope:lover_participant
							value >= 70
						}
						NOT = { has_trait = lustful }
					}
					has_relation_soulmate = scope:lover_participant
				}
			}
			text = hunt.4015.d_2
		}
		trigger = { #Either you are soulmates, or you like them very much
			OR = {
				OR = {
					AND = {
						has_relation_lover = scope:lover_participant
						opinion = {
							target = scope:lover_participant
							value >= 70
						}
						NOT = { has_trait = lustful }
					}
					has_relation_soulmate = scope:lover_participant
				}
				OR = {
					AND = {
						has_relation_lover = scope:second_lover_participant
						opinion = {
							target = scope:second_lover_participant
							value >= 70
						}
						NOT = { has_trait = lustful }
					}
					has_relation_soulmate = scope:second_lover_participant
				}
			}
		}
		if = {
			limit = {
				OR = {
					AND = {
						has_relation_lover = scope:lover_participant
						opinion = {
							target = scope:lover_participant
							value >= 70
						}
						NOT = { has_trait = lustful }
					}
					has_relation_soulmate = scope:lover_participant
				}
			}
			scope:lover_participant = { save_scope_as = betraying_lover }
		}
		else = {
			scope:second_lover_participant = { save_scope_as = betraying_lover }
		}
		scope:activity = {
			add_activity_log_entry = {
				key = hunt_lover_secret_log
				score = 25
				tags = { random social bad }
				character = scope:lover_participant
				target = scope:second_lover_participant
				
				#Effect
				root = {
					remove_relation_lover = scope:betraying_lover
					hunt_activity_success_change_effect = { CHANGE = decrease_minor }
				}
			}
		}
		ai_chance = {
			base = 100
		}
	}

	option = { #Oh come on, we have a hunt to focus on!
		name = hunt.4015.e
		scope:activity = {
			add_activity_log_entry = {
				key = hunt_lover_secret_log
				character = scope:lover_participant
				target = scope:second_lover_participant
				
				#Effect
				root = {
					hunt_activity_success_change_effect = { CHANGE = increase_minor }
					stress_and_fulfillment_impact = {
						just = minor_stress_impact_gain
						diligent = minor_stress_impact_loss
					}
				}
			}
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_energy = 0.5
			}
			modifier = {
				add = 20
				NOR = {
					has_relation_lover = scope:lover_participant
					has_relation_lover = scope:second_lover_participant
				}
			}
		}
	}
}

