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

Sub Fire.Object
 On Local Error Goto ErrorTrap48
 Gosub Get.Config
 Call Parse
 If Parser Then
    Call Numeric
 Endif
 Call Check.User.Items
 If Temp7!<=SFalse Then
    Strng="You can't fire that!"
    Call IO.O
    Exit Sub
 Endif
 If TreasureRecord.Loadable=False Then
    Strng="You can't fire that!"
    Call IO.O
    Exit Sub
 Endif
 If TreasureRecord.AmmoLoads=SFalse Then
    Strng="It's not loaded with ammunition!"
    Call IO.O
    Exit Sub
 Endif
 Call Read.Record(TreasureFile,TreasureRecord.AmmoLoads)
 If TreasureRecord.Ammunition=False Then
    Strng="It's not loaded with ammunition!"
    Call IO.O
    Exit Sub
 Endif
 Call Read.Record(TreasureFile,Temp7!)
 If MessWorkRecord6.Charges<=False Then
    Strng="It's not loaded!"
    Call IO.O
    Exit Sub
 Endif
 MessWorkRecord6.Charges=MessWorkRecord6.Charges-1
 Call Write.Record(MessWorkFile6,Temp5!)
 Parsed.Command1=Parsed.Command2
 Call Numeric
 If Option3 Then
    If Len(option1$) Then
       Out2=option1$
       Call Equate(Temp#)
    Else
       Temp#=Rnd<Csng(Config1(12))
    Endif
    If Temp# Then
       If Option1 Then
          OutZ$="*bang*"
          Call Send.Mess(5,SFalse,Room,OutZ$)
       Endif
       Strng="Bang! The ammunition explodes in your face!"
       Call IO.O
       Prefix2=Nul
       Out5=TreasureRecord.ShortName
       Out5=Rtrim$(Out5)
       Out5=Lcase$(Out5)
       Strng="The "+Out5+" hits you for"
       Out3="loading ammunition"
       Temp2=Int(Rnd*TreasureRecord.Plus+1)
       Multiplier=1
       Call Hit.Player(Temp2)
       Exit Sub
    Endif
 Endif
 If Option4 Then
    If Len(option2$) Then
       Out2=option2$
       Call Equate(Temp#)
    Else
       Temp#=Rnd<Csng(Config1(13))
    Endif
    If Temp# Then
       If Option1 Then
          OutZ$="*bang*"
          Call Send.Mess(5,SFalse,Room,OutZ$)
       Endif
       Out5=TreasureRecord.ShortName
       Out5=Rtrim$(Out5)
       Out5=Lcase$(Out5)
       Strng="The "+Out5+" fires harmlessly!"
       Call IO.O
       Exit Sub
    Endif
 Endif
 Out5=TreasureRecord.ShortName
 Out5=Rtrim$(Out5)
 Out5=Lcase$(Out5)
 If Out5="shotgun" Or Out5="crossbolt" Then
    If Option2 Then
       OutZ$="-click-"
       Call Send.Mess(5,SFalse,Room,OutZ$)
    Endif
 Else
    If Option1 Then
       OutZ$="*bang*"
       Call Send.Mess(5,SFalse,Room,OutZ$)
    Endif
 Endif
 ' fire at monster
 TempC=False
 Call Check.Monster
 If Monster.Temp Then
    Out3=MessWorkRecord3.Monster.MonsterName
    Out3=Rtrim$(Out3)
    Out3=Lcase$(Out3)
    Strng="You fire the "+Out5+" at the "+Out3+"!"
    Call IO.O
    Multiplier=TreasureRecord.Plus
    Call Hit.Monster
    Exit Sub
 Endif
 ' fire at user
 Call Num
 Call Search.Mess(SFalse)
 If Temp!=Room And TempB!<>User.Index Then
    User.Temp=TempB!
    Out3=MessWorkRecord1.UserName
    Out3=Rtrim$(Out3)
    Out3=Lcase$(Out3)
    Strng="You fire the "+Out5+" at "+Out3+"!"
    Call IO.O
    Out2=TreasureRecord.TreasureName
    Out2=Lcase$(Out2)
    Out2=Rtrim$(Out2)
    Call Send.Mess(22,TempB!,Room,Out2)
    Multiplier=TreasureRecord.Plus
    Call Hit.Game.Player
    Exit Sub
 Endif
 ' fire at self
 If Option5 Then
    If Temp!=Room And TempB!=User.Index Then
       User.Temp=TempB!
       Strng="You fire the "+Out5+" at yourself!"
       Call IO.O
       Multiplier=TreasureRecord.Plus
       Var=TreasureRecord.Plus
       If Var>False Then
          Strng="You are hit for"
          Out3="a firing item"
          Call Hit.Player(Var)
       Else
          Strng="Nothing happens!"
          Call IO.O
       Endif
       Exit Sub
    Endif
 Endif
 Strng="The "+Out5+" fires into empty air!"
 Call IO.O
 Exit Sub
Get.Config:
 Option1=-1
 Option2=-1
 Option3=-1
 Option4=-1
 Option5=-1
 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$)="[CMD049]" 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+"CMD049.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=-1
          Option2=-1
          Option3=-1
          Option4=-1
          Option5=-1
          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 "fire.at.self"
    Select Case Lcase$(Var3$)
    Case "0", "false", "off"
       Option5=0
    End Select
 Case "override.check.explodes"
    Select Case Lcase$(Var3$)
    Case "0", "false", "off"
       Option3=0
    End Select
 Case "override.discharges.harmless"
    Select Case Lcase$(Var3$)
    Case "0", "false", "off"
       Option4=0
    End Select
 Case "override.bang.message"
    Select Case Lcase$(Var3$)
    Case "0", "false", "off"
       Option1=0
    End Select
 Case "override.click.message"
    Select Case Lcase$(Var3$)
    Case "0", "false", "off"
       Option2=0
    End Select
 Case "device.explodes"
    If Left$(Var3$,1)=Chr$(34) Then
       If Right$(Var3$,1)=Chr$(34) Then
          option1$=Var3$
          option1$=Left$(option1$,Len(option1$)-1)
          option1$=Mid$(option1$,2)
       Endif
    Endif
 Case "device.misfires"
    If Left$(Var3$,1)=Chr$(34) Then
       If Right$(Var3$,1)=Chr$(34) Then
          option2$=Var3$
          option2$=Left$(option2$,Len(option2$)-1)
          option2$=Mid$(option2$,2)
       Endif
    Endif
 End Select
 Return
ErrorResume48:
 Exit Sub
ErrorTrap48:
 Strng="Error"+Str$(Err)
 Call IO.O
 Resume ErrorResume48
End Sub
