• Add Review
  • Subscribe
  • Nominate
  • Submit Media
  • RSS

How hard do I punch?

  • kentona
  • 02/26/2015 06:11 PM
  • 2479 views
I want to chat about my damage algorithm because right now it is so basic. My algorithm is so basic it wears Ugg boots. My algorithm is so basic that it exclusively drinks Starbucks pumpkin spice lattes.

pseudocode
A battler's damage is randomly chosen between 80% to 120% of their base attack power.
If they have a weapon equipped, choose a random value between the weapon's min and max damage range and add it to the battler's damage.
Set the damage element to the weapon's element (or default to PHYSICAL)

Actual code
//just hardcode range for now
double atkrange = 0.8 + ((1.2 - 0.8) * rand.nextDouble());
damage = (int) (this.getAtk() * atkrange);

//get weapon range
if (this.getEquippedWeapon() != null) {
	int weaprange = rand.nextInt(this.getEquippedWeapon().getRange() + 1) + this.getEquippedWeapon().getMinDamage();
	damage += weaprange;
...etc...


that's some basic shit


But I don't really have any better ideas. All the creativity for attacks and damage are built into weapons - min and max ranges, damage types, critical rates, lifesteal, etc... And I don't currently have a concept of "defense" built into the game (yet).

However, right now "damage" is passed around as a mapping between Damage_Type and an integer, so the potential is there to have a damage that does: like 16 PHYSICAL, 3 ICE, 10 ELECTRIC damage, Diablo 2 style.

For defense, I am inclined to go down the "resistances" route - ie: 15% resist PHYSICAL, 30% resist FIRE, etc... with a hard cap of 75% (also Diablo 2 style).

...maybe I should look up Diablo 2's damage algorithm?

I am really looking for ideas and brainstorming here on how to approach damage and defense.

Posts

Pages: 1
Wasn't the D2 optimal stat spread just hitting minimum requirements for cool gear and pumping the rest into vitality and energy? When it came time to kick butt you prayed to RNJesus that he gave you a rare weapon with good and relevant modifiers on it (also using the right skills, don't choose poorly!).

Also my understanding of defense and resistances in D2:
- Defense only affects if melee attacks hit
- Unless it's an attack that defense doesn't apply
- Or you're running, then defense doesn't apply
- Blocking only affects ranged physical attacks
- Resistances for the rest


My suggestion is to have weapons have their own damage algorithms that are applied when the weapon is used. So we might have
- Longsword, which does STR * 2 + 10 physical damage, +20% crit damage
- Fire Sword, which does STR + 30 fire damage + STR physical damage
- Shoot Guns, which does 50 physical damage

Weapons use stats instead of weapons augmenting stats and attacks using just stats as seen in RPG Maker. Equip weapons that have effects you want and compliment your stats!


For resistances I hate cumulative percentages like D2 due to marginal utility. Say you get Ring of Fire Resist, +5% fire resistance. When is it best to use? If you're naked then that +5% fire resistance means shit, 100 fire damage will become 95, yippee ki fucking yay. Now if you've found a few good sources of it you can finally stack them and that +5% can finally become relevant when you, say, have 60% fire resistance bring it up to 65%. The same 100 fire damage goes from 40 damage to 35, that fire ring will shave off 1/8th of the damage you would've taken instead of 1/20th.

The problem is that the first percentage points are worth significantly less than the last ones and without being able to hit a good baseline the Ring of Fire Resistance is garbage. You'd be better off with a ring of anything else until you can get a baseline going. It also has scaling issues, if equipment improves over time and you start finding Ring of Fire Resist +1 for +10% fire resistance the player will hit the resistance cap and then the only purpose of fire resistance gear is to replace old fire resistance gear with other gear that doesn't have it and having max resistance becomes the natural player state. D2 worked around this with the negative resistance modifiers in Nightmare and Hell difficulties.


*
I'll finish my post when I have more time, posting form work can be problematic


e:
Here's a quote from Jude that told me about a defense algorithm that compensates for marginal utility:
author=Jude
I think having two formulas goes against a transparent system. If you are that concerned with enemies dealing a non-trivial amount of damage even at high defensive values, consider scaling damage reduction from defense off of the idea of "effective HP," which is an increasingly popular solution in modern western RPGs. Basically, you scale the effectiveness of defense based on how many more hits it allows an actor to sustain rather than how much defense reduces the amount of damage per hit.

If that doesn't make sense, observe these formulas and this shitty unlabeled graph I made in ten seconds:

Modifier = 100 / (100 + Defense)
Damage = Modifier * Attack



In the graph, X represents the number of hits the target can sustain while Y represents the amount of armor the target has. For this graph I used a constant Attack of 100 and a constant Health of 1000. As you can see, every 10 points of Defense increases the number of hits a target can sustain by 1.



This second graph shows armor as X and damage as Y. At 0 armor, 100 damage is received. At 50 armor, 66 damage is received. At 100 armor, 50 damage is received. You can see how the formula has "diminishing returns" built into it without having to compare two different equations and taking the better of the two--the rules are consistent across the board which allows for transparency. Keep in mind that the "diminishing returns" are applied to damage mitigation, while the hits vs armor graph clearly shows there are no diminishing returns in the way that actually matters (how many hits can I take?).

This page has a video and examples describing the algorithm too.
Boss! That's exactly the kind of thing I was grappling with with defense and this is exactly the solution I'd want to implement!
Oh yeah, if you want to stick to attack ranges you can go the D&D way where weapons have a damage range based on dice and stat modifiers to that. So you have a Battleaxe that does 1d12 (1-12) + Strength Modifier or a Great Sword that does 2d6 (1-6 + 1-6 for 2-12 with a weighting in the middle) + Strength Modifier. It keeps stats more relevant than D2's approach (hit min requirements) while still having damage ranges.
LockeZ
I'd really like to get rid of LockeZ. His play style is way too unpredictable. He's always like this too. If he ran a country, he'd just kill and imprison people at random until crime stopped.
5958
I think you can get away with pretty basic damage formulas for the most part. I would say that making defense work in a way such that damage is divided by the target's defense, rather than having the target's defense be subtracted, is definitely better in games where you only control a single character.

Explanation: If defense is subtracted from the final damage then damage can be zero. If your defense outranks the enemy's attack by a big enough margin you are simply invincible. This can be interesting in games where you control a larger cast, like a tactical RPG or a crazegame, because high defense becomes like an elemental immunity, and the player can switch characters or use buffs to overcome it. When you only have one character and your stats are set in stone it's just "oops, you lost."

I would handle defense and shields/armor differently from each-other. Since the armor is mostly designed around blocking specific types of attacks, one idea which might work would be for each shield item to give the robot an amount of damage immunity to a specific element. A weatherguard would prevent the first 100 damage worth of water damage, a tower shield would prevent the first 250 damage worth of beam cannon damage, and so forth. After your opponent deals that much damage, the shield is broken and your robot starts taking damage instead.
So, what I have done is changed it so that instead of just having a base ATK for your battler and weapon's having a MIN and MAX and TYPE, I've implemented a map of TYPEs and MINs and MAXs (and called it DAMAGE). So that means that battlers have a base level of damage for each element, and weapons can add to that in any combination of elements.

for example:
battler base damage:{PHYSICAL=MinMax <min=16, max=24>, COLD=0, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=0, SONIC=0}

here are some weapons I hardcoded:

Squaturian's Weapons: <Weapon <name=Sword {PHYSICAL=MinMax <min=2, max=12>}>, Weapon <name=Flamesword {PHYSICAL=MinMax <min=1, max=5>, FIRE=MinMax <min=1, max=4>}>>
Planet Smasher's Weapons: <Weapon <name=Big Stick {PHYSICAL=MinMax <min=1, max=8>}>, Weapon <name=Ice Stick {PHYSICAL=MinMax <min=1, max=4>, COLD=MinMax <min=1, max=12>}>>

For ATK, it still exists, except now it is translated into PHYSICAL with a 80% to 120% range, and set in that battlers DAMAGE map.

I don't have defense implemented yet, but it will follow the same map concept: a DEFENSE map of each element. I love that Modifier algorithm that GRS/Jude posted, so I will be doing that once I get around to there.

foreach ELEMENT
Modifier = 100 / (100 + ELEMENT.Defense)
Damage = Modifier * ELEMENT.Attack


I like the idea of elemental shields absorbing damage, so I will have to think on a good way of implementing that! Probably a SHIELD map for each element, and set it to 0 to start, and if the battler deploys a shield, increment that ELEMENT by the shield's value, and subtract from that first before touching HP for that ELEMENT.

Anywho, here is what the output is looking like now:

Welcome to Battledome!
Enter your name: K
Thanks for the name, K
0 - Squaturian: a Brute-class battler
1 - Planet Smasher: a Crawler-class battler
2 - Lil Mac: a Fighter-class battler
3 - Lilith: a Lithe-class battler
4 - Johnny5: a Johnny5-class battler
any other number - Robot: a default robot battler
Enter battler number 1 ID: 0
Enter battler number 2 ID: 1
Squaturian's Weapons: <Weapon <name=Sword {PHYSICAL=MinMax <min=2, max=12>}>, Weapon <name=Flamesword {PHYSICAL=MinMax <min=1, max=5>, FIRE=MinMax <min=1, max=4>}>>
Planet Smasher's Weapons: <Weapon <name=Big Stick {PHYSICAL=MinMax <min=1, max=8>}>, Weapon <name=Ice Stick {PHYSICAL=MinMax <min=1, max=4>, COLD=MinMax <min=1, max=12>}>>
Turnpoints threshold is 456
----- Turn 1 -----------------------------------
Turnpoints: Squaturian= 308 Planet Smasher= 289
Squaturian added 213 turnpoints for total of 521
Squaturian added to turnqueue, has 65 turnpoints remaining.
Planet Smasher added 205 turnpoints for total of 494
Planet Smasher added to turnqueue, has 38 turnpoints remaining.
Squaturian prepares to act...
battler base damage:{PHYSICAL=23, COLD=0, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=0, SONIC=0}
Squaturian inflicts {PHYSICAL=23, COLD=0, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=0, SONIC=0} damage to Planet Smasher
Planet Smasher: 172/195 HP
Planet Smasher prepares to act...
Planet Smasher has deployed the Big Stick
battler base damage:{PHYSICAL=12, COLD=0, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=0, SONIC=0}
add weapon damage:{PHYSICAL=20, COLD=0, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=0, SONIC=0}
critical(1.4):{PHYSICAL=28, COLD=0, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=0, SONIC=0}
Planet Smasher attacks! Terrific blow!
Planet Smasher inflicts {PHYSICAL=28, COLD=0, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=0, SONIC=0} damage to Squaturian
Squaturian: 192/220 HP
End of turn 1 (press <Enter> to continue)
----- Turn 2 -----------------------------------
Turnpoints: Squaturian= 65 Planet Smasher= 38
Squaturian added 218 turnpoints for total of 283
Planet Smasher added 219 turnpoints for total of 257
Turnpoints: Squaturian= 283 Planet Smasher= 257
Squaturian added 229 turnpoints for total of 512
Squaturian added to turnqueue, has 56 turnpoints remaining.
Planet Smasher added 221 turnpoints for total of 478
Planet Smasher added to turnqueue, has 22 turnpoints remaining.
Squaturian prepares to act...
Squaturian has deployed the Sword
battler base damage:{PHYSICAL=23, COLD=0, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=0, SONIC=0}
add weapon damage:{PHYSICAL=33, COLD=0, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=0, SONIC=0}
Squaturian inflicts {PHYSICAL=33, COLD=0, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=0, SONIC=0} damage to Planet Smasher
Planet Smasher: 139/195 HP
Planet Smasher prepares to act...
battler base damage:{PHYSICAL=17, COLD=0, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=0, SONIC=0}
add weapon damage:{PHYSICAL=24, COLD=0, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=0, SONIC=0}
Planet Smasher inflicts {PHYSICAL=24, COLD=0, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=0, SONIC=0} damage to Squaturian
Squaturian: 168/220 HP
End of turn 2 (press <Enter> to continue)
----- Turn 3 -----------------------------------
Turnpoints: Squaturian= 56 Planet Smasher= 22
Squaturian added 225 turnpoints for total of 281
Planet Smasher added 203 turnpoints for total of 225
Turnpoints: Squaturian= 281 Planet Smasher= 225
Squaturian added 209 turnpoints for total of 490
Squaturian added to turnqueue, has 34 turnpoints remaining.
Planet Smasher added 227 turnpoints for total of 452
Squaturian prepares to act...
Squaturian undeploys the Sword
Squaturian has deployed the Flamesword
battler base damage:{PHYSICAL=20, COLD=0, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=0, SONIC=0}
add weapon damage:{PHYSICAL=25, COLD=0, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=2, SONIC=0}
critical(1.4):{PHYSICAL=35, COLD=0, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=2, SONIC=0}
Squaturian attacks! Terrific blow!
Squaturian inflicts {PHYSICAL=35, COLD=0, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=2, SONIC=0} damage to Planet Smasher
Planet Smasher: 102/195 HP
End of turn 3 (press <Enter> to continue)
----- Turn 4 -----------------------------------
Turnpoints: Squaturian= 34 Planet Smasher= 452
Squaturian added 228 turnpoints for total of 262
Planet Smasher added 226 turnpoints for total of 678
Planet Smasher added to turnqueue, has 222 turnpoints remaining.
Planet Smasher prepares to act...
battler base damage:{PHYSICAL=14, COLD=0, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=0, SONIC=0}
add weapon damage:{PHYSICAL=22, COLD=0, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=0, SONIC=0}
Planet Smasher inflicts {PHYSICAL=22, COLD=0, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=0, SONIC=0} damage to Squaturian
Squaturian: 146/220 HP
End of turn 4 (press <Enter> to continue)
----- Turn 5 -----------------------------------
Turnpoints: Squaturian= 262 Planet Smasher= 222
Squaturian added 206 turnpoints for total of 468
Squaturian added to turnqueue, has 12 turnpoints remaining.
Planet Smasher added 210 turnpoints for total of 432
Squaturian prepares to act...
battler base damage:{PHYSICAL=24, COLD=0, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=0, SONIC=0}
add weapon damage:{PHYSICAL=27, COLD=0, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=4, SONIC=0}
Squaturian inflicts {PHYSICAL=27, COLD=0, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=4, SONIC=0} damage to Planet Smasher
Planet Smasher: 71/195 HP
End of turn 5 (press <Enter> to continue)
----- Turn 6 -----------------------------------
Turnpoints: Squaturian= 12 Planet Smasher= 432
Squaturian added 224 turnpoints for total of 236
Planet Smasher added 236 turnpoints for total of 668
Planet Smasher added to turnqueue, has 212 turnpoints remaining.
Planet Smasher prepares to act...
Planet Smasher undeploys the Big Stick
Planet Smasher has deployed the Ice Stick
battler base damage:{PHYSICAL=14, COLD=0, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=0, SONIC=0}
add weapon damage:{PHYSICAL=15, COLD=2, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=0, SONIC=0}
critical(1.4):{PHYSICAL=21, COLD=2, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=0, SONIC=0}
Planet Smasher attacks! Terrific blow!
Planet Smasher inflicts {PHYSICAL=21, COLD=2, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=0, SONIC=0} damage to Squaturian
Squaturian: 123/220 HP
End of turn 6 (press <Enter> to continue)
----- Turn 7 -----------------------------------
Turnpoints: Squaturian= 236 Planet Smasher= 212
Squaturian added 231 turnpoints for total of 467
Squaturian added to turnqueue, has 11 turnpoints remaining.
Planet Smasher added 210 turnpoints for total of 422
Squaturian prepares to act...
battler base damage:{PHYSICAL=19, COLD=0, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=0, SONIC=0}
add weapon damage:{PHYSICAL=22, COLD=0, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=4, SONIC=0}
fumble(0.6):{PHYSICAL=13, COLD=0, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=2, SONIC=0}
Squaturian attacks! Terrible blow.
Squaturian inflicts {PHYSICAL=13, COLD=0, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=2, SONIC=0} damage to Planet Smasher
Planet Smasher: 56/195 HP
End of turn 7 (press <Enter> to continue)
----- Turn 8 -----------------------------------
Turnpoints: Squaturian= 11 Planet Smasher= 422
Squaturian added 206 turnpoints for total of 217
Planet Smasher added 220 turnpoints for total of 642
Planet Smasher added to turnqueue, has 186 turnpoints remaining.
Planet Smasher prepares to act...
battler base damage:{PHYSICAL=17, COLD=0, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=0, SONIC=0}
add weapon damage:{PHYSICAL=20, COLD=7, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=0, SONIC=0}
Planet Smasher inflicts {PHYSICAL=20, COLD=7, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=0, SONIC=0} damage to Squaturian
Squaturian: 96/220 HP
End of turn 8 (press <Enter> to continue)
----- Turn 9 -----------------------------------
Turnpoints: Squaturian= 217 Planet Smasher= 186
Squaturian added 220 turnpoints for total of 437
Planet Smasher added 200 turnpoints for total of 386
Turnpoints: Squaturian= 437 Planet Smasher= 386
Squaturian added 192 turnpoints for total of 629
Squaturian added to turnqueue, has 173 turnpoints remaining.
Planet Smasher added 195 turnpoints for total of 581
Planet Smasher added to turnqueue, has 125 turnpoints remaining.
Squaturian prepares to act...
battler base damage:{PHYSICAL=21, COLD=0, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=0, SONIC=0}
add weapon damage:{PHYSICAL=25, COLD=0, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=3, SONIC=0}
critical(1.4):{PHYSICAL=35, COLD=0, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=4, SONIC=0}
Squaturian attacks! Terrific blow!
Squaturian inflicts {PHYSICAL=35, COLD=0, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=4, SONIC=0} damage to Planet Smasher
Planet Smasher: 17/195 HP
Planet Smasher prepares to act...
Planet Smasher undeploys the Ice Stick
Planet Smasher has deployed the Big Stick
battler base damage:{PHYSICAL=14, COLD=0, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=0, SONIC=0}
add weapon damage:{PHYSICAL=20, COLD=0, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=0, SONIC=0}
Planet Smasher inflicts {PHYSICAL=20, COLD=0, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=0, SONIC=0} damage to Squaturian
Squaturian: 76/220 HP
End of turn 9 (press <Enter> to continue)
----- Turn 10 -----------------------------------
Turnpoints: Squaturian= 173 Planet Smasher= 125
Squaturian added 218 turnpoints for total of 391
Planet Smasher added 216 turnpoints for total of 341
Turnpoints: Squaturian= 391 Planet Smasher= 341
Squaturian added 222 turnpoints for total of 613
Squaturian added to turnqueue, has 157 turnpoints remaining.
Planet Smasher added 219 turnpoints for total of 560
Planet Smasher added to turnqueue, has 104 turnpoints remaining.
Squaturian prepares to act...
battler base damage:{PHYSICAL=24, COLD=0, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=0, SONIC=0}
add weapon damage:{PHYSICAL=27, COLD=0, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=4, SONIC=0}
Squaturian inflicts {PHYSICAL=27, COLD=0, CORROSIVE=0, ELECTRIC=0, ENERGY=0, FIRE=4, SONIC=0} damage to Planet Smasher
Planet Smasher: 0/195 HP
Planet Smasher has been defeated!
End of turn 10 (press <Enter> to continue)
Planet Smasher has died!
And so concludes the Battledome.
Quick question:
should a battler's base damage map be considered bonuses to weapon damage, or unarmed damage? Or perhaps some sort of hybrid (such as weapons having a damage modifier map that would take the base damage map of the battler, apply the modifiers for each element to it, and then use that to enhance the weapon's final damage output?

Because right now I will have a battler with, say, 17 PHYSICAL base damage deploy a Laser Rifle (that does, say, 8 ENERGY damage), and then when they attack they are doing 25 damage total (17 PHYSICAL, 8 ENERGY) while shooting the laser rifle.

A damage modifier map could be cool. So that I could have a Beam Sword weapon that could take from the base damage map 50% PHYSICAL damage and 100% ENERGY damage as a bonus and 0% for all the rest of the elements to the weapon's damage output...

Thoughts?
Pages: 1