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

' give <value/item> to <player/monster>
Sub Give.Object
 On Local Error Goto ErrorTrap27
 Gosub Get.Config
 Call Parse
 If Parser Then
    Call Numeric
 Endif
 Temp#=DFalse
 If Int(Val(Parsed.Command1)+.5)>False Then
    Temp#=Int(Val(Parsed.Command1)+.5)
    If UserRecord.Gold-Temp#<DFalse Then
       Strng="You don't have that much gold!"
       Call IO.O
       Exit Sub
    Endif
 Endif
 If Option1 Then
    If Temp#=DFalse Then
       If Lcase$(Parsed.Command1)="all" Then
          Temp#=UserRecord.Gold
          If Temp#=DFalse Then
             Strng="You don't have that much gold!"
             Call IO.O
             Exit Sub
          Endif
       Endif
    Endif
 Endif
 If Temp#>DFalse Then
    If option1x#=-1# Then
       eat$=nul
    Else
       If Temp#>option1x# Then
          Strng="You can't give that much gold!"
          Call IO.O
          Exit Sub
       Endif
    Endif
 Endif
 If Temp#=DFalse Then
    VarQ=False
    Parsed.Command1=Ucase$(Parsed.Command1)
    Call Check.User.Items
    If Temp7!<0! Then
       Var4$=Rtrim$(ObjectRecord.Prefix1)
    Else
       If Temp7!>0! Then
          Var4$=Rtrim$(TreasureRecord.Prefix1)
       Endif
    Endif
    If Temp7!=SFalse Then
       Call Num
       VarQ=True
       Call Search.User.Containers
       If TempA!>0! Then
          Var4$=Rtrim$(ContainerRecord.Prefix1)
       Endif
       If TempA!=False Then
          Strng="You can't give that!"
          Call IO.O
          Exit Sub
       Endif
    Endif
    Out5=Out3
    VarA!=Temp5!
 Endif

 ' give to online user
 Parsed.Command1=Parsed.Command2
 Call Numeric
 Call Search.Mess(SFalse)
 If Temp!=Room And TempB!<>User.Index Then
    VarY=TempC ' node
    Out2=Lcase$(Rtrim$(MessWorkRecord1.UserName))
    Mid$(Out2,1,1)=Ucase$(Mid$(Out2,1,1))
    Call Read.Record(UserFile2,TempB!)
    Strng3=Rtrim$(UserRecord2.Prefix1)
    If UserRecord2.Block2 Then
       Strng=Strng3+Out2
       Call Convert.ANSI(True,VarQ,VarR)
       Carriage.Return=True
       Graphics.On=True
       Call IO.O
       Graphics.On=False
       Strng=" doesn't want it!"
       Call IO.O
       Exit Sub
    Endif
    If Temp#>DFalse Then ' gold
       Select Case Temp#
       Case 1 To 10
          Strng2=" "+Rtrim$(Numeral(Temp#))
       Case Else
          Call Amount(Temp#,VarZ$)
          Strng2=VarZ$
       End Select

       Strng="You give"+Strng2+" gold to "+Strng3+Out2
       Call Convert.ANSI(True,VarQ,VarR)
       Carriage.Return=True
       Graphics.On=True
       Call IO.O
       Graphics.On=False
       Strng="!"
       Call IO.O

       Out2=Str$(Temp#)
       Call Send.Mess(15,TempB!,Room,Out2)
       UserRecord.Gold=UserRecord.Gold-Temp#
       Exit Sub
    Endif

    Strng="You give "+Var4$+Out3
    Call Convert.ANSI(True,VarQ,VarR)
    Carriage.Return=True
    Graphics.On=True
    Call IO.O

    Strng=" to "+Strng3+Out2
    Call Convert.ANSI(True,VarQ,VarR)
    Carriage.Return=True
    Graphics.On=True
    Call IO.O

    Graphics.On=False
    Strng="!"
    Call IO.O

    Call Send.Mess(13,TempB!,Room,Out3)
    If VarQ=False Then ' item
       MessWorkRecord6.User=TempB!
       Call Write.Record(MessWorkFile6,Temp5!)
       If Temp7!>SFalse Then
          Weight=Weight-TreasureRecord.Weight
          If Weight<DFalse Then
             Weight=DFalse
          Endif
       Endif
       Exit Sub
    Endif

    ' container
    Call Delete.User.Container(TempA!)
    Call Read.Record(ContainerFile,TempA!)
    ContainerRecord.UserNumber=TempB!
    ContainerRecord.RoomNumber=SFalse
    Call Add.User.Container2(TempA!)
    Call Read.Message.Record(MessWorkFile7,VarY+1)
    MessWorkRecord7.First2=UserRecord2.First2
    MessWorkRecord7.Last2=UserRecord2.Last2
    MessWorkRecord7.Weight=ContainerRecord.Weight
    MessWorkRecord7.Flags4=MessWorkRecord7.Flags4 Or 2^9
    Call Write.Message.Record(MessWorkFile7,VarY+1)
    Weight=Weight-ContainerRecord.Weight
    If Weight<DFalse Then
       Weight=DFalse
    Endif
    Exit Sub
 Endif
 Call Num

 ' give to offline user
 Call Check.User
 If User.Temp Then
    Strng3=Rtrim$(UserRecord2.Prefix1)
    TempB!=MessWorkRecord4.Index
    Out3=Lcase$(Rtrim$(Out3))
    Mid$(Out3,1,1)=Ucase$(Mid$(Out3,1,1))
    If UserRecord2.Block2 Then
       Strng=Strng3+Out3
       Call Convert.ANSI(True,VarQ,VarR)
       Carriage.Return=True
       Graphics.On=True
       Call IO.O
       Graphics.On=False
       Strng=" doesn't want it!"
       Call IO.O
       Exit Sub
    Endif
    If Temp#>DFalse Then ' gold
       Select Case Temp#
       Case 1 To 10
          Strng2=" "+Rtrim$(Numeral(Temp#))
       Case Else
          Call Amount(Temp#,VarZ$)
          Strng2=VarZ$
       End Select

       Strng="You give"+Strng2+" gold to "+Strng3+Out3
       Call Convert.ANSI(True,VarQ,VarR)
       Carriage.Return=True
       Graphics.On=True
       Call IO.O
       Graphics.On=False
       Strng="!"
       Call IO.O
       UserRecord2.Gold=UserRecord2.Gold+Temp#
       Call Write.Record(UserFile2,MessWorkRecord4.Index)
       UserRecord.Gold=UserRecord.Gold-Temp#
       Exit Sub
    Endif

    Strng="You give "+Var4$+Out5
    Call Convert.ANSI(True,VarQ,VarR)
    Carriage.Return=True
    Graphics.On=True
    Call IO.O

    Strng=" to "+Strng3+Out3
    Call Convert.ANSI(True,VarQ,VarR)
    Carriage.Return=True
    Graphics.On=True
    Call IO.O

    Graphics.On=False
    Strng="!"
    Call IO.O

    If VarQ=False Then ' item
       MessWorkRecord6.User=TempB!
       Call Write.Record(MessWorkFile6,VarA!)
       VarB!=Lof(UserInvFile)/MessWorkRecLen6+1!
       Call Write.Record(UserInvFile,VarB!)
       Call Add.User.Item2(VarB!)
       If Temp7!>SFalse Then
          Weight=Weight-TreasureRecord.Weight
          If Weight<DFalse Then
             Weight=DFalse
          Endif
       Endif
       Exit Sub
    Endif

    ' container
    Call Delete.User.Container(TempA!)
    Call Read.Record(ContainerFile,TempA!)
    ContainerRecord.UserNumber=TempB!
    ContainerRecord.RoomNumber=SFalse
    Call Add.User.Container2(TempA!)
    Weight=Weight-ContainerRecord.Weight
    If Weight<DFalse Then
       Weight=DFalse
    Endif
    Exit Sub
 Endif

 ' give item monster
 Call Num
 Temp2#=Temp#
 Parsed.Command1=Parsed.Command2
 Call Check.Monster
 If Monster.Temp=SFalse Then
    Strng="You can't give that!"
    Call IO.O
    Exit Sub
 Endif

 Strng3=Rtrim$(MessWorkRecord3.Monster.Prefix1)
 Out3=Lcase$(Out3)

 If VarQ Then ' container
    Strng="The "+Strng3+Out3
    Call Convert.ANSI(True,VarQ,VarR)
    Carriage.Return=True
    Graphics.On=True
    Call IO.O
    Graphics.On=False
    Strng=" doesn't want it!"
    Call IO.O
    Exit Sub
 Endif

 ' check permanent/nonplayer
 If MessWorkRecord3.Monster.Magic<=True Or _
    MessWorkRecord3.Monster.Permanent<=True Then
    If Temp2#>DFalse Then ' gold
       Eat$=Nul
    Else
       Strng="The "+Strng3+Out3
       Call Convert.ANSI(True,VarQ,VarR)
       Carriage.Return=True
       Graphics.On=True
       Call IO.O
       Graphics.On=False
       Strng=" refuses your offer!"
       Call IO.O
       Exit Sub
    Endif
 Endif

 ' gold
 If Temp2#>DFalse Then
    Select Case Temp2#
    Case 1 To 10
       Strng2=" "+Rtrim$(Numeral(Temp2#))
    Case Else
       Call Amount(Temp2#,VarZ$)
       Strng2=VarZ$
    End Select

    Strng="You give"+Strng2+" gold to the "+Strng3+Out3
    Call Convert.ANSI(True,VarQ,VarR)
    Carriage.Return=True
    Graphics.On=True
    Call IO.O
    Graphics.On=False
    Strng="!"
    Call IO.O

    MessWorkRecord3.Monster.Gold=MessWorkRecord3.Monster.Gold+Temp2#
    Call Write.Record(MessWorkFile3,Temp5!)
    UserRecord.Gold=UserRecord.Gold-Temp2#
    Exit Sub
 Endif

 ' accept equation
 If Len(option1$) Then
    Out2=option1$
    Call Equate(Temp#)
 Else
    Temp#=Rnd>.9
 Endif
 If Temp# Then
    Strng="The "+Strng3+Out3
    Call Convert.ANSI(True,VarQ,VarR)
    Carriage.Return=True
    Graphics.On=True
    Call IO.O
    Graphics.On=False
    Strng=" doesn't want it!"
    Call IO.O
    Exit Sub
 Endif

 ' item
 MessWorkRecord6.User=SFalse
 Call Write.Record(MessWorkFile6,VarA!)
 Temp3!=Lof(MessWorkFile5)/MessWorkRecLen5+1!
 MessWorkRecord5.Index=MessWorkRecord3.Index
 MessWorkRecord5.Inv=Temp7!
 MessWorkRecord5.Charges=Temp6
 MessWorkRecord5.Room=Room
 MessWorkRecord5.Monster=Temp5!
 MessWorkRecord5.IsAutomaton=False
 Call Write.Record(MessWorkFile5,Temp3!)
 If Temp7!>SFalse Then
    Weight=Weight-TreasureRecord.Weight
    If Weight<DFalse Then
       Weight=DFalse
    Endif
 Endif

 Strng="You give "+Var4$+Out5
 Call Convert.ANSI(True,VarQ,VarR)
 Carriage.Return=True
 Graphics.On=True
 Call IO.O

 Strng=" to the "+Strng3+Out3
 Call Convert.ANSI(True,VarQ,VarR)
 Carriage.Return=True
 Graphics.On=True
 Call IO.O

 Graphics.On=False
 Strng="!"
 Call IO.O

 Exit Sub
Get.Config:
 Option1=True
 Option1x#=1d300
 VarX=0
 Do
    VarX=VarX+1
    If VarX>Options.Lines Then
       Goto Next.Read
       Exit Do
    Endif
    Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
    If Ucase$(Var$)="[CMD054]" 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$=Ltrim$(Rtrim$(Left$(Var$,Var-1)))
             Var3$=Ltrim$(Rtrim$(Mid$(Var$,Var+1)))
             Gosub Parse.Options
          Endif
       Loop
    Endif
 Loop
 Return
Next.Read:
 Close #TempFile1
 Filename$=DND.Path+"CMD054.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=True
          Option1x#=1d300
          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 Lcase$(Var2$)
 Case "accept.object"
    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 "allow.give.all"
    Select Case Lcase$(Var3$)
    Case "false", "0", "off"
       Option1=False
    End Select
 Case "maximum.gold.give"
    option1x#=Int(Val(Var3$)+.5)
 End Select
 Return
ErrorResume27:
 Exit Sub
ErrorTrap27:
 Resume ErrorResume27
End Sub
