 Rem File: Dndsub3 for Dndbbs Version v5.0a Release r2.0 Tweak t5.0a
 Rem $Include: 'dndbbs.inc'
Sub Get.Ring.Hits(Var1,Var2)
 On Local Error Goto ErrorTrap15a
 If Var1 Then
    Var3=4
    Strng2="left"
 Else
    Var3=9
    Strng2="right"
 Endif
 Select Case Var2
 Case 7
    Strng3="inventory damage"
 Case 8
    Strng3="fumble"
 Case 9
    Strng3="teleport"
 End Select
 Strng="Your "+Strng2+" ring absorbs the "+Strng3+" spell!"
 Call IO.O
 ' decrement ring hits.
 Var=UserRecord.Weapon(Var3).Charges-1
 UserRecord.Weapon(Var3).Charges=Var
 If Var<=False Then
    Strng="Your "+Strng2+" ring disintegrated!"
    Call IO.O
    UserRecord.Weapon(Var3).Index=SFalse
    UserRecord.Weapon(Var3).Charges=False
    UserRecord.Weapon(Var3).Plus=False
 Endif
ErrorResume15a:
 Exit Sub
ErrorTrap15a:
 Resume ErrorResume15a
End Sub

Sub Hit.Player(Var)
 On Local Error Goto ErrorTrap16
 If Var>False Then
    If UserRecord.Fatigue-Var>=False Then
       UserRecord.Fatigue=UserRecord.Fatigue-Var
       Strng=Strng+Str$(Var)+" fatigue points!"
       Call IO.O
       Exit Sub
    Endif
    Var=Var-UserRecord.Fatigue
    If UserRecord.Fatigue>False Then
       Strng=Strng+Str$(UserRecord.Fatigue)+" fatigue and"
    Endif
    UserRecord.Fatigue=False
 Endif
 Var1=Abs(Var)
 If Var1>False Then
    Strng=Strng+Str$(Var1)+" vitality points!"
    Call IO.O
    If UserRecord.Vitality-Var1<=False Then
       UserRecord.Vitality=False
       Message1="You were just killed!"
       Strng="was killed by "+Prefix2+Out3
       Call Update.DayFile(Strng,False,1)
       Call Player.Died
       Exit Sub
    Endif
    UserRecord.Vitality=UserRecord.Vitality-Var1
 Endif
ErrorResume16:
 Exit Sub
ErrorTrap16:
 Resume ErrorResume16
End Sub

Sub Fumble
 On Local Error Goto ErrorTrap17
 If UserRecord.Weapon(7).Index Or UserRecord.Weapon(5).Index Then
    Strng="You fumbled! "
    Out2="You dropped your "
    Graphics.Off=True
    Carriage.Return=True
    Call IO.O
    Var1!=UserRecord.Weapon(5).Index
    If Var1! Then
       Call Read.Record(TreasureFile,Var1!)
       Out4=TreasureRecord.ShortName
       Out4=Rtrim$(Out4)
       Out4=Lcase$(Out4)
       Var2=UserRecord.Weapon(5).Charges
       Call Add.Inventory(Var1!,Var2)
       UserRecord.Weapon(5).Index=SFalse
       UserRecord.Weapon(5).Plus=False
       Call Discard(Temp0!,False)
       If UserRecord.Weapon(7).Index Then
          Strng=" and "+Out4
       Else
          Strng=Out2+Out4+"!"
       Endif
    Else
       Strng=Nul
    Endif
    Var1!=UserRecord.Weapon(7).Index
    If Var1! Then
       Call Read.Record(TreasureFile,Var1!)
       Out4=TreasureRecord.ShortName
       Out4=Rtrim$(Out4)
       Out4=Lcase$(Out4)
       Var2=UserRecord.Weapon(7).Charges
       Call Add.Inventory(Var1!,Var2)
       UserRecord.Weapon(7).Index=SFalse
       UserRecord.Weapon(7).Plus=False
       Call Discard(Temp0!,False)
       Strng=Out2+Out4+Strng+"!"
    Endif
    Call IO.O
    Graphics.Off=False
 Endif
ErrorResume17:
 Exit Sub
ErrorTrap17:
 Resume ErrorResume17
End Sub

Sub Player.Died
 On Local Error Goto ErrorTrap25
 Gosub Get.Config1
 Call Remove.Vehicle
 UserRecord.Poison=False
 Strng=Message1
 If Len(Strng) Then
    Call IO.O
 Endif
 UserRecord.TimesDied=UserRecord.TimesDied+1#
 Call Write.Record(UserFile,User.Index)
 If Normal.User=False Then
    Strng="You were resurrected!"
    Call IO.O
    Gosub Died.Times
    If GuestLogin Then
       Next.Room=GuestRecord.GuestRoomResurrect
    Else
       Next.Room=Int(Val(Config3(24))+.5)
    Endif
    Action.Recurse=0
    Call Enter.Room
    If New.Room Then
       Call Enter.New.Room
    Endif
    Exit Sub
 Endif
 Temp4=UserRecord.Stats(5)
 If Temp4>1 Then
    UserRecord.Stats(5)=Temp4-1
    Out2=Stat(5)
    Out2=Rtrim$(Out2)
    Out2=Lcase$(Out2)
    Strng="lost one "+Out2+" point"
    Call Update.DayFile(Strng,False,2)
    Strng="You "+Lcase$(Strng)+"!"
    Call IO.O
 Endif
 Temp4=UserRecord.Stats(6)
 If Temp4>1 Then
    UserRecord.Stats(6)=Temp4-1
    Out2=Stat(6)
    Out2=Rtrim$(Out2)
    Out2=Lcase$(Out2)
    Strng="lost one "+Out2+" point"
    Call Update.DayFile(Strng,False,2)
    Strng="You "+Lcase$(Strng)+"!"
 Endif
 If Rnd>.5 Then
    Temp2=Int(Rnd*4+1)
    Temp4=UserRecord.Stats(Temp2)
    If Temp4>1 Then
       UserRecord.Stats(Temp2)=Temp4-1
       Out2=Stat(Temp2)
       Out2=Rtrim$(Out2)
       Out2=Lcase$(Out2)
       Strng="lost one "+Out2+" point"
       Call Update.DayFile(Strng,False,2)
       Strng="You "+Lcase$(Strng)+"!"
    Endif
 Endif
 UserRecord.Gold=Config2(32)
 Gosub Died.Times
 UserRecord.Poison=False
 UserRecord.First=SFalse
 UserRecord.Last=SFalse
 If Config2(108) Then
    Call Drop.All.UserContainers
    Weight=False
    Call Clear.UserWeapons
    Call Drop.All.UserItems
    Call Clear.UserInv
 Endif
 UserRecord.Fatigue=False
 UserRecord.Vitality=False
 UserRecord.Magic=False
 UserRecord.Psionic=False
 ' resurrection room
 If GuestLogin Then
    Room=GuestRecord.GuestRoomResurrect
    Next.Room=GuestRecord.GuestRoomResurrect
 Else
    Room=Int(Val(Config3(24))+.5)
    Next.Room=Int(Val(Config3(24))+.5)
 Endif
 Out2="Has just died!"
 If Node>False Then
    Call Send.Mess(4,SFalse,SFalse,Out2)
 Endif
 Temp#=(Int(Rnd*10+10)+UserRecord.Stats(5)/2)>20
 If Temp#=DFalse Then
    Strng="Constitution roll failed!"
    Call IO.O
    Strng=Nul
    Temp1=UserRecord.Level
    If Temp1>=1 Then
       Temp1=Int(Temp1/2+.5)
    Else
       Temp1=False
    Endif
    Select Case Temp1
    Case 1 To 10
       Strng="lost "+Rtrim$(Numeral(Temp1))
    Case Is>10
       Strng="lost"+Str$(Temp1)
    End Select
    Select Case Temp1
    Case 1
       Strng=Strng+" level"
    Case Is>1
       Strng=Strng+" levels"
    End Select
    If Len(Strng) Then
       Call Update.DayFile(Strng,False,2)
       Strng="You "+Lcase$(Strng)+"!"
       Call IO.O
    Endif
    UserRecord.Level=Int(UserRecord.Level/2)
    Strng="You were not resurrected!"
    Call IO.O
    If Config2(39) Then
       Call Hang.Up(9)
    Endif
 Else
    UserRecord.Level=UserRecord.Level-1
    Strng="lost one level"
    Call Update.DayFile(Strng,False,2)
    Strng="You "+Lcase$(Strng)+"!"
    Call IO.O
    Strng="You were resurrected!"
    Call IO.O
    If UserRecord.Stats(5)<=1 Then
       Strng="Except your constitution failed!"
       Call IO.O
       UserRecord.Level=1
    Endif
 Endif
 Call Zero.Stats
 Action.Recurse=0
 Call Enter.Room
 If New.Room Then
    Call Enter.New.Room
 Endif
 Exit Sub
' reward death
Died.Times:
 If UserRecord.TimesDied > 0# Then
    If (UserRecord.TimesDied MOD Option1#) = 0# Then
       Call Amount(UserRecord.TimesDied,Var$)
       Call Amount(Option2#,Var2$)
       Strng="For dying"+Var$+" times you earn"+Var2$+" gold!"
       Call IO.O
       UserRecord.Gold=UserRecord.Gold+Option2#
       Strng="was rewarded for dying"
       Call Update.DayFile(Strng,False,2)
    Endif
 Endif
 Return
Get.Config1:
 Option1#=10#
 Option2#=1000#
 VarX=0
 Do
    VarX=VarX+1
    If VarX>Options.Lines Then
       Exit Do
    Endif
    Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
    If Ucase$(Var$)="[TRAIN]" Then
       Do
          VarX=VarX+1
          If VarX>Options.Lines Then
             Return
          Endif
          Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
          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)))
             Select Case Lcase$(Var2$)
             Case "times.died.counter"
                If Int(Val(Var3$)+.5)>0# Then
                   Option1#=Int(Val(Var3$)+.5)
                Endif
             Case "times.died.reward"
                If Int(Val(Var3$)+.5)>0# Then
                   Option2#=Int(Val(Var3$)+.5)
                Endif
             End Select
          Endif
       Loop
    Endif
 Loop
 Return
ErrorResume25:
 Exit Sub
ErrorTrap25:
 Resume ErrorResume25
End Sub

Sub Drop.All.UserItems
 On Local Error Goto ErrorTrap25a
 For Temp1!=1! To Lof(MessWorkFile6)/MessWorkRecLen6
    Call Read.Record(MessWorkFile6,Temp1!)
    If MessWorkRecord6.User=User.Index Then
       Var1!=MessWorkRecord6.Index
       Var2=MessWorkRecord6.Charges
       Call Drop.Inventory(Var1!,Var2)
       MessWorkRecord6.User=SFalse
       MessWorkRecord6.Room=SFalse
       MessWorkRecord6.Index=SFalse
       MessWorkRecord6.Charges=False
       MessWorkRecord6.Plus=False
       MessWorkRecord6.Prev=SFalse
       MessWorkRecord6.Next=SFalse
       Call Write.Record(MessWorkFile6,Temp1!)
    Endif
 Next
ErrorResume25a:
 Exit Sub
ErrorTrap25a:
 Resume ErrorResume25a
End Sub

Sub Drop.All.UserContainers
 On Local Error Goto ErrorTrap25x
 Temp3!=UserRecord.First2 ' containers
 If Temp3! Then
    Do
       Call Read.Record(ContainerFile,Temp3!)
       VarQ!=ContainerRecord.Next
       ' drop container
       Call Delete.User.Container(Temp3!)
       Call Read.Record(ContainerFile,Temp3!)
       ContainerRecord.RoomNumber=Room
       ContainerRecord.UserNumber=SFalse
       ContainerRecord.InvisibleContainer=False
       Call Add.Room.Container(Temp3!)
       If VarQ!=SFalse Then
          Exit Do
       Endif
       Temp3!=VarQ!
    Loop
 Endif
ErrorResume25x:
 Exit Sub
ErrorTrap25x:
 Resume ErrorResume25x
End Sub

Sub Zero.Stats
 On Local Error Goto ErrorTrap26
 UserRecord.Experience=False
 If Config2(93)=False Then
    Call Experience(Temp#)
    UserRecord.Experience=Temp#
 Endif
 Call New.Stats
 Call Put.User.Record
 UserRecord.Flags=UserRecord.Flags And Not Wished
 UserRecord.Flags=UserRecord.Flags And Not Rerolled
 UserRecord.Flags=UserRecord.Flags And Not Alignmented
 Call Write.Record(UserFile,User.Index)
ErrorResume26:
 Exit Sub
ErrorTrap26:
 Resume ErrorResume26
End Sub

Sub New.Stats
 On Local Error Goto ErrorTrp39
 If UserRecord.Level<False Then
    UserRecord.Level=False
 Endif
 Temp#=Cdbl(Training.Stats(UserRecord.ClassType,1))*Cdbl(UserRecord.Level)
 If Temp#>MaxInt Then
    Temp#=MaxInt
 Endif
 UserRecord.FatigueMax=Cint(Temp#)
 Temp#=Cdbl(Training.Stats(UserRecord.ClassType,2))*Cdbl(UserRecord.Level)
 If Temp#>MaxInt Then
    Temp#=MaxInt
 Endif
 UserRecord.VitalityMax=Cint(Temp#)
 Temp#=Cdbl(Training.Stats(UserRecord.ClassType,3))*Cdbl(UserRecord.Level)
 If Temp#>MaxInt Then
    Temp#=MaxInt
 Endif
 UserRecord.MagicMax=Cint(Temp#)
 Temp#=Cdbl(Training.Stats(UserRecord.ClassType,4))*Cdbl(UserRecord.Level)
 If Temp#>MaxInt Then
    Temp#=MaxInt
 Endif
 UserRecord.PsionicMax=Cint(Temp#)
 If UserRecord.Fatigue<False Or _
 UserRecord.Fatigue>UserRecord.FatigueMax Then
    UserRecord.Fatigue=UserRecord.FatigueMax
 Endif
 If UserRecord.Vitality<False Or UserRecord.Vitality>UserRecord.VitalityMax Then
    UserRecord.Vitality=UserRecord.VitalityMax
 Endif
 If UserRecord.Magic<False Or UserRecord.Magic>UserRecord.MagicMax Then
    UserRecord.Magic=UserRecord.MagicMax
 Endif
 If UserRecord.Psionic<False Or UserRecord.Psionic>UserRecord.PsionicMax Then
    UserRecord.Psionic=UserRecord.PsionicMax
 Endif
 If Normal.User Then
    For Temp=1 To MaxStats
       If UserRecord.Stats(Temp)>Config2(31) Then
          UserRecord.Stats(Temp)=Config2(31)
          Strng=Lcase$(Rtrim$(Stat(Temp)))
          Mid$(Strng,1,1)=Ucase$(Mid$(Strng,1,1))
          Strng="Your "+Strng+" is reset to"+Str$(Config2(31))+"."
          Call IO.O
       Endif
    Next
 Endif
 Call Status.Line(False)
 If Normal.User Then
    Var=False
    For Var1=1 To MaxStats
       If UserRecord.Stats(Var1)<=False Then
          Var=True
          Out2=Stat(Var1)
          Out2=Rtrim$(Out2)
          Out2=Lcase$(Out2)
          Strng="Your "+Out2+" is zero!"
          Call IO.O
          UserRecord.Stats(Var1)=1
       Endif
    Next
    If Var Then
       Strng="died from low stats"
       Call Update.DayFile(Strng,False,1)
       Message1="You died from low statistics!"
       Call Player.Died
       Exit Sub
    Endif
 Endif
 If Config2(48) Then
    If UserRecord.Level>=10 Then
       If UserRecord.ClassType>=Fighter And UserRecord.ClassType<AsstDM Then
          Var1$=Lcase$(Rtrim$(UserRecord.ClassName))
          ' check if classname is not custom
          If Var1$=Lcase$(Rtrim$(Class.Name(UserRecord.ClassType))) Then
             ' store high level classname
             Var2$=Lcase$(Rtrim$(High.Class.Name(UserRecord.ClassType)))
             If Len(Var2$) Then
                Call Valid(Var2$,20)
                If Var2$=Nul Then
                   Eat$=Nul
                Else
                   Var2$=Rtrim$(Var2$)
                   If Var1$<>Var2$ Then
                      Call Capitalize(Var2$)
                      UserRecord.ClassName=Var2$
                      Strng="Your classname was upgraded to "+Var2$+"."
                      Call IO.O
                   Endif
                Endif
             Endif
          Endif
       Endif
    Endif
 Endif
 Call Get.User.Stats(Temp)
 If Temp=False Then
    Call Hang.Up(12)
 Endif
ErrorRsm39:
 Exit Sub
ErrorTrp39:
 Resume ErrorRsm39
End Sub

Sub Get.User.Stats(Var)
 On Local Error Goto ErrorTrp53
 Var=True
 If UserRecord.Flags And Special.Char1 Then
    Town.Mayor=True
 Else
    Town.Mayor=False
 Endif
 If UserRecord.Flags And Special.Char2 Then
    Governor=True
 Else
    Governor=False
 Endif
 If UserRecord.Flags And Special.Char3 Then
    Guild.Master=True
 Else
    Guild.Master=False
 Endif
 If UserRecord.ClassType=AsstDM Or UserRecord.Level>999 Then
    Dungeon.Master.Assistant=True
 Else
    Dungeon.Master.Assistant=False
 Endif
 If UserRecord.ClassType=DM Or UserRecord.Level>9999 Then
    Dungeon.Master=True
 Else
    Dungeon.Master=False
 Endif
 If UserRecord.Flags And Special.Char4 Then
    Sysop=True
 Else
    Sysop=False
 Endif
 If Dungeon.Master Or Dungeon.Master.Assistant Or Sysop Then
    Normal.User=False
 Else
    Normal.User=True
 Endif
 If Disable.DM Then
    If Dungeon.Master Or Dungeon.Master.Assistant Then
       Var=False
    Endif
 Endif
 If Disable.Sysop Then
    If Sysop Then
       Var=False
    Endif
 Endif
 If Normal.User Then
    Debug.Mode=False
 Endif
ErrorRsm53:
 Exit Sub
ErrorTrp53:
 Resume ErrorRsm53
End Sub

Sub Safe.Room
 On Local Error Goto ErrorTrp1
 TempA=False
 If Room=1 Then
    TempA=True
    Exit Sub
 Endif
 Var1$=","+Rtrim$(Room.Array(11))+","
 Var2$=","+Mid$(Str$(Room),2)+","
 If Instr(Var1$,Var2$) Then
    TempA=True
    Exit Sub
 Endif
 If GuestLogin Then
    If Room=GuestRecord.GuestRoomResurrect Then
       TempA=True
    Endif
 Endif
ErrorRsm1:
 Exit Sub
ErrorTrp1:
 Resume ErrorRsm1
End Sub

Sub Safe.Room2
 On Local Error Goto ErrorTrp1x
 TempA=False
 If Next.Room=1 Then
    TempA=True
    Exit Sub
 Endif
 Var1$=","+Rtrim$(Room.Array(11))+","
 Var2$=","+Mid$(Str$(Next.Room),2)+","
 If Instr(Var1$,Var2$) Then
    TempA=True
    Exit Sub
 Endif
 If GuestLogin Then
    If Next.Room=GuestRecord.GuestRoomResurrect Then
       TempA=True
    Endif
 Endif
ErrorRsm1x:
 Exit Sub
ErrorTrp1x:
 Resume ErrorRsm1x
End Sub

' Var!=-1!  load node.array with online usernames in current room.
' Var!=0!   search for online username in
'           parsed.command1 and return room number in Temp!
' Var!>0!   search for online user.index=Var! and
'           return room number in Temp!
Sub Search.Mess(Var!)
 On Local Error Goto ErrorTrap16a
 Temp!=SFalse
 For VarX=False To MaxNodes
    Node.Work.Array1(VarX)=Nul
    Node.Work.Array2(VarX)=False
 Next
 TempD=False
 For VarX=False To MaxNodes
    Call Read.Message.Record(MessWorkFile1,VarX+1)
    Var$=Rtrim$(MessWorkRecord1.UserName)
    Call Valid.Name(Var$)
    If TempA Then
       TempB!=MessWorkRecord1.UserIndex
       TempC=VarX
       Select Case Var!
       Case -1!
          If MessWorkRecord1.RoomNumber=Room Then
             Node.Work.Array1(VarX)=Lcase$(Var$)
             Node.Work.Array2(VarX)=MessWorkRecord1.Level
          Endif
       Case SFalse
          Strng=MessWorkRecord1.UserName
          Strng=Rtrim$(Strng)
          Strng=Lcase$(Strng)
          Out4=Lcase$(Parsed.Command1)
          If Len(Out4) Then
             If Left$(Strng,Len(Out4))=Out4 Then
                Out4=Strng
                If Parse.Temp>False Then
                   TempD=TempD+1
                   If TempD=Parse.Temp Then
                      Temp!=MessWorkRecord1.RoomNumber
                      Exit For
                   Endif
                Else
                   Temp!=MessWorkRecord1.RoomNumber
                   Exit For
                Endif
             Endif
          Endif
       Case Else
          If MessWorkRecord1.UserIndex=Var! Then
             Temp!=MessWorkRecord1.RoomNumber
             Exit For
          Endif
       End Select
    Endif
 Next
ErrorResume16a:
 Exit Sub
ErrorTrap16a:
 Resume ErrorResume16a
End Sub

Sub Experience(Var#)
 On Local Error Goto ErrTrap16b
 Var1#=Config2(92)+Config2(95)
 Var2#=2^Var1#
 If UserRecord.Level<=Config2(95) Then
    Var#=2^(UserRecord.Level+Config2(92))
 Else
    Var#=Var2#+(UserRecord.Level-Config2(95))*Config1(32)
 Endif
ErrResume16b:
 Exit Sub
ErrTrap16b:
 Resume ErrResume16b
End Sub

Sub Get.Direction
 On Local Error Goto ErrorTrap46
 For TempA=1 To MaxDirections
    Out3=Direction(TempA)
    Out3=Rtrim$(Out3)
    Out3=Ucase$(Out3)
    If Left$(Out3,Len(User.Command))=User.Command Then
       Exit Sub
    Endif
 Next
 Call Find.Link(User.Command)
 If Temp3 Then
    TempA=Temp3
 Else
    TempA=False
 Endif
ErrorResume46:
 Exit Sub
ErrorTrap46:
 Resume ErrorResume46
End Sub

Sub Find.Link(Var1$)
 On Local Error Goto ErrorTrap49
 Select Case Ucase$(Var1$)
 Case "N"
    Temp3=1
 Case "E"
    Temp3=2
 Case "S"
    Temp3=3
 Case "W"
    Temp3=4
 Case "NE"
    Temp3=5
 Case "SE"
    Temp3=6
 Case "SW"
    Temp3=7
 Case "NW"
    Temp3=8
 Case "U"
    Temp3=9
 Case "D"
    Temp3=10
 Case "I"
    Temp3=11
 Case "O"
    Temp3=12
 Case Else
    Temp3=False
 End Select
ErrorResume49:
 Exit Sub
ErrorTrap49:
 Resume ErrorResume49
End Sub
