Files
Server/src/engine/documentation/Handler Specific Documentation/dbNPCHandler_Documentation.md
T

2.2 KiB

dbNPCHandler Documentation

Overview

This document describes the database relationships and interactions for the dbNPCHandler class. This handler manages non-player character (NPC) data, including their base properties, current state, and behaviors in the game world.

Handler Class

File: src/engine/db/handlers/dbNPCHandler.java Class: dbNPCHandler Extends: dbHandlerBase

Database Tables

Main NPC Table

  • Table Name: dyn_npc
  • Description: Stores current state information for NPCs, including location, health, and behavior flags
  • Columns:
    • UID (Primary Key)
    • npcBaseID
    • zoneUUID
    • x
    • y
    • z
    • health
    • isAlive
    • behavior
Table Name Description Relationship
static_npc_base Base properties of NPCs npcBaseID → static_npc_base.UID

Key Queries

Get NPC by UID

SELECT * FROM dyn_npc WHERE `UID` = ?

File: dbNPCHandler.java, Line ~25

Save NPC

INSERT INTO `dyn_npc` (`npcBaseID`, `zoneUUID`, `x`, `y`, `z`, `health`, `isAlive`, `behavior`) VALUES(?,?,?,?,?,?,?,?)

File: dbNPCHandler.java, Line ~40

Get NPCs by Zone

SELECT * FROM dyn_npc WHERE `zoneUUID` = ?

File: dbNPCHandler.java, Line ~55

Relationships

  1. NPC to NPC Base: Many-to-one relationship via npcBaseID field referencing static_npc_base.UID
  2. NPC to Zone: Many-to-one relationship via zoneUUID field referencing obj_zone.UID

Java Field to Database Column Mappings

Java Field Database Column Notes
UID dyn_npc.UID Unique identifier for the NPC
npcBaseID dyn_npc.npcBaseID UID of the base NPC definition
zoneUUID dyn_npc.zoneUUID Zone where the NPC is located
x dyn_npc.x X coordinate of NPC position
y dyn_npc.y Y coordinate of NPC position
z dyn_npc.z Z coordinate of NPC position
health dyn_npc.health Current health of the NPC
isAlive dyn_npc.isAlive Flag indicating if NPC is alive
behavior dyn_npc.behavior Behavior type or state of the NPC
other fields... Various columns Other properties related to NPC state