ScheduleSystem

Manages 24-hour schedules, activity points, occupancy reservations, danger interruptions, and multi-NPC routines.

Constructor

new ScheduleSystem(configopt)

Parameters:
NameTypeAttributesDefaultDescription
configObject<optional>
{}

System configuration.

Properties
NameTypeAttributesDefaultDescription
clockObject<optional>
null

Optional GameClock instance.

slotsArray<optional>
null

Initial slots for default single-NPC routine.

defaultActivitystring<optional>
"idle"

Default fallback activity.

initialHournumber | string<optional>
0

Initial game hour.

Classes

ScheduleSystem

Methods

addSlot(slot, npcIdopt) → {ScheduleSlot}

Adds a schedule slot to the default or specified NPC routine.

Parameters:
NameTypeAttributesDefaultDescription
slotObject | ScheduleSlot

Slot configuration.

npcIdstring<optional>
"default"

Target NPC identifier.

Returns:
Type: 
ScheduleSlot

advance(delta, unitopt) → {number}

Advances time by the given amount and updates all schedules.

Parameters:
NameTypeAttributesDefaultDescription
deltanumber

Amount of time to advance.

unitstring<optional>
"hours"

"hours" or "minutes".

Returns:

New current hour.

Type: 
number

clearMissedAppointments(npcIdopt)

Clears missed appointment history for an NPC.

Parameters:
NameTypeAttributesDefaultDescription
npcIdstring<optional>
"default"

NPC identifier.

emit(event, data)

Emits a system event to registered listeners.

Parameters:
NameTypeDescription
eventstring

Event name.

dataObject

Payload data.

getActivity(npcIdopt) → {string}

Gets the current activity of an NPC.

Parameters:
NameTypeAttributesDefaultDescription
npcIdstring<optional>
"default"

NPC identifier.

Returns:
Type: 
string

getCurrentDestination(npcIdopt) → {Object|string|null}

Gets the current destination point for an NPC.

Parameters:
NameTypeAttributesDefaultDescription
npcIdstring<optional>
"default"

NPC identifier.

Returns:
Type: 
Object | string | null

getCurrentSlot(npcIdopt) → {ScheduleSlot|null}

Gets the active schedule slot for an NPC.

Parameters:
NameTypeAttributesDefaultDescription
npcIdstring<optional>
"default"

NPC identifier.

Returns:
Type: 
ScheduleSlot | null

getMissedAppointments(npcIdopt) → {Array}

Gets missed appointments recorded for an NPC.

Parameters:
NameTypeAttributesDefaultDescription
npcIdstring<optional>
"default"

NPC identifier.

Returns:

List of missed appointment records.

Type: 
Array

getOccupant(point) → {string|null}

Gets the identifier of the NPC occupying a point.

Parameters:
NameTypeDescription
pointObject | string

Activity point.

Returns:

Occupant NPC identifier or null.

Type: 
string | null

getSchedule(npcIdopt) → {NPCSchedule|null}

Gets the schedule instance for an NPC.

Parameters:
NameTypeAttributesDefaultDescription
npcIdstring<optional>
"default"

NPC identifier.

Returns:
Type: 
NPCSchedule | null

isInDanger(npcIdopt) → {boolean}

Alias for isSuspended.

Parameters:
NameTypeAttributesDefaultDescription
npcIdstring<optional>
"default"

NPC identifier.

Returns:
Type: 
boolean

isPointOccupied(point, excludingNpcIdopt) → {boolean}

Checks if an activity point is currently occupied.

Parameters:
NameTypeAttributesDescription
pointObject | string

Activity point to check.

excludingNpcIdstring<optional>

Optional NPC identifier to ignore (e.g. self).

Returns:

True if occupied.

Type: 
boolean

isSuspended(npcIdopt) → {boolean}

Checks whether an NPC schedule is currently suspended by danger.

Parameters:
NameTypeAttributesDefaultDescription
npcIdstring<optional>
"default"

NPC identifier.

Returns:
Type: 
boolean

occupyPoint(point, npcId) → {boolean}

Claims an activity point for an NPC.

Parameters:
NameTypeDescription
pointObject | string

Activity point to claim.

npcIdstring

Claiming NPC identifier.

Returns:

True if successfully claimed.

Type: 
boolean

off(event, callback) → {ScheduleSystem}

Unsubscribes a listener from a system event.

Parameters:
NameTypeDescription
eventstring

Event name.

callbackfunction

Callback function.

Returns:

This instance.

Type: 
ScheduleSystem

on(event, callback) → {ScheduleSystem}

Subscribes a listener to a system event.

Parameters:
NameTypeDescription
eventstring

Event name.

callbackfunction

Callback function.

Returns:

This instance.

Type: 
ScheduleSystem

perceiveDanger(npcId, target, factionRegistry, dangerOverridesopt) → {boolean}

Evaluates a perceived target against a FactionRegistry and interrupts schedule if hostile.

Parameters:
NameTypeAttributesDefaultDescription
npcIdstring

Observing NPC identifier.

targetObject

Perceived target entity.

factionRegistryFactionRegistry

Faction registry to query.

dangerOverridesObject<optional>
{}

Optional danger settings.

Returns:

True if hostile danger reaction was triggered.

Type: 
boolean

registerNPC(npcId, config) → {NPCSchedule}

Registers an NPC routine with the schedule system.

Parameters:
NameTypeDescription
npcIdstring

Unique identifier for the NPC.

configObject | Array | NPCSchedule

Schedule configuration or slots array.

Returns:

Registered schedule.

Type: 
NPCSchedule

resolveDanger(npcIdopt, optionsopt) → {string}

Resolves danger reaction for an NPC, resuming normal schedule routine.

Parameters:
NameTypeAttributesDefaultDescription
npcIdstring<optional>
"default"

NPC identifier.

optionsObject<optional>
{}

Options passed to resolveDanger.

Returns:

Resumed activity.

Type: 
string

triggerDanger(npcIdOrDanger, maybeDangeropt) → {boolean}

Suspends an NPC's schedule with a danger reaction.

Parameters:
NameTypeAttributesDefaultDescription
npcIdOrDangerstring | Object

NPC identifier or danger data for default NPC.

maybeDangerObject<optional>
{}

Danger configuration if npcId was provided.

Returns:

True if danger was triggered.

Type: 
boolean

unregisterNPC(npcId) → {boolean}

Unregisters an NPC routine and frees its claimed points.

Parameters:
NameTypeDescription
npcIdstring

NPC identifier.

Returns:

True if removed.

Type: 
boolean

update(timeOrClockopt) → {number}

Updates time across all registered NPC schedules. Accepts a game hour float, time string, or GameClock instance.

Parameters:
NameTypeAttributesDescription
timeOrClocknumber | string | Object<optional>

New time value or clock.

Returns:

Current hour after update.

Type: 
number

vacateAllForNPC(npcId)

Vacates all activity points claimed by an NPC.

Parameters:
NameTypeDescription
npcIdstring

NPC identifier.

vacatePoint(point, npcIdopt) → {boolean}

Vacates a claimed activity point.

Parameters:
NameTypeAttributesDescription
pointObject | string

Point to vacate.

npcIdstring<optional>

Optional NPC identifier to ensure ownership.

Returns:

True if vacated.

Type: 
boolean