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

' offer <value/item/container> to <online player> for <value/item/container>
Sub Offer.Player
 On Local Error Goto Err.Trap5
 Call Parse
 Call Numeric
 Temp2=Parse.Temp
 Temp$=Parsed.Command1
 Parsed.Command1=Parsed.Command2
 Call Parse
 Temp2$=Parsed.Command1
 Temp3$=Parsed.Command2
 Call Search.Mess(SFalse)
 VarX=TempC
 If TempB=User.Index Or Temp!<>Room Then
    Strng="You can't offer to that player!"
    Call IO.O
    Exit Sub
 Endif

 VarX2=Node+1
 Call Read.Message.Record(MessWorkFile1,VarX2)
 If MessWorkRecord1.OfferTime>False Then
    Strng="Offer already in progress!"
    Call IO.O
    Exit Sub
 Endif

 Call Read.Message.Record(MessWorkFile1,VarX+1)
 If MessWorkRecord1.OfferTime>False Then
    Strng=MessWorkRecord1.UserName
    Strng=Rtrim$(Strng)
    Strng=Lcase$(Strng)
    Mid$(Strng,1,1)=Ucase$(Mid$(Strng,1,1))
    Strng=Strng+" already has an offer!"
    Call IO.O
    Exit Sub
 Endif

 VarA#=DFalse
 Temp41=False
 Parsed.Command1=Temp3$
 Call Numeric
 Call Search.User.Inventory
 If Temp7!=SFalse Then
    Call Num
    Call Search.User.Container2
    If TempA!>SFalse Then
       Temp41=True
       Temp7!=TempA!
       OutZ1$=ContainerRecord.ContainerName
       OutZ1$=Rtrim$(OutZ1$)
       OutZ1$=Lcase$(OutZ1$)
    Endif
 Endif
 If Temp7!=SFalse Then
    VarA#=Int(Val(Parsed.Command1))
 Endif
 If Temp7!=SFalse Then
    If VarA#<=DFalse Then
       Strng="You can't offer for that!"
       Call IO.O
       Exit Sub
    Endif
 Endif
 Var1!=Temp5!
 Var2=Temp6
 Var3!=Temp7!
 VarB#=DFalse
 Temp42=False
 Parsed.Command1=Temp$
 Parse.Temp=Temp2
 Call Check.User.Items
 If Temp7!=SFalse Then
    Call Num
    Call Search.User.Containers
    If TempA!>SFalse Then
       Temp42=True
       Temp7!=TempA!
       OutZ2$=ContainerRecord.ContainerName
       OutZ2$=Rtrim$(OutZ2$)
       OutZ2$=Lcase$(OutZ2$)
    Endif
 Endif
 If Temp7!=SFalse Then
    VarB#=Int(Val(Parsed.Command1))
 Endif
 If Temp7!=SFalse Then
    If VarB#=DFalse Then
       Strng="You can't offer that!"
       Call IO.O
       Exit Sub
    Endif
 Endif
 If VarB#>DFalse Then
    If UserRecord.Gold-VarB#<DFalse Then
       Strng="You don't have that much gold!"
       Call IO.O
       Exit Sub
    Endif
 Endif

 ' send node offer
 Var4!=Temp5!
 Var5=Temp6
 Var6!=Temp7!
 TempX=VarX
 Gosub Send.Node.Offer
 TempX=Node
 Gosub Send.Node.Offer
 Out2="offers you"
 If VarB#>DFalse Then
    Call Amount(VarB#,VarZ$)
    Out2=Out2+VarZ$+" gold"
 Else
    If Temp42 Then
       Out3=OutZ2$
    Else
       If Var6!>SFalse Then
          Call Read.Record(TreasureFile,Var6!)
          Out3=TreasureRecord.TreasureName
          Out3=Rtrim$(Out3)
          Out3=Lcase$(Out3)
       Else
          If Var6!<SFalse Then
             Call Read.Record(ObjectFile,Abs(Var6!))
             Out3=ObjectRecord.ObjectName
             Out3=Rtrim$(Out3)
             Out3=Lcase$(Out3)
          Endif
       Endif
    Endif
    Out2=Out2+" "+Out3
 Endif
 Out2=Out2+" for"
 If VarA#>DFalse Then
    Call Amount(VarA#,VarZ$)
    Out2=Out2+VarZ$+" gold"
 Else
    If Temp41 Then
       Out3=OutZ1$
    Else
       If Var3!>SFalse Then
          Call Read.Record(TreasureFile,Var3!)
          Out3=TreasureRecord.TreasureName
          Out3=Rtrim$(Out3)
          Out3=Lcase$(Out3)
       Else
          If Var3!<SFalse Then
             Call Read.Record(ObjectFile,Abs(Var3!))
             Out3=ObjectRecord.ObjectName
             Out3=Rtrim$(Out3)
             Out3=Lcase$(Out3)
          Endif
       Endif
    Endif
    Out2=Out2+" "+Out3
 Endif
 Out2=Out2+"!"
 Call Send.Mess(19,TempB!,Room,Out2)
 Strng="Offer sent!"
 Call IO.O
 Exit Sub

Send.Node.Offer:
 Call Read.Message.Record(MessWorkFile1,TempX+1)
 MessWorkRecord1.OfferTime=Timeit!
 If VarA#>DFalse Then
    MessWorkRecord1.GoldFor=VarA#
    MessWorkRecord1.ItemFor=SFalse
    MessWorkRecord1.ForCharges=False
    MessWorkRecord1.ContainerFor=False
 Else
    If Temp41 Then
       MessWorkRecord1.GoldFor=DFalse
       MessWorkRecord1.ItemFor=SFalse
       MessWorkRecord1.ForCharges=False
       MessWorkRecord1.ContainerFor=True
       Call Read.Record(ContainerFile,Var1!)
       ContainerRecord.SwapFlag=True
       Call Write.Record(ContainerFile,Var1!)
    Else
       MessWorkRecord1.GoldFor=DFalse
       MessWorkRecord1.ItemFor=Var3!
       MessWorkRecord1.ForCharges=Var2
       MessWorkRecord1.ContainerFor=False
    Endif
 Endif
 If VarB#>False Then
    MessWorkRecord1.GoldOffer=VarB#
    MessWorkRecord1.ItemOffer=SFalse
    MessWorkRecord1.OfferCharges=False
    MessWorkRecord1.ContainerOffer=False
 Else
    If Temp42 Then
       MessWorkRecord1.GoldOffer=DFalse
       MessWorkRecord1.ItemOffer=SFalse
       MessWorkRecord1.OfferCharges=False
       MessWorkRecord1.ContainerOffer=True
       Call Read.Record(ContainerFile,Var4!)
       ContainerRecord.SwapFlag=True
       Call Write.Record(ContainerFile,Var4!)
    Else
       MessWorkRecord1.GoldOffer=DFalse
       MessWorkRecord1.ItemOffer=Var6!
       MessWorkRecord1.OfferCharges=Var5
       MessWorkRecord1.ContainerOffer=False
    Endif
 Endif
 MessWorkRecord1.FromNode=Node
 MessWorkRecord1.ToNode=VarX
 Call Write.Message.Record(MessWorkFile1,TempX+1)
 Return
Err.Resume5:
 Exit Sub
Err.Trap5:
 Resume Err.Resume5
End Sub
