NPC Configuration - UQcsse3200/2024-studio-1 GitHub Wiki

Overview

This page outlines the structure and configuration of NPC entities within the game, including their tasks, animations, and attack components. NPC configurations are stored in JSON format and loaded into the game via the NPCConfigs class. Each NPC is defined by its name and a set of attributes such as health, strength, tasks, attacks, and animations.

NPCConfigs.java

The NPCConfigs class loads all NPC configurations from the NPCs.json file and maps each NPC's string name to its corresponding configuration. This allows the game to dynamically create NPCs using these configurations.

NPCConfig

The NPCConfig class defines the structure of an NPC's configuration. Each NPC configuration includes the following properties:

  • name: The name of the NPC - does not need to be specified in JSON file.
  • health: The NPC's max health.
  • baseAttack: The NPC's base attack damage.
  • strength: The NPC's strength level.
  • isBoss: A boolean indicating if the NPC is a boss. Is false if not specified in the JSON file.
  • isDirectional: A boolean indicating if the NPC uses directional movement.
  • isScaled: A boolean indicating if the NPC is scaled to a different size on creation.
  • scale: A list containing floats for scaling x and y.
  • variableDensity: A boolean indicating if the NPC has variable density.
  • density: A float value representing the NPC's density (only used if variableDensity is true).
  • tasks: A set of task configurations for the NPC, detailing the actions the NPC can perform (e.g., wander, chase, charge).
  • attacks: A set of attack configurations, defining the types of attacks the NPC can use (e.g., melee, ranged, AOE).
  • animations: An array of animations, defining the visual representation of the NPC's actions (e.g., idle, walk, attack).

AnimationData

Each NPC can have multiple animations, which are defined by the AnimationData class. Each animation includes:

  • name: The name of the animation.
  • frameDuration: The duration of each frame in the animation.
  • playMode: The play mode of the animation (e.g., LOOP, NORMAL).

TaskConfig.java

The TaskConfig class defines the set of tasks that an NPC can perform. Tasks represent the behaviours and actions an NPC can execute, such as wandering, chasing, or attacking. Each task has its own configuration structure. If a task is not specified in the JSON file, it will not be added to the entity on creation.

Task Types and Configurations

  • WanderTaskConfig: Defines parameters for wandering behaviour, including wanderRadius, waitTime, and wanderSpeed.
  • StraightWanderTaskConfig: Defines the straight wandering parameter wanderSpeed.
  • FollowTaskConfig: Configures NPC following behavior, including followRadius, waitTime, followDistance, and followSpeed.
  • ChaseTaskConfig: Defines NPC chasing behavior, with attributes such as chaseSpeed, viewDistance, chaseDistance, and maxTime.
  • ChargeTaskConfig: Configures charging behavior, including activation ranges, speed, cooldown time, and distanceMultiplier.
  • JumpTaskConfig: Defines the NPC's jumping behavior, with parameters such as jumpDuration, cooldownTime, and activation ranges.
  • RunAwayTaskConfig: Configures running away behavior based on NPC health and distance from the player.
  • RangeAttackTaskConfig: Defines ranged attack parameters, such as attack range, number of attacks, and cooldown.
  • AOEAttackTaskConfig: Configures AOE (Area of Effect) attacks with parameters for preparation time, range, and cooldown.
  • BulletStormTaskConfig: Configures bullet storm attacks with a single parameter for duration.
  • SpreadRangeAttackTaskConfig: Configures spread range attacks with parameters for activation ranges, number of attacks, and cooldown.

Task Configurations:

  • wanderRadius: The area within which the NPC moves randomly.
  • waitTime: The duration the NPC pauses between actions.
  • wanderSpeed: The speed at which the NPC moves while wandering.
  • viewDistance: The distance at which the NPC can detect the player.
  • chaseDistance: The distance within which the NPC actively chases the player.
  • chaseSpeed: The speed at which the NPC moves while chasing.
  • maxTime: The maximum duration the NPC will chase before reverting to other behaviors.
  • activationRange: The range within which a specific task (like charge or attack) is triggered.
  • distanceMultiplier: Adjusts the distance covered during specific tasks like charging.
  • cooldown: The cooldown period before a NPC can perform the same task again.
  • preparationTime: Time taken to prepare for a task like AOE attacks.
  • jumpDuration: Duration of jump actions.
  • runSpeed: Speed during run-away behaviours.
  • stopDistance: The distance at which the NPC stops running away.
  • maxRunTime: Maximum duration the NPC can run away.
  • attackNum: Number of projectiles or attacks performed in ranged tasks.

AttackConfig.java

The AttackConfig class defines the attack capabilities of an NPC, including melee, ranged, and AOE attacks. Each attack has its own configuration structure. If an attack is not specified in the JSON file, it will not be added to the entity on creation.

Attack Types and Configurations

  • MeleeAttack: Configures melee attack properties such as range, rate, and possible effects (e.g., knockback, poison).
  • RangeAttack: Defines ranged attack parameters including range, rate, and attack type.
  • AOEAttack: Configures area of effect attacks with parameters such as range, rate, and effects.

EffectConfig

Each attack can optionally have one or more effects defined by the EffectConfig class. These effects include properties such as:

  • type: The type of effect (e.g., knockback, stun, poison).
  • force: The force of the effect (e.g., for knockback).
  • duration: The duration of the effect (e.g., for stun or poison).
  • damagePerSecond: The damage dealt per second (e.g., for poison effects).

Example Configuration (JSON)

Below is an example of how an NPC is configured in the JSON file:

{
  "bear": {
    "strength": 6,
    "health": 600,
    "baseAttack": 35,
    "isDirectional": true,
    "variableDensity": true,
    "density": 2,
    "isScaled": true,
    "scale": {
        "x": 1.5,
        "y": 1.5
    },
    "tasks": {
      "wander": {
        "wanderRadius": 3,
        "waitTime": 2,
        "wanderSpeed": 0.5
      },
      "chase": {
        "chaseSpeed": 1.5,
        "viewDistance": 5,
        "chaseDistance": 5.5
      },
      "charge": {
        "activationMinRange": 4,
        "activationMaxRange": 5,
        "distanceMultiplier": 1.2,
        "chaseSpeed": 4,
        "waitTime": 1.5,
        "cooldownTime": 5
      }
    },
    "attacks": {
      "melee": {
        "range": 1.7,
        "rate": 1,
        "effects": [
          {
            "type": "KNOCKBACK",
            "force": 3
          },
          {
            "type": "STUN",
            "duration": 1
          }
        ]
      }
    },
    "animations": [
      {"name": "idle_left", "frameDuration": 0.2, "playMode": "LOOP"},
      {"name": "idle_right", "frameDuration": 0.2, "playMode": "LOOP"},
      {"name": "walk_left", "frameDuration": 0.2, "playMode": "LOOP"},
      {"name": "walk_right", "frameDuration": 0.2, "playMode": "LOOP"},
      {"name": "run_left", "frameDuration": 0.1, "playMode": "LOOP"},
      {"name": "run_right", "frameDuration": 0.1, "playMode": "LOOP"},
      {"name": "attack_left", "frameDuration": 0.2, "playMode": "NORMAL"},
      {"name": "attack_right", "frameDuration": 0.2, "playMode": "NORMAL"},
      {"name": "death_left", "frameDuration": 0.2, "playMode": "NORMAL"},
      {"name": "death_right", "frameDuration": 0.2, "playMode": "NORMAL"}
    ]
  }
  ...
}

This configuration defines an NPC named "bear" with health, strength, attack, tasks, and animations, as well as density and scaling properties.

⬅ Back to Animal Overview