start_lathe timer

This commit is contained in:
nicetoolbox
2020-10-03 16:00:34 -07:00
parent 7bfff58da5
commit 93e1ebb71f
+78 -75
View File
@@ -379,6 +379,83 @@ won't update every console in existence) but it's more of a hassle to do. Also,
/obj/machinery/computer/rdconsole/proc/start_lathe(mob/usr, design_id, amount)
if(!linked_lathe)
return
if(linked_lathe.busy)
to_chat(usr, "<span class='danger'>[linked_lathe] is busy at the moment.</span>")
return
var/coeff = linked_lathe.efficiency_coeff
var/datum/design/being_built = files.known_designs[design_id]
if(!being_built)
return
var/power = BUILD_POWER
if(being_built.make_reagents.len)
return FALSE
amount = max(1, min(10, amount))
for(var/M in being_built.materials)
power += round(being_built.materials[M] * amount / 5)
power = max(BUILD_POWER, power)
var/key = usr.key //so we don't lose the info during the spawn delay
if(!(being_built.build_type & PROTOLATHE))
message_admins("Protolathe exploit attempted by [key_name(usr, TRUE)]!")
return
var/new_coeff = coeff * being_built.lathe_time_factor
var/time_to_construct = PROTOLATHE_CONSTRUCT_DELAY * new_coeff * amount ** 0.8
var/enough_materials = TRUE
add_wait_message("Constructing Prototype. Please Wait...", time_to_construct)
linked_lathe.busy = TRUE
flick("protolathe_n", linked_lathe)
use_power(power)
var/list/efficient_mats = list()
for(var/MAT in being_built.materials)
efficient_mats[MAT] = being_built.materials[MAT] * coeff
if(!linked_lathe.materials.has_materials(efficient_mats, amount))
atom_say("Not enough materials to complete prototype.")
enough_materials = FALSE
else
for(var/R in being_built.reagents_list)
if(!linked_lathe.reagents.has_reagent(R, being_built.reagents_list[R]) * coeff)
atom_say("Not enough reagents to complete prototype.")
enough_materials = FALSE
if(enough_materials)
linked_lathe.materials.use_amount(efficient_mats, amount)
for(var/R in being_built.reagents_list)
linked_lathe.reagents.remove_reagent(R, being_built.reagents_list[R] * coeff)
addtimer(CALLBACK(src, .proc/finish_lathe, key, being_built, enough_materials, amount, efficient_mats), time_to_construct)
/obj/machinery/computer/rdconsole/proc/finish_lathe(key, datum/design/being_built, enough_materials, amount, list/efficient_mats)
if(!linked_lathe || !being_built)
return
if(enough_materials) //And if we only fail the material requirements, we still spend time and power
for(var/i in 1 to amount)
var/obj/item/new_item = new being_built.build_path(src)
if(istype(new_item, /obj/item/storage/backpack/holding))
new_item.investigate_log("built by [key]","singulo")
if(!istype(new_item, /obj/item/stack/sheet)) // To avoid materials dupe glitches
new_item.materials = efficient_mats.Copy()
if(being_built.locked)
var/obj/item/storage/lockbox/research/L = new/obj/item/storage/lockbox/research(linked_lathe.loc)
new_item.forceMove(L)
L.name += " ([new_item.name])"
L.origin_tech = new_item.origin_tech
L.req_access = being_built.access_requirement
var/list/lockbox_access
for(var/A in L.req_access)
lockbox_access += "[get_access_desc(A)] "
L.desc = "A locked box. It is locked to [lockbox_access]access."
else
new_item.loc = linked_lathe.loc
clear_wait_message()
linked_lathe.busy = FALSE
SStgui.update_uis(src)
/obj/machinery/computer/rdconsole/tgui_act(action, list/params)
if(..())
return
@@ -513,81 +590,7 @@ won't update every console in existence) but it's more of a hassle to do. Also,
sync = !sync
if("build") //Causes the Protolathe to build something.
if(!linked_lathe)
return
if(linked_lathe.busy)
to_chat(usr, "<span class='danger'>[linked_lathe] is busy at the moment.</span>")
return
var/coeff = linked_lathe.efficiency_coeff
var/datum/design/being_built = files.known_designs[params["id"]]
if(!being_built)
return
var/power = BUILD_POWER
var/amount = text2num(params["amount"])
if(being_built.make_reagents.len)
return FALSE
amount = max(1, min(10, amount))
for(var/M in being_built.materials)
power += round(being_built.materials[M] * amount / 5)
power = max(BUILD_POWER, power)
var/key = usr.key //so we don't lose the info during the spawn delay
if(!(being_built.build_type & PROTOLATHE))
message_admins("Protolathe exploit attempted by [key_name(usr, TRUE)]!")
return
var/new_coeff = coeff * being_built.lathe_time_factor
var/time_to_construct = PROTOLATHE_CONSTRUCT_DELAY * new_coeff * amount ** 0.8
var/enough_materials = TRUE
add_wait_message("Constructing Prototype. Please Wait...", time_to_construct)
linked_lathe.busy = TRUE
flick("protolathe_n", linked_lathe)
use_power(power)
var/list/efficient_mats = list()
for(var/MAT in being_built.materials)
efficient_mats[MAT] = being_built.materials[MAT] * coeff
if(!linked_lathe.materials.has_materials(efficient_mats, amount))
atom_say("Not enough materials to complete prototype.")
enough_materials = FALSE
else
for(var/R in being_built.reagents_list)
if(!linked_lathe.reagents.has_reagent(R, being_built.reagents_list[R]) * coeff)
atom_say("Not enough reagents to complete prototype.")
enough_materials = FALSE
if(enough_materials)
linked_lathe.materials.use_amount(efficient_mats, amount)
for(var/R in being_built.reagents_list)
linked_lathe.reagents.remove_reagent(R, being_built.reagents_list[R] * coeff)
var/P = being_built.build_path //lets save these values before the spawn() just in case. Nobody likes runtimes.
var/O = being_built.locked
spawn(time_to_construct)
if(enough_materials) //And if we only fail the material requirements, we still spend time and power
for(var/i in 1 to amount)
var/obj/item/new_item = new P(src)
if(istype(new_item, /obj/item/storage/backpack/holding))
new_item.investigate_log("built by [key]","singulo")
if(!istype(new_item, /obj/item/stack/sheet)) // To avoid materials dupe glitches
new_item.materials = efficient_mats.Copy()
if(O)
var/obj/item/storage/lockbox/research/L = new/obj/item/storage/lockbox/research(linked_lathe.loc)
new_item.forceMove(L)
L.name += " ([new_item.name])"
L.origin_tech = new_item.origin_tech
L.req_access = being_built.access_requirement
var/list/lockbox_access
for(var/A in L.req_access)
lockbox_access += "[get_access_desc(A)] "
L.desc = "A locked box. It is locked to [lockbox_access]access."
else
new_item.loc = linked_lathe.loc
clear_wait_message()
linked_lathe.busy = FALSE
SStgui.update_uis(src)
start_lathe(usr, params["id"], text2num(params["amount"]))
if("imprint") //Causes the Circuit Imprinter to build something.
var/coeff = linked_imprinter.efficiency_coeff