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




############################
# A LIVELY DISH
# 0051 - 0100
############################
# Among a number of delightfully presented entremets, a peacock [or other fowl] turns out to still be alive.

# 0051 - 0060: Standard setup and descriptive events.
# 0061 - 0070: Standard unique followup events.
# 0091 - 0100: Standard end events.


####
# Weight and Setup Event
####
feast_main_live_fowl.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:live_fowl }
		}
		scope:activity = {
			NOT = {
				has_activity_option = {
					category = feast_option_courses
					option = feast_courses_bad
				}
			}
			any_attending_character = {
				feast_default_participant_including_player_trigger = yes
				this != scope:activity.activity_host
				save_temporary_scope_as = fowl_dinner_target
			}
			any_attending_character = {
				feast_default_participant_including_player_trigger = yes
				NOR = {
					this = scope:activity.activity_host
					this = scope:fowl_dinner_target
				}
				NOT = { has_trait = lazy }
				NOT = { has_trait = compassionate }
				save_temporary_scope_as = fowl_bird_chaser
			}
			any_attending_character = {
				feast_default_participant_including_player_trigger = yes
				NOR = {
					this = scope:activity.activity_host
					this = scope:fowl_dinner_target
					this = scope:fowl_bird_chaser
				}
				count > 1
			}
		}
	}

	immediate = {
		scope:activity = {

			# Someone has to take the pain for the enjoyment of others.
			random_attending_character = {
				limit = {
					feast_default_participant_including_player_trigger = yes
					this != scope:activity.activity_host
				}
				save_scope_as = fowl_dinner_target
			}

			# A sadistic character kills the bird
			random_attending_character = {
				limit = {
					feast_default_participant_including_player_trigger = yes
					has_trait = sadistic
					NOR = {
						this = scope:activity.activity_host
						this = scope:fowl_dinner_target
					}
				}
				random = {
					chance = 50
					save_scope_as = fowl_bird_killer
				}
			}

			# If the bird is not killed, someone chases it out.
			random_attending_character = {
				limit = {
					feast_default_participant_including_player_trigger = yes
					NOT = { exists = scope:fowl_bird_killer }
					NOR = {
						this = scope:activity.activity_host
						this = scope:fowl_dinner_target
					}
					NOT = { has_trait = lazy }
					NOT = { has_trait = compassionate }
					NOT = { has_trait = sadistic }
				}

				save_scope_as = fowl_bird_chaser
			}

			activity_host = {
				set_variable = {
					name = last_feast_was
					value = flag:live_fowl
				}
				if = {
					limit = {
						NAND = {
							exists = scope:fowl_bird_killer
							this = scope:fowl_bird_killer
						}
					}

					# Generic host event, as long as they are not the bird killer.
					trigger_event = feast_main_live_fowl.0003
				}
			}

			every_attending_character = {
				limit = {
					feast_default_participant_including_player_trigger = yes
					NOR = {
						this = scope:activity.activity_host
						this = scope:fowl_dinner_target
						AND = {
							exists = scope:fowl_bird_killer
							this = scope:fowl_bird_killer
						}
						AND = {
							exists = scope:fowl_bird_chaser
							this = scope:fowl_bird_chaser
						}
					}
				}
				# Generic guest description event
				trigger_event = feast_main_live_fowl.0002
			}

			scope:fowl_dinner_target = {
				trigger_event = feast_main_live_fowl.0004
			}
			if = {
				limit = { exists = scope:fowl_bird_killer }
				scope:fowl_bird_killer = {
					trigger_event = feast_main_live_fowl.0005
				}
			}
			if = {
				limit = { exists = scope:fowl_bird_chaser }
				scope:fowl_bird_chaser = {
					trigger_event = feast_main_live_fowl.0006
				}
			}
		}
	}
}


###
# Generic event for Guests
###
feast_main_live_fowl.0002 = {
	title = feast_main_live_fowl.0002.t
	type = activity_event
	desc = {
		desc = feast_main_live_fowl.0002.entremets_served
		first_valid = {
			# If a character kills the bird
			triggered_desc = {
				trigger = {
					exists = scope:fowl_bird_killer
				}
				desc = feast_main_live_fowl.0002.bird_killed
			}
			# If a named character chases the bird out
			triggered_desc = {
				trigger = {
					exists = scope:fowl_bird_chaser
				}
				desc = feast_main_live_fowl.0002.bird_chased_by_character
			}
			# If a servant chases it away.
			desc = feast_main_live_fowl.0002.bird_chased_away
		}
	}
	theme = feast_activity
	left_portrait = {
		character = scope:fowl_dinner_target
		animation = pain
	}
	right_portrait = {
		character = scope:fowl_bird_killer
		animation = anger
	}

	option = {
		name = feast_main_live_fowl.0002.a
		add_character_modifier = {
			modifier = feast_raucous_entertainment_modifier
			years = 5
		}
		if = {
			limit = { exists = scope:fowl_bird_killer }
			show_as_tooltip = {
				scope:fowl_bird_killer = {
					add_dread = medium_dread_gain
				}
			}
		}
	}
}


###
# Event for Host
###
feast_main_live_fowl.0003 = {
	title = feast_main_live_fowl.0003.t
	type = activity_event
	desc = {
		desc = feast_main_live_fowl.0003.entremets_served
		first_valid = {
			# If a character kills the bird
			triggered_desc = {
				trigger = {
					exists = scope:fowl_bird_killer
				}
				desc = {
					desc = feast_main_live_fowl.0003.bird_killed
				}
			}
			# If a named character chases the bird out
			triggered_desc = {
				trigger = {
					exists = scope:fowl_bird_chaser
				}
				desc = {
					desc = feast_main_live_fowl.0003.bird_chased_by_character
				}
			}
			# If a servant chases it away.
			desc = feast_main_live_fowl.0003.bird_chased_away
		}
	}
	theme = feast_activity
	right_portrait = {
		character = scope:fowl_dinner_target
		animation = pain
	}
	left_portrait = {
		character = root
		animation = shock
	}
	center_portrait = {
		character = scope:fowl_bird_killer
		animation = anger
	}

	immediate = {
		play_music_cue = mx_cue_meadandwine
	}

	trigger = {
		NOT = {
			has_character_modifier = feast_raucous_entertainment_modifier
		}
	}

	option = {
		name = feast_main_live_fowl.0003.a
		add_character_modifier = {
			modifier = feast_raucous_entertainment_modifier
			years = 5
		}
		if = {
			limit = { exists = scope:fowl_bird_killer }
			show_as_tooltip = {
				scope:fowl_bird_killer = {
					add_dread = medium_dread_gain
				}
			}
		}
	}

	after = {
		hidden_effect = {
			trigger_event = {
				id = feast_main_live_fowl.9000
				days = 10
			}

			scope:activity = {
				add_activity_log_entry = {
					key = feast_live_fowl_log
					tags = { good }
					score = 25
					character = root
					target = scope:fowl_dinner_target
				}
			}
		}
	}
}


###
# Event for Bird Target
###
# The guest that suffers the fowl's wrath.
feast_main_live_fowl.0004 = {
	title = feast_main_live_fowl.0004.t
	type = activity_event
	desc = {
		desc = feast_main_live_fowl.0004.entremets_served
		first_valid = {
			# If a character kills the bird
			triggered_desc = {
				trigger = {
					exists = scope:fowl_bird_killer
				}
				desc = feast_main_live_fowl.0004.bird_killed
			}
			# If a named character chases the bird out
			triggered_desc = {
				trigger = {
					exists = scope:fowl_bird_chaser
				}
				desc = feast_main_live_fowl.0004.bird_chased_by_character
			}
			# If a servant chases it away.
			desc = feast_main_live_fowl.0004.bird_chased_away
		}
	}
	theme = feast_activity
	left_portrait = {
		character = scope:fowl_dinner_target
		animation = pain
	}
	right_portrait = {
		character = scope:fowl_bird_killer
		animation = anger
	}

	option = {
		name = feast_main_live_fowl.0004.a
		if = {
			limit = { has_trait = wounded_3 }
			add_internal_flag = dangerous
		}
		random_list = {
			15 = {
				increase_wounds_effect = {
					REASON = feast_accident
				}
				add_character_flag = was_wounded_by_bird_at_feast
			}
			85 = { } # Nothing happens
		}
		add_character_modifier = {
			modifier = feast_suspicious_of_food_modifier
			years = 10
		}
		if = {
			limit = { exists = scope:fowl_bird_killer }
			show_as_tooltip = {
				scope:fowl_bird_killer = {
					add_dread = medium_dread_gain
				}
			}
		}
	}

	after = {
		hidden_effect = {
			random = {
				chance = 15
				scope:activity.activity_host = {
					save_scope_as = host
				}
				trigger_event = {
					id = feast_main_live_fowl.1001
					days = { 10 20 }
				}
			}
		}
	}
}


###
# Event for Bird Killer
###
feast_main_live_fowl.0005 = {
	title = feast_main_live_fowl.0005.t
	type = activity_event
	desc = {
		desc = feast_main_live_fowl.0005.entremets_served
		desc = feast_main_live_fowl.0005.bird_killed
	}
	theme = feast_activity
	left_portrait = {
		character = scope:fowl_dinner_target
		animation = pain
	}
	right_portrait = {
		character = scope:activity.activity_host
		animation = shock
	}

	option = {
		name = feast_main_live_fowl.0005.a
		add_dread = medium_dread_gain
		add_character_modifier = {
			modifier = feast_display_of_ruthlessness_modifier
			years = 10
		}
	}
}


###
# Event for Bird Chaser
###
feast_main_live_fowl.0006 = {
	title = feast_main_live_fowl.0006.t
	type = activity_event
	desc = {
		desc = feast_main_live_fowl.0006.entremets_served
		desc = feast_main_live_fowl.0006.bird_chased_by_character
	}
	theme = feast_activity
	left_portrait = {
		character = scope:fowl_dinner_target
		animation = pain
	}
	right_portrait = {
		character = scope:fowl_bird_killer
		animation = anger
	}

	option = {
		name = feast_main_live_fowl.0006.a
		add_character_modifier = {
			modifier = feast_bird_based_exercise_modifier
			years = 5
		}
	}
}


##################
# FOLLOW-UPS
##################

# Become scarred from the bird peck
feast_main_live_fowl.1001 = {
	type = activity_event
	title = feast_main_live_fowl.1001.t
	desc = feast_main_live_fowl.1001.desc
	theme = feast_activity
	left_portrait = {
		character = root
		animation = pain
	}
	lower_left_portrait = scope:host

	option = {
		name = feast_main_live_fowl.1001.a
		if = {
			limit = { has_character_flag = was_wounded_by_bird_at_feast }
			if = {
				limit = {
					has_trait = wounded
				}
				change_trait_rank = {
					trait = wounded
					rank = -1
				}
			}
		}
		add_trait = scarred
		add_trait_xp = {
            trait = scarred
            value = {
                integer_range = {
                    min = 5
                    max = 25
                }
            }
        }
		if = {
			limit = {
				scope:host = { is_alive = yes }
			}
			progress_towards_rival_effect = {
				CHARACTER = scope:host
				REASON = rival_bird_pecked
				OPINION = 0
			}
		}
	}
}




##################
# END EVENT SETUP
##################
feast_main_live_fowl.9000 = {
	type = activity_event

	hidden = yes

	trigger = {
		exists = scope:activity
	}

	immediate = {
		scope:activity = {
			
			# Fire the end event for the host
			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
					}
				}
			}
	
			# 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
						this = scope:fowl_dinner_target
						AND = {
							exists = scope:fowl_bird_killer
							this = scope:fowl_bird_killer
						}
						AND = {
							exists = scope:fowl_bird_chaser
							this = scope:fowl_bird_chaser
						}
					}
				}
				trigger_event = feast_main_live_fowl.9001
			}

	
			# Fire special guest end events
			if = {
				limit = {
					exists = scope:fowl_dinner_target
				}
				scope:fowl_dinner_target = {
					trigger_event = feast_main_live_fowl.9003
				}
			}
		
			if = {
				limit = {
					exists = scope:fowl_bird_killer
				}
				scope:fowl_bird_killer = {
					trigger_event = feast_main_live_fowl.9004
				}
			}

			if = {
				limit = {
					exists = scope:fowl_bird_chaser
				}
				scope:fowl_bird_chaser = {
					trigger_event = feast_main_live_fowl.9005
				}
			}
			activity_host = { trigger_event = feast_main_live_fowl.9002 }
		}
	}
}


###################
# Guest End event
###################
feast_main_live_fowl.9001 = {
	type = activity_event
	title = feast_main_live_fowl.9001.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:fowl_bird_killer
				}
				desc = feast_main_live_fowl.9001.bird_killer
			}
			desc = feast_main_live_fowl.9001.no_bird_killer
		}
	}
	theme = feast_activity
	left_portrait = {
		character = scope:activity.activity_host
		animation = happiness
	}
	right_portrait = {
		character = scope:fowl_dinner_target
		animation = pain
	}
	lower_left_portrait = scope:spouse
	lower_right_portrait = scope:fowl_bird_killer

	option = {
		name = feast_main_live_fowl.9001.a
		stress_impact = {
			base = minor_stress_loss
		}
	}
}


######################
# Host End event
######################
feast_main_live_fowl.9002 = {
	type = activity_event
	title = feast_main_live_fowl.9002.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:fowl_bird_killer
				}
				desc = feast_main_live_fowl.9002.bird_killer
			}
			desc = feast_main_live_fowl.9002.no_bird_killer
		}
	}
	theme = feast_activity
	left_portrait = {
		character = root
		animation = personality_bold
	}
	right_portrait = {
		character = scope:fowl_dinner_target
		animation = pain
	}

	option = {
		name = feast_main_live_fowl.9002.a
		stress_impact = {
			base = minor_stress_loss
		}
	}

}


########################
# Bird Target end event
########################
feast_main_live_fowl.9003 = {
	type = activity_event
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:fowl_bird_killer
				}
				desc = feast_main_live_fowl.9003.bird_killer
			}
			desc = feast_main_live_fowl.9003.no_bird_killer
		}
	}
	theme = feast_activity
	left_portrait = {
		character = scope:activity.activity_host
		animation = happiness
	}
	lower_left_portrait = scope:spouse

	option = {
		name = feast_main_live_fowl.9003.a
		increase_wounds_no_death_effect = { REASON = wild_animal }
		add_opinion = {
			modifier = feast_victimised_in_prank
			target = scope:activity.activity_host
		}
		progress_towards_rival_effect = {
			CHARACTER = scope:activity.activity_host
			OPINION = 0
			REASON = rival_fowl_prank
		}
	}
}


##################
# Bird Killer end event
##################
feast_main_live_fowl.9004 = {
	type = activity_event
	desc = feast_main_live_fowl.9004.desc
	theme = feast_activity
	left_portrait = {
		character = scope:activity.activity_host
		animation = happiness
	}
	lower_left_portrait = scope:spouse

	option = {
		name = feast_main_live_fowl.9004.a
		add_dread = minor_dread_gain
		stress_impact = {
			callous = medium_stress_impact_loss
			sadistic = medium_stress_impact_loss
		}
	}
}


##################
# Bird Chaser end event
##################
feast_main_live_fowl.9005 = {
	type = activity_event
	desc = feast_main_live_fowl.9005.desc
	theme = feast_activity
	left_portrait = {
		character = scope:activity.activity_host
		animation = happiness
	}
	lower_left_portrait = scope:spouse

	option = {
		name = feast_main_live_fowl.9005.a
		add_prestige = minor_prestige_gain
		stress_impact = {
			shy = medium_stress_impact_gain
		}
	}
}
