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


(local
    newView
    local1
    local2
    local3

)
(instance public Room66 of Rm
    (properties
        picture 66
        style 16
    )

    (method (init)
        Load(rsVIEW 512)
        Load(rsVIEW 44)
        Load(rsVIEW 42)
        Load(rsVIEW 41)
        Load(rsVIEW 4)
        Load(rsSCRIPT 991)
        (self:setRegions(603))
        (super:init())
        (send ((View:new())):
            view(512)
            loop(1)
            cel(0)
            posn(208 80)
            setPri(4)
            addToPic()
        )
        (send ((Prop:new())):
            view(512)
            loop(0)
            posn(206 65)
            setPri(3)
            init()
            setCycle(Fwd)
        )
        (if (== (send ((send gInv:at(15))):owner()) 66)
            (send (= newView (View:new())):
                view(512)
                loop(2)
                cel(0)
                posn(194 123)
                init()
                stopUpd()
            )
        )
        (if ((== gPicture 67) or (== gPicture 0))
            (send gEgo:
                illegalBits(49152)
                posn(240 128)
                view(4)
                xStep(4)
                yStep(1)
                init()
                setPri(-1)
            )
            = local1 1
            (send gEgo:observeBlocks(stair1))
        )
        (if (== gPicture 61)
            (send gEgo:
                illegalBits(32768)
                view(4)
                xStep(4)
                setPri(7)
                yStep(1)
                posn(102 38)
                baseSetter(ScriptID(0 1))
                init()
            )
            = local1 0
        )
        (send gEgo:observeBlocks(stair2))
    )


    (method (doit)
        (super:doit())
        (if (& (send gEgo:onControl(0)) $0040)
            (send global2:newRoom(67))
        )
        (if (& (send gEgo:onControl(0)) $0020)
            (send global2:newRoom(61))
        )
        (if (((& (send gEgo:onControl(0)) $0004) and not local1) and (<> (self:script()) stairTrip))
            (self:setScript(stairTrip))
        )
        (if (& (send gEgo:onControl(1)) $0800)
            (if (> (send gEgo:heading()) 180)
                = local1 0
                (if ((send gEgo:blocks()))
                    (send gEgo:ignoreBlocks(stair1))
                )
                (send gEgo:
                    illegalBits(32768)
                    baseSetter(ScriptID(0 1))
                    setPri(12)
                )
            )(else
                = local1 1
                (send gEgo:
                    observeBlocks(stair1)
                    illegalBits(49152)
                    baseSetter(0)
                    setPri(-1)
                )
            )
        )
        (if (((send gEgo:inRect(183 150 205 168)) and (& (send gEgo:onControl()) $0800)) and local1)
            (send gEgo:setPri(12))
        )(else
            (if ((local1 and not (send gEgo:inRect(183 150 205 168))) and (== (send gEgo:priority()) 12))
                (send gEgo:setPri(-1))
            )
        )
        (if (& (send gEgo:onControl(1)) $0400)
            (if ((< (send gEgo:heading()) 90) or (> (send gEgo:heading()) 270))
                (send gEgo:setPri(7))
            )(else
                (send gEgo:setPri(12))
            )
        )
    )


    (method (dispose)
        DisposeScript(991)
        (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>'))
                        (if (Said('/stair'))
                            Print(66 0)
                        )(else
                            (if (Said('/door'))
                                Print(66 1)
                            )(else
                                (if (Said('/dirt') or Said('<down'))
                                    Print(66 2)
                                )(else
                                    (if (Said('/wall'))
                                        Print(66 3)
                                    )(else
                                        (if (Said('/torch'))
                                            Print(66 4)
                                        )(else
                                            (if (Said('<up'))
                                                Print(66 5)
                                            )(else
                                                (if (Said('[<around][/room,tower]'))
                                                    Print(Format(@global300 66 6 
                                                            (if (== (send ((send gInv:at(15))):owner()) 66)
                                                                "You notice a shovel leaning against the wall."
                                                            )(else
                                                                " "
                                                            )
))
                                                )(else
                                                    (send pEvent:claimed(0))
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )(else
                        (if (Said('*/stair'))
                            Print(66 7)
                        )(else
                            (if (Said('get/shovel'))
                                (if ((== (send ((send gInv:at(15))):owner()) 66) and (send gCast:contains(newView)))
                                    (if (< (send gEgo:distanceTo(newView)) 15)
                                        (send gEgo:get(15))
                                        = global182 1
                                        (send gGame:changeScore(2))
                                        (send newView:dispose())
                                    )(else
                                        Print(800 1)
                                    )
                                )(else
                                    Print(66 8)
                                )
                            )(else
                                (if (Said('get/torch'))
                                    Print(66 9)
                                )(else
                                    (if (Said('close/door'))
                                        Print(66 10)
                                    )(else
                                        (if (Said('open/door'))
                                            Print(66 11)
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
    )

)
(instance stairTrip of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (proc0_10() (send gEgo:
                    illegalBits(0)
                    ignoreActors(1)
                )
 
                (if (< (send gEgo:y()) 90)
                    = local2 1
                )
 (self:cue())  )
            )
            (case 1
                ((send gEgo:
                    view(44)
                    moveSpeed(0)
                    setMotion(0)
                    setLoop(0)
                    setCycle(End self)
                )
 (send ((Sound:new())):
                    number(51)
                    loop(1)
                    play()
                )
  )
            )
            (case 2
                ((send gEgo:setPri(11)) proc0_20() (send gEgo:
                    setStep(10 10)
                    setLoop(2)
                    setCycle(Fwd)
                    setMotion(JumpTo 185 142 self)
                )
  )
            )
            (case 3
                (
                (if (local2)
                    (send gEgo:
                        view(42)
                        loop(0)
                        cel(0)
                        setPri(8)
                    )
                    (send (ScriptID(0 4)):setCycle(self 2))
                )(else
                    = local1 1
                    (send gEgo:observeBlocks(stair1))
                    (send gEgo:
                        view(41)
                        setPri(-1)
                        cel(0)
                        setLoop(0)
                        setCycle(End self)
                    )
                )
 )
            )
            (case 4
                (
                (if (local2)
                    kernel[106](10)
                    = seconds 3
                )(else
                    (send gEgo:
                        view(4)
                        xStep(4)
                        yStep(1)
                        setCycle(Walk)
                        setLoop(-1)
                        setPri(-1)
                        illegalBits(49152)
                        baseSetter(0)
                        ignoreActors(0)
                    )
                    = state -1
                    proc0_11()
                    (send client:setScript(0))
                )
 )
            )
            (case 5
                (= global127 1 )
            )
        )
    )

)
(instance stair1 of Blk
    (properties
        top 116
        left 147
        bottom 117
        right 159
    )
)
(instance stair2 of Blk
    (properties
        top 194
        left 198
        bottom 149
        right 151
    )
)
