﻿# 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_stew_flood


############################
# THE STEW FLOOD
# by Petter Vilberg
############################
# 0001 - 0010: Standard setup and descriptive events.
# 0031 - 0040: Extraneous events
# 0041 - 0050: Standard end events.


# A giant cauldron of stew tips over in the middle of the meal
# Half the hall gets covered in a sea of stew.


####
# Weight and Setup Event
####
feast_main_stew_flood.0001 = {
	type = activity_event
	
	hidden = yes

	trigger = {
		trigger_if = {
			limit = { scope:activity.activity_host = { has_variable = last_feast_was } }
			NOT = { scope:activity.activity_host.var:last_feast_was = flag:stew_flood }
		}
		NOT = {
			scope:activity = {
				has_activity_option = {
					category = feast_option_food
					option = feast_food_good
				}
			}
		}
		scope:activity = {
			any_attending_character = {
				feast_default_participant_including_player_trigger = yes
				this != scope:activity.activity_host
				drinks_alcohol_trigger = yes 
				save_temporary_scope_as = stew_sea_blamed_temp
			}
			any_attending_character = {
				feast_default_participant_including_player_trigger = yes
				has_trait = gluttonous
				NOR = {
					this = scope:activity.activity_host
					this = scope:stew_sea_blamed_temp
				}
				save_temporary_scope_as = stew_sea_glutton_temp
			}
			any_attending_character = {
				feast_default_participant_including_player_trigger = yes
				has_trait = temperate
				NOR = {
					this = scope:activity.activity_host
					this = scope:stew_sea_blamed_temp
					this = scope:stew_sea_glutton_temp
				}
				save_temporary_scope_as = stew_sea_horrified_character_temp
			}
			any_attending_character = {
				feast_default_participant_including_player_trigger = yes
				this != scope:stew_sea_blamed_temp
				this != scope:stew_sea_glutton_temp
				this != scope:stew_sea_horrified_character_temp
				this != scope:activity.activity_host
			}
		}
	}

	weight_multiplier = {
		base = 1
	}

	immediate = {
		scope:activity = {
			# Find someone who can take the blame
			random_attending_character = {
				limit = {
					feast_default_participant_including_player_trigger = yes
					this != scope:activity.activity_host
					drinks_alcohol_trigger = yes
				}

				save_scope_as = stew_sea_blamed
			}

			# Find someone who can cause themselves shame by eating off the floor.
			random_attending_character = {
				limit = {
					feast_default_participant_including_player_trigger = yes
					has_trait = gluttonous
					NOR = {
						this = scope:activity.activity_host
						this = scope:stew_sea_blamed
					}
				}
				random_list = { #Gluttons should not eat from the floor at _every_ feast where we spill food
					25 = { save_scope_as = stew_sea_glutton }
					75 = { }
				}
			}
	
			# Find someone who can be horrified by the waste
			random_attending_character = {
				limit = {
					feast_default_participant_including_player_trigger = yes
					has_trait = temperate
					NOR = {
						this = scope:activity.activity_host
						this = scope:stew_sea_blamed
					}
				}
	
				save_scope_as = stew_sea_horrified_character
			}
	
			# Find someone who gets covered in stew
			random_attending_character = {
				limit = {
					feast_default_participant_including_player_trigger = yes
					# Not any of the other targets
					this != scope:stew_sea_blamed
					trigger_if = {
						limit = { exists = scope:stew_sea_glutton }
						this != scope:stew_sea_glutton
					}
					trigger_else = { always = yes }
					trigger_if = {
						limit = { exists = scope:stew_sea_horrified_character }
						this != scope:stew_sea_horrified_character
					}
					trigger_else = { always = yes }
					this != scope:activity.activity_host
					OR = { # Prefer someone arrogant, beautiful or angry
						has_trait = arrogant
						has_trait = beauty_good
						has_trait = wrathful
						trigger_if = {
							limit = {
								exists = scope:activity.special_guest:honorary_guest_regular
							}
							this = scope:activity.special_guest:honorary_guest_regular
						}
					}
				}
				alternative_limit = {
					feast_default_participant_including_player_trigger = yes
					# Not any of the other targets
					this != scope:stew_sea_blamed
					trigger_if = {
						limit = { exists = scope:stew_sea_glutton }
						this != scope:stew_sea_glutton
					}
					trigger_if = {
						limit = { exists = scope:stew_sea_horrified_character }
						this != scope:stew_sea_horrified_character
					}
					this != scope:activity.activity_host
					OR = { # Take someone who might have an outsized reaction
						has_trait = stubborn
						has_trait = callous
						has_trait = sadistic
						has_trait = paranoid
						has_trait = lunatic
					}
				}
				alternative_limit = { # Fallback
					# Not any of the other targets
					feast_default_participant_including_player_trigger = yes
					this != scope:stew_sea_blamed
					trigger_if = {
						limit = { exists = scope:stew_sea_glutton }
						this != scope:stew_sea_glutton
					}
					trigger_if = {
						limit = { exists = scope:stew_sea_horrified_character }
						this != scope:stew_sea_horrified_character
					}
					this != scope:activity.activity_host
				}
	
				save_scope_as = stew_sea_gets_covered
			}

	
			activity_host = {
				set_variable = {
					name = last_feast_was
					value = flag:stew_flood
				}
				if = {
					limit = {
						NOR = {
							AND = {
								exists = scope:stew_sea_horrified_character
								this = scope:stew_sea_horrified_character
							}
							AND = {
								exists = scope:stew_sea_glutton
								this = scope:stew_sea_glutton
							}
							AND = {
								exists = scope:stew_sea_gets_covered
								this = scope:stew_sea_gets_covered
							}
						}
					}
					trigger_event = feast_main_stew_flood.0003
				}
			}
	
			every_attending_character = {
				# Every participant that does not get a special event.
				limit = {
					feast_default_participant_including_player_trigger = yes
					NOR = {
						AND = {
							exists = scope:stew_sea_glutton
							this = scope:stew_sea_glutton
						}
						AND = {
							exists = scope:stew_sea_horrified_character
							this = scope:stew_sea_horrified_character
						}
						AND = {
							exists = scope:stew_sea_gets_covered
							this = scope:stew_sea_gets_covered
						}
						this = scope:activity.activity_host
					}
				}
	
				# Standard key event
				trigger_event = feast_main_stew_flood.0002
			}
			if = {
				limit = { exists = scope:stew_sea_gets_covered }
				scope:stew_sea_gets_covered = {
					trigger_event = feast_main_stew_flood.0004
				}
			}
			if = {
				limit = { exists = scope:stew_sea_glutton }
				scope:stew_sea_glutton = {
					trigger_event = feast_main_stew_flood.0005
				}
			}
			if = {
				limit = { exists = scope:stew_sea_horrified_character }
				scope:stew_sea_horrified_character = {
					trigger_event = feast_main_stew_flood.0006
				}
			}

		}
	}
}


####
# Standard Descriptive Event
####
feast_main_stew_flood.0002 = {
	title = feast_main_stew_flood.0002.t
	type = activity_event
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:stew_sea_blamed
					root = scope:stew_sea_blamed
				}
				desc = feast_main_stew_flood.0002.stew_introduction_blamed
			}
			# Introduction, which also places blame.
			triggered_desc = {
				# If there is a character to blame, they'll be named and shamed
				trigger = {
					exists = scope:stew_sea_blamed
				}
				desc = feast_main_stew_flood.0002.stew_introduction_blame
			}
			# Fallback using blaming a generic servant if there aren't enough characters
			desc = feast_main_stew_flood.0002.stew_introduction
		}
		triggered_desc = {
			# Someone may get covered by meat stew, which is terrible for them.
			trigger = {
				exists = scope:stew_sea_gets_covered
			}
			desc = feast_main_stew_flood.0002.someone_got_covered
		}
		# A general description of the state of things after the accident:
		desc = feast_main_stew_flood.0002.splash_desc_standard
		first_valid = {
			# A character may bring shame upon themselves by eating off the floor.
			triggered_desc = {
				# If there is a horrified witness to the action.
				trigger = {
					exists = scope:stew_sea_glutton
					exists = scope:stew_sea_horrified_character
				}
				desc = feast_main_stew_flood.0002.every_target
			}
			triggered_desc = {
				# If there is someone eating off the floor, but no named witness.
				trigger = {
					exists = scope:stew_sea_glutton
				}
				desc = feast_main_stew_flood.0002.only_glutton
			}
			triggered_desc = {
				# If there is a horrified witness, but nobody eating off the floor.
				trigger = {
					exists = scope:stew_sea_horrified_character
				}
				desc = feast_main_stew_flood.0002.only_horror
			}
		}
	}
	theme = feast_activity
	left_portrait = {
		character = scope:activity.activity_host
		animation = shock
	}
	right_portrait = {
		character = scope:stew_sea_blamed
		animation = shame
	}
	lower_left_portrait = scope:stew_sea_gets_covered
	lower_center_portrait = scope:stew_sea_glutton
	lower_right_portrait = scope:stew_sea_horrified_character

	option = {
		name = feast_main_stew_flood.0002.a
		stress_impact = {
			base = minor_stress_impact_gain
			shy = minor_stress_impact_gain
		}
	}
}

###
# Descrptive Event for Host
###
feast_main_stew_flood.0003 = {
	title = feast_main_stew_flood.0003.t
	type = activity_event
	desc = {
		first_valid = {
			# Introduction, which also places blame.
			triggered_desc = {
				# If there is a character to blame, they'll be named and shamed
				trigger = {
					exists = scope:stew_sea_blamed
				}
				desc = feast_main_stew_flood.0003.stew_introduction_blame
			}
			# Fallback using blaming a generic servant if there aren't enough characters
			desc = feast_main_stew_flood.0003.stew_introduction
		}
		triggered_desc = {
			# Someone may get covered by meat stew, which is terrible for them.
			trigger = {
				exists = scope:stew_sea_gets_covered
			}
			desc = feast_main_stew_flood.0003.someone_got_covered
		}
		# A general description of the state of things after the accident:
		desc = feast_main_stew_flood.0003.splash_desc_standard
		first_valid = {
			# A character may bring shame upon themselves by eating off the floor.
			triggered_desc = {
				# If there is a horrified witness to the action.
				trigger = {
					exists = scope:stew_sea_glutton
					exists = scope:stew_sea_horrified_character
				}
				desc = feast_main_stew_flood.0003.every_target
			}
			triggered_desc = {
				# If there is someone eating off the floor, but no named witness.
				trigger = {
					exists = scope:stew_sea_glutton
				}
				desc = feast_main_stew_flood.0003.only_glutton
			}
			triggered_desc = {
				# If there is a horrified witness, but nobody eating off the floor.
				trigger = {
					exists = scope:stew_sea_horrified_character
				}
				desc = feast_main_stew_flood.0003.only_horror
			}
		}
	}
	theme = feast_activity
	left_portrait = {
		character = scope:activity.activity_host
		animation = shock
	}
	right_portrait = {
		character = scope:stew_sea_blamed
		animation = shame
	}
	lower_left_portrait = scope:stew_sea_gets_covered
	lower_center_portrait = scope:stew_sea_glutton
	lower_right_portrait = scope:stew_sea_horrified_character

	immediate = {
		play_music_cue = mx_cue_meadandwine
	}

	option = {
		name = feast_main_stew_flood.0003.a
		add_prestige = medium_prestige_loss
		add_character_modifier = {
			modifier = feast_spilled_stew_modifier
			years = 5
		}
	}

	after = {
		hidden_effect = {
			trigger_event = {
				id = feast_main_stew_flood.0040
				days = 10
			}
 			scope:activity = {
				add_activity_log_entry = {
					key = feast_stew_flood_log
					tags = { good }
					score = 25
					character = root
					target = scope:stew_sea_gets_covered
					scope:stew_sea_gets_covered = {
						add_prestige = minor_prestige_loss
					}
				}
			}
		}
	}
}


###
# Descriptive Event for Getting Covered
###
feast_main_stew_flood.0004 = {
	title = feast_main_stew_flood.0004.t
	type = activity_event
	desc = {
		# First part of event desc
		first_valid = {
			triggered_desc = {
				# If there is a named character to blame.
				trigger = {
					exists = scope:stew_sea_blamed
				}
				desc = feast_main_stew_flood.0004.stew_introduction_blame
			}
			# No named character to blame:
			desc = feast_main_stew_flood.0004.stew_introduction
		}
		# Second part of the event desc
		desc = feast_main_stew_flood.0004.getting_covered
	}
	theme = feast_activity
	left_portrait = {
		character = scope:activity.activity_host
		animation = shock
	}
	right_portrait = {
		character = scope:stew_sea_blamed
		animation = shame
	}
	lower_center_portrait = scope:stew_sea_glutton
	lower_right_portrait = scope:stew_sea_horrified_character

	option = {
		name = feast_main_stew_flood.0004.a
		if = {
			limit = { exists = scope:stew_sea_blamed }
			add_opinion = {
				modifier = feast_got_stew_all_over_me
				target = scope:stew_sea_blamed
			}
		}
		else = { #If no one else is to blame I blame my host
			scope:stew_sea_gets_covered = {
				add_opinion = {
					modifier = feast_got_stew_all_over_me
					target = root
				}
			}
		}
	}
}

###
# Descriptive Event for Glutton
###
feast_main_stew_flood.0005 = {
	title = feast_main_stew_flood.0005.t
	type = activity_event
	desc = {
		first_valid = {
		# First part of gluttons desc
			triggered_desc = {
				# If there's a named character to blame
				trigger = {
					exists = scope:stew_sea_blamed
				}
				desc = feast_main_stew_flood.0005.stew_introduction_blame
			}
			# Fallback for not having a named blame character
			desc = feast_main_stew_flood.0005.stew_introduction
		}
		# Second part of the gluttons desc
		desc = feast_main_stew_flood.0005.cannot_resist
		triggered_desc = {
			# If the horrified character is watching them, that detail is appended.
			trigger = {
				exists = scope:stew_sea_horrified_character
			}
			desc = feast_main_stew_flood.0005.being_watched
		}
	}
	theme = feast_activity
	left_portrait = {
		character = scope:activity.activity_host
		animation = shock
	}
	right_portrait = {
		character = scope:stew_sea_blamed
		animation = shame
	}
	lower_left_portrait = scope:stew_sea_gets_covered
	lower_right_portrait = scope:stew_sea_horrified_character

	option = {
		name = feast_main_stew_flood.0005.a
		scope:activity = {
			every_attending_character = {
				limit = {
					feast_default_participant_including_player_trigger = yes
					NOT = {
						has_trait = gluttonous
					}
				}
				add_opinion = {
					modifier = feast_disgracefully_ate_from_floor
					target = root
				}
			}
		}
	}
}

###
# Descriptive Event for Horrified
###
feast_main_stew_flood.0006 = {
	title = feast_main_stew_flood.0006.t
	type = activity_event
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:stew_sea_blamed
				}
				desc = feast_main_stew_flood.0006.stew_introduction
			}
			desc = feast_main_stew_flood.0006.stew_introduction_blame
		}
		triggered_desc = {
			trigger = {
				exists = scope:stew_sea_glutton
			}
		}
		desc = feast_main_stew_flood.0006.shocking_experience
	}
	theme = feast_activity
	left_portrait = {
		character = scope:activity.activity_host
		animation = shock
	}
	right_portrait = {
		character = scope:stew_sea_blamed
		animation = shame
	}
	lower_left_portrait = scope:stew_sea_gets_covered
	lower_center_portrait = scope:stew_sea_glutton

	option = {
		name = feast_main_stew_flood.0006.a
		
		stress_impact = {
			base = medium_stress_gain
		}
	}
}




##################
# END EVENT SETUP
##################
feast_main_stew_flood.0040 = {
	type = activity_event

	hidden = yes

	trigger = {
		exists = scope:activity
	}

	immediate = {
		scope:activity = {
			activity_host = {
				save_scope_as = host
				if = {
					limit = { exists = primary_partner }
					random_consort = {
						limit = {
							feast_default_participant_including_player_trigger = yes
							this = scope:activity.activity_host.primary_partner
							is_available_ai = yes
						}
						alternative_limit = {
							feast_default_participant_including_player_trigger = yes
							is_available_ai = yes
						}
						save_scope_as = spouse
					}
				}
			}

			# Fire the end event for every participant except specials
			every_attending_character = {
				limit = {
					feast_default_participant_including_player_trigger = yes
					NOR = {
						this = scope:activity.activity_host
						AND = {
							exists = scope:stew_sea_gets_covered
							this = scope:stew_sea_gets_covered
						}
						AND = {
							exists = scope:stew_sea_blamed
							this = scope:stew_sea_blamed
						}
					}
				}
				trigger_event = feast_main_stew_flood.0041
			}
	
			# Fire special guest end events
			if = {
				limit = {
					exists = scope:stew_sea_gets_covered
				}
				scope:stew_sea_gets_covered = {
					trigger_event = feast_main_stew_flood.0043
				}
			}
	
			if = {
				limit = {
					exists = scope:stew_sea_blamed
				}
				scope:stew_sea_blamed = {
					trigger_event = feast_main_stew_flood.0044
				}
			}
			
			# Fire the end event for the host
			activity_host = {
				trigger_event = feast_main_stew_flood.0042
			}
		}
	}
}


###################
# Guest End event
###################
feast_main_stew_flood.0041 = {
	type = activity_event
	title = feast_main_stew_flood.0041.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:stew_sea_blamed
				}
				desc = feast_main_stew_flood.0041.blame_placed
			}
			desc = feast_main_stew_flood.0041.no_blame_placed
		}
	}
	theme = feast_activity
	left_portrait = {
		character = scope:host
		animation = happiness
	}
	right_portrait = {
		character = scope:spouse
		animation = personality_bold
	}

	option = {
		name = feast_main_stew_flood.0041.a
		stress_impact = {
			base = minor_stress_impact_loss
		}
		show_as_tooltip = {
			if = {
				limit = {
					exists = scope:stew_sea_blamed
				}
				scope:stew_sea_gets_covered = {
					add_opinion = {
						modifier = feast_got_stew_all_over_me
						target = scope:stew_sea_blamed
					}
				}
			}
			else = {
				scope:stew_sea_gets_covered = {
					add_opinion = {
						modifier = feast_got_stew_all_over_me
						target = scope:host
					}
				}
			}
		}
	}
}


######################
# Host End event
######################
feast_main_stew_flood.0042 = {
	type = activity_event
	title = feast_main_stew_flood.0042.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:stew_sea_blamed
				}
				desc = feast_main_stew_flood.0042.blame_placed
			}
			desc = feast_main_stew_flood.0042.no_blame_placed
		}
	}
	theme = feast_activity
	left_portrait = {
		character = scope:host
		animation = happiness
	}
	right_portrait = {
		character = scope:stew_sea_blamed
		triggered_animation = {
			trigger = {
				exists = scope:stew_sea_blamed
			}
			animation = shame
		}
		triggered_animation = {
			trigger = {
				NOT = { exists = scope:stew_sea_blamed }
			}
			animation = shock
		}
	}

	option = {
		name = feast_main_stew_flood.0042.a
		show_as_tooltip = {
			if = {
				limit = {
					exists = scope:stew_sea_blamed
				}
				scope:stew_sea_gets_covered = {
					add_opinion = {
						modifier = feast_got_stew_all_over_me
						target = scope:stew_sea_blamed
					}
				}
			}
			else = {
				scope:stew_sea_gets_covered = {
					add_opinion = {
						modifier = feast_got_stew_all_over_me
						target = root
					}
				}
			}
		}
		stress_impact = {
			base = minor_stress_impact_loss
		}
	}
}


########################
# Got Covered end event
########################
feast_main_stew_flood.0043 = {
	type = activity_event
	title = feast_main_stew_flood.0042.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:stew_sea_blamed
				}
				desc = feast_main_stew_flood.0043.blame_placed
			}
			desc = feast_main_stew_flood.0043.no_blame_placed
		}
	}
	theme = feast_activity
	left_portrait = {
		character = scope:host
		animation = happiness
	}
	right_portrait = {
		character = scope:spouse
		animation = personality_bold
	}

	immediate = {
		increase_wounds_no_death_effect = { REASON = burned }
	}

	option = {
		name = feast_main_stew_flood.0043.a
		stress_impact = {
			base = minor_stress_impact_gain
		}
	}
}

feast_main_stew_flood.0044 = {
	type = activity_event
	title = feast_main_stew_flood.0042.t
	desc = feast_main_stew_flood.0044.desc
	theme = feast_activity
	left_portrait = {
		character = scope:host
		animation = happiness
	}
	right_portrait = {
		character = scope:spouse
		animation = personality_bold
	}

	option = {
		name = feast_main_stew_flood.0044.a
		stress_impact = {
			base = minor_stress_impact_gain
		}
	}
}
