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

' offer <value/item> to <monster>
Sub Offer.Monster
 On Local Error Goto Err.Trap4
 Gosub Get.Config
 Call Parse
 Call Numeric
 Temp3=Parse.Temp
 User.Command=Parsed.Command1
 Parsed.Command1=Parsed.Command2
 Call Numeric
 Call Check.Room.Items
 If Temp7!<>SFalse Then
    Strng="You can't! It's not a monster!"
    Call IO.O
    Exit Sub
 Endif
 Call Num
 Call Check.Monster
 If Monster.Temp=SFalse Then
    Strng="That's not here!"
    Call IO.O
    Exit Sub
 Endif
 VarZ$=Lcase$(Out3)
 Temp9=False
 Temp2#=DFalse
 Parsed.Command1=User.Command
 Parse.Temp=Temp3
 Call Check.Inventory.Treasure
 If Temp7! Then
    If TreasureRecord.Spell Then
       Call Read.Record(SpellFile,TreasureRecord.Spell)
       If SpellRecord.SpellType=4 Then ' wish item
          Temp9=True
       Endif
    Endif
    If TreasureRecord.Plus>=Config2(27) Then
       Temp9=True
    Endif
 Else
    Temp2#=Int(Val(Parsed.Command1))
    If Temp2#>DFalse Then
       Out2=option1$
       Call Equate(Temp#)
       If Temp2#>Temp# Then
          If UserRecord.Gold-Temp2#>=DFalse Then
             Temp9=True
          Else
             Strng="You don't have that much gold!"
             Call IO.O
             Exit Sub
          Endif
       Else
          Strng="The "+VarZ$+" ignores your offer!"
          Call IO.O
          Exit Sub
       Endif
    Else
       If Option3 Then
          If Lcase$(Parsed.Command1)="all" Then
             Temp2#=UserRecord.Gold
             If Temp2#=DFalse Then
                Strng="You don't have that much gold!"
                Call IO.O
                Exit Sub
             Endif
             Out2=option2$
             Call Equate(Temp#)
             If Temp2#>Temp# Then
                Temp9=True
             Else
                Strng="The "+VarZ$+" ignores your offer!"
                Call IO.O
                Exit Sub
             Endif
          Endif
       Endif
    Endif
 Endif
 If Temp2#>DFalse Then
    If option1x#=-1# Then
       eat$=nul
    Else
       If Temp2#>option1x# Then
          Strng="You can't offer that much gold!"
          Call IO.O
          Exit Sub
       Endif
    Endif
 Endif
 If MessWorkRecord3.Monster.Permanent=-1 Then ' monster
    If option2=0 Then
       Temp9=0
    Endif
 Endif
 If MessWorkRecord3.Monster.Permanent=-2 Then ' nonplayer
    If Temp2# Then
       UserRecord.Gold=UserRecord.Gold-Temp2#
       MessWorkRecord3.Monster.Gold=MessWorkRecord3.Monster.Gold+Temp2#
       Call Write.Record(MessWorkFile3,Monster.Temp)
       Call Read.Record(NonPlayerFile,Choice)
       MonsterRecord.Gold=MonsterRecord.Gold+Temp2#
       Call Write.Record(NonPlayerFile,Choice)
       Strng="The "+VarZ$+" takes your offer!"
       Call IO.O
       Exit Sub
    Endif
    If Temp7! Then
       If option1 Then
          Gosub Add.Monster.Inventory3
          Call Discard(Temp5!,True)
          Strng="The "+VarZ$+" takes your offer!"
          Call IO.O
       Else
          Strng="The "+VarZ$+" ignores your offer!"
          Call IO.O
       Endif
       Exit Sub
    Endif
    Temp9=False
 Endif
 If Temp9=False Then
    Strng="The "+VarZ$+" ignores your offer!"
    Call IO.O
    Exit Sub
 Endif
 Call Remove.Monster
 If Temp2# Then
    UserRecord.Gold=UserRecord.Gold-Temp2#
    Strng="The "+VarZ$+" takes your offer and leaves!"
    Call IO.O
    Exit Sub
 Endif
 Call Discard(Temp5!,True)
 Strng="The "+VarZ$+" trades with you and leaves!"
 Call IO.O
 Exit Sub
Add.Monster.Inventory3:
 Temp9!=Lof(MessWorkFile5)/MessWorkRecLen5+1!
 MessWorkRecord5.Index=-Choice
 MessWorkRecord5.Inv=Temp7!
 MessWorkRecord5.Charges=Temp6
 MessWorkRecord5.Room=Room
 MessWorkRecord5.Monster=Monster.Temp
 MessWorkRecord5.IsAutomaton=False
 Call Write.Record(MessWorkFile5,Temp9!)

 Temp9!=Lof(MonInvFile)/MessWorkRecLen6+1!
 MessWorkRecord6.Room=SFalse
 MessWorkRecord6.User=Temp7!
 MessWorkRecord6.Index=-Choice
 MessWorkRecord6.Charges=Temp6
 MessWorkRecord6.Plus=False
 Call Add.List.Node2(Temp9!)
 Return
Get.Config:
 Option1=0
 Option2=0
 Option3=-1
 Option1x#=1d300
 Option1$="CONFIG1(15)*MLVL"
 Option2$="CONFIG1(15)*MLVL"
 Do
    VarX=VarX+1
    If VarX>Options.Lines Then
       Exit Do
    Endif
    Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
    If Ucase$(Var$)="[CMD018]" 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
             Var4$=Ltrim$(Rtrim$(Left$(Var$,Var-1)))
             Var5$=Ltrim$(Rtrim$(Mid$(Var$,Var+1)))
             Select Case Lcase$(Var4$)
             Case "allow.add.inv.nonplayer"
                Select Case Lcase$(Var5$)
                Case "-1","true","on"
                   Option1=-1
                End Select
             Case "allow.offer.permanent"
                Select Case Lcase$(Var5$)
                Case "-1","true","on"
                   Option2=-1
                End Select
             Case "allow.offer.all"
                Select Case Lcase$(Var3$)
                Case "false", "0", "off"
                   Option3=False
                End Select
             Case "maximum.gold.offer"
                option1x#=Int(Val(Var3$))
             Case "offer.gold.value"
                If Left$(Var3$,1)=Chr$(34) Then
                   If Right$(Var3$,1)=Chr$(34) Then
                      option1$=Mid$(Var3$,2)
                      option1$=Left$(option1$,Len(option1$)-1)
                   Endif
                Endif
             Case "offer.maximum.gold.value"
                If Left$(Var3$,1)=Chr$(34) Then
                   If Right$(Var3$,1)=Chr$(34) Then
                      option2$=Mid$(Var3$,2)
                      option2$=Left$(option2$,Len(option2$)-1)
                   Endif
                Endif
             End Select
          Endif
       Loop
    Endif
 Loop
 Return
Err.Resume4:
 Exit Sub
Err.Trap4:
 Resume Err.Resume4
End Sub

Sub Add.List.Node2(VarZ!)
 On Local Error Goto ErrorTrp27c
 If MonsterRecord.First=SFalse Then
    MonsterRecord.First=VarZ!
    MonsterRecord.Last=VarZ!
    Call Write.Record(NonplayerFile,Temp5!)
    MessWorkRecord6.Prev=SFalse
    MessWorkRecord6.Next=SFalse
    Call Write.Record(MonInvFile,VarZ!)
    Exit Sub
 Endif
 MessWorkRecord6.Prev=MonsterRecord.Last
 MessWorkRecord6.Next=SFalse
 Call Write.Record(MonInvFile,VarZ!)
 Call Read.Record(MonInvFile,MonsterRecord.Last)
 MessWorkRecord6.Next=VarZ!
 Call Write.Record(MonInvFile,MonsterRecord.Last)
 Call Read.Record(MonInvFile,VarZ!)
 MonsterRecord.Last=VarZ!
 Call Write.Record(NonplayerFile,Temp5!)
ErrorRsm27c:
 Exit Sub
ErrorTrp27c:
 Resume ErrorRsm27c
End Sub
