mirror of
https://github.com/Aurorastation/Aurora.3.git
synced 2026-08-22 12:29:46 +01:00
Material Crafting (#9398)
This commit is contained in:
@@ -68,63 +68,65 @@
|
||||
else
|
||||
to_chat(user, "You have enough charge to produce <b>[get_amount()]</b>.")
|
||||
|
||||
/obj/item/stack/attack_self(mob/user as mob)
|
||||
list_recipes(user)
|
||||
/obj/item/stack/attack_self(mob/user)
|
||||
list_recipes(user, recipes)
|
||||
|
||||
/obj/item/stack/proc/list_recipes(mob/user as mob, recipes_sublist)
|
||||
if (!recipes)
|
||||
/obj/item/stack/proc/list_recipes(mob/user, recipes_sublist, var/datum/stack_recipe/sublist)
|
||||
if(!recipes)
|
||||
return
|
||||
if (!src || get_amount() <= 0)
|
||||
if(!src || get_amount() <= 0)
|
||||
user << browse(null, "window=stack")
|
||||
user.set_machine(src) //for correct work of onclose
|
||||
var/list/recipe_list = recipes
|
||||
if (recipes_sublist && recipe_list[recipes_sublist] && istype(recipe_list[recipes_sublist], /datum/stack_recipe_list))
|
||||
var/datum/stack_recipe_list/srl = recipe_list[recipes_sublist]
|
||||
recipe_list = srl.recipes
|
||||
var/t1 = text("<HTML><HEAD><title>Constructions from []</title></HEAD><body><TT>Amount Left: []<br>", src, src.get_amount())
|
||||
for(var/i=1;i<=recipe_list.len,i++)
|
||||
var/E = recipe_list[i]
|
||||
if (isnull(E))
|
||||
t1 += "<hr>"
|
||||
|
||||
var/t1 = "<html><head><title>Constructions from [capitalize_first_letters(src.name)]</title></head><body><tt>Amount Left: [src.get_amount()]<br>"
|
||||
|
||||
if(locate(/datum/stack_recipe_list) in recipes_sublist)
|
||||
t1 += "<h2>Recipe Categories</h2>"
|
||||
for(var/datum/stack_recipe_list/srl in recipes_sublist)
|
||||
t1 += "<a href='?src=\ref[src];sublist=\ref[srl]'>[capitalize_first_letters(srl.title)]</a><br>"
|
||||
|
||||
if(locate(/datum/stack_recipe) in recipes_sublist)
|
||||
var/sublist_title = sublist ? " ([capitalize_first_letters(sublist.title)])" : ""
|
||||
t1 += "<h2>Recipes[sublist_title]</h2>"
|
||||
for(var/datum/stack_recipe/R in recipes_sublist)
|
||||
var/max_multiplier = round(src.get_amount() / R.req_amount)
|
||||
var/title = ""
|
||||
var/can_build = TRUE
|
||||
can_build = (max_multiplier > 0)
|
||||
|
||||
if(R.res_amount > 1)
|
||||
title += "[R.res_amount]x [R.title]\s"
|
||||
else
|
||||
title += "[capitalize_first_letters(R.title)]"
|
||||
|
||||
title += " ([R.req_amount] [src.singular_name]\s)"
|
||||
|
||||
if(can_build)
|
||||
var/sublist_var = sublist ? "\ref[sublist]" : ""
|
||||
t1 += "<a href='?src=\ref[src];make=\ref[R];sublist=[sublist_var];multiplier=1'>[title]</a>"
|
||||
else
|
||||
t1 += "<div class='no-build inline'>[title]</div><br>"
|
||||
continue
|
||||
|
||||
if (i>1 && !isnull(recipe_list[i-1]))
|
||||
t1+="<br>"
|
||||
if(R.max_res_amount > 1 && max_multiplier > 1)
|
||||
max_multiplier = min(max_multiplier, round(R.max_res_amount / R.res_amount))
|
||||
t1 += " |"
|
||||
var/list/multipliers = list(5, 10, 25)
|
||||
for(var/n in multipliers)
|
||||
if(max_multiplier >= n)
|
||||
var/sublist_var = sublist ? "\ref[sublist]" : ""
|
||||
t1 += " <a href='?src=\ref[src];make=\ref[R];sublist=[sublist_var];multiplier=[n]'>[n * R.res_amount]x</a>"
|
||||
if(!(max_multiplier in multipliers))
|
||||
var/sublist_var = sublist ? "\ref[sublist]" : ""
|
||||
t1 += " <a href='?src=\ref[src];make=\ref[R];sublist=[sublist_var];multiplier=[max_multiplier]'>[max_multiplier * R.res_amount]x</a>"
|
||||
t1 += "<br>"
|
||||
|
||||
if (istype(E, /datum/stack_recipe_list))
|
||||
var/datum/stack_recipe_list/srl = E
|
||||
t1 += "<a href='?src=\ref[src];sublist=[i]'>[srl.title]</a>"
|
||||
t1 += "</tt></body></html>"
|
||||
|
||||
if (istype(E, /datum/stack_recipe))
|
||||
var/datum/stack_recipe/R = E
|
||||
var/max_multiplier = round(src.get_amount() / R.req_amount)
|
||||
var/title
|
||||
var/can_build = 1
|
||||
can_build = can_build && (max_multiplier>0)
|
||||
if (R.res_amount>1)
|
||||
title+= "[R.res_amount]x [R.title]\s"
|
||||
else
|
||||
title+= "[R.title]"
|
||||
title+= " ([R.req_amount] [src.singular_name]\s)"
|
||||
if (can_build)
|
||||
t1 += text("<A href='?src=\ref[src];sublist=[recipes_sublist];make=[i];multiplier=1'>[title]</A> ")
|
||||
else
|
||||
t1 += text("[]", title)
|
||||
continue
|
||||
if (R.max_res_amount>1 && max_multiplier>1)
|
||||
max_multiplier = min(max_multiplier, round(R.max_res_amount/R.res_amount))
|
||||
t1 += " |"
|
||||
var/list/multipliers = list(5,10,25)
|
||||
for (var/n in multipliers)
|
||||
if (max_multiplier>=n)
|
||||
t1 += " <A href='?src=\ref[src];make=[i];multiplier=[n]'>[n*R.res_amount]x</A>"
|
||||
if (!(max_multiplier in multipliers))
|
||||
t1 += " <A href='?src=\ref[src];make=[i];multiplier=[max_multiplier]'>[max_multiplier*R.res_amount]x</A>"
|
||||
|
||||
t1 += "</TT></body></HTML>"
|
||||
user << browse(t1, "window=stack")
|
||||
onclose(user, "stack")
|
||||
return
|
||||
var/datum/browser/stack_win = new(user, "stack", capitalize_first_letters(name))
|
||||
stack_win.set_content(t1)
|
||||
stack_win.add_stylesheet("misc", 'html/browser/misc.css')
|
||||
stack_win.open()
|
||||
|
||||
/obj/item/stack/proc/produce_recipe(datum/stack_recipe/recipe, var/quantity, mob/user)
|
||||
var/required = quantity*recipe.req_amount
|
||||
@@ -132,21 +134,21 @@
|
||||
|
||||
if (!can_use(required))
|
||||
if (produced>1)
|
||||
to_chat(user, "<span class='warning'>You haven't got enough [src] to build \the [produced] [recipe.title]\s!</span>")
|
||||
to_chat(user, SPAN_WARNING("You haven't got enough [src] to build \the [produced] [recipe.title]\s!"))
|
||||
else
|
||||
to_chat(user, "<span class='warning'>You haven't got enough [src] to build \the [recipe.title]!</span>")
|
||||
to_chat(user, SPAN_WARNING("You haven't got enough [src] to build \the [recipe.title]!"))
|
||||
return
|
||||
|
||||
if (recipe.one_per_turf && (locate(recipe.result_type) in user.loc))
|
||||
to_chat(user, "<span class='warning'>There is another [recipe.title] here!</span>")
|
||||
to_chat(user, SPAN_WARNING("There is another [recipe.title] here!"))
|
||||
return
|
||||
|
||||
if (recipe.on_floor && !isfloor(user.loc))
|
||||
to_chat(user, "<span class='warning'>\The [recipe.title] must be constructed on the floor!</span>")
|
||||
to_chat(user, SPAN_WARNING("\The [recipe.title] must be constructed on the floor!"))
|
||||
return
|
||||
|
||||
to_chat(user, SPAN_NOTICE("Building [recipe.title]..."))
|
||||
if (recipe.time)
|
||||
to_chat(user, "<span class='notice'>Building [recipe.title] ...</span>")
|
||||
if (!do_after(user, recipe.time))
|
||||
return
|
||||
|
||||
@@ -170,32 +172,27 @@
|
||||
|
||||
/obj/item/stack/Topic(href, href_list)
|
||||
..()
|
||||
if ((usr.restrained() || usr.stat || usr.get_active_hand() != src))
|
||||
if((usr.restrained() || usr.stat || usr.get_active_hand() != src))
|
||||
return
|
||||
|
||||
if (href_list["sublist"] && !href_list["make"])
|
||||
list_recipes(usr, text2num(href_list["sublist"]))
|
||||
if(href_list["sublist"] && !href_list["make"])
|
||||
var/datum/stack_recipe_list/recipe_list = locate(href_list["sublist"]) in recipes
|
||||
list_recipes(usr, recipe_list.recipes, recipe_list)
|
||||
|
||||
if (href_list["make"])
|
||||
if (src.get_amount() < 1) qdel(src) //Never should happen
|
||||
if(href_list["make"])
|
||||
if(src.get_amount() < 1)
|
||||
qdel(src) //Never should happen
|
||||
|
||||
var/list/recipes_list = recipes
|
||||
if (href_list["sublist"])
|
||||
var/datum/stack_recipe_list/srl = recipes_list[text2num(href_list["sublist"])]
|
||||
recipes_list = srl.recipes
|
||||
|
||||
var/datum/stack_recipe/R = recipes_list[text2num(href_list["make"])]
|
||||
var/datum/stack_recipe/R = locate(href_list["make"]) in recipes
|
||||
if(href_list["sublist"])
|
||||
var/datum/stack_recipe_list/recipe_list = locate(href_list["sublist"]) in recipes
|
||||
R = locate(href_list["make"]) in recipe_list.recipes
|
||||
var/multiplier = text2num(href_list["multiplier"])
|
||||
if (!multiplier || (multiplier <= 0)) //href exploit protection
|
||||
if(!multiplier || (multiplier <= 0)) //href exploit protection
|
||||
return
|
||||
|
||||
src.produce_recipe(R, multiplier, usr)
|
||||
|
||||
if (src && usr.machine==src) //do not reopen closed window
|
||||
spawn( 0 )
|
||||
src.interact(usr)
|
||||
return
|
||||
return
|
||||
produce_recipe(R, multiplier, usr)
|
||||
updateUsrDialog()
|
||||
|
||||
//Return 1 if an immediate subsequent call to use() would succeed.
|
||||
//Ensures that code dealing with stacks uses the same logic
|
||||
@@ -318,7 +315,7 @@
|
||||
continue
|
||||
var/transfer = src.transfer_to(item)
|
||||
if (transfer)
|
||||
to_chat(user, "<span class='notice'>You add a new [item.singular_name] to the stack. It now contains [item.amount] [item.singular_name]\s.</span>")
|
||||
to_chat(user, SPAN_NOTICE("You add a new [item.singular_name] to the stack. It now contains [item.amount] [item.singular_name]\s."))
|
||||
if(!amount)
|
||||
break
|
||||
|
||||
@@ -368,16 +365,16 @@
|
||||
var/on_floor = 0
|
||||
var/use_material
|
||||
|
||||
New(title, result_type, req_amount = 1, res_amount = 1, max_res_amount = 1, time = 0, one_per_turf = 0, on_floor = 0, supplied_material = null)
|
||||
src.title = title
|
||||
src.result_type = result_type
|
||||
src.req_amount = req_amount
|
||||
src.res_amount = res_amount
|
||||
src.max_res_amount = max_res_amount
|
||||
src.time = time
|
||||
src.one_per_turf = one_per_turf
|
||||
src.on_floor = on_floor
|
||||
src.use_material = supplied_material
|
||||
/datum/stack_recipe/New(title, result_type, req_amount = 1, res_amount = 1, max_res_amount = 1, time = 0, one_per_turf = 0, on_floor = 0, supplied_material = null)
|
||||
src.title = title
|
||||
src.result_type = result_type
|
||||
src.req_amount = req_amount
|
||||
src.res_amount = res_amount
|
||||
src.max_res_amount = max_res_amount
|
||||
src.time = time
|
||||
src.one_per_turf = one_per_turf
|
||||
src.on_floor = on_floor
|
||||
src.use_material = supplied_material
|
||||
|
||||
/*
|
||||
* Recipe list datum
|
||||
@@ -385,6 +382,7 @@
|
||||
/datum/stack_recipe_list
|
||||
var/title = "ERROR"
|
||||
var/list/recipes = null
|
||||
New(title, recipes)
|
||||
src.title = title
|
||||
src.recipes = recipes
|
||||
|
||||
/datum/stack_recipe_list/New(new_title, new_recipes)
|
||||
src.title = new_title
|
||||
src.recipes = new_recipes
|
||||
Reference in New Issue
Block a user