Skip to content

Commit

Permalink
* Added boundary checks for stack sheets inserting (fixes tgstation#1…
Browse files Browse the repository at this point in the history
…1732)

* Limited material inserting to stack sheets for the protolathe and banana shoes
  • Loading branch information
Menshin committed Sep 12, 2015
1 parent f9a01d1 commit ce2ee15
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
8 changes: 7 additions & 1 deletion code/datums/material_container.dm
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,15 @@
return 0

/datum/material_container/proc/insert_stack(obj/item/stack/S, amt = 0)
if(!amt)
if(amt <= 0)
return 0
if(amt > S.amount)
amt = S.amount

var/material_amt = get_item_material_amount(S)
if(!material_amt)
return 0

amt = min(amt, round(((max_amount - total_amount) / material_amt)))
if(!amt)
return 0
Expand Down
6 changes: 5 additions & 1 deletion code/modules/clothing/shoes/bananashoes.dm
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,17 @@
user << "<span class='notice'>You cannot retrieve any bananium from the prototype shoes.</span>"

/obj/item/clothing/shoes/clown_shoes/banana_shoes/attackby(obj/item/O, mob/user, params)
if(!istype(O,/obj/item/stack/sheet))
return
if(!bananium.get_item_material_amount(O))
user << "<span class='notice'>This item has no bananium!</span>"
return
if(!user.unEquip(O))
user << "<span class='notice'>You can't drop [O]!</span>"
return
var/sheet_amount = bananium.insert_stack(O)

var/obj/item/stack/sheet/S = O
var/sheet_amount = bananium.insert_stack(O,S.amount)
if(sheet_amount)
user << "<span class='notice'>You insert [sheet_amount] bananium sheets into the prototype shoes.</span>"
else
Expand Down
11 changes: 6 additions & 5 deletions code/modules/research/protolathe.dm
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,19 @@ Note: Must be placed west/left of and R&D console to function.
return
if (stat)
return 1
if(istype(O,/obj/item/stack/sheet))
if(!materials.has_space( materials.get_item_material_amount(O) ))
user << "<span class='warning'>The [src.name]'s material bin is full! Please remove material before adding more.</span>"
return 1
if(!istype(O,/obj/item/stack/sheet))
return 1

if(!materials.has_space( materials.get_item_material_amount(O) ))
user << "<span class='warning'>The [src.name]'s material bin is full! Please remove material before adding more.</span>"
return 1

var/obj/item/stack/sheet/stack = O
var/amount = round(input("How many sheets do you want to add?") as num)//No decimals
if(!in_range(src, stack) || !user.Adjacent(src))
return
var/amount_inserted = materials.insert_stack(O,amount)
if(!amount_inserted)
user << "<span class='warning'>You could not insert [O], it has no usable materials.</span>"
return 1
else
busy = 1
Expand Down

0 comments on commit ce2ee15

Please sign in to comment.