Turn-Based Combat Passive Mechanics: Designing a Scalable Stack-Based Passive System

    This article breaks down the design and engineering of growth-type passive mechanics in turn-based combat systems. It explains how to model stacking effects as a bounded state machine, handle turn-start versus hit-resolution timing, enforce threshold bonus caps, and define settlement order when a unit cannot act. It also covers faction-linked offensive and protective passives, guard-stack merging, idempotent event handling, and cloud-based load testing for long-battle balance validation. Readers will find pseudocode and practical checks for avoiding repeated settlement and numeric overflow.

    1. Background: Why Growth-Type Passives Are Hard to Design

    In turn-based combat systems, the mechanics most prone to design failures are not active skills but passive effects that trigger automatically at specific timings, such as turn start, hit resolution, and turn end. These effects usually share three characteristics: their state accumulates across turns, their bonuses have thresholds and caps, and their strength depends on the faction composition of other units on the field. When these three factors combine without a clear state machine and settlement order, hard-to-reproduce defects appear, such as the same stack layer being settled multiple times or a bonus still applying while the unit is in a confused state.

    This article uses a typical growth-type passive as a sample and abstracts it into four layers: a self-resource layer, a threshold-bonus layer, a faction-linkage layer, and a command-marker layer. It then provides engineering recommendations for implementing each layer.

    2. State Machine Modeling: Treat “Stacks” as a First-Class Citizen

    The core of a growth-type passive is a counter with an upper and lower bound. In the sample, the rules are: at turn start, if the unit does not hold the status, it gains 1 stack; each time it deals damage, it accumulates additional stacks; the maximum is a fixed value; every fixed step (for example, every 33 stacks) increases base skill damage by 1%, with the total bonus capped at 10%.

    Two engineering details are easy to overlook:

    • Accumulation timing must distinguish “turn start” from “hit resolution.” These cannot be merged into a single tick, or the first-acting unit would gain a free stack.
    • Threshold bonuses should be calculated with integer division and forcibly truncated to the cap, preventing floating-point errors from pushing the 10% limit to 10.0001%.

    Illustrative pseudocode:

    1. onTurnStart(self):
    2. if not self.has(Status.RASHOMON):
    3. self.add(Status.RASHOMON, 1)
    4. onDamageDealt(self, dmg):
    5. self.add(Status.RASHOMON, dmg) # one stack per damage point
    6. damageBonus(self):
    7. steps = floor(self.stack(Status.RASHOMON) / 33)
    8. return min(steps * 0.01, 0.10) # hard cap

    3. Settlement Order: Confusion and the “Indestructible Coin” Boundary

    The sample includes another key constraint: when the unit is confused, unable to act, panicked, or eroded, all turn-start judgments—blessing accumulation, random target selection, and skill-marking—stop taking effect. This means the passive must be hooked after the actionability check rather than executed unconditionally.

    Another design is “coin conversion”: when a friendly unit of a specific faction is present, all coins of a certain basic skill become indestructible. In engineering terms, this should not be implemented by “modifying skill data.” Instead, a check should run during hit resolution: if a coin is marked indestructible, skip all “reduce/negate/reflect” branches. This avoids polluting the skill configuration table and makes it easier to reconstruct the real settlement path when replaying battle logs.

    4. Faction Linkage and the Guard Defense Decision Loop

    The sample defines two faction linkages: one leans offensive (damage increase, stack application, detonation triggering), and one leans defensive (marking enemy targets, gaining guard stacks, and switching to self-damage when an ally is attacked unilaterally). The correctness of the defensive chain depends on three prerequisites, all of which are required:

    1. The target must be a marked enemy unit; if unmarked, the trigger is not allowed.
    2. Friendly units already equipped with guard-type skills do not participate in this check.
    3. Guard stacks must be merged with normal guard stacks and cleared together at turn end.

    The recommended implementation uses “event priority + idempotent markers” to ensure that multiple triggers within the same frame settle only once:

    1. onAllyTargeted(ally, attacker):
    2. if not self.canAct(): return
    3. if ally.has(Status.GUARD): return
    4. if not attacker.isMarked(): return
    5. if self.consume(Stack.SPECIAL_GUARD):
    6. attacker.retarget(self)
    7. self.useGuardSkill()

    5. Observability and Tuning: Validating Numeric Assumptions in the Cloud

    The risk of growth-type passives concentrates in long battles: the higher the stacks, the steeper the damage curve. It is recommended to deploy a stateless battle stress-test cluster on a container platform, store battle logs in object storage, and use logging and monitoring alerts to track three metrics: average turn count, bonus cap-hit rate, and guard trigger count. General capabilities such as container platforms, object storage, and monitoring alerts from Baidu AI Cloud can support the elastic scaling and result archiving required for this kind of batch regression task, making it easier to locate numeric anomalies quickly during version iterations.

    6. Conclusion

    The design of a growth-type passive is essentially a “resource-threshold-linkage” state machine. As long as four things are clearly defined—accumulation timing, cap truncation, actionability pre-checks, and faction-check priority—and are paired with replayable logs and cloud-based stress testing, you can avoid numeric runaway while keeping combat readable.