(include "sci.sh")
(use "Main")
(use "Class_255_0")
(use "Sound")
(use "Cycle")
(use "Game")
(use "InvI")
(use "User")
(use "PV")
(use "Obj")
(script 82)


(local
    newAct
    newView
    newProp_3
    newProp_4
    local4
    newAct_2
    local6
    newProp
    newProp_2

)
(procedure (localproc_0038)
    = global220 1
    Print(82 0)
    (send gGame:changeScore(2))
)


(instance theMusic of Sound
    (properties
        number 45
    )
)
(instance public Room82 of Rm
    (properties
        picture 82
        style 16
    )

    (method (init)
        Load(rsVIEW 605)
        Load(rsVIEW 122)
        Load(rsVIEW 123)
        Load(rsVIEW 85)
        Load(rsVIEW 68)
        Load(rsVIEW 633)
        Load(rsVIEW 646)
        Load(rsSOUND 46)
        Load(rsSOUND 45)
        (self:setRegions(604))
        (super:init())
        proc0_12(604 0)
        (send ((View:new())):
            view(633)
            loop(4)
            cel(0)
            posn(61 84)
            setPri(4)
            addToPic()
        )
        (send ((View:new())):
            view(633)
            loop(4)
            cel(0)
            posn(38 88)
            setPri(5)
            addToPic()
        )
        (if (global100)
            (send ((Prop:new())):
                view(633)
                loop(0)
                posn(62 70)
                setPri(3)
                init()
                setCycle(Fwd)
            )
            (send ((Prop:new())):
                view(633)
                loop(1)
                posn(39 74)
                setPri(4)
                init()
                setCycle(Fwd)
            )
            (send (= newProp (Prop:new())):
                view(646)
                loop(0)
                cel(0)
                posn(92 93)
                cycleSpeed(5)
                init()
                stopUpd()
            )
            (send (= newProp_2 (Prop:new())):
                view(646)
                loop(1)
                cel(0)
                posn(225 94)
                cycleSpeed(5)
                init()
                stopUpd()
            )
        )
        (send gEgo:
            posn(233 166)
            view(4)
            setStep(4 1)
            baseSetter(0)
            ignoreActors(0)
            illegalBits(49152)
            setPri(-1)
            init()
        )
        (if (global169)
            (send (= newAct (Act:new())):
                view(122)
                illegalBits(0)
                posn(162 94)
                init()
                stopUpd()
            )
            (send (= newProp_3 (Prop:new())):
                view(123)
                posn((send newAct:x()) - (send newAct:y()) 20)
                init()
                hide()
            )
            (send (= newProp_4 (Prop:new())):
                view(605)
                cel(0)
                posn(234 155)
                init()
                stopUpd()
                ignoreActors(0)
            )
        )(else
            (send (= newProp_4 (Prop:new())):
                view(605)
                posn(234 153)
                init()
                stopUpd()
                ignoreActors(1)
            )
            (send (= newAct (Act:new())):
                view(123)
                illegalBits(0)
                posn(162 94)
                setLoop(1)
                setCel(255)
                init()
                stopUpd()
            )
            (if (== (send ((send gInv:at(2))):owner()) 82)
                (send (= newView (View:new())):
                    view(123)
                    loop(3)
                    posn(172 95)
                    setPri(6)
                    init()
                )
            )
            (send gEgo:illegalBits(32768))
            (send newProp_4:setCel(255))
        )
    )


    (method (doit)
        (super:doit())
        (if (& (send gEgo:onControl(0)) $0040)
            (send global2:newRoom(88))
        )
    )


    (method (dispose)
        (send gSounds:eachElementDo(172))
        (super:dispose())
    )


    (method (handleEvent pEvent)
        return 
            (if ((send pEvent:claimed()))
                return 1
            )(else
                (if (== (send pEvent:type()) 128)
                    (if (not & (send gEgo:onControl(0)) $0800)
                        (if ((Said('look[<around][/!*]') or Said('look[<around]/room')) or Said('look/castle,tower,bedroom'))
                            Print(Format(@global300 82 1 
                                    (if (== (send newAct:view()) 122)
                                        "And speaking of Lolotte...the old bat is sound asleep on her massive bed."
                                    )(else
                                        "However, since Lolotte is now dead, it doesn't really matter anymore."
                                    )
))
                        )(else
                            (if (Said('look>'))
                                (if (Said('<under/bed'))
                                    Print(82 2)
                                )(else
                                    (if (Said('/bed'))
                                        Print(82 3)
                                    )(else
                                        (if (Said('/window'))
                                            (if ((send gEgo:inRect(66 118 131 131)) or (send gEgo:inRect(196 118 240 135)))
                                                Print(82 4)
                                            )(else
                                                proc0_15()
                                            )
                                        )(else
                                            (if (Said('/wall'))
                                                Print(82 5)
                                            )(else
                                                (if (Said('/dirt'))
                                                    Print(82 6)
                                                )(else
                                                    (if (Said('/carpet'))
                                                        Print(82 7)
                                                    )(else
                                                        (if (Said('/mirror'))
                                                            (if ((send gEgo:inRect(42 123 108 144)))
                                                                Print(82 8)
                                                            )(else
                                                                proc0_15()
                                                            )
                                                        )(else
                                                            (if (Said('/stair'))
                                                                Print(82 9)
                                                            )(else
                                                                (if (Said('/door'))
                                                                    Print(82 10)
                                                                )(else
                                                                    (if (Said('/lolotte,fairies'))
                                                                        (if (global169)
                                                                            Print(82 11)
                                                                        )(else
                                                                            Print(Format(@global300 82 12 
                                                                                    (if (== (send ((send gInv:at(2))):owner()) 82)
                                                                                        "\nGenesta's magic talisman hangs from around her neck."
                                                                                    )(else
                                                                                        " "
                                                                                    )
))
                                                                        )
                                                                    )(else
                                                                        (send pEvent:claimed(0))
                                                                    )
                                                                )
                                                            )
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )(else
                                (if (Said('help,,/lolotte,fairies'))
                                    Print(82 13)
                                )(else
                                    (if (Said('kiss[/lolotte,fairies]'))
                                        (if (global169)
                                            Print(82 14)
                                        )(else
                                            Print(82 15)
                                        )
                                    )(else
                                        (if (Said('deliver>'))
                                            Print(82 16)
                                            (send pEvent:claimed(1))
                                        )(else
                                            (if (Said('awaken/lolotte,fairies'))
                                                (if (global169)
                                                    (send global2:setScript(egoZapped))
                                                )(else
                                                    Print(82 17 66 global23 134 15 20 50 4)
                                                )
                                            )(else
                                                (if (Said('get,capture/lolotte,fairies'))
                                                    (if (global169)
                                                        Print(82 18)
                                                    )(else
                                                        Print(82 15)
                                                    )
                                                )(else
                                                    (if (Said('converse[<lolotte,fairies]'))
                                                        (if (global169)
                                                            (send global2:setScript(egoZapped))
                                                        )(else
                                                            Print(82 19 50 5)
                                                        )
                                                    )(else
                                                        (if (Said('blow/whistle'))
                                                            (if (global169)
                                                                (send global2:setScript(egoZapped))
                                                            )(else
                                                                (send pEvent:claimed(0))
                                                            )
                                                        )(else
                                                            (if (Said('get/amulet'))
                                                                (if ((send gEgo:has(2)))
                                                                    Print(82 20 50 3)
                                                                )(else
                                                                    (if (<> (send ((send gInv:at(2))):owner()) 82)
                                                                        Print(82 21 50 5)
                                                                    )(else
                                                                        (if (not (send gEgo:inRect(120 120 215 135)))
                                                                            Print(82 22 50 3)
                                                                        )(else
                                                                            (if (global169)
                                                                                (send global2:setScript(egoZapped))
                                                                            )(else
                                                                                Print(82 23 50 2)
                                                                                (send gEgo:get(2))
                                                                                (send newView:dispose())
                                                                                = global182 1
                                                                                (send gGame:changeScore(5))
                                                                            )
                                                                        )
                                                                    )
                                                                )
                                                            )(else
                                                                (if (Said('close/door'))
                                                                    (if (== (send newProp_4:cel()) 0)
                                                                        Print(82 24)
                                                                    )(else
                                                                        Print(82 25)
                                                                    )
                                                                )(else
                                                                    (if (Said('lay<down,sleep') or Said('(sleep<in,on),(lay<down,in,on),(get<in,on)/bed'))
                                                                        Print(82 26)
                                                                    )(else
                                                                        (if (Said('kill/lolotte,fairies'))
                                                                            (if (== global169 0)
                                                                                Print(82 27)
                                                                            )(else
                                                                                (if ((send gEgo:has(14)))
                                                                                    Print(82 28)
                                                                                )(else
                                                                                    Print(82 29)
                                                                                )
                                                                            )
                                                                        )(else
                                                                            (if (Said('launch[/!*]'))
                                                                                Print(82 30)
                                                                            )(else
                                                                                (if (Said('launch/lolotte,fairies,arrow,arrow'))
                                                                                    (if (>= (send ((send gInv:at(14))):loop()) 2)
                                                                                        Print(82 31)
                                                                                    )(else
                                                                                        (if (not global169)
                                                                                            Print(82 32)
                                                                                        )(else
                                                                                            (if (== (send global2:script()) lolotteDead)
                                                                                                Print(82 33)
                                                                                            )(else
                                                                                                (self:setScript(shootLolotte))
                                                                                            )
                                                                                        )
                                                                                    )
                                                                                )
                                                                            )
                                                                        )
                                                                    )
                                                                )
                                                            )
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )(else
                        (if (Said('look/stair'))
                            Print(82 34)
                        )(else
                            (if (Said('look/wall'))
                                Print(82 5)
                            )(else
                                (if (Said('look/door'))
                                    Print(82 35)
                                )(else
                                    (if (Said('open/window'))
                                        Print(82 36)
                                    )(else
                                        (if (Said('break/window'))
                                            Print(82 37)
                                        )(else
                                            (if (Said('look[<around][/room]'))
                                                Print(82 38)
                                            )(else
                                                (if (Said('unlatch/door>'))
                                                    (if (global220)
                                                        (send pEvent:claimed(1))
                                                        Print(82 24)
                                                    )(else
                                                        (if (> (send gEgo:distanceTo(newProp_4)) 15)
                                                            (send pEvent:claimed(1))
                                                            proc0_15()
                                                        )(else
                                                            (if (((send gEgo:has(32)) and not (send gEgo:has(20))) or (Said('*/*/(key<gold)') and (send gEgo:has(32))))
                                                                (send pEvent:claimed(1))
                                                                localproc_0038()
                                                            )(else
                                                                (if (Said('*/*/key<skeleton') and (send gEgo:has(20)))
                                                                    Print(82 39)
                                                                )(else
                                                                    (if ((send gEgo:has(20)) and (send gEgo:has(32)))
                                                                        (send pEvent:claimed(1))
                                                                        Print(82 40)
                                                                        = local4 1
                                                                    )(else
                                                                        (send pEvent:claimed(1))
                                                                        Print(82 41)
                                                                    )
                                                                )
                                                            )
                                                        )
                                                    )
                                                )(else
                                                    (if (Said('[use]/key<gold') or Said('/gold'))
                                                        (if (not (send gEgo:has(32)))
                                                            Print(82 42)
                                                        )(else
                                                            (if (> (send gEgo:distanceTo(newProp_4)) 15)
                                                                (send pEvent:claimed(1))
                                                                proc0_15()
                                                            )(else
                                                                (if (global220)
                                                                    Print(82 43)
                                                                )(else
                                                                    (if (local4 or not (send gEgo:has(20)))
                                                                        localproc_0038()
                                                                    )(else
                                                                        Print(82 44)
                                                                    )
                                                                )
                                                            )
                                                        )
                                                    )(else
                                                        (if (Said('[use]/key<skeleton') or Said('/skeleton'))
                                                            (if (((send gEgo:has(20)) and local4) and not global220)
                                                                Print(82 39)
                                                            )(else
                                                                Print(82 45)
                                                            )
                                                        )(else
                                                            (if (Said('open/door'))
                                                                (if (< (send gEgo:distanceTo(newProp_4)) 15)
                                                                    (if (global220 and (== (send newProp_4:cel()) 0))
                                                                        (User:
                                                                            canControl(0)
                                                                            canInput(0)
                                                                        )
                                                                        (send newProp_4:
                                                                            startUpd()
                                                                            ignoreActors(1)
                                                                            setCycle(End doDoor)
                                                                        )
                                                                        (send gEgo:stopUpd())
                                                                        (send ((Sound:new())):
                                                                            number(300)
                                                                            loop(1)
                                                                            play()
                                                                        )
                                                                    )(else
                                                                        (if (not global220)
                                                                            Print(82 46)
                                                                        )(else
                                                                            Print(82 47)
                                                                        )
                                                                    )
                                                                )(else
                                                                    proc0_15()
                                                                )
                                                            )(else
                                                                (if (Said('close/door'))
                                                                    (if (== (send newProp_4:cel()) 0)
                                                                        Print(82 24)
                                                                    )(else
                                                                        Print(82 25)
                                                                    )
                                                                )
                                                            )
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
    )

)
(instance doDoor of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send newProp_4:stopUpd()) (User:
                    canControl(1)
                    canInput(1)
                )
 (send gEgo:
                    illegalBits(32768)
                    startUpd()
                )
 )
            )
        )
    )

)
(instance lolotteDead of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((theMusic:
                    number(46)
                    loop(1)
                    play()
                )
 = cycles 2  )
            )
            (case 1
                (proc0_23() (send newAct:setCycle(End self))  )
            )
            (case 2
                (Print(82 48 66 global23 140 135 134 2 20) Print(82 49 66 global23 140 135 134 2 20) (send newProp_3:
                    loop(2)
                    cel(0)
                    show()
                    cycleSpeed(4)
                    setCycle(End stopHeart)
                )
 (send newAct:
                    view(123)
                    loop(0)
                    cel(0)
                    cycleSpeed(2)
                    setCycle(End self)
                )
  )
            )
            (case 3
                (Print(82 50 134 -1 20 66 global23 140 250) (send newAct:
                    loop(1)
                    cel(0)
                    cycleSpeed(3)
                    setCycle(End self)
                )
  )
            )
            (case 4
                (Print(82 51 134 -1 20 140 250 66 global23) (send (= newView (View:new())):
                    view(123)
                    loop(3)
                    posn(172 95)
                    init()
                    setPri(+ (send newAct:priority()) 1)
                )
 Print(82 52 134 -1 20 66 global23 140 250) (send gGame:changeScore(8)) (send newAct:stopUpd()) = global169 0 
                (if (< global160 30)
                    = global160 30
                    = global159 0
                )
 = seconds 3  )
            )
            (case 5
                (Print(82 53 134 -1 20 66 global23) (send newProp:setCycle(End self)) (send newProp_2:setCycle(End)) = global100 0  )
            )
            (case 6
                ((User:
                    canControl(1)
                    canInput(1)
                )
 (send global2:setScript(edsHere)) )
            )
        )
    )

)
(instance shootLolotte of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((User:
                    canControl(0)
                    canInput(0)
                )
 proc0_3(gEgo newAct) (send gEgo:
                    cel(0)
                    view(68)
                    cel(0)
                    setMotion(0)
                    setCycle(End self)
                )
  )
            )
            (case 1
                (Print(82 54 134 -1 20 66 global23) = seconds 1  )
            )
            (case 2
                ((send gEgo:
                    view(4)
                    setCycle(Walk)
                )
 (send ((Inv:at(14))):loop((+ (send ((Inv:at(14))):loop()) 1))) (send global2:setScript(lolotteDead)) )
            )
        )
    )

)
(instance stopHeart of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((send newProp_3:dispose()) )
            )
        )
    )

)
(instance egoZapped of Script
    (properties)

    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((User:
                    canControl(0)
                    canInput(0)
                )
 (send newProp:startUpd()) (send newProp_2:startUpd()) (theMusic:
                    number(45)
                    loop(1)
                    play()
                )
 (send newAct:setCycle(End self))  )
            )
            (case 1
                ((send newAct:
                    loop(1)
                    setCycle(Fwd)
                )
 (send gEgo:
                    view(85)
                    loop(0)
                    cel(0)
                    cycleSpeed(1)
                    setCycle(End self)
                )
  )
            )
            (case 2
                ((send newAct:
                    setCycle(0)
                    cel(0)
                )
 (send gEgo:
                    loop(1)
                    setCycle(End self)
                )
  )
            )
            (case 3
                (Print(82 55 134 15 15 66 global23) (send (ScriptID(0 4)):setReal(self 3))  )
            )
            (case 4
                (= global127 1 )
            )
        )
    )

)
(instance edsHere of Script
    (properties)

    (method (init param1)
        Load(rsVIEW 130)
        Load(rsVIEW 132)
        (super:init(param1))
    )


    (method (changeState newState)
        (switch (= state newState)
            (case 0
                ((theMusic:
                    number(43)
                    loop(1)
                    play()
                )
 (User:
                    canControl(0)
                    canInput(0)
                )
 (send gEgo:
                    setMotion(0)
                    loop(0)
                )
 (send (= newAct_2 (Act:new())):
                    view(130)
                    illegalBits(0)
                    posn(185 205)
                    init()
                    ignoreActors(0)
                    setCycle(Walk)
                    setMotion(MoveTo 251 162 self)
                )
  )
            )
            (case 1
                ((send newAct_2:
                    view(132)
                    loop(1)
                    cel(0)
                    cycleSpeed(6)
                    setCycle(CT 3 1 self)
                )
 = seconds 1  )
            )
            (case 2
                ((send newAct_2:setCycle(CT 0 -1)) = seconds 2  )
            )
            (case 3
                (Print(82 56) (send newAct_2:
                    view(132)
                    setLoop(2)
                    cycleSpeed(0)
                    setCycle(End)
                )
 = seconds 3  )
            )
            (case 4
                ((send newAct_2:
                    view(130)
                    setLoop(-1)
                    setCycle(Walk)
                    setMotion(MoveTo 185 205 self)
                )
  )
            )
            (case 5
                ((User:
                    canControl(1)
                    canInput(1)
                )
 (send newAct_2:dispose()) = state -1 )
            )
        )
    )

)
