﻿# Pilgrims and Preachers - pulse actions for the Camp Retreat activity (ppr_activity_camp_retreat)
# Modelled on vanilla apa_prayer (pilgrimage_actions.txt) and apa_camp_party_lecture (camp_party_actions.txt).
# Root = the activity; scope:host = host; scope:province = retreat location.
# Guests are always AI followers (see can_be_activity_guest).
#
# ppr_apa_retreat_choir_prayer   - Prayer in the Choir (piety; weighted up for Pilgrims)
# ppr_apa_retreat_scriptorium    - Copying in the Scriptorium (learning; weighted up for Scholars)
# ppr_apa_retreat_vespers_debate - Debate after Vespers (opinion between two attendees)
# ppr_apa_retreat_cloister_garden - Labour in the Cloister Garden (stress loss)

ppr_apa_retreat_choir_prayer = {
	icon = positive

	is_valid = {
		has_activity_type = ppr_activity_camp_retreat
		is_current_phase_active = yes
		has_current_phase = ppr_camp_retreat_phase_retreat
		any_attending_character = {
			location = scope:province
			is_adult = yes
		}
	}

	weight = {
		value = 1
		if = {
			limit = { ppr_camp_retreat_pilgrims_trigger = yes }
			multiply = 3
		}
	}

	effect = {
		random_attending_character = {
			limit = {
				location = scope:province
				is_adult = yes
			}
			weight = {
				base = 1
				modifier = {
					add = 2
					has_trait = zealous
				}
				modifier = {
					add = 2
					has_activity_intent = reflection_intent
				}
			}
			save_scope_as = first
		}
		add_activity_log_entry = {
			key = ppr_apa_retreat_choir_prayer
			tags = { pulse_action }
			character = scope:first

			scope:activity = { ppr_camp_retreat_gain_minor_effect = yes }
			scope:first = {
				add_piety = 15
				if = {
					limit = { has_trait = lifestyle_mystic }
					add_trait_xp = {
						trait = lifestyle_mystic
						value = lifestyle_mystic_xp_gain_minor_value
					}
				}
			}
		}
	}
}

ppr_apa_retreat_scriptorium = {
	icon = learning

	is_valid = {
		has_activity_type = ppr_activity_camp_retreat
		is_current_phase_active = yes
		has_current_phase = ppr_camp_retreat_phase_retreat
		any_attending_character = {
			location = scope:province
			is_adult = yes
			learning >= mediocre_skill_rating
		}
	}

	weight = {
		value = 1
		if = {
			limit = { ppr_camp_retreat_scholars_trigger = yes }
			multiply = 3
		}
	}

	effect = {
		random_attending_character = {
			limit = {
				location = scope:province
				is_adult = yes
				learning >= mediocre_skill_rating
			}
			weight = {
				base = 1
				modifier = {
					add = 2
					has_activity_intent = study_hard_intent
				}
				modifier = {
					add = 1
					learning >= high_skill_rating
				}
			}
			save_scope_as = first
		}
		add_activity_log_entry = {
			key = ppr_apa_retreat_scriptorium
			tags = { pulse_action }
			character = scope:first

			scope:activity = { ppr_camp_retreat_gain_minor_effect = yes }
			scope:first = {
				add_learning_lifestyle_xp = miniscule_lifestyle_xp
			}
		}
	}
}

ppr_apa_retreat_vespers_debate = {
	icon = friend

	is_valid = {
		has_activity_type = ppr_activity_camp_retreat
		is_current_phase_active = yes
		has_current_phase = ppr_camp_retreat_phase_retreat
		any_attending_character = {
			location = scope:province
			is_physically_able_ai_adult = yes
			save_temporary_scope_as = attendee_1
		}
		any_attending_character = {
			location = scope:province
			is_physically_able_ai_adult = yes
			this != scope:attendee_1
		}
	}

	weight = {
		value = 1
		if = {
			limit = {
				has_variable = ppr_apa_retreat_vespers_debate
			}
			multiply = 0.5
		}
	}

	effect = {
		set_variable = {
			name = ppr_apa_retreat_vespers_debate
			value = yes
		}
		random_attending_character = {
			limit = {
				location = scope:province
				is_physically_able_ai_adult = yes
			}
			save_scope_as = first
		}
		random_attending_character = {
			limit = {
				location = scope:province
				is_physically_able_ai_adult = yes
				this != scope:first
			}
			save_scope_as = second
		}

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

			scope:activity = { ppr_camp_retreat_gain_minor_effect = yes }
			scope:first = {
				add_opinion = {
					target = scope:second
					modifier = respect_opinion
					opinion = 10
				}
			}
			scope:second = {
				add_opinion = {
					target = scope:first
					modifier = respect_opinion
					opinion = 10
				}
			}
		}
	}
}

ppr_apa_retreat_cloister_garden = {
	icon = stress_loss

	is_valid = {
		has_activity_type = ppr_activity_camp_retreat
		is_current_phase_active = yes
		has_current_phase = ppr_camp_retreat_phase_retreat
		any_attending_character = {
			location = scope:province
			is_adult = yes
			stress > 0
		}
	}

	weight = {
		value = 1
	}

	effect = {
		random_attending_character = {
			limit = {
				location = scope:province
				is_adult = yes
				stress > 0
			}
			weight = {
				base = 1
				modifier = {
					add = 2
					has_activity_intent = reduce_stress_intent
				}
			}
			save_scope_as = first
		}
		add_activity_log_entry = {
			key = ppr_apa_retreat_cloister_garden
			tags = { pulse_action }
			character = scope:first

			scope:activity = { ppr_camp_retreat_gain_minor_effect = yes }
			scope:first = {
				add_stress = minor_stress_loss
			}
		}
	}
}
