(version 2)
(include "sci.sh")
(exports
    0 rm820
    1 demonaTalker
)
(use "Main")
(use "TargFeature")
(use "n026")
(use "GloryTalker")
(use "PolyPath")
(use "Polygon")
(use "CueObj")
(use "n958")
(use "Cycle")
(use "Game")
(use "View")
(use "Obj")
(script 820)


(local
    local0 =     1
    local1 =     1
    local2
    local3
    local4

)
(instance public rm820 of Rm
    (properties
        noun 3
        picture 820
        vanishingY -20
    )

    (method (init)
        proc958_0(128 820 821 822)
        (send gOwner:
            x(122)
            y(41)
            setScale(150)
            normalize()
        )
        proc0_3()
        (super:init())
        (send gLongSong:
            number(820)
            setLoop(-1)
            play(127)
        )
        (send global2:addObstacle((send ((Polygon:new())):
                type(3)
                init(225 36 218 43 148 36 37 70 32 81 9 82 3 92 3 186 115 186 83 173 57 152 51 134 56 115 68 95 52 87 73 74 88 79 140 56 187 62 236 66 282 71 316 58 316 50 231 44 237 38)
                yourself()
            )
))
        (brazier:init())
        (brazier2:init())
        (brazier3:init())
        (brazier4:init())
        (doorWay:init())
        (stairs:init())
        (floor:init())
        (visage:init())
        (flame1:
            setCycle(Fwd)
            init()
        )
        (flame2:
            setPri(6)
            setCycle(Fwd)
            init()
        )
        (flame3:
            setPri(3)
            setCycle(Fwd)
            init()
        )
        (flame4:
            setPri(5)
            setCycle(Fwd)
            init()
        )
        (door:
            ignoreActors(0)
            init()
        )
        (if (not == gGClientModNum 550)
            (frac:
                init()
                stopUpd()
            )
            (fric:
                init()
                stopUpd()
            )
            (if (== global125 2)
                (send gOwner:code(thiefGaitChek))
            )(else
                (send gOwner:code(demonTurnChek))
            )
            (send global2:setScript(egoEnters))
        )(else
            (if ((== gGClientModNum 550) and (== global155 0))
                (fric:
                    init()
                    stopUpd()
                )
                (send global2:setScript(knockEmDead))
            )(else
                (if ((== gGClientModNum 550) and not (== global155 0))
                    (fric:
                        x(156)
                        y(67)
                        view(824)
                        signal(1)
                        init()
                    )
                    (send gOwner:
                        x(212)
                        y(61)
                        init()
                        solvePuzzle(335 7 9)
                    )
                    (send global2:setScript(afterFight))
                )(else
                    (send global2:setScript(egoEnters))
                )
            )
        )
        (if ((== global125 3) and (> (send gOwner:trySkill(4 100)) 0))
            (send gQg3Messager:say(1 6 1))
        )
    )


    (method (dispose param1)
        (send gOwner:code(0))
        (if (gNewList)
            (send gNewList:eachElementDo(111))
        )
        UnLoad(128 820)
        UnLoad(128 821)
        UnLoad(128 822)
        (super:dispose(rest param1))
    )


    (method (doVerb theVerb)
        (switch (theVerb)
            (case 65
                (send gQg3Messager:say(1 6 9))
            )
            (case 80
                (self:setScript(castCalm))
            )
            (default 
                (super:doVerb(theVerb))
            )
        )
    )

)
(instance closeCombat of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                = cycles 2
            )
            (case 1
                = gGMonsterMonHP 320
                = global365 845
                (send global2:newRoom(550))
            )
        )
    )

)
(instance lubeLock of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send gOwner:setMotion(PolyPath 230 40 self))
            )
            (case 1
                (send gOwner:solvePuzzle(332 5 4))
                (send gQg3Messager:say(4 35 0 0 self))
            )
            (case 2
                = local0 0
                proc0_3()
                (self:dispose())
            )
        )
    )

)
(instance afterFight of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                = seconds 2
            )
            (case 1
                (if (== global155 0)
                    proc26_0()
                )(else
                    (self:cue())
                )
            )
            (case 2
                (send gLongSong2:
                    number(931)
                    setLoop(1)
                    play(127)
                )
                = local1 0
                = local0 0
                = local3 1
            )
        )
    )

)
(instance demonsDissolve of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                = cycles 1
            )
            (case 1
                (fric:dispose())
                DrawPic((send global2:picture) dpCLOSEREOPEN_HCENTER)
                = cycles 4
            )
            (case 2
                = local1 0
                proc0_3()
                (self:dispose())
            )
        )
    )

)
(instance castCalm of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (self:setScript(ScriptID(12 0) self))
            )
            (case 1
                (send gQg3Messager:say(3 80 0 0 self))
            )
            (case 2
                = local1 0
                (send gOwner:
                    solvePuzzle(333 6 2)
                    code(0)
                )
                (self:dispose())
            )
        )
    )

)
(instance demonsTalk of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (fric:setCycle(End self))
            )
            (case 1
                (send gQg3Messager:say(2 6 3 0 self))
            )
            (case 2
                (fric:setCycle(Beg self))
            )
            (case 3
                (frac:setCycle(End self))
            )
            (case 4
                (frac:setCycle(Beg))
                (self:dispose())
            )
        )
    )

)
(instance demonsTurn of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send gQg3Messager:say(2 6 5 0 self))
            )
            (case 1
                (fric:
                    loop(2)
                    setCycle(End)
                )
                (frac:
                    loop(3)
                    setCycle(End self)
                )
            )
            (case 2
                (send gQg3Messager:say(2 6 6 0 self))
            )
            (case 3
                = global365 845
                (send global2:newRoom(550))
            )
        )
    )

)
(instance tryToPickLock of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send gOwner:setMotion(PolyPath 230 40 self))
            )
            (case 1
                (if (local3)
                    (send gQg3Messager:say(4 17 12 0 self))
                )(else
                    (send gOwner:useSkill(9 200))
                    = local3 1
                    (send gQg3Messager:say(4 17 11))
                    proc0_3()
                    (self:dispose())
                )
            )
            (case 2
                proc0_3()
                (self:dispose())
            )
        )
    )

)
(instance castOpenOnDoor of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                proc0_14(235 20)
                (self:setScript(ScriptID(13 0) self))
            )
            (case 1
                (send gOwner:solvePuzzle(334 4 2))
                (send gQg3Messager:say(4 75 0 0 self))
            )
            (case 2
                = local3 1
                = local0 0
                proc0_3()
                (send gOwner:normalize())
                (self:dispose())
            )
        )
    )

)
(instance hearNoise of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (if (local2)
                    (send gQg3Messager:say(2 6 8 0 self))
                )(else
                    (send gQg3Messager:say(2 6 7 0 self))
                )
            )
            (case 1
                (self:dispose())
            )
        )
    )

)
(instance messWithDoor of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send gOwner:setMotion(PolyPath 230 40 self))
            )
            (case 1
                (if (== local1 1)
                    (fric:setScript(demonsTurn))
                )(else
                    (if (== local3 0)
                        (send gQg3Messager:say(4 4 10))
                        proc0_3()
                        (self:dispose())
                    )(else
                        (if (== local0 1)
                            (fric:setScript(demonsTurn))
                        )(else
                            (if ((send gGQg3KDHandler:contains(frac)))
                                = local2 0
                                (self:setScript(hearNoise self))
                            )
                            = cycles 1
                        )
                    )
                )
            )
            (case 2
                (door:
                    setCycle(End self)
                    ignoreActors(1)
                )
                (send gLongSong2:
                    number(821)
                    setLoop(1)
                    play()
                )
            )
            (case 3
                (send gOwner:setMotion(MoveTo 230 30 self))
            )
            (case 4
                (if (not local4)
                    (send gOwner:solvePuzzle(331 5 4))
                )
                (send global2:newRoom(830))
                proc0_3()
                (self:dispose())
            )
        )
    )

)
(instance egoEnters of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (secretDoor:
                    init()
                    setCycle(End self)
                )
                (send gLongSong2:
                    number(8)
                    setLoop(1)
                    play(127)
                )
            )
            (case 1
                (send gOwner:
                    init()
                    setMotion(MoveTo 129 51 self)
                )
            )
            (case 2
                (fric:setScript(demonsTalk self))
            )
            (case 3
                (secretDoor:setCycle(Beg self))
            )
            (case 4
                (if (proc0_6(150))
                    (send gQg3Messager:say(1 6 2 0 self))
                )(else
                    (self:cue())
                )
            )
            (case 5
                (secretDoor:dispose())
                proc0_3()
                (self:dispose())
            )
        )
    )

)
(instance theyAttack of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send gQg3Messager:say(2 6 4 0 self))
            )
            (case 1
                = global365 845
                (send global2:newRoom(550))
            )
        )
    )

)
(instance knockEmDead of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                = seconds 1
            )
            (case 1
                proc26_0()
            )
        )
    )

)
(instance flame1 of Prop
    (properties
        x 20
        y 43
        view 820
        loop 2
        signal $4000
        detailLevel 3
    )
)
(instance flame2 of Prop
    (properties
        x 74
        y 53
        view 820
        loop 2
        cel 2
        signal $4000
        detailLevel 3
    )
)
(instance flame3 of Prop
    (properties
        x 157
        y 33
        view 820
        loop 2
        cel 1
        signal $4000
        detailLevel 3
    )
)
(instance flame4 of Prop
    (properties
        x 258
        y 44
        view 820
        loop 2
        cel 4
        signal $4000
        detailLevel 3
    )
)
(instance secretDoor of Prop
    (properties
        x 122
        y 42
        noun 12
        view 820
        signal $4000
    )
)
(instance door of Prop
    (properties
        x 222
        y 35
        noun 4
        view 820
        loop 1
    )

    (method (doVerb theVerb)
        (switch (theVerb)
            (case 4
                (send gOwner:setScript(messWithDoor))
            )
            (case 75
                (send gOwner:setScript(castOpenOnDoor))
            )
            (case 35
                (send gOwner:setScript(lubeLock))
            )
            (case 17
                (send gOwner:setScript(tryToPickLock))
            )
            (default 
                (super:doVerb(theVerb))
            )
        )
    )

)
(instance fric of TargProp
    (properties
        x 154
        y 103
        noun 2
        view 821
        signal $4000
    )

    (method (doVerb theVerb)
        (switch (theVerb)
            (case 4
                (if (not == gGClientModNum 550)
                    (send global2:setScript(theyAttack))
                )(else
                    (send gQg3Messager:say(1 6 13))
                )
            )
            (case 20
                (if (not (send global2:script))
                    (send global2:setScript(ScriptID(32 0) 0 theVerb))
                )
            )
            (case 81
                (if (not (send global2:script))
                    (send global2:setScript(ScriptID(32 0) 0 theVerb))
                )
            )
            (case 88
                (if (not (send global2:script))
                    (send global2:setScript(ScriptID(32 0) 0 theVerb))
                )
            )
            (case 83
                (if (not (send global2:script))
                    (send global2:setScript(ScriptID(32 0) 0 theVerb))
                )
            )
            (case 33
                (if (not (send global2:script))
                    (send global2:setScript(ScriptID(32 0) 0 theVerb))
                )
            )
            (default 
                (super:doVerb(theVerb))
            )
        )
    )


    (method (getHurt)
        (send global2:setScript(closeCombat))
    )

)
(instance frac of TargProp
    (properties
        x 193
        y 110
        noun 13
        view 821
        loop 1
        signal $4000
    )

    (method (doVerb theVerb)
        (switch (theVerb)
            (case 4
                (if (not == gGClientModNum 550)
                    (send global2:setScript(theyAttack))
                )(else
                    (send gQg3Messager:say(1 6 13))
                )
            )
            (case 20
                (if (not (send global2:script))
                    (send global2:setScript(ScriptID(32 0) 0 theVerb))
                )
            )
            (case 81
                (if (not (send global2:script))
                    (send global2:setScript(ScriptID(32 0) 0 theVerb))
                )
            )
            (case 88
                (if (not (send global2:script))
                    (send global2:setScript(ScriptID(32 0) 0 theVerb))
                )
            )
            (case 83
                (if (not (send global2:script))
                    (send global2:setScript(ScriptID(32 0) 0 theVerb))
                )
            )
            (case 33
                (if (not (send global2:script))
                    (send global2:setScript(ScriptID(32 0) 0 theVerb))
                )
            )
            (default 
                (super:doVerb(theVerb))
            )
        )
    )


    (method (getHurt)
        (send global2:setScript(closeCombat))
    )

)
(instance public demonaTalker of GloryTalker
    (properties
        x 10
        y 10
        view 822
        loop 1
        talkWidth 260
        back 57
        textX 15
        textY 100
        backColor 42
    )

    (method (init param1)
        (super:init(demonaBust demonaEyes demonaMouth rest param1))
    )

)
(instance demonaMouth of Prop
    (properties
        nsTop 31
        nsLeft 60
        view 822
    )
)
(instance demonaEyes of Prop
    (properties
        nsTop 24
        nsLeft 49
        view 822
        loop 2
    )
)
(instance demonaBust of View
    (properties
        nsTop 14
        nsLeft 53
        view 822
        loop 3
    )
)
(instance brazier of Feature
    (properties
        x 23
        y 58
        noun 5
        nsTop 45
        nsLeft 14
        nsBottom 71
        nsRight 33
        sightAngle 180
    )
)
(instance brazier2 of Feature
    (properties
        x 76
        y 64
        noun 6
        nsTop 48
        nsLeft 67
        nsBottom 81
        nsRight 86
        sightAngle 180
    )
)
(instance brazier3 of Feature
    (properties
        x 158
        y 42
        noun 7
        nsTop 34
        nsLeft 149
        nsBottom 51
        nsRight 168
        sightAngle 180
    )
)
(instance brazier4 of Feature
    (properties
        x 260
        y 56
        noun 8
        nsTop 47
        nsLeft 251
        nsBottom 66
        nsRight 269
        sightAngle 180
    )
)
(instance doorWay of Feature
    (properties
        x 229
        y 21
        noun 9
        nsTop 1
        nsLeft 205
        nsBottom 41
        nsRight 254
        sightAngle 180
    )
)
(instance floor of Feature
    (properties
        x 189
        y 155
        noun 10
        nsTop 134
        nsLeft 148
        nsBottom 177
        nsRight 230
        sightAngle 180
    )
)
(instance stairs of Feature
    (properties
        x 44
        y 136
        noun 11
        nsTop 84
        nsBottom 189
        nsRight 88
        sightAngle 180
    )
)
(instance visage of Feature
    (properties
        x 291
        y 145
        noun 14
        nsTop 114
        nsLeft 270
        nsBottom 177
        nsRight 313
        sightAngle 180
    )
)
(instance thiefGaitChek of Code
    (properties)

    (method (doit)
        (if (== global100 2)
            = local1 0
        )(else
            = local1 1
        )
        (if ((not (send global2:script) and (== local1 1)) and (send gOwner:inRect(180 20 200 80)))
            = local4 1
            (send global2:setScript(demonsTurn))
        )
    )

)
(instance demonTurnChek of Code
    (properties)

    (method (doit)
        (if ((not (send global2:script) and (== local1 1)) and ((send gOwner:inRect(180 20 200 80)) or (send gOwner:inRect(0 80 135 189))))
            (send global2:setScript(demonsTurn))
        )
    )

)
