(version 2)
(include "sci.sh")
(exports
    0 leviCode
    1 sLevitate
)
(use "Main")
(use "n026")
(use "PolyPath")
(use "Cycle")
(use "User")
(use "View")
(use "Obj")
(script 31)


(local
    gOwnerX
    gOwnerY
    theTheGOwnerX =     100
    local3
    local4[4] = (135 225 45 315 )
    local8[8] = (0 1 0 2 0 1 2 3 )
    local16
    gOwnerLoop
    local18
    theGLastTicks
    newProp
    local21
    local22[10]

)
(instance public leviCode of Code
    (properties)

    (method (init theGOwnerX)
        proc0_2()
        (send gOwner:setMotion(0))
        (if (paramTotal)
            = gOwnerX theGOwnerX[0]
            = gOwnerY theGOwnerX[1]
        )(else
            = gOwnerX (send gOwner:x)
            = gOwnerY (send gOwner:y)
            (sLevitate:start(2))
        )
        (if (> paramTotal 2)
            = theTheGOwnerX theGOwnerX[2]
        )
        (if (> paramTotal 3)
            = local3 proc999_2(theGOwnerX[3] 3)
        )
        (send (ScriptID(gClientModNum)):setScript(sLevitate))
    )

)
(instance public sLevitate of Script
    (properties)

    (method (doit param1)
        (var temp0)
        (super:doit(rest param1))
        (if (< state 9)
            (if (>= state 3)
                (if ((send gOwner:mover))
                    (if (== state 5)
                        = local21 0
                    )(else
                        = local21 (+ (- gOwnerY (send ((send gOwner:mover)):y)) (send gOwner:z))
                    )
                    (send gOwner:
                        y(gOwnerY)
                        x(gOwnerX)
                        setMotion(0)
                    )
                )(else
                    (if (< (send gOwner:z) theTheGOwnerX)
                        (if (< local21 (send gOwner:z))
                            (send gOwner:z((- (send gOwner:z) 1)))
                        )(else
                            (if (> local21 (send gOwner:z))
                                (send gOwner:z((+ (send gOwner:z) 1)))
                            )
                        )
                    )(else
                        (if (< local21 theTheGOwnerX)
                            (send gOwner:z((- (send gOwner:z) 1)))
                        )
                    )
                )
            )
            (if (IsObject(newProp))
                (send newProp:z((send gOwner:z)))
            )
            (if (== state 4)
                (if (not 
                (if ((> (send gOwner:view) 17) and (< (send gOwner:view) 21))
                )
 and (> Abs((- gLastTicks theGLastTicks)) 50))
                    = theGLastTicks gLastTicks
                    (if (not (send gOwner:useMana(1)))
                        (self:cue())
                    )
                )
                (if (<= (send gOwner:z) 0)
                    = state 7
                    (send gOwner:z(0))
                    (self:cue())
                )
            )
            (if (<= (send gOwner:z) 0)
                (if (== state 5)
                    (self:cue())
                )
                (send gOwner:z(0))
            )
        )
    )


    (method (dispose)
        = global67 1
        (send gOwner:z(0))
        = local16 0
        (super:dispose())
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                proc0_2()
                (if ((> (send gOwner:view) 17) and (< (send gOwner:view) 21))
                    (if (< (send gOwner:view) 21)
                        = local16 1
                    )
                )
                (send gOwner:setMotion(PolyPath gOwnerX gOwnerY self))
            )
            (case 1
                (if (local16)
                    (send ((send gOwner:looper)):dispose())
                    (send gOwner:looper(0))
                    proc0_12(gOwner + (send gOwner:x) 5 + (send gOwner:y) 5 self)
                )(else
                    (if (local3)
                        (send gOwner:setHeading(local4[local3] self))
                    )(else
                        (self:cue())
                    )
                )
            )
            (case 2
                = global67 0
                = gOwnerLoop (send gOwner:loop)
                (if (local16)
                    (send gOwner:
                        view(19)
                        setLoop(5)
                        setCel(0)
                        setCycle(CT 4 1 self)
                        xStep(0)
                        setPri((send gOwner:priority))
                    )
                )(else
                    (send gOwner:
                        view(17)
                        setLoop(
                            (if (local3)
                            )(else
                                local8[(send gOwner:loop)]
                            )
)
                        setCel(0)
                        setCycle(End self)
                        xStep(0)
                        setPri((send gOwner:priority))
                    )
                )
                (send gLongSong2:
                    number(281)
                    setLoop(1)
                    play()
                )
            )
            (case 3
                (if (local16)
                    (send gOwner:
                        loop(6)
                        setCel(0)
                        setMotion(MoveTo (send gOwner:x) - (send gOwner:y) 10)
                    )
                )(else
                    (send gOwner:
                        setCel(255)
                        setMotion(MoveTo (send gOwner:x) - (send gOwner:y) 10)
                    )
                )
                = newProp (Prop:new())
                (send newProp:
                    view(17)
                    loop(4)
                    x((send gOwner:x))
                    y(+ (send gOwner:y) 1)
                    setCycle(Fwd)
                    setScale()
                    scaleX((send gOwner:scaleX))
                    scaleY((send gOwner:scaleY))
                    priority((send gOwner:priority))
                    signal(16400)
                    init()
                )
                = cycles 15
            )
            (case 4
                (User:
                    canControl(1)
                    canInput(1)
                )
                (send gMainIconBar:
                    enable(1)
                    advanceCurIcon()
                )
            )
            (case 5
                proc0_2()
                = local16 0
                (send newProp:dispose())
                = newProp 0
                (send gQg3Messager:say(1 6 1 1 0 31))
                = register (send gOwner:z)
                (send gOwner:
                    view(6)
                    setLoop(
                        (if (Random(0 1))
                            0
                        )(else
                            4
                        )
)
                    cel(0)
                    setCycle(CT 2 1)
                    setMotion(MoveTo (send gOwner:x) + gOwnerY 10)
                )
            )
            (case 6
                ShakeScreen(2)
                (send gOwner:setCycle(End self))
                (send gLongSong2:
                    number(901)
                    play()
                )
            )
            (case 7
                (if ((send gOwner:takeDamage((/ register 5))))
                    (send gOwner:
                        loop(+ (send gOwner:loop) 2)
                        cel(0)
                        setCycle(End self)
                    )
                )(else
                    proc26_0(2 31)
                )
            )
            (case 8
                (if (IsObject(newProp))
                    (send newProp:dispose())
                    = newProp 0
                    (if (local16)
                        (send gOwner:
                            loop(5)
                            cel(4)
                            setCycle(Beg self)
                        )
                    )(else
                        (send gOwner:setCycle(Beg self))
                    )
                )(else
                    (send gOwner:normalize(gOwnerLoop))
                    proc0_3()
                    (self:dispose())
                )
            )
            (case 9
                (if (local16)
                    (send gOwner:
                        view(20)
                        loop(2)
                        cel(4)
                    )
                )(else
                    (send gOwner:normalize(gOwnerLoop))
                )
                proc0_3()
                (self:dispose())
            )
        )
    )

)
