Difference between revisions of "Spell Success"

From CrawlWiki
Jump to: navigation, search
m (Final Step)
 
(91 intermediate revisions by 10 users not shown)
Line 1: Line 1:
{{version010}}
+
{{version031}}
 
 
 
{| style="float: right;"
 
{| style="float: right;"
 
| __TOC__
 
| __TOC__
Line 6: Line 5:
  
 
'''Spell success''' is the rate at which casting a [[spell]] can be expected to succeed.
 
'''Spell success''' is the rate at which casting a [[spell]] can be expected to succeed.
As of 0.10.3 spell success rate is determined by a complex combination of:
+
Spell success rate is determined by a complex combination of:
 
 
* Spell skills
 
* [[Intelligence]]
 
* Spell level
 
* Armour EV penalty, mitigated by [[Strength]] and [[Armour (skill)|Armour skill]]
 
* Shield penalty, mitigated by the [[Shields (skill)|Shields skill]]
 
* Transformations penalties for ([[Blade Hands]], [[Bat Form]], and [[Spider Form]]) and Mutations ([[Good_mutations#Wild_Magic|Wild Magic]])
 
* Piety with [[Vehumet]] for [[Conjurations]] spells
 
* Any equipped wizardry items
 
 
 
== Spell success calculations ==
 
 
 
It is debatable whether the following formulae are of real use during a game. However, inflection points such when the extra armour EV penalty disappears are fairly easy to discern. Calculating this stuff on the fly is only for savants!
 
  
=== Base chance ===
+
# Spell level
 +
# Spell-related skills, [[Intelligence]]
 +
# Penalties from [[body armour]] and [[shields]] (mitigated by [[Armour (skill)|Armour skill]] / [[Shields (skill)|Shields skill]])
 +
# Modifiers like [[Wizardry]] and [[Good_mutations#Wild_Magic|Wild Magic]]
  
The 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 Perfect success rate, your chance to fail has to be '''negative'''. More on that below.
+
==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% failure rate, your chance to fail has to be '''negative'''. More on that below.
  
To begin with, there's a 60% chance of failure. From this, two things are subtracted - twice the caster's Intelligence, and a value calculated from the user's relevant skills. This value is similar to (but simpler than) the [[spell power]]. Note that these two factors are the only ones that '''directly''' improve spell success, while other factors described below only serve to ''mitigate'' spellcasting penalties. Therefore, focus on these areas if you want to maximize your spellcasting chances, particularly spell skills.
+
The base failure before ''any'' modifiers is as follows:<ref>{{source ref|0.30.0|spl-cast.cc|406}}</ref>
 
 
Here's an overview of the basic formula, before stepdown and miscellaneous penalties and enhancers.
 
  
 
   spellFailure = 60
 
   spellFailure = 60
               - [6 * spell skills]
+
               - [6 * spell_skills]
 
               - [2 * Intelligence]
 
               - [2 * Intelligence]
 
               + Spell difficulty
 
               + Spell difficulty
               + Armour/shield penalty
+
               + 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.
  
 
=== Spell skills ===
 
=== 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:<ref>{{source ref|0.30.0|spl-cast.cc|413}}</ref>
Very similar to the first part of the spell power calculation - in fact, it's the same bit of code that does it. Half of [[Spellcasting]] is added to twice the average of all the spell schools used in the spell.
+
<ref>{{source ref|0.30.0|spl-cast.cc|377}}</ref>
 
+
   spell_skills = [Spellcasting / 2] + [Average(Skill_level) * 2]
   spellSkills = [Spellcasting / 2]
 
              + [Average(SpellSkills) * 2]
 
  
 
=== Spell difficulty ===
 
=== Spell difficulty ===
 
+
Higher level spells are more difficult. Each level of spell adds a number to your spell failure rate:<ref>{{source ref|0.30.0|spl-cast.cc|422}}</ref>
A number is added, making spellcasting more difficult, dependent on the spell's level.
 
  
 
   spellDifficulty =  3 (level 1)
 
   spellDifficulty =  3 (level 1)
                     15 (level 2)
+
                     15 (level 2)  (+12)
                     35 (level 3)
+
                     35 (level 3)  (+20)
                     70 (level 4)
+
                     70 (level 4)  (+35)
                     100 (level 5)
+
                     100 (level 5)  (+30)
                     150 (level 6)
+
                     150 (level 6)  (+50)
                     200 (level 7)
+
                     200 (level 7)  (+50)
                     260 (level 8)
+
                     260 (level 8)  (+60)
                     330 (level 9)
+
                     340 (level 9)  (+80)
  
=== Armour and shield penalties ===
+
=== Encumbrance penalties ===
  
The spellcasting penalties from armour and shields are linked together. The gist of it, for body armour, is as follows:
+
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.
  
* The more a piece of body armour impedes [[Evasion]], the more it will impede spellcasting.
+
'''Armour'''<ref>{{source ref|0.30.0|player.cc|5723}}</ref><ref>{{source ref|0.30.0|player.cc|2131}}</ref>
* If your character's Strength is not at least three times your body armour's EV penalty, you receive an ''additional'' penalty to spellcasting.
 
* The Armour skill reduces your body armour's penalty, but non-elven armours with -3EV penalty or higher cannot have their penalty fully removed.
 
  
And for shields:
+
  ev penalty = 1/225 * [[encumbrance]]^2 * (90 - 2 * [[Armour (skill)|armour_skill]]) / ([[str]] + 3)
 +
  spell penalty = 19 * ev penalty
  
* The larger the shield, the larger the penalty. Bucklers are your friends.
+
'''Shield'''<ref>{{source ref|0.30.0|player.cc|5739}}</ref><ref>{{source ref|0.30.0|player.cc|2134}}</ref>
* The Shields skill offsets the spellcasting penalty.
 
* For medium size characters every 5 points of Shield eliminates the penalty associated with a single point of EV penalty. Larger characters require less Shield skill, while smaller characters require more.
 
* If you are using a 0 EVP body armour, you need less Shield skill to remove the penalty. See [[Shields#Shield_Penalties|shield penalties]].
 
  
Racial armour also has an effect. Elven armour impedes spellcasting less than normal armour, while dwarven armour impedes it more. Wearing racial armour that matches the character's species reduces the penalty - which, for dwarves in dwarven armour, actually cancels out the racial penalty. Note that only body armour and shields affect spellcasting; bardings inflict no spellcasting penalty.
+
  ev penalty = 2/5 * [[Shields#EV_Penalty|encumbrance]]^2 / (5 + str) * (27 - [[Shields_(skill)|shield_skill]]) / 27
 +
  spell penalty = 19 * ev penalty
  
For the non-math inclined:
+
== Step down ==
 +
At this point, the spell failure is put through a complicated post-processing curve:<ref>{{source ref|0.30.0|spl-cast.cc|463}}</ref>
  
* Elven leather has no spell casting penalty.
+
(x^3 + 426x^2 + 82670x + 6983254) / 262144 IF spellFailure < 43
* Elves can wear elven ring mail (-2 EV) with no spell casting penalty (assuming no additional shield penalty).
 
* Orcs can wear orcish leather with no spell casting penalty (assuming no additional shield penalty).
 
* Dwarven armor should be avoided for non-Dwarf characters.
 
* 9 points in Armor skill removes the spell casting penalty for leather (assuming no additional shield penalty).
 
* 27 points in Armor skill removes the spell casting penalty for all -2 EV armors (assuming no additional shield penalty).
 
  
  armourShieldPenalty = max(0,
+
This replicates a step-down curve:
                            max(0,
+
[[File:Spell_success_stepdown.png|thumb|center|800px|x-axis = spellFailure, y-axis = Raw Failure Rate]]
                                25 * adjustedArmourEVPenalty
 
                              - racialArmourSpellcastingBonus)
 
                          + 25 * adjustedShieldEVPenalty
 
                          - 2000)
 
                      / 100
 
 
 
  adjustedArmourEVPenalty = 0 if armour EV penalty is 0, otherwise
 
                            (EV penalty + max(3 * EV penalty - Strength, 0))
 
                          * (45 - Armour skill)
 
                          * 100
 
                          / 45
 
 
 
  adjustedShieldEVPenlaty = 0 if no shield, otherwise
 
                            max(0,
 
                                EV penalty * 100
 
                              - (Shield skill * 100 / max(1, 5 + sizeEvasionFactor)))
 
 
 
  racialArmourSpellcastingBonus = 0
 
                                + 2500 if elven armour
 
                                - 1500 if dwarven armour
 
                                + 1500 if in correct racial armour (eg, orc in orcish armour)
 
  
=== Step down ===
+
This curve has the following points:
 
+
{| class="prettytable" style="text-align: center" border=1
At this point, the spell failure is put through a step down curve. If it's over 45 (just into the 'Fair' range), it's unaffected, otherwise it needs to be progressively lower to improve the overall result. This is a stepwise curve, and complex to describe. In the table is the listed native chance to reach certain points (i.e., spell success bands), although note that there are a couple of further steps performed after this.
+
|-
 
+
!SpellFailure!!Raw fail chance
{| class="prettytable" border=1
 
 
|-
 
|-
!Description!!Success rate!!Needed fail chance
+
|43 || 43%
 
|-
 
|-
|Fair||50%||50
+
|25 || 36.6%
 
|-
 
|-
|Good||70%||10
+
|0 || 27.7%
 
|-
 
|-
|Very Good||80%||−24
+
|<nowiki>-</nowiki>50 || 15.5%
 
|-
 
|-
|Great||90%||−80
+
|<nowiki>-</nowiki>72 || 10%
 
|-
 
|-
|Excellent||95%||−140
+
|<nowiki>-</nowiki>100 || 8.5%
 
|-
 
|-
|Perfect||100%||−180
+
|<nowiki>-</nowiki>173 || 0%  
 
|-
 
|-
 
|}
 
|}
  
For Excellent, −140 actually gives a 96% chance of success here. It's not possible to hit 95% directly.
+
==Modifiers==
 +
The following modifiers are added after the STEPPED DOWN failure rates above. However, it is still considered the ''raw spell failure chance'', which is adjusted by a sigmoid function later.<ref>{{source ref|0.30.0|spl-cast.cc|466}}</ref>
  
From −60 to −180 it's linear, with each difference of 20 giving 2% in the final spell success chance. So penalties affect bad wizards more than good ones. Penalty mitigation (for armour) applies before this, so the stepping function doesn't change that.
+
'''Positive (+spell failure):'''
 +
*[[Wild Magic (mutation)|Wild Magic]]: +4% per level
 +
*Disrupted Magic (-Wiz) [[Ru|sacrifice]]: +4% per level
 +
*[[Orb]] of [[energy]]: +10%
 +
**[[Crystal ball of Wucad Mu]]: +10%
 +
*[[Vertigo]]: +7%
  
=== Transformations penalties and Mutations ===
+
'''Negative (-spell failure):'''
 +
*[[Subdued Magic]]: -2% per level
 +
*[[Wizardry]]: multiplied by ×<code>6 / (7 + sources)</code>%, assuming you have at least one source. (×75% for Wiz x1, ×66.6% for Wiz x2, and so on.)
 +
*[[Vehumet]]: multiplied by ×66.6%.<ref>{{source ref|0.30.0|spl-cast.cc|335}}</ref> (Note: this is not considered a source of wizardry, but it multiplicatively stacks with wizardry.)
  
Blade Hands gives a penalty of 20, and [[Bat Form|Bat]] and [[Spider Form]] each gives a penalty of 10. The [[Good_mutations#Wild_Magic|Wild Magic]] mutation gives a penalty of 7 for each level. Note that as this happens after the stepping, these can be taken as a direct on the spell success chances (modulo any enhancers - that suggests that for [[Transmuter]]s, they are of greater value).  
+
The wizardry and Vehumet multipliers are applied after all others.<ref>{{source ref|0.30.0|spl-cast.cc|475}}</ref>
  
It's instructive to note the transformations that don't penalize spell success: [[Ice Form]], [[Statue Form]] and [[Dragon Form]].
+
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.
  
  transformationPenalty = 20 (for Blade Hands)
+
==Final Step==
                          10 (for Bat or Spider Form)
+
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.<ref>{{source ref|0.30.0|spl-cast.cc|2533}}</ref>
 +
(1d101 + 1d101 + 1d100 - 3)/3 < fail chance
  
=== Wizardry, Vehumet, and other factors ===
+
This is equivalent to applying this transformation to the chance of failure (x-axis: raw failure rate; y-axis: actual fail %):
  
Finally (phew!) spellcasting success boosts from items and other sources are applied. Note that these are actually calculated as a reduction in the fail chance, so in the table below, a low number is better.
+
[[Image:Spell_success_transformation.png]]
 
 
* Vehumet knocks 1/3 off the fail chance for Conjurations for disciples in good standing (piety over 70).
 
 
 
*[[Potion_of_brilliance|Brilliance]] decreases the fail chance by one third (in addition to a wizardry bonus).
 
  
* Rings of wizardry and staves of wizardry give some assistance, given by their "Wizardry" bonus in that column, but they suffer from decreasing cumulative effects. Look up the combination of '''R'''ings and '''S'''taves you have in the table below. Other spell enhancers, such as rings of fire/ice or staves of various kinds, do not affect spell success chances, only their power. Wizardry is determined using this formula:
+
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:
  
   Wizardry = +3 (for every ring of wizardry)
+
   N                = (raw_failure_rate) * 3
            +4 (if wielding a staff of wizardry)
+
  Real Failure Rate = N * (N+1) * (N+2) / 6 / 101 / 101 (in unit of %)
            +6 (under the effect of a potion of brilliance)
 
  
Note that there is an absolute limit of 50% for the effect of all enhancers.
+
This can be tabulated for usefulness.
  
The value in the "Fail chance" or "Vehumet" columns is the percentage of calculated fail chance used. Note that this happens after step down, meaning that enhancers have more effect for difficult spells than easy spells; don't load up on them if all your spells are Excellent, put on a ring of magical power instead! Looking at the table, it seems that after equipping two enhancers, you're not going to get much more benefit.
+
{| class="prettytable" style="text-align: center" border=1
 
 
{| class="prettytable" border=1
 
 
|-
 
|-
!Equipment!!Wizardry!!Fail chance!!Vehumet
+
!SpellFailure*!!Raw fail chance!!Actual fail chance
 
|-
 
|-
|None||0||100||67
+
|13||32%||14.9%
 
|-
 
|-
| -||1||87||58
+
|7||30%||12.3%
 
|-
 
|-
| -||2||79||52
+
|1||28%||10.0%
 
|-
 
|-
|R||3||74||50
+
|<nowiki>-</nowiki>6||26%||8.1%
 
|-
 
|-
|S||4||71||50
+
|<nowiki>-</nowiki>12||24%||6.4%
 
|-
 
|-
| -||5||68||50
+
|<nowiki>-</nowiki>20||22%||4.9%
 
|-
 
|-
|RR||6||66||50
+
|<nowiki>-</nowiki>28||20%||3.7%
 
|-
 
|-
|RS||7||64||50
+
|<nowiki>-</nowiki>37||18%||2.7%
 
|-
 
|-
| -||8||62||50
+
|<nowiki>-</nowiki>47||16%||1.9%
 
|-
 
|-
|RRR||9||60||50
+
|<nowiki>-</nowiki>58||14%||1.3%
 
|-
 
|-
|RRS||10||58||50
+
|<nowiki>-</nowiki>71||12%||0.8%
 
|-
 
|-
| -||11||56||50
 
|-
 
|RRRR||12||54||50
 
 
|}
 
|}
 +
<nowiki>*</nowiki>SpellFailure required to reach a given raw fail chance, ''assuming you don't have any modifiers like [[wizardry]]''. E.g. if you have wizardry x1, having 1 SpellFailure = (28% * 0.75) raw failure = 21% raw failure.
  
===The final step===
+
== Strategy ==
The number we have obtained isn't the final chance of failure. The game doesn't compare that number with a random number between 0 and 99, but with the sum of three numbers divided by three.
+
It is debatable whether these formulae are of any practical use during a game.
(1d101 + 1d101 + 1d100 - 3)/3 < fail chance
+
 
 +
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]]. A caster could say "a set of [[fire dragon scales]] gives a spell penalty equal to 6 levels of each 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 in game. 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 sake of example, we're trying to reach a 10% failure rate. You can look at the table above: to get a 10% actual failure rate, you'd need 28% raw failure. If you have no wizardry, 28% raw failure = 1 SpellFailure.
 +
 
 +
Using the [[#Base Chance|SpellFailure]] calculations at the top of the page, you can calculate what's needed to get to 1 SpellFailure. For this example, assume you have 30 intelligence, no wizardry, and 0 encumbrance from armour/shields.
 +
 
 +
60 (base failure)
 +
+ 340 (level 9 spell)
 +
- 6 * [0.5 * spellcasting + 2 * avg_skill] (spell skills)
 +
- 30 * 2 (30 intelligence)
 +
+ 0 (encumbrance)<br><br>= 340 - (3 * spellcasting) - (12 * avg_skill) = SpellFailure
 +
 
 +
We want a SpellFailure = 1, so <code>340 - (3 * spellcasting) - (12 * avg_skill) = 1</code>. So if you had an Spellcasting skill of 14, you'd need 24.75 in avg_skill - that is, 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 rate by x75% for 1 stack, x66% for 2 stacks, etc.. So if you had wizardry x1, you'd need a (28 / .75) = 37.3% raw failure before wizardry (which, in turn, equals 29.21 SpellFailure). The same calculations can be done for other amounts of wizardry.
 +
 
 +
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}
 +
*'''Vehumet + Wizardry x1''': {14 Spellcasting, 20.2 avg_skill}, {18.9 Spellcasting, 18.9 avg_skill}
 +
 
 +
These numbers apply to any level 9 spell in the game, not just Fire Storm... again, ''assuming you 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. Change the values of spell level, intelligence, encumbrance as you see fit.
 +
 
 +
===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 <code>19/225 * encumbrance^2 * (90 - 2 * Armour) / (str + 3)</code>. Having 1 level of every spell school (except Spellcasting) reduces SpellFailure by 12. Therefore, armour encumbrance can be measured in terms of skill levels, using the formula [SpellFailure Increase] / 12.
 +
 
 +
As an example: say you have 6 strength, are wearing [[troll leather armour]] (encumbrance = 4), and have 0 Armour skill. Your SpellFailure would be <code>19/225 * 4^2 * (90 - 0) / (6 + 3)</code> = 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:
 +
*10 strength, [[leather armour]], 0 Armour skill: -0.78 levels in each skill
 +
*10 strength, [[ring mail]] or [[swamp dragon scales]], 5 Armour skill:  -2.12 levels in each skill
 +
*10 strength, [[fire dragon scales]], 5 Armour skill: -5.24 levels in each skill
 +
 
 +
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|Armour skill vs Spell skill]] for more).
 +
 
 +
'''Shields'''
 +
 
 +
Shield increases SpellFailure by <code>38/5 * encumbrance^2 / (str + 5) * (27 - Shields)/27</code>. 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 <code>38/5 * 5^2 / (6 + 5) * 27/27</code> = 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 <code>-Armour * 38/225 * encumbrance^2 / (str + 3)</code>.
 +
*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 <code>19/1350 * encumbrance^2 / (str + 3)</code>, or roughly <code>1/71 * encumbrance^2 / (str + 3)</code>, levels in each spell school.
 +
 
 +
For example, if you have 11 strength and are wearing [[fire dragon scales]], the equation <code>1/71 * 11^2 / 14</code> = 0.122, or 8.21 Armour : 1 in each spell school. If you have a dual-school spell, like [[Fireball]], 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 by:
 +
**Armour: <code>(1/<str+3> - 1/<str+x+3>) * 19/225 * encumbrance^2 * (90 - 2 * Armour)</code>
 +
**Shield: <code>(1/<str+5> - 1/<str+x+5>) * 38/5 * encumbrance^2 * (27 - Shields)/27</code>
 +
*Intelligence reduces SpellFailure by 2 per point.
 +
 
 +
Say 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 <code>(1/14 - 1/16) * 19/225 * 11^2 * (90 - 0)</code> = 8.21 SpellFailure, greater than 2*2 = 4 SpellFailure from intelligence.
  
This is equivalent to applying this transformation to the chance of failure:
+
If this 11 strength character is also wearing a [[kite shield]], with 9 Shields skill, +2 strength would also give <code>(1/16 - 1/18) * 38/5 * 10^2 * 18/27</code> = 3.52 SpellFailure.
[[Image: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.
+
Of course, intelligence also increases [[spell power]], while strength reduces [[EV]] penalties.
  
 
==See also==
 
==See also==
 +
*[[Spell power]]
 +
*[[Miscast effect]]
 +
 +
==History==
 +
*Prior to [[0.31]], the raw failure rate multiplier from wizardry/Vehumet was capped at 50%. Therefore, you could only have a maximum of 5 stacks of wizardry, or 1 stack of wizardry with Vehumet's bonus. Also, some [[transmutations]] increased your spell failure: [[Spider Form]] (+10%) and [[Blade Hands (spell)|Blade Hands]] (+20%).
 +
*Prior to [[0.22]], spell_schools went through a stepdown, <code>50 * log2(1 + spell_schools/50)</code>, which penalized the caster if <code>(Spellcasting/2) + (2* AvgSpellSchool) > 50</code>. However, spellFailure for level 9 spells was 330 instead of 340.
 +
*Prior to [[0.20]], the [[#Step down|Step down]] function was different, relying on breakpoints rather than a polynomial. Also, more breakpoints existed elsewhere in the spell failure calculation.
  
* [[Spell power]]
+
==References==
* [[Miscast effect]]
+
<references/>
  
 
[[Category:Magic]]
 
[[Category:Magic]]

Latest revision as of 11:14, 25 October 2024

Version 0.31: 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% failure 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.

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]

Spell difficulty

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

 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[5][6]

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

Shield[7][8]

 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:[9]

(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%

Modifiers

The following modifiers are added after the STEPPED DOWN failure rates above. However, it is still considered the raw spell failure chance, which is adjusted by a sigmoid function later.[10]

Positive (+spell failure):

Negative (-spell failure):

  • Subdued Magic: -2% per level
  • Wizardry: multiplied by ×6 / (7 + sources)%, assuming you have at least one source. (×75% for Wiz x1, ×66.6% for Wiz x2, and so on.)
  • Vehumet: multiplied by ×66.6%.[11] (Note: this is not considered a source of wizardry, but it multiplicatively stacks with wizardry.)

The wizardry and Vehumet multipliers are applied after all others.[12]

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.[13]

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

This is equivalent to applying this transformation to the chance of failure (x-axis: raw failure rate; y-axis: actual fail %):

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%

*SpellFailure required to reach a given raw fail chance, assuming you don't have any modifiers like wizardry. E.g. if you have wizardry x1, having 1 SpellFailure = (28% * 0.75) raw failure = 21% raw failure.

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. A caster could say "a set of fire dragon scales gives a spell penalty equal to 6 levels of each 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 in game. 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 sake of example, we're trying to reach a 10% failure rate. You can look at the table above: to get a 10% actual failure rate, you'd need 28% raw failure. 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 SpellFailure. For this example, assume you have 30 intelligence, no wizardry, and 0 encumbrance from armour/shields.

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

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

We want a SpellFailure = 1, so 340 - (3 * spellcasting) - (12 * avg_skill) = 1. So if you had an Spellcasting skill of 14, you'd need 24.75 in avg_skill - that is, 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 rate by x75% for 1 stack, x66% for 2 stacks, etc.. So if you had wizardry x1, you'd need a (28 / .75) = 37.3% raw failure before wizardry (which, in turn, equals 29.21 SpellFailure). The same calculations can be done for other amounts of wizardry.

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}
  • Vehumet + Wizardry x1: {14 Spellcasting, 20.2 avg_skill}, {18.9 Spellcasting, 18.9 avg_skill}

These numbers apply to any level 9 spell in the game, not just Fire Storm... again, assuming you 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. Change the values of spell level, intelligence, encumbrance as you see fit.

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, armour encumbrance can be measured in terms of skill levels, using the formula [SpellFailure Increase] / 12.

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 are wearing fire dragon scales, the equation 1/71 * 11^2 / 14 = 0.122, or 8.21 Armour : 1 in each spell school. If you have a dual-school spell, like Fireball, 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 by:
    • 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.

Say 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 this 11 strength character is also wearing a kite shield, with 9 Shields skill, +2 strength would also give (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.31, the raw failure rate multiplier from wizardry/Vehumet was capped at 50%. Therefore, you could only have a maximum of 5 stacks of wizardry, or 1 stack of wizardry with Vehumet's bonus. Also, some transmutations increased your spell failure: Spider Form (+10%) and Blade Hands (+20%).
  • 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