plague_witch_hunt = {
	# by James Beaumont
	
	on_setup = {
	}

	on_end = {
		debug_log = "Witch hunt story ended on:"
		debug_log_date = yes
	}

	on_owner_death = {
		# Should be inherited, people won't stop the witch trials just because the ruler died
	}

	# The plague is over, end the story
	effect_group = {
		days = { 40 60 }

		trigger = {
			NOT = {
				story_owner = {
					any_sub_realm_county = {
						any_county_province_epidemic = {
							this = root.var:plague
						}
					}
				}
			}
		}

		first_valid = {
			triggered_effect = {
				trigger = { always = yes }
				effect = {
					end_story = yes
				}
			}
		}
	}

	# Something happens - random events
	effect_group = {
		days = { 365 600 }
		chance = 50

		trigger = {
			story_owner = {
				any_sub_realm_county = {
					any_county_province_epidemic = {
						this = root.var:plague
					}
				}
			}
		}

		first_valid = {
			triggered_effect = {
				trigger = { always = yes }
				effect = {
					save_scope_as = story_scope
					var:plague = { save_scope_as = epidemic_scope }
					var:faith_blamed ?= { save_scope_as = faith_blamed }
					var:trait_blamed ?= { save_scope_as = trait_blamed }
					story_owner = {
						trigger_event = {
							on_action = ongoing_witch_hunt_events
						}
					}
				}
			}
		}
	}

	#Maintenance group
	effect_group = {
		days = 1
		trigger = {
			story_owner = { is_landed = no }
		}
		triggered_effect = {
			trigger = { always = yes }
			effect = {
				#You became a landless adventurer/administrative! Ending story prematurely.
				story_owner = { save_scope_as = story_owner }
				debug_log = "Plague Witches invalidated"
				debug_log_scopes = yes
				end_story = yes
			}
		}
	}
}