@its-not-rocket-science/ananke 0.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/CHANGELOG.md +135 -0
- package/LICENSE +21 -0
- package/README.md +2199 -0
- package/STABLE_API.md +266 -0
- package/dist/src/anatomy/anatomy-compiler.d.ts +14 -0
- package/dist/src/anatomy/anatomy-compiler.js +277 -0
- package/dist/src/anatomy/anatomy-contracts.d.ts +94 -0
- package/dist/src/anatomy/anatomy-contracts.js +1 -0
- package/dist/src/anatomy/anatomy-helpers.d.ts +82 -0
- package/dist/src/anatomy/anatomy-helpers.js +233 -0
- package/dist/src/anatomy/anatomy-schema.d.ts +28 -0
- package/dist/src/anatomy/anatomy-schema.js +388 -0
- package/dist/src/anatomy/index.d.ts +4 -0
- package/dist/src/anatomy/index.js +4 -0
- package/dist/src/archetypes.d.ts +87 -0
- package/dist/src/archetypes.js +285 -0
- package/dist/src/arena.d.ts +173 -0
- package/dist/src/arena.js +695 -0
- package/dist/src/bridge/bridge-engine.d.ts +46 -0
- package/dist/src/bridge/bridge-engine.js +252 -0
- package/dist/src/bridge/index.d.ts +4 -0
- package/dist/src/bridge/index.js +5 -0
- package/dist/src/bridge/interpolation.d.ts +64 -0
- package/dist/src/bridge/interpolation.js +130 -0
- package/dist/src/bridge/mapping.d.ts +33 -0
- package/dist/src/bridge/mapping.js +54 -0
- package/dist/src/bridge/types.d.ts +94 -0
- package/dist/src/bridge/types.js +2 -0
- package/dist/src/campaign.d.ts +141 -0
- package/dist/src/campaign.js +235 -0
- package/dist/src/channels.d.ts +15 -0
- package/dist/src/channels.js +20 -0
- package/dist/src/chronicle.d.ts +124 -0
- package/dist/src/chronicle.js +232 -0
- package/dist/src/collective-activities.d.ts +154 -0
- package/dist/src/collective-activities.js +247 -0
- package/dist/src/competence/acoustic.d.ts +101 -0
- package/dist/src/competence/acoustic.js +242 -0
- package/dist/src/competence/catalogue.d.ts +30 -0
- package/dist/src/competence/catalogue.js +241 -0
- package/dist/src/competence/crafting.d.ts +35 -0
- package/dist/src/competence/crafting.js +88 -0
- package/dist/src/competence/engineering.d.ts +53 -0
- package/dist/src/competence/engineering.js +108 -0
- package/dist/src/competence/framework.d.ts +68 -0
- package/dist/src/competence/framework.js +694 -0
- package/dist/src/competence/index.d.ts +12 -0
- package/dist/src/competence/index.js +13 -0
- package/dist/src/competence/interspecies.d.ts +81 -0
- package/dist/src/competence/interspecies.js +108 -0
- package/dist/src/competence/language.d.ts +79 -0
- package/dist/src/competence/language.js +115 -0
- package/dist/src/competence/naturalist.d.ts +97 -0
- package/dist/src/competence/naturalist.js +187 -0
- package/dist/src/competence/navigation.d.ts +24 -0
- package/dist/src/competence/navigation.js +48 -0
- package/dist/src/competence/performance.d.ts +125 -0
- package/dist/src/competence/performance.js +210 -0
- package/dist/src/competence/teaching.d.ts +64 -0
- package/dist/src/competence/teaching.js +121 -0
- package/dist/src/competence/willpower.d.ts +74 -0
- package/dist/src/competence/willpower.js +114 -0
- package/dist/src/crafting/index.d.ts +55 -0
- package/dist/src/crafting/index.js +229 -0
- package/dist/src/crafting/manufacturing.d.ts +83 -0
- package/dist/src/crafting/manufacturing.js +165 -0
- package/dist/src/crafting/materials.d.ts +53 -0
- package/dist/src/crafting/materials.js +120 -0
- package/dist/src/crafting/recipes.d.ts +75 -0
- package/dist/src/crafting/recipes.js +233 -0
- package/dist/src/crafting/workshops.d.ts +61 -0
- package/dist/src/crafting/workshops.js +170 -0
- package/dist/src/debug.d.ts +86 -0
- package/dist/src/debug.js +76 -0
- package/dist/src/derive.d.ts +21 -0
- package/dist/src/derive.js +88 -0
- package/dist/src/describe.d.ts +29 -0
- package/dist/src/describe.js +276 -0
- package/dist/src/dialogue.d.ts +122 -0
- package/dist/src/dialogue.js +266 -0
- package/dist/src/dist.d.ts +20 -0
- package/dist/src/dist.js +39 -0
- package/dist/src/downtime.d.ts +89 -0
- package/dist/src/downtime.js +391 -0
- package/dist/src/economy.d.ts +116 -0
- package/dist/src/economy.js +182 -0
- package/dist/src/emotional-contagion.d.ts +142 -0
- package/dist/src/emotional-contagion.js +274 -0
- package/dist/src/equipment.d.ts +206 -0
- package/dist/src/equipment.js +598 -0
- package/dist/src/faction.d.ts +102 -0
- package/dist/src/faction.js +237 -0
- package/dist/src/generate.d.ts +35 -0
- package/dist/src/generate.js +166 -0
- package/dist/src/index.d.ts +42 -0
- package/dist/src/index.js +54 -0
- package/dist/src/inheritance.d.ts +69 -0
- package/dist/src/inheritance.js +136 -0
- package/dist/src/inventory.d.ts +194 -0
- package/dist/src/inventory.js +637 -0
- package/dist/src/item-durability.d.ts +69 -0
- package/dist/src/item-durability.js +308 -0
- package/dist/src/legend.d.ts +97 -0
- package/dist/src/legend.js +269 -0
- package/dist/src/lod.d.ts +9 -0
- package/dist/src/lod.js +84 -0
- package/dist/src/metrics.d.ts +51 -0
- package/dist/src/metrics.js +91 -0
- package/dist/src/model3d.d.ts +138 -0
- package/dist/src/model3d.js +214 -0
- package/dist/src/mythology.d.ts +101 -0
- package/dist/src/mythology.js +308 -0
- package/dist/src/narrative-render.d.ts +42 -0
- package/dist/src/narrative-render.js +194 -0
- package/dist/src/narrative-stress.d.ts +123 -0
- package/dist/src/narrative-stress.js +183 -0
- package/dist/src/narrative.d.ts +44 -0
- package/dist/src/narrative.js +257 -0
- package/dist/src/party.d.ts +70 -0
- package/dist/src/party.js +226 -0
- package/dist/src/polity.d.ts +262 -0
- package/dist/src/polity.js +398 -0
- package/dist/src/presets.d.ts +42 -0
- package/dist/src/presets.js +170 -0
- package/dist/src/progression.d.ts +170 -0
- package/dist/src/progression.js +256 -0
- package/dist/src/quest-generators.d.ts +76 -0
- package/dist/src/quest-generators.js +534 -0
- package/dist/src/quest.d.ts +239 -0
- package/dist/src/quest.js +520 -0
- package/dist/src/relationships-effects.d.ts +75 -0
- package/dist/src/relationships-effects.js +219 -0
- package/dist/src/relationships.d.ts +104 -0
- package/dist/src/relationships.js +347 -0
- package/dist/src/replay.d.ts +47 -0
- package/dist/src/replay.js +82 -0
- package/dist/src/rng.d.ts +9 -0
- package/dist/src/rng.js +37 -0
- package/dist/src/settlement-services.d.ts +67 -0
- package/dist/src/settlement-services.js +267 -0
- package/dist/src/settlement.d.ts +143 -0
- package/dist/src/settlement.js +419 -0
- package/dist/src/sim/action.d.ts +28 -0
- package/dist/src/sim/action.js +12 -0
- package/dist/src/sim/aging.d.ts +95 -0
- package/dist/src/sim/aging.js +243 -0
- package/dist/src/sim/ai/decide.d.ts +10 -0
- package/dist/src/sim/ai/decide.js +267 -0
- package/dist/src/sim/ai/perception.d.ts +12 -0
- package/dist/src/sim/ai/perception.js +54 -0
- package/dist/src/sim/ai/personality.d.ts +54 -0
- package/dist/src/sim/ai/personality.js +202 -0
- package/dist/src/sim/ai/presets.d.ts +2 -0
- package/dist/src/sim/ai/presets.js +28 -0
- package/dist/src/sim/ai/system.d.ts +6 -0
- package/dist/src/sim/ai/system.js +13 -0
- package/dist/src/sim/ai/targeting.d.ts +8 -0
- package/dist/src/sim/ai/targeting.js +42 -0
- package/dist/src/sim/ai/types.d.ts +14 -0
- package/dist/src/sim/ai/types.js +1 -0
- package/dist/src/sim/body.d.ts +9 -0
- package/dist/src/sim/body.js +32 -0
- package/dist/src/sim/bodyplan.d.ts +161 -0
- package/dist/src/sim/bodyplan.js +677 -0
- package/dist/src/sim/capability.d.ts +135 -0
- package/dist/src/sim/capability.js +8 -0
- package/dist/src/sim/combat.d.ts +21 -0
- package/dist/src/sim/combat.js +77 -0
- package/dist/src/sim/commandBuilders.d.ts +11 -0
- package/dist/src/sim/commandBuilders.js +39 -0
- package/dist/src/sim/commands.d.ts +71 -0
- package/dist/src/sim/commands.js +8 -0
- package/dist/src/sim/condition.d.ts +35 -0
- package/dist/src/sim/condition.js +21 -0
- package/dist/src/sim/cone.d.ts +40 -0
- package/dist/src/sim/cone.js +44 -0
- package/dist/src/sim/context.d.ts +68 -0
- package/dist/src/sim/context.js +1 -0
- package/dist/src/sim/density.d.ts +14 -0
- package/dist/src/sim/density.js +33 -0
- package/dist/src/sim/disease.d.ts +141 -0
- package/dist/src/sim/disease.js +353 -0
- package/dist/src/sim/entity.d.ts +251 -0
- package/dist/src/sim/entity.js +19 -0
- package/dist/src/sim/events.d.ts +25 -0
- package/dist/src/sim/events.js +5 -0
- package/dist/src/sim/explosion.d.ts +40 -0
- package/dist/src/sim/explosion.js +40 -0
- package/dist/src/sim/formation-unit.d.ts +138 -0
- package/dist/src/sim/formation-unit.js +197 -0
- package/dist/src/sim/formation.d.ts +12 -0
- package/dist/src/sim/formation.js +54 -0
- package/dist/src/sim/frontage.d.ts +30 -0
- package/dist/src/sim/frontage.js +84 -0
- package/dist/src/sim/grapple.d.ts +100 -0
- package/dist/src/sim/grapple.js +480 -0
- package/dist/src/sim/hazard.d.ts +104 -0
- package/dist/src/sim/hazard.js +201 -0
- package/dist/src/sim/hydrostatic.d.ts +58 -0
- package/dist/src/sim/hydrostatic.js +117 -0
- package/dist/src/sim/impairment.d.ts +20 -0
- package/dist/src/sim/impairment.js +162 -0
- package/dist/src/sim/indexing.d.ts +7 -0
- package/dist/src/sim/indexing.js +7 -0
- package/dist/src/sim/injury.d.ts +54 -0
- package/dist/src/sim/injury.js +66 -0
- package/dist/src/sim/intent.d.ts +26 -0
- package/dist/src/sim/intent.js +7 -0
- package/dist/src/sim/kernel.d.ts +45 -0
- package/dist/src/sim/kernel.js +1992 -0
- package/dist/src/sim/kinds.d.ts +64 -0
- package/dist/src/sim/kinds.js +56 -0
- package/dist/src/sim/knockback.d.ts +50 -0
- package/dist/src/sim/knockback.js +82 -0
- package/dist/src/sim/limb.d.ts +48 -0
- package/dist/src/sim/limb.js +78 -0
- package/dist/src/sim/medical.d.ts +32 -0
- package/dist/src/sim/medical.js +33 -0
- package/dist/src/sim/morale.d.ts +69 -0
- package/dist/src/sim/morale.js +92 -0
- package/dist/src/sim/mount.d.ts +150 -0
- package/dist/src/sim/mount.js +225 -0
- package/dist/src/sim/nutrition.d.ts +74 -0
- package/dist/src/sim/nutrition.js +168 -0
- package/dist/src/sim/occlusion.d.ts +8 -0
- package/dist/src/sim/occlusion.js +71 -0
- package/dist/src/sim/push.d.ts +11 -0
- package/dist/src/sim/push.js +79 -0
- package/dist/src/sim/ranged.d.ts +44 -0
- package/dist/src/sim/ranged.js +69 -0
- package/dist/src/sim/seeds.d.ts +3 -0
- package/dist/src/sim/seeds.js +16 -0
- package/dist/src/sim/sensory-extended.d.ts +103 -0
- package/dist/src/sim/sensory-extended.js +181 -0
- package/dist/src/sim/sensory.d.ts +38 -0
- package/dist/src/sim/sensory.js +109 -0
- package/dist/src/sim/skills.d.ts +70 -0
- package/dist/src/sim/skills.js +69 -0
- package/dist/src/sim/sleep.d.ts +107 -0
- package/dist/src/sim/sleep.js +215 -0
- package/dist/src/sim/spatial.d.ts +8 -0
- package/dist/src/sim/spatial.js +59 -0
- package/dist/src/sim/step/capability.d.ts +8 -0
- package/dist/src/sim/step/capability.js +77 -0
- package/dist/src/sim/step/concentration.d.ts +9 -0
- package/dist/src/sim/step/concentration.js +25 -0
- package/dist/src/sim/step/effects.d.ts +17 -0
- package/dist/src/sim/step/effects.js +96 -0
- package/dist/src/sim/step/energy.d.ts +3 -0
- package/dist/src/sim/step/energy.js +31 -0
- package/dist/src/sim/step/hazards.d.ts +4 -0
- package/dist/src/sim/step/hazards.js +19 -0
- package/dist/src/sim/step/injury.d.ts +10 -0
- package/dist/src/sim/step/injury.js +353 -0
- package/dist/src/sim/step/morale.d.ts +11 -0
- package/dist/src/sim/step/morale.js +130 -0
- package/dist/src/sim/step/movement.d.ts +5 -0
- package/dist/src/sim/step/movement.js +172 -0
- package/dist/src/sim/step/push.d.ts +11 -0
- package/dist/src/sim/step/push.js +79 -0
- package/dist/src/sim/step/substances.d.ts +3 -0
- package/dist/src/sim/step/substances.js +75 -0
- package/dist/src/sim/substance.d.ts +38 -0
- package/dist/src/sim/substance.js +57 -0
- package/dist/src/sim/systemic-toxicology.d.ts +109 -0
- package/dist/src/sim/systemic-toxicology.js +263 -0
- package/dist/src/sim/team.d.ts +9 -0
- package/dist/src/sim/team.js +37 -0
- package/dist/src/sim/tech.d.ts +36 -0
- package/dist/src/sim/tech.js +46 -0
- package/dist/src/sim/terrain.d.ts +121 -0
- package/dist/src/sim/terrain.js +141 -0
- package/dist/src/sim/testing.d.ts +13 -0
- package/dist/src/sim/testing.js +100 -0
- package/dist/src/sim/thermoregulation.d.ts +77 -0
- package/dist/src/sim/thermoregulation.js +161 -0
- package/dist/src/sim/tick.d.ts +3 -0
- package/dist/src/sim/tick.js +3 -0
- package/dist/src/sim/toxicology.d.ts +52 -0
- package/dist/src/sim/toxicology.js +104 -0
- package/dist/src/sim/trace.d.ts +141 -0
- package/dist/src/sim/trace.js +1 -0
- package/dist/src/sim/tuning.d.ts +16 -0
- package/dist/src/sim/tuning.js +42 -0
- package/dist/src/sim/vec3.d.ts +14 -0
- package/dist/src/sim/vec3.js +31 -0
- package/dist/src/sim/weapon_dynamics.d.ts +102 -0
- package/dist/src/sim/weapon_dynamics.js +142 -0
- package/dist/src/sim/weather.d.ts +95 -0
- package/dist/src/sim/weather.js +105 -0
- package/dist/src/sim/world.d.ts +52 -0
- package/dist/src/sim/world.js +1 -0
- package/dist/src/sim/wound-aging.d.ts +120 -0
- package/dist/src/sim/wound-aging.js +223 -0
- package/dist/src/species.d.ts +106 -0
- package/dist/src/species.js +664 -0
- package/dist/src/story-arcs.d.ts +17 -0
- package/dist/src/story-arcs.js +276 -0
- package/dist/src/tech-diffusion.d.ts +80 -0
- package/dist/src/tech-diffusion.js +185 -0
- package/dist/src/traits.d.ts +25 -0
- package/dist/src/traits.js +178 -0
- package/dist/src/types.d.ts +117 -0
- package/dist/src/types.js +1 -0
- package/dist/src/units.d.ts +41 -0
- package/dist/src/units.js +64 -0
- package/dist/src/weapons.d.ts +20 -0
- package/dist/src/weapons.js +824 -0
- package/dist/src/world-generation.d.ts +52 -0
- package/dist/src/world-generation.js +301 -0
- package/package.json +74 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// src/inheritance.ts — Phase 49: Legacy & Inheritance
|
|
2
|
+
//
|
|
3
|
+
// Character death does not end the campaign. An heir:
|
|
4
|
+
// • inherits all equipped items from the deceased's loadout
|
|
5
|
+
// • receives a partial transfer of the deceased's relationship graph
|
|
6
|
+
// • takes possession of the deceased's campaign inventory
|
|
7
|
+
// • is registered in the campaign; the deceased is removed
|
|
8
|
+
//
|
|
9
|
+
// No simulation physics — pure bookkeeping that composes with campaign.ts.
|
|
10
|
+
import { SCALE, q, clampQ, mulDiv } from "./units.js";
|
|
11
|
+
import { establishRelationship } from "./relationships.js";
|
|
12
|
+
// ── Equipment transfer ────────────────────────────────────────────────────────
|
|
13
|
+
/**
|
|
14
|
+
* Move all loadout items from deceased to heir.
|
|
15
|
+
* Heir's existing items are preserved (deceased's items are appended).
|
|
16
|
+
* Deceased's loadout is cleared.
|
|
17
|
+
*
|
|
18
|
+
* @returns Number of items transferred.
|
|
19
|
+
*/
|
|
20
|
+
export function transferEquipment(deceased, heir) {
|
|
21
|
+
const items = deceased.loadout.items;
|
|
22
|
+
const count = items.length;
|
|
23
|
+
heir.loadout.items = [...heir.loadout.items, ...items];
|
|
24
|
+
deceased.loadout.items = [];
|
|
25
|
+
return count;
|
|
26
|
+
}
|
|
27
|
+
// ── Relationship transfer ─────────────────────────────────────────────────────
|
|
28
|
+
/**
|
|
29
|
+
* Partially copy the deceased's relationships to the heir.
|
|
30
|
+
*
|
|
31
|
+
* For each relationship R(deceased, X):
|
|
32
|
+
* heir's trust_Q = R.trust_Q × transferRate_Q
|
|
33
|
+
* heir's affinity_Q = |R.affinity_Q| × transferRate_Q (sign preserved)
|
|
34
|
+
*
|
|
35
|
+
* Existing heir–X relationships are not overwritten.
|
|
36
|
+
* The deceased's relationships are left in the graph unmodified.
|
|
37
|
+
*
|
|
38
|
+
* @returns Number of new heir relationships created.
|
|
39
|
+
*/
|
|
40
|
+
export function transferRelationships(graph, deceasedId, heirId, transferRate_Q) {
|
|
41
|
+
const keys = graph.entityIndex.get(deceasedId);
|
|
42
|
+
if (!keys || keys.size === 0)
|
|
43
|
+
return 0;
|
|
44
|
+
let created = 0;
|
|
45
|
+
for (const key of keys) {
|
|
46
|
+
const rel = graph.relationships.get(key);
|
|
47
|
+
if (!rel)
|
|
48
|
+
continue;
|
|
49
|
+
const otherId = rel.entityA === deceasedId ? rel.entityB : rel.entityA;
|
|
50
|
+
if (otherId === heirId)
|
|
51
|
+
continue;
|
|
52
|
+
// Skip if heir already has a relationship with this entity
|
|
53
|
+
const existingKey = heirId < otherId ? `${heirId}:${otherId}` : `${otherId}:${heirId}`;
|
|
54
|
+
if (graph.relationships.has(existingKey))
|
|
55
|
+
continue;
|
|
56
|
+
const newTrust = clampQ(mulDiv(rel.trust_Q, transferRate_Q, SCALE.Q), q(0), SCALE.Q);
|
|
57
|
+
// Affinity can be negative: scale magnitude, preserve sign
|
|
58
|
+
const rawMag = mulDiv(rel.affinity_Q < 0 ? -rel.affinity_Q : rel.affinity_Q, transferRate_Q, SCALE.Q);
|
|
59
|
+
const newAffinity = clampQ((rel.affinity_Q < 0 ? -rawMag : rawMag), (-SCALE.Q), SCALE.Q);
|
|
60
|
+
establishRelationship(graph, heirId, otherId, 0, newAffinity, newTrust);
|
|
61
|
+
created++;
|
|
62
|
+
}
|
|
63
|
+
return created;
|
|
64
|
+
}
|
|
65
|
+
// ── Inventory transfer ────────────────────────────────────────────────────────
|
|
66
|
+
/**
|
|
67
|
+
* Transfer all campaign inventory items from deceased to heir.
|
|
68
|
+
* Stacks merge: heir's existing counts are summed with deceased's amounts.
|
|
69
|
+
* The deceased's campaign inventory entry is deleted after transfer.
|
|
70
|
+
*
|
|
71
|
+
* @returns Map of transferred items (itemId → count transferred).
|
|
72
|
+
*/
|
|
73
|
+
export function transferInventory(campaign, deceasedId, heirId) {
|
|
74
|
+
const deceasedInv = campaign.entityInventories.get(deceasedId);
|
|
75
|
+
if (!deceasedInv || deceasedInv.size === 0)
|
|
76
|
+
return new Map();
|
|
77
|
+
const transferred = new Map(deceasedInv);
|
|
78
|
+
const heirInv = campaign.entityInventories.get(heirId) ?? new Map();
|
|
79
|
+
for (const [itemId, count] of deceasedInv) {
|
|
80
|
+
heirInv.set(itemId, (heirInv.get(itemId) ?? 0) + count);
|
|
81
|
+
}
|
|
82
|
+
campaign.entityInventories.set(heirId, heirInv);
|
|
83
|
+
campaign.entityInventories.delete(deceasedId);
|
|
84
|
+
return transferred;
|
|
85
|
+
}
|
|
86
|
+
// ── Full inheritance orchestration ────────────────────────────────────────────
|
|
87
|
+
/**
|
|
88
|
+
* Apply the full inheritance process when a character dies and an heir takes over.
|
|
89
|
+
*
|
|
90
|
+
* Steps performed:
|
|
91
|
+
* 1. Transfers loadout equipment from deceased to heir entity.
|
|
92
|
+
* 2. Transfers campaign inventory (deceased → heir, with stack merging).
|
|
93
|
+
* 3. Partially transfers relationships (if `graph` is provided).
|
|
94
|
+
* 4. Moves the deceased's campaign location to the heir.
|
|
95
|
+
* 5. Registers the heir in the campaign; removes the deceased.
|
|
96
|
+
* 6. Logs the event to `campaign.log`.
|
|
97
|
+
*
|
|
98
|
+
* Both deceased (via `campaign.entities`) and heir (provided directly) must be
|
|
99
|
+
* supplied. The deceased entity is updated in-place before being removed so
|
|
100
|
+
* that equipment is properly cleared.
|
|
101
|
+
*
|
|
102
|
+
* @returns InheritanceReport with counts of transferred items and relationships.
|
|
103
|
+
*/
|
|
104
|
+
export function applyInheritance(campaign, graph, spec, heir) {
|
|
105
|
+
const { deceasedId, heirId } = spec;
|
|
106
|
+
const transferRate_Q = spec.relationshipTransferRate_Q ?? q(0.50);
|
|
107
|
+
// 1. Equipment
|
|
108
|
+
const deceased = campaign.entities.get(deceasedId);
|
|
109
|
+
let itemsTransferred = 0;
|
|
110
|
+
if (deceased) {
|
|
111
|
+
itemsTransferred = transferEquipment(deceased, heir);
|
|
112
|
+
}
|
|
113
|
+
// 2. Inventory
|
|
114
|
+
const inventoryTransferred = transferInventory(campaign, deceasedId, heirId);
|
|
115
|
+
// 3. Relationships
|
|
116
|
+
let relationshipsTransferred = 0;
|
|
117
|
+
if (graph) {
|
|
118
|
+
relationshipsTransferred = transferRelationships(graph, deceasedId, heirId, transferRate_Q);
|
|
119
|
+
}
|
|
120
|
+
// 4. Location
|
|
121
|
+
const loc = campaign.entityLocations.get(deceasedId);
|
|
122
|
+
if (loc !== undefined) {
|
|
123
|
+
campaign.entityLocations.set(heirId, loc);
|
|
124
|
+
campaign.entityLocations.delete(deceasedId);
|
|
125
|
+
}
|
|
126
|
+
// 5. Registry update
|
|
127
|
+
campaign.entities.set(heirId, heir);
|
|
128
|
+
if (deceased)
|
|
129
|
+
campaign.entities.delete(deceasedId);
|
|
130
|
+
// 6. Log
|
|
131
|
+
campaign.log.push({
|
|
132
|
+
worldTime_s: campaign.worldTime_s,
|
|
133
|
+
text: `Entity ${heirId} inherits from deceased entity ${deceasedId} (${itemsTransferred} items, ${relationshipsTransferred} relationships).`,
|
|
134
|
+
});
|
|
135
|
+
return { itemsTransferred, relationshipsTransferred, inventoryTransferred };
|
|
136
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import type { Q } from "./units.js";
|
|
2
|
+
import type { IndividualAttributes } from "./types.js";
|
|
3
|
+
/** An instance of an item in the inventory. */
|
|
4
|
+
export interface ItemInstance {
|
|
5
|
+
/** Unique identifier for this specific item instance. */
|
|
6
|
+
instanceId: string;
|
|
7
|
+
/** References the equipment catalogue template. */
|
|
8
|
+
templateId: string;
|
|
9
|
+
/** Stack quantity (for stackable items). */
|
|
10
|
+
quantity: number;
|
|
11
|
+
/** Durability: 1.0 = pristine, 0.0 = broken. Undefined = no durability. */
|
|
12
|
+
durability_Q?: Q | undefined;
|
|
13
|
+
/** Modifications applied to this item. */
|
|
14
|
+
modifications?: ItemMod[] | undefined;
|
|
15
|
+
/** Path to containing container(s), empty if top-level. */
|
|
16
|
+
containerPath: string[];
|
|
17
|
+
}
|
|
18
|
+
/** A container (bag, pouch, backpack) that holds items. */
|
|
19
|
+
export interface Container {
|
|
20
|
+
/** Unique identifier within the inventory. */
|
|
21
|
+
containerId: string;
|
|
22
|
+
/** Display name. */
|
|
23
|
+
name: string;
|
|
24
|
+
/** Maximum weight capacity in kg (scaled by SCALE.kg). */
|
|
25
|
+
capacity_Kg: number;
|
|
26
|
+
/** Optional volume capacity in litres. */
|
|
27
|
+
volume_L?: number | undefined;
|
|
28
|
+
/** Items stored directly in this container. */
|
|
29
|
+
items: ItemInstance[];
|
|
30
|
+
/** Whether this container is currently equipped/accessible. */
|
|
31
|
+
isEquipped: boolean;
|
|
32
|
+
/** Base mass of the empty container itself. */
|
|
33
|
+
emptyMass_kg: number;
|
|
34
|
+
}
|
|
35
|
+
/** A record of equipped items by slot. */
|
|
36
|
+
export interface EquippedItems {
|
|
37
|
+
/** Weapon in main hand. */
|
|
38
|
+
mainHand?: ItemInstance;
|
|
39
|
+
/** Weapon/shield in off hand. */
|
|
40
|
+
offHand?: ItemInstance;
|
|
41
|
+
/** Body armour. */
|
|
42
|
+
body?: ItemInstance;
|
|
43
|
+
/** Head protection. */
|
|
44
|
+
head?: ItemInstance;
|
|
45
|
+
/** Container slots (back, belt, etc.). */
|
|
46
|
+
containers: Map<string, ItemInstance>;
|
|
47
|
+
}
|
|
48
|
+
/** Complete inventory for an entity. */
|
|
49
|
+
export interface Inventory {
|
|
50
|
+
/** Owner entity ID. */
|
|
51
|
+
ownerId: number;
|
|
52
|
+
/** All containers owned (equipped or not). */
|
|
53
|
+
containers: Container[];
|
|
54
|
+
/** Currently equipped items. */
|
|
55
|
+
equipped: EquippedItems;
|
|
56
|
+
/** Total encumbrance in kg (scaled). */
|
|
57
|
+
encumbrance_Kg: number;
|
|
58
|
+
/** Maximum encumbrance based on strength. */
|
|
59
|
+
maxEncumbrance_Kg: number;
|
|
60
|
+
/** Currency/money (if applicable). */
|
|
61
|
+
currency?: number;
|
|
62
|
+
}
|
|
63
|
+
/** Item modification types. */
|
|
64
|
+
export interface ItemMod {
|
|
65
|
+
type: "sharpened" | "reinforced" | "enchanted" | "damaged" | "masterwork";
|
|
66
|
+
/** Display name of the modification. */
|
|
67
|
+
name: string;
|
|
68
|
+
/** Effects on item stats (applied as multipliers). */
|
|
69
|
+
statMultipliers?: {
|
|
70
|
+
damageMul?: Q;
|
|
71
|
+
durabilityMul?: Q;
|
|
72
|
+
weightMul?: Q;
|
|
73
|
+
valueMul?: Q;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
export type EncumbranceCategory = "unencumbered" | "light" | "medium" | "heavy" | "overloaded";
|
|
77
|
+
export interface EncumbranceCategoryDef {
|
|
78
|
+
category: EncumbranceCategory;
|
|
79
|
+
maxRatio: number;
|
|
80
|
+
penalties: InventoryEncumbrancePenalties;
|
|
81
|
+
}
|
|
82
|
+
export interface InventoryEncumbrancePenalties {
|
|
83
|
+
/** Fine control penalty (affects combat precision). */
|
|
84
|
+
fineControlPenalty_Q: Q;
|
|
85
|
+
/** Dodge/parry latency increase as multiplier. */
|
|
86
|
+
dodgeParryLatencyMul: Q;
|
|
87
|
+
/** Movement speed multiplier. */
|
|
88
|
+
speedMul: Q;
|
|
89
|
+
/** Cannot sprint if true. */
|
|
90
|
+
noSprint: boolean;
|
|
91
|
+
/** Cannot move if true. */
|
|
92
|
+
noMove: boolean;
|
|
93
|
+
}
|
|
94
|
+
export declare const ENCUMBRANCE_CATEGORIES: EncumbranceCategoryDef[];
|
|
95
|
+
/** Create an empty inventory for an entity. */
|
|
96
|
+
export declare function createInventory(ownerId: number): Inventory;
|
|
97
|
+
/** Create a new container. */
|
|
98
|
+
export declare function createContainer(containerId: string, name: string, capacity_Kg: number, emptyMass_kg: number, volume_L?: number): Container;
|
|
99
|
+
/**
|
|
100
|
+
* Calculate maximum encumbrance based on physical strength.
|
|
101
|
+
* Stronger characters can carry more absolute weight.
|
|
102
|
+
*/
|
|
103
|
+
export declare function calculateMaxEncumbrance_Kg(attributes: IndividualAttributes, capacityFactor?: Q): number;
|
|
104
|
+
/** Calculate total weight of items in a container (including container itself). */
|
|
105
|
+
export declare function calculateContainerWeight(container: Container): number;
|
|
106
|
+
/** Get mass of a single item instance (including modifications). */
|
|
107
|
+
export declare function getItemInstanceMass(item: ItemInstance): number;
|
|
108
|
+
/** Calculate total encumbrance for an inventory. */
|
|
109
|
+
export declare function calculateTotalEncumbrance(inventory: Inventory): number;
|
|
110
|
+
/** Recalculate encumbrance and update inventory. */
|
|
111
|
+
export declare function recalculateEncumbrance(inventory: Inventory, attributes: IndividualAttributes): void;
|
|
112
|
+
/** Get the encumbrance category and penalties for current load. */
|
|
113
|
+
export declare function getEncumbranceCategory(inventory: Inventory): EncumbranceCategoryDef;
|
|
114
|
+
/** Get effective encumbrance penalties (combines with any existing penalties). */
|
|
115
|
+
export declare function getEffectiveEncumbrancePenalties(inventory: Inventory, baseFineControl: Q): {
|
|
116
|
+
category: EncumbranceCategory;
|
|
117
|
+
penalties: InventoryEncumbrancePenalties;
|
|
118
|
+
effectiveFineControl: Q;
|
|
119
|
+
};
|
|
120
|
+
/** Add a container to inventory. */
|
|
121
|
+
export declare function addContainer(inventory: Inventory, container: Container): void;
|
|
122
|
+
/** Remove a container from inventory. */
|
|
123
|
+
export declare function removeContainer(inventory: Inventory, containerId: string): boolean;
|
|
124
|
+
/** Equip/unequip a container. */
|
|
125
|
+
export declare function setContainerEquipped(inventory: Inventory, containerId: string, equipped: boolean): boolean;
|
|
126
|
+
/** Find a container by ID. */
|
|
127
|
+
export declare function findContainer(inventory: Inventory, containerId: string): Container | undefined;
|
|
128
|
+
/** Add an item to a specific container. */
|
|
129
|
+
export declare function addItemToContainer(container: Container, item: ItemInstance): {
|
|
130
|
+
success: boolean;
|
|
131
|
+
reason?: string;
|
|
132
|
+
};
|
|
133
|
+
/** Remove an item from a container by instance ID. */
|
|
134
|
+
export declare function removeItemFromContainer(container: Container, instanceId: string): ItemInstance | undefined;
|
|
135
|
+
/** Find an item anywhere in the inventory. */
|
|
136
|
+
export declare function findItem(inventory: Inventory, instanceId: string): {
|
|
137
|
+
item: ItemInstance;
|
|
138
|
+
container: Container | null;
|
|
139
|
+
} | undefined;
|
|
140
|
+
/** Move an item between containers. */
|
|
141
|
+
export declare function moveItem(inventory: Inventory, itemId: string, fromContainerId: string | null, // null = equipped
|
|
142
|
+
toContainerId: string): {
|
|
143
|
+
success: boolean;
|
|
144
|
+
reason?: string;
|
|
145
|
+
};
|
|
146
|
+
/** Equip an item from a container to an equipment slot. */
|
|
147
|
+
export declare function equipItem(inventory: Inventory, itemId: string, slot: "mainHand" | "offHand" | "body" | "head"): {
|
|
148
|
+
success: boolean;
|
|
149
|
+
reason?: string | undefined;
|
|
150
|
+
previousItem?: ItemInstance | undefined;
|
|
151
|
+
};
|
|
152
|
+
/** Unequip an item and return it to a container. */
|
|
153
|
+
export declare function unequipItem(inventory: Inventory, slot: "mainHand" | "offHand" | "body" | "head", targetContainerId?: string): {
|
|
154
|
+
success: boolean;
|
|
155
|
+
reason?: string | undefined;
|
|
156
|
+
item?: ItemInstance | undefined;
|
|
157
|
+
};
|
|
158
|
+
/**
|
|
159
|
+
* Count items in inventory by template ID.
|
|
160
|
+
* Searches all containers and equipped items.
|
|
161
|
+
*/
|
|
162
|
+
export declare function getItemCountByTemplateId(inventory: Inventory, templateId: string): number;
|
|
163
|
+
/**
|
|
164
|
+
* Find all material items of a specific material type.
|
|
165
|
+
* Returns an array of Material items (requires kind "material" and materialTypeId).
|
|
166
|
+
* Note: This assumes ItemInstance can be cast to Material if kind === "material".
|
|
167
|
+
* The caller must ensure the item is a material.
|
|
168
|
+
*/
|
|
169
|
+
export declare function findMaterialsByType(inventory: Inventory, materialTypeId: string): ItemInstance[];
|
|
170
|
+
/**
|
|
171
|
+
* Consume items by template ID, removing them from inventory.
|
|
172
|
+
* Returns true if enough items were found and consumed.
|
|
173
|
+
*/
|
|
174
|
+
export declare function consumeItemsByTemplateId(inventory: Inventory, templateId: string, quantity: number): boolean;
|
|
175
|
+
/**
|
|
176
|
+
* Add an item to inventory, attempting to place it in a suitable container.
|
|
177
|
+
* Prefers equipped containers with sufficient capacity.
|
|
178
|
+
* Returns success and the container it was added to (or null if equipped).
|
|
179
|
+
*/
|
|
180
|
+
export declare function addItemToInventory(inventory: Inventory, item: ItemInstance): {
|
|
181
|
+
success: boolean;
|
|
182
|
+
container: Container | null;
|
|
183
|
+
reason?: string;
|
|
184
|
+
};
|
|
185
|
+
/** Apply a modification to an item. */
|
|
186
|
+
export declare function applyItemMod(item: ItemInstance, mod: ItemMod): void;
|
|
187
|
+
/** Remove a modification from an item. */
|
|
188
|
+
export declare function removeItemMod(item: ItemInstance, modType: ItemMod["type"]): boolean;
|
|
189
|
+
/** Get effective stat multiplier from all modifications. */
|
|
190
|
+
export declare function getItemStatMultiplier(item: ItemInstance, stat: keyof NonNullable<ItemMod["statMultipliers"]>): Q;
|
|
191
|
+
/** Serialize inventory to JSON-friendly format. */
|
|
192
|
+
export declare function serializeInventory(inventory: Inventory): unknown;
|
|
193
|
+
/** Deserialize inventory. */
|
|
194
|
+
export declare function deserializeInventory(data: unknown): Inventory;
|