(include "sci.sh")
(use "Main")
(use "Class_255_0")
(use "Sound")
(use "Cycle")
(use "Game")
(use "User")
(use "PV")
(use "Obj")
(script 87)


(local
    newAct
    newAct_2
    newAct_3
    newProp_2
    newProp_3
    newProp_4
    newProp
    local7

)
(instance theMusic of Sound
    (properties)
)
(instance public Room87 of Rm
    (properties
        picture 87
        style 16
    )

    (method (init)
        Load(rsVIEW 145)
        Load(rsVIEW 141)
        Load(rsVIEW 633)
        Load(rsVIEW 608)
        Load(rsVIEW 147)
        (self:setRegions(604))
        (super:init())
        proc0_12(604 0)
        (theMusic:
            number(41)
            loop(0)
            init()
        )
        (send (= newProp (Prop:new())):
            view(608)
            posn(111 118)
            cel(0)
            init()
            stopUpd()
        )
        (send (= newProp_2 (Prop:new())):
            posn(24 65)
            view(633)
            cel(2)
            init()
            setCycle(Fwd)
        )
        (send (= newProp_3 (Prop:new())):
            posn(32 75)
            view(633)
            cel(0)
            init()
            setCycle(Fwd)
        )
        (send (= newProp_4 (Prop:new())):
            posn(42 65)
            view(633)
            cel(1)
            init()
            setCycle(Fwd)
        )
        (if (global169)
            (send (= newAct (Act:new())):
                view(145)
                loop(4)
                posn(200 123)
                init()
                setScript(henchChase)
            )
        )(else
            (send (= newAct (Act:new())):
                view(147)
                loop(1)
                cel(0)
                posn(266 146)
                init()
                stopUpd()
            )
            (send (= newAct_2 (Act:new())):
                view(147)
                loop(2)
                cel(0)
                posn(250 158)
                init()
                stopUpd()
            )
            (send (= newAct_3 (Act:new())):
                view(147)
                loop(2)
                cel(0)
                posn(212 159)
                init()
                stopUpd()
            )
            (send newAct:setScript(circleJerk))
        )
        (if ((== gPicture 88) or (== gPicture 0))
            (send gEgo:
                posn(261 134)
                view(4)
                xStep(4)
                yStep(1)
                init()
            )
        )
        (if (== gPicture 86)
            (send gEgo:
                posn(25 142)
                view(4)
                xStep(4)
                yStep(1)
                init()
            )
        )
        (if (== gPicture 84)
            (send gEgo:
                posn(131 124)
                view(4)
                xStep(4)
                yStep(1)
                init()
            )
        )
    )


    (method (doit)
        (super:doit())
        (if (& (send gEgo:onControl(0)) $0040)
            (send global2:newRoom(86))
        )
        (if (& (send gEgo:onControl(0)) $0020)
            (send global2:newRoom(84))
        )
        (if (& (send gEgo:onControl(0)) $0010)
            (send global2:newRoom(88))
        )
    )


    (method (dispose)
        (send gSounds:eachElementDo(172))
        (super:dispose())
    )


    (method (handleEvent pEvent)
        return 
            (if ((send pEvent:claimed()))
                return 1
            )(else
                (if (== (send pEvent:type()) 128)
                    (if (Said('look[<around][/!*]') or Said('look[<around]/room,castle,hall'))
                        Print(87 0)
                    )(else
                        (if (Said('look>'))
                            (if (Said('/goon'))
                                Print(87 1 134 -1 20)
                            )(else
                                (if (Said('/door'))
                                    Print(87 2)
                                )(else
                                    (if (Said('/table'))
                                        Print(87 3)
                                    )(else
                                        (if (Said('/candelabra,candle'))
                                            Print(87 4)
                                        )(else
                                            (if (Said('/wall'))
                                                Print(87 5)
                                            )(else
                                                (if (Said('/dirt') or Said('<down'))
                                                    Print(87 6)
                                                )(else
                                                    (send pEvent:claimed(0))
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )(else
                            (if (Said('get/candelabra,candle'))
                                Print(87 7 134 -1 20)
                            )(else
                                (if (Said('bang/door'))
                                    (if (< (send gEgo:distanceTo(newProp)) 15)
                                        Print(87 8 134 -1 20)
                                    )(else
                                        Print(800 1)
                                    )
                                )(else
                                    (if (Said('open/door'))
                                        (if (<> (send newProp:cel()) 0)
                                            Print(87 9 134 -1 20)
                                        )(else
                                            (if (> (send gEgo:distanceTo(newProp)) 15)
                                                Print(800 1)
                                            )(else
                                                (send newProp:setCycle(End doDoor))
                                                (send ((Sound:new())):
                                                    number(300)
                                                    loop(1)
                                                    play()
                                                )
                                            )
                                        )
                                    )(else
                                        (if (Said('close/door'))
                                            Print(87 10)
                                        )(else
                                            (if (Said('unlatch/door'))
                                                (if (< (send gEgo:distanceTo(newProp)) 15)
                                                    Print(87 11)
                                                )(else
                                                    Print(800 1)
                                                )
                                            )(else
                                                (if (Said('/goon,man>'))
                                                    (if (Said('converse'))
                                                        Print(87 12 134 -1 20)
                                                    )(else
                                                        (if (Said('get,capture'))
                                                            Print(87 13 134 -1 20)
                                                        )(else
                                                            (if (Said('kiss'))
                                                                Print(87 14 134 -1 20)
                                                            )(else
                                                                (if (Said('deliver'))
                                                                    Print(87 15 134 -1 20)
                                                                )
                                                            )
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
    )

)
(instance doDoor of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send newProp:stopUpd()) (send global2:newRoom(84)) )
            )
        )
    )

)
(instance henchChase of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send newAct:
                    loop(2)
                    setCycle(End self)
                )
  )
            )
            (case 1
                ((send newAct:
                    loop(0)
                    setCycle(End self)
                )
  )
            )
            (case 2
                (= global175 1 (theMusic:
                    number(41)
                    loop(10)
                    play()
                )
 (send newAct:
                    view(141)
                    setCycle(Walk)
                    setMotion(Chase gEgo 15 self)
                )
  )
            )
            (case 3
                ((User:
                    canControl(0)
                    canInput(0)
                )
 (send gEgo:
                    moveSpeed(0)
                    setMotion(0)
                )
 (theMusic:
                    number(42)
                    loop(1)
                    play()
                )
 = seconds 4  )
            )
            (case 4
                (= global205 1 (send global2:newRoom(81)) )
            )
        )
    )

)
(instance circleJerk of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send (ScriptID(0 4)):setReal(self 2))  )
            )
            (case 1
                ((send newAct:setCycle(End)) (send newAct_2:setCycle(End)) (send newAct_3:setCycle(End)) (send (ScriptID(0 4)):setReal(self 5))  )
            )
            (case 2
                ((send newAct_2:setCycle(Beg)) (send newAct:setCycle(Beg)) (send newAct_3:setCycle(Beg self))  )
            )
            (case 3
                ((send newAct:stopUpd()) (send newAct_2:stopUpd()) (send newAct_3:stopUpd()) (send client:setScript(0)) )
            )
        )
    )

)
