@phalanx-engine/abilities 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.
Files changed (152) hide show
  1. package/README.md +564 -0
  2. package/dist/api/AbilitySystemFacade.d.ts +34 -0
  3. package/dist/api/AbilitySystemFacade.d.ts.map +1 -0
  4. package/dist/api/AbilitySystemFacade.js +213 -0
  5. package/dist/api/createAbilitySystem.d.ts +49 -0
  6. package/dist/api/createAbilitySystem.d.ts.map +1 -0
  7. package/dist/api/createAbilitySystem.js +205 -0
  8. package/dist/api/defineAbility.d.ts +3 -0
  9. package/dist/api/defineAbility.d.ts.map +1 -0
  10. package/dist/api/defineAbility.js +9 -0
  11. package/dist/api/defineAbilitySystem.d.ts +8 -0
  12. package/dist/api/defineAbilitySystem.d.ts.map +1 -0
  13. package/dist/api/defineAbilitySystem.js +7 -0
  14. package/dist/api/defineAttribute.d.ts +3 -0
  15. package/dist/api/defineAttribute.d.ts.map +1 -0
  16. package/dist/api/defineAttribute.js +3 -0
  17. package/dist/api/defineEffect.d.ts +6 -0
  18. package/dist/api/defineEffect.d.ts.map +1 -0
  19. package/dist/api/defineEffect.js +23 -0
  20. package/dist/api/index.d.ts +11 -0
  21. package/dist/api/index.d.ts.map +1 -0
  22. package/dist/api/index.js +6 -0
  23. package/dist/components/AbilitiesComponentType.d.ts +7 -0
  24. package/dist/components/AbilitiesComponentType.d.ts.map +1 -0
  25. package/dist/components/AbilitiesComponentType.js +7 -0
  26. package/dist/components/AbilitySystemComponent.d.ts +17 -0
  27. package/dist/components/AbilitySystemComponent.d.ts.map +1 -0
  28. package/dist/components/AbilitySystemComponent.js +31 -0
  29. package/dist/components/ActiveEffectsComponent.d.ts +12 -0
  30. package/dist/components/ActiveEffectsComponent.d.ts.map +1 -0
  31. package/dist/components/ActiveEffectsComponent.js +6 -0
  32. package/dist/components/AttributesComponent.d.ts +9 -0
  33. package/dist/components/AttributesComponent.d.ts.map +1 -0
  34. package/dist/components/AttributesComponent.js +15 -0
  35. package/dist/components/GameplayTagsComponent.d.ts +8 -0
  36. package/dist/components/GameplayTagsComponent.d.ts.map +1 -0
  37. package/dist/components/GameplayTagsComponent.js +7 -0
  38. package/dist/components/index.d.ts +7 -0
  39. package/dist/components/index.d.ts.map +1 -0
  40. package/dist/components/index.js +5 -0
  41. package/dist/cues/Cue.d.ts +15 -0
  42. package/dist/cues/Cue.d.ts.map +1 -0
  43. package/dist/cues/Cue.js +7 -0
  44. package/dist/cues/index.d.ts +3 -0
  45. package/dist/cues/index.d.ts.map +1 -0
  46. package/dist/cues/index.js +1 -0
  47. package/dist/events/AbilityEvents.d.ts +10 -0
  48. package/dist/events/AbilityEvents.d.ts.map +1 -0
  49. package/dist/events/AbilityEvents.js +1 -0
  50. package/dist/events/CueEvents.d.ts +5 -0
  51. package/dist/events/CueEvents.d.ts.map +1 -0
  52. package/dist/events/CueEvents.js +4 -0
  53. package/dist/events/index.d.ts +5 -0
  54. package/dist/events/index.d.ts.map +1 -0
  55. package/dist/events/index.js +2 -0
  56. package/dist/index.d.ts +10 -0
  57. package/dist/index.d.ts.map +1 -0
  58. package/dist/index.js +9 -0
  59. package/dist/registry/AbilityHooksRegistry.d.ts +10 -0
  60. package/dist/registry/AbilityHooksRegistry.d.ts.map +1 -0
  61. package/dist/registry/AbilityHooksRegistry.js +25 -0
  62. package/dist/registry/AbilityRegistry.d.ts +6 -0
  63. package/dist/registry/AbilityRegistry.d.ts.map +1 -0
  64. package/dist/registry/AbilityRegistry.js +4 -0
  65. package/dist/registry/AbilitySystemRegistries.d.ts +12 -0
  66. package/dist/registry/AbilitySystemRegistries.d.ts.map +1 -0
  67. package/dist/registry/AbilitySystemRegistries.js +12 -0
  68. package/dist/registry/AttributeRegistry.d.ts +7 -0
  69. package/dist/registry/AttributeRegistry.d.ts.map +1 -0
  70. package/dist/registry/AttributeRegistry.js +11 -0
  71. package/dist/registry/DefinitionRegistry.d.ts +16 -0
  72. package/dist/registry/DefinitionRegistry.d.ts.map +1 -0
  73. package/dist/registry/DefinitionRegistry.js +37 -0
  74. package/dist/registry/EffectRegistry.d.ts +6 -0
  75. package/dist/registry/EffectRegistry.d.ts.map +1 -0
  76. package/dist/registry/EffectRegistry.js +4 -0
  77. package/dist/registry/index.d.ts +7 -0
  78. package/dist/registry/index.d.ts.map +1 -0
  79. package/dist/registry/index.js +5 -0
  80. package/dist/runtime/AbilitySystemRuntime.d.ts +26 -0
  81. package/dist/runtime/AbilitySystemRuntime.d.ts.map +1 -0
  82. package/dist/runtime/AbilitySystemRuntime.js +11 -0
  83. package/dist/runtime/GameplayCueBuffer.d.ts +10 -0
  84. package/dist/runtime/GameplayCueBuffer.d.ts.map +1 -0
  85. package/dist/runtime/GameplayCueBuffer.js +16 -0
  86. package/dist/runtime/InstanceIdCounter.d.ts +6 -0
  87. package/dist/runtime/InstanceIdCounter.d.ts.map +1 -0
  88. package/dist/runtime/InstanceIdCounter.js +10 -0
  89. package/dist/runtime/index.d.ts +6 -0
  90. package/dist/runtime/index.d.ts.map +1 -0
  91. package/dist/runtime/index.js +3 -0
  92. package/dist/systems/AbilityActivationSystem.d.ts +23 -0
  93. package/dist/systems/AbilityActivationSystem.d.ts.map +1 -0
  94. package/dist/systems/AbilityActivationSystem.js +277 -0
  95. package/dist/systems/AbilityHookExecutorSystem.d.ts +10 -0
  96. package/dist/systems/AbilityHookExecutorSystem.d.ts.map +1 -0
  97. package/dist/systems/AbilityHookExecutorSystem.js +35 -0
  98. package/dist/systems/AttributeAggregationSystem.d.ts +12 -0
  99. package/dist/systems/AttributeAggregationSystem.d.ts.map +1 -0
  100. package/dist/systems/AttributeAggregationSystem.js +117 -0
  101. package/dist/systems/CueBufferCleanupSystem.d.ts +8 -0
  102. package/dist/systems/CueBufferCleanupSystem.d.ts.map +1 -0
  103. package/dist/systems/CueBufferCleanupSystem.js +11 -0
  104. package/dist/systems/CueDispatchSystem.d.ts +8 -0
  105. package/dist/systems/CueDispatchSystem.d.ts.map +1 -0
  106. package/dist/systems/CueDispatchSystem.js +17 -0
  107. package/dist/systems/CuePresentationSystem.d.ts +14 -0
  108. package/dist/systems/CuePresentationSystem.d.ts.map +1 -0
  109. package/dist/systems/CuePresentationSystem.js +50 -0
  110. package/dist/systems/EffectApplicationSystem.d.ts +20 -0
  111. package/dist/systems/EffectApplicationSystem.d.ts.map +1 -0
  112. package/dist/systems/EffectApplicationSystem.js +174 -0
  113. package/dist/systems/EffectTickSystem.d.ts +16 -0
  114. package/dist/systems/EffectTickSystem.d.ts.map +1 -0
  115. package/dist/systems/EffectTickSystem.js +152 -0
  116. package/dist/systems/index.d.ts +9 -0
  117. package/dist/systems/index.d.ts.map +1 -0
  118. package/dist/systems/index.js +8 -0
  119. package/dist/targeting/TargetResolver.d.ts +19 -0
  120. package/dist/targeting/TargetResolver.d.ts.map +1 -0
  121. package/dist/targeting/TargetResolver.js +45 -0
  122. package/dist/targeting/index.d.ts +3 -0
  123. package/dist/targeting/index.d.ts.map +1 -0
  124. package/dist/targeting/index.js +1 -0
  125. package/dist/types/AbilityDef.d.ts +13 -0
  126. package/dist/types/AbilityDef.d.ts.map +1 -0
  127. package/dist/types/AbilityDef.js +1 -0
  128. package/dist/types/AbilityHook.d.ts +10 -0
  129. package/dist/types/AbilityHook.d.ts.map +1 -0
  130. package/dist/types/AbilityHook.js +1 -0
  131. package/dist/types/ActiveEffectInstance.d.ts +9 -0
  132. package/dist/types/ActiveEffectInstance.d.ts.map +1 -0
  133. package/dist/types/ActiveEffectInstance.js +1 -0
  134. package/dist/types/AttributeDef.d.ts +10 -0
  135. package/dist/types/AttributeDef.d.ts.map +1 -0
  136. package/dist/types/AttributeDef.js +1 -0
  137. package/dist/types/CueEvent.d.ts +9 -0
  138. package/dist/types/CueEvent.d.ts.map +1 -0
  139. package/dist/types/CueEvent.js +1 -0
  140. package/dist/types/EffectDef.d.ts +23 -0
  141. package/dist/types/EffectDef.d.ts.map +1 -0
  142. package/dist/types/EffectDef.js +17 -0
  143. package/dist/types/ModifierOp.d.ts +8 -0
  144. package/dist/types/ModifierOp.d.ts.map +1 -0
  145. package/dist/types/ModifierOp.js +1 -0
  146. package/dist/types/TargetSpec.d.ts +32 -0
  147. package/dist/types/TargetSpec.d.ts.map +1 -0
  148. package/dist/types/TargetSpec.js +1 -0
  149. package/dist/types/index.d.ts +10 -0
  150. package/dist/types/index.d.ts.map +1 -0
  151. package/dist/types/index.js +1 -0
  152. package/package.json +54 -0
@@ -0,0 +1,174 @@
1
+ import { GameSystem } from '@phalanx-engine/ecs';
2
+ import { FP } from '@phalanx-engine/math';
3
+ import { AbilitiesComponentType, GameplayTagsComponent, getActiveEffectsComponent, getAttributesComponent, getGameplayTagsComponent, } from '../components';
4
+ import { appendGameplayCueEvents } from '../runtime';
5
+ export class EffectApplicationSystem extends GameSystem {
6
+ registries;
7
+ runtime;
8
+ constructor(registries, runtime) {
9
+ super();
10
+ this.registries = registries;
11
+ this.runtime = runtime;
12
+ }
13
+ processTick(tick) {
14
+ const entities = this.entityManager.queryEntitiesAny(AbilitiesComponentType.AbilitySystem, AbilitiesComponentType.ActiveEffects);
15
+ const attributeIndexCache = this.attributeIndexCache;
16
+ attributeIndexCache.clear();
17
+ for (const entity of entities) {
18
+ const activeEffects = getActiveEffectsComponent(entity);
19
+ if (!activeEffects || activeEffects.pendingAdd.length === 0) {
20
+ continue;
21
+ }
22
+ const drained = activeEffects.pendingAdd.splice(0, activeEffects.pendingAdd.length);
23
+ for (let i = 0; i < drained.length; i++) {
24
+ this.applyOne(entity, drained[i], attributeIndexCache, tick);
25
+ }
26
+ }
27
+ }
28
+ attributeIndexCache = new Map();
29
+ applyOne(entity, pending, attributeIndexCache, tick) {
30
+ const effectDef = this.registries.effects.tryGet(pending.defId);
31
+ if (!effectDef) {
32
+ throw new Error(`EffectRegistry does not contain '${pending.defId}'`);
33
+ }
34
+ const tags = this.getOrCreateTags(entity);
35
+ if (!this.checkTagPredicates(effectDef, tags)) {
36
+ return;
37
+ }
38
+ this.validateEffectOrThrow(effectDef, attributeIndexCache);
39
+ this.grantTags(effectDef, tags);
40
+ switch (effectDef.type) {
41
+ case 'Instant':
42
+ this.applyInstant(entity, effectDef, attributeIndexCache);
43
+ appendGameplayCueEvents(this.runtime.gameplayCueBuffer, effectDef.cues, 'OnApplied', tick, pending.sourceEntityId, entity.id);
44
+ return;
45
+ case 'Duration':
46
+ case 'Periodic':
47
+ this.queueDurational(entity, effectDef, pending, attributeIndexCache, tick);
48
+ appendGameplayCueEvents(this.runtime.gameplayCueBuffer, effectDef.cues, 'OnApplied', tick, pending.sourceEntityId, entity.id);
49
+ if (effectDef.type === 'Periodic' &&
50
+ effectDef.executePeriodicOnApplication === true) {
51
+ this.applyInstant(entity, effectDef, attributeIndexCache);
52
+ appendGameplayCueEvents(this.runtime.gameplayCueBuffer, effectDef.cues, 'OnPeriodic', tick, pending.sourceEntityId, entity.id);
53
+ }
54
+ return;
55
+ }
56
+ }
57
+ validateEffectOrThrow(effectDef, attributeIndexCache) {
58
+ if (effectDef.type === 'Duration' || effectDef.type === 'Periodic') {
59
+ const durationTicks = effectDef.durationTicks;
60
+ if (durationTicks === undefined || durationTicks <= 0) {
61
+ throw new Error(`EffectDef '${effectDef.id}' is type '${effectDef.type}' but has invalid durationTicks=${String(durationTicks)}`);
62
+ }
63
+ }
64
+ if (effectDef.type === 'Periodic') {
65
+ const periodTicks = effectDef.periodTicks;
66
+ if (periodTicks === undefined || periodTicks <= 0) {
67
+ throw new Error(`EffectDef '${effectDef.id}' is type 'Periodic' but has invalid periodTicks=${String(periodTicks)}`);
68
+ }
69
+ }
70
+ for (const modifier of effectDef.modifiers) {
71
+ this.resolveAttributeIndex(modifier.attributeId, attributeIndexCache);
72
+ }
73
+ }
74
+ checkTagPredicates(effectDef, tags) {
75
+ if (effectDef.tagsRequired) {
76
+ for (const tag of effectDef.tagsRequired) {
77
+ if (!tags.tags.has(tag)) {
78
+ return false;
79
+ }
80
+ }
81
+ }
82
+ if (effectDef.tagsBlocked) {
83
+ for (const tag of effectDef.tagsBlocked) {
84
+ if (tags.tags.has(tag)) {
85
+ return false;
86
+ }
87
+ }
88
+ }
89
+ return true;
90
+ }
91
+ grantTags(effectDef, tags) {
92
+ if (!effectDef.tagsGranted) {
93
+ return;
94
+ }
95
+ for (const tag of effectDef.tagsGranted) {
96
+ const current = tags.effectGrantCounts.get(tag) ?? 0;
97
+ tags.effectGrantCounts.set(tag, current + 1);
98
+ tags.tags.add(tag);
99
+ }
100
+ }
101
+ applyInstant(entity, effectDef, attributeIndexCache) {
102
+ const attributes = getAttributesComponent(entity);
103
+ if (!attributes) {
104
+ return;
105
+ }
106
+ for (const modifier of effectDef.modifiers) {
107
+ const index = this.resolveAttributeIndex(modifier.attributeId, attributeIndexCache);
108
+ const current = FP.FromRaw(attributes.base[index]);
109
+ const next = applyInstantModifier(current, modifier.op, modifier.magnitude);
110
+ attributes.base[index] = FP.ToRaw(next);
111
+ attributes.dirty[index] = 1;
112
+ }
113
+ }
114
+ queueDurational(entity, effectDef, pending, attributeIndexCache, tick) {
115
+ const activeEffects = getActiveEffectsComponent(entity);
116
+ if (!activeEffects) {
117
+ throw new Error('ActiveEffectsComponent missing while draining pendingAdd');
118
+ }
119
+ const durationTicksValidated = effectDef.durationTicks;
120
+ const nextPeriodTick = effectDef.type === 'Periodic' ? tick + effectDef.periodTicks : 0;
121
+ const instance = {
122
+ instanceId: this.runtime.instanceIdCounter.next(),
123
+ defId: effectDef.id,
124
+ remainingTicks: durationTicksValidated,
125
+ nextPeriodTick,
126
+ sourceEntityId: pending.sourceEntityId,
127
+ enteredOnTick: tick,
128
+ };
129
+ activeEffects.queue.push(instance);
130
+ this.markAttributesDirty(entity, effectDef.modifiers, attributeIndexCache);
131
+ }
132
+ markAttributesDirty(entity, modifiers, attributeIndexCache) {
133
+ if (modifiers.length === 0) {
134
+ return;
135
+ }
136
+ const attributes = getAttributesComponent(entity);
137
+ if (!attributes) {
138
+ return;
139
+ }
140
+ for (const modifier of modifiers) {
141
+ const index = this.resolveAttributeIndex(modifier.attributeId, attributeIndexCache);
142
+ attributes.dirty[index] = 1;
143
+ }
144
+ }
145
+ resolveAttributeIndex(attributeId, attributeIndexCache) {
146
+ const cached = attributeIndexCache.get(attributeId);
147
+ if (cached !== undefined) {
148
+ return cached;
149
+ }
150
+ const index = this.registries.attributes.indexOf(attributeId);
151
+ attributeIndexCache.set(attributeId, index);
152
+ return index;
153
+ }
154
+ getOrCreateTags(entity) {
155
+ const existing = getGameplayTagsComponent(entity);
156
+ if (existing) {
157
+ return existing;
158
+ }
159
+ const tags = new GameplayTagsComponent();
160
+ entity.addComponent(tags);
161
+ this.entityManager.onComponentAdded(entity, tags.type);
162
+ return tags;
163
+ }
164
+ }
165
+ function applyInstantModifier(value, op, magnitude) {
166
+ switch (op) {
167
+ case 'Add':
168
+ return FP.Add(value, magnitude);
169
+ case 'Multiply':
170
+ return FP.Mul(value, magnitude);
171
+ case 'Override':
172
+ return magnitude;
173
+ }
174
+ }
@@ -0,0 +1,16 @@
1
+ import { GameSystem } from '@phalanx-engine/ecs';
2
+ import type { AbilitySystemRegistries } from '../registry';
3
+ import type { AbilitySystemRuntime } from '../runtime';
4
+ export declare class EffectTickSystem extends GameSystem {
5
+ private readonly registries;
6
+ private readonly runtime;
7
+ constructor(registries: AbilitySystemRegistries, runtime: AbilitySystemRuntime);
8
+ processTick(tick: number): void;
9
+ private tickEntity;
10
+ private processExpirations;
11
+ private firePeriodics;
12
+ private applyPeriodicPayload;
13
+ private revokeTags;
14
+ private markModifiersDirty;
15
+ }
16
+ //# sourceMappingURL=EffectTickSystem.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EffectTickSystem.d.ts","sourceRoot":"","sources":["../../src/systems/EffectTickSystem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAajD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAE3D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAmCvD,qBAAa,gBAAiB,SAAQ,UAAU;IAE5C,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,OAAO;gBADP,UAAU,EAAE,uBAAuB,EACnC,OAAO,EAAE,oBAAoB;IAKhC,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAgB/C,OAAO,CAAC,UAAU;IA4DlB,OAAO,CAAC,kBAAkB;IAuC1B,OAAO,CAAC,aAAa;IAmErB,OAAO,CAAC,oBAAoB;IAgB5B,OAAO,CAAC,UAAU;IA4BlB,OAAO,CAAC,kBAAkB;CAY3B"}
@@ -0,0 +1,152 @@
1
+ import { GameSystem } from '@phalanx-engine/ecs';
2
+ import { FP } from '@phalanx-engine/math';
3
+ import { AbilitiesComponentType, getActiveEffectsComponent, getAttributesComponent, getGameplayTagsComponent, } from '../components';
4
+ import { appendGameplayCueEvents } from '../runtime';
5
+ export class EffectTickSystem extends GameSystem {
6
+ registries;
7
+ runtime;
8
+ constructor(registries, runtime) {
9
+ super();
10
+ this.registries = registries;
11
+ this.runtime = runtime;
12
+ }
13
+ processTick(tick) {
14
+ const entities = this.entityManager.queryEntitiesAny(AbilitiesComponentType.AbilitySystem, AbilitiesComponentType.ActiveEffects);
15
+ for (const entity of entities) {
16
+ const activeEffects = getActiveEffectsComponent(entity);
17
+ if (!activeEffects || activeEffects.queue.length === 0) {
18
+ continue;
19
+ }
20
+ this.tickEntity(entity, activeEffects, tick);
21
+ }
22
+ }
23
+ tickEntity(entity, activeEffects, tick) {
24
+ const queue = activeEffects.queue;
25
+ this.firePeriodics(entity, queue, tick);
26
+ for (let i = 0; i < queue.length; i++) {
27
+ const instance = queue[i];
28
+ if (instance.enteredOnTick === tick) {
29
+ continue;
30
+ }
31
+ if (instance.remainingTicks > 0) {
32
+ instance.remainingTicks -= 1;
33
+ }
34
+ }
35
+ const expired = [];
36
+ let writeIndex = 0;
37
+ for (let readIndex = 0; readIndex < queue.length; readIndex++) {
38
+ const instance = queue[readIndex];
39
+ if (instance.remainingTicks <= 0) {
40
+ expired.push(instance);
41
+ continue;
42
+ }
43
+ if (writeIndex !== readIndex) {
44
+ queue[writeIndex] = instance;
45
+ }
46
+ writeIndex += 1;
47
+ }
48
+ queue.length = writeIndex;
49
+ if (expired.length === 0) {
50
+ return;
51
+ }
52
+ this.processExpirations(entity, activeEffects, expired, tick);
53
+ }
54
+ processExpirations(entity, activeEffects, expired, tick) {
55
+ const tags = getGameplayTagsComponent(entity);
56
+ const attributes = getAttributesComponent(entity);
57
+ for (const instance of expired) {
58
+ const effectDef = this.registries.effects.tryGet(instance.defId);
59
+ if (!effectDef) {
60
+ throw new Error(`EffectRegistry does not contain '${instance.defId}'`);
61
+ }
62
+ this.revokeTags(effectDef, tags, activeEffects.queue);
63
+ this.markModifiersDirty(effectDef, attributes);
64
+ appendGameplayCueEvents(this.runtime.gameplayCueBuffer, effectDef.cues, 'OnExpired', tick, instance.sourceEntityId, entity.id);
65
+ }
66
+ }
67
+ firePeriodics(entity, queue, tick) {
68
+ if (queue.length === 0) {
69
+ return;
70
+ }
71
+ let attributes;
72
+ for (let i = 0; i < queue.length; i++) {
73
+ const instance = queue[i];
74
+ if (instance.enteredOnTick === tick) {
75
+ continue;
76
+ }
77
+ if (instance.remainingTicks <= 0) {
78
+ continue;
79
+ }
80
+ if (tick < instance.nextPeriodTick) {
81
+ continue;
82
+ }
83
+ const effectDef = this.registries.effects.tryGet(instance.defId);
84
+ if (!effectDef) {
85
+ throw new Error(`EffectRegistry does not contain '${instance.defId}'`);
86
+ }
87
+ if (effectDef.type !== 'Periodic') {
88
+ continue;
89
+ }
90
+ const periodTicks = effectDef.periodTicks;
91
+ if (periodTicks === undefined || periodTicks <= 0) {
92
+ throw new Error(`EffectDef '${effectDef.id}' is Periodic but has invalid periodTicks=${String(periodTicks)}`);
93
+ }
94
+ if (attributes === undefined) {
95
+ attributes = getAttributesComponent(entity);
96
+ }
97
+ while (tick >= instance.nextPeriodTick) {
98
+ this.applyPeriodicPayload(effectDef, attributes);
99
+ appendGameplayCueEvents(this.runtime.gameplayCueBuffer, effectDef.cues, 'OnPeriodic', tick, instance.sourceEntityId, entity.id);
100
+ instance.nextPeriodTick += periodTicks;
101
+ }
102
+ }
103
+ }
104
+ applyPeriodicPayload(effectDef, attributes) {
105
+ if (!attributes || effectDef.modifiers.length === 0) {
106
+ return;
107
+ }
108
+ for (const modifier of effectDef.modifiers) {
109
+ const index = this.registries.attributes.indexOf(modifier.attributeId);
110
+ const current = FP.FromRaw(attributes.base[index]);
111
+ const next = applyPeriodicModifier(current, modifier.op, modifier.magnitude);
112
+ attributes.base[index] = FP.ToRaw(next);
113
+ attributes.dirty[index] = 1;
114
+ }
115
+ }
116
+ revokeTags(effectDef, tags, _remainingQueue) {
117
+ if (!tags || !effectDef.tagsGranted || effectDef.tagsGranted.length === 0) {
118
+ return;
119
+ }
120
+ for (const grantedTag of effectDef.tagsGranted) {
121
+ const current = tags.effectGrantCounts.get(grantedTag) ?? 0;
122
+ if (current <= 1) {
123
+ tags.effectGrantCounts.delete(grantedTag);
124
+ if (!tags.adHocTags.has(grantedTag)) {
125
+ tags.tags.delete(grantedTag);
126
+ }
127
+ }
128
+ else {
129
+ tags.effectGrantCounts.set(grantedTag, current - 1);
130
+ }
131
+ }
132
+ }
133
+ markModifiersDirty(effectDef, attributes) {
134
+ if (!attributes || effectDef.modifiers.length === 0) {
135
+ return;
136
+ }
137
+ for (const modifier of effectDef.modifiers) {
138
+ const index = this.registries.attributes.indexOf(modifier.attributeId);
139
+ attributes.dirty[index] = 1;
140
+ }
141
+ }
142
+ }
143
+ function applyPeriodicModifier(value, op, magnitude) {
144
+ switch (op) {
145
+ case 'Add':
146
+ return FP.Add(value, magnitude);
147
+ case 'Multiply':
148
+ return FP.Mul(value, magnitude);
149
+ case 'Override':
150
+ return magnitude;
151
+ }
152
+ }
@@ -0,0 +1,9 @@
1
+ export { AbilityActivationSystem } from './AbilityActivationSystem';
2
+ export { AbilityHookExecutorSystem } from './AbilityHookExecutorSystem';
3
+ export { AttributeAggregationSystem } from './AttributeAggregationSystem';
4
+ export { CueBufferCleanupSystem } from './CueBufferCleanupSystem';
5
+ export { CueDispatchSystem } from './CueDispatchSystem';
6
+ export { CuePresentationSystem } from './CuePresentationSystem';
7
+ export { EffectApplicationSystem } from './EffectApplicationSystem';
8
+ export { EffectTickSystem } from './EffectTickSystem';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/systems/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,8 @@
1
+ export { AbilityActivationSystem } from './AbilityActivationSystem';
2
+ export { AbilityHookExecutorSystem } from './AbilityHookExecutorSystem';
3
+ export { AttributeAggregationSystem } from './AttributeAggregationSystem';
4
+ export { CueBufferCleanupSystem } from './CueBufferCleanupSystem';
5
+ export { CueDispatchSystem } from './CueDispatchSystem';
6
+ export { CuePresentationSystem } from './CuePresentationSystem';
7
+ export { EffectApplicationSystem } from './EffectApplicationSystem';
8
+ export { EffectTickSystem } from './EffectTickSystem';
@@ -0,0 +1,19 @@
1
+ import type { ProvidedTarget, TargetSpec } from '../types';
2
+ export interface TargetResolutionInput {
3
+ casterEntityId: number;
4
+ spec: TargetSpec;
5
+ providedTarget?: ProvidedTarget;
6
+ }
7
+ export type TargetResolutionResult = {
8
+ dropped: false;
9
+ targets: number[];
10
+ } | {
11
+ dropped: true;
12
+ };
13
+ export declare class TargetResolver {
14
+ constructor();
15
+ private static readonly DROPPED;
16
+ resolve(input: TargetResolutionInput): TargetResolutionResult;
17
+ private resolveEntityOrigin;
18
+ }
19
+ //# sourceMappingURL=TargetResolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TargetResolver.d.ts","sourceRoot":"","sources":["../../src/targeting/TargetResolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAgB,UAAU,EAAE,MAAM,UAAU,CAAC;AAMzE,MAAM,WAAW,qBAAqB;IAKpC,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,UAAU,CAAC;IAQjB,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC;AAkBD,MAAM,MAAM,sBAAsB,GAC9B;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,GACrC;IAAE,OAAO,EAAE,IAAI,CAAA;CAAE,CAAC;AAkBtB,qBAAa,cAAc;;IAOzB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAA6C;IAErE,OAAO,CAAC,KAAK,EAAE,qBAAqB,GAAG,sBAAsB;IAyDpE,OAAO,CAAC,mBAAmB;CA2B5B"}
@@ -0,0 +1,45 @@
1
+ export class TargetResolver {
2
+ constructor() { }
3
+ static DROPPED = { dropped: true };
4
+ resolve(input) {
5
+ const { spec } = input;
6
+ switch (spec.kind) {
7
+ case 'Self':
8
+ return { dropped: false, targets: [input.casterEntityId] };
9
+ case 'Entity': {
10
+ const resolved = this.resolveEntityOrigin(input.casterEntityId, spec.origin, input.providedTarget);
11
+ if (resolved.dropped) {
12
+ return TargetResolver.DROPPED;
13
+ }
14
+ if (resolved.entityId === undefined) {
15
+ return { dropped: false, targets: [] };
16
+ }
17
+ return { dropped: false, targets: [resolved.entityId] };
18
+ }
19
+ case 'Point': {
20
+ if (spec.origin.kind === 'Caller') {
21
+ const provided = input.providedTarget;
22
+ if (!provided || provided.x === undefined || provided.z === undefined) {
23
+ return TargetResolver.DROPPED;
24
+ }
25
+ }
26
+ return { dropped: false, targets: [] };
27
+ }
28
+ }
29
+ }
30
+ resolveEntityOrigin(casterId, origin, providedTarget) {
31
+ switch (origin.kind) {
32
+ case 'Caster':
33
+ return { dropped: false, entityId: casterId };
34
+ case 'TargetEntity':
35
+ return { dropped: false, entityId: origin.entityId };
36
+ case 'Caller':
37
+ if (providedTarget?.entityId === undefined) {
38
+ return { dropped: true };
39
+ }
40
+ return { dropped: false, entityId: providedTarget.entityId };
41
+ case 'Point':
42
+ throw new Error("TargetOrigin.kind === 'Point' is not valid for TargetSpec.kind === 'Entity'.");
43
+ }
44
+ }
45
+ }
@@ -0,0 +1,3 @@
1
+ export { TargetResolver } from './TargetResolver';
2
+ export type { TargetResolutionInput, TargetResolutionResult } from './TargetResolver';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/targeting/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,YAAY,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1 @@
1
+ export { TargetResolver } from './TargetResolver';
@@ -0,0 +1,13 @@
1
+ import type { TargetSpec } from './TargetSpec';
2
+ export interface AbilityDef {
3
+ id: string;
4
+ costEffectId?: string;
5
+ cooldownEffectId?: string;
6
+ tagsRequired?: string[];
7
+ activationBlockedTags?: string[];
8
+ selfEffectIds?: string[];
9
+ targetEffectIds?: string[];
10
+ target: TargetSpec;
11
+ hookId?: string;
12
+ }
13
+ //# sourceMappingURL=AbilityDef.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AbilityDef.d.ts","sourceRoot":"","sources":["../../src/types/AbilityDef.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC;IACjC,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,MAAM,EAAE,UAAU,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import type { ProvidedTarget } from './TargetSpec';
2
+ export interface AbilityActivationContext {
3
+ abilityId: string;
4
+ casterEntityId: number;
5
+ resolvedTargets: number[];
6
+ providedTarget?: ProvidedTarget;
7
+ tick: number;
8
+ }
9
+ export type AbilityHook = (ctx: AbilityActivationContext) => void;
10
+ //# sourceMappingURL=AbilityHook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AbilityHook.d.ts","sourceRoot":"","sources":["../../src/types/AbilityHook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD,MAAM,WAAW,wBAAwB;IACvC,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,EAAE,wBAAwB,KAAK,IAAI,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ export interface ActiveEffectInstance {
2
+ instanceId: number;
3
+ defId: string;
4
+ remainingTicks: number;
5
+ nextPeriodTick: number;
6
+ sourceEntityId: number;
7
+ enteredOnTick: number;
8
+ }
9
+ //# sourceMappingURL=ActiveEffectInstance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ActiveEffectInstance.d.ts","sourceRoot":"","sources":["../../src/types/ActiveEffectInstance.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,oBAAoB;IAEnC,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,MAAM,CAAC;IASvB,cAAc,EAAE,MAAM,CAAC;IAOvB,cAAc,EAAE,MAAM,CAAC;IAOvB,aAAa,EAAE,MAAM,CAAC;CACvB"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import type { FixedPoint } from '@phalanx-engine/math';
2
+ export type AttributeClampMode = 'both' | 'min' | 'max' | 'none';
3
+ export interface AttributeDef {
4
+ id: string;
5
+ default: FixedPoint;
6
+ min: FixedPoint;
7
+ max: FixedPoint;
8
+ clamp: AttributeClampMode;
9
+ }
10
+ //# sourceMappingURL=AttributeDef.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AttributeDef.d.ts","sourceRoot":"","sources":["../../src/types/AttributeDef.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,CAAC;AAEjE,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,UAAU,CAAC;IACpB,GAAG,EAAE,UAAU,CAAC;IAChB,GAAG,EAAE,UAAU,CAAC;IAChB,KAAK,EAAE,kBAAkB,CAAC;CAC3B"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ export type CuePhase = 'OnApplied' | 'OnPeriodic' | 'OnExpired';
2
+ export interface CueEvent {
3
+ tick: number;
4
+ cueId: string;
5
+ sourceEntityId: number;
6
+ targetEntityId: number;
7
+ phase: CuePhase;
8
+ }
9
+ //# sourceMappingURL=CueEvent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CueEvent.d.ts","sourceRoot":"","sources":["../../src/types/CueEvent.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,WAAW,GAAG,YAAY,GAAG,WAAW,CAAC;AAEhE,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,KAAK,EAAE,QAAQ,CAAC;CACjB"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,23 @@
1
+ import type { CuePhase } from './CueEvent';
2
+ import type { Modifier } from './ModifierOp';
3
+ export type EffectType = 'Instant' | 'Duration' | 'Periodic';
4
+ export interface EffectCues {
5
+ onApplied?: string[];
6
+ onPeriodic?: string[];
7
+ onExpired?: string[];
8
+ }
9
+ export type EffectCueSpec = EffectCues | string[];
10
+ export interface EffectDef {
11
+ id: string;
12
+ type: EffectType;
13
+ durationTicks?: number;
14
+ periodTicks?: number;
15
+ executePeriodicOnApplication?: boolean;
16
+ modifiers: Modifier[];
17
+ tagsGranted?: string[];
18
+ tagsRequired?: string[];
19
+ tagsBlocked?: string[];
20
+ cues?: EffectCueSpec;
21
+ }
22
+ export declare function getCueIdsForPhase(cues: EffectCueSpec | undefined, phase: CuePhase): readonly string[];
23
+ //# sourceMappingURL=EffectDef.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EffectDef.d.ts","sourceRoot":"","sources":["../../src/types/EffectDef.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE7C,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,UAAU,GAAG,UAAU,CAAC;AAE7D,MAAM,WAAW,UAAU;IACzB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,MAAM,MAAM,aAAa,GAAG,UAAU,GAAG,MAAM,EAAE,CAAC;AAIlD,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,UAAU,CAAC;IAEjB,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,4BAA4B,CAAC,EAAE,OAAO,CAAC;IACvC,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,IAAI,CAAC,EAAE,aAAa,CAAC;CACtB;AAED,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,aAAa,GAAG,SAAS,EAC/B,KAAK,EAAE,QAAQ,GACd,SAAS,MAAM,EAAE,CAenB"}
@@ -0,0 +1,17 @@
1
+ const EMPTY_CUE_IDS = [];
2
+ export function getCueIdsForPhase(cues, phase) {
3
+ if (!cues) {
4
+ return EMPTY_CUE_IDS;
5
+ }
6
+ if (Array.isArray(cues)) {
7
+ return phase === 'OnApplied' ? cues : EMPTY_CUE_IDS;
8
+ }
9
+ switch (phase) {
10
+ case 'OnApplied':
11
+ return cues.onApplied ?? EMPTY_CUE_IDS;
12
+ case 'OnPeriodic':
13
+ return cues.onPeriodic ?? EMPTY_CUE_IDS;
14
+ case 'OnExpired':
15
+ return cues.onExpired ?? EMPTY_CUE_IDS;
16
+ }
17
+ }
@@ -0,0 +1,8 @@
1
+ import type { FixedPoint } from '@phalanx-engine/math';
2
+ export type ModifierOp = 'Add' | 'Multiply' | 'Override';
3
+ export interface Modifier {
4
+ attributeId: string;
5
+ op: ModifierOp;
6
+ magnitude: FixedPoint;
7
+ }
8
+ //# sourceMappingURL=ModifierOp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ModifierOp.d.ts","sourceRoot":"","sources":["../../src/types/ModifierOp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,UAAU,GAAG,UAAU,CAAC;AAEzD,MAAM,WAAW,QAAQ;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,EAAE,EAAE,UAAU,CAAC;IACf,SAAS,EAAE,UAAU,CAAC;CACvB"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,32 @@
1
+ import type { FixedPoint } from '@phalanx-engine/math';
2
+ export type TargetOrigin = {
3
+ kind: 'Caster';
4
+ } | {
5
+ kind: 'TargetEntity';
6
+ entityId: number;
7
+ } | {
8
+ kind: 'Point';
9
+ x: FixedPoint;
10
+ z: FixedPoint;
11
+ } | {
12
+ kind: 'Caller';
13
+ };
14
+ export interface TargetFilter {
15
+ tagsRequired?: string[];
16
+ tagsBlocked?: string[];
17
+ }
18
+ export type TargetSpec = {
19
+ kind: 'Self';
20
+ } | {
21
+ kind: 'Entity';
22
+ origin: TargetOrigin;
23
+ } | {
24
+ kind: 'Point';
25
+ origin: TargetOrigin;
26
+ };
27
+ export interface ProvidedTarget {
28
+ entityId?: number;
29
+ x?: FixedPoint;
30
+ z?: FixedPoint;
31
+ }
32
+ //# sourceMappingURL=TargetSpec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TargetSpec.d.ts","sourceRoot":"","sources":["../../src/types/TargetSpec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,MAAM,YAAY,GACpB;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAClB;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAC1C;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,CAAC,EAAE,UAAU,CAAC;IAAC,CAAC,EAAE,UAAU,CAAA;CAAE,GAC/C;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC;AAEvB,MAAM,WAAW,YAAY;IAC3B,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACxB;AAED,MAAM,MAAM,UAAU,GAClB;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAChB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,YAAY,CAAA;CAAE,GACxC;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,YAAY,CAAA;CAAE,CAAC;AAE5C,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,CAAC,CAAC,EAAE,UAAU,CAAC;IACf,CAAC,CAAC,EAAE,UAAU,CAAC;CAChB"}
@@ -0,0 +1 @@
1
+ export {};