Welcome to the new platform of Programmers Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use it's exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
Game Programming -> Player Agro
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
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