<commit_before>/* Library Items
 *
 * Contains:
 *		Bookcase
 *		Book
 *		Barcode Scanner
 */

/*
 * Bookcase
 */

/obj/structure/bookcase
	name = "bookcase"
	icon = 'icons/obj/library.dmi'
	icon_state = "bookempty"
	anchored = 0
	density = 1
	opacity = 0
	var/state = 0


/obj/structure/bookcase/initialize()
	state = 2
	icon_state = "book-0"
	anchored = 1
	for(var/obj/item/I in loc)
		if(istype(I, /obj/item/weapon/book))
			I.loc = src
	update_icon()


/obj/structure/bookcase/attackby(obj/item/I, mob/user)
	switch(state)
		if(0)
			if(istype(I, /obj/item/weapon/wrench))
				playsound(loc, 'sound/items/Ratchet.ogg', 100, 1)
				if(do_after(user, 20))
					user << "<span class='notice'>You wrench the frame into place.</span>"
					anchored = 1
					state = 1
			if(istype(I, /obj/item/weapon/crowbar))
				playsound(loc, 'sound/items/Crowbar.ogg', 100, 1)
				if(do_after(user, 20))
					user << "<span class='notice'>You pry the frame apart.</span>"
					new /obj/item/stack/sheet/mineral/wood(loc, 4)
					qdel(src)

		if(1)
			if(istype(I, /obj/item/stack/sheet/mineral/wood))
				var/obj/item/stack/sheet/mineral/wood/W = I
				W.use(2)
				user << "<span class='notice'>You add a shelf.</span>"
				state = 2
				icon_state = "book-0"
			if(istype(I, /obj/item/weapon/wrench))
				playsound(loc, 'sound/items/Ratchet.ogg', 100, 1)
				user << "<span class='notice'>You unwrench the frame.</span>"
				anchored = 0
				state = 0

		if(2)
			if(istype(I, /obj/item/weapon/book) || istype(I, /obj/item/weapon/spellbook))
				user.drop_item()
				I.loc = src
				update_icon()
			else if(istype(I, /obj/item/weapon/storage/bag/books))
				var/obj/item/weapon/storage/bag/books/B = I
				for(var/obj/item/T in B.contents)
					if(istype(T, /obj/item/weapon/book) || istype(T, /obj/item/weapon/spellbook))
						B.remove_from_storage(T, src)
				user << "<span class='notice'>You empty \the [I] into \the [src].</span>"
				update_icon()
			else if(istype(I, /obj/item/weapon/pen))
				var/newname = stripped_input(usr, "What would you like to title this bookshelf?")
				if(!newname)
					return
				else
					name = ("bookcase ([sanitize(newname)])")
			else if(istype(I, /obj/item/weapon/crowbar))
				if(contents.len)
					user << "<span class='notice'>You need to remove the books first.</span>"
				else
					playsound(loc, 'sound/items/Crowbar.ogg', 100, 1)
					user << "<span class='notice'>You pry the shelf out.</span>"
					new /obj/item/stack/sheet/mineral/wood(loc, 1)
					state = 1
					icon_state = "bookempty"
			else
				..()


/obj/structure/bookcase/attack_hand(mob/user)
	if(contents.len)
		var/obj/item/weapon/book/choice = input("Which book would you like to remove from the shelf?") as null|obj in contents
		if(choice)
			if(!usr.canmove || usr.stat || usr.restrained() || !in_range(loc, usr))
				return
			if(ishuman(user))
				if(!user.get_active_hand())<commit_msg>Fixes wood duplicating exploit with bookcase<commit_after>/* Library Items
 *
 * Contains:
 *		Bookcase
 *		Book
 *		Barcode Scanner
 */

/*
 * Bookcase
 */

/obj/structure/bookcase
	name = "bookcase"
	icon = 'icons/obj/library.dmi'
	icon_state = "bookempty"
	anchored = 0
	density = 1
	opacity = 0
	var/state = 0


/obj/structure/bookcase/initialize()
	state = 2
	icon_state = "book-0"
	anchored = 1
	for(var/obj/item/I in loc)
		if(istype(I, /obj/item/weapon/book))
			I.loc = src
	update_icon()


/obj/structure/bookcase/attackby(obj/item/I, mob/user)
	switch(state)
		if(0)
			if(istype(I, /obj/item/weapon/wrench))
				playsound(loc, 'sound/items/Ratchet.ogg', 100, 1)
				if(do_after(user, 20))
					user << "<span class='notice'>You wrench the frame into place.</span>"
					anchored = 1
					state = 1
			if(istype(I, /obj/item/weapon/crowbar))
				playsound(loc, 'sound/items/Crowbar.ogg', 100, 1)
				if(do_after(user, 20))
					user << "<span class='notice'>You pry the frame apart.</span>"
					new /obj/item/stack/sheet/mineral/wood(loc, 4)
					qdel(src)

		if(1)
			if(istype(I, /obj/item/stack/sheet/mineral/wood))
				var/obj/item/stack/sheet/mineral/wood/W = I
				if(W.get_amount() >= 2)
					W.use(2)
					user << "<span class='notice'>You add a shelf.</span>"
					state = 2
					icon_state = "book-0"
			if(istype(I, /obj/item/weapon/wrench))
				playsound(loc, 'sound/items/Ratchet.ogg', 100, 1)
				user << "<span class='notice'>You unwrench the frame.</span>"
				anchored = 0
				state = 0

		if(2)
			if(istype(I, /obj/item/weapon/book) || istype(I, /obj/item/weapon/spellbook))
				user.drop_item()
				I.loc = src
				update_icon()
			else if(istype(I, /obj/item/weapon/storage/bag/books))
				var/obj/item/weapon/storage/bag/books/B = I
				for(var/obj/item/T in B.contents)
					if(istype(T, /obj/item/weapon/book) || istype(T, /obj/item/weapon/spellbook))
						B.remove_from_storage(T, src)
				user << "<span class='notice'>You empty \the [I] into \the [src].</span>"
				update_icon()
			else if(istype(I, /obj/item/weapon/pen))
				var/newname = stripped_input(usr, "What would you like to title this bookshelf?")
				if(!newname)
					return
				else
					name = ("bookcase ([sanitize(newname)])")
			else if(istype(I, /obj/item/weapon/crowbar))
				if(contents.len)
					user << "<span class='notice'>You need to remove the books first.</span>"
				else
					playsound(loc, 'sound/items/Crowbar.ogg', 100, 1)
					user << "<span class='notice'>You pry the shelf out.</span>"
					new /obj/item/stack/sheet/mineral/wood(loc, 2)
					state = 1
					icon_state = "bookempty"
			else
				..()


/obj/structure/bookcase/attack_hand(mob/user)
	if(contents.len)
		var/obj/item/weapon/book/choice = input("Which book would you like to remove from the shelf?") as null|obj in contents
		if(choice)
			if(!usr.canmove || usr.stat || usr.restrained() || !in_range(loc, usr))
				return
			if(ishuman(user))
				if(!user.get_active_hand())
{'fraction_non_alphanumeric': 0.16754729844895178, 'fraction_numerical': 0.013806033748082496, 'mean_word_length': 3.092050209205021, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6794172', 'n_tokens_mistral': 2714, 'n_tokens_neox': 2253, 'n_words': 456}