summaryrefslogtreecommitdiff
path: root/types.d.ts
blob: d55f03ea14413ebe0f65214774d31cec2324b000 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
declare const brand: unique symbol;

// branded typing
export type Brand<T, TBrand extends string> = T & {
  [brand]: TBrand;
};

export type Player = Brand<string, 'Player'>;
export type CardId = Brand<number, 'CardId'>;
export type FactionId = 'a' | 'c' | 'm';
export type FrontId = 'a' | 'm' | 'n' | 's';

export interface Front {
  value: number;
  contributions: FactionId[];
  status: 'Victory' | 'Defeat' | null;
}

export interface Game {
  // TODO: why is this needed?
  [index: number]: any;
  // RTT
  active: Player | 'None' | null;
  log: string[];
  seed: number;
  state: string | null;
  undo: Game[];
  result?: string;
  victory?: string;
  // Game specific
  active_abilities: number[];
  turn: number;
  year: number;
  bag_of_glory: FactionId[];
  blank_markers: number[][];
  bonuses: number[];
  current_events: CardId[];
  discard: Record<FactionId | 'f', number[]>;
  engine: EngineNode[];
  /**
   * Set to faction whos turn it is or null if not player turn
   * Used to determine who can spend Hero Points. Could be the case
   * a player becomes active in another players turn.
   */
  faction_turn: FactionId | null;
  /**
   * First player of current game turn
   */
  first_player: FactionId | null;
  fronts: {
    a: Front;
    m: Front;
    n: Front;
    s: Front;
  };
  glory: FactionId[];
  hands: Record<FactionId, CardId[]>;
  hero_points: Record<FactionId | 'pool', number>;
  initiative: FactionId;
  medallions: Record<FactionId, number[]> & { pool: Array<number | null> };
  played_card: CardId | null;
  player_order: Player[];
  selected_cards: Record<FactionId, CardId[]>;
  selectable_cards: CardId[]; // used for specific events
  tableaus: Record<FactionId, CardId[]>;
  /**
   * Used for event effect that allows Anarchist to put an event
   * card on top of the deck
   */
  top_of_events_deck: CardId | null;
  tracks: number[];
  trash: Record<FactionId, CardId[]>;
  triggered_track_effects: number[];
  used_medallions: number[];
}

export interface View {
  engine: Game['engine'];
  log: number | string[];
  active?: string | null;
  prompt: string | null;
  state: Game['state'];
  actions?: any;
  victory?: string;
  current: Player | 'Observer';
  current_player_faction: FactionId | null;
  selected_cards: number[];
  bag_of_glory: Game['bag_of_glory']; // TODO: remove
  bag_of_glory_count: number;
  bonuses: Game['bonuses'];
  current_events: CardId[];
  first_player: Game['first_player'];
  fronts: Game['fronts'];
  glory: Game['glory'];
  hand: number[];
  discard: number[];
  deck: number[];
  trash: number[];
  hero_points: Game['hero_points'];
  initiative: Game['initiative'];
  medallions: Game['medallions'];
  played_card: Game['played_card'];
  player_order: Game['player_order'];
  selectable_cards: Game['selectable_cards'];
  tableaus: Game['tableaus'];
  tracks: number[];
  triggered_track_effects: Game['triggered_track_effects'];
  used_medallions: Game['used_medallions'];
  year: number;
}

export type States = {
  [key: string]: any;
};

export type EngineNode = FunctionNode | LeafNode | SeqNode;

export interface FunctionNode {
  t: 'f';
  f: string; // function to be triggered
  a?: any; // args
  r?: 0 | 1; // 1 if resolved
}

export interface SeqNode {
  t: 's'; // Type
  c: EngineNode[];
}

export interface LeafNode<T = any> {
  t: 'l';
  s: string; // State
  p: FactionId | 'None'; // Player
  a?: T; // args
  r?: 0 | 1; // 1 if resolved
}

export interface CardBase {
  id: number;
  title: string;
}

export type Card = EventCard | PlayerCard;

export interface EventCard extends CardBase {
  type: 'ec';
  year: number;
  effects: Effect[];
  test: {
    front: FrontId;
    value: number;
    pass: Effect;
    fail: Effect;
  };
}

export type Icon =
  | 'add_to_front'
  | 'collectivization'
  | 'd_collectivization'
  | 'd_foreign_aid'
  | 'd_government'
  | 'd_liberty'
  | 'd_soviet_support'
  | 'draw_card'
  | 'foreign_aid'
  | 'government'
  | 'government_to_center'
  | 'liberty'
  | 'soviet_support'
  | 'teamwork_on';

export interface PlayerCard extends CardBase {
  type: 'pc';
  strength: number;
  effects: Effect[];
  icons: Icon[];
}

export type EffectSource = 'fascist_event' | 'fascist_test' | 'track_icon' | 'momentum';

export interface Effect {
  type:
    | 'attack'
    | 'track'
    | 'bonus'
    | 'hero_points'
    | 'front'
    | 'function' // Use for unqique effects
    | 'medallion'
    | 'draw_card'
    | 'play_card'
    | 'swap_card_tableau_hand'
    | 'state'
    | 'add_card_to_tableau'
    | 'remove_blank_marker'
    | 'return_card'
    | 'take_hero_points';
  target: string | number | FactionId;
  value: number;
  faction?: FactionId | 'i';
}

export interface StaticData {
  cards: Card[];
  fronts: Array<{
    id: string;
    name: string;
    left: number;
    top: number;
  }>;
  medallions: Array<{
    id: number;
    name: string;
  }>;
  tracks: Array<{
    id: number;
    name: string;
    triggers: Array<null | Effect>;
  }>;
}

// #region engine node args

export interface EngineNodeArgsBase {
  /**
   * If set, node was added to engine as result of given effect.
   * Used for prompts
   */
  src?: EffectSource;
}

export interface ChooseCardArgs extends EngineNodeArgsBase {
}

export interface PlayerTurnArgs extends EngineNodeArgsBase {
  /**
   * When set to true, player can use current card 
   * for action points (using for ap sets it to false)
   */
  use_ap?: boolean;
  /**
   * When set to true, player can use current card for
   * morale bonus if that is active (using morale bonus sets it to dalse)
   */
  use_morale_bonus?: boolean;
  /**
   * Set when starting to resolve event effect from card. Will be set to false
   * after all effects have been resolved. Used to determine if momentum medallion
   * can be used.
   */
  resolving_event?: boolean;
  /**
   * Strength of the current card
   */
  strength?: number;
  /**
   * Set to true if player got momentum medallion,
   * but was not able to resolve directly as they were still
   * resolving their current card
   */
  use_momentum?: boolean;
}

// #endregion