summaryrefslogtreecommitdiff
path: root/types.d.ts
blob: eda1c590f0ebe70361ff2cbbacdd2402d6e30b56 (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
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;
  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;
  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;
  actions?: any;
  victory?: string;

  selected_cards: CardId[];
  bag_of_glory: Game['bag_of_glory'];
  bonuses: Game['bonuses'];
  current_events: CardId[];
  fronts: Game['fronts'];
  glory: Game['glory'];
  hand: CardId[];
  hero_points: Game['hero_points'];
  initiative: Game['initiative'];
  medallions: Game['medallions'];
  played_card: Game['played_card'];
  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: 'l';
  s: string; // State
  p: FactionId | 'None'; // Player
  a?: any; // 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 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>;
  }>;
}