From ff5901cadbfb8d6a9ac54fb4d5718eee30d919a2 Mon Sep 17 00:00:00 2001 From: kappa-sama <44128284+kappa-sama@users.noreply.github.com> Date: Wed, 8 Jan 2020 16:50:40 -0500 Subject: [PATCH] hi --- code/game/machinery/toylathe.dm | 389 ++++++++++++++++++++++++++++++++ 1 file changed, 389 insertions(+) create mode 100644 code/game/machinery/toylathe.dm diff --git a/code/game/machinery/toylathe.dm b/code/game/machinery/toylathe.dm new file mode 100644 index 0000000000..ecd2132a9d --- /dev/null +++ b/code/game/machinery/toylathe.dm @@ -0,0 +1,389 @@ +#define AUTOYLATHE_MAIN_MENU 1 +#define AUTOYLATHE_CATEGORY_MENU 2 +#define AUTOYLATHE_SEARCH_MENU 3 + +/obj/machinery/autoylathe + name = "autoylathe" + desc = "It produces toys using plastic, metal and glass." + icon_state = "autolathe" + density = TRUE + use_power = IDLE_POWER_USE + idle_power_usage = 10 + active_power_usage = 100 + circuit = /obj/item/circuitboard/machine/autoylathe + layer = BELOW_OBJ_LAYER + + var/operating = FALSE + var/list/L = list() + var/list/LL = list() + var/hacked = FALSE + var/disabled = 0 + var/shocked = FALSE + var/hack_wire + var/disable_wire + var/shock_wire + + var/busy = FALSE + var/prod_coeff = 1 + + var/datum/design/being_built + var/datum/techweb/stored_research + var/list/datum/design/matching_designs + var/selected_category + var/screen = 1 + + var/list/categories = list( + "Toys", + "Figurines", + "Pistols", + "Rifles", + "Heavy", + "Melee", + "Armor", + "Adult", + "Misc", + "Imported" + ) + +/obj/machinery/autoylathe/Initialize() + AddComponent(/datum/component/material_container, list(MAT_METAL, MAT_GLASS, MAT_PLASTIC), 0, TRUE, null, null, CALLBACK(src, .proc/AfterMaterialInsert)) + . = ..() + + wires = new /datum/wires/autoylathe(src) + stored_research = new /datum/techweb/specialized/autounlocking/autoylathe + matching_designs = list() + +/obj/machinery/autoylathe/Destroy() + QDEL_NULL(wires) + return ..() + +/obj/machinery/autoylathe/ui_interact(mob/user) + . = ..() + if(!is_operational()) + return + + if(shocked && !(stat & NOPOWER)) + shock(user,50) + + var/dat + + switch(screen) + if(AUTOYLATHE_MAIN_MENU) + dat = main_win(user) + if(AUTOYLATHE_CATEGORY_MENU) + dat = category_win(user,selected_category) + if(AUTOYLATHE_SEARCH_MENU) + dat = search_win(user) + + var/datum/browser/popup = new(user, "Autoylathe", name, 400, 500) + popup.set_content(dat) + popup.open() + +/obj/machinery/autoylathe/on_deconstruction() + var/datum/component/material_container/materials = GetComponent(/datum/component/material_container) + materials.retrieve_all() + +/obj/machinery/autoylathe/attackby(obj/item/O, mob/user, params) + if (busy) + to_chat(user, "The autoylathe is busy. Please wait for completion of previous operation.") + return TRUE + + if(default_deconstruction_screwdriver(user, "autolathe_t", "autolathe", O)) + updateUsrDialog() + return TRUE + + if(default_deconstruction_crowbar(O)) + return TRUE + + if(panel_open && is_wire_tool(O)) + wires.interact(user) + return TRUE + + if(user.a_intent == INTENT_HARM) //so we can hit the machine + return ..() + + if(stat) + return TRUE + + if(istype(O, /obj/item/disk/design_disk)) + user.visible_message("[user] begins to load \the [O] in \the [src]...", + "You begin to load a design from \the [O]...", + "You hear the chatter of a floppy drive.") + busy = TRUE + var/obj/item/disk/design_disk/D = O + if(do_after(user, 14.4, target = src)) + for(var/B in D.blueprints) + if(B) + stored_research.add_design(B) + busy = FALSE + return TRUE + + return ..() + +/obj/machinery/autoylathe/proc/AfterMaterialInsert(type_inserted, id_inserted, amount_inserted) + if(ispath(type_inserted, /obj/item/stack/ore/bluespace_crystal)) + use_power(amount_inserted / 10) + else + switch(id_inserted) + if (MAT_METAL) + flick("autolathe_o",src)//plays metal insertion animation + if (MAT_GLASS) + flick("autolathe_r",src)//plays glass insertion animation + if (MAT_PLASTIC) + flick("autolathe_o",src)//plays metal insertion animation + use_power(amount_inserted / 10) + updateUsrDialog() + +/obj/machinery/autoylathe/Topic(href, href_list) + if(..()) + return + if (!busy) + if(href_list["menu"]) + screen = text2num(href_list["menu"]) + updateUsrDialog() + + if(href_list["category"]) + selected_category = href_list["category"] + updateUsrDialog() + + if(href_list["make"]) + + ///////////////// + //href protection + being_built = stored_research.isDesignResearchedID(href_list["make"]) + if(!being_built) + return + + var/multiplier = text2num(href_list["multiplier"]) + var/is_stack = ispath(being_built.build_path, /obj/item/stack) + multiplier = CLAMP(multiplier,1,50) + + ///////////////// + + var/coeff = (is_stack ? 1 : prod_coeff) //stacks are unaffected by production coefficient + var/metal_cost = being_built.materials[MAT_METAL] + var/glass_cost = being_built.materials[MAT_GLASS] + var/plastic_cost = being_built.materials[MAT_PLASTIC] + var/power = max(2000, (metal_cost+glass_cost+plastic_cost)*multiplier/5) + + var/datum/component/material_container/materials = GetComponent(/datum/component/material_container) + if((materials.amount(MAT_METAL) >= metal_cost*multiplier*coeff) && (materials.amount(MAT_GLASS) >= glass_cost*multiplier*coeff) && (materials.amount(MAT_PLASTIC) >= plastic_cost*multiplier*coeff)) + busy = TRUE + use_power(power) + icon_state = "autolathe_n" + var/time = is_stack ? 32 : 32*coeff*multiplier + addtimer(CALLBACK(src, .proc/make_item, power, metal_cost, glass_cost, plastic_cost, multiplier, coeff, is_stack), time) + + if(href_list["search"]) + matching_designs.Cut() + + for(var/v in stored_research.researched_designs) + var/datum/design/D = SSresearch.techweb_design_by_id(v) + if(findtext(D.name,href_list["to_search"])) + matching_designs.Add(D) + updateUsrDialog() + else + to_chat(usr, "The autoylathe is busy. Please wait for completion of previous operation.") + + updateUsrDialog() + + return + +/obj/machinery/autoylathe/proc/make_item(power, metal_cost, glass_cost, plastic_cost, multiplier, coeff, is_stack) + var/datum/component/material_container/materials = GetComponent(/datum/component/material_container) + var/atom/A = drop_location() + use_power(power) + var/list/materials_used = list(MAT_METAL=metal_cost*coeff*multiplier, MAT_GLASS=glass_cost*coeff*multiplier, MAT_PLASTIC=plastic_cost*coeff*multiplier) + materials.use_amount(materials_used) + + if(is_stack) + var/obj/item/stack/N = new being_built.build_path(A, multiplier) + N.update_icon() + N.autoylathe_crafted(src) + else + for(var/i=1, i<=multiplier, i++) + var/obj/item/new_item = new being_built.build_path(A) + new_item.materials = new_item.materials.Copy() + for(var/mat in materials_used) + new_item.materials[mat] = materials_used[mat] / multiplier + new_item.autoylathe_crafted(src) + icon_state = "autolathe" + busy = FALSE + updateDialog() + +/obj/machinery/autoylathe/RefreshParts() + var/T = 0 + for(var/obj/item/stock_parts/matter_bin/MB in component_parts) + T += MB.rating*75000 + var/datum/component/material_container/materials = GetComponent(/datum/component/material_container) + materials.max_amount = T + T=1.2 + for(var/obj/item/stock_parts/manipulator/M in component_parts) + T -= M.rating*0.2 + prod_coeff = CLAMP(T,1,0) // Coeff going 1 -> 0,8 -> 0,6 -> 0,4 + +/obj/machinery/autoylathe/proc/main_win(mob/user) + var/dat = "
| [C] | " + line_length++ + + dat += "