@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.
- package/README.md +564 -0
- package/dist/api/AbilitySystemFacade.d.ts +34 -0
- package/dist/api/AbilitySystemFacade.d.ts.map +1 -0
- package/dist/api/AbilitySystemFacade.js +213 -0
- package/dist/api/createAbilitySystem.d.ts +49 -0
- package/dist/api/createAbilitySystem.d.ts.map +1 -0
- package/dist/api/createAbilitySystem.js +205 -0
- package/dist/api/defineAbility.d.ts +3 -0
- package/dist/api/defineAbility.d.ts.map +1 -0
- package/dist/api/defineAbility.js +9 -0
- package/dist/api/defineAbilitySystem.d.ts +8 -0
- package/dist/api/defineAbilitySystem.d.ts.map +1 -0
- package/dist/api/defineAbilitySystem.js +7 -0
- package/dist/api/defineAttribute.d.ts +3 -0
- package/dist/api/defineAttribute.d.ts.map +1 -0
- package/dist/api/defineAttribute.js +3 -0
- package/dist/api/defineEffect.d.ts +6 -0
- package/dist/api/defineEffect.d.ts.map +1 -0
- package/dist/api/defineEffect.js +23 -0
- package/dist/api/index.d.ts +11 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +6 -0
- package/dist/components/AbilitiesComponentType.d.ts +7 -0
- package/dist/components/AbilitiesComponentType.d.ts.map +1 -0
- package/dist/components/AbilitiesComponentType.js +7 -0
- package/dist/components/AbilitySystemComponent.d.ts +17 -0
- package/dist/components/AbilitySystemComponent.d.ts.map +1 -0
- package/dist/components/AbilitySystemComponent.js +31 -0
- package/dist/components/ActiveEffectsComponent.d.ts +12 -0
- package/dist/components/ActiveEffectsComponent.d.ts.map +1 -0
- package/dist/components/ActiveEffectsComponent.js +6 -0
- package/dist/components/AttributesComponent.d.ts +9 -0
- package/dist/components/AttributesComponent.d.ts.map +1 -0
- package/dist/components/AttributesComponent.js +15 -0
- package/dist/components/GameplayTagsComponent.d.ts +8 -0
- package/dist/components/GameplayTagsComponent.d.ts.map +1 -0
- package/dist/components/GameplayTagsComponent.js +7 -0
- package/dist/components/index.d.ts +7 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +5 -0
- package/dist/cues/Cue.d.ts +15 -0
- package/dist/cues/Cue.d.ts.map +1 -0
- package/dist/cues/Cue.js +7 -0
- package/dist/cues/index.d.ts +3 -0
- package/dist/cues/index.d.ts.map +1 -0
- package/dist/cues/index.js +1 -0
- package/dist/events/AbilityEvents.d.ts +10 -0
- package/dist/events/AbilityEvents.d.ts.map +1 -0
- package/dist/events/AbilityEvents.js +1 -0
- package/dist/events/CueEvents.d.ts +5 -0
- package/dist/events/CueEvents.d.ts.map +1 -0
- package/dist/events/CueEvents.js +4 -0
- package/dist/events/index.d.ts +5 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/index.js +2 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/registry/AbilityHooksRegistry.d.ts +10 -0
- package/dist/registry/AbilityHooksRegistry.d.ts.map +1 -0
- package/dist/registry/AbilityHooksRegistry.js +25 -0
- package/dist/registry/AbilityRegistry.d.ts +6 -0
- package/dist/registry/AbilityRegistry.d.ts.map +1 -0
- package/dist/registry/AbilityRegistry.js +4 -0
- package/dist/registry/AbilitySystemRegistries.d.ts +12 -0
- package/dist/registry/AbilitySystemRegistries.d.ts.map +1 -0
- package/dist/registry/AbilitySystemRegistries.js +12 -0
- package/dist/registry/AttributeRegistry.d.ts +7 -0
- package/dist/registry/AttributeRegistry.d.ts.map +1 -0
- package/dist/registry/AttributeRegistry.js +11 -0
- package/dist/registry/DefinitionRegistry.d.ts +16 -0
- package/dist/registry/DefinitionRegistry.d.ts.map +1 -0
- package/dist/registry/DefinitionRegistry.js +37 -0
- package/dist/registry/EffectRegistry.d.ts +6 -0
- package/dist/registry/EffectRegistry.d.ts.map +1 -0
- package/dist/registry/EffectRegistry.js +4 -0
- package/dist/registry/index.d.ts +7 -0
- package/dist/registry/index.d.ts.map +1 -0
- package/dist/registry/index.js +5 -0
- package/dist/runtime/AbilitySystemRuntime.d.ts +26 -0
- package/dist/runtime/AbilitySystemRuntime.d.ts.map +1 -0
- package/dist/runtime/AbilitySystemRuntime.js +11 -0
- package/dist/runtime/GameplayCueBuffer.d.ts +10 -0
- package/dist/runtime/GameplayCueBuffer.d.ts.map +1 -0
- package/dist/runtime/GameplayCueBuffer.js +16 -0
- package/dist/runtime/InstanceIdCounter.d.ts +6 -0
- package/dist/runtime/InstanceIdCounter.d.ts.map +1 -0
- package/dist/runtime/InstanceIdCounter.js +10 -0
- package/dist/runtime/index.d.ts +6 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +3 -0
- package/dist/systems/AbilityActivationSystem.d.ts +23 -0
- package/dist/systems/AbilityActivationSystem.d.ts.map +1 -0
- package/dist/systems/AbilityActivationSystem.js +277 -0
- package/dist/systems/AbilityHookExecutorSystem.d.ts +10 -0
- package/dist/systems/AbilityHookExecutorSystem.d.ts.map +1 -0
- package/dist/systems/AbilityHookExecutorSystem.js +35 -0
- package/dist/systems/AttributeAggregationSystem.d.ts +12 -0
- package/dist/systems/AttributeAggregationSystem.d.ts.map +1 -0
- package/dist/systems/AttributeAggregationSystem.js +117 -0
- package/dist/systems/CueBufferCleanupSystem.d.ts +8 -0
- package/dist/systems/CueBufferCleanupSystem.d.ts.map +1 -0
- package/dist/systems/CueBufferCleanupSystem.js +11 -0
- package/dist/systems/CueDispatchSystem.d.ts +8 -0
- package/dist/systems/CueDispatchSystem.d.ts.map +1 -0
- package/dist/systems/CueDispatchSystem.js +17 -0
- package/dist/systems/CuePresentationSystem.d.ts +14 -0
- package/dist/systems/CuePresentationSystem.d.ts.map +1 -0
- package/dist/systems/CuePresentationSystem.js +50 -0
- package/dist/systems/EffectApplicationSystem.d.ts +20 -0
- package/dist/systems/EffectApplicationSystem.d.ts.map +1 -0
- package/dist/systems/EffectApplicationSystem.js +174 -0
- package/dist/systems/EffectTickSystem.d.ts +16 -0
- package/dist/systems/EffectTickSystem.d.ts.map +1 -0
- package/dist/systems/EffectTickSystem.js +152 -0
- package/dist/systems/index.d.ts +9 -0
- package/dist/systems/index.d.ts.map +1 -0
- package/dist/systems/index.js +8 -0
- package/dist/targeting/TargetResolver.d.ts +19 -0
- package/dist/targeting/TargetResolver.d.ts.map +1 -0
- package/dist/targeting/TargetResolver.js +45 -0
- package/dist/targeting/index.d.ts +3 -0
- package/dist/targeting/index.d.ts.map +1 -0
- package/dist/targeting/index.js +1 -0
- package/dist/types/AbilityDef.d.ts +13 -0
- package/dist/types/AbilityDef.d.ts.map +1 -0
- package/dist/types/AbilityDef.js +1 -0
- package/dist/types/AbilityHook.d.ts +10 -0
- package/dist/types/AbilityHook.d.ts.map +1 -0
- package/dist/types/AbilityHook.js +1 -0
- package/dist/types/ActiveEffectInstance.d.ts +9 -0
- package/dist/types/ActiveEffectInstance.d.ts.map +1 -0
- package/dist/types/ActiveEffectInstance.js +1 -0
- package/dist/types/AttributeDef.d.ts +10 -0
- package/dist/types/AttributeDef.d.ts.map +1 -0
- package/dist/types/AttributeDef.js +1 -0
- package/dist/types/CueEvent.d.ts +9 -0
- package/dist/types/CueEvent.d.ts.map +1 -0
- package/dist/types/CueEvent.js +1 -0
- package/dist/types/EffectDef.d.ts +23 -0
- package/dist/types/EffectDef.d.ts.map +1 -0
- package/dist/types/EffectDef.js +17 -0
- package/dist/types/ModifierOp.d.ts +8 -0
- package/dist/types/ModifierOp.d.ts.map +1 -0
- package/dist/types/ModifierOp.js +1 -0
- package/dist/types/TargetSpec.d.ts +32 -0
- package/dist/types/TargetSpec.d.ts.map +1 -0
- package/dist/types/TargetSpec.js +1 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +1 -0
- package/package.json +54 -0
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import { GameSystem } from '@phalanx-engine/ecs';
|
|
2
|
+
import { FP } from '@phalanx-engine/math';
|
|
3
|
+
import { ActiveEffectsComponent, getAbilitySystemComponent, getActiveEffectsComponent, getAttributesComponent, getGameplayTagsComponent, } from '../components';
|
|
4
|
+
import { ABILITY_ACTIVATED_EVENT } from '../events';
|
|
5
|
+
import { TargetResolver } from '../targeting';
|
|
6
|
+
export class AbilityActivationSystem extends GameSystem {
|
|
7
|
+
registries;
|
|
8
|
+
runtime;
|
|
9
|
+
inFlightTagsByCaster = new Map();
|
|
10
|
+
inFlightCostsByCaster = new Map();
|
|
11
|
+
targetResolver;
|
|
12
|
+
constructor(registries, runtime) {
|
|
13
|
+
super();
|
|
14
|
+
this.registries = registries;
|
|
15
|
+
this.runtime = runtime;
|
|
16
|
+
}
|
|
17
|
+
processTick(tick) {
|
|
18
|
+
this.runtime.currentTick = tick;
|
|
19
|
+
this.inFlightTagsByCaster.clear();
|
|
20
|
+
this.inFlightCostsByCaster.clear();
|
|
21
|
+
if (this.runtime.resolvedActivationsThisTick.length !== 0) {
|
|
22
|
+
throw new Error('AbilityActivationSystem: resolvedActivationsThisTick is not empty at start of tick. ' +
|
|
23
|
+
'Ensure AbilityHookExecutorSystem is registered after AbilityActivationSystem ' +
|
|
24
|
+
'and EffectApplicationSystem in the system pipeline.');
|
|
25
|
+
}
|
|
26
|
+
const pending = this.runtime.activationRequests;
|
|
27
|
+
if (pending.length === 0) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
let readIndex = 0;
|
|
31
|
+
let writeIndex = 0;
|
|
32
|
+
try {
|
|
33
|
+
for (; readIndex < pending.length; readIndex++) {
|
|
34
|
+
const request = pending[readIndex];
|
|
35
|
+
if (request.enqueueTick === tick) {
|
|
36
|
+
if (writeIndex !== readIndex) {
|
|
37
|
+
pending[writeIndex] = request;
|
|
38
|
+
}
|
|
39
|
+
writeIndex += 1;
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
this.processOne(request, tick);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
finally {
|
|
46
|
+
if (readIndex + 1 < pending.length) {
|
|
47
|
+
for (let k = readIndex + 1; k < pending.length; k++) {
|
|
48
|
+
pending[writeIndex++] = pending[k];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
pending.length = writeIndex;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
processOne(request, tick) {
|
|
55
|
+
const abilityDef = this.registries.abilities.tryGet(request.abilityId);
|
|
56
|
+
if (!abilityDef) {
|
|
57
|
+
throw new Error(`AbilityRegistry does not contain '${request.abilityId}'`);
|
|
58
|
+
}
|
|
59
|
+
const caster = this.entityManager.getEntity(request.casterEntityId);
|
|
60
|
+
if (!caster) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (!this.canActivate(caster, abilityDef)) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const resolution = this.resolveTargets(caster, abilityDef, request.providedTarget);
|
|
67
|
+
if (resolution.dropped) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const resolvedTargets = resolution.targets;
|
|
71
|
+
this.enqueueCasterEffects(caster, abilityDef);
|
|
72
|
+
if (abilityDef.targetEffectIds && abilityDef.targetEffectIds.length > 0) {
|
|
73
|
+
for (let i = 0; i < resolvedTargets.length; i++) {
|
|
74
|
+
const targetEntity = this.entityManager.getEntity(resolvedTargets[i]);
|
|
75
|
+
if (!targetEntity) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
for (const effectId of abilityDef.targetEffectIds) {
|
|
79
|
+
this.enqueueEffect(targetEntity, effectId, request.casterEntityId);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
this.recordCooldownInFlight(request.casterEntityId, abilityDef);
|
|
84
|
+
const record = {
|
|
85
|
+
abilityId: abilityDef.id,
|
|
86
|
+
casterEntityId: request.casterEntityId,
|
|
87
|
+
resolvedTargets,
|
|
88
|
+
providedTarget: request.providedTarget,
|
|
89
|
+
hookId: abilityDef.hookId,
|
|
90
|
+
tick,
|
|
91
|
+
};
|
|
92
|
+
this.runtime.resolvedActivationsThisTick.push(record);
|
|
93
|
+
const event = {
|
|
94
|
+
abilityId: abilityDef.id,
|
|
95
|
+
casterEntityId: request.casterEntityId,
|
|
96
|
+
resolvedTargets,
|
|
97
|
+
providedTarget: request.providedTarget,
|
|
98
|
+
tick,
|
|
99
|
+
};
|
|
100
|
+
this.eventBus.emit(ABILITY_ACTIVATED_EVENT, event);
|
|
101
|
+
}
|
|
102
|
+
canActivate(caster, def) {
|
|
103
|
+
const casterId = caster.id;
|
|
104
|
+
const abilitySystem = getAbilitySystemComponent(caster);
|
|
105
|
+
if (abilitySystem && !abilitySystem.abilities.has(def.id)) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
const tags = getGameplayTagsComponent(caster);
|
|
109
|
+
const inFlightTags = this.inFlightTagsByCaster.get(casterId);
|
|
110
|
+
if (def.activationBlockedTags) {
|
|
111
|
+
for (const tag of def.activationBlockedTags) {
|
|
112
|
+
if (tags?.tags.has(tag) === true) {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
if (inFlightTags?.has(tag) === true) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (def.tagsRequired) {
|
|
121
|
+
for (const tag of def.tagsRequired) {
|
|
122
|
+
if (tags?.tags.has(tag) !== true && inFlightTags?.has(tag) !== true) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (def.costEffectId !== undefined) {
|
|
128
|
+
if (!this.canAffordCost(caster, def.costEffectId)) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (def.cooldownEffectId !== undefined) {
|
|
133
|
+
if (!this.isOffCooldown(caster, def.cooldownEffectId)) {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
canAffordCost(caster, costEffectId) {
|
|
140
|
+
const effectDef = this.registries.effects.tryGet(costEffectId);
|
|
141
|
+
if (!effectDef) {
|
|
142
|
+
throw new Error(`EffectRegistry does not contain '${costEffectId}'`);
|
|
143
|
+
}
|
|
144
|
+
if (effectDef.type !== 'Instant') {
|
|
145
|
+
throw new Error(`Ability cost effect '${costEffectId}' must be type 'Instant'; got '${effectDef.type}'`);
|
|
146
|
+
}
|
|
147
|
+
if (effectDef.modifiers.length === 0) {
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
const attributes = getAttributesComponent(caster);
|
|
151
|
+
if (!attributes) {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
const inFlightCosts = this.inFlightCostsByCaster.get(caster.id);
|
|
155
|
+
for (const modifier of effectDef.modifiers) {
|
|
156
|
+
if (modifier.op !== 'Add') {
|
|
157
|
+
throw new Error(`Ability cost effect '${costEffectId}' uses unsupported op '${modifier.op}'. ` +
|
|
158
|
+
'MVP supports only Instant + Add modifiers for cost.');
|
|
159
|
+
}
|
|
160
|
+
const rawMagnitude = FP.ToRaw(modifier.magnitude);
|
|
161
|
+
if (rawMagnitude >= 0n) {
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
const attributeIndex = this.registries.attributes.indexOfOrMinusOne(modifier.attributeId);
|
|
165
|
+
if (attributeIndex === -1) {
|
|
166
|
+
throw new Error(`Ability cost effect '${costEffectId}' references unknown attribute '${modifier.attributeId}'`);
|
|
167
|
+
}
|
|
168
|
+
const currentRaw = attributes.current[attributeIndex];
|
|
169
|
+
const inFlightDebit = inFlightCosts?.get(modifier.attributeId) ?? 0n;
|
|
170
|
+
const after = currentRaw - inFlightDebit + rawMagnitude;
|
|
171
|
+
if (after < 0n) {
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
isOffCooldown(caster, cooldownEffectId) {
|
|
178
|
+
const effectDef = this.registries.effects.tryGet(cooldownEffectId);
|
|
179
|
+
if (!effectDef) {
|
|
180
|
+
throw new Error(`EffectRegistry does not contain '${cooldownEffectId}'`);
|
|
181
|
+
}
|
|
182
|
+
if (!effectDef.tagsGranted || effectDef.tagsGranted.length === 0) {
|
|
183
|
+
throw new Error(`Ability cooldown effect '${cooldownEffectId}' must have at least one tagsGranted entry.`);
|
|
184
|
+
}
|
|
185
|
+
const tags = getGameplayTagsComponent(caster);
|
|
186
|
+
const inFlightTags = this.inFlightTagsByCaster.get(caster.id);
|
|
187
|
+
for (const tag of effectDef.tagsGranted) {
|
|
188
|
+
if (tags?.tags.has(tag) === true) {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
if (inFlightTags?.has(tag) === true) {
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
enqueueCasterEffects(caster, def) {
|
|
198
|
+
if (def.costEffectId !== undefined) {
|
|
199
|
+
this.enqueueEffect(caster, def.costEffectId, caster.id);
|
|
200
|
+
this.recordCostInFlight(caster.id, def.costEffectId);
|
|
201
|
+
}
|
|
202
|
+
if (def.cooldownEffectId !== undefined) {
|
|
203
|
+
this.enqueueEffect(caster, def.cooldownEffectId, caster.id);
|
|
204
|
+
}
|
|
205
|
+
if (def.selfEffectIds) {
|
|
206
|
+
for (const effectId of def.selfEffectIds) {
|
|
207
|
+
this.enqueueEffect(caster, effectId, caster.id);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
enqueueEffect(target, effectId, sourceEntityId) {
|
|
212
|
+
if (!this.registries.effects.has(effectId)) {
|
|
213
|
+
throw new Error(`EffectRegistry does not contain '${effectId}'`);
|
|
214
|
+
}
|
|
215
|
+
const activeEffects = this.getOrCreateActiveEffects(target);
|
|
216
|
+
activeEffects.pendingAdd.push({ defId: effectId, sourceEntityId });
|
|
217
|
+
}
|
|
218
|
+
getOrCreateActiveEffects(target) {
|
|
219
|
+
const existing = getActiveEffectsComponent(target);
|
|
220
|
+
if (existing) {
|
|
221
|
+
return existing;
|
|
222
|
+
}
|
|
223
|
+
const component = new ActiveEffectsComponent();
|
|
224
|
+
target.addComponent(component);
|
|
225
|
+
this.entityManager.onComponentAdded(target, component.type);
|
|
226
|
+
return component;
|
|
227
|
+
}
|
|
228
|
+
recordCooldownInFlight(casterId, def) {
|
|
229
|
+
if (def.cooldownEffectId === undefined) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
const effectDef = this.registries.effects.tryGet(def.cooldownEffectId);
|
|
233
|
+
if (!effectDef || !effectDef.tagsGranted) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
let set = this.inFlightTagsByCaster.get(casterId);
|
|
237
|
+
if (!set) {
|
|
238
|
+
set = new Set();
|
|
239
|
+
this.inFlightTagsByCaster.set(casterId, set);
|
|
240
|
+
}
|
|
241
|
+
for (const tag of effectDef.tagsGranted) {
|
|
242
|
+
set.add(tag);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
recordCostInFlight(casterId, costEffectId) {
|
|
246
|
+
const effectDef = this.registries.effects.tryGet(costEffectId);
|
|
247
|
+
if (!effectDef) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
let map = this.inFlightCostsByCaster.get(casterId);
|
|
251
|
+
for (const modifier of effectDef.modifiers) {
|
|
252
|
+
if (modifier.op !== 'Add') {
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
const rawMagnitude = FP.ToRaw(modifier.magnitude);
|
|
256
|
+
if (rawMagnitude >= 0n) {
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
if (!map) {
|
|
260
|
+
map = new Map();
|
|
261
|
+
this.inFlightCostsByCaster.set(casterId, map);
|
|
262
|
+
}
|
|
263
|
+
const existing = map.get(modifier.attributeId) ?? 0n;
|
|
264
|
+
map.set(modifier.attributeId, existing + -rawMagnitude);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
resolveTargets(caster, def, providedTarget) {
|
|
268
|
+
if (this.targetResolver === undefined) {
|
|
269
|
+
this.targetResolver = new TargetResolver();
|
|
270
|
+
}
|
|
271
|
+
return this.targetResolver.resolve({
|
|
272
|
+
casterEntityId: caster.id,
|
|
273
|
+
spec: def.target,
|
|
274
|
+
providedTarget,
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { GameSystem } from '@phalanx-engine/ecs';
|
|
2
|
+
import type { AbilitySystemRegistries } from '../registry';
|
|
3
|
+
import type { AbilitySystemRuntime } from '../runtime';
|
|
4
|
+
export declare class AbilityHookExecutorSystem extends GameSystem {
|
|
5
|
+
private readonly registries;
|
|
6
|
+
private readonly runtime;
|
|
7
|
+
constructor(registries: AbilitySystemRegistries, runtime: AbilitySystemRuntime);
|
|
8
|
+
processTick(_tick: number): void;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=AbilityHookExecutorSystem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AbilityHookExecutorSystem.d.ts","sourceRoot":"","sources":["../../src/systems/AbilityHookExecutorSystem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAiCvD,qBAAa,yBAA0B,SAAQ,UAAU;IAErD,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,OAAO;gBADP,UAAU,EAAE,uBAAuB,EACnC,OAAO,EAAE,oBAAoB;IAKhC,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;CAkCjD"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { GameSystem } from '@phalanx-engine/ecs';
|
|
2
|
+
export class AbilityHookExecutorSystem extends GameSystem {
|
|
3
|
+
registries;
|
|
4
|
+
runtime;
|
|
5
|
+
constructor(registries, runtime) {
|
|
6
|
+
super();
|
|
7
|
+
this.registries = registries;
|
|
8
|
+
this.runtime = runtime;
|
|
9
|
+
}
|
|
10
|
+
processTick(_tick) {
|
|
11
|
+
const buffer = this.runtime.resolvedActivationsThisTick;
|
|
12
|
+
if (buffer.length === 0) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const drained = buffer.splice(0, buffer.length);
|
|
16
|
+
for (let i = 0; i < drained.length; i++) {
|
|
17
|
+
const resolved = drained[i];
|
|
18
|
+
if (resolved.hookId === undefined) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
const hook = this.registries.hooks.tryGet(resolved.hookId);
|
|
22
|
+
if (!hook) {
|
|
23
|
+
throw new Error(`AbilityHooksRegistry does not contain '${resolved.hookId}'`);
|
|
24
|
+
}
|
|
25
|
+
const ctx = {
|
|
26
|
+
abilityId: resolved.abilityId,
|
|
27
|
+
casterEntityId: resolved.casterEntityId,
|
|
28
|
+
resolvedTargets: resolved.resolvedTargets,
|
|
29
|
+
providedTarget: resolved.providedTarget,
|
|
30
|
+
tick: resolved.tick,
|
|
31
|
+
};
|
|
32
|
+
hook(ctx);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { GameSystem } from '@phalanx-engine/ecs';
|
|
2
|
+
import type { AbilitySystemRegistries } from '../registry';
|
|
3
|
+
export declare class AttributeAggregationSystem extends GameSystem {
|
|
4
|
+
private readonly registries;
|
|
5
|
+
private readonly orderedEffectsBuffer;
|
|
6
|
+
constructor(registries: AbilitySystemRegistries);
|
|
7
|
+
processTick(_tick: number): void;
|
|
8
|
+
private takeOrderedEffects;
|
|
9
|
+
private readonly resolvedEffectDefsBuffer;
|
|
10
|
+
private resolveEffectDefs;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=AttributeAggregationSystem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AttributeAggregationSystem.d.ts","sourceRoot":"","sources":["../../src/systems/AttributeAggregationSystem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AASjD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAyB3D,qBAAa,0BAA2B,SAAQ,UAAU;IAGrC,OAAO,CAAC,QAAQ,CAAC,UAAU;IAF9C,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAA4B;gBAE7B,UAAU,EAAE,uBAAuB;IAIvD,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAkEhD,OAAO,CAAC,kBAAkB;IAyB1B,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAAmB;IAa5D,OAAO,CAAC,iBAAiB;CAY1B"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { GameSystem } from '@phalanx-engine/ecs';
|
|
2
|
+
import { FP } from '@phalanx-engine/math';
|
|
3
|
+
import { AbilitiesComponentType, getActiveEffectsComponent, getAttributesComponent, } from '../components';
|
|
4
|
+
export class AttributeAggregationSystem extends GameSystem {
|
|
5
|
+
registries;
|
|
6
|
+
orderedEffectsBuffer = [];
|
|
7
|
+
constructor(registries) {
|
|
8
|
+
super();
|
|
9
|
+
this.registries = registries;
|
|
10
|
+
}
|
|
11
|
+
processTick(_tick) {
|
|
12
|
+
const entities = this.entityManager.queryEntitiesAny(AbilitiesComponentType.AbilitySystem, AbilitiesComponentType.Attributes);
|
|
13
|
+
const attributeDefs = this.registries.attributes.values();
|
|
14
|
+
for (const entity of entities) {
|
|
15
|
+
const attributes = getAttributesComponent(entity);
|
|
16
|
+
if (!attributes) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
if (!hasAnyDirty(attributes.dirty)) {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
const activeEffects = getActiveEffectsComponent(entity);
|
|
23
|
+
const orderedEffects = this.takeOrderedEffects(activeEffects);
|
|
24
|
+
const resolvedEffectDefs = this.resolveEffectDefs(orderedEffects);
|
|
25
|
+
for (let attributeIndex = 0; attributeIndex < attributes.dirty.length; attributeIndex++) {
|
|
26
|
+
if (attributes.dirty[attributeIndex] === 0) {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
const attributeDef = attributeDefs[attributeIndex];
|
|
30
|
+
if (!attributeDef) {
|
|
31
|
+
throw new Error(`AttributeRegistry does not contain index ${attributeIndex}`);
|
|
32
|
+
}
|
|
33
|
+
let value = FP.FromRaw(attributes.base[attributeIndex]);
|
|
34
|
+
for (let i = 0; i < resolvedEffectDefs.length; i++) {
|
|
35
|
+
const effectDef = resolvedEffectDefs[i];
|
|
36
|
+
for (const modifier of effectDef.modifiers) {
|
|
37
|
+
if (modifier.attributeId !== attributeDef.id) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
value = applyModifier(value, modifier.op, modifier.magnitude);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const clamped = clampAttribute(value, attributeDef);
|
|
44
|
+
attributes.current[attributeIndex] = FP.ToRaw(clamped);
|
|
45
|
+
if (attributeDef.clamp !== 'none') {
|
|
46
|
+
attributes.base[attributeIndex] = FP.ToRaw(clampAttribute(FP.FromRaw(attributes.base[attributeIndex]), attributeDef));
|
|
47
|
+
}
|
|
48
|
+
attributes.dirty[attributeIndex] = 0;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
takeOrderedEffects(activeEffects) {
|
|
53
|
+
const buffer = this.orderedEffectsBuffer;
|
|
54
|
+
buffer.length = 0;
|
|
55
|
+
if (!activeEffects) {
|
|
56
|
+
return buffer;
|
|
57
|
+
}
|
|
58
|
+
const queue = activeEffects.queue;
|
|
59
|
+
let alreadySorted = true;
|
|
60
|
+
for (let i = 0; i < queue.length; i++) {
|
|
61
|
+
buffer.push(queue[i]);
|
|
62
|
+
if (i > 0 && queue[i - 1].instanceId > queue[i].instanceId) {
|
|
63
|
+
alreadySorted = false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (!alreadySorted) {
|
|
67
|
+
buffer.sort(byInstanceIdAsc);
|
|
68
|
+
}
|
|
69
|
+
return buffer;
|
|
70
|
+
}
|
|
71
|
+
resolvedEffectDefsBuffer = [];
|
|
72
|
+
resolveEffectDefs(orderedEffects) {
|
|
73
|
+
const buffer = this.resolvedEffectDefsBuffer;
|
|
74
|
+
buffer.length = 0;
|
|
75
|
+
for (let i = 0; i < orderedEffects.length; i++) {
|
|
76
|
+
const def = this.registries.effects.get(orderedEffects[i].defId);
|
|
77
|
+
if (def.type === 'Periodic') {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
buffer.push(def);
|
|
81
|
+
}
|
|
82
|
+
return buffer;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function byInstanceIdAsc(a, b) {
|
|
86
|
+
return a.instanceId - b.instanceId;
|
|
87
|
+
}
|
|
88
|
+
function hasAnyDirty(dirty) {
|
|
89
|
+
for (let i = 0; i < dirty.length; i++) {
|
|
90
|
+
if (dirty[i] !== 0) {
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
function applyModifier(value, op, magnitude) {
|
|
97
|
+
switch (op) {
|
|
98
|
+
case 'Add':
|
|
99
|
+
return FP.Add(value, magnitude);
|
|
100
|
+
case 'Multiply':
|
|
101
|
+
return FP.Mul(value, magnitude);
|
|
102
|
+
case 'Override':
|
|
103
|
+
return magnitude;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function clampAttribute(value, def) {
|
|
107
|
+
switch (def.clamp) {
|
|
108
|
+
case 'both':
|
|
109
|
+
return FP.Clamp(value, def.min, def.max);
|
|
110
|
+
case 'min':
|
|
111
|
+
return FP.Max(value, def.min);
|
|
112
|
+
case 'max':
|
|
113
|
+
return FP.Min(value, def.max);
|
|
114
|
+
case 'none':
|
|
115
|
+
return value;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { GameSystem } from '@phalanx-engine/ecs';
|
|
2
|
+
import type { AbilitySystemRuntime } from '../runtime';
|
|
3
|
+
export declare class CueBufferCleanupSystem extends GameSystem {
|
|
4
|
+
private readonly runtime;
|
|
5
|
+
constructor(runtime: AbilitySystemRuntime);
|
|
6
|
+
processTick(_tick: number): void;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=CueBufferCleanupSystem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CueBufferCleanupSystem.d.ts","sourceRoot":"","sources":["../../src/systems/CueBufferCleanupSystem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAUvD,qBAAa,sBAAuB,SAAQ,UAAU;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,oBAAoB;IAIjD,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;CAGjD"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { GameSystem } from '@phalanx-engine/ecs';
|
|
2
|
+
export class CueBufferCleanupSystem extends GameSystem {
|
|
3
|
+
runtime;
|
|
4
|
+
constructor(runtime) {
|
|
5
|
+
super();
|
|
6
|
+
this.runtime = runtime;
|
|
7
|
+
}
|
|
8
|
+
processTick(_tick) {
|
|
9
|
+
this.runtime.gameplayCueBuffer.events.length = 0;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { GameSystem } from '@phalanx-engine/ecs';
|
|
2
|
+
import type { AbilitySystemRuntime } from '../runtime';
|
|
3
|
+
export declare class CueDispatchSystem extends GameSystem {
|
|
4
|
+
private readonly runtime;
|
|
5
|
+
constructor(runtime: AbilitySystemRuntime);
|
|
6
|
+
processTick(_tick: number): void;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=CueDispatchSystem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CueDispatchSystem.d.ts","sourceRoot":"","sources":["../../src/systems/CueDispatchSystem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAWvD,qBAAa,iBAAkB,SAAQ,UAAU;IAC5B,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,oBAAoB;IAIjD,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;CAQjD"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { GameSystem } from '@phalanx-engine/ecs';
|
|
2
|
+
import { GAMEPLAY_CUE_EVENT, gameplayCueKey } from '../events';
|
|
3
|
+
export class CueDispatchSystem extends GameSystem {
|
|
4
|
+
runtime;
|
|
5
|
+
constructor(runtime) {
|
|
6
|
+
super();
|
|
7
|
+
this.runtime = runtime;
|
|
8
|
+
}
|
|
9
|
+
processTick(_tick) {
|
|
10
|
+
const events = this.runtime.gameplayCueBuffer.events;
|
|
11
|
+
for (let i = 0; i < events.length; i++) {
|
|
12
|
+
const event = events[i];
|
|
13
|
+
this.eventBus.emit(GAMEPLAY_CUE_EVENT, event);
|
|
14
|
+
this.eventBus.emit(gameplayCueKey(event.cueId), event);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { GameSystem } from '@phalanx-engine/ecs';
|
|
2
|
+
import type { IAfterFrame, SystemContext } from '@phalanx-engine/ecs';
|
|
3
|
+
import type { CueConfig } from '../cues';
|
|
4
|
+
export declare class CuePresentationSystem extends GameSystem implements IAfterFrame {
|
|
5
|
+
private readonly cues;
|
|
6
|
+
private cueContext;
|
|
7
|
+
private activeCues;
|
|
8
|
+
constructor(cues: CueConfig);
|
|
9
|
+
init(context: SystemContext): void;
|
|
10
|
+
processTick(_tick: number): void;
|
|
11
|
+
afterFrame(_alpha: number, deltaTimeSeconds: number): void;
|
|
12
|
+
dispose(): void;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=CuePresentationSystem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CuePresentationSystem.d.ts","sourceRoot":"","sources":["../../src/systems/CuePresentationSystem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGtE,OAAO,KAAK,EAAO,SAAS,EAAc,MAAM,SAAS,CAAC;AAU1D,qBAAa,qBAAsB,SAAQ,UAAW,YAAW,WAAW;IAIvD,OAAO,CAAC,QAAQ,CAAC,IAAI;IAHxC,OAAO,CAAC,UAAU,CAAc;IAChC,OAAO,CAAC,UAAU,CAAa;gBAEK,IAAI,EAAE,SAAS;IAInC,IAAI,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI;IAsBlC,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAEzC,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,GAAG,IAAI;IAajD,OAAO,IAAI,IAAI;CAOhC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { GameSystem } from '@phalanx-engine/ecs';
|
|
2
|
+
import { gameplayCueKey } from '../events';
|
|
3
|
+
export class CuePresentationSystem extends GameSystem {
|
|
4
|
+
cues;
|
|
5
|
+
cueContext;
|
|
6
|
+
activeCues = [];
|
|
7
|
+
constructor(cues) {
|
|
8
|
+
super();
|
|
9
|
+
this.cues = cues;
|
|
10
|
+
}
|
|
11
|
+
init(context) {
|
|
12
|
+
super.init(context);
|
|
13
|
+
this.cueContext = {
|
|
14
|
+
entityManager: context.entityManager,
|
|
15
|
+
eventBus: context.eventBus,
|
|
16
|
+
};
|
|
17
|
+
for (const [cueId, factory] of Object.entries(this.cues)) {
|
|
18
|
+
this.subscribe(gameplayCueKey(cueId), (event) => {
|
|
19
|
+
const cue = factory();
|
|
20
|
+
cue.onSpawn(event, this.cueContext);
|
|
21
|
+
if (cue.isFinished()) {
|
|
22
|
+
cue.dispose();
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
this.activeCues.push(cue);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
processTick(_tick) { }
|
|
31
|
+
afterFrame(_alpha, deltaTimeSeconds) {
|
|
32
|
+
const cues = this.activeCues;
|
|
33
|
+
for (let i = cues.length - 1; i >= 0; i--) {
|
|
34
|
+
const cue = cues[i];
|
|
35
|
+
cue.update(deltaTimeSeconds);
|
|
36
|
+
if (cue.isFinished()) {
|
|
37
|
+
cue.dispose();
|
|
38
|
+
cues[i] = cues[cues.length - 1];
|
|
39
|
+
cues.pop();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
dispose() {
|
|
44
|
+
for (const cue of this.activeCues) {
|
|
45
|
+
cue.dispose();
|
|
46
|
+
}
|
|
47
|
+
this.activeCues = [];
|
|
48
|
+
super.dispose();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { GameSystem } from '@phalanx-engine/ecs';
|
|
2
|
+
import type { AbilitySystemRegistries } from '../registry';
|
|
3
|
+
import type { AbilitySystemRuntime } from '../runtime';
|
|
4
|
+
export declare class EffectApplicationSystem extends GameSystem {
|
|
5
|
+
private readonly registries;
|
|
6
|
+
private readonly runtime;
|
|
7
|
+
constructor(registries: AbilitySystemRegistries, runtime: AbilitySystemRuntime);
|
|
8
|
+
processTick(tick: number): void;
|
|
9
|
+
private readonly attributeIndexCache;
|
|
10
|
+
private applyOne;
|
|
11
|
+
private validateEffectOrThrow;
|
|
12
|
+
private checkTagPredicates;
|
|
13
|
+
private grantTags;
|
|
14
|
+
private applyInstant;
|
|
15
|
+
private queueDurational;
|
|
16
|
+
private markAttributesDirty;
|
|
17
|
+
private resolveAttributeIndex;
|
|
18
|
+
private getOrCreateTags;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=EffectApplicationSystem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EffectApplicationSystem.d.ts","sourceRoot":"","sources":["../../src/systems/EffectApplicationSystem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAYjD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAE3D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAiDvD,qBAAa,uBAAwB,SAAQ,UAAU;IAEnD,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;IAyB/C,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAA6B;IAEjE,OAAO,CAAC,QAAQ;IAuFhB,OAAO,CAAC,qBAAqB;IA2B7B,OAAO,CAAC,kBAAkB;IAkB1B,OAAO,CAAC,SAAS;IAejB,OAAO,CAAC,YAAY;IAuBpB,OAAO,CAAC,eAAe;IAwCvB,OAAO,CAAC,mBAAmB;IAkB3B,OAAO,CAAC,qBAAqB;IAa7B,OAAO,CAAC,eAAe;CAUxB"}
|