OSDN Git Service

3a16e73165238a879c3e34de57c01c7459aea60c
[nazghul-jp/nazghul-jp.git] / worlds / haxima-1.002 / disarm-trap.scm
1 ;; ----------------------------------------------------------------------------
2 ;; Disarm Trap skill
3 ;; ----------------------------------------------------------------------------
4
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)
18   (let* (
19          (traps (filter (lambda (trap) 
20                           (and (trap-detected? trap) 
21                                (not (trap-tripped? trap))))
22                         (ifccall ktarg 'get-traps)))
23         )
24     ;; Check if any unprocessed traps remaining
25     (println "traps: " traps)
26     (cond ((null? traps) 
27            (kern-char-task-end kchar)
28            )
29           ((not (handles? ktarg 'rm-traps)) 
30            (kern-log-msg "Traps can't be removed!")
31            (kern-char-task-abort kchar)
32            )
33           (else
34            ;; Roll to complete the task (on the current trap)
35            (let* (
36                   (trap (car traps))
37                   (dc (trap-avoid-dc trap))
38                   (roll (kern-dice-roll "1d20"))
39                   (bonus (occ-thief-dice-roll kchar))
40                   )
41              (println "trap: " trap " dc: " dc " roll: " roll " bonus: " bonus)
42              (if (or 
43                   (= roll 20) 
44                   (> (+ roll bonus) (* 2 dc))
45                   )
46                  ;; Roll to succeed
47                  (let (
48                        (roll (kern-dice-roll "1d20"))
49                        (bonus (occ-thief-dice-roll kchar))
50                        )
51                    (println "roll2: " roll " bonus2: " bonus)
52                    (cond ((or 
53                            (= roll 20) 
54                            (> (+ roll bonus) dc)
55                            )
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)
59                           )
60                       (else
61                        ;; Failure - trip the trap (kchar will get another roll
62                        ;; to avoid the damage)
63                        (trap-trigger trap ktarg kchar)
64                        ))
65                    ;; Last trap just proceessed
66                    (if (= 1 (length traps))
67                        (kern-char-task-end kchar))
68                    )))))))
69                 
70
71 (define (skill-disarm-trap kactor)
72
73   ;; Called after the player has selected a target to disarm.
74   (define (cb kactor ktarg power)
75     (let (
76           (traps (filter (lambda (trap) 
77                            (and (trap-detected? trap) 
78                                 (not (trap-tripped? trap))))
79                          (ifccall ktarg 'get-traps)))
80           )
81       ;; Check if there are any unprocessed traps
82       (println "traps: " traps)
83       (cond ((null? traps) 
84              result-no-effect
85              )
86             (else
87              ;; Start a task to disarm the traps
88              (kern-char-task-begin kactor "disarming a trap" 'disarm-task ktarg)
89              result-ok
90              ))))
91
92   ;; fixme: only checks topmost item.
93   (cast-ui-ranged-any cb
94                       kactor 
95                       1
96                       (occ-ability-thief kactor)
97                       (lambda (kobj)
98                         (and (kern-obj-is-visible? kobj)
99                              (handles? kobj 
100                                        'rm-traps)))))