 Rem File: DndeditB.bas
 Rem Sub: EditMonClass
 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,"b")
    Close #TempFile1
    If Var=False Then
       Call Terminate.Program(True)
       End
    Endif
 Endif
Main.Resume:
 Call EditMonClass
 If Chained2 Then
    Chain DND.Path+"DNDEDIT.EXE"
 Endif
 Call Terminate.Program(True)
 End
Main.Error:
 Resume Main.Resume

Sub EditMonClass
 On Local Error Goto Error.Trap120
 MonClass.Number=1
 If Lof(MonClassFile)=SFalse Then
    Call AddMonClass
 Endif
 Call MonClassScreen
 Call MonClassStatusLine
 Call DisplayMonClass
 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 MonClassMouseButton
          If Len(TempX$) Then
             Exit Do
          Endif
       Endif
       If Mouse.Row Or Mouse.Column Then
          Call MonClassMouseSelect
       Endif
    Loop
    TempX=False
    Select Case Len(TempX$)
    Case 1
       TempX=Asc(TempX$)
       Select Case TempX
       Case 1
          Call AddMonClass
       Case 8
          Call Help(8)
          Call MonClassScreen
          Call MonClassStatusLine
          Call DisplayMonClass
       Case 13
          Call EditSelectedMonClass
       Case 14
          Call NextMonClass
       Case 17
          Call PreviousMonClass
       Case 18
          Call SelectNextMonClass
          Call MonClassStatusLine
       Case 23
          Call SearchMonClass
       Case 27
          Call Write.Record(MonClassFile,MonClass.Number)
          Exit Sub
       End Select
    Case 2
       TempX=Asc(Mid$(TempX$,2,1))
       If TempX=0 Then
          Call Write.Record(MonClassFile,MonClass.Number)
          Exit Do
       Endif
       Call MonClassSelect
    End Select
 Loop
Error.Resume120:
 Exit Sub
Error.Trap120:
 Resume Error.Resume120
End Sub

Sub SelectNextMonClass
 On Local Error Goto Error.Trap121
 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 MonClass: "
 Call Scrn(Strng)
 Call ANSI(4,37,40)
 Call ANSI(2,23,18)
 Strng=Space$(6)
 Call Scrn(Strng)
 Call ANSI(4,37,44)
 Call ANSI(2,23,27)
 Strng="(1-"+Mid$(Str$(Lof(MonClassFile)/MonClassRecLen),2)+")"
 Multiplier=Len(Strng)+27
 Strng=Strng+" (+/-/x)"
 Call Scrn(Strng)
 Restore MonClassData2
 Read Xcoor, Ycoor, Column, Line.Length, Max.Lines, Row, Line.Number
 Edit.Data(1)=Nul
 Call ScreenEdit
 Multiplier=False
 Temp2!=Int(Val(Edit.Data(1)))
 If Temp2!<=SFalse Or Temp2!>Lof(MonClassFile)/MonClassRecLen Then
    Strng="The monclass number is not within the monclass file range."
    Call MonClassErrorMessage
    Exit Sub
 Endif
 Call Write.Record(MonClassFile,MonClass.Number)
 MonClass.Number=Temp2!
 Call DisplayMonClass
Error.Resume121:
 Exit Sub
Error.Trap121:
 Resume Error.Resume121
End Sub

Sub MonClassMouseSelect
 On Local Error Goto Error.Trap84
 For Var=1 To 10
    If Mouse.Row=Var*2+1 Then
       If Mouse.Column>=2 Then
          If Mouse.Column<=8 Then
             If Var<>Selection Then
                Next.Field=Var
                Call MonClassSelectDisplay
             Endif
             Exit Sub
          Endif
       Endif
    Endif
 Next
Error.Resume84:
 Exit Sub
Error.Trap84:
 Resume Error.Resume84
End Sub

Sub MonClassMouseButton
 On Local Error Goto Error.Trap85
 For Var=1 To 10
    If Mouse.Row=Var*2+1 Then
       If Mouse.Column>=2 Then
          If Mouse.Column<=8 Then
             If Var=Selection Then
                Selection=Var
                TempX$=Chr$(13)
             Endif
             Exit Sub
          Endif
       Endif
    Endif
 Next
 Call MouseCheck
Error.Resume85:
 Exit Sub
Error.Trap85:
 Resume Error.Resume85
End Sub

Sub EditSelectedMonClass
 On Local Error Goto Error.Trap86
 Strng=Nul
 Out2="^ Cursor Edit "+Chr$(60)+Chr$(217)+" Exit Field "
 Call StatusLine
 Xcoor=Selection*2+1
 Row=Xcoor
 Restore MonClassData1
 Read Ycoor, Column, Line.Length, Max.Lines, Line.Number
 Edit.Data(1)=Mid$(Str$(MonClassRecord.Monsters(Selection)),2)
 Call ScreenEdit
 MonClassRecord.Monsters(Selection)=Int(Val(Edit.Data(1)))
 Call Write.Record(MonClassFile,MonClass.Number)
 TempX=Selection
 Call ShowMonClass
 Call MonClassStatusLine
 Call MonClassField
Error.Resume86:
 Exit Sub
Error.Trap86:
 Resume Error.Resume86
End Sub

Sub SearchMonClass
 On Local Error Goto Error.Trap87
 Call Write.Record(MonClassFile,MonClass.Number)
 Strng=Nul
 Out2="^ Cursor Edit "+Chr$(60)+Chr$(217)+" Exit Field  "
 Out2=Out2+"Append # sign and number for duplicate monsters"
 Call StatusLine
 Call ANSI(4,33,44)
 Call ANSI(2,23,2)
 Strng="Enter Monster Name or Number: "
 Call Scrn(Strng)
 Call ANSI(4,37,40)
 Call ANSI(2,23,32)
 Strng=Space$(30)
 Call Scrn(Strng)
 Restore MonClassData3
 Read Xcoor, Ycoor, Column, Line.Length, Max.Lines, Row, Line.Number
 Edit.Data(1)=Nul
 Call ScreenEdit
 Call MonClassStatusLine
 Temp2!=Int(Val(Edit.Data(1)))
 If Temp2!>SFalse Then
    For Temp4!=1! To Lof(MonClassFile)/MonClassRecLen
       Call Read.Record(MonClassFile,Temp4!)
       For Temp3!=1! To MaxMonClass
          Temp5!=MonClassRecord.Monsters(Temp3!)
          If Temp5!>SFalse And Temp5!<=Lof(MonsterFile)/MonsterRecLen Then
             If Temp5!=Temp2! Then
                MonClass.Number=Temp4!
                Call DisplayMonClass
                Exit Sub
             Endif
          Endif
       Next
    Next
 Endif
 Temp$=Lcase$(Edit.Data(1))
 Temp.Index=SFalse
 Temp1=Instr(Temp$,"#")
 If Temp1 Then
    Temp.Index=Csng(Int(Val(Mid$(Temp$,Temp1+1))))
    Temp$=Left$(Temp$,Temp1-1)
 Endif
 Temp6=Len(Temp$)
 Temp5!=SFalse
 For Temp2!=1! To Lof(MonClassFile)/MonClassRecLen
    Call Read.Record(MonClassFile,Temp2!)
    For Temp3=1 To MaxMonClass
       Temp4!=MonClassRecord.Monsters(Temp3)
       If Temp4!>SFalse And Temp4!<=Lof(MonsterFile)/MonsterRecLen Then
          Call Read.Record(MonsterFile,Temp4!)
          Out3=Rtrim$(MonsterRecord.MonsterName)
          Call InstrSUB(TempX,Out3,Temp$)
          If TempX Then
             Temp5!=Temp5!+1!
             If Temp5!=Temp.Index Or Temp.Index=SFalse Then
                MonClass.Number=Temp2!
                Call DisplayMonClass
                Exit Sub
             Endif
          Endif
       Endif
    Next
 Next
 Strng="The monster name was not found in the monclass file."
 Call MonClassErrorMessage
 Call Read.Record(MonClassFile,MonClass.Number)
Error.Resume87:
 Exit Sub
Error.Trap87:
 Resume Error.Resume87
End Sub

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

Sub MonClassErrorMessage
 On Local Error Goto Error.Trap91
 TempB$=Strng+" Press <esc>."
 Call ANSI(4,37,44)
 Call ANSI(2,23,2)
 Strng=Space$(78)
 Call Scrn(Strng)
 Call ANSI(2,24,2)
 Strng=Space$(78)
 Call Scrn(Strng)
 Call ANSI(2,24,2)
 Call Scrn(TempB$)
 TempB$=" "+TempB$
 TempX$=Nul
 Do While TempX$<>Chr$(27)
    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
    Endif
 Loop
 Call MonClassStatusLine
 Call MonClassField
Error.Resume91:
 Exit Sub
Error.Trap91:
 Resume Error.Resume91
End Sub

Sub NextMonClass
 On Local Error Goto Error.Trap92
 If MonClass.Number>=Lof(MonClassFile)/MonClassRecLen Then
    Strng="This is the last monclass in the monclass file."
    Call MonClassErrorMessage
 Else
    Call Write.Record(MonClassFile,MonClass.Number)
    MonClass.Number=MonClass.Number+1!
    Call DisplayMonClass
 Endif
Error.Resume92:
 Exit Sub
Error.Trap92:
 Resume Error.Resume92
End Sub

Sub PreviousMonClass
 On Local Error Goto Error.Trap93
 If MonClass.Number<=1 Then
    Strng="This is the first monclass in the monclass file."
    Call MonClassErrorMessage
    Exit Sub
 Endif
 Call Write.Record(MonClassFile,MonClass.Number)
 MonClass.Number=MonClass.Number-1!
 Call DisplayMonClass
Error.Resume93:
 Exit Sub
Error.Trap93:
 Resume Error.Resume93
End Sub

Sub AddMonClass
 On Local Error Goto Error.Trap94
 MonClass.Number=Lof(MonClassFile)/MonClassRecLen+1!
 For Temp2=1 To MaxMonClass
    MonClassRecord.Monsters(Temp2)=SFalse
 Next
 Call Write.Record(MonClassFile,MonClass.Number)
 Call DisplayMonClass
 UserRecord.ObjectsCreated(2)=UserRecord.ObjectsCreated(2)+1#
 If User.Index Then
    Call Write.Record(UserFile,User.Index)
 Endif
Error.Resume94:
 Exit Sub
Error.Trap94:
 Resume Error.Resume94
End Sub

Sub DisplayMonClass
 On Local Error Goto Error.Trap95
 If MonClass.Number>False And _
 MonClass.Number<=Lof(MonClassFile)/MonClassRecLen Then
    Call Read.Record(MonClassFile,MonClass.Number)
    For TempX=False To 10
       Call ShowMonClass
    Next
 Endif
 Call MonClassField
Error.Resume95:
 Exit Sub
Error.Trap95:
 Resume Error.Resume95
End Sub

Sub MonClassScreen
 On Local Error Goto Error.Trap96
 Out3="Sysop MonClass Edit"
 Call DisplayBorder(Out3)
 Call ANSI(4,37,40)
 Call ANSI(2,3,2)
 Strng="Monster 1"
 Call Scrn(Strng)
 Call ANSI(4,37,44)
 For Temp2=2 To 10
    Call ANSI(2,Temp2*2+1,2)
    Strng="Monster "+Mid$(Str$(Temp2),2)
    Call Scrn(Strng)
 Next
 Selection=1
 Call ANSI(4,33,44)
 Call ANSI(2,2,22)
 Strng="Hits"
 Call Scrn(Strng)
 Call ANSI(2,2,28)
 Strng="Lvl"
 Call Scrn(Strng)
 Call ANSI(2,2,34)
 Strng="Exp"
 Call Scrn(Strng)
 Call ANSI(2,2,57)
 Strng="P D B P F"
 Call Scrn(Strng)
 Call ANSI(2,2,67)
 Strng="P)oison"
 Call Scrn(Strng)
 Call ANSI(2,3,67)
 Strng="D)rain"
 Call Scrn(Strng)
 Call ANSI(2,4,67)
 Strng="B)lock"
 Call Scrn(Strng)
 Call ANSI(2,5,67)
 Strng="P)revent"
 Call Scrn(Strng)
 Call ANSI(2,6,67)
 Strng="F)ollow"
 Call Scrn(Strng)
Error.Resume96:
 Exit Sub
Error.Trap96:
 Resume Error.Resume96
End Sub

Sub ShowMonClass
 On Local Error Goto Error.Trap119
 If TempX=False Then
    Call ANSI(4,33,44)
    Call ANSI(2,2,11)
    Strng=Space$(8)
    Call Scrn(Strng)
    Call ANSI(2,2,2)
    Strng="MonClass"+Str$(MonClass.Number)
    Call Scrn(Strng)
 Endif
 If TempX>False Then
    Temp3!=MonClassRecord.Monsters(TempX)
    If Temp3!<=SFalse Or Temp3!>Lof(MonsterFile)/MonsterRecLen Then
       MonClassRecord.Monsters(TempX)=SFalse
       If Temp3!>SFalse Then
          Strng="The monster number is not within the monster file range."
          Call MonClassErrorMessage
       Endif
       Call ANSI(4,37,40)
       Call ANSI(2,TempX*2+1,13)
       Strng="0       "
       Call Scrn(Strng)
       Call ANSI(4,33,44)
       Call ANSI(2,TempX*2+2,2)
       Strng=Space$(58)
       Call Scrn(Strng)
    Else
       Call ANSI(4,37,40)
       Call ANSI(2,TempX*2+1,13)
       Strng=Space$(8)
       Call Scrn(Strng)
       Call ANSI(2,TempX*2+1,13)
       Strng=Mid$(Str$(Temp3!),2)
       Call Scrn(Strng)
       Call ANSI(4,33,44)
       Call Read.Record(MonsterFile,Temp3!)
       Temp1=TempX*2+2
       Call ANSI(2,Temp1,2)
       Strng=MonsterRecord.MonsterName
       Call Scrn(Strng)
       Temp1=Temp1-1
       Call ANSI(2,Temp1,22)
       Strng=Space$(5)
       Call Scrn(Strng)
       Call ANSI(2,Temp1,22)
       Strng=Mid$(Str$(MonsterRecord.Hits),2)
       Call Scrn(Strng)
       Call ANSI(2,Temp1,28)
       Strng=Space$(5)
       Call Scrn(Strng)
       Call ANSI(2,Temp1,28)
       Strng=Mid$(Str$(MonsterRecord.Level),2)
       Call Scrn(Strng)
       Call ANSI(2,Temp1,34)
       Strng=Space$(16)
       Call Scrn(Strng)
       Call ANSI(2,Temp1,34)
       Strng=Mid$(Str$(MonsterRecord.Experience),2)
       Call Scrn(Strng)
       Call ANSI(2,Temp1,57)
       If MonsterRecord.Poison Then
          Call Scrn("Y")
       Else
          Call Scrn("N")
       Endif
       Call ANSI(2,Temp1,59)
       If MonsterRecord.LevelDrain Then
          Call Scrn("Y")
       Else
          Call Scrn("N")
       Endif
       Call ANSI(2,Temp1,61)
       If MonsterRecord.Block Then
          Call Scrn("Y")
       Else
          Call Scrn("N")
       Endif
       Call ANSI(2,Temp1,63)
       If MonsterRecord.Prevent Then
          Call Scrn("Y")
       Else
          Call Scrn("N")
       Endif
       Call ANSI(2,Temp1,65)
       If MonsterRecord.Follow Then
          Call Scrn("Y")
       Else
          Call Scrn("N")
       Endif
    Endif
 Endif
Error.Resume119:
 Exit Sub
Error.Trap119:
 Resume Error.Resume119
End Sub

MonClassData1:
 Data 13,13,8,1,1
MonClassData2:
 Data 23,18,18,6,1,23,1
MonClassData3:
 Data 23,32,32,30,1,23,1

Sub MonClassField
 On Local Error Goto Error.Trap34
 Call ANSI(4,37,45)
 Call ANSI(2,Selection*2+1,2)
 Strng="Monster"+Str$(Selection)
 Call Scrn(Strng)
Error.Resume34:
 Exit Sub
Error.Trap34:
 Resume Error.Resume34
End Sub

Sub MonClassSelect
 On Local Error Goto Error.Trap123
 Next.Field=False
 Select Case TempX
 Case 72, 141, 152
    If Selection>1 Then
       Next.Field=Selection-1
    Endif
 Case 80, 145, 160
    If Selection<10 Then
       Next.Field=Selection+1
    Endif
 Case 71, 119
    If Selection<>1 Then
       Next.Field=1
    Endif
 Case 79, 117
    If Selection<>10 Then
       Next.Field=10
    Endif
 Case 73, 132
    If Selection<>1 Then
       Next.Field=1
    Endif
 Case 81, 118
    If Selection<>10 Then
       Next.Field=10
    Endif
 End Select
 Call MonClassSelectDisplay
Error.Resume123:
 Exit Sub
Error.Trap123:
 Resume Error.Resume123
End Sub

Sub MonClassSelectDisplay
 On Local Error Goto Error.Trap124
 If Next.Field Then
    Call ANSI(4,33,44)
    Call ANSI(2,Selection*2+1,2)
    Strng="Monster"+Str$(Selection)
    Call Scrn(Strng)
    Selection=Next.Field
    Call MonClassField
 Endif
Error.Resume124:
 Exit Sub
Error.Trap124:
 Resume Error.Resume124
End Sub
