Skip to main content
Glama

calculate_aoe

Calculate area of effect for D&D 5e spells and abilities, supporting sphere, cone, line, cube, and cylinder shapes to determine combat impact.

Instructions

Calculate area of effect for D&D 5e spells/abilities (sphere, cone, line, cube, cylinder)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
encounterIdNo
shapeYes
originYes
lengthNo
widthNo
radiusNo
sideLengthNo
heightNo
directionNo
includeOriginNo
excludeIdsNo

Implementation Reference

  • Core handler function implementing calculate_aoe tool logic: computes affected grid tiles for D&D 5e AoE shapes (sphere, cone, line, cube, cylinder) and generates formatted ASCII output with parameters, tile count, and sample positions.
    export function calculateAoe(input: CalculateAoeInput): string {
      const content: string[] = [];
      const {
        encounterId,
        shape,
        origin,
        length,
        width = 5,
        radius,
        sideLength,
        height,
        direction,
        includeOrigin = false,
        excludeIds = [],
      } = input;
    
      // Calculate affected tiles based on shape
      let tiles: Position[] = [];
    
      switch (shape) {
        case 'sphere':
          tiles = calculateSphereTiles(origin, radius!, includeOrigin);
          break;
        case 'cone':
          tiles = calculateConeTiles(origin, length!, direction || { x: 1, y: 0 }, includeOrigin);
          break;
        case 'line':
          tiles = calculateLineTiles(origin, length!, width, direction || { x: 1, y: 0 });
          break;
        case 'cube':
          tiles = calculateCubeTiles(origin, sideLength!, direction, includeOrigin);
          break;
        case 'cylinder':
          tiles = calculateCylinderTiles(origin, radius!, height!, includeOrigin);
          break;
      }
    
      // Build header
      content.push(centerText(`${shape.toUpperCase()} AoE`, AOE_DISPLAY_WIDTH));
      content.push('');
      content.push(`Origin: (${origin.x}, ${origin.y}, ${origin.z ?? 0})`);
      content.push('');
      content.push(BOX.LIGHT.H.repeat(AOE_DISPLAY_WIDTH));
      content.push('');
    
      // Show shape parameters
      content.push(centerText('PARAMETERS', AOE_DISPLAY_WIDTH));
      content.push('');
      content.push(`Shape: ${shape}`);
    
      switch (shape) {
        case 'sphere':
          content.push(`Radius: ${radius} ft`);
          break;
        case 'cone':
          content.push(`Length: ${length} ft`);
          content.push(`Width at base: ${length} ft`);
          if (direction) {
            content.push(`Direction: (${direction.x}, ${direction.y})`);
          }
          break;
        case 'line':
          content.push(`Length: ${length} ft`);
          content.push(`Width: ${width} ft`);
          if (direction) {
            content.push(`Direction: (${direction.x}, ${direction.y})`);
          }
          break;
        case 'cube':
          content.push(`Side: ${sideLength} ft`);
          break;
        case 'cylinder':
          content.push(`Radius: ${radius} ft`);
          content.push(`Height: ${height} ft`);
          break;
      }
    
      content.push('');
      content.push(BOX.LIGHT.H.repeat(AOE_DISPLAY_WIDTH));
      content.push('');
    
      // Show tile count
      content.push(centerText('AFFECTED AREA', AOE_DISPLAY_WIDTH));
      content.push('');
      content.push(`Tiles affected: ${tiles.length} squares`);
      content.push(`Origin included: ${includeOrigin ? 'Yes' : 'No'}`);
    
      // If includeOrigin, show the origin position
      if (includeOrigin) {
        content.push(`Origin tile: (${origin.x}, ${origin.y}, ${origin.z ?? 0})`);
      }
    
      // Show sample tiles (first few)
      if (tiles.length > 0) {
        content.push('');
        const sampleSize = Math.min(5, tiles.length);
        content.push(`Sample tiles (first ${sampleSize}):`);
        for (let i = 0; i < sampleSize; i++) {
          const t = tiles[i];
          content.push(`  (${t.x}, ${t.y}, ${t.z ?? 0})`);
        }
        if (tiles.length > sampleSize) {
          content.push(`  ... and ${tiles.length - sampleSize} more`);
        }
      }
    
      // Find creatures in AoE if encounterId provided
      if (encounterId) {
        content.push('');
        content.push(BOX.LIGHT.H.repeat(AOE_DISPLAY_WIDTH));
        content.push('');
        content.push(centerText('CREATURES IN AoE', AOE_DISPLAY_WIDTH));
        content.push('');
    
        // This would check encounter participants
        // For now, show placeholder
        content.push('(Encounter integration pending)');
      }
    
      // Show excluded IDs if any
      if (excludeIds.length > 0) {
        content.push('');
        content.push(`Excluded: ${excludeIds.join(', ')}`);
      }
    
      return createBox('AREA OF EFFECT', content);
    }
  • Zod schema for validating calculate_aoe input parameters, including shape-specific refinements.
    export const calculateAoeSchema = z.object({
      encounterId: z.string().optional(),
      shape: AoeShapeSchema,
      origin: PositionSchema,
    
      // Shape-specific parameters
      length: z.number().optional(),    // Line, Cone
      width: z.number().default(5).optional(),  // Line
      radius: z.number().optional(),    // Sphere, Cylinder
      sideLength: z.number().optional(), // Cube
      height: z.number().optional(),    // Cylinder
    
      direction: DirectionSchema.optional(),
    
      // Options
      includeOrigin: z.boolean().default(false),
      excludeIds: z.array(z.string()).optional(),
    }).refine((data) => {
      // Validate required parameters based on shape
      switch (data.shape) {
        case 'sphere':
          return data.radius !== undefined;
        case 'cone':
          return data.length !== undefined;
        case 'line':
          return data.length !== undefined;
        case 'cube':
          return data.sideLength !== undefined;
        case 'cylinder':
          return data.radius !== undefined && data.height !== undefined;
        default:
          return true;
      }
    }, {
      message: 'Missing required parameters for shape',
    });
  • Tool registration in the central registry, including name, description, schema conversion, and wrapper handler with validation and error handling.
    calculate_aoe: {
      name: 'calculate_aoe',
      description: 'Calculate area of effect for D&D 5e spells/abilities (sphere, cone, line, cube, cylinder)',
      inputSchema: toJsonSchema(calculateAoeSchema),
      handler: async (args) => {
        try {
          const validated = calculateAoeSchema.parse(args);
          const result = calculateAoe(validated);
          return success(result);
        } catch (err) {
          if (err instanceof z.ZodError) {
            const messages = err.errors.map(e => `${e.path.join('.')}: ${e.message}`).join(', ');
            return error(`Validation failed: ${messages}`);
          }
          const message = err instanceof Error ? err.message : String(err);
          return error(message);
        }
      },
    },
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states what the tool does (calculate area of effect) but doesn't describe how it behaves: e.g., whether it modifies game state, requires specific permissions, has rate limits, returns data format, or handles errors. For a tool with 11 parameters and no annotations, this is a significant gap in transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded in a single, efficient sentence. It wastes no words, clearly stating the tool's purpose and scope without redundancy. Every part of the sentence earns its place by specifying the domain (D&D 5e), action (calculate area of effect), and applicable shapes.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity (11 parameters, nested objects, no output schema, and 0% schema description coverage), the description is incomplete. It doesn't explain the tool's behavior, parameter usage, or return values, leaving the agent with insufficient context to use it correctly. For a calculation tool with many parameters in a game system like D&D, more guidance is needed.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds no meaning beyond what the input schema provides. With 0% schema description coverage and 11 parameters (including complex nested objects like 'origin' and 'direction'), the description doesn't explain what parameters like 'encounterId', 'excludeIds', or 'includeOrigin' mean, how shapes map to parameters (e.g., 'radius' for sphere, 'length' for line), or provide any D&D-specific context. This fails to compensate for the low schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Calculate area of effect for D&D 5e spells/abilities' with specific shape types listed (sphere, cone, line, cube, cylinder). It distinguishes from siblings like 'measure_distance' or 'check_line_of_sight' by focusing on area calculation rather than distance or visibility. However, it doesn't explicitly differentiate from all siblings (e.g., 'synthesize_spell' might overlap in spell context).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing an active encounter), when not to use it, or how it relates to siblings like 'synthesize_spell' (which might handle spell effects) or 'measure_distance' (which might handle simpler measurements). Usage is implied only by the tool's name and description context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Mnehmos/ChatRPG'

If you have feedback or need assistance with the MCP directory API, please join our Discord server