forked from tgstation/tgstation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
traps.dm
225 lines (183 loc) · 8.22 KB
/
traps.dm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/obj/effect/pressure_plate
name = "pressure plate"
desc = "A pressure plate that triggers a trap or a few of them."
density = 0
var/list/connected_traps_names = list() //mappers, edit this when you place pressure plates on the map. don't forget to make the connected traps have an UNIQUE name
var/list/connected_traps = list() //actual references to the connected traps. leave empty, it is generated at runtime from connected_traps_names
var/trigger_type = "mob and obj" //can be "mob", "obj" or "mob and obj", the only moveable types
/obj/effect/pressure_plate/New()
..()
src:visibility = 0
refresh()
/obj/effect/pressure_plate/verb/refresh()
set name = "Refresh Pressure Plate Links"
set category = "Object"
set src in view()
connected_traps = list() //emptying the list first
for(var/trap_name in connected_traps_names)
for(var/obj/effect/trap/the_trap in world)
if(the_trap.name == trap_name)
connected_traps += the_trap //adding the trap with the matching name
/obj/effect/pressure_plate/HasEntered(atom/victim as mob|obj)
if(victim.density && (trigger_type == "mob and obj" || (trigger_type == "mob" && istype(victim,/mob)) || (trigger_type == "obj" && istype(victim,/obj))))
for(var/obj/effect/trap/T in connected_traps)
T.trigger(victim)
/obj/effect/pressure_plate/Bumped(atom/victim as mob|obj)
if(victim.density && (trigger_type == "mob and obj" || (trigger_type == "mob" && istype(victim,/mob)) || (trigger_type == "obj" && istype(victim,/obj))))
for(var/obj/effect/trap/T in connected_traps)
T.trigger(victim)
/obj/effect/trap //has three subtypes - /aoe, /area (ie affects an entire area), /single (only the victim is affected)
name = "trap"
desc = "It's a trap!"
density = 0
var/uses = 1 //how many times it can be triggered
var/trigger_type = "mob and obj" //can be "mob", "obj" or "mob and obj", the only moveable types. can also be "none" to not be triggered by entering its square (needs to have a pressure plate attached in that case)
var/target_type = "mob" //if it targets mobs, turfs or objs
var/include_dense = 1 //if it includes dense targets in the aoe (may be important for some reason). you'll probably want to change it to 1 if you target mobs or objs
/obj/effect/trap/New()
..()
src:visibility = 0 //seriously, it keeps saying "undefined var" when I try to do it in the define
/obj/effect/trap/HasEntered(victim as mob|obj)
if(trigger_type == "mob and obj" || (trigger_type == "mob" && istype(victim,/mob)) || (trigger_type == "obj" && istype(victim,/obj)))
trigger(victim)
/obj/effect/trap/Bumped(victim as mob|obj)
if(trigger_type == "mob and obj" || (trigger_type == "mob" && istype(victim,/mob)) || (trigger_type == "obj" && istype(victim,/obj)))
trigger(victim)
/obj/effect/trap/proc/trigger(victim)
if(!uses)
return
uses--
activate(victim)
/obj/effect/trap/proc/activate()
/obj/effect/trap/aoe
name = "aoe trap"
desc = "This trap affects a number of mobs, turfs or objs in an aoe"
var/aoe_radius = 3 //radius of aoe
var/aoe_range_or_view = "view" //if it includes all tiles in [radius] range or view
/obj/effect/trap/aoe/proc/picktargets()
var/list/targets = list()
switch(target_type)
if("turf")
switch(aoe_range_or_view)
if("view")
for(var/turf/T in view(src,aoe_radius))
if(!T.density || include_dense)
targets += T
if("range")
for(var/turf/T in range(src,aoe_radius))
if(!T.density || include_dense)
targets += T
if("mob")
switch(aoe_range_or_view)
if("view")
for(var/mob/living/M in view(src,aoe_radius))
if(!M.density || include_dense)
targets += M
if("range")
for(var/mob/living/M in range(src,aoe_radius))
if(!M.density || include_dense)
targets += M
if("obj")
switch(aoe_range_or_view)
if("view")
for(var/obj/O in view(src,aoe_radius))
if(!O.density || include_dense)
targets += O
if("range")
for(var/obj/O in range(src,aoe_radius))
if(!O.density || include_dense)
targets += O
return targets
/obj/effect/trap/aoe/rocksfall
name = "rocks fall trap"
desc = "Your DM must really hate you."
target_type = "turf"
include_dense = 0
var/rocks_amt = 10 //amount of rocks falling
var/rocks_min_dmg = 50 //min damage per rock
var/rocks_max_dmg = 100 //max damage per rock
var/rocks_hit_chance = 100 //the chance for a rock to hit you
var/list/rocks_type = list() //what rocks might it drop on the target. with var editing, not even limited to rocks.
/obj/effect/trap/aoe/rocksfall/New()
..()
rocks_type = pick_rock_types()
/obj/effect/trap/aoe/rocksfall/proc/pick_rock_types() //since we may want subtypes of the trap with completely different rock types, which is best done this way
var/list/varieties = list()
varieties = typesof(/obj/item/weapon/ore)
varieties -= /obj/item/weapon/ore/diamond //don't want easily available rare ores, hmm?
varieties -= /obj/item/weapon/ore/uranium
varieties -= /obj/item/weapon/ore/slag //that'd be just stupid
return varieties
/obj/effect/trap/aoe/rocksfall/activate()
var/list/targets = list()
targets = picktargets()
if(target_type == "turf")
for(var/i=0,i<rocks_amt,i++)
var/turf/hit_loc = pick(targets)
var/rock_type = pick(rocks_type)
var/obj/item/weapon/ore/rock = new rock_type(hit_loc)
for(var/mob/living/M in hit_loc)
if(prob(rocks_hit_chance))
M.take_organ_damage(rand(rocks_min_dmg,rocks_max_dmg))
M << "A chunk of [lowertext(rock.name)] hits you in the head!"
if(target_type == "mob")
for(var/i=0,i<rocks_amt,i++)
var/mob/living/hit_loc = pick(targets)
var/rock_type = pick(rocks_type)
var/obj/item/weapon/ore/rock = new rock_type(hit_loc.loc)
if(prob(rocks_hit_chance))
hit_loc.take_organ_damage(rand(rocks_min_dmg,rocks_max_dmg))
hit_loc << "A chunk of [lowertext(rock.name)] hits you in the head!"
/obj/effect/trap/single
name = "single-target trap"
desc = "This trap targets a single movable atom, usually the one who triggered it" //usually as in I will code only those ones. if you want to add a different type of targeting, go ahead.
/obj/effect/trap/single/rockfalls
name = "rock falls trap"
desc = "Your DM must really hate <b>YOU</b>."
trigger_type = "mob"
var/rock_min_dmg = 100 //min damage of the rock
var/rock_max_dmg = 200 //max damage of the rock
var/rock_hit_chance = 100 //the chance for the rock to hit you
var/list/rocks_type = list() //what rocks might it drop on the target. with var editing, not even limited to rocks.
/obj/effect/trap/single/rockfalls/New()
..()
rocks_type = pick_rock_types()
/obj/effect/trap/single/rockfalls/proc/pick_rock_types() //since we may want subtypes of the trap with completely different rock types, which is best done this way
var/list/varieties = list()
varieties = typesof(/obj/item/weapon/ore)
varieties -= /obj/item/weapon/ore/diamond //don't want easily available rare ores, hmm?
varieties -= /obj/item/weapon/ore/uranium
varieties -= /obj/item/weapon/ore/slag //that'd be just stupid
return varieties
/obj/effect/trap/single/rockfalls/activate(mob/living/victim)
var/rock_type = pick(rocks_type)
var/obj/item/weapon/ore/rock = new rock_type(victim:loc)
if (istype(victim) && prob(rock_hit_chance))
var/dmg = rand(rock_min_dmg,rock_max_dmg)
if(istype(victim, /mob/living/carbon/human))
var/mob/living/carbon/human/H = victim
var/datum/limb/affecting = H.organs["head"]
affecting.take_damage(dmg)
H.updatehealth()
else
victim.take_organ_damage(dmg)
victim << "A chunk of [lowertext(rock.name)] hits you in the head!"
/obj/effect/trap/area
name = "area trap"
desc = "This trap targets all atoms of the target_type in its area"
/obj/effect/trap/area/proc/pick_targets() //src.loc.loc should be the area
var/list/targets = list()
switch(target_type)
if("turf")
for(var/turf/T in src.loc.loc)
if(!T.density || include_dense)
targets += T
if("mob")
for(var/mob/living/M in src.loc.loc)
if(!M.density || include_dense)
targets += M
if("obj")
for(var/obj/O in src.loc.loc)
if(!O.density || include_dense)
targets += O
return targets