1 ;; ----------------------------------------------------------------------------
3 ;; ----------------------------------------------------------------------------
5 ;; Runs the 'disarm-trap' task. kchar is the person doing the task, ktarg is
6 ;; the object the traps are attached to. Only one trap is worked on per
7 ;; iteration. When there are no traps left the task is done. Each time in, we
8 ;; roll to see if the char is done with the next trap. If so, we roll to see if
9 ;; they succeed in disarming. If not, we trip the trap. Note that the
10 ;; trap-trigger procedure gives the char another chance to roll to avoid. The
11 ;; chief benefit of using the disarm skill is it gives an extra roll to avoid
12 ;; tripping the trap. The only other advantage is when the on-damage hooks are
13 ;; in place for tasks they will give the player a chance to abort before
14 ;; tripping any more traps. By comparison, when you search or open a door (for
15 ;; example) it will trip all the traps in sequence, which can do a lot of
16 ;; damage if there are multiple traps.
17 (define (disarm-task kchar ktarg)
19 (traps (filter (lambda (trap)
20 (and (trap-detected? trap)
21 (not (trap-tripped? trap))))
22 (ifccall ktarg 'get-traps)))
24 ;; Check if any unprocessed traps remaining
25 (println "traps: " traps)
27 (kern-char-task-end kchar)
29 ((not (handles? ktarg 'rm-traps))
30 (kern-log-msg "Traps can't be removed!")
31 (kern-char-task-abort kchar)
34 ;; Roll to complete the task (on the current trap)
37 (dc (trap-avoid-dc trap))
38 (roll (kern-dice-roll "1d20"))
39 (bonus (occ-thief-dice-roll kchar))
41 (println "trap: " trap " dc: " dc " roll: " roll " bonus: " bonus)
44 (> (+ roll bonus) (* 2 dc))
48 (roll (kern-dice-roll "1d20"))
49 (bonus (occ-thief-dice-roll kchar))
51 (println "roll2: " roll " bonus2: " bonus)
56 ;; Success - disarm the trap
57 (kern-log-msg (kern-obj-get-name kchar) " ^c+gdisarms^c- a " (trap-name trap) " trap!")
58 (trap-set-tripped! trap #t)
61 ;; Failure - trip the trap (kchar will get another roll
62 ;; to avoid the damage)
63 (trap-trigger trap ktarg kchar)
65 ;; Last trap just proceessed
66 (if (= 1 (length traps))
67 (kern-char-task-end kchar))
71 (define (skill-disarm-trap kactor)
73 ;; Called after the player has selected a target to disarm.
74 (define (cb kactor ktarg power)
76 (traps (filter (lambda (trap)
77 (and (trap-detected? trap)
78 (not (trap-tripped? trap))))
79 (ifccall ktarg 'get-traps)))
81 ;; Check if there are any unprocessed traps
82 (println "traps: " traps)
87 ;; Start a task to disarm the traps
88 (kern-char-task-begin kactor "disarming a trap" 'disarm-task ktarg)
92 ;; fixme: only checks topmost item.
93 (cast-ui-ranged-any cb
96 (occ-ability-thief kactor)
98 (and (kern-obj-is-visible? kobj)