# 05 Formulas

In this tutorial we’ll set up the main formulas for our status system.

# Formulas #

We’ll set up the following formulas:

• physical damage
• magical damage
• hit chance
• critical chance
• level based reward

Due to formulas working as a steb-by-step calculation, we’ll have to split some things into multiple formulas to work correctly.

Navigate to Game > Formulas, well change the already added Default formula and add additional formulas. You can optionally use formula types for organizing them in the editor, but it’s not required (and isn’t part of this tutorial series).

## Calculating Physical Damage #

The physical damage is calculated like this:

Value * User.WPN * User.ATK / ((100+Target.DEF) / 100)

It uses the following values:

• Value
The initial value forwarded to the formula, e.g. 1 for a base attack or 2 for a critical hit.
• User.WPN
The user’s Weapon Damage status value.
• User.ATK
The user’s Attack status value.
• Target.DEF
The target’s Defence status value.

Due to how formulas work, we’ll have to split this into 2 formulas:

• DEF Base
The defence basis calculation: (100+Target.DEF) / 100
• Physical Damage
The formula used to calculate the damage: Value * User.WPN * User.ATK / DEF Base

## Calculating Magical Damage #

The magical damage is calculated like this:

Value * 2 * User.MATK * User.MATK / (User.MATK + Target.MDEF)

It uses the following values:

• Value
The initial value forwarded to the formula, e.g. 15 for a low level magic spell.
• User.MATK
The user’s Magic Attack status value.
• Target.MDEF
The target’s Magic Defence status value.

Due to how formulas work, we’ll have to split this into 2 formulas:

• MDEF Base
The magic defence basis calculation: User.MATK + Target.MDEF
• Magical Damage
The formula used to calculate the damage: Value * 2 * User.MATK * User.MATK

## Calculating Hit Chance #

The hit chance is calculated like this:

(User.DEX / Target.AGI) * 100

It uses the following values:

• User.DEX
The user’s Dexterity status value.
• Target.AGI
The target’s Agility status value.

The result will be limited to values between 0 and 100. We only need one formula for this.

## Calculating Critical Chance #

The critical chance is calculated like this:

(User.LUK + (User.DEX / 4)) – (Target.LUK + (Target.DEX / 4))

It uses the following values:

• User.LUK
The user’s Luck status value.
• User.DEX
The user’s Dexterity status value.
• Target.LUK
The target’s Luck status value.
• Target.DEX
The target’s Dexterity status value.

Due to how formulas work, we’ll have to split this into 2 formulas:

• LUK Base
The formula used to calculate user and target sides of the formula (by passing on different users): (LUK + (DEX / 4)) / 3
• Critical Chance
The formula used to calculate the critical chance: LUK Base(User) – LUK Base(Target).

The result will be limited to values between 0 and 100.

## Calculating Level Based Reward #

Combatants will give experience and quantity (e.g. gold) rewards scaled by their level. The level based reward is calculated like this:

Value * User.Level

It uses the following values:

• Value
The initial value forwarded to the formula, e.g. 1 for 1x level experience/quantity, 2 for 2x level experience/quantity.
• User.Level
The user’s level.

We only need one formula for this.

# 0: DEF Base #

This formula is part of the physical damage calculation and calculates the defence basis that’ll be used by the actual physical damage formula. ## Formula Settings #

• Name
Set to DEF Base.

## Value #

Add Node > Value > Value

This node is used to add a value, e.g. a defined value or the result of another formula.

• Operator
• Value
Select Value > Value.
Set the value to 100.

## Status Value #

Add Node > Combatant > Status Value

Uses a combatant’s status value – we’ll use the target’s defence.

• Operator
• Status Origin
Select Target.
• Status Value
Select Defence.
• Value Origin
Select Current.
We’ll use the current value of the status value.

## Value #

Add Node > Value > Value

Divide by 100.

• Operator
Select Divide.
• Value
Select Value > Value.
Set the value to 100.

# 1: Physical Damage #

This formula calculates the physical damage, using the DEF Base formula as part of the calculation. Using the formula requires to pass on an initial value that is greater than 0 to achieve actual damage. ## Formula Settings #

• Name
Set to Physical Damage.

## Status Value #

Add Node > Combatant > Status Value

Multiply by the user’s weapon damage. This’ll multiply the passed on initial value (coming from an ability) by the weapon damage.

• Operator
Select Multiply.
• Status Origin
Select User.
• Status Value
Select Weapon Damage.
• Value Origin
Select Current.

## Status Value #

Add Node > Combatant > Status Value

Multiply by the user’s attack.

• Operator
Select Multiply.
• Status Origin
Select User.
• Status Value
Select Attack.
• Value Origin
Select Current.

## Value #

Add Node > Value > Value

Divide by the DEF Base formula.

• Operator
Select Divide.
• Value
Select Value > Formula.
Select DEF Base.

The setup should automatically use the User as the user and the Target as the target of the other formula.

• Game Object (User)
Select User.
• Game Object (Target)
Select Target.

# 2: MDEF Base #

This formula is part of the magical damage calculation and calculates the magic defence basis that’ll be used by the actual magical damage formula. ## Formula Settings #

• Name
Set to MDEF Base.

## Status Value #

Add Node > Combatant > Status Value

• Operator
• Status Origin
Select User.
• Status Value
Select Magic Attack.
• Value Origin
Select Current.

## Status Value #

Add Node > Combatant > Status Value

• Operator
• Status Origin
Select Target.
• Status Value
Select Magic Defence.
• Value Origin
Select Current.

# 3: Magical Damage #

This formula calculates the magical damage, using the MDEF Base formula as part of the calculation. Using the formula requires to pass on an initial value that is greater than 0 to achieve actual damage. ## Formula Settings #

• Name
Set to Magical Damage.

## Value #

Add Node > Value > Value

Multiply by 2. This’ll multiply the passed on initial value (coming from an ability) by 2.

• Operator
Select Multiply.
• Value
Select Value > Value.
Set the value to 2.

## Status Value #

Add Node > Combatant > Status Value

Multiply by the user’s magic attack.

• Operator
Select Multiply.
• Status Origin
Select User.
• Status Value
Select Magic Attack.
• Value Origin
Select Current.

## Status Value #

Add Node > Combatant > Status Value

Once more multiply by the user’s magic attack. You can just copy the previous node.

• Operator
Select Multiply.
• Status Origin
Select User.
• Status Value
Select Magic Attack.
• Value Origin
Select Current.

## Value #

Add Node > Value > Value

Divide by the MDEF Base formula.

• Operator
Select Divide.
• Value
Select Value > Formula.
Select MDEF Base.

The setup should automatically use the User as the user and the Target as the target of the other formula.

• Game Object (User)
Select User.
• Game Object (Target)
Select Target.

# 4: Hit Chance #

This formula calculates the hit chance. ## Formula Settings #

• Name
Set to Hit Chance.
• Use Minimum Value
Enable this setting.
• Minimum Value
Select Value > Value.
Set the value to 0.
• Use Maximum Value
Enable this setting.
• Maximum Value
Select Value > Value.
Set the value to 100.

## Status Value #

Add Node > Combatant > Status Value

• Operator
• Status Origin
Select User.
• Status Value
Select Dexterity.
• Value Origin
Select Current.

## Status Value #

Add Node > Combatant > Status Value

Divide by the target’s agility.

• Operator
Select Divide.
• Status Origin
Select Target.
• Status Value
Select Agility.
• Value Origin
Select Current.

## Value #

Add Node > Value > Value

Multiply by 100.

• Operator
Select Multiply.
• Value
Select Value > Value.
Set the value to 100.

# 5: LUK Base #

This formula is part of the critical chance calculation and calculates the user’s and target’s side of the calculation by passing on the user or target. ## Formula Settings #

• Name
Set to LUK Base.

## Status Value #

Add Node > Combatant > Status Value

• Operator
• Status Origin
Select User.
• Status Value
Select Dexterity.
• Value Origin
Select Current.

## Value #

Add Node > Value > Value

Divide by 4.

• Operator
Select Divide.
• Value
Select Value > Value.
Set the value to 4.

## Status Value #

Add Node > Combatant > Status Value

• Operator
• Status Origin
Select User.
• Status Value
Select Luck.
• Value Origin
Select Current.

# 6: Critical Chance #

This formula calculates the critical chance using the LUK Base formula for user and target. ## Formula Settings #

• Name
Set to Critical Chance.
• Use Minimum Value
Enable this setting.
• Minimum Value
Select Value > Value.
Set the value to 0.
• Use Maximum Value
Enable this setting.
• Maximum Value
Select Value > Value.
Set the value to 100.

## Value #

Add Node > Value > Value

Add the LUK Base formula for the user.

• Operator
• Value
Select Value > Formula.
Select LUK Base.

The setup should automatically use the User as the user and the Target as the target of the other formula.

• Game Object (User)
Select User.
• Game Object (Target)
Select Target.

## Value #

Add Node > Value > Value

Subtract the LUK Base formula for the target.

• Operator
Select Sub.
• Value
Select Value > Formula.
Select LUK Base.

This time we need to change the user of the formula.

• Game Object (User)
Select Target.
• Game Object (Target)
Select Target.

# 7: Level Based Reward #

This formula calculates the level based reward, e.g. used by experience rewards of defeated combatants or loot tables dropping level based gold quantities.

Using the formula requires to pass on an initial value that is greater than 0 to get an actual reward. ## Formula Settings #

• Name
Set to Level Based Reward.

## Level #

Add Node > Combatant > Level

Uses a combatant’s level as value. We’ll multiply the initial formula value by the user’s level.

• Operator
Select Multiply.
• Status Origin
Select User.

# Save Changes #

And that’s it for the formula setup.

Don’t forget to save your changes by clicking on Save Settings at the bottom of the editor.

Next, we’ll set up ability types and item types.