﻿namespace = sc_council_events

# ============================================================
# EVENT 0001: COUNCIL OPENING
# ============================================================
sc_council_events.0001 = {
	type = activity_event
	title = sc_council_events.0001.t
	desc = sc_council_events.0001.desc
	theme = diplomacy
	window = big_event_window
	override_background = ep3_relaxing_room

	trigger = {
		NOT = { has_character_flag = council_interacted_recently }
		NOT = { this = scope:activity.activity_host }
		NOT = { this = scope:activity.special_guest:the_pretender }
	}

	immediate = {
		involved_activity = {
			activity_host = { save_scope_as = current_ruler }
			if = {
				limit = { exists = special_guest:the_pretender }
				special_guest:the_pretender = { save_scope_as = claimant }
			}
			else = {
				activity_host = { save_scope_as = claimant }
			}
		}
	}

	left_portrait = {
		character = scope:current_ruler
		animation = disapproval
		camera = camera_body_right
	}

	right_portrait = {
		character = scope:claimant
		animation = dismissal
		camera = camera_body_left
	}

	option = {
		name = sc_council_events.0001.a
		sc_council_interaction_effect_reg = yes
	}
}

# ============================================================
# EVENT 0002: Whispers in the Corridor
# ============================================================
sc_council_events.0002 = {
	type = activity_event
	title = sc_council_events.0002.t
	desc = sc_council_events.0002.desc
	theme = diplomacy
	window = event_window
	override_background = ep3_relaxing_room

	trigger = {
		NOT = { has_character_flag = council_interacted_recently }
		NOT = { this = involved_activity.activity_host }
		NOT = { this = involved_activity.special_guest:the_pretender }
		involved_activity = {
			any_attending_character = {
				NOT = { this = root }
				NOT = { this = involved_activity.activity_host }
				NOT = { this = involved_activity.special_guest:the_pretender }
				OR = {
					AND = {
						is_lowborn = yes
						root = { is_lowborn = yes }
					}
					AND = {
						is_lowborn = no
						root = { is_lowborn = no }
					}
				}
			}
		}
	}

	immediate = {
		involved_activity = {
			random_attending_character = {
				limit = {
					NOT = { this = root }
					NOT = { this = involved_activity.activity_host }
					NOT = { this = involved_activity.special_guest:the_pretender }
					OR = {
						AND = {
							is_lowborn = yes
							root = { is_lowborn = yes }
						}
						AND = {
							is_lowborn = no
							root = { is_lowborn = no }
						}
					}
				}
				save_scope_as = recipient
			}
		}
	}

	left_portrait = {
		character = root
		animation = scheme
	}

	right_portrait = {
		character = scope:recipient
		animation = interested
	}

	option = {
		name = sc_council_events.0002.a
		sc_council_interaction_effect_reg = yes
		ai_chance = { base = 50 modifier = { factor = 2.0 has_trait = gregarious } }
		add_opinion = { target = scope:recipient modifier = friendly_opinion }
		scope:recipient = {
			if = {
				limit = { is_ai = yes }
				add_opinion = { target = root modifier = friendly_opinion }
			}
			else = {
				root = { save_scope_as = actor }
				trigger_event = sc_council_player_events.0002
			}
		}
	}

	option = {
		name = sc_council_events.0002.b
		sc_council_interaction_effect_reg = yes
		ai_chance = { base = 50 modifier = { factor = 2.0 has_trait = cynical } }
		add_prestige = minor_prestige_value
	}
}

# ============================================================
# EVENT 0003: The Spilled Goblet
# ============================================================
sc_council_events.0003 = {
	type = activity_event
	title = sc_council_events.0003.t
	desc = sc_council_events.0003.desc
	theme = diplomacy
	window = event_window
	override_background = ep3_relaxing_room

	trigger = {
		NOT = { has_character_flag = council_interacted_recently }
		NOT = { this = involved_activity.activity_host }
		NOT = { this = involved_activity.special_guest:the_pretender }
		involved_activity = {
			any_attending_character = {
				NOT = { this = root }
				NOT = { this = involved_activity.activity_host }
				NOT = { this = involved_activity.special_guest:the_pretender }
				OR = {
					AND = {
						is_lowborn = yes
						root = { is_lowborn = yes }
					}
					AND = {
						is_lowborn = no
						root = { is_lowborn = no }
					}
				}
			}
		}
	}

	immediate = {
		involved_activity = {
			random_attending_character = {
				limit = {
					NOT = { this = root }
					NOT = { this = involved_activity.activity_host }
					NOT = { this = involved_activity.special_guest:the_pretender }
					OR = {
						AND = {
							is_lowborn = yes
							root = { is_lowborn = yes }
						}
						AND = {
							is_lowborn = no
							root = { is_lowborn = no }
						}
					}
				}
				save_scope_as = recipient
			}
		}
	}

	left_portrait = {
		character = root
		animation = toast_goblet
	}

	right_portrait = {
		character = scope:recipient
		animation = shock
	}

	option = {
		name = sc_council_events.0003.a
		sc_council_interaction_effect_reg = yes
		ai_chance = { base = 50 modifier = { factor = 2.0 has_trait = compassionate } }
		add_stress = minor_stress_loss
		scope:recipient = {
			if = {
				limit = { is_ai = yes }
				add_opinion = { target = root modifier = forgiving_opinion }
			}
			else = {
				root = { save_scope_as = actor }
				trigger_event = sc_council_player_events.0003
			}
		}
	}

	option = {
		name = sc_council_events.0003.b
		sc_council_interaction_effect_reg = yes
		ai_chance = { base = 50 modifier = { factor = 2.0 has_trait = calm } }
		add_prestige = minor_prestige_value
		add_opinion = { target = scope:recipient modifier = impressed_opinion }
		scope:recipient = {
			if = {
				limit = { is_ai = yes }
				add_opinion = { target = root modifier = impressed_opinion }
			}
			else = {
				root = { save_scope_as = actor }
				trigger_event = sc_council_player_events.0003
			}
		}
	}
}

# ============================================================
# EVENT 0004: The Historical Precedent
# ============================================================
sc_council_events.0004 = {
	type = activity_event
	title = sc_council_events.0004.t
	desc = sc_council_events.0004.desc
	theme = diplomacy
	window = event_window
	override_background = ep3_relaxing_room

	trigger = {
		NOT = { has_character_flag = council_interacted_recently }
		NOT = { this = involved_activity.activity_host }
		NOT = { this = involved_activity.special_guest:the_pretender }
		learning >= 10
		involved_activity = {
			any_attending_character = {
				NOT = { this = root }
				NOT = { this = involved_activity.activity_host }
				NOT = { this = involved_activity.special_guest:the_pretender }
				OR = {
					AND = {
						is_lowborn = yes
						root = { is_lowborn = yes }
					}
					AND = {
						is_lowborn = no
						root = { is_lowborn = no }
					}
				}
			}
		}
	}

	immediate = {
		involved_activity = {
			random_attending_character = {
				limit = {
					NOT = { this = root }
					NOT = { this = involved_activity.activity_host }
					NOT = { this = involved_activity.special_guest:the_pretender }
					OR = {
						AND = {
							is_lowborn = yes
							root = { is_lowborn = yes }
						}
						AND = {
							is_lowborn = no
							root = { is_lowborn = no }
						}
					}
				}
				save_scope_as = recipient
			}
		}
	}

	left_portrait = {
		character = root
		animation = storyteller
	}

	right_portrait = {
		character = scope:recipient
		animation = boredom
	}

	option = {
		name = sc_council_events.0004.a
		sc_council_interaction_effect_reg = yes
		ai_chance = { base = 70 modifier = { factor = 2.0 has_trait = content } }
		add_learning_lifestyle_xp = minor_lifestyle_xp
		scope:recipient = {
			if = {
				limit = { is_ai = yes }
				add_opinion = { target = root modifier = impressed_opinion }
			}
			else = {
				root = { save_scope_as = actor }
				trigger_event = sc_council_player_events.0004
			}
		}
	}

	option = {
		name = sc_council_events.0004.b
		sc_council_interaction_effect_reg = yes
		ai_chance = { base = 30 modifier = { factor = 2.0 has_trait = impatient } }
		scope:recipient = {
			if = {
				limit = { is_ai = yes }
				add_opinion = { target = root modifier = annoyed_opinion }
			}
			else = {
				root = { save_scope_as = actor }
				trigger_event = sc_council_player_events.0004
			}
		}
	}
}

# ============================================================
# EVENT 0005: The Weight of Coin
# ============================================================
sc_council_events.0005 = {
	type = activity_event
	title = sc_council_events.0005.t
	desc = sc_council_events.0005.desc
	theme = diplomacy
	window = event_window
	override_background = ep3_relaxing_room

	trigger = {
		NOT = { has_character_flag = council_interacted_recently }
		NOT = { this = involved_activity.activity_host }
		NOT = { this = involved_activity.special_guest:the_pretender }
		gold >= 50
		involved_activity = {
			any_attending_character = {
				NOT = { this = root }
				NOT = { this = involved_activity.activity_host }
				NOT = { this = involved_activity.special_guest:the_pretender }
				OR = {
					AND = {
						is_lowborn = yes
						root = { is_lowborn = yes }
					}
					AND = {
						is_lowborn = no
						root = { is_lowborn = no }
					}
				}
			}
		}
	}

	immediate = {
		involved_activity = {
			random_attending_character = {
				limit = {
					NOT = { this = root }
					NOT = { this = involved_activity.activity_host }
					NOT = { this = involved_activity.special_guest:the_pretender }
					OR = {
						AND = {
							is_lowborn = yes
							root = { is_lowborn = yes }
						}
						AND = {
							is_lowborn = no
							root = { is_lowborn = no }
						}
					}
				}
				save_scope_as = recipient
			}
		}
	}

	left_portrait = {
		character = root
		animation = scheme
	}

	right_portrait = {
		character = scope:recipient
		animation = paranoia
	}

	option = {
		name = sc_council_events.0005.a
		sc_council_interaction_effect_reg = yes
		ai_chance = { base = 60 modifier = { factor = 2.0 has_trait = greedy } }
		remove_short_term_gold = minor_gold_value
		scope:recipient = {
			if = {
				limit = { is_ai = yes }
				add_gold = minor_gold_value
				add_opinion = { target = root modifier = grateful_opinion }
			}
			else = {
				root = { save_scope_as = actor }
				trigger_event = sc_council_player_events.0005
			}
		}
	}

	option = {
		name = sc_council_events.0005.b
		sc_council_interaction_effect_reg = yes
		ai_chance = { base = 40 modifier = { factor = 2.0 has_trait = honest } }
		add_opinion = { target = scope:recipient modifier = furious_opinion }
		scope:recipient = {
			if = {
				limit = { is_ai = yes }
				add_opinion = { target = root modifier = furious_opinion }
			}
			else = {
				root = { save_scope_as = actor }
				trigger_event = sc_council_player_events.0005
			}
		}
	}
}

# ============================================================
# EVENT 0006: Shadows of War
# ============================================================
sc_council_events.0006 = {
	type = activity_event
	title = sc_council_events.0006.t
	desc = sc_council_events.0006.desc
	theme = diplomacy
	window = event_window
	override_background = ep3_relaxing_room

	trigger = {
		NOT = { has_character_flag = council_interacted_recently }
		NOT = { this = involved_activity.activity_host }
		NOT = { this = involved_activity.special_guest:the_pretender }
		involved_activity = {
			any_attending_character = {
				NOT = { this = root }
				NOT = { this = involved_activity.activity_host }
				NOT = { this = involved_activity.special_guest:the_pretender }
				OR = {
					AND = {
						is_lowborn = yes
						root = { is_lowborn = yes }
					}
					AND = {
						is_lowborn = no
						root = { is_lowborn = no }
					}
				}
			}
		}
	}

	immediate = {
		involved_activity = {
			random_attending_character = {
				limit = {
					NOT = { this = root }
					NOT = { this = involved_activity.activity_host }
					NOT = { this = involved_activity.special_guest:the_pretender }
					OR = {
						AND = {
							is_lowborn = yes
							root = { is_lowborn = yes }
						}
						AND = {
							is_lowborn = no
							root = { is_lowborn = no }
						}
					}
				}
				save_scope_as = recipient
			}
		}
	}

	left_portrait = {
		character = root
		animation = sadness
	}

	right_portrait = {
		character = scope:recipient
		animation = idle
	}

	option = {
		name = sc_council_events.0006.a
		sc_council_interaction_effect_reg = yes
		ai_chance = { base = 70 modifier = { factor = 2.0 has_trait = trusting } }
		add_stress = minor_stress_loss
		add_opinion = { target = scope:recipient modifier = trusted_opinion }
		scope:recipient = {
			if = {
				limit = { is_ai = yes }
				add_stress = minor_stress_loss
				add_opinion = { target = root modifier = trusted_opinion }
			}
			else = {
				root = { save_scope_as = actor }
				trigger_event = sc_council_player_events.0006
			}
		}
	}

	option = {
		name = sc_council_events.0006.b
		sc_council_interaction_effect_reg = yes
		ai_chance = { base = 30 modifier = { factor = 2.0 has_trait = paranoid } }
		add_stress = minor_stress_gain
	}
}

# ============================================================
# EVENT 0007: Unexpected Alliances
# ============================================================
sc_council_events.0007 = {
	type = activity_event
	title = sc_council_events.0007.t
	desc = sc_council_events.0007.desc
	theme = diplomacy
	window = event_window
	override_background = ep3_relaxing_room

	trigger = {
		NOT = { has_character_flag = council_interacted_recently }
		NOT = { this = involved_activity.activity_host }
		NOT = { this = involved_activity.special_guest:the_pretender }
		involved_activity = {
			any_attending_character = {
				NOT = { this = root }
				NOT = { this = involved_activity.activity_host }
				NOT = { this = involved_activity.special_guest:the_pretender }
				OR = {
					AND = {
						is_lowborn = yes
						root = { is_lowborn = yes }
					}
					AND = {
						is_lowborn = no
						root = { is_lowborn = no }
					}
				}
			}
		}
	}

	immediate = {
		involved_activity = {
			random_attending_character = {
				limit = {
					NOT = { this = root }
					NOT = { this = involved_activity.activity_host }
					NOT = { this = involved_activity.special_guest:the_pretender }
					OR = {
						AND = {
							is_lowborn = yes
							root = { is_lowborn = yes }
						}
						AND = {
							is_lowborn = no
							root = { is_lowborn = no }
						}
					}
				}
				save_scope_as = recipient
			}
		}
	}

	left_portrait = {
		character = root
		animation = personality_honorable
	}

	right_portrait = {
		character = scope:recipient
		animation = interested
	}

	option = {
		name = sc_council_events.0007.a
		sc_council_interaction_effect_reg = yes
		ai_chance = { base = 60 modifier = { factor = 2.0 has_trait = just } }
		add_opinion = { target = scope:recipient modifier = friendly_opinion }
		scope:recipient = {
			if = {
				limit = { is_ai = yes }
				add_opinion = { target = root modifier = friendly_opinion }
			}
			else = {
				root = { save_scope_as = actor }
				trigger_event = sc_council_player_events.0007
			}
		}
	}

	option = {
		name = sc_council_events.0007.b
		sc_council_interaction_effect_reg = yes
		ai_chance = { base = 40 modifier = { factor = 2.0 has_trait = ambitious } }
		add_dread = minor_dread_gain
	}
}

# ============================================================
# EVENT 0008: A Shared Meal
# ============================================================
sc_council_events.0008 = {
	type = activity_event
	title = sc_council_events.0008.t
	desc = sc_council_events.0008.desc
	theme = diplomacy
	window = event_window
	override_background = ep3_relaxing_room

	trigger = {
		NOT = { has_character_flag = council_interacted_recently }
		NOT = { this = involved_activity.activity_host }
		NOT = { this = involved_activity.special_guest:the_pretender }
		involved_activity = {
			any_attending_character = {
				NOT = { this = root }
				NOT = { this = involved_activity.activity_host }
				NOT = { this = involved_activity.special_guest:the_pretender }
				OR = {
					AND = {
						is_lowborn = yes
						root = { is_lowborn = yes }
					}
					AND = {
						is_lowborn = no
						root = { is_lowborn = no }
					}
				}
			}
		}
	}

	immediate = {
		involved_activity = {
			random_attending_character = {
				limit = {
					NOT = { this = root }
					NOT = { this = involved_activity.activity_host }
					NOT = { this = involved_activity.special_guest:the_pretender }
					OR = {
						AND = {
							is_lowborn = yes
							root = { is_lowborn = yes }
						}
						AND = {
							is_lowborn = no
							root = { is_lowborn = no }
						}
					}
				}
				save_scope_as = recipient
			}
		}
	}

	left_portrait = {
		character = root
		animation = throne_room_conversation_1
	}

	right_portrait = {
		character = scope:recipient
		animation = throne_room_conversation_2
	}

	option = {
		name = sc_council_events.0008.a
		sc_council_interaction_effect_reg = yes
		ai_chance = { base = 70 modifier = { factor = 2.0 has_trait = gregarious } }
		add_stress = minor_stress_loss
		add_opinion = { target = scope:recipient modifier = friendly_opinion }
		scope:recipient = {
			if = {
				limit = { is_ai = no }
				root = { save_scope_as = actor }
				trigger_event = sc_council_player_events.0008
			}
		}
	}

	option = {
		name = sc_council_events.0008.b
		sc_council_interaction_effect_reg = yes
		ai_chance = { base = 30 modifier = { factor = 2.0 has_trait = shy } }
		add_stress = minor_stress_gain
	}
}

# ============================================================
# EVENT 0009: A Tense Encounter
# ============================================================
sc_council_events.0009 = {
	type = activity_event
	title = sc_council_events.0009.t
	desc = sc_council_events.0009.desc
	theme = diplomacy
	window = event_window
	override_background = ep3_relaxing_room

	trigger = {
		NOT = { has_character_flag = council_interacted_recently }
		NOT = { this = involved_activity.activity_host }
		NOT = { this = involved_activity.special_guest:the_pretender }
		involved_activity = {
			any_attending_character = {
				NOT = { this = root }
				NOT = { this = involved_activity.activity_host }
				NOT = { this = involved_activity.special_guest:the_pretender }
				OR = {
					AND = {
						is_lowborn = yes
						root = { is_lowborn = yes }
					}
					AND = {
						is_lowborn = no
						root = { is_lowborn = no }
					}
				}
			}
		}
	}

	immediate = {
		involved_activity = {
			random_attending_character = {
				limit = {
					NOT = { this = root }
					NOT = { this = involved_activity.activity_host }
					NOT = { this = involved_activity.special_guest:the_pretender }
					OR = {
						AND = {
							is_lowborn = yes
							root = { is_lowborn = yes }
						}
						AND = {
							is_lowborn = no
							root = { is_lowborn = no }
						}
					}
				}
				save_scope_as = recipient
			}
		}
	}

	left_portrait = {
		character = root
		animation = anger
	}

	right_portrait = {
		character = scope:recipient
		animation = personality_bold
	}

	option = {
		name = sc_council_events.0009.a
		sc_council_interaction_effect_reg = yes
		ai_chance = { base = 60 modifier = { factor = 2.0 has_trait = wrathful } }
		add_dread = minor_dread_gain
		add_opinion = { target = scope:recipient modifier = intimidated_opinion }
		scope:recipient = {
			if = {
				limit = { is_ai = no }
				root = { save_scope_as = actor }
				trigger_event = sc_council_player_events.0009
			}
		}
	}

	option = {
		name = sc_council_events.0009.b
		sc_council_interaction_effect_reg = yes
		ai_chance = { base = 40 modifier = { factor = 2.0 has_trait = brave } }
		add_opinion = { target = scope:recipient modifier = furious_opinion }
		scope:recipient = {
			if = {
				limit = { is_ai = yes }
				add_opinion = { target = root modifier = furious_opinion }
			}
			else = {
				root = { save_scope_as = actor }
				trigger_event = sc_council_player_events.0009
			}
		}
	}
}

# ============================================================
# EVENT 0010: A Moment of Reflection
# ============================================================
sc_council_events.0010 = {
	type = activity_event
	title = sc_council_events.0010.t
	desc = sc_council_events.0010.desc
	theme = diplomacy
	window = event_window
	override_background = ep3_relaxing_room

	trigger = {
		NOT = { has_character_flag = council_interacted_recently }
		NOT = { this = involved_activity.activity_host }
		NOT = { this = involved_activity.special_guest:the_pretender }
	}

	left_portrait = {
		character = root
		animation = thinking
	}

	option = {
		name = sc_council_events.0010.a
		sc_council_interaction_effect_reg = yes
		ai_chance = { base = 50 modifier = { factor = 2.0 has_trait = patient } }
		add_stress = minor_stress_loss
		add_piety = 50
	}

	option = {
		name = sc_council_events.0010.b
		sc_council_interaction_effect_reg = yes
		ai_chance = { base = 50 modifier = { factor = 2.0 has_trait = ambitious } }
		add_prestige = minor_prestige_value
	}
}

# ============================================================
# EVENT 0011: Council Resolution
# ============================================================
sc_council_events.0011 = {
	type = activity_event
	title = sc_council_events.0011.t
	theme = diplomacy
	window = event_window
	override_background = ep3_relaxing_room

	trigger = {
		NOT = { has_character_flag = council_interacted_recently }
		NOT = { this = involved_activity.activity_host }
		NOT = { this = involved_activity.special_guest:the_pretender }
	}

	immediate = {
		if = {
			limit = { NOT = { exists = scope:crisis_title } }
			involved_activity = {
				activity_host = {
					var:crisis_title = {
						save_scope_as = crisis_title
					}
				}
			}
		}

		# Identify current holder of the crisis title
		scope:crisis_title = {
			holder = {
				save_scope_as = title_holder
			}
		}
	}

	desc = {
		first_valid = {
			triggered_desc = { 
				trigger = {
					scope:title_holder = { has_character_flag = crisis_heir_flag }
				}
				desc = sc_council_events.0011.desc.heir
			}
			desc = sc_council_events.0011.desc.claimant
		}
	}

	center_portrait = {
		character = scope:title_holder
		animation = personality_bold
	}

	option = {
		name = sc_council_events.0011.a
		sc_council_interaction_effect_reg = yes
		ai_chance = { base = 100 }
		add_stress = minor_stress_loss
		add_piety = 50
	}
}
# ============================================================
# EVENT 0012: Imminent War
# ============================================================
sc_council_events.0012 = {
	type = activity_event
	title = sc_council_events.0012.t
	desc = sc_council_events.0012.desc
	theme = war
	override_background = ep3_relaxing_room

	immediate = {
		involved_activity = {
			activity_host = {
				save_scope_as = host
			}
			special_guest:the_pretender = {
				save_scope_as = pretender
			}
		}

		if = {
			limit = {
				scope:host = {
					has_character_flag = imminent_war
				}
			}
			scope:host = {
				save_scope_as = attacker
			}
			scope:pretender = {
				save_scope_as = defender
			}
		}
		else = {
			scope:pretender = {
				save_scope_as = attacker
			}
			scope:host = {
				save_scope_as = defender
			}
		}
	}

	left_portrait = {
		character = scope:attacker
		animation = anger
	}

	right_portrait = {
		character = scope:defender
		animation = fear
	}

	option = {
		name = sc_council_events.0012.a
	}
}

# ============================================================
# EVENT 0014: Council Concluded - Peace Maintained
# ============================================================
sc_council_events.0014 = {
	type = activity_event
	title = sc_council_events.0014.t
	desc = sc_council_events.0014.desc
	theme = diplomacy
	window = event_window
	override_background = ep3_relaxing_room

	immediate = {
		involved_activity = {
			activity_host = {
				save_scope_as = host
			}
			special_guest:the_pretender = {
				save_scope_as = pretender
			}
		}

		# Check for the crisis_title variable on the host if the scope does not exist
		if = {
			limit = { NOT = { exists = scope:crisis_title } }
			scope:host = {
				if = {
					limit = { exists = var:crisis_title }
					var:crisis_title = { save_scope_as = crisis_title }
				}
				else = {
					primary_title = { save_scope_as = crisis_title }
				}
			}
		}

		# Determine the winner
		scope:crisis_title = {
			if = {
				limit = { holder = scope:host }
				scope:host = { save_scope_as = winner }
			}
			else = {
				scope:pretender = { save_scope_as = winner }
			}
		}

		# Clean up flags for all attendees
		scope:activity = {
			every_attending_character = {
				remove_character_flag = pledged_to_heir
				remove_character_flag = pledged_to_claimant
				remove_character_flag = active_crisis_rebel_flag
				remove_character_flag = crisis_heir_flag
			}
		}
	}

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

	right_portrait = {
		character = scope:pretender
		animation = drink
	}

	option = {
		name = sc_council_events.0014.a
	}
}