@bct-app/game-engine 0.1.8 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { TPlayer, TOperation, TAbility, TPopulatedCharacter, TTimeline, TTriggerEvent, TEffect, TPlayerReminder, TReminder } from '@bct-app/game-model';
1
+ import { TPlayer, TOperation, TAbility, TPopulatedCharacter, TTimeline, TTriggerPhase, TEffect, TTargetRef, TPlayerReminder, TReminder } from '@bct-app/game-model';
2
2
 
3
3
  type TLifetimeStatusResolver = (input: {
4
4
  player: TPlayer;
@@ -24,24 +24,22 @@ type TApplyOperationToPlayersArgs = {
24
24
  };
25
25
  declare const applyOperationToPlayers: ({ players, operations, allAbilities, characters, timelines, timelineIndexAtNow, statusResolver, customResolver, }: TApplyOperationToPlayersArgs) => TPlayer[];
26
26
 
27
- type TTriggerEventContext = {
28
- event: TTriggerEvent;
29
- actorSeat?: number;
30
- targetSeat?: number;
31
- payload?: Record<string, unknown>;
32
- };
27
+ type TCanInvokeAbilityCustomResolver = (atom: {
28
+ resolverId: string;
29
+ args?: Record<string, unknown>;
30
+ }, ctx: TDerivedContext) => boolean;
33
31
  type TCanInvokeAbilityArgs = {
34
32
  ability: TAbility;
35
- effector: TPlayer | undefined;
36
- currentTimelineIdx: number;
37
33
  timelines: TTimeline[];
38
- priorOperations?: TOperation[];
39
- players?: TPlayer[];
40
- event?: TTriggerEventContext;
41
- customConditionResolver?: (condition: {
42
- key: string;
43
- value?: unknown;
44
- }) => boolean;
34
+ candidate: {
35
+ abilityId: string;
36
+ effector: number;
37
+ payloads?: unknown[];
38
+ };
39
+ initialPlayers: TPlayer[];
40
+ allAbilities: TAbility[];
41
+ characters: TPopulatedCharacter[];
42
+ customResolver?: TCanInvokeAbilityCustomResolver;
45
43
  };
46
44
  type TCanInvokeAbilityResult = {
47
45
  allowed: true;
@@ -49,7 +47,41 @@ type TCanInvokeAbilityResult = {
49
47
  allowed: false;
50
48
  reason: string;
51
49
  };
52
- declare const canInvokeAbility: ({ ability, effector, currentTimelineIdx, timelines, priorOperations, players, event, customConditionResolver, }: TCanInvokeAbilityArgs) => TCanInvokeAbilityResult;
50
+ type TDerivedContext = {
51
+ currentTurn: number;
52
+ currentPhase: TTriggerPhase;
53
+ isFirstOfPhase: boolean;
54
+ players: TPlayer[];
55
+ allOperations: TOperation[];
56
+ todayOperations: TOperation[];
57
+ tonightOperations: TOperation[];
58
+ yesterdayDayOperations: TOperation[];
59
+ yesterdayNightOperations: TOperation[];
60
+ todayNominations: {
61
+ nominator: number;
62
+ nominee: number;
63
+ }[];
64
+ effectorSeat: number;
65
+ effector: TPlayer | undefined;
66
+ abilityId: string;
67
+ characterMap: Map<string, TPopulatedCharacter>;
68
+ operationTurnMap: Map<TOperation, number>;
69
+ operationTimeMap: Map<TOperation, TTimeline['time']>;
70
+ };
71
+ declare const deriveContext: ({ timelines, candidate, initialPlayers, allAbilities, characters, }: {
72
+ timelines: TTimeline[];
73
+ candidate: {
74
+ abilityId: string;
75
+ effector: number;
76
+ payloads?: unknown[];
77
+ };
78
+ initialPlayers: TPlayer[];
79
+ allAbilities: TAbility[];
80
+ characters: TPopulatedCharacter[];
81
+ }) => TDerivedContext | {
82
+ error: string;
83
+ };
84
+ declare const canInvokeAbility: ({ ability, timelines, candidate, initialPlayers, allAbilities, characters, customResolver, }: TCanInvokeAbilityArgs) => TCanInvokeAbilityResult;
53
85
 
54
86
  declare const transformEmptyArray: <T>(arr: T[]) => T[];
55
87
  declare const copyPlayers: (players: TPlayer[]) => TPlayer[];
@@ -63,6 +95,13 @@ declare const getSourceValue: (source: TEffect["source"], payloads: unknown[]) =
63
95
  * Resolve a value from effect source, handling PAYLOAD (with player-seat indirection), CONSTANT, and EFFECTOR.
64
96
  */
65
97
  declare const resolveSourceValue: <TResolved>(source: TEffect["source"], writableInputs: TAbility["inputs"], payloads: unknown[], effector: TPlayer | undefined, snapshotSeatMap: Map<number, TPlayer>, resolveFromPlayer: (player: TPlayer) => TResolved, isResolvedValue?: (value: unknown) => value is TResolved, resolveFromCharacter?: (characterId: string) => TResolved) => TResolved | undefined;
98
+ type TResolveTargetRefArgs = {
99
+ ref: TTargetRef;
100
+ players: TPlayer[];
101
+ effectorSeat: number | undefined;
102
+ characterMap?: Map<string, TPopulatedCharacter>;
103
+ };
104
+ declare const resolveTargetRef: ({ ref, players, effectorSeat, characterMap, }: TResolveTargetRefArgs) => TPlayer[];
66
105
 
67
106
  /**
68
107
  * Type guard to check if a value is a number or an array of numbers.
@@ -83,4 +122,4 @@ declare const isReminder: (value: unknown) => value is TReminder;
83
122
  */
84
123
  declare const isPlayerReminderArray: (value: unknown) => value is TPlayerReminder[];
85
124
 
86
- export { type TCanInvokeAbilityArgs, type TCanInvokeAbilityResult, adjustValueAsNumber, adjustValueAsNumberArray, applyOperationToPlayers, buildPlayerSeatMap, canInvokeAbility, copyPlayers, getSourceValue, getValueFromPayloads, isNumberOrNumberArray, isPlayerReminderArray, isReminder, resolveSourceValue, transformEmptyArray };
125
+ export { type TCanInvokeAbilityArgs, type TCanInvokeAbilityCustomResolver, type TCanInvokeAbilityResult, type TDerivedContext, adjustValueAsNumber, adjustValueAsNumberArray, applyOperationToPlayers, buildPlayerSeatMap, canInvokeAbility, copyPlayers, deriveContext, getSourceValue, getValueFromPayloads, isNumberOrNumberArray, isPlayerReminderArray, isReminder, resolveSourceValue, resolveTargetRef, transformEmptyArray };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { TPlayer, TOperation, TAbility, TPopulatedCharacter, TTimeline, TTriggerEvent, TEffect, TPlayerReminder, TReminder } from '@bct-app/game-model';
1
+ import { TPlayer, TOperation, TAbility, TPopulatedCharacter, TTimeline, TTriggerPhase, TEffect, TTargetRef, TPlayerReminder, TReminder } from '@bct-app/game-model';
2
2
 
3
3
  type TLifetimeStatusResolver = (input: {
4
4
  player: TPlayer;
@@ -24,24 +24,22 @@ type TApplyOperationToPlayersArgs = {
24
24
  };
25
25
  declare const applyOperationToPlayers: ({ players, operations, allAbilities, characters, timelines, timelineIndexAtNow, statusResolver, customResolver, }: TApplyOperationToPlayersArgs) => TPlayer[];
26
26
 
27
- type TTriggerEventContext = {
28
- event: TTriggerEvent;
29
- actorSeat?: number;
30
- targetSeat?: number;
31
- payload?: Record<string, unknown>;
32
- };
27
+ type TCanInvokeAbilityCustomResolver = (atom: {
28
+ resolverId: string;
29
+ args?: Record<string, unknown>;
30
+ }, ctx: TDerivedContext) => boolean;
33
31
  type TCanInvokeAbilityArgs = {
34
32
  ability: TAbility;
35
- effector: TPlayer | undefined;
36
- currentTimelineIdx: number;
37
33
  timelines: TTimeline[];
38
- priorOperations?: TOperation[];
39
- players?: TPlayer[];
40
- event?: TTriggerEventContext;
41
- customConditionResolver?: (condition: {
42
- key: string;
43
- value?: unknown;
44
- }) => boolean;
34
+ candidate: {
35
+ abilityId: string;
36
+ effector: number;
37
+ payloads?: unknown[];
38
+ };
39
+ initialPlayers: TPlayer[];
40
+ allAbilities: TAbility[];
41
+ characters: TPopulatedCharacter[];
42
+ customResolver?: TCanInvokeAbilityCustomResolver;
45
43
  };
46
44
  type TCanInvokeAbilityResult = {
47
45
  allowed: true;
@@ -49,7 +47,41 @@ type TCanInvokeAbilityResult = {
49
47
  allowed: false;
50
48
  reason: string;
51
49
  };
52
- declare const canInvokeAbility: ({ ability, effector, currentTimelineIdx, timelines, priorOperations, players, event, customConditionResolver, }: TCanInvokeAbilityArgs) => TCanInvokeAbilityResult;
50
+ type TDerivedContext = {
51
+ currentTurn: number;
52
+ currentPhase: TTriggerPhase;
53
+ isFirstOfPhase: boolean;
54
+ players: TPlayer[];
55
+ allOperations: TOperation[];
56
+ todayOperations: TOperation[];
57
+ tonightOperations: TOperation[];
58
+ yesterdayDayOperations: TOperation[];
59
+ yesterdayNightOperations: TOperation[];
60
+ todayNominations: {
61
+ nominator: number;
62
+ nominee: number;
63
+ }[];
64
+ effectorSeat: number;
65
+ effector: TPlayer | undefined;
66
+ abilityId: string;
67
+ characterMap: Map<string, TPopulatedCharacter>;
68
+ operationTurnMap: Map<TOperation, number>;
69
+ operationTimeMap: Map<TOperation, TTimeline['time']>;
70
+ };
71
+ declare const deriveContext: ({ timelines, candidate, initialPlayers, allAbilities, characters, }: {
72
+ timelines: TTimeline[];
73
+ candidate: {
74
+ abilityId: string;
75
+ effector: number;
76
+ payloads?: unknown[];
77
+ };
78
+ initialPlayers: TPlayer[];
79
+ allAbilities: TAbility[];
80
+ characters: TPopulatedCharacter[];
81
+ }) => TDerivedContext | {
82
+ error: string;
83
+ };
84
+ declare const canInvokeAbility: ({ ability, timelines, candidate, initialPlayers, allAbilities, characters, customResolver, }: TCanInvokeAbilityArgs) => TCanInvokeAbilityResult;
53
85
 
54
86
  declare const transformEmptyArray: <T>(arr: T[]) => T[];
55
87
  declare const copyPlayers: (players: TPlayer[]) => TPlayer[];
@@ -63,6 +95,13 @@ declare const getSourceValue: (source: TEffect["source"], payloads: unknown[]) =
63
95
  * Resolve a value from effect source, handling PAYLOAD (with player-seat indirection), CONSTANT, and EFFECTOR.
64
96
  */
65
97
  declare const resolveSourceValue: <TResolved>(source: TEffect["source"], writableInputs: TAbility["inputs"], payloads: unknown[], effector: TPlayer | undefined, snapshotSeatMap: Map<number, TPlayer>, resolveFromPlayer: (player: TPlayer) => TResolved, isResolvedValue?: (value: unknown) => value is TResolved, resolveFromCharacter?: (characterId: string) => TResolved) => TResolved | undefined;
98
+ type TResolveTargetRefArgs = {
99
+ ref: TTargetRef;
100
+ players: TPlayer[];
101
+ effectorSeat: number | undefined;
102
+ characterMap?: Map<string, TPopulatedCharacter>;
103
+ };
104
+ declare const resolveTargetRef: ({ ref, players, effectorSeat, characterMap, }: TResolveTargetRefArgs) => TPlayer[];
66
105
 
67
106
  /**
68
107
  * Type guard to check if a value is a number or an array of numbers.
@@ -83,4 +122,4 @@ declare const isReminder: (value: unknown) => value is TReminder;
83
122
  */
84
123
  declare const isPlayerReminderArray: (value: unknown) => value is TPlayerReminder[];
85
124
 
86
- export { type TCanInvokeAbilityArgs, type TCanInvokeAbilityResult, adjustValueAsNumber, adjustValueAsNumberArray, applyOperationToPlayers, buildPlayerSeatMap, canInvokeAbility, copyPlayers, getSourceValue, getValueFromPayloads, isNumberOrNumberArray, isPlayerReminderArray, isReminder, resolveSourceValue, transformEmptyArray };
125
+ export { type TCanInvokeAbilityArgs, type TCanInvokeAbilityCustomResolver, type TCanInvokeAbilityResult, type TDerivedContext, adjustValueAsNumber, adjustValueAsNumberArray, applyOperationToPlayers, buildPlayerSeatMap, canInvokeAbility, copyPlayers, deriveContext, getSourceValue, getValueFromPayloads, isNumberOrNumberArray, isPlayerReminderArray, isReminder, resolveSourceValue, resolveTargetRef, transformEmptyArray };