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

Sub Take.From.Container
 On Local Error Goto ErrTrap43
 Gosub Get.Config1

 Call Parse
 Call Numeric
 Temp2=Parse.Temp
 User.Command=Parsed.Command1
 Parsed.Command1=Parsed.Command2
 Call Numeric

 ' check take coins
 If Parsed.Command2="COINS" Then
    If User.Command="ALL" Then
       If Sysop=False Then
          If Option1=False Then
             Strng="Take all not allowed."
             Call IO.O
             Exit Sub
          Endif
          If UserRecord.Level<Option2 Then
             Strng="You are not high enough level!"
             Call IO.O
             Exit Sub
          Endif
       Endif
       VarX#=0#
       VarZ=0
       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
       For X!=1! To V!
          Get #TempFile1, X!
          If Cvs(R$)=Room Then
             VarX#=Cvd(G$)
             If UserRecord.Gold>=Option1# Then ' check overflow
                Exit For
             Endif
             VarZ=VarZ+1
             If Cvi(P2$)=0 Then
                UserRecord.Gold=UserRecord.Gold+VarX#
             Else
                If Cvi(P2$)=1 Then
                   UserRecord.Gold=UserRecord.Gold+Int(VarX#/10#)
                Else
                   If Cvi(P2$)=2 Then
                      UserRecord.Gold=UserRecord.Gold+Int(VarX#/100#)
                   Endif
                Endif
             Endif
             LSET R$ = MKS$(0!)
             LSET G$ = MKD$(0#)
             LSET P1$ = MKI$(0%)
             LSET P2$ = MKI$(0%)
             PUT #TempFile1, X!
          Endif
       Next
       Select Case VarZ
       Case 0
          Strng="You take nothing!"
       Case 1
          Strng="You take some coins!"
          Call IO.O
          Call Amount(UserRecord.Gold,Var$)
          Strng="You now have"+Var$+" Gold!"
       Case Else
          Strng="You take"+Str$(VarZ)+" piles of coins!"
          Call IO.O
          Call Amount(UserRecord.Gold,Var$)
          Strng="You now have"+Var$+" Gold!"
       End Select
       Call IO.O
       Exit Sub
    Endif
 Endif

 ' check take gold
 If Parsed.Command2="GOLD" Then
    If User.Command="ALL" Then
       If Sysop=False Then
          If Option1x=False Then
             Strng="Take all not allowed."
             Call IO.O
             Exit Sub
          Endif
          If UserRecord.Level<Option2x Then
             Strng="You are not high enough level!"
             Call IO.O
             Exit Sub
          Endif
       Endif
       VarX#=0#
       VarZ=0
       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
       For X!=1! To V!
          Get #TempFile1, X!
          If Cvs(R$)=Room Then
             If Cvi(P2$)=0 Then
             VarX#=Cvd(G$)
             If UserRecord.Gold>=Option2# Then ' check overflow
                Exit For
             Endif
             VarZ=VarZ+1
             UserRecord.Gold=UserRecord.Gold+VarX#
             LSET R$ = MKS$(0!)
             LSET G$ = MKD$(0#)
             LSET P1$ = MKI$(0%)
             LSET P2$ = MKI$(0%)
             PUT #TempFile1, X!
             Endif
          Endif
       Next
       Select Case VarZ
       Case 0
          Strng="You take nothing!"
       Case 1
          Strng="You take some gold!"
          Call IO.O
          Call Amount(UserRecord.Gold,Var$)
          Strng="You now have"+Var$+" Gold!"
       Case Else
          Strng="You take"+Str$(VarZ)+" piles of gold!"
          Call IO.O
          Call Amount(UserRecord.Gold,Var$)
          Strng="You now have"+Var$+" Gold!"
       End Select
       Call IO.O
       Exit Sub
    Endif
 Endif

 ' check take silver
 If Parsed.Command2="SILVER" Then
    If User.Command="ALL" Then
       If Sysop=False Then
          If Option1y=False Then
             Strng="Take all not allowed."
             Call IO.O
             Exit Sub
          Endif
          If UserRecord.Level<Option2y Then
             Strng="You are not high enough level!"
             Call IO.O
             Exit Sub
          Endif
       Endif
       VarX#=0#
       VarZ=0
       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
       For X!=1! To V!
          Get #TempFile1, X!
          If Cvs(R$)=Room Then
             If Cvi(P2$)=1 Then
             VarX#=Cvd(G$)
             If UserRecord.Gold>=Option3# Then ' check overflow
                Exit For
             Endif
             VarZ=VarZ+1
             UserRecord.Gold=UserRecord.Gold+Int(VarX#/10#)
             LSET R$ = MKS$(0!)
             LSET G$ = MKD$(0#)
             LSET P1$ = MKI$(0%)
             LSET P2$ = MKI$(0%)
             PUT #TempFile1, X!
             Endif
          Endif
       Next
       Select Case VarZ
       Case 0
          Strng="You take nothing!"
       Case 1
          Strng="You take some silver!"
          Call IO.O
          Call Amount(UserRecord.Gold,Var$)
          Strng="You now have"+Var$+" Gold!"
       Case Else
          Strng="You take"+Str$(VarZ)+" piles of silver!"
          Call IO.O
          Call Amount(UserRecord.Gold,Var$)
          Strng="You now have"+Var$+" Gold!"
       End Select
       Call IO.O
       Exit Sub
    Endif
 Endif

 ' check take copper
 If Parsed.Command2="COPPER" Then
    If User.Command="ALL" Then
       If Sysop=False Then
          If Option1z=False Then
             Strng="Take all not allowed."
             Call IO.O
             Exit Sub
          Endif
          If UserRecord.Level<Option2z Then
             Strng="You are not high enough level!"
             Call IO.O
             Exit Sub
          Endif
       Endif
       VarX#=0#
       VarZ=0
       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
       For X!=1! To V!
          Get #TempFile1, X!
          If Cvs(R$)=Room Then
             If Cvi(P2$)=2 Then
             VarX#=Cvd(G$)
             If UserRecord.Gold>=Option4# Then ' check overflow
                Exit For
             Endif
             VarZ=VarZ+1
             UserRecord.Gold=UserRecord.Gold+Int(VarX#/100#)
             LSET R$ = MKS$(0!)
             LSET G$ = MKD$(0#)
             LSET P1$ = MKI$(0%)
             LSET P2$ = MKI$(0%)
             PUT #TempFile1, X!
             Endif
          Endif
       Next
       Select Case VarZ
       Case 0
          Strng="You take nothing!"
       Case 1
          Strng="You take some copper!"
          Call IO.O
          Call Amount(UserRecord.Gold,Var$)
          Strng="You now have"+Var$+" Gold!"
       Case Else
          Strng="You take"+Str$(VarZ)+" piles of copper!"
          Call IO.O
          Call Amount(UserRecord.Gold,Var$)
          Strng="You now have"+Var$+" Gold!"
       End Select
       Call IO.O
       Exit Sub
    Endif
 Endif

 Call Examine.Containers
 If ContainerRecord.InvisibleContainer Then
    VarZZ=-1
 Endif
 Var2$=ContainerRecord.ContainerName
 Var2$=Rtrim$(Var2$)
 Var2$=Lcase$(Var2$)
 Var3$=Rtrim$(ContainerRecord.Prefix1)
 VarZ$=ContainerRecord.ContainerShort
 VarZ$=Rtrim$(VarZ$)
 VarZ$=Lcase$(VarZ$)
 Parsed.Command1=User.Command
 Parse.Temp=Temp2
 VarQ=False
 If Lcase$(Parsed.Command1)="all" Then
    If Config2(136)=False Then
       Strng="Take all not allowed."
       Call IO.O
       Exit Sub
    Endif
    VarQ=True
 Endif
 If TempA!=SFalse Then
    Strng="You can't take that from 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
 VarQ2=ContainerRecord.TrapType
 VarQ3=ContainerRecord.TrapHits
 VarQ4!=ContainerRecord.TrapItem
 If VarQ Then
    If Sysop=False Then
       If Option3=False And Option5=False Then
          Strng="Take all not allowed."
          Call IO.O
          Exit Sub
       Endif
       If UserRecord.Level<Option4 And UserRecord.Level<Option6 Then
          Strng="You are not high enough level!"
          Call IO.O
          Exit Sub
       Endif
    Endif
    TempX=False
    If Sysop=False Then
       if option3 and userrecord.level>=option4 then
          Call Take.All.From.Container(Var2$)
       endif
    else
       Call Take.All.From.Container(Var2$)
    endif
    If Sysop=False Then
       if option5 and userrecord.level>=option6 then
          Call Take.All.Containers.From.Container(Var2$)
       endif
    else
       Call Take.All.Containers.From.Container(Var2$)
    endif
    if tempx=0 then
       If Sysop=False Then
          if option3=0 or option5=0 then
             strng = "Take all not allowed!"
             call io.o
             exit sub
          endif
       endif
       If Sysop=False Then
          if userrecord.level<option4 or userrecord.level<option6 then
             strng = "You are not high enough level!"
             call io.o
             exit sub
          endif
       endif
       Strng="You take nothing!"
       Call IO.O
    else
       Call ContainerTraps(VarQ2,VarQ3,VarQ4!,VarZ$)
    Endif
    Exit Sub
 Endif
 Call Search.In.Container
 If TempB! Then
    If ContainerRecord.InvisibleContainer Then
       VarZZ2=-1
    Endif
    VarX$=Lcase$(Out3)
    Call Take.Within.Container
    Graphics.Off=False
    Var5$=Rtrim$(ContainerRecord.Prefix1)
    Strng="You take "+Var5$+Out3
    Call Convert.ANSI(True,VarQ,VarR)
    Carriage.Return=True
    Graphics.On=True
    Call IO.O

    Graphics.On=False
    Graphics.Off=True
    Strng=Nul
    If VarZZ2 Then
       Strng=" [inv]"
    Endif
    Strng=Strng+" from "
    Carriage.Return=True
    Call IO.O

    Graphics.Off=False
    Strng=Var3$+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
    Graphics.Off=False

    Call ContainerTraps(VarQ2,VarQ3,VarQ4!,VarZ$)
    Exit Sub
 Endif
 Call Find.In.Container
 If Temp7!=SFalse Then
    Strng="You can't take that!"
    Call IO.O
    Exit Sub
 Endif
 VarC=False
 If MessWorkRecord6.Plus Then
    VarZZ3=-1
 Endif
 If Temp6<False Then
    VarZZ4=-1
 Endif
 If Temp7!>SFalse Then
    Var5$=Rtrim$(TreasureRecord.Prefix1)
    If TreasureRecord.Invisible Then
       VarZZ3=-1
    Endif
    If TreasureRecord.Coin Then
       VarC=True
    Else
       If UserRecord.Encumbrance>=False Then
          Temp1#=Cdbl(Weight+TreasureRecord.Weight)
          Temp2#=Cdbl(UserRecord.Stats(1))*Cdbl(UserRecord.Encumbrance)
          If Temp1#>Temp2# Then
             Strng="You can't carry any more!"
             Call IO.O
             Exit Sub
          Endif
       Endif
    Endif
 Endif
 If Temp7!<SFalse Then
    Var5$=Rtrim$(ObjectRecord.Prefix1)
    If ObjectRecord.Invisible Then
       VarZZ3=-1
    Endif
 Endif
 If VarC=False Then
    Call Add.Inventory(Temp7!,Temp6)
 Endif
 Call Delete.List.Node5(Temp5!)
 Call Clear.List.Node
 Call Write.Record(CtnInvFile,Temp5!)
 Out3=Lcase$(Out3)

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

 Graphics.On=False
 Graphics.Off=True
 Strng=Nul
 If VarZZ4 Then
    Strng=" [lit]"
 Endif
 If VarZZ3 Then
    Strng=Strng+" [inv]"
 Endif
 Strng=Strng+" from "
 Carriage.Return=True
 Call IO.O

 Graphics.Off=False
 Strng=Var3$+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
 Graphics.Off=False

 If VarC Then
    UserRecord.Gold=UserRecord.Gold+TreasureRecord.Gold
    Call Amount(UserRecord.Gold,Var$)
    Strng="You now have"+Var$+" Gold!"
    Call IO.O
    Exit Sub
 Endif

 Call ContainerTraps(VarQ2,VarQ3,VarQ4!,VarZ$)
 Exit Sub

Get.Config1:
 Option1#=Cdbl(1d300)
 Option2#=Cdbl(1d300)
 Option3#=Cdbl(1d300)
 Option4#=Cdbl(1d300)

 Option1=-1
 Option2=1

 Option1x=-1
 Option2x=1

 Option1y=-1
 Option2y=1

 Option1z=-1
 Option2z=1

 Option3=-1
 Option4=1
 Option5=-1
 Option6=1
 VarX=0
 Do
    VarX=VarX+1
    If VarX>Options.Lines Then
       Exit Do
    Endif
    Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
    If Ucase$(Var$)="[CMD125]" 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 "take.all.maximum.coins"
                If Val(Var3$)>0# Then
                   Option1#=Int(Cdbl(Val(Var3$)))
                Endif
             Case "take.all.maximum.gold"
                If Val(Var3$)>0# Then
                   Option2#=Int(Cdbl(Val(Var3$)))
                Endif
             Case "take.all.maximum.silver"
                If Val(Var3$)>0# Then
                   Option3#=Int(Cdbl(Val(Var3$)))
                Endif
             Case "take.all.maximum.copper"
                If Val(Var3$)>0# Then
                   Option4#=Int(Cdbl(Val(Var3$)))
                Endif

             Case "take.all.coins"
                Select Case Lcase$(Var3$)
                Case "0", "false", "off"
                   Option1=0
                End Select
             Case "take.all.coins.level"
                Option2=Int(Val(Var3$))

             Case "take.all.gold"
                Select Case Lcase$(Var3$)
                Case "0", "false", "off"
                   Option1x=0
                End Select
             Case "take.all.gold.level"
                Option2x=Int(Val(Var3$))

             Case "take.all.silver"
                Select Case Lcase$(Var3$)
                Case "0", "false", "off"
                   Option1y=0
                End Select
             Case "take.all.silver.level"
                Option2y=Int(Val(Var3$))

             Case "take.all.copper"
                Select Case Lcase$(Var3$)
                Case "0", "false", "off"
                   Option1z=0
                End Select
             Case "take.all.copper.level"
                Option2z=Int(Val(Var3$))

             Case "take.all.container"
                Select Case Lcase$(Var3$)
                Case "0", "false", "off"
                   Option3=0
                End Select
             Case "take.all.container.level"
                Option4=Int(Val(Var3$))
             Case "take.all.container.from.container"
                Select Case Lcase$(Var3$)
                Case "0", "false", "off"
                   Option5=0
                End Select
             Case "take.all.container.from.container.level"
                Option6=Int(Val(Var3$))
             End Select
          Endif
       Loop
    Endif
 Loop
 Return
ErrResume43:
 Exit Sub
ErrTrap43:
 If Err=6 Then
    Strng="Overflow."
    Call IO.O
 Endif
 Resume ErrResume43
End Sub
