Wednesday, May 22, 2013

Heart Realm Update #006

This week I decided to focus my time on combat. In doing so I started figuring out what happens when an enemy/the player is hit by an attack, and all necessary calculations that came with it. I also worked on the combat layer, which included some kind of AI for the mobs as well as a way for combat to actually start. To finish off the week, in keeping with the theme of combat, I added health/mana bars to the player and enemies (just health bar) and damage numbers when hit.

I'll go into detail about how the attack effect works first. When trying to solve the problem of what happens when a character, be it player or enemy, is hit, I need to come up with some formulas that calculated what happens in that instance. What came with that was figuring out all necessary calculations that needed to take place for whether you actually hit, how much damage you deal, and how critical hits work. The formulas took a little bit of time to figure out. I had to come up with a way that made sense in the context of this game and so it took me a few weeks figuring this out. Ultimately I came up with some formulas that I liked, which is what matters, and I felt were balanced, though we'll see as time goes on. Rather than just going through some long in-depth explanation of all the calculations, I think it'll be easier to just list them here as they're fairly straight forward.

1) Chance to Miss = (Defender's Agility + Defender's Reflex) ^ 2 / (Attacker's Dexterity + Attacker's Base Hit Chance) ^ 2 * 120
    1a) Base Hit Chance is based off the player's weapon for example: with a slower heavier weapon like a great two-handed hammer it would have a lower Hit Chance of like 60, while something quicker, easier to hit with like a shortsword, it could have a Hit Chance of like 90.

2) Attack power = Random value between Minimum and Maximum basic attack damage
3) Damage = (Attack Power x Attack Power) / (Attack Power + Armor of defender

4) Correct Damage based on Elemental weaknesses/resistances. For example Dragon has elemental set of 100% Physical, 35% Fire damage for it's basic attack against the player who has 0% Physical resistance and 15% Fire resistance.
    4a) For each element in the attacker's element set add the following result to the initial value of 0
    4b) Result = 0
    4c) Result += Attack Element Value x (100 - Defender's Element Resistance) / 100
    4d) Result /= 100
    4e) For the example: Result = ((100 x (100 - 0) / 100) + (35 x (100 - 15) / 100)) / 100
    4f) That would come out to... 1.2975 which is what you would multiply the current Damage value by

5) Chance to Critical Hit = Bonus Crit. Rate + (4 * Attacker's Dexterity / Defender's Agility)
6) If Crit Hits: Damge is multiplied by: (200 + Bonus Crit. Damage) / 100

Then the result is what is subtracted from the defender's health.

I now realize that writing that all out takes up a lot of space when explaining things too, which I said I wouldn't, but oh well.

Next we have the combat itself. When the player is within an enemies sight range and has line of sight (not yet implemented) the enemy will be added to the combat "encounter" meaning they will then perform an action as a response to your actions. In the game's current state I only have one AI type and it is a very basic melee enemy AI package. That's also something I'd like to mention. I hope to create multiple packages for the various types of AI that enemies can use making it easier to add in new ones without having to re-write a lot of code. I'll probably have a data set too so I can import more from data files like all my other content in the game. Going back to the melee AI, the way it currently works is the enemy will either move towards the player, or attack when it performs an action. The way it decides on whether it moves or not is a random chance based on the player and enemies Agility differences, slower enemies less likely to move, faster enemies more likely to move as well as a static "Initiative" value. If it decides not to move it will then see if it can attack the player, if is within range and not affected by some restrictive status condition, otherwise it'll just stand still doing nothing.

Finally I added in health bars for characters, which was quite simple as well as a mana bar for the player (don't want to show enemies mana pool) and numbers that pop up above the character's when receiving damage. For the damage numbers displaying them wasn't too hard in that I had to come up with a way to display text on the screen in a more manageable way, which was quite simple, but the hard part was positioning them in proper location. Ultimately it boiled down to how I used one of the functions I created. I was calculating the offsets wrong which can be a bit of a pain to figure out sometimes.

For this update rather than posting some screen shots, which wouldn't show you much other than the health/mana bars and damage numbers, I figured I'd upload a quick video showing both that stuff and the AI in action.


~ Rogue Templar

No comments:

Post a Comment