Difference between revisions of "Template:Apparel AP Calculation"

From RimWorld Wiki
Jump to navigation Jump to search
(Created page with "The armor rating is reduced by the armor penetration value, dependent on the weapon. This gives the "effective armor rating" The effective armor rating is then compared agains...")
 
(Previous edits break existing usecase because there are times where the result will be 2 or below. You can't change this piecemeal. If you want to change the standard, you'll have to change all of the uses of it at once, all the way otherwise issues like this will reoccur)
 
(12 intermediate revisions by 2 users not shown)
Line 1: Line 1:
The armor rating is reduced by the armor penetration value, dependent on the weapon. This gives the "effective armor rating"
+
{{#vardefine: effectiveArmor1 |{{#expr: {{{armor1|0}}} - {{{ap|0}}}}}}} <!--
The effective armor rating is then compared against a random number from 0 to 100:
+
-->{{#vardefine: effectiveArmor2 |{{#expr: {{{armor2|0}}} - {{{ap|0}}}}}}} <!--
If the random number is under half the armor rating, the damage deflects harmlessly.
+
-->{{#vardefine: effectiveArmor3 |{{#expr: {{{armor3|0}}} - {{{ap|0}}}}}}} <!--
If the random number is over half the armor rating, but not higher than the armor rating, the damage is halved.
+
-->{{#vardefine: effectiveArmor4 |{{#expr: {{{armor4|0}}} - {{{ap|0}}}}}}} <!--
If the random number is greater than the armor rating, the armor has no effect.
+
-->{{#ifexpr: {{#var: effectiveArmor1}} < 0| {{#vardefine: effectiveArmor1 | 0 }} }} <!--
 +
-->{{#ifexpr: {{#var: effectiveArmor2}} < 0| {{#vardefine: effectiveArmor2 | 0 }} }} <!--
 +
-->{{#ifexpr: {{#var: effectiveArmor3}} < 0| {{#vardefine: effectiveArmor3 | 0 }} }} <!--
 +
-->{{#ifexpr: {{#var: effectiveArmor4}} < 0| {{#vardefine: effectiveArmor4 | 0 }} }} <!--
  
{{#vardefine: effectiveArmor |{{#expr: {{{1|armor}}} - {{{2|ap}}}}} }}
+
-->{{#expr:100*(({{#ifexpr: (100-{{#var: effectiveArmor1}}) > 0 | {{#expr:100-{{#var: effectiveArmor1}}}} | 0}}/100.0) + ({{#ifexpr: ({{#var: effectiveArmor1}}/2.0) < (100.0-{{#var: effectiveArmor1}}/2.0) | {{#expr:{{#var: effectiveArmor1}}/2.0}} | {{#expr:100.0-{{#var: effectiveArmor1}}/2.0}} }}/100)* 0.5)
  
{{#vardefine: effectiveArmor | 150 }}  
+
{{#if: {{{armor2|}}} | * (({{#ifexpr: (100-{{#var: effectiveArmor2}}) > 0 | {{#expr:100-{{#var: effectiveArmor2}}}} | 0}}/100.0) + ({{#ifexpr: ({{#var: effectiveArmor2}}/2.0) < (100.0-{{#var: effectiveArmor2}}/2.0) | {{#expr:{{#var: effectiveArmor2}}/2.0}} | {{#expr:100.0-{{#var: effectiveArmor2}}/2.0}} }}/100)* 0.5) }}
  
{{#ifexpr: {{#var: effectiveArmor}} < 0| {{#vardefine: effectiveArmor | 0 }} }}
+
{{#if: {{{armor3|}}} | * (({{#ifexpr: (100-{{#var: effectiveArmor3}}) > 0 | {{#expr:100-{{#var: effectiveArmor3}}}} | 0}}/100.0) + ({{#ifexpr: ({{#var: effectiveArmor3}}/2.0) < (100.0-{{#var: effectiveArmor3}}/2.0) | {{#expr:{{#var: effectiveArmor3}}/2.0}} | {{#expr:100.0-{{#var: effectiveArmor3}}/2.0}} }}/100)* 0.5) }}
  
 
+
{{#if: {{{armor4|}}} | * (({{#ifexpr: (100-{{#var: effectiveArmor4}}) > 0 | {{#expr:100-{{#var: effectiveArmor4}}}} | 0}}/100.0) + ({{#ifexpr: ({{#var: effectiveArmor4}}/2.0) < (100.0-{{#var: effectiveArmor4}}/2.0) | {{#expr:{{#var: effectiveArmor4}}/2.0}} | {{#expr:100.0-{{#var: effectiveArmor4}}/2.0}} }}/100)* 0.5) }}
{{#expr: ({{#ifexpr: (100-{{#var: effectiveArmor}}) > 0 | {{#expr:100-{{#var: effectiveArmor}}}} | 0}}/100.0) + ({{#ifexpr: ({{#var: effectiveArmor}}/2.0) < (100.0-{{#var: effectiveArmor}}/2.0) | {{#expr:{{#var: effectiveArmor}}/2.0}} | {{#expr:100.0-{{#var: effectiveArmor}}/2.0}} }}/100)* 0.5}}
+
}}<noinclude>{{Documentation wanted}}</noinclude>

Latest revision as of 23:21, 1 November 2024

       100