(version 2)
(include "sci.sh")
(exports
    0 doCode
    1 useCode
)
(use "Main")
(use "GloryWindow")
(use "Obj")
(script 29)



(instance aChestWindow of GloryWindow
    (properties
        color 5
        back 2
        yOffset 28
    )

    (method (open)
        (send (ScriptID(16 2)):nsLeft((- (/ (- (self:right) (self:left)) 2) 60)))
        = bottom (+ bottom 4)
        (super:open())
    )

)
(instance public doCode of Code
    (properties)

    (method (init)
        (var temp0, temp1, temp2)
        = temp1 0
        = temp2 
            (if (== gClientModNum 310)
                0
            )(else
                (if (== gClientModNum 430)
                    14
                )(else
                    14
                )
            )
        = temp0 0
        (while (< temp0 14)
            (if (global331[+ temp0 temp2])
                (send ((send gInv:at((+ temp0 10)))):realOwner(ScriptID(gClientModNum 0)))
                = temp1 1
            )
            ++temp0
        )
        = temp0 0
        (while (< temp0 47)
            (if (== (send ((send gInv:at(temp0))):realOwner) gClientModNum)
                (send ((send gInv:at(temp0))):realOwner(ScriptID(gClientModNum 0)))
                = temp1 1
            )
            ++temp0
        )
        (if (temp1)
            (send gInv:window(aChestWindow))
            (send (ScriptID(16 1)):init(ScriptID(gClientModNum 0)))
            = temp0 0
            (while (< temp0 47)
                (if (== (send ((send gInv:at(temp0))):realOwner) ScriptID(gClientModNum 0))
                    (send ((send gInv:at(temp0))):realOwner(gClientModNum))
                )
                (if ((send ((send gInv:at(temp0))):amount))
                    (send ((send gInv:at(temp0))):realOwner(gOwner))
                )
                ++temp0
            )
        )(else
            (send gQg3Messager:say(1 6 1 1 0 29))
        )
    )

)
(instance public useCode of Code
    (properties)

    (method (init param1 param2 param3)
        (if (not param1 or (== param1 48))
            (send gQg3Messager:say(1 6 2 1 0 29))
        )(else
            (if ((send ((send gInv:at(param1))):mustKeep))
                (send gQg3Messager:say(1 6 3 1 0 29))
            )(else
                (if ((< param1 10) or (>= param1 24))
                    (send ((send gInv:at(param1))):
                        loseItem()
                        roomGets()
                    )
                    (send gQg3Messager:say(1 6 4 1 0 29))
                    (send gMainIconBar:curInvIcon(0))
                )(else
                    = param3 
                        (if (== gClientModNum 310)
                            0
                        )(else
                            (if (== gClientModNum 430)
                                14
                            )(else
                                14
                            )
                        )
                    (send ((send gInv:at(param1))):roomGets())
                    (send ((send gInv:at(param1))):amount((- (send ((send gInv:at(param1))):amount) 1)))
                    (if (> (send ((send gInv:at(param1))):amount) 0)
                        (send gQg3Messager:say(1 6 5 1 0 29))
                    )(else
                        (send ((send gInv:at(param1))):loseItem())
                        (send gMainIconBar:curInvIcon(0))
                        (send gQg3Messager:say(1 6 4 1 0 29))
                    )
                )
            )
        )
    )

)
