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

Sub Picklock.Object
 On Local Error Goto ErrTrap31
 Gosub Get.Config1
 Call Parse
 If Parser Then
    Call Numeric
 Endif
 If Lcase$(Parsed.Command1)="equations" Then
    If Len(option2$) Then
       Strng="Strength.To.Picklock="+option2$
       Call IO.O
    Endif
    If Len(option3$) Then
       Strng="Intelligence.To.Picklock="+option3$
       Call IO.O
    Endif
    If Len(option4$) Then
       Strng="Random.Picklock.Failure="+option4$
       Call IO.O
    Endif
    Exit Sub
 Endif
 Call Check.Room.Items
 If Temp7!>SFalse Then
    Strng="You can't picklock 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 picklock that!"
       Call IO.O
       Exit Sub
    Endif
    If Temp7!=SFalse Then
       Call Num
       Call Examine.Containers
       If TempA! Then
          Call Picklock.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 picklock that!"
       Call IO.O
       Exit Sub
    Endif
    If ObjectRecord.DoorLock=False Then
       Strng="You can't picklock that!"
       Call IO.O
       Exit Sub
    Endif
    If ObjectRecord.DoorLock=1 Then
       Strng="It's already unlocked!"
       Call IO.O
       Exit Sub
    Endif
    If ObjectRecord.KeyNumber=SFalse Then
       Strng="Its' lock can't be picked!"
       Call IO.O
       Exit Sub
    Endif
    If ObjectRecord.Hidden Then
       If option3 Then
          Strng="You can't picklock hidden doors!"
          Call IO.O
          Exit Sub
       Endif
    Endif
    If Normal.User Then
       If UserRecord.ClassType<AsstDM Then
          If UserRecord.ClassType<>Thief Then
             If option1 Then
                Strng="Only thieves can picklock!"
                Call IO.O
                Exit Sub
             Endif
          Endif
          If Len(option2$) Then
             Out2=option2$
             Call Equate(Temp#)
             If Temp# Then
                Strng="You didn't picklock it!"
                Call IO.O
                Exit Sub
             Endif
          Else
             If Int(Rnd*UserRecord.Stats(1))+5<Config2(35) Then
                Strng="You didn't picklock it!"
                Call IO.O
                Exit Sub
             Endif
          Endif
          If Len(option3$) Then
             Out2=option3$
             Call Equate(Temp#)
             If Temp# Then
                Strng="You didn't picklock it!"
                Call IO.O
                Exit Sub
             Endif
          Else
             If Int(Rnd*UserRecord.Stats(2))+5<Config2(36) Then
                Strng="You didn't picklock it!"
                Call IO.O
                Exit Sub
             Endif
          Endif
          If Len(option4$) Then
             Out2=option4$
             Call Equate(Temp#)
             If Temp# Then
                Strng="You didn't picklock it!"
                Call IO.O
                Exit Sub
             Endif
          Else
             If Rnd<Config1(22) Then
                Strng="You didn't picklock it!"
                Call IO.O
                Exit Sub
             Endif
          Endif
       Endif
    Endif
    ObjectRecord.DoorLock=1
    ObjectRecord.Closed=True
    Call Write.Record(ObjectFile,Temp7!)
    Strng="You picklock it!"
    Call IO.O
    Exit Sub
 Endif
 Strng="You can't picklock that!"
 Call IO.O
 Exit Sub
Get.Config1:
 Gosub Reset.Options1
 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$)="[CMD097]" 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
Reset.Options1:
 option1=-1
 option2=10
 option3=-1
 Return
Next.Read1:
 Close #TempFile1
 Filename$=DND.Path+"CMD097.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
          Gosub Reset.Options1
          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 "only.thieves.can.picklock"
    Select Case Lcase$(Var3$)
    Case "0", "false", "off"
       option1=0
    End Select
 Case "cant.picklock.hidden.doors"
    Select Case Lcase$(Var3$)
    Case "0", "false", "off"
       option3=0
    End Select
 Case "strength.to.picklock"
    If Left$(Var3$,1)=Chr$(34) Then
       If Right$(Var3$,1)=Chr$(34) Then
          option2$=Mid$(Var3$,2)
          option2$=Left$(option2$,Len(option2$)-1)
       Endif
    Endif
 Case "intelligence.to.picklock"
    If Left$(Var3$,1)=Chr$(34) Then
       If Right$(Var3$,1)=Chr$(34) Then
          option3$=Mid$(Var3$,2)
          option3$=Left$(option3$,Len(option3$)-1)
       Endif
    Endif
 Case "random.picklock.failure"
    If Left$(Var3$,1)=Chr$(34) Then
       If Right$(Var3$,1)=Chr$(34) Then
          option4$=Mid$(Var3$,2)
          option4$=Left$(option4$,Len(option4$)-1)
       Endif
    Endif
 End Select
 Return
ErrResume31:
 Exit Sub
ErrTrap31:
 Resume ErrResume31
End Sub

Sub Picklock.Container
 On Local Error Goto ErrTrap37
 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
    Strng="You can't picklock that!"
    Call IO.O
    Exit Sub
 Endif
 If ContainerRecord.Locked=1 Then
    Strng="It's already unlocked!"
    Call IO.O
    Exit Sub
 Endif
 If ContainerRecord.KeyNumber=SFalse Then
    Strng="Its' lock can't be picked!"
    Call IO.O
    Exit Sub
 Endif
 If Normal.User Then
    If UserRecord.ClassType<AsstDM Then
       If UserRecord.ClassType<>Thief Then
          If option1 Then
             Strng="Only thieves can picklock!"
             Call IO.O
             Exit Sub
          Endif
       Endif
       If Len(option2$) Then
          Out2=option2$
          Call Equate(Temp#)
          If Temp# Then
             Strng="You didn't picklock it!"
             Call IO.O
             Exit Sub
          Endif
       Else
          If Int(Rnd*UserRecord.Stats(1))+5<Config2(35) Then
             Strng="You didn't picklock it!"
             Call IO.O
             Exit Sub
          Endif
       Endif
       If Len(option3$) Then
          Out2=option3$
          Call Equate(Temp#)
          If Temp# Then
             Strng="You didn't picklock it!"
             Call IO.O
             Exit Sub
          Endif
       Else
          If Int(Rnd*UserRecord.Stats(2))+5<Config2(36) Then
             Strng="You didn't picklock it!"
             Call IO.O
             Exit Sub
          Endif
       Endif
       If Len(option4$) Then
          Out2=option4$
          Call Equate(Temp#)
          If Temp# Then
             Strng="You didn't picklock it!"
             Call IO.O
             Exit Sub
          Endif
       Else
          If Rnd<Config1(22) Then
             Strng="You didn't picklock it!"
             Call IO.O
             Exit Sub
          Endif
       Endif
    Endif
 Endif
 ContainerRecord.Locked=1
 ContainerRecord.Closed=True
 Call Write.Record(ContainerFile,TempA!)
 Strng="You picklock it!"
 Call IO.O
 Exit Sub
Get.Config2:
 option1=-1
 option2=10
 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$)="[CMD097]" 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+"CMD097.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=10
          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 "only.thieves.can.picklock.container"
    Select Case Lcase$(Var3$)
    Case "0", "false", "off"
       option1=0
    End Select
 Case "strength.to.picklock.container"
    If Left$(Var3$,1)=Chr$(34) Then
       If Right$(Var3$,1)=Chr$(34) Then
          option2$=Mid$(Var3$,2)
          option2$=Left$(option2$,Len(option2$)-1)
       Endif
    Endif
 Case "intelligence.to.picklock.container"
    If Left$(Var3$,1)=Chr$(34) Then
       If Right$(Var3$,1)=Chr$(34) Then
          option3$=Mid$(Var3$,2)
          option3$=Left$(option3$,Len(option3$)-1)
       Endif
    Endif
 Case "random.picklock.failure.container"
    If Left$(Var3$,1)=Chr$(34) Then
       If Right$(Var3$,1)=Chr$(34) Then
          option4$=Mid$(Var3$,2)
          option4$=Left$(option4$,Len(option4$)-1)
       Endif
    Endif
 End Select
 Return
ErrResume37:
 Exit Sub
ErrTrap37:
 Resume ErrResume37
End Sub
