Cycle

The Scriptorium

Smart Assembly code templates and tools for on-chain development in Eve Frontier.

Advanced Combat Systems
AdvancedChapter 1 of 320 min read

Combat System Architecture

Combat in Eve Frontier is driven by Smart Assemblies. Ships, weapons, and defensive systems all interact through on-chain systems. In this advanced tutorial, we'll build a combat system with damage calculation, resistance, and cooldowns.

Design Overview

A combat system needs:

  • Weapon Systems — define damage output per weapon type
  • Defense Systems — calculate damage reduction from resistances
  • Cooldown Management — prevent weapon spam
  • Hit Resolution — determine if an attack lands
  • solidity
    // Core combat tables
    export default mudConfig({
      tables: {
        WeaponConfig: {
          keySchema: { weaponId: "uint256" },
          valueSchema: {
            damageType: "uint8",      // 0=kinetic, 1=thermal, 2=em, 3=explosive
            baseDamage: "uint32",
            cooldownSeconds: "uint32",
            optimalRange: "uint32",
            falloffRange: "uint32",
          },
        },
        ShipDefenses: {
          keySchema: { shipId: "uint256" },
          valueSchema: {
            kineticResist: "uint16",   // 0-10000 (basis points, 100% = 10000)
            thermalResist: "uint16",
            emResist: "uint16",
            explosiveResist: "uint16",
            shieldHp: "uint32",
            armorHp: "uint32",
            hullHp: "uint32",
          },
        },
        WeaponCooldown: {
          keySchema: {
            shipId: "uint256",
            weaponSlot: "uint8",
          },
          valueSchema: {
            lastFiredAt: "uint256",
          },
        },
      },
    });

    Damage Types and Resistances

    Eve Frontier uses four damage types, mirroring the classic EVE Online system:

    TypeStrong AgainstWeak Against
    KineticArmorShields
    ThermalShieldsArmor
    EMShieldsHull
    ExplosiveArmorShields

    Resistances are stored in basis points (0-10000) where 10000 = 100% resistance:

    solidity
    function calculateDamageReduction(
      uint32 baseDamage,
      uint16 resistance
    ) internal pure returns (uint32) {
      // resistance is in basis points (100% = 10000)
      uint32 reduction = (baseDamage * resistance) / 10000;
      return baseDamage - reduction;
    }

    Architecture Pattern: Strategy

    We use the Strategy pattern for damage calculation. Each damage type can have its own formula:

    solidity
    interface IDamageCalculator {
      function calculate(
        uint32 baseDamage,
        uint32 range,
        uint32 optimalRange,
        uint32 falloffRange,
        uint16 resistance
      ) external pure returns (uint32 finalDamage);
    }

    This allows us to swap damage formulas without modifying the core combat system.

    In the next chapter, we'll implement the full damage resolution pipeline.

    Sign in to track your progress.