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

Sub Cast.Spell
 On Local Error Goto ErrorTrap28
 Var=TempX ' -1=cast, 0=discharge/use
 VarX2=Len(Parsed.Command2)
 VarX3=Instr(Parsed.Command2," ")
 If Var=0 Then
    If VarX3 Then
       Var1$=Parsed.Command2
       Call Tumbler(Var1$,VarX) ' use key on portal
       If VarX Then
          Exit Sub
       Endif
    Endif
 Endif
 Temp0=0
 If Normal.User Then
    If UserRecord.ClassType<>MagicUser Then
       If UserRecord.Weapon(7).Index Then
          Strng="You must return your weapon first!"
          Call IO.O
          Exit Sub
       Endif
    Endif
 Endif
 Temp1=False
 Temp2!=SFalse
 Temp3=False
 If Var Then
    If UserRecord.Magic=False Then
       Strng="You have no more spell points!"
       Call IO.O
       Exit Sub
    Endif
    Strng="Chant? "
    Call IO.I
    Out2=Ucase$(Out2)
    Temp5=False
    For Temp2!=1! To Lof(SpellFile)/SpellRecLen
       If Config1(38)>SFalse Then
          If Temp2!>Config1(38) Then
             Exit For
          Endif
       Endif
       If Temp2!>Len(LearnedSpells) Then
          LearnedSpells=LearnedSpells+String$(Temp2!-Len(LearnedSpells),"0")
       Endif
       Call Read.Record(SpellFile,Temp2!)
       Out4=SpellRecord.Chant
       Out4=Rtrim$(Out4)
       Out4=Ucase$(Out4)
       If Out4=Out2 Then
          If SpellRecord.Psionic=False Then
             Temp5=True
             Exit For
          Endif
       Endif
       Out4=SpellRecord.SpellName
       Out4=Rtrim$(Out4)
       Out4=Ucase$(Out4)
       If Out4=Out2 Then
          If SpellRecord.Psionic=False Then
             If Mid$(LearnedSpells,Temp2!,1)="1" Then
                Temp5=True
                Exit For
             Endif
          Endif
       Endif
    Next
    If Temp5=False Then
       Strng="Wrong spell chant!"
       Call IO.O
       Exit Sub
    Endif
    VarX!=Temp2!
    Temp1=Cast.Spell.Type
 Else
    Call Parse
    If Parser Then
       Call Numeric
    Endif
    Call Check.User.Rings
    If Temp7!>SFalse Then
       VarZ1=TempD
       If Temp6=False Then
          Strng="You can't, it's discharged!"
          Call IO.O
          Exit Sub
       Endif
       Temp0=2 ' use ring
       If Last.Command.Number=Discharge Then
          Temp0=-1 ' discharge ring
       Endif
       Temp1=Use.Spell.Type
       VarX!=Temp5!
    Else
       Call Num
       Call Check.User.Items
       If Temp7!<=SFalse Then
          Strng="You can't use that!"
          Call IO.O
          Exit Sub
       Endif
       If TreasureRecord.Potion Then
          Strng="You can't use that!"
          Call IO.O
          Exit Sub
       Endif
       If TreasureRecord.Edible Then
          Strng="You can't use that!"
          Call IO.O
          Exit Sub
       Endif
       If TreasureRecord.WeaponNumber Then
          Strng="You can't use that!"
          Call IO.O
          Exit Sub
       Endif
       If TreasureRecord.Scroll Then
          Strng="The scroll disintegrated!"
          Call IO.O
          Gosub Clear.Scroll
          For Var=1 To 4
             MessWorkRecord6.Desc(Var)=0!
          Next
          Call Write.Record(MessWorkFile6,Temp5!)
          Call Discard(Temp5!,True)
          VarX!=Temp5!
          Temp1=Scroll.Spell.Type
       Else
          If TreasureRecord.Spell=SFalse Then
             Strng="That's not a magical device!"
             Call IO.O
             Exit Sub
          Endif
          If MessWorkRecord6.Charges=False Then
             Strng="You can't, it's empty!"
             Call IO.O
             Exit Sub
          Endif
          If Last.Command.Number=Discharge Then
             Temp0=1
          Else
             Temp6=MessWorkRecord6.Charges
             Temp6=Temp6-1
             If Temp6<False Then
                Temp6=False
             Endif
             MessWorkRecord6.Charges=Temp6
             MessWorkRecord6.Time1=Timeit!
             Call Write.Record(MessWorkFile6,Temp5!)
          Endif
          Temp1=Use.Spell.Type
          VarX!=Temp5!
       Endif
    Endif
    Temp2!=TreasureRecord.Spell
    Temp3=True
 Endif
 Temp7!=SFalse
 If Temp2!=SFalse Then
    Exit Sub
 Endif
 Call Read.Record(SpellFile,Temp2!)
 Magic.Spell=SpellRecord.SpellType
 If Last.Command.Number=Discharge Then
    If Magic.Spell<>Offense Then
       Strng="Wrong spell type for discharge!"
       Call IO.O
       Exit Sub
    Endif
 Endif
 If Magic.Spell=Damnate Or Magic.Spell=Resurrect Or Magic.Spell=GrantWish Or Magic.Spall=StealWish Then
    If Var Then ' cast
       If VarX2=0 Then
          Strng="Invalid target!"
          Call IO.O
          Exit Sub
       Endif
    Endif
    If Var=0 Then ' use
       If VarX3=0 Then
          Strng="Invalid target!"
          Call IO.O
          Gosub Increase.Charges
          Exit Sub
       Endif
    Endif
 Endif
 Multiplier=SpellRecord.Level
 If Last.Command.Number=Discharge Then
    Multiplier=Multiplier+Temp6
 Endif
 If Parser Then
    Parsed.Command1=Parsed.Command2
    Call Numeric
    Call Check.Room.Items
    If Temp7! Then
       Temp4=False
    Endif
    If Temp7!=SFalse Then
       Call Num
       Call Check.User.Items2
       If Temp7! Then
          Temp4=True
       Endif
    Endif
 Endif
 Call Magic1(VarZ1,VarX!)
 If TempX=-1 Then ' bad wish/teleport
    If Temp1=Use.Spell.Type Then
       Gosub Increase.Charges
    Endif
 Endif
 If TempX=1 Then ' bad target
    If Last.Command.Number<>Discharge Then
       If Temp1=Use.Spell.Type Then
          Gosub Increase.Charges
       Endif
    Endif
 Endif
 Exit Sub
' restore object charges
Increase.Charges:
 Call Read.Record(MessWorkFile6,VarX!)
 Temp6=MessWorkRecord6.Charges
 Temp6=Temp6+1
 MessWorkRecord6.Charges=Temp6
 MessWorkRecord6.Time1=Timeit!
 Call Write.Record(MessWorkFile6,VarX!)
 Return
' remove written messages.
Clear.Scroll:
 Close #LogFile
 FileName=DND.Path+"writing.log"
 Open FileName For Random Shared As #LogFile Len=LogRecLen
 For Var=1 To 4
    Temp1!=MessWorkRecord6.Desc(Var)
    If Temp1!>SFalse And Temp1!<=Lof(LogFile)/LogRecLen Then
       LogRecord.User=0!
       LogRecord.Message=Nul
       LogRecord.Clock=Nul
       Call Write.Record(LogFile,Temp1!)
    Endif
 Next
 Return
ErrorResume28:
 Exit Sub
ErrorTrap28:
 Resume ErrorResume28
End Sub

' cast/discharge/use <item>, ..
Sub Magic1(VarZ1,VarX!)
 On Local Error Goto Err.Trap1
 Gosub Get.Config1
 TempX=False
 VarQ4=Temp4
 If Temp7!>SFalse Then ' treasure item target
    If Magic.Spell=Enchant Then
       If TreasureRecord.Spell=SFalse Then
          Strng="Improper spell target for chant!"
          Call IO.O
          TempX=1
          Exit Sub
       Endif
    Else
       If Magic.Spell=Vigor Or Magic.Spell=Heal Then
          If TreasureRecord.Vehicle=False Then
             Strng="Improper spell target for chant!"
             Call IO.O
             TempX=1
             Exit Sub
          Endif
       Else
          If Magic.Spell=Hiding Then
             If VarQ4=False Then ' only user inventory can be hidden
                Strng="Improper spell target for chant!"
                Call IO.O
                TempX=1
                Exit Sub
             Endif
          Else
             If Magic.Spell<>Bless And Magic.Spell<>Curse Then
                Strng="Improper spell target for chant!"
                Call IO.O
                TempX=1
                Exit Sub
             Endif
          Endif
       Endif
    Endif
 Endif
 If Temp7!<SFalse Then ' object item
    Strng="Improper spell target for chant!"
    Call IO.O
    TempX=1
    Exit Sub
 Endif
 If Temp7!=SFalse Then ' monster target
    If Parser Then
       Temp7!=STrue
       Select Case Magic.Spell
       Case Offense, CurePoison, Poison, LevelDrain, Befuddled, TurnUndead, _
          Intoxicate, Telepathy, Bless, Curse, Damnate, Resurrect, GrantWish, StealWish
          Temp7!=SFalse
       End Select
       If Temp7! Then
          Strng="Improper spell target for chant!!"
          Call IO.O
          TempX=1
          Exit Sub
       Endif
    Endif
 Endif
 If Temp3=False Then
    If Multiplier>UserRecord.Level Then
       Strng="You are not high enough level to cast the spell!"
       Call IO.O
       Exit Sub
    Endif
    If UserRecord.Magic=False Then
       Strng="You have no more spell points!"
       Call IO.O
       Exit Sub
    Endif
    If (SpellRecord.ClassType And 2^UserRecord.ClassType)=False Then
       If Normal.User=True Then
          Strng="Your class can't cast that spell!"
          Call IO.O
          Exit Sub
       Endif
    Endif
    Temp6=UserRecord.Magic
    Temp6=Temp6-Multiplier
    If Temp6<False Then
       Temp6=False
    Endif
    UserRecord.Magic=Temp6
 Endif
 If SpellRecord.SpellFlag And Temp1 Then
    For Temp=1 To MaxIngredients
       TempA!=SpellRecord.Ingred(Temp)
       If TempA!>SFalse And TempA!<=Lof(TreasureFile)/TreasureRecLen Then
          Temp9=False
          For TempB!=1! To Lof(MessWorkFile6)/MessWorkRecLen6
             Call Read.Record(MessWorkFile6,TempB!)
             If MessWorkRecord6.User=User.Index Then
                If MessWorkRecord6.Index=TempA! Then
                   Call Read.Record(TreasureFile,MessWorkRecord6.Index)
                   Temp9=True
                   Exit For
                Endif
             Endif
          Next
          If Temp9=False Then
             Strng="You don't have the correct spell ingredients!"
             Call IO.O
             Out2=TreasureRecord.TreasureName
             Out2=Rtrim$(Out2)
             Out2=Lcase$(Out2)
             Strng="You need "+Out2+"!"
             Call IO.O
             Exit Sub
          Endif
          If MessWorkRecord6.Charges<=False Then
             Out2=TreasureRecord.ShortName
             Out2=Rtrim$(Out2)
             Out2=Lcase$(Out2)
             Strng="The "+Out2+" are used up!"
             Call IO.O
             Exit Sub
          Endif
          MessWorkRecord6.Charges=MessWorkRecord6.Charges-1
          MessWorkRecord6.Time1=Timeit!
          Call Write.Record(MessWorkFile6,TempB!)
       Endif
    Next
 Endif
 If Magic.Spell=Teleporting Then
    If GuestLogin Then
       If GuestRecord.GuestCanTeleport=False Then
          Strng="Sorry, guests cannot teleport."
          Call IO.O
          Temp=1
          Exit Sub
       Endif
    Endif
 Endif
 If Last.Command.Number=Discharge Then
    Strng="The device discharges!"
    Call IO.O
 Endif
 Out6=SpellRecord.SpellName
 Out6=Rtrim$(Out6)
 Out6=Lcase$(Out6)
 If Instr("aeiou",Left$(Out6,1)) Then
    Out7=" an "
 Else
    Out7=" a "
 Endif
 Strng="cast"+Out7+Out6+" spell"
 Call Update.DayFile(Strng,False,3)
 Strng=Rtrim$(SpellRecord.Prefix1)
 Strng="You cast"+Out7+Strng+Out6
 Call Convert.ANSI(True,VarQ,VarR)
 Carriage.Return=True
 Graphics.On=True
 Call IO.O
 Graphics.On=False
 Strng=" spell!"
 Graphics.Off=True
 Call IO.O
 Strng=SpellRecord.Desc
 Strng=Rtrim$(Strng)
 If Len(Strng) Then
    Call Convert.ANSI(True,VarQ,VarR)
    Graphics.On=True
    Call IO.O
    Graphics.On=False
 Endif
 If Node>False Then
    Out2=UserRecord.CodeName
    Out2=Rtrim$(Out2)
    Out2=Lcase$(Out2)
    Strng=SpellRecord.SpellName
    Strng=Rtrim$(Strng)
    Out2=Out2+" casts a "+Strng+" spell!"
    Call Send.Mess(8,SFalse,Room,Out2)
 Endif
 Call Read.Record(RoomFile,Room)
 Var!=RoomRecord.Action
 If Var!>SFalse And Var!<=Lof(ActionFile)/ActionRecLen Then
    Call Read.Record(ActionFile,Var!)
    If ActionRecord.SpellTrigger=Temp2! Then
       Out3="As the spell is cast,"
       Out4="You are hit for"
       Action.Recurse=0
       Call Actions(Var!)
    Endif
 Endif
 If Magic.Spell<>Illuminate And Magic.Spell<>SetTrap Then
    Temp!=RoomRecord.First
    If Temp! Then
       Do While Lost.Carrier=False
          Call Read.Record(RoomInvFile,Temp!)
          If MessWorkRecord6.Room=SFalse Then
             Exit Do
          Endif
          Var2!=MessWorkRecord6.Next
          Var3!=MessWorkRecord6.Room
          If Var3!<SFalse Then
             Var3!=Abs(Var3!)
             If MessWorkRecord6.Plus=Magic.Trap Then
                If Len(option1$) Then
                   Out2=option1$
                   Call Equate(Temp#)
                Else
                   Temp#=UserRecord.Stats(2)<Int(Rnd*6+10)
                Endif
                If Temp# Then
                   If Len(option2$) Then
                      Out2=option2$
                      Call Equate(Temp#)
                      Temp2=Int(Temp#)
                   Else
                      Temp2=Int(Rnd*10+UserRecord.Level+MessWorkRecord6.Charges)
                   Endif
                   Call Delete.List.Node(Temp!)
                   Call Clear.List.Node
                   Call Write.Record(RoomInvFile,Temp!)
                   Strng="You triggered a magical trap!"
                   Call IO.O
                   Prefix2=Nul
                   Strng="The trap hit you for"
                   Out3="an exploding trap"
                   Call Hit.Player(Temp2)
                   Exit Do
                Endif
             Endif
          Endif
          If Var2!=SFalse Then
             Exit Do
          Endif
          Temp!=Var2!
       Loop
    Endif
 Endif
 If Last.Command.Number=Discharge Then
    If Magic.Spell=Offense Then
       ' discharge
       If Temp0=-1 Then ' ring
          VarQ=UserRecord.Weapon(VarZ1).Charges
          UserRecord.Weapon(VarZ1).Charges=False
       Endif
       If Temp0=1 Then ' inventory item
          Call Read.Record(MessWorkFile6,VarX!)
          VarQ=MessWorkRecord6.Charges
          MessWorkRecord6.Charges=False
          MessWorkRecord6.Time1=Timeit!
          Call Write.Record(MessWorkFile6,VarX!)
       Endif
       Call Attack.Monster(VarZ)
       If VarZ=0 Then ' bad target
          ' recharge
          If Temp0=-1 Then ' ring
             UserRecord.Weapon(VarZ1).Charges=VarQ
          Endif
          If Temp0=1 Then ' inventory item
             Call Read.Record(MessWorkFile6,VarX!)
             MessWorkRecord6.Charges=VarQ
             MessWorkRecord6.Time1=Timeit!
             Call Write.Record(MessWorkFile6,VarX!)
          Endif
       Endif
    Else
       Strng="Wrong spell type for discharge!"
       Call IO.O
    Endif
    Exit Sub
 Endif
 If Parser=False Then
    Select Case Magic.Spell
    Case Intoxicate
       Intoxicated=UserRecord.Level
       Strng="You just became drunk!"
       If Intoxicated<=1 Then
          Intoxicated=1
          Strng="You just became slightly drunk!"
       Endif
       If Intoxicated>=10 Then
          Intoxicated=10
          Strng="You just became very drunk!"
       Endif
       Call IO.O
       Exit Sub
    Case CurePoison
       If UserRecord.Poison Then
          UserRecord.Poison=False
          Strng="The poison disappeared!"
       Else
          Strng="Nothing happened!"
       Endif
       Call IO.O
       Exit Sub
    Case Poison
       If UserRecord.Poison=False Then
          VarX=False
          Var2!=UserRecord.Weapon(4).Index
          If Var2! Then
             Call Read.Record(TreasureFile,Var2!)
             If TreasureRecord.RingType=1 Or TreasureRecord.RingType=3 Then
                VarX=True
                Call Get.Ring.Hits4(True)
             Endif
          Endif
          If VarX=False Then
             Var2!=UserRecord.Weapon(9).Index
             If Var2! Then
                Call Read.Record(TreasureFile,Var2!)
                If TreasureRecord.RingType=1 Or TreasureRecord.RingType=3 Then
                   VarX=True
                   Call Get.Ring.Hits4(False)
                Endif
             Endif
          Endif
          If VarX=False Then
             UserRecord.Poison=True
             Strng="You poisoned yourself!"
             Call IO.O
          Endif
       Else
          Strng="Nothing happened!"
          Call IO.O
       Endif
       Exit Sub
    End Select
 Endif
 Select Case Magic.Spell
 Case Offense, CurePoison, Poison, LevelDrain, Befuddled, TurnUndead, _
    Intoxicate, Damnate, Resurrect, GrantWish, StealWish
    Call Read.Record(MessWorkFile6,VarX!)
    If Temp0=2 Then ' ring
       VarQ=UserRecord.Weapon(VarZ1).Charges
       VarQ=VarQ-1
       UserRecord.Weapon(VarZ1).Charges=VarQ
    Else
       VarQ=MessWorkRecord6.Charges
    Endif
    MessWorkRecord6.Time1=Timeit!
    Call Attack.Monster(VarZ)
    If VarZ=0 Then ' bad target
       ' recharge
       If Temp0=2 Then ' ring
          UserRecord.Weapon(VarZ1).Charges=VarQ+1
       Else ' inventory item
          Call Read.Record(MessWorkFile6,VarX!)
          MessWorkRecord6.Charges=VarQ+1
          MessWorkRecord6.Time1=Timeit!
          Call Write.Record(MessWorkFile6,VarX!)
       Endif
    Endif
    Exit Sub
 Case Vigor
    If Temp7!>SFalse Then
       Call Read.Record(TreasureFile,Temp7!)
       Out3=TreasureRecord.ShortName
       Out3=Rtrim$(Out3)
       Out3=Lcase$(Out3)
       If VarQ4=False Then
          Call Read.Record(MessWorkFile6,Temp5!)
       Else
          Call Read.Record(RoomInvFile,Temp5!)
       Endif
       Temp2=MessWorkRecord6.Charges
       If Temp2>=TreasureRecord.Charges Then
          Strng="Nothing happens!"
          Call IO.O
          Exit Sub
       Endif
       Temp2=Temp2+UserRecord.Level*2
       If Temp2>TreasureRecord.Charges Then
          Temp2=TreasureRecord.Charges
       Endif
       MessWorkRecord6.Charges=Temp2
       MessWorkRecord6.Time1=Timeit!
       If VarQ4=False Then
          Call Write.Record(MessWorkFile6,Temp5!)
       Else
          Call Write.Record(RoomInvFile,Temp5!)
       Endif
       Strng="The "+Out3+" now has"+Str$(Temp2)+" hits!"
       Call IO.O
       Exit Sub
    Endif
    Temp#=Cdbl(UserRecord.Level+Multiplier)
    Temp#=Temp#*Config2(21)
    If Temp#<False Or Temp#>MaxInt Then
       Temp#=MaxInt
    Endif
    If UserRecord.Fatigue+Temp#>MaxInt Then
       UserRecord.Fatigue=MaxInt
    Else
       UserRecord.Fatigue=UserRecord.Fatigue+Temp#
    Endif
    Call New.Stats
    Strng="You now have"+Str$(UserRecord.Fatigue)+" fatigue points!"
    Call IO.O
    Exit Sub
 Case Heal
    If Temp7!>SFalse Then
       Call Read.Record(TreasureFile,Temp7!)
       Out3=TreasureRecord.ShortName
       Out3=Rtrim$(Out3)
       Out3=Lcase$(Out3)
       If VarQ4=False Then
          Call Read.Record(MessWorkFile6,Temp5!)
       Else
          Call Read.Record(RoomInvFile,Temp5!)
       Endif
       Temp2=MessWorkRecord6.Charges
       If Temp2>=TreasureRecord.Charges Then
          Strng="Nothing happens!"
          Call IO.O
          Exit Sub
       Endif
       Temp2=Temp2+UserRecord.Level*2
       If Temp2>TreasureRecord.Charges Then
          Temp2=TreasureRecord.Charges
       Endif
       MessWorkRecord6.Charges=Temp2
       MessWorkRecord6.Time1=Timeit!
       If VarQ4=False Then
          Call Write.Record(MessWorkFile6,Temp5!)
       Else
          Call Write.Record(RoomInvFile,Temp5!)
       Endif
       Strng="The "+Out3+" now has"+Str$(Temp2)+" hits!"
       Call IO.O
       Exit Sub
    Endif
    Temp#=Cdbl(UserRecord.Level+Multiplier)
    Temp#=Temp#*Config2(22)
    If Temp#<False Or Temp#>MaxInt Then
       Temp#=MaxInt
    Endif
    If UserRecord.Vitality+Temp#>MaxInt Then
       UserRecord.Vitality=MaxInt
    Else
       UserRecord.Vitality=UserRecord.Vitality+Temp#
    Endif
    Call New.Stats
    Strng="You now have"+Str$(UserRecord.Vitality)+" vitality points!"
    Call IO.O
    Exit Sub
 Case Enchant
    If Temp7!>SFalse Then
       If TreasureRecord.Spell=False Then
          Strng="You can't recharge that!"
          Call IO.O
          Exit Sub
       Endif
       Call Read.Record(SpellFile,TreasureRecord.Spell)
       If SpellRecord.SpellType=Wish Then
          If Normal.User Then
             Strng="You can't recharge that!"
             Call IO.O
             Exit Sub
          Endif
       Endif
       If VarQ4=False Then
          Call Read.Record(MessWorkFile6,Temp5!)
       Else
          Call Read.Record(RoomInvFile,Temp5!)
       Endif
       Temp2=MessWorkRecord6.Charges
       If Temp2>=TreasureRecord.Charges Then
          Strng="Nothing happens!"
          Call IO.O
          Exit Sub
       Endif
       Temp2=Temp2+UserRecord.Level*2
       If Temp2>TreasureRecord.Charges Then
          Temp2=TreasureRecord.Charges
       Endif
       MessWorkRecord6.Charges=Temp2
       MessWorkRecord6.Time1=Timeit!
       If VarQ4=False Then
          Call Write.Record(MessWorkFile6,Temp5!)
       Else
          Call Write.Record(RoomInvFile,Temp5!)
       Endif
       Strng="You recharge it!"
       Call IO.O
       Exit Sub
    Endif
    Temp#=Cdbl(UserRecord.Level+Multiplier)
    Temp#=Temp#*Config2(23)
    If Temp#<False Or Temp#>MaxInt Then
       Temp#=MaxInt
    Endif
    If UserRecord.Magic+Temp#>MaxInt Then
       UserRecord.Magic=MaxInt
    Else
       UserRecord.Magic=UserRecord.Magic+Temp#
    Endif
    Call New.Stats
    Strng="You now have"+Str$(UserRecord.Magic)+" magic points!"
    Call IO.O
    Exit Sub
 Case Bless
    If Temp7!>SFalse Then ' check treasure target
       Out3=TreasureRecord.ShortName
       Out3=Rtrim$(Out3)
       Out3=Lcase$(Out3)
       If TreasureRecord.Spell=SFalse Then
          Var=TreasureRecord.TimesBlessed
          If Var>=100 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
          Strng="You can't bless that!"
          Call IO.O
          TempX=1
          Exit Sub
       Endif
       TempZ=False
       Select Case VarQ4
       Case 0
          Call Read.Record(RoomInvFile,Temp5!)
          MessWorkRecord6.Charges=MessWorkRecord6.Charges+1
          If MessWorkRecord6.Charges>TreasureRecord.Charges Then
             MessWorkRecord6.Charges=TreasureRecord.Charges
             TempZ=True
          Endif
          MessWorkRecord6.Time1=Timeit!
          Call Write.Record(RoomInvFile,Temp5!)
       Case -1
          Call Read.Record(MessWorkFile6,Temp5!)
          MessWorkRecord6.Charges=MessWorkRecord6.Charges+1
          If MessWorkRecord6.Charges>TreasureRecord.Charges Then
             MessWorkRecord6.Charges=TreasureRecord.Charges
             TempZ=True
          Endif
          MessWorkRecord6.Time1=Timeit!
          Call Write.Record(MessWorkFile6,Temp5!)
       End Select
       If TempZ Then
          Strng="Nothing happens!"
       Else
          Strng="You bless the "+Out3+"!"
       Endif
       Call IO.O
       Exit Sub
    Endif
    If Parser Then ' check target
       ' 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(option3a$) Then
             Out2=option3a$
             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(option3b$) Then
             Out2=option3b$
             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
       TempX=1
       Strng="You can't bless that!"
       Call IO.O
       Exit Sub
    Endif
    ' bless self
    If Len(option3c$) Then
       Out2=option3c$
       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)
          Strng="You feel a magical glow about you!"
          Call IO.O
          Strng="Your piety is now"+Str$(UserRecord.Stats(6))+"!"
          Call IO.O
          'Call New.Stats
          Exit Sub
       Endif
    Endif
    Strng="Nothing happened.."
    Call IO.O
    Exit Sub
 Case Curse
    If Temp7!>SFalse Then ' check treasure target
       Out3=TreasureRecord.ShortName
       Out3=Rtrim$(Out3)
       Out3=Lcase$(Out3)
       If TreasureRecord.Spell=SFalse Then
          Var=TreasureRecord.TimesCursed
          If Var>=100 Then
             Strng="You curse the "+Out3+"!"
             Call IO.O
             TreasureRecord.TimesCursed=0
             Var2=TreasureRecord.Charges
             If Var2>0 Then
                TreasureRecord.Charges=Var2-1
                Strng="The "+Out3+" loses 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.TimesCursed=Var
                Call Write.Record(TreasureFile,Temp7!)
                Strng="You curse 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
          TempX=1
          Strng="You can't curse that!"
          Call IO.O
          Exit Sub
       Endif
       TempZ=False
       Select Case VarQ4
       Case 0
          Call Read.Record(RoomInvFile,Temp5!)
          VarQ=MessWorkRecord6.Charges-1
          If VarQ>=0 Then
             MessWorkRecord6.Charges=VarQ
          Else
             TempZ=True
          Endif
          MessWorkRecord6.Time1=Timeit!
          Call Write.Record(RoomInvFile,Temp5!)
       Case -1
          Call Read.Record(MessWorkFile6,Temp5!)
          VarQ=MessWorkRecord6.Charges-1
          If VarQ>=0 Then
             MessWorkRecord6.Charges=VarQ
          Else
             TempZ=True
          Endif
          MessWorkRecord6.Time1=Timeit!
          Call Write.Record(MessWorkFile6,Temp5!)
       End Select
       If TempZ Then
          Strng="Nothing happens!"
       Else
          Strng="You curse the "+Out3+"!"
       Endif
       Call IO.O
       Exit Sub
    Endif
    If Parser Then ' check target
       ' 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 curse the "+Out3+"!"
          Call IO.O
          If Len(option4$) Then
             Out2=option4$
             Call Equate(Temp#)
             Multiplier=Int(Temp#)
          Else
             Multiplier=Int(Rnd*3+2)
          Endif
          Call Hit.Monster
          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 curse "+Out3+"!"
          Call IO.O
          If Len(option5a$) Then
             Out2=option5a$
             Call Equate(Temp#)
          Else
             Temp#=Rnd>.8
          Endif
          If Temp# Then
             If UserRecord2.Stats(6)>False Then ' piety
                Out2="curses you!"
                Call Send.Mess(24,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 curse "+Lcase$(Out3)+"!"
          Call IO.O
          If Len(option5b$) Then
             Out2=option5b$
             Call Equate(Temp#)
          Else
             Temp#=Rnd>.8
          Endif
          If Temp# Then
             If UserRecord2.Stats(6)>False 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
       TempX=1
       Strng="You can't curse that!"
       Call IO.O
       Exit Sub
    Endif
    ' curse self
    If Len(option5c$) Then
       Out2=option5c$
       Call Equate(Temp#)
    Else
       Temp#=Rnd>.8
    Endif
    If Temp# Then
       If UserRecord.Stats(6)>False Then
          UserRecord.Stats(6)=UserRecord.Stats(6)-1
          Call Write.Record(UserFile,User.Index)

          Strng=Rtrim$(Stat(6))
          Strng="lost one "+Strng+" point"
          Call Update.DayFile(Strng,False,2)
          Strng="You feel a darkening about you!"
          Call IO.O
          Strng="Your piety is now"+Str$(UserRecord.Stats(6))+"!"
          Call IO.O
          'Call New.Stats
          Exit Sub
       Endif
    Endif
    Strng="Nothing happened.."
    Call IO.O
    Exit Sub
 Case Wish
Wish.Loop1:
    If Lost.Carrier Then
       Exit Sub
    Endif
    Strng="The Ghods Thunder.."
    Call IO.O
    Strng="   What Do You Wish For? "
    Call IO.I
    If Out2="?" Then
       Call Out.File(Data.Path2+"WISH.DOC","")
       Goto Wish.Loop1
    Endif
    Stored.Parsed.Command2=Out2
    Parsed.Command1=Stored.Parsed.Command2
    Call Numeric
    Out2=Parsed.Command1
    Out2=Lcase$(Out2)
    If Out2=Nul Then
       TempX=-1
       Exit Sub
    Endif
    If Lcase$(Out2)="invisibility" Or Lcase$(Out2)="invisible" Then
       If Len(option10$) Then
          Out2=option10$
          Call Equate(Temp#)
          If Temp# Then
             If Len(option11$) Then
                Out2=option11$
                Call Equate(Temp#)
                Temp2=Cint(Temp#)
                If Temp2>False Then
                   Invisible=Temp2
                   UserRecord.Invisible=True
                   Strng="You are now invisible!"
                   Call IO.O
                   Exit Sub
                Endif
             Endif
          Endif
          Strng="Didn't work!"
          Call IO.O
          Exit Sub
       Endif
       If Config2(126)=False Then
          VarQ=1
       Else
          Call Count.Mess(VarQ)
       Endif
       Temp3=Room.Health.Rate*VarQ
       Temp2=False
       If Temp3 Then
          Temp2=Int((UserRecord.Level+5)/Temp3)
       Endif
       If Temp2>False Then
          Invisible=Temp2
          UserRecord.Invisible=True
          Strng="You are now invisible!"
       Else
          Strng="Didn't work!"
       Endif
       Call IO.O
       Exit Sub
    Endif
    If Lcase$(Out2)="curepoison" Then
       If UserRecord.Poison Then
          If Len(option12$) Then
             Out2=option21$
             Call Equate(Temp#)
             If Temp# Then
                UserRecord.Poison=False
                Strng="The poison disappeared!"
                Call IO.O
                Exit Sub
             Else
                Strng="Nothing happened!"
                Call IO.O
                Exit Sub
             Endif
          Endif
          If Rnd>.5 Then
             UserRecord.Poison=False
             Strng="The poison disappeared!"
             Call IO.O
             Exit Sub
          Endif
       Endif
       Strng="Nothing happened!"
       Call IO.O
       Exit Sub
    Endif
    If Lcase$(Out2)="teleport" Then
Wish.Loop:
       If GuestLogin Then
          If GuestRecord.GuestCanTeleport=False Then
             Strng="Sorry, guests cannot teleport!"
             Call IO.O
             Exit Sub
          Endif
       Endif
       If Lost.Carrier Then
          Exit Sub
       Endif
       Strng="Destination(?=help)? "
       Call IO.I
       If Out2=Nul Then
          TempX=-1
          Exit Sub
       Endif
       If Out2="?" Then
          Call Out.File(Data.Path2+"TELEPORT.DOC","")
          Goto Wish.Loop
       Endif
       Stored.Parsed.Command2=Out2
       Parsed.Command1=Stored.Parsed.Command2
       Call Numeric
       Out2=Parsed.Command1
       Out2=Lcase$(Out2)
       Call Read.Record(MessWorkFile6,VarX!)
       Call Teleport.Function(VarQ2)
       ' bad wish/teleport
       If VarQ2 Then
          TempX=-1
       Endif
       Exit Sub
    Endif
    If Temp1=Use.Spell.Type Or Temp1=Scroll.Spell.Type Then
       UserRecord.Flags=UserRecord.Flags And Not Wished
    Endif
    Call Drop(False)
    Exit Sub
 Case Teleporting
    If GuestLogin Then
       If GuestRecord.GuestCanTeleport=False Then
          Strng="Sorry, guests cannot teleport."
          Call IO.O
          TempX=-1
          Exit Sub
       Endif
    Endif
    Select Case SpellRecord.Teleport
    Case IS>SFalse
       Next.Room=SpellRecord.Teleport
       Call Teleport
       Action.Recurse=0
       Call Enter.Room
       Exit Sub
    Case IS<SFalse
       Strng="Enter room number(1-"+Mid$(Str$(Lof(RoomFile)/RoomRecLen),2)+")/description? "
       Call IO.I
       If Out2=Nul Then
          TempX=-1
          Exit Sub
       Endif
       Call Find.Teleport(Var!)
       If Var!=0! Then
          TempX=-1
          Exit Sub
       Endif
       Next.Room=Var!
       Call Teleport
       Action.Recurse=0
       Call Enter.Room
       Exit Sub
    Case Else
       Strng="Nothing happens!"
       Call IO.O
       Exit Sub
    End Select
 Case PassDoor
    Pass.Door=True
    Strng="You hear a click!"
    Call IO.O
    Exit Sub
 Case Conjure
    For Temp5!=1! To Lof(MonClassFile)/MonClassRecLen
       Call Read.Record(MonClassFile,Temp5!)
       Choice=MonClassRecord.Monsters(Int(Rnd*10+1))
       If Choice Then
          Call Read.Record(MonsterFile,Choice)
          If MonsterRecord.Level=UserRecord.Level Then
             Call Get.Monster
             Exit Sub
          Endif
       Endif
    Next
    Strng="Nothing conjures!"
    Call IO.O
    Exit Sub
 Case Psionic
    Strng="You can't cast a psi spell!"
    Call IO.O
    Exit Sub
 Case DetectLock
    Temp5!=RoomRecord.First
    If Temp5! Then
       Do While Lost.Carrier=False
          Call Read.Record(RoomInvFile,Temp5!)
          If MessWorkRecord6.Room=SFalse Then
             Exit Do
          Endif
          Temp6!=MessWorkRecord6.Next
          Temp4!=MessWorkRecord6.Index
          If Temp4!<SFalse Then
             Temp4!=Abs(Temp4!)
             If Temp4!>SFalse And Temp4!<=Lof(ObjectFile)/ObjectRecLen Then
                Call Read.Record(ObjectFile,Temp4!)
                If ObjectRecord.Invisible Or ObjectRecord.Hidden Then
                   Strng="You detect hidden objects here!"
                   Call IO.O
                   Exit Sub
                Endif
             Endif
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp5!=Temp6!
       Loop
    Endif
    Strng="You detect nothing."
    Call IO.O
    Exit Sub
 Case DetectEvil
    Temp2=False
    Temp4=False
    For Temp5=1 To MaxDirections
       Call Read.Record(RoomFile,Room)
       Var1!=RoomRecord.Direct(Temp5)
       If Var1! Then
          Call Read.Record(RoomFile,Var1!)
          If RoomRecord.MonClass>Temp2 Then
             Temp4=Temp5
             Temp2=RoomRecord.MonClass
          Endif
       Endif
    Next
    Call Read.Record(RoomFile,Room)
    If Temp4 Then
       Strng="You detect evil going "+Rtrim$(Direction(Temp4))+"!"
       Call IO.O
       Exit Sub
    Endif
    Strng="You detect no evil presence."
    Call IO.O
    Exit Sub
 Case DetectTrap
    Temp5!=RoomRecord.First
    If Temp5! Then
       Do While Lost.Carrier=False
          Call Read.Record(RoomInvFile,Temp5!)
          If MessWorkRecord6.Room=SFalse Then
             Exit Do
          Endif
          Temp6!=MessWorkRecord6.Next
          Temp4!=MessWorkRecord6.Index
          If Temp4!<SFalse Then
             Temp4!=Abs(Temp4!)
             If Temp4!>SFalse And Temp4!<=Lof(ObjectFile)/ObjectRecLen Then
                Call Read.Record(ObjectFile,Temp4!)
                If ObjectRecord.Trap Then
                   Strng="You detect traps here!"
                   Call IO.O
                   Exit Sub
                Endif
             Endif
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp5!=Temp6!
       Loop
    Endif
    Strng="You detect nothing."
    Call IO.O
    Exit Sub
 Case SetTrap
    If Len(option6$) Then
       Out2=option6$
       Call Equate(Temp#)
    Else
       Temp#=UserRecord.Stats(2)<Int(Rnd*5+5)
    Endif
    If Temp# Then
       Strng="You didn't set the trap!"
       Call IO.O
       Exit Sub
    Endif
    If Len(option7$) Then
       Out2=option7$
       Call Equate(Temp#)
    Else
       Temp#=UserRecord.Stats(2)+UserRecord.Stats(3)<Int(Rnd*10+5)
    Endif
    If Temp# Then
       Strng="The trap explodes in your face!"
       Call IO.O
       Prefix2=Nul
       If Len(option8$) Then
          Out2=option8$
          Call Equate(Temp#)
          Temp2=Int(Temp#)
       Else
          Temp2=Int(Rnd*10+2)*UserRecord.Level
       Endif
       Strng="The trap hit you for"
       Out3="setting a trap"
       Call Hit.Player(Temp2)
       Exit Sub
    Endif
    Temp5!=Lof(RoomInvFile)/MessWorkRecLen6+1!
    MessWorkRecord6.Room=-Room
    MessWorkRecord6.User=SFalse
    MessWorkRecord6.Index=SFalse
    MessWorkRecord6.Charges=UserRecord.Level
    MessWorkRecord6.Plus=Magic.Trap
    MessWorkRecord6.Time1=Timeit!
    Call Add.List.Node(Temp5!)
    Strng="You set a magical trap!"
    Call IO.O
    Exit Sub
 Case Hiding
    If Len(option9$) Then
       Out2=option9$
       Call Equate(Temp#)
    Else
       Temp#=UserRecord.Stats(2)<Int(Rnd*5+4)
    Endif
    If Temp# Then
       Strng="You didn't hide the object!"
       Call IO.O
       Exit Sub
    Endif
    Call Read.Record(MessWorkFile6,Temp5!)
    Temp6=MessWorkRecord6.Charges
    Call Discard(Temp5!,True)
    Temp5!=Lof(RoomInvFile)/MessWorkRecLen6+1!
    MessWorkRecord6.Room=Room
    MessWorkRecord6.User=SFalse
    MessWorkRecord6.Index=Temp7!
    MessWorkRecord6.Charges=Temp6
    MessWorkRecord6.Plus=Magically.Hidden
    MessWorkRecord6.Time1=Timeit!
    Call Add.List.Node(Temp5!)
    Strng="You hide the object magically!"
    Call IO.O
    Exit Sub
 Case Search
    Graphics.Off=True
    Strng="You find "
    Carriage.Return=True
    Call IO.O
    Temp1=False
    Strng=Nul
    Temp5!=RoomRecord.First
    If Temp5! Then
       Do While Lost.Carrier=False
          Call Read.Record(RoomInvFile,Temp5!)
          If MessWorkRecord6.Room=SFalse Then
             Exit Do
          Endif
          Temp6!=MessWorkRecord6.Next
          If MessWorkRecord6.Plus=Magically.Hidden Then
             Temp2!=MessWorkRecord6.Index
             If Temp2!>SFalse And Temp2!<=Lof(TreasureFile)/TreasureRecLen Then
                Call Read.Record(TreasureFile,Temp2!)
                Carriage.Return=True
                Call IO.O
                Strng=Rtrim$(TreasureRecord.TreasureName)+"[inv], "
                Temp1=Temp1+1
             Endif
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp5!=Temp6!
       Loop
    Endif
    If Temp1=False Then
       Strng="nothing special.."
    Else
       Strng=Left$(Strng,Len(Strng)-2)+"."
       If Temp1>1 Then
          Strng="and "+Strng
       Endif
    Endif
    Call IO.O
    Graphics.Off=False
    Exit Sub
 Case Invisibly
    If Len(option10$) Then
       Out2=option10$
       Call Equate(Temp#)
       If Temp# Then
          If Len(option11$) Then
             Out2=option11$
             Call Equate(Temp#)
             Temp2=Cint(Temp#)
             If Temp2>False Then
                Invisible=Temp2
                UserRecord.Invisible=True
                Strng="You are now invisible!"
                Call IO.O
                Exit Sub
             Endif
          Endif
       Endif
       Strng="Didn't work!"
       Call IO.O
       Exit Sub
    Endif
    If Config2(126)=False Then
       VarQ=1
    Else
       Call Count.Mess(VarQ)
    Endif
    Temp3=Room.Health.Rate*VarQ
    Temp2=False
    If Temp3 Then
       Temp2=Int((UserRecord.Level+5)/Temp3)
    Endif
    If Temp2>False Then
       Invisible=Temp2
       UserRecord.Invisible=True
       Strng="You are now invisible!"
    Else
       Strng="Didn't work!"
    Endif
    Call IO.O
    Exit Sub
 Case Identified
    Parsed.Command1=Last.Monster
    Call Check.Monster
    If Monster.Temp=SFalse Then
       Strng="You are not fighting a monster now!"
       Call IO.O
       Exit Sub
    Endif
    Graphics.Off=True
    Call The.Or.An
    Out3=MessWorkRecord3.Monster.MonsterName
    Out3=Rtrim$(Out3)
    Out3=Lcase$(Out3)
    Temp4=MessWorkRecord3.Monster.Level
    Strng="You are fighting "+Prefix1+Out3+_
    " (level "+Form$(Cdbl((Temp4-1)*2+1))+" to "+Form$(Cdbl(Temp4*2))+")"
    Call IO.O
    Strng="The "+Out3+" has "+Form$(Cdbl(MessWorkRecord3.Monster.Hits))+" hits,"
    If Instr(Str$(MessWorkRecord3.Monster.Experience),"D") Then
       Strng=Strng+Str$(MessWorkRecord3.Monster.Experience)+" experience,"
    Else
       Strng=Strng+" "+Form$(MessWorkRecord3.Monster.Experience)+" experience,"
    Endif
    If Instr(Str$(MessWorkRecord3.Monster.Gold),"D") Then
       Strng=Strng+" and"+Str$(MessWorkRecord3.Monster.Gold)+" Gold."
    Else
       Strng=Strng+" and "+Form$(MessWorkRecord3.Monster.Gold)+" Gold."
    Endif
    Call IO.O
    Temp4!=MessWorkRecord3.Monster.Spell
    If Temp4!>SFalse And Temp4!<=Lof(SpellFile)/SpellRecLen Then
       Call Read.Record(SpellFile,Temp4!)
       Strng="It can cast "+Rtrim$(SpellRecord.SpellName)+" spells."
       Call IO.O
    Endif
    If MessWorkRecord3.Monster.Poison Then
       Strng="It can poison."
       Call IO.O
    Endif
    If MessWorkRecord3.Monster.LevelDrain Then
       Strng="It can drain levels."
       Call IO.O
    Endif
    If MessWorkRecord3.Monster.Psionic Then
       Strng="It can cast psi spells."
       Call IO.O
    Endif
    If MessWorkRecord3.Monster.Magic Then
       Strng="It is magical."
       Call IO.O
    Endif
    If MessWorkRecord3.Monster.Block Then
       Strng="It blocks exits."
       Call IO.O
    Endif
    If MessWorkRecord3.Monster.Prevent Then
       Strng="It prevents treasure take."
       Call IO.O
    Endif
    If MessWorkRecord3.Monster.Follow Then
       Strng="It follows users."
       Call IO.O
    Endif
    If MessWorkRecord3.Monster.Jail Then
       Strng="It jails attacker."
       Call IO.O
    Endif
    If MessWorkRecord3.Monster.TeleportPercent Then
       Strng="It can teleport."
       Call IO.O
    Endif
    Graphics.Off=False
    Exit Sub
 Case Enlighten
    Graphics.Off=True
    Strng="You see "
    Carriage.Return=True
    Call IO.O
    Temp1=False
    Strng=Nul
    Temp5!=RoomRecord.First
    If Temp5! Then
       Do While Lost.Carrier=False
          Call Read.Record(RoomInvFile,Temp5!)
          If MessWorkRecord6.Room=SFalse Then
             Exit Do
          Endif
          Temp6!=MessWorkRecord6.Next
          If MessWorkRecord6.Plus=Hidden.Object Then
             Temp2!=MessWorkRecord6.Index
             If Temp2!>SFalse And Temp2!<=Lof(TreasureFile)/TreasureRecLen Then
                Call Read.Record(TreasureFile,Temp2!)
                Carriage.Return=True
                Call IO.O
                Strng=Rtrim$(TreasureRecord.TreasureName)+"[inv], "
                Temp1=Temp1+1
             Endif
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp5!=Temp6!
       Loop
    Endif
    If Temp1=False Then
       Strng="nothing special.."
    Else
       Strng=Left$(Strng,Len(Strng)-2)+"."
       If Temp1>1 Then
          Strng="and "+Strng
       Endif
    Endif
    Call IO.O
    Graphics.Off=False
    Exit Sub
 Case Illuminate
    Graphics.Off=True
    Strng="You see "
    Carriage.Return=True
    Call IO.O
    Temp1=False
    Strng=Nul
    Temp5!=RoomRecord.First
    If Temp5! Then
       Do While Lost.Carrier=False
          Call Read.Record(RoomInvFile,Temp5!)
          If MessWorkRecord6.Room=SFalse Then
             Exit Do
          Endif
          Temp6!=MessWorkRecord6.Next
          Var2!=MessWorkRecord6.Room
          If Var2!<SFalse Then
             Var2!=Abs(Var2!)
             If MessWorkRecord6.Plus=Magic.Trap Then
                Carriage.Return=True
                Call IO.O
                Temp8=MessWorkRecord6.Charges
                Strng="a magical trap["+Mid$(Str$(Temp8),2)+" hits], "
                Temp1=Temp1+1
             Endif
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp5!=Temp6!
       Loop
    Endif
    If Temp1=False Then
       Strng="nothing special.."
    Else
       Strng=Left$(Strng,Len(Strng)-2)+"."
       If Temp1>1 Then
          Strng="and "+Strng
       Endif
    Endif
    Call IO.O
    Graphics.Off=False
    Exit Sub
 Case Psyche
    Temp#=Cdbl(UserRecord.Level+Multiplier)
    Temp#=Temp#*Config2(82)
    If Temp#<False Or Temp#>MaxInt Then
       Temp#=MaxInt
    Endif
    If UserRecord.Psionic+Temp#>MaxInt Then
       UserRecord.Psionic=MaxInt
    Else
       UserRecord.Psionic=UserRecord.Psionic+Temp#
    Endif
    Call New.Stats
    Strng="You now have"+Str$(UserRecord.Psionic)+" psionic points!"
    Call IO.O
    Exit Sub
 Case Telepathy
    If UserRecord.Psionic=False Then
       Strng="You have no more psionic points!"
       Call IO.O
       Exit Sub
    Endif
    If Parser Then
       Call Search.Mess(SFalse)
       If Temp!=SFalse Then
          Out2=Parsed.Command1
          Out2=Lcase$(Out2)
          Strng=Out2+" is not online!"
          Call IO.O
          Exit Sub
       Endif
       Strng="Message:"
       Call IO.I
       If Len(Out2) Then
          Call Send.Mess(10,TempB!,SFalse,Out2)
          Temp6=UserRecord.Psionic
          Temp6=Temp6-Multiplier
          If Temp6<False Then
             Temp6=False
          Endif
          UserRecord.Psionic=Temp6
       Endif
       Exit Sub
    Endif
    Strng="Message:"
    Call IO.I
    If Len(Out2) Then
       Call Send.Mess(11,SFalse,SFalse,Out2)
       Temp6=UserRecord.Psionic
       Temp6=Temp6-Multiplier
       If Temp6<False Then
          Temp6=False
       Endif
       UserRecord.Psionic=Temp6
    Endif
    Exit Sub
 Case Else
    Strng="You can't cast that spell!"
    Call IO.O
 End Select
 Exit Sub
Get.Config1:
 VarX=0
 Do
    VarX=VarX+1
    If VarX>Options.Lines Then
       Exit Do
    Endif
    Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
    If Ucase$(Var$)="[CMD024]" 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 "trigger.magical.trap"
                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 "magical.trap.hits"
                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
             Case "bless.online.user"
                If Left$(Var3$,1)=Chr$(34) Then
                   If Right$(Var3$,1)=Chr$(34) Then
                      option3a$=Mid$(Var3$,2)
                      option3a$=Left$(option3a$,Len(option3a$)-1)
                   Endif
                Endif
             Case "bless.offline.user"
                If Left$(Var3$,1)=Chr$(34) Then
                   If Right$(Var3$,1)=Chr$(34) Then
                      option3b$=Mid$(Var3$,2)
                      option3b$=Left$(option3b$,Len(option3b$)-1)
                   Endif
                Endif
             Case "bless.self"
                If Left$(Var3$,1)=Chr$(34) Then
                   If Right$(Var3$,1)=Chr$(34) Then
                      option3c$=Mid$(Var3$,2)
                      option3c$=Left$(option3c$,Len(option3c$)-1)
                   Endif
                Endif
             Case "curse.multiplier"
                If Left$(Var3$,1)=Chr$(34) Then
                   If Right$(Var3$,1)=Chr$(34) Then
                      option4$=Mid$(Var3$,2)
                      option4$=Left$(option4$,Len(option4$)-1)
                   Endif
                Endif
             Case "curse.online.user"
                If Left$(Var3$,1)=Chr$(34) Then
                   If Right$(Var3$,1)=Chr$(34) Then
                      option5a$=Mid$(Var3$,2)
                      option5a$=Left$(option5a$,Len(option5a$)-1)
                   Endif
                Endif
             Case "curse.offline.user"
                If Left$(Var3$,1)=Chr$(34) Then
                   If Right$(Var3$,1)=Chr$(34) Then
                      option5b$=Mid$(Var3$,2)
                      option5b$=Left$(option5b$,Len(option5b$)-1)
                   Endif
                Endif
             Case "curse.self"
                If Left$(Var3$,1)=Chr$(34) Then
                   If Right$(Var3$,1)=Chr$(34) Then
                      option5c$=Mid$(Var3$,2)
                      option5c$=Left$(option5c$,Len(option5c$)-1)
                   Endif
                Endif
             Case "set.trap.equation"
                If Left$(Var3$,1)=Chr$(34) Then
                   If Right$(Var3$,1)=Chr$(34) Then
                      option6$=Mid$(Var3$,2)
                      option6$=Left$(option6$,Len(option6$)-1)
                   Endif
                Endif
             Case "trap.explodes"
                If Left$(Var3$,1)=Chr$(34) Then
                   If Right$(Var3$,1)=Chr$(34) Then
                      option7$=Mid$(Var3$,2)
                      option7$=Left$(option7$,Len(option7$)-1)
                   Endif
                Endif
             Case "trap.explode.hits"
                If Left$(Var3$,1)=Chr$(34) Then
                   If Right$(Var3$,1)=Chr$(34) Then
                      option8$=Mid$(Var3$,2)
                      option8$=Left$(option8$,Len(option8$)-1)
                   Endif
                Endif
             Case "magically.hide.object"
                If Left$(Var3$,1)=Chr$(34) Then
                   If Right$(Var3$,1)=Chr$(34) Then
                      option9$=Mid$(Var3$,2)
                      option9$=Left$(option9$,Len(option9$)-1)
                   Endif
                Endif
             Case "invisible.equation"
                If Left$(Var3$,1)=Chr$(34) Then
                   If Right$(Var3$,1)=Chr$(34) Then
                      option10$=Mid$(Var3$,2)
                      option10$=Left$(option10$,Len(option10$)-1)
                   Endif
                Endif
             Case "invisible.count"
                If Left$(Var3$,1)=Chr$(34) Then
                   If Right$(Var3$,1)=Chr$(34) Then
                      option11$=Mid$(Var3$,2)
                      option11$=Left$(option11$,Len(option11$)-1)
                   Endif
                Endif
             Case "curepoison"
                If Left$(Var3$,1)=Chr$(34) Then
                   If Right$(Var3$,1)=Chr$(34) Then
                      option12$=Mid$(Var3$,2)
                      option12$=Left$(option12$,Len(option12$)-1)
                   Endif
                Endif
             End Select
          Endif
       Loop
    Endif
 Loop
 Return
Err.Resume1:
 Exit Sub
Err.Trap1:
 Resume Err.Resume1
End Sub

Sub Check.User.Rings
 On Local Error Goto ErrorTrp17
 Temp6=False
 Temp7!=SFalse
 TempC=False
 TempD=False
 If Parsed.Command1<>Nul Then
    Temp5!=UserRecord.Weapon(4).Index ' left ring
    If Temp5! Then
       Call Read.Record(TreasureFile,Temp5!)
       If TreasureRecord.BindType Then ' binds to offense spell
          If TreasureRecord.Spell Then
             Call Read.Record(SpellFile,TreasureRecord.Spell)
             ' offense type spell
             Select Case SpellRecord.SpellType
             Case Offense, Damnate, LevelDrain, Befuddled
                Out3=TreasureRecord.ShortName
                Out3=Left$(Out3,Len(Parsed.Command1))
                If Out3=Parsed.Command1 Then
                   TempC=TempC+1
                   If Parse.Temp=False Or TempC=Parse.Temp Then
                      Out3=TreasureRecord.TreasureName
                      Out3=Rtrim$(Out3)
                      Temp7!=Temp5!
                      Temp6=UserRecord.Weapon(4).Charges
                      TempD=4
                      Exit Sub
                   Endif
                Endif
             End Select
          Endif
       Endif
    Endif
    Temp5!=UserRecord.Weapon(9).Index ' right ring
    If Temp5! Then
       Call Read.Record(TreasureFile,Temp5!)
       If TreasureRecord.BindType Then ' binds to offense spell
          If TreasureRecord.Spell Then
             Call Read.Record(SpellFile,TreasureRecord.Spell)
             ' offense type spell
             Select Case SpellRecord.SpellType
             Case Offense, Damnate, LevelDrain, Befuddled
                Out3=TreasureRecord.ShortName
                Out3=Left$(Out3,Len(Parsed.Command1))
                If Out3=Parsed.Command1 Then
                   TempC=TempC+1
                   If Parse.Temp=False Or TempC=Parse.Temp Then
                      Out3=TreasureRecord.TreasureName
                      Out3=Rtrim$(Out3)
                      Temp7!=Temp5!
                      Temp6=UserRecord.Weapon(9).Charges
                      TempD=9
                      Exit Sub
                   Endif
                Endif
             End Select
          Endif
       Endif
    Endif
 Endif
ErrorRsm17:
 Exit Sub
ErrorTrp17:
 Resume ErrorRsm17
End Sub

' absorb poison hits
Sub Get.Ring.Hits4(Var1)
 On Local Error Goto ErrorTrap15z
 If Var1 Then
    Var=UserRecord.Weapon(4).Charges
 Else
    Var=UserRecord.Weapon(9).Charges
 Endif
 Var=Var-1
 If Var1 Then
    UserRecord.Weapon(4).Charges=Var
 Else
    UserRecord.Weapon(9).Charges=Var
 Endif
 If Var1 Then
    Strng="Your left ring absorbs the poison spell!"
 Else
    Strng="Your right ring absorbs the poison spell!"
 Endif
 Call IO.O
 If Var<=False Then
    If Var1 Then
       Strng="Your left ring disintegrated!"
       UserRecord.Weapon(4).Index=SFalse
       UserRecord.Weapon(4).Charges=False
       UserRecord.Weapon(4).Plus=False
    Else
       Strng="Your right ring disintegrated!"
       UserRecord.Weapon(9).Index=SFalse
       UserRecord.Weapon(9).Charges=False
       UserRecord.Weapon(9).Plus=False
    Endif
    Call IO.O
 Endif
ErrorResume15z:
 Exit Sub
ErrorTrap15z:
 Resume ErrorResume15z
End Sub

' use key on portal
Sub Tumbler(Var1$,VarX)
 On Local Error Goto ErrorTrap15z2
 VarQ=Instr(Var1$," ")
 Key1$=Left$(Var1$,VarQ-1)
 Key2$=Mid$(Var1$,VarQ+1)
 Key1$=Ltrim$(Rtrim$(Key1$))
 Key2$=Ltrim$(Rtrim$(Key2$))
 Key1$=Lcase$(Key1$)
 Key2$=Lcase$(Key2$)
 Key1=0
 Key2=0
 VarQ=Instr(Key1$,"#")
 If VarQ Then
    Key1=Int(Val(Mid$(Key1$,VarQ+1)))
    Key1$=Left$(Key1$,VarQ-1)
 Endif
 VarQ=Instr(Key2$,"#")
 If VarQ Then
    Key2=Int(Val(Mid$(Key2$,VarQ+1)))
    Key2$=Left$(Key2$,VarQ-1)
 Endif

 ' check user inventory for key number
 Temp6=False
 Temp7!=SFalse
 TempC=False
 If Key1$<>Nul Then
    For Temp5!=1! To Lof(MessWorkFile6)/MessWorkRecLen6
       Call Read.Record(MessWorkFile6,Temp5!)
       If MessWorkRecord6.User=User.Index Then
          VarQ!=MessWorkRecord6.Index
          If VarQ!>SFalse And VarQ!<=Lof(TreasureFile)/TreasureRecLen Then
             Call Read.Record(TreasureFile,VarQ!)
             Out3=TreasureRecord.ShortName
             Out3=Left$(Out3,Len(Key1$))
             Out3=Lcase$(Out3)
             If Out3=Key1$ Then
                TempC=TempC+1
                If Key1=False Or TempC=Key1 Then
                   If TreasureRecord.KeyNumber>0! Then
                      VarK1=True
                      Out3=TreasureRecord.TreasureName
                      Out3=Rtrim$(Out3)
                      Temp7!=VarQ!
                      Temp6=MessWorkRecord6.Charges
                      Exit For
                   Endif
                Endif
             Endif
          Endif
       Endif
    Next
 Endif

 ' check room inventory for key number
 Temp6=False
 Temp7!=SFalse
 TempC=False
 If Key2$<>Nul Then
    Temp5!=RoomRecord.First
    If Temp5! Then
       Do While Lost.Carrier=False
          Call Read.Record(RoomInvFile,Temp5!)
          If MessWorkRecord6.Room=SFalse Then
             Exit Do
          Endif
          Temp6!=MessWorkRecord6.Next
          TempA!=MessWorkRecord6.Index
          If TempA!<SFalse Then
             VarA!=Abs(TempA!)
             If VarA!>SFalse And VarA!<=Lof(ObjectFile)/ObjectRecLen Then
                Call Read.Record(ObjectFile,VarA!)
                Out3=Rtrim$(ObjectRecord.ShortName)
                Out3=Left$(Out3,Len(Key2$))
                Out3=Lcase$(Out3)
                If Out3=Key2$ Then
                   TempC=TempC+1
                   If Key2=False Or TempC=Key2 Then
                      If ObjectRecord.KeyNumber>0! Then
                         VarK2=True
                         Out3=ObjectRecord.ObjectName
                         Out3=Rtrim$(Out3)
                         Temp7!=TempA!
                         Temp6=MessWorkRecord6.Charges
                         Exit Do
                      Endif
                   Endif
                Endif
             Endif
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp5!=Temp6!
       Loop
    Endif
 Endif

 ' check key/portal/room tumbler file
 If VarK1 And VarK2 Then
    Filename$=DND.Path+"TUMBLER.DAT"
    If Dir$(Filename$)<>Nul Then
       Close #TempFile1
       Open Filename$ For Input As #TempFile1
       Do While Not Eof(TempFile1)
          Line Input #TempFile1,Var$
          Var$=Ltrim$(Rtrim$(Var$))
          If Var$=Nul Then
             Eat$=Nul
          Else
             If Left$(Var$,1)=";" Then
                Eat$=Nul
             Else
                ' key/portal/room
                If Len(Var$)>14 Then
                   Match=-1
                   For Var=1 To 14
                      VarX$=Mid$(Var$,Var,1)
                      Select Case Var
                      Case 1 To 6, 8 To 13
                         If VarX$>="0" And VarX$<="9" Then
                            Eat$=Nul
                         Else
                            Match=0
                         Endif
                      Case 7, 14
                         If VarX$<>"," Then
                            Match=0
                         Endif
                      End Select
                   Next

                   ' match tumblers
                   If Match Then
                      Match1!=Int(Val(Mid$(Var$,1,6)))
                      Match2!=Int(Val(Mid$(Var$,8,6)))
                      If Match1!=TreasureRecord.KeyNumber Then
                         If Match2!=ObjectRecord.KeyNumber Then
                            VarR!=Int(Val(Mid$(Var$,15)))
                            If VarR!>0! And VarR!<=Lof(RoomFile)/RoomRecLen Then
                               Strng="You use the "
                               Carriage.Return=True
                               Call IO.O
                               Strng=Rtrim$(TreasureRecord.Prefix1)+Lcase$(Rtrim$(TreasureRecord.ShortName))
                               Call Convert.ANSI(True,VarQ,VarR)
                               Carriage.Return=True
                               Graphics.On=True
                               Call IO.O
                               Graphics.On=False
                               Carriage.Return=True
                               Strng=" on the "
                               Call IO.O
                               Strng=Rtrim$(ObjectRecord.Prefix1)+Lcase$(Rtrim$(ObjectRecord.ShortName))
                               Call Convert.ANSI(True,VarQ,VarR)
                               Carriage.Return=True
                               Graphics.On=True
                               Call IO.O
                               Graphics.On=False
                               Strng="!"
                               Call IO.O
                               VarX=True
                               Next.Room=VarR!
                               Action.Recurse=0
                               Call Enter.Room
                               Exit Sub
                            Endif
                         Endif
                      Endif
                   Endif
                Endif
             Endif
          Endif
       Loop
    Endif
 Endif
ErrorResume15z2:
 Exit Sub
ErrorTrap15z2:
 Resume ErrorResume15z2
End Sub
