# Gatcha System

In this example, we will implement a Gatcha System using Dataset.

First, we will need to create a spreadsheet with the following data:

## Season 1 Gatcha Characters

| Character ID | Gatcha Chance | Rank |
| ------------ | ------------- | ---- |
| 0            | 1.51          | 5    |
| 1            | 32.83         | 4    |
| 2            | 32.83         | 3    |
| 3            | 32.83         | 2    |

{% hint style="warning" %}
Please note that the sum of the Gatcha Chance column is equal to 100.&#x20;

This will be very important to calculate a random weighted selection in the Gatcha Pull formula.
{% endhint %}

## Importing the Spreadsheet Into the Diagram

To import your spreadsheet into the diagram, first export it using the XLSX or CSV formats.

With your exported file in hands, click on the Spreadsheets menu button. The Spreadsheets drawer will appear on the right.

Click on the "+" button to add a new spreadsheet.

<figure><img src="https://3575185254-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fib30WaNePUQBBFJBULTa%2Fuploads%2FAGnffltqzbOXLpwx6u58%2FNVIDIA_Share_2024-05-09_08-45-16.png?alt=media&#x26;token=8d6947a0-caf9-4444-8faf-3b8fd2c7f0ed" alt=""><figcaption></figcaption></figure>

After clicking on the "+" button, the following dialog will be displayed

<figure><img src="https://3575185254-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fib30WaNePUQBBFJBULTa%2Fuploads%2F11E3w06sgYyoxviARiPA%2Fimage.png?alt=media&#x26;token=3f8af02f-777d-407e-8c8a-26b1a0c33997" alt=""><figcaption></figcaption></figure>

Click on "Choose" and then select your exported file. After selecting the file on your computer, the dialog will change, asking for confirmation. If the selected file is correct, click on "Submit".

<figure><img src="https://3575185254-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fib30WaNePUQBBFJBULTa%2Fuploads%2FahcN3y5lx8mKoikBpX91%2Fimage.png?alt=media&#x26;token=546c0d89-8df5-4fd2-a1c8-ab0d18314188" alt=""><figcaption></figcaption></figure>

If the dialog displays a "Success" message, you'll be able to find your uploaded spreadsheet in the Spreadsheets Menu.

We can open the spreadsheet by clicking on its name.

<figure><img src="https://3575185254-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fib30WaNePUQBBFJBULTa%2Fuploads%2FrJOSXjgPBv84NRDWZFy9%2Fimage.png?alt=media&#x26;token=bc676232-550a-43c3-8240-58a151359124" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3575185254-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fib30WaNePUQBBFJBULTa%2Fuploads%2FSYbzBcKlyffrrWMERGtW%2Fimage.png?alt=media&#x26;token=4bb5907f-2884-40ff-ab41-a9cb80020225" alt=""><figcaption></figcaption></figure>

We can then rename the Spreadsheet by clicking on the "Properties" button.

<figure><img src="https://3575185254-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fib30WaNePUQBBFJBULTa%2Fuploads%2FUjnwYBXYK1IHDBVER0Fi%2Fimage.png?alt=media&#x26;token=b306422d-6154-48d7-8f5a-e03856487432" alt=""><figcaption></figcaption></figure>

We can see the updated name in the Spreadsheets Drawer:

<figure><img src="https://3575185254-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fib30WaNePUQBBFJBULTa%2Fuploads%2FUYmNPB8GDaqtFBXkm7gQ%2Fimage.png?alt=media&#x26;token=4443d01e-af37-4f03-ba47-9402907edd75" alt=""><figcaption></figcaption></figure>

## Adding a Dataset Node

The next step is to add a Dataset node. This way we will be able to reference the values we have just imported into our diagram.

To add a Dataset node, you can drag and drop the Dataset node from the Node Toolbox into your diagram.

<figure><img src="https://3575185254-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fib30WaNePUQBBFJBULTa%2Fuploads%2Frw0WtapCFu60NCNWGIqk%2Fimage.png?alt=media&#x26;token=ff5208f6-6e41-460b-90ac-705f127f3223" alt=""><figcaption></figcaption></figure>

The Dataset node added into the diagram:

<figure><img src="https://3575185254-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fib30WaNePUQBBFJBULTa%2Fuploads%2Fg8ULYlW5aZAruUNHuu6t%2Fimage.png?alt=media&#x26;token=dd181657-57b8-4835-878e-6bb87d537338" alt=""><figcaption></figcaption></figure>

The next step is to rename our node and select the Dataset from the dropdown menu. In this example we will use the following name:

> Active Season Gatcha Dataset

<figure><img src="https://3575185254-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fib30WaNePUQBBFJBULTa%2Fuploads%2FxZ808Vis5HzcrIgmtqMm%2Fimage.png?alt=media&#x26;token=00b0cf37-1010-4f17-a02c-9b2ec5c0e383" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
Please note the automatically generated Tag name (in yellow).&#x20;

In this example, with the Dataset node named "Active Season Gatcha Dataset", our tag for this specific node becomes "activeSeasonGatchaDataset".&#x20;

We will use this tag to connect the Dataset node to other nodes.

If you named your node differently, your Tag name will also be different and you will need to update the following formulas accordingly, otherwise the formulas will become invalid.
{% endhint %}

## Creating the Diagram Loop

With the Dataset import part done, we can then start implementing the actual logic behind our simulation.

In this example, we will need 3 Formula nodes, 1 Origin node and 1 Data Node.

### Nodes Overview

#### Formula 1

```
Name: Gatcha RNG

Tag: gatchaRNG

Expression: random(0, 100)

Connected to: Gatcha Pull (Formula)

Value: true

Description: Generates a random number between 0 and 100. 
This random number will be used to determine pulled character
```

#### Formula 2

{% code fullWidth="false" %}

```
Name: Gatcha Pull

Tag: gatchaPull

Expression: larger(gatchaRNG, 0)*smallerEq(gatchaRNG, activeSeasonGatchaDataset[1][0])*0+
larger(gatchaRNG, activeSeasonGatchaDataset[1][0])*smallerEq(gatchaRNG, activeSeasonGatchaDataset[1][0] + activeSeasonGatchaDataset[1][1])*1+
larger(gatchaRNG, activeSeasonGatchaDataset[1][0] + activeSeasonGatchaDataset[1][1])*smallerEq(gatchaRNG, activeSeasonGatchaDataset[1][0] + activeSeasonGatchaDataset[1][1] + activeSeasonGatchaDataset[1][2])*2+
larger(gatchaRNG, activeSeasonGatchaDataset[1][0] + activeSeasonGatchaDataset[1][1] + activeSeasonGatchaDataset[1][2])*smallerEq(gatchaRNG, activeSeasonGatchaDataset[1][0] + activeSeasonGatchaDataset[1][1] + activeSeasonGatchaDataset[1][2] + activeSeasonGatchaDataset[1][3])*3


Connected to: Gatcha Pull Rank (Formula)

Value: true

Description: Compares generated random number to the Dataset table. 
If between the thresholds for each character, return character number.
We are comparing the randomly generated number to the values defined in the dataset's "Gatcha Chance" column to create a weighted random.
```

{% endcode %}

#### Understanding the Formula's Expression

1. <mark style="color:red;">larger(</mark><mark style="color:purple;">gatchaRNG</mark><mark style="color:red;">,</mark> <mark style="color:blue;">0</mark><mark style="color:red;">)</mark> <mark style="color:orange;">\*</mark> <mark style="color:red;">smallerEq(</mark><mark style="color:purple;">gatchaRNG</mark><mark style="color:red;">,</mark> <mark style="color:blue;">activeSeasonGatchaDataset\[1]\[</mark><mark style="color:yellow;">0</mark><mark style="color:blue;">]</mark><mark style="color:red;">)</mark> <mark style="color:orange;">\*</mark> <mark style="color:green;">0</mark> *<mark style="color:red;">+</mark>*&#x20;
2. <mark style="color:red;">larger(</mark><mark style="color:purple;">gatchaRNG</mark><mark style="color:red;">,</mark> <mark style="color:blue;">activeSeasonGatchaDataset\[1]\[</mark><mark style="color:yellow;">0</mark><mark style="color:blue;">]</mark><mark style="color:red;">)</mark> <mark style="color:orange;">\*</mark> <mark style="color:red;">smallerEq(</mark><mark style="color:purple;">gatchaRNG</mark><mark style="color:red;">,</mark> <mark style="color:blue;">activeSeasonGatchaDataset\[1]\[</mark><mark style="color:yellow;">0</mark><mark style="color:blue;">] + activeSeasonGatchaDataset\[1]\[</mark><mark style="color:yellow;">1</mark><mark style="color:blue;">]</mark><mark style="color:red;">)</mark> <mark style="color:orange;">\*</mark> <mark style="color:green;">1</mark> *<mark style="color:red;">+</mark>*
3. <mark style="color:red;">larger(</mark><mark style="color:purple;">gatchaRNG</mark><mark style="color:red;">,</mark> <mark style="color:blue;">activeSeasonGatchaDataset\[1]\[</mark><mark style="color:yellow;">0</mark><mark style="color:blue;">] + activeSeasonGatchaDataset\[1]\[</mark><mark style="color:yellow;">1</mark><mark style="color:blue;">]</mark><mark style="color:red;">)</mark> <mark style="color:orange;">\*</mark> <mark style="color:red;">smallerEq(</mark><mark style="color:purple;">gatchaRNG</mark><mark style="color:red;">,</mark> <mark style="color:blue;">activeSeasonGatchaDataset\[1]\[</mark><mark style="color:yellow;">0</mark><mark style="color:blue;">] + activeSeasonGatchaDataset\[1]\[</mark><mark style="color:yellow;">1</mark><mark style="color:blue;">] + activeSeasonGatchaDataset\[1]\[</mark><mark style="color:yellow;">2</mark><mark style="color:blue;">]</mark><mark style="color:red;">)</mark> <mark style="color:orange;">\*</mark> <mark style="color:green;">2</mark> *<mark style="color:red;">+</mark>*
4. <mark style="color:red;">larger(</mark><mark style="color:purple;">gatchaRNG</mark><mark style="color:red;">,</mark> <mark style="color:blue;">activeSeasonGatchaDataset\[1]\[</mark><mark style="color:yellow;">0</mark><mark style="color:blue;">] + activeSeasonGatchaDataset\[1]\[</mark><mark style="color:yellow;">1</mark><mark style="color:blue;">] + activeSeasonGatchaDataset\[1]\[</mark><mark style="color:yellow;">2</mark><mark style="color:blue;">]</mark><mark style="color:red;">)</mark> <mark style="color:orange;">\*</mark> <mark style="color:red;">smallerEq(</mark><mark style="color:purple;">gatchaRNG</mark><mark style="color:red;">,</mark> <mark style="color:blue;">activeSeasonGatchaDataset\[1]\[</mark><mark style="color:yellow;">0</mark><mark style="color:blue;">] + activeSeasonGatchaDataset\[1]\[</mark><mark style="color:yellow;">1</mark><mark style="color:blue;">] + activeSeasonGatchaDataset\[1]\[</mark><mark style="color:yellow;">2</mark><mark style="color:blue;">] + activeSeasonGatchaDataset\[1]\[</mark><mark style="color:yellow;">3</mark><mark style="color:blue;">]</mark><mark style="color:red;">)</mark> <mark style="color:orange;">\*</mark> <mark style="color:green;">3</mark>

In natural language:

1. If the <mark style="color:purple;">value</mark> is <mark style="color:red;">larger than</mark> <mark style="color:blue;">zero</mark>, <mark style="color:orange;">and</mark> the <mark style="color:purple;">value</mark> is <mark style="color:red;">smaller or equal</mark> to the <mark style="color:blue;">Character ID</mark> <mark style="color:yellow;">0</mark><mark style="color:blue;">'s "Gatcha Chance"</mark> *(1.51)*, we <mark style="color:orange;">return</mark> <mark style="color:green;">0</mark> *<mark style="color:red;">or</mark>*&#x20;
2. if the <mark style="color:purple;">value</mark> is <mark style="color:red;">larger than</mark> <mark style="color:blue;">Character ID</mark> <mark style="color:yellow;">0</mark><mark style="color:blue;">'s "Gatcha Chance"</mark> *(1.51)* <mark style="color:orange;">and</mark> <mark style="color:red;">smaller or equal</mark> to <mark style="color:blue;">the sum of Character ID</mark> <mark style="color:yellow;">0</mark> <mark style="color:blue;">and</mark> <mark style="color:yellow;">1</mark><mark style="color:blue;">'s "Gatcha Chance"</mark> *(1.51 + 32.83)*, we <mark style="color:orange;">return</mark> <mark style="color:green;">1</mark> *<mark style="color:red;">or</mark>*
3. if the <mark style="color:purple;">value</mark> is <mark style="color:red;">larger than</mark> the <mark style="color:blue;">sum of</mark> <mark style="color:blue;">Character ID</mark> <mark style="color:yellow;">0</mark> <mark style="color:blue;">and</mark> <mark style="color:yellow;">1</mark><mark style="color:blue;">'s "Gatcha Chance"</mark> *(1.51 + 32.83)* <mark style="color:orange;">and</mark> the <mark style="color:purple;">value</mark> <mark style="color:orange;">is</mark> <mark style="color:red;">smaller or equal</mark> to <mark style="color:blue;">the sum of Character ID</mark> <mark style="color:yellow;">0, 1</mark> <mark style="color:blue;">and</mark> <mark style="color:yellow;">2</mark><mark style="color:blue;">'s "Gatcha Chance"</mark> *(1.51 + 32.83 + 32.83)*, we <mark style="color:orange;">return</mark> <mark style="color:green;">2</mark> *<mark style="color:red;">or</mark>*
4. if the <mark style="color:purple;">value</mark> is <mark style="color:red;">larger than</mark> the <mark style="color:blue;">sum of</mark> <mark style="color:blue;">Character ID</mark> <mark style="color:yellow;">0, 1</mark> <mark style="color:blue;">and</mark> <mark style="color:yellow;">2</mark><mark style="color:blue;">'s "Gatcha Chance"</mark> *(1.51 + 32.83 + 32.83)* <mark style="color:orange;">and</mark> <mark style="color:red;">smaller or equal</mark> to <mark style="color:blue;">the sum of Character ID</mark> <mark style="color:yellow;">0, 1, 2</mark> <mark style="color:blue;">and</mark> <mark style="color:yellow;">3</mark><mark style="color:blue;">'s "Gatcha Chance"</mark> *(1.51 + 32.83 + 32.83 + 32.83)*, we <mark style="color:orange;">return</mark> <mark style="color:green;">3</mark>

Graphically (not to scale):

<figure><img src="https://3575185254-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fib30WaNePUQBBFJBULTa%2Fuploads%2FzRxWyVcNME6PKHMWokd0%2FCharacterIDIntervalsBackground.png?alt=media&#x26;token=0c9d347b-8928-462d-8be7-2928926a5f44" alt=""><figcaption></figcaption></figure>

#### Formula 3

```
Name: Gatcha Pull Rank

Tag: gatchaPullRank

Expression: activeSeasonGatchaDataset[2][gatchaPull]

Connected to: Gatcha Pulls Origin (Origin)

Value: true

Description: Get pulled character data from the Dataset
```

#### Origin 1

```
Name: Gatcha Pulls Origin

Tag: gatchaPullsOrigin

Connected to: Gatcha Pulls (Data)

Value: 1

Description: Add 1 to pulled characters counter
```

#### Data 1

```
Name: Gatcha Pulls

Tag: gatchaPulls

Connected to: Gatcha Pulls Origin (Origin)

Description: Holds pulled characters amount
```

The nodes will be connected as such:

<figure><img src="https://3575185254-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fib30WaNePUQBBFJBULTa%2Fuploads%2FYT4lZvmJHa5QzPd91EG4%2Fimage.png?alt=media&#x26;token=75fc51ae-cd15-43ef-bbc1-20ee23c59079" alt=""><figcaption></figcaption></figure>

The logic works as follow:

1. Generate a random number between 0 and 100 (Gatcha RNG Formula Node)
2. Return a value between 0 and 3 that corresponds to the Character ID, based on the previously generated random number (Gatcha Pull)
3. Get data from the previously generated Character ID and display it
4. Add 1 to the pull counter
5. Repeat (1. \~ 4.)
