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


(local
    newAct
    newAct_2
    newProp_2
    newProp_3
    newProp_4
    newProp

)
(instance theMusic of Sound
    (properties)
)
(instance public Room86 of Rm
    (properties
        picture 86
        style 16
    )

    (method (init)
        Load(rsVIEW 81)
        Load(rsVIEW 82)
        Load(rsVIEW 147)
        Load(rsVIEW 607)
        Load(rsVIEW 141)
        Load(rsVIEW 633)
        (super:init())
        (self:setRegions(604))
        (send (= newProp (Prop:new())):
            view(607)
            posn(202 118)
            init()
            hide()
        )
        (send (= newProp_2 (Prop:new())):
            posn(281 65)
            view(633)
            cel(2)
            init()
            setCycle(Fwd)
        )
        (send (= newProp_3 (Prop:new())):
            posn(289 76)
            view(633)
            cel(0)
            init()
            setCycle(Fwd)
        )
        (send (= newProp_4 (Prop:new())):
            posn(296 65)
            view(633)
            cel(1)
            init()
            setCycle(Fwd)
        )
        (if ((== gPicture 87) or (== gPicture 0))
            (send gEgo:
                posn(303 142)
                view(4)
                xStep(4)
                yStep(1)
                init()
            )
            (send newProp:
                cel(0)
                init()
                stopUpd()
            )
            (if (global175)
                (send (= newAct (Act:new())):
                    view(141)
                    posn(+ (send gEgo:x()) 40 (send gEgo:y()))
                    setCycle(Walk)
                    illegalBits(0)
                    init()
                    setScript(henchChase)
                )
                (theMusic:
                    number(41)
                    loop(1)
                    init()
                )
            )
        )
        (if (== gPicture 83)
            (if (== global109 0)
                (User:
                    canControl(0)
                    canInput(0)
                )
                (send gEgo:
                    view(81)
                    loop(2)
                    posn(190 121)
                    init()
                    setCycle(Walk)
                    setScript(toThrone)
                )
            )(else
                (send gEgo:
                    posn(190 121)
                    view(4)
                    setStep(4 1)
                    init()
                )
            )
            (send newProp:
                cel(0)
                init()
                stopUpd()
            )
        )
        (if (== gPicture 92)
            (send gEgo:
                view(81)
                loop(1)
                posn(293 142)
                setStep(4 1)
                init()
                setCycle(Walk)
            )
            (User:
                canControl(0)
                canInput(0)
            )
            (self:setScript(intoDungeon))
        )
    )


    (method (doit)
        (super:doit())
        (if ((& (send gEgo:onControl()) $0040) and (<> global109 0))
            (send global2:newRoom(87))
        )
    )


    (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/room,castle,hall'))
                        Print(Format(@global300 86 0 
                                (if (== (send newProp:cel()) 0)
                                    "a closed"
                                )(else
                                    "an open"
                                )
))
                    )(else
                        (if (Said('look>'))
                            (if (Said('/door'))
                                Print(86 1)
                            )(else
                                (if (Said('/table'))
                                    Print(86 2)
                                )(else
                                    (if (Said('/candelabra,candle'))
                                        Print(86 3)
                                    )(else
                                        (if (Said('/chair'))
                                            Print(86 4)
                                        )(else
                                            (if (Said('/wall'))
                                                Print(86 5)
                                            )(else
                                                (if (Said('/dirt') or Said('<down'))
                                                    Print(86 6)
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )(else
                            (if (Said('bang/door'))
                                (if (< (send gEgo:distanceTo(newProp)) 15)
                                    Print(86 7)
                                )(else
                                    Print(800 1)
                                )
                            )(else
                                (if (Said('open/door'))
                                    (if (> (send gEgo:distanceTo(newProp)) 15)
                                        Print(800 1)
                                    )(else
                                        (if (<> (send newProp:cel()) 0)
                                            Print(86 8)
                                        )(else
                                            (self:setScript(openDoor))
                                        )
                                    )
                                )(else
                                    (if (Said('close/door'))
                                        Print(86 9)
                                    )(else
                                        (if (Said('unlatch/door'))
                                            (if (< (send gEgo:distanceTo(newProp)) 15)
                                                Print(86 10)
                                            )(else
                                                Print(800 1)
                                            )
                                        )(else
                                            (if (Said('sit/chair'))
                                                Print(86 11)
                                            )(else
                                                (if (Said('get/candelabra'))
                                                    Print(86 12)
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
    )

)
(instance openDoor of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (proc0_10() (send newProp:setCycle(End self)) (send newProp:ignoreActors(1)) (send ((Sound:new())):
                    number(300)
                    loop(1)
                    play()
                )
  )
            )
            (case 1
                (proc0_11() (send global2:newRoom(83)) )
            )
        )
    )

)
(instance intoDungeon of Script
    (properties)

    (method (init param1)
        (super:init(param1))
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send gEgo:setMotion(MoveTo 187 122 self))  )
            )
            (case 1
                ((send gEgo:
                    view(82)
                    loop(0)
                )
 (self:cue())  )
            )
            (case 2
                ((send (= newAct (Act:new())):
                    view(147)
                    loop(3)
                    posn(- (send gEgo:x()) 15 (send gEgo:y()))
                    init()
                    moveSpeed(1)
                    setCycle(End)
                )
 (send (= newAct_2 (Act:new())):
                    view(147)
                    loop(4)
                    posn(+ (send gEgo:x()) 15 (send gEgo:y()))
                    setPri(+ (send gEgo:priority()) 1)
                    init()
                    moveSpeed(1)
                    setCycle(End)
                )
 (send gEgo:
                    loop(1)
                    setCycle(End self)
                )
  )
            )
            (case 3
                ((User:
                    canControl(1)
                    canInput(1)
                )
 (send gEgo:setLoop(-1)) (send global2:newRoom(83)) )
            )
        )
    )

)
(instance toThrone of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send gEgo:setMotion(MoveTo 329 130 self))  )
            )
            (case 1
                (= global205 1 (send global2:newRoom(92)) )
            )
        )
    )

)
(instance henchChase of Script
    (properties)

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

)
