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

Sub Hide.User
 On Local Error Goto ErrTrap12
 Gosub Get.Config
 If Hidden.Player Then
    Strng="You are already hidden!"
    Call IO.O
    Exit Sub
 Endif
 Var=False
 If Len(option1$) Then
    Out2=option1$
    Call Equate(Temp#)
    If Temp# Then
       Var=True
    Endif
 Else
    If Rnd>.66 Then
       Var=True
    Endif
 Endif
 If Var Then
    If Normal.User Then
       If Len(option2$) Then
          Out2=option2$
          Call Equate(Temp#)
          If Temp# Then
             Var1=True
          Endif
       Else
          If UserRecord.Stats(7)<=5 Then
             Var1=True
          Endif
       Endif
       If Var1 Then
          Strng="You are too ugly to hide!"
          Call IO.O
          Exit Sub
       Endif
    Endif
    Hidden.Player=True
    UserRecord.Room=Room
    UserRecord.SortInv=Sorting
    UserRecord.Hidden=Hidden.Player
    Call Write.Record(UserFile,User.Index)
    Strng="You hide in the shadows.."
    Call IO.O
    Exit Sub
 Endif
 Strng="Didn't work!"
 Call IO.O
 Exit Sub
Get.Config:
 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$)="[CMD062]" 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+"CMD062.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
          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 "hide.equation"
    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
 Case "hide.failure"
    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
  End Select
  Return
ErrResume12:
 Exit Sub
ErrTrap12:
 Resume ErrResume12
End Sub

Sub Hide.Object
 On Local Error Goto ErrTrap24
 Gosub Get.Config1
 If Lcase$(Parsed.Command1)="all" Then
    If Config2(137)=False Then
       Strng="Hide all not allowed."
       Call IO.O
       Exit Sub
    Endif
    Call Hide.All.Items
    Exit Sub
 Endif
 VarX#=Int(Val(Parsed.Command1)+.5)
 If VarX#>DFalse Then
    If VarX#<=UserRecord.Gold Then
       If VarX#<=Option1# Or Option1#=-1# Then
          Close #TempFile1
          FileName=DND.Path+"coins.dat"
          Open FileName For Random Shared As #TempFile1 Len=16
          Field #TempFile1, 4 As R$, 8 As G$, 2 As P1$, 2 As P2$
          V! = Lof(TempFile1)/16+1!
          LSET R$ = MKS$(Room)
          LSET G$ = MKD$(VarX#)
          LSET P1$ = MKI$(-1)
          LSET P2$ = MKI$(0%)
          PUT #TempFile1, V!
          UserRecord.Gold=UserRecord.Gold-VarX#
          Call Amount(VarX#,VarQ$)
          Strng="You hide"+VarQ$+" gold!"
          Call IO.O
          Exit Sub
       Else
          Strng="You can't hide that much gold!"
          Call IO.O
          Exit Sub
       Endif
    Else
       Strng="You don't have that much gold!"
       Call IO.O
       Exit Sub
    Endif
 Endif
 Call Parse
 If Parser Then
    Call Numeric
 Endif
 Call Check.User.Items
 If Temp7!<SFalse Then
    If ObjectRecord.Invisible Then
       TempZ3=-1
    Endif
    Call Hide.Item.In.Room(Temp7!,Temp6)
    MessWorkRecord6.Room=SFalse
    MessWorkRecord6.User=SFalse
    MessWorkRecord6.Index=SFalse
    MessWorkRecord6.Charges=False
    MessWorkRecord6.Plus=False
    MessWorkRecord6.Prev=SFalse
    MessWorkRecord6.Next=SFalse
    MessWorkRecord6.Plus=False
    Call Write.Record(MessWorkFile6,Temp5!)
    Out3=Lcase$(Out3)
    Strng2="You hide "
    Out4=Rtrim$(ObjectRecord.Prefix1)
    Strng=Strng2+Out4+Out3
    Call Convert.ANSI(True,VarQ,VarR)
    Carriage.Return=True
    Graphics.On=True
    Call IO.O
    Graphics.On=False
    Grpahics.Off=True
    Strng=Nul
    If TempZ3 Then
       Strng=" [inv]"
    Endif
    Strng=Strng+"!"
    Call IO.O
    Exit Sub
 Endif
 If Temp7!>SFalse Then
    If TreasureRecord.Container Then
       Call Hide.Container.In.Room(Temp7!)
       Call Hide.Discard(Temp5!,True,VarZ)
    Else
       If TreasureRecord.LightType Then
          If MessWorkRecord6.Charges<False Then
             TempZ2=-1
          Endif
       Endif
       Call Hide.Discard(Temp5!,False,VarZ)
    Endif
    If TreasureRecord.Invisible Then
       TempZ3=-1
    Endif
    Out3=Lcase$(Out3)
    Strng2="You hide "
    Out4=Rtrim$(TreasureRecord.Prefix1)
    Strng=Strng2+Out4+Out3
    Call Convert.ANSI(True,VarQ,VarR)
    Carriage.Return=True
    Graphics.On=True
    Call IO.O
    Graphics.On=False
    Grpahics.Off=True
    Strng=Nul
    If TempZ2 Then
       Strng=" [lit]"
    Endif
    If TempZ3 Then
       Strng=Strng+" [inv]"
    Endif
    Strng=Strng+"!"
    Call IO.O
    Exit Sub
 Endif
 Call Num
 Call Search.User.Containers
 If TempA! Then
    Call Hide.Container
    Exit Sub
 Endif
 Strng="You can't hide that!"
 Call IO.O
 Exit Sub

Get.Config1:
 Option1#=1D300
 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$)="[CMD062]" 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+"CMD062.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
          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 "hide.gold.maximum"
    Option1#=Int(Val(Var3$)+.5)
 End Select
 Return
ErrResume24:
 Exit Sub
ErrTrap24:
 Resume ErrResume24
End Sub

Sub Hide.All.Items
 On Local Error Goto ErrTrap23a
 Temp6=False
 Temp7!=SFalse
 For Temp5!=1! To Lof(MessWorkFile6)/MessWorkRecLen6
    Call Read.Record(MessWorkFile6,Temp5!)
    If MessWorkRecord6.User=User.Index Then
       VarQ!=MessWorkRecord6.Index
       If VarQ!<SFalse Then
          VarA!=Abs(VarQ!)
          If VarA!>SFalse And VarA!<=Lof(ObjectFile)/ObjectRecLen Then
             Call Read.Record(ObjectFile,VarA!)
             Out3=ObjectRecord.ShortName
             Out3=Left$(Out3,Len(Parsed.Command1))
             Out3=ObjectRecord.ObjectName
             Out3=Rtrim$(Out3)
             Temp7!=VarQ!
             Temp6=MessWorkRecord6.Charges
             Call Hide.Item.In.Room(Temp7!,Temp6)
             MessWorkRecord6.User=SFalse
             MessWorkRecord6.Room=SFalse
             MessWorkRecord6.Index=SFalse
             MessWorkRecord6.Charges=False
             MessWorkRecord6.Plus=False
             MessWorkRecord6.Prev=SFalse
             MessWorkRecord6.Next=SFalse
             Call Write.Record(MessWorkFile6,Temp5!)
             TempZ3=0
             If ObjectRecord.Invisible Then
                TempZ3=-1
             Endif
             Strng2="You hide "
             Out4=Rtrim$(ObjectRecord.Prefix1)
             Strng=Strng2+Out4+Out3
             Call Convert.ANSI(True,VarQ,VarR)
             Carriage.Return=True
             Graphics.On=True
             Call IO.O
             Graphics.On=False
             Grpahics.Off=True
             Strng=Nul
             If TempZ3 Then
                Strng=Strng+" [inv]"
             Endif
             Strng=Strng+"!"
             Call IO.O
          Endif
       Endif
       If VarQ!>SFalse Then
          If VarQ!>SFalse And VarQ!<=Lof(TreasureFile)/TreasureRecLen Then
             Call Read.Record(TreasureFile,VarQ!)
             Out3=TreasureRecord.ShortName
             Out3=Left$(Out3,Len(Parsed.Command1))
             Out3=TreasureRecord.TreasureName
             Out3=Rtrim$(Out3)
             Out3=Lcase$(Out3)
             TempZ2=0
             TempZ3=0
             Temp7!=VarQ!
             Temp6=MessWorkRecord6.Charges
             If TreasureRecord.Container Then
                Call Hide.Container.In.Room(Temp7!)
                Call Hide.Discard(Temp5!,True,VarZ)
             Else
                If TreasureRecord.LightType Then
                   If MessWorkRecord6.Charges<False Then
                      TempZ2=-1
                   Endif
                Endif
                Call Hide.Discard(Temp5!,False,VarZ)
             Endif
             If TreasureRecord.Invisible Then
                TempZ3=-1
             Endif
             Strng2="You hide "
             Out4=Rtrim$(TreasureRecord.Prefix1)
             Strng=Strng2+Out4+Out3
             Call Convert.ANSI(True,VarQ,VarR)
             Carriage.Return=True
             Graphics.On=True
             Call IO.O
             Graphics.On=False
             Grpahics.Off=True
             Strng=Nul
             If TempZ2 Then
                Strng=" [lit]"
             Endif
             If TempZ3 Then
                Strng=Strng+" [inv]"
             Endif
             Strng=Strng+"!"
             Call IO.O
          Endif
       Endif
    Endif
 Next
 Temp6=False
 Temp7!=SFalse
 TempA!=SFalse
 Temp5!=UserRecord.First2
 If Temp5! Then
    Do While Lost.Carrier=False
       Call Read.Record(ContainerFile,Temp5!)
       Var6!=ContainerRecord.Next
       If ContainerRecord.DeletedContainer=False Then
          If ContainerRecord.WithinContainer=SFalse Then
             Out3=ContainerRecord.ContainerShort
             Out3=Left$(Out3,Len(Parsed.Command1))
             Out3=ContainerRecord.ContainerName
             Out3=Rtrim$(Out3)
             TempA!=Temp5!
             Call Hide.Container
          Endif
       Endif
       If Var6!=SFalse Then
          Exit Do
       Endif
       Temp5!=Var6!
    Loop
 Endif
ErrResume23a:
 Exit Sub
ErrTrap23a:
 Resume ErrResume23a
End Sub

Sub Hide.Container
 On Local Error Goto ErrTrap38
 Call Delete.User.Container(TempA!)
 Call Read.Record(ContainerFile,TempA!)
 ContainerRecord.RoomNumber=Room
 ContainerRecord.UserNumber=SFalse
 ContainerRecord.InvisibleContainer=True
 Call Add.Room.Container(TempA!)
 Weight=Weight-ContainerRecord.Weight
 If Weight<DFalse Then
    Weight=DFalse
 Endif
 Out3=Lcase$(Out3)
 Strng2="You hide "
 Out4=Rtrim$(ContainerRecord.Prefix1)
 Strng=Strng2+Out4+Out3
 Call Convert.ANSI(True,VarQ,VarR)
 Carriage.Return=True
 Graphics.On=True
 Call IO.O
 Graphics.On=False
 Grpahics.Off=True
 Strng="!"
 Call IO.O
ErrResume38:
 Exit Sub
ErrTrap38:
 Resume ErrResume38
End Sub

Sub Hide.Item.In.Room(Var1!,Var2)
 On Local Error Goto ErrTrap23b
 VarX!=Lof(RoomInvFile)/MessWorkRecLen6+1!
 MessWorkRecord6.Room=Room
 MessWorkRecord6.User=SFalse
 MessWorkRecord6.Index=-Abs(Var1!)
 MessWorkRecord6.Charges=Var2
 MessWorkRecord6.Plus=Hidden.Object
 Call Write.Record(RoomInvFile,VarX!)
 Call Add.List.Node(VarX!)
ErrResume23b:
 Exit Sub
ErrTrap23b:
 Resume ErrResume23b
End Sub

Sub Hide.Container.In.Room(Var2!)
 On Local Error Goto ErrTrap48
 VarA!=Lof(ContainerFile)/ContainerRecLen+1!
 Call Clear.Container
 ContainerRecord.ContainerName=TreasureRecord.TreasureName
 ContainerRecord.ContainerShort=TreasureRecord.ShortName
 ContainerRecord.ContainerMax=TreasureRecord.ContainerMax
 ContainerRecord.NamePrefix=TreasureRecord.ContainerPrefix
 ContainerRecord.Size=TreasureRecord.ContainerSize
 ContainerRecord.Material=TreasureRecord.ContainerMaterial
 If TreasureRecord.KeyNumber Then
    ContainerRecord.KeyNumber=TreasureRecord.KeyNumber
    ContainerRecord.Closed=True
    ContainerRecord.Locked=True
 Endif
 If TreasureRecord.Locked Then
    ContainerRecord.Closed=True
    ContainerRecord.Locked=True
 Endif
 ContainerRecord.RoomNumber=Room
 ContainerRecord.UserNumber=False
 ContainerRecord.Weight=TreasureRecord.Weight
 ContainerRecord.ContainerIndex=Abs(Var2!)
 ContainerRecord.Disappears=TreasureRecord.ContainerDisappears
 ContainerRecord.SelfImplodes=TreasureRecord.ContainerSelfImplodes
 ContainerRecord.Permanent=TreasureRecord.Permanent
 For VarR=1 To 3
    ContainerRecord.RestrictItem(VarR)=TreasureRecord.RestrictItem(VarR)
 Next
 ContainerRecord.TrapType=TreasureRecord.TrapType
 ContainerRecord.TrapHits=TreasureRecord.TrapHits
 ContainerRecord.TrapItem=TreasureRecord.TrapItem
 ContainerRecord.Prefix1=TreasureRecord.Prefix1
 ContainerRecord.InvisibleContainer=True
 Call Write.Record(ContainerFile,VarA!)
 Call Add.Room.Container(VarA!)
ErrResume48:
 Exit Sub
ErrTrap48:
 Resume ErrResume48
End Sub

Sub Hide.Discard(Var1!,Var2,Var3)
 On Local Error Goto ErrorTrp28
 Call Read.Record(MessWorkFile6,Var1!)
 VarA!=MessWorkRecord6.Index
 VarB=MessWorkRecord6.Charges
 If VarA!>SFalse Then
    Call Read.Record(TreasureFile,VarA!)
    Weight=Weight-TreasureRecord.Weight
    If Weight<DFalse Then
       Weight=DFalse
    Endif
 Endif
 MessWorkRecord6.User=SFalse
 Call Write.Record(MessWorkFile6,Var1!)
 If Var2=False Then
    Call Hide.Inventory(VarA!,VarB,Var3)
 Else
    Var3=True
 Endif
ErrorRsm28:
 Exit Sub
ErrorTrp28:
 Resume ErrorRsm28
End Sub

Sub Hide.Inventory(Var1!,Var2,Var3)
 On Local Error Goto ErrorTrp27
 Var3=True
 VarX!=Lof(RoomInvFile)/MessWorkRecLen6+1!
 MessWorkRecord6.Room=Room
 MessWorkRecord6.User=SFalse
 MessWorkRecord6.Index=Var1!
 MessWorkRecord6.Charges=Var2
 MessWorkRecord6.Plus=Hidden.Object
 Call Write.Record(RoomInvFile,VarX!)
 Call Add.List.Node(VarX!)
ErrorRsm27:
 Exit Sub
ErrorTrp27:
 Resume ErrorRsm27
End Sub
