﻿namespace = activity_system

#####################################
# Activity - System Events			#
# activity_system - 0000-9999		#
# by Chad Uhl						#
#####################################

# New Host after character death
activity_system.0080 = {
	type = character_event
	title = activity_system.0080.t
	desc = {
		desc = activity_system.0080.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					root = scope:host
				}
				desc = activity_system.0080.desc_me
			}
			desc = activity_system.0080.desc_other
		}
	}
	theme = realm
	override_background = {
		reference = ep2_activity
	}
	left_portrait = {
		character = root
		animation = admiration
	}
	right_portrait = {
		trigger = {
			root != scope:host
		}
		character = scope:host
		animation = personality_honorable
	}
	immediate = {
		involved_activity.activity_host = { save_scope_as = host }
	}
	option = { 
		name = activity_system.0080.a
	}
}

# Pilgrimage: New Host after character death
activity_system.0081 = {
	type = activity_event
	title = activity_system.0081.t
	desc = {
		first_valid = {
			#Dearly departed mother/father
			triggered_desc = {
				trigger = {
					is_close_family_of = scope:old_host
					has_character_flag = pilgrimage_liked_my_predecessor
				}
				desc = activity_system.0081.desc.relation_family_liked
			}
			#Dearly departed <name>
			triggered_desc = {
				trigger = { has_character_flag = pilgrimage_liked_my_predecessor }
				desc = activity_system.0081.desc.relation_liked
			}
			#Departed mother/father
			triggered_desc = {
				trigger = {
					is_close_family_of = scope:old_host
				}
				desc = activity_system.0081.desc.relation_family
			}
			#... dead liege?
			triggered_desc = {
				desc = activity_system.0081.desc.relation_neutral
			}
		}
		desc = activity_system.0081.desc.outro
	}
	theme = pilgrimage_destination
	override_background = {
		reference = army_camp
	}
	left_portrait = {
		character = root
		animation = sadness
	}
	right_portrait = {
		trigger = { exists = scope:grieving_pilgrim }
		character = scope:grieving_pilgrim
		animation = grief
	}
	lower_left_portrait = {
		character = scope:old_host
	}
	immediate = {
		#Some grieving atmosphere
		scope:activity = {
			if = {
				limit = {
					any_attending_character = {
						this != root
					}
				}
				random_attending_character = {
					limit = {
						this != root
					}
					save_scope_as = grieving_pilgrim
				}
			}
			add_activity_log_entry = {
				key = pilgrimage_host_death_log
				tags = { bad }
				score = 50
				character = scope:old_host
			}
		}
		#Override Obligatory in case you inherited the pilgrimage
		if = {
			limit = {
				scope:activity = {
					has_activity_option = {
						category = pilgrimage_option_fidelity
						option = pilgrimage_fidelity_obligatory
					}
				}
			}
			add_character_flag = pilgrimage_counter_obligatory
		}
	}
	#Cancel activity and bury them back home
	option = { 
		name = activity_system.0081.a
		set_variable = {
			name = pilgrimage_death_turn_back
			value = flag:yes
		}
		custom_tooltip = activity_system.0081.a.tt
		invalidate_activity = scope:activity
	}
	#Bury them at Destination
	option = { 
		name = activity_system.0081.b
		set_variable = {
			name = pilgrimage_death_bury_there
			value = flag:yes
		}
		custom_tooltip = activity_system.0081.b.tt
		pious_type_option_effect = yes
		scope:activity = {
			add_activity_log_entry = {
				key = pilgrimage_inherited_pilgrimage_log
				tags = { bad }
				score = 50
				character = root
				show_in_conclusion = yes
				#Effects
				root = {
					add_character_modifier = {
						modifier = pilgrimage_burial_at_destination_modifier
					}
				}
			}
		}
	}
	#Carry them with you to Destination and then bury them back home
	option = { 
		name = activity_system.0081.c
		set_variable = {
			name = pilgrimage_death_bury_home
			value = flag:yes
		}
		custom_tooltip = activity_system.0081.c.tt
		worldly_type_option_effect = yes
		scope:activity = {
			add_activity_log_entry = {
				key = pilgrimage_inherited_pilgrimage_log
				character = root
				show_in_conclusion = yes
				#Effects
				root = {
					add_character_modifier = {
						modifier = pilgrimage_burial_at_capital_modifier
					}
				}
			}
		}
	}
	after = { 
		remove_character_flag = pilgrimage_dealing_with_invalidation
		if = {
			limit = { exists = scope:activity }

			set_variable = {
				name = previous_holy_site
				value = scope:activity.activity_location
			}

			# If a Hajj and already arrived at Mecca, re-start the rail roaded event chain, it handles activity conclusion
			# So it must be restarted else the activity will never end.
			if = {
				limit = {
					scope:activity = {
						has_activity_option = {
							category = special_type
							option = pilgrimage_type_hajj
						}

						has_variable = at_pilgrimage_destination
					}
				}
				trigger_event = pilgrimage.3101
			}
		}
	}
}

# Intent Invalidated
activity_system.0090 = {
	type = activity_event
	title = activity_system.0090.t
	desc = activity_system.0090.desc
	theme = realm
	override_background = {
		reference = ep2_involved_activity
	}

	left_portrait = {
		character = root
		animation = sadness
	}

	trigger = {
		exists = scope:activity
	}

	immediate = {
		
	}

	option = { 
		name = activity_system.0090.a
	}
}

# Intent Target Invalidated
activity_system.0091 = {
	type = activity_event
	title = activity_system.0091.t
	desc = activity_system.0091.desc
	theme = realm
	override_background = {
		reference = ep2_involved_activity
	}

	left_portrait = {
		character = root
		animation = sadness
	}
	lower_right_portrait = scope:target

	trigger = {
		exists = scope:activity
	}

	immediate = {
		
	}

	option = { 
		name = activity_system.0091.a
	}
}

activity_system.0092 = {
	type = activity_event
	title = activity_system.0091.t
	desc = activity_system.0091.desc
	theme = realm
	override_background = {
		reference = ep2_involved_activity
	}

	left_portrait = {
		character = root
		animation = sadness
	}
	lower_right_portrait = scope:target

	trigger = {
		exists = involved_activity
		exists = scope:activity
	}

	immediate = {
		
	}

	option = { 
		name = activity_system.0091.a
	}
}

# No one shows up to your activity
activity_system.0100 = {
	type = character_event 
	title = activity_system.0100.t
	desc = {
		desc = activity_system.0100.desc 
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = current_travel_plan
				}
				desc = activity_system.0100.outro_away
			}
			desc = activity_system.0100.outro_home
		}
	}
	theme = realm 

	override_background = {
		reference = terrain 
	}

	left_portrait = {
		character = root
		animation = sadness 
	}

	option = {
		name = activity_system.0100.a
		stress_impact = {
			base = minor_stress_impact_gain
			gregarious = medium_stress_impact_gain
			charming = medium_stress_impact_gain
			shy = minor_stress_impact_loss
			pensive = minor_stress_impact_loss
		}
	}
}

# ACTIVITY SPECIFIC INVALIDATION EVENTS

# Tour Invalidation for Host Death - Player Heir
activity_system.1010 = {
	type = character_event
	title = activity_system.1010.t
	desc = {
		desc = activity_system.1010.desc
		desc = activity_system.1010.desc.entourage
		desc = activity_system.1010.desc.ruler
	}
	theme = realm

	left_portrait = {
		character = root
		animation = worry
	}

	immediate = {}

	option = { 
		name = activity_system.1010.a
		custom_tooltip = activity_system.1010.tt
	}
}

#Tour Invalidation for Host Death - Attending Characters
activity_system.1011 = {
	type = character_event
	title = activity_system.1010.t
	desc = activity_system.1011.desc
	theme = realm

	left_portrait = {
		character = root
		animation = worry
	}

	option = { 
		name = activity_system.1010.a
		custom_tooltip = activity_system.1010.tt
	}
}

# Host has joined a war and has the option to cancel activity 
activity_system.0300 = {
	type = character_event 
	title = activity_system.0300.t
	desc = {
		# Intro loc based on whether you are traveling to your activity or if you're already there
		first_valid = {
			triggered_desc = {
				trigger = {
					location != scope:target_activity_location
				}
				desc = activity_system.0300.desc.intro.traveling
			}
			triggered_desc = {
				trigger = {
					location = scope:target_activity_location
				}
				desc = activity_system.0300.desc.intro.activity
			}
		}
		# Provide some info about the war
		first_valid = { # War info
			triggered_desc = {
				trigger = {
					any_character_war = {
						is_attacker = root
					}
				}
				desc = activity_system.0300.desc.attacker
			}
			triggered_desc = {
				trigger = {
					any_character_war = {
						is_defender = root
					}
				}
				desc = activity_system.0300.desc.defender
			}
		}
		# Outro
		desc = activity_system.0300.desc.outro
	}
	theme = realm
	override_background = {
		trigger = { location != scope:target_activity_location }
		reference = terrain
	}
	override_background = {
		trigger = { location = scope:target_activity_location }
		reference = terrain_activity
	}

	left_portrait = {
		character = root
		animation = worry
	}
	lower_right_portrait = scope:war_opponent

	immediate = {
		# Save scopes about the activity so they can be passed on to the follow-up event if needed
		save_scope_as = target_activity_host
		involved_activity = { save_scope_as = target_activity }
		scope:target_activity.activity_location = { save_scope_as = target_activity_location }
		if = {
			limit = {
				scope:war = {
					any_war_attacker = {
						this = root
					}
				} 
			}
			scope:war.primary_defender = { save_scope_as = war_opponent }
		}
		else = {
			scope:war.primary_attacker = { save_scope_as = war_opponent }
		}
	}

	option = { # Do not cancel the activity
		name = activity_system.0300.a
		custom_tooltip = activity_system.0300.a.tt

		ai_chance = {
			base = 0
			modifier = {
				add = 100
				OR = {
					scope:target_activity = {
						has_activity_type = activity_coronation
						activity_host = root
					}
					scope:target_activity = {
						has_activity_type = activity_imperial_examination
						activity_host = root
					}
					scope:target_activity = {
						has_activity_type = activity_local_examination
						activity_host = root
					}
				}
			}
		}
	}

	option = { # Cancel the activity
		name = activity_system.0300.b
		custom_tooltip = activity_system.0300.b.tt
		custom_tooltip = activity_system.0300.b.tt.cost
		hidden_effect = {
			scope:target_activity = {
				# Sends out a notifying event to all the attendees that the activity has been cancelled
				every_attending_character = {
					limit = {
						this != root
						is_at_war = no # If you are at war you have a different event
					}
					trigger_event = activity_system.0301
				}
			}
			# Cancel the activity and return home
			invalidate_activity = scope:target_activity 
		}

		ai_chance = {
			base = 100 
			modifier = {
				factor = 0
				OR = {
					scope:target_activity = {
						has_activity_type = activity_coronation
						activity_host = root
					}
					scope:target_activity = {
						has_activity_type = activity_imperial_examination
						activity_host = root
					}
					scope:target_activity = {
						has_activity_type = activity_local_examination
						activity_host = root
					}
				}
			}
		}
	}
}

# Follow-up for guests if the host has decided to cancel the activity
activity_system.0301 = {
	type = character_event 
	title = activity_system.0301.t
	desc = activity_system.0301.desc
	theme = realm 
	override_background = {
		trigger = { location != scope:target_activity_location }
		reference = terrain
	}

	left_portrait = {
		character = scope:target_activity_host
		animation = marshal
	}
	right_portrait = {
		character = scope:war_opponent
		animation = personality_callous
	}

	option = { # Ok guess I'll go home now
		name = activity_system.0301.a
	}
}

# Guest has joined/started a war and has the option to leave the activity 
activity_system.0310 = {
	type = character_event 
	title = activity_system.0300.t
	desc = {
		desc = activity_system.0310.desc.intro
		first_valid = {
			triggered_desc = {
				trigger = { 
					root = scope:war.primary_defender
				}
				desc = activity_system.0310.desc.primary_defender
			}
			desc = activity_system.0310.desc.random_defender
		}
	}
	theme = realm

	left_portrait = {
		character = scope:attacker
		animation = marshal
	}
	right_portrait = {
		character = scope:defender
		animation = personality_callous 
	}

	trigger = {
		exists = involved_activity
	}

	immediate = {
		# Save scopes about the activity so they can be passed on to the follow-up event if needed
		save_scope_as = target_activity_host
		involved_activity = { save_scope_as = target_activity }
		scope:target_activity.activity_location = { save_scope_as = target_activity_location }
		scope:war.primary_attacker = { save_scope_as = attacker }
		scope:war.primary_defender = { save_scope_as = defender }
	}

	option = { # Stay and participate 
		# Reuses name from 0300
		name = activity_system.0300.a
		custom_tooltip = activity_system.0310.a.tt

		trigger = {
			NOR = {
				scope:war.primary_attacker = { this = root }
				scope:war.primary_defender = { this = root }
				is_a_faction_member = yes
			}
		}

		ai_chance = {
			base = 0
		}
	}

	option = { # Leave and go home
		# Reuses name from 0300
		name = activity_system.0300.b
		custom_tooltip = activity_system.0310.b.tt
		current_travel_plan = { 
			if = {
				limit = { can_cancel = yes }
				cancel_travel_plan = yes
			}
		}

		ai_chance = {
			base = 100
		}
	}
}

# Activity Invalidated when host becomes unlanded
activity_system.0320 = {
	type = character_event 
	title = activity_system.0320.t
	desc = activity_system.0320.desc
	theme = realm

	left_portrait = {
		character = scope:host
		animation = grief
	}
	right_portrait = {
		character = scope:new_holder
		animation = personality_callous 
	}

	immediate = {
	}

	option = {
		name = activity_system.0320.a
	}
}

# Host has gained the incapable trait
activity_system.0330 = {
	type = character_event
	title = activity_system.0330.t 
	desc = {
		triggered_desc = {
			trigger = {
				exists = scope:incapable_memory
			}
			desc = activity_system.0330.desc.memory
		}
		desc = activity_system.0330.desc.intro 
		desc = activity_system.0330.desc.outro
	}
	theme = realm

	override_background = { reference = terrain } 

	left_portrait = {
		character = root 
		animation = personality_honorable
	}

	immediate = {
		capital_province = {
			save_scope_as = home
		}
		if = {
			limit = {
				any_memory = {
					has_memory_category = incapable 
				}
			}
			random_memory = {
				limit = {
					has_memory_category = incapable
				}
				save_scope_as = incapable_memory
			}
		}
	}

	option = {
		name = activity_system.0330.a 
		show_as_tooltip = {
			return_home = yes
		}
	}
}

activity_system.0331 = {
	type = character_event
	title = activity_system.0331.t 
	desc = activity_system.0331.desc 
	theme = realm 

	override_background = { reference = terrain } 

	left_portrait = {
		character = root 
		animation = personality_honorable
	}
	right_portrait = {
		character = scope:new_host 
		animation = personality_rational
	}

	immediate = {
		scope:activity.activity_host ?= { save_scope_as = host }
	}

	option = {
		name = activity_system.0331.a 
		show_as_tooltip = {
			return_home = yes
		}
	}
}

# You are late and won't probably make it to the activity
activity_system.0400 = {
	type = character_event
	title = activity_system.0400.t 
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:travel_leader }
				desc = activity_system.0400.desc_leader
			}
			desc = activity_system.0400.desc_no_leader
		}
	}
	theme = realm 

	override_background = { reference = terrain } 

	left_portrait = {
		character = root 
		animation = worry
	}
	right_portrait = {
		trigger = {
			exists = scope:travel_leader
		}
		character = scope:travel_leader
		animation = shame
	}

	trigger = {
		# Hosts and special guests get automatic delays
		involved_activity ?= {
			activity_host != root
			NOT = { any_special_guest = { this = root } }
		}
	}

	immediate = {
		scope:activity.activity_host ?= { save_scope_as = host }
		current_travel_plan.travel_leader ?= { save_scope_as = travel_leader }
	}

	#Push forward
	option = {
		name = activity_system.0400.a
		flavor = activity_system.0400.a.tt
	}

	#Go home
	option = {
		name = activity_system.0400.b 
		involved_activity ?= {
			root = { remove_from_activity = involved_activity }
		}
		return_home = yes
	}
}

# You are too late and the activity has started: go home
activity_system.0401 = {
	type = character_event
	title = activity_system.0401.t 
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = { exists = scope:travel_leader }
				desc = activity_system.0401.desc_leader
			}
			desc = activity_system.0401.desc_no_leader
		}
	}
	theme = realm 

	override_background = { reference = terrain } 

	left_portrait = {
		character = root 
		animation = disapproval
	}
	right_portrait = {
		trigger = {
			exists = scope:travel_leader
		}
		character = scope:travel_leader
		animation = shame
	}

	immediate = {
		scope:activity.activity_host ?= { save_scope_as = host }
		current_travel_plan.travel_leader ?= { save_scope_as = travel_leader }
	}

	option = {
		name = activity_system.0401.a
	}
}

# Generic - Invalidated Activity due to Host Death
activity_system.0500 = {
	type = character_event
	title = activity_system.0500.t
	desc = activity_system.0500.desc
	
	theme = realm

	override_background = { reference = terrain } 

	left_portrait = {
		character = root 
		animation = personality_honorable
	}
	right_portrait = {
		character = scope:host
		animation = dead
	}

	immediate = {
		scope:activity.activity_host ?= { save_scope_as = host }
	}

	option = { 
		name = activity_system.0500.a
		show_as_tooltip = {
			return_home = yes
		}
	}
}

# Imperial Examination - Invalidated Activity due to Death of Hegemon
activity_system.0501 = {
	type = character_event
	title = activity_system.0501.t
	desc = activity_system.0501.desc
	
	theme = imperial_examination

	left_portrait = {
		character = root 
		animation = personality_honorable
	}
	right_portrait = {
		character = scope:host
		animation = dead
	}

	immediate = {
		scope:activity.activity_host ?= { save_scope_as = host }
	}

	option = { 
		name = activity_system.0501.a
		show_as_tooltip = {
			return_home = yes
		}
	}
}

# Generic - Invalidated Activity due to Host Imprisonment
activity_system.0550 = {
	type = character_event
	title = activity_system.0550.t
	desc = activity_system.0550.desc
	
	theme = realm

	override_icon = {
		reference = "gfx/interface/icons/event_types/type_prison.dds"
	}

	left_portrait = {
		character = root 
		animation = prisonhouse
	}

	option = { 
		name = activity_system.0550.a
	}
}

activity_system.0551 = {
	type = character_event
	title = activity_system.0551.t
	desc = activity_system.0551.desc
	
	theme = realm

	override_background = { reference = terrain } 

	left_portrait = {
		character = scope:host
		animation = prisonhouse
	}

	override_icon = {
		reference = "gfx/interface/icons/event_types/type_prison.dds"
	}

	immediate = {
		scope:activity.activity_host ?= { save_scope_as = host }
	}

	option = { 
		name = activity_system.0551.a
		show_as_tooltip = {
			return_home = yes
		}
	}
}

# Debate - no other movement showed up
activity_system.0552 = {
	type = character_event
	title = activity_system.0552.t
	desc = activity_system.0552.desc

	theme = debate

	left_portrait = {
		character = root
		animation = shame
	}

	immediate = {
		# Save scopes about the activity so they can be passed on to the follow-up event if needed
		save_scope_as = target_activity_host
		involved_activity = { save_scope_as = target_activity }
		scope:target_activity.activity_location = { save_scope_as = target_activity_location }
	}

	option = {
		name = activity_system.0552.a
		hidden_effect = {
			scope:target_activity = {
				# Sends out a notifying event to all the attendees that the activity has been cancelled
				every_attending_character = {
					limit = { this != root }
					trigger_event = activity_system.0553
				}
			}
			# Cancel the activity and return home
			invalidate_activity = scope:target_activity 
		}
		ai_chance = {
			base = 100
		}
	}
}

activity_system.0553 = {
	type = character_event
	title = activity_system.0552.t
	desc = activity_system.0552.desc

	theme = debate

	left_portrait = {
		character = root
		animation = dismissal
	}
	right_portrait = {
		character = scope:target_activity_host
		animation = shame
	}

	option = {
		name = activity_system.0552.a

		ai_chance = {
			base = 100
		}
	}
}

# You are a movement leader challenged to a Debate!
activity_system.0554 = {
	type = letter_event
	opening = activity_system.0554.opening
	desc = invite_to_activity_flavor_movement_debate_honorary_guest
	sender = scope:host


	option = { # Let's go!
		name = activity_system.0554.a
		accept_activity_invite = scope:host.involved_activity
	}

	option = { # Nah
		name = activity_system.0554.b
		decline_activity_invite = scope:host.involved_activity
		change_influence = medium_influence_loss
	}
}