 Rem File: DndeditJ.bas
 Rem Sub: EditSpell
 Rem $Include: 'dndedit.inc'

 On Error Goto Main.Error
 If Chained2=0 Then
    Call Init.Arrays
    Call Read.Rows(Var2)
    Max.Row=Var2
    Call Save.Screen(False)
    Call Clear.Screen2
    Call Init.Mouse
    Call Read.Config(False)
    Call Passwrd5(Var,"j")
    Close #TempFile1
    If Var=False Then
       Call Terminate.Program(True)
       End
    Endif
 Endif
Main.Resume:
 Call EditSpell
 If Chained2 Then
    Chain DND.Path+"DNDEDIT.EXE"
 Endif
 Call Terminate.Program(True)
 End
Main.Error:
 Resume Main.Resume

Sub EditSpell
 On Local Error Goto Error.Trap191
 Spell.Number=1!
 If Lof(SpellFile)=SFalse Then
    Call AddSpell
 Endif
 Out3="Sysop Spell Edit"
 Call DisplayEditScreen(5,21,Out3)
 Call SpellStatusLine
 Call DisplaySpell
 Do While Lost.Carrier=False
    TempX$=Nul
    Do While TempX$=Nul
       If Lost.Carrier Then
          Exit Do
       Endif
       Call Read.Keyboard(TempX$)
       Call MouseDriver(3)
       If Mouse.Button2 Then
          TempX$=Chr$(27)
       Endif
       If Mouse.Button Then
          Call MouseButton(21)
          If Len(TempX$) Then
             Exit Do
          Endif
       Endif
       If Mouse.Row Or Mouse.Column Then
          Call MouseSelect(21)
       Endif
    Loop
    TempX=False
    Select Case Len(TempX$)
    Case 2
       TempX=Asc(Mid$(TempX$,2,1))
       If TempX=0 Then
          Call Write.Record(SpellFile,Spell.Number)
          Exit Do
       Endif
       Call SpellSelect
    Case 1
       TempX=Asc(TempX$)
       Select Case TempX
       Case 1
          Call AddSpell
       Case 8
          Call Help(5)
          Out3="Sysop Spell Edit"
          Call DisplayEditScreen(5,21,Out3)
          Call SpellStatusLine
          Call DisplaySpell
       Case 9
          Call SpellSelect
       Case 13
          Call SpellEdit
          Call Write.Record(SpellFile,Spell.Number)
          Call SpellStatusLine
          TempX=Selection
          Call ShowSpell
          Call RedisplayField
       Case 14
          Call NextSpell
       Case 17
          Call PreviousSpell
       Case 18
          Call SelectNextSpell
          Call SpellStatusLine
       Case 23
          Call SearchSpell
       Case 27
          Call Write.Record(SpellFile,Spell.Number)
          Exit Sub
       End Select
    End Select
 Loop
Error.Resume191:
 Exit Sub
Error.Trap191:
 Resume Error.Resume191
End Sub

Sub NextSpell
 On Local Error Goto Error.Trap192
 If Spell.Number>=Lof(SpellFile)/SpellRecLen Then
    Strng="This is the last spell in the spell file."
    Call ErrorMessage
 Else
    Call Write.Record(SpellFile,Spell.Number)
    Spell.Number=Spell.Number+1!
    Call DisplaySpell
 Endif
Error.Resume192:
 Exit Sub
Error.Trap192:
 Resume Error.Resume192
End Sub

Sub PreviousSpell
 On Local Error Goto Error.Trap193
 If Spell.Number>1! Then
    Call Write.Record(SpellFile,Spell.Number)
    Spell.Number=Spell.Number-1!
    Call DisplaySpell
    Exit Sub
 Endif
 Strng="This is the first spell in the spell file."
 Call ErrorMessage
Error.Resume193:
 Exit Sub
Error.Trap193:
 Resume Error.Resume193
End Sub

Sub SelectNextSpell
 On Local Error Goto Error.Trap194
 Strng=Nul
 Out2="^ Cursor Edit"+Chr$(60)+Chr$(217)+" Exit Field "
 Call StatusLine
 Call ANSI(4,33,44)
 Call ANSI(2,23,2)
 Strng="Enter Spell: "
 Call Scrn(Strng)
 Call ANSI(4,37,40)
 Call ANSI(2,23,15)
 Strng=Space$(6)
 Call Scrn(Strng)
 Call ANSI(4,37,44)
 Call ANSI(2,23,24)
 Strng="(1-"+Mid$(Str$(Lof(SpellFile)/SpellRecLen),2)+")"
 Multiplier=Len(Strng)+24
 Strng=Strng+" (+/-/x)"
 Call Scrn(Strng)
 Restore Data8
 Read Xcoor, Ycoor, Column, Line.Length, Row, Max.Lines, Line.Number
 Edit.Data(1)=Nul
 Call ScreenEdit
 Multiplier=False
 Temp2!=Int(Val(Edit.Data(1)))
 If Temp2!<=SFalse Or Temp2!>Lof(SpellFile)/SpellRecLen Then
    Strng="The spell number is not within the spell file range."
    Call ErrorMessage
    Exit Sub
 Endif
 Call Write.Record(SpellFile,Spell.Number)
 Spell.Number=Temp2!
 Call DisplaySpell
Error.Resume194:
 Exit Sub
Error.Trap194:
 Resume Error.Resume194
End Sub

Sub SearchSpell
 On Local Error Goto Error.Trap195
 Call Write.Record(SpellFile,Spell.Number)
 Strng=Nul
 Out2="^ Cursor Edit "+Chr$(60)+Chr$(217)+" Exit Field  "
 Out2=Out2+"Append # sign and number for duplicate spells"
 Call StatusLine
 Call ANSI(4,33,44)
 Call ANSI(2,23,2)
 Strng="Enter Spell Name or Number: "
 Call Scrn(Strng)
 Call ANSI(4,37,40)
 Call ANSI(2,23,30)
 Strng=Space$(30)
 Call Scrn(Strng)
 Restore Data9
 Read Xcoor, Ycoor, Column, Line.Length, Row, Max.Lines, Line.Number
 Edit.Data(1)=Nul
 Call ScreenEdit
 Call SpellStatusLine
 Temp2!=Int(Val(Edit.Data(1)))
 Temp$=Lcase$(Edit.Data(1))
 If Temp2!>SFalse And Temp2!<=Lof(SpellFile)/SpellRecLen Then
    Spell.Number=Temp2!
    Call DisplaySpell
    Exit Sub
 Endif
 Temp.Index=SFalse
 Temp1=Instr(Temp$,"#")
 If Temp1 Then
    Temp.Index=Csng(Int(Val(Mid$(Temp$,Temp1+1))))
    Temp$=Left$(Temp$,Temp1-1)
 Endif
 Temp4=Len(Temp$)
 Temp!=SFalse
 Temp3!=SFalse
 For Temp2!=1! To Lof(SpellFile)/SpellRecLen
    Call Read.Record(SpellFile,Temp2!)
    Out3=Rtrim$(SpellRecord.SpellName)
    Call InstrSUB(TempX,Out3,Temp$)
    If TempX Then
       Temp3!=Temp3!+1!
       If Temp3!=1! Then
          Temp!=Temp2!
       Endif
       If Temp.Index Then
          If Temp3!=Temp.Index Then
             Spell.Number=Temp2!
             Call DisplaySpell
             Exit Sub
          Endif
       Endif
    Endif
 Next
 If Temp.Index>SFalse Then
    Strng="The spell name was not found in the spell file."
    Call ErrorMessage
    Call DisplaySpell
    Exit Sub
 Endif
 If Temp3!=SFalse Then
    Strng="The spell name was not found in the spell file."
    Call ErrorMessage
    Call DisplaySpell
    Exit Sub
 Endif
 If Temp3!=1! Then
    Spell.Number=Temp!
    Call DisplaySpell
    Exit Sub
 Endif
 Strng="There was more than one spell found."
 Call ErrorMessage
 Strng="^ Scroll Spell  "+Chr$(60)+Chr$(217)+" Select Spell"
 Out2=Nul
 Call StatusLine
 Spell.Number=Temp!
 Temp2!=Temp!
 Call Read.Record(SpellFile,Spell.Number)
 Call DisplaySpell
 Do While Lost.Carrier=False
    TempX$=Nul
    Do While TempX$=Nul
       If Lost.Carrier Then
          Exit Do
       Endif
       Call Read.Keyboard(TempX$)
       Call MouseDriver(3)
       If Mouse.Button2 Then
          TempX$=Chr$(27)
       Endif
       If Mouse.Button Then
          Call MouseCheck
          Exit Do
       Endif
    Loop
    TempX=False
    Select Case Len(TempX$)
    Case 1
       If TempX$=Chr$(13) Then
          Spell.Number=Temp2!
          Call SpellStatusLine
          Call DisplaySPell
          Exit Sub
       Endif
    Case 2
       TempX=Asc(Mid$(TempX$,2,1))
       Select Case TempX
       Case 72, 141, 152
          TempA=False
          For Temp3!=Temp2!-1! To 1! Step -1!
             Call Read.Record(SpellFile,Temp3!)
             Out3=Rtrim$(SpellRecord.SpellName)
             Call InstrSUB(TempX,Out3,Temp$)
             If TempX Then
                TempA=True
                Temp2!=Temp3!
                Spell.Number=Temp3!
                Call DisplaySpell
                Exit For
             Endif
          Next
          If TempA=False Then
             Strng="This is the first spell in the search."
             Call ErrorMessage
          Endif
       Case 80, 145, 160
          TempA=False
          For Temp3!=Temp2!+1! To Lof(SpellFile)/SpellRecLen
             Call Read.Record(SpellFile,Temp3!)
             Out3=Rtrim$(SpellRecord.SpellName)
             Call InstrSUB(TempX,Out3,Temp$)
             If TempX Then
                TempA=True
                Temp2!=Temp3!
                Spell.Number=Temp3!
                Call DisplaySpell
                Exit For
             Endif
          Next
          If TempA=False Then
             Strng="This is the last spell in the search.
             Call ErrorMessage
          Endif
       End Select
    End Select
 Loop
Error.Resume195:
 Exit Sub
Error.Trap195:
 Resume Error.Resume195
End Sub

Sub SpellStatusLine
 On Local Error Goto Error.Trap196
 Strng="^ Cursor Select "+Chr$(60)+Chr$(217)
 Strng=Strng+" Enter Choice <esc> Exit and Save ^h Help ^a Add Record"
 Out2="^n Next Spell ^q Previous Spell ^r Select Spell ^w Search Spell"
 Call StatusLine
Error.Resume196:
 Exit Sub
Error.Trap196:
 Resume Error.Resume196
End Sub

Sub DisplaySpell
 On Local Error Goto Error.Trap190
 If Spell.Number>SFalse And Spell.Number<=Lof(SpellFile)/SpellRecLen Then
    Call Read.Record(SpellFile,Spell.Number)
    For TempX=False To 21
       Call ShowSpell
    Next
    Call RedisplayField
 Endif
Error.Resume190:
 Exit Sub
Error.Trap190:
 Resume Error.Resume190
End Sub

Data8:
 Data 23,15,15,6,23,1,1
Data9:
 Data 23,30,30,30,23,1,1

Sub ShowSpell
 On Local Error Goto Error.Trap31
 Select Case TempX
 Case 0
    Call ANSI(4,37,44)
    Call ANSI(2,2,8)
    Strng=Space$(8)
    Call Scrn(Strng)
    Call ANSI(4,33,44)
    Call ANSI(2,2,2)
    Strng="Spell"+Str$(Spell.Number)
    Call Scrn(Strng)
    Call ANSI(2,19,2)
    Strng="Class Type Restrictions"
    Call Scrn(Strng)
    Call ANSI(2,9,49)
    Strng="Ingredient Casting Type"
    Call Scrn(Strng)
 Case Else
    Call ANSI(4,37,40)
    Select Case TempX
    Case 1
       Call ANSI(2,4,2)
       Strng=SpellRecord.SpellName
       Call Scrn(Strng)
    Case 2
       Call ANSI(2,6,16)
       Strng=Space$(8)
       Call Scrn(Strng)
       Call ANSI(2,6,16)
       Strng=Ltrim$(Str$(SpellRecord.Teleport))
       Call Scrn(Strng)
    Case 3
       Call ANSI(2,8,8)
       Strng=Space$(2)
       Call Scrn(Strng)
       Call ANSI(2,8,8)
       Strng=Mid$(Str$(SpellRecord.Level),2)
       Call Scrn(Strng)
    Case 4
       Call ANSI(2,8,22)
       Strng=Space$(2)
       Call Scrn(Strng)
       Call ANSI(2,8,22)
       Strng=Mid$(Str$(SpellRecord.SpellType),2)
       Call Scrn(Strng)
    Case 5
       Call ANSI(2,10,16)
       If SpellRecord.Psionic Then
          Call Scrn("Y")
       Else
          Call Scrn("N")
       Endif
    Case 6
       Call ANSI(2,12,20)
       Select Case SpellRecord.PsionicMode
       Case 1
          Strng="A"
       Case 2
          Strng="D"
       Case Else
          Strng="?"
       End Select
       Call Scrn(Strng)
    Case 7
       Call ANSI(2,13,11)
       If SpellRecord.Equation Then
          Call Scrn("Y")
       Else
          Call Scrn("N")
       Endif
       Call ANSI(2,14,2)
       Strng=Space$(40)
       Call Scrn(Strng)
       Call ANSI(2,14,2)
       Strng=Rtrim$(SpellRecord.SpellEquate)
       If Strng=Nul Then
          Strng="<none>"
       Endif
       Call Scrn(Strng)
    Case 8
       Call ANSI(2,16,2)
       Strng=Lcase$(Left$(SpellRecord.Chant,78))
       Call Scrn(Strng)
    Case 9
       Call ANSI(2,18,2)
       Strng=Left$(SpellRecord.Desc,78)
       Call Scrn(Strng)
    Case 10
       Call ANSI(2,20,10)
       If SpellRecord.ClassType And 2 Then
          Call Scrn("Y")
       Else
          Call Scrn("N")
       Endif
    Case 11
       Call ANSI(2,20,23)
       If SpellRecord.ClassType And 4 Then
          Call Scrn("Y")
       Else
          Call Scrn("N")
       Endif
    Case 12
       Call ANSI(2,20,31)
       If SpellRecord.ClassType And 8 Then
          Call Scrn("Y")
       Else
          Call Scrn("N")
       Endif
    Case 13
       Call ANSI(2,20,40)
       If SpellRecord.ClassType And 16 Then
          Call Scrn("Y")
       Else
          Call Scrn("N")
       Endif
    Case 14
       Call ANSI(2,20,50)
       If SpellRecord.ClassType And 32 Then
          Call Scrn("Y")
       Else
          Call Scrn("N")
       Endif
    Case 15
       Call ANSI(2,20,59)
       If SpellRecord.ClassType And 64 Then
          Call Scrn("Y")
       Else
          Call Scrn("N")
       Endif
    Case 16
       Call ANSI(2,20,67)
       If SpellRecord.ClassType And 128 Then
          Call Scrn("Y")
       Else
          Call Scrn("N")
       Endif
    Case 17
       Call ANSI(2,20,75)
       If SpellRecord.ClassType And 256 Then
          Call Scrn("Y")
       Else
          Call Scrn("N")
       Endif
    Case 18
       For Temp6=1 To MaxIngredients
          Temp7!=SpellRecord.Ingred(Temp6)
          Call ANSI(2,Temp6+3,49)
          If Temp7!>SFalse And Temp7!<=Lof(TreasureFile)/TreasureRecLen Then
             Call Read.Record(TreasureFile,Temp7!)
             Strng=TreasureRecord.TreasureName
             Call Scrn(Strng)
          Else
             Strng=Space$(30)
             Call Scrn(Strng)
          Endif
       Next
    Case 19
       Call ANSI(2,10,61)
       If SpellRecord.SpellFlag And Use.Spell.Type Then
          Call Scrn("Y")
       Else
          Call Scrn("N")
       Endif
    Case 20
       Call ANSI(2,12,56)
       If SpellRecord.SpellFlag And Scroll.Spell.Type Then
          Call Scrn("Y")
       Else
          Call Scrn("N")
       Endif
    Case 21
       Call ANSI(2,14,62)
       If SpellRecord.SpellFlag And Cast.Spell.Type Then
          Call Scrn("Y")
       Else
          Call Scrn("N")
       Endif
    End Select
 End Select
Error.Resume31:
 Exit Sub
Error.Trap31:
 Resume Error.Resume31
End Sub

Sub AddSpell
 On Local Error Goto Error.Trap32
 Spell.Number=Lof(SpellFile)/SpellRecLen+1!
 SpellRecord.SpellName=Nul
 SpellRecord.Teleport=False
 SpellRecord.Level=False
 SpellRecord.Chant=Nul
 SpellRecord.SpellType=False
 SpellRecord.Psionic=False
 SpellRecord.PsionicMode=False
 SpellRecord.ClassType=False
 SpellRecord.Desc=Nul
 For Temp6=1 To MaxIngredients
    SpellRecord.Ingred(Temp6)=False
 Next
 SpellRecord.SpellFlag=False
 SpellRecord.SpellEquate=Nul
 SpellRecord.Equation=False
 SpellRecord.Prefix1=Nul
 Call Write.Record(SpellFile,Spell.Number)
 Call DisplaySpell
 UserRecord.ObjectsCreated(8)=UserRecord.ObjectsCreated(8)+1#
 If User.Index Then
    Call Write.Record(UserFile,User.Index)
 Endif
Error.Resume32:
 Exit Sub
Error.Trap32:
 Resume Error.Resume32
End Sub

Sub SpellEdit
 On Local Error Goto Error.Trap40
 Restore SpellEditData
 For TempX=1 To Selection
    Read Xcoor, Ycoor, Column, Line.Length, Max.Lines, Row, Line.Number
 Next
 Select Case Selection
 Case 1
    Edit.Data(1)=SpellRecord.SpellName
 Case 2
    Edit.Data(1)=Ltrim$(Str$(SpellRecord.Teleport))
 Case 3
    Edit.Data(1)=Mid$(Str$(SpellRecord.Level),2)
 Case 4
    Call DisplaySpellTypes
    Edit.Data(1)=Mid$(Str$(SpellRecord.SpellType),2)
 Case 5
    If SpellRecord.Psionic Then
       Edit.Data(1)="Y"
    Else
       Edit.Data(1)="N"
    Endif
 Case 6
    Select Case SpellRecord.PsionicMode
    Case 1
       Edit.Data(1)="A"
    Case 2
       Edit.Data(1)="D"
    Case Else
       Edit.Data(1)="?"
    End Select
 Case 7
    If SpellRecord.Equation Then
       Edit.Data(1)="Y"
    Else
       Edit.Data(1)="N"
    Endif
 Case 8
    Edit.Data(1)=Lcase$(SpellRecord.Chant)
 Case 9
    Edit.Data(1)=SpellRecord.Desc
 Case 10 To 17
    If SpellRecord.ClassType And 2^(Selection-9) Then
       Edit.Data(1)="Y"
    Else
       Edit.Data(1)="N"
    Endif
 Case 18
    For Temp2=1 To MaxIngredients
       Temp4!=SpellRecord.Ingred(Temp2)
       Edit.Data(Temp2)=Nul
       If Temp4!>SFalse And Temp4!<=Lof(TreasureFile)/TreasureRecLen Then
          Call Read.Record(TreasureFile,Temp4!)
          Edit.Data(Temp2)=TreasureRecord.TreasureName
       Endif
    Next
 Case 19
    If SpellRecord.SpellFlag And Use.Spell.Type Then
       Edit.Data(1)="Y"
    Else
       Edit.Data(1)="N"
    Endif
 Case 20
    If SpellRecord.SpellFlag And Scroll.Spell.Type Then
       Edit.Data(1)="Y"
    Else
       Edit.Data(1)="N"
    Endif
 Case 21
    If SpellRecord.SpellFlag And Cast.Spell.Type Then
       Edit.Data(1)="Y"
    Else
       Edit.Data(1)="N"
    Endif
 End Select
 Strng="^ Cursor Edit   "
 Out2=Chr$(60)+Chr$(217)+" Exit Field"
 Call StatusLine
 Edit.Data(1)=Rtrim$(Edit.Data(1))
 Call ScreenEdit
 Select Case Selection
 Case 1
    SpellRecord.SpellName=Lcase$(Edit.Data(1))
 Case 2
    SpellRecord.Teleport=Int(Val(Edit.Data(1)))
 Case 3
    SpellRecord.Level=Int(Val(Edit.Data(1)))
 Case 4
    Tmp1=Int(Val(Edit.Data(1)))
    If Tmp1>=0 And Tmp1<=33 Then
       SpellRecord.SpellType=Tmp1
'       If Tmp1=10 Then
'          SpellRecord.Teleport=True
'       Else
'          SpellRecord.Teleport=False
'       Endif
    Endif
    Call ANSI(4,37,44)
    For TempX=2 To 15
       Call ANSI(2,TempX,31)
       Strng=Space$(49)
       Call Scrn(Strng)
    Next
    Call ANSI(4,33,44)
    For Temp2=18 To 21
       Call ANSI(2,Array.Data(Temp2,1),Array.Data(Temp2,2))
       Strng=Title.Data(Temp2)
       Call Scrn(Strng)
    Next
    TempX=False
    Call ShowSpell
    TempX=7
    Call ShowSpell
    For TempX=17 To 21
       Call ShowSpell
    Next
 Case 5
    If Ucase$(Edit.Data(1))="Y" Then
       SpellRecord.SpellType=15
       SpellRecord.Psionic=True
       If SpellRecord.PsionicMode=False Then
          SpellRecord.PsionicMode=1
       Endif
    Endif
    If Ucase$(Edit.Data(1))="N" Then
       SpellRecord.SpellType=False
       SpellRecord.PsionicMode=False
       SpellRecord.Psionic=False
    Endif
    TempX=4
    Call ShowSpell
    TempX=6
    Call ShowSpell
 Case 6
    If Ucase$(Edit.Data(1))="A" Then
       SpellRecord.Psionic=True
       SpellRecord.PsionicMode=1
       SpellRecord.SpellType=15
    Else
       If Ucase$(Edit.Data(1))="D" Then
          SpellRecord.Psionic=True
          SpellRecord.PsionicMode=2
          SpellRecord.SpellType=15
       Else
          SpellRecord.Psionic=False
          SpellRecord.PsionicMode=False
          SpellRecord.SpellType=0
       Endif
    Endif
    TempX=4
    Call ShowSpell
    TempX=5
    Call ShowSpell
 Case 7
    If Ucase$(Edit.Data(1))="Y" Then
       Restore SpellEditData2
       Read Xcoor, Ycoor, Column, Line.Length, Max.Lines, Row, Line.Number
       If Rtrim$(SpellRecord.SpellEquate)=Nul Then
          Call ANSI(4,37,40)
          Call ANSI(2,14,2)
          Strng=Space$(40)
          Call Scrn(Strng)
       Endif
       Edit.Data(1)=Rtrim$(SpellRecord.SpellEquate)
       Strng="^ Cursor Edit   "
       Out2=Chr$(60)+Chr$(217)+" Exit Field"
       Call StatusLine
       Call ScreenEdit
       Strng=Rtrim$(Edit.Data$(1))
       If Len(Strng) Then
          SpellRecord.Equation=True
          SpellRecord.SpellEquate=Ucase$(Edit.Data$(1))
       Else
          SpellRecord.Equation=False
          SpellRecord.SpellEquate=Nul
       Endif
    Else
       If Ucase$(Edit.Data(1))="N" Then
          SpellRecord.Equation=False
          SpellRecord.SpellEquate=Nul
       Endif
    Endif
    TempX=7
    Call ShowSpell
 Case 8
    SpellRecord.Chant=Ucase$(Edit.Data(1))
 Case 9
    SpellRecord.Desc=Edit.Data(1)
 Case 10 To 17
    If Ucase$(Edit.Data(1))="N" Then
       SpellRecord.ClassType=SpellRecord.ClassType And Not 2^(Selection-9)
    Endif
    If Ucase$(Edit.Data(1))="Y" Then
       SpellRecord.ClassType=SpellRecord.ClassType Or 2^(Selection-9)
    Endif
 Case 18
    For Temp2=1 To MaxIngredients
       Temp1!=SFalse
       Edit.Data(Temp2)=Rtrim$(Edit.Data(Temp2))
       If Edit.Data(Temp2)<>Nul Then
          Edit.Data(Temp2)=Lcase$(Edit.Data(Temp2))
          For Temp3!=1! To Lof(TreasureFile)/TreasureRecLen
             Call Read.Record(TreasureFile,Temp3!)
             If Left$(TreasureRecord.TreasureName, _
             Len(Edit.Data(Temp2)))=Edit.Data(Temp2) Then
                Temp1!=Temp3!
                Exit For
             Endif
          Next
       Endif
       SpellRecord.Ingred(Temp2)=Temp1!
    Next
 Case 19
    If Ucase$(Edit.Data(1))="Y" Then
       SpellRecord.SpellFlag=SpellRecord.SpellFlag Or Use.Spell.Type
    Else
       SpellRecord.SpellFlag=SpellRecord.SpellFlag And Not Use.Spell.Type
    Endif
 Case 20
    If Ucase$(Edit.Data(1))="Y" Then
       SpellRecord.SpellFlag=SpellRecord.SpellFlag Or Scroll.Spell.Type
    Else
       SpellRecord.SpellFlag=SpellRecord.SpellFlag And Not Scroll.Spell.Type
    Endif
 Case 21
    If Ucase$(Edit.Data(1))="Y" Then
       SpellRecord.SpellFlag=SpellRecord.SpellFlag Or Cast.Spell.Type
    Else
       SpellRecord.SpellFlag=SpellRecord.SpellFlag And Not Cast.Spell.Type
    Endif
 End Select
Error.Resume40:
 Exit Sub
Error.Trap40:
 Resume Error.Resume40
End Sub

SpellEditData:
 Data 4,2,2,30,1,4,1
 Data 6,16,16,8,1,6,1
 Data 8,8,8,2,1,8,1
 Data 8,22,22,2,1,8,1
 Data 10,16,16,1,1,10,1
 Data 12,20,20,1,1,12,1
 Data 13,11,11,1,1,13,1
 Data 16,2,2,78,1,16,1
 Data 18,2,2,78,1,18,1
 Data 20,10,10,1,1,20,1
 Data 20,23,23,1,1,20,1
 Data 20,31,31,1,1,20,1
 Data 20,40,40,1,1,20,1
 Data 20,50,50,1,1,20,1
 Data 20,59,59,1,1,20,1
 Data 20,67,67,1,1,20,1
 Data 20,75,75,1,1,20,1
 Data 4,49,49,30,5,4,1
 Data 10,61,61,1,1,10,1
 Data 12,56,56,1,1,12,1
 Data 14,62,62,1,1,14,1

SpellEditData2:
 Data 14,2,2,40,1,14,1

Sub SpellSelect
 On Local Error Goto Error.Trap68
 Next.Field=False
 If TempX$=Chr$(9) Then
    TempX=77
 Endif
 Select Case TempX
 Case 15, 75, 155, 115
    Select Case Selection
    Case 4
       Next.Field=3
    Case 10 To 17
       Next.Field=Selection-1
    Case 18
       Next.Field=1
    Case 19 To 21
       Next.Field=Selection-14
    End Select
 Case 77, 157, 116
    Select Case Selection
    Case 1
       Next.Field=18
    Case 3
       Next.Field=4
    Case 10 To 16
       Next.Field=Selection+1
    Case 5 To 7
       Next.FIeld=Selection+14
    End Select
 Case 72, 141, 152
    Select Case Selection
    Case 2 To 16, 19 To 21
       Next.Field=Selection-1
    Case 17
       Next.Field=21
    End Select
 Case 80, 145, 160
    Select Case Selection
    Case 1 To 16, 18 To 20
       Next.Field=Selection+1
    Case 21
       Next.FIeld=17
    End Select
 Case 71, 73, 119, 132
    Select Case Selection
    Case 2 To 10
       Next.Field=1
    Case 11 To 17
       Next.Field=10
    Case 19 To 21
       Next.Field=18
    End Select
 Case 79, 81, 117, 118
    Select Case Selection
    Case 1 To 9
       Next.Field=10
    Case 10 To 16
       Next.Field=17
    Case 18 To 20
       Next.Field=21
    End Select
 End Select
 Call ShowField
Error.Resume68:
 Exit Sub
Error.Trap68:
 Resume Error.Resume68
End Sub

Sub DisplaySpellTypes
 On Local Error Goto Error.Trap132
 ' MakeBox(x1,y1,x2,y2)
 Call MakeBox(3,31,15,79)
 Call ANSI(4,37,44)
 Call ANSI(2,2,33)
 Strng=Space$(45)
 Call Scrn(Strng)
 Call ANSI(2,2,47)
 Strng="Spell Type Numbers"
 Call Scrn(Strng)
 Call ANSI(2,4,32)
 Strng=Space$(47)
 Call Scrn(Strng)
 Call ANSI(2,4,33)
 Strng="1)Enchant     12)Turn Undead   23)Invisibility"
 Call Scrn(Strng)
 Call ANSI(2,5,32)
 Strng=Space$(47)
 Call Scrn(Strng)
 Call ANSI(2,5,33)
 Strng="2)Offense     13)Pass Door     24)Identify"
 Call Scrn(Strng)
 Call ANSI(2,6,32)
 Strng=Space$(47)
 Call Scrn(Strng)
 Call ANSI(2,6,33)
 Strng="3)Bless       14)Conjure       25)Enlighten"
 Call Scrn(Strng)
 Call ANSI(2,7,32)
 Strng=Space$(47)
 Call Scrn(Strng)
 Call ANSI(2,7,33)
 Strng="4)Wish        15)Psionic       26)Illuminate"
 Call Scrn(Strng)
 Call ANSI(2,8,32)
 Strng=Space$(47)
 Call Scrn(Strng)
 Call ANSI(2,8,33)
 Strng="5)Poison      16)Detect Lock   27)Psyche"
 Call Scrn(Strng)
 Call ANSI(2,9,32)
 Strng=Space$(47)
 Call Scrn(Strng)
 Call ANSI(2,9,33)
 Strng="6)Vigor       17)Detect Evil   28)Telepathy"
 Call Scrn(Strng)
 Call ANSI(2,10,32)
 Strng=Space$(47)
 Call Scrn(Strng)
 Call ANSI(2,10,33)
 Strng="7)Heal        18)Detect Trap   29)Curse"
 Call Scrn(Strng)
 Call ANSI(2,11,32)
 Strng=Space$(47)
 Call Scrn(Strng)
 Call ANSI(2,11,33)
 Strng="8)Curepoison  19)Intoxicate    30)Damnate"
 Call Scrn(Strng)
 Call ANSI(2,12,32)
 Strng=Space$(47)
 Call Scrn(Strng)
 Call ANSI(2,12,33)
 Strng="9)Level Drain 20)Set Trap      31)Resurrect"
 Call Scrn(Strng)
 Call ANSI(2,13,32)
 Strng=Space$(47)
 Call Scrn(Strng)
 Call ANSI(2,13,33)
 Strng="10)Teleport   21)Hide          32)GrantWish"
 Call Scrn(Strng)
 Call ANSI(2,14,32)
 Strng=Space$(47)
 Call Scrn(Strng)
 Call ANSI(2,14,33)
 Strng="11)Befuddle   22)Search        33)StealWish"
 Call Scrn(Strng)
Error.Resume132:
 Exit Sub
Error.Trap132:
 Resume Error.Resume132
End Sub
