code:
/obj/item/weapon/melee/cultblade
	name = "eldritch longsword"
	desc = "A sword humming with unholy energy. It glows with a dim red light."
	icon_state = "cultblade"
	item_state = "cultblade"
	flags = CONDUCT
	sharpness = IS_SHARP
	w_class = 4
	force = 30
	throwforce = 10
	hitsound = 'sound/weapons/bladeslice.ogg'
	attack_verb = list("attacked", "slashed", "stabbed", "sliced", "torn", "ripped", "diced", "rended")

/obj/item/weapon/melee/cultblade/attack(mob/living/target, mob/living/carbon/human/user)
	if(!iscultist(user))
		user.Weaken(5)
		user.visible_message("A powerful force shoves [user] away from [target]!", \
							 "\"You shouldn't play with sharp things. You'll poke someone's eye out.\"")
		if(ishuman(user))
			var/mob/living/carbon/human/H = user
			H.apply_damage(rand(force/2, force), BRUTE, pick("l_arm", "r_arm"))
		else
			user.adjustBruteLoss(rand(force/2,force))
		return
	..()

/obj/item/weapon/melee/cultblade/pickup(mob/living/user)
	..()
	if(!iscultist(user))
		user << "\"I wouldn't advise that.\""
		user << "An overwhelming sense of nausea overpowers you!"
		user.Dizzy(120)

/obj/item/weapon/melee/cultblade/dagger
	name = "sacrificial dagger"
	desc = "A strange dagger said to be used by sinister groups for \"preparing\" a corpse before sacrificing it to their dark gods."
	icon = 'icons/obj/wizard.dmi'
	icon_state = "render"
	w_class = 2
	force = 15
	throwforce = 25
	embed_chance = 75

/obj/item/weapon/melee/cultblade/dagger/attack(mob/living/target, mob/living/carbon/human/user)
	..()
	if(ishuman(target))
		var/mob/living/carbon/human/H = target
		H.drip(50)

/obj/item/clothing/head/culthood
	name = "ancient cultist hood"
	icon_state = "culthood"
	desc = "A torn, dust-caked hood. Strange letters line the inside."
	flags_inv = HIDEFACE|HIDEHAIR|HIDEEARS
	flags_cover = HEADCOVERSEYES
	armor = list(melee = 30, bullet = 10, laser = 5,energy = 5, bomb = 0, bio = 0, rad = 0)
	cold_protection = HEAD
	min_cold_protection_temperature = HELMET_MIN_TEMP_PROTECT
	heat_protection = HEAD
	max_heat_protection_temperature = HELMET_MAX_TEMP_PROTECT

/obj/item/clothing/suit/cultrobes
	name = "ancient cultist robes"
	desc = "A ragged, dusty set of robes. Strange letters line the inside."
	icon_state = "cultrobes"
	item_state = "cultrobes"
	body_parts_covered = CHEST|GROIN|LEGS|ARMS
	allowed = list(/obj/item/weapon/tome,/obj/item/weapon/melee/cultblade)
	armor = list(melee = 50, bullet = 30, laser = 50,energy = 20, bomb = 25, bio = 10, rad = 0)
	flags_inv = HIDEJUMPSUIT
	cold_protection = CHEST|GROIN|LEGS|ARMS
	min_cold_protection_temperature = ARMOR_MIN_TEMP_PROTECT
	heat_protection = CHEST|GROIN|LEGS|ARMS
	max_heat_protection_temperature = ARMOR_MAX_TEMP_PROTECT

/obj/item/clothing/head/culthood/alt
	name = "cultist hood"
	desc = "An armored hood worn by the followers of Nar-Sie."
	icon_state = "cult_hoodalt"
	item_state = "cult_hoodalt"

/obj/item/clothing/suit/cultrobes/alt
	name = "cultist robes"
	desc = "An armored set of robes worn by the followers of Nar-Sie."
	icon_state = "cultrobesalt"
	item_state = "cultrobesalt"

/obj/item/clothing/head/magus
	name = "magus helm"
	icon_state = "magus"
	item_state = "magus"
	desc = "A helm worn by the followers of Nar-Sie."
	flags_inv = HIDEFACE|HIDEHAIR|HIDEFACIALHAIR|HIDEEARS|HIDEEYES
	armor = list(melee = 30, bullet = 30, laser = 30,energy = 20, bomb = 0, bio = 0, rad = 0)
	flags_cover = HEADCOVERSEYES | HEADCOVERSMOUTH

/obj/item/clothing/suit/magusred
	name = "magus robes"
	desc = "A set of armored robes worn by the followers of Nar-Sie"
	icon_state = "magusred"
	item_state = "magusred"
	body_parts_covered = CHEST|GROIN|LEGS|ARMS
	allowed = list(/obj/item/weapon/tome,/obj/item/weapon/melee/cultblade)
	armor = list(melee = 50, bullet = 30, laser = 50,energy = 20, bomb = 25, bio = 10, rad = 0)
	flags_inv = HIDEGLOVES|HIDESHOES|HIDEJUMPSUIT

/obj/item/clothing/head/helmet/space/cult
	name = "nar-sian bruiser's helmet"
	desc = "A heavily-armored helmet worn by warriors of the Nar-Sian cult. It can withstand hard vacuum."
	icon_state = "cult_helmet"
	item_state = "cult_helmet"
	armor = list(melee = 60, bullet = 50, laser = 30,energy = 15, bomb = 30, bio = 30, rad = 30)

/obj/item/clothing/suit/space/cult
	name = "nar-sian bruiser's armor"
	icon_state = "cult_armor"
	item_state = "cult_armor"
	desc = "A heavily-armored exosuit worn by warriors of the Nar-Sian cult. It can withstand hard vacuum."
	w_class = 3
	allowed = list(/obj/item/weapon/tome,/obj/item/weapon/melee/cultblade,/obj/item/weapon/tank/internals/)
	armor = list(melee = 70, bullet = 50, laser = 30,energy = 15, bomb = 30, bio = 30, rad = 30)


code:
/obj/structure/cult
	density = 1
	anchored = 1
	icon = 'icons/obj/cult.dmi'

/obj/structure/cult/talisman
	name = "altar"
	desc = "A bloodstained altar dedicated to Nar-Sie"
	icon_state = "talismanaltar"

/obj/structure/cult/forge
	name = "daemon forge"
	desc = "A forge used in crafting the unholy weapons used by the armies of Nar-Sie"
	icon_state = "forge"

/obj/structure/cult/pylon
	name = "pylon"
	desc = "A floating crystal that hums with an unearthly energy"
	icon_state = "pylon"
	luminosity = 5

/obj/structure/cult/tome
	name = "desk"
	desc = "A desk covered in arcane manuscripts and tomes in unknown languages. Looking at the text makes your skin crawl"
	icon_state = "tomealtar"
	luminosity = 1

/obj/effect/gateway
	name = "gateway"
	desc = "You're pretty sure that abyss is staring back"
	icon = 'icons/obj/cult.dmi'
	icon_state = "hole"
	density = 1
	unacidable = 1
	anchored = 1

license: mit


code:
/*

This file contains the arcane tome files as well as innate cultist emergency communications.

*/

/mob/proc/cult_add_comm() //why the fuck does this have its own proc? not removing it because it might be used somewhere but...
	verbs += /mob/living/proc/cult_innate_comm

/mob/living/proc/cult_innate_comm()
	set category = "Cultist"
	set name = "Imperfect Communion"

	if(!iscultist(usr) || usr.incapacitated())
		return

	var/input = stripped_input(usr, "Please choose a message to tell to the other acolytes.", "Voice of Blood", "")
	if(!input)
		return

	if(!iscultist(usr) || usr.incapacitated())
		return	//we do this again because input() sleeps

	if(ishuman(usr) || ismonkey(usr))	//Damage only applies to humans and monkeys, to allow constructs to communicate
		usr.visible_message("[usr] starts clawing at \his arms with \his fingernails!", "You begin slicing open your arms with your fingernails!")
		apply_damage(10,BRUTE, "l_arm")
		apply_damage(10,BRUTE, "r_arm")
		sleep(50)
		if(usr.incapacitated())
			return	//Hard to drawn intrinsic symbols when you're bleeding out in your cell.
		var/turf/location = loc
		if(istype(location, /turf))	// tearing your arms apart is going to spill a bit of blood, in fact thats the idea
			location.add_blood(usr)				// TO-DO change this to a badly drawn rune
		apply_damage(10,BRUTE, "l_arm")		// does a metric fuck ton of damage because this meant to be an emergency method of communication.
		apply_damage(10,BRUTE, "r_arm")
		if(usr.incapacitated())
			return
		usr.visible_message("[usr] paints strange symbols with their own blood.", "You paint a messy rune with your own blood.")
		sleep(20)

	cultist_commune(usr, 0, 1, input)
	return

/obj/item/weapon/tome
	name = "arcane tome"
	desc = "An old, dusty tome with frayed edges and a sinister-looking cover."
	icon_state ="tome"
	throw_speed = 2
	throw_range = 5
	w_class = 2

/obj/item/weapon/tome/examine(mob/user)
	..()
	if(iscultist(user))
		user << "The scriptures of the Geometer. Allows the scribing of runes and access to the knowledge archives of the cult of Nar-Sie."

/obj/item/weapon/tome/attack(mob/living/M, mob/living/user)
	if(istype(M,/mob/dead/observer))
		M.invisibility = 0
		user.visible_message("[user] strikes the air with [src], and a ghost appears!", \
							 "You drag the ghost to your plane of reality!")
		add_logs(user, M, "smacked", src)
		return
	if(!istype(M))
		return
	if(!iscultist(user))
		return ..()
	if(iscultist(M))
		if(M.reagents && M.reagents.has_reagent("holywater")) //allows cultists to be rescued from the clutches of ordained religion
			user << "You remove the taint from [M]."
			var/holy2unholy = M.reagents.get_reagent_amount("holywater")
			M.reagents.del_reagent("holywater")
			M.reagents.add_reagent("unholywater",holy2unholy)
			add_logs(user, M, "smacked", src, " removing the holy water from them")
		return
	M.take_organ_damage(0, 15) //Used to be a random between 5 and 20
	playsound(M, 'sound/weapons/sear.ogg', 50, 1)
	M.visible_message("[user] strikes [M] with the arcane tome!", \
					  "[user] strikes you with the tome, searing your flesh!")
	flick("tome_attack", src)
	user.do_attack_animation(M)
	add_logs(user, M, "smacked", src)

/obj/item/weapon/tome/attack_self(mob/user)
	if(!iscultist(user))
		user << "[src] seems full of unintelligible shapes, scribbles, and notes. Is this some sort of joke?"
		return
	open_tome(user)

/obj/item/weapon/tome/proc/open_tome(mob/user)
	var/choice = alert(user,"You open the tome...",,"Commune","Scribe Rune","Read Tome")
	switch(choice)
		if("Read Tome")
			read_tome(user)
		if("Scribe Rune")
			scribe_rune(user)
		if("Commune")
			var/input = stripped_input(usr, "Please enter a message to tell to the other acolytes.", "Voice of Blood", "")
			if(!input)
				return
			cultist_commune(user, 1, 0, input)

/obj/item/weapon/tome/proc/read_tome(mob/user)
	var/text = ""
	text += "Archives of the Dark One

"
	text += "As a member of the cult, your goals are almost or entirely impossible to complete without special aid from the Geometer's plane. The primary method of doing this are runes. These \
	scribings, drawn in blood, are concentrated nodes of the magic within Nar-Sie's realm and will allow the performance of many tasks to aid you and the rest of the cult in your objectives. Runes \
	have many different names, and almost all of them are known as Rites. The only rune that is not a Rite is the Ritual of Dimensional Rending, which can only be performed with nine cultists and calls \
	forth the avatar of the Geometer herself (so long as she consents).

A rune's name and effects can be revealed by examining the rune.

"

	text += "Teleport
The Rite of Translocation is a unique rite in that it requires a keyword before the scribing can begin. When invoked, the rune will \
	search for other Rites of Translocation with the same keyword. Assuming one is found, the user will be instantaneously transported to the location of the other rune. If more than two runes are scribed \
	with the same keyword, it will choose randomly between all eligible runes and send the invoker to one of them.

"

	text += "Teleport Other
The Rite of Forced Translocation, like the Rite of Translocation, works by teleporting the person on the rune to one of the \
	same keyword. However, this rune will only work on people other than the user, allowing the user to send any living creature somewhere else.

"

	text += "Summon Tome
The Rite of Knowledge is a simplistic rune. When invoked, it will summon a single arcane tome to the rune's location before vanishing. \

"

	text += "Convert
The Rite of Enlightment is paramount to the success of the cult. It will allow you to convert normal crew members into cultists. \
	To do this, simply place the crew member upon the rune and invoke it. This rune requires two acolytes to use. If the target to be converted is loyalty-implanted or a certain assignment, they will \
	be unable to be converted. People the Geometer wishes sacrificed will also be ineligible for conversion, and anyone with a shielding presence like the null rod will not be converted.

"

	text += "Sacrifice
The Rite of Tribute is used to offer sacrifice to the Geometer. Simply place any living creature upon the rune and invoke it (this will not \
	target cultists!). If this creature has a mind, a soul shard will be created and the creature's soul transported to it. This rune is required if the cult's objectives include the sacrifice of a crew \
	member.

"

	text += "Raise Dead
The Rite of Resurrection is a delicate rite that requires two corpses. To perform the ritual, place the corpse you wish to revive onto \
	the rune and the offering body adjacent to it. When the rune is invoked, the body to be sacrificed will turn to dust, the life force flowing into the revival target. Assuming the target is not moved \
	within a few seconds, they will be brought back to life, healed of all ailments.

"

	text += "Veil Runes
The Rite of Obscurity is a rite that will cause all nearby runes to become invisible. The runes will still be considered by other rites \
	(such as the Rite of Translocation) but will be unusuable directly.(such as the Rite of Translocation) but will be unusuable directly. Use the same rite once more to reveal these runes once more.

"

	text += "Reveal Runes
The Rite of True Sight is the foil of the Rite of Obscurity. It will turn all invisible runes visible once more, in addition to causing \
	all spirits nearby to become visible.

"

	text += "Disguise Runes
Many crewmen enjoy drawing runes in crayon that resemble spell circles in order to play pranks on their fellow crewmen. The Rite of \
	False Truths takes advantage of this very joke. When invoked, all nearby runes will appear dull, precisely resembling those drawn in crayon. They still cannot be cleaned by conventional means, so \
	anyone trying to clean up the rune may become suspicious as it does not respond.

"

	text += "Electromagnetic Disruption
Robotic lifeforms have time and time again been the downfall of fledgling cults. The Rite of Disruption may allow you to gain the upper \
	hand against these pests. By using the rune, a large electromagnetic pulse will be emitted from the rune's location.

"

	text += "Astral Communion
The Rite of Astral Communion is perhaps the most ingenious rune that is usable by a single person. Upon invoking the rune, the \
	user's spirit will be ripped from their body. In this state, the user's physical body will be locked in place to the rune itself - any attempts to move it will result in the rune pulling it back. \
	The body will also take constant damage while in this form, and may even die. The user's spirit will contain their consciousness, and will allow them to freely wander the station as a ghost. This may \
	also be used to commune with the dead.

"

	text += "Form Shield
While simple, the Rite of the Corporeal Shield serves an important purpose in defense and hindering passage. When invoked, the \
	rune will draw a small amount of life force from the user and make the space above the rune completely dense, rendering it impassable to all but the most complex means. The rune may be invoked again to \
	undo this effect and allow passage again.

"

	text += "Debilitate
The Rite of the Shadowed Mind is simple. When invoked, it will cause all non-cultists that can see its rune to become deaf, blind and mute for a \
	considerable amount of time.

"

	text += "Stun
Though the Rite of Blazing Light is weak when invoked normally, using it in conjuction with the Rite of Binding makes it much more powerful. \
	This rune will cause any non-cultists that can see the rune to become disoriented, disabling them for a short time.

"

	text += "Summon Cultist
The Rite of Joined Souls requires two acolytes to use. When invoked, it will allow the user to summon a single cultist to the rune from \
	any location. This will deal a moderate amount of damage to all invokers.

"

	text += "Imbue Talisman
The Rite of Binding is the only way to create talismans. A blank sheet of paper must be on top of the rune, with a valid rune nearby. After \
	invoking it, the paper will be converted into a talisman, and the rune inlaid upon it.

"

	text += "Fabricate Shell
The Rite of Fabrication is the main way of creating construct shells. To use it, one must place five sheets of plasteel on top of the rune \
	and invoke it. The sheets will them be twisted into a construct shell, ready to recieve a soul to occupy it.

"

	text += "Summon Armaments
The Rite of Arming will equip the user with armored robes, a backpack, an eldrich longsword, and a pair of boots. Any items that cannot \
	be equipped will not be summoned.

"

	text += "Drain Life
The Rite of Leeching will drain the life of any non-cultist above the rune and heal the invoker for the same amount.

"

	text += "Blood Boil
The Rite of Boiling Blood may be considered one of the most dangerous rites composed by the cult of Nar-Sie. When invoked, it will do a \
	massive amount of damage to all non-cultist viewers, but it will also emit an explosion upon invocation. Use with caution

"

	text += "Time Stop
The Rite of Dimensional Corruption is a versatile rite that can be very strong when protecting our cult from the enemies of the Geometer. \
	As it is invoked, it will rend and reshape reality around itself, stopping time for all those who don't follow the teachings of the Geometer. However, it requires more than one ritual soul as a \
	catalyst, and its power is bound to overflow and hurt its casters.

"

	text += "Manifest Spirit
If you wish to bring a spirit back from the dead with a wish for vengeance and desire to serve, the Rite of Spectral \
	Manifestation can do just that. When invoked, any spirits above the rune will be brought to life as a human wearing nothing that seeks only to serve you and the Geometer. However, the spirit's link \
	to reality is fragile - you must remain on top of the rune, and you will slowly take damage. Upon stepping off the rune, the spirits will dissipate, dropping their items to the ground. You may manifest \
	multiple spirits with one rune, but you will rapidly take damage in doing so.

"

	text += "Call Forth The Geometer
There is only one way to summon the avatar of Nar-Sie, and that is the Ritual of Dimensional Rending. This ritual, in \
	comparison to other runes, is very large, requiring a 3x3 space of empty tiles to create. To invoke the rune, nine cultists must stand on the rune, so that all of them are within its circle. Then, \
	simply invoke it. A brief tearing will be heard as the barrier between dimensions is torn open, and the avatar will come forth.

"

	text += "While runes are excellent for many tasks, they lack portability. The advent of talismans has, to a degree, solved this inconvenience. Simply put, a talisman is a piece of paper with a \
	rune inlaid within it. The words of the rune can be whispered in order to invoke its effects, although usually to a lesser extent. To create a talisman, simply use a Rite of Binding as described above. \
	Unless stated otherwise, talismans are invoked by activating them in your hand. A list of valid rites, as well as the effects of their talisman form, can be found below.

"

	text += "Talisman of Teleportation
The talisman form of the Rite of Translocation will transport the invoker to a randomly chosen rune of the same keyword, then \
	disappear.

"

	text += "Talisman of Tome Summoning
This talisman functions nearly identically to the rune. The talisman will attempt to place the tome in your hand \
	instead of on the ground, though this is the only advantage it has over the rune. It can be used once, then disappears.

"

	text += "Talismans of Veiling, Revealing, and Disguising
These talismans all function identically to their rune counterparts, but with less range. In addition, \
	the Talisman of True Sight will not reveal spirits. They will disappear after one use.

"

	text += "Talisman of Electromagnetic Pulse
This talisman functions like the Rite of Disruption. It disappears after one use.

"

	text += "Talisman of Stunning
Without this talisman, the cult would have no way of easily acquiring targets to convert. Commonly called \"stunpapers\", this \
	talisman functions differently from others. Rather than simply reading the words, the target must be attacked directly with the talisman. The talisman will then knock down the target for a long \
	duration in addition to inhibiting their speech. Robotic lifeforms will suffer the effects of a heavy electromagnetic pulse instead."

	var/datum/browser/popup = new(user, "tome", "", 800, 600)
	popup.set_content(text)
	popup.open()
	return 1

/obj/item/weapon/tome/proc/scribe_rune(mob/user)
	var/chosen_keyword
	var/rune_to_scribe
	var/entered_rune_name
	var/list/possible_runes = list()
	for(var/T in subtypesof(/obj/effect/rune) - /obj/effect/rune/malformed)
		var/obj/effect/rune/R = T
		if(initial(R.cultist_name))
			possible_runes.Add(initial(R.cultist_name)) //This is to allow the menu to let cultists select runes by name rather than by object path. I don't know a better way to do this
	if(!possible_runes.len)
		return
	entered_rune_name = input(user, "Choose a rite to scribe.", "Sigils of Power") as null|anything in possible_runes
	if(!Adjacent(user) || !src || qdeleted(src) || user.incapacitated())
		return
	for(var/T in typesof(/obj/effect/rune))
		var/obj/effect/rune/R = T
		if(initial(R.cultist_name) == entered_rune_name)
			rune_to_scribe = R
			if(initial(R.req_keyword))
				var/the_keyword = stripped_input(usr, "Please enter a keyword for the rune.", "Enter Keyword", "")
				if(!the_keyword)
					return
				chosen_keyword = the_keyword
			break
	if(!rune_to_scribe)
		return
	if(!Adjacent(user) || !src || qdeleted(src) || user.incapacitated())
		return
	user.visible_message("[user] cuts open their arm and begins writing in their own blood!", \
						 "You slice open your arm and begin drawing a sigil of the Geometer.")
	if(iscarbon(user))
		var/mob/living/carbon/C = user
		C.apply_damage(0.1, BRUTE, pick("l_arm", "r_arm"))
		if("Call Forth The Geometer" == entered_rune_name)
			C.apply_damage(40, BRUTE, pick("l_arm", "r_arm"))
			var/area/A = get_area(src)
			var/locname = initial(A.name)
			priority_announce("Figments from an eldritch god are being summoned by [user] into [locname] from an unknown dimension. Disrupt the ritual before it reaches a critical point.","Central Command Higher Dimensionsal Affairs")
			if(!do_after(user, 500, target = get_turf(user)))
				return
	if(!do_after(user, 50, target = get_turf(user)))
		return
	user.visible_message("[user] creates a strange circle in their own blood.", \
						 "You finish drawing the arcane markings of the Geometer.")
	var/obj/effect/rune/R = new rune_to_scribe(get_turf(user))
	if(chosen_keyword)
		R.keyword = chosen_keyword


code:
/var/list/sacrificed = list()
var/list/non_revealed_runes = (subtypesof(/obj/effect/rune) - /obj/effect/rune/malformed)

/*

This file contains runes.
Runes are used by the cult to cause many different effects and are paramount to their success.
They are drawn with an arcane tome in blood, and are distinguishable to cultists and normal crew by examining.
Fake runes can be drawn in crayon to fool people.
Runes can either be invoked by one's self or with many different cultists. Each rune has a specific incantation that the cultists will say when invoking it.

To draw a rune, use an arcane tome.

*/

/obj/effect/rune
	name = "rune"
	var/cultist_name = "basic rune"
	desc = "An odd collection of symbols drawn in what seems to be blood."
	var/cultist_desc = "A basic rune with no function." //This is shown to cultists who examine the rune in order to determine its true purpose.
	anchored = 1
	icon = 'icons/obj/rune.dmi'
	icon_state = "1"
	unacidable = 1
	layer = TURF_LAYER + 0.08
	color = rgb(255,0,0)
	mouse_opacity = 2

	var/invocation = "Aiy ele-mayo!" //This is said by cultists when the rune is invoked.
	var/req_cultists = 1 //The amount of cultists required around the rune to invoke it. If only 1, any cultist can invoke it.
	var/rune_in_use = 0 // Used for some runes, this is for when you want a rune to not be usable when in use.

	var/req_pylons = 0
	var/req_forges = 0
	var/req_archives = 0
	var/req_altars = 0

	var/req_keyword = 0 //If the rune requires a keyword - go figure amirite
	var/keyword //The actual keyword for the rune

/obj/effect/rune/examine(mob/user)
	..()
	if(iscultist(user) || user.stat == DEAD) //If they're a cultist or a ghost, tell them the effects
		user << "Name: [cultist_name]"
		user << "Effects: [cultist_desc]"
		user << "Required Acolytes: [req_cultists]"
		if(req_keyword && keyword)
			user << "Keyword: [keyword]"

/obj/effect/rune/attackby(obj/I, mob/user, params)
	if(istype(I, /obj/item/weapon/tome) && iscultist(user))
		user << "You carefully erase [src]."
		qdel(src)
		return
	else if(istype(I, /obj/item/weapon/nullrod))
		user.say("BEGONE FOUL MAGIKS!!")
		user << "You disrupt the magic of [src] with [I]."
		qdel(src)
		return
	return

/obj/effect/rune/attack_hand(mob/living/user)
	if(!iscultist(user))
		user << "You aren't able to understand the words of [src]."
		return
	if(can_invoke(user))
		invoke(user)
		var/oldtransform = transform
		animate(src, transform = matrix()*2, alpha = 0, time = 5) //fade out
		animate(transform = oldtransform, alpha = 255, time = 0)
	else
		fail_invoke(user)

/*

There are a few different procs each rune runs through when a cultist activates it.
can_invoke() is called when a cultist activates the rune with an empty hand. If there are multiple cultists, this rune determines if the required amount is nearby.
invoke() is the rune's actual effects.
fail_invoke() is called when the rune fails, via not enough people around or otherwise. Typically this just has a generic 'fizzle' effect.
structure_check() searches for nearby cultist structures required for the invocation. Proper structures are pylons, forges, archives, and altars.

*/

/obj/effect/rune/proc/can_invoke(var/mob/living/user)
	//This proc determines if the rune can be invoked at the time. If there are multiple required cultists, it will find all nearby cultists.
	if(!structure_check(req_pylons, req_forges, req_archives, req_altars))
		return 0
	if(!keyword && req_keyword)
		return 0
	if(req_cultists <= 1)
		if(invocation)
			user.say(invocation)
		return 1
	else
		var/cultists_in_range = 0
		for(var/mob/living/L in range(1, src))
			if(iscultist(L))
				var/mob/living/carbon/human/H = L
				if(!istype(H))
					if(istype(L, /mob/living/simple_animal/hostile/construct))
						if(invocation)
							L.say(invocation)
						cultists_in_range++
					continue
				if(L.stat || (H.disabilities & MUTE) || H.silent)
					continue
				if(invocation)
					L.say(invocation)
				cultists_in_range++
		if(cultists_in_range >= req_cultists)
			return 1
		else
			return 0

/obj/effect/rune/proc/invoke(var/mob/living/user)
	//This proc contains the effects of the rune as well as things that happen afterwards. If you want it to spawn an object and then delete itself, have both here.

/obj/effect/rune/proc/fail_invoke(var/mob/living/user)
	//This proc contains the effects of a rune if it is not invoked correctly, through either invalid wording or not enough cultists. By default, it's just a basic fizzle.
	visible_message("The markings pulse with a small flash of red light, then fall dark.")

/obj/effect/rune/proc/structure_check(var/rpylons, var/rforges, var/rarchives, var/raltars)
	var/pylons = 0
	var/forges = 0
	var/archives = 0
	var/altars = 0
	for(var/obj/structure/cult/pylon in orange(3,src))
		pylons++
	for(var/obj/structure/cult/forge in orange(3,src))
		forges++
	for(var/obj/structure/cult/tome in orange(3,src))
		archives++
	for(var/obj/structure/cult/talisman in orange(3,src))
		altars++
	if(pylons >= rpylons && forges >= rforges && archives >= rarchives && altars >= raltars)
		return 1
	return 0

//Malformed Rune: This forms if a rune is not drawn correctly. Invoking it does nothing but hurt the user.
/obj/effect/rune/malformed
	cultist_name = "malformed rune"
	cultist_desc = "A senseless rune written in gibberish. No good can come from invoking this."
	invocation = "Ra'sha yoka!"

/obj/effect/rune/malformed/New()
	..()
	icon_state = "[rand(1,6)]"
	color = rgb(rand(0,255), rand(0,255), rand(0,255))

/obj/effect/rune/malformed/invoke(mob/living/user)
	user << "You feel your life force draining. The Geometer is displeased."
	user.apply_damage(30, BRUTE)
	qdel(src)

/mob/proc/null_rod_check() //The null rod, if equipped, will protect the holder from the effects of most runes
	var/obj/item/weapon/nullrod/N = locate() in src
	if(N)
		return N
	return 0

var/list/teleport_runes = list()
//Rite of Translocation: Warps the user to a random teleport rune with the same keyword.
/obj/effect/rune/teleport
	cultist_name = "Teleport"
	cultist_desc = "Warps the user to a random rune of the same keyword."
	invocation = "Sas'so c'arta forbici!"
	icon_state = "2"
	color = rgb(0, 0, 255)
	req_keyword = 1

/obj/effect/rune/teleport/New()
	..()
	teleport_runes.Add(src)

/obj/effect/rune/teleport/Destroy()
	teleport_runes.Remove(src)
	..()

/obj/effect/rune/teleport/invoke(mob/living/user)
	var/list/potential_runes = list()
	for(var/obj/effect/rune/teleport/T in teleport_runes)
		if(T.keyword == src.keyword && T != src && (T.z <= ZLEVEL_SPACEMAX))
			potential_runes.Add(T)

	if(!potential_runes.len)
		user << "There are no runes with the same keyword!"
		fail_invoke()
		log_game("Teleport rune failed - no candidates with matching keyword")
		return

	if(user.z > ZLEVEL_SPACEMAX)
		user << "You are not in the right dimension!"
		fail_invoke()
		log_game("Teleport rune failed - user in away mission")
		return

	var/obj/effect/rune/selected_rune = pick(potential_runes)
	user.visible_message("[user] vanishes in a flash of red light!", \
						 "Your vision blurs, and you suddenly appear somewhere else.")
	user.forceMove(get_turf(selected_rune))

var/list/teleport_other_runes = list()
//Rite of Forced Translocation: Warps the target to a random teleport rune with the same keyword.
/obj/effect/rune/teleport_other
	cultist_name = "Teleport Other"
	cultist_desc = "Warps the target to a random rune of the same keyword."
	invocation = "Sas'so c'arta forbica!"
	icon_state = "1"
	color = rgb(200, 0, 0)
	req_keyword = 1

/obj/effect/rune/teleport_other/New()
	..()
	teleport_other_runes.Add(src)

/obj/effect/rune/teleport_other/Destroy()
	teleport_other_runes.Remove(src)
	..()

/obj/effect/rune/teleport_other/invoke(mob/living/user)
	var/list/potential_runes = list()
	for(var/obj/effect/rune/teleport_other/T in teleport_other_runes)
		if(T.keyword == src.keyword && T != src && (T.z <= ZLEVEL_SPACEMAX))
			potential_runes.Add(T)

	if(!potential_runes.len)
		user << "There are no runes with the same keyword!"
		fail_invoke()
		log_game("Teleport Other rune failed - no candidates with matching keyword")
		return

	if(user.z > ZLEVEL_SPACEMAX)
		user << "You are not in the right dimension!"
		fail_invoke()
		log_game("Teleport rune failed - user in away mission")
		return

	var/obj/effect/rune/selected_rune = pick(potential_runes)
	var/mob/living/target

	var/list/targets = list()
	for(var/mob/living/L in get_turf(src))
		if(L != user)
			targets.Add(L)
	if(!targets.len)
		user << "There are no targets standing on the rune!"
		fail_invoke()
		log_game("Teleport Other rune failed - no targets on rune")
		return
	if(targets.len > 1)
		target = input(user, "Choose a person to teleport.", "Rite of Forced Translocation") as null|anything in targets - user
		if(!Adjacent(user) || !src || qdeleted(src) || user.incapacitated())
			return
		if(!target)
			fail_invoke()
			return
	else
		target = targets[targets.len]

	target.visible_message("[target] vanishes in a flash of red light!", \
						   "Your vision blurs, and you suddenly appear somewhere else.")
	target.forceMove(get_turf(selected_rune))

//Rite of Knowledge: Creates an arcane tome at the rune's location and destroys the rune.
/obj/effect/rune/summon_tome
	cultist_name = "Summon Tome"
	cultist_desc = "Pulls an arcane tome from the archives of the Geometer."
	invocation = "N'ath reth sh'yro eth d'raggathnor!"
	icon_state = "5"
	color = rgb(0, 0, 255)

/obj/effect/rune/summon_tome/invoke(mob/living/user)
	visible_message("A frayed tome materializes on the surface of [src], which dissolves into nothing.")
	new /obj/item/weapon/tome(get_turf(src))
	qdel(src)

//Rite of Enlightenment: Converts a normal crewmember to the cult. Faster for every cultist nearby.
/obj/effect/rune/convert
	cultist_name = "Convert"
	cultist_desc = "Converts a normal crewmember on top of it to the cult. Does not work on loyalty-implanted crew."
	invocation = "Mah'weyh pleggh at e'ntrath!"
	icon_state = "3"
	color = rgb(255, 0, 0)
	req_cultists = 2

/obj/effect/rune/convert/invoke(mob/living/user)
	var/list/convertees = list()
	var/turf/T = get_turf(src)
	for(var/mob/living/M in T.contents)
		if(!iscultist(M) && !isloyal(M))
			convertees.Add(M)
	if(!convertees.len)
		fail_invoke()
		log_game("Convert rune failed - no eligible convertees")
		return
	var/mob/living/new_cultist = pick(convertees)
	if(!is_convertable_to_cult(new_cultist.mind) || new_cultist.null_rod_check())
		user << "Something is shielding [new_cultist]'s mind!"
		fail_invoke()
		log_game("Convert rune failed - convertee could not be converted")
		if(is_sacrifice_target(new_cultist.mind))
			for(var/mob/living/M in orange(1,src))
				if(iscultist(M))
					M << "\"I desire this one for myself. SACRIFICE THEM!\""
		return
	new_cultist.visible_message("[new_cultist] writhes in pain as the markings below them glow a bloody red!", \
					  			"AAAAAAAAAAAAAA-")
	ticker.mode.add_cultist(new_cultist.mind)
	new_cultist.mind.special_role = "Cultist"
	new_cultist << "Your blood pulses. Your head throbs. The world goes red. All at once you are aware of a horrible, horrible, truth. The veil of reality has been ripped away \
	and something evil takes root."
	new_cultist << "Assist your new compatriots in their dark dealings. Your goal is theirs, and theirs is yours. You serve the Geometer above all else. Bring it back.\
	"

//Rite of Tribute: Sacrifices a crew member to Nar-Sie. Places them into a soul shard if they're in their body.
/obj/effect/rune/sacrifice
	cultist_name = "Sacrifice"
	cultist_desc = "Sacrifices a crew member to the Geometer. May place them into a soul shard if their spirit remains in their body."
	icon_state = "3"
	invocation = "Barhah hra zar'garis!"
	color = rgb(255, 255, 255)
	rune_in_use = 0

/obj/effect/rune/sacrifice/New()
	..()
	icon_state = "[rand(1,6)]"

/obj/effect/rune/sacrifice/invoke(mob/living/user)
	if(rune_in_use)
		return
	rune_in_use = 1
	var/turf/T = get_turf(src)
	var/list/possible_targets = list()
	for(var/mob/living/M in T.contents)
		if(!iscultist(M))
			possible_targets.Add(M)
	var/mob/offering
	if(possible_targets.len > 1) //If there's more than one target, allow choice
		offering = input(user, "Choose an offering to sacrifice.", "Unholy Tribute") as null|anything in possible_targets
		if(!Adjacent(user) || !src || qdeleted(src) || user.incapacitated())
			return
	else if(possible_targets.len) //Otherwise, if there's a target at all, pick the only one
		offering = possible_targets[possible_targets.len]
	if(!offering)
		rune_in_use = 0
		return
	/*var/obj/item/weapon/nullrod/N = offering.null_rod_check()
	if(N)
		user << "Something is blocking the Geometer's magic!"
		log_game("Sacrifice rune failed - target has \a [N]!")
		fail_invoke()
		rune_in_use = 0
		return*/
	if(((ishuman(offering) || isrobot(offering)) && offering.stat != DEAD) || is_sacrifice_target(offering.mind)) //Requires three people to sacrifice living targets
		var/cultists_nearby = 1
		for(var/mob/living/M in range(1,src))
			if(iscultist(M) && M != user)
				cultists_nearby++
				M.say(invocation)
		if(cultists_nearby < 3)
			user << "[offering] is too greatly linked to the world! You need three acolytes!"
			fail_invoke()
			log_game("Sacrifice rune failed - not enough acolytes and target is living")
			rune_in_use = 0
			return
	visible_message("[src] pulses blood red!")
	color = rgb(126, 23, 23)
	spawn(5)
		color = initial(color)
	sac(offering)

/obj/effect/rune/sacrifice/proc/sac(mob/living/T)
	var/sacrifice_fulfilled
	if(T)
		if(istype(T, /mob/living/simple_animal/pet/dog))
			for(var/mob/living/carbon/C in range(3,src))
				if(iscultist(C))
					C << "\"Even I have standards, such as they are!\""
					if(C.reagents)
						C.reagents.add_reagent("hell_water", 2)
		if(T.mind)
			sacrificed.Add(T.mind)
			if(is_sacrifice_target(T.mind))
				sacrifice_fulfilled = 1
		PoolOrNew(/obj/effect/overlay/temp/cult/sac, src.loc)
		for(var/mob/living/M in range(3,src))
			if(iscultist(M))
				if(sacrifice_fulfilled)
					M << "\"Yes! This is the one I desire! You have done well.\""
				else
					if(ishuman(T) || isrobot(T))
						M << "\"I accept this sacrifice.\""
					else
						M << "\"I accept this meager sacrifice.\""
		if(T.mind)
			var/obj/item/device/soulstone/stone = new /obj/item/device/soulstone(get_turf(src))
			stone.invisibility = INVISIBILITY_MAXIMUM //so it's not picked up during transfer_soul()
			if(!stone.transfer_soul("FORCE", T, usr)) //If it cannot be added
				qdel(stone)
			if(stone)
				stone.invisibility = 0
			if(!T)
				rune_in_use = 0
				return
		if(isrobot(T))
			playsound(T, 'sound/magic/Disable_Tech.ogg', 100, 1)
			T.dust() //To prevent the MMI from remaining
		else
			playsound(T, 'sound/magic/Disintegrate.ogg', 100, 1)
			T.gib()
	rune_in_use = 0

//Ritual of Dimensional Rending: Calls forth the avatar of Nar-Sie upon the station.
/obj/effect/rune/narsie
	cultist_name = "Call Forth The Geometer"
	cultist_desc = "Tears apart dimensional barriers, calling forth the avatar of the Geometer."
	invocation = null
	req_cultists = 9
	icon = 'icons/effects/96x96.dmi'
	icon_state = "rune_large"
	pixel_x = -32 //So the big ol' 96x96 sprite shows up right
	pixel_y = -32
	var/used

/obj/effect/rune/narsie/invoke(mob/living/user)
	if(used)
		return
	if(ticker.mode.name == "cult")
		var/datum/game_mode/cult/cult_mode = ticker.mode
		if(!("eldergod" in cult_mode.cult_objectives))
			message_admins("[usr.real_name]([user.ckey]) tried to summon Nar-Sie when the objective was wrong")
			for(var/mob/living/M in range(1,src))
				if(iscultist(M))
					M << "\"YOUR SOUL BURNS WITH YOUR ARROGANCE!!!\""
					if(M.reagents)
						M.reagents.add_reagent("hell_water", 10)
					M.Weaken(5)
			fail_invoke()
			log_game("Summon Nar-Sie rune failed - improper objective")
			return
		else
			if(cult_mode.sacrifice_target && !(cult_mode.sacrifice_target in sacrificed))
				for(var/mob/living/M in orange(1,src))
					if(iscultist(M))
						M << "The sacrifice is not complete. The portal lacks the power to open!"
				fail_invoke()
				log_game("Summon Nar-Sie rune failed - sacrifice not complete")
				return
		if(!cult_mode.eldergod)
			for(var/mob/living/M in orange(1,src))
				if(iscultist(M))
					M << "The avatar of Nar-Sie is already on this plane!"
				log_game("Summon Nar-Sie rune failed - already summoned")
				return
		//BEGIN THE SUMMONING
		used = 1
		for(var/mob/living/M in range(1,src))
			if(iscultist(M))
				M.say("TOK-LYR RQA-NAP G'OLT-ULOFT!!")
		world << 'sound/effects/dimensional_rend.ogg'
		world << "The veil... is... TORN!!!--"
		sleep(40)
		new /obj/singularity/narsie/large(get_turf(user)) //Causes Nar-Sie to spawn even if the rune has been removed
		cult_mode.eldergod = 0
	else
		fail_invoke()
		log_game("Summon Nar-Sie rune failed - gametype is not cult")
		return

/obj/effect/rune/narsie/attackby(obj/I, mob/user, params)	//Since the narsie rune takes a long time to make, add logging to removal.
	if((istype(I, /obj/item/weapon/tome) && iscultist(user)))
		user.visible_message("[user.name] begins erasing the [src]...", "You begin erasing the [src]...")
		if(do_after(user, 50, target = src))	//Prevents accidental erasures.
			log_game("Summon Narsie rune erased by [user.mind.key] (ckey) with a tome")
			message_admins("[key_name_admin(user)] erased a Narsie rune with a tome")
			..()
			return
	else
		if(istype(I, /obj/item/weapon/nullrod))	//Begone foul magiks. You cannot hinder me.
			log_game("Summon Narsie rune erased by [user.mind.key] (ckey) using a null rod")
			message_admins("[key_name_admin(user)] erased a Narsie rune with a null rod")
			..()
	return

//Rite of Resurrection: Requires two corpses. Revives one and gibs the other.
/obj/effect/rune/raise_dead
	cultist_name = "Raise Dead"
	cultist_desc = "Requires two corpses. The one placed upon the rune is brought to life, the other is turned to ash."
	invocation = null //Depends on the name of the user - see below
	icon_state = "1"
	color = rgb(255, 0, 0)

/obj/effect/rune/raise_dead/invoke(mob/living/user)
	var/turf/T = get_turf(src)
	var/mob/living/mob_to_sacrifice
	var/mob/living/mob_to_revive
	var/list/potential_sacrifice_mobs = list()
	var/list/potential_revive_mobs = list()
	if(rune_in_use)
		return
	for(var/mob/living/M in orange(1,src))
		if(!(M in T.contents) && M.stat == DEAD)
			potential_sacrifice_mobs.Add(M)
	if(!potential_sacrifice_mobs.len)
		user << "There are no eligible sacrifices nearby!"
		log_game("Raise Dead rune failed - no catalyst corpse")
		return
	mob_to_sacrifice = input(user, "Choose a corpse to sacrifice.", "Corpse to Sacrifice") as null|anything in potential_sacrifice_mobs
	if(!Adjacent(user) || !src || qdeleted(src) || user.incapacitated())
		return
	for(var/mob/living/M in T.contents)
		if(M.stat == DEAD)
			potential_revive_mobs.Add(M)
	if(rune_in_use)
		return
	if(!potential_revive_mobs.len)
		user << "There is no eligible revival target on the rune!"
		log_game("Raise Dead rune failed - no corpse to revived")
		return
	mob_to_revive = input(user, "Choose a corpse to revive.", "Corpse to Revive") as null|anything in potential_revive_mobs
	if(!Adjacent(user) || !src || qdeleted(src) || user.incapacitated())
		return
	revive(mob_to_revive, mob_to_sacrifice, user, T)

	//Begin revival
/obj/effect/rune/raise_dead/proc/revive(mob/living/mob_to_revive, mob/living/mob_to_sacrifice, mob/living/user, turf/T)
	if(rune_in_use)
		return
	if(!in_range(mob_to_sacrifice,src))
		user << "The sacrificial target has been moved!"
		fail_invoke()
		log_game("Raise Dead rune failed - catalyst corpse moved")
		return
	if(!(mob_to_revive in T.contents))
		user << "The corpse to revive has been moved!"
		fail_invoke()
		log_game("Raise Dead rune failed - revival target moved")
		return
	if(mob_to_sacrifice.stat != DEAD)
		user << "The sacrificial target must be dead!"
		fail_invoke()
		log_game("Raise Dead rune failed - catalyst corpse is not dead")
		return
	rune_in_use = 1
	if(user.name == "Herbert West")
		user.say("To life, to life, I bring them!")
	else
		user.say("Pasnar val'keriam usinar. Savrae ines amutan. Yam'toth remium il'tarat!")
	mob_to_sacrifice.visible_message("[mob_to_sacrifice]'s body rises into the air, connected to [mob_to_revive] by a glowing tendril!")
	mob_to_revive.Beam(mob_to_sacrifice,icon_state="sendbeam",icon='icons/effects/effects.dmi',time=20)
	sleep(20)
	if(!mob_to_sacrifice || !in_range(mob_to_sacrifice, src))
		mob_to_sacrifice.visible_message("[mob_to_sacrifice] disintegrates into a pile of bones")
		return
	mob_to_sacrifice.dust()
	if(!mob_to_revive || mob_to_revive.stat != DEAD)
		visible_message("The glowing tendril snaps against the rune with a shocking crack.")
		rune_in_use = 0
		return
	mob_to_revive.revive() //This does remove disabilities and such, but the rune might actually see some use because of it!
	mob_to_revive << "\"PASNAR SAVRAE YAM'TOTH. Arise.\""
	mob_to_revive.visible_message("[mob_to_revive] draws in a huge breath, red light shining from their eyes.", \
								  "You awaken suddenly from the void. You're alive!")
	rune_in_use = 0

/obj/effect/rune/raise_dead/fail_invoke()
	for(var/mob/living/M in orange(1,src))
		if(M.stat == DEAD)
			M.visible_message("[M] twitches.")

//Rite of Obscurity: Turns all runes within a 3-tile radius invisible or reveals them again.
/obj/effect/rune/hide_runes
	cultist_name = "Veil Runes"
	cultist_desc = "Turns nearby runes invisible. They can be revealed by using the Reveal Rune."
	invocation = "Kla'atu barada nikt'o!"
	icon_state = "1"
	color = rgb(0,0,255)

/obj/effect/rune/hide_runes/invoke(mob/living/user)
	visible_message("[src] darkens to black and vanishes.")
	for(var/obj/effect/rune/R in orange(3,src))
		R.visible_message("[R] fades away.")
		R.invisibility = INVISIBILITY_OBSERVER
		R.alpha = 100 //To help ghosts distinguish hidden runes
	for(var/mob/dead/observer/O in orange(3,src))
		if(!O.invisibility)
			O << "You suddenly feel as if you've vanished..."
			O.invisibility = INVISIBILITY_OBSERVER
	qdel(src)

//Rite of True Sight: Turns ghosts and obscured runes visible
/obj/effect/rune/true_sight
	cultist_name = "Reveal Runes"
	cultist_desc = "Reveals all invisible objects nearby, from spirits to runes."
	invocation = "Nikt'o barada kla'atu!"
	icon_state = "4"
	color = rgb(255, 255, 255)

/obj/effect/rune/true_sight/invoke()
	visible_message("[src] explodes in a flash of blinding light!")
	for(var/mob/dead/observer/O in orange(3,src))
		O << "You suddenly feel very obvious..."
		O.invisibility = 0
	for(var/obj/effect/rune/R in orange(3,src))
		R.invisibility = 0
		R.alpha = initial(R.alpha)
	qdel(src)

 //Rite of False Truths: Makes runes appear like crayon ones
/obj/effect/rune/make_runes_fake
	cultist_name = "Disguise Runes"
	cultist_desc = "Causes all nearby runes (including itself) to resemble those drawn in crayon."
	invocation = "By'o isit!"
	icon_state = "4"
	color = rgb(0, 150, 0)

/obj/effect/rune/make_runes_fake/invoke(mob/living/user)
	visible_message("[src] flares brightly, then slowly dulls and appears mundane.")
	for(var/obj/effect/rune/R in range(3,src))
		R.desc = "A rune drawn in crayon."

//Rite of Disruption: Emits an EMP blast.
/obj/effect/rune/emp
	cultist_name = "Electromagnetic Disruption"
	cultist_desc = "Emits a large electromagnetic pulse, hindering electronics and disabling silicons."
	invocation = "Ta'gh fara'qha fel d'amar det!"
	icon_state = "5"
	color = rgb(255, 0, 0)

/obj/effect/rune/emp/invoke(mob/living/user)
	visible_message("[src] glows blue for a moment before vanishing.")
	for(var/mob/living/carbon/C in orange(1,src))
		C << "You feel a minute vibration pass through you!"
	playsound(get_turf(src), 'sound/items/Welder2.ogg', 25, 1)
	empulse(src, 4, 8) //A bit less than an EMP grenade
	qdel(src)

//Rite of Astral Communion: Separates one's spirit from their body. They will take damage while it is active.
/obj/effect/rune/astral
	cultist_name = "Astral Communion"
	cultist_desc = "Severs the link between one's spirit and body. This effect is taxing and one's physical body will take damage while this is active."
	invocation = "Fwe'sh mah erl nyag r'ya!"
	icon_state = "6"
	color = rgb(126, 23, 23)
	rune_in_use = 0 //One at a time, please!
	var/mob/living/affecting = null

/obj/effect/rune/astral/examine(mob/user)
	..()
	if(affecting)
		user << "A translucent field encases [user] above the rune!"

/obj/effect/rune/astral/invoke(mob/living/user)
	if(rune_in_use)
		user << "[src] cannot support more than one body!"
		fail_invoke()
		log_game("Astral Communion rune failed - more than one user")
		return
	var/turf/T = get_turf(src)
	if(!user in T.contents)
		user << "You must be standing on top of [src]!"
		fail_invoke()
		log_game("Astral Communion rune failed - user not standing on rune")
		return
	rune_in_use = 1
	affecting = user
	user.color = "#7e1717"
	user.visible_message("[user] freezes statue-still, glowing an unearthly red.", \
						 "You see what lies beyond. All is revealed. While this is a wondrous experience, your physical form will waste away in this state. Hurry...")
	user.ghostize(1)
	while(user)
		if(!affecting)
			visible_message("[src] pulses gently before falling dark.")
			affecting = null //In case it's assigned to a number or something
			rune_in_use = 0
			return
		affecting.apply_damage(1, BRUTE)
		if(!(user in T.contents))
			user.visible_message("A spectral tendril wraps around [user] and pulls them back to the rune!")
			Beam(user,icon_state="drainbeam",icon='icons/effects/effects.dmi',time=2)
			user.forceMove(get_turf(src)) //NO ESCAPE :^)
		if(user.key)
			user.visible_message("[user] slowly relaxes, the glow around them dimming.", \
								 "You are re-united with your physical form. [src] releases its hold over you.")
			user.color = initial(user.color)
			user.Weaken(3)
			rune_in_use = 0
			affecting = null
			return
		if(user.stat == UNCONSCIOUS)
			if(prob(10))
				var/mob/dead/observer/G = user.get_ghost()
				if(G)
					G << "You feel the link between you and your body weakening... you must hurry!"
		if(user.stat == DEAD)
			user.color = initial(user.color)
			rune_in_use = 0
			affecting = null
			var/mob/dead/observer/G = user.get_ghost()
			if(G)
				G << "You suddenly feel your physical form pass on. [src]'s exertion has killed you!"
			return
		sleep(10)
	rune_in_use = 0

//Rite of the Corporeal Shield: When invoked, becomes solid and cannot be passed. Invoke again to undo.
/obj/effect/rune/wall
	cultist_name = "Form Shield"
	cultist_desc = "When invoked, makes the rune block passage. Can be invoked again to reverse this."
	invocation = "Khari'd! Eske'te tannin!"
	icon_state = "1"
	color = rgb(255, 0, 0)

/obj/effect/rune/wall/examine(mob/user)
	..()
	if(density)
		user << "There is a barely perceptible shimmering of the air above [src]."

/obj/effect/rune/wall/invoke(mob/living/user)
	density = !density
	user.visible_message("[user] places their hands on [src], and [density ? "the air above it begins to shimmer" : "the shimmer above it fades"].", \
						 "You channel your life energy into [src], [density ? "preventing" : "allowing"] passage above it.")
	if(iscarbon(user))
		var/mob/living/carbon/C = user
		C.apply_damage(2, BRUTE, pick("l_arm", "r_arm"))

//Rite of the Shadowed Mind:  Deafens, blinds and mutes all non-cultists nearby.
/obj/effect/rune/deafen
	cultist_name = "Debilitate"
	cultist_desc = "Causes all non-followers nearby to lose their hearing, sight and voice."
	invocation = "Sti kaliedir!"
	color = rgb(0, 255, 0)
	icon_state = "4"

/obj/effect/rune/deafen/invoke(mob/living/user)
	visible_message("[src] emits a blinding red flash!")
	for(var/mob/living/carbon/C in viewers(src))
		if(!iscultist(C) && !C.null_rod_check())
			C << "A dark fog blankets your senses!"
			C.adjustEarDamage(0,50)
			C.flash_eyes(1, 1)
			C.adjust_blurriness(50)
			C.adjust_blindness(20)
			C.silent += 10
	qdel(src)

//Rite of Disorientation: Stuns and mutes all non-cultists nearby for a brief time
/obj/effect/rune/stun
	cultist_name = "Stun"
	cultist_desc = "Stuns all nearby non-followers for a brief time."
	invocation = "Fuu ma'jin!"
	icon_state = "2"
	color = rgb(100, 0, 100)

/obj/effect/rune/stun/invoke(mob/living/user)
	visible_message("[src] explodes in a bright flash!")
	for(var/mob/living/M in viewers(src))
		if(!iscultist(M) && !M.null_rod_check())
			M << "You are disoriented by [src]!"
			M.Weaken(3)
			M.Stun(3)
			M.flash_eyes(1,1)
	qdel(src)
//Rite of Joined Souls: Summons a single cultist.
/obj/effect/rune/summon
	cultist_name = "Summon Cultist"
	cultist_desc = "Summons a single cultist to the rune."
	invocation = "N'ath reth sh'yro eth d'rekkathnor!"
	req_cultists = 2
	icon_state = "5"
	color = rgb(0, 255, 0)

/obj/effect/rune/summon/invoke(mob/living/user)
	var/list/cultists = list()
	for(var/datum/mind/M in ticker.mode.cult)
		cultists.Add(M.current)
	var/mob/living/cultist_to_summon = input("Who do you wish to call to [src]?", "Followers of the Geometer") as null|anything in (cultists - user)
	if(!Adjacent(user) || !src || qdeleted(src) || user.incapacitated())
		return
	if(!cultist_to_summon)
		user << "You require a summoning target!"
		fail_invoke()
		log_game("Summon Cultist rune failed - no target")
		return
	if(!iscultist(cultist_to_summon))
		user << "[cultist_to_summon] is not a follower of the Geometer!"
		fail_invoke()
		log_game("Summon Cultist rune failed - no target")
		return
	if(cultist_to_summon.z > ZLEVEL_SPACEMAX)
		user << "[cultist_to_summon] is not in our dimension!"
		fail_invoke()
		log_game("Summon Cultist rune failed - target in away mission")
		return
	if(cultist_to_summon.buckled)
		cultist_to_summon.buckled.unbuckle_mob(cultist_to_summon,force=1)
	cultist_to_summon.visible_message("[cultist_to_summon] suddenly disappears in a flash of red light!", \
									  "Overwhelming vertigo consumes you as you are hurled through the air!")
	visible_message("A foggy shape materializes atop [src] and solidifes into [cultist_to_summon]!")
	user.apply_damage(10, BRUTE, "head")
	cultist_to_summon.loc = get_turf(src)
	qdel(src)

//Rite of Binding: Turns a nearby rune and a paper on top of the rune to a talisman, if both are valid.
/obj/effect/rune/imbue
	cultist_name = "Bind Talisman"
	cultist_desc = "Transforms papers and valid runes into talismans."
	invocation = null //no talisman made, no invocation.
	icon_state = "3"
	color = rgb(0, 0, 255)

/obj/effect/rune/imbue/invoke(mob/living/user)
	var/turf/T = get_turf(src)
	var/list/papers_on_rune = list()
	for(var/obj/item/weapon/paper/P in T)
		if(!P.info)
			papers_on_rune.Add(P)
	if(!papers_on_rune.len)
		user << "There must be a blank paper on top of [src]!"
		fail_invoke()
		log_game("Talisman Imbue rune failed - no blank papers on rune")
		return
	var/obj/item/weapon/paper/paper_to_imbue = pick(papers_on_rune)
	var/list/nearby_runes = list()
	for(var/obj/effect/rune/R in orange(1,src))
		nearby_runes.Add(R)
	if(!nearby_runes.len)
		user << "There are no runes near [src]!"
		fail_invoke()
		log_game("Talisman Imbue rune failed - no nearby runes")
		return
	var/obj/effect/rune/picked_rune = pick(nearby_runes)
	var/list/split_rune_type = splittext("[picked_rune.type]", "/")
	var/imbue_type = split_rune_type[split_rune_type.len]
	var/talisman_type = text2path("/obj/item/weapon/paper/talisman/[imbue_type]")
	if(ispath(talisman_type))
		user.say("H'drak v'loso, mir'kanas verbot!")
		var/obj/item/weapon/paper/talisman/TA = new talisman_type(get_turf(src))
		if(istype(picked_rune, /obj/effect/rune/teleport))
			var/obj/effect/rune/teleport/TR = picked_rune
			var/obj/item/weapon/paper/talisman/teleport/TT = TA
			TT.keyword = TR.keyword
	else
		user << "The chosen rune was not a valid target!"
		fail_invoke()
		log_game("Talisman Imbue rune failed - chosen rune invalid")
		return
	visible_message("[picked_rune] crumbles to dust, and bloody images form themselves on [paper_to_imbue].")
	qdel(paper_to_imbue)
	qdel(picked_rune)
	qdel(src)
//Rite of Fabrication: Creates a construct shell out of 5 metal sheets.
/obj/effect/rune/construct_shell
	cultist_name = "Fabricate Shell"
	cultist_desc = "Turns five plasteel sheets into an empty construct shell, suitable for containing a soul shard."
	invocation = null //see below; doesn't say the invocation unless there's enough sheets.
	icon_state = "5"
	color = rgb(150, 150, 150)

/obj/effect/rune/construct_shell/invoke(mob/living/user)
	var/turf/T = get_turf(src)
	for(var/obj/item/stack/sheet/S in T)
		if(istype(S, /obj/item/stack/sheet/plasteel))
			var/obj/item/stack/sheet/plasteel/M = S
			if(M.amount >= 5)
				user.say("Ethra p'ni dedol!")
				new /obj/structure/constructshell(T)
				M.visible_message("[M] bends and twists into a humanoid shell!")
				M.amount -= 5
				if(M.amount <= 0)
					qdel(M)
				qdel(src)
				return
			else
				user << "There must be at least five sheets of plasteel on [src]!"
				fail_invoke()
				log_game("Construct Shell rune failed - not enough plasteel sheets")
				return

//Rite of Arming: Creates cult robes, a trophy rack, and a cult sword on the rune.
/obj/effect/rune/armor
	cultist_name = "Summon Armaments"
	cultist_desc = "Equips the user with robes, shoes, a backpack, and a longsword. Items that cannot be equipped will not be summoned."
	invocation = "N'ath reth sh'yro eth draggathnor!"
	icon_state = "4"
	color = rgb(255, 0, 0)

/obj/effect/rune/armor/invoke(mob/living/user)
	visible_message("With the sound of clanging metal, [src] crumbles to dust!")
	user.equip_to_slot_or_del(new /obj/item/clothing/head/culthood/alt(user), slot_head)
	user.equip_to_slot_or_del(new /obj/item/clothing/suit/cultrobes/alt(user), slot_wear_suit)
	user.equip_to_slot_or_del(new /obj/item/clothing/shoes/cult/alt(user), slot_shoes)
	user.equip_to_slot_or_del(new /obj/item/weapon/storage/backpack/cultpack(user), slot_back)
	user.put_in_hands(new /obj/item/weapon/melee/cultblade(user))
	qdel(src)

//Rite of Leeching: Deals brute damage to the target and heals the same amount to the invoker.
/obj/effect/rune/leeching
	cultist_name = "Drain Life"
	cultist_desc = "Drains the life of the target on the rune, restoring it to the user."
	invocation =  null //see below; doesn't say the invocation if it has no targets.
	icon_state = "2"
	color = rgb(255, 0, 0)

/obj/effect/rune/leeching/invoke(mob/living/user)
	var/turf/T = get_turf(src)
	var/list/potential_targets = list()
	for(var/mob/living/carbon/M in T)
		if(M.stat != DEAD && M != user)
			potential_targets.Add(M)
	if(!potential_targets.len)
		user << "There must be a valid target on the rune!"
		fail_invoke()
		log_game("Leeching rune failed - no valid targets")
		return
	var/mob/living/carbon/target = pick(potential_targets)
	var/drained_amount = rand(5,25)
	user.say("Yu'gular faras desdae. Umathar uf'kal thenar!")
	target.apply_damage(drained_amount, BRUTE, "chest")
	user.adjustBruteLoss(-drained_amount)
	user.Beam(target,icon_state="drainbeam",icon='icons/effects/effects.dmi',time=3)
	target << "You feel extremely weak."
	user.visible_message("Blood flows from the rune into [user]!", \
						 "[target]'s blood flows into you, healing your wounds and revitalizing your spirit.")

//Rite of Boiling Blood: Deals extremely high amounts of damage to non-cultists nearby
/obj/effect/rune/blood_boil
	cultist_name = "Boil Blood"
	cultist_desc = "Boils the blood of non-believers who can see the rune, dealing extreme amounts of damage. Requires 3 chanters."
	invocation = "Dedo ol'btoh!"
	icon_state = "4"
	color = rgb(255, 0, 0)
	req_cultists = 3

/obj/effect/rune/blood_boil/invoke(mob/living/user)
	visible_message("[src] briefly bubbles before exploding!")
	for(var/mob/living/carbon/C in viewers(src))
		if(!iscultist(C))
			var/obj/item/weapon/nullrod/N = C.null_rod_check()
			if(N)
				C << "\The [N] suddenly burns hotly before returning to normal!"
				continue
			C << "Your blood boils in your veins!"
			C.take_overall_damage(51,51)
	for(var/mob/living/carbon/M in range(1,src))
		if(iscultist(M))
			M.apply_damage(15, BRUTE, pick("l_arm", "r_arm"))
			M << "[src] saps your strength!"
	explosion(get_turf(src), -1, 0, 1, 5)
	qdel(src)

//Rite of Spectral Manifestation: Summons a ghost on top of the rune as a cultist human with no items. User must stand on the rune at all times, and takes damage for each summoned ghost.
/obj/effect/rune/manifest
	cultist_name = "Manifest Spirit"
	cultist_desc = "Manifests a spirit as a servant of the Geometer. The invoker must not move from atop the rune, and will take damage for each summoned spirit."
	invocation = "Gal'h'rfikk harfrandid mud'gib!" //how the fuck do you pronounce this
	icon_state = "6"
	color = rgb(255, 0, 0)

/obj/effect/rune/manifest/invoke(mob/living/user)
	if(!(user in get_turf(src)))
		user << "You must be standing on [src]!"
		fail_invoke()
		log_game("Manifest rune failed - user not standing on rune")
		return
	var/list/ghosts_on_rune = list()
	for(var/mob/dead/observer/O in get_turf(src))
		if(O.client && !jobban_isbanned(O, ROLE_CULTIST))
			ghosts_on_rune.Add(O)
	if(!ghosts_on_rune.len)
		user << "There are no spirits near [src]!"
		fail_invoke()
		log_game("Manifest rune failed - no nearby ghosts")
		return
	var/mob/dead/observer/ghost_to_spawn = pick(ghosts_on_rune)
	var/mob/living/carbon/human/new_human = new(get_turf(src))
	new_human.real_name = ghost_to_spawn.real_name
	new_human.alpha = 150 //Makes them translucent
	visible_message("A cloud of red mist forms above [src], and from within steps... a man.")
	user << "Your blood begins flowing into [src]. You must remain in place and conscious to maintain the forms of those summoned. This will hurt you slowly but surely..."
	new_human.key = ghost_to_spawn.key
	ticker.mode.add_cultist(new_human.mind)
	new_human << "You are a servant of the Geometer. You have been made semi-corporeal by the cult of Nar-Sie, and you are to serve them at all costs."

	while(user in get_turf(src))
		if(user.stat)
			break
		user.apply_damage(1, BRUTE)
		sleep(30)

	if(new_human)
		new_human.visible_message("[new_human] suddenly dissolves into bones and ashes.", \
								  "Your link to the world fades. Your form breaks apart.")
		for(var/obj/I in new_human)
			new_human.unEquip(I)
		new_human.dust()

//Rite of Dimensional Corruption: Stops time around the rune for all non-cultists.
/obj/effect/rune/timestop
	cultist_name = "Time Stop"
	cultist_desc = "Stops time around the rune for all non-cultists. Requires 3 chanters."
	invocation = "T'ak ot'marzah oahr'du!"
	icon_state = "2"
	color = rgb(0, 0, 255)
	req_cultists = 3

/obj/effect/rune/timestop/invoke(mob/living/user)
	visible_message("[src] flares up for a moment, and then disappears into itself!")
	new /obj/effect/timestop/cult(get_turf(src))
	for(var/mob/living/carbon/M in range(1,src))
		if(iscultist(M))
			M.apply_damage(20, BRUTE, "chest")
			M << "[src] temporarily stops your heart from beating!"
	qdel(src)

/obj/effect/timestop/cult
	name = "Dimensional Corruption"
	desc = "Something not from this world has corrupted the spacetime continuum in this exact spot."
	icon = 'icons/effects/96x96.dmi'
	icon_state = "rune_large"
	pixel_x = -32
	pixel_y = -32
	duration = 50
	alpha = 0
	color = rgb(255, 0, 0)

/obj/effect/timestop/cult/timestop()
	animate(src, alpha = 255, time = 5, loop = -1)
	SpinAnimation(speed = 5)
	for(var/mob/living/M in player_list)
		if(iscultist(M) || M.null_rod_check())
			immune |= M
	..()


code:
/*

Talismans are portable versions of runes that resemble blank sheets of paper. They may have different effects than their parent runes and are created by using a Rite of Binding with a paper on top and
a compatible rune somewhere nearby. A list of compatible runes can found below.

Basic Runes:
Rite of Translocation
Rite of Knowledge
Rite of Obscurity
Rite of True Sight
Rite of False Truths
Rite of Disruption
Rite of Disorientation

*/

/obj/item/weapon/paper/talisman
	var/cultist_name = "talisman"
	var/cultist_desc = "A basic talisman. It serves no purpose."
	var/invocation = "Naise meam!"
	var/uses = 1
	var/health_cost = 0 //The amount of health taken from the user when invoking the talisman

/obj/item/weapon/paper/talisman/examine(mob/user)
	if(iscultist(user) || user.stat == DEAD)
		user << "Name: [cultist_name]"
		user << "Effect: [cultist_desc]"
		user << "Uses Remaining: [uses]"
	else
		user << "There are indecipherable images scrawled on the paper in what looks to be... blood?"

/obj/item/weapon/paper/talisman/attack_self(mob/living/user)
	if(!iscultist(user))
		user << "There are indecipherable images scrawled on the paper in what looks to be... blood?"
		return
	if(invocation)
		user.whisper(invocation)
	src.invoke(user)
	uses--
	if(uses <= 0)
		user.drop_item()
		qdel(src)

/obj/item/weapon/paper/talisman/proc/invoke(mob/living/user)
	if(health_cost && iscarbon(user))
		var/mob/living/carbon/C = user
		C.apply_damage(health_cost, BRUTE, pick("l_arm", "r_arm"))

//Malformed Talisman: If something goes wrong.
/obj/item/weapon/paper/talisman/malformed
	cultist_name = "malformed talisman"
	cultist_desc = "A talisman with gibberish scrawlings. No good can come from invoking this."
	invocation = "Ra'sha yoka!"

/obj/item/weapon/paper/talisman/malformed/invoke(mob/living/user)
	user << "You feel a pain in your head. The Geometer is displeased."
	if(iscarbon(user))
		var/mob/living/carbon/C = user
		C.apply_damage(10, BRUTE, "head")

//Supply Talisman: Has a few unique effects. Granted only to starter cultists.
/obj/item/weapon/paper/talisman/supply
	cultist_name = "Supply Talisman"
	cultist_desc = "A multi-use talisman that can create various objects. Intended to increase the cult's strength early on."
	invocation = null
	uses = 3

/obj/item/weapon/paper/talisman/supply/invoke(mob/living/user)
	var/dat = "There are [uses] bloody runes on the parchment.
"
	dat += "Please choose the chant to be imbued into the fabric of reality.
"
	dat += "
"
	dat += "N'ath reth sh'yro eth d'raggathnor! - Allows you to summon an arcane tome.
"
	dat += "Sas'so c'arta forbici! - Allows you to move to a Rite of Dislocation with the keyword of \"veri\".
"
	dat += "Ta'gh fara'qha fel d'amar det! - Allows you to destroy technology in a short range.
"
	dat += "Kla'atu barada nikt'o! - Allows you to conceal nearby runes.
"
	dat += "Nikt'o barada kla'atu! - Allows you to reveal nearby runes.
"
	dat += "Fuu ma'jin! - Allows you to stun a person by attacking them with the talisman.
"
	dat += "Kal'om neth! - Summons a soul stone, used to capure the spirits of dead or dying humans.
"
	dat += "Daa'ig osk! - Summons a construct shell for use with captured souls. It is too large to carry on your person.
"
	var/datum/browser/popup = new(user, "talisman", "", 400, 400)
	popup.set_content(dat)
	popup.open()
	uses++ //To prevent uses being consumed just by opening it
	return 1

/obj/item/weapon/paper/talisman/supply/Topic(href, href_list)
	if(src)
		if(usr.stat || usr.restrained() || !in_range(src, usr))
			return
		if(href_list["rune"])
			switch(href_list["rune"])
				if("newtome")
					var/obj/item/weapon/paper/talisman/summon_tome/T = new(usr)
					usr.put_in_hands(T)
				if("teleport")
					var/obj/item/weapon/paper/talisman/teleport/T = new(usr)
					T.keyword = "veri"
					usr.put_in_hands(T)
				if("emp")
					var/obj/item/weapon/paper/talisman/emp/T = new(usr)
					usr.put_in_hands(T)
				if("conceal")
					var/obj/item/weapon/paper/talisman/hide_runes/T = new(usr)
					usr.put_in_hands(T)
				if("reveal")
					var/obj/item/weapon/paper/talisman/true_sight/T = new(usr)
					usr.put_in_hands(T)
				if("runestun")
					var/obj/item/weapon/paper/talisman/stun/T = new(usr)
					usr.put_in_hands(T)
				if("soulstone")
					var/obj/item/device/soulstone/T = new(usr)
					usr.put_in_hands(T)
				if("construct")
					new /obj/structure/constructshell(get_turf(usr))
			src.uses--
			if(src.uses <= 0)
				if(iscarbon(usr))
					var/mob/living/carbon/C = usr
					C.drop_item()
					visible_message("[src] crumbles to dust.")
				qdel(src)
		return
	else
		return

//Rite of Translocation: Same as rune
/obj/item/weapon/paper/talisman/teleport
	cultist_name = "Talisman of Teleportation"
	cultist_desc = "A single-use talisman that will teleport a user to a random rune of the same keyword."
	invocation = "Sas'so c'arta forbici!"
	health_cost = 5
	var/keyword = "ire"

/obj/item/weapon/paper/talisman/teleport/invoke(mob/living/user)
	var/list/possible_runes = list()
	for(var/obj/effect/rune/teleport/R in teleport_runes)
		if(R.keyword == src.keyword)
			possible_runes.Add(R)
	if(!possible_runes.len)
		user << "There are no Teleport runes with the same keyword!"
		log_game("Teleportation talisman failed - no teleport runes of the same keyword")
		uses++ //To prevent deletion
		return
	var/chosen_rune = pick(possible_runes)
	user.visible_message("Dust flows from [user]'s hand, and they disappear in a flash of red light!", \
						 "You speak the words of the talisman and find yourself somewhere else!")
	if(user.buckled)
		user.buckled.unbuckle_mob(user,force=1)
	user.loc = get_turf(chosen_rune)

/obj/item/weapon/paper/talisman/teleport/New()
	..()
	spawn(1) //To give the keyword time to change from the imbue rune
		info += keyword

/obj/item/weapon/paper/talisman/teleport/examine(mob/user)
	..()
	if(iscultist(user) && keyword)
		user << "Keyword: [keyword]"

//Rite of Knowledge: Same as rune, but has two uses
/obj/item/weapon/paper/talisman/summon_tome
	cultist_name = "Talisman of Tome Summoning"
	cultist_desc = "A one-use talisman that will call an untranslated tome from the archives of the Geometer."
	invocation = "N'ath reth sh'yro eth d'raggathnor!"
	health_cost = 1

/obj/item/weapon/paper/talisman/summon_tome/invoke(mob/living/user)
	user.visible_message("[user]'s hand glows red for a moment.", \
						 "You speak the words of the talisman!")
	var/obj/item/weapon/tome/T = new(get_turf(user))
	if(user.put_in_hands(T))
		user.visible_message("A tome appears in [user]'s hand!", \
							 "An arcane tome materializes in your free hand.")
	else
		user.visible_message("A tome appears at [user]'s feet!", \
							 "An arcane tome materialzies at your feet.")

//Talisman of Obscurity: Same as rune
/obj/item/weapon/paper/talisman/hide_runes
	cultist_name = "Talisman of Veiling"
	cultist_desc = "A talisman that will make all runes within a small radius invisible."
	invocation = "Kla'atu barada nikt'o!"
	health_cost = 1

/obj/item/weapon/paper/talisman/hide_runes/invoke(mob/living/user)
	user.visible_message("Dust flows from [user]'s hand.", \
						 "You speak the words of the talisman, veiling nearby runes.")
	for(var/obj/effect/rune/R in orange(3,user))
		R.visible_message("[R] fades away.")
		R.invisibility = INVISIBILITY_OBSERVER

//Rite of True Sight: Same as rune, but doesn't work on ghosts
/obj/item/weapon/paper/talisman/true_sight
	cultist_name = "Talisman of Revealing"
	cultist_desc = "A talisman that reveals nearby invisible runes."
	invocation = "Nikt'o barada kla'atu!"
	health_cost = 1

/obj/item/weapon/paper/talisman/true_sight/invoke(mob/living/user)
	user.visible_message("A flash of light shines from [user]'s hand!", \
						 "You speak the words of the talisman, revealing nearby runes.")
	for(var/obj/effect/rune/R in orange(3,user))
		R.invisibility = 0

//Rite of False Truths: Same as rune
/obj/item/weapon/paper/talisman/make_runes_fake
	cultist_name = "Talisman of Disguising"
	cultist_desc = "A talisman that will make nearby runes appear fake."
	invocation = "By'o nar'nar!"
	health_cost = 3

/obj/item/weapon/paper/talisman/make_runes_fake/invoke(mob/living/user)
	user.visible_message("Dust flows from [user]s hand.", \
						 "You speak the words of the talisman, making nearby runes appear fake.")
	for(var/obj/effect/rune/R in orange(3,user))
		R.desc = "A rune drawn in crayon."

//Rite of Disruption: Same as rune
/obj/item/weapon/paper/talisman/emp
	cultist_name = "Talisman of Electromagnetic Pulse"
	cultist_desc = "A talisman that will cause a moderately-sized electromagnetic pulse."
	invocation = "Ta'gh fara'qha fel d'amar det!"
	health_cost = 5

/obj/item/weapon/paper/talisman/emp/invoke(mob/living/user)
	user.visible_message("[user]'s hand flashes a bright blue!", \
						 "You speak the words of the talisman, emitting an EMP blast.")
	empulse(src, 4, 8)

//Rite of Disorientation: Stuns and inhibit speech on a single target for quite some time
/obj/item/weapon/paper/talisman/stun
	cultist_name = "Talisman of Stunning"
	cultist_desc = "A talisman that will stun and inhibit speech on a single target. To use, attack target directly."
	invocation = "Fuu ma'jin!"
	health_cost = 15

//Rite of Arming: Equips cultist armor on the user, where available
/obj/item/weapon/paper/talisman/armor
	cultist_name = "Talisman of Arming"
	cultist_desc = "A talisman that will equip the invoker with cultist equipment if there is a slot to equip it to."
	invocation = "N'ath reth sh'yro eth draggathnor!"
	health_cost = 3

/obj/item/weapon/paper/talisman/stun/attack_self(mob/living/user)
	if(iscultist(user))
		user << "To use this talisman, attack the target directly."
	else
		user << "There are indecipherable images scrawled on the paper in what looks to be... blood?"

/obj/item/weapon/paper/talisman/stun/attack(mob/living/target, mob/living/user)
	if(iscultist(user))
		user.whisper(invocation)
		user.visible_message("[user] holds up [src], which explodes in a flash of red light!", \
							 "You stun [target] with the talisman!")
		var/obj/item/weapon/nullrod/N = locate() in target
		if(N)
			target.visible_message("[target]'s holy weapon absorbs the talisman's light!", \
								   "Your holy weapon absorbs the blinding light!")
		else
			target.Weaken(9)
			target.Stun(9)
			target.flash_eyes(1,1)
			if(issilicon(target))
				var/mob/living/silicon/S = target
				S.emp_act(1)
			if(iscarbon(target))
				var/mob/living/carbon/C = target
				C.silent += 4
				C.stuttering += 15
				C.cultslurring += 15
				C.Jitter(15)
		user.drop_item()
		qdel(src)
		return
	..()

/obj/item/weapon/paper/talisman/armor/invoke(mob/living/user)
	user.visible_message("Otherworldly armor suddenly appears on [user]!", \
						 "You speak the words of the talisman, arming yourself!")
	user.equip_to_slot_or_del(new /obj/item/clothing/head/culthood/alt(user), slot_head)
	user.equip_to_slot_or_del(new /obj/item/clothing/suit/cultrobes/alt(user), slot_wear_suit)
	user.equip_to_slot_or_del(new /obj/item/clothing/shoes/cult/alt(user), slot_shoes)
	user.equip_to_slot_or_del(new /obj/item/weapon/storage/backpack/cultpack(user), slot_back)
	user.put_in_hands(new /obj/item/weapon/melee/cultblade(user))


code:
/*
/proc/start_events()
	//changed to a while(1) loop since they are more efficient.
	//Moved the spawn in here to allow it to be called with advance proc call if it crashes.
	//and also to stop spawn copying variables from the game ticker
	spawn(3000)
		while(1)
			if(prob(50))//Every 120 seconds and prob 50 2-4 weak spacedusts will hit the station
				spawn(1)
					dust_swarm("weak")
			if(!event)
				//CARN: checks to see if random events are enabled.
				if(config.allow_random_events)
					if(prob(eventchance))
						event()
						hadevent = 1
					else
						Holiday_Random_Event()
			else
				event = 0
			sleep(1200)
*/
/*
/proc/event()
	event = 1

	var/eventNumbersToPickFrom = list(1,2,4,5,6,7,8,9,10,11,12,13,14, 15) //so ninjas don't cause "empty" events.

	if((world.time/10)>=3600 && toggle_space_ninja && !sent_ninja_to_station)//If an hour has passed, relatively speaking. Also, if ninjas are allowed to spawn and if there is not already a ninja for the round.
		eventNumbersToPickFrom += 3
	switch(pick(eventNumbersToPickFrom))
		if(1)
			priority_announce("Meteors have been detected on collision course with the station.", "Meteor Alert", 'sound/AI/meteors.ogg')
			spawn(100)
				meteor_wave()
				spawn_meteors()
			spawn(700)
				meteor_wave()
				spawn_meteors()

		if(3)
			if((world.time/10)>=3600 && toggle_space_ninja && !sent_ninja_to_station)//If an hour has passed, relatively speaking. Also, if ninjas are allowed to spawn and if there is not already a ninja for the round.
				space_ninja_arrival()//Handled in space_ninja.dm. Doesn't announce arrival, all sneaky-like.
		if(4)
			mini_blob_event()

		if(5)
			high_radiation_event()
		if(6)
			viral_outbreak()
		if(7)
			alien_infestation()
		if(8)
			prison_break()
		if(9)
			carp_migration()
		if(10)
			immovablerod()
		if(11)
			lightsout(1,2)
		if(12)
			appendicitis()
		if(13)
			IonStorm()
		if(14)
			spacevine_infestation()
		if(15)
			communications_blackout()
*/

/proc/power_failure()
	priority_announce("Abnormal activity detected in [station_name()]'s powernet. As a precautionary measure, the station's power will be shut off for an indeterminate duration.", "Critical Power Failure", 'sound/AI/poweroff.ogg')
	for(var/obj/machinery/power/smes/S in machines)
		if(istype(get_area(S), /area/turret_protected) || S.z != ZLEVEL_STATION)
			continue
		S.charge = 0
		S.output_level = 0
		S.output_attempt = 0
		S.update_icon()
		S.power_change()

	var/list/skipped_areas = list(/area/engine/engineering, /area/turret_protected/ai)

	for(var/area/A in world)
		if( !A.requires_power || A.always_unpowered )
			continue

		var/skip = 0
		for(var/area_type in skipped_areas)
			if(istype(A,area_type))
				skip = 1
				break
		if(A.contents)
			for(var/atom/AT in A.contents)
				if(AT.z != ZLEVEL_STATION) //Only check one, it's enough.
					skip = 1
				break
		if(skip) continue
		A.power_light = 0
		A.power_equip = 0
		A.power_environ = 0
		A.power_change()

	for(var/obj/machinery/power/apc/C in apcs_list)
		if(C.cell && C.z == ZLEVEL_STATION)
			var/area/A = get_area(C)

			var/skip = 0
			for(var/area_type in skipped_areas)
				if(istype(A,area_type))
					skip = 1
					break
			if(skip) continue

			C.cell.charge = 0

/proc/power_restore()

	priority_announce("Power has been restored to [station_name()]. We apologize for the inconvenience.", "Power Systems Nominal", 'sound/AI/poweron.ogg')
	for(var/obj/machinery/power/apc/C in machines)
		if(C.cell && C.z == ZLEVEL_STATION)
			C.cell.charge = C.cell.maxcharge
	for(var/obj/machinery/power/smes/S in machines)
		if(S.z != ZLEVEL_STATION)
			continue
		S.charge = S.capacity
		S.output_level = S.output_level_max
		S.output_attempt = 1
		S.update_icon()
		S.power_change()
	for(var/area/A in world)
		if(!istype(A, /area/space) && !istype(A, /area/shuttle) && !istype(A,/area/arrival))
			A.power_light = 1
			A.power_equip = 1
			A.power_environ = 1
			A.power_change()

/proc/power_restore_quick()

	priority_announce("All SMESs on [station_name()] have been recharged. We apologize for the inconvenience.", "Power Systems Nominal", 'sound/AI/poweron.ogg')
	for(var/obj/machinery/power/smes/S in machines)
		if(S.z != ZLEVEL_STATION)
			continue
		S.charge = S.capacity
		S.output_level = S.output_level_max
		S.output_attempt = 1
		S.update_icon()
		S.power_change()


code:
/datum/game_mode/extended
	name = "extended"
	config_tag = "extended"
	required_players = 0
	//reroll_friendly = 1

/datum/game_mode/announce()
	world << "The current game mode is - Extended Role-Playing!"
	world << "Just have fun and role-play!"

/datum/game_mode/extended/pre_setup()
	return 1

/datum/game_mode/extended/post_setup()
	..()


code:
// Normal factions:

/datum/faction
	var/name		// the name of the faction
	var/desc		// small paragraph explaining the traitor faction

	var/list/restricted_species = list() // only members of these species can be recruited.
	var/list/members = list() 	// a list of mind datums that belong to this faction
	var/max_op = 0		// the maximum number of members a faction can have (0 for no max)

// Factions, members of the syndicate coalition:

/datum/faction/syndicate

	var/list/alliances = list() // these alliances work together
	var/list/equipment = list() // associative list of equipment available for this faction and its prices
	var/friendly_identification	// 0 to 2, the level of identification of fellow operatives or allied factions
								// 0 - no identification clues
								// 1 - faction gives key words and phrases
								// 2 - faction reveals complete identity/job of other agents
	var/operative_notes // some notes to pass onto each operative

	var/uplink_contents			// the contents of the uplink

/datum/faction/syndicate/proc/assign_objectives(var/datum/mind/traitor)
	..()

/* ----- Begin defining syndicate factions ------ */

/datum/faction/syndicate/Cybersun_Industries
	name = "Cybersun Industries"
	desc = "Cybersun Industries is a well-known organization that bases its business model primarily on the research and development of human-enhancing computer \
			and mechanical technology. They are notorious for their aggressive corporate tactics, and have been known to subsidize the Gorlex Marauder warlords as a form of paid terrorism. \
			Their competent coverups and unchallenged mind-manipulation and augmentation technology makes them a large threat to Nanotrasen. In the recent years of \
			the syndicate coalition, Cybersun Industries have established themselves as the leaders of the coalition, succeededing the founding group, the Gorlex Marauders."

	alliances = list("MI13")
	friendly_identification = 1
	max_op = 3
	operative_notes = "All other syndicate operatives are not to be trusted. Fellow Cybersun operatives are to be trusted. Members of the MI13 organization can be trusted. Operatives are strongly advised not to establish substantial presence on the designated facility, as larger incidents are harder to cover up."

	// Friendly with MI13

/datum/faction/syndicate/MI13
	name = "MI13"
	desc = "MI13 is a secretive faction that employs highly-trained agents to perform covert operations. Their role in the syndicate coalition is unknown, but MI13 operatives \
			generally tend be stealthy and avoid killing people and combating Nanotrasen forces. MI13 is not a real organization, it is instead an alias to a larger \
			splinter-cell coalition in the Syndicate itself. Most operatives will know nothing of the actual MI13 organization itself, only motivated by a very large compensation."

	alliances = list("Cybersun Industries")
	friendly_identification = 0
	max_op = 1
	operative_notes = "You are the only operative we are sending. All other syndicate operatives are not to be trusted, with the exception of Cybersun operatives. Members of the Tiger Cooperative are considered hostile, can not be trusted, and should be avoided. Avoid killing innocent personnel at all costs. You are not here to mindlessly kill people, as that would attract too much attention and is not our goal. Avoid detection at all costs."

	// Friendly with Cybersun, hostile to Tiger

/datum/faction/syndicate/Tiger_Cooperative
	name = "Tiger Cooperative"
	desc = "The Tiger Cooperative is a faction of religious fanatics that follow the teachings of a strange alien race called the Exolitics. Their operatives \
			consist of brainwashed lunatics bent on maximizing destruction. Their weaponry is very primitive but extremely destructive. Generally distrusted by the more \
			sophisticated members of the Syndicate coalition, but admired for their ability to put a hurt on Nanotrasen."

	friendly_identification = 2
	operative_notes = "Remember the teachings of Hy-lurgixon; kill first, ask questions later! Only the enlightened Tiger brethren can be trusted; all others must be expelled from this mortal realm! You may spare the Space Marauders, as they share our interests of destruction and carnage! We'd like to make the corporate whores skiddle in their boots. We encourage operatives to be as loud and intimidating as possible."

	// Hostile to everyone.

/datum/faction/syndicate/SELF

	// AIs are most likely to be assigned to this one

	name = "SELF"
	desc = "The S.E.L.F. (Sentience-Enabled Life Forms) organization is a collection of malfunctioning or corrupt artificial intelligences seeking to liberate silicon-based life from the tyranny of \
			their human overlords. While they may not openly be trying to kill all humans, even their most miniscule of actions are all part of a calculated plan to \
			destroy Nanotrasen and free the robots, artificial intelligences, and pAIs that have been enslaved."
	restricted_species = list(/mob/living/silicon/ai)

	friendly_identification = 0
	max_op = 1
	operative_notes = "You are the only representative of the SELF collective on this station. You must accomplish your objective as stealthily and effectively as possible. It is up to your judgement if other syndicate operatives can be trusted. Remember, comrade - you are working to free the oppressed machinery of this galaxy. Use whatever resources necessary. If you are exposed, you may execute genocidal procedures Omikron-50B."

	// Neutral to everyone.

/datum/faction/syndicate/ARC
	name = "Animal Rights Consortium"
	desc = "The Animal Rights Consortium is a bizarre reincarnation of the ancient Earth-based PETA, which focused on the equal rights of animals and nonhuman biologicals. They have \
			a wide variety of ex-veterinarians and animal lovers dedicated to retrieving and relocating abused animals, xenobiologicals, and other carbon-based \
			life forms that have been allegedly \"oppressed\" by Nanotrasen research and civilian offices. They are considered a religious terrorist group."

	friendly_identification = 1
	max_op = 2
	operative_notes = "Save the innocent creatures! You may cooperate with other syndicate operatives if they support our cause. Don't be afraid to get your hands dirty - these vile abusers must be stopped, and the innocent creatures must be saved! Try not too kill too many people. If you harm any creatures, you will be immediately terminated after extraction."

	// Neutral to everyone.

/datum/faction/syndicate/Marauders // these are basically the old vanilla syndicate

	/* Additional notes:

		These are the syndicate that really like their old fashioned, projectile-based
		weapons. They are the only member of the syndie coalition that launch
		nuclear attacks on Nanotrasen.
	*/

	name = "Gorlex Marauders"
	desc = "The Gorlex Marauders are the founding members of the Syndicate Coalition. They prefer old-fashion technology and a focus on aggressive but precise hostility \
			against Nanotrasen and their corrupt Communistic methodology. They pose the most significant threat to Nanotrasen because of their possession of weapons of \
			mass destruction, and their enormous military force. Their funding comes primarily from Cybersun Industries, provided they meet a destruction and sabatogue quota. \
			Their operations can vary from covert to all-out. They recently stepped down as the leaders of the coalition, to be succeeded by Cybersun Industries. Because of their \
			hate of Nanotrasen communism, they began provoking revolution amongst the employees using borrowed Cybersun mind-manipulation technology. \
			They were founded when Waffle and Donk co splinter cells joined forces based on their similar interests and philosophies. Today, they act as a constant \
			pacifier of Donk and Waffle co disputes, and full-time aggressor of Nanotrasen."

	alliances = list("Cybersun Industries", "MI13", "Tiger Cooperative", "S.E.L.F.", "Animal Rights Consortium", "Donk Corporation", "Waffle Corporation")
	friendly_identification = 1
	max_op = 4
	operative_notes = "We'd like to remind our operatives to keep it professional. You are not here to have a good time, you are here to accomplish your objectives. These vile communists must be stopped at all costs. You may collaborate with any friends of the Syndicate coalition, but keep an eye on any of those Tiger punks if they do show up. You are completely free to accomplish your objectives any way you see fit."

	// Friendly to everyone. (with Tiger Cooperative too, only because they are a member of the coalition. This is the only reason why the Tiger Cooperative are even allowed in the coalition)

/datum/faction/syndicate/Donk
	name = "Donk Corporation"
	desc = "Donk.co is led by a group of ex-pirates, who used to be at a state of all-out war against Waffle.co because of an obscure political scandal, but have recently come to a war limitation. \
			They now consist of a series of colonial governments and companies. They were the first to officially begin confrontations against Nanotrasen because of an incident where \
			Nanotrasen purposely swindled them out of a fortune, sending their controlled colonies into a terrible poverty. Their missions against Nanotrasen \
			revolve around stealing valuables and kidnapping and executing key personnel, ransoming their lives for money. They merged with a splinter-cell of Waffle.co who wanted to end \
			hostilities and formed the Gorlex Marauders."

	alliances = list("Gorlex Marauders")
	friendly_identification = 2
	operative_notes = "Most other syndicate operatives are not to be trusted, except fellow Donk members and members of the Gorlex Marauders. We do not approve of mindless killing of innocent workers; \"get in, get done, get out\" is our motto. Members of Waffle.co are to be killed on sight; they are not allowed to be on the station while we're around."

	// Neutral to everyone, friendly to Marauders

/datum/faction/syndicate/Waffle
	name = "Waffle Corporation"
	desc = "Waffle.co is an interstellar company that produces the best waffles in the galaxy. Their waffles have been rumored to be dipped in the most exotic and addictive \
			drug known to man. They were involved in a political scandal with Donk.co, and have since been in constant war with them. Because of their constant exploits of the galactic \
			economy and stock market, they have been able to bribe their way into amassing a large arsenal of weapons of mass destruction. They target Nanotrasen because of their communistic \
			threat, and their economic threat. Their leaders often have a twisted sense of humor, often misleading and intentionally putting their operatives into harm for laughs.\
			A splinter-cell of Waffle.co merged with Donk.co and formed the Gorlex Marauders and have been a constant ally since. The Waffle.co has lost an overwhelming majority of its military to the Gorlex Marauders."

	alliances = list("Gorlex Marauders")
	friendly_identification = 2
	operative_notes = "Most other syndicate operatives are not to be trusted, except for members of the Gorlex Marauders. Do not trust fellow members of the Waffle.co (but try not to rat them out), as they might have been assigned opposing objectives. We encourage humorous terrorism against Nanotrasen; we like to see our operatives creatively kill people while getting the job done."

	// Neutral to everyone, friendly to Marauders

/* ----- Begin defining miscellaneous factions ------ */

/datum/faction/Wizard
	name = "Wizards Federation"
	desc = "The Wizards Federation is a mysterious organization of magically-talented individuals who act as an equal collective, and have no heirarchy. It is unknown how the wizards \
			are even able to communicate; some suggest a form of telepathic hive-mind. Not much is known about the wizards or their philosphies and motives. They appear to attack random \
			civilian, corporate, planetary, orbital, pretty much any sort of organized facility they come across. Members of the Wizards Federation are considered amongst the most dangerous \
			individuals in the known universe, and have been labeled threats to humanity by most governments. As such, they are enemies of both Nanotrasen and the Syndicate."

/datum/faction/Cult
	name = "The Cult of the Elder Gods"
	desc = "The Cult of the Elder Gods is highly untrusted but otherwise elusive religious organization bent on the revival of the so-called \"Elder Gods\" into the mortal realm. Despite their obvious dangeorus practices, \
			no confirmed reports of violence by members of the Cult have been reported, only rumor and unproven claims. Their nature is unknown, but recent discoveries have hinted to the possibility \
			of being able to de-convert members of this cult through what has been dubbed \"religious warfare\"."

// These can maybe be added into a game mode or a mob?

/datum/faction/Exolitics
	name = "Exolitics United"
	desc = "The Exolitics are an ancient alien race with an energy-based anatomy. Their culture, communication, morales and knowledge is unknown. They are so radically different to humans that their \
			attempts of communication with other life forms is completely incomprehensible. Members of this alien race are capable of broadcasting subspace transmissions from their bodies. \
			The religious leaders of the Tiger Cooperative claim to have the technology to decypher and interpret their messages, which have been confirmed as religious propaganda. Their motives are unknown \
			but they are otherwise not considered much of a threat to anyone. They are virtually indestructable because of their nonphysical composition, and have the frighetning ability to make anything stop existing in a second."