Designing and Implementing a Game Stat System and Combat Attribute Model

    A practical guide to building a configurable, extensible, and validatable combat attribute system for games. Starting from a fictional stat sheet, the article abstracts the requirements into a strongly typed attribute model with an entity–form–attribute hierarchy, then covers modifier stacking, value normalization and dynamic tiering, server authority, storage and consistency, observability and validation, common anti-patterns, and a four-step rollout. The core takeaway: model semantics explicitly, externalize parameters into configuration, and keep authoritative decisions on the server.

    1. Where It Starts: The Data-Modeling Needs Behind a Spec Sheet

    In a fictional creative setting, different weapons each carry a set of quantifiable metrics for their “human form”: beyond height and weight, there are punch force, kick force, armor or defense levels, information level, extensibility (or growth potential), and both normal-state top speed and shift-state top speed. On the surface this is just lore material, but from an engineering perspective it is really a role stat sheet requirement document: field dimensions are inconsistent, value shapes vary (single values, levels, ranges, missing data), a single entity carries multiple sets of form data, and the system must switch between “normal state” and “special ability activated.”

    Hardcoding such a table directly into business code leads to failure on three fronts:

    • Structural failure: punch force is a number, armor is a level, top speed is “value + unit,” and growth is a range. The field types conflict with each other.
    • Balance failure: the magnitude of values spans a huge range (from single-digit tons of force to five-digit tons of force). Without a unified normalization and tiering strategy, new characters can only be filled in by “feel.”
    • Validation failure: attributes are maintained by multiple parties such as designers and operations. If the server performs no authoritative validation, a modified client can immediately cause combat-power imbalance and economic-system risk.

    So this article does not discuss any specific work. Instead, it abstracts this kind of requirement into a general problem: how to design a configurable, extensible, and validatable multi-form combat attribute system.

    2. Requirement Abstraction: From “Weapon Data” to an “Attribute Dimension Matrix”

    Before technical design, classify the requirements. Group the fields from the original table into four dimensions by semantics:

    Dimension Meaning Value shape
    Base physique attributes Appearance/physical parameters like height and weight Value + unit
    Output attributes Punch force, kick force Value (possibly a range)
    Defense attributes Armor level, defense coefficient Level (ordinal)
    Special attributes Information level, extensibility, growth, top speed Mixed: level / value / range / optional

    Three key conclusions:

    1. Fields must be classified and typed, not unified into integers. Stuffing “punch force” and “armor level” into the same int field forces all subsequent validation, balancing, and display logic to interpret them through implicit conventions — a classic form of technical debt.
    2. “Level” is essentially an ordinal, not a continuous value. Linear interpolation between lv3 and lv4 should not feed a damage formula directly; it must be converted through a mapping table into a numeric range before entering calculations.
    3. Missing data and no-form states must be explicitly supported. The original table has multiple instances of “data missing (no human form)” and “no entity.” This is not abnormal data but a legitimate business state, and it needs first-class modeling rather than vague expression with 0 or null.

    3. Data Model Design: Layering + Typing + Form Collection

    A recommended approach is an “entity–form–attribute” three-layer model that explicitly expresses the trait “the same weapon owns multiple sets of human-form data.”

    3.1 Conceptual layering

    1. Entity (unit)
    2. ├─ forms: Form[] // all available forms of this entity
    3. │ ├─ formId: FormId // form identifier, e.g. normal / awakened / inherited
    4. │ ├─ stateRules: StateRule[] // switchable state rules such as normal / shift
    5. │ └─ attrs: AttrSet // attribute set for this form
    6. └─ meta: { presentable: bool } // whether a displayable form exists (false if missing)

    meta.presentable directly maps to legitimate default states like “no human form / no entity.” When a form is missing, the entire attribute set is empty, and the rendering layer shows a placeholder based on this rather than throwing an error.

    3.2 Attribute typing

    To avoid “one punch kills all types,” introduce strong-typed wrappers so each dimension carries its own semantics and validation rules:

    1. {
    2. "entityId": "sample-unit",
    3. "forms": [
    4. {
    5. "formId": "normal",
    6. "attrs": {
    7. "height": { "kind": "quantity", "value": 189, "unit": "cm" },
    8. "punch": { "kind": "force", "min": 10, "max": 199 },
    9. "kick": { "kind": "force", "min": 12, "max": 198 },
    10. "defense": { "kind": "level", "lv": 3 },
    11. "infoLevel": { "kind": "level", "lv": 0, "unbounded": false },
    12. "growth": { "kind": "level", "lv": 10 },
    13. "speed": { "kind": "quantity", "value": 178, "unit": "km/h" }
    14. }
    15. }
    16. ]
    17. }

    Design points:

    • The kind field acts as a discriminated union, so the server can route to different validators and calculation formulas.
    • The force type naturally supports ranges (min/max), solving cases like “punch force 10–199t” that float with state.
    • The level type supports an unbounded flag to express special semantics such as “no upper limit,” rather than stuffing in a magic number.
    • Units are consolidated under unit to avoid string concatenation everywhere that leads to mixing “1080000000 km/h” with “1.08e9 m/s.”

    3.3 Level-to-value mapping table

    Levels cannot participate in operations directly and need an explicit mapping (illustrative):

    1. {
    2. "defenseLevelTable": {
    3. "0": { "mitigation": 0.00 },
    4. "1": { "mitigation": 0.05 },
    5. "2": { "mitigation": 0.12 },
    6. "3": { "mitigation": 0.22 },
    7. "4": { "mitigation": 0.35 }
    8. }
    9. }

    This table lives in its own file with its own versioning, and serves as the single source of truth for all subsequent value balancing. Changing balance without touching code is the biggest engineering payoff of this design.

    4. Key Mechanism Design

    4.1 Multi-form switching and state stacking

    The same entity’s attributes differ enormously across forms (for example, normal top speed of 122 km/h versus 2500 km/h underwater). Such “conditional bonuses” should not be modeled by duplicating entity data; they should be modeled as modifier stacking:

    1. {
    2. "modifierId": "aqua-boost",
    3. "trigger": "in_water",
    4. "appliesTo": ["speed"],
    5. "op": "multiply",
    6. "factor": 20.4,
    7. "priority": 100
    8. }

    The runtime calculation order must be deterministic. A recommended fixed order is: base value → additive modifiers → multiplicative modifiers → clamp to upper/lower bounds → rounding. priority resolves conflicts among multiple modifiers and avoids the fragile convention of relying on declaration order.

    4.2 Value normalization and dynamic tiering

    The raw data spans a huge range of magnitudes. Using absolute values directly for matching, ranking, or recommendations distorts results. Two common engineering paths:

    1. Range bucketing: divide into tiers by magnitude, linearly map within each tier to [0,1], avoiding long tails that flatten the top.
    2. Logarithmic compression: score = log(1 + value), smoother for data spanning multiple orders of magnitude and suitable for leaderboards or match weights.

    Illustrative implementation:

    1. import math
    2. def normalize(value: float, cap: float) -> float:
    3. """Compress a cross-magnitude metric into 0~1; cap is a soft upper bound"""
    4. if value <= 0:
    5. return 0.0
    6. return min(1.0, math.log1p(value) / math.log1p(cap))
    7. def combat_score(attrs: dict, weights: dict) -> float:
    8. return sum(
    9. w * normalize(attrs[k], caps[k])
    10. for k, w in weights.items()
    11. )

    Normalization parameters (cap, weights) are likewise externalized into configuration; otherwise every balance tweak requires a release.

    4.3 Server authority and tamper resistance

    Attributes directly determine combat outcomes, so the principle must be “server calculates, client only displays“:

    • All result-affecting values come from the server config center; the client does not participate in adjudication.
    • Config delivery undergoes integrity checks (signature + version number), rejecting old versions or configs of unknown origin.
    • Changes to key attributes go through canary rollout and auditing, retaining before/after snapshots for tracing imbalance issues.
    • Combat settlement results are produced and persisted by the server; the client only performs presentation-layer interpolation.

    5. Performance, Storage, and Consistency

    • Hot updates: attribute tables are small and read extremely frequently, making them suitable for resident memory plus atomic switching driven by a version number (in read-heavy, write-light scenarios, double-buffer swapping is the most robust).
    • Caching strategy: cache parsed attribute objects and deserialize the raw JSON only once; on config updates, replace the whole thing to avoid intermediate states from per-entry invalidation.
    • Storage tiering: cold data (full settings, historical versions) goes to object storage; online reads use in-memory tables or key-value caches; change logs are written asynchronously to the database via a message queue to decouple reads and writes.
    • Consistency: a version switch must take effect atomically. Forbid “half the entities on the new table, half on the old,” or you get bizarre effects where the same entity’s different forms fight over attributes.

    6. Observability and Validation

    The complexity of a stat system usually lies not in writing it, but in understanding “why did this unit suddenly get stronger.” Three things are worth adding:

    1. Change audit: record the diff, operator, scope, and effective time window for each config release.
    2. Metric instrumentation: monitor and alert on attribute distributions, combat-power percentiles, form usage rates, and abnormal ranges (for example, maxed-out growth combined with max-level defense).
    3. Automated validation: during CI, run schema validation and business-invariant validation on configs, such as “a range field’s min must be ≤ max,” “a level field must fall within the mapping table’s key set,” and “the required-field sets must match across different forms of the same entity.”

    A minimal invariant-check illustration:

    1. def validate(cfg: dict, level_table: dict) -> list[str]:
    2. errors = []
    3. for form in cfg.get("forms", []):
    4. attrs = form.get("attrs", {})
    5. for key in ("punch", "kick"):
    6. f = attrs.get(key)
    7. if f and f["kind"] == "force" and f["min"] > f["max"]:
    8. errors.append(f"{form['formId']}.{key}: min > max")
    9. lv = attrs.get("defense", {}).get("lv")
    10. if lv is not None and str(lv) not in level_table:
    11. errors.append(f"{form['formId']}.defense: lv {lv} not in mapping table")
    12. return errors

    7. Common Anti-Patterns

    • Magic numbers everywhere: writing “no upper limit” as 999999, so every later comparison needs special-casing.
    • Mixed field semantics: level and value share one field, distinguished only by comments.
    • Hardcoded config: attributes written into logic, so any balance adjustment requires a code change and release.
    • Zero-value defaults: this makes “data missing” indistinguishable from “value is zero,” producing wrong prompts like “combat power 0” in the display layer.
    • Client participating in settlement: this opens a door for cheaters and makes it hard to trace the source of abnormal data.

    8. Rollout Path and Summary

    A four-step approach is recommended, with each step delivering value independently:

    1. Modeling phase: settle the entity–form–attribute three-layer structure and attribute typing, first expressing the three boundary cases — “missing form,” “no upper limit,” and “range values” — clearly in the model.
    2. Configuration phase: externalize all values and the level mapping table, establish version numbering and canary release, and achieve balance changes without releases.
    3. Calculation phase: implement modifier-stacking order and normalization scoring in a unified way, and converge all combat-related calculation onto the server.
    4. Governance phase: fill in schema validation, business-invariant validation, monitoring alerts, and change auditing to form a closed loop.

    The essence of this design is turning seemingly loose lore material into an engineering asset that is clearly typed, semantically complete, versionable, and validatable. Readers can reuse it directly in any scenario requiring “multi-form + multi-dimensional attributes + configurable balancing”: not just combat stats, but device capability profiles, risk-control subject scoring, resource spec tiering, and more. The core principle is one line: model semantics explicitly, externalize parameters into configuration, and keep adjudication on the server.