GS2-Stamina

Stamina feature

Stamina is used to limit the number of times a game can be played. GS2-Limit expresses the limit as “3 times a day”, while GS2-Stamina uses stamina that recovers 1 point in 8 hours to realize the limit of 3 times a day.

In the case of stamina, by differentiating the points used, it is possible to achieve specifications such as 3 times per day for action A and 5 times per day for action B. This makes it easier to balance the game by setting guidelines for experience and in-game currency earned per stamina, and eliminates the idea that every action in the game is an efficient action.

We don’t often specify this, though, because developers should strive to get people to log in every day. For players, if the spec allows them to recover 1 point every 8 hours and accumulate up to 15 points, they can log in once every 5 days without having to log in every day and still use up their points without wasting them.

Stamina

Stamina is configured with “Recovery Cycle”, “Recovery Amount”, and “Maximum Value”.

Overflow

Stamina can be recovered beyond the maximum value. If the maximum is exceeded, there will be no recovery over time. Also, even if the maximum is exceeded, the “true maximum” can be set so that no more is added for UI reasons, etc.

Why do you let it overflow?

This spec may seem strange to developers who have not had the opportunity to play many games that include stamina in the spec.

Generally, stamina is restored through items or in-game purchases. This specification was created to minimize the stress on the player when using the item or purchasing stamina.

Here is a specific example.

The game restores 1 point of stamina every 5 minutes, and your maximum stamina is 50 points. You need 10 stamina points to play the next quest you want to play. However, your current stamina is only 9 points and you have to wait 5 minutes before you can play the next quest. So you decide to buy stamina. Purchasing stamina restores 50 stamina points. However, if you buy stamina now, even if you restore 50 points, 9 points will be wasted. So you wait 5 minutes for 1 point to recover, play the quest to bring your stamina to 0 points, and then buy stamina to play the next quest.

This does not allow players to play the game comfortably. As a result, games were created that introduced a specification that allowed players to recover stamina beyond the maximum.

Let’s take a look at how the user experience changes with the addition of overflow specification.

Currently, your stamina is down to 9 points, and you have to wait 5 minutes before you can play the next quest. So you buy stamina, regain 50 stamina points, and now have 59 stamina points. In this state, stamina will no longer be restored over time, but you immediately start the next quest, bringing your stamina to 49 points.

Script Triggers

Setting overflowTriggerScript in the namespace allows you to execute custom processing synchronously or asynchronously via Amazon EventBridge when stamina recovery exceeds the maximum value.

The main configurable event triggers and script configuration names are as follows:

  • overflowTriggerScript (Completion Notification: overflowDone): When stamina overflows

Master Data Management

Registering master data allows you to configure data and behaviors available to microservices.

Master data types include:

  • StaminaModel: Recovery amount, recovery interval, and maximum value definitions

Master data can be registered via the Management Console. Additionally, workflows can be set up to reflect data from GitHub or register via CI using GS2-Deploy.

Buff-Based Adjustments

Integrating with GS2-Buff allows you to adjust maxValue, recoverIntervalMinutes, and recoverValue, as well as action parameters such as consumeValue and recoverValue via buffs. This enables flexible adjustment of stamina cap, recovery speed, and consumption amount for events and other purposes.

Transaction Actions

GS2-Stamina provides the following transaction actions:

  • Verify Action: Verify current value, Verify maximum value, Verify recovery speed, Verify recovery amount, Verify overflow amount
  • Consume Action: Consume stamina, Decrease maximum value
  • Acquire Action: Recover (add) stamina, Add/Set maximum value, Set recovery speed, Set recovery amount

By using “Add maximum value” as an acquire action, it is possible to safely perform processes within a transaction to automatically expand the maximum stamina capacity, such as when an item is purchased at a shop or when a player’s rank increases. This facilitates the design of rewards that clearly demonstrate player growth. Additionally, by setting “Recover stamina” as a reward, it is possible to fully restore stamina upon achieving a specific mission, encouraging continuous play.

Example implementation

Get current stamina value

    var item = await gs2.Stamina.Namespace(
        namespaceName: "namespace-0001"
    ).Me(
        gameSession: GameSession
    ).Stamina(
        staminaName: "stamina-0001"
    ).ModelAsync();
    const auto Domain = Gs2->Stamina->Namespace(
        "namespace-0001" // namespaceName
    )->Me(
        AccessToken
    )->Stamina(
        "stamina-0001" // staminaName
    );
    const auto item = Domain.Model();

Consuming Stamina

It is not recommended to use this API to consume stamina.

It is recommended to use GS2-Quest or other services to perform some other process instead of consuming stamina.

    var result = await gs2.Stamina.Namespace(
        namespaceName: "namespace-0001"
    ).Me(
        gameSession: GameSession
    ).Stamina(
        staminaName: "stamina-0001"
    ).ConsumeAsync(
        consumeValue: 50
    );
    var item = await result.ModelAsync();
    const auto Domain = Gs2->Stamina->Namespace(
        "namespace-0001" // namespaceName
    )->Me(
        AccessToken
    )->Stamina(
        "stamina-0001" // staminaName
    );
    const auto Future = Domain->Consume(
        50
    );
    Future->StartSynchronousTask();
    if (Future->GetTask().IsError()) return false;

Detailed Reference