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

Sub Drop.Into.Container
 On Local Error Goto ErrTrap39
 Gosub Get.Config1

 ' determine drop/hide
 VarX=TempX
 If VarX Then
    Var3$=" hide "
 Else
    Var3$=" drop "
 Endif

 ' store parameters
 Call Parse
 Call Numeric
 Temp2=Parse.Temp
 User.Command=Parsed.Command1
 Parsed.Command1=Parsed.Command2
 Call Numeric
 Temp3=Parse.Temp
 Parsed.Command2=Parsed.Command1
 Parsed.Command1=User.Command
 Parse.Temp=Temp2

 ' put out item
 If Temp.Command="PUT" Then
    If Parsed.Command1="OUT" Then
       Parsed.Command1=Parsed.Command2 ' <item>
       Call Check.User.Items
       If Temp7!<=SFalse Then
          Strng="You can't put that out!"
          Call IO.O
          Exit Sub
       Endif
       If TreasureRecord.LightType=False Then
          Strng="You can't put that out!"
          Call IO.O
          Exit Sub
       Endif
       If Temp6>=False Then
          Strng="You can't, it's not lit!"
          Call IO.O
          Exit Sub
       Endif
       MessWorkRecord6.Charges=Abs(Temp6)
       Call Write.Record(MessWorkFile6,Temp5!)
       Out2=Rtrim$(TreasureRecord.Prefix1)
       Out3=Lcase$(Rtrim$(TreasureRecord.ShortName))
       Strng="You put out the "+Out2+Out3
       Call Convert.ANSI(True,VarQ,VarR)
       Carriage.Return=True
       Graphics.On=True
       Call IO.O
       Graphics.On=False
       Graphics.Off=True
       Strng="!"
       Call IO.O
       Exit Sub
    Endif
 Endif

 ' drop all gold/drop <value> gold
 If Parsed.Command2="COINS" Or Parsed.Command2="GOLD" Then
    If Parsed.Command1="ALL" Then
       If Sysop=False Then
          If VarX=0 Then
             If Option1=False Then
                Strng="Drop all not allowed."
                Call IO.O
                Exit Sub
             Endif
             If UserRecord.Level<Option3 Then
                Strng="You are not high enough level!"
                Call IO.O
                Exit Sub
             Endif
          Endif
          If VarX=-1 Then
             If Option2=False Then
                Strng="Hide all not allowed."
                Call IO.O
                Exit Sub
             Endif
             If UserRecord.Level<Option4 Then
                Strng="You are not high enough level!"
                Call IO.O
                Exit Sub
             Endif
          Endif
       Endif
       VarX#=UserRecord.Gold
    Else
       VarX#=Int(Val(Parsed.Command1)+.5)
    Endif
    If VarX#>DFalse Then
       If VarX#<=UserRecord.Gold Then
          If VarX=0 Then
             VarZ#=Option1#
          Else
             VarZ#=Option2#
          Endif
          If VarX#<=VarZ# 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$(VarX)
             LSET P2$ = MKI$(0%)
             PUT #TempFile1, V!
             UserRecord.Gold=UserRecord.Gold-VarX#
             Call Amount(VarX#,VarQ$)
             Strng="You"+Var3$+Ltrim$(VarQ$)+" gold!"
             Call IO.O
             Exit Sub
          Else
             Strng="You can't"+Var3$+"that much gold!"
             Call IO.O
             Exit Sub
          Endif
       Else
          Strng="You don't have that much gold!"
          Call IO.O
          Exit Sub
       Endif
    Else
       Strng="You don't have enough gold!"
       Call IO.O
       Exit Sub
    Endif
 Endif

 ' drop <value> <cointype>
 If Parsed.Command2="SILVER" Then
    VarX#=Int(Val(Parsed.Command1)+.5)
    If VarX#>DFalse Then
       If VarX#<10# Then
          Strng="You can't drop that much silver!"
          Call IO.O
          Exit Sub
       Endif
       If VarX# Mod 10# Then ' silver divisor
          Strng="You can only drop silver in multiples of 10.."
          Call IO.O
          Exit Sub
       Endif
       If Int(VarX#/10#)<=UserRecord.Gold Then
          If VarX=0 Then
             VarZ#=Option3#
          Else
             VarZ#=Option4#
          Endif
          If Int(VarX#/10#)<=VarZ# 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$(VarX)
             LSET P2$ = MKI$(1%) ' silver
             PUT #TempFile1, V!
             UserRecord.Gold=UserRecord.Gold-Int(VarX#/10#)
             Call Amount(VarX#,VarQ$)
             Strng="You"+Var3$+Ltrim$(VarQ$)+" silver!"
             Call IO.O
             Exit Sub
          Else
             Strng="You can't"+Var3$+"that much silver!"
             Call IO.O
             Exit Sub
          Endif
       Else
          Strng="You don't have that much silver!"
          Call IO.O
          Exit Sub
       Endif
    Else
       Strng="You don't have enough silver!"
       Call IO.O
       Exit Sub
    Endif
 Endif

 ' drop <value> <cointype>
 If Parsed.Command2="COPPER" Then
    VarX#=Int(Val(Parsed.Command1)+.5)
    If VarX#>DFalse Then
       If VarX#<100# Then
          Strng="You can't drop that much copper!"
          Call IO.O
          Exit Sub
       Endif
       If VarX# Mod 100# Then ' copper divisor
          Strng="You can only drop copper in multiples of 100.."
          Call IO.O
          Exit Sub
       Endif
       If Int(VarX#/100#)<=UserRecord.Gold Then
          If VarX=0 Then
             VarZ#=Option5#
          Else
             VarZ#=Option6#
          Endif
          If Int(VarX#/100#)<=VarZ# 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$(VarX)
             LSET P2$ = MKI$(2%) ' copper
             PUT #TempFile1, V!
             UserRecord.Gold=UserRecord.Gold-Int(VarX#/100#)
             Call Amount(VarX#,VarQ$)
             Strng="You"+Var3$+Ltrim$(VarQ$)+" copper!"
             Call IO.O
             Exit Sub
          Else
             Strng="You can't"+Var3$+"that much copper!"
             Call IO.O
             Exit Sub
          Endif
       Else
          Strng="You don't have that much copper!"
          Call IO.O
          Exit Sub
       Endif
    Else
       Strng="You don't have enough copper!"
       Call IO.O
       Exit Sub
    Endif
 Endif

 ' drop <value> <cointype>
 If Parsed.Command2="BRONZE" Then
    VarX#=Int(Val(Parsed.Command1)+.5)
    If VarX#>DFalse Then
       If VarX#<1000# Then
          Strng="You can't drop that much bronze!"
          Call IO.O
          Exit Sub
       Endif
       If VarX# Mod 1000# Then ' bronze divisor
          Strng="You can only drop bronze in multiples of 1000.."
          Call IO.O
          Exit Sub
       Endif
       If Int(VarX#/1000#)<=UserRecord.Gold Then
          If VarX=0 Then
             VarZ#=Option7#
          Else
             VarZ#=Option8#
          Endif
          If Int(VarX#/1000#)<=VarZ# 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$(VarX)
             LSET P2$ = MKI$(3%) ' bronze
             PUT #TempFile1, V!
             UserRecord.Gold=UserRecord.Gold-Int(VarX#/1000#)
             Call Amount(VarX#,VarQ$)
             Strng="You"+Var3$+Ltrim$(VarQ$)+" bronze!"
             Call IO.O
             Exit Sub
          Else
             Strng="You can't"+Var3$+"that much bronze!"
             Call IO.O
             Exit Sub
          Endif
       Else
          Strng="You don't have that much bronze!"
          Call IO.O
          Exit Sub
       Endif
    Else
       Strng="You don't have enough bronze!"
       Call IO.O
       Exit Sub
    Endif
 Endif

 ' check for drop all
 VarQ=False
 If Parsed.Command1="ALL" Then
    If Config2(136)=False Then
       Strng="Drop all not allowed."
       Call IO.O
       Exit Sub
    Endif
    VarQ=True
 Endif

 ' drop container into container
 VarZZ1$=Parsed.Command1
 VarZZ2$=Parsed.Command2
 If VarQ=False Then
    Parse.Temp=Temp2
    Call Search.User.Containers
    If TempA! Then
       TempZ!=TempA!

       ' check destination container
       User.Command=VarZZ1$
       Parsed.Command1=VarZZ2$
       Parse.Temp=Temp3
       Call Examine.Containers
       If TempA!=SFalse Then
          Strng="Can't drop container into item!"
          Call IO.O
          Exit Sub
       Endif

       ' check imploding container
       VarQ2=ContainerRecord.TrapType
       VarQ3=ContainerRecord.TrapHits
       VarQ4!=ContainerRecord.TrapItem
       VarZ3$=Rtrim$(Lcase$(ContainerRecord.ContainerShort))
       Call ContainerTraps(VarQ2,VarQ3,VarQ4!,VarZ3$)
       If VarQ2=-1 Then ' *boom*
          Exit Sub
       Endif

       ' drop container into container
       TempA!=TempZ!
       User.Command=VarZZ1$
       Parsed.Command1=VarZZ2$
       Parse.Temp=Temp3
       Call Read.Record(ContainerFile,TempA!)
       Call Drop.Container.In.Container(VarX)
       Exit Sub
    Endif
 Endif

 ' drop an item into a container
 Parse.Temp=Temp3
 User.Command=Parsed.Command1
 Parsed.Command1=Parsed.Command2
 Call Examine.Containers
 If ContainerRecord.InvisibleContainer Then
    VarZZ=-1
 Endif
 Var2$=Rtrim$(Lcase$(ContainerRecord.ContainerName))
 VarZ2$=Rtrim$(ContainerRecord.Prefix1)

 ' check imploding container
 VarQ2=ContainerRecord.TrapType
 VarQ3=ContainerRecord.TrapHits
 VarQ4!=ContainerRecord.TrapItem
 VarZ3$=Rtrim$(Lcase$(ContainerRecord.ContainerShort))
 Call ContainerTraps(VarQ2,VarQ3,VarQ4!,VarZ3$)
 If VarQ2=-1 Then ' *boom*
    Exit Sub
 Endif

 Var4$=Ltrim$(Rtrim$(ContainerRecord.NamePrefix))
 If Var4$=Nul Then
    Var4$=" in "
 Else
    If Instr(Var4$," ") Then
       Var4$=Left$(Var4$,Instr(Var4$," ")-1)
    Endif
    Var4$=" "+Var4$+" "
 Endif

 Parsed.Command1=User.Command
 If TempA!=SFalse Then
    Strng="You can't"+Var3$+"that there!"
    Call Io.O
    Exit Sub
 Endif
 If ContainerRecord.Damaged=True Then
    Strng="You can't, it's damaged."
    Call IO.O
    Exit Sub
 Endif
 If ContainerRecord.Locked=True Then
    Strng="You can't, it's locked."
    Call IO.O
    Exit Sub
 Endif
 If ContainerRecord.Locked=1 Then
    If ContainerRecord.Closed Then
       Strng="You can't, it's closed."
       Call IO.O
       Exit Sub
    Endif
 Endif
 Parse.Temp=Temp2
 If VarQ Then
    For VarZ=1 To 3
       If ContainerRecord.RestrictItem(VarZ) Then
          Strng="The container is restricted to items of treasure only."
          Call IO.O
          Exit Sub
       Endif
    Next
    Call Drop.All.Into.Container(Var2$,Var3$,Var4$,VarX)
    Exit Sub
 Endif
 Call Check.User.Items
 If Temp7!=SFalse Then
    Strng="You can't"+Var3$+"that!"
    Call IO.O
    Exit Sub
 Endif
 If Temp7!>SFalse Then
    Var1$=TreasureRecord.TreasureName
    VarZ1$=Rtrim$(TreasureRecord.Prefix1)
    If TreasureRecord.Invisible Then
       VarZZ2=-1
    Endif
    If TreasureRecord.LightType Then
       If Temp6<False Then
          VarZZ4=-1
       Endif
    Endif
 Endif
 If Temp7!<SFalse Then
    Var1$=ObjectRecord.ObjectName
    VarZ1$=Rtrim$(ObjectRecord.Prefix1)
    If ObjectRecord.Invisible Then
       VarZZ2=-1
    Endif
 Endif
 VarZ1=False
 VarZ2=False
 For VarZ=1 To 3
    If ContainerRecord.RestrictItem(VarZ) Then
       VarZ1=True
       VarZ2=VarZ2+1
    Endif
 Next
 If VarZ1 Then
    VarZ1=False
    For VarZ=1 To 3
       If ContainerRecord.RestrictItem(VarZ)=Temp7! Then
          VarZ1=True
       Endif
    Next
    If VarZ1=False Then
       Strng="You can't"+Var3$+"that!"
       Call IO.O
       Strng="The container is restricted to certain items."
       Call IO.O
       Exit Sub
    Endif
 Endif
 Var1$=Rtrim$(Var1$)
 Var1$=Lcase$(Var1$)

 ' count max restrict size
 IF VarZ1 Then
    Max!=Csng(ContainerRecord.ContainerMax)
    Max!=Max!*VarZ2
 Else
    Max!=Csng(ContainerRecord.ContainerMax)
 Endif

 ' check container size
 If Max!<0! Then ' unlimited
    Eat$=Nul
 Else
    If Max!=SFalse Then
       Strng="You can't put anything in there!"
       Call IO.O
       Exit Sub
    Endif
    Call Count.Container.Items
    If TempB!>=Max! Then
       Strng="You can't, it's full!"
       Call IO.O
       Exit Sub
    Endif
 Endif

 ' remove the item from user
 Call Discard(Temp5!,True)

 ' add item to container inventory
 Temp3!=Lof(CtnInvFile)/MessWorkRecLen6+1!
 MessWorkRecord6.Room=SFalse
 MessWorkRecord6.User=Temp7!
 MessWorkRecord6.Index=TempA!
 MessWorkRecord6.Charges=Temp6
 MessWorkRecord6.Plus=VarX
 Call Add.List.Node5(Temp3!)

 ' display what was dropped into container
 '  Var3$="hide/drop"
 '  Var1$=inventory name
 '  Var4$=" in "/" on "
 '  Var2$=containername
 '  VarZ1$=inventory prefix
 '  VarZ2$=container prefix
 '  VarZZ=invisible container
 '  VarZZ2=invisible item
 '  VarZZ4=lit treasure

 Graphics.Off=False
 Strng="You"+Var3$+VarZ1$+Var1$
 Call Convert.ANSI(True,VarQ,VarR)
 Carriage.Return=True
 Graphics.On=True
 Call IO.O

 Graphics.On=False
 Graphics.Off=True
 If VarZZ4 Then
    Strng=" [lit]"
    Carriage.Return=True
    Call IO.O
 Endif
 If VarZZ2 Then
    Strng=" [inv]"
    Carriage.Return=True
    Call IO.O
 Endif
 Strng=Var4$
 Carriage.Return=True
 Call IO.O

 Graphics.Off=False
 Strng=VarZ2$+Var2$
 Call Convert.ANSI(True,VarQ,VarR)
 Carriage.Return=True
 Graphics.On=True
 Call IO.O

 Graphics.On=False
 Graphics.Off=True
 Strng=Nul
 If VarZZ Then
   Strng=" [inv]"
 Endif
 Strng=Strng+"!"
 Call IO.O
 Exit Sub

Get.Config1:
 Gosub Reset.Options
 VarX=0
 Do
    VarX=VarX+1
    If VarX>Options.Lines Then
       Goto Next.Read
       Exit Do
    Endif
    Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
    If Ucase$(Var$)="[CMD063]" Then
       Do
          VarX=VarX+1
          If VarX>Options.Lines Then
             Goto Next.Read
             Return
          Endif
          Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
          If Ucase$(Var$)="[END]" Then
             Goto Next.Read
             Return
          Endif
          Var=Instr(Var$,"=")
          If Var Then
             Var2$=Ltrim$(Rtrim$(Left$(Var$,Var-1)))
             Var3$=Ltrim$(Rtrim$(Mid$(Var$,Var+1)))
             Gosub Parse.Options
          Endif
       Loop
    Endif
 Loop
 Return
Next.Read:
 Close #TempFile1
 Filename$=DND.Path+"CMD063.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.Options
          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.Options
             Endif
          Loop
       Endif
    Endif
 Loop
 Return
Reset.Options:
 Option1#=1D100
 Option2#=1D100
 Option3#=1D100
 Option4#=1D100
 Option5#=1D100
 Option6#=1D100
 Option7#=1D100
 Option8#=1D100
 Option1=-1
 Option2=-1
 Option3=1
 Option4=1
 Return
Parse.Options:
 Select Case Lcase$(Var2$)
 Case "drop.gold.maximum"
    Option1#=Int(Val(Var3$)+.5)
 Case "drop.silver.maximum"
    Option3#=Int(Val(Var3$)+.5)
 Case "drop.copper.maximum"
    Option5#=Int(Val(Var3$)+.5)
 Case "drop.bronze.maximum"
    Option7#=Int(Val(Var3$)+.5)
 Case "drop.all.gold"
    Select Case Lcase$(Var3$)
    Case "0", "false", "off"
       Option1=0
    End Select
 Case "drop.all.gold.level"
    Option3=Int(Val(Var3$)+.5)
 Case "hide.gold.maximum"
    Option2#=Int(Val(Var3$)+.5)
 Case "hide.silver.maximum"
    Option4#=Int(Val(Var3$)+.5)
 Case "hide.copper.maximum"
    Option6#=Int(Val(Var3$)+.5)
 Case "hide.bronze.maximum"
    Option8#=Int(Val(Var3$)+.5)
 Case "hide.all.gold"
    Select Case Lcase$(Var3$)
    Case "0", "false", "off"
       Option2=0
    End Select
 Case "hide.all.gold.level"
    Option4=Int(Val(Var3$)+.5)
 End Select
 Return
ErrResume39:
 Exit Sub
ErrTrap39:
 Resume ErrResume39
End Sub
