Tuesday, March 4, 2014

Heart Realm Update #012

There's been a decent amount of progress since the last update including some minor changes to the damage/armor system and some basic spell casting functionality. That being said, this post is going to be quite wordy as I cover these things in detail.

Damage/Armor Change

To start off with I'm going to talk about the changes to the damage/armor system. Originally the way damage worked was there was a range of 2 numbers and the damage would be random between those two values. For example you had a weapon that had an attack damage of 38-45, it would deal an amount between 38 and 45, so like 42 for example. That random number would then be calculated against the target's armor in a fairly simple formula. The result of that formula would then be broken down into multiple numbers based on the attack elements, for example an Iron Fire Sword that had an attack of 38-45 with 70% Physical, 30% Pierce, 30% Fire (the percentages didn't have to add up to 100%). So with that result of say 31 after the armor calculation and the randomly chosen number from that range, that 31 would be split up based on those percentages. You'd have 21.7 Physical, 9.3 Pierce, and 9.3 Fire damage, each of those numbers would then be reduced further based on the target's resistances. For example a goblin with 5% Physical, 0% Pierce, 0% Fire resistance would reduce that 21.7 Physical, 9.3 Pierce, and 9.3 Fire to 20.615 Physical, 9.3 Pierce, 9.3 Fire damage. Those numbers would be added up: 20.615 + 9.3 + 9.3 = 39.215 then converted to an integer for the final amount, 39.
  1. Random number between: 38-45, 42
  2. 42 calculated in a simple formula vs target's armor value = 31
  3. 31 split between 70% Physical = 21.7, 30% Pierce = 9.3, 30% Fire = 9.3
  4. Array of values reduced by target's resistances: 21.7 * 95% (5% Physical Resistance), 0% Pierce and 0% Fire Resistance.
  5. Add up values: 20.615 + 9.3 + 9.3 = 39.215 = 39 (converted to integer)
That was changed to a more direct damage and armor system. Now all damage is an array (well hashmap, technically) of values in their element's respective index with no range (the random element is still present). So for example that Iron Fire Sword is now: 22 Physical, 9 Pierce, and 9 Fire damage. Those numbers are then calculated in the same way armor was originally calculated, except vs each of these values and instead of having one armor value it's just the resistances array and they are no longer percentage reductions. So for example that Goblin with: 15 Physical, 15 Strike, 5 Slash, 15 Pierce, 0 everything else, would be calculated against each of the damage values from the attack. With a result of: 13 Physical, 3 Pierce, 9 Fire damage, added up to 25. That number would would then have a variance value applied to it, of say 15% so the total could be anywhere between 21.25 and 28.75 (25 * +-15%). Of course all of this doesn't include the stat scaling from Strength, Dexterity, and Intellect, which would occur before the resistances are calculated. That 22 Physical damage could go up to like 32 with a decent Strength scale, for example.

Why did I make this change? Well it's easier to articulate how effective a piece of armor is vs certain damage types compared to other damage types it's applied to. The different attack elements have more weight in the actual outcome where before resistances were percentage based which is fine for higher values, but I didn't want a low level Goblin to resist 15% of all physical damage on top of the base armor. It's just simpler to see a single number to represent all physical damage reduction, or fire damage reduction, etc than having the armor value, plus the resistances which were percentage reductions (not the best decision initially). I can now have a piece of armor that does really well at protecting against lightning damage, but terrible at everything else, before that, since it was percentage based, that level of protection would vary based on the incoming damage.

Abilities

Enough about the damage/armor change. Let's talk about the progress on spell casting and abilities. In the previous update I believe I mentioned some basic spell casting. At that point the one spell I had was stored in an XML file, which more were going to be stored in as well, but that limits the potential of spells and abilities I could have as I would need to write a whole bunch of java classes with a variety of functionality for the number of possible abilities.

I now have it working where there's just a very basic ability class that calls a cast function on an ability's script that is tied to that object. I would have multiple basic ability objects with a script tied to it each with their respective ability scripts. For example 1 script file for Magic Missile, 1 script file for Force Push, 1 script file for Fireball, etc. The game would have 3 different ability objects each tied to one of those script files and would call the cast function on their scripts. The script would then handle any logic necessary. I could have a spell that does the specific thing of moving the player up 2 tiles, then left 3 tiles if I wanted to, all of which would be in that script.

Dumping the logic of each specific ability into a script file allows for much more freedom in the types of abilities instead of creating a Java class file for each ability or an XML file that stored some data on these spells that were based on some basic spell archetypes. XML files work just fine for static types of content like a weapon or armor where there is no interaction with anything in the game world or entities, but for something like abilities where you'd want some kind of interaction with the game world or whatever, scripts work wonderfully. That being said, I'll be using Lua for all scripting which would be for things like AI, abilities, possibly dialog, basic world generation (the setup at least), etc. I will be using XML for the more static types of content like items, armor, weapons, and enemies. Fortunately, if I wanted to, I can link any of these static types of content to scripts as well. I could have a weapon that when it hits an enemy knocks them back, or teleports the player 5 tiles to the left, of course that's not very practical and just doesn't make sense, but it can be done.

Scripting is a beautiful thing, and I'm glad I finally got around to implementing Lua. It's been a bit challenging working with Lua as someone who's new to it, trying to fix problems that I won't know about until I test it out, but I've been improving and it's been going great so far.

To finish off this lengthy update, instead of including screenshots, I've decided to include a video which sort of demonstrates the bare-bones spell casting system, showing off like 4 or 5 different spells, as well as the inventory and character screens.


Note: I'm going to try and include labels for these posts from now on. I think it will improve the organization of these updates. I've also gone back and added labels to all my previous Heart Realm updates.

~ Rogue Templar

No comments:

Post a Comment