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

Sub Write.On.Object
 On Local Error Goto Error.Trap75
 Gosub Get.Config
 Temp4=False
 Call Check.Room.Items
 If Temp7!<SFalse Then
    Strng="You can't write on that!"
    Call IO.O
    Exit Sub
 Endif
 If Temp7!=SFalse Then
    Call Num
    Temp4=True
    Call Check.User.Items
    If Temp7!<SFalse Then
       Strng="You can't write on that!"
       Call IO.O
       Exit Sub
    Endif
 Endif
 If Temp7!>SFalse Then
    If TreasureRecord.Scroll Then
       VarX=False
       If Option1 Then
          If TreasureRecord.Spell Then
             If Sysop Then
                Strng="Override scroll spell(y/n)? "
                Call IO.I
                If Yes Then
                   VarX=True
                Endif
             Endif
          Else
             If TreasureRecord.Spell=False Then
                VarX=True
             Endif
          Endif
       Endif
       If VarX Then
          Strng="Enter spell? "
          Call IO.I
          Var2$=Lcase$(Rtrim$(Out2))
          If Len(Var2$) Then
             TempD=False
             Var1=Instr(Var2$,"#")
             If Var1 Then
                TempD=Int(Val(Mid$(Var2$,Var1+1))+.5)
                Var2$=Left$(Var2$,Var1-1)
             Endif
             TempC=False
             If Len(Var2$) Then
                For Var!=1! To Lof(SpellFile)/SpellRecLen
                   Call Read.Record(SpellFile,Var!)
                   Var$=Lcase$(Rtrim$(SpellRecord.SpellName))
                   If Len(Var$) Then
                      If Instr(Var$,Var2$) Then
                         TempC=TempC+1
                         If TempC=TempD Or TempD=0 Then
                            TreasureRecord.Spell=Var!
                            Call Write.Record(TreasureFile,Temp7!)
                            Carriage.Return=True
                            Strng="Scroll now has a '"
                            Call IO.O
                            Strng=Rtrim$(SpellRecord.SpellName)
                            Strng=Rtrim$(SpellRecord.Prefix1)+Strng
                            Call Convert.ANSI(True,VarQ,VarR)
                            Carriage.Return=True
                            Graphics.On=True
                            Call IO.O
                            Graphics.On=False
                            Strng="' spell."
                            Call IO.O
                            Exit Sub
                         Endif
                      Endif
                   Endif
                Next
             Endif
          Endif
          Strng="Spell not found."
          Call IO.O
          Exit Sub
       Endif

       ' scroll can be written on.
       If TreasureRecord.Scroll=1 Then
          VarQ$=Lcase$(Rtrim$(TreasureRecord.TreasureName))
          VarQ2$=Rtrim$(TreasureRecord.Prefix1)
          Do While Lost.Carrier=False

             Graphics.Off=True
             Carriage.Return=True
             Strng="Editing "
             Call IO.O
             Strng=VarQ2$+VarQ$
             Call Convert.ANSI(True,VarQ,VarR)
             Carriage.Return=True
             Graphics.On=True
             Call IO.O
             Graphics.Off=True
             Graphics.On=False
             Strng=":"
             Call IO.O

             No.Input.Out="Q"
             Graphics.Off=False
             Strng="Enter option(1-4, ?=list, Q=quit)?"
             Call IO.I
             Select Case Lcase$(Out2)
             Case "1", "2", "3", "4"
                Var=Int(Val(Out2)+.5)
                If Temp.Array1(Var)=0 Then
                   No.Input.Out=""
                   Strng="Enter text<enter to clear>:"
                   Call IO.I
                   If Len(Out2) Then
                      Gosub Set.Scroll
                   Else
                      Gosub Clear.Scroll
                   Endif
                Else
                   Strng="Can't edit item"+Str$(Var)+"."
                   Call IO.O
                Endif
             Case "?"
                Gosub Display.Scroll
             Case "q"
                Exit Sub
             End Select
          Loop
       Endif
    Endif
 Endif
 Strng="You can't write on that!"
 Call IO.O
 Exit Sub
' store scroll text
Set.Scroll:
 If Len(Out2) Then
    ' check text disable
    Var1$=Option1$
    If Len(Var1$) Then
       Var1$=Lcase$(Var1$)
       Do While Lost.Carrier=False
          VarX=Instr(Var1$,";")
          If VarX Then
             Var$=Left$(Var1$,VarX-1)
             Var1$=Mid$(Var1$,VarX+1)
             If Len(Var$) Then
                If Left$(Var$,1)=Chr$(34) And Right$(Var$,1)=Chr$(34) Then
                   Var$=Left$(Var$,Len(Var$)-1) : Var$=Mid$(Var$,2)
                Endif
                If Len(Var$) Then
                   VarY=Instr(Lcase$(Out2),Var$)
                   If VarY Then
                      Strng="Illegal text "+Chr$(34)+Var$+Chr$(34)+" in position"+Str$(VarY)+"."
                      Call IO.O
                      Return
                   Endif
                Endif
             Endif
          Else
             Var$=Var1$
             If Len(Var$) Then
                If Left$(Var$,1)=Chr$(34) And Right$(Var$,1)=Chr$(34) Then
                   Var$=Left$(Var$,Len(Var$)-1) : Var$=Mid$(Var$,2)
                Endif
                If Len(Var$) Then
                   VarY=Instr(Lcase$(Out2),Var$)
                   If VarY Then
                      Strng="Illegal text "+Chr$(34)+Var$+Chr$(34)+" in position"+Str$(VarY)+"."
                      Call IO.O
                      Return
                   Endif
                Endif
             Endif
             Exit Do
          Endif
       Loop
    Endif
    ' check char disable
    If Len(Option2$) Then
       For VarX=1 To Len(Option2$)
          Var2$=Mid$(Option2$,VarX,1)
          VarY=Instr(Lcase$(Out2),Var2$)
          If VarY Then
             Strng="Illegal char "+Var2$+" in position"+Str$(VarY)+"."
             Call IO.O
             Return
          Endif
       Next
    Endif
    ' write text
    Close #LogFile
    FileName=DND.Path+"writing.log"
    Open FileName For Random Shared As #LogFile Len=LogRecLen
    Temp1!=Lof(LogFile)/LogRecLen+1!
    LogRecord.User=User.Index
    LogRecord.Message=Out2
    LogRecord.Clock=Fclock2$
    Call Write.Record(LogFile,Temp1!)
    MessWorkRecord6.Desc(Var)=Temp1!
    If Temp4=0 Then
       Call Write.Record(RoomInvFile,Temp5!)
    Else
       Call Write.Record(MessWorkFile6,Temp5!)
    Endif
    Strng="You write on it!"
    Call IO.O
 Else
    Strng="Nothing happens!"
    Call IO.O
 Endif
 Return
Clear.Scroll:
 MessWorkRecord6.Desc(Var)=0!
 If Temp4=0 Then
    Call Write.Record(RoomInvFile,Temp5!)
 Else
    Call Write.Record(MessWorkFile6,Temp5!)
 Endif
 Strng="You clear it!"
 Call IO.O
 Return
Display.Scroll:
 Close #LogFile
 FileName=DND.Path+"writing.log"
 Open FileName For Random Shared As #LogFile Len=LogRecLen
 If Temp4=0 Then
    Call Read.Record(RoomInvFile,Temp5!)
 Else
    Call Read.Record(MessWorkFile6,Temp5!)
 Endif
 Graphics.Off=True
 Strng="Scroll descriptions:"
 Call IO.O
 For Var2=1 To 4
    Strng="Item:"+Str$(Var2)+": "
    Temp1!=MessWorkRecord6.Desc(Var2)
    If Temp1!>0! And Temp1!<=Lof(LogFile)/LogRecLen Then
       Call Read.Record(LogFile,Temp1!)
       VarQ!=LogRecord.User
       If VarQ!>0! And VarQ!<=Lof(UserFile2)/UserRecLen Then
          Call Read.Record(UserFile2,VarQ!)
          VarC$=Rtrim$(UserRecord2.CodeName)
          Call Valid.Name(VarC$)
          Strng=Strng+"Written "
          If TempA Then
             VarC$=Lcase$(VarC$)
             Mid$(VarC$,1,1)=Ucase$(Mid$(VarC$,1,1))
             Strng=Strng+"by "+VarC$+" "
          Endif
          Strng=Strng+"on "+LogRecord.Clock
          Call IO.O
       Endif
       Strng="Text: "+Rtrim$(LogRecord.Message)
       Call IO.O
       Var$=Rtrim$(LogRecord.Message)
       If Len(Var$) Then
          If Instr(Var$,"{") Or Instr(Var$,"[") Or Instr(Var$,"<") Or Instr(Var$,"(") Then
             Strng=" Display: "+Var$
             Call Convert.String
             Call Convert.ANSI(True,VarQ,VarR)
             Graphics.On=True
             Call IO.O
             Graphics.On=False
          Endif
       Endif
    Else
       Strng=Strng+"<none>"
       Call IO.O
    Endif
 Next
 Graphics.Off=False
 If Sysop Or Normal.User=False Or Debug.Mode Then
    If Len(Option1$) Then
       Strng="disable.scroll.text="+Option1$
       Call IO.O
    Endif
    If Len(Option2$) Then
       Strng="disable.scroll.char="+Option2$
       Call IO.O
    Endif
    Strng="disable.items= "
    For Var2=1 To 4
       Strng=Strng+Ltrim$(Str$(Temp.Array1(Var2)))+", "
    Next
    Strng=Left$(Strng,Len(Strng)-2)+"."
    Call IO.O
 Endif
 Graphics.On=False
 Call More.Prompt
 Return
Get.Config:
 Option1=-1
 Option1$=""
 Option2$=""
 Redim Temp.Array1(4) As Integer
 Do
    VarX=VarX+1
    If VarX>Options.Lines Then
       Goto Next.Read
       Exit Do
    Endif
    Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
    If Ucase$(Var$)="[CMD151]" 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+"CMD151.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 "allow.scroll.write"
    Select Case Ucase$(Var3$)
    Case "0", "OFF", "FALSE"
       Option1=0
    End Select
 Case "disable.scroll.text"
    Option1$=Var3$
 Case "disable.scroll.char"
    Option2$=Var3$
 Case "disable.item1"
    Select Case Ucase$(Var3$)
    Case "-1", "ON", "TRUE"
       Temp.Array1(1)=-1
    End Select
 Case "disable.item2"
    Select Case Ucase$(Var3$)
    Case "-1", "ON", "TRUE"
       Temp.Array1(2)=-1
    End Select
 Case "disable.item3"
    Select Case Ucase$(Var3$)
    Case "-1", "ON", "TRUE"
       Temp.Array1(3)=-1
    End Select
 Case "disable.item4"
    Select Case Ucase$(Var3$)
    Case "-1", "ON", "TRUE"
       Temp.Array1(4)=-1
    End Select
 End Select
 Return
Error.Resume75:
 Exit Sub
Error.Trap75:
 Resume Error.Resume75
End Sub
