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

Sub Fix.Object
 On Local Error Goto Error.Trap18
 Gosub Get.Config1
 VarA$=Parsed.Command1
 VarB$=Parsed.Command2

 Var$=User.Command
 Var=Instr(Var$," ")
 If Var Then
    Var$=Left$(Var$,Var-1)
 Endif
 If Instr(Parsed.command2," ")=0 Then
    If Lcase$(Var$)="restore" Then
       Call Num
       Call Examine.Containers
       If TempA! Then
          If ContainerRecord.Material<=False Then ' paper
             Select Case ContainerRecord.Size
             Case 2 ' medium
                ContainerRecord.Size=3
                Call Write.Record(ContainerFile,TempA!)
                Strng="You restore it!"
                Call IO.O
                Exit Sub
             Case 1 ' small
                ContainerRecord.Size=2
                Call Write.Record(ContainerFile,TempA!)
                Strng="You restore it!"
                Call IO.O
                Exit Sub
             End Select
          Endif
       Endif
    Endif
 Endif

 If Instr(Parsed.command2," ") Then
    ' fix box user
    Call ParseX
    ' parsed.command1=user
    ' parsed.command2=box
    Call Numeric
    ' online users
    Call Search.Mess(SFalse)
    If Temp!=Room And TempB!<>User.Index Then
       VarY=TempC ' node
       VarB!=TempB!
       Out2=MessWorkRecord1.UserName
       Out2=Rtrim$(Out2)
       Out2=Lcase$(Out2)
       Var3$=Out2
       Parsed.Command1=Parsed.Command2
       Call Numeric
       Call Search.User.Container2
       If TempA!<>SFalse Then
          VarQ2=ContainerRecord.TrapType
          VarQ3=ContainerRecord.TrapHits
          VarQ4!=ContainerRecord.TrapItem
          Var2$=ContainerRecord.ContainerShort
          Var2$=Rtrim$(Var2$)
          Var2$=Lcase$(Var2$)
          VarZ$=Var2$
          If Normal.User Then
             If UserRecord2.ClassType>=Lady Then
                Strng3=Rtrim$(Class.Name(UserRecord2.ClassType))
                Call A.Or.An
                Strng="You can't search "+Prefix1+Strng3+"."
                Call IO.O
                Exit Sub
             Endif
             If UserRecord.ClassType<AsstDM Then
                If UserRecord.ClassType<>Thief Then
                   Strng="Only thieves can fix containers!"
                   Call IO.O
                   Exit Sub
                Endif
                If UserRecord.Level<2 Then
                   Strng="Only level 2 thieves can fix containers!"
                   Call IO.O
                   Exit Sub
                Endif
             Endif
          Endif
          Call ContainerTraps(VarQ2,VarQ3,VarQ4!,VarZ$)
          If VarQ2=-1 Then ' *boom*
             Exit Sub
          Endif
          Temp4=False
          Call Fix.Container
          Exit Sub
       Endif
       Strng="You can't search that user!"
       Call IO.O
       Exit Sub
    Endif
    Parsed.Command1=VarA$
    Parsed.Command2=VarB$
    ' look box user
    Call ParseX
    ' parsed.command1=user
    ' parsed.command2=box
    Call Numeric
    ' offline users
    Call Check.User
    If User.Temp Then
       Var3$=Out3
       Parsed.Command1=Parsed.Command2
       Call Numeric
       TempB!=MessWorkRecord4.Index
       Call Search.User.Container2
       If TempA!<>SFalse Then
          VarQ2=ContainerRecord.TrapType
          VarQ3=ContainerRecord.TrapHits
          VarQ4!=ContainerRecord.TrapItem
          Var2$=ContainerRecord.ContainerShort
          Var2$=Rtrim$(Var2$)
          Var2$=Lcase$(Var2$)
          VarZ$=Var2$
          If Normal.User Then
             If UserRecord2.ClassType>=Lady Then
                Strng3=Rtrim$(Class.Name(UserRecord2.ClassType))
                Call A.Or.An
                Strng="You can't search "+Prefix1+Strng3+"."
                Call IO.O
                Exit Sub
             Endif
             If UserRecord.ClassType<AsstDM Then
                If UserRecord.ClassType<>Thief Then
                   Strng="Only thieves can fix containers!"
                   Call IO.O
                   Exit Sub
                Endif
                If UserRecord.Level<2 Then
                   Strng="Only level 2 thieves can fix containers!"
                   Call IO.O
                   Exit Sub
                Endif
             Endif
          Endif
          Call ContainerTraps(VarQ2,VarQ3,VarQ4!,VarZ$)
          If VarQ2=-1 Then ' *boom*
             Exit Sub
          Endif
          Temp4=False
          Call Fix.Container
          Exit Sub
       Endif
    Endif
    Strng="You can't search that user!"
    Call IO.O
    Exit Sub
 Endif
 Call Parse
 If Parser Then
    Call Numeric
 Endif
 Call Check.User.Items
 If Temp7!<SFalse Then
    Strng="You can't fix that!"
    Call IO.O
    Exit Sub
 Endif
 If Temp7!=SFalse Then
    Call Num
    Call Examine.Containers
    If TempA! Then
       Call Fix.Container
       Exit Sub
    Endif
 Endif
 If TreasureRecord.Spell Then
    Strng="You can't fix that!"
    Call IO.O
    Exit Sub
 Endif
 If MessWorkRecord6.Charges>False Then
    Strng="That's not broken!"
    Call IO.O
    Exit Sub
 Endif
 If UserRecord.Stats(3)<Config2(28) Then
    Strng="You didn't fix it!"
    Call IO.O
    Exit Sub
 Endif
 If TreasureRecord.Plus>Config2(29) Then
    Strng="You didn't fix it!"
    Call IO.O
    Exit Sub
 Endif
 If Len(option1$) Then
    Out2=option1$
    Call Equate(Temp#)
 Else
    Temp#=Rnd<Config1(16)
 Endif
 If Temp# Then
    Strng="You didn't fix it!"
    Call IO.O
    Exit Sub
 Endif
 Temp1=TreasureRecord.Charges
 If Temp1>Config2(30) Then
    Temp1=Config2(30)
 Endif
 MessWorkRecord6.Charges=Temp1
 Call Write.Record(MessWorkFile6,Temp5!)
 Strng="You fix it!"
 Call IO.O
 Exit Sub
Get.Config1:
 VarX=0
 Do
    VarX=VarX+1
    If VarX>Options.Lines Then
       Exit Do
    Endif
    Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
    If Ucase$(Var$)="[CMD050]" Then
       Do
          VarX=VarX+1
          If VarX>Options.Lines Then
             Return
          Endif
          Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
          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)))
             Select Case Lcase$(Var2$)
             Case "fix.object"
                If Left$(Var3$,1)=Chr$(34) Then
                   If Right$(Var3$,1)=Chr$(34) Then
                      option1$=Mid$(Var3$,2)
                      option1$=Left$(option1$,Len(option1$)-1)
                   Endif
                Endif
             End Select
          Endif
       Loop
    Endif
 Loop
 Return
Error.Resume18:
 Exit Sub
Error.Trap18:
 Resume Error.Resume18
End Sub

Sub Fix.Container
 On Local Error Goto ErrTrap37x
 Gosub Get.Config2
 If ContainerRecord.Damaged=False Then
    Strng="You can't! It's not damaged!"
    Call IO.O
    Exit Sub
 Endif
 If Len(option1$) Then
    Out2=option1$
    Call Equate(Temp#)
 Else
    Temp#=Rnd<Config1(16)
 Endif
 If Temp# Then
    Strng="You didn't fix it!"
    Call IO.O
    Exit Sub
 Endif
 Call Read.Record(ContainerFile,TempA!)
 ContainerRecord.Damaged=False
 Call Write.Record(ContainerFile,TempA!)
 Strng="You fix it!"
 Call IO.O
 Exit Sub
Get.Config2:
 VarX=0
 Do
    VarX=VarX+1
    If VarX>Options.Lines Then
       Exit Do
    Endif
    Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
    If Ucase$(Var$)="[CMD050]" Then
       Do
          VarX=VarX+1
          If VarX>Options.Lines Then
             Return
          Endif
          Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
          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)))
             Select Case Lcase$(Var2$)
             Case "fix.container"
                If Left$(Var3$,1)=Chr$(34) Then
                   If Right$(Var3$,1)=Chr$(34) Then
                      option1$=Mid$(Var3$,2)
                      option1$=Left$(option1$,Len(option1$)-1)
                   Endif
                Endif
             End Select
          Endif
       Loop
    Endif
 Loop
 Return
ErrResume37x:
 Exit Sub
ErrTrap37x:
 Resume ErrResume37x
End Sub
