⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 modmonster.vb.svn-base

📁 MirUnleashed vb.net Module modMainServer Public WithEvents Socket As New WinsockServer Pub
💻 SVN-BASE
📖 第 1 页 / 共 5 页
字号:
                End If

                'Get all the local objects around the monsters area
                Dim LocalPlayers As Hashtable = GetLocalPlayers(X, Y, Map, mStats.ViewRange, mStats.ViewRange)
                Dim LocalPets As Hashtable = GetLocalPets(X, Y, Map, mStats.ViewRange, mStats.ViewRange)
                'If there is no ememies around the monster then there is no targets to find
                If LocalPlayers.Count = 0 And LocalPets.Count = 0 Then Exit Sub
                'There are enemies for the monster to target

                Dim ClosestPlayer As Integer = 50
                Dim ClosestPlayerID As Integer = -1
                Dim ClosestPet As Integer = 50
                Dim ClosestPetID As Long = -1

                If Not LocalPlayers.Count = 0 Then
                    'There are players around the monster
                    'Find the nearest player
                    Dim pID As Integer 'PlayerID
                    Dim i As Integer
                    Dim Done As New Hashtable
                    Dim Closeness As Integer

                    For i = 0 To LocalPlayers.Count - 1
                        pID = LocalPlayers(i)
                        If Not Done.ContainsKey(pID) Then
                            Dim lPlayer As clsPlayer
                            lPlayer = ObjectList(pID)
                            If Not lPlayer.IsDead And Not lPlayer.Name = PetOwner Then
                                Closeness = (lPlayer.X - X) + (lPlayer.Y - Y)
                                If Closeness < ClosestPlayer And Closeness <> 0 Then
                                    ClosestPlayer = Closeness
                                    ClosestPlayerID = pID
                                    If ClosestPlayer = 1 Then
                                        Exit For
                                    End If
                                End If
                            End If
                            Done.Add(pID, "")
                        End If
                    Next i
                End If

                If Not LocalPets.Count = 0 Then
                    'There are pets around the monster
                    'Find the nearest pet
                    Dim pID As Long 'PetID
                    Dim i As Long
                    Dim Done As New Hashtable
                    Dim Closeness As Integer

                    For i = 0 To LocalPets.Count - 1
                        pID = LocalPets(i)
                        If Not Done.ContainsKey(pID) Then
                            Dim lMonster As clsMonster
                            lMonster = ObjectList(pID)
                            If Not lMonster.IsDead And lMonster.MobId <> MobId Then
                                Closeness = (lMonster.X - X) + (lMonster.Y - Y)
                                If Closeness < ClosestPet And Closeness <> 0 Then
                                    ClosestPet = Closeness
                                    ClosestPetID = pID
                                    If ClosestPet = 1 Then
                                        Exit For
                                    End If
                                End If
                            End If
                            Done.Add(pID, "")
                        End If
                    Next i
                End If

                'Find out which is closest to the monster, Player or Pet
                If ClosestPet > ClosestPlayer Then
                    'Player is closer to the monster
                    'Target Player
                    TargetId = ClosestPlayerID
                    Target = Races.Player
                ElseIf ClosestPlayer > ClosestPet Then
                    'Pet is closer to the monster
                    'Target Pet
                    TargetId = ClosestPetID
                    Target = Races.Monster
                Else
                    'They are both as close as each other
                    If Rand(0, 1) = 0 Then
                        'Target Player
                        TargetId = ClosestPlayerID
                        Target = Races.Player
                    Else
                        'Target Pet
                        TargetId = ClosestPetID
                        Target = Races.Monster
                    End If
                End If

                If Not Target = Races.None Then
                    'Begin trying to attack target
                    AttackTarget()
                End If
            End If
        End Sub

#End Region
#Region "Wonder"

        Private Sub Wonder()
            Dim Stats As clsMobStats = MonsterStatsList(Me.Name)
            If LastWalk + (Stats.WalkSpeed * 10000) < Now.Ticks Then

                If Rand(0, 20) = 0 Then
                    If Rand(0, 4) = 0 Then
                        GMCommands.GMShout("Server", "Monster Turned")
                        Turn()
                    Else
                        GMCommands.GMShout("Server", "Monster Walked")
                        Walk()
                        LastWalk = Now.Ticks
                    End If
                End If

            End If
        End Sub

#End Region
#Region "AttackTarget"

        Private Sub AttackTarget()
            If Not Target = Races.None Then
                'We have a target
                Select Case Target
                    Case Races.Player
                        Dim tPlayer As clsPlayer = ObjectList(TargetId)

                        If tPlayer Is Nothing Then
                            TargetId = 0
                            Target = Races.None
                            Exit Sub
                        End If

                        If tPlayer.IsDead Then
                            TargetId = 0
                            Target = Races.None
                            Exit Sub
                        End If

                        If IsNextTo(tPlayer.X, tPlayer.Y) Then
                            'Begin attacking the target
                            Dim Stats As clsMobStats = MonsterStatsList(Me.Name)
                            If LastHit + (Stats.AttackSpeed * 10000) < Now.Ticks Then
                                'Face target
                                Me.Dir = FaceTarget(New Point(tPlayer.X, tPlayer.Y), New Point(Me.X, Me.Y))

                                'Start calculating damage
                                '######################'
                                '######################'
                                Dim Damage As Short 'Amount of damage
                                Dim WillHit As Boolean = False 'Will it hit or not?
                                Dim tMonster As clsMonster
                                Dim tMonStats As clsMobStats

                                '#######################################'
                                '###GET THE DAMAGE + IF WE HIT OR NOT###'
                                '#######################################'

                                'Attack Player
                                'Get the damage we do
                                Damage = GetDamage(Stats.DC, Stats.MaxDC, 0)

                                'Do we hit or miss?
                                If Stats.Accuracy > Rand(0, tPlayer.Agility) Then
                                    WillHit = True
                                End If

                                'If the target player is dead then we cant hit him
                                If tPlayer.IsDead Or tPlayer.HP <= 0 Then
                                    Damage = 0
                                    WillHit = False
                                End If

                                'If were not going to hit it dont hurt it
                                If WillHit = False Then Damage = 0
                                If Damage = 0 Then WillHit = False

                                'Get the real damage including AC
                                If Damage > 0 Then
                                    Damage = Math.Max(0, Damage - GetAC(TargetId))
                                    'Dim WeapDuraLoss As Byte = Rand(0, 5) + 2
                                    'If Player.LooseDura(WeapDuraLoss, EquipId.weapon) Then
                                    '    'TellPlayer weapon broke
                                    'End If
                                End If

                                Dim HP As Integer
                                Dim MaxHP As Integer
                                Dim MP As Integer

                                '########################################'
                                '###DO THE ACTUAL DAMAGE TO THE TARGET###'
                                '########################################'

                                'Now do the damage
                                If Damage > 0 Then
                                    'Take away some of taget players HP
                                    tPlayer.HP = Math.Max(tPlayer.HP - Damage, 0)
                                    If tPlayer.HP <= 0 Then
                                        'Player died, has he got a revival ring?
                                        tPlayer.Died()
                                    End If
                                    HP = tPlayer.HP
                                    MaxHP = tPlayer.MaxHP
                                    MP = tPlayer.MP
                                    'Process any loss on dura
                                    'Dim Break As Boolean = False
                                    'Dim DuraLoss As Byte = Rand(0, 10) + 5
                                    'For i = 0 To 10
                                    '    If i = equipid.weapon Or i = equipid.candle Or equipid.shoes Then
                                    '    ElseIf tPlayer.losedur(durloss, i) = True Then
                                    '        If i = equipid.armour Or i = equipid.helmet Then
                                    '            break = True
                                    '            'tell others we broke something later :p
                                    '        End If
                                    '        If i = equipid.candle Then
                                    '            sendchangelight(State.Index, PlayerList(Player.Name), Player.Light)
                                    '            'technicaly we should tell others our light ended aswell
                                    '        End If
                                    '    End If
                                    'Next i
                                    'If break = True Then
                                    '    tPlayer.recalcstats()
                                    '    'send the packet informing targetplayer about his new stats
                                    '    sendlookchanges(tPlayer)
                                    'End If


                                End If

                                '######################################'
                                '###TELL EVERYONE YOU HIT THE TARGET###'
                                '######################################'

                                Dim i As Integer
                                Dim Locals As Hashtable = GetLocalPlayers(Me.X, Me.Y, Me.Map, 15, 15)
                                If WillHit And Damage > 0 Then
                                    'Attack has been Processed, Tell Players what got hit
                                    Dim lPlayer As clsPlayer
                                    For i = 0 To Locals.Count - 1
                                        If Not Locals(i) Is Nothing Then
                                            'Tell players
                                            lPlayer = ObjectList(Locals(i))
                                            If tPlayer.IsDead Then
                                                'If player died tell everyone
                                                Packets.SendDied(lPlayer.StateId, tPlayer.StateId, Target)
                                                GMCommands.GMShout(Me.Name, "Killed " & tPlayer.Name)
                                                'Do Drops
                                            Else
                                                GMCommands.GMShout(Me.Name, "Hit " & tPlayer.Name)
                                                Packets.SendStruck(lPlayer.StateId, Target, GetSmallPlayerBuffer(tPlayer))
                                            End If

                                        End If
                                    Next i
                                End If
                                '######################'
                                '######################'

                                Dim pID As Integer

                                For i = 0 To Locals.Count - 1
                                    pID = Locals(i)
                                    tPlayer.Attacker = Races.Monster
                                    tPlayer.AttackerId = MobId
                                    Packets.SendHit(pID, Me.MobId, Races.Monster, Me.Dir)
                                Next i
                                LastHit = Now.Ticks
                            End If
                        Else
                            'Move towards the target
                            'GMCommands.GMShout(Me.Name, "Moving towards: " & tPlayer.X & ":" & tPlayer.Y)
                            GotoTarget()
                        End If
                    Case Races.Monster
                        Dim tMonster As clsMonster = ObjectList(TargetId)

                        If tMonster Is Nothing Then
                            TargetId = 0
                            Target = Races.None
                            Exit Sub
                        End If

                        If tMonster.IsDead Then
                            TargetId = 0
                            Target = Races.None
                            Exit Sub
                        End If

                        Dim tMonStats As clsMobStats = MonsterStatsList(tMonster.Name)

                        If IsNextTo(tMonster.X, tMonster.Y) Then
                            'Begin attacking the target
                            Dim Stats As clsMobStats = MonsterStatsList(Me.Name)
                            If LastHit + (Stats.AttackSpeed * 10000) < Now.Ticks Then
                                'Face target
                                Me.Dir = FaceTarget(New Point(tMonster.X, tMonster.Y), New Point(Me.X, Me.Y))

                                'Start calculating damage
                                '######################'
                                '######################'
                                Dim Damage As Short 'Amount of damage
                                Dim WillHit As Boolean = False 'Will it hit or not?

                                '#######################################'
                                '###GET THE DAMAGE + IF WE HIT OR NOT###'
                                '#######################################'


                                'Attack Monster
                                Damage = GetDamage(Stats.DC, Stats.MaxDC, 0)
                                'Do we hit or miss?
                                If Stats.Accuracy > Rand(0, tMonStats.Agility) Then

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -