# Cash Shop

####

{% embed url="<https://youtu.be/ovY9AmPXtak>" %}

#### Cash Points

* **Storage**: Account-wide currency stored in `sd->cashPoints`
* **Database Variable**: `CASHPOINT_VAR`
* **Maximum Value**: `MAX_CASHPOINT` (default: `INT_MAX` = 2,147,483,647)
* **Usage**: Primary currency for most cash shop purchases
* **Overflow Protection**: Automatically capped at maximum when adding points

#### Kafra Points

* **Storage**: Account-wide currency stored in `sd->kafraPoints`
* **Database Variable**: `KAFRAPOINT_VAR`
* **Maximum Value**: `MAX_KAFRAPOINT` (default: `INT_MAX` = 2,147,483,647)
* **Usage**: Secondary currency, can be used alongside Cash Points or exclusively for Limited tab
* **Overflow Protection**: Automatically capped at maximum when adding points

### Payment Rules by Tab

#### Limited Tab (`CASHSHOP_TAB_LIMITED`)

* **Payment Method**: Kafra Points ONLY
* **Restriction**: Cannot use Cash Points
* **Payment Logic**: Full price must be paid entirely with Kafra Points
* **Error**: "You don't have enough Kafra Points." if insufficient

#### All Other Tabs

* **Payment Method**: Split payment (Cash Points + Kafra Points)
* **Payment Logic**:
  * Total cost = Cash Points portion + Kafra Points portion
  * Cash Points = Total price - Kafra Points amount
  * Kafra Points = Amount specified by client (up to total price)
* **Flexibility**: Player can choose how much to pay with each currency

### Currency Limits

#### Maximum Values

* **Cash Points**: `MAX_CASHPOINT` = 2,147,483,647 (default)
* **Kafra Points**: `MAX_KAFRAPOINT` = 2,147,483,647 (default)
* **Custom Limits**: Can be overridden by defining constants before including `mmo.hpp`

#### Price Limits

* **Minimum Price**: Must be greater than 0
* **Maximum Price**: Must be less than `MAX_CASHPOINT`
* **Validation**: Checked during database loading

#### Purchase Quantity Limits

* **Maximum per Transaction**: 99 items of the same type
* **Validation**: Server-side check to prevent packet manipulation
* **Error**: Purchase fails if quantity exceeds 99

### Overflow Protection

#### When Adding Currency

* Input values are capped to maximum limits
* If result would exceed maximum, amount is capped to available space
* Warning logged if overflow would occur

#### When Paying

* Kafra Points parameter is capped to `MAX_KAFRAPOINT` before calculation
* Validates player has sufficient funds before deduction
* No overflow possible as deduction cannot exceed current balance

### Payment Processing

#### Function: `pc_paycash()`

**Parameters**:

* `price`: Total amount (Cash Points + Kafra Points)
* `points`: Amount to pay with Kafra Points

**Calculation**:

Cash Points deducted = price - points\
Kafra Points deducted = points

**Validation**:

* Checks: `cashPoints >= (price - points)` AND `kafraPoints >= points`
* Returns: Total deducted on success, -1 on failure

### Account Storage

* Both currencies are account-level (shared across all characters)
* Stored in account variables: `CASHPOINT_VAR` and `KAFRAPOINT_VAR`
* Persists across server restarts

### Error Codes

* `CASHSHOP_RESULT_ERROR_SHORTTAGE_CASH`: Insufficient currency
* `CASHSHOP_RESULT_ERROR_UNKNOWN`: Generic error (may include payment failures)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://the-ragnarok-classic-1.gitbook.io/wiki/server-information/cash-shop.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
