I really need some help to get this one right... but here is what I've found.

First, it calculates the a base value based on your stats to pass to the function that calculates the defense value.

It is calculated like this:

Physical Defence: (VIT*0.9 + ATT*0.9 + END*0.9 + STR*0.9 + DEX*0.9 + INT*0.9 + FAI*0.9 + HUM*0.9 + RES*1.80)

Magic Defence: (VIT*0.85 + ATT*0.85 + END*0.85 + STR*0.85 + DEX*0.85 + INT*0.85 + FAI*2.2 + HUM*0.85 + RES*0.85)

Fire Defence: (VIT*0.85 + ATT*0.85 + END*0.85 + STR*0.85 + DEX*0.85 + INT*0.85 + FAI*0.85 + HUM*0.85 + RES*2.2)

Lightning Defence: (VIT + ATT + END + STR + DEX + INT + FAI + HUM + RES)

This value is saturated to a maximum value of 800. If it is smaller than 0, the whole calculation is skipped.

Then it checks what range this value lies within. The ranges are 1-80, 80-160, 160-260, and 260-800. These values correspond to the final defence value range of 10, 10-120, 120-170, and 170-200.

If the value is between the range 80-160, or 160-260, the ratio to the number to reach the next range of defence, ie. (160-Base)/(160-80) or (260-Base)/(260-160). Otherwise, the ratio of that range is found, eg, for 170-200, (Base-170)/(200-170).

Also a factor value is chosen for used later, 1 for 1-80, and 260-800, 1.1 for 80-160, and 1.2 for 160-260.

Then that ratio number and the factor number is passed to the actual function that calculates the portion of defence that is added to the minimum defence value for the particular range of defence values. (Portion of 50 added to 120 for the range of 120 - 170 for example.

The next part is what I don't understand very well. I think it uses some higher precision calculation routines so the codes don't get translated easily back to mathematical function easily.

It invovles 7 lookup tables and several constant coefficients to do the calculations. The way it uses the lookup tables is like this: each time it uses a lookup table, it accesses 8 bits of fraction number of the ratio number and round it up if last bit is odd, effectively seperating the decimal places into 128 regions.

Other than that, I don't really know much. I don't understand in general what it is up to so I can't really explain here. If someone can shed light on this or even provide a mathematical formula. That would be great.

(I mean I can make some codes to do the same thing but I can't really simplify it, back to the original form.)

thanks

First, it calculates the a base value based on your stats to pass to the function that calculates the defense value.

It is calculated like this:

Physical Defence: (VIT*0.9 + ATT*0.9 + END*0.9 + STR*0.9 + DEX*0.9 + INT*0.9 + FAI*0.9 + HUM*0.9 + RES*1.80)

Magic Defence: (VIT*0.85 + ATT*0.85 + END*0.85 + STR*0.85 + DEX*0.85 + INT*0.85 + FAI*2.2 + HUM*0.85 + RES*0.85)

Fire Defence: (VIT*0.85 + ATT*0.85 + END*0.85 + STR*0.85 + DEX*0.85 + INT*0.85 + FAI*0.85 + HUM*0.85 + RES*2.2)

Lightning Defence: (VIT + ATT + END + STR + DEX + INT + FAI + HUM + RES)

This value is saturated to a maximum value of 800. If it is smaller than 0, the whole calculation is skipped.

Then it checks what range this value lies within. The ranges are 1-80, 80-160, 160-260, and 260-800. These values correspond to the final defence value range of 10, 10-120, 120-170, and 170-200.

If the value is between the range 80-160, or 160-260, the ratio to the number to reach the next range of defence, ie. (160-Base)/(160-80) or (260-Base)/(260-160). Otherwise, the ratio of that range is found, eg, for 170-200, (Base-170)/(200-170).

Also a factor value is chosen for used later, 1 for 1-80, and 260-800, 1.1 for 80-160, and 1.2 for 160-260.

Then that ratio number and the factor number is passed to the actual function that calculates the portion of defence that is added to the minimum defence value for the particular range of defence values. (Portion of 50 added to 120 for the range of 120 - 170 for example.

The next part is what I don't understand very well. I think it uses some higher precision calculation routines so the codes don't get translated easily back to mathematical function easily.

It invovles 7 lookup tables and several constant coefficients to do the calculations. The way it uses the lookup tables is like this: each time it uses a lookup table, it accesses 8 bits of fraction number of the ratio number and round it up if last bit is odd, effectively seperating the decimal places into 128 regions.

Other than that, I don't really know much. I don't understand in general what it is up to so I can't really explain here. If someone can shed light on this or even provide a mathematical formula. That would be great.

(I mean I can make some codes to do the same thing but I can't really simplify it, back to the original form.)

thanks