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

Sub Pawn.Shop
 On Local Error Goto Err.Trap21
 Gosub Get.Config
 TempA=True
 If Config2(50)=False Then
    Call In.Room(13)
 Endif
 If TempA=False Then
    Strng="Find the Pawn Shoppe!"
    Call IO.O
    If Sysop Or Local.Mode Then
       Strng="Pawn shoppe: "+Rtrim$(Room.Array(13))
       Call IO.O
    Endif
    Exit Sub
 Endif
 Temp9=False
 Call Parse
 If Parser Then
    Call Numeric
 Endif
 ' sell statistic point
 VarX1$=Ucase$(Rtrim$(Parsed.Command1))
 If Len(VarX1$) Then
    For VarX=1 To MaxStats
       VarX2$=Rtrim$(Stat(VarX))
       If Len(VarX2$) Then
          VarX2$=Ucase$(VarX2$)
          If VarX1$=VarX2$ Then
             If Option1 Then
                If Option2#>0# Then
                   Strng="The Broker says:"
                   Call IO.O
                   If UserRecord.Stats(VarX)>0 Then
                      Strng="Do You want to sell a "+Lcase$(VarX2$)+" point(y/n)?"
                      Call IO.I
                      If Yes Then
                         Strng="You sell one "+Lcase$(VarX2$)+" point!"
                         Call IO.O
                         UserRecord.Stats(VarX)=UserRecord.Stats(VarX)-1
                         UserRecord.Gold=UserRecord.Gold+Option2#
                         Call Write.Record(UserFile,User.Index)
                         Call Amount2(UserRecord.Gold,Var$)
                         Strng="You now have"+Var$+" Gold!"
                         Call IO.O
                      Endif
                   Else
                      Strng="You can't sell that many points!"
                      Call IO.O
                   Endif
                   Exit Sub
                Endif
             Endif
          Endif
       Endif
    Next
 Endif
 Call Check.User.Items
 If Temp7!=SFalse Then
    Call Num
    Call Search.User.Containers
    If TempA! Then
       Call Sell.Container
       Exit Sub
    Endif
    Strng="The Broker says: You can't sell that!"
    Call IO.O
    Exit Sub
 Endif
 If Temp7!<SFalse Then
    Strng="The Broker says: I'll take it for free! Okay(y/n)?"
    No.Input.Out="y"
    Call IO.I
    If No Then
       If Rnd>.5 Then
          Strng="The Broker says: Oh well!"
       Else
          Strng="The Broker says: Ok then!"
       Endif
       Call IO.O
       Exit Sub
    Endif
    Strng="The Broker says: Thanks!"
    Call IO.O
    Call Read.Record(MessWorkFile6,Temp5!)
    MessWorkRecord6.User=SFalse
    Call Write.Record(MessWorkFile6,Temp5!)
    Exit Sub
 Endif
 Out3=TreasureRecord.ShortName
 Out3=Rtrim$(Out3)
 Out3=Lcase$(Out3)
 Temp#=Int(TreasureRecord.Gold*Config1(19))
 If (TreasureRecord.Edible And 4)=4 Then
    If MessWorkRecord6.Charges=False Then
       Temp#=1#
       Out3="used "+Out3
    Endif
 Else
    If TreasureRecord.Spell Then
       If MessWorkRecord6.Charges=False Then
          Temp#=1#
          Out3="discharged "+Out3
       Endif
    Else
       If TreasureRecord.Loadable=False Then
          If TreasureRecord.Launchable=False Then
             If TreasureRecord.Plus Then
                If MessWorkRecord6.Charges=False Then
                   Temp#=1#
                   Out3="broken "+Out3
                Endif
             Endif
          Endif
       Endif
    Endif
 Endif
 If Rnd>.5 Then
    If Temp#>10# Then
       Temp2#=Int(Temp#/10#)
       Temp#=Temp#-Int(Rnd*Temp2#+1#)
    Else
       Temp#=Temp#-1#
    Endif
 Endif
 If Temp#=0# Then
    Temp#=1#
 Endif
 Graphics.Off=True
 Call Amount(Temp#,VarQ$)
 Strng="The Broker says: Well, I'll give you"+VarQ$+" gold for the "+Out3+"."
 Call IO.O
 Graphics.Off=False
 If Rnd>.5 Then
    Strng="The Broker asks: Is that Okay(y/n)?"
 Else
    Strng="The Broker asks: Good nuff(y/n)?"
 Endif
 No.Input.Out="y"
 Call IO.I
 If No Then
    If Rnd>.5 Then
       Strng="The Broker says: Oh well!"
    Else
       Strng="The Broker says: Ok then!"
    Endif
    Call IO.O
    Exit Sub
 Endif
 UserRecord.Gold=UserRecord.Gold+Temp#
 If Rnd>.5 Then
    Strng="The Broker says: Great!"
 Else
    Strng="The Broker says: Excellent!"
 Endif
 Call IO.O
 If TreasureRecord.Scroll Then
    Gosub Clear.Scroll
    For Var=1 To 4
       MessWorkRecord6.Desc(Var)=0!
    Next
    Call Write.Record(MessWorkFile6,Temp5!)
 Endif
 Call Discard(Temp5!,True)
 Exit Sub
' remove written messages.
Clear.Scroll:
 Close #LogFile
 FileName=DND.Path+"writing.log"
 Open FileName For Random Shared As #LogFile Len=LogRecLen
 For Var=1 To 4
    Temp1!=MessWorkRecord6.Desc(Var)
    If Temp1!>SFalse And Temp1!<=Lof(LogFile)/LogRecLen Then
       LogRecord.User=0!
       LogRecord.Message=Nul
       LogRecord.Clock=Nul
       Call Write.Record(LogFile,Temp1!)
    Endif
 Next
 Return
Get.Config:
 VarX=0
 Option1=0
 Option2#=1000000#
 Option3=10
 Do
    VarX=VarX+1
    If VarX>Options.Lines Then
       Goto Next.Read
       Exit Do
    Endif
    Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
    If Ucase$(Var$)="[CMD117]" 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$=Lcase$(Ltrim$(Rtrim$(Left$(Var$,Var-1))))
             Var3$=Lcase$(Ltrim$(Rtrim$(Mid$(Var$,Var+1))))
             Gosub Parse.Options
          Endif
       Loop
    Endif
 Loop
 Return
Next.Read:
 Close #TempFile1
 Filename$=DND.Path+"CMD117.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=0
          Option2#=1000000#
          Option3=10
          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 Var2$
 Case "allow.point.sell"
    Select Case Var3$
    Case "-1", "on", "true"
       Option1=True
    End Select
 Case "point.cost"
    Var#=Int(Val(Var3$)+.5)
    If Var#>0# Then
       Option2#=Var#
    Endif
 End Select
 Return
Err.Resume21:
 Exit Sub
Err.Trap21:
 Resume Err.Resume21
End Sub

Sub Sell.Container
 On Local Error Goto ErrTrap44
 Temp7!=ContainerRecord.First
 If Temp7! Then
    Do While Lost.Carrier=False
       Call Read.Record(CtnInvFile,Temp7!)
       If MessWorkRecord6.User=SFalse Then
          Exit Do
       Endif
       Temp6!=MessWorkRecord6.Next
       Temp8!=MessWorkRecord6.User
       If Temp8!>SFalse And Temp8!<=Lof(TreasureFile)/TreasureRecLen Then
          Call Sell.Container.Contents
          Exit Sub
       Endif
       If Temp6!=SFalse Then
          Exit Do
       Endif
       Temp7!=Temp6!
    Loop
 Endif
 Temp7!=ContainerRecord.First
 If Temp7! Then
    Do While Lost.Carrier=False
       Call Read.Record(CtnInvFile,Temp7!)
       If MessWorkRecord6.User=SFalse Then
          Exit Do
       Endif
       Temp6!=MessWorkRecord6.Next
       Temp8!=MessWorkRecord6.User
       If Temp8! Then
          Strng=Rtrim$(ContainerRecord.NamePrefix)
          Strng=Lcase$(Strng)
          Strng="The Broker says: There's still stuff "+Strng+"!"
          Call IO.O
          Exit Sub
       Endif
       If Temp6!=SFalse Then
          Exit Do
       Endif
       Temp7!=Temp6!
    Loop
 Endif
 Temp7!=ContainerRecord.First2
 If Temp7! Then
    Call Read.Record(ContainerFile,Temp7!)
    Strng=Rtrim$(ContainerRecord.NamePrefix)
    Strng=Lcase$(Strng)
    Strng="The Broker says: There's still stuff "+Strng+"!"
    Call IO.O
    Exit Sub
 Endif
 Call Read.Record(ContainerFile,TempA!)
 Out3=ContainerRecord.ContainerShort
 Out3=Rtrim$(Out3)
 Out3=Lcase$(Out3)
 Temp#=1#
 Var1!=ContainerRecord.ContainerIndex
 If Var1!>SFalse And Var1!<=Lof(TreasureFile)/TreasureRecLen Then
    Call Read.Record(TreasureFile,Var1!)
    Temp#=TreasureRecord.Gold
 Endif
 Graphics.Off=True
 Call Amount(Temp#,VarQ$)
 Strng="The Broker says: Well, I'll give you"+VarQ$+" gold for the "
 If ContainerRecord.Damaged Then
    Strng=Strng+"damaged"
 Else
    Strng=Strng+"empty"
 Endif
 Strng=Strng+" "+Out3+"."
 Call IO.O
 Graphics.Off=False
 If Rnd>.5 Then
    Strng="The Broker asks: Is that Okay(y/n)?"
 Else
    Strng="The Broker asks: Good nuff(y/n)?"
 Endif
 No.Input.Out="y"
 Call IO.I
 If No Then
    If Rnd>.5 Then
       Strng="The Broker says: Oh well!"
    Else
       Strng="The Broker says: Ok then!"
    Endif
    Call IO.O
    Exit Sub
 Endif
 UserRecord.Gold=UserRecord.Gold+Temp#
 Call Delete.User.Container(TempA!)
 Call Clear.Container
 Call Write.Record(ContainerFile,TempA!)
 If Rnd>.5 Then
    Strng="The Broker says: Great!"
 Else
    Strng="The Broker says: Excellent!"
 Endif
 Call IO.O
ErrResume44:
 Exit Sub
ErrTrap44:
 Resume ErrResume44
End Sub

Sub Sell.Container.Contents
 On Local Error Goto ErrTrap45
 Var1#=DFalse
 Temp7!=ContainerRecord.First
 If Temp7! Then
    Do While Lost.Carrier=False
       Call Read.Record(CtnInvFile,Temp7!)
       If MessWorkRecord6.User=SFalse Then
          Exit Do
       Endif
       Temp6!=MessWorkRecord6.Next
       Temp8!=MessWorkRecord6.User
       If Temp8!>SFalse And Temp8!<=Lof(TreasureFile)/TreasureRecLen Then
          Call Read.Record(TreasureFile,Temp8!)
          Temp#=Int(TreasureRecord.Gold*Config1(19))
          If TreasureRecord.Spell Or TreasureRecord.Plus Then
             If MessWorkRecord6.Charges=False Then
                Temp#=1#
             Endif
          Endif
          Var1#=Var1#+Temp#
       Endif
       If Temp6!=SFalse Then
          Exit Do
       Endif
       Temp7!=Temp6!
    Loop
 Endif
 If Var1#=0# Then
    Var1#=1#
 Endif
 Out3=ContainerRecord.ContainerShort
 Out3=Rtrim$(Out3)
 Out3=Lcase$(Out3)
 Graphics.Off=True
 Call Amount(Var1#,VarQ$)
 Strng="The Broker says: Well, I'll give you"+VarQ$+" gold for the contents of the "+Out3+"."
 Call IO.O
 Graphics.Off=False
 If Rnd>.5 Then
    Strng="The Broker asks: Is that Okay(y/n)?"
 Else
    Strng="The Broker asks: Good nuff(y/n)?"
 Endif
 No.Input.Out="y"
 Call IO.I
 If No Then
    If Rnd>.5 Then
       Strng="The Broker says: Oh well!"
    Else
       Strng="The Broker says: Ok then!"
    Endif
    Call IO.O
    Exit Sub
 Endif
 UserRecord.Gold=UserRecord.Gold+Var1#
 Temp5!=ContainerRecord.First
 If Temp5! Then
    Do While Lost.Carrier=False
       Call Read.Record(CtnInvFile,Temp5!)
       If MessWorkRecord6.User=SFalse Then
          Exit Do
       Endif
       Temp6!=MessWorkRecord6.Next
       Temp8!=MessWorkRecord6.User
       If Temp8!>SFalse And Temp8!<=Lof(TreasureFile)/TreasureRecLen Then
          Call Delete.List.Node5(Temp5!)
          Call Clear.List.Node
          Call Write.Record(CtnInvFile,Temp5!)
       Endif
       If Temp6!=SFalse Then
          Exit Do
       Endif
       Temp5!=Temp6!
    Loop
 Endif
 If Rnd>.5 Then
    Strng="The Broker says: Great!"
 Else
    Strng="The Broker says: Excellent!"
 Endif
 Call IO.O
ErrResume45:
 Exit Sub
ErrTrap45:
 Resume ErrResume45
End Sub

Sub Amount2(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
