 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
    If UserRecord.Gold>=Option1# 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
          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
          If VarZ2=0 Then
             UserRecord.Gold=UserRecord.Gold+VarX#
             Call Amount(VarX#,VarQ$)
             Strng="You pick up"+VarQ$+" Gold"
          Else
             If VarZ2=1 Then
                UserRecord.Gold=UserRecord.Gold+Int(VarX#/10#)
                Call Amount(VarX#,VarQ$)
                Strng="You pick up"+VarQ$+" Silver"
             Else
                If VarZ2=2 Then
                   UserRecord.Gold=UserRecord.Gold+Int(VarX#/100#)
                   Call Amount(VarX#,VarQ$)
                   Strng="You pick up"+VarQ$+" Copper"
                Endif
             Endif
          Endif
          If VarZ Then
             Strng=Strng+" [inv]"
          Endif
          Strng=Strng+"!"
          Call IO.O
          Call Amount(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 Amount(VarX#,VarQ$)
          Strng="You pick up"+VarQ$+" Gold"
          If VarZ Then
             Strng=Strng+" [inv]"
          Endif
          Strng=Strng+"!"
          Call IO.O
          Call Amount(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
    If UserRecord.Gold>=Option3# 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$)=1 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+Int(VarX#/10#)
          Call Amount(VarX#,VarQ$)
          Strng="You pick up"+VarQ$+" Silver"
          If VarZ Then
             Strng=Strng+" [inv]"
          Endif
          Strng=Strng+"!"
          Call IO.O
          Call Amount(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
    If UserRecord.Gold>=Option4# 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$)=2 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+Int(VarX#/100#)
          Call Amount(VarX#,VarQ$)
          Strng="You pick up"+VarQ$+" Copper"
          If VarZ Then
             Strng=Strng+" [inv]"
          Endif
          Strng=Strng+"!"
          Call IO.O
          Call Amount(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 Amount(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:
 Option1#=Cdbl(1d300)
 Option2#=Cdbl(1d300)
 Option3#=Cdbl(1d300)
 Option4#=Cdbl(1d300)
 VarX=0
 Do
    VarX=VarX+1
    If VarX>Options.Lines Then
       Exit Do
    Endif
    Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
    If Ucase$(Var$)="[CMD124]" 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.maximum,coins"
                If Val(Var3$)>0# Then
                   Option1#=Int(Cdbl(Val(Var3$)))
                Endif
             Case "take.maximum.gold"
                If Val(Var3$)>0# Then
                   Option2#=Int(Cdbl(Val(Var3$)))
                Endif
             Case "take.maximum.silver"
                If Val(Var3$)>0# Then
                   Option3#=Int(Cdbl(Val(Var3$)))
                Endif
             Case "take.maximum.copper"
                If Val(Var3$)>0# Then
                   Option4#=Int(Cdbl(Val(Var3$)))
                Endif
             End Select
          Endif
       Loop
    Endif
 Loop
 Return
ErrResume25:
 Exit Sub
ErrTrap25:
 Resume ErrResume25
End Sub
