Skip to content
ToanLB
Go back

Weapon Base Damage is 100: Is It Config, Runtime Data, or Business Logic?

~12 min read
Weapon Base Damage is 100: Is It Config, Runtime Data, or Business Logic?

When prototyping an Action RPG or dungeon crawler, setting up a starting weapon with baseDamage = 100 looks like the most straightforward task in the project. We create a Weapon : MonoBehaviour or a WeaponConfigSO : ScriptableObject, assign 100 in the Inspector, and the player character swings their sword to deal damage.

However, as production scales up and game systems mature, that number 100 never remains in isolation:

At that point, the initial number 100 traverses multiple systems: ScriptableObject holds part of it, the inventory state holds another, the combat system applies math rules, and the UI displays floating combat text.

If the architectural boundaries between Config, Runtime Data, and Business Logic are blurred, technical debt quickly piles up: data gets embedded into logic, gameplay rules leak into config assets, and mutable runtime state corrupts shared project templates.


1. The Three Framing Questions

To establish clear architectural separation, we can categorize any value or mechanism using three guiding questions:

flowchart LR
    subgraph ThreeQuestions["Three Boundary Perspectives"]
        Q1["1. How is it designed?<br/>Config Layer"]
        Q2["2. What is its current state?<br/>Runtime Data Layer"]
        Q3["3. What rule governs the outcome?<br/>Business Logic Layer"]
    end

1. Config: “How is this entity designed?”

Config defines the foundational, immutable, and shared characteristics of an object archetype:

These values represent the blueprint. They define the sword as a catalog item, not the specific sword currently held in a player’s hands. Even if 10,000 active players equip this weapon model, they all reference this exact same blueprint. Config is owned and tuned by Game Designers, stored in ScriptableObject assets, JSON files, CSV tables, or remote configuration servers.

2. Runtime Data: “What is its current state?”

Runtime Data describes the volatile, transient condition of a specific instance at a given moment in a play session:

Two weapons sharing the same IronSword config can have entirely different runtime states: one freshly looted at level 1 with pristine condition, and another upgraded to level 20, socketed with fire gems, and close to breaking. Runtime Data belongs to player ownership, changes frame-by-frame, and is the only data slice that needs serialization into save files.

3. Business Logic: “What rule governs the outcome?”

Business Logic is not data. It represents the algorithmic rules and operational constraints that dictate how Config and Runtime Data interact to produce gameplay outcomes:


2. Clean Architecture Data Flow

When all three layers are decoupled, data flows through the combat pipeline in a clean, unidirectional sequence:

flowchart LR
    subgraph ConfigLayer["Config Layer (Immutable Blueprint)"]
        SO["Weapon Blueprint<br/>BaseDamage: 100<br/>Scaling: 8% per level<br/>MaxDurability: 100"]
    end

    subgraph RuntimeLayer["Runtime Data (Session State)"]
        RT["Player Weapon State<br/>CurrentLevel: 5<br/>CurrentDurability: 0 (Broken)<br/>ElementalBonus: +25 Fire"]
    end

    subgraph LogicLayer["Business Logic (Domain Rules)"]
        Calc["Damage Calculator<br/>1. Scale Base by Level<br/>2. Add Elemental Buff<br/>3. Apply Broken Penalty<br/>4. Deduct Target Armor"]
    end

    subgraph OutputResult["Calculation Output"]
        Out["Combat Calculation Result<br/>FinalDamage: 64<br/>IsBrokenPenalty: True"]
    end

    SO -->|"Inject base stats"| Calc
    RT -->|"Inject active state"| Calc
    Calc -->|"Produce output"| Out

In this pipeline:

  1. Config Layer provides static design constants.
  2. Runtime Layer provides player-owned state.
  3. Business Logic receives both as pure inputs, executes calculations, and outputs a result without mutating either input source.

3. Grey Areas and Nuances in Production

In real-world game development, boundaries occasionally intersect in subtle ways that require careful evaluation:

Are AnimationCurves and Growth Curves Config or Logic?

Using AnimationCurve to model stat progression across 100 levels is common in Unity:

Equipment Requirements

Armor Mitigation Formulas

The standard armor damage reduction formula: MitigatedDamage=RawDamage×100100+Armor\text{MitigatedDamage} = \text{RawDamage} \times \frac{100}{100 + \text{Armor}}


4. Common Architectural Anti-Patterns

When development teams lack alignment on these boundaries, projects frequently run into three structural pitfalls:

1. Business Logic Leaking into Config Assets

Adding calculation methods directly to ScriptableObject classes:

using UnityEngine;

public class PlayerCharacter : MonoBehaviour { public int Strength = 10; }
public class EnemyTarget : MonoBehaviour { public int Armor = 5; }

// Anti-Pattern: Config asset containing business logic and scene dependencies
public class FlawedWeaponConfigSO : ScriptableObject
{
    public int baseDamage = 100;

    public int CalculateDamage(PlayerCharacter player, EnemyTarget enemy)
    {
        // ScriptableObject couples directly to scene entities
        int finalDamage = baseDamage + (player.Strength * 2) - enemy.Armor;
        return Mathf.Max(1, finalDamage);
    }
}

Consequence: The config asset becomes tightly coupled to scene GameObjects. Running headless unit tests on this formula becomes impossible without mocking full Unity scene hierarchies.

2. Runtime State Mutating Config Assets

Modifying config assets to reflect player progression:

public class UpgradeServiceAntiPattern
{
    public void UpgradeWeapon(FlawedWeaponConfigSO weaponConfig)
    {
        // Anti-Pattern: Mutating shared asset state at runtime
        weaponConfig.baseDamage += 20; // Corrupts global template for all players!
    }
}

As covered previously, this mutates YAML assets on disk in the Editor, behaves inconsistently in standalone builds, and unintentionally buffs every weapon clone in the game.

3. Business Logic Scattered into UI Scripts

Duplicating formulas across presentation components:

using UnityEngine;

public class WeaponTooltipAntiPattern : MonoBehaviour
{
    [SerializeField] private FlawedWeaponConfigSO _weaponConfig;

    public string GetTooltipDamageText(int playerLevel)
    {
        // Anti-Pattern: UI component independently calculating gameplay logic
        int previewDamage = _weaponConfig.baseDamage + (playerLevel * 10);
        return $"Damage: {previewDamage}";
    }
}

When designers alter the balance formula in the combat system, UI scripts that duplicate this calculation become out of sync, producing regression bugs where UI values diverge from combat reality.


5. Production C# Implementation: Action RPG Damage Pipeline

To illustrate clean boundary enforcement, we implement a complete weapon damage calculation pipeline for an Action RPG.

This pipeline processes a sword with a base damage of 100, handles level scaling, elemental gem bonuses, durability degradation penalties, critical hit multipliers, and enemy armor mitigation with a minimum damage floor.

1. Config Layer (Immutable Blueprint)

We define the configuration contract using an interface, implemented by a ScriptableObject:

using UnityEngine;

// Immutable configuration contract for weapon blueprints
public interface IWeaponBlueprint
{
    string WeaponId { get; }
    int BaseDamage { get; }
    float LevelScalingFactor { get; }
    int MaxDurability { get; }
}

// ScriptableObject implementation stored in Assets/Data/Weapons
public class WeaponBlueprintSO : ScriptableObject, IWeaponBlueprint
{
    [SerializeField] private string _weaponId = "iron_sword";
    [SerializeField] private int _baseDamage = 100;
    [SerializeField] private float _levelScalingFactor = 0.08f; // +8% per level
    [SerializeField] private int _maxDurability = 100;

    public string WeaponId => _weaponId;
    public int BaseDamage => _baseDamage;
    public float LevelScalingFactor => _levelScalingFactor;
    public int MaxDurability => _maxDurability;
}

2. Runtime Data Layer (Session State)

Each weapon instance in player inventory is represented by a pure C# class. It has no Unity engine dependencies and serializes cleanly into JSON save files:

using System;

// Volatile runtime state representing a concrete inventory weapon instance
[Serializable]
public class WeaponRuntimeState
{
    public string InstanceGuid { get; set; }
    public string BlueprintId { get; set; }
    public int CurrentLevel { get; set; }
    public int CurrentDurability { get; set; }
    public int BonusElementalDamage { get; set; }

    public WeaponRuntimeState(string instanceGuid, string blueprintId, int initialDurability)
    {
        InstanceGuid = instanceGuid;
        BlueprintId = blueprintId;
        CurrentLevel = 1;
        CurrentDurability = initialDurability;
        BonusElementalDamage = 0;
    }
}

3. Business Logic Layer (Domain Rules)

Calculation logic is isolated inside a pure C# domain service. It has no scene references, operates purely on input parameters, and returns an immutable result struct:

using System;

// Immutable calculation result consumed by combat systems and UI
public readonly struct CombatDamageResult
{
    public readonly int FinalDamage;
    public readonly bool IsCritical;
    public readonly bool IsBrokenPenaltyApplied;

    public CombatDamageResult(int finalDamage, bool isCritical, bool isBrokenPenaltyApplied)
    {
        FinalDamage = finalDamage;
        IsCritical = isCritical;
        IsBrokenPenaltyApplied = isBrokenPenaltyApplied;
    }
}

// Target defensive context
public readonly struct CombatTargetContext
{
    public readonly int TargetArmor;
    public readonly bool ForceCritical;

    public CombatTargetContext(int targetArmor, bool forceCritical = false)
    {
        TargetArmor = targetArmor;
        ForceCritical = forceCritical;
    }
}

// Pure C# domain service executing combat calculation rules
public static class WeaponDamageCalculator
{
    private const float BrokenDurabilityPenalty = 0.5f; // 50% damage reduction when broken
    private const float CriticalMultiplier = 1.5f;      // 1.5x damage on critical hit
    private const int MinimumDamageFloor = 1;           // Minimum damage is always clamped to 1

    public static CombatDamageResult CalculateDamage(
        IWeaponBlueprint blueprint,
        WeaponRuntimeState state,
        CombatTargetContext context)
    {
        if (blueprint == null) throw new ArgumentNullException(nameof(blueprint));
        if (state == null) throw new ArgumentNullException(nameof(state));

        // 1. Scale base damage by level: Base * (1 + (Level - 1) * ScalingFactor)
        float levelMultiplier = 1f + ((state.CurrentLevel - 1) * blueprint.LevelScalingFactor);
        float scaledBaseDamage = blueprint.BaseDamage * levelMultiplier;

        // 2. Add flat elemental enchantment bonus
        float rawDamage = scaledBaseDamage + state.BonusElementalDamage;

        // 3. Check durability: apply penalty if weapon is broken
        bool isBroken = state.CurrentDurability <= 0;
        if (isBroken)
        {
            rawDamage *= BrokenDurabilityPenalty;
        }

        // 4. Apply critical hit multiplier
        bool isCritical = context.ForceCritical;
        if (isCritical)
        {
            rawDamage *= CriticalMultiplier;
        }

        // 5. Deduct target armor and clamp to minimum damage floor
        int damageAfterArmor = (int)Math.Round(rawDamage) - context.TargetArmor;
        int finalDamage = Math.Max(MinimumDamageFloor, damageAfterArmor);

        return new CombatDamageResult(finalDamage, isCritical, isBroken);
    }
}

4. Technical Verification via NUnit Unit Tests

Because all three layers are decoupled, we can verify our combat formulas with fast NUnit tests executing outside the Unity Editor:

using NUnit.Framework;

// Mock blueprint for isolated testing outside Unity Editor
public class MockWeaponBlueprint : IWeaponBlueprint
{
    public string WeaponId { get; set; } = "iron_sword";
    public int BaseDamage { get; set; } = 100;
    public float LevelScalingFactor { get; set; } = 0.08f;
    public int MaxDurability { get; set; } = 100;
}

[TestFixture]
public class WeaponDamageCalculatorTests
{
    private MockWeaponBlueprint _blueprint;
    private WeaponRuntimeState _state;

    [SetUp]
    public void SetUp()
    {
        _blueprint = new MockWeaponBlueprint();
        _state = new WeaponRuntimeState("item_guid_01", _blueprint.WeaponId, _blueprint.MaxDurability);
    }

    [Test]
    public void CalculateDamage_Level1WithDurability_DealsExpectedDamage()
    {
        // 100 base * 1.0 + 0 elemental = 100. Minus 20 armor = 80 damage
        var context = new CombatTargetContext(targetArmor: 20, forceCritical: false);

        CombatDamageResult result = WeaponDamageCalculator.CalculateDamage(_blueprint, _state, context);

        Assert.AreEqual(80, result.FinalDamage);
        Assert.IsFalse(result.IsCritical);
        Assert.IsFalse(result.IsBrokenPenaltyApplied);
    }

    [Test]
    public void CalculateDamage_Level5WithElementalBonus_ScalesCorrectly()
    {
        // Level 5: 100 * (1 + 4 * 0.08) = 132. Plus 25 fire gem = 157. Minus 15 armor = 142
        _state.CurrentLevel = 5;
        _state.BonusElementalDamage = 25;
        var context = new CombatTargetContext(targetArmor: 15, forceCritical: false);

        CombatDamageResult result = WeaponDamageCalculator.CalculateDamage(_blueprint, _state, context);

        Assert.AreEqual(142, result.FinalDamage);
        Assert.IsFalse(result.IsCritical);
    }

    [Test]
    public void CalculateDamage_ZeroDurability_AppliesFiftyPercentPenalty()
    {
        // Level 1: 100 damage. Durability 0 -> 50% penalty = 50. Minus 10 armor = 40
        _state.CurrentDurability = 0;
        var context = new CombatTargetContext(targetArmor: 10, forceCritical: false);

        CombatDamageResult result = WeaponDamageCalculator.CalculateDamage(_blueprint, _state, context);

        Assert.AreEqual(40, result.FinalDamage);
        Assert.IsTrue(result.IsBrokenPenaltyApplied);
    }

    [Test]
    public void CalculateDamage_CriticalHit_MultipliesCorrectly()
    {
        // Level 1: 100 damage. Critical (1.5x) = 150. Minus 30 armor = 120
        var context = new CombatTargetContext(targetArmor: 30, forceCritical: true);

        CombatDamageResult result = WeaponDamageCalculator.CalculateDamage(_blueprint, _state, context);

        Assert.AreEqual(120, result.FinalDamage);
        Assert.IsTrue(result.IsCritical);
    }

    [Test]
    public void CalculateDamage_ExtremelyHighArmor_ClampsToMinimumFloor()
    {
        // Level 1: 100 damage. Target armor is 999. Damage must be clamped to minimum floor = 1
        var context = new CombatTargetContext(targetArmor: 999, forceCritical: false);

        CombatDamageResult result = WeaponDamageCalculator.CalculateDamage(_blueprint, _state, context);

        Assert.AreEqual(1, result.FinalDamage);
    }
}

6. Layer Comparison and Trade-Offs

The following matrix summarizes the distinct responsibilities across all three architectural layers:

DimensionConfigRuntime DataBusiness Logic
Core NatureStatic archetype blueprintVolatile session stateOperational rules and formulas
LifecyclePersists globally across project lifetimePersists during active session or save slotStateless, active during application execution
Storage LocationScriptableObject, JSON, Google SheetPure C# Class, SQLite, JSON Save FileStatic Class, Domain Service, System
OwnershipGame Designer balances parametersPlayer session owns instance conditionGameplay Engineers implement and maintain rules
TestabilityData validation schemasSerialization and integrity testsFast headless unit testing
Failure ModeAsset corruption, Editor vs Build divergenceMemory leaks, bloated save filesFragmented logic, UI divergence bugs

7. Practical Decision Checklist

Whenever evaluating where a specific value belongs during gameplay feature development, run through this three-step checklist:

  1. Does this value apply identically to every instance of this archetype?
    • If Yes (Base damage, Max HP, Icon, Name) -> Place in Config.
  2. Does this value mutate based on player actions during gameplay?
    • If Yes (Current HP, Equipment Level, Position, Currency balance) -> Place in Runtime Data.
  3. Is this value the output of an algorithm, formula, or conditional constraint?
    • If Yes (Mitigated damage, drop rates modified by luck, skill unlock requirements) -> Place in Business Logic.

8. Summary

A weapon’s baseDamage = 100 is intrinsically Config.

It becomes Runtime Data when tied to an upgraded or damaged weapon instance inside a player’s inventory. And it flows through Business Logic when mathematical combat formulas translate it into real hit point reductions on target health bars.

Clean game architecture does not require complicated design patterns. It begins with fundamental clarity: knowing what each number in the project represents, who owns it, and where it belongs so the codebase remains stable, testable, and maintainable as the game expands.


Share this post:
Lương Bảo Toàn

Luong Bao Toan

I work in HMI Automotive and Game development, sharing knowledge, hands-on experience, and stories I find interesting throughout my journey.

Did this article bring you value?

If this article helped your work, or you simply enjoyed it and want to support me, you can

Buy me a coffee

Related Articles

Comments & Discussions

Powered by Giscus

Get New Posts via Email

Subscribe to stay updated and never miss new posts from me.

* No spam. You can unsubscribe at any time with a single click.