@sharpee/world-model 3.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/behaviors/index.d.ts +1 -0
- package/behaviors/index.d.ts.map +1 -1
- package/behaviors/index.js +4 -1
- package/behaviors/index.js.map +1 -1
- package/capabilities/action-interceptor.d.ts +93 -6
- package/capabilities/action-interceptor.d.ts.map +1 -1
- package/capabilities/action-interceptor.js +59 -2
- package/capabilities/action-interceptor.js.map +1 -1
- package/capabilities/index.d.ts +1 -1
- package/capabilities/index.d.ts.map +1 -1
- package/capabilities/index.js +2 -1
- package/capabilities/index.js.map +1 -1
- package/index.d.ts +13 -0
- package/index.d.ts.map +1 -1
- package/index.js +23 -0
- package/index.js.map +1 -1
- package/package.json +3 -3
- package/traits/combatant/combatantBehavior.d.ts +23 -18
- package/traits/combatant/combatantBehavior.d.ts.map +1 -1
- package/traits/combatant/combatantBehavior.js +47 -45
- package/traits/combatant/combatantBehavior.js.map +1 -1
- package/traits/combatant/combatantTrait.d.ts +14 -48
- package/traits/combatant/combatantTrait.d.ts.map +1 -1
- package/traits/combatant/combatantTrait.js +13 -80
- package/traits/combatant/combatantTrait.js.map +1 -1
- package/traits/cuttable/cuttableBehavior.d.ts +23 -0
- package/traits/cuttable/cuttableBehavior.d.ts.map +1 -0
- package/traits/cuttable/cuttableBehavior.js +39 -0
- package/traits/cuttable/cuttableBehavior.js.map +1 -0
- package/traits/cuttable/cuttableTrait.d.ts +37 -0
- package/traits/cuttable/cuttableTrait.d.ts.map +1 -0
- package/traits/cuttable/cuttableTrait.js +30 -0
- package/traits/cuttable/cuttableTrait.js.map +1 -0
- package/traits/cuttable/index.d.ts +3 -0
- package/traits/cuttable/index.d.ts.map +1 -0
- package/traits/cuttable/index.js +20 -0
- package/traits/cuttable/index.js.map +1 -0
- package/traits/deadly-room/deadlyRoomBehavior.d.ts +48 -0
- package/traits/deadly-room/deadlyRoomBehavior.d.ts.map +1 -0
- package/traits/deadly-room/deadlyRoomBehavior.js +59 -0
- package/traits/deadly-room/deadlyRoomBehavior.js.map +1 -0
- package/traits/deadly-room/deadlyRoomTrait.d.ts +51 -0
- package/traits/deadly-room/deadlyRoomTrait.d.ts.map +1 -0
- package/traits/deadly-room/deadlyRoomTrait.js +37 -0
- package/traits/deadly-room/deadlyRoomTrait.js.map +1 -0
- package/traits/deadly-room/index.d.ts +3 -0
- package/traits/deadly-room/index.d.ts.map +1 -0
- package/traits/deadly-room/index.js +8 -0
- package/traits/deadly-room/index.js.map +1 -0
- package/traits/diggable/diggableBehavior.d.ts +23 -0
- package/traits/diggable/diggableBehavior.d.ts.map +1 -0
- package/traits/diggable/diggableBehavior.js +39 -0
- package/traits/diggable/diggableBehavior.js.map +1 -0
- package/traits/diggable/diggableTrait.d.ts +37 -0
- package/traits/diggable/diggableTrait.d.ts.map +1 -0
- package/traits/diggable/diggableTrait.js +30 -0
- package/traits/diggable/diggableTrait.js.map +1 -0
- package/traits/diggable/index.d.ts +3 -0
- package/traits/diggable/index.d.ts.map +1 -0
- package/traits/diggable/index.js +20 -0
- package/traits/diggable/index.js.map +1 -0
- package/traits/health/healthBehavior.d.ts +66 -0
- package/traits/health/healthBehavior.d.ts.map +1 -0
- package/traits/health/healthBehavior.js +98 -0
- package/traits/health/healthBehavior.js.map +1 -0
- package/traits/health/healthTrait.d.ts +60 -0
- package/traits/health/healthTrait.d.ts.map +1 -0
- package/traits/health/healthTrait.js +49 -0
- package/traits/health/healthTrait.js.map +1 -0
- package/traits/health/index.d.ts +3 -0
- package/traits/health/index.d.ts.map +1 -0
- package/traits/health/index.js +8 -0
- package/traits/health/index.js.map +1 -0
- package/traits/implementations.d.ts +5 -1
- package/traits/implementations.d.ts.map +1 -1
- package/traits/implementations.js +15 -1
- package/traits/implementations.js.map +1 -1
- package/traits/index.d.ts +4 -0
- package/traits/index.d.ts.map +1 -1
- package/traits/index.js +5 -0
- package/traits/index.js.map +1 -1
- package/traits/npc/npcTrait.d.ts +5 -27
- package/traits/npc/npcTrait.d.ts.map +1 -1
- package/traits/npc/npcTrait.js +0 -38
- package/traits/npc/npcTrait.js.map +1 -1
- package/traits/openable/openableBehavior.d.ts +10 -0
- package/traits/openable/openableBehavior.d.ts.map +1 -1
- package/traits/openable/openableBehavior.js +21 -0
- package/traits/openable/openableBehavior.js.map +1 -1
- package/traits/openable/openableTrait.d.ts +7 -0
- package/traits/openable/openableTrait.d.ts.map +1 -1
- package/traits/openable/openableTrait.js +4 -0
- package/traits/openable/openableTrait.js.map +1 -1
- package/traits/room/roomTrait.d.ts +8 -3
- package/traits/room/roomTrait.d.ts.map +1 -1
- package/traits/room/roomTrait.js +2 -2
- package/traits/room/roomTrait.js.map +1 -1
- package/traits/trait-types.d.ts +4 -0
- package/traits/trait-types.d.ts.map +1 -1
- package/traits/trait-types.js +12 -0
- package/traits/trait-types.js.map +1 -1
- package/world/VisibilityBehavior.d.ts +1 -1
- package/world/VisibilityBehavior.js +4 -4
- package/world/VisibilityBehavior.js.map +1 -1
- package/world/WorldModel.js +1 -1
- package/world/WorldModel.js.map +1 -1
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Behavior for the deadly-room trigger shape (ADR-224).
|
|
3
|
+
*
|
|
4
|
+
* Computes the lethal/safe verdict for a parsed verb against a {@link DeadlyRoomTrait}.
|
|
5
|
+
* Consumers (the deadly-room command transformer) call `checkVerb` rather than
|
|
6
|
+
* reading the trait directly, so the model survives `loadJSON()`.
|
|
7
|
+
*
|
|
8
|
+
* Public interface: `checkVerb`, `isSafeVerb`.
|
|
9
|
+
* Owner context: `@sharpee/world-model` — the deadly-room trigger shape (ADR-224).
|
|
10
|
+
*/
|
|
11
|
+
import { SeededRandom } from '@sharpee/core';
|
|
12
|
+
import { Behavior } from '../../behaviors/behavior';
|
|
13
|
+
import { DeadlyRoomTrait } from './deadlyRoomTrait';
|
|
14
|
+
/** Verdict returned by {@link DeadlyRoomBehavior.checkVerb}. */
|
|
15
|
+
export interface DeadlyRoomVerdict {
|
|
16
|
+
/** Whether this verb kills the player in this room. */
|
|
17
|
+
lethal: boolean;
|
|
18
|
+
/** Cause to record on the death (from the trait). */
|
|
19
|
+
cause: string;
|
|
20
|
+
/** Optional death-text message id (from the trait). */
|
|
21
|
+
messageId?: string;
|
|
22
|
+
}
|
|
23
|
+
export declare class DeadlyRoomBehavior extends Behavior {
|
|
24
|
+
static requiredTraits: "deadlyRoom"[];
|
|
25
|
+
/**
|
|
26
|
+
* Whether `verb` is in the room's safe allowlist. Matches the resolved action id
|
|
27
|
+
* exactly (case-insensitive) or by its final dotted segment, so both an action id
|
|
28
|
+
* (`'if.action.looking'`) and the bare participle (`'looking'`) count as safe.
|
|
29
|
+
* @param t the deadly-room trait
|
|
30
|
+
* @param verb the command's resolved action id
|
|
31
|
+
*/
|
|
32
|
+
static isSafeVerb(t: DeadlyRoomTrait, verb: string): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* The lethal/safe verdict for a verb in this room.
|
|
35
|
+
*
|
|
36
|
+
* A safe verb is never lethal. Otherwise the verb is lethal outright when the
|
|
37
|
+
* trait has no `chance`, or lethal with probability `chance` (rolled against the
|
|
38
|
+
* seeded `rng`) when it does. If `chance` is set but no `rng` is supplied, the
|
|
39
|
+
* verb is treated as lethal (fail-deadly) — production always supplies the
|
|
40
|
+
* engine's seeded RNG; a missing RNG is a wiring error, not a survival chance.
|
|
41
|
+
*
|
|
42
|
+
* @param t the deadly-room trait
|
|
43
|
+
* @param verb the command's resolved action id
|
|
44
|
+
* @param rng the engine's seeded RNG (required only for the `chance` variant)
|
|
45
|
+
*/
|
|
46
|
+
static checkVerb(t: DeadlyRoomTrait, verb: string, rng?: SeededRandom): DeadlyRoomVerdict;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=deadlyRoomBehavior.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deadlyRoomBehavior.d.ts","sourceRoot":"","sources":["../../../../../../../../repos/sharpee_v2/packages/world-model/src/traits/deadly-room/deadlyRoomBehavior.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEpD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,gEAAgE;AAChE,MAAM,WAAW,iBAAiB;IAChC,uDAAuD;IACvD,MAAM,EAAE,OAAO,CAAC;IAChB,qDAAqD;IACrD,KAAK,EAAE,MAAM,CAAC;IACd,uDAAuD;IACvD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,kBAAmB,SAAQ,QAAQ;IAC9C,MAAM,CAAC,cAAc,iBAA2B;IAEhD;;;;;;OAMG;IACH,MAAM,CAAC,UAAU,CAAC,CAAC,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO;IAS5D;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,YAAY,GAAG,iBAAiB;CAY1F"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Behavior for the deadly-room trigger shape (ADR-224).
|
|
4
|
+
*
|
|
5
|
+
* Computes the lethal/safe verdict for a parsed verb against a {@link DeadlyRoomTrait}.
|
|
6
|
+
* Consumers (the deadly-room command transformer) call `checkVerb` rather than
|
|
7
|
+
* reading the trait directly, so the model survives `loadJSON()`.
|
|
8
|
+
*
|
|
9
|
+
* Public interface: `checkVerb`, `isSafeVerb`.
|
|
10
|
+
* Owner context: `@sharpee/world-model` — the deadly-room trigger shape (ADR-224).
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.DeadlyRoomBehavior = void 0;
|
|
14
|
+
const behavior_1 = require("../../behaviors/behavior");
|
|
15
|
+
const trait_types_1 = require("../trait-types");
|
|
16
|
+
class DeadlyRoomBehavior extends behavior_1.Behavior {
|
|
17
|
+
static requiredTraits = [trait_types_1.TraitType.DEADLY_ROOM];
|
|
18
|
+
/**
|
|
19
|
+
* Whether `verb` is in the room's safe allowlist. Matches the resolved action id
|
|
20
|
+
* exactly (case-insensitive) or by its final dotted segment, so both an action id
|
|
21
|
+
* (`'if.action.looking'`) and the bare participle (`'looking'`) count as safe.
|
|
22
|
+
* @param t the deadly-room trait
|
|
23
|
+
* @param verb the command's resolved action id
|
|
24
|
+
*/
|
|
25
|
+
static isSafeVerb(t, verb) {
|
|
26
|
+
const v = (verb ?? '').toLowerCase();
|
|
27
|
+
const seg = v.split('.').pop() ?? v;
|
|
28
|
+
return t.safeVerbs.some((s) => {
|
|
29
|
+
const safe = s.toLowerCase();
|
|
30
|
+
return v === safe || seg === safe;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The lethal/safe verdict for a verb in this room.
|
|
35
|
+
*
|
|
36
|
+
* A safe verb is never lethal. Otherwise the verb is lethal outright when the
|
|
37
|
+
* trait has no `chance`, or lethal with probability `chance` (rolled against the
|
|
38
|
+
* seeded `rng`) when it does. If `chance` is set but no `rng` is supplied, the
|
|
39
|
+
* verb is treated as lethal (fail-deadly) — production always supplies the
|
|
40
|
+
* engine's seeded RNG; a missing RNG is a wiring error, not a survival chance.
|
|
41
|
+
*
|
|
42
|
+
* @param t the deadly-room trait
|
|
43
|
+
* @param verb the command's resolved action id
|
|
44
|
+
* @param rng the engine's seeded RNG (required only for the `chance` variant)
|
|
45
|
+
*/
|
|
46
|
+
static checkVerb(t, verb, rng) {
|
|
47
|
+
const base = { cause: t.cause, messageId: t.messageId };
|
|
48
|
+
if (DeadlyRoomBehavior.isSafeVerb(t, verb)) {
|
|
49
|
+
return { lethal: false, ...base };
|
|
50
|
+
}
|
|
51
|
+
if (t.chance === undefined) {
|
|
52
|
+
return { lethal: true, ...base };
|
|
53
|
+
}
|
|
54
|
+
const lethal = rng ? rng.chance(t.chance) : true;
|
|
55
|
+
return { lethal, ...base };
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.DeadlyRoomBehavior = DeadlyRoomBehavior;
|
|
59
|
+
//# sourceMappingURL=deadlyRoomBehavior.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deadlyRoomBehavior.js","sourceRoot":"","sources":["../../../../../../../../repos/sharpee_v2/packages/world-model/src/traits/deadly-room/deadlyRoomBehavior.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAGH,uDAAoD;AACpD,gDAA2C;AAa3C,MAAa,kBAAmB,SAAQ,mBAAQ;IAC9C,MAAM,CAAC,cAAc,GAAG,CAAC,uBAAS,CAAC,WAAW,CAAC,CAAC;IAEhD;;;;;;OAMG;IACH,MAAM,CAAC,UAAU,CAAC,CAAkB,EAAE,IAAY;QAChD,MAAM,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;QACrC,MAAM,GAAG,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QACpC,OAAO,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;YAC5B,MAAM,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC;YAC7B,OAAO,CAAC,KAAK,IAAI,IAAI,GAAG,KAAK,IAAI,CAAC;QACpC,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,SAAS,CAAC,CAAkB,EAAE,IAAY,EAAE,GAAkB;QACnE,MAAM,IAAI,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC,SAAS,EAAE,CAAC;QAExD,IAAI,kBAAkB,CAAC,UAAU,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC;YAC3C,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,CAAC;QACpC,CAAC;QACD,IAAI,CAAC,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAC3B,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,CAAC;QACnC,CAAC;QACD,MAAM,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACjD,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,CAAC;IAC7B,CAAC;;AA3CH,gDA4CC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deadly Room Trait (ADR-224 — the reusable deadly-room trigger shape).
|
|
3
|
+
*
|
|
4
|
+
* Marks a room where verbs outside a safe allowlist kill the player: MDL's
|
|
5
|
+
* Aragain Falls ("every verb but LOOK is fatal here"). An optional `chance` turns
|
|
6
|
+
* the same shape into a probabilistic hazard (the grue: a non-safe verb dies only
|
|
7
|
+
* `chance` of the time), rolled against the engine's seeded RNG.
|
|
8
|
+
*
|
|
9
|
+
* Data only — no methods. The lethal/safe verdict lives in {@link DeadlyRoomBehavior}
|
|
10
|
+
* (a getter would not survive `loadJSON()`). The trait carries no logic and no RNG;
|
|
11
|
+
* the deadly-room command transformer supplies the seeded RNG at check time.
|
|
12
|
+
*
|
|
13
|
+
* Public interface: read the verdict via `DeadlyRoomBehavior.checkVerb`.
|
|
14
|
+
* Owner context: `@sharpee/world-model` — the deadly-room trigger shape (ADR-224).
|
|
15
|
+
*/
|
|
16
|
+
import { ITrait } from '../trait';
|
|
17
|
+
/**
|
|
18
|
+
* Constructor/serialization data for {@link DeadlyRoomTrait}.
|
|
19
|
+
*/
|
|
20
|
+
export interface IDeadlyRoomData {
|
|
21
|
+
/** Cause recorded on the death (e.g. 'fall', 'grue'). Defaults to `'hazard'`. */
|
|
22
|
+
cause?: string;
|
|
23
|
+
/** Optional death-text message id (rendered by the language layer). */
|
|
24
|
+
messageId?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Verbs that are safe in this room — matched against a command's resolved
|
|
27
|
+
* action id, tolerant of the bare participle (`'looking'` matches
|
|
28
|
+
* `'if.action.looking'`). Defaults to `['looking', 'examining']` (LOOK/EXAMINE),
|
|
29
|
+
* the MDL falls allowlist.
|
|
30
|
+
*/
|
|
31
|
+
safeVerbs?: string[];
|
|
32
|
+
/**
|
|
33
|
+
* Probability (0–1) that a non-safe verb is lethal. When omitted, every non-safe
|
|
34
|
+
* verb is lethal (the falls). When set, the hazard is probabilistic (the grue)
|
|
35
|
+
* and rolled against the engine's seeded RNG — never `Math.random()`.
|
|
36
|
+
*/
|
|
37
|
+
chance?: number;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The deadly-room trigger trait. Data-only; see file header.
|
|
41
|
+
*/
|
|
42
|
+
export declare class DeadlyRoomTrait implements ITrait, IDeadlyRoomData {
|
|
43
|
+
static readonly type: "deadlyRoom";
|
|
44
|
+
readonly type: "deadlyRoom";
|
|
45
|
+
cause: string;
|
|
46
|
+
messageId?: string;
|
|
47
|
+
safeVerbs: string[];
|
|
48
|
+
chance?: number;
|
|
49
|
+
constructor(data?: IDeadlyRoomData);
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=deadlyRoomTrait.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deadlyRoomTrait.d.ts","sourceRoot":"","sources":["../../../../../../../../repos/sharpee_v2/packages/world-model/src/traits/deadly-room/deadlyRoomTrait.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,iFAAiF;IACjF,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,uEAAuE;IACvE,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IAErB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,qBAAa,eAAgB,YAAW,MAAM,EAAE,eAAe;IAC7D,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAG,YAAY,CAAU;IAC7C,QAAQ,CAAC,IAAI,EAAG,YAAY,CAAU;IAEtC,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;gBAEJ,IAAI,GAAE,eAAoB;CAMvC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Deadly Room Trait (ADR-224 — the reusable deadly-room trigger shape).
|
|
4
|
+
*
|
|
5
|
+
* Marks a room where verbs outside a safe allowlist kill the player: MDL's
|
|
6
|
+
* Aragain Falls ("every verb but LOOK is fatal here"). An optional `chance` turns
|
|
7
|
+
* the same shape into a probabilistic hazard (the grue: a non-safe verb dies only
|
|
8
|
+
* `chance` of the time), rolled against the engine's seeded RNG.
|
|
9
|
+
*
|
|
10
|
+
* Data only — no methods. The lethal/safe verdict lives in {@link DeadlyRoomBehavior}
|
|
11
|
+
* (a getter would not survive `loadJSON()`). The trait carries no logic and no RNG;
|
|
12
|
+
* the deadly-room command transformer supplies the seeded RNG at check time.
|
|
13
|
+
*
|
|
14
|
+
* Public interface: read the verdict via `DeadlyRoomBehavior.checkVerb`.
|
|
15
|
+
* Owner context: `@sharpee/world-model` — the deadly-room trigger shape (ADR-224).
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.DeadlyRoomTrait = void 0;
|
|
19
|
+
/**
|
|
20
|
+
* The deadly-room trigger trait. Data-only; see file header.
|
|
21
|
+
*/
|
|
22
|
+
class DeadlyRoomTrait {
|
|
23
|
+
static type = 'deadlyRoom';
|
|
24
|
+
type = 'deadlyRoom';
|
|
25
|
+
cause;
|
|
26
|
+
messageId;
|
|
27
|
+
safeVerbs;
|
|
28
|
+
chance;
|
|
29
|
+
constructor(data = {}) {
|
|
30
|
+
this.cause = data.cause ?? 'hazard';
|
|
31
|
+
this.messageId = data.messageId;
|
|
32
|
+
this.safeVerbs = data.safeVerbs ?? ['looking', 'examining'];
|
|
33
|
+
this.chance = data.chance;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.DeadlyRoomTrait = DeadlyRoomTrait;
|
|
37
|
+
//# sourceMappingURL=deadlyRoomTrait.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deadlyRoomTrait.js","sourceRoot":"","sources":["../../../../../../../../repos/sharpee_v2/packages/world-model/src/traits/deadly-room/deadlyRoomTrait.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AA8BH;;GAEG;AACH,MAAa,eAAe;IAC1B,MAAM,CAAU,IAAI,GAAG,YAAqB,CAAC;IACpC,IAAI,GAAG,YAAqB,CAAC;IAEtC,KAAK,CAAS;IACd,SAAS,CAAU;IACnB,SAAS,CAAW;IACpB,MAAM,CAAU;IAEhB,YAAY,OAAwB,EAAE;QACpC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,QAAQ,CAAC;QACpC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;QAChC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;QAC5D,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IAC5B,CAAC;;AAdH,0CAeC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../../repos/sharpee_v2/packages/world-model/src/traits/deadly-room/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DeadlyRoomBehavior = exports.DeadlyRoomTrait = void 0;
|
|
4
|
+
var deadlyRoomTrait_1 = require("./deadlyRoomTrait");
|
|
5
|
+
Object.defineProperty(exports, "DeadlyRoomTrait", { enumerable: true, get: function () { return deadlyRoomTrait_1.DeadlyRoomTrait; } });
|
|
6
|
+
var deadlyRoomBehavior_1 = require("./deadlyRoomBehavior");
|
|
7
|
+
Object.defineProperty(exports, "DeadlyRoomBehavior", { enumerable: true, get: function () { return deadlyRoomBehavior_1.DeadlyRoomBehavior; } });
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../../repos/sharpee_v2/packages/world-model/src/traits/deadly-room/index.ts"],"names":[],"mappings":";;;AAAA,qDAAqE;AAA5D,kHAAA,eAAe,OAAA;AACxB,2DAA6E;AAApE,wHAAA,kBAAkB,OAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { EntityId } from '@sharpee/core';
|
|
2
|
+
import { Behavior } from '../../behaviors/behavior';
|
|
3
|
+
import { IFEntity } from '../../entities/if-entity';
|
|
4
|
+
/**
|
|
5
|
+
* Behavior for diggable entities (ADR-230 Phase 6 (sketch ruling 6)).
|
|
6
|
+
*
|
|
7
|
+
* Pure predicates only — the digging action's validate() consults these;
|
|
8
|
+
* the cut mutation itself belongs to the entity's registered
|
|
9
|
+
* implementation, never here.
|
|
10
|
+
*/
|
|
11
|
+
export declare class DiggableBehavior extends Behavior {
|
|
12
|
+
static requiredTraits: "diggable"[];
|
|
13
|
+
/**
|
|
14
|
+
* Check if this entity requires a tool to cut (mirrors
|
|
15
|
+
* LockableBehavior.requiresKey / OpenableBehavior.requiresTool)
|
|
16
|
+
*/
|
|
17
|
+
static requiresTool(entity: IFEntity): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Check if a tool can cut this entity (mirrors LockableBehavior.canUnlockWith)
|
|
20
|
+
*/
|
|
21
|
+
static canDigWith(entity: IFEntity, toolId: EntityId): boolean;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=diggableBehavior.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diggableBehavior.d.ts","sourceRoot":"","sources":["../../../../../../../../repos/sharpee_v2/packages/world-model/src/traits/diggable/diggableBehavior.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAIpD;;;;;;GAMG;AACH,qBAAa,gBAAiB,SAAQ,QAAQ;IAC5C,MAAM,CAAC,cAAc,eAAwB;IAE7C;;;OAGG;IACH,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,QAAQ,GAAG,OAAO;IAK9C;;OAEG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,GAAG,OAAO;CAa/D"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// packages/world-model/src/traits/diggable/diggableBehavior.ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.DiggableBehavior = void 0;
|
|
5
|
+
const behavior_1 = require("../../behaviors/behavior");
|
|
6
|
+
const trait_types_1 = require("../trait-types");
|
|
7
|
+
/**
|
|
8
|
+
* Behavior for diggable entities (ADR-230 Phase 6 (sketch ruling 6)).
|
|
9
|
+
*
|
|
10
|
+
* Pure predicates only — the digging action's validate() consults these;
|
|
11
|
+
* the cut mutation itself belongs to the entity's registered
|
|
12
|
+
* implementation, never here.
|
|
13
|
+
*/
|
|
14
|
+
class DiggableBehavior extends behavior_1.Behavior {
|
|
15
|
+
static requiredTraits = [trait_types_1.TraitType.DIGGABLE];
|
|
16
|
+
/**
|
|
17
|
+
* Check if this entity requires a tool to cut (mirrors
|
|
18
|
+
* LockableBehavior.requiresKey / OpenableBehavior.requiresTool)
|
|
19
|
+
*/
|
|
20
|
+
static requiresTool(entity) {
|
|
21
|
+
const diggable = DiggableBehavior.require(entity, trait_types_1.TraitType.DIGGABLE);
|
|
22
|
+
return !!(diggable.toolId || diggable.toolIds?.length);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Check if a tool can cut this entity (mirrors LockableBehavior.canUnlockWith)
|
|
26
|
+
*/
|
|
27
|
+
static canDigWith(entity, toolId) {
|
|
28
|
+
const diggable = DiggableBehavior.require(entity, trait_types_1.TraitType.DIGGABLE);
|
|
29
|
+
if (diggable.toolId === toolId) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
if (diggable.toolIds && diggable.toolIds.includes(toolId)) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.DiggableBehavior = DiggableBehavior;
|
|
39
|
+
//# sourceMappingURL=diggableBehavior.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diggableBehavior.js","sourceRoot":"","sources":["../../../../../../../../repos/sharpee_v2/packages/world-model/src/traits/diggable/diggableBehavior.ts"],"names":[],"mappings":";AAAA,+DAA+D;;;AAG/D,uDAAoD;AAEpD,gDAA2C;AAG3C;;;;;;GAMG;AACH,MAAa,gBAAiB,SAAQ,mBAAQ;IAC5C,MAAM,CAAC,cAAc,GAAG,CAAC,uBAAS,CAAC,QAAQ,CAAC,CAAC;IAE7C;;;OAGG;IACH,MAAM,CAAC,YAAY,CAAC,MAAgB;QAClC,MAAM,QAAQ,GAAG,gBAAgB,CAAC,OAAO,CAAgB,MAAM,EAAE,uBAAS,CAAC,QAAQ,CAAC,CAAC;QACrF,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACzD,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,UAAU,CAAC,MAAgB,EAAE,MAAgB;QAClD,MAAM,QAAQ,GAAG,gBAAgB,CAAC,OAAO,CAAgB,MAAM,EAAE,uBAAS,CAAC,QAAQ,CAAC,CAAC;QAErF,IAAI,QAAQ,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;YAC/B,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,QAAQ,CAAC,OAAO,IAAI,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YAC1D,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;;AA3BH,4CA4BC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { EntityId } from '@sharpee/core';
|
|
2
|
+
import { ITrait } from '../trait';
|
|
3
|
+
/**
|
|
4
|
+
* Data for the diggable trait (ADR-230 Phase 6 (sketch ruling 6)).
|
|
5
|
+
*
|
|
6
|
+
* Tool fields mirror ILockableData's key config (PIN 2 shared shape with
|
|
7
|
+
* OpenableTrait's tool fields): a declared requirement makes the digging
|
|
8
|
+
* action refuse wrong/missing tools; no requirement means any explicit
|
|
9
|
+
* tool (or none) passes validation.
|
|
10
|
+
*/
|
|
11
|
+
export interface IDiggableData {
|
|
12
|
+
/** Single tool entity required to dig this (mirrors ILockableData.keyId) */
|
|
13
|
+
toolId?: EntityId;
|
|
14
|
+
/** Multiple tool entities that can dig this (mirrors ILockableData.keyIds) */
|
|
15
|
+
toolIds?: EntityId[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Diggable trait — marks an entity the digging action may target.
|
|
19
|
+
*
|
|
20
|
+
* The trait gates eligibility only. The dig OUTCOME is the entity's own
|
|
21
|
+
* registered implementation (ADR-090 capability behavior from TS, or a
|
|
22
|
+
* Chord `on digging it` interceptor) — the standard digging action never
|
|
23
|
+
* mutates state itself. An entity with this trait and no registered
|
|
24
|
+
* implementation is an authoring error (load-time in Chord; runtime
|
|
25
|
+
* safety-net refusal otherwise).
|
|
26
|
+
*
|
|
27
|
+
* This trait contains only data - eligibility/tool logic is in
|
|
28
|
+
* DiggableBehavior.
|
|
29
|
+
*/
|
|
30
|
+
export declare class DiggableTrait implements ITrait, IDiggableData {
|
|
31
|
+
static readonly type: "diggable";
|
|
32
|
+
readonly type: "diggable";
|
|
33
|
+
toolId?: EntityId;
|
|
34
|
+
toolIds?: EntityId[];
|
|
35
|
+
constructor(data?: IDiggableData);
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=diggableTrait.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diggableTrait.d.ts","sourceRoot":"","sources":["../../../../../../../../repos/sharpee_v2/packages/world-model/src/traits/diggable/diggableTrait.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAGlC;;;;;;;GAOG;AACH,MAAM,WAAW,aAAa;IAC5B,4EAA4E;IAC5E,MAAM,CAAC,EAAE,QAAQ,CAAC;IAElB,8EAA8E;IAC9E,OAAO,CAAC,EAAE,QAAQ,EAAE,CAAC;CACtB;AAED;;;;;;;;;;;;GAYG;AACH,qBAAa,aAAc,YAAW,MAAM,EAAE,aAAa;IACzD,MAAM,CAAC,QAAQ,CAAC,IAAI,aAAsB;IAC1C,QAAQ,CAAC,IAAI,aAAsB;IAEnC,MAAM,CAAC,EAAE,QAAQ,CAAC;IAClB,OAAO,CAAC,EAAE,QAAQ,EAAE,CAAC;gBAET,IAAI,GAAE,aAAkB;CAIrC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// packages/world-model/src/traits/diggable/diggableTrait.ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.DiggableTrait = void 0;
|
|
5
|
+
const trait_types_1 = require("../trait-types");
|
|
6
|
+
/**
|
|
7
|
+
* Diggable trait — marks an entity the digging action may target.
|
|
8
|
+
*
|
|
9
|
+
* The trait gates eligibility only. The dig OUTCOME is the entity's own
|
|
10
|
+
* registered implementation (ADR-090 capability behavior from TS, or a
|
|
11
|
+
* Chord `on digging it` interceptor) — the standard digging action never
|
|
12
|
+
* mutates state itself. An entity with this trait and no registered
|
|
13
|
+
* implementation is an authoring error (load-time in Chord; runtime
|
|
14
|
+
* safety-net refusal otherwise).
|
|
15
|
+
*
|
|
16
|
+
* This trait contains only data - eligibility/tool logic is in
|
|
17
|
+
* DiggableBehavior.
|
|
18
|
+
*/
|
|
19
|
+
class DiggableTrait {
|
|
20
|
+
static type = trait_types_1.TraitType.DIGGABLE;
|
|
21
|
+
type = trait_types_1.TraitType.DIGGABLE;
|
|
22
|
+
toolId;
|
|
23
|
+
toolIds;
|
|
24
|
+
constructor(data = {}) {
|
|
25
|
+
this.toolId = data.toolId;
|
|
26
|
+
this.toolIds = data.toolIds;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.DiggableTrait = DiggableTrait;
|
|
30
|
+
//# sourceMappingURL=diggableTrait.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diggableTrait.js","sourceRoot":"","sources":["../../../../../../../../repos/sharpee_v2/packages/world-model/src/traits/diggable/diggableTrait.ts"],"names":[],"mappings":";AAAA,4DAA4D;;;AAI5D,gDAA2C;AAkB3C;;;;;;;;;;;;GAYG;AACH,MAAa,aAAa;IACxB,MAAM,CAAU,IAAI,GAAG,uBAAS,CAAC,QAAQ,CAAC;IACjC,IAAI,GAAG,uBAAS,CAAC,QAAQ,CAAC;IAEnC,MAAM,CAAY;IAClB,OAAO,CAAc;IAErB,YAAY,OAAsB,EAAE;QAClC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;IAC9B,CAAC;;AAVH,sCAWC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../../repos/sharpee_v2/packages/world-model/src/traits/diggable/index.ts"],"names":[],"mappings":"AAEA,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// packages/world-model/src/traits/diggable/index.ts
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
__exportStar(require("./diggableTrait"), exports);
|
|
19
|
+
__exportStar(require("./diggableBehavior"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../../repos/sharpee_v2/packages/world-model/src/traits/diggable/index.ts"],"names":[],"mappings":";AAAA,oDAAoD;;;;;;;;;;;;;;;;AAEpD,kDAAgC;AAChC,qDAAmC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Behavior for the HEALTH layer (ADR-226).
|
|
3
|
+
*
|
|
4
|
+
* All derivation and mutation over {@link HealthTrait} data. Consumers call these
|
|
5
|
+
* static methods rather than reading the trait's fields through getters, so the
|
|
6
|
+
* model survives `loadJSON()` (the `npc-service` `canAct`-getter footgun this layer
|
|
7
|
+
* removes). Consciousness is purely derived from `health` — there is no stored
|
|
8
|
+
* knocked-out flag, no `knockOut`/`wakeUp`, and no recovery timer (ADR-226 §1 F1).
|
|
9
|
+
*
|
|
10
|
+
* Public interface: `isAlive` / `isConscious` / `canAct` (pure derivation) and
|
|
11
|
+
* `takeDamage` / `heal` / `kill` (mutation). All operate on a `HealthTrait` directly;
|
|
12
|
+
* callers first confirm the entity has one (an entity with no `HealthTrait` is alive
|
|
13
|
+
* and conscious by default — ADR-226 §3 opt-in rule — a check owned by the caller).
|
|
14
|
+
* Owner context: `@sharpee/world-model` — HEALTH layer (ADR-223 child A).
|
|
15
|
+
*/
|
|
16
|
+
import { Behavior } from '../../behaviors/behavior';
|
|
17
|
+
import { HealthTrait } from './healthTrait';
|
|
18
|
+
export declare class HealthBehavior extends Behavior {
|
|
19
|
+
static requiredTraits: "health"[];
|
|
20
|
+
/**
|
|
21
|
+
* Whether the entity is alive: not terminally dead and above zero health.
|
|
22
|
+
* @param t the entity's health trait
|
|
23
|
+
*/
|
|
24
|
+
static isAlive(t: HealthTrait): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Whether the entity is conscious: alive, not asleep, and above the
|
|
27
|
+
* unconsciousness threshold. Consciousness is derived from `health` alone.
|
|
28
|
+
* @param t the entity's health trait
|
|
29
|
+
*/
|
|
30
|
+
static isConscious(t: HealthTrait): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Whether the entity can take a turn / act. Alias of {@link isConscious} — the
|
|
33
|
+
* turn loop's eligibility predicate (replaces `NpcTrait.canAct`).
|
|
34
|
+
* @param t the entity's health trait
|
|
35
|
+
*/
|
|
36
|
+
static canAct(t: HealthTrait): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Apply damage to health. Armor is the caller's concern (a `CombatantTrait` stat),
|
|
39
|
+
* so `amount` is already post-armor. On reaching zero health the entity dies with
|
|
40
|
+
* the given `cause`.
|
|
41
|
+
* @param t the entity's health trait
|
|
42
|
+
* @param amount post-armor damage; negatives are treated as zero
|
|
43
|
+
* @param cause cause recorded if this blow is lethal (default 'damage')
|
|
44
|
+
* @returns `true` iff the entity is now dead
|
|
45
|
+
*/
|
|
46
|
+
static takeDamage(t: HealthTrait, amount: number, cause?: string): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Restore health, clamped to `maxHealth`. Healing back above the unconsciousness
|
|
49
|
+
* threshold *is* regaining consciousness (no separate wake step). The dead do not
|
|
50
|
+
* heal — resurrection is a deliberate separate act, not `heal`.
|
|
51
|
+
* @param t the entity's health trait
|
|
52
|
+
* @param amount healing; negatives are treated as zero
|
|
53
|
+
* @returns the actual amount healed
|
|
54
|
+
*/
|
|
55
|
+
static heal(t: HealthTrait, amount: number): number;
|
|
56
|
+
/**
|
|
57
|
+
* Kill the entity: set the terminal `dead` flag and its `cause`, leaving `health`
|
|
58
|
+
* untouched. This is death's single writer — non-damage deaths (grue/fall/drown,
|
|
59
|
+
* ADR-224 `killPlayer`) call it directly; `takeDamage` calls it on a lethal blow.
|
|
60
|
+
* Death is distinct from `health === 0` (an entity can be dead at full health).
|
|
61
|
+
* @param t the entity's health trait
|
|
62
|
+
* @param cause the cause of death (e.g. 'grue', 'fall', 'combat')
|
|
63
|
+
*/
|
|
64
|
+
static kill(t: HealthTrait, cause: string): void;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=healthBehavior.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"healthBehavior.d.ts","sourceRoot":"","sources":["../../../../../../../../repos/sharpee_v2/packages/world-model/src/traits/health/healthBehavior.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEpD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,qBAAa,cAAe,SAAQ,QAAQ;IAC1C,MAAM,CAAC,cAAc,aAAsB;IAI3C;;;OAGG;IACH,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,WAAW,GAAG,OAAO;IAIvC;;;;OAIG;IACH,MAAM,CAAC,WAAW,CAAC,CAAC,EAAE,WAAW,GAAG,OAAO;IAQ3C;;;;OAIG;IACH,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,WAAW,GAAG,OAAO;IAMtC;;;;;;;;OAQG;IACH,MAAM,CAAC,UAAU,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,GAAE,MAAiB,GAAG,OAAO;IAUpF;;;;;;;OAOG;IACH,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM;IAOnD;;;;;;;OAOG;IACH,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;CAIjD"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Behavior for the HEALTH layer (ADR-226).
|
|
4
|
+
*
|
|
5
|
+
* All derivation and mutation over {@link HealthTrait} data. Consumers call these
|
|
6
|
+
* static methods rather than reading the trait's fields through getters, so the
|
|
7
|
+
* model survives `loadJSON()` (the `npc-service` `canAct`-getter footgun this layer
|
|
8
|
+
* removes). Consciousness is purely derived from `health` — there is no stored
|
|
9
|
+
* knocked-out flag, no `knockOut`/`wakeUp`, and no recovery timer (ADR-226 §1 F1).
|
|
10
|
+
*
|
|
11
|
+
* Public interface: `isAlive` / `isConscious` / `canAct` (pure derivation) and
|
|
12
|
+
* `takeDamage` / `heal` / `kill` (mutation). All operate on a `HealthTrait` directly;
|
|
13
|
+
* callers first confirm the entity has one (an entity with no `HealthTrait` is alive
|
|
14
|
+
* and conscious by default — ADR-226 §3 opt-in rule — a check owned by the caller).
|
|
15
|
+
* Owner context: `@sharpee/world-model` — HEALTH layer (ADR-223 child A).
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.HealthBehavior = void 0;
|
|
19
|
+
const behavior_1 = require("../../behaviors/behavior");
|
|
20
|
+
const trait_types_1 = require("../trait-types");
|
|
21
|
+
class HealthBehavior extends behavior_1.Behavior {
|
|
22
|
+
static requiredTraits = [trait_types_1.TraitType.HEALTH];
|
|
23
|
+
// ---- Derivation (pure — no mutation) ----
|
|
24
|
+
/**
|
|
25
|
+
* Whether the entity is alive: not terminally dead and above zero health.
|
|
26
|
+
* @param t the entity's health trait
|
|
27
|
+
*/
|
|
28
|
+
static isAlive(t) {
|
|
29
|
+
return !t.dead && t.health > 0;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Whether the entity is conscious: alive, not asleep, and above the
|
|
33
|
+
* unconsciousness threshold. Consciousness is derived from `health` alone.
|
|
34
|
+
* @param t the entity's health trait
|
|
35
|
+
*/
|
|
36
|
+
static isConscious(t) {
|
|
37
|
+
return (HealthBehavior.isAlive(t) &&
|
|
38
|
+
!t.asleep &&
|
|
39
|
+
t.health > t.maxHealth * t.unconsciousThreshold);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Whether the entity can take a turn / act. Alias of {@link isConscious} — the
|
|
43
|
+
* turn loop's eligibility predicate (replaces `NpcTrait.canAct`).
|
|
44
|
+
* @param t the entity's health trait
|
|
45
|
+
*/
|
|
46
|
+
static canAct(t) {
|
|
47
|
+
return HealthBehavior.isConscious(t);
|
|
48
|
+
}
|
|
49
|
+
// ---- Mutation (behaviors own mutations) ----
|
|
50
|
+
/**
|
|
51
|
+
* Apply damage to health. Armor is the caller's concern (a `CombatantTrait` stat),
|
|
52
|
+
* so `amount` is already post-armor. On reaching zero health the entity dies with
|
|
53
|
+
* the given `cause`.
|
|
54
|
+
* @param t the entity's health trait
|
|
55
|
+
* @param amount post-armor damage; negatives are treated as zero
|
|
56
|
+
* @param cause cause recorded if this blow is lethal (default 'damage')
|
|
57
|
+
* @returns `true` iff the entity is now dead
|
|
58
|
+
*/
|
|
59
|
+
static takeDamage(t, amount, cause = 'damage') {
|
|
60
|
+
if (t.dead)
|
|
61
|
+
return true; // a corpse takes no further damage (idempotent)
|
|
62
|
+
t.health = Math.max(0, t.health - Math.max(0, amount));
|
|
63
|
+
if (t.health <= 0) {
|
|
64
|
+
HealthBehavior.kill(t, cause);
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Restore health, clamped to `maxHealth`. Healing back above the unconsciousness
|
|
71
|
+
* threshold *is* regaining consciousness (no separate wake step). The dead do not
|
|
72
|
+
* heal — resurrection is a deliberate separate act, not `heal`.
|
|
73
|
+
* @param t the entity's health trait
|
|
74
|
+
* @param amount healing; negatives are treated as zero
|
|
75
|
+
* @returns the actual amount healed
|
|
76
|
+
*/
|
|
77
|
+
static heal(t, amount) {
|
|
78
|
+
if (t.dead)
|
|
79
|
+
return 0;
|
|
80
|
+
const before = t.health;
|
|
81
|
+
t.health = Math.min(t.maxHealth, t.health + Math.max(0, amount));
|
|
82
|
+
return t.health - before;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Kill the entity: set the terminal `dead` flag and its `cause`, leaving `health`
|
|
86
|
+
* untouched. This is death's single writer — non-damage deaths (grue/fall/drown,
|
|
87
|
+
* ADR-224 `killPlayer`) call it directly; `takeDamage` calls it on a lethal blow.
|
|
88
|
+
* Death is distinct from `health === 0` (an entity can be dead at full health).
|
|
89
|
+
* @param t the entity's health trait
|
|
90
|
+
* @param cause the cause of death (e.g. 'grue', 'fall', 'combat')
|
|
91
|
+
*/
|
|
92
|
+
static kill(t, cause) {
|
|
93
|
+
t.dead = true;
|
|
94
|
+
t.causeOfDeath = cause;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.HealthBehavior = HealthBehavior;
|
|
98
|
+
//# sourceMappingURL=healthBehavior.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"healthBehavior.js","sourceRoot":"","sources":["../../../../../../../../repos/sharpee_v2/packages/world-model/src/traits/health/healthBehavior.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,uDAAoD;AACpD,gDAA2C;AAG3C,MAAa,cAAe,SAAQ,mBAAQ;IAC1C,MAAM,CAAC,cAAc,GAAG,CAAC,uBAAS,CAAC,MAAM,CAAC,CAAC;IAE3C,4CAA4C;IAE5C;;;OAGG;IACH,MAAM,CAAC,OAAO,CAAC,CAAc;QAC3B,OAAO,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IACjC,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,WAAW,CAAC,CAAc;QAC/B,OAAO,CACL,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;YACzB,CAAC,CAAC,CAAC,MAAM;YACT,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,oBAAoB,CAChD,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,MAAM,CAAC,CAAc;QAC1B,OAAO,cAAc,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IACvC,CAAC;IAED,+CAA+C;IAE/C;;;;;;;;OAQG;IACH,MAAM,CAAC,UAAU,CAAC,CAAc,EAAE,MAAc,EAAE,QAAgB,QAAQ;QACxE,IAAI,CAAC,CAAC,IAAI;YAAE,OAAO,IAAI,CAAC,CAAC,gDAAgD;QACzE,CAAC,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;QACvD,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;YAClB,cAAc,CAAC,IAAI,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;YAC9B,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;;;;;OAOG;IACH,MAAM,CAAC,IAAI,CAAC,CAAc,EAAE,MAAc;QACxC,IAAI,CAAC,CAAC,IAAI;YAAE,OAAO,CAAC,CAAC;QACrB,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;QACxB,CAAC,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;QACjE,OAAO,CAAC,CAAC,MAAM,GAAG,MAAM,CAAC;IAC3B,CAAC;IAED;;;;;;;OAOG;IACH,MAAM,CAAC,IAAI,CAAC,CAAc,EAAE,KAAa;QACvC,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC;QACd,CAAC,CAAC,YAAY,GAAG,KAAK,CAAC;IACzB,CAAC;;AAlFH,wCAmFC"}
|