﻿# Pilgrims and Preachers - effects for the Camp Retreat activity (ppr_activity_camp_retreat)
#
# Score: the vanilla special progression variable (var:activity_special_type_progression on the activity),
# set up with activity_setup_special_type_progression_effect in on_start.
# The Rule of Life scales every change: Gentle = gains x1, losses x0.5; Strict = gains and losses x1.5.

######################################################################
# Score changes (ACTIVITY scope)
######################################################################

# Internal: adds $NUM$ (positive) to the score, scaled by the Rule of Life.
ppr_camp_retreat_add_score_effect = {
	if = {
		limit = { exists = var:activity_special_type_progression }
		change_variable = {
			name = activity_special_type_progression
			add = {
				value = $NUM$
				if = {
					limit = { ppr_camp_retreat_strict_rule_trigger = yes }
					multiply = ppr_camp_retreat_strict_gain_mult
				}
			}
		}
		ppr_camp_retreat_clamp_score_effect = yes
	}
}

# Internal: removes $NUM$ (positive) from the score, scaled by the Rule of Life.
ppr_camp_retreat_remove_score_effect = {
	if = {
		limit = { exists = var:activity_special_type_progression }
		change_variable = {
			name = activity_special_type_progression
			subtract = {
				value = $NUM$
				if = {
					limit = { ppr_camp_retreat_strict_rule_trigger = yes }
					multiply = ppr_camp_retreat_strict_loss_mult
				}
				else = {
					multiply = ppr_camp_retreat_gentle_loss_mult
				}
			}
		}
		ppr_camp_retreat_clamp_score_effect = yes
	}
}

# Internal: keeps the score between 0 and 100.
ppr_camp_retreat_clamp_score_effect = {
	if = {
		limit = { var:activity_special_type_progression > 100 }
		set_variable = {
			name = activity_special_type_progression
			value = 100
		}
	}
	else_if = {
		limit = { var:activity_special_type_progression < 0 }
		set_variable = {
			name = activity_special_type_progression
			value = 0
		}
	}
}

ppr_camp_retreat_gain_minor_effect = {
	custom_tooltip = ppr_camp_retreat_tt_gain_minor
	ppr_camp_retreat_add_score_effect = { NUM = 4 }
}
ppr_camp_retreat_gain_medium_effect = {
	custom_tooltip = ppr_camp_retreat_tt_gain_medium
	ppr_camp_retreat_add_score_effect = { NUM = 8 }
}
ppr_camp_retreat_gain_major_effect = {
	custom_tooltip = ppr_camp_retreat_tt_gain_major
	ppr_camp_retreat_add_score_effect = { NUM = 15 }
}
ppr_camp_retreat_loss_minor_effect = {
	custom_tooltip = ppr_camp_retreat_tt_loss_minor
	ppr_camp_retreat_remove_score_effect = { NUM = 4 }
}
ppr_camp_retreat_loss_medium_effect = {
	custom_tooltip = ppr_camp_retreat_tt_loss_medium
	ppr_camp_retreat_remove_score_effect = { NUM = 8 }
}
ppr_camp_retreat_loss_major_effect = {
	custom_tooltip = ppr_camp_retreat_tt_loss_major
	ppr_camp_retreat_remove_score_effect = { NUM = 15 }
}

######################################################################
# Conclusion (CHARACTER scope: root = host; scope:activity, scope:host set)
# Called inside the completion log entry (ppr_camp_retreat.0009).
######################################################################

ppr_camp_retreat_completed_log_entry_effect = {
	involved_activity = {
		add_activity_log_entry = {
			key = ppr_camp_retreat_completed_log
			tags = { completed }
			score = 100
			show_in_conclusion = yes
			character = root
			#Effects
			root = {
				ppr_camp_retreat_outcome_effect = yes
			}
		}
	}
	pam_vows_of_poverty_host_completion_piety_effect = yes
}

ppr_camp_retreat_outcome_effect = {
	#### Great success: 75+
	if = {
		limit = { scope:activity.var:activity_special_type_progression >= 75 }
		custom_description_no_bullet = { text = ppr_camp_retreat_outcome_great_tt }
		ppr_camp_retreat_success_rewards_effect = yes
		if = {
			limit = { scope:activity = { ppr_camp_retreat_scholars_trigger = yes } }
			# A treatise written during the retreat.
			custom_tooltip = ppr_camp_retreat_treatise_tt
			hidden_effect = {
				create_artifact_book_effect = {
					OWNER = root
					CREATOR = root
					SET_SUBJECT = flag:learning
					SET_TOPIC = flag:no
				}
			}
		}
		else = {
			# Pilgrims: deeper progress on the pilgrim's path.
			if = {
				limit = { has_trait = pilgrim }
				add_trait_xp = {
					trait = pilgrim
					value = 20
				}
			}
			else = {
				add_piety = medium_piety_gain
			}
			scope:activity = {
				every_attending_character = {
					limit = {
						this != scope:host
						has_trait = pilgrim
					}
					custom = ppr_camp_retreat_every_attendee
					add_trait_xp = {
						trait = pilgrim
						value = 20
					}
				}
			}
		}
	}
	#### Success: 50+
	else_if = {
		limit = { scope:activity.var:activity_special_type_progression >= 50 }
		custom_description_no_bullet = { text = ppr_camp_retreat_outcome_success_tt }
		ppr_camp_retreat_success_rewards_effect = yes
	}
	#### Middling: 25-49
	else_if = {
		limit = { scope:activity.var:activity_special_type_progression >= 25 }
		custom_description_no_bullet = { text = ppr_camp_retreat_outcome_middling_tt }
		add_stress = minor_stress_loss
		scope:activity = {
			every_attending_character = {
				limit = { this != scope:host }
				custom = ppr_camp_retreat_every_attendee
				add_stress = minor_stress_loss
			}
		}
	}
	#### Failure: below 25
	else = {
		custom_description_no_bullet = { text = ppr_camp_retreat_outcome_failure_tt }
		add_character_modifier = {
			modifier = ppr_retreat_restless_camp_modifier
			years = 3
		}
		domicile ?= { change_provisions = minor_provisions_loss }
		if = {
			limit = { scope:activity = { ppr_camp_retreat_strict_rule_trigger = yes } }
			every_courtier = {
				custom = ppr_camp_retreat_every_follower
				add_opinion = {
					target = scope:host
					modifier = ppr_retreat_harsh_opinion
				}
			}
		}
	}
	#### Intents (everyone attending, any outcome)
	scope:activity = {
		every_attending_character = {
			limit = { has_activity_intent = reduce_stress_intent }
			custom = ppr_camp_retreat_every_attendee_rest
			add_stress = minor_stress_loss
		}
		every_attending_character = {
			limit = { has_activity_intent = study_hard_intent }
			custom = ppr_camp_retreat_every_attendee_study
			add_learning_lifestyle_xp = minor_lifestyle_xp
		}
		every_attending_character = {
			limit = { has_activity_intent = reflection_intent }
			custom = ppr_camp_retreat_every_attendee_reflection
			add_piety = minor_piety_gain
		}
	}
}

# Rewards shared by Success and Great Success. Root = host.
ppr_camp_retreat_success_rewards_effect = {
	add_stress = medium_stress_loss
	if = {
		limit = { scope:activity = { ppr_camp_retreat_scholars_trigger = yes } }
		add_character_modifier = {
			modifier = ppr_retreat_scholarly_insight_modifier
			years = 5
		}
		add_learning_lifestyle_xp = medium_lifestyle_xp
	}
	else = {
		add_character_modifier = {
			modifier = ppr_retreat_spiritual_renewal_modifier
			years = 5
		}
		add_piety = medium_piety_gain
		if = {
			limit = { has_pam_dlc_trigger = yes }
			change_spiritual_fulfillment = medium_spiritual_fulfillment_value
		}
		# Retreat held at a holy site of the camp's faith.
		if = {
			limit = {
				scope:activity.activity_location.barony ?= { is_holy_site_of = root.faith }
			}
			add_character_modifier = {
				modifier = ppr_camp_pilgrimage_modifier
				years = 5
			}
		}
	}
	# The whole camp shares the memory (camp temperament follows followers' opinion of the leader).
	every_courtier = {
		custom = ppr_camp_retreat_every_follower
		add_opinion = {
			target = scope:host
			modifier = ppr_retreat_shared_opinion
		}
	}
	# Those who came along.
	scope:activity = {
		every_attending_character = {
			limit = { this != scope:host }
			custom = ppr_camp_retreat_every_attendee
			add_stress = minor_stress_loss
			if = {
				limit = { scope:activity = { ppr_camp_retreat_scholars_trigger = yes } }
				add_learning_lifestyle_xp = minor_lifestyle_xp
			}
			else = {
				add_piety = minor_piety_gain
			}
		}
	}
}
