﻿festival_friendship = {
	icon = friend
	is_valid = {
		is_current_phase_active = yes
		any_attending_character = {
			num_of_relation_friend < 2
			is_physically_able_ai_adult = yes
			save_temporary_scope_as = friend_1
		}
		any_attending_character = {
			this != scope:friend_1
			num_of_relation_friend < 2
			is_physically_able_ai_adult = yes
			NOT = { has_relation_friend = scope:friend_1 }
		}
	}

	weight = 1

	effect = {
		random_attending_character = {
			limit = {
				num_of_relation_friend < 2
				is_physically_able_ai_adult = yes
				save_temporary_scope_as = friend_1
				scope:activity = {
					any_attending_character = {
						num_of_relation_friend < 2
						is_physically_able_ai_adult = yes
						this != scope:friend_1
						NOT = {
							has_relation_friend = scope:friend_1
						}
					}
				}
			}
			save_scope_as = first
		}
		random_attending_character = {
			limit = {
				num_of_relation_friend < 2
				is_physically_able_ai_adult = yes
				this != scope:first
				NOT = {
					has_relation_friend = scope:first
				}
			}
			weight = {
				base = 1
				modifier = {
					factor = 2
					trait_compatibility = {
						target = scope:first
						value >= low_positive_trait_compatibility
					}
				}
				modifier = {
					factor = 10
					trait_compatibility = {
						target = scope:first
						value >= medium_positive_trait_compatibility
					}
				}
			}
			save_scope_as = second
		}
		add_activity_log_entry = {
			key = festival_friendship
			tags = { good }
			score = 5
			character = scope:first
			target = scope:second
			# Effects
			scope:second = {
				set_relation_friend = {
					target = scope:first
					reason = friend_courtiers_bonded_on_festival
				}
			}
		}
	}
}

festival_romance = {
	icon = lover
	is_valid = {
		is_current_phase_active = yes
		any_attending_character = {
			might_cheat_on_every_partner_trigger = yes
			num_of_relation_lover < 2
			is_physically_able_ai_adult = yes
			save_temporary_scope_as = first_lover_temp
		}
		any_attending_character = {
			this != scope:first_lover_temp
			might_cheat_on_every_partner_trigger = yes
			NOT = { has_relation_lover = scope:first_lover_temp }
			num_of_relation_lover < 2
			is_physically_able_ai_adult = yes
			save_temporary_scope_as = second_lover_temp
			matching_gender_and_sexuality_trigger = {
				CHARACTER_1 = scope:second_lover_temp
				CHARACTER_2 = scope:first_lover_temp
			}
		}
	}

	weight = 1

	effect = {
		random_attending_character = {
			limit = {
				might_cheat_on_every_partner_trigger = yes
				num_of_relation_lover < 2
				is_physically_able_ai_adult = yes
				save_temporary_scope_as = first_lover_temp
				scope:activity = {
					any_attending_character = {
						this != scope:first_lover_temp
						might_cheat_on_every_partner_trigger = yes
						NOT = { has_relation_lover = scope:first_lover_temp }
						num_of_relation_lover < 2
						is_physically_able_ai_adult = yes
						save_temporary_scope_as = second_lover_temp
						matching_gender_and_sexuality_trigger = {
							CHARACTER_1 = scope:second_lover_temp
							CHARACTER_2 = scope:first_lover_temp
						}
					}
				}
			}
			save_scope_as = first
		}
		random_attending_character = {
			limit = {
				this != scope:first
				might_cheat_on_every_partner_trigger = yes
				NOT = { has_relation_lover = scope:first }
				num_of_relation_lover < 2
				is_physically_able_ai_adult = yes
				save_temporary_scope_as = second_lover_temp
				matching_gender_and_sexuality_trigger = {
					CHARACTER_1 = scope:second_lover_temp
					CHARACTER_2 = scope:first
				}
			}
			weight = {
				base = 1
				modifier = {
					factor = 2
					trait_compatibility = {
						target = scope:first
						value >= low_positive_trait_compatibility
					}
				}
				modifier = {
					factor = 10
					trait_compatibility = {
						target = scope:first
						value >= medium_positive_trait_compatibility
					}
				}
			}
			save_scope_as = second
		}
		add_activity_log_entry = {
			key = festival_romance
			tags = { good }
			score = 5
			character = scope:first
			target = scope:second
			# Effects
			scope:second = {
				set_relation_lover = {
					target = scope:first
					reason = lover_courtiers_bonded_on_festival
				}
			}
		}
	}
}

festival_rivalry = {
	icon = negative
	is_valid = {
		is_current_phase_active = yes
		any_attending_character = {
			num_of_relation_rival < 2
			is_physically_able_ai_adult = yes
			save_temporary_scope_as = first_rival
		}
		any_attending_character = {
			num_of_relation_rival < 2
			is_physically_able_ai_adult = yes
			NOT = { has_relation_rival = scope:first_rival }
		}
	}

	weight = 1

	effect = {
		random_attending_character = {
			limit = {
				num_of_relation_rival < 2
				is_physically_able_ai_adult = yes
				save_temporary_scope_as = first_rival
				scope:activity = {
					any_attending_character = {
						num_of_relation_rival < 2
						is_physically_able_ai_adult = yes
						NOT = { has_relation_rival = scope:first_rival }
					}
				}
			}
			save_scope_as = first
		}
		random_attending_character = {
			limit = {
				num_of_relation_rival < 2
				is_physically_able_ai_adult = yes
				NOT = {
					has_relation_rival = scope:first
				}
			}
			weight = {
				base = 1
				modifier = {
					factor = 2
					trait_compatibility = {
						target = scope:first
						value <= low_negative_trait_compatibility
					}
				}
				modifier = {
					factor = 10
					trait_compatibility = {
						target = scope:first
						value <= medium_negative_trait_compatibility
					}
				}
			}
			save_scope_as = second
		}
		add_activity_log_entry = {
			key = festival_rivalry
			tags = { bad }
			score = -5
			character = scope:first
			target = scope:second
			# Effects
			scope:second = {
				set_relation_rival = {
					target = scope:first
					reason = rival_courtiers_friction_on_festival
				}
			}
		}
	}
}

beautiful_festival = {
	icon = public
	is_valid = {
		is_current_phase_active = yes
		any_attending_character = {
			has_activity_intent = reduce_stress_intent
		}
	}

	weight = {
		value = 1
	}

	effect = {			
		random_attending_character = {
			limit = {
				has_activity_intent = reduce_stress_intent
			}
			save_scope_as = first
		}
		
		add_activity_log_entry = {
			key = beautiful_festival
			tags = { pulse_action }
			character = scope:first
			
			scope:first = {
				add_stress = minor_stress_loss
			}
		}
	}
}

festival_learning = {
	icon = learning
	is_valid = {
		is_current_phase_active = yes
		any_attending_character = {
			count > 2
		}
	}

	weight = {
		value = 1
		if = {
			limit = {
				has_variable = festival_learning
			}
			multiply = 0.1
		}
	}

	effect = {
		set_variable = {
			name = festival_learning
			value = yes
		}

		random_attending_character = {
			save_scope_as = first
		}
		random_attending_character = {
			limit = {
				this != scope:first
			}
			save_scope_as = second
		}

		add_activity_log_entry = {
			key = festival_learning
			tags = { pulse_action }
			character = scope:first
			target = scope:second

			scope:first = {
				add_stress = miniscule_stress_loss
				bp2_lifestyle_xp_gain_per_type_effect = { VALUE = minor }
			}

			scope:second = {
				bp2_lifestyle_xp_gain_per_type_effect = { VALUE = medium }
			}
		}
	}
}

liege_festival_presence = {
	icon = positive
	is_valid = {
		is_current_phase_active = yes
		NOT = { 
			scope:host.location.county = {
				has_county_modifier = ep2_popular_liege
			} 
		}
		scope:host.location = {
			has_holding = yes
		}
	}

	weight = 2

	effect = {
		scope:host = {
			save_scope_as = first
		}
		scope:host.location.county = {
			save_scope_as = second
		}
		scope:activity = {
			add_activity_log_entry = {
				key = liege_festival_presence
				tags = { good }
				score = 5
				character = scope:first
				
				scope:host.location.county = {
					add_county_modifier = {
						modifier = ep2_popular_liege
						years = 10
					}
				}
			}
		}
	}
}

festival_cohesion = {
	icon = positive
	is_valid = {
		is_current_phase_active = yes
		any_attending_character = {
			has_activity_intent = raise_cohesion_intent
			save_temporary_scope_as = first_house
		}
		any_attending_character = {
			has_activity_intent = raise_cohesion_intent
			this != scope:first_house
			house = scope:first_house.house
		}
	}

	weight = {
		value = 1
		if = {
			limit = {
				has_variable = festival_cohesion
			}
			multiply = 0.1
		}
	}

	effect = {
		set_variable = {
			name = festival_cohesion
			value = yes
		}
		random_attending_character = {
			limit = {
				has_activity_intent = raise_cohesion_intent
			}
			save_scope_as = first
		}
		random_attending_character = {
			limit = {
				has_activity_intent = raise_cohesion_intent
				this != scope:first
				house = scope:first.house
			}
			save_scope_as = second
		}
		scope:activity = {
			add_activity_log_entry = {
				key = festival_cohesion
				tags = { good }
				score = 5
				character = scope:first
				target = scope:second
				
				scope:first.house.house_confederation = {
					change_cohesion = cohesion_gain_minor
				}
			}
		}
	}
}

festival_join_bloc = {
	icon = positive
	is_valid = {
		is_current_phase_active = yes
		any_attending_character = {
			has_activity_intent = add_to_bloc_intent
			is_confederation_member = yes
		}
		any_attending_character = {
			is_confederation_member = no
		}
	}

	weight = {
		value = 1
		if = {
			limit = {
				has_variable = festival_join_bloc
			}
			multiply = 0.1
		}
	}

	effect = {
		set_variable = {
			name = festival_join_bloc
			value = yes
		}
		random_attending_character = {
			limit = {
				has_activity_intent = add_to_bloc_intent
				is_confederation_member = yes
			}
			save_scope_as = first
			# for loc
			house.house_confederation = {
				save_scope_as = bloc
			}
		}
		random_attending_character = {
			limit = {
				is_confederation_member = no
			}
			save_scope_as = second
		}
		scope:activity = {
			add_activity_log_entry = {
				key = festival_join_bloc
				tags = { good }
				score = 5
				character = scope:first
				target = scope:second
				scope:second.house = {
					tgp_join_house_bloc_effect = {
						INVITER = scope:first.house
						OPINION = flag:yes
					}
				}	
			}
		}
	}
}

festival_remove_from_bloc = {
	icon = positive
	is_valid = {
		is_current_phase_active = yes
		any_attending_character = {
			has_activity_intent = remove_from_bloc_intent
		}
		any_attending_character = {
			is_confederation_member = yes
		}
	}

	weight = {
		value = 1
		if = {
			limit = {
				has_variable = festival_remove_from_bloc
			}
			multiply = 0.1
		}
	}

	effect = {
		set_variable = {
			name = festival_remove_from_bloc
			value = yes
		}
		random_attending_character = {
			limit = {
				has_activity_intent = remove_from_bloc_intent
			}
			save_scope_as = first
		}
		random_attending_character = {
			limit = {
				is_confederation_member = yes
			}
			save_scope_as = second
			# for loc
			house.house_confederation ?= {
				save_scope_as = bloc
			}
		}
		scope:activity = {
			add_activity_log_entry = {
				key = festival_remove_from_bloc
				tags = { bad }
				score = 5
				character = scope:first
				target = scope:second
				scope:second.house.house_confederation = { #Unop: Fix missing house scope before house_confederation 
					remove_confederation_member = scope:second
				}	
			}
		}
	}
}

festival_influence = {
	icon = public

	is_valid = {
		is_current_phase_active = yes
		any_attending_character = {
			government_has_flag = government_has_influence
		}
	}

	weight = {
		value = 1
	}

	effect = {
		random_attending_character = {
			limit = { government_has_flag = government_has_influence }
			save_scope_as = first
		}
		add_activity_log_entry = {
			key = festival_influence
			tags = { pulse_action }
			character = scope:first

			scope:first = {
				change_influence = miniscule_influence_gain
			}
		}
	}
}

liege_festival_prosperity = {
	icon = positive
	is_valid = {
		is_current_phase_active = yes
		NOT = { 
			scope:host.location.county = {
				has_county_modifier = tgp_festival_prosperity
			} 
		}
		scope:host.location = {
			has_holding = yes
		}
	}

	weight = 2

	effect = {
		scope:host = {
			save_scope_as = first
		}
		scope:host.location.county = {
			save_scope_as = second
		}
		scope:activity = {
			add_activity_log_entry = {
				key = liege_festival_prosperity
				tags = { good }
				score = 5
				character = scope:first
				
				scope:host.location.county = {
					add_county_modifier = {
						modifier = tgp_festival_prosperity
						years = 10
					}
				}
			}
		}
	}
}

festival_prayer = {
	icon = positive
	is_valid = {
		is_current_phase_active = yes
		any_attending_character = {
			has_activity_intent = reduce_stress_intent
			NOT = {
				has_trait = cynical
			}
		}
	}

	weight = {
		value = 1
	}

	effect = {			
		random_attending_character = {
			limit = {
				has_activity_intent = reduce_stress_intent
				NOT = {
					has_trait = cynical
				}
			}
			save_scope_as = first
		}
		
		add_activity_log_entry = {
			key = festival_prayer
			tags = { pulse_action }
			character = scope:first
			
			scope:first = {
				add_stress = minor_stress_loss
				add_piety = minor_piety_gain
			}
		}
	}
}

festival_flowers = {
	icon = positive
	is_valid = {
		is_current_phase_active = yes
		any_attending_character = {
			has_activity_intent = reduce_stress_intent
		}
	}

	weight = {
		value = 1
	}

	effect = {			
		random_attending_character = {
			limit = {
				has_activity_intent = reduce_stress_intent
			}
			save_scope_as = first
		}
		
		add_activity_log_entry = {
			key = festival_flowers
			tags = { pulse_action }
			character = scope:first
			
			scope:first = {
				add_stress = minor_stress_loss
			}
		}
	}
}

festival_house_relation_increase = {
	icon = positive
	is_valid = {
		is_current_phase_active = yes
		any_attending_character = {
			save_temporary_scope_as = first_house
		}
		any_attending_character = {
			opinion = {
				target = scope:first_house
				value > 0
			}
			house != scope:first_house.house
		}
	}

	weight = {
		value = 1
		if = {
			limit = {
				has_variable = festival_house_relation_increase
			}
			multiply = 0.1
		}
	}

	effect = {
		set_variable = {
			name = festival_house_relation_increase
			value = yes
		}
		random_attending_character = {
			save_scope_as = first
		}
		random_attending_character = {
			limit = {
				opinion = {
					target = scope:first
					value > 0
				}
				this != scope:first
				house != scope:first.house
			}
			save_scope_as = second
		}
		scope:activity = {
			add_activity_log_entry = {
				key = festival_house_relation_increase
				tags = { good }
				score = 5
				character = scope:first
				target = scope:second
				
				scope:first = {
					house = {
			            change_house_relation_effect = {
			                HOUSE = scope:second.house
			                VALUE = house_relation_improve_minor_value
			                REASON = festival_increase
			                CHAR = scope:first
			                TARGET_CHAR = scope:second
			                TITLE = scope:dummy_gender
			            }
			        }
				}
			}
		}
	}
}