@ai-rpg-engine/modules 1.0.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/dist/belief-provenance.d.ts +41 -0
- package/dist/belief-provenance.d.ts.map +1 -0
- package/dist/belief-provenance.js +254 -0
- package/dist/belief-provenance.js.map +1 -0
- package/dist/belief-provenance.test.d.ts +2 -0
- package/dist/belief-provenance.test.d.ts.map +1 -0
- package/dist/belief-provenance.test.js +139 -0
- package/dist/belief-provenance.test.js.map +1 -0
- package/dist/cognition-core.d.ts +89 -0
- package/dist/cognition-core.d.ts.map +1 -0
- package/dist/cognition-core.js +370 -0
- package/dist/cognition-core.js.map +1 -0
- package/dist/cognition-core.test.d.ts +2 -0
- package/dist/cognition-core.test.d.ts.map +1 -0
- package/dist/cognition-core.test.js +215 -0
- package/dist/cognition-core.test.js.map +1 -0
- package/dist/combat-core.d.ts +11 -0
- package/dist/combat-core.d.ts.map +1 -0
- package/dist/combat-core.js +152 -0
- package/dist/combat-core.js.map +1 -0
- package/dist/dialogue-core.d.ts +10 -0
- package/dist/dialogue-core.d.ts.map +1 -0
- package/dist/dialogue-core.js +172 -0
- package/dist/dialogue-core.js.map +1 -0
- package/dist/district-core.d.ts +59 -0
- package/dist/district-core.d.ts.map +1 -0
- package/dist/district-core.js +224 -0
- package/dist/district-core.js.map +1 -0
- package/dist/district-core.test.d.ts +2 -0
- package/dist/district-core.test.d.ts.map +1 -0
- package/dist/district-core.test.js +157 -0
- package/dist/district-core.test.js.map +1 -0
- package/dist/environment-core.d.ts +78 -0
- package/dist/environment-core.d.ts.map +1 -0
- package/dist/environment-core.js +229 -0
- package/dist/environment-core.js.map +1 -0
- package/dist/environment-core.test.d.ts +2 -0
- package/dist/environment-core.test.d.ts.map +1 -0
- package/dist/environment-core.test.js +252 -0
- package/dist/environment-core.test.js.map +1 -0
- package/dist/faction-cognition.d.ts +39 -0
- package/dist/faction-cognition.d.ts.map +1 -0
- package/dist/faction-cognition.js +139 -0
- package/dist/faction-cognition.js.map +1 -0
- package/dist/faction-cognition.test.d.ts +2 -0
- package/dist/faction-cognition.test.d.ts.map +1 -0
- package/dist/faction-cognition.test.js +166 -0
- package/dist/faction-cognition.test.js.map +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/inventory-core.d.ts +10 -0
- package/dist/inventory-core.d.ts.map +1 -0
- package/dist/inventory-core.js +69 -0
- package/dist/inventory-core.js.map +1 -0
- package/dist/knowledge-decay.test.d.ts +2 -0
- package/dist/knowledge-decay.test.d.ts.map +1 -0
- package/dist/knowledge-decay.test.js +143 -0
- package/dist/knowledge-decay.test.js.map +1 -0
- package/dist/narrative-authority.d.ts +40 -0
- package/dist/narrative-authority.d.ts.map +1 -0
- package/dist/narrative-authority.js +89 -0
- package/dist/narrative-authority.js.map +1 -0
- package/dist/narrative-authority.test.d.ts +2 -0
- package/dist/narrative-authority.test.d.ts.map +1 -0
- package/dist/narrative-authority.test.js +237 -0
- package/dist/narrative-authority.test.js.map +1 -0
- package/dist/observer-presentation.d.ts +74 -0
- package/dist/observer-presentation.d.ts.map +1 -0
- package/dist/observer-presentation.js +277 -0
- package/dist/observer-presentation.js.map +1 -0
- package/dist/observer-presentation.test.d.ts +2 -0
- package/dist/observer-presentation.test.d.ts.map +1 -0
- package/dist/observer-presentation.test.js +156 -0
- package/dist/observer-presentation.test.js.map +1 -0
- package/dist/perception-filter.d.ts +46 -0
- package/dist/perception-filter.d.ts.map +1 -0
- package/dist/perception-filter.js +281 -0
- package/dist/perception-filter.js.map +1 -0
- package/dist/perception-filter.test.d.ts +2 -0
- package/dist/perception-filter.test.d.ts.map +1 -0
- package/dist/perception-filter.test.js +308 -0
- package/dist/perception-filter.test.js.map +1 -0
- package/dist/progression-core.d.ts +63 -0
- package/dist/progression-core.d.ts.map +1 -0
- package/dist/progression-core.js +232 -0
- package/dist/progression-core.js.map +1 -0
- package/dist/progression-core.test.d.ts +2 -0
- package/dist/progression-core.test.d.ts.map +1 -0
- package/dist/progression-core.test.js +328 -0
- package/dist/progression-core.test.js.map +1 -0
- package/dist/rumor-propagation.d.ts +31 -0
- package/dist/rumor-propagation.d.ts.map +1 -0
- package/dist/rumor-propagation.js +180 -0
- package/dist/rumor-propagation.js.map +1 -0
- package/dist/rumor-propagation.test.d.ts +2 -0
- package/dist/rumor-propagation.test.d.ts.map +1 -0
- package/dist/rumor-propagation.test.js +176 -0
- package/dist/rumor-propagation.test.js.map +1 -0
- package/dist/simulation-inspector.d.ts +78 -0
- package/dist/simulation-inspector.d.ts.map +1 -0
- package/dist/simulation-inspector.js +263 -0
- package/dist/simulation-inspector.js.map +1 -0
- package/dist/simulation-inspector.test.d.ts +2 -0
- package/dist/simulation-inspector.test.d.ts.map +1 -0
- package/dist/simulation-inspector.test.js +152 -0
- package/dist/simulation-inspector.test.js.map +1 -0
- package/dist/status-core.d.ts +17 -0
- package/dist/status-core.d.ts.map +1 -0
- package/dist/status-core.js +106 -0
- package/dist/status-core.js.map +1 -0
- package/dist/traversal-core.d.ts +3 -0
- package/dist/traversal-core.d.ts.map +1 -0
- package/dist/traversal-core.js +93 -0
- package/dist/traversal-core.js.map +1 -0
- package/package.json +34 -0
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { createTestEngine } from '@ai-rpg-engine/core';
|
|
3
|
+
import { createEnvironmentCore, getZoneProperty, setZoneProperty, modifyZoneProperty, getHazardLog, processEnvironmentDecays, } from './environment-core.js';
|
|
4
|
+
import { traversalCore } from './traversal-core.js';
|
|
5
|
+
import { combatCore } from './combat-core.js';
|
|
6
|
+
const makePlayer = (zoneId) => ({
|
|
7
|
+
id: 'player',
|
|
8
|
+
blueprintId: 'player',
|
|
9
|
+
type: 'player',
|
|
10
|
+
name: 'Hero',
|
|
11
|
+
tags: ['player'],
|
|
12
|
+
stats: { vigor: 5, instinct: 5 },
|
|
13
|
+
resources: { hp: 20, stamina: 5 },
|
|
14
|
+
statuses: [],
|
|
15
|
+
zoneId,
|
|
16
|
+
});
|
|
17
|
+
const makeEnemy = (id, zoneId) => ({
|
|
18
|
+
id,
|
|
19
|
+
blueprintId: id,
|
|
20
|
+
type: 'enemy',
|
|
21
|
+
name: id,
|
|
22
|
+
tags: ['enemy'],
|
|
23
|
+
stats: { vigor: 3, instinct: 3 },
|
|
24
|
+
resources: { hp: 5, stamina: 3 },
|
|
25
|
+
statuses: [],
|
|
26
|
+
zoneId,
|
|
27
|
+
});
|
|
28
|
+
describe('Zone property access', () => {
|
|
29
|
+
it('reads base zone property', () => {
|
|
30
|
+
const engine = createTestEngine({
|
|
31
|
+
modules: [createEnvironmentCore()],
|
|
32
|
+
entities: [makePlayer('a')],
|
|
33
|
+
zones: [{ id: 'a', roomId: 'test', name: 'A', tags: [], neighbors: [], light: 7 }],
|
|
34
|
+
});
|
|
35
|
+
expect(getZoneProperty(engine.world, 'a', 'light')).toBe(7);
|
|
36
|
+
expect(getZoneProperty(engine.world, 'a', 'noise')).toBe(0); // Default
|
|
37
|
+
});
|
|
38
|
+
it('sets and reads dynamic zone property', () => {
|
|
39
|
+
const engine = createTestEngine({
|
|
40
|
+
modules: [createEnvironmentCore()],
|
|
41
|
+
entities: [makePlayer('a')],
|
|
42
|
+
zones: [{ id: 'a', roomId: 'test', name: 'A', tags: [], neighbors: [], light: 5 }],
|
|
43
|
+
});
|
|
44
|
+
setZoneProperty(engine.world, 'a', 'noise', 10);
|
|
45
|
+
expect(getZoneProperty(engine.world, 'a', 'noise')).toBe(10);
|
|
46
|
+
});
|
|
47
|
+
it('modifies zone property by delta', () => {
|
|
48
|
+
const engine = createTestEngine({
|
|
49
|
+
modules: [createEnvironmentCore()],
|
|
50
|
+
entities: [makePlayer('a')],
|
|
51
|
+
zones: [{ id: 'a', roomId: 'test', name: 'A', tags: [], neighbors: [], light: 5 }],
|
|
52
|
+
});
|
|
53
|
+
setZoneProperty(engine.world, 'a', 'noise', 3);
|
|
54
|
+
modifyZoneProperty(engine.world, 'a', 'noise', 5);
|
|
55
|
+
expect(getZoneProperty(engine.world, 'a', 'noise')).toBe(8);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
describe('Combat raises noise (built-in rule)', () => {
|
|
59
|
+
it('combat hit increases zone noise', () => {
|
|
60
|
+
const engine = createTestEngine({
|
|
61
|
+
modules: [traversalCore, combatCore, createEnvironmentCore()],
|
|
62
|
+
entities: [makePlayer('a'), makeEnemy('rat', 'a')],
|
|
63
|
+
zones: [{ id: 'a', roomId: 'test', name: 'A', tags: [], neighbors: [] }],
|
|
64
|
+
});
|
|
65
|
+
engine.submitAction('attack', { targetIds: ['rat'] });
|
|
66
|
+
// Combat should have raised noise (hit=3, miss=2)
|
|
67
|
+
const noise = getZoneProperty(engine.world, 'a', 'noise');
|
|
68
|
+
expect(noise).toBeGreaterThan(0);
|
|
69
|
+
});
|
|
70
|
+
it('zone entry adds minor noise', () => {
|
|
71
|
+
const engine = createTestEngine({
|
|
72
|
+
modules: [traversalCore, createEnvironmentCore()],
|
|
73
|
+
entities: [makePlayer('a')],
|
|
74
|
+
zones: [
|
|
75
|
+
{ id: 'a', roomId: 'test', name: 'A', tags: [], neighbors: ['b'] },
|
|
76
|
+
{ id: 'b', roomId: 'test', name: 'B', tags: [], neighbors: ['a'] },
|
|
77
|
+
],
|
|
78
|
+
});
|
|
79
|
+
engine.submitAction('move', { targetIds: ['b'] });
|
|
80
|
+
const noise = getZoneProperty(engine.world, 'b', 'noise');
|
|
81
|
+
expect(noise).toBeGreaterThan(0);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
describe('Noise decay', () => {
|
|
85
|
+
it('noise decays toward baseline over time', () => {
|
|
86
|
+
const engine = createTestEngine({
|
|
87
|
+
modules: [traversalCore, combatCore, createEnvironmentCore()],
|
|
88
|
+
entities: [makePlayer('a'), makeEnemy('rat', 'a')],
|
|
89
|
+
zones: [{ id: 'a', roomId: 'test', name: 'A', tags: [], neighbors: ['b'] },
|
|
90
|
+
{ id: 'b', roomId: 'test', name: 'B', tags: [], neighbors: ['a'] }],
|
|
91
|
+
});
|
|
92
|
+
engine.submitAction('attack', { targetIds: ['rat'] });
|
|
93
|
+
const noiseAfterCombat = getZoneProperty(engine.world, 'a', 'noise');
|
|
94
|
+
expect(noiseAfterCombat).toBeGreaterThan(0);
|
|
95
|
+
// Explicitly process decays (in a game loop, this happens via environment-tick)
|
|
96
|
+
processEnvironmentDecays(engine.world);
|
|
97
|
+
const noiseAfterDecay = getZoneProperty(engine.world, 'a', 'noise');
|
|
98
|
+
expect(noiseAfterDecay).toBeLessThan(noiseAfterCombat);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
describe('Custom environment rules', () => {
|
|
102
|
+
it('custom rule modifies zone property on event', () => {
|
|
103
|
+
const engine = createTestEngine({
|
|
104
|
+
modules: [
|
|
105
|
+
traversalCore,
|
|
106
|
+
createEnvironmentCore({
|
|
107
|
+
rules: [{
|
|
108
|
+
id: 'torch-light',
|
|
109
|
+
eventPattern: 'world.zone.entered',
|
|
110
|
+
property: 'light',
|
|
111
|
+
delta: 2, // Player brings light
|
|
112
|
+
}],
|
|
113
|
+
}),
|
|
114
|
+
],
|
|
115
|
+
entities: [makePlayer('a')],
|
|
116
|
+
zones: [
|
|
117
|
+
{ id: 'a', roomId: 'test', name: 'A', tags: [], neighbors: ['b'] },
|
|
118
|
+
{ id: 'b', roomId: 'test', name: 'B', tags: [], neighbors: ['a'], light: 3 },
|
|
119
|
+
],
|
|
120
|
+
});
|
|
121
|
+
engine.submitAction('move', { targetIds: ['b'] });
|
|
122
|
+
// Light in zone B should have increased by custom rule + base
|
|
123
|
+
const light = getZoneProperty(engine.world, 'b', 'light');
|
|
124
|
+
expect(light).toBe(5); // 3 base + 2 from torch rule
|
|
125
|
+
});
|
|
126
|
+
it('dynamic delta function uses event context', () => {
|
|
127
|
+
const engine = createTestEngine({
|
|
128
|
+
modules: [
|
|
129
|
+
traversalCore,
|
|
130
|
+
combatCore,
|
|
131
|
+
createEnvironmentCore({
|
|
132
|
+
rules: [{
|
|
133
|
+
id: 'blood-stain',
|
|
134
|
+
eventPattern: 'combat.contact.hit',
|
|
135
|
+
property: 'stability',
|
|
136
|
+
delta: (event) => -(event.payload.damage ?? 1),
|
|
137
|
+
}],
|
|
138
|
+
}),
|
|
139
|
+
],
|
|
140
|
+
entities: [makePlayer('a'), makeEnemy('rat', 'a')],
|
|
141
|
+
zones: [{ id: 'a', roomId: 'test', name: 'A', tags: [], neighbors: [], stability: 10 }],
|
|
142
|
+
});
|
|
143
|
+
engine.submitAction('attack', { targetIds: ['rat'] });
|
|
144
|
+
const stability = getZoneProperty(engine.world, 'a', 'stability');
|
|
145
|
+
// Stability should have decreased based on damage dealt
|
|
146
|
+
expect(stability).toBeLessThanOrEqual(10);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
describe('Hazards', () => {
|
|
150
|
+
it('hazard activates when condition is met', () => {
|
|
151
|
+
let hazardTriggered = false;
|
|
152
|
+
let affectedEntity = '';
|
|
153
|
+
const engine = createTestEngine({
|
|
154
|
+
modules: [
|
|
155
|
+
traversalCore,
|
|
156
|
+
createEnvironmentCore({
|
|
157
|
+
hazards: [{
|
|
158
|
+
id: 'exposed-wiring',
|
|
159
|
+
triggerOn: 'world.zone.entered',
|
|
160
|
+
condition: (zone) => zone.hazards?.includes('exposed wiring') ?? false,
|
|
161
|
+
effect: (zone, entity, world, tick) => {
|
|
162
|
+
hazardTriggered = true;
|
|
163
|
+
affectedEntity = entity.id;
|
|
164
|
+
// Deal 2 damage
|
|
165
|
+
entity.resources.hp = Math.max(0, (entity.resources.hp ?? 0) - 2);
|
|
166
|
+
return [{
|
|
167
|
+
id: `hazard-${tick}`,
|
|
168
|
+
tick,
|
|
169
|
+
type: 'environment.hazard.triggered',
|
|
170
|
+
actorId: entity.id,
|
|
171
|
+
payload: {
|
|
172
|
+
hazardId: 'exposed-wiring',
|
|
173
|
+
zoneId: zone.id,
|
|
174
|
+
damage: 2,
|
|
175
|
+
},
|
|
176
|
+
}];
|
|
177
|
+
},
|
|
178
|
+
}],
|
|
179
|
+
}),
|
|
180
|
+
],
|
|
181
|
+
entities: [makePlayer('a')],
|
|
182
|
+
zones: [
|
|
183
|
+
{ id: 'a', roomId: 'test', name: 'A', tags: [], neighbors: ['b'] },
|
|
184
|
+
{ id: 'b', roomId: 'test', name: 'B', tags: ['hazardous'], neighbors: ['a'], hazards: ['exposed wiring'] },
|
|
185
|
+
],
|
|
186
|
+
});
|
|
187
|
+
const hpBefore = engine.player().resources.hp;
|
|
188
|
+
engine.submitAction('move', { targetIds: ['b'] });
|
|
189
|
+
expect(hazardTriggered).toBe(true);
|
|
190
|
+
expect(affectedEntity).toBe('player');
|
|
191
|
+
expect(engine.player().resources.hp).toBe(hpBefore - 2);
|
|
192
|
+
});
|
|
193
|
+
it('hazard log tracks activations', () => {
|
|
194
|
+
const engine = createTestEngine({
|
|
195
|
+
modules: [
|
|
196
|
+
traversalCore,
|
|
197
|
+
createEnvironmentCore({
|
|
198
|
+
hazards: [{
|
|
199
|
+
id: 'ice-floor',
|
|
200
|
+
triggerOn: 'world.zone.entered',
|
|
201
|
+
condition: (zone) => zone.tags.includes('icy'),
|
|
202
|
+
effect: (_zone, _entity, _world, tick) => [],
|
|
203
|
+
}],
|
|
204
|
+
}),
|
|
205
|
+
],
|
|
206
|
+
entities: [makePlayer('a')],
|
|
207
|
+
zones: [
|
|
208
|
+
{ id: 'a', roomId: 'test', name: 'A', tags: [], neighbors: ['b'] },
|
|
209
|
+
{ id: 'b', roomId: 'test', name: 'B', tags: ['icy'], neighbors: ['a'] },
|
|
210
|
+
],
|
|
211
|
+
});
|
|
212
|
+
engine.submitAction('move', { targetIds: ['b'] });
|
|
213
|
+
const log = getHazardLog(engine.world, 'b');
|
|
214
|
+
expect(log.length).toBeGreaterThan(0);
|
|
215
|
+
expect(log[0].hazardId).toBe('ice-floor');
|
|
216
|
+
expect(log[0].entityId).toBe('player');
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
describe('Zone tick effects', () => {
|
|
220
|
+
it('tick effect applies to qualifying zones', () => {
|
|
221
|
+
const regenEvents = [];
|
|
222
|
+
const engine = createTestEngine({
|
|
223
|
+
modules: [
|
|
224
|
+
createEnvironmentCore({
|
|
225
|
+
tickEffects: [{
|
|
226
|
+
id: 'healing-spring',
|
|
227
|
+
condition: (zone) => zone.tags.includes('healing'),
|
|
228
|
+
apply: (zone, world, tick) => {
|
|
229
|
+
// Heal all entities in zone
|
|
230
|
+
for (const entity of Object.values(world.entities)) {
|
|
231
|
+
if (entity.zoneId === zone.id) {
|
|
232
|
+
entity.resources.hp = Math.min(20, (entity.resources.hp ?? 0) + 1);
|
|
233
|
+
regenEvents.push(entity.id);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return [];
|
|
237
|
+
},
|
|
238
|
+
}],
|
|
239
|
+
}),
|
|
240
|
+
],
|
|
241
|
+
entities: [makePlayer('a')],
|
|
242
|
+
zones: [{ id: 'a', roomId: 'test', name: 'A', tags: ['healing'], neighbors: [] }],
|
|
243
|
+
});
|
|
244
|
+
// Manually lower HP
|
|
245
|
+
engine.player().resources.hp = 15;
|
|
246
|
+
// Trigger environment tick
|
|
247
|
+
engine.submitAction('environment-tick', {});
|
|
248
|
+
expect(engine.player().resources.hp).toBe(16);
|
|
249
|
+
expect(regenEvents).toContain('player');
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
//# sourceMappingURL=environment-core.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment-core.test.js","sourceRoot":"","sources":["../src/environment-core.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,OAAO,EACL,q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AAC,CAAC;QAEH,oBAAoB;QACpB,MAAM,CAAC,MAAM,EAAE,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,CAAC;QAElC,2BAA2B;QAC3B,MAAM,CAAC,YAAY,CAAC,kBAAkB,EAAE,EAAE,CAAC,CAAC;QAE5C,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC9C,MAAM,CAAC,WAAW,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { EngineModule, WorldState, ScalarValue } from '@ai-rpg-engine/core';
|
|
2
|
+
export type FactionBelief = {
|
|
3
|
+
subject: string;
|
|
4
|
+
key: string;
|
|
5
|
+
value: ScalarValue;
|
|
6
|
+
confidence: number;
|
|
7
|
+
sourceEntities: string[];
|
|
8
|
+
lastUpdateTick: number;
|
|
9
|
+
distortion: number;
|
|
10
|
+
};
|
|
11
|
+
export type FactionCognitionState = {
|
|
12
|
+
beliefs: FactionBelief[];
|
|
13
|
+
alertLevel: number;
|
|
14
|
+
cohesion: number;
|
|
15
|
+
};
|
|
16
|
+
export type FactionMembership = {
|
|
17
|
+
factionId: string;
|
|
18
|
+
entityIds: string[];
|
|
19
|
+
cohesion?: number;
|
|
20
|
+
};
|
|
21
|
+
export type FactionCognitionConfig = {
|
|
22
|
+
factions: FactionMembership[];
|
|
23
|
+
};
|
|
24
|
+
export declare function createFactionCognition(config: FactionCognitionConfig): EngineModule;
|
|
25
|
+
/** Get cognition state for a faction */
|
|
26
|
+
export declare function getFactionCognition(world: WorldState, factionId: string): FactionCognitionState;
|
|
27
|
+
/** Get the faction an entity belongs to */
|
|
28
|
+
export declare function getEntityFaction(world: WorldState, entityId: string): string | undefined;
|
|
29
|
+
/** Get all entity IDs in a faction */
|
|
30
|
+
export declare function getFactionMembers(world: WorldState, factionId: string): string[];
|
|
31
|
+
/** Set or update a faction belief */
|
|
32
|
+
export declare function setFactionBelief(factionState: FactionCognitionState, subject: string, key: string, value: ScalarValue, confidence: number, sourceEntityId: string, tick: number, distortion?: number): void;
|
|
33
|
+
/** Get a specific faction belief */
|
|
34
|
+
export declare function getFactionBelief(factionState: FactionCognitionState, subject: string, key: string): FactionBelief | undefined;
|
|
35
|
+
/** Check if a faction believes something */
|
|
36
|
+
export declare function factionBelieves(factionState: FactionCognitionState, subject: string, key: string, value?: ScalarValue): boolean;
|
|
37
|
+
/** Get all beliefs about a subject */
|
|
38
|
+
export declare function getFactionBeliefsAbout(factionState: FactionCognitionState, subject: string): FactionBelief[];
|
|
39
|
+
//# sourceMappingURL=faction-cognition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"faction-cognition.d.ts","sourceRoot":"","sources":["../src/faction-cognition.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,YAAY,EACZ,UAAU,EAEV,WAAW,EACZ,MAAM,qBAAqB,CAAC;AAI7B,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,WAAW,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC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ate beliefs from members, producing collective awareness.
|
|
3
|
+
// Entity beliefs propagate to factions via rumor events with delay and distortion.
|
|
4
|
+
// --- Module ---
|
|
5
|
+
export function createFactionCognition(config) {
|
|
6
|
+
const membershipMap = {};
|
|
7
|
+
const factionMembersMap = {};
|
|
8
|
+
const initialCognition = {};
|
|
9
|
+
for (const faction of config.factions) {
|
|
10
|
+
factionMembersMap[faction.factionId] = [...faction.entityIds];
|
|
11
|
+
initialCognition[faction.factionId] = {
|
|
12
|
+
beliefs: [],
|
|
13
|
+
alertLevel: 0,
|
|
14
|
+
cohesion: faction.cohesion ?? 0.8,
|
|
15
|
+
};
|
|
16
|
+
for (const entityId of faction.entityIds) {
|
|
17
|
+
membershipMap[entityId] = faction.factionId;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
id: 'faction-cognition',
|
|
22
|
+
version: '0.1.0',
|
|
23
|
+
dependsOn: ['cognition-core'],
|
|
24
|
+
register(ctx) {
|
|
25
|
+
ctx.persistence.registerNamespace('faction-cognition', {
|
|
26
|
+
factionCognition: initialCognition,
|
|
27
|
+
membership: membershipMap,
|
|
28
|
+
factionMembers: factionMembersMap,
|
|
29
|
+
});
|
|
30
|
+
// Handle rumor propagation events → update faction beliefs
|
|
31
|
+
ctx.events.on('rumor.belief.propagated', (event, world) => {
|
|
32
|
+
handleRumorArrival(event, world);
|
|
33
|
+
});
|
|
34
|
+
// Register faction-tick verb for alert level decay
|
|
35
|
+
ctx.actions.registerVerb('faction-tick', (_action, world) => {
|
|
36
|
+
processFactionTick(world);
|
|
37
|
+
return [];
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
// --- State Access ---
|
|
43
|
+
function getModuleState(world) {
|
|
44
|
+
return (world.modules['faction-cognition'] ?? {
|
|
45
|
+
factionCognition: {},
|
|
46
|
+
membership: {},
|
|
47
|
+
factionMembers: {},
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/** Get cognition state for a faction */
|
|
51
|
+
export function getFactionCognition(world, factionId) {
|
|
52
|
+
const state = getModuleState(world);
|
|
53
|
+
if (!state.factionCognition[factionId]) {
|
|
54
|
+
state.factionCognition[factionId] = {
|
|
55
|
+
beliefs: [],
|
|
56
|
+
alertLevel: 0,
|
|
57
|
+
cohesion: 0.8,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
return state.factionCognition[factionId];
|
|
61
|
+
}
|
|
62
|
+
/** Get the faction an entity belongs to */
|
|
63
|
+
export function getEntityFaction(world, entityId) {
|
|
64
|
+
return getModuleState(world).membership[entityId];
|
|
65
|
+
}
|
|
66
|
+
/** Get all entity IDs in a faction */
|
|
67
|
+
export function getFactionMembers(world, factionId) {
|
|
68
|
+
return getModuleState(world).factionMembers[factionId] ?? [];
|
|
69
|
+
}
|
|
70
|
+
// --- Faction Belief Operations ---
|
|
71
|
+
/** Set or update a faction belief */
|
|
72
|
+
export function setFactionBelief(factionState, subject, key, value, confidence, sourceEntityId, tick, distortion = 0) {
|
|
73
|
+
const existing = factionState.beliefs.find((b) => b.subject === subject && b.key === key);
|
|
74
|
+
if (existing) {
|
|
75
|
+
// Update if higher confidence or significantly newer
|
|
76
|
+
if (confidence >= existing.confidence || tick > existing.lastUpdateTick + 5) {
|
|
77
|
+
existing.value = value;
|
|
78
|
+
existing.confidence = Math.min(1, confidence);
|
|
79
|
+
existing.lastUpdateTick = tick;
|
|
80
|
+
existing.distortion = Math.min(existing.distortion, distortion);
|
|
81
|
+
}
|
|
82
|
+
// Track corroborating sources
|
|
83
|
+
if (!existing.sourceEntities.includes(sourceEntityId)) {
|
|
84
|
+
existing.sourceEntities.push(sourceEntityId);
|
|
85
|
+
// Multiple corroborating sources boost confidence
|
|
86
|
+
existing.confidence = Math.min(1, existing.confidence + 0.05);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
factionState.beliefs.push({
|
|
91
|
+
subject,
|
|
92
|
+
key,
|
|
93
|
+
value,
|
|
94
|
+
confidence,
|
|
95
|
+
sourceEntities: [sourceEntityId],
|
|
96
|
+
lastUpdateTick: tick,
|
|
97
|
+
distortion,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/** Get a specific faction belief */
|
|
102
|
+
export function getFactionBelief(factionState, subject, key) {
|
|
103
|
+
return factionState.beliefs.find((b) => b.subject === subject && b.key === key);
|
|
104
|
+
}
|
|
105
|
+
/** Check if a faction believes something */
|
|
106
|
+
export function factionBelieves(factionState, subject, key, value) {
|
|
107
|
+
const belief = getFactionBelief(factionState, subject, key);
|
|
108
|
+
if (!belief)
|
|
109
|
+
return false;
|
|
110
|
+
if (value !== undefined)
|
|
111
|
+
return belief.value === value;
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
/** Get all beliefs about a subject */
|
|
115
|
+
export function getFactionBeliefsAbout(factionState, subject) {
|
|
116
|
+
return factionState.beliefs.filter((b) => b.subject === subject);
|
|
117
|
+
}
|
|
118
|
+
// --- Internal ---
|
|
119
|
+
function handleRumorArrival(event, world) {
|
|
120
|
+
const { factionId, subject, key, value, confidence, sourceEntityId, distortion, } = event.payload;
|
|
121
|
+
const factionCog = getFactionCognition(world, factionId);
|
|
122
|
+
// Scale confidence by faction cohesion
|
|
123
|
+
const effectiveConfidence = confidence * factionCog.cohesion;
|
|
124
|
+
setFactionBelief(factionCog, subject, key, value, effectiveConfidence, sourceEntityId, event.tick, distortion);
|
|
125
|
+
// Hostile beliefs raise faction alert level
|
|
126
|
+
if (key === 'hostile' && value === true) {
|
|
127
|
+
factionCog.alertLevel = Math.min(100, factionCog.alertLevel + Math.round(20 * effectiveConfidence));
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function processFactionTick(world) {
|
|
131
|
+
const state = getModuleState(world);
|
|
132
|
+
for (const factionCog of Object.values(state.factionCognition)) {
|
|
133
|
+
// Alert level decays slowly
|
|
134
|
+
if (factionCog.alertLevel > 0) {
|
|
135
|
+
factionCog.alertLevel = Math.max(0, factionCog.alertLevel - 2);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=faction-cognition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"faction-cognition.js","sourceRoot":"","sources":["../src/faction-cognition.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,2EAA2E;AAC3E,mFAAmF;AA2CnF,iBAAiB;AAEjB,MAAM,UAAU,sBAAsB,CAAC,MAA8B;IACnE,MAAM,aAAa,GAA2B,EAAE,CAAC;IACjD,MAAM,iBAAiB,GAA6B,EAAE,CAAC;IACvD,MAAM,gBAAgB,GAA0C,EAAE,CAAC;IAEnE,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;QACtC,iBAAiB,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;QAC9D,gBAAgB,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG;YACpC,OAAO,EAAE,EAAE;YACX,UAAU,EAAE,CAAC;YACb,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,GAAG;SAClC,CAAC;QACF,KAAK,MAAM,QAAQ,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;YACzC,aAAa,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC;QAC9C,CAAC;IACH,CAAC;IAED,OAAO;QACL,EAAE,EAAE,mBAAmB;QACvB,OAAO,EAAE,OAAO;QAChB,SAAS,EAAE,CAAC,gBAAgB,CAAC;QAE7B,QAAQ,CAAC,GAAG;YACV,GAAG,CAAC,WAAW,CAAC,iBAAiB,CAAC,mBAAmB,EAAE;gBACrD,gBAAgB,EAAE,gBAAgB;gBAClC,UAAU,EAAE,aAAa;gBACzB,cAAc,EAAE,iBAAiB;aACnB,CAAC,CAAC;YAElB,2DAA2D;YAC3D,GAAG,C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QAAQ,CAAC;IAE7D,gBAAgB,CACd,UAAU,EACV,OAAO,EACP,GAAG,EACH,KAAK,EACL,mBAAmB,EACnB,cAAc,EACd,KAAK,CAAC,IAAI,EACV,UAAU,CACX,CAAC;IAEF,4CAA4C;IAC5C,IAAI,GAAG,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACxC,UAAU,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,CAC9B,GAAG,EACH,UAAU,CAAC,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,mBAAmB,CAAC,CAC7D,CAAC;IACJ,CAAC;AACH,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAiB;IAC3C,MAAM,KAAK,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;IACpC,KAAK,MAAM,UAAU,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAAC,EAAE,CAAC;QAC/D,4BAA4B;QAC5B,IAAI,UAAU,CAAC,UAAU,GAAG,CAAC,EAAE,CAAC;YAC9B,UAAU,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,UAAU,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC;QACjE,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"faction-cognition.test.d.ts","sourceRoot":"","sources":["../src/faction-cognition.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { describe, test, expect } from 'vitest';
|
|
2
|
+
import { createTestEngine } from '@ai-rpg-engine/core';
|
|
3
|
+
import { createCognitionCore } from './cognition-core.js';
|
|
4
|
+
import { createPerceptionFilter } from './perception-filter.js';
|
|
5
|
+
import { createEnvironmentCore } from './environment-core.js';
|
|
6
|
+
import { createFactionCognition, getFactionCognition, getEntityFaction, getFactionMembers, setFactionBelief, getFactionBelief, factionBelieves, getFactionBeliefsAbout, } from './faction-cognition.js';
|
|
7
|
+
function makeGuard(id, zone) {
|
|
8
|
+
return {
|
|
9
|
+
id,
|
|
10
|
+
blueprintId: id,
|
|
11
|
+
type: 'npc',
|
|
12
|
+
name: `Guard ${id}`,
|
|
13
|
+
tags: ['enemy'],
|
|
14
|
+
stats: { vigor: 5, instinct: 6, will: 4 },
|
|
15
|
+
resources: { hp: 20, stamina: 10 },
|
|
16
|
+
statuses: [],
|
|
17
|
+
zoneId: zone,
|
|
18
|
+
ai: { profileId: 'aggressive', goals: ['guard'], fears: [], alertLevel: 0, knowledge: {} },
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const player = {
|
|
22
|
+
id: 'player',
|
|
23
|
+
blueprintId: 'player',
|
|
24
|
+
type: 'player',
|
|
25
|
+
name: 'Hero',
|
|
26
|
+
tags: ['player'],
|
|
27
|
+
stats: { vigor: 7, instinct: 5, will: 5 },
|
|
28
|
+
resources: { hp: 30, stamina: 15 },
|
|
29
|
+
statuses: [],
|
|
30
|
+
zoneId: 'courtyard',
|
|
31
|
+
};
|
|
32
|
+
const zones = [
|
|
33
|
+
{ id: 'courtyard', roomId: 'castle', name: 'Courtyard', tags: [], neighbors: ['gatehouse', 'hall'] },
|
|
34
|
+
{ id: 'gatehouse', roomId: 'castle', name: 'Gatehouse', tags: [], neighbors: ['courtyard'] },
|
|
35
|
+
{ id: 'hall', roomId: 'castle', name: 'Great Hall', tags: [], neighbors: ['courtyard'] },
|
|
36
|
+
];
|
|
37
|
+
describe('faction-cognition', () => {
|
|
38
|
+
function createEngine() {
|
|
39
|
+
return createTestEngine({
|
|
40
|
+
modules: [
|
|
41
|
+
createCognitionCore(),
|
|
42
|
+
createPerceptionFilter(),
|
|
43
|
+
createEnvironmentCore(),
|
|
44
|
+
createFactionCognition({
|
|
45
|
+
factions: [
|
|
46
|
+
{ factionId: 'castle-guard', entityIds: ['guard_1', 'guard_2'], cohesion: 0.9 },
|
|
47
|
+
],
|
|
48
|
+
}),
|
|
49
|
+
],
|
|
50
|
+
entities: [player, makeGuard('guard_1', 'courtyard'), makeGuard('guard_2', 'gatehouse')],
|
|
51
|
+
zones,
|
|
52
|
+
playerId: 'player',
|
|
53
|
+
startZone: 'courtyard',
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
test('initializes faction cognition state', () => {
|
|
57
|
+
const engine = createEngine();
|
|
58
|
+
const factionCog = getFactionCognition(engine.world, 'castle-guard');
|
|
59
|
+
expect(factionCog).toBeDefined();
|
|
60
|
+
expect(factionCog.beliefs).toEqual([]);
|
|
61
|
+
expect(factionCog.alertLevel).toBe(0);
|
|
62
|
+
expect(factionCog.cohesion).toBe(0.9);
|
|
63
|
+
});
|
|
64
|
+
test('tracks entity-faction membership', () => {
|
|
65
|
+
const engine = createEngine();
|
|
66
|
+
expect(getEntityFaction(engine.world, 'guard_1')).toBe('castle-guard');
|
|
67
|
+
expect(getEntityFaction(engine.world, 'guard_2')).toBe('castle-guard');
|
|
68
|
+
expect(getEntityFaction(engine.world, 'player')).toBeUndefined();
|
|
69
|
+
});
|
|
70
|
+
test('returns faction members', () => {
|
|
71
|
+
const engine = createEngine();
|
|
72
|
+
const members = getFactionMembers(engine.world, 'castle-guard');
|
|
73
|
+
expect(members).toContain('guard_1');
|
|
74
|
+
expect(members).toContain('guard_2');
|
|
75
|
+
expect(members).toHaveLength(2);
|
|
76
|
+
});
|
|
77
|
+
test('sets and queries faction beliefs', () => {
|
|
78
|
+
const engine = createEngine();
|
|
79
|
+
const factionCog = getFactionCognition(engine.world, 'castle-guard');
|
|
80
|
+
setFactionBelief(factionCog, 'player', 'hostile', true, 0.7, 'guard_1', 5);
|
|
81
|
+
expect(factionBelieves(factionCog, 'player', 'hostile', true)).toBe(true);
|
|
82
|
+
const belief = getFactionBelief(factionCog, 'player', 'hostile');
|
|
83
|
+
expect(belief?.confidence).toBe(0.7);
|
|
84
|
+
expect(belief?.sourceEntities).toEqual(['guard_1']);
|
|
85
|
+
});
|
|
86
|
+
test('corroborating sources boost confidence', () => {
|
|
87
|
+
const engine = createEngine();
|
|
88
|
+
const factionCog = getFactionCognition(engine.world, 'castle-guard');
|
|
89
|
+
setFactionBelief(factionCog, 'player', 'hostile', true, 0.6, 'guard_1', 5);
|
|
90
|
+
setFactionBelief(factionCog, 'player', 'hostile', true, 0.5, 'guard_2', 6);
|
|
91
|
+
const belief = getFactionBelief(factionCog, 'player', 'hostile');
|
|
92
|
+
expect(belief?.sourceEntities).toContain('guard_1');
|
|
93
|
+
expect(belief?.sourceEntities).toContain('guard_2');
|
|
94
|
+
// Corroboration should boost confidence
|
|
95
|
+
expect(belief.confidence).toBeGreaterThan(0.6);
|
|
96
|
+
});
|
|
97
|
+
test('higher confidence updates override lower', () => {
|
|
98
|
+
const engine = createEngine();
|
|
99
|
+
const factionCog = getFactionCognition(engine.world, 'castle-guard');
|
|
100
|
+
setFactionBelief(factionCog, 'player', 'location', 'courtyard', 0.5, 'guard_1', 5);
|
|
101
|
+
setFactionBelief(factionCog, 'player', 'location', 'hall', 0.8, 'guard_2', 6);
|
|
102
|
+
const belief = getFactionBelief(factionCog, 'player', 'location');
|
|
103
|
+
expect(belief?.value).toBe('hall');
|
|
104
|
+
expect(belief?.confidence).toBeGreaterThanOrEqual(0.8);
|
|
105
|
+
});
|
|
106
|
+
test('getFactionBeliefsAbout returns all beliefs about a subject', () => {
|
|
107
|
+
const engine = createEngine();
|
|
108
|
+
const factionCog = getFactionCognition(engine.world, 'castle-guard');
|
|
109
|
+
setFactionBelief(factionCog, 'player', 'hostile', true, 0.7, 'guard_1', 5);
|
|
110
|
+
setFactionBelief(factionCog, 'player', 'location', 'courtyard', 0.6, 'guard_1', 5);
|
|
111
|
+
const beliefs = getFactionBeliefsAbout(factionCog, 'player');
|
|
112
|
+
expect(beliefs).toHaveLength(2);
|
|
113
|
+
});
|
|
114
|
+
test('rumor.belief.propagated event updates faction beliefs', () => {
|
|
115
|
+
const engine = createEngine();
|
|
116
|
+
engine.drainEvents();
|
|
117
|
+
// Simulate a rumor event arriving
|
|
118
|
+
engine.store.emitEvent('rumor.belief.propagated', {
|
|
119
|
+
factionId: 'castle-guard',
|
|
120
|
+
subject: 'player',
|
|
121
|
+
key: 'hostile',
|
|
122
|
+
value: true,
|
|
123
|
+
confidence: 0.8,
|
|
124
|
+
sourceEntityId: 'guard_1',
|
|
125
|
+
distortion: 0.05,
|
|
126
|
+
originTick: 0,
|
|
127
|
+
hops: 1,
|
|
128
|
+
});
|
|
129
|
+
const factionCog = getFactionCognition(engine.world, 'castle-guard');
|
|
130
|
+
expect(factionBelieves(factionCog, 'player', 'hostile', true)).toBe(true);
|
|
131
|
+
// Confidence scaled by cohesion (0.8 * 0.9 = 0.72)
|
|
132
|
+
const belief = getFactionBelief(factionCog, 'player', 'hostile');
|
|
133
|
+
expect(belief.confidence).toBeCloseTo(0.72, 1);
|
|
134
|
+
});
|
|
135
|
+
test('hostile rumor raises faction alert level', () => {
|
|
136
|
+
const engine = createEngine();
|
|
137
|
+
engine.drainEvents();
|
|
138
|
+
engine.store.emitEvent('rumor.belief.propagated', {
|
|
139
|
+
factionId: 'castle-guard',
|
|
140
|
+
subject: 'player',
|
|
141
|
+
key: 'hostile',
|
|
142
|
+
value: true,
|
|
143
|
+
confidence: 0.9,
|
|
144
|
+
sourceEntityId: 'guard_1',
|
|
145
|
+
distortion: 0.02,
|
|
146
|
+
originTick: 0,
|
|
147
|
+
hops: 1,
|
|
148
|
+
});
|
|
149
|
+
const factionCog = getFactionCognition(engine.world, 'castle-guard');
|
|
150
|
+
expect(factionCog.alertLevel).toBeGreaterThan(0);
|
|
151
|
+
});
|
|
152
|
+
test('faction-tick decays alert level', () => {
|
|
153
|
+
const engine = createEngine();
|
|
154
|
+
const factionCog = getFactionCognition(engine.world, 'castle-guard');
|
|
155
|
+
factionCog.alertLevel = 20;
|
|
156
|
+
engine.submitAction('faction-tick');
|
|
157
|
+
expect(factionCog.alertLevel).toBe(18);
|
|
158
|
+
});
|
|
159
|
+
test('unknown faction returns fresh state', () => {
|
|
160
|
+
const engine = createEngine();
|
|
161
|
+
const factionCog = getFactionCognition(engine.world, 'bandits');
|
|
162
|
+
expect(factionCog.beliefs).toEqual([]);
|
|
163
|
+
expect(factionCog.alertLevel).toBe(0);
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
//# sourceMappingURL=faction-cognition.test.js.map
|