Minor Mountable Frame Code Refactor (#18738)

* bugfix turned into a refactor

* fixes exploit with producing infinite metal

* Update code/__DEFINES/construction.dm

Co-authored-by: Charlie <69320440+hal9000PR@users.noreply.github.com>

Co-authored-by: Charlie <69320440+hal9000PR@users.noreply.github.com>
This commit is contained in:
Sirryan2002
2022-08-27 17:04:43 -04:00
committed by GitHub
parent 7eb65e8831
commit b4539344e4
11 changed files with 59 additions and 48 deletions
@@ -2,29 +2,37 @@
name = "mountable frame"
desc = "Place it on a wall."
origin_tech = "materials=1;engineering=1"
var/sheets_refunded = 2
var/list/mount_reqs = list() //can contain simfloor, nospace. Used in try_build to see if conditions are needed, then met
toolspeed = 1
usesound = 'sound/items/deconstruct.ogg'
///amount of metal sheets returned upon the frame being wrenched
var/metal_sheets_refunded = 2
///amount of glass sheets returned upon the frame being wrenched
var/glass_sheets_refunded = 0
///The requirements for this frame to be placed, uses bit flags
var/mount_requirements = 0
/obj/item/mounted/frame/attackby(obj/item/W, mob/user)
..()
if(istype(W, /obj/item/wrench) && sheets_refunded)
//new /obj/item/stack/sheet/metal( get_turf(src.loc), sheets_refunded )
var/obj/item/stack/sheet/metal/M = new /obj/item/stack/sheet/metal(get_turf(src))
M.amount = sheets_refunded
if(istype(W, /obj/item/wrench))
var/turf/user_turf = get_turf(user)
if(metal_sheets_refunded)
new /obj/item/stack/sheet/metal(user_turf, metal_sheets_refunded)
if(glass_sheets_refunded)
new /obj/item/stack/sheet/glass(user_turf, glass_sheets_refunded)
qdel(src)
/obj/item/mounted/frame/try_build(turf/on_wall, mob/user)
if(..()) //if we pass the parent tests
var/turf/turf_loc = get_turf(user)
if(!..())
return
if(src.mount_reqs.Find("simfloor") && !istype(turf_loc, /turf/simulated/floor))
to_chat(user, "<span class='warning'>[src] cannot be placed on this spot.</span>")
var/turf/build_turf = get_turf(user)
if((mount_requirements & MOUNTED_FRAME_SIMFLOOR) && !isfloorturf(build_turf))
to_chat(user, "<span class='warning'>[src] cannot be placed on this spot.</span>")
return
if(mount_requirements & MOUNTED_FRAME_NOSPACE)
var/area/my_area = get_area(build_turf)
if(!istype(my_area) || !my_area.requires_power || istype(my_area, /area/space))
to_chat(user, "<span class='warning'>[src] cannot be placed in this area.</span>")
return
if(src.mount_reqs.Find("nospace"))
var/area/my_area = turf_loc.loc
if(!istype(my_area) || (my_area.requires_power == 0 || istype(my_area,/area/space)))
to_chat(user, "<span class='warning'>[src] cannot be placed in this area.</span>")
return
return 1
return TRUE