Difference between revisions of "Spell Success"

From CrawlWiki
Jump to: navigation, search
m (2armour -> 2 * armour)
(re-add the skills req'd to cast a level 9 spell)
Line 173: Line 173:
  
 
Of course, this isn't necessary. You can derive most (if not all) of this information by just checking your spell failure. If you wear a pierce of armour, and determine that your spell failure is unacceptable, then don't wear that armour - no need to calculate it! After you trained your skill a bit, you can wear a desired armour again, and see if it's any better.
 
Of course, this isn't necessary. You can derive most (if not all) of this information by just checking your spell failure. If you wear a pierce of armour, and determine that your spell failure is unacceptable, then don't wear that armour - no need to calculate it! After you trained your skill a bit, you can wear a desired armour again, and see if it's any better.
<!-- This example is currently outdated, but the numbers should be roughly similar
 
  
===Example: [[Fire Storm]]===
+
==Analysis==
For an actual failure rate of 10%, a raw failure rate of 28% is required. Assume Int=32, a good value for a dedicated caster (if a bit low). Also assume no armour/shield penalty.
 
  
* '''Without any aid:''' With a raw spell failure of 28%, you'll need a spellFailure value of 2. This is equivalent to 54.0 points of spell skills, requiring <code>(school skill*2 + spellcasting*0.5) = 55.7</code>. With a Spellcasting skill of 27, you'll need an average spell schools of 21.1.
+
===Skill Req'd to Cast L9 Spells===
 +
Say you wanted to [[Fire Storm]] reliably - for instance, to a 10% failure rate. To get a 10% actual failure rate, you'd need 28% raw failure. From the table above: if you have no wizardry, 28% raw failure = 1 SpellFailure.
  
* '''Wizardry x1:''' A wizardry ring knocks 1/4 of failure rate before sigmoid function, so the required raw fail rate is 38%. A spellFailure of 32% is stepped down to 38%. This value is quite easy to be achieved now, and average of 19.4 Lv (including spellcasting) is sufficient for 10% failure rate.
+
Using the [[#Base Chance|SpellFailure]] calculations at the top of the page, you can calculate what's needed to get to 1 SepllFailure. For this example, assume you have 30 intelligence, no wizardry, and 0 encumbrance from armour/skills.  
  
* '''Vehumet worshipper / Wizardry x2''': These enhancements knock off 1/3 of failure rate before sigmoid. Now the raw fail rate required before stepdown is 38%, and <code>(school skill*2 + spellcasting*0.5) = 47.3</code>. Required average skill Lvs (including spellcasting) is 18.9. Worshipping Vehumet really offers tremendous benefits for high-level spells.
+
60 (base failure)
 +
+ 340 (level 9 spell)
 +
- 6 * (0.5 * spellcasting + 2 * avg_skill)
 +
- 30 * 2 (30 intelligence)
 +
+ 0 (encumbrance)<br><br>= 340 - (3 * spellcasting) - (12 * avg_skill) = SpellFailure
  
* '''Vehumet + Wizardry / Wizardry x3''': Maxed out enhancer effect. Raw fail rate of 56% can be used without stepdown, and <code>(school skill*2 + spellcasting*0.5) = 43.3</code>. Required average skill Lvs (including spellcasting) is 17.3. If one regulates spellcasting up to 15, then 17.9 Lv of each school level is sufficient!
+
Therefore, if you had 30 Int, no encumbrance, and a Spellcasting skill of 14, you'd need 24.75 in Fire Magic and Conjurations. If you had a Spellcasting skill of 22.7, you'd need 22.7 in Fire Magic and Conjurations.
 +
 
 +
Wizardry reduces your raw failure chance by x75%, x66%, or x50%, depending on the stacks. So if you had wizardry x1, you'd need a (28 / .75) = 37.3% raw failure before wizardry (29.21 SpellFailure). The same calculations can be done for the other wizardry stats.
 +
 
 +
So, assuming you have 30 int and 0 encumbrance, the following skills would reach the desired 10% actual failure rate:
 +
*'''No Wizardry''': {14 Spellcasting, 24.75 avg_skill}, {22.7 Spellcasting, 22.7 avg_skill}
 +
*'''Wizardry x1''': {14 Spellcasting, 22.49 avg_skill}, {20.7 Spellcasting, 20.7 avg_skill}
 +
*'''Wizardry x2''' / '''Vehumet''': {14 Spellcasting, 21.5 avg_skill}, {20 Spellcasting, 20 avg_skill}
 +
*'''Wizardry x3''' / '''Vehumet + Wizardry x1''': {14 Spellcasting, 20.2 avg_skill}, {18.9 Spellcasting, 18.9 avg_skill}
 +
 
 +
These numbers apply to every level 9 spell in the game, not just Fire Storm... assuming you do have 30 int / 0 encumbrance. If you're wearing [[swamp dragon scales]] and a [[kite shield]], for instance, it'll take more skill to cast.
  
These numbers can be applied to any level 9 spell. -->
 
==Analysis==
 
 
===Measuring Encumbrance===
 
===Measuring Encumbrance===
 
The effect of encumbrance on your actual % to fail is non-linear. However, it can be measured by "levels of a spell school needed to compensate".
 
The effect of encumbrance on your actual % to fail is non-linear. However, it can be measured by "levels of a spell school needed to compensate".

Revision as of 00:49, 1 November 2023

Version 0.30: This article may not be up to date for the latest stable release of Crawl.

Spell success is the rate at which casting a spell can be expected to succeed. Spell success rate is determined by a complex combination of:

  1. Spell level
  2. Spell-related skills, Intelligence
  3. Penalties from body armour and shields (mitigated by Armour skill / Shields skill)
  4. Modifiers like Wizardry and Wild Magic

Base Chance

The source code talks in terms of chance of failure, not success. Therefore, we want the spellFailure chance to be as low as possible - in fact, to reach a 0% success rate, your chance to fail has to be negative. More on that below.

The base failure before any modifiers is as follows:[1]

 spellFailure = 60
              - [6 * spell_skills]
              - [2 * Intelligence]
              + Spell difficulty
              + Encumbrance penalties
  • 60 is an arbitrary base chance of failure.
  • Increasing intelligence and spell skills (skills respective to the spell and Spellcasting) will decrease failure.
  • Higher level spells are more difficult, wearing armour/shields make it more difficult.

spellFailure, at this stage, is capped at 1400.

Spell skills

"Spell_skills" takes into account Spellcasting and an average of a spell's schools (e.g. a Conjurations / Fire spell will take the average of the Conjurations skill and Fire Magic skill). This is calculated with the following equation:[2] [3]

 spell_skills = [Spellcasting / 2] + [Average(Skill_level) * 2]

For Djinn, the Spellcasting skill is counted as both Average Spell Schools and Spellcasting itself, resulting in the following formula:[4]

 spell_skills = Spellcasting * 2.5

With 27 in Spellcasting and 27 in relevant skills, the total value of (6 * spell_skills) is capped at 405.

Spell difficulty

Higher level spells are more difficult. Each level of spell adds a number to your spell failure rate:[5]

 spellDifficulty =   3 (level 1)
                    15 (level 2)   (+12)
                    35 (level 3)   (+20)
                    70 (level 4)   (+35)
                   100 (level 5)   (+30)
                   150 (level 6)   (+50)
                   200 (level 7)   (+50)
                   260 (level 8)   (+60)
                   340 (level 9)   (+80)

Encumbrance penalties

Both Armour and Shield penalties for spells are derived from their EV penalties. First, calculate the ev penalty, then calculate the spell penalty. Armour and Shields do not influence each other.

Armour[6][7]

 ev penalty = 1/225 * encumbrance^2 * (90 - 2 * armour_skill) / (str + 3)
 spell penalty = 19 * ev penalty

Shield[8][9]

 ev penalty = 2/5 * encumbrance^2 / (5 + str) * (27 - shield_skill) / 27
 spell penalty = 19 * ev penalty

Step down

At this point, the spell failure is put through a complicated post-processing curve:[10]

(x^3 + 426x^2 + 82670x + 6983254) / 262144 IF spellFailure < 43

This replicates a step-down curve:

x-axis = spellFailure, y-axis = Raw Failure Rate

This curve has the following points:

SpellFailure Raw Fail chance
43 43%
25 36.6%
0 27.7%
-50 15.5%
-72 10%
-100 8.5%
-173 0%

This is not the final spell rate; there are more modifiers.

Modifiers

The following modifiers are added after the STEPPED DOWN failure rates. However, they are still raw spell failure chance, and are adjusted by a sigmoid function later. [11]

Positive (+spell failure):

Negative (-spell failure):

  • Subdued Magic: -2% per level
  • Wizardry: x75% for 1 source, x66.6% for 2, x50% for 3 (applied after all other factors)

Vehumet gives 2 levels of wizardry for destructive spells.

After all modifiers have applied, you will get a cumulative raw spell failure chance. This is converted into the final success via the function below.

Final Step

In short, the game doesn't compare your raw failure chance with a number from 0 to 99. Instead, it compares the raw failure to the sum of three numbers divided by three.[12]

(1d101 + 1d101 + 1d100 - 3)/3 < fail chance

This is equivalent to applying this transformation to the chance of failure:

Spell success transformation.png

This sigmoid function makes it more difficult to decrease your failure rate when it is high or low, but it will go down very quickly when it is in the middle. For raw failures below 33%, one can use this formula:

 N                 = (raw_failure_rate) * 3
 Real Failure Rate = N * (N+1) * (N+2) / 6 / 101 / 101 (in unit of %)

This can be tabulated for usefulness.

SpellFailure Raw Fail chance Actual fail chance
13 32% 14.9%
7 30% 12.3%
1 28% 10.0%
-6 26% 8.1%
-12 24% 6.4%
-20 22% 4.9%
-28 20% 3.7%
-37 18% 2.7%
-47 16% 1.9%
-58 14% 1.3%
-71 12% 0.8%

Strategy

It is debatable whether these formulae are of any practical use during a game.

It may be nice to know a few things from a strategic point of view.

  • High level spells take a massive amount of XP to train, and it can be useful to know how many levels you'd need.
  • You can quantize your level of armour encumbrance. For example, a caster could say "a set of fire dragon scales gives a spell penalty equal to 9 levels of a spell school". Then, you could determine if wearing FDS is worth it, both short-term ("can I cast a spell in this right now?") and long-term ("can I cast a spell in this when I reach Zot?").
  • You can calculate the relative value of a skill. For example, you can see when a level of <Spell School> would be more valuable than a level of Armour skill, or when a point of strength is worth more than a point of intelligence.

Of course, this isn't necessary. You can derive most (if not all) of this information by just checking your spell failure. If you wear a pierce of armour, and determine that your spell failure is unacceptable, then don't wear that armour - no need to calculate it! After you trained your skill a bit, you can wear a desired armour again, and see if it's any better.

Analysis

Skill Req'd to Cast L9 Spells

Say you wanted to Fire Storm reliably - for instance, to a 10% failure rate. To get a 10% actual failure rate, you'd need 28% raw failure. From the table above: if you have no wizardry, 28% raw failure = 1 SpellFailure.

Using the SpellFailure calculations at the top of the page, you can calculate what's needed to get to 1 SepllFailure. For this example, assume you have 30 intelligence, no wizardry, and 0 encumbrance from armour/skills.

60 (base failure)
+ 340 (level 9 spell)
- 6 * (0.5 * spellcasting + 2 * avg_skill)
- 30 * 2 (30 intelligence)
+ 0 (encumbrance)

= 340 - (3 * spellcasting) - (12 * avg_skill) = SpellFailure

Therefore, if you had 30 Int, no encumbrance, and a Spellcasting skill of 14, you'd need 24.75 in Fire Magic and Conjurations. If you had a Spellcasting skill of 22.7, you'd need 22.7 in Fire Magic and Conjurations.

Wizardry reduces your raw failure chance by x75%, x66%, or x50%, depending on the stacks. So if you had wizardry x1, you'd need a (28 / .75) = 37.3% raw failure before wizardry (29.21 SpellFailure). The same calculations can be done for the other wizardry stats.

So, assuming you have 30 int and 0 encumbrance, the following skills would reach the desired 10% actual failure rate:

  • No Wizardry: {14 Spellcasting, 24.75 avg_skill}, {22.7 Spellcasting, 22.7 avg_skill}
  • Wizardry x1: {14 Spellcasting, 22.49 avg_skill}, {20.7 Spellcasting, 20.7 avg_skill}
  • Wizardry x2 / Vehumet: {14 Spellcasting, 21.5 avg_skill}, {20 Spellcasting, 20 avg_skill}
  • Wizardry x3 / Vehumet + Wizardry x1: {14 Spellcasting, 20.2 avg_skill}, {18.9 Spellcasting, 18.9 avg_skill}

These numbers apply to every level 9 spell in the game, not just Fire Storm... assuming you do have 30 int / 0 encumbrance. If you're wearing swamp dragon scales and a kite shield, for instance, it'll take more skill to cast.

Measuring Encumbrance

The effect of encumbrance on your actual % to fail is non-linear. However, it can be measured by "levels of a spell school needed to compensate".

Armour

Body armour increases SpellFailure by 19/225 * encumbrance^2 * (90 - 2 * armour) / (str + 3). Having 1 level of every spell school (except Spellcasting) reduces SpellFailure by 12. Therefore, you can divide the SpellFailure increase by 12 in order to get levels of compensation.

As an example: say you have 6 strength, are wearing troll leather armour (encumbrance = 4), and have 0 Armour skill. Your SpellFailure would be 19/225 * 4^2 * (90 - 0) / (6 + 3) = 13.51 SpellFailure, or 1.13 levels in each skill. That really isn't much in the grand scheme of things. By the time you get troll leather armour, you can negate a ~1 level penalty.

For reference:

Remember that things change based on strength and skill. Also remember that you can train armour skill to lower the penalty (see Armour skill vs Spell skill for more).

Shields

Shield increases SpellFailure by 38/5 * encumbrance^2 / (str + 5) * (27 - Shields)/27. Using the same method as body armour, as seen above, you can get a number for shield encumbrance, too. Relative to armour, strength matters a little less, but Shields skill matters more.

If you have 6 strength, a buckler (encumbrance = 5), and have 0 Shields skill, SpellFailure equals 38/5 * 5^2 / (6 + 5) * 27/27 = 17.27, or 1.44 levels in each skill. A kite shield would be 4x that, a tower shield would be 9x that.

Armour skill vs Spell skill

  • Armour skill reduces SpellFailure by -armour * 38/225 * encumbrance^2 / (str + 3).
  • Having 1 of every spell school (except Spellcasting) reduces SpellFailure by 12. Divide by number of spell schools if needed.
  • Therefore, each level in Armour is worth 19/1350 * encumbrance^2 / (str + 3), or roughly 1/71 * encumbrance^2 / (str + 3), levels in each spell school.

For example, if you have 11 strength and fire dragon scales, 1/71 * 11^2 / 14 = 0.122. That's a ratio of 8.21 Armour skill : 1 in each spell school. If you have a dual-school spell, like Iron Shot, 4.1 Armour skill = 1 Earth Magic OR 1 Conjurations, while 8.21 Armour = 1 Earth AND Conjurations.

Of course, this ONLY takes into account spell failure. Training Armour skill increases your defenses; training spell schools increases your power.

Strength vs Intelligence

  • For a given change in strength 'x', strength reduces both armour and shield encumbrance:
    • Armour: (1/<str+3> - 1/<str+x+3>) * 19/225 * encumbrance^2 * (90 - 2 * armour)
    • Shield: (1/<str+5> - 1/<str+x+5>) * 38/5 * encumbrance^2 * (27 - Shields)/27
  • Intelligence reduces SpellFailure by 2 per point.

For example, you have 11 strength, fire dragon scales, and 0 Armour skill. On level up, you have a choice of 2 str or 2 int. The impact of +2 str is equal to (1/14 - 1/16) * 19/225 * 11^2 * (90 - 0) = 8.21 SpellFailure, greater than 2*2 = 4 SpellFailure from intelligence.

If you have 11 strength, kite shield, and 9 Shields skill, +2 strength gives (1/16 - 1/18) * 38/5 * 10^2 * 18/27 = 3.52 SpellFailure.

Of course, intelligence also increases spell power, while strength reduces EV penalties.

See also

History

  • Prior to 0.22, spell_schools went through a stepdown, 50 * log2(1 + spell_schools/50), which penalized the caster if (Spellcasting/2) + (2* AvgSpellSchool) > 50. However, spellFailure for level 9 spells was 330 instead of 340.
  • Prior to 0.20, the Step down function was different, relying on breakpoints rather than a polynomial. Also, more breakpoints existed elsewhere in the spell failure calculation.

References