We moved our repositories to BitBucket!

If you can't login or you can't register to the forums do not rise an issue, instead please write to support (at) l2jserver.com

Check our wiki!

Report server issues here

Forum has been updated to phpBB 3.2, let's see if this fixes some minor bugs we had.

Thank you for visiting http://www.l2jserver.com/

How stats order working

Find all FAQs, HOWTOs and guides here.
Forum rules
READ NOW: L2j Forums Rules of Conduct
Post Reply
User avatar
Zealar
L2j Senior Developer
L2j Senior Developer
Posts: 1235
Joined: Sun Jul 15, 2007 10:29 am

How stats order working

Post by Zealar » Fri Nov 21, 2014 9:55 pm

"Order" allow us to change basic math operation order.

"Add" == "Addition" == +
"Mul" == "Multiplication" == *

For example if we got :

Code: Select all

Base stat : (10)Add (+30)Mul (* 30)
In normal math mul is before add so will got follow:

Code: Select all

10 * 30 + 30 = 330
But if we use order "2" for (*30) and order "1" for (+30) then will get.

Code: Select all

(10 + 30 ) * 30 = 1200
In other words we tell to calculator to calculate "Add" before "Mul".

For see example how orders can be used in L2J and what effect they will have lets do some calculations with characters Critical Rate (Crit. Rate).

Before we look in formulas and order need to understand what is DEX bonus and how to see proper value.

See file game\data\stats\statBonus.xml

Code: Select all

     <DEX>        <!-- 1.009^(DEX-19.360) -->        <stat value="20" bonus="1.01" />        <stat value="21" bonus="1.01" />        <stat value="22" bonus="1.02" />        <stat value="23" bonus="1.03" />        <stat value="24" bonus="1.04" />        <stat value="25" bonus="1.05" />        <stat value="26" bonus="1.06" />        <stat value="27" bonus="1.07" />        <stat value="28" bonus="1.08" />        <stat value="29" bonus="1.09" />    </DEX></list>
Inside we can see Character with 23 DEX got 3% bonus ( * 1.3)

Code: Select all

<stat value="23" bonus="1.03" />
Also need to check default orders for "Mul" and "Add" if they is not changed in DataPack
Mul = 20
Add = 30
Or Mul will be calculate before Add if order is not set to different values in DP.
For see default values for all stats look java.com.l2jserver.gameserver.enums.StatFunction.java

Code: Select all

    ADD("Add", 30),    DIV("Div", 20),    ENCHANT("Enchant", 0),    ENCHANTHP("EnchantHp", 40),    MUL("Mul", 20),    SET("Set", 0),    SHARE("Share", 30),    SUB("Sub", 30);
Lower value mean will be used first.

=======================================
For that example will use:
Class : Maestro
Level : 85
Equip : None

For calculate proper critical rate we need to look inside char template.
game\data\stats\chars\baseStats\Maestro.xml
Look the line

Code: Select all

<baseCritRate>4</baseCritRate>
That "4" is char base critical rate.

Then we need the formula for critical rate so we look inside

Code: Select all

com.l2jserver.gameserver.model.stats.functions.formulas.FuncAtkCritical.java
And we see

Code: Select all

initVal * BaseStats.DEX.calcBonus(effector) * 10
Or "val * dexBonus * 10"

Is time for replace "val" and "dex" bonus.

Maestro got 29 dex what give us 1.09 bonus, and we got 4 base when replace in formula we be

Code: Select all

4 * 1.09 * 10 = 43.6 = 44
Critical Rate

For that example will use 2 skills one give "Add 15 critical (15 static)" and second one give "Mul 1.3 critical(30%)"

Code: Select all

<skill id="22160" name="Vesper Critical Power">    <for>        <effect name="Buff">            <add stat="rCrit" val="15" />        </effect>    </for></skill>

Code: Select all

<skill id="1077" name="Focus">    <for>        <effect name="Buff">            <mul stat="rCrit" val="1.3" />        </effect>    </for></skill>
How formula will be change if use "22160"
FROM

Code: Select all

4 * 1.09 * 10 = 43.6 = 44 // Critical Rate
TO

Code: Select all

(4 * 1.09 * 10) + 15= 58.6 = 59 // Critical Rate
How formula will be change if use "1077"
FROM

Code: Select all

4 * 1.09 * 10 = 43.6 = 44 // Critical Rate
TO

Code: Select all

(4 * 1.09 * 10) * 1.3 = 56.68 = 57 // Critical Rate
How formula will be change if use BOTH
FROM

Code: Select all

4 * 1.09 * 10 = 43.6 = 44 // Critical Rate

TO

Code: Select all

(4 * 1.09 * 10 * 1.3) + 15 = 71.68 = 72 // Critical Rate
Ok now lets play with orders. Add got order 30 by default so is calc last but what will happen if we put it before Mul.
Mul got order 20. So we change skill "22160"
FROM

Code: Select all

<add stat="rCrit" val="15" />
TO

Code: Select all

<add order="19" stat="rCrit" val="15" />
Now that "Add" got lower stat so will be calculate before mul and formula change.
FROM

Code: Select all

(4 * 1.09 * 10 * 1.3) + 15 = 71.68 = 72 // Critical Rate
TO

Code: Select all

((4 * 1.09 * 10 ) + 15) * 1.3 = 76.18 = 76 // Critical Rate
What happen if we got weapon.
For weapon will use "(233) Dark Screamer"
That weapon got

Code: Select all

<set stat="rCrit" val="12" />
That set override the default value so instant of 4 will got 12 so formula is change.
FROM

Code: Select all

4 * 1.09 * 10 = 43.6 = 44 // Critical Rate

TO

Code: Select all

12 * 1.09 * 10 = 130.8 = 131
Lets say we switch weapon to "(4772)Dark Screamer - Focus"
That weapon got "<set stat="rCrit" val="12" />"
But also give skill "3011" and that skill got

Code: Select all

<add stat="rCrit" val="81.2" />
We know need to replace base "4" with set "12" then we look the StatFunction and see where Add is. Add got value 30 so is add last. then formula change to

Code: Select all

(12 * 1.09 * 10) + 81.2 = 212
Q & A
|_______________________________|
Q : In com.l2jserver.gameserver.mode.stats.functions.formulas.* each formula got "Order" called in constructor super for what that is used?
A :
SPOILER:
Basically that order control when formula will be included in calculation.
If we take first example
How formula will be change if use "22160"
FROM

Code: Select all

4 * 1.09 * 10 = 43.6 = 44 // Critical Rate
TO

Code: Select all

(4 * 1.09 * 10) + 15= 58.6 = 59 // Critical Rate
That is when "FuncAtkCritical" get order 1. So formula is called first then other values is add.
In that case we use "Add" to add (+15) that "Add" stat got order 30 what will happen if change order inside "FuncAtkCritical" to 31.
FROM

Code: Select all

(4 * 1.09 * 10) + 15= 58.6 = 59 // Critical Rate
TO

Code: Select all

(4+15) * 1.09 * 10= 58.6 = 207,1 = 207 // Critical Rate
All stats with order under 31 will be perform first then formula will be called. If look code "initValue" will not be called with "4" will use already calculate value.
So really will look like

Code: Select all

19 * 1.09 * 10= 58.6 = 207,1 = 207 // Critical Rate
Q : In com.l2jserver.gameserver.mode.stats.functions.formulas.* Orders used in that formulas effect the other formulas?
For example order inside FuncAtkAccuracy effect in some way FuncAtkCritical?
A : No
Q : Why there is some items what not use default orders and they got custom one like Jewels and Armors
A :
SPOILER:
Lets take again "Maestro" again and see how Pdef and Mdef is calculate.
game\data\stats\chars\baseStats\Maestro.xml

Code: Select all

<basePDef>    <chest>31</chest>    <legs>18</legs>    <head>12</head>    <feet>7</feet>    <gloves>8</gloves>    <underwear>3</underwear>    <cloak>1</cloak></basePDef><baseMDef>    <rear>9</rear>    <lear>9</lear>    <rfinger>5</rfinger>    <lfinger>5</lfinger>    <neck>13</neck></baseMDef>
For example to calculate base Pdef we need to sum all base Pdef so we calculate "chest + legs + head + feet + gloves + underwear + clock" in that case 31 + 18 + 12 + 7 + 8 + 3 + 1.
But we don't keep that values separated and in server start we calculate the sum and put in one variable. Later when we need to calculate base PDef we look used slots and sub value based on item.

Base PDef for Maestro will be 80, then PDef formula is called.
Why is that order 0. That is used to not made new "setGlovesDef", "setChestDef" and other values what will change base Glolves, BaseChest defence when item is used.
Add stats got order 30 so if we not change the order they will be add to late and formula will return bad stats. Using order 0 on them we put that calculation on the begining.

Lets say we put item

Code: Select all

<item id="23" type="Armor" name="Wooden Breastplate">    <for>        <add order="0" stat="pDef" val="47" />    </for></item>
Coz that stat got order 0 is called before formula so we do.
80 + 47 = 127 Base PDef and then we called the PDef formula.
Few lines before calculate the stat is check if "Chest" is used, and see we put that new armor so he remove from that value base chest PDef.
127 - 31 = 96 Base PDef.
For value is used 96.

So basically that is hack to use same value in a lot places (real power of custom orders).
With MDef is the same.

User avatar
Zoey76
L2j Inner Circle
L2j Inner Circle
Posts: 6828
Joined: Tue Aug 11, 2009 3:36 am

Re: How stats order working

Post by Zoey76 » Fri Nov 28, 2014 6:40 pm

Moved to FAQ - HOWTO - Guides, thanks.
Using Eclipse Neon 4.6.3 - JDK8u112 - MySQL 5.7.17 - L2J Server :+1:
Live support

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest