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

Sub Weapons.Shoppe
 On Local Error Goto Err.Trap22
 Gosub Get.Config
 TempA=True
 If Config2(50)=False Then
    Call In.Room(14)
 Endif
 If TempA=False Then
    Strng="Find the Weapons Shoppe!"
    Call IO.O
    If Sysop Or Local.Mode Then
       Strng="Weapons shoppe: "+Rtrim$(Room.Array(14))
       Call IO.O
    Endif
    Exit Sub
 Endif
 Var!=RoomRecord.Action
 If Var!>SFalse And Var!<=Lof(ActionFile)/ActionRecLen Then
    Call Read.Record(ActionFile,Var!)
    Var2!=ActionRecord.ItemForSale
    If Var2!<SFalse Then ' object
       Var3!=Abs(Var2!)
       If Var3!>SFalse And Var3!<=Lof(ObjectFile)/ObjectRecLen Then
          Call Read.Record(ObjectFile,Var3!)
          Temp$=Ucase$(Rtrim$(Parsed.Command1))
          Temp2$=Ucase$(Rtrim$(ObjectRecord.ShortName))
          If Temp$=Temp2$ Then
             Strng="You purchase a "+Lcase$(Temp2$)+"!"
             Call IO.O
             Temp9=False
             Call Add.Inventory(Var2!,Temp9)
             Exit Sub
          Endif
       Endif
    Endif
    If Var2!>SFalse Then ' treasure
       Var3!=Var2!
       If Var3!>SFalse And Var3!<=Lof(TreasureFile)/TreasureRecLen Then
          Call Read.Record(TreasureFile,Var3!)
          Temp$=Ucase$(Rtrim$(Parsed.Command1))
          Temp2$=Ucase$(Rtrim$(TreasureRecord.ShortName))
          If Temp$=Temp2$ Then
             If UserRecord.Gold-TreasureRecord.Gold<False Then
                Strng="The Blacksmith says: You don't have enough gold!"
                Call IO.O
                Exit Sub
             Endif
             UserRecord.Gold=UserRecord.Gold-TreasureRecord.Gold
             Call Write.Record(UserFile,User.Index)
             Strng="You purchase a "+Lcase$(Temp2$)+"!"
             Call IO.O
             If TreasureRecord.Container Then
                Call Drop.Container.In.User(Var2!)
             Else
                Temp9=TreasureRecord.Charges
                Call Add.Inventory(Var2!,Temp9)
             Endif
             Exit Sub
          Endif
       Endif
    Endif
 Endif
 ' purchase statistic points
 VarX1$=Ucase$(Rtrim$(Parsed.Command1))
 VarZ1=1
 If Parse.Temp Then
    VarZ1=Parse.Temp
 Endif
 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 Blacksmith says:"
                   Call IO.O
                   If VarZ1<=Option3 Then
                      Option2#=Option2#*VarZ1
                      If Option2#<=UserRecord.Gold Then
                         If UserRecord.Stats(VarX)<32767 Then
                            Var2#=UserRecord.Stats(VarX)
                            Var2#=Var2#+VarZ1
                            If Var2#>32767 Then
                               Strng="You can't buy that many points!"
                               Call IO.O
                            Else
                               Strng2="point" : If VarZ1>1 Then Strng2="points"
                               If VarZ1<=10 Then Strng3=" "+Rtrim$(Numeral(VarZ1)) Else Strng3=Str$(VarZ1)
                               Strng="Do you want to buy"+Strng3+" "+Lcase$(VarX2$)+" "+Strng2+" for "+Form$(Option2#)+" Gold(y/n)?"
                               Call IO.I
                               If Yes Then
                                  UserRecord.Gold=UserRecord.Gold-Option2#
                                  UserRecord.Stats(VarX)=Var2#
                                  Call Write.Record(UserFile,User.Index)
                                  Strng2="point" : If VarZ1>1 Then Strng2="points"
                                  If VarZ1<=10 Then Strng3=" "+Rtrim$(Numeral(VarZ1)) Else Strng3=Str$(VarZ1)
                                  Strng="You purchase"+Strng3+" "+Lcase$(VarX2$)+" "+Strng2+"!"
                                  Call IO.O
                               Endif
                            Endif
                         Else
                            Strng="You can't buy any more "+Lcase$(VarX2$)+" points!"
                            Call IO.O
                         Endif
                      Else
                         Strng="You don't have enough Gold!"
                         Call IO.O
                      Endif
                   Else
                      Strng="You can't buy that many points!"
                      Call IO.O
                   Endif
                   Exit Sub
                Endif
             Endif
          Endif
       Endif
    Next
 Endif
 Temp2=Int(Val(Parsed.Command1))
 If Temp2>False Then
    Temp5=False
    Temp8!=SFalse
    Var$=Config3(74)+","
    Do While Instr(Var$,",")
       Temp5=Temp5+1
       If Temp2=Temp5 Then
          Temp8!=Int(Val(Left$(Var$,Instr(Var$,",")-1)))
          Exit Do
       Endif
       Var$=Mid$(Var$,Instr(Var$,",")+1)
    Loop
 Else
    VarX$=Ucase$(Rtrim$(Parsed.Command1))
    If Len(VarX$) Then
       Temp8!=SFalse
       TempC=False
       Var$=Config3(74)
       Do
          If Instr(Var$,",") Then
             Var!=Int(Val(Left$(Var$,Instr(Var$,",")-1)))
             Var$=Mid$(Var$,Instr(Var$,",")+1)
          Else
             Var!=Int(Val(Var$))
             Var$=Nul
          Endif
          If Var!>SFalse And Var!<=Lof(TreasureFile)/TreasureRecLen Then
             Call Read.Record(TreasureFile,Var!)
             Strng=Ucase$(Rtrim$(TreasureRecord.ShortName))
             If Strng=VarX$ Then
                TempC=TempC+1
                If Parse.Temp=False Or Parse.Temp=TempC Then
                   Temp8!=Var!
                   Exit Do
                Endif
             Endif
          Endif
          If Var$=Nul Then
             Exit Do
          Endif
       Loop
    Endif
 Endif
 If Temp8!=SFalse Then
    Strng="The Blacksmith says: You can't buy that!"
    Call IO.O
    Exit Sub
 Endif
 If Temp8!<=SFalse Or Temp8!>Lof(TreasureFile)/TreasureRecLen Then
    Strng="The Blacksmith says: You can't buy that!"
    Call IO.O
    Exit Sub
 Endif
 Call Read.Record(TreasureFile,Temp8!)
 If UserRecord.Gold-TreasureRecord.Gold<False Then
    Strng="The Blacksmith says: You don't have enough gold!"
    Call IO.O
    Exit Sub
 Endif
 If UserRecord.Encumbrance>=False Then
    Temp1#=Cdbl(Weight+TreasureRecord.Weight)
    Temp2#=Cdbl(UserRecord.Stats(1))*Cdbl(UserRecord.Encumbrance)
    If Temp1#>Temp2# Then
       Strng="The Blacksmith says: You can't carry any more!"
       Call IO.O
       Exit Sub
    Endif
 Endif
 UserRecord.Gold=UserRecord.Gold-TreasureRecord.Gold
 Call Write.Record(UserFile,User.Index)
 Strng="The Blacksmith says: Ok, there ya go!"
 Call IO.O
 Strng="You give the Blacksmith "+Form$(TreasureRecord.Gold)+" gold!"
 Call IO.O
 If TreasureRecord.Container Then
    Call Drop.Container.In.User(Temp8!)
 Else
    Temp9=TreasureRecord.Charges
    Call Add.Inventory(Temp8!,Temp9)
 Endif
 Exit Sub
Get.Config:
 VarX=0
 Option1=0
 Option2#=1000000#
 Option3=10
 Do
    VarX=VarX+1
    If VarX>Options.Lines Then
       Exit Do
    Endif
    Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
    If Ucase$(Var$)="[CMD022]" 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$=Lcase$(Ltrim$(Rtrim$(Left$(Var$,Var-1))))
             Var3$=Lcase$(Ltrim$(Rtrim$(Mid$(Var$,Var+1))))
             Select Case Var2$
             Case "allow.point.purchase"
                Select Case Var3$
                Case "-1", "on", "true"
                   Option1=True
                End Select
             Case "point.cost"
                Var#=Int(Val(Var3$))
                If Var#>0# Then
                   Option2#=Var#
                Endif
             Case "max.points"
                Var=Int(Val(Var3$))
                If Var>0 And Var<=32767 Then
                   Option3=Var
                Endif
             End Select
          Endif
       Loop
    Endif
 Loop
 Return
Err.Resume22:
 Exit Sub
Err.Trap22:
 Resume Err.Resume22
End Sub
