Page 1 of 2

Calculating Player Attack Score?

Posted: Tue Jan 26, 2010 3:12 pm
by OldRod
Anyone got tips on how to calculate an attack score for a player? I'm wanting to use Strength (which can be from 5-25), Dexterity (5-25) and Weapon skill (5-50) values and combine them in some combination to produce an attack score that is within the range of 25-100.

So, if all 3 stats were "5", which is the minimum, then the attack score would be 25
If all 3 stats were maxed (25, 25, 50 respectively) the attack score would be 100

It's been too long since I had Algebra - I can't remember how to set up the formulas :)

Anyone got any ideas?

Re: Calculating Player Attack Score?

Posted: Tue Jan 26, 2010 3:25 pm
by Cayle
What kind of general behavior are you looking for? Describe it, not with numbers, but with general trends.

E.g.

Does the weapon skill also count towards defense? If so does it contribute the same towards defense and attack, or is it weighted towards one?

Do you just have one weapon skill or more? Do characters et a bonus when fighting against a style they know and a penalty when encountering a new style?

How much of a role should luck play?

Re: Calculating Player Attack Score?

Posted: Tue Jan 26, 2010 3:33 pm
by OldRod
Hmm... good questions :)

Basically I am using the attack score to compare against the opponent's defense score to determine if a successful hit is made or not. Damage will then be calculated separately.

The weapon skill is based on whatever weapon they have equipped at the time, so they might have a separate skill number for 1 handed slashing weapons as opposed to 2 handed crushing weapons. I'm using the skill for whatever weapon is currently equipped.

Weapon skill does not contribute towards defense (defense is calculated separately) and there are no fighting styles.

I'm trying to keep things as simple as possible, at least starting out.

Re: Calculating Player Attack Score?

Posted: Tue Jan 26, 2010 3:49 pm
by Cayle
Next questions.

Do you want a strictly linear behavior, or a curvy behavior? In other words, do you want a newly created character to be able to get lucky and score a hit on a well defended character (with a low probability)? A strictly linear behavior is easy to calculate, but limits competitive combat to within a certain skill/level band. I'll give an example with D20 because everybody knows it. It is essentially a random number between 1 and 20, with a modifier (for level/attack skill/etc.) against a defense number (armor class in the case, dex, etc ). Your AC defines who can hit you. An alternative is to use something like a Weibull distribution, where attack and defense get plugged in as parameters and your probability of hitting changes as those parameters change. E.g. a low attack score against a high defense score would yield a probability distribution like the one in blue in the picture on the top right. Increasing the attack score relative to the defense score would give you something more like the light green line.

If you are using Python, it is trivial to use these bell curve like random distributions. In other languages, it is not so easy.

Re: Calculating Player Attack Score?

Posted: Tue Jan 26, 2010 4:02 pm
by Last Known Hero
OldRod wrote:Anyone got tips on how to calculate an attack score for a player? I'm wanting to use Strength (which can be from 5-25), Dexterity (5-25) and Weapon skill (5-50) values and combine them in some combination to produce an attack score that is within the range of 25-100.

So, if all 3 stats were "5", which is the minimum, then the attack score would be 25
If all 3 stats were maxed (25, 25, 50 respectively) the attack score would be 100

It's been too long since I had Algebra - I can't remember how to set up the formulas :)

Anyone got any ideas?
strength + dexterity + weapon skill = attack score
(s + d + ws = as)

As simple as that really, no multiplacation needed since it is just the sum of those three attributes. Now if you had debuffs that can be put on the player to say reduce the players attack by %30 then it would be:

strength + dexterity + weapon skill x multiplier = attack score
naturally multiplier would have to be 1.0 and if it reduced it by %30 then the 1.0 would have to change to 0.7, therefore reducing the attack by the debuff amount. or you can make it equal to 1.3 so that the player can have a buff instead

That should be about it, I have some complicated accuracy algrebraic equations if you wanna see them.

Re: Calculating Player Attack Score?

Posted: Tue Jan 26, 2010 4:06 pm
by OldRod
@ LKH

str+dex+wpn works at the top end, but at the bottom end I want a minimum attack score of 25 and simple addition only yields 15.

So there has to be some factoring in there doesn't there?

Plus the stat numbers may change as I work with it and see what does/doesn't work. I'm mainly wanting help setting up a formula so I can test various levels and then run some simulated combat against calculated defense scores.


@ Cayle:

Well, I obviously haven't thought this out very well, have I :) Linear is fine, but I always want there to be a minimum chance to hit, no matter the disparity in player skills.

This is a browser text rpg, written in PHP/JavaScript, no Python was harmed in the production of this game (so far) :)

Re: Calculating Player Attack Score?

Posted: Tue Jan 26, 2010 4:14 pm
by Last Known Hero
Ah i see, you want a minimum of 25, now that will use some mathematics to get that going.

If trying to utilise a multiplier, you can yield 25 by multiplying the sum of each by 1.67 (youll get 25.05 but close enough), but once you do that you run into a problem with your max value, 100 x 1.67 = 167, almost double the max that you want. I recommend having different lowest values so that they are already 25 with simple addition, that is if you did want to keep it simple.

**EDIT**
Sorry, also realized this is with scripting, couldn't you do the simple addition then add an 'if' clause? don't know php but i only know Turing so ill use that as an example:

strength + dexterity + weaponskill = attackscore
if attackscore < 25 then
attackscore := 25
else
end if

that way, if the attack score is lower than 25 it is just moved to 25 by the if statement

Re: Calculating Player Attack Score?

Posted: Tue Jan 26, 2010 5:22 pm
by Loopy
I wouldn't let what you want to arrive at limit what you put into your equation to define a hit. IMO your combat system must be the most intuitive and most fun element of your game to keep someone's interest. Too simplistic and it won't make sense nor will it provide much creativity on you or the players side, and too complex and the numbers lose their value (i.e. you hit Orc for eleventy-billion-uber-electric-damage)

For instance, it doesn't make sense to me to make STR the same equivalent of DEX in a "to hit" equation, because STR doesn't influence your ability to hit something as much as coordination does (DEX). STR defines what you can hit something with, and how hard you can hit it, but whether or not you hit it has less to do (not nothing, just less) than DEX.

So if I were you I would define a basic "to hit" equation... essentially a statement that reads 'regardless of the item being used, this the basic formula to hit something'.

Perhaps that looks something like this:

((.25 * Player_STR) + (Player_DEX))

That says STR plays a part in hitting, but DEX plays a higher part.

Then I would assign individual variables to each item. Some items, such a polearm, might require less DEX to use and more STR, than say a finesse weapon, like a dagger.

So then your equation might look something like this:


((.25 * Player_STR) + (Player_DEX)) + ((Player_STR * how item responds to STR) + (Player_DEX * how item responds to DEX))

Or something like this:
Dagger
STR_VAR_DAGGER: .2
DEX_VAR_DAGGER: .8

Dagger Equation:
((.25 * Player_STR) + (Player_DEX)) + ((Player_STR *STR_VAR_DAGGER) + (Player_DEX * DEX_VAR_DAGGER))

Perhaps a halberd responds more to STR than to DEX, however, you still have to have some basic coordination to use the thing, so you also include your basic hit equation you defined above:
Halberd
STR_VAR_Hal: .75
DEX_VAR_Hal: .25
((.25 * Player_STR) + (Player_DEX)) + ((Player_STR * STR_VAR_Hal) + (Player_DEX * DEX_VAR_Hal))


That's a good place to start punching in numbers and see how the numbers relate to both player stats and item stats. Likely you'll rework this over and over and over until it contains the items that make sense to the goal you're trying to achieve.

I've reworked my attack equation probably a hundred times or more... it has like 15-20 checks being passed through it to make it as realistic as possible to the effect I'm trying to achieve.

You can add checks for the type of armor the weapon is being used against too. LIkewise, you can do the same type of analysis for the defender as well.. so you don't need to arrive at a number between 25 and 100. If attacker rating comes back 314, and defender rating comes back 287, 314>287 so attacker = hit.

I also like to provide some element of randomness in it... it's not really fun if you always hit or always miss.

Re: Calculating Player Attack Score?

Posted: Tue Jan 26, 2010 5:40 pm
by OldRod
Interesting! I like the idea of making different weapon types affect the score differently, that makes a lot of sense.

A big club with a spike in it would be harder to swing than a light, balanced rapier, so you might do more damage with the club, but it would be harder to hit with it.

Re: Calculating Player Attack Score?

Posted: Tue Jan 26, 2010 5:59 pm
by Loopy
OldRod wrote:Interesting! I like the idea of making different weapon types affect the score differently, that makes a lot of sense.
Yes, "affect" with regards to responding to attributes.
OldRod wrote: A big club with a spike in it would be harder to swing than a light, balanced rapier, so you might do more damage with the club, but it would be harder to hit with it.
Yes.. you can expand on this too. Perhaps you implement number of attacks per turn and run your "to hit" equation however many attacks per turn the weapon has. So for instnace, a club might be large, cumbersome, require a high strength to use, and have only 1-2 attacks per round. It relies on hitting your opponent anywhere and suffers a penalty to any armor that would naturally resist smashing damage. Damage output is high, but offset by the limited amount of times you can swing it.

Alernatively, perhaps a dagger has a higher critical rate since the most effective use of the weapon would be sticking it in vital spots. Perhaps it also has a high number of attacks per round and relies more on finesse to use well (increased critical rate, and highly responsive to DEX). Perhaps it is more effective against plate (slide dagger between plates), and less effective against chainmail

These are things you'll add once you see everything in action and responding to each other. I love modifying my attack equation, it's the best part of building games IMO.