Files
Bubberstation/code/modules/library/random_books.dm
vuonojenmustaturska 772924ba38 More Initialize() fixes, requires someone to test with DB (#30831)
* Batch 1

/obj/item/storage/firstaid/fire
/obj/structure/bookcase
/obj/item/book/random QDEL, not actually in the logs but returned wrong hint
/obj/effect/landmark/start/wizard QDEL
/obj/effect/landmark/start/wizard
/obj/effect/landmark/start/new_player
/obj/effect/landmark/latejoin
/obj/effect/landmark/xeno_spawn
/obj/effect/landmark/blobstart
/obj/effect/landmark/secequipment
/obj/effect/landmark/prisonwarp
/obj/effect/landmark/ert_spawn
/obj/effect/landmark/holding_facility
/obj/effect/landmark/thunderdome/observe
/obj/effect/landmark/thunderdome/one
/obj/effect/landmark/thunderdome/two
/obj/effect/landmark/thunderdome/admin

* Batch 2

/obj/machinery/computer/operating
/obj/machinery/computer/telecrystals/uplinker
/obj/item/card/id/centcom
/obj/item/card/id/syndicate
/obj/item/card/id/captains_spare
/obj/item/card/id/ert
/obj/item/card/id/ert/Security
/obj/item/card/id/ert/Engineer
/obj/item/card/id/ert/Medical
/obj/structure/trap
/obj/machinery/magnetic_controller
/obj/item/storage/toolbox
/obj/structure/table

* Batch 3

/obj/machinery/vending/snack/random
/obj/machinery/vending/cola/random
/obj/machinery/computer/pod
/obj/machinery/computer/message_monitor
/obj/machinery/computer/atmos_control
/obj/item/implanter
/obj/item/implantcase
/obj/item/construction
/turf/open/floor/grass
/turf/open/floor/grass/snow/basalt
/turf/open/floor/grass/fakebasalt
/turf/open/floor/carpet
/turf/open/floor/fakespace
/turf/open/floor/light
/turf/open/floor/mineral
/turf/open/floor/mineral/abductor
/turf/open/floor/circuit
/turf/open/floor/clockwork
/turf/open/floor/plating
/turf/open/floor/engine/cult

* Batch 4

/obj/item/storage/backpack/satchel/flat
/obj/item/storage/backpack/satchel/flat/secret
/turf/closed/indestructible/fakeglass
/turf/closed/mineral/random
/turf/closed/mineral/gibtonite
/turf/closed/mineral
/turf/open/floor
/obj/effect/spawner/lootdrop

* Batch 5

/obj/effect/spawner/lootdrop/maintenance
/obj/effect/spawner/lootdrop/costume
/obj/item/toy/eightball/broken
/obj/item/toy/eightball
/obj/item/toy/eightball/haunted
/obj/item/device/electropack
/obj/item/restraints/legcuffs/beartrap
/obj/machinery/airlock_sensor
/obj/item/storage/box/ingredients

* Batch 6

/mob/living/simple_animal/hostile/carp/ranged
/obj/structure/lattice/clockwork
/obj/structure/lattice/clockwork/large
/obj/structure/lattice/catwalk/clockwork
/mob/living/simple_animal/hostile/mushroom
/mob/living/carbon/alien
/mob/living/carbon/alien/larva
/mob/living/carbon/alien/humanoid
/mob/living/carbon/alien/humanoid/drone
/mob/living/carbon/alien/humanoid/royal/praetorian
/mob/living/carbon/alien/humanoid/sentinel
2017-09-19 08:45:18 -04:00

84 lines
2.7 KiB
Plaintext

/obj/item/book/manual/random/Initialize()
..()
var/static/banned_books = list(/obj/item/book/manual/random, /obj/item/book/manual/nuclear, /obj/item/book/manual/wiki)
var/newtype = pick(subtypesof(/obj/item/book/manual) - banned_books)
new newtype(loc)
return INITIALIZE_HINT_QDEL
/obj/item/book/random
var/amount = 1
var/category = null
/obj/item/book/random/Initialize()
..()
create_random_books(amount, src.loc, TRUE, category)
return INITIALIZE_HINT_QDEL
/obj/item/book/random/triple
amount = 3
/obj/structure/bookcase/random
var/category = null
var/book_count = 2
anchored = TRUE
state = 2
/obj/structure/bookcase/random/Initialize(mapload)
. = ..()
if(!book_count || !isnum(book_count))
update_icon()
return
book_count += pick(-1,-1,0,1,1)
create_random_books(book_count, src, FALSE, category)
update_icon()
/proc/create_random_books(amount = 2, location, fail_loud = FALSE, category = null)
. = list()
if(!isnum(amount) || amount<1)
return
if (!SSdbcore.Connect())
if(fail_loud || prob(5))
var/obj/item/paper/P = new(location)
P.info = "There once was a book from Nantucket<br>But the database failed us, so f*$! it.<br>I tried to be good to you<br>Now this is an I.O.U<br>If you're feeling entitled, well, stuff it!<br><br><font color='gray'>~</font>"
P.update_icon()
return
if(prob(25))
category = null
var/c = category? " AND category='[sanitizeSQL(category)]'" :""
var/datum/DBQuery/query_get_random_books = SSdbcore.NewQuery("SELECT * FROM [format_table_name("library")] WHERE isnull(deleted)[c] GROUP BY title ORDER BY rand() LIMIT [amount];") // isdeleted copyright (c) not me
if(query_get_random_books.Execute())
while(query_get_random_books.NextRow())
var/obj/item/book/B = new(location)
. += B
B.author = query_get_random_books.item[2]
B.title = query_get_random_books.item[3]
B.dat = query_get_random_books.item[4]
B.name = "Book: [B.title]"
B.icon_state= "book[rand(1,8)]"
else
return
/obj/structure/bookcase/random/fiction
name = "bookcase (Fiction)"
category = "Fiction"
/obj/structure/bookcase/random/nonfiction
name = "bookcase (Non-Fiction)"
category = "Non-fiction"
/obj/structure/bookcase/random/religion
name = "bookcase (Religion)"
category = "Religion"
/obj/structure/bookcase/random/adult
name = "bookcase (Adult)"
category = "Adult"
/obj/structure/bookcase/random/reference
name = "bookcase (Reference)"
category = "Reference"
var/ref_book_prob = 20
/obj/structure/bookcase/random/reference/Initialize(mapload)
. = ..()
while(book_count > 0 && prob(ref_book_prob))
book_count--
new /obj/item/book/manual/random(src)