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

Sub Take.Object
 On Local Error Goto ErrTrap25
 Gosub Get.Config1

 ' pickup coins in room
 Var$=Lcase$(Parsed.Command1)
 If Var$="coins" 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
    For X!=1! To V!
       GET #TempFile1, X!
       If CVS(R$)=Room Then
          VarX#=CVD(G$)
          VarZ=Cvi(P1$)
          VarZ2=Cvi(P2$)
          LSET R$ = MKS$(0!)
          LSET G$ = MKD$(0#)
          LSET P1$ = MKI$(0%)
          LSET P2$ = MKI$(0%)
          PUT #TempFile1, X!
          Close #TempFile1
          VarZ#=0#
          If VarZ2=0 Then
             VarZ#=VarX#
             UserRecord.Gold=UserRecord.Gold+VarZ#
             Call Amount5(VarZ#,VarQ$)
             Strng="You pick up"+VarQ$+" Gold"
          Else
             If VarZ2=1 Then
                VarZ#=Int(VarX#/10#)
                UserRecord.Gold=UserRecord.Gold+VarZ#
                Call Amount5(VarZ#,VarQ$)
                Strng="You pick up"+VarQ$+" Silver"
             Else
                If VarZ2=2 Then
                   VarZ#=Int(VarX#/100#)
                   UserRecord.Gold=UserRecord.Gold+VarZ#
                   Call Amount5(VarZ#,VarQ$)
                   Strng="You pick up"+VarQ$+" Copper"
                Else
                   If VarZ2=3 Then
                      VarZ#=Int(VarX#/1000#)
                      UserRecord.Gold=UserRecord.Gold+VarZ#
                      Call Amount5(VarZ#,VarQ$)
                      Strng="You pick up"+VarQ$+" Bronze"
                   Endif
                Endif
             Endif
          Endif
          If VarZ#=0# Then
             Strng="You can't take that!"
             Call IO.O
             Exit Sub
          Endif
          If UserRecord.Gold+VarZ#>=Option1# Then ' check overflow
             Strng="You can't take any more!"
             Call IO.O
             Exit Sub
          Endif
          If VarZ Then
             Strng=Strng+" [inv]"
          Endif
          Strng=Strng+"!"
          Call IO.O
          Call Amount5(UserRecord.Gold,Var$)
          Strng="You now have"+Var$+" Gold!"
          Call IO.O
          Exit Sub
       Endif
    Next
 Endif

 ' pickup gold in room
 Var$=Lcase$(Parsed.Command1)
 If Var$="gold" Then
    If UserRecord.Gold>=Option2# Then ' check overflow
       Strng="You can't take any more!"
       Call IO.O
       Exit Sub
    Endif
    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$)
          VarZ=Cvi(P1$)
          LSET R$ = MKS$(0!)
          LSET G$ = MKD$(0#)
          LSET P1$ = MKI$(0%)
          LSET P2$ = MKI$(0%)
          PUT #TempFile1, X!
          Close #TempFile1
          UserRecord.Gold=UserRecord.Gold+VarX#
          Call Amount5(VarX#,VarQ$)
          Strng="You pick up"+VarQ$+" Gold"
          If VarZ Then
             Strng=Strng+" [inv]"
          Endif
          Strng=Strng+"!"
          Call IO.O
          Call Amount5(UserRecord.Gold,Var$)
          Strng="You now have"+Var$+" Gold!"
          Call IO.O
          Exit Sub
          Endif
       Endif
    Next
 Endif

 ' pickup silver in room
 Var$=Lcase$(Parsed.Command1)
 If Var$="silver" 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
    For X!=1! To V!
       GET #TempFile1, X!
       If CVS(R$)=Room Then
          If Cvi(P2$)=1 Then
             VarX#=CVD(G$)
             VarZ#=Int(VarX#/10#)
             If UserRecord.Gold+VarZ#>=Option3# Then ' check overflow
                Strng="You can't take any more!"
                Call IO.O
                Exit Sub
             Endif
             VarZ=Cvi(P1$)
             LSET R$ = MKS$(0!)
             LSET G$ = MKD$(0#)
             LSET P1$ = MKI$(0%)
             LSET P2$ = MKI$(0%)
             PUT #TempFile1, X!
             Close #TempFile1
             UserRecord.Gold=UserRecord.Gold+VarZ#
             Call Amount5(VarZ#,VarQ$)
             Strng="You pick up"+VarQ$+" Silver"
             If VarZ Then
                Strng=Strng+" [inv]"
             Endif
             Strng=Strng+"!"
             Call IO.O
             Call Amount5(UserRecord.Gold,Var$)
             Strng="You now have"+Var$+" Gold!"
             Call IO.O
             Exit Sub
          Endif
       Endif
    Next
 Endif

 ' pickup copper in room
 Var$=Lcase$(Parsed.Command1)
 If Var$="copper" 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
    For X!=1! To V!
       GET #TempFile1, X!
       If CVS(R$)=Room Then
          If Cvi(P2$)=2 Then
             VarX#=CVD(G$)
             VarZ#=Int(VarX#/100#)
             If UserRecord.Gold+VarZ#>=Option4# Then ' check overflow
                Strng="You can't take any more!"
                Call IO.O
                Exit Sub
             Endif
             VarZ=Cvi(P1$)
             LSET R$ = MKS$(0!)
             LSET G$ = MKD$(0#)
             LSET P1$ = MKI$(0%)
             LSET P2$ = MKI$(0%)
             PUT #TempFile1, X!
             Close #TempFile1
             UserRecord.Gold=UserRecord.Gold+VarZ#
             Call Amount5(VarZ#,VarQ$)
             Strng="You pick up"+VarQ$+" Copper"
             If VarZ Then
                Strng=Strng+" [inv]"
             Endif
             Strng=Strng+"!"
             Call IO.O
             Call Amount5(UserRecord.Gold,Var$)
             Strng="You now have"+Var$+" Gold!"
             Call IO.O
             Exit Sub
          Endif
       Endif
    Next
 Endif

 ' pickup bronze in room
 Var$=Lcase$(Parsed.Command1)
 If Var$="bronze" 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
    For X!=1! To V!
       GET #TempFile1, X!
       If CVS(R$)=Room Then
          If Cvi(P2$)=3 Then
             VarX#=CVD(G$)
             VarZ#=Int(VarX#/1000#)
             If UserRecord.Gold+VarZ#>=Option5# Then ' check overflow
                Strng="You can't take any more!"
                Call IO.O
                Exit Sub
             Endif
             VarZ=Cvi(P1$)
             LSET R$ = MKS$(0!)
             LSET G$ = MKD$(0#)
             LSET P1$ = MKI$(0%)
             LSET P2$ = MKI$(0%)
             PUT #TempFile1, X!
             Close #TempFile1
             UserRecord.Gold=UserRecord.Gold+VarZ#
             Call Amount5(VarZ#,VarQ$)
             Strng="You pick up"+VarQ$+" Bronze"
             If VarZ Then
                Strng=Strng+" [inv]"
             Endif
             Strng=Strng+"!"
             Call IO.O
             Call Amount5(UserRecord.Gold,Var$)
             Strng="You now have"+Var$+" Gold!"
             Call IO.O
             Exit Sub
          Endif
       Endif
    Next
 Endif

 ' set autopickup mode.
 If Lcase$(Parsed.Command1)="auto" Then
    If Parse.Temp=False Then
       If Config2(135)=False Then
          Strng="Auto pickup not allowed."
          Call IO.O
          Exit Sub
       Endif
       Auto.Pickup=Not Auto.Pickup
       If Auto.Pickup Then
          Strng="Auto pickup activated."
       Else
          Strng="Auto pickup deactivated."
       Endif
       Call IO.O
       Exit Sub
    Endif
 Endif

 ' check take all.
 If Lcase$(Parsed.Command1)="all" Then
    If Config2(136)=False Then
       Strng="Take all not allowed."
       Call IO.O
       Exit Sub
    Endif
    Call Take.All.Objects(VarQ)
    If VarQ=False Then
       Graphics.Off=False
       Strng="You take nothing!"
       Call IO.O
    Endif
    Exit Sub
 Endif

 ' check items in room.
 Call Check.Room.Items
 If Temp7!<SFalse Then
    Temp4=False
    If Normal.User=False Then
       Temp4=True
    Else
       If ObjectRecord.Permanent=False Then
          Temp4=True
       Endif
    Endif
    If Temp4 Then
       Graphics.Off=False
       Strng2=Rtrim$(ObjectRecord.Prefix1)
       Out3=Lcase$(Out3)
       Strng="You take "+Strng2+Out3
       Call Convert.ANSI(True,VarQ,VarR)
       Carriage.Return=True
       Graphics.On=True
       Call IO.O
       Strng=Nul
       If ObjectRecord.Invisible Then
          Strng=" [inv]"
       Endif
       Graphics.On=False
       Graphics.Off=True
       Strng=Strng+"!"
       Call IO.O
       Graphics.Off=False
       Call Add.Inventory(Temp7!,Temp6)
       Call Delete.List.Node(Temp5!)
       Call Clear.List.Node
       Call Write.Record(RoomInvFile,Temp5!)
       Exit Sub
    Endif
 Endif
 If Temp7!>SFalse Then
    If TreasureRecord.Vehicle Then
       Var2!=MessWorkRecord6.User
       If Var2!>SFalse And Var2!<=Lof(UserFile)/UserRecLen Then
          Call Read.Record(UserFile2,Var2!)
          Out3=UserRecord2.CodeName
          Out3=Rtrim$(Out3)
          Out3=Lcase$(Out3)
          Mid$(Out3,1,1)=UCase$(Mid$(Out3,1,1))
          Strng="It's being used by "+Out3+"."
          Call IO.O
          Exit Sub
       Endif
    Endif
    If TreasureRecord.Coin Then
       Graphics.Off=False
       Strng2=Rtrim$(TreasureRecord.Prefix1)
       Out3=Lcase$(Out3)
       Strng="You take "+Strng2+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
       Graphics.Off=False
       If TreasureRecord.Gold>0# Then
          UserRecord.Gold=UserRecord.Gold+TreasureRecord.Gold
          Call Amount5(UserRecord.Gold,Var$)
          Strng="You now have"+Var$+" Gold!"
          Call IO.O
       Endif
       Call Delete.List.Node(Temp5!)
       Call Clear.List.Node
       Call Write.Record(RoomInvFile,Temp5!)
       Exit Sub
    Endif
    If UserRecord.ClassType<Lady Then
       For Temp1!=1! To Lof(MessWorkFile3)/MessWorkRecLen3
          Call Read.Record(MessWorkFile3,Temp1!)
          If MessWorkRecord3.Room=Room Then
             If MessWorkRecord3.Monster.Prevent Then
                If Rnd<(MessWorkRecord3.Monster.PreventPercent/100) Then
                   Out2=MessWorkRecord3.Monster.MonsterName
                   Out2=Rtrim$(Out2)
                   Strng="The "+Out2+" prevents you from getting it!"
                   Call IO.O
                   Exit Sub
                Endif
             Endif
          Endif
       Next
    Endif
    If Normal.User Then
       If TreasureRecord.Permanent Then
          Strng="You can't get that!"
          Call IO.O
          Exit Sub
       Endif
    Endif
    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
    Graphics.Off=False
    Strng2=Rtrim$(TreasureRecord.Prefix1)
    Out3=Lcase$(Out3)
    Strng="You take "+Strng2+Out3
    Call Convert.ANSI(True,VarQ,VarR)
    Carriage.Return=True
    Graphics.On=True
    Call IO.O
    Strng=Nul
    If TreasureRecord.LightType Then
       If MessWorkRecord6.Charges<False Then
          Strng=" [lit]"
       Endif
    Endif
    If TreasureRecord.Invisible Then
       Strng=Strng+" [inv]"
    Endif
    Graphics.On=False
    Graphics.Off=True
    Strng=Strng+"!"
    Call IO.O
    Graphics.Off=False
    Call Add.Inventory(Temp7!,Temp6)
    Call Delete.List.Node(Temp5!)
    Call Clear.List.Node
    Call Write.Record(RoomInvFile,Temp5!)
    Exit Sub
 Endif

 ' check containers in room.
 Call Num
 Call Read.Record(RoomFile,Room)
 Call Search.Room.Containers
 If TempA! Then
    If UserRecord.Encumbrance>=False Then
       Temp1#=Cdbl(Weight+ContainerRecord.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
    If ContainerRecord.InvisibleContainer Then
       VarZZ1=-1
    Endif
    Call Delete.Room.Container(TempA!)
    Call Read.Record(ContainerFile,TempA!)
    ContainerRecord.UserNumber=User.Index
    ContainerRecord.RoomNumber=SFalse
    ContainerRecord.InvisibleContainer=False
    Call Add.User.Container(TempA!)
    Weight=Weight+ContainerRecord.Weight
    Graphics.Off=False
    Strng2=Rtrim$(ContainerRecord.Prefix1)
    Out3=Lcase$(Out3)
    Strng="You take "+Strng2+Out3
    Call Convert.ANSI(True,VarQ,VarR)
    Carriage.Return=True
    Graphics.On=True
    Call IO.O
    Strng=Nul
    If VarZZ1 Then
       Strng=" [inv]"
    Endif
    Graphics.On=False
    Graphics.Off=True
    Strng=Strng+"!"
    Call IO.O
    Graphics.Off=False
    Exit Sub
 Endif
 Strng="You can't get that!"
 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$)="[CMD124]" 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
Reset.Options:
 Option1#=Cdbl(1d300)
 Option2#=Cdbl(1d300)
 Option3#=Cdbl(1d300)
 Option4#=Cdbl(1d300)
 Option5#=Cdbl(1d300)
 Return
Next.Read:
 Close #TempFile1
 Filename$=DND.Path+"CMD124.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
Parse.Options:
 Select Case Lcase$(Var2$)
 Case "take.maximum,coins"
    If Val(Var3$)>0# Then
       Option1#=Int(Cdbl(Val(Var3$)+.5))
    Endif
 Case "take.maximum.gold"
    If Val(Var3$)>0# Then
       Option2#=Int(Cdbl(Val(Var3$)+.5))
    Endif
 Case "take.maximum.silver"
    If Val(Var3$)>0# Then
       Option3#=Int(Cdbl(Val(Var3$)+.5))
    Endif
 Case "take.maximum.copper"
    If Val(Var3$)>0# Then
       Option4#=Int(Cdbl(Val(Var3$)+.5))
    Endif
 Case "take.maximum.bronze"
    If Val(Var3$)>0# Then
       Option5#=Int(Cdbl(Val(Var3$)+.5))
    Endif
 End Select
 Return
ErrResume25:
 Exit Sub
ErrTrap25:
 Resume ErrResume25
End Sub

Sub Amount5(Var#,Var$)
 VarX$=Ltrim$(Str$(Var#)) ' 1.111D308
 V=Instr(VarX$,"D")
 If V Then
    If Mid$(VarX$,2,1)="." Then
       VarX$=Left$(VarX$,1)+Mid$(VarX$,V)
    Endif
    Var$=" "+VarX$
 Else
    Var$=" "+Form$(Var#)
 Endif
End Sub
