Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Game Programming -> Player Agro

RayonMazterRayonMazter Member Posts: 1
In order to get the target a creature will attack, it bases it off the players agro, which can have a large range between 1 and 1000.

My code is below, but i'm wondering if there are better algorithms for this system.
Public Class TChance
Public MinVal As Integer
Public MaxVal As Integer
Public Obj As Object

Sub New(ByVal _MinVal As Integer, ByVal _MaxVal As Integer, ByVal _Obj As Object)
Me.MinVal = _MinVal
Me.MaxVal = _MaxVal
Me.Obj = _Obj
End Sub
End Class

Function Get_Player_To_Attack(ByVal Players As List(Of Object)) As TPlayer
Dim AgroCount As Integer
Dim ListArray As New List(Of TChance)
For Each P As TPlayer In Players
Dim Chance As New TChance(AgroCount, P.Character.Agro, P)
AgroCount += P.Character.Agro
Dim Rando As Integer = Rand(0, AgroCount)
For Each Chance As TChance In ListArray
If Rando >= Chance.MinVal Then
If Rando <= Chance.MaxVal Then
Return Chance.Obj
End If
End If
End Function
Sign In or Register to comment.