This commit is contained in:
+52
-81
@@ -1,21 +1,18 @@
|
||||
/datum/component/personal_crafting/Initialize()
|
||||
if(!ismob(parent))
|
||||
return COMPONENT_INCOMPATIBLE
|
||||
RegisterSignal(parent, COMSIG_MOB_CLIENT_LOGIN, .proc/create_mob_button)
|
||||
if(ismob(parent))
|
||||
RegisterSignal(parent, COMSIG_MOB_CLIENT_LOGIN, .proc/create_mob_button)
|
||||
|
||||
/datum/component/personal_crafting/proc/create_mob_button(mob/user, client/CL)
|
||||
var/datum/hud/H = user.hud_used
|
||||
var/obj/screen/craft/C = new()
|
||||
C.icon = H.ui_style
|
||||
H.static_inventory += C
|
||||
if(!CL.prefs.widescreenpref)
|
||||
C.screen_loc = ui_boxcraft
|
||||
CL.screen += C
|
||||
RegisterSignal(C, COMSIG_CLICK, .proc/component_ui_interact)
|
||||
|
||||
/datum/component/personal_crafting
|
||||
var/busy
|
||||
var/viewing_category = 1
|
||||
var/viewing_category = 1 //typical powergamer starting on the Weapons tab
|
||||
var/viewing_subcategory = 1
|
||||
var/list/categories = list(
|
||||
CAT_WEAPONRY = list(
|
||||
@@ -58,9 +55,6 @@
|
||||
var/display_craftable_only = FALSE
|
||||
var/display_compact = TRUE
|
||||
|
||||
|
||||
|
||||
|
||||
/* This is what procs do:
|
||||
get_environment - gets a list of things accessable for crafting by user
|
||||
get_surroundings - takes a list of things and makes a list of key-types to values-amounts of said type in the list
|
||||
@@ -70,8 +64,6 @@
|
||||
del_reqs - takes recipe and a user, loops over the recipes reqs var and tries to find everything in the list make by get_environment and delete it/add to parts list, then returns the said list
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Check that the contents of the recipe meet the requirements.
|
||||
*
|
||||
@@ -79,7 +71,7 @@
|
||||
* R: The /datum/crafting_recipe being attempted.
|
||||
* contents: List of items to search for R's reqs.
|
||||
*/
|
||||
/datum/component/personal_crafting/proc/check_contents(mob/user, datum/crafting_recipe/R, list/contents)
|
||||
/datum/component/personal_crafting/proc/check_contents(atom/a, datum/crafting_recipe/R, list/contents)
|
||||
var/list/item_instances = contents["instances"]
|
||||
contents = contents["other"]
|
||||
|
||||
@@ -91,7 +83,7 @@
|
||||
var/needed_amount = R.reqs[requirement_path]
|
||||
for(var/content_item_path in contents)
|
||||
// Right path and not blacklisted
|
||||
if(!ispath(content_item_path, requirement_path) || R.blacklist.Find(requirement_path))
|
||||
if(!ispath(content_item_path, requirement_path) || R.blacklist.Find(content_item_path))
|
||||
continue
|
||||
|
||||
needed_amount -= contents[content_item_path]
|
||||
@@ -113,32 +105,25 @@
|
||||
if(contents[requirement_path] < R.chem_catalysts[requirement_path])
|
||||
return FALSE
|
||||
|
||||
return R.check_requirements(user, requirements_list)
|
||||
return R.check_requirements(a, requirements_list)
|
||||
|
||||
/datum/component/personal_crafting/proc/get_environment(mob/user)
|
||||
/datum/component/personal_crafting/proc/get_environment(atom/a, list/blacklist = null, radius_range = 1)
|
||||
. = list()
|
||||
for(var/obj/item/I in user.held_items)
|
||||
. += I
|
||||
if(!isturf(user.loc))
|
||||
return
|
||||
var/list/L = block(get_step(user, SOUTHWEST), get_step(user, NORTHEAST))
|
||||
for(var/A in L)
|
||||
var/turf/T = A
|
||||
if(T.Adjacent(user))
|
||||
for(var/B in T)
|
||||
var/atom/movable/AM = B
|
||||
if(AM.flags_1 & HOLOGRAM_1)
|
||||
continue
|
||||
. += AM
|
||||
for(var/slot in list(SLOT_R_STORE, SLOT_L_STORE))
|
||||
. += user.get_item_by_slot(slot)
|
||||
|
||||
/datum/component/personal_crafting/proc/get_surroundings(mob/user)
|
||||
if(!isturf(a.loc))
|
||||
return
|
||||
|
||||
for(var/atom/movable/AM in range(radius_range, a))
|
||||
if(AM.flags_1 & HOLOGRAM_1)
|
||||
continue
|
||||
. += AM
|
||||
|
||||
/datum/component/personal_crafting/proc/get_surroundings(atom/a)
|
||||
. = list()
|
||||
.["tool_behaviour"] = list()
|
||||
.["other"] = list()
|
||||
.["instances"] = list()
|
||||
for(var/obj/item/I in get_environment(user))
|
||||
for(var/obj/item/I in get_environment(a))
|
||||
if(I.flags_1 & HOLOGRAM_1)
|
||||
continue
|
||||
if(.["instances"][I.type])
|
||||
@@ -159,13 +144,13 @@
|
||||
.["other"][A.type] += A.volume
|
||||
.["other"][I.type] += 1
|
||||
|
||||
/datum/component/personal_crafting/proc/check_tools(mob/user, datum/crafting_recipe/R, list/contents)
|
||||
/datum/component/personal_crafting/proc/check_tools(atom/a, datum/crafting_recipe/R, list/contents)
|
||||
if(!R.tools.len)
|
||||
return TRUE
|
||||
var/list/possible_tools = list()
|
||||
var/list/present_qualities = list()
|
||||
present_qualities |= contents["tool_behaviour"]
|
||||
for(var/obj/item/I in user.contents)
|
||||
for(var/obj/item/I in a.contents)
|
||||
if(istype(I, /obj/item/storage))
|
||||
for(var/obj/item/SI in I.contents)
|
||||
possible_tools += SI.type
|
||||
@@ -190,43 +175,28 @@
|
||||
return FALSE
|
||||
return TRUE
|
||||
|
||||
/datum/component/personal_crafting/proc/construct_item(mob/user, datum/crafting_recipe/R)
|
||||
var/list/contents = get_surroundings(user)
|
||||
var/send_feedback = TRUE
|
||||
if(check_contents(user, R, contents))
|
||||
if(check_tools(user, R, contents))
|
||||
if(do_after(user, R.time, target = user))
|
||||
contents = get_surroundings(user)
|
||||
if(!check_contents(user, R, contents))
|
||||
return ", missing component."
|
||||
if(!check_tools(user, R, contents))
|
||||
return ", missing tool."
|
||||
var/list/parts = del_reqs(R, user)
|
||||
var/atom/movable/I = new R.result (get_turf(user.loc))
|
||||
I.CheckParts(parts, R)
|
||||
if(isitem(I))
|
||||
if(isfood(I))
|
||||
var/obj/item/reagent_containers/food/food_result = I
|
||||
var/total_quality = 0
|
||||
var/total_items = 0
|
||||
for(var/obj/item/ingredient in parts)
|
||||
var/obj/item/reagent_containers/food/food_ingredient = ingredient
|
||||
total_items += 1
|
||||
total_quality += food_ingredient.food_quality
|
||||
if(total_items == 0)
|
||||
food_result.adjust_food_quality(50)
|
||||
else
|
||||
food_result.adjust_food_quality(total_quality / total_items)
|
||||
user.put_in_hands(I)
|
||||
if(send_feedback)
|
||||
SSblackbox.record_feedback("tally", "object_crafted", 1, I.type)
|
||||
log_craft("[I] crafted by [user] at [loc_name(I.loc)]")
|
||||
return FALSE
|
||||
return "."
|
||||
/datum/component/personal_crafting/proc/construct_item(atom/a, datum/crafting_recipe/R)
|
||||
var/list/contents = get_surroundings(a)
|
||||
var/send_feedback = 1
|
||||
if(check_contents(a, R, contents))
|
||||
if(check_tools(a, R, contents))
|
||||
//If we're a mob we'll try a do_after; non mobs will instead instantly construct the item
|
||||
if(ismob(a) && !do_after(a, R.time, target = a))
|
||||
return "."
|
||||
contents = get_surroundings(a)
|
||||
if(!check_contents(a, R, contents))
|
||||
return ", missing component."
|
||||
if(!check_tools(a, R, contents))
|
||||
return ", missing tool."
|
||||
var/list/parts = del_reqs(R, a)
|
||||
var/atom/movable/I = new R.result (get_turf(a.loc))
|
||||
I.CheckParts(parts, R)
|
||||
if(send_feedback)
|
||||
SSblackbox.record_feedback("tally", "object_crafted", 1, I.type)
|
||||
return I //Send the item back to whatever called this proc so it can handle whatever it wants to do with the new item
|
||||
return ", missing tool."
|
||||
return ", missing component."
|
||||
|
||||
|
||||
/*Del reqs works like this:
|
||||
|
||||
Loop over reqs var of the recipe
|
||||
@@ -251,7 +221,7 @@
|
||||
del_reqs return the list of parts resulting object will receive as argument of CheckParts proc, on the atom level it will add them all to the contents, on all other levels it calls ..() and does whatever is needed afterwards but from contents list already
|
||||
*/
|
||||
|
||||
/datum/component/personal_crafting/proc/del_reqs(datum/crafting_recipe/R, mob/user)
|
||||
/datum/component/personal_crafting/proc/del_reqs(datum/crafting_recipe/R, atom/a)
|
||||
var/list/surroundings
|
||||
var/list/Deletion = list()
|
||||
. = list()
|
||||
@@ -260,7 +230,7 @@
|
||||
main_loop:
|
||||
for(var/A in R.reqs)
|
||||
amt = R.reqs[A]
|
||||
surroundings = get_environment(user)
|
||||
surroundings = get_environment(a, R.blacklist)
|
||||
surroundings -= Deletion
|
||||
if(ispath(A, /datum/reagent))
|
||||
var/datum/reagent/RG = new A
|
||||
@@ -353,6 +323,7 @@
|
||||
if(user == parent)
|
||||
ui_interact(user)
|
||||
|
||||
//For the UI related things we're going to assume the user is a mob rather than typesetting it to an atom as the UI isn't generated if the parent is an atom
|
||||
/datum/component/personal_crafting/ui_interact(mob/user, ui_key = "main", datum/tgui/ui = null, force_open = FALSE, datum/tgui/master_ui = null, datum/ui_state/state = GLOB.not_incapacitated_turf_state)
|
||||
ui = SStgui.try_update_ui(user, src, ui_key, ui, force_open)
|
||||
if(!ui)
|
||||
@@ -362,10 +333,9 @@
|
||||
cur_subcategory = subcats[1]
|
||||
else
|
||||
cur_subcategory = CAT_NONE
|
||||
ui = new(user, src, ui_key, "personal_crafting", "Crafting Menu", 700, 800, master_ui, state)
|
||||
ui = new(user, src, ui_key, "PersonalCrafting", "Crafting Menu", 700, 800, master_ui, state)
|
||||
ui.open()
|
||||
|
||||
|
||||
/datum/component/personal_crafting/ui_data(mob/user)
|
||||
var/list/data = list()
|
||||
data["busy"] = busy
|
||||
@@ -417,23 +387,24 @@
|
||||
data["crafting_recipes"] = crafting_recipes
|
||||
return data
|
||||
|
||||
|
||||
/datum/component/personal_crafting/ui_act(action, params)
|
||||
if(..())
|
||||
return
|
||||
switch(action)
|
||||
if("make")
|
||||
var/mob/user = usr
|
||||
var/datum/crafting_recipe/TR = locate(params["recipe"]) in GLOB.crafting_recipes
|
||||
ui_interact(usr)
|
||||
if(busy)
|
||||
to_chat(usr, "<span class='warning'>You are already making something!</span>")
|
||||
return
|
||||
busy = TRUE
|
||||
var/fail_msg = construct_item(usr, TR)
|
||||
if(!fail_msg)
|
||||
to_chat(usr, "<span class='notice'>[TR.name] constructed.</span>")
|
||||
ui_interact(user)
|
||||
var/atom/movable/result = construct_item(user, TR)
|
||||
if(!istext(result)) //We made an item and didn't get a fail message
|
||||
if(ismob(user) && isitem(result)) //In case the user is actually possessing a non mob like a machine
|
||||
user.put_in_hands(result)
|
||||
else
|
||||
result.forceMove(user.drop_location())
|
||||
to_chat(user, "<span class='notice'>[TR.name] constructed.</span>")
|
||||
else
|
||||
to_chat(usr, "<span class='warning'>Construction failed[fail_msg]</span>")
|
||||
to_chat(user, "<span class='warning'>Construction failed[result]</span>")
|
||||
busy = FALSE
|
||||
if("toggle_recipes")
|
||||
display_craftable_only = !display_craftable_only
|
||||
@@ -0,0 +1,153 @@
|
||||
///Global GPS_list. All GPS components get saved in here for easy reference.
|
||||
GLOBAL_LIST_EMPTY(GPS_list)
|
||||
///GPS component. Atoms that have this show up on gps. Pretty simple stuff.
|
||||
/datum/component/gps
|
||||
var/gpstag = "COM0"
|
||||
var/tracking = TRUE
|
||||
var/emped = FALSE
|
||||
|
||||
/datum/component/gps/Initialize(_gpstag = "COM0")
|
||||
if(!isatom(parent))
|
||||
return COMPONENT_INCOMPATIBLE
|
||||
gpstag = _gpstag
|
||||
GLOB.GPS_list += src
|
||||
|
||||
/datum/component/gps/Destroy()
|
||||
GLOB.GPS_list -= src
|
||||
return ..()
|
||||
|
||||
///GPS component subtype. Only gps/item's can be used to open the UI.
|
||||
/datum/component/gps/item
|
||||
var/updating = TRUE //Automatic updating of GPS list. Can be set to manual by user.
|
||||
var/global_mode = TRUE //If disabled, only GPS signals of the same Z level are shown
|
||||
|
||||
/datum/component/gps/item/Initialize(_gpstag = "COM0", emp_proof = FALSE)
|
||||
. = ..()
|
||||
if(. == COMPONENT_INCOMPATIBLE || !isitem(parent))
|
||||
return COMPONENT_INCOMPATIBLE
|
||||
var/atom/A = parent
|
||||
A.add_overlay("working")
|
||||
A.name = "[initial(A.name)] ([gpstag])"
|
||||
RegisterSignal(parent, COMSIG_ITEM_ATTACK_SELF, .proc/interact)
|
||||
if(!emp_proof)
|
||||
RegisterSignal(parent, COMSIG_ATOM_EMP_ACT, .proc/on_emp_act)
|
||||
RegisterSignal(parent, COMSIG_PARENT_EXAMINE, .proc/on_examine)
|
||||
RegisterSignal(parent, COMSIG_CLICK_ALT, .proc/on_AltClick)
|
||||
|
||||
///Called on COMSIG_ITEM_ATTACK_SELF
|
||||
/datum/component/gps/item/proc/interact(datum/source, mob/user)
|
||||
if(user)
|
||||
ui_interact(user)
|
||||
|
||||
///Called on COMSIG_PARENT_EXAMINE
|
||||
/datum/component/gps/item/proc/on_examine(datum/source, mob/user, list/examine_list)
|
||||
examine_list += "<span class='notice'>Alt-click to switch it [tracking ? "off":"on"].</span>"
|
||||
|
||||
///Called on COMSIG_ATOM_EMP_ACT
|
||||
/datum/component/gps/item/proc/on_emp_act(datum/source, severity)
|
||||
emped = TRUE
|
||||
var/atom/A = parent
|
||||
A.cut_overlay("working")
|
||||
A.add_overlay("emp")
|
||||
addtimer(CALLBACK(src, .proc/reboot), 300, TIMER_UNIQUE|TIMER_OVERRIDE) //if a new EMP happens, remove the old timer so it doesn't reactivate early
|
||||
SStgui.close_uis(src) //Close the UI control if it is open.
|
||||
|
||||
///Restarts the GPS after getting turned off by an EMP.
|
||||
/datum/component/gps/item/proc/reboot()
|
||||
emped = FALSE
|
||||
var/atom/A = parent
|
||||
A.cut_overlay("emp")
|
||||
A.add_overlay("working")
|
||||
|
||||
///Calls toggletracking
|
||||
/datum/component/gps/item/proc/on_AltClick(datum/source, mob/user)
|
||||
toggletracking(user)
|
||||
|
||||
///Toggles the tracking for the gps
|
||||
/datum/component/gps/item/proc/toggletracking(mob/user)
|
||||
if(!user.canUseTopic(parent, BE_CLOSE))
|
||||
return //user not valid to use gps
|
||||
if(emped)
|
||||
to_chat(user, "<span class='warning'>It's busted!</span>")
|
||||
return
|
||||
var/atom/A = parent
|
||||
if(tracking)
|
||||
A.cut_overlay("working")
|
||||
to_chat(user, "<span class='notice'>[parent] is no longer tracking, or visible to other GPS devices.</span>")
|
||||
tracking = FALSE
|
||||
else
|
||||
A.add_overlay("working")
|
||||
to_chat(user, "<span class='notice'>[parent] is now tracking, and visible to other GPS devices.</span>")
|
||||
tracking = TRUE
|
||||
|
||||
/datum/component/gps/item/ui_interact(mob/user, ui_key = "gps", datum/tgui/ui = null, force_open = FALSE, datum/tgui/master_ui = null, datum/ui_state/state = GLOB.default_state) // Remember to use the appropriate state.
|
||||
if(emped)
|
||||
to_chat(user, "<span class='hear'>[parent] fizzles weakly.</span>")
|
||||
return
|
||||
ui = SStgui.try_update_ui(user, src, ui_key, ui, force_open)
|
||||
if(!ui)
|
||||
// Variable window height, depending on how many GPS units there are
|
||||
// to show, clamped to relatively safe range.
|
||||
var/gps_window_height = clamp(325 + GLOB.GPS_list.len * 14, 325, 700)
|
||||
ui = new(user, src, ui_key, "Gps", "Global Positioning System", 470, gps_window_height, master_ui, state) //width, height
|
||||
ui.open()
|
||||
|
||||
ui.set_autoupdate(state = updating)
|
||||
|
||||
/datum/component/gps/item/ui_data(mob/user)
|
||||
var/list/data = list()
|
||||
data["power"] = tracking
|
||||
data["tag"] = gpstag
|
||||
data["updating"] = updating
|
||||
data["globalmode"] = global_mode
|
||||
if(!tracking || emped) //Do not bother scanning if the GPS is off or EMPed
|
||||
return data
|
||||
|
||||
var/turf/curr = get_turf(parent)
|
||||
data["currentArea"] = "[get_area_name(curr, TRUE)]"
|
||||
data["currentCoords"] = "[curr.x], [curr.y], [curr.z]"
|
||||
|
||||
var/list/signals = list()
|
||||
data["signals"] = list()
|
||||
|
||||
for(var/gps in GLOB.GPS_list)
|
||||
var/datum/component/gps/G = gps
|
||||
if(G.emped || !G.tracking || G == src)
|
||||
continue
|
||||
var/turf/pos = get_turf(G.parent)
|
||||
if(!pos || !global_mode && pos.z != curr.z)
|
||||
continue
|
||||
var/list/signal = list()
|
||||
signal["entrytag"] = G.gpstag //Name or 'tag' of the GPS
|
||||
signal["coords"] = "[pos.x], [pos.y], [pos.z]"
|
||||
if(pos.z == curr.z) //Distance/Direction calculations for same z-level only
|
||||
signal["dist"] = max(get_dist(curr, pos), 0) //Distance between the src and remote GPS turfs
|
||||
signal["degrees"] = round(Get_Angle(curr, pos)) //0-360 degree directional bearing, for more precision.
|
||||
signals += list(signal) //Add this signal to the list of signals
|
||||
data["signals"] = signals
|
||||
return data
|
||||
|
||||
/datum/component/gps/item/ui_act(action, params)
|
||||
if(..())
|
||||
return
|
||||
switch(action)
|
||||
if("rename")
|
||||
var/atom/parentasatom = parent
|
||||
var/a = stripped_input(usr, "Please enter desired tag.", parentasatom.name, gpstag, 20)
|
||||
|
||||
if (!a)
|
||||
return
|
||||
|
||||
gpstag = a
|
||||
. = TRUE
|
||||
parentasatom.name = "global positioning system ([gpstag])"
|
||||
|
||||
if("power")
|
||||
toggletracking(usr)
|
||||
. = TRUE
|
||||
if("updating")
|
||||
updating = !updating
|
||||
. = TRUE
|
||||
if("globalmode")
|
||||
global_mode = !global_mode
|
||||
. = TRUE
|
||||
@@ -140,9 +140,8 @@ GLOBAL_LIST_EMPTY(uplinks)
|
||||
active = TRUE
|
||||
ui = SStgui.try_update_ui(user, src, ui_key, ui, force_open)
|
||||
if(!ui)
|
||||
ui = new(user, src, ui_key, "uplink", name, 620, 580, master_ui, state)
|
||||
ui = new(user, src, ui_key, "Uplink", name, 620, 580, master_ui, state)
|
||||
ui.set_autoupdate(FALSE) // This UI is only ever opened by one person, and never is updated outside of user input.
|
||||
ui.set_style("syndicate")
|
||||
ui.open()
|
||||
|
||||
/datum/component/uplink/ui_host(mob/user)
|
||||
@@ -157,8 +156,7 @@ GLOBAL_LIST_EMPTY(uplinks)
|
||||
var/list/data = list()
|
||||
data["telecrystals"] = telecrystals
|
||||
data["lockable"] = lockable
|
||||
data["compact_mode"] = compact_mode
|
||||
|
||||
data["compactMode"] = compact_mode
|
||||
return data
|
||||
|
||||
/datum/component/uplink/ui_static_data(mob/user)
|
||||
|
||||
Reference in New Issue
Block a user