﻿# FEAST ACTIVITY KEY EVENTS
# Most custom variables checked here will have been set by the "welcoming" events in feast_activity_standard_events
# Each unique key event gets a range of 50 IDs. This should more than suffice in all cases.

namespace = feast_main_befriend


################################
# Feast Befriend Events
# by Petter Vilberg
################################

###
# Weight and setup event
###
feast_main_befriend.0001 = {
	type = activity_event

	hidden = yes

	trigger = {
		not_hosting_a_murder_feast = yes
		OR = {
			AND = {
				scope:activity = {
					has_variable = potential_friend
				}
				scope:activity.var:potential_friend = {
					opinion = {
						target = scope:activity.activity_host
						value > 20
					}
				}
			}
			AND = {
				has_activity_intent = befriend_attendee_intent
				intent_target ?= {
					is_alive = yes
				}
			}
			scope:activity = {
				any_attending_character = {
					feast_default_participant_trigger = yes
					this != scope:activity.activity_host
					NOT = { has_relation_friend = root }
					opinion = {
						target = scope:activity.activity_host
						value > 35
					}
				}
			}
		}
	}

	weight_multiplier = {
		base = 1
		opinion_modifier = {
			trigger = { exists = scope:activity.var:potential_friend }
			who = scope:activity.var:potential_friend
			opinion_target = scope:activity.activity_host
			multiplier = 0.1
			step = 0.1
		}
		modifier = {
			add = 2
			has_activity_intent = befriend_attendee_intent
			intent_target ?= {
				is_alive = yes
			}
		}
		modifier = {
			add = -0.5
			NOT = { has_activity_intent = befriend_attendee_intent }
			NOT = {
				scope:activity = {
					has_variable = potential_friend
				}
			}
		}
		modifier = {
			add = -0.5
			is_ai = yes
		}
	}

	immediate = {
		if = {
			limit = {
				scope:activity = {
					has_variable = potential_friend
					var:potential_friend = {
						opinion = {
							target = scope:activity.activity_host
							value > 20
						}
					}
				}
			}
			scope:activity.var:potential_friend = {
				save_scope_as = potential_friend
			}
		}
		else_if = {
			limit = {
				has_activity_intent = befriend_attendee_intent
				intent_target ?= {
					is_alive = yes
				}
			}
			intent_target = {
				save_scope_as = potential_friend
			}
		}
		else = {
			scope:activity = {
				random_attending_character = {
					limit = {
						feast_default_participant_trigger = yes
						this != scope:activity.activity_host
						NOT = { has_relation_friend = root }
						opinion = {
							target = scope:activity.activity_host
							value > 35
						}
					}
					save_scope_as = potential_friend
				}
			}
		}
		scope:activity = {
			random_attending_character = {
				limit = {
					feast_default_participant_trigger = yes
					this != scope:activity.activity_host
					this != scope:potential_friend
					highest_held_title_tier > 1
					OR = {
						has_trait = arrogant
						has_trait = vengeful
					}
				}
				save_scope_as = arrogant_guest
			}
			random_attending_character = {
				limit = {
					feast_default_participant_trigger = yes
					this != scope:activity.activity_host
					this != scope:potential_friend
					trigger_if = {
						limit = { exists = scope:arrogant_guest }
						this != scope:arrogant_guest
					}
					highest_held_title_tier > 1
					OR = {
						has_trait = humble
						has_trait = compassionate
						any_secret = {
							type = secret_cannibal
						}
					}
				}
				save_scope_as = kind_to_lower_nobility
			}
			if = {
				limit = {
					exists = scope:kind_to_lower_nobility
					scope:kind_to_lower_nobility = {
						any_secret = { type = secret_cannibal }
					}
				}
				random_attending_character = {
					limit = {
						feast_default_participant_trigger = yes
						this != scope:activity.activity_host
						this != scope:potential_friend
						trigger_if = {
							limit = { exists = scope:arrogant_guest }
							this != scope:arrogant_guest
						}
						trigger_if = {
							limit = { exists = scope:kind_to_lower_nobility }
							this != scope:kind_to_lower_nobility
						}
						OR = {
							has_trait = gluttonous
							has_trait = lifestyle_reveler
						}
					}
					save_scope_as = glutton_target
				}
			}
			activity_host = {
				trigger_event = feast_main_befriend.1001
			}
			scope:potential_friend = {
				trigger_event = feast_main_befriend.2001
			}
			if = {
				limit = {
					exists = scope:arrogant_guest
				}
				scope:arrogant_guest = {
					trigger_event = feast_main_befriend.2002
				}
			}
			if = {
				limit = {
					exists = scope:kind_to_lower_nobility
				}
				scope:kind_to_lower_nobility = {
					trigger_event = feast_main_befriend.2003
				}
			}
			if = {
				limit = {
					exists = scope:glutton_target
				}
				scope:glutton_target = {
					trigger_event = feast_main_befriend.2004
				}
			}
			every_attending_character = {
				limit = {
					feast_default_participant_trigger = yes
					this != scope:activity.activity_host
					this != scope:potential_friend
					trigger_if = {
						limit = { exists = scope:arrogant_guest }
						this != scope:arrogant_guest
					}
					trigger_if = {
						limit = { exists = scope:kind_to_lower_nobility }
						this != scope:kind_to_lower_nobility
					}
					trigger_if = {
						limit = { exists = scope:glutton_target }
						this != scope:glutton_target
					}
				}
				trigger_event = feast_main_befriend.3001
			}
		}
	}
}



##########################
# Main event for Host
##########################
feast_main_befriend.1001 = {
	title = feast_main_befriend.1001.t
	type = activity_event
	desc = {
		desc = feast_main_befriend.1001.opening
		desc = feast_main_befriend.1001.getting_close
		triggered_desc = {
			trigger = { exists = scope:arrogant_guest }
			desc = {
				desc = feast_main_befriend.1001.arrogant_guest
				triggered_desc = {
					trigger = { exists = scope:kind_to_lower_nobility }
					desc = feast_main_befriend.1001.arrogant_kind_link
				}
			}
		}
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:kind_to_lower_nobility }
				desc = {
					desc = feast_main_befriend.1001.kind_to_lower_nobility
					triggered_desc = {
						trigger = {
							scope:kind_to_lower_nobility = {
								any_secret = { type = secret_cannibal }
							}
						}
						desc = feast_main_befriend.1001.really_hungry
					}
				}
			}
			desc = feast_main_befriend.1001.no_kind_target
		}
		desc = feast_main_befriend.1001.friendship
	}
	theme = feast_activity
	center_portrait = {
		character = root
		animation = toast
	}
	right_portrait = {
		character = scope:potential_friend
		animation = happiness
	}
	lower_right_portrait = scope:kind_to_lower_nobility
	
	trigger = {
		OR = {
			any_scheme = {
				type = befriend
				scheme_target_character = {
					involved_activity ?= scope:activity
				}
			}
			AND = {
				has_activity_intent = befriend_attendee_intent
				intent_target ?= {
					is_alive = yes
				}
			}
			scope:activity = {
				any_attending_character = {
					feast_default_participant_trigger = yes
					this != scope:activity.activity_host
					NOT = { has_relation_friend = root }
					opinion = {
						target = scope:activity.activity_host
						value > 35
					}
				}
			}
		}
	}
	
	immediate = {
		play_music_cue = mx_cue_meadandwine
		if = {
			limit = {
				has_activity_intent = befriend_attendee_intent
				intent_target ?= {
					is_alive = yes
				}
			}
			intent_target = { save_scope_as = potential_friend }
		}
		else_if = {
			limit = {
				any_scheme = {
					type = befriend
					scheme_target_character = {
						involved_activity ?= scope:activity
					}
				}
			}
			random_scheme = {
				type = befriend
				limit = {
					scheme_target_character = {
						involved_activity ?= scope:activity
					}
				}
				scheme_target_character = {
					save_scope_as = potential_friend
				}
			}
		}
		else = {
			scope:activity = {
				random_attending_character = {
					limit = {
						feast_default_participant_trigger = yes
						this != scope:activity.activity_host
						NOT = { has_relation_friend = root }
						opinion = {
							target = scope:activity.activity_host
							value > 35
						}
					}
					save_scope_as = potential_friend
				}
			}
		}
	}

	option = {
		name = feast_main_befriend.1001.a
		if = {
			limit = {
				can_set_relation_friend_trigger = { CHARACTER = scope:potential_friend }
			}
			set_relation_friend = { reason = friend_feast_talking_and_laughing target = scope:potential_friend }
			# Complete activity intent if relevant
			if = {
				limit = {
					exists = involved_activity
					has_activity_intent = befriend_attendee_intent
					intent_target ?= scope:potential_friend
					intent_target.involved_activity ?= root.involved_activity
				}
				save_scope_as = intent_completer
				send_interface_toast = {
					title = activity_intent_complete_toast
					left_icon = scope:potential_friend
					complete_activity_intent = yes
				}
			}
		}
		else = {
			progress_towards_friend_effect = {
				REASON = friend_feast_talking_and_laughing
				CHARACTER = scope:potential_friend
				OPINION = default_friend_opinion
			}
		}
		if = {
			limit = {
				any_scheme = {
					type = befriend
					scheme_target_character = scope:potential_friend
				}
			}
			random_scheme = {
				type = befriend
				limit = {
					scheme_target_character = scope:potential_friend
				}
				end_scheme = yes
			}
		}
	}

	after = {
		hidden_effect = {
			# Fire the end events
			trigger_event = {
				id = feast_main_befriend.5001
				days = 10
			}
		}
	}
}


##########################
# Main Event for Potential Friend
##########################
feast_main_befriend.2001 = {
	title = feast_main_befriend.2001.t
	type = activity_event
	desc = {
		desc = feast_main_befriend.1001.opening
		desc = feast_main_befriend.2001.getting_close
		triggered_desc = {
			trigger = { exists = scope:arrogant_guest }
			desc = {
				desc = feast_main_befriend.2001.arrogant_guest
				triggered_desc = {
					trigger = { exists = scope:kind_to_lower_nobility }
					desc = feast_main_befriend.2001.arrogant_kind_link
				}
			}
		}
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:kind_to_lower_nobility }
				desc = {
					desc = feast_main_befriend.2001.kind_to_lower_nobility
					triggered_desc = {
						trigger = {
							scope:kind_to_lower_nobility = {
								any_secret = { type = secret_cannibal }
							}
						}
						desc = feast_main_befriend.2001.really_hungry
					}
				}
			}
			desc = feast_main_befriend.2001.no_kind_target
		}
		desc = feast_main_befriend.2001.friendship
	}
	theme = feast_activity
	left_portrait = root
	right_portrait = {
		character = scope:activity.activity_host
		animation = happiness
	}
	lower_left_portrait = scope:kind_to_lower_nobility
	lower_right_portrait = scope:arrogant_guest
	
	option = {
		name = feast_main_befriend.2001.a
		add_prestige = medium_prestige_gain
		show_as_tooltip = {
			set_relation_friend = scope:activity.activity_host
			hidden_effect = {
				add_opinion = {
					target = scope:activity.activity_host
					modifier = bonded_at_feast_opinion
				}
			}
		}
	}
}


##########################
# Main Event for Arrogant Guest
##########################
feast_main_befriend.2002 = {
	title = feast_main_befriend.2002.t
	type = activity_event
	desc = {
		desc = feast_main_befriend.1001.opening
		desc = feast_main_befriend.2002.arrogant_guest
		triggered_desc = {
			trigger = {
				exists = scope:kind_to_lower_nobility
			}
			desc = feast_main_befriend.2002.disgusted_by_kindness
		}
	}
	theme = feast_activity
	left_portrait = {
		character = scope:activity.activity_host
		animation = happiness
	}
	right_portrait = {
		character = scope:kind_to_lower_nobility
		animation = personality_compassionate
	}

	option = {
		name = feast_main_befriend.2002.a
		add_prestige = medium_prestige_loss
		if = {
			limit = {
				exists = scope:kind_to_lower_nobility
			}
			add_opinion = {
				modifier = disgusted_by_humility_opinion
				target = scope:kind_to_lower_nobility
			}
			progress_towards_rival_effect = {
				CHARACTER = scope:kind_to_lower_nobility
				REASON = rival_feast_commoners
				OPINION = 0
			}
		}
		if = {
			limit = {
				faith = { has_doctrine_parameter = host_honored_guests_active }
			}
			custom_description_no_bullet = {
				text = feast_main_befriend.2002.because_of_hospitality_tenet
			}
			add_piety = medium_piety_loss
		}
	}
}


##########################
# Main Event for Kind to Nobility
##########################
feast_main_befriend.2003 = {
	title = feast_main_befriend.2003.t
	type = activity_event
	desc = {
		desc = feast_main_befriend.2003.opening
		triggered_desc = {
			trigger = { exists = scope:arrogant_guest }
			desc = feast_main_befriend.2003.arrogant_guest	
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					any_secret = { type = secret_cannibal }
					exists = scope:glutton_target
				}
				desc = feast_main_befriend.2003.kind_to_glutton
			}
			triggered_desc = {
				trigger = {
					any_secret = { type = secret_cannibal }
				}
				desc = feast_main_befriend.2003.cannibal_kindness
			}
			desc = feast_main_befriend.2003.kind_to_lower_nobility
		}
		desc = feast_main_befriend.2003.ending
	}
	theme = feast_activity
	left_portrait = {
		character = scope:activity.activity_host
		animation = happiness
	}
	lower_left_portrait = scope:arrogant_guest
	
	option = {
		name = feast_main_befriend.2003.a
		scope:activity = {
			every_attending_character = {
				limit = {
					feast_default_participant_trigger = yes
					trigger_if = {
						limit = { exists = scope:arrogant_guest }
						this != scope:arrogant_guest
					}
				}
				add_opinion = {
					target = root
					modifier = impressed_with_humility_opinion
				}
			}
		}
		if = {
			limit = {
				exists = scope:arrogant_guest
			}
			show_as_tooltip = {
				scope:arrogant_guest = {
					add_prestige = minor_prestige_loss
				}
			}
		}
	}
}


##########################
# Main Event for Glutton Target
##########################
feast_main_befriend.2004 = {
	title = feast_main_befriend.2004.t
	type = activity_event
	desc = {
		desc = feast_main_befriend.2003.opening
		triggered_desc = {
			trigger = { exists = scope:arrogant_guest }
			desc = feast_main_befriend.2004.arrogant_guest	
		}
		desc = feast_main_befriend.2004.kindness_from_other
	}
	theme = feast_activity
	left_portrait = {
		character = scope:activity.activity_host
		animation = happiness
	}
	right_portrait = {
		character = scope:kind_to_lower_nobility
		animation = personality_compassionate
	}
	lower_right_portrait = scope:arrogant_guest

	option = {
		name = feast_main_befriend.2004.a
		stress_impact = {
			base = medium_stress_loss
		}
		progress_towards_friend_effect = {
			REASON = friend_had_a_great_feast_together
			CHARACTER = scope:kind_to_lower_nobility
			OPINION = 0
		}
		hidden_effect = {
			if = {
				limit = {
					exists = scope:kind_to_lower_nobility
					NOT = { has_trait = arrogant }
				}
				add_opinion = {
					modifier = impressed_with_humility_opinion
					target = scope:kind_to_lower_nobility
				}
			}
		}
	}
}


##########################
# Generic Main Event for Guests
##########################
feast_main_befriend.3001 = {
	title = feast_main_befriend.3001.t
	type = activity_event
	desc = {
		desc = feast_main_befriend.2003.opening
		triggered_desc = {
			trigger = { exists = scope:arrogant_guest }
			desc = {
				desc = feast_main_befriend.3001.arrogant_guest
				triggered_desc = {
					trigger = { exists = scope:kind_to_lower_nobility }
					desc = feast_main_befriend.1001.arrogant_kind_link
				}
			}
		}
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:kind_to_lower_nobility }
				desc = {
					desc = feast_main_befriend.3001.kind_to_lower_nobility
					triggered_desc = {
						trigger = {
							scope:kind_to_lower_nobility = {
								any_secret = { type = secret_cannibal }
							}
						}
						desc = feast_main_befriend.3001.really_hungry
					}
				}
			}
		}
		desc = feast_main_befriend.3001.ending
	}
	theme = feast_activity
	left_portrait = {
		character = scope:activity.activity_host
		animation = happiness
	}
	lower_left_portrait = scope:arrogant_guest
	
	option = {
		name = feast_main_befriend.3001.a
		if = {
			limit = {
				exists = scope:kind_to_lower_nobility
				NOT = { has_trait = arrogant }
			}
			add_opinion = {
				modifier = impressed_with_humility_opinion
				target = scope:kind_to_lower_nobility
			}
		}
	}
}



##########################################################
# END EVENTS
# 5000-5999
##########################################################

# Fire End Events
feast_main_befriend.5001 = {
	type = activity_event
	
	hidden = yes
	
	trigger = {
		#verify that the activity still exists 
		exists = scope:activity
	}

	immediate = {		
		scope:activity = {

			activity_host = {
				save_scope_as = host_saying_goodbye
				if = {
					limit = { exists = primary_partner }
					random_consort = {
						limit = {
							this = scope:activity.activity_host.primary_partner
							is_available_ai = yes
						}
						alternative_limit = {
							is_available_ai = yes
						}
						save_scope_as = spouse
					}
				}
				scope:potential_friend = {
					trigger_event = feast_main_befriend.5003
				}
			}

			every_attending_character = {
				limit = {
					feast_default_participant_trigger = yes
					this != scope:activity.activity_host
					this != scope:potential_friend
				}
				trigger_event = feast_main_befriend.5004
			}
			
			activity_host = { trigger_event = feast_main_befriend.5002 }
		}
	}
}


#################
# Host End Event
#################
feast_main_befriend.5002 = {
	type = activity_event
	title = feast_main_befriend.5002.t
	desc = feast_main_befriend.5002.desc
	theme = feast_activity
	center_portrait = {
		character = root
		animation = toast
	}
	right_portrait = {
		character = scope:potential_friend
		animation = happiness
	}
	
	trigger = {
		OR = {
			any_scheme = {
				type = befriend
				scheme_target_character = {
					involved_activity ?= scope:activity
				}
			}
			AND = {
				has_activity_intent = befriend_attendee_intent
				intent_target ?= {
					is_alive = yes
				}
			}
			scope:activity = {
				any_attending_character = {
					feast_default_participant_trigger = yes
					this != scope:activity.activity_host
					NOT = { has_relation_friend = root }
					opinion = {
						target = scope:activity.activity_host
						value > 35
					}
				}
			}
		}
	}
	
	immediate = {
		if = {
			limit = {
				has_activity_intent = befriend_attendee_intent
				intent_target ?= {
					is_alive = yes
				}
			}
			intent_target = { save_scope_as = potential_friend }
		}
		else_if = {
			limit = {
				any_scheme = {
					type = befriend
					scheme_target_character = {
						involved_activity ?= scope:activity
					}
				}
			}
			random_scheme = {
				type = befriend
				limit = {
					scheme_target_character = {
						involved_activity ?= scope:activity
					}
				}
				scheme_target_character = {
					save_scope_as = potential_friend
				}
			}
		}
		else = {
			scope:activity = {
				random_attending_character = {
					limit = {
						feast_default_participant_trigger = yes
						this != scope:activity.activity_host
						NOT = { has_relation_friend = root }
						opinion = {
							target = scope:activity.activity_host
							value > 35
						}
					}
					save_scope_as = potential_friend
				}
			}
		}
	}

	option = {
		name = feast_main_befriend.5002.a
		scope:potential_friend = {
			add_opinion = {
				modifier = bonded_at_feast_opinion
				target = root
			}
		}
	}
}


#################
# Friend End Event
#################
feast_main_befriend.5003 = {
	type = activity_event
	title = feast_main_befriend.5003.t
	desc = feast_main_befriend.5003.desc
	theme = feast_activity
	left_portrait = {
		character = scope:activity.activity_host
		animation = happiness
	}
	lower_left_portrait = scope:spouse

	option = {
		name = feast_main_befriend.5003.a
		scope:host_saying_goodbye = {
			add_opinion = {
				modifier = bonded_at_feast_opinion
				target = scope:potential_friend
			}
		}
		feast_end_guest_effect = yes
	}
}


###################
# General Guest End Event
###################
feast_main_befriend.5004 = {
	type = activity_event
	title = feast_main_befriend.5004.t
	desc = feast_main_befriend.5004.desc
	theme = feast_activity
	left_portrait = {
		character = scope:activity.activity_host
		animation = happiness
	}
	right_portrait = {
		character = scope:spouse
		animation = personality_bold
	}

	option = {
		name = feast_main_befriend.5004.a
		add_hosted_feast_modifier_towards_character = { CHARACTER = scope:activity.activity_host }
		feast_end_guest_effect = yes
	}
}
