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


(local
    local0
    newAct
    local2
    newAct_2
    newAct_3
    local5
    newAct_4
    local7
    newAct_5
    local9
    newProp
    newProp_2
    newProp_3
    newProp_4

)
(instance public Room55 of Rm
    (properties
        picture 55
        style 16
        east 56
    )

    (method (init)
        Load(rsSCRIPT 991)
        Load(rsVIEW 4)
        Load(rsVIEW 44)
        Load(rsVIEW 41)
        Load(rsVIEW 518)
        Load(rsVIEW 18)
        (self:setRegions(600))
        (super:init())
        = local0 0
        = global101 1
        (if ((== gPicture 28) or (== gPicture 0))
            (send gEgo:
                posn(100 83)
                view(4)
                loop(0)
                xStep(4)
                yStep(1)
                ignoreActors(0)
                illegalBits(32768)
                init()
            )
        )(else
            (send gEgo:
                posn(290 150)
                view(4)
                xStep(4)
                yStep(1)
                ignoreActors(0)
                illegalBits(32768)
                init()
            )
        )
        (send (= newProp (Prop:new())):
            view(518)
            posn(60 68)
            setPri(5)
            cel(2)
            cycleSpeed(1)
            setLoop(3)
            init()
            stopUpd()
        )
        (send (= newProp_2 (Prop:new())):
            view(518)
            posn(95 121)
            setPri(10)
            cel(1)
            setLoop(3)
            init()
            stopUpd()
        )
        (send (= newProp_3 (Prop:new())):
            view(518)
            posn(220 90)
            cycleSpeed(1)
            setLoop(3)
            init()
            stopUpd()
        )
        (send (= newProp_4 (Prop:new())):
            view(518)
            posn(245 49)
            cel(3)
            setLoop(3)
            init()
            stopUpd()
        )
        (send newProp:setScript(sparkle))
        (if (== global102 1)
            Load(rsVIEW 284)
            Load(rsVIEW 285)
            Load(rsVIEW 282)
            (send (= newAct (Act:new())):
                view(282)
                illegalBits(0)
                posn(219 154)
                setLoop(0)
                init()
                setScript(Watch)
            )
            (send (= newAct_2 (Act:new())):
                view(284)
                illegalBits(0)
                posn(188 129)
                setCycle(Fwd)
                init()
            )
            (send (= newAct_3 (Act:new())):
                view(285)
                illegalBits(0)
                posn(200 75)
                setLoop(1)
                setCycle(Fwd)
                init()
            )
        )(else
            Load(rsVIEW 289)
            Load(rsVIEW 286)
            Load(rsVIEW 287)
            (send gEgo:illegalBits(32772))
            (send ((View:new())):
                view(287)
                loop(2)
                cel(0)
                posn(213 130)
                addToPic()
            )
            (send ((View:new())):
                view(286)
                loop(5)
                cel(0)
                posn(233 130)
                addToPic()
            )
            (send (= newAct_4 (Act:new())):
                view(287)
                illegalBits(0)
                posn(213 114)
                setPri(11)
                setLoop(0)
                setCycle(Fwd)
                cycleSpeed(1)
                ignoreActors(1)
                init()
            )
            (send (= newAct_5 (Act:new())):
                view(286)
                illegalBits(0)
                posn(233 114)
                setPri(11)
                setLoop(3)
                setCycle(Fwd)
                cycleSpeed(2)
                ignoreActors(1)
                init()
            )
            (send (= newAct (Act:new())):
                view(289)
                illegalBits(0)
                posn(60 108)
                setCycle(Walk)
                init()
                ignoreActors(1)
            )
            (send newAct:setScript(SendOut))
        )
    )


    (method (doit)
        (if (== (send gEgo:script()) 0)
            (send gEgo:setPri(-1))
        )
        (if ((& (send gEgo:onControl(0)) $0040) and (<> (send gEgo:script()) Tripped))
            (send global2:newRoom(28))
        )
        (if (((& (send gEgo:onControl(1)) $1000) and (== local0 0)) and (== (send gEgo:script()) 0))
            (send gEgo:setScript(WalkPath))
        )
        (if ((((& (send gEgo:onControl()) $0002) or (& (send gEgo:onControl()) $1000)) and (== local0 0)) and (== (send gEgo:script()) 0))
            (send gEgo:setScript(WalkPath))
        )
        (if (((& (send gEgo:onControl(1)) $0004) and (== global102 1)) and (<> (send gEgo:script()) Tripped))
            (send gEgo:setScript(Tripped))
        )
        (if ((& (send gEgo:onControl()) $0010) and (== (send gEgo:script()) 0))
            (send gEgo:setPri(12))
            (if ((>= (send gEgo:heading()) 180) or (== (send gEgo:heading()) 0))
                = local0 0
                (send gEgo:illegalBits(32768))
            )(else
                = local0 1
                (send gEgo:illegalBits(36864))
            )
            (if (> (send gEgo:x()) 121)
                (send gEgo:setPri(-1))
            )
        )
        (super:doit())
    )


    (method (dispose)
        DisposeScript(991)
        (super:dispose())
    )


    (method (handleEvent pEvent)
        return 
            (if ((send pEvent:claimed()))
                return 1
            )(else
                (if ((== (send pEvent:type()) 128) and Said('look>'))
                    (if (Said('/door'))
                        Print(55 0)
                    )(else
                        (if (Said('<out[/(mine[<diamond]),(door[<mine])]'))
                            Print(55 1)
                        )(else
                            (if (Said('[<around][/!*]'))
                                Print(55 2)
                            )(else
                                (if (Said('<around') or Said('[<around]/room,mine<[diamond]'))
                                    Print(55 2)
                                )
                            )
                        )
                    )
                )
            )
    )


    (method (newRoom param1)
        (if (== param1 28)
            (send (ScriptID(600)):keep(0))
        )
        (super:newRoom(param1))
    )

)
(instance SendOut of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (= seconds 3  )
            )
            (case 1
                (proc0_10() Print(55 3) (send newAct:
                    setPri(-1)
                    setMotion(MoveTo 92 89)
                )
 (send gEgo:
                    illegalBits(0)
                    ignoreActors(1)
                    setMotion(MoveTo 101 81 self)
                )
  )
            )
            (case 2
                ((send gEgo:setMotion(MoveTo 74 81 self))  )
            )
            (case 3
                (proc0_11() (send gEgo:illegalBits(32768)) (send global2:newRoom(28)) )
            )
        )
    )

)
(instance Tripped of Script
    (properties)

    (method (changeState newState)
        (var temp0[40])
        (switch (= state newState)
            (case 0
                (proc0_10() (send gEgo:
                    illegalBits(0)
                    setPri(
                        (if (> (send gEgo:y()) 115)
                            11
                        )(else
                            10
                        )
)
                    ignoreActors(1)
                    view(44)
                    setStep(10 20)
                    setLoop(2)
                    setCycle(Fwd)
                    setMotion(JumpTo 
                        (if (< (send gEgo:x()) 100)
                            100
                        )(else
                            + (send gEgo:x()) 20
                        )
 149 self)
                )
  )
            )
            (case 1
                ((send gEgo:
                    view(18)
                    setLoop(1)
                    cel(0)
                    setCycle(Fwd)
                )
 = seconds 5  )
            )
            (case 2
                ((send gEgo:
                    view(41)
                    setLoop(0)
                    cel(0)
                    setCycle(End self)
                )
  )
            )
            (case 3
                (= local0 1 (send gEgo:
                    view(4)
                    setStep(4 1)
                    setCycle(Walk)
                    setLoop(-1)
                    setPri(-1)
                    illegalBits(36864)
                    ignoreActors(-1)
                )
 = state 0 (send client:setScript(0)) proc0_11() )
            )
        )
    )

)
(instance WalkPath of Script
    (properties)

    (method (doit)
        (if (((& (send gEgo:onControl()) $0002) or (& (send gEgo:onControl()) $1000)) and (== local0 0))
            (send gEgo:setPri(13))
            (if (& (send gEgo:onControl(0)) $0008)
                (send gEgo:setScript(Tripped))
            )
        )(else
            (if (not & (send gEgo:onControl(1)) $0010)
                (send gEgo:setPri(-1))
                (if (== (send gEgo:script()) WalkPath)
                    (send gEgo:setScript(0))
                )
            )
        )
    )

)
(instance Watch of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send newAct:setCycle(End self))  )
            )
            (case 1
                (= seconds 5  )
            )
            (case 2
                ((send newAct:setCel(0)) = seconds 10 = state -1 )
            )
        )
    )

)
(instance sparkle of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (
                (switch (Random(1 4))
                    (case 1
                        ((send newProp:setCycle(End self))  )
                    )
                    (case 2
                        ((send newProp_2:setCycle(End self))  )
                    )
                    (case 3
                        ((send newProp_3:setCycle(End self))  )
                    )
                    (case 4
                        ((send newProp_4:setCycle(End self)) )
                    )
                )
  )
            )
            (case 1
                ((send newProp:stopUpd()) (send newProp_2:stopUpd()) (send newProp_3:stopUpd()) (send newProp_4:stopUpd()) = state -1 (self:cue()) )
            )
        )
    )

)
