Material door updates: lock and damage (#5659)

-ported locks and keys from baystation
-fixed the simple door damage interaction, now you can properly destroy it and etc
This commit is contained in:
Alberyk
2018-12-08 18:40:06 -02:00
committed by Werner
parent b91ad62fe8
commit 59be553606
15 changed files with 288 additions and 45 deletions

View File

@@ -1522,6 +1522,9 @@
#include "code\modules\lighting\lighting_verbs.dm"
#include "code\modules\lighting\~lighting_undefs.dm"
#include "code\modules\liquid\splash_simulation.dm"
#include "code\modules\lock\key.dm"
#include "code\modules\lock\lock.dm"
#include "code\modules\lock\lock_construct.dm"
#include "code\modules\maps\dmm_suite.dm"
#include "code\modules\maps\map_template.dm"
#include "code\modules\maps\reader.dm"

View File

@@ -34,6 +34,8 @@
throwforce = 0
throw_speed = 4
throw_range = 20
flags = OPENCONTAINER
var/key_data
/obj/item/weapon/soap/nanotrasen
desc = "A NanoTrasen-brand bar of soap. Smells of phoron."

View File

@@ -79,6 +79,7 @@
var/cleaving = FALSE
var/reach = 1 // Length of tiles it can reach, 1 is adjacent.
var/lock_picking_level = 0 //used to determine whether something can pick a lock, and how well.
/obj/item/Destroy()
if(ismob(loc))

View File

@@ -24,6 +24,7 @@ var/global/list/datum/stack_recipe/rod_recipes = list(
matter = list(DEFAULT_WALL_MATERIAL = 1875)
max_amount = 60
attack_verb = list("hit", "bludgeoned", "whacked")
lock_picking_level = 3
/obj/item/stack/rods/cyborg
name = "metal rod synthesizer"

View File

@@ -24,6 +24,21 @@
playsound(loc, 'sound/effects/slosh.ogg', 25, 1)
reagents.add_reagent("cleaner", 10)
/obj/item/weapon/soap/attackby(var/obj/item/I, var/mob/user)
if(istype(I, /obj/item/weapon/key))
if(!key_data)
to_chat(user, "<span class='notice'>You imprint \the [I] into \the [src].</span>")
var/obj/item/weapon/key/K = I
key_data = K.key_data
update_icon()
return
..()
/obj/item/weapon/soap/update_icon()
overlays.Cut()
if(key_data)
overlays += image('icons/obj/items.dmi', icon_state = "soap_key_overlay")
/obj/item/weapon/soap/Crossed(AM as mob|obj)
if (istype(AM, /mob/living))
var/mob/living/M = AM

View File

@@ -47,6 +47,7 @@
throw_range = 5
matter = list(DEFAULT_WALL_MATERIAL = 75)
attack_verb = list("stabbed")
lock_picking_level = 5
var/random_icon = TRUE
/obj/item/weapon/screwdriver/Initialize()

View File

@@ -9,17 +9,20 @@
var/material/material
var/state = 0 //closed, 1 == open
var/isSwitchingStates = 0
var/hardness = 1
var/oreAmount = 7
var/datum/lock/lock
var/initial_lock_value //for mapping purposes. Basically if this value is set, it sets the lock to this value.
var/health = 100
var/maxhealth = 100
/obj/structure/simple_door/fire_act(datum/gas_mixture/air, exposed_temperature, exposed_volume)
TemperatureAct(exposed_temperature)
/obj/structure/simple_door/proc/TemperatureAct(temperature)
hardness -= material.combustion_effect(get_turf(src),temperature, 0.3)
CheckHardness()
health -= material.combustion_effect(get_turf(src),temperature, 0.3)
CheckHealth()
/obj/structure/simple_door/New(var/newloc, var/material_name)
/obj/structure/simple_door/New(var/newloc, var/material_name, var/locked)
..()
if(!material_name)
material_name = DEFAULT_WALL_MATERIAL
@@ -27,10 +30,19 @@
if(!material)
qdel(src)
return
hardness = max(1,round(material.integrity/10))
icon_state = material.door_icon_base
name = "[material.display_name] door"
color = material.icon_colour
maxhealth = max(1,round(material.integrity/10))
health = maxhealth
if(initial_lock_value)
locked = initial_lock_value
if(locked)
lock = new(src,locked)
if(material.opacity < 0.5)
opacity = 0
else
@@ -42,8 +54,15 @@
/obj/structure/simple_door/Destroy()
STOP_PROCESSING(SSprocessing, src)
update_nearby_tiles()
qdel(lock)
lock = null
return ..()
/obj/structure/simple_door/examine(mob/user)
..(user)
if(lock)
to_chat(user, "<span class='notice'>It appears to have a lock.</span>")
/obj/structure/simple_door/get_material()
return material
@@ -81,19 +100,25 @@
if(iscarbon(M))
var/mob/living/carbon/C = M
if(!C.handcuffed)
SwitchState()
SwitchState(user)
else
SwitchState()
SwitchState(user)
else if(istype(user, /obj/mecha))
SwitchState()
/obj/structure/simple_door/proc/SwitchState()
/obj/structure/simple_door/proc/SwitchState(mob/user)
if(state)
Close()
else
Open()
Open(user)
/obj/structure/simple_door/proc/Open(mob/user)
if(lock && lock.isLocked())
if(user)
to_chat(user, "<span class='warning'>\The [src] is locked!</span>")
return
/obj/structure/simple_door/proc/Open()
isSwitchingStates = 1
playsound(loc, material.dooropen_noise, 100, 1)
flick("[material.door_icon_base]opening",src)
@@ -124,26 +149,48 @@
icon_state = material.door_icon_base
/obj/structure/simple_door/attackby(obj/item/weapon/W as obj, mob/user as mob)
if(istype(W,/obj/item/weapon/pickaxe))
var/obj/item/weapon/pickaxe/digTool = W
user << "You start digging the [name]."
if(do_after(user,digTool.digspeed*hardness) && src)
user << "You finished digging."
Dismantle()
else if(istype(W,/obj/item/weapon)) //not sure, can't not just weapons get passed to this proc?
hardness -= W.force/100
user << "You hit the [name] with your [W.name]!"
CheckHardness()
else if(iswelder(W))
var/obj/item/weapon/weldingtool/WT = W
if(material.ignition_point && WT.remove_fuel(0, user))
TemperatureAct(150)
if(istype(W, /obj/item/weapon/key) && lock)
var/obj/item/weapon/key/K = W
if(!lock.toggle(W))
to_chat(user, "<span class='warning'>\The [K] does not fit in the lock!</span>")
return
if(lock && lock.pick_lock(W,user))
return
if(istype(W,/obj/item/weapon/material/lock_construct))
if(lock)
to_chat(user, "<span class='warning'>\The [src] already has a lock.</span>")
else
var/obj/item/weapon/material/lock_construct/L = W
lock = L.create_lock(src,user)
return
else if(istype(W,/obj/item/weapon))
var/obj/item/weapon/I = W
user.setClickCooldown(DEFAULT_ATTACK_COOLDOWN)
if(I.damtype == BRUTE || I.damtype == BURN)
if(I.force < 10)
user.visible_message("<span class='danger'>\The [user] hits \the [src] with \the [I] with no visible effect.</span>")
else
user.do_attack_animation(src)
animate_shake()
user.visible_message("<span class='danger'>\The [user] forcefully strikes \the [src] with \the [I]!</span>")
playsound(src.loc, material.hitsound, 100, 1)
src.health -= W.force * 1
CheckHealth()
else
attack_hand(user)
return
/obj/structure/simple_door/proc/CheckHardness()
if(hardness <= 0)
/obj/structure/simple_door/bullet_act(var/obj/item/projectile/Proj)
health -= Proj.damage
CheckHealth()
return
/obj/structure/simple_door/proc/CheckHealth()
if(health <= 0)
Dismantle(1)
/obj/structure/simple_door/proc/Dismantle(devastated = 0)
@@ -158,11 +205,11 @@
if(prob(20))
Dismantle(1)
else
hardness--
CheckHardness()
health--
CheckHealth()
if(3)
hardness -= 0.1
CheckHardness()
health -= 0.1
CheckHealth()
return
/obj/structure/simple_door/process()
@@ -171,26 +218,26 @@
for(var/mob/living/L in range(1,src))
L.apply_effect(round(material.radioactivity/3),IRRADIATE,0)
/obj/structure/simple_door/iron/New(var/newloc,var/material_name)
..(newloc, "iron")
/obj/structure/simple_door/iron/New(var/newloc,var/material_name, var/complexity)
..(newloc, "iron", complexity)
/obj/structure/simple_door/silver/New(var/newloc,var/material_name)
..(newloc, "silver")
/obj/structure/simple_door/silver/New(var/newloc,var/material_name, var/complexity)
..(newloc, "silver", complexity)
/obj/structure/simple_door/gold/New(var/newloc,var/material_name)
..(newloc, "gold")
/obj/structure/simple_door/gold/New(var/newloc,var/material_name, var/complexity)
..(newloc, "gold", complexity)
/obj/structure/simple_door/uranium/New(var/newloc,var/material_name)
..(newloc, "uranium")
/obj/structure/simple_door/uranium/New(var/newloc,var/material_name, var/complexity)
..(newloc, "uranium", complexity)
/obj/structure/simple_door/sandstone/New(var/newloc,var/material_name)
..(newloc, "sandstone")
/obj/structure/simple_door/sandstone/New(var/newloc,var/material_name, var/complexity)
..(newloc, "sandstone", complexity)
/obj/structure/simple_door/phoron/New(var/newloc,var/material_name)
..(newloc, "phoron")
/obj/structure/simple_door/phoron/New(var/newloc,var/material_name, var/complexity)
..(newloc, "phoron", complexity)
/obj/structure/simple_door/diamond/New(var/newloc,var/material_name)
..(newloc, "diamond")
/obj/structure/simple_door/diamond/New(var/newloc,var/material_name, var/complexity)
..(newloc, "diamond", complexity)
/obj/structure/simple_door/wood/New(var/newloc,var/material_name)
..(newloc, "wood")

28
code/modules/lock/key.dm Normal file
View File

@@ -0,0 +1,28 @@
/obj/item/weapon/key
name = "key"
desc = "Used to unlock things."
icon = 'icons/obj/items.dmi'
icon_state = "keys"
w_class = 1
var/key_data = ""
/obj/item/weapon/key/New(var/newloc,var/data)
if(data)
key_data = data
..(newloc)
/obj/item/weapon/key/proc/get_data(var/mob/user)
return key_data
/obj/item/weapon/key/soap
name = "soap key"
desc = "a fragile key made using a bar of soap."
var/uses = 0
/obj/item/weapon/key/soap/get_data(var/mob/user)
uses--
if(uses <= 0)
user.drop_from_inventory(src,user)
to_chat(user, "<span class='warning'>\The [src] crumbles in your hands!</span>")
qdel(src)
return ..()

81
code/modules/lock/lock.dm Normal file
View File

@@ -0,0 +1,81 @@
#define LOCK_LOCKED 1
#define LOCK_BROKEN 2
/datum/lock
var/status = 1 //unlocked, 1 == locked 2 == broken
var/lock_data = "" //basically a randomized string. The longer the string the more complex the lock.
var/atom/holder
/datum/lock/New(var/atom/h, var/complexity = 1)
holder = h
if(istext(complexity))
lock_data = complexity
else
lock_data = generateRandomString(complexity)
/datum/lock/Destroy()
holder = null
..()
/datum/lock/proc/unlock(var/key = "", var/mob/user)
if(status ^ LOCK_LOCKED)
to_chat(user, "<span class='warning'>Its already unlocked!</span>")
return 2
key = get_key_data(key, user)
if(cmptext(lock_data,key) && (status ^ LOCK_BROKEN))
to_chat(user, "<span class='warning'>You unlock the lock.</span>")
status &= ~LOCK_LOCKED
return 1
return 0
/datum/lock/proc/lock(var/key = "", var/mob/user)
if(status & LOCK_LOCKED)
to_chat(user, "<span class='warning'>Its already locked!</span>")
return 2
key = get_key_data(key, user)
if(cmptext(lock_data,key) && (status ^ LOCK_BROKEN))
to_chat(user, "<span class='warning'>You close the lock.</span>")
status |= LOCK_LOCKED
return 1
return 0
/datum/lock/proc/toggle(var/key = "", var/mob/user)
if(status & LOCK_LOCKED)
return unlock(key, user)
else
return lock(key, user)
/datum/lock/proc/getComplexity()
return length(lock_data)
/datum/lock/proc/get_key_data(var/key = "", var/mob/user)
if(istype(key,/obj/item/weapon/key))
var/obj/item/weapon/key/K = key
return K.get_data(user)
if(istext(key))
return key
return null
/datum/lock/proc/isLocked()
return status & LOCK_LOCKED
/datum/lock/proc/pick_lock(var/obj/item/I, var/mob/user)
if(!istype(I) || (status ^ LOCK_LOCKED))
return 0
var/unlock_power = I.lock_picking_level
if(!unlock_power)
return 0
user.visible_message("\The [user] takes out \the [I], picking \the [holder]'s lock.")
if(!do_after(user, 20, holder))
return 0
if(prob(20*(unlock_power/getComplexity())))
to_chat(user, "<span class='notice'>You pick open \the [holder]'s lock!</span>")
unlock(lock_data)
return 1
else if(prob(5 * unlock_power))
to_chat(user, "<span class='warning'>You accidently break \the [holder]'s lock with \the [I]!</span>")
status |= LOCK_BROKEN
else
to_chat(user, "<span class='warning'>You fail to pick open \the [holder].</span>")
return 0

View File

@@ -0,0 +1,30 @@
/obj/item/weapon/material/lock_construct
name = "lock"
desc = "A crude but useful lock and bolt."
icon = 'icons/obj/storage.dmi'
icon_state = "largebinemag"
w_class = 1
var/lock_data
/obj/item/weapon/material/lock_construct/New()
..()
force = 0
throwforce = 0
lock_data = generateRandomString(round(material.integrity/50))
/obj/item/weapon/material/lock_construct/attackby(var/obj/item/I, var/mob/user)
if(istype(I,/obj/item/weapon/key))
var/obj/item/weapon/key/K = I
if(!K.key_data)
to_chat(user, "<span class='notice'>You fashion \the [I] to unlock \the [src]</span>")
K.key_data = lock_data
else
to_chat(user, "<span class='warning'>\The [I] already unlocks something.</span>")
return
..()
/obj/item/weapon/material/lock_construct/proc/create_lock(var/atom/target, var/mob/user)
. = new /datum/lock(target,lock_data)
user.drop_from_inventory(src,user)
user.visible_message("<span class='notice'>\The [user] attaches \the [src] to \the [target].</span>")
qdel(src)

View File

@@ -13,11 +13,12 @@
recipes += new/datum/stack_recipe("[display_name] armor plate", /obj/item/weapon/material/armor_plating, 3, time = 20, on_floor = 1, supplied_material = "[name]")
if(integrity>=50)
recipes += new/datum/stack_recipe("[display_name] door", /obj/structure/simple_door, 10, one_per_turf = 1, on_floor = 1, supplied_material = "[name]")
recipes += new/datum/stack_recipe("[display_name] door", /obj/structure/simple_door, 10, time = 50, one_per_turf = 1, on_floor = 1, supplied_material = "[name]")
recipes += new/datum/stack_recipe("[display_name] barricade", /obj/structure/barricade, 5, time = 50, one_per_turf = 1, on_floor = 1, supplied_material = "[name]")
recipes += new/datum/stack_recipe("[display_name] stool", /obj/item/weapon/stool, one_per_turf = 1, on_floor = 1, supplied_material = "[name]")
recipes += new/datum/stack_recipe("[display_name] chair", /obj/structure/bed/chair, one_per_turf = 1, on_floor = 1, supplied_material = "[name]")
recipes += new/datum/stack_recipe("[display_name] bed", /obj/structure/bed, 2, one_per_turf = 1, on_floor = 1, supplied_material = "[name]")
recipes += new/datum/stack_recipe("[display_name] lock",/obj/item/weapon/material/lock_construct, 1, time = 20, one_per_turf = 0, on_floor = 1, supplied_material = "[name]")
if(hardness>=10)
recipes += new/datum/stack_recipe("[display_name] ashtray", /obj/item/weapon/material/ashtray, 2, one_per_turf = 1, on_floor = 1, supplied_material = "[name]")
if(hardness>50)
@@ -44,6 +45,7 @@
new/datum/stack_recipe("green comfy chair", /obj/structure/bed/chair/comfy/green, 2, one_per_turf = 1, on_floor = 1), \
))
recipes += new/datum/stack_recipe("key", /obj/item/weapon/key, 1, time = 10, one_per_turf = 0, on_floor = 1)
recipes += new/datum/stack_recipe("table frame", /obj/structure/table, 1, time = 10, one_per_turf = 1, on_floor = 1)
recipes += new/datum/stack_recipe("custodial cart", /obj/structure/janitorialcart, 15, time = 120, one_per_turf = 1, on_floor = 1)
recipes += new/datum/stack_recipe("rack", /obj/structure/table/rack, 1, time = 5, one_per_turf = 1, on_floor = 1)

View File

@@ -114,6 +114,8 @@ var/list/name_to_material
var/tableslam_noise = 'sound/weapons/tablehit1.ogg'
// Noise made when a simple door made of this material opens or closes.
var/dooropen_noise = 'sound/effects/stonedoor_openclose.ogg'
// Noise made when you hit structure made of this material.
var/hitsound = 'sound/weapons/genhit.ogg'
// Path to resulting stacktype. Todo remove need for this.
var/stack_type
// Wallrot crumble message.
@@ -280,6 +282,7 @@ var/list/name_to_material
conductivity = 1
shard_type = SHARD_SHARD
tableslam_noise = 'sound/effects/Glasshit.ogg'
hitsound = 'sound/effects/Glasshit.ogg'
hardness = 100
stack_origin_tech = list(TECH_MATERIAL = 6)
golem = "Diamond Golem"
@@ -384,6 +387,7 @@ var/list/name_to_material
icon_reinf = "reinf_over"
icon_colour = "#666666"
golem = "Steel Golem"
hitsound = 'sound/weapons/smash.ogg'
/material/diona
name = "biomass"
@@ -420,6 +424,7 @@ var/list/name_to_material
stack_origin_tech = list(TECH_MATERIAL = 2)
composite_material = list(DEFAULT_WALL_MATERIAL = 3750, "platinum" = 3750) //todo
golem = "Plasteel Golem"
hitsound = 'sound/weapons/smash.ogg'
/material/plasteel/titanium
name = "titanium"
@@ -636,6 +641,7 @@ var/list/name_to_material
sheet_singular_name = "ingot"
sheet_plural_name = "ingots"
golem = "Iron Golem"
hitsound = 'sound/weapons/smash.ogg'
// Adminspawn only, do not let anyone get this.
/material/voxalloy
@@ -677,6 +683,7 @@ var/list/name_to_material
sheet_singular_name = "plank"
sheet_plural_name = "planks"
golem = "Wood Golem"
hitsound = 'sound/effects/woodhit.ogg'
/material/rust
name = "rust"

View File

@@ -1513,6 +1513,24 @@
var/obj/effect/golemrune/Z = new /obj/effect/golemrune
Z.forceMove(get_turf(holder.my_atom))
/datum/chemical_reaction/soap_key
name = "Soap Key"
id = "skey"
result = null
required_reagents = list("triglyceride" = 2, "water" = 2, "cleaner" = 3)
var/strength = 3
/datum/chemical_reaction/soap_key/can_happen(var/datum/reagents/holder)
if(holder.my_atom && istype(holder.my_atom, /obj/item/weapon/soap))
return ..()
return 0
/datum/chemical_reaction/soap_key/on_reaction(var/datum/reagents/holder)
var/obj/item/weapon/soap/S = holder.my_atom
if(S.key_data)
var/obj/item/weapon/key/soap/key = new(get_turf(holder.my_atom), S.key_data)
key.uses = strength
..()
/*
====================

View File

@@ -0,0 +1,7 @@
author: Alberyk
delete-after: True
changes:
- rscadd: "Ported key and lock from baystation, you can place them in regular material doors to lock them."
- bugfix: "Fixed material doors being nearly indestructible."

Binary file not shown.

Before

Width:  |  Height:  |  Size: 85 KiB

After

Width:  |  Height:  |  Size: 85 KiB