(version 2)
(include "sci.sh")
(exports
    0 rm853
    1 mageEndScript
    2 deMageBattle
    3 deWizRecoils
)
(use "Main")
(use "n026")
(use "OccasionalCycle")
(use "Scaler")
(use "Sound")
(use "Jump")
(use "Cycle")
(use "Game")
(use "View")
(use "Obj")
(script 853)


(local
    local0

)
(instance public rm853 of Rm
    (properties
        modNum 850
        noun 18
        picture 850
    )

    (method (init)
        (super:init())
        (self:setRegions(850))
        (if (== gGClientModNum 550)
            = local0 1
            proc0_4(124)
            (self:setScript(fromFracas))
        )(else
            (send (ScriptID(850 6)):
                init()
                stopUpd()
            )
            (self:setScript(mageEndScript))
        )
        (if (not == global155 0)
            (send gGame:save(1))
        )
    )


    (method (doVerb theVerb)
        (if ((not (== (mageEndScript:state) 3) and (== (send (ScriptID(850 2)):view) 861)) and (== (send (ScriptID(850 2)):loop) 0))
            (send (ScriptID(850 2)):
                loop(1)
                cel(0)
                setCycle(End)
            )
        )
        (switch (theVerb)
            (case 85
                (if (== (deMageBattle:state) 11)
                    proc26_0(18 850 857 End)
                )
                (if (== local0 1)
                    (send gQg3Messager:say(2 6 65 0 0 850))
                )(else
                    (if ((not (== local0 1) and not (== (self:script) egoSummon)) and not (== (self:script) deMageBattle))
                        = local0 1
                        (send (ScriptID(850 8)):dispose())
                        proc0_4(82)
                        (self:setScript(deMageBattle))
                    )
                )
            )
            (case 81
                (if (== (deMageBattle:state) 11)
                    proc26_0(18 850 857 End)
                )
                (if ((send gOwner:script))
                    (send ((send gOwner:script)):setScript(ScriptID(850 12)))
                )(else
                    (send gOwner:setScript(ScriptID(850 12) 0 theVerb))
                )
            )
            (case 83
                (if (== (deMageBattle:state) 11)
                    proc26_0(18 850 857 End)
                )
                (if ((send gOwner:script))
                    (send ((send gOwner:script)):setScript(ScriptID(850 12)))
                )(else
                    (send gOwner:setScript(ScriptID(850 12) 0 theVerb))
                )
            )
            (case 88
                (if (== (deMageBattle:state) 11)
                    proc26_0(18 850 857 End)
                )
                (if ((send gOwner:script))
                    (send ((send gOwner:script)):setScript(ScriptID(850 12)))
                )(else
                    (send gOwner:setScript(ScriptID(850 12) 0 theVerb))
                )
            )
            (case 84
                (if (== (deMageBattle:script) egoTakesDamage)
                    (egoTakesDamage:dispose())
                    (deMageBattle:setScript(egoLevitates deMageBattle))
                )(else
                    (send gQg3Messager:say(2 6 64 0 0 850))
                )
            )
            (case 87
                (if (== (deMageBattle:state) 11)
                    proc26_0(18 850 857 End)
                )
                (if (not == (egoSummon:state) -1)
                    (super:doVerb(theVerb))
                )
                (if (not proc0_6(97))
                    (mageEndScript:dispose())
                    (send (ScriptID(850 8)):dispose())
                    (deMageBattle:dispose())
                    (send global2:setScript(egoSummon))
                )
            )
            (case 80
                (if (== (deMageBattle:script) egoTakesDamage)
                    (sFx3:
                        number(942)
                        play()
                    )
                    (egoTakesDamage:dispose())
                    (deMageBattle:cue())
                )(else
                    (send gQg3Messager:say(2 6 66 0 0 850))
                )
            )
            (case 77
                (if (== (deMageBattle:state) 11)
                    proc26_0(18 850 857 End)
                )(else
                    (if (proc0_6(97))
                        (send global2:setScript(kablooie))
                    )(else
                        (if (== (deMageBattle:state) 17)
                            (deMageBattle:state(-1))
                            (send ((deMageBattle:client)):setScript(triggerGarg))
                        )(else
                            (send gQg3Messager:say(2 6 66 0 0 850))
                        )
                    )
                )
            )
            (case 76
                (if (== (deMageBattle:state) 11)
                    proc26_0(18 850 857 End)
                )(else
                    (send gQg3Messager:say(2 6 66 0 0 850))
                )
            )
            (case 78
                (if (== (deMageBattle:state) 11)
                    proc26_0(18 850 857 End)
                )(else
                    (send gQg3Messager:say(2 6 66 0 0 850))
                )
            )
            (case 86
                (if (== (deMageBattle:state) 11)
                    proc26_0(18 850 857 End)
                )(else
                    (send gQg3Messager:say(2 6 66 0 0 850))
                )
            )
            (case 75
                (send gQg3Messager:say(2 6 66 0 0 850))
            )
            (default 
                (super:doVerb(theVerb))
            )
        )
    )

)
(instance triggerGarg of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send gOwner:
                    view(15)
                    cel(0)
                    setCycle(End self)
                )
                (send gLongSong2:
                    setLoop(1)
                    number(900)
                    play()
                )
            )
            (case 1
                (send gOwner:setCycle(Beg self))
            )
            (case 2
                (send gOwner:normalize())
                (send client:setScript(fromFracas))
            )
        )
    )

)
(instance public deWizRecoils of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (send (ScriptID(850 2)):
                    view(866)
                    loop(0)
                    cel(0)
                    setCycle(End self)
                )
            )
            (case 1
                (send (ScriptID(850 2)):setCycle(Beg self))
            )
            (case 2
                (send (ScriptID(850 2)):view(863))
                (send gQg3Messager:say(3 6 46 0 self 850))
            )
            (case 3
                (if (== (egoSummon:state) 4)
                    (egoSummon:seconds(1))
                )
                (self:dispose())
            )
        )
    )

)
(instance kablooie of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                proc0_5(97)
                (send gOwner:
                    view(15)
                    cel(0)
                    setCycle(End self)
                )
                (send gLongSong2:
                    number(944)
                    setLoop(1)
                    play()
                )
            )
            (case 1
                (send gOwner:setCycle(Beg self))
            )
            (case 2
                (send gOwner:normalize())
                (send (ScriptID(850 2)):
                    loop(2)
                    cel(0)
                    setCycle(End)
                )
                (stick:setMotion(MoveTo 183 68))
                = seconds 3
            )
            (case 3
                (stick:dispose())
                (send (ScriptID(850 17)):
                    number(930)
                    play()
                )
                (kaBoom:
                    init()
                    setPri(14)
                    setCycle(CT 5 1 self)
                )
            )
            (case 4
                (send (ScriptID(850 2)):dispose())
                (kaBoom:setCycle(End self))
            )
            (case 5
                (kaBoom:
                    setLoop(1)
                    x(193)
                    y(77)
                    setScale(Scaler 22 150 96 34)
                    cycleSpeed(10)
                    setCycle(Fwd)
                    setMotion(JumpTo 67 174 self)
                )
            )
            (case 6
                (send (ScriptID(850 17)):
                    number(403)
                    play()
                )
                (kaBoom:setMotion(JumpTo 44 178 self))
            )
            (case 7
                (send (ScriptID(850 17)):
                    number(403)
                    play()
                )
                (kaBoom:setCycle(0))
                = seconds 3
            )
            (case 8
                (send gOwner:setMotion(MoveTo 22 176 self))
            )
            (case 9
                (send gOwner:
                    setLoop(0)
                    setCycle(CT 3 1 self)
                )
            )
            (case 10
                (send (ScriptID(850 17)):
                    number(920)
                    play()
                )
                (kaBoom:setMotion(JumpTo 144 189 self))
            )
            (case 11
                (send gOwner:
                    solvePuzzle(340 10)
                    normalize()
                )
                (kaBoom:dispose())
                proc0_3()
                (send (ScriptID(32 0)):start(0))
                (self:setScript(portalTimer))
            )
        )
    )

)
(instance portalTimer of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (switch (global209)
                    (case 1
                        = seconds 180
                    )
                    (case 2
                        = seconds 30
                    )
                    (case 3
                        = seconds 15
                    )
                )
            )
            (case 1
                (switch (global209)
                    (case 1
                        = seconds 180
                    )
                    (case 2
                        = seconds 30
                    )
                    (case 3
                        = seconds 20
                    )
                )
            )
            (case 2
                proc0_2()
                (send (ScriptID(850 6)):init())
                DrawPic(850 dpCLOSEREOPEN_HCENTER)
                proc26_0(2 850 857 End)
            )
        )
    )

)
(instance egoSummon of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_4(124)
                (if ((send gGQg3KDHandler:contains(ScriptID(850 6))))
                    (self:setScript(deMasterBails self))
                )(else
                    (self:cue())
                )
            )
            (case 1
                proc0_2()
                (send gOwner:
                    view(20)
                    loop(4)
                    cel(0)
                    setCycle(End self)
                )
                (send (ScriptID(850 17)):
                    number(900)
                    play()
                )
            )
            (case 2
                (send gOwner:
                    setLoop(6)
                    cel(0)
                    setCycle(End self)
                )
            )
            (case 3
                (send gQg3Messager:say(3 6 23 0 self 850))
            )
            (case 4
                (send gMainIconBar:enable(6 2 3 8))
                (send gMainIconBar:curIcon((send gMainIconBar:at(2))))
                (send gGame:setCursor(941))
                (send gUser:canInput(1))
                proc0_4(15)
                (send (ScriptID(32 0)):start(1))
                = seconds 10
            )
            (case 5
                proc0_4(97)
                proc0_2()
                (send (ScriptID(850 2)):
                    view(864)
                    loop(0)
                    cel(0)
                    setCycle(CT 4 1 self)
                )
            )
            (case 6
                (send (ScriptID(850 17)):
                    number(12)
                    play()
                )
                (send (ScriptID(850 9)):
                    view(21)
                    setLoop(7)
                    x(167)
                    y(81)
                    init()
                    setCycle(Fwd)
                    setMotion(JumpTo 23 143 self)
                )
            )
            (case 7
                (send gOwner:
                    view(20)
                    loop(6)
                    cel(0)
                    setCycle(CT 2 1)
                )
                (send (ScriptID(850 9)):setMotion(MoveTo 17 128))
                = seconds 4
            )
            (case 8
                (send gOwner:
                    setLoop(4)
                    cel(255)
                    setCycle(Beg)
                )
                (stick:
                    init()
                    setLoop(1)
                    setMotion(JumpTo 183 63)
                )
                (send (ScriptID(850 9)):setMotion(JumpTo 169 81 self))
            )
            (case 9
                (send gOwner:normalize())
                (send (ScriptID(850 9)):dispose())
                (send (ScriptID(850 2)):setCycle(End self))
            )
            (case 10
                (send (ScriptID(850 2)):
                    loop(1)
                    cel(0)
                    setCycle(End self)
                )
            )
            (case 11
                (send gQg3Messager:say(3 6 24 0 self 850))
            )
            (case 12
                (send gOwner:drop(44))
                (send gUser:canInput(1))
                (send gMainIconBar:enable(3 2 8 6))
                (send gMainIconBar:curIcon((send gMainIconBar:at(2))))
                (send gGame:setCursor(941))
                = seconds 5
            )
            (case 13
                (send gQg3Messager:say(3 6 25 0 self 850))
            )
            (case 14
                = seconds 5
            )
            (case 15
                (send gQg3Messager:say(3 6 14 0 self 850))
            )
            (case 16
                (stick:dispose())
                (send (ScriptID(850 2)):
                    view(861)
                    loop(1)
                    cel(5)
                    cycleSpeed(10)
                    setCycle(Beg self)
                )
            )
            (case 17
                (send (ScriptID(850 2)):
                    loop(2)
                    setCycle(OccasionalCycle self 1 10 30)
                )
                = seconds 5
            )
            (case 18
                (send (ScriptID(850 2)):setCycle(0))
                (send (ScriptID(850 6)):init())
                DrawPic(850 dpCLOSEREOPEN_HCENTER)
                = seconds 2
            )
            (case 19
                proc26_0(2 850 857 End)
            )
        )
    )

)
(instance egoLevitates of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (send gOwner:
                    view(17)
                    setLoop(0)
                    cel(0)
                    setCycle(End self)
                )
            )
            (case 1
                (send (ScriptID(850 17)):
                    number(281)
                    play()
                )
                (send gOwner:
                    setCel(255)
                    setScale()
                    setMotion(MoveTo (send gOwner:x) - (send gOwner:y) 50 self)
                )
            )
            (case 2
                = seconds 2
            )
            (case 3
                (floorFire:dispose())
                (send gOwner:setMotion(MoveTo (send gOwner:x) (+ (send gOwner:y) 50) self))
            )
            (case 4
                (send gOwner:
                    setScale(Scaler 92 63 189 130)
                    setCycle(Beg self)
                )
            )
            (case 5
                (send gOwner:normalize())
                (send gUser:canInput(1))
                (send gMainIconBar:enable(2 4 6 3 8))
                = state -1
                (self:dispose())
            )
        )
    )

)
(instance public mageEndScript of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                = seconds 1
            )
            (case 1
                (send gQg3Messager:say(1 6 4 0 self 850))
            )
            (case 2
                (send gOwner:setMotion(MoveTo 20 183 self))
            )
            (case 3
                proc0_3()
                (send gMainIconBar:disable(1 5))
                (switch (global209)
                    (case 1
                        = seconds 60
                    )
                    (case 2
                        = seconds 30
                    )
                    (case 3
                        = seconds 20
                    )
                )
            )
            (case 4
                (if ((send gGQg3KDHandler:contains(ScriptID(850 6))))
                    (self:setScript(deMasterBails self))
                )(else
                    (self:cue())
                )
            )
            (case 5
                (send gUser:canInput(1))
                (send (ScriptID(850 2)):setCycle(End self))
            )
            (case 6
                (send (ScriptID(850 2)):
                    loop(1)
                    setCycle(End self)
                )
            )
            (case 7
                (send gQg3Messager:say(3 6 6 0 self 850))
            )
            (case 8
                (send gMainIconBar:enable(3 6 8))
                (send gGame:setCursor(941))
                (send (ScriptID(850 2)):setScript(ScriptID(850 8)))
                (self:dispose())
            )
        )
    )

)
(instance public deMageBattle of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (if ((send gGQg3KDHandler:contains(ScriptID(850 6))))
                    (self:setScript(deMasterBails self))
                )(else
                    (self:cue())
                )
            )
            (case 1
                proc0_2()
                (send (ScriptID(850 2)):
                    view(863)
                    loop(0)
                    setCycle(CT 6 1 self)
                )
            )
            (case 2
                (send gOwner:
                    view(15)
                    loop(2)
                    cel(0)
                    setCycle(End)
                )
                (send (ScriptID(850 17)):
                    number(943)
                    play()
                )
                (send (ScriptID(850 9)):
                    setLoop(Random(0 4))
                    x(186)
                    y(60)
                    setStep(8 7)
                    cycleSpeed(0)
                    moveSpeed(0)
                    setScale()
                    init()
                    setMotion(MoveTo (send gOwner:x) - (send gOwner:y) 35 self)
                )
                (send (ScriptID(850 2)):setCycle(End))
                (send (ScriptID(850 17)):
                    number(13)
                    play()
                )
            )
            (case 3
                (send gOwner:normalize(6))
                (send (ScriptID(850 17)):
                    number(10)
                    play()
                )
                (send (ScriptID(850 9)):setMotion(MoveTo (send (ScriptID(850 2)):x) (- (send (ScriptID(850 2)):y) 35) self))
            )
            (case 4
                (send (ScriptID(850 9)):
                    loop(10)
                    setCycle(End self)
                )
                (send (ScriptID(850 17)):
                    number(930)
                    play()
                )
            )
            (case 5
                (send (ScriptID(850 9)):dispose())
                (send (ScriptID(850 2)):
                    view(868)
                    loop(0)
                    cel(0)
                    setCycle(End self)
                )
            )
            (case 6
                (send (ScriptID(850 2)):setCycle(Beg self))
            )
            (case 7
                (send (ScriptID(850 2)):
                    view(863)
                    loop(0)
                    cel(0)
                )
                (send gQg3Messager:say(3 6 16 0 self 850))
            )
            (case 8
                (send (ScriptID(850 2)):setCycle(End self))
            )
            (case 9
                (send (ScriptID(850 2)):setCycle(Beg self))
            )
            (case 10
                (send gQg3Messager:say(3 6 17 0 self 850))
            )
            (case 11
                (send (ScriptID(850 17)):
                    number(101)
                    play()
                )
                (floorFire:
                    x((send gOwner:x))
                    y((send gOwner:y))
                    init()
                    setCycle(Fwd)
                )
                (send gMainIconBar:enable(8 2 6))
                (send gGame:setCursor(941))
                (send gUser:canInput(1))
                (self:setScript(egoTakesDamage self))
            )
            (case 12
                (if (not == (egoLevitates:state) -1)
                    (self:cue())
                )
            )
            (case 13
                (send gOwner:normalize())
                (floorFire:dispose())
                (send gQg3Messager:say(3 6 56 0 self 850))
            )
            (case 14
                (send (ScriptID(850 2)):setCycle(End self))
            )
            (case 15
                proc0_2()
                (send (ScriptID(850 3)):
                    view(852)
                    loop(0)
                    cel(0)
                    noun(4)
                    setCycle(End self)
                )
            )
            (case 16
                (sFx3:
                    number(900)
                    play()
                )
                (send (ScriptID(850 3)):
                    loop(1)
                    setCycle(CT 3 1 self)
                )
            )
            (case 17
                proc0_3()
                (send gMainIconBar:disable(5))
                = seconds 5
            )
            (case 18
                (send gQg3Messager:say(3 6 33 0 self 850))
            )
            (case 19
                = global365 855
                (send global2:newRoom(550))
            )
        )
    )

)
(instance fromFracas of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                proc0_4(124)
                (send gOwner:
                    x(20)
                    y(183)
                )
                (send (ScriptID(850 3)):
                    view(852)
                    loop(2)
                    cel(0)
                )
                (send (ScriptID(850 2)):
                    view(863)
                    loop(Random(0 6))
                    cel(0)
                )
                = seconds 2
            )
            (case 1
                (if ((== gGClientModNum 550) and (== global155 0))
                    proc26_0(60 850)
                )(else
                    (self:cue())
                )
            )
            (case 2
                (send (ScriptID(850 3)):
                    cycleSpeed(3)
                    setCycle(End self)
                )
            )
            (case 3
                (send (ScriptID(850 3)):
                    view(854)
                    setLoop(1)
                )
                (send gQg3Messager:say(3 6 21 0 self 850))
            )
            (case 4
                (send gQg3Messager:say(3 6 22 0 self 850))
            )
            (case 5
                proc0_3()
                (send gMainIconBar:disable(1 5))
                (send (ScriptID(850 2)):
                    view(861)
                    loop(1)
                    cel(255)
                    setCycle(Beg self)
                )
            )
            (case 6
                (send (ScriptID(850 2)):
                    loop(0)
                    cel(255)
                    setCycle(End self)
                )
            )
            (case 7
                (send (ScriptID(850 2)):setCycle(OccasionalCycle self 1 10 25))
                (switch (global209)
                    (case 1
                        = seconds 60
                    )
                    (case 2
                        = seconds 40
                    )
                    (case 3
                        = seconds 20
                    )
                )
            )
            (case 8
                (send (ScriptID(850 2)):setCycle(0))
                (send (ScriptID(850 6)):init())
                DrawPic(850 dpCLOSEREOPEN_HCENTER)
                = seconds 1
            )
            (case 9
                proc26_0(2 850)
                (self:dispose())
            )
        )
    )

)
(instance egoTakesDamage of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                (send gOwner:
                    view(29)
                    setCycle(Fwd)
                )
                (if ((send gOwner:takeDamage(10)))
                    (switch (global209)
                        (case 1
                            = seconds 6
                        )
                        (case 2
                            = seconds 4
                        )
                        (case 3
                            = seconds 2
                        )
                    )
                )(else
                    proc26_0(18 850 857 End)
                )
            )
            (case 1
                (self:init())
            )
        )
    )

)
(instance deMasterBails of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                = seconds 3
            )
            (case 1
                (send (ScriptID(850 6)):dispose())
                DrawPic(850 dpCLOSEREOPEN_HCENTER)
                = seconds 2
            )
            (case 2
                (self:dispose())
            )
        )
    )

)
(instance floorFire of Prop
    (properties
        modNum 850
        view 872
        signal $4000
    )
)
(instance kaBoom of Actor
    (properties
        x 193
        y 97
        noun 5
        modNum 850
        view 867
        signal $4000
    )
)
(instance stick of Actor
    (properties
        x 20
        y 117
        view 790
        loop 1
    )
)
(instance sFx3 of Sound
    (properties)
)
