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

Sub Drink.Potion
 On Local Error Goto Error.Trap19
 Call Parse
 If Parser Then
    Call Numeric
 Endif
 Call Check.User.Items
 If Temp7!<SFalse Then
    Strng="You can't drink that!"
    Call IO.O
    Exit Sub
 Endif
 If Temp7!=SFalse Then
    Call Num
    Temp4=False
    Call Examine.Containers
    If TempA! Then
       Call Drink.From.Container
       Exit Sub
    Endif
    Strng="You can't drink that!"
    Call IO.O
    Exit Sub
 Endif
 If TreasureRecord.Potion=False Then
    Strng="That's not a potion!"
    Call IO.O
    Exit Sub
 Endif
 If MessWorkRecord6.Charges<=False Then
    If TreasureRecord.Liquid Then
       Strng="Nothing happens!"
       Call IO.O
       Call Discard.Liquid(Temp5!)
    Else
       Strng="You can't, it's empty!"
       Call IO.O
    Endif
    Exit Sub
 Endif
 Temp2!=TreasureRecord.Spell
 If Temp2!>SFalse And Temp2!<=Lof(SpellFile)/SpellRecLen Then
    Call Read.Record(SpellFile,Temp2!)
    If TreasureRecord.Liquid Then
       Var=TreasureRecord.LiquidType
       If Var=1 Or Var=2 Or Var=3 Then
          MessWorkRecord6.Charges=MessWorkRecord6.Charges-Var
       Else
          MessWorkRecord6.Charges=MessWorkRecord6.Charges-1
       Endif
    Else
       MessWorkRecord6.Charges=MessWorkRecord6.Charges-1
    Endif
    MessWorkRecord6.Time1=Timeit!
    Call Write.Record(MessWorkFile6,Temp5!)
    If TreasureRecord.Liquid Then
       If MessWorkRecord6.Charges<=False Then
          Call Discard.Liquid(Temp5!)
       Endif
    Endif
    Magic.Spell=SpellRecord.SpellType
    Multiplier=SpellRecord.Level
    Monster.Temp=SFalse
    Parser=False
    Temp7!=SFalse
    Temp3=True
    Call Magic2
    Exit Sub
 Endif
 If TreasureRecord.Liquid Then
    Var=TreasureRecord.LiquidType
    If Var=1 Or Var=2 Or Var=3 Then
       MessWorkRecord6.Charges=MessWorkRecord6.Charges-Var
    Else
       MessWorkRecord6.Charges=MessWorkRecord6.Charges-1
    Endif
    MessWorkRecord6.Time1=Timeit!
    Call Write.Record(MessWorkFile6,Temp5!)
    If MessWorkRecord6.Charges<=False Then
       Call Discard.Liquid(Temp5!)
    Endif
 Endif
 Strng="Nothing happens!"
 Call IO.O
Error.Resume19:
 Exit Sub
Error.Trap19:
 Resume Error.Resume19
End Sub

Sub Discard.Liquid(Var1!)
 On Local Error Goto ErrorTrp28x
 Call Read.Record(MessWorkFile6,Var1!)
 VarA!=MessWorkRecord6.Index
 VarB=MessWorkRecord6.Charges
 Call Read.Record(TreasureFile,VarA!)
 Weight=Weight-TreasureRecord.Weight
 If Weight<False Then
    Weight=False
 Endif
 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,Var1!)
ErrorRsm28x:
 Exit Sub
ErrorTrp28x:
 Resume ErrorRsm28x
End Sub

Sub Drink.From.Container
 On Local Error Goto Error.Trap19x
 If ContainerRecord.Damaged=True Then
    Strng="You can't, it's damaged."
    Call IO.O
    Exit Sub
 Endif
 If ContainerRecord.Locked=True Then
    Strng="You can't, it's locked."
    Call IO.O
    Exit Sub
 Endif
 If ContainerRecord.Locked=1 Then
    If ContainerRecord.Closed Then
       Strng="You can't, it's closed."
       Call IO.O
       Exit Sub
    Endif
 Endif
 VarQ2=ContainerRecord.TrapType
 VarQ3=ContainerRecord.TrapHits
 VarQ4!=ContainerRecord.TrapItem
 Var2$=ContainerRecord.ContainerName
 Var2$=Rtrim$(Var2$)
 Var2$=Lcase$(Var2$)
 VarZ$=ContainerRecord.ContainerShort
 VarZ$=Rtrim$(VarZ$)
 VarZ$=Lcase$(VarZ$)
 Call Find.Liquid.In.Container
 If Temp7!=SFalse Then
    Strng="You can't drink that!"
    Call IO.O
    Exit Sub
 Endif
 Select Case TreasureRecord.LiquidType
 Case 1
    Var$="sip"
 Case 2
    Var$="gulp"
 Case 3
    Var$="guzzle"
 Case Else
    Var$="drink"
 End Select
 Strng="You "+Var$+" "+Out3+" from "+Var2$+"!"
 Call IO.O
 If Temp6>False Then
    Var=TreasureRecord.LiquidType
    If Var=1 Or Var=2 Or Var=3 Then
       MessWorkRecord6.Charges=MessWorkRecord6.Charges-Var
    Else
       MessWorkRecord6.Charges=MessWorkRecord6.Charges-1
    Endif
    MessWorkRecord6.Time1=Timeit!
    Call Write.Record(CtnInvFile,Temp5!)
    If MessWorkRecord6.Charges<=False Then
       Call Delete.List.Node5(Temp5!)
    Endif
    Temp2!=TreasureRecord.Spell
    If Temp2!>SFalse And Temp2!<=Lof(SpellFile)/SpellRecLen Then
       Call Read.Record(SpellFile,Temp2!)
       Magic.Spell=SpellRecord.SpellType
       Multiplier=SpellRecord.Level
       Monster.Temp=SFalse
       Parser=False
       Temp7!=SFalse
       Temp3=True
       Call Magic2
    Else
       Strng="Nothing happens!"
       Call IO.O
    Endif
 Else
    MessWorkRecord6.Charges=False
    MessWorkRecord6.Time1=Timeit!
    Call Write.Record(CtnInvFile,Temp5!)
    Call Delete.List.Node5(Temp5!)
    Strng="Nothing happens!"
    Call IO.O
 Endif
 Call ContainerTraps(VarQ2,VarQ3,VarQ4!,VarZ$)
Error.Resume19x:
 Exit Sub
Error.Trap19x:
 Resume Error.Resume19x
End Sub

Sub Find.Liquid.In.Container
 On Local Error Goto ErrorTrp13b
 Parse.Temp=Temp2
 Temp6=False
 Temp7!=SFalse
 Call Read.Record(ContainerFile,TempA!)
 Temp5!=ContainerRecord.First
 If Temp5! Then
    Do While Lost.Carrier=False
       Call Read.Record(CtnInvFile,Temp5!)
       If MessWorkRecord6.User=SFalse Then
          Exit Do
       Endif
       Temp6!=MessWorkRecord6.Next
       TempB!=MessWorkRecord6.User
       If TempB!>SFalse And TempB!<=Lof(TreasureFile)/TreasureRecLen Then
          Call Read.Record(TreasureFile,TempB!)
          If TreasureRecord.Potion Then
             If TreasureRecord.Liquid Then
                Out3=TreasureRecord.TreasureName
                Out3=Rtrim$(Out3)
                Temp7!=TempB!
                Temp6=MessWorkRecord6.Charges
                Exit Do
             Endif
          Endif
       Endif
       If Temp6!=SFalse Then
          Exit Do
       Endif
       Temp5!=Temp6!
    Loop
 Endif
ErrorRsm13b:
 Exit Sub
ErrorTrp13b:
 Resume ErrorRsm13b
End Sub
