Traits Reference

All traits are imported from @sharpee/world-model. Traits are pure data structures — logic lives in the associated behavior class.

import { RoomTrait, ContainerTrait, OpenableTrait } from '@sharpee/world-model';
import { ContainerBehavior, OpenableBehavior } from '@sharpee/world-model';
const chest = world.createEntity('chest', 'object');
chest.addTrait(new ContainerTrait({ capacity: { maxItems: 10 } }));
chest.addTrait(new OpenableTrait({ isOpen: false }));
// Behaviors provide the logic
OpenableBehavior.open(chest); // → IOpenResult
OpenableBehavior.isOpen(chest); // → true

Core

IdentityTrait

Type: 'identity' — Provides naming, description, and localization support.

PropertyTypeDefaultDescription
namestringDisplay name
descriptionstringFull description
nameIdstringLocalization message ID for name
descriptionIdstringLocalization message ID for description
aliasesstring[][]Alternative names the parser recognizes
briefstringShort description for inventory/lists
properNamebooleanfalseIf true, no article used (“Bob” vs “the chest”)
articlestring'a'Article to use (“a”, “an”, “the”, “some”)
concealedbooleanfalseHidden from room descriptions
adjectivesstring[][]Adjectives the parser recognizes
grammaticalNumber'singular' | 'plural''singular'For verb conjugation

Behavior — IdentityBehavior:

MethodReturnsDescription
getPossessiveName(entity)stringPossessive form of name
isConcealed(entity)booleanWhether entity is hidden
getWeight(entity)numberEntity weight
getVolume(entity)numberEntity volume
getSize(entity)stringSize category
getTotalWeight(entity, getContents?)numberWeight including contents

ActorTrait

Type: 'actor' — Marks entities that can act in the world (players, NPCs).

PropertyTypeDefaultDescription
isPlayerbooleanfalseWhether this is the player character
isPlayablebooleanfalseWhether the player can switch to this actor
statestringCurrent actor state
pronounsPronounSet | PronounSet[]Pronoun sets for this actor
capacity{ maxItems?, maxWeight?, maxVolume? }Inventory capacity limits
isTransparentbooleanfalseWhether contents are visible

Behavior — ActorBehavior:

MethodReturnsDescription
isPlayer(entity)booleanCheck if player character
isPlayable(entity)booleanCheck if switchable
getPronouns(entity)PronounSetGet pronoun set
canCarry(actor, item, world)booleanCheck inventory capacity
canTakeItem(actor, item, world)booleanFull take validation
takeItem(actor, item, world)ITakeItemResultMove item to inventory
dropItem(actor, item, world)IDropItemResultMove item to location
isHolding(actor, itemId, world)booleanCheck if holding item
getCarriedWeight(actor, world)numberTotal carried weight
getRemainingCapacity(actor, world)objectRemaining weight/volume/items
getState(entity)stringGet actor state
setState(entity, state)voidSet actor state
findPlayer(entities)IFEntityFind player in entity list

RoomTrait

Type: 'room' — Marks entity as a location. Rooms are inherently containers.

PropertyTypeDefaultDescription
visitedbooleanfalseWhether the player has been here
exitsRecord<DirectionType, IExitInfo>{}Available exits by direction
blockedExitsRecord<DirectionType, string>{}Blocked exits with message IDs
isDarkbooleanfalseRequires light source to see
isOutdoorsbooleanfalseOutdoor location
isUndergroundbooleanfalseUnderground location
initialDescriptionstringFirst-visit description
initialDescriptionIdstringLocalization ID for first-visit description
regionstringRegion grouping
tagsstring[][]Arbitrary tags

Behavior — RoomBehavior:

MethodReturnsDescription
getExit(room, direction)IExitInfo | nullGet exit in direction
isExitBlocked(room, direction)booleanCheck if exit is blocked
getBlockedMessage(room, direction)stringGet blocked exit message
removeExit(room, direction)voidRemove an exit
getAllExits(room)Map<DirectionType, IExitInfo>All exits
getAvailableExits(room)Map<DirectionType, IExitInfo>Unblocked exits only
isOutdoors(room)booleanCheck outdoor flag
isUnderground(room)booleanCheck underground flag
addTag(room, tag)voidAdd a tag
removeTag(room, tag)voidRemove a tag

ContainerTrait

Type: 'container' — Allows entities to hold other entities inside.

PropertyTypeDefaultDescription
capacity{ maxWeight?, maxVolume?, maxItems? }Size limits
isTransparentbooleanfalseContents visible when closed
enterablebooleanfalseWhether actors can enter
allowedTypesstring[][]Only these types allowed (empty = all)
excludedTypesstring[][]These types blocked

Behavior — ContainerBehavior:

MethodReturnsDescription
addItem(container, item, world)IAddItemResultAdd item to container
removeItem(container, item, world)IRemoveItemResultRemove item from container
checkCapacity(container, item, world)booleanCheck if item fits
getTotalWeight(container, world)numberWeight of contents
getTotalVolume(container, world)numberVolume of contents
getRemainingCapacity(container, world)objectRemaining capacity
isTransparent(container)booleanCheck transparency
isEnterable(container)booleanCheck enterability
getAllowedTypes(container)string[]Get allowed types
getExcludedTypes(container)string[]Get excluded types

SupporterTrait

Type: 'supporter' — Allows entities to have items placed on top.

PropertyTypeDefaultDescription
capacity{ maxWeight?, maxItems? }Size limits
enterablebooleanfalseWhether actors can get on
allowedTypesstring[][]Only these types allowed
excludedTypesstring[][]These types blocked

Behavior — SupporterBehavior:

MethodReturnsDescription
addItem(supporter, item, world)IAddItemToSupporterResultPlace item on supporter
removeItem(supporter, item, world)IRemoveItemFromSupporterResultRemove item from supporter
canAccept(supporter, item, world)booleanCheck if item allowed
checkCapacity(supporter, item, world)booleanCheck if item fits
getTotalWeight(supporter, world)numberWeight of items on top
getRemainingCapacity(supporter, world)objectRemaining capacity
isEnterable(supporter)booleanCheck enterability

SceneryTrait

Type: 'scenery' — Marks items as fixed in place (not takeable).

PropertyTypeDefaultDescription
cantTakeMessagestringMessage ID when player tries to take
mentionedbooleanfalseAlready mentioned in room description
visiblebooleantrueWhether visible in room

Behavior — SceneryBehavior:

MethodReturnsDescription
getUntakeableReason(entity)stringReason entity can’t be taken
getCantTakeMessage(entity)stringCustom can’t-take message
isMentioned(entity)booleanAlready mentioned in description

Interactive

OpenableTrait

Type: 'openable' — Objects that can be opened and closed (doors, containers, books).

PropertyTypeDefaultDescription
isOpenbooleanfalseCurrent state
startsOpenbooleanfalseInitial state
canClosebooleantrueWhether closing is allowed
revealsContentsbooleantrueShow contents when opened
openMessagestringCustom open message ID
closeMessagestringCustom close message ID

Behavior — OpenableBehavior:

MethodReturnsDescription
canOpen(entity)booleanCheck if can be opened
canClose(entity)booleanCheck if can be closed
open(entity)IOpenResultOpen the entity
close(entity)ICloseResultClose the entity
toggle(entity)IOpenResult | ICloseResultToggle open/closed
isOpen(entity)booleanCheck current state
revealsContents(entity)booleanCheck if contents shown

LockableTrait

Type: 'lockable' — Entities that can be locked/unlocked. Usually paired with OpenableTrait.

PropertyTypeDefaultDescription
isLockedbooleanfalseCurrent state
startsLockedbooleanfalseInitial state
keyIdEntityIdRequired key entity
keyIdsEntityId[][]Multiple accepted keys
acceptsMasterKeybooleanfalseWhether a master key works
autoLockbooleanfalseRe-locks automatically

Behavior — LockableBehavior:

MethodReturnsDescription
lock(entity, keyEntity?)ILockResultLock the entity
unlock(entity, keyEntity?)IUnlockResultUnlock the entity
isLocked(entity)booleanCheck locked state
getLockedMessage(entity)stringGet locked message

SwitchableTrait

Type: 'switchable' — Objects that can be turned on and off.

PropertyTypeDefaultDescription
isOnbooleanfalseCurrent state
startsOnbooleanfalseInitial state
requiresPowerbooleanfalseNeeds external power
hasPowerbooleantrueCurrently has power
autoOffTimenumberTurns until auto-off

Behavior — SwitchableBehavior:

MethodReturnsDescription
canSwitchOn(entity)booleanCheck if can turn on
canSwitchOff(entity)booleanCheck if can turn off
switchOn(entity)ISwitchOnResultTurn on
switchOff(entity)ISwitchOffResultTurn off
toggle(entity)ISwitchOnResult | ISwitchOffResultToggle on/off
setPower(entity, hasPower)ISemanticEvent[]Set power state
updateTurn(entity)ISemanticEvent[]Tick auto-off timer
isOn(entity)booleanCheck current state
getTimeRemaining(entity)numberTurns until auto-off
getPowerConsumption(entity)numberPower usage

ReadableTrait

Type: 'readable' — Entities with text to read (books, signs, notes).

PropertyTypeDefaultDescription
textstringThe readable text
previewstringBrief preview text
isReadablebooleantrueWhether currently readable
hasBeenReadbooleanfalseTracks if read
pagesnumberNumber of pages
currentPagenumberCurrent page
pageContentstring[][]Content per page

Behavior — ReadableBehavior:

MethodReturnsDescription
getText(entity)stringGet full text
getPreview(entity)stringGet preview text
read(reader, readable)ISemanticEvent[]Read the entity (emits events)

LightSourceTrait

Type: 'lightSource' — Allows entities to provide illumination.

PropertyTypeDefaultDescription
brightnessnumberLight level
isLitbooleanfalseCurrently providing light
fuelRemainingnumberTurns of fuel left
maxFuelnumberMaximum fuel capacity
fuelConsumptionRatenumberFuel used per turn

Behavior — LightSourceBehavior:

MethodReturnsDescription
light(source)booleanLight the source
extinguish(source)voidExtinguish the source
isLit(source)booleanCheck if lit
getBrightness(source)numberGet brightness level
getFuelRemaining(source)numberGet remaining fuel
consumeFuel(source, amount?)booleanConsume fuel (returns false if empty)
getFuelPercentage(source)numberFuel remaining as percentage

PushableTrait

Type: 'pushable' — Objects that can be pushed. No dedicated behavior — handled by the pushing stdlib action.

PropertyTypeDefaultDescription
pushType'button' | 'heavy' | 'moveable'Type of push interaction
state'default' | 'pushed' | 'activated''default'Current state
repeatablebooleantrueCan be pushed again
requiresStrengthnumberMinimum strength needed
activatesstringEntity ID activated by push

PullableTrait

Type: 'pullable' — Objects that can be pulled. No dedicated behavior — handled by the pulling stdlib action.

PropertyTypeDefaultDescription
pullType'lever' | 'cord' | 'attached' | 'heavy'Type of pull interaction
state'default' | 'pulled' | 'activated''default'Current state
repeatablebooleantrueCan be pulled again
requiresStrengthnumberMinimum strength needed
activatesstringEntity ID activated by pull

ButtonTrait

Type: 'button' — Button-specific properties. Should also have PushableTrait. No dedicated behavior.

PropertyTypeDefaultDescription
latchingbooleanfalseStays pressed
colorstringButton color
labelstringButton label text
pressedbooleanfalseCurrently pressed

ClimbableTrait

Type: 'climbable' — Objects that can be climbed (ladders, trees, walls).

PropertyTypeDefaultDescription
canClimbbooleantrueWhether climbing is allowed
direction'up' | 'down' | 'both''up'Allowed climb direction
destinationstringRoom ID reached by climbing
blockedMessagestringMessage when climb is blocked

Behavior — ClimbableBehavior:

MethodReturnsDescription
isClimbable(entity)booleanCheck if can be climbed
climb(entity)IClimbResultPerform climb
getDirection(entity)stringGet allowed direction
getDestination(entity)stringGet destination room ID

AttachedTrait

Type: 'attached' — Objects fastened to something. No dedicated behavior.

PropertyTypeDefaultDescription
attachedTostringEntity ID this is attached to
attachmentType'glued' | 'nailed' | 'screwed' | 'tied' | 'welded' | 'magnetic' | 'stuck'How it’s attached
detachablebooleanfalseCan be detached
loosebooleanfalseNearly detached

MoveableSceneryTrait

Type: 'moveableScenery' — Large pushable/pullable objects. Should also have PushableTrait/PullableTrait. No dedicated behavior.

PropertyTypeDefaultDescription
weightClass'light' | 'medium' | 'heavy' | 'immense'How hard to move
revealsWhenMovedbooleanfalseReveals something underneath
revealsstringEntity ID revealed
movedbooleanfalseHas been moved
blocksExitsbooleanfalseBlocks room exits
blockedExitsstring[][]Which exits are blocked

Spatial

DoorTrait

Type: 'door' — Marks connection between two rooms.

PropertyTypeDefaultDescription
room1stringFirst connected room entity ID
room2stringSecond connected room entity ID
bidirectionalbooleantrueAccessible from both sides

Behavior — DoorBehavior:

MethodReturnsDescription
getRooms(door)[string, string]Get both room IDs
getOtherRoom(door, currentRoom)stringGet room on other side
isBidirectional(door)booleanCheck bidirectionality
getEntryRoom(door)stringGet room1
getExitRoom(door)stringGet room2

ExitTrait

Type: 'exit' — Represents passages between locations.

PropertyTypeDefaultDescription
fromstringSource room entity ID
tostringDestination room entity ID
directionstringDirection from source
visiblebooleantrueListed in room description
bidirectionalbooleantrueHas a return path
conditionalbooleanfalseRequires condition to use
conditionIdstringCondition identifier
blockedMessagestringMessage when blocked

Behavior — ExitBehavior:

MethodReturnsDescription
getBlockedReason(exit)stringGet blocked message
getExitsFrom(locationId, world)IFEntity[]All exits from a location
getVisibleExitsFrom(locationId, world)IFEntity[]Only visible exits
getListedExitsFrom(locationId, world)IFEntity[]Only listed exits
getReverseDirection(direction)stringOpposite direction
getReverseCommand(command)stringReverse command string

EnterableTrait

Type: 'enterable' — Objects that can be entered by actors. No dedicated behavior.

PropertyTypeDefaultDescription
preposition'in' | 'on''in'”get in X” vs “get on X”

VehicleTrait

Type: 'vehicle' — Enterable containers that transport actors.

PropertyTypeDefaultDescription
vehicleTypeVehicleTypeType of vehicle
movesWithContentsbooleantrueContents travel along
blocksWalkingMovementbooleanfalseMust exit before walking
isOperationalbooleantrueCurrently working
notOperationalReasonstringWhy it’s broken

Behavior — standalone functions:

FunctionReturnsDescription
isVehicle(entity)booleanCheck if entity is a vehicle
isActorInVehicle(world, actorId)booleanCheck if actor is in any vehicle
getActorVehicle(world, actorId)IFEntityGet actor’s current vehicle
getVehicleOccupants(world, vehicleId)IFEntity[]Get all occupants
moveVehicle(...)Move vehicle and contents
canVehicleMove(vehicle){ canMove, reason? }Check if vehicle can move
canActorLeaveLocation(...)Check if actor can leave via walking
canActorWalkInVehicle(...)Check if walking is blocked

Items

WearableTrait

Type: 'wearable' — Base trait for all wearable items.

PropertyTypeDefaultDescription
wornbooleanfalseCurrently being worn
wornBystringEntity ID of wearer
slotstringBody slot (e.g., “head”, “hands”)
layernumber0Layer order (higher = outer)
canRemovebooleantrueWhether it can be taken off

Behavior — WearableBehavior:

MethodReturnsDescription
canWear(item, actor)booleanCheck if item can be worn
canRemove(item, actor)booleanCheck if item can be removed
wear(item, actor)IWearResultPut on item
remove(item, actor)IRemoveResultTake off item
isWorn(item)booleanCheck if currently worn
getWearer(item)stringGet wearer entity ID
getSlot(item)stringGet body slot
getLayer(item)numberGet layer number
getBlockedSlots(item)string[]Get slots this blocks

ClothingTrait

Type: 'clothing' — Specialized wearable for clothing with condition tracking. Extends WearableTrait properties. Uses WearableBehavior.

PropertyTypeDefaultDescription
condition'pristine' | 'good' | 'worn' | 'torn' | 'ruined''good'Current condition
materialstringFabric/material type
stylestringClothing style
damageablebooleanfalseCan be damaged

EdibleTrait

Type: 'edible' — Objects that can be eaten or drunk.

PropertyTypeDefaultDescription
nutritionnumberNutrition value
servingsnumber1Number of servings
liquidbooleanfalseIs a liquid (drink vs eat)
consumeMessagestringCustom consumption message ID
effectsstring[][]Effect IDs applied on consumption

Behavior — EdibleBehavior:

MethodReturnsDescription
canConsume(item)booleanCheck if consumable (has servings)
consume(item, actor)ISemanticEvent[]Consume a serving
isEmpty(item)booleanCheck if all servings used
isLiquid(item)booleanCheck if liquid
getNutrition(item)numberGet nutrition value
getServings(item)numberGet remaining servings
getTaste(item)TasteQualityGet taste quality
getEffects(item)string[]Get effect IDs
hasEffect(item)booleanCheck if has effects
satisfiesHunger(item)booleanCheck hunger satisfaction

WeaponTrait

Type: 'weapon' — Objects that can be used to attack.

PropertyTypeDefaultDescription
damagenumberBase damage
minDamagenumberMinimum damage roll
maxDamagenumberMaximum damage roll
skillBonusnumber0Bonus to hit
weaponTypestringWeapon category
twoHandedbooleanfalseRequires both hands
breakablebooleanfalseCan break from use
durabilitynumberCurrent durability

Behavior — WeaponBehavior:

MethodReturnsDescription
calculateDamage(weapon)IWeaponDamageResultRoll damage
canDamage(weapon, targetType?)booleanCheck if weapon works on target
getWeaponType(weapon)stringGet weapon type
isTwoHanded(weapon)booleanCheck two-handed
repair(weapon)booleanRepair weapon
isBroken(weapon)booleanCheck if broken

EquippedTrait

Type: 'equipped' — Indicates item is currently equipped by an actor. No dedicated behavior.

PropertyTypeDefaultDescription
slot'weapon' | 'armor' | 'shield' | 'helmet' | 'boots' | 'gloves' | 'ring' | 'amulet' | 'accessory'Equipment slot
isEquippedbooleanfalseCurrently equipped
modifiers{ attack?, defense?, health?, speed? }Stat modifiers when equipped

Combat

CombatantTrait

Type: 'combatant' — Entities that can engage in combat.

PropertyTypeDefaultDescription
healthnumberCurrent health
maxHealthnumberMaximum health
skillnumberCombat skill level
baseDamagenumberUnarmed damage
isAlivebooleantrueCurrently alive
isConsciousbooleantrueCurrently conscious
hostilebooleanfalseAttacks on sight
armornumber0Damage reduction
canRetaliatebooleantrueFights back when attacked
dropsInventorybooleantrueDrops items on death

Behavior — CombatBehavior:

MethodReturnsDescription
canAttack(entity)booleanCheck if can attack
attack(entity, damage, world)ICombatResultApply damage to entity
heal(entity, amount)numberHeal entity, returns new health
resurrect(entity)booleanBring back to life
isAlive(entity)booleanCheck if alive
getHealth(entity)numberGet current health
getHealthPercentage(entity)numberHealth as percentage
isHostile(entity)booleanCheck hostility
setHostile(entity, hostile)voidSet hostility

BreakableTrait

Type: 'breakable' — Objects that can be broken with a single hit.

PropertyTypeDefaultDescription
brokenbooleanfalseCurrently broken

Behavior — BreakableBehavior:

MethodReturnsDescription
break(entity, world)IBreakResultBreak the entity
isBroken(entity)booleanCheck if broken

DestructibleTrait

Type: 'destructible' — Objects requiring multiple hits or specific tools to destroy.

PropertyTypeDefaultDescription
hitPointsnumberCurrent HP
maxHitPointsnumberMaximum HP
requiresWeaponbooleanfalseNeeds a weapon to damage
requiresTypestringSpecific weapon type needed
invulnerablebooleanfalseCannot be damaged
transformTostringBecomes this entity when destroyed
revealExitstringExit revealed when destroyed

Behavior — DestructibleBehavior:

MethodReturnsDescription
canDamage(entity, weaponType?)booleanCheck if can be damaged
damage(entity, damage, weaponType, world)IDamageResultApply damage
isDestroyed(entity)booleanCheck if HP reached zero
getHitPoints(entity)numberGet current HP
repair(entity)booleanRestore to max HP

NPC

NpcTrait

Type: 'npc' — Marks entity as an autonomous NPC with turn cycle participation. NPC behavior is handled by the plugin-npc package via registered behavior plugins, not a world-model behavior class.

PropertyTypeDefaultDescription
isAlivebooleantrueCurrently alive
isConsciousbooleantrueCurrently conscious
isHostilebooleanfalseHostile to player
canMovebooleantrueCan move between rooms
allowedRoomsEntityId[][]Rooms the NPC can visit
forbiddenRoomsEntityId[][]Rooms the NPC cannot enter
behaviorIdstringRegistered behavior plugin ID
conversationStatestringCurrent dialogue state
knowledgeRecord<string, unknown>{}NPC knowledge store
goalsstring[][]Current NPC goals