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

Sub Bless.Object
 On Local Error Goto ErrorTrap29
 Gosub Get.Config
 If Lcase$(Parsed.Command1)="self" Then
    Call Bless.Self
    Exit Sub
 Endif
 Call Parse
 If Parser Then
    Call Numeric
 Endif
 Temp4=False
 Call Check.Room.Items
 If Temp7!<SFalse Then
    Strng="You can't bless that!"
    Call IO.O
    Exit Sub
 Endif
 If Temp7!=SFalse Then
    Call Num
    Temp4=UnTrue
    Call Check.User.Items
    If Temp7!<SFalse Then
       Strng="You can't bless that!"
       Call IO.O
       Exit Sub
    Endif
 Endif
 If Temp7!>SFalse Then
    Out3=TreasureRecord.ShortName
    Out3=Rtrim$(Out3)
    Out3=Lcase$(Out3)
    If TreasureRecord.Spell=SFalse Then
       Var=TreasureRecord.TimesBlessed
       If option1 Then
          Var2=option1
       Else
          Var2=100
       Endif
       If Var>=Var2 Then
          Strng="You bless the "+Out3+"!"
          Call IO.O
          TreasureRecord.TimesBlessed=0
          Var2=TreasureRecord.Charges
          If Var2<32767 Then
             TreasureRecord.Charges=Var2+1
             Strng="The "+Out3+" gains 1 charge.."
             Call IO.O
          Else
             Strng="Nothing happens!"
             Call IO.O
          Endif
          Call Write.Record(TreasureFile,Temp7!)
       Else
          If Var<32767 Then
             Var=Var+1
             TreasureRecord.TimesBlessed=Var
             Call Write.Record(TreasureFile,Temp7!)
             Strng="You bless the "+Out3+"!"
             Call IO.O
          Else
             Strng="Nothing happens.."
             Call IO.O
          Endif
       Endif
       Exit Sub
    Endif
    Call Read.Record(SpellFile,TreasureRecord.Spell)
    If SpellRecord.SpellType=4 Then ' wish spell
       Strng="You can't bless that!"
       Call IO.O
       Exit Sub
    Endif
    TempZ=False
    Select Case Temp4
    Case 1
       If MessWorkRecord6.Charges<32767 Then
          MessWorkRecord6.Charges=MessWorkRecord6.Charges+1
          Call Write.Record(MessWorkFile6,Temp5!)
       Else
          TempZ=True
       Endif
    Case 0
       If MessWorkRecord6.Charges<32767 Then
          MessWorkRecord6.Charges=MessWorkRecord6.Charges+1
          Call Write.Record(RoomInvFile,Temp5!)
       Else
          TempZ=True
       Endif
    End Select
    If TempZ Then
       Strng="Nothing happens!"
    Else
       Strng="You bless the "+Out3+"!"
    Endif
    Call IO.O
    Exit Sub
 Endif
 ' online monsters
 TempC=False
 Call Num
 Call Check.Monster
 If Monster.Temp Then
    Out3=MessWorkRecord3.Monster.MonsterName
    Out3=Rtrim$(Out3)
    Out3=Lcase$(Out3)
    Strng="You bless the "+Out3+"!"
    Call IO.O
    Temp#=MessWorkRecord3.Monster.Hits+1#
    If Temp#<Config2(62) Then
       MessWorkRecord3.Monster.Hits=Temp#
       Call Write.Record(MessWorkFile3,Monster.Temp)
       Strng="The "+Out3+" gains 1 hit point!"
       Call IO.O
    Else
       Strng="Nothing happens!"
       Call IO.O
    Endif
    Exit Sub
 Endif
 ' online users
 Call Num
 Call Search.Mess(SFalse)
 If Temp!=Room And TempB!<>User.Index Then
    User.Temp=TempB!
    Call Read.Record(UserFile2,User.Temp)
    Out3=MessWorkRecord1.UserName
    Out3=Rtrim$(Out3)
    Out3=Lcase$(Out3)
    Strng="You bless "+Out3+"!"
    Call IO.O
    If Len(option1$) Then
       Out2=option1$
       Call Equate(Temp#)
    Else
       Temp#=Rnd>.75
    Endif
    If Temp# Then
       If UserRecord2.Stats(6)<32767 Then ' piety
          Out2="blesses you!"
          Call Send.Mess(23,TempB!,Room,Out2)
          Exit Sub
       Endif
    Endif
    Strng="Nothing happens!"
    Call IO.O
    Exit Sub
 Endif
 ' offline users
 Call Num
 Call Check.User
 If User.Temp Then
    User.Temp=MessWorkRecord4.Index
    Strng="You bless "+Lcase$(Out3)+"!"
    Call IO.O
    If Len(option2$) Then
       Out2=option2$
       Call Equate(Temp#)
    Else
       Temp#=Rnd>.75
    Endif
    If Temp# Then
       If UserRecord2.Stats(6)<32767 Then ' piety
          UserRecord2.Stats(6)=UserRecord2.Stats(6)+1
          Call Write.Record(UserFile2,User.Temp)
          Exit Sub
       Endif
    Endif
    Strng="Nothing happens!"
    Call IO.O
    Exit Sub
 Endif
 Strng="You can't bless that!"
 Call IO.O
 Exit Sub
Get.Config:
 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$)="[CMD016]" 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+"CMD016.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
          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 "bless.times"
    option1=Int(Val(Var3$)+.5)
 Case "bless.online.user"
    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 "bless.offline.user"
    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
 Return
ErrorResume29:
 Exit Sub
ErrorTrap29:
 Resume ErrorResume29
End Sub

Sub Bless.Self
 On Local Error Goto ErrorTrap31
 Gosub Get.Config1
 If Len(option1$) Then
    Out2=option1$
    Call Equate(Temp#)
 Else
    Temp#=Rnd>.75
 Endif
 If Temp# Then
    If UserRecord.Stats(6)<32767 Then
       UserRecord.Stats(6)=UserRecord.Stats(6)+1
       Call Write.Record(UserFile,User.Index)
       Strng=Rtrim$(Stat(6))
       Strng="gained one "+Strng+" point"
       Call Update.DayFile(Strng,False,2)
       If Node>False Then
          Out2=Lcase$(Rtrim$(UserRecord.CodeName))
          Out2=Out2+" just got blessed!"
          Call Send.Mess(8,SFalse,Room,Out2)
       Endif
       Strng="You feel a magical glow about you!"
       Call IO.O
       Strng="Your piety is now "+Form$(Cdbl(UserRecord.Stats(6)))+"!"
       Call IO.O
       Call New.Stats
       Exit Sub
    Endif
 Endif
 Strng="Nothing happens!"
 Call IO.O
 Exit Sub
Get.Config1:
 VarX=0
 Do
    VarX=VarX+1
    If VarX>Options.Lines Then
       Goto Next.Read2
       Exit Do
    Endif
    Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
    If Ucase$(Var$)="[CMD035]" Then
       Do
          VarX=VarX+1
          If VarX>Options.Lines Then
             Goto Next.Read2
             Return
          Endif
          Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
          If Ucase$(Var$)="[END]" Then
             Goto Next.Read2
             Return
          Endif
          Var=Instr(Var$,"=")
          If Var Then
             Var2$=Ltrim$(Rtrim$(Left$(Var$,Var-1)))
             Var3$=Ltrim$(Rtrim$(Mid$(Var$,Var+1)))
             Gosub Parse.Options2
          Endif
       Loop
    Endif
 Loop
 Return
Next.Read2:
 Close #TempFile1
 Filename$=DND.Path+"CMD035.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
          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.Options2
             Endif
          Loop
       Endif
    Endif
 Loop
 Return
Parse.Options2:
 Select Case Lcase$(Var2$)
 Case "bless.self"
    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
 End Select
 Return
ErrorResume31:
 Exit Sub
ErrorTrap31:
 Resume ErrorResume31
End Sub
