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

Sub Smash.Object
 On Local Error Goto ErrTrap26
 Gosub Get.Config1
 VarA$=Parsed.Command1
 VarB$=Parsed.Command2

 Var$=User.Command
 Var=Instr(Var$," ")
 If Var Then
    Var$=Left$(Var$,Var-1)
 Endif
 If Instr(Parsed.command2," ")=0 Then
    If Lcase$(Var$)="crush" Then
       Call Num
       Call Examine.Containers
       If TempA! Then
          If ContainerRecord.Material<=False Then ' paper
             Select Case ContainerRecord.Size
             Case 3 ' large
                ContainerRecord.Size=2
                Call Write.Record(ContainerFile,TempA!)
                Strng="You crush it!"
                Call IO.O
                Exit Sub
             Case 2 ' medium
                ContainerRecord.Size=1
                Call Write.Record(ContainerFile,TempA!)
                Strng="You crush it!"
                Call IO.O
                Exit Sub
             End Select
          Endif
       Endif
    Endif
 Endif

 If Instr(Parsed.command2," ") Then
    ' smash box user
    Call ParseX
    ' parsed.command1=user
    ' parsed.command2=box
    Call Numeric
    ' online users
    Call Search.Mess(SFalse)
    If Temp!=Room And TempB!<>User.Index Then
       VarY=TempC ' node
       VarB!=TempB!
       Out2=MessWorkRecord1.UserName
       Out2=Rtrim$(Out2)
       Out2=Lcase$(Out2)
       Var3$=Out2
       Parsed.Command1=Parsed.Command2
       Call Numeric
       Call Search.User.Container2
       If TempA!<>SFalse Then
          VarQ2=ContainerRecord.TrapType
          VarQ3=ContainerRecord.TrapHits
          VarQ4!=ContainerRecord.TrapItem
          Var2$=ContainerRecord.ContainerShort
          Var2$=Rtrim$(Var2$)
          Var2$=Lcase$(Var2$)
          VarZ$=Var2$
          If Normal.User Then
             If UserRecord2.ClassType>=Lady Then
                Strng3=Rtrim$(Class.Name(UserRecord2.ClassType))
                Call A.Or.An
                Strng="You can't search "+Prefix1+Strng3+"."
                Call IO.O
                Exit Sub
             Endif
             If UserRecord.ClassType<AsstDM Then
                If UserRecord.ClassType<>Thief Then
                   Strng="Only thieves can smash containers!"
                   Call IO.O
                   Exit Sub
                Endif
                If UserRecord.Level<2 Then
                   Strng="Only level 2 thieves can smash containers!"
                   Call IO.O
                   Exit Sub
                Endif
             Endif
          Endif
          Call ContainerTraps(VarQ2,VarQ3,VarQ4!,VarZ$)
          If VarQ2=-1 Then ' *boom*
             Exit Sub
          Endif
          Temp4=False
          Call Smash.Container
          Exit Sub
       Endif
       Strng="You can't search that user!"
       Call IO.O
       Exit Sub
    Endif
    Parsed.Command1=VarA$
    Parsed.Command2=VarB$
    ' look box user
    Call ParseX
    ' parsed.command1=user
    ' parsed.command2=box
    Call Numeric
    ' offline users
    Call Check.User
    If User.Temp Then
       Var3$=Out3
       Parsed.Command1=Parsed.Command2
       Call Numeric
       TempB!=MessWorkRecord4.Index
       Call Search.User.Container2
       If TempA!<>SFalse Then
          VarQ2=ContainerRecord.TrapType
          VarQ3=ContainerRecord.TrapHits
          VarQ4!=ContainerRecord.TrapItem
          Var2$=ContainerRecord.ContainerShort
          Var2$=Rtrim$(Var2$)
          Var2$=Lcase$(Var2$)
          VarZ$=Var2$
          If Normal.User Then
             If UserRecord2.ClassType>=Lady Then
                Strng3=Rtrim$(Class.Name(UserRecord2.ClassType))
                Call A.Or.An
                Strng="You can't search "+Prefix1+Strng3+"."
                Call IO.O
                Exit Sub
             Endif
             If UserRecord.ClassType<AsstDM Then
                If UserRecord.ClassType<>Thief Then
                   Strng="Only thieves can smash containers!"
                   Call IO.O
                   Exit Sub
                Endif
                If UserRecord.Level<2 Then
                   Strng="Only level 2 thieves can smash containers!"
                   Call IO.O
                   Exit Sub
                Endif
             Endif
          Endif
          Call ContainerTraps(VarQ2,VarQ3,VarQ4!,VarZ$)
          If VarQ2=-1 Then ' *boom*
             Exit Sub
          Endif
          Temp4=False
          Call Smash.Container
          Exit Sub
       Endif
    Endif
    Strng="You can't search that user!"
    Call IO.O
    Exit Sub
 Endif
 Call Parse
 If Parser Then
    Call Numeric
 Endif
 Call Check.Room.Items
 Temp4=False
 If Temp7!=SFalse Then
    Call Num
    Call Check.User.Items
    Temp4=True
    If Temp7!=SFalse Then
       Call Num
       Call Examine.Containers
       If TempA! Then
          Call Smash.Container
       Else
          Strng="You can't smash that!"
          Call IO.O
       Endif
       Exit Sub
    Endif
 Endif
 If Temp7!>SFalse Then
    If TreasureRecord.Launchable Then
       Strng="You can't smash that!"
       Call IO.O
       Exit Sub
    Endif
    If TreasureRecord.Loadable Then
       Strng="You can't smash that!"
       Call IO.O
       Exit Sub
    Endif
    If TreasureRecord.Spell Then
       Strng="You can't smash that!"
       Call IO.O
       Exit Sub
    Endif
    If TreasureRecord.WeaponNumber>False Then
       If MessWorkRecord6.Charges<=False Then
          Strng="You can't! It's already broken!"
          Call IO.O
          Exit Sub
       Endif
       MessWorkRecord6.Charges=MessWorkRecord6.Charges-1
       If Temp4=False Then ' room.item
          Call Write.Record(RoomInvFile,Temp5!)
       Else ' user.item
          Call Write.Record(MessWorkFile6,Temp5!)
       Endif
       If MessWorkRecord6.Charges=False Then
          Strng="You broke it!"
          Call IO.O
       Else
          Strng="You smash it!"
          Call IO.O
       Endif
       Exit Sub
    Endif
    Strng="You can't smash that!"
    Call IO.O
    Exit Sub
 Endif
 If Temp7!<SFalse Then
    Temp7!=Abs(Temp7!)
    If ObjectRecord.Hidden Then
       Strng="You can't smash that!"
       Call IO.O
       Exit Sub
    Endif
    Call Return.Room(Var!)
    If Var!=SFalse Then
       Strng="You can't smash that!"
       Call IO.O
       Exit Sub
    Endif
    If ObjectRecord.KeyNumber Then
       Strng="You can't smash that!"
       Call IO.O
       Exit Sub
    Endif
    If ObjectRecord.DoorLock=0 Then
       Strng="You can't smash that!"
       Call IO.O
       Exit Sub
    Endif
    If ObjectRecord.DoorLock=1 Then
       Strng="It's already unlocked!"
       Call IO.O
       Exit Sub
    Endif
    If Len(option1$) Then
       Out2=option1$
       Call Equate(Temp#)
    Else
       Temp#=Int(Rnd*UserRecord.Stats(2))+1<Config2(33)
    Endif
    If Temp# Then
       Strng="You didn't smash it open!"
       Call IO.O
       Exit Sub
    Endif
    If Len(option2$) Then
       Out2=option2$
       Call Equate(Temp#)
    Else
       Temp#=Int(Rnd*UserRecord.Stats(1))+1<Config2(34)
    Endif
    If Temp# Then
       Strng="You didn't smash it open!"
       Call IO.O
       Exit Sub
    Endif
    If Len(option3$) Then
       Out2=option3$
       Call Equate(Temp#)
    Else
       Temp#=Rnd<Config1(21)
    Endif
    If Temp# Then
       Strng="You didn't smash it open!"
       Call IO.O
       Exit Sub
    Endif
    ObjectRecord.DoorLock=1
    Call Write.Record(ObjectFile,Temp7!)
    Strng="You smash it open!"
    Call IO.O
    If ObjectRecord.Trap Then
       Call Traps
    Endif
    Exit Sub
 Endif
 Strng="You can't smash that!"
 Call IO.O
 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$)="[CMD017]" 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 "smash.open1"
                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 "smash.open2"
                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 "smash.open3"
                If Left$(Var3$,1)=Chr$(34) Then
                   If Right$(Var3$,1)=Chr$(34) Then
                      option3$=Mid$(Var3$,2)
                      option3$=Left$(option3$,Len(option3$)-1)
                   Endif
                Endif
             End Select
          Endif
       Loop
    Endif
 Loop
 Return
ErrResume26:
 Exit Sub
ErrTrap26:
 Resume ErrResume26
End Sub

Sub Smash.Container
 On Local Error Goto ErrTrap37
 Gosub Get.Config2
 If ContainerRecord.Locked=False Then
    Call Damage.Container
    Exit Sub
 Endif
 If ContainerRecord.Locked=1 Then
    Call Damage.Container
    Exit Sub
 Endif
 If ContainerRecord.KeyNumber=SFalse Then
    Call Damage.Container
    Exit Sub
 Endif
 If Normal.User Then
    If UserRecord.ClassType<AsstDM Then
       If Len(option1$) Then
          Out2=option1$
          Call Equate(Temp#)
       Else
          Temp#=Int(Rnd*UserRecord.Stats(2))+1<Config2(33)
       Endif
       If Temp# Then
          Strng="You didn't smash it open!"
          Call IO.O
          Exit Sub
       Endif
       If Len(option2$) Then
          Out2=option2$
          Call Equate(Temp#)
       Else
          Temp#=Int(Rnd*UserRecord.Stats(1))+1<Config2(34)
       Endif
       If Temp# Then
          Strng="You didn't smash it open!"
          Call IO.O
          Exit Sub
       Endif
       If Len(option3$) Then
          Out2=option3$
          Call Equate(Temp#)
       Else
          Temp#=Rnd<Config1(21)
       Endif
       If Temp# Then
          Strng="You didn't smash it open!"
          Call IO.O
          Exit Sub
       Endif
    Endif
 Endif
 Call Read.Record(ContainerFile,TempA!)
 ContainerRecord.Locked=1
 ContainerRecord.Closed=True
 Call Write.Record(ContainerFile,TempA!)
 Strng="You smash it open!"
 Call IO.O
 Exit Sub
Get.Config2:
 VarX=0
 Do
    VarX=VarX+1
    If VarX>Options.Lines Then
       Exit Do
    Endif
    Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
    If Ucase$(Var$)="[CMD017]" 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 "smash.container.open1"
                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 "smash.container.open2"
                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 "smash.container.open3"
                If Left$(Var3$,1)=Chr$(34) Then
                   If Right$(Var3$,1)=Chr$(34) Then
                      option3$=Mid$(Var3$,2)
                      option3$=Left$(option3$,Len(option3$)-1)
                   Endif
                Endif
             End Select
          Endif
       Loop
    Endif
 Loop
 Return
ErrResume37:
 Exit Sub
ErrTrap37:
 Resume ErrResume37
End Sub

Sub Damage.Container
 On Local Error Goto ErrTrap37x
 Gosub Get.Config3
 If ContainerRecord.Damaged=True Then
    Strng="You can't! It's already damaged!"
    Call IO.O
    Exit Sub
 Endif
 If ContainerRecord.Material=3 Then
    Strng="You can't! It's metal!"
    Call IO.O
    Exit Sub
 Endif
 If ContainerRecord.Material=1 Then ' glass
    If Len(option2$) Then
       Out2=option2$
       Call Equate(Temp#)
    Else
       Temp#=UserRecord.Stats(1)<5
    Endif
    If Temp# Then
       Strng="You didn't smash it!"
       Call IO.O
       Exit Sub
    Endif
    Strng="You shatter it! It's contents fall to the ground!"
    Call IO.O
    Call Shatter.Container
    Exit Sub
 Endif
 If Len(option1$) Then
    Out2=option1$
    Call Equate(Temp#)
 Else
    Temp#=UserRecord.Stats(1)<10
 Endif
 If Temp# Then
    Strng="You didn't smash it!"
    Call IO.O
    Exit Sub
 Endif
 Call Read.Record(ContainerFile,TempA!)
 ContainerRecord.Damaged=True
 Call Write.Record(ContainerFile,TempA!)
 Strng="You smash it! Now it's damaged!"
 Call IO.O
 Exit Sub
Get.Config3:
 VarX=0
 Do
    VarX=VarX+1
    If VarX>Options.Lines Then
       Exit Do
    Endif
    Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
    If Ucase$(Var$)="[CMD017]" 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 "smash.container"
                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 "shatter.container"
                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
             End Select
          Endif
       Loop
    Endif
 Loop
 Return
ErrResume37x:
 Exit Sub
ErrTrap37x:
 Resume ErrResume37x
End Sub

Sub Shatter.Container
 On Local Error Goto ErrTrap37z
 If Temp4 Then
    Weight=Weight-ContainerRecord.Weight
    If Weight<DFalse Then
       Weight=DFalse
    Endif
 Endif
 VarA!=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
       Temp7!=MessWorkRecord6.User
       Temp6=MessWorkRecord6.Charges
       If Temp7! Then
          If Temp7!<SFalse Then ' object
             Temp7!=Abs(Temp7!)
             If Temp7!>SFalse And Temp7!<=Lof(ObjectFile)/ObjectRecLen Then
                Call Read.Record(ObjectFile,Temp7!)
                Call Drop.Item.In.Room(Temp7!,Temp6)
             Endif
          Else
             If Temp7!>SFalse And Temp7!<=Lof(TreasureFile)/TreasureRecLen Then ' treasure
                Call Read.Record(TreasureFile,Temp7!)
                If TreasureRecord.Container Then
                   Call Drop.Container.In.Room(Temp7!)
                Else
                   Call Drop.Inventory(Temp7!,Temp6)
                Endif
             Endif
          Endif
       Endif
       If Temp6!=SFalse Then
          Exit Do
       Endif
       Temp5!=Temp6!
    Loop
 Endif
 Temp5!=ContainerRecord.First2
 If Temp5! Then
    Do While Lost.Carrier=False
       Call Read.Record(ContainerFile,Temp5!)
       Temp6!=ContainerRecord.Next
       TempA!=VarA!
       TempB!=Temp5!
       Call Take.Within.Container2
       If Temp6!=SFalse Then
          Exit Do
       Endif
       Temp5!=Temp6!
    Loop
 Endif
 If Temp4 Then
    Call Delete.User.Container(VarA!)
 Else
    Call Delete.Room.Container(VarA!)
 Endif
ErrResume37z:
 Exit Sub
ErrTrap37z:
 Resume ErrResume37z
End Sub
