 Rem File: Cmd080.bas
 Rem Sub: Lock.Object
 Rem $Include: 'dndbbs.inc'
 On Error Goto Main.Error
 If Chained<>-2 Then
    Color 15,0
    Print "DNDBBS Command 080 -- Lock.Object."
    Color 7,0
    End
 Endif
 Call Lock.Object
Main.Resume:
 Chain DND.Path+"DNDBBS.EXE"
 End
Main.Error:
 Resume Main.Resume

Sub Lock.Object
 On Local Error Goto ErrTrap29
 Gosub Get.Config1
 Call Parse
 If Parser Then
    Call Numeric
 Endif
 Call Check.Room.Items
 If Temp7!>SFalse Then
    Strng="You can't lock that!"
    Call IO.O
    Exit Sub
 Endif
 If Temp7!=SFalse Then
    Call Num
    Call Check.User.Items
    If Temp7!>SFalse Then
       Strng="You can't lock that!"
       Call IO.O
       Exit Sub
    Endif
    If Temp7!=SFalse Then
       Call Num
       Call Examine.Containers
       If TempA! Then
          Call Lock.Container
          Exit Sub
       Endif
    Endif
 Endif
 If Temp7!<SFalse Then
    Temp7!=Abs(Temp7!)
    Call Return.Room(Var!)
    If Var!=SFalse Then
       Strng="You can't lock that!"
       Call IO.O
       Exit Sub
    Endif
    If ObjectRecord.DoorLock=False Then
       Strng="You can't lock that!"
       Call IO.O
       If Sysop Then
          If option1 Then
             No.Input.Out="n"
             Strng="Add lock to item(y/n)? "
             Call IO.I
             If Yes Then
                ObjectRecord.DoorLock=2
                ObjectRecord.Closed=True
                Call Write.Record(ObjectFile,Temp7!)
                Strng="You lock it!"
                Call IO.O
                If option2 Then
                   If ObjectRecord.KeyNumber>SFalse Then
                      Strng="Already has keynumber (#"+Right$(Str$(ObjectRecord.KeyNumber+1000000!),6)+")"
                      Call IO.O
                   Endif
                   No.Input.Out="n"
                   Strng="Add keynumber to lock(y/n)? "
                   Call IO.I
                   If Yes Then
                      Strng="Key number(1-999999)? "
                      Call IO.I
                      Temp3!=Int(Val(Out2)+.5)
                      If Temp3!>SFalse And Temp3!<=999999! Then
                         ObjectRecord.KeyNumber=Temp3!
                         Call Write.Record(ObjectFile,Temp7!)
                         Strng="Keynumber added to lock!"
                         Call IO.O
                      Endif
                   Endif
                Endif
             Endif
          Endif
       Endif
       Exit Sub
    Endif
    If ObjectRecord.DoorLock=2 Then
       Strng="It's already locked!"
       Call IO.O
       Exit Sub
    Endif
    ObjectRecord.DoorLock=2
    ObjectRecord.Closed=True
    Call Write.Record(ObjectFile,Temp7!)
    Strng="You lock it!"
    Call IO.O
    Exit Sub
 Endif
 Strng="You can't lock that!"
 Call IO.O
 Exit Sub
Get.Config1:
 option1=-1
 option2=0
 VarX=0
 Do
    VarX=VarX+1
    If VarX>Options.Lines Then
       Goto Next.Read1
       Exit Do
    Endif
    Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
    If Ucase$(Var$)="[CMD080]" Then
       Do
          VarX=VarX+1
          If VarX>Options.Lines Then
             Goto Next.Read1
             Return
          Endif
          Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
          If Ucase$(Var$)="[END]" Then
             Goto Next.Read1
             Return
          Endif
          Var=Instr(Var$,"=")
          If Var Then
             Var2$=Ltrim$(Rtrim$(Left$(Var$,Var-1)))
             Var3$=Ltrim$(Rtrim$(Mid$(Var$,Var+1)))
             Gosub Parse.Options1
          Endif
       Loop
    Endif
 Loop
 Return
Next.Read1:
 Close #TempFile1
 Filename$=DND.Path+"CMD080.CFG"
 If Dir$(Filename$)="" Then
    Return
 Endif
 Open Filename$ For Input As #TempFile1
 Do
    If Eof(TempFile1) Then
       Exit Do
    Endif
    Line Input #TempFile1, Var$
    Var$=Ltrim$(Rtrim$(Var$))
    If Left$(Var$,1)<>";" Then
       VarX$=UserRecord.CodeName
       VarX$=Rtrim$(VarX$)
       VarX$=Ucase$(VarX$)
       If Ucase$(Var$)="["+VarX$+"]" Then
          VarZ=0
          option1=-1
          option2=0
          Do
             If Eof(TempFile1) Then
                Exit Do
             Endif
             Line Input #TempFile1, Var$
             If Ucase$(Var$)="[END]" Then
                Return
             Endif
             Var=Instr(Var$,"=")
             If Var Then
                Var2$=Ltrim$(Rtrim$(Left$(Var$,Var-1)))
                Var3$=Ltrim$(Rtrim$(Mid$(Var$,Var+1)))
                Gosub Parse.Options1
             Endif
          Loop
       Endif
    Endif
 Loop
 Return
Parse.Options1:
 Select Case Lcase$(Var2$)
 Case "allow.lock.override"
    Select Case Lcase$(Var3$)
    Case "0", "false", "off"
       option1=0
    End Select
 Case "allow.keynuber.override"
    Select Case Lcase$(Var3$)
    Case "-1", "true", "on"
       option2=-1
    End Select
 End Select
 Return
ErrResume29:
 Exit Sub
ErrTrap29:
 Resume ErrResume29
End Sub

' ContainerRecord.Locked=
'   -1  is locked
'    1  is unlocked
'    0  has no lock
' ContainerRecord.Closed=
'   -1  is closed
'    0  is open

Sub Lock.Container
 On Local Error Goto ErrTrap35
 Gosub Get.Config2
 If ContainerRecord.Damaged=True Then
    Strng="You can't, it's damaged!"
    Call IO.O
    Exit Sub
 Endif
 If ContainerRecord.Locked=False Then ' has no lock
    Strng="You can't lock that!"
    Call IO.O
    If Sysop Then
       If option1 Then
          No.Input.Out="n"
          Strng="Add lock to item(y/n)? "
          Call IO.I
          If Yes Then
             ContainerRecord.Locked=True ' locked
             ContainerRecord.Closed=True ' closed
             Call Write.Record(ContainerFile,TempA!)
             Strng="You lock it!"
             Call IO.O
             If option2 Then
                If ContainerRecord.KeyNumber>SFalse Then
                   Strng="Already has keynumber (#"+Right$(Str$(ContainerRecord.KeyNumber+1000000!),6)+")"
                   Call IO.O
                Endif
                No.Input.Out="n"
                Strng="Add keynumber to lock(y/n)? "
                Call IO.I
                If Yes Then
                   Strng="Key number(1-999999)? "
                   Call IO.I
                   Temp3!=Int(Val(Out2)+.5)
                   If Temp3!>SFalse And Temp3!<=999999! Then
                      ContainerRecord.KeyNumber=Temp3!
                      Call Write.Record(ContainerFile,TempA!)
                      Strng="Keynumber added to lock!"
                      Call IO.O
                   Endif
                Endif
             Endif
          Endif
       Endif
    Endif
    Exit Sub
 Endif
 If ContainerRecord.Locked=True Then ' is locked
    Strng="It's already locked!"
    Call IO.O
    Exit Sub
 Endif
 ContainerRecord.Locked=True ' locked
 ContainerRecord.Closed=True ' closed
 Call Write.Record(ContainerFile,TempA!)
 Strng="You lock it!"
 Call IO.O
 Exit Sub
Get.Config2:
 option1=-1
 option2=0
 VarX=0
 Do
    VarX=VarX+1
    If VarX>Options.Lines Then
       Goto Next.Read2
       Exit Do
    Endif
    Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
    If Ucase$(Var$)="[CMD080]" Then
       Do
          VarX=VarX+1
          If VarX>Options.Lines Then
             Goto Next.Read2
             Return
          Endif
          Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
          If Ucase$(Var$)="[END]" Then
             Goto Next.Read2
             Return
          Endif
          Var=Instr(Var$,"=")
          If Var Then
             Var2$=Ltrim$(Rtrim$(Left$(Var$,Var-1)))
             Var3$=Ltrim$(Rtrim$(Mid$(Var$,Var+1)))
             Gosub Parse.Options2
          Endif
       Loop
    Endif
 Loop
 Return
Next.Read2:
 Close #TempFile1
 Filename$=DND.Path+"CMD080.CFG"
 If Dir$(Filename$)="" Then
    Return
 Endif
 Open Filename$ For Input As #TempFile1
 Do
    If Eof(TempFile1) Then
       Exit Do
    Endif
    Line Input #TempFile1, Var$
    Var$=Ltrim$(Rtrim$(Var$))
    If Left$(Var$,1)<>";" Then
       VarX$=UserRecord.CodeName
       VarX$=Rtrim$(VarX$)
       VarX$=Ucase$(VarX$)
       If Ucase$(Var$)="["+VarX$+"]" Then
          VarZ=0
          option1=-1
          option2=0
          Do
             If Eof(TempFile1) Then
                Exit Do
             Endif
             Line Input #TempFile1, Var$
             If Ucase$(Var$)="[END]" Then
                Return
             Endif
             Var=Instr(Var$,"=")
             If Var Then
                Var2$=Ltrim$(Rtrim$(Left$(Var$,Var-1)))
                Var3$=Ltrim$(Rtrim$(Mid$(Var$,Var+1)))
                Gosub Parse.Options2
             Endif
          Loop
       Endif
    Endif
 Loop
 Return
Parse.Options2:
 Select Case Lcase$(Var2$)
 Case "allow.container.lock.override"
    Select Case Lcase$(Var3$)
    Case "0", "false", "off"
       option1=0
    End Select
 Case "allow.container.keynuber.override"
    Select Case Lcase$(Var3$)
    Case "-1", "true", "on"
       option2=-1
    End Select
 End Select
 Return
ErrResume35:
 Exit Sub
ErrTrap35:
 Resume ErrResume35
End Sub
