Page 1 of 3

Is My Math Right or Wrong for The Hit Formula?

Posted: Thu Feb 27, 2020 4:02 pm
by Magicono43
I was looking more into how DFU calculates how the player rolls for their attacks against a monster, such as a skeleton warrior or a rat. I went through the code here "https://github.com/Interkarma/daggerfal ... r.cs/#L944" for the FormulaHelper script and made this equation based on it.

chanceToHit = (armorValue) + (attacker.ChanceToHitModifier + ChanceToHitMod) + ((attacker.Stats.LiveLuck - target.Stats.LiveLuck) / 10) + ((attacker.Stats.LiveAgility - target.Stats.LiveAgility) / 10) - (target.Skills.GetLiveSkillValue(DFCareer.Skills.Dodging) / 4) + (attacker.Skills.GetLiveSkillValue(DFCareer.Skills.CriticalStrike) / 10) + (40 if enemy is a monster/non-human) - 50

and you get "attacker.ChanceToHitModifier" with this equation.

ChanceToHitMod = (attacker.Skills.GetLiveSkillValue(skillID)) + (WeaponStates [StrikeUp = +10, StrikeDownRight = +5, StrikeDownLeft = -5, StrikeDown = -10, Horizontal prob. = 0]) + (ExpertProficiencies.attacker.Level [Assuming level is just player current level, so if level 4, would just add 4 to total hit mod]) + (Racial_Bonus.Level/3 or 4 [Depends on Race]) + (backstabChance [If behind target]) + (weapon.GetWeaponMaterialModifier() * 10)

and I guess "ChanceToHitMod" is just the value that is displayed when you click on your agility attribute, so if it's say 60, it would be +1 and 70 +2? I omitted adding the Adrenaline Rush variables to the chanceToHit equation for simplicity, but I know they exist.

Then all of this gets ran through a 1-100 Diceroll method, where you can't go below 3 nor above 97.
__________________________________________________________________________

So with all of that mess aside, let me put up an example or two to see if i'm understanding this correctly.

Example 1:

Level 4 Argonian custom class that has Axe expertise, 40 Axe skill, 30 crit strike, 60 agility, 50 luck, using an elven battle-axe.

Is attacking a Rat, with a horizontal slash, from the front. Rat stats from here: https://en.uesp.net/wiki/Daggerfall:Rat

ChanceToHitMod = (40) + (0) + (4) + (0) + (0) + (10) = 54

chanceToHit = (6) + (54 + 1) + ((50-50)/10) +((60-80)/10) - (0 [Do non-human monsters have dodge skill?]) + (30/10) + (40) - (50) = 52%

So when the 100 sided dice is rolled, if it rolls any number BELOW 52, my hit will collide and deal all of the other damage modification formula damage. Likewise, if it rolls ABOVE 52, my hit will miss.
__________________________________________________________________________

Example 2:

Level 12 Red-guard custom class that has Short-blade expertise, 70 short-blade skill, 60 crit strike, 90 agility, 60 luck, using an ebony dagger.

Is attacking an Ancient Lich, with a downward slash, from the front. Ancient Lich stats from here: https://en.uesp.net/wiki/Daggerfall:Ancient_Lich

ChanceToHitMod = (70) + (-10) + (12) + (12/3) + (0) + (40) = 116

chanceToHit = (-12) + (116 + 4) + ((60-50)/10) +((90-90)/10) - (0 [Do non-human monsters have dodge skill?]) + (60/10) + (40) - (50) = 105%

So when the 100 sided dice is rolled, if it rolls any number BELOW 97, my hit will collide and deal all of the other damage modification formula damage. Likewise, if it rolls ABOVE 97, my hit will miss.
__________________________________________________________________________

Before I ask more about details like "So difference in luck stat only effects hit chance by 1% per 10 point difference" or "So every 10 points of agility has a 2% effect on hit chance" or "Do monsters not have a dodge stat?". I want to make sure that I am understanding the math here correctly, am I missing anything?

Re: Is My Math Right or Wrong for The Hit Formula?

Posted: Sat Feb 29, 2020 1:56 pm
by Dubiousintent
I'd hoped one of the devs would jump in, but rather than let this languish ...

As I recall from original D&D, your end result is correct. The "to hit AC0 (THAC0) system" is summarized as "roll low". The "chance to hit" must be rolled under the THAC0 value. Defense bonuses reduce the THAC0 value (making it harder to achieve a hit) while attack bonuses (such as weapon "to hit" enchantments) increase it.

An apparent point of confusion is the subtle difference between the terms "armor CLASS" and "armor VALUE". The two tend to be "conflated" and used interchangeably, but in the code are not. "Class" appears to be used as a comparative relation to "AC0", while "Value" is the "current chance to hit percentage".

However, the Player "paperdoll" does not appear to be showing an "armor class". It is showing armor values (reductions to THAC0) at particular parts of the body, which only apply when that particular body part is struck. (See the "FormulaHelper.cs" code in the referenced thread below.)

As pointed out by l3lessed in How does AC of a creature works? "monster" equipment armor value may get used only if it is better than their base monster type armor value. However, I think he misspoke when he said "So, armor value increases your chance to hit value. As a result, everytime that 100 sided dice is rolled, it is less likely it will roll a number larger than your now modified armor value and tell the engine it was a successful hit." That is directly contradicted by his immediately preceding statement: "For a successful hit, the random number needs to be smaller than the end chancetohit number" and the code following, because "chance to hit" is essentially "armor value" with adjustments. It should read "So, armor value DEcreases your chancetohit value" and "it is less likely it will roll a number LESS than your now modified armor value". (The operator "-=" subtracts the value on the right from the variable on the left. The "+=" operator does the opposite. Defensive factors ("target") are subtracted while offensive factors ("attacker") are added to the "chanceToHit" variable.)

All of which is to say: "I think you have it correct."

Re: Is My Math Right or Wrong for The Hit Formula?

Posted: Sat Feb 29, 2020 4:04 pm
by Baler
Pardon my ignorance.
When I asked about hit chance on discord I was told it's a d20 roll with modifiers. However looking at the code I'm not seeing this case?
Specifically I asked how Agility affected hit chance and was told the game rolls a D20, then each 10 points of agility adds +1 to that. If you're 20 or above you're gurenteed to hit. :| :?:

Re: Is My Math Right or Wrong for The Hit Formula?

Posted: Sun Mar 01, 2020 1:56 am
by Magicono43
Dubiousintent wrote: Sat Feb 29, 2020 1:56 pm I'd hoped one of the devs would jump in, but rather than let this languish ...

As I recall from original D&D, your end result is correct. The "to hit AC0 (THAC0) system" is summarized as "roll low". The "chance to hit" must be rolled under the THAC0 value. Defense bonuses reduce the THAC0 value (making it harder to achieve a hit) while attack bonuses (such as weapon "to hit" enchantments) increase it.

An apparent point of confusion is the subtle difference between the terms "armor CLASS" and "armor VALUE". The two tend to be "conflated" and used interchangeably, but in the code are not. "Class" appears to be used as a comparative relation to "AC0", while "Value" is the "current chance to hit percentage".

However, the Player "paperdoll" does not appear to be showing an "armor class". It is showing armor values (reductions to THAC0) at particular parts of the body, which only apply when that particular body part is struck. (See the "FormulaHelper.cs" code in the referenced thread below.)

As pointed out by l3lessed in How does AC of a creature works? "monster" equipment armor value may get used only if it is better than their base monster type armor value. However, I think he misspoke when he said "So, armor value increases your chance to hit value. As a result, everytime that 100 sided dice is rolled, it is less likely it will roll a number larger than your now modified armor value and tell the engine it was a successful hit." That is directly contradicted by his immediately preceding statement: "For a successful hit, the random number needs to be smaller than the end chancetohit number" and the code following, because "chance to hit" is essentially "armor value" with adjustments. It should read "So, armor value DEcreases your chancetohit value" and "it is less likely it will roll a number LESS than your now modified armor value". (The operator "-=" subtracts the value on the right from the variable on the left. The "+=" operator does the opposite. Defensive factors ("target") are subtracted while offensive factors ("attacker") are added to the "chanceToHit" variable.)

All of which is to say: "I think you have it correct."
Yeah, I figured I was not too far off, but I think I got one "big" detail incorrect in this post, that being that monsters actually appear to have skills, just like the player, but their value is based on the level of the monster, with a default value of 30 in all skills, and the rest being based on monster_level * 5, so the lowest possible level enemy, being the level 1 Rat, has 35 skill in everything. While the highest level enemy being the ancient lich having 100 skill in everything (everything is capped at 100, besides magic schools, which cap at 80 for monsters). This info coming from this source: https://en.uesp.net/wiki/Daggerfall:Bestiary

The point of this mistake correction being that the hit chances that I used as examples are actually a fair amount off from what their actual values would be with this info in mind. With a monster being level 14 or higher, having an inherent -25 modifier to their chance of being hit due to their 100 dodge skill, and EVERY monster in the game having AT LEAST a -8.75 modifier to their chances of being hit.

I went into some more detail in this other post from another thread: viewtopic.php?f=27&t=3372&start=60#p40425

So I feel like my math and the majority of my assumptions on this system are correct, but who knows, that Unofficial source could be completely off to how Daggerfall Unity has coded these things and I could be completely wrong.

Re: Is My Math Right or Wrong for The Hit Formula?

Posted: Sun Mar 01, 2020 1:59 am
by Magicono43
Baler wrote: Sat Feb 29, 2020 4:04 pm Pardon my ignorance.
When I asked about hit chance on discord I was told it's a d20 roll with modifiers. However looking at the code I'm not seeing this case?
Specifically I asked how Agility affected hit chance and was told the game rolls a D20, then each 10 points of agility adds +1 to that. If you're 20 or above you're gurenteed to hit. :| :?:
At least from the code that I read, I did not see anywhere that a D20 is ever rolled, at least not in the formula for chance to hit. I'm also not even sure if the code-base has a class for rolling a D20, the only one that I saw was the "Dice100" class. At least if you search "Dice" in the API documentation here: https://thelacus.github.io/daggerfall-u ... index.html

I can't find anything referencing a lower roll than 100.

Re: Is My Math Right or Wrong for The Hit Formula?

Posted: Thu Mar 05, 2020 11:55 am
by Ralzar
I've been looking at the combat code in FormulaHelper and to get a general feel of how ToHit is calculated I made this.
I hope I managed to include all bonuses and penalties. There was... a lot.

(Some abilities give effects based on level. I assumed a range of lvl1 to lvl20)

Attack Skill (+1 to +100)
+
Target Dodge skill ( 0 to -25 )
+
WeaponSwing (-10 to +10)
+
Proficiency (+1 to +20)
+
RaceBonus (+1 to +6)
+
Biography Avoid Hit Mod (not sure about this value at the moment)
+
Weapon Material (-10 to +60)
+
Player Armor (-5 to +85)
or
Monster Armor (-60 to +60)
+
Adrenaline Rush (-8 to +8)
+
Enchantment (not sure about this value at the moment)
+
Luck vs Luck (-10 to +10)
+
Agility vs Agility (-10 to +10)
+
Critical Strike (chance of +1 to +10)
+
If Monster ( +40 )
+
Bonus/Phobia (-20 to +20)
+
-50
=
% chance to hit (minimum 3, maximum 97)

Re: Is My Math Right or Wrong for The Hit Formula?

Posted: Thu Mar 05, 2020 12:32 pm
by Ralzar
So unless I'm missing something, the first example above:

Attacker:
Argonian, lvl4, Axe 40%, Crit 30%, Ag 60, 50 Luck, Elven Axe

Defender:
Rat, Lvl1, Armor 6, AG 80, Luck 50

+40 for Skill
-9 for Dodge
+10 for Elven Material
+30 for Armor
-2 for Agility
+3 for Critical Stricke (30% of this happening)
+40 for being Monster
-50

= 62% chance of hitting


Second example:

Attacker:
Redguard, lvl12, Proficiency, Skill 70, Crit 60, 90AG, 60LCK, Ebony

Target:
Ancient Lich, lvl21, Armor -12, AG 90, Luck 50

+70 for Skill
-23 for Dodge
+12 for Proficiency
+4 for Redguard
+40 for Ebony
-60 for Armor
+1 for Luck
+6 for Critical Hit (60% chance of this happening)
+40 for Monster
-50

= 40% chance of hitting

Edit: Monster Agility and Luck added

Re: Is My Math Right or Wrong for The Hit Formula?

Posted: Thu Mar 05, 2020 1:11 pm
by mikeprichard
Just noting that Agility (like Luck) should range from -10 to +10, not -5 to +5, at least in classic - see also the code linked in the top post of this topic, particularly:

// Apply luck modifier.
chanceToHit += ((attacker.Stats.LiveLuck - target.Stats.LiveLuck) / 10);

// Apply agility modifier.
chanceToHit += ((attacker.Stats.LiveAgility - target.Stats.LiveAgility) / 10);

Re: Is My Math Right or Wrong for The Hit Formula?

Posted: Thu Mar 05, 2020 1:18 pm
by Ralzar
mikeprichard wrote: Thu Mar 05, 2020 1:11 pm Just noting that Agility (like Luck) should range from -10 to +10, not -5 to +5, at least in classic - see also the code linked in the top post of this topic, particularly:

// Apply luck modifier.
chanceToHit += ((attacker.Stats.LiveLuck - target.Stats.LiveLuck) / 10);

// Apply agility modifier.
chanceToHit += ((attacker.Stats.LiveAgility - target.Stats.LiveAgility) / 10);
But, do monsters have Luck and Agility? I mean, how do you detract a rats Luck from the players Luck?
I am assuming all you get is one of the two numbers being 0. So argonian vs Rat is:

(50 - 0) / 10 = 5

So the Luck bonus should be +5?

Edit: or do all mosters count as having 50 in all attriutes? Making the actual Luck and ability Bonus be:

(Attribute - 5) / 10

Giving a range of -5 to +5 ?

Re: Is My Math Right or Wrong for The Hit Formula?

Posted: Thu Mar 05, 2020 1:25 pm
by Dubiousintent
Excellent point about "do monsters have Luck", but there is an apparent tendency to use "(Level * 5)" as a substitute for any missing stat, at least in the code fragments I've seen published in threads. Suspect it would be more prudent to assume that instead of "zero" for any missing formula element until it can be determined absolutely.