forked from NebulaSS13/Nebula
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclick.dm
More file actions
372 lines (302 loc) · 10.4 KB
/
click.dm
File metadata and controls
372 lines (302 loc) · 10.4 KB
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
/*
Click code cleanup
~Sayu
*/
// 1 decisecond click delay (above and beyond mob/next_move)
/mob/var/next_click = 0
/*
Before anything else, defer these calls to a per-mobtype handler. This allows us to
remove istype() spaghetti code, but requires the addition of other handler procs to simplify it.
Alternately, you could hardcode every mob's variation in a flat ClickOn() proc; however,
that's a lot of code duplication and is hard to maintain.
Note that this proc can be overridden, and is in the case of screen objects.
*/
/atom/Click(var/location, var/control, var/params) // This is their reaction to being clicked on (standard proc)
var/list/L = params2list(params)
var/dragged = L["drag"]
if(dragged && !L[dragged])
return
var/datum/click_handler/click_handler = usr.GetClickHandler()
click_handler.OnClick(src, params)
/atom/DblClick(var/location, var/control, var/params)
var/datum/click_handler/click_handler = usr.GetClickHandler()
click_handler.OnDblClick(src, params)
/atom/proc/allow_click_through(var/atom/A, var/params, var/mob/user)
return FALSE
/turf/allow_click_through(var/atom/A, var/params, var/mob/user)
return TRUE
/*
Standard mob ClickOn()
Handles exceptions: middle click, modified clicks, exosuit actions
After that, mostly just check your state, check whether you're holding an item,
check whether you're adjacent to the target, then pass off the click to whoever
is receiving it.
The most common are:
* mob/UnarmedAttack(atom,adjacent) - used here only when adjacent, with no item in hand; in the case of humans, checks gloves
* atom/attackby(item,user) - used only when adjacent
* item/afterattack(atom,user,adjacent,params) - used both ranged and adjacent
* mob/RangedAttack(atom,params) - used only ranged, only used for tk and laser eyes but could be changed
*/
/mob/proc/ClickOn(var/atom/A, var/params)
if(world.time <= next_click) // Hard check, before anything else, to avoid crashing
return
next_click = world.time + 1
var/list/modifiers = params2list(params)
if(modifiers["right"])
RightClickOn(A)
return 1
if(modifiers["shift"] && modifiers["ctrl"])
CtrlShiftClickOn(A)
return 1
if(modifiers["ctrl"] && modifiers["alt"])
CtrlAltClickOn(A)
return 1
if(modifiers["middle"] && modifiers["alt"])
AltMiddleClickOn(A)
return 1
if(modifiers["middle"])
MiddleClickOn(A)
return 1
if(modifiers["shift"])
ShiftClickOn(A)
return 0
if(modifiers["alt"]) // alt and alt-gr (rightalt)
AltClickOn(A)
return 1
if(modifiers["ctrl"])
CtrlClickOn(A)
return 1
if(incapacitated(INCAPACITATION_KNOCKOUT))
return
// Do not allow player facing change in fixed chairs
if(!istype(buckled) || buckled.buckle_movable || buckled.buckle_allow_rotation)
face_atom(A) // change direction to face what you clicked on
if(!canClick()) // in the year 2000...
return
if(restrained())
setClickCooldown(10)
RestrainedClickOn(A)
return 1
if(in_throw_mode)
if(isturf(A) || isturf(A.loc))
mob_throw_item(A)
trigger_aiming(TARGET_CAN_CLICK)
return 1
toggle_throw_mode(FALSE)
var/obj/item/holding = get_active_held_item()
if(holding == A) // Handle attack_self
holding.attack_self(src)
trigger_aiming(TARGET_CAN_CLICK)
update_inhand_overlays(FALSE)
return 1
//Atoms on your person
// A is your location but is not a turf; or is on you (backpack); or is on something on you (box in backpack); sdepth is needed here because contents depth does not equate inventory storage depth.
var/sdepth = A.storage_depth(src)
if((!isturf(A) && A == loc) || (sdepth != -1 && sdepth <= 1))
if(holding)
var/resolved = holding.resolve_attackby(A, src, params)
if(!resolved && A && holding)
holding.afterattack(A, src, 1, params) // 1 indicates adjacency
setClickCooldown(DEFAULT_QUICK_COOLDOWN)
else
if(ismob(A)) // No instant mob attacking
setClickCooldown(DEFAULT_QUICK_COOLDOWN)
UnarmedAttack(A, TRUE)
trigger_aiming(TARGET_CAN_CLICK)
return 1
if(!loc.allow_click_through(A, params, src)) // This is going to stop you from telekinesing from inside a closet, but I don't shed many tears for that
return
//Atoms on turfs (not on your person)
// A is a turf or is on a turf, or in something on a turf (pen in a box); but not something in something on a turf (pen in a box in a backpack)
sdepth = A.storage_depth_turf()
if(isturf(A) || isturf(A.loc) || (sdepth != -1 && sdepth <= 1))
if(A.Adjacent(src)) // see adjacent.dm
if(holding)
// Return 1 in attackby() to prevent afterattack() effects (when safely moving items for example)
var/resolved = holding.resolve_attackby(A, src, params)
if(!resolved && A && holding)
holding.afterattack(A, src, 1, params) // 1: clicking something Adjacent
setClickCooldown(DEFAULT_QUICK_COOLDOWN)
else
if(ismob(A)) // No instant mob attacking
setClickCooldown(DEFAULT_QUICK_COOLDOWN)
UnarmedAttack(A, TRUE)
trigger_aiming(TARGET_CAN_CLICK)
return
else // non-adjacent click
if(holding)
holding.afterattack(A, src, 0, params) // 0: not Adjacent
else
RangedAttack(A, params)
trigger_aiming(TARGET_CAN_CLICK)
return 1
/mob/proc/setClickCooldown(var/timeout)
next_move = max(world.time + timeout, next_move)
/mob/proc/canClick()
if(get_config_value(/decl/config/toggle/no_click_cooldown) || next_move <= world.time)
return 1
return 0
// Default behavior: ignore double clicks, the second click that makes the doubleclick call already calls for a normal click
/mob/proc/DblClickOn(var/atom/A, var/params)
if(get_preference_value(/datum/client_preference/show_turf_contents) == PREF_DOUBLE_CLICK)
. = A.show_atom_list_for_turf(src, get_turf(A))
/*
Translates into attack_hand, etc.
Note: proximity_flag here is used to distinguish between normal usage (flag=1),
and usage when clicking on things telekinetically (flag=0). This proc will
not be called at ranged except with telekinesis.
proximity_flag is not currently passed to attack_hand, and is instead used
in human click code to allow glove touches only at melee range.
Returns TRUE if no further processing is desired, FALSE otherwise.
*/
/mob/proc/UnarmedAttack(var/atom/A, var/proximity_flag)
return
/mob/living/UnarmedAttack(var/atom/A, var/proximity_flag)
if(GAME_STATE < RUNLEVEL_GAME)
to_chat(src, "You cannot attack people before the game has started.")
return TRUE
if(stat || try_maneuver(A) || !proximity_flag)
return TRUE
// Handle any prepared ability/spell/power invocations.
var/datum/extension/abilities/abilities = get_extension(src, /datum/extension/abilities)
if(abilities?.do_melee_invocation(A))
return TRUE
// Special glove functions:
// If the gloves do anything, have them return 1 to stop
// normal attack_hand() here.
var/obj/item/clothing/gloves/G = get_equipped_item(slot_gloves_str) // not typecast specifically enough in defines
if(istype(G) && G.Touch(A,1))
return TRUE
return A.attack_hand(src)
/*
Ranged unarmed attack:
This currently is just a default for all mobs, involving
laser eyes and telekinesis. You could easily add exceptions
for things like ranged glove touches, spitting alien acid/neurotoxin,
animals lunging, etc.
*/
/mob/proc/RangedAttack(var/atom/A, var/params)
return FALSE
/mob/living/RangedAttack(var/atom/A, var/params)
if(try_maneuver(A))
return TRUE
// Handle any prepared ability/spell/power invocations.
var/datum/extension/abilities/abilities = get_extension(src, /datum/extension/abilities)
if(abilities?.do_ranged_invocation(A))
return TRUE
if(A.attack_hand_ranged(src))
return TRUE
return FALSE
/*
Restrained ClickOn
Used when you are cuffed and click things.
Not currently used by anything but could easily be.
*/
/mob/proc/RestrainedClickOn(var/atom/A)
return
/*
Middle click
Only used for swapping hands
*/
/mob/proc/MiddleClickOn(var/atom/A)
swap_hand()
/mob/proc/AltMiddleClickOn(var/atom/A)
pointed(A)
// In case of use break glass
/*
/atom/proc/MiddleClick(var/mob/M)
return
*/
/*
Shift click
For most mobs, examine.
This is overridden in ai.dm
*/
/mob/proc/ShiftClickOn(var/atom/A)
A.ShiftClick(src)
return
/atom/proc/ShiftClick(var/mob/user)
if(user.client && user.client.eye == user)
user.examine_verb(src)
return
/*
Ctrl click
For most objects, pull
*/
/mob/proc/CtrlClickOn(var/atom/A)
return A.CtrlClick(src)
/atom/proc/CtrlClick(var/mob/user)
if(get_recursive_loc_of_type(/mob) == user)
var/decl/interaction_handler/handler = get_quick_interaction_handler(user)
if(handler)
var/using_item = user.get_active_held_item()
if(handler.is_possible(src, user, using_item))
return handler.invoked(src, user, using_item)
return FALSE
/atom/movable/CtrlClick(var/mob/living/user)
if(!(. = ..()) && loc != user)
return try_make_grab(user, defer_hand = TRUE) || ..()
/*
Alt click
Unused except for AI
*/
/mob/proc/AltClickOn(var/atom/A)
A.AltClick(src)
/atom/proc/AltClick(var/mob/user)
if(try_handle_interactions(user, get_alt_interactions(user), user?.get_active_held_item(), check_alt_interactions = TRUE))
return TRUE
if(user?.get_preference_value(/datum/client_preference/show_turf_contents) == PREF_ALT_CLICK)
. = show_atom_list_for_turf(user, get_turf(src))
/atom/proc/show_atom_list_for_turf(var/mob/user, var/turf/T)
if(T && user.TurfAdjacent(T))
if(user.listed_turf == T)
user.listed_turf = null
else
user.listed_turf = T
user.client.statpanel = "Turf"
. = TRUE
/mob/proc/TurfAdjacent(var/turf/T)
return T.AdjacentQuick(src)
/mob/observer/ghost/TurfAdjacent(var/turf/T)
if(!isturf(loc) || !client)
return FALSE
return z == T.z && (get_dist(loc, T) <= get_effective_view(client))
/mob/proc/RightClickOn(atom/A)
A.RightClick(src)
return
/atom/proc/RightClick(mob/user)
return
/*
Control+Shift click
Unused except for AI
*/
/mob/proc/CtrlShiftClickOn(var/atom/A)
A.CtrlShiftClick(src)
return
/atom/proc/CtrlShiftClick(var/mob/user)
return
/*
Control+Alt click
*/
/mob/proc/CtrlAltClickOn(var/atom/A)
A.CtrlAltClick(src)
return
/atom/proc/CtrlAltClick(var/mob/user)
return
// Simple helper to face what you clicked on, in case it should be needed in more than one place
/mob/proc/face_atom(var/atom/A)
if(!A || !x || !y || !A.x || !A.y) return
var/dx = A.x - x
var/dy = A.y - y
if(!dx && !dy) return
var/direction
if(abs(dx) < abs(dy))
if(dy > 0) direction = NORTH
else direction = SOUTH
else
if(dx > 0) direction = EAST
else direction = WEST
if(direction != dir)
if(facing_dir)
facing_dir = direction
facedir(direction)