*Feel free to read only parts of the post and reply concerning only specific algorithms*
Hello there, I have recently started making a simple web browser game (Coded in VB) in order to make time go by. I have moderate development finished (details shortly) and need some help with my algorithms in particular.
At the moment, I have the inventory, quest, leveling, combat and map systems running. I plan future implementation of extra stuff but would like to get through these pesky algorithms first.
The most important at the moment are my combat algorithms. I have 1 for combat damage dealt to an enemy, combat damage from an enemy and a critical hit calculator. Note, I currently have 2 classes for the game, Rogue and Warrior and currently only have 2 attributes that affect damage, strength and agility. As you see in the code below, rogues gain more from having agility and warriors from having strength. (Rogues have higher crit chance, though less health than warriors.)
Type: r=Rogue, w=Warrior
astr/aagi: Character strength/agility
weapRNG: A random number between the minimum and maximum damage of the equipped weapon
ddef: Enemy defense
tagi: used to calculate critical hit chance
dmg: Damage dealt
If a.type = "r" Then
dmg = (((astr / 2) + aagi) + weapRNG) - ddef
tagi = (aagi - (dagi / 2)) * 4
ElseIf a.type = "w" Then
dmg = ((astr + (aagi / 2)) + weapRNG) - ddef
tagi = (aagi - (dagi / 2)) * 2
End If
The damage just doesn't always seem all that random sometimes. Maybe with better implementation and extra attributes things could go smoother? (I would like to implement a "Miss" algorithm as well, currently it's 100% hit rate.)
Now the similar enemy damage algorithm:
*Note: Why divide the str and agi instead of just creating enemies with half the values? Because I just recently notice I was not incorporating agility into the damage calculation (Doh!) and quickly added it and have not had the time to balance the attributes.
Dim dmg As Integer = ((astr / 2) + (aagi / 2)) - ddef
Dim tagi As Integer = aagi * 5
I find it very hard to calibrate this puny thing in order to have balance damage for every monster that I have. I have some weak, some strong, some bosses, and I would like to be able to have 1 algorithm that balances the damage they all do accordingly. Mine just seems very sloppy and hard-cut.
Next, the crit calculator, which is the same for everyone save the damage that a critical hit does. Players get *3 damage while enemies get *2 damage:
the tagi variable is used to randomly generate a number between tagi and tagi +100. Using my very simple logic, here's an example: tagi = 5. Generate a number between 5-105. If the number is above 100, a crit occurs. Therefore, there is a 5% chance a crit will occur. Very sloppy indeed.
Dim random As New Random
Dim crit As Integer = random.Next(tagi, 100 + tagi)
If crit >= 100 Then
dmg = dmg * 3
msg = "It was a crit! "
End If
Id you have any suggestions regarding these algorithms, including adding additional variables (which I plan to anyways) please let loose, ideas spark other ideas, even if one thinks their idea is not the best.
Now, I have my "random encounter" algorithm as such:
Dif: Difficulty setting, 20 default.
prob: Starts at 0, increments by 5 every time a combat is not initiated, resets after a combat.
battle: random number generated between 1 and 50 (1-49, 50 is excluded limit)
Add them all up and if it's greater than or equal to 100, a battle occurs.
Dim random As New Random
Dim battle As Integer = random.Next(1, 50)
battle = battle + prob + dif
If battle >= 100 Then
Return True
Else
Return False
End If
It's the first thing I came up with and is very dirty, as are most of my other ones. This is the one I am least worried about however considering it gives me 6-8 steps before getting into an encounter. And yes, for now all terrains give same chances but that can easily be modified with an extra variable. Any advice on this?
That is all for the moment. Thank you for taking the time to read any of this and helping me out with my first game! Leave as many comments as desired so we may discuss at length!