-
Notifications
You must be signed in to change notification settings - Fork 4
/
gamestate_cpp.js
4804 lines (4783 loc) · 181 KB
/
gamestate_cpp.js
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# 1 "gamestate.js"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 417 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "gamestate.js" 2
const fs = require('fs');
const process = require('process');
const uf = require('@leeoniya/ufuzzy');
export const swogi = JSON.parse(fs.readFileSync('swogi.json', 'utf8'));
const names_json = JSON.parse(fs.readFileSync('names.json', 'utf8'));
import { card_actions } from './card_actions.js';
//import { readFileSync } from 'fs';
//let swogi = JSON.parse(readFileSync('swogi.json', 'utf8'));
//import { readFileSync } from 'fs';
//let swogi = JSON.parse(readFileSync('swogi.json', 'utf8'));
let keys = Object.keys(swogi);
keys.sort();
// the base_id of a card is the same id except that it always ends in 1
function get_base_id(card_id) {
return card_id.substring(0, card_id.length-1) + "1";
}
function format_name_level(name, level) {
return name + " (level " + level + ")";
}
export function format_card(card_id) {
//console.log(card_id);
let card_name = swogi[card_id].name;
let card_level = card_id.substring(card_id.length-1);
return format_name_level(card_name, card_level);
}
function actions_contains_str(actions, str) {
if (actions.length > 0 && actions[0] === str) {
return true;
}
for (let i=0; i<actions.length; i++) {
if (Array.isArray(actions[i])) {
if (actions_contains_str(actions[i], str)) {
return true;
}
}
}
return false;
}
function id_is_continuous(card_id) {
return actions_contains_str(swogi[card_id].actions, "continuous");
}
function id_is_consumption(card_id) {
return actions_contains_str(swogi[card_id].actions, "consumption");
}
const SECTS = ["sw", "he", "fe", "dx"];
export const CHARACTER_ID_TO_NAME = {
"sw1": "Mu Yifeng",
"sw2": "Yan Xue",
"sw3": "Long Yao",
"sw4": "Lin Xiaoyue",
"sw5": "Lu Jianxin",
"he1": "Tan Shuyan",
"he2": "Yan Chen",
"he3": "Yao Ling",
"he4": "Jiang Ximing",
"he5": "Wu Ce",
"fe1": "Wu Xingzhi",
"fe2": "Du Lingyuan",
"fe3": "Hua Qinrui",
"fe4": "Mu Hu",
"fe5": "Nangong Sheng",
"dx1": "Xiao Bu",
"dx2": "Tu Kui",
"dx3": "Ye Mingming",
"dx4": "Ji Fangsheng",
}
const PREFIX_TO_MARKING = {
["11"]: "sw", // regular sect cards - cloud spirit sword sect
["12"]: "he", // regular sect cards - heptastar
["13"]: "fe", // regular sect cards - five elements
["14"]: "dx", // regular sect cards - duan xuan
["21"]: "sw", // secret enchantment cards - cloud spirit sword sect
["22"]: "he", // secret enchantment cards - heptastar
["23"]: "fe", // secret enchantment cards - five elements
["24"]: "dx", // secret enchantment cards - duan xuan
["31"]: "el", // side job cards - elixirist
["32"]: "fu", // side job cards - fuluist
["33"]: "mu", // side job cards - musician
["34"]: "pa", // side job cards - painter
["35"]: "fm", // side job cards - formation master
["36"]: "pm", // side job cards - plant master
["37"]: "ft", // side job cards - fortune teller
["40"]: "talisman", // talisman cards
["50"]: "spiritual_pet", // spiritual pet cards
["60"]: "no_marking", // normal attack, event cards
["61"]: "no_marking", // character-specific cards - cloud spirit sword sect
["62"]: "no_marking", // character-specific cards - heptastar
["63"]: "no_marking", // character-specific cards - five elements
["64"]: "no_marking", // character-specific cards - duan xuan
["71"]: "sw", // legendary cards - cloud spirit sword sect
["72"]: "he", // legendary cards - heptastar
["73"]: "fe", // legendary cards - five elements
["74"]: "dx", // legendary cards - duan xuan
["80"]: "no_marking", // zongzi cards
["90"]: "check", // fusion cards - side jobs
["91"]: "check", // fusion cards - cloud spirit sword sect
["92"]: "check", // fusion cards - heptastar
["93"]: "check", // fusion cards - five elements
["94"]: "check", // fusion cards - duan xuan
};
const valid_markings_list = ["no_marking","el", "fu", "mu", "pa", "fm", "pm", "ft", "sw", "he", "fe", "dx", "talisman", "spiritual_pet"];
const valid_markings = new Set(valid_markings_list);
function get_marking(card_id) {
const prefix = card_id.substring(0, 2);
let marking = PREFIX_TO_MARKING[prefix];
if (marking === "check") {
const card = swogi[card_id];
if (card.character !== undefined) {
return "no_marking";
}
const sect = parseInt(card_id.substring(1, 2)) - 1;
if (sect === -1) {
marking = card.marking;
}
if (sect >= 0 && sect < SECTS.length) {
marking = SECTS[sect];
}
}
if (card_id.startsWith("90600")) {
marking = "no_marking";
}
if (!valid_markings.has(marking)) {
throw new Error("suspicious card id " + card_id);
}
return marking;
}
// for the purpose of our little sim, a player of a certain sect
// has access to these cards:
// - all cards of their sect (ID starts with 1 or 2 and the second digit is the sect number)
// - all cards of every side job (ID starts with 3)
// - all talisman cards (ID starts with 4)
// - all spiritual pet cards (ID starts with 5)
// - all "general" no-marking cards (ID starts with 6 and the second digit is 0)
// - all "sect-affiliated" no-marking cards (ID starts with 6 and the second digit is the sect number)
function get_available_deck_cards_for_sect(sect_num) {
let ret = [];
for (let i=0; i<keys.length; i++) {
let card_id = keys[i];
if (card_id.startsWith("1" + sect_num) || card_id.startsWith("2" + sect_num) || card_id.startsWith("3") || card_id.startsWith("4") || card_id.startsWith("5") || card_id.startsWith("60") || card_id.startsWith("6" + sect_num)) {
ret.push(card_id);
}
}
return ret;
}
// divine brush can generate "any sect card" meaning just those cards
// with the marking of the sect of the player
function get_available_divine_brush_cards_for_sect(sect_num) {
let ret = [];
for (let i=0; i<keys.length; i++) {
let card_id = keys[i];
if (card_id.startsWith("1" + sect_num) || card_id.startsWith("2" + sect_num)) {
ret.push(card_id);
}
}
return ret;
}
const SECT_TO_DIVINE_BRUSH_CARDS = {};
const SECT_TO_AVAILABLE_DECK_CARDS = {};
for (let i=0; i<SECTS.length; i++) {
const sect_num = i;
const sect = SECTS[i];
SECT_TO_AVAILABLE_DECK_CARDS[sect] = get_available_deck_cards_for_sect(sect_num);
SECT_TO_DIVINE_BRUSH_CARDS[sect] = get_available_divine_brush_cards_for_sect(sect_num);
}
let is_unrestrained_sword = function(card_id) {
return swogi[card_id].name.includes("Unrestrained Sword");
}
let is_cloud_sword = function(card_id) {
return swogi[card_id].name.includes("Cloud Sword");
}
let is_sword_formation = function(card_id) {
return swogi[card_id].name.includes("Sword Formation");
}
let is_crash_fist = function(card_id) {
return swogi[card_id].name.includes("Crash Fist");
}
let is_wood_spirit = function(card_id) {
return swogi[card_id].name.includes("Wood Spirit");
}
let is_fire_spirit = function(card_id) {
return swogi[card_id].name.includes("Fire Spirit");
}
let is_earth_spirit = function(card_id) {
if (swogi[card_id].name === "Earth Spirit Elixir") {
return false;
}
return swogi[card_id].name.includes("Earth Spirit");
}
let is_metal_spirit = function(card_id) {
return swogi[card_id].name.includes("Metal Spirit");
}
let is_water_spirit = function(card_id) {
return swogi[card_id].name.includes("Water Spirit");
}
let is_add_physique = function(card_id) {
return actions_contains_str(swogi[card_id].actions, "physique");
}
let is_astral_move = function(card_id) {
return swogi[card_id].name.includes("Astral Move");
}
let is_post_action = function(card_id) {
return actions_contains_str(swogi[card_id].actions, "post_action");
}
let is_thunder = function(card_id) {
return swogi[card_id].name.includes("Thunder");
}
let is_seal = function(card_id) {
if (swogi[card_id].name === "Mysterious Gates Devil Seal Tower") {
return false;
}
if (swogi[card_id].name === "Cosmos Seal Divine Orb") {
return false;
}
return swogi[card_id].name.includes("Seal");
}
let is_spirit_sword = function(card_id) {
return swogi[card_id].name.includes("Spirit Sword");
}
function with_default(x, default_val) {
if (x === undefined) {
return default_val;
}
return x;
}
const id_to_names_ = {};
const id_to_name_ = {};
for (let i=0; i<names_json.length; i++) {
const id = names_json[i].id + "";
const names = [];
for (const prop in names_json[i]) {
// if it starts with "name", add it to the names array
if (prop.startsWith("name")) {
names.push(names_json[i][prop]);
}
}
id_to_names_[id] = names;
if (names_json[i].name !== undefined) {
id_to_name_[id] = names_json[i].name;
}
}
for (let i=0; i<keys.length; i++) {
const card_id = keys[i];
if (id_to_names_[card_id] !== undefined) {
swogi[card_id].names = id_to_names_[card_id];
}
if (id_to_name_[card_id] !== undefined) {
swogi[card_id].name = id_to_name_[card_id];
}
}
for (let i=0; i<keys.length; i++) {
const card_id = keys[i];
const base_id = get_base_id(card_id);
const name = with_default(swogi[card_id].name, swogi[base_id].name);
swogi[card_id].name = name;
let names = with_default(swogi[card_id].names, swogi[base_id].names);
if (names === undefined && name !== undefined) {
names = [name];
}
const qi_cost = with_default(swogi[card_id].qi_cost, with_default(swogi[base_id].qi_cost, 0));
const hp_cost = with_default(swogi[card_id].hp_cost, with_default(swogi[base_id].hp_cost, undefined));
const character = with_default(swogi[card_id].character, with_default(swogi[base_id].character, undefined));
const decrease_qi_cost_by_x = with_default(swogi[card_id].decrease_qi_cost_by_x, with_default(swogi[base_id].decrease_qi_cost_by_x, undefined));
const water_spirit_cost_0_qi = with_default(swogi[card_id].water_spirit_cost_0_qi, with_default(swogi[base_id].water_spirit_cost_0_qi, undefined));
const is_salty = with_default(swogi[card_id].is_salty, with_default(swogi[base_id].is_salty, undefined));
const is_sweet = with_default(swogi[card_id].is_sweet, with_default(swogi[base_id].is_sweet, undefined));
const marking = with_default(swogi[card_id].marking, with_default(swogi[base_id].marking, undefined));
const gather_qi = with_default(swogi[card_id].gather_qi, with_default(swogi[base_id].gather_qi, undefined));
const card = {
name: name,
names: names,
qi_cost: qi_cost,
hp_cost: hp_cost,
decrease_qi_cost_by_x: decrease_qi_cost_by_x,
water_spirit_cost_0_qi: water_spirit_cost_0_qi,
gather_qi: gather_qi,
actions: swogi[card_id].actions,
card_actions: card_actions[card_id],
opening: swogi[card_id].opening,
character: character,
is_continuous: id_is_continuous(card_id),
is_consumption: id_is_consumption(card_id),
is_unrestrained_sword: is_unrestrained_sword(card_id),
is_cloud_sword: is_cloud_sword(card_id),
is_sword_formation: is_sword_formation(card_id),
is_crash_fist: is_crash_fist(card_id),
is_wood_spirit: is_wood_spirit(card_id),
is_fire_spirit: is_fire_spirit(card_id),
is_earth_spirit: is_earth_spirit(card_id),
is_metal_spirit: is_metal_spirit(card_id),
is_water_spirit: is_water_spirit(card_id),
is_add_physique: is_add_physique(card_id),
is_astral_move: is_astral_move(card_id),
is_post_action: is_post_action(card_id),
is_thunder: is_thunder(card_id),
is_seal: is_seal(card_id),
is_spirit_sword: is_spirit_sword(card_id),
marking: marking,
is_salty: is_salty,
is_sweet: is_sweet,
};
swogi[card_id] = card;
card.marking = get_marking(card_id);
Object.freeze(card);
}
is_unrestrained_sword = function(card_id) {
return swogi[card_id].is_unrestrained_sword;
}
is_cloud_sword = function(card_id) {
return swogi[card_id].is_cloud_sword;
}
is_sword_formation = function(card_id) {
return swogi[card_id].is_sword_formation;
}
is_crash_fist = function(card_id) {
return swogi[card_id].is_crash_fist;
}
is_wood_spirit = function(card_id) {
return swogi[card_id].is_wood_spirit;
}
is_fire_spirit = function(card_id) {
return swogi[card_id].is_fire_spirit;
}
is_earth_spirit = function(card_id) {
return swogi[card_id].is_earth_spirit;
}
is_metal_spirit = function(card_id) {
return swogi[card_id].is_metal_spirit;
}
is_water_spirit = function(card_id) {
return swogi[card_id].is_water_spirit;
}
is_add_physique = function(card_id) {
return swogi[card_id].is_add_physique;
}
is_astral_move = function(card_id) {
return swogi[card_id].is_astral_move;
}
is_post_action = function(card_id) {
return swogi[card_id].is_post_action;
}
is_thunder = function(card_id) {
return swogi[card_id].is_thunder;
}
is_seal = function(card_id) {
return swogi[card_id].is_seal;
}
is_spirit_sword = function(card_id) {
return swogi[card_id].is_spirit_sword;
}
const CRASH_FIST_CARDS = [[],[],[],[]];
for (let i=0; i<keys.length; i++) {
let card_id = keys[i];
if (is_crash_fist(card_id)) {
let level = parseInt(card_id.substring(card_id.length-1));
CRASH_FIST_CARDS[level].push(card_id);
}
}
const card_names = [];
const card_name_to_id = {};
for (let i=0; i<keys.length; i++) {
const card_id = keys[i];
//console.log(card_id, swogi[card_id].name, swogi[card_id].names);
for (const name of [swogi[card_id].name, ...swogi[card_id].names]) {
if (card_id.endsWith("1")) {
card_names.push(name);
card_name_to_id[name] = card_id;
}
const level = card_id.substring(card_id.length-1);
const another_name = format_name_level(name, level);
card_names.push(another_name);
card_name_to_id[another_name] = card_id;
if (card_id.endsWith("3")) {
const lvmax = name + " (level max)";
card_names.push(lvmax);
card_name_to_id[lvmax] = card_id;
}
}
}
card_names.sort((a, b) => a.length - b.length);
const fuzzy = new uf();
export function card_name_to_id_fuzzy(name) {
if (swogi[name] !== undefined) {
return name;
}
const [idxs, info, order] = fuzzy.search(card_names, name);
if (idxs.length === 0) {
console.log("could not find card with name " + name);
throw new Error("could not find card with name " + name);
}
return card_name_to_id[card_names[idxs[0]]];
}
const DEBUFF_NAMES = [
"internal_injury",
"decrease_atk",
"weaken",
"flaw",
"entangle",
"wound",
"underworld",
"indigestion",
];
function is_debuff(attr_name) {
return attr_name == "internal_injury" ||
attr_name == "decrease_atk" ||
attr_name == "weaken" ||
attr_name == "flaw" ||
attr_name == "entangle" ||
attr_name == "wound" ||
attr_name == "underworld" ||
attr_name == "indigestion";
}
const ACTIVATE_NAMES = ["activate_wood_spirit_stacks", "activate_fire_spirit_stacks", "activate_earth_spirit_stacks", "activate_metal_spirit_stacks", "activate_water_spirit_stacks"];
function is_activate(attr_name) {
return attr_name == "activate_wood_spirit_stacks" ||
attr_name == "activate_fire_spirit_stacks" ||
attr_name == "activate_earth_spirit_stacks" ||
attr_name == "activate_metal_spirit_stacks" ||
attr_name == "activate_water_spirit_stacks";
}
export class Player {
constructor() {
this.cards = [];
this.can_play = []; // used for consumption/continuous cards
this.is_star_point = [];
this.can_post_action = [];
this.skip_one_play = [];
this.reset();
}
reset() {
this.next_card_index = 0;
this.cards.length = 0;
this.can_play.length = 0; // used for consumption/continuous cards
this.is_star_point.length = 0;
this.can_post_action.length = 0;
this.skip_one_play.length = 0;
this.exchange_card_chance = 0;
this.round_number = 15;
this.destiny = 100;
this.cultivation = 70;
this.speed = 0;
this.qi = 0;
this.hp = 400;
this.max_hp = 400;
this.def = 0;
this.this_card_attacked = false; // whether the player has attacked with this card
// TODO: the above is for... nothing?
this.this_card_directly_attacked = false; // whether this card attacked, excluding attacks by triggering other cards
this.this_trigger_directly_attacked = false; // whether this card (the triggering one) attacked, excluding attacks by triggering other cards
this.this_turn_attacked = false; // whether the player has attacked this turn
this.this_atk_injured = false; // whether the enemy hp has been injured by this atk
this.damage_dealt_to_hp_by_atk = 0; // for stuff that keys off how much damage went through to hp
this.damage_dealt_to_hp_by_this_card_atk = 0; // for stuff that keys off how much damage went through to hp for all attacks by this card
this.ignore_def = 0;
this.smash_def = 0;
this.bonus_atk_amt = 0; // card-specific bonus atk
this.bonus_dmg_amt = 0; // card-specific bonus dmg
this.bonus_rep_amt = 0; // card-specific bonus rep
this.bonus_def_amt = 0; // card-specific bonus def
this.bonus_reduce_enemy_hp_amt = 0; // this is getting to be a bit much
this.bonus_reduce_enemy_max_hp_amt = 0;
this.bonus_heal_amt = 0;
this.bonus_max_hp_amt = 0;
this.bonus_force_amt = 0;
this.next_turn_def = 0;
// for situations where multiple chases are allowed (Loong),
// I'm not sure whether a single card chasing two times works the same as two cards chasing once.
// So cards record their chases in `this_card_chases`, and then we can change how we apply that to
// `chases` later. Also, what's the interaction of 2 chase on 1 card with entangle?
// we can check irl i guess...
this.this_card_chases = 0;
this.chases = 0;
this.max_chases = 1;
this.currently_playing_card_idx = undefined;
//this.currently_playing_card_id = undefined;
this.currently_triggering_card_idx = undefined;
this.currently_triggering_card_id = undefined;
this.trigger_depth = 0; // used to decide whether "continuous" and "consumption" deactivate a card
this.increase_atk = 0;
this.regen = 0;
this.hexproof = 0;
// debuffs
this.internal_injury = 0;
this.decrease_atk = 0;
this.weaken = 0;
this.flaw = 0;
this.entangle = 0;
this.wound = 0;
// cloud sword sect normal cards
this.sword_intent_flow_mode = false; // whether the current card is in sword intent flow mode
this.this_card_sword_intent = 0; // the amount of sword intent restored by flying fang sword
this.sword_intent = 0; // the amount of sword intent we currently have in some sense
this.unrestrained_sword_count = 0;
this.cloud_sword_softheart_stacks = 0;
this.cloud_sword_chain_count = 0;
this.centibird_spirit_sword_rhythm_stacks = 0;
this.moon_water_sword_formation_stacks = 0;
this.spirit_gather_citta_dharma_stacks = 0;
this.spirit_gather_citta_dharma_odd_gives_qi = true;
this.unrestrained_sword_zero_stacks = 0;
// cloud sword sect secret enchantment cards
this.bonus_sword_intent_multiplier = 0;
this.ignore_weaken = false;
this.sword_formation_deck_count = 0;
this.other_sword_formation_deck_count = 0;
this.sword_intent_flow_stacks = 0;
this.emptiness_sword_formation_stacks = 0;
this.apex_sword_citta_dharma_stacks = 0;
this.step_moon_into_cloud_stacks = 0;
this.unrestrained_sword_twin_dragons_stacks = 0;
this.cloud_sword_hand_count = 17;
// cloud sword sect character-specific cards
this.hand_count = 17;
this.unrestrained_sword_clear_heart_stacks = 0;
this.cloud_sword_clear_heart_stacks = 0;
// cloud sword sect legendary cards
this.dragon_devours_clouds_stacks = 0;
this.beast_spirit_sword_formation_stacks = 0;
this.triggered_beast_spirit_sword_formation = false;
// heptastar sect normal cards
this.hexagram = 0;
this.star_power = 0;
this.strike_twice_stacks = 0;
this.hp_gained = 0;
this.stillness_citta_dharma_stacks = 0;
this.triggered_hexagram_count = 0;
this.hexagram_formacide_stacks = 0;
this.repel_citta_dharma_stacks = 0;
this.card_play_direction = 1;
this.hunter_hunting_hunter_stacks = 0;
// heptastar sect secret enchantment cards
this.vitality_blossom_stacks = 0;
this.bonus_star_power_multiplier = 0;
this.thunder_citta_dharma_stacks = 0;
this.preemptive_strike_stacks = 0;
this.covert_shift_stacks = 0;
// heptastar sect character-specific cards
this.cannot_act_stacks = 0;
this.reduce_qi_cost_on_star_point_stacks = 0;
// heptastar sect legendary cards
this.spiritual_divination_stacks = 0;
this.throw_petals_stacks = 0;
// five elements sect normal cards
this.last_card_id = "601011";
this.activate_wood_spirit_stacks = 0;
this.activate_fire_spirit_stacks = 0;
this.activate_earth_spirit_stacks = 0;
this.activate_metal_spirit_stacks = 0;
this.activate_water_spirit_stacks = 0;
this.penetrate = 0;
this.force_of_water = 0;
this.cosmos_seal_stacks = 0;
this.wood_spirit_formation_stacks = 0;
this.fire_spirit_formation_stacks = 0;
this.earth_spirit_formation_stacks = 0;
this.metal_spirit_formation_stacks = 0;
this.water_spirit_formation_stacks = 0;
this.earth_spirit_cliff_stacks = 0;
this.metal_spirit_iron_bone_stacks = 0;
this.water_spirit_dive_stacks = 0;
this.earth_spirit_combine_world_stacks = 0;
this.def_lost = 0;
this.metal_spirit_giant_tripod_stacks = 0;
this.disable_penetrate_stacks = 0;
this.ultimate_world_formation_stacks = 0;
this.five_elements_heavenly_marrow_rhythm_stacks = 0;
this.different_five_elements = 0;
this.water_spirit_spring_stacks = 0;
// five elements sect secret enchantment cards
this.metal_spirit_chokehold_stacks = 0;
this.max_hp_lost = 0;
// five elements sect character-specific cards
this.kun_wu_metal_ring_stacks = 0;
this.water_spirit_spring_rain_stacks = 0;
// five elements sect legendary cards
this.wild_crossing_seal_stacks = 0;
this.played_card_count = 0;
// duan xuan sect normal cards
this.agility = 0;
this.physique = 0;
this.max_physique = 0;
this.force = 0;
this.max_force = 6;
this.later_crash_fist_poke_stacks = 0;
this.crash_fist_poke_stacks = 0;
this.crash_fist_block_stacks = 0;
this.crash_fist_bounce_stacks = 0;
this.crash_fist_shake_stacks = 0;
this.crash_fist_entangle_stacks = 0;
this.crash_fist_blitz_stacks = 0;
this.this_card_crash_fist_blitz_stacks = 0;
this.crash_footwork_stacks = 0;
this.crash_fist_truncate_stacks = 0;
this.crash_fist_blink_stacks = 0;
this.crash_fist_inch_force_stacks = 0;
this.this_card_crash_fist_inch_force_stacks = 0;
this.crash_fist_shocked_stacks = 0;
this.this_card_crash_fist_shocked_stacks = 0;
this.elusive_footwork_triggered = false;
this.elusive_footwork_stacks = 0;
this.crash_citta_dharma_stacks = 0;
this.hp_lost = 0;
this.physique_gained = 0;
this.exercise_bones_stacks = 0;
this.majestic_qi_stacks = 0;
this.ignore_decrease_atk = false;
// duan xuan sect secret enchantment cards
this.endless_force_stacks = 0;
this.toxin_immunity_stacks = 0;
this.lying_drunk_stacks = 0;
this.crash_fist_double_stacks = 0;
this.return_to_simplicity_stacks = 0;
// duan xuan sect character-specific cards
this.overwhelming_power_stacks = 0;
this.underworld = 0;
this.character = "sw1";
this.crash_fist_stygian_night_stacks = 0;
this.meditation_of_xuan_stacks = 0;
// musician side job cards
this.carefree_tune_stacks = 0;
this.kindness_tune_stacks = 0;
this.illusion_tune_stacks = 0;
this.heartbroken_tune_stacks = 0;
this.craze_dance_tune_stacks = 0;
this.regen_tune_stacks = 0;
this.predicament_for_immortals_stacks = 0;
this.apparition_confusion_stacks = 0;
this.has_played_musician_card = 0;
// painter side job cards
this.inspiration_stacks = 0;
this.flying_brush_stacks = 0;
this.finishing_touch_stacks = 0;
// formation master side job cards
this.thunderphilia_formation_stacks = 0;
this.fraccide_formation_stacks = 0;
this.scutturtle_formation_stacks = 0;
this.cacopoisonous_formation_stacks = 0;
this.spiritage_formation_stacks = 0;
this.endless_sword_formation_stacks = 0;
this.heavenly_spirit_forceage_formation_stacks = 0;
this.octgates_lock_formation_stacks = 0;
this.motionless_tutelary_formation_stacks = 0;
this.skip_next_card_stacks = 0;
this.has_played_continuous_card = false;
this.anthomania_formation_stacks = 0;
// plant master side job cards
this.hard_bamboo_stacks = 0;
this.leaf_blade_flower_stacks = 0;
this.leaf_shield_flower_stacks = 0;
this.frozen_snow_lotus_stacks = 0;
this.entangling_ancient_vine_stacks = 0;
this.devouring_ancient_vine_stacks = 0;
this.shadow_owl_reishi_stacks = 0;
// fortune teller side job cards
this.observe_body_stacks = 0;
this.god_luck_approach_stacks = 0;
this.god_luck_avoid_stacks = 0;
this.bad_omen_stacks = 0;
this.skip_to_previous_card_stacks = 0;
this.everything_goes_way_stacks = 0;
this.nothing_is_appropriate_stacks = 0;
// TODO: i've heard that after you play fate reincarnates
// skipping an Opening card for any reason will trigger its opening effect
this.fate_reincarnates_stacks = 0;
this.god_opportunity_conform_stacks = 0;
this.god_opportunity_reversal_stacks = 0;
// talisman cards
this.carefree_guqin_stacks = 0;
// spiritual pet cards
this.break_sky_eagle_stacks = 0;
this.fat_immortal_raccoon_stacks = 0;
this.dark_star_bat_stacks = 0;
this.lonely_night_wolf_stacks = 0;
this.black_earth_turtle_stacks = 0;
this.brocade_rat_stacks = 0;
this.scarlet_eye_the_sky_consumer_stacks = 0;
this.ashes_phoenix_stacks = 0;
this.three_tailed_cat_stacks = 0;
this.colorful_spirit_crane_stacks = 0;
this.shadow_owl_rabbit_stacks = 0;
this.void_the_spirit_consumer_stacks = 0;
this.nether_void_canine_stacks = 0;
// general immortal fates
this.p2_store_qi_stacks = 0;
this.p3_store_qi_stacks = 0;
this.p4_store_qi_stacks = 0;
this.p5_store_qi_stacks = 0;
// cloud sword sect immortal fates
this.sword_in_sheathed_stacks = 0;
this.endurance_as_cloud_sea_stacks = 0;
this.fire_flame_blade_stacks = 0;
this.drift_ice_blade_stacks = 0;
this.coral_sword_stacks = 0;
this.lithe_as_cat_stacks = 0;
this.blade_forging_sharpness_stacks = 0;
this.blade_forging_stable_stacks = 0;
this.sword_pattern_carving_chain_attack_stacks = 0;
this.sword_pattern_carving_charge_stacks = 0;
this.sword_pattern_carving_intense_stacks = 0;
this.qi_forging_spiritage_stacks = 0;
this.qi_forging_spiritstat_stacks = 0;
this.qi_forging_spiritual_power_stacks = 0;
this.quench_of_sword_heart_unrestrained_stacks = 0;
this.quench_of_sword_heart_cloud_stacks = 0;
this.quench_of_sword_heart_ultimate_stacks = 0;
this.p4_mad_obsession_stacks = 0;
this.p5_mad_obsession_stacks = 0;
this.p2_rule_of_the_cloud_stacks = 0;
this.p3_rule_of_the_cloud_stacks = 0;
this.p4_rule_of_the_cloud_stacks = 0;
this.p5_rule_of_the_cloud_stacks = 0;
this.p2_sword_rhyme_cultivate_stacks = 0;
this.p3_sword_rhyme_cultivate_stacks = 0;
this.p4_sword_rhyme_cultivate_stacks = 0;
this.p5_sword_rhyme_cultivate_stacks = 0;
this.p2_sword_formation_guard_stacks = 0;
this.p3_sword_formation_guard_stacks = 0;
this.p4_sword_formation_guard_stacks = 0;
this.p5_sword_formation_guard_stacks = 0;
// heptastar sect immortal fates
this.birdie_wind_stacks = 0;
this.astrology_stacks = 0;
this.heptastar_soulstat_stacks = 0;
this.astral_divination_hexagram_stacks = 0;
this.star_moon_folding_fan_stacks = 0;
this.act_underhand_stacks = 0;
this.rest_and_outwit_stacks = 0;
this.ultimate_hexagram_base_stacks = 0;
this.p2_divination_stacks = 0;
this.p3_divination_stacks = 0;
this.p4_divination_stacks = 0;
this.p5_divination_stacks = 0;
this.p2_stargaze_stacks = 0;
this.p3_stargaze_stacks = 0;
this.p4_stargaze_stacks = 0;
this.p5_stargaze_stacks = 0;
this.p2_astral_eclipse_stacks = 0;
this.p3_astral_eclipse_stacks = 0;
this.p4_astral_eclipse_stacks = 0;
this.p5_astral_eclipse_stacks = 0;
this.gain_extra_debuff = 0;
this.p2_post_strike_stacks = 0;
this.p3_post_strike_stacks = 0;
this.p4_post_strike_stacks = 0;
this.p5_post_strike_stacks = 0;
this.has_post_strike = false;
this.p2_rejuvenation_stacks = 0;
this.p3_rejuvenation_stacks = 0;
this.p4_rejuvenation_stacks = 0;
this.p5_rejuvenation_stacks = 0;
this.has_rejuvenation = false;
// five elements sect immortal fates
this.fire_spirit_generation_stacks = 0;
this.flame_soul_rebirth_stacks = 0;
this.five_elements_explosion_stacks = 0;
this.swift_burning_seal_stacks = 0;
this.mark_of_five_elements_stacks = 0;
this.innate_wood_stacks = 0;
this.innate_fire_stacks = 0;
this.innate_earth_stacks = 0;
this.innate_metal_stacks = 0;
this.innate_water_stacks = 0;
this.innate_mark_stacks = 0;
this.five_elements_anima_stacks = 0;
this.peach_branch_ruyi_stacks = 0;
this.mark_of_water_spirit_stacks = 0;
this.blossom_dance_stacks = 0;
this.the_body_of_fierce_tiger_stacks = 0;
this.p2_cycle_of_five_elements_stacks = 0;
this.p3_cycle_of_five_elements_stacks = 0;
this.p4_cycle_of_five_elements_stacks = 0;
this.p5_cycle_of_five_elements_stacks = 0;
this.p2_mutual_growth_stacks = 0;
this.p3_mutual_growth_stacks = 0;
this.p4_mutual_growth_stacks = 0;
this.p5_mutual_growth_stacks = 0;
this.mutual_growth_stacks = 0;
this.p2_concentrated_element_stacks = 0;
this.p3_concentrated_element_stacks = 0;
this.p4_concentrated_element_stacks = 0;
this.p5_concentrated_element_stacks = 0;
this.flame_soul_rebirth_reviving = false;
this.just_revived = false;
// duan xuan sect immortal fates
this.unbounded_qi_stacks = 0;
this.unwavering_soul_stacks = 0;
this.courage_to_fight_stacks = 0;
this.cracking_fist_stacks = 0;
this.stance_of_fierce_attack_stacks = 0;
this.p2_firmness_body_stacks = 0;
this.p3_firmness_body_stacks = 0;
this.p4_firmness_body_stacks = 0;
this.p5_firmness_body_stacks = 0;
this.p2_regenerating_body_stacks = 0;
this.p3_regenerating_body_stacks = 0;
this.p4_regenerating_body_stacks = 0;
this.p5_regenerating_body_stacks = 0;
this.p2_full_of_force_stacks = 0;
this.p3_full_of_force_stacks = 0;
this.p4_full_of_force_stacks = 0;
this.p5_full_of_force_stacks = 0;
this.p2_mark_of_dark_heart_stacks = 0;
this.p3_mark_of_dark_heart_stacks = 0;
this.p4_mark_of_dark_heart_stacks = 0;
this.p5_mark_of_dark_heart_stacks = 0;
this.entering_styx_stacks = 0;
this.zen_mind_forging_body_stacks = 0;
this.mind_body_resonance_stacks = 0;
// life shop buffs
this.pact_of_adversity_reinforcement_stacks = 0;
this.pact_of_equilibrium_stacks = 0;
// super serious event buffs
this.alkaline_water_zongzi_stacks = 0;
this.fresh_fruit_zongzi_stacks = 0;
this.salted_egg_yolk_zongzi_stacks = 0;
this.mixed_grain_zongzi_stacks = 0;
this.sweet_zongzi_count = 0;
this.appetite = 0;
this.indigestion = 0;
// immortal relics fusion cards
this.ultimate_polaris_hexagram_base_stacks = 0;
this.star_moon_hexagram_fan_stacks = 0;
this.kun_wu_molten_ring_stacks = 0;
this.heavenly_marrow_gourd_stacks = 0;
this.ultimate_overcome_formation_stacks = 0;
this.wood_spirit_all_things_grow_stacks = 0;
this.styx_night_footwork_triggered = false;
this.styx_night_footwork_stacks = 0;
this.crash_fist_return_to_xuan_stacks = 0;
this.star_sky_forge_bone_stacks = 0;
this.crash_fist_star_seizing_stacks = 0;
this.this_card_crash_fist_star_seizing_stacks = 0;
this.chase_if_hp_gained = 0;
this.nuwa_stone_stacks = 0;
this.is_triggering_donghuang_zhong = 0;
this.is_triggering_kunlun_mirror = 0;
this.pangu_axe_stacks = 0;
this.kongtong_seal_stacks = 0;
this.spirit_fusion_pot_stacks = 0;
this.heavenly_maiden_white_jade_ring_stacks = 0;
this.prevent_anti_chase = 0;
this.xuanming_forceage_formation_stacks = 0;
this.xuanming_regen_tune_heal_stacks = 0;
this.xuanming_regen_tune_hurt_stacks = 0;
this.xuanming_recurring_hp = 0;
// merpeople pearls
this.qi_gathering_merpeople_pearl_stacks = 0;
this.crystallized_merpeople_pearl_stacks = 0;
}
reset_can_play() {
this.cards = this.cards.slice();
this.can_play.length = 0;
this.is_star_point.length = 0;
this.can_post_action.length = 0;
this.skip_one_play.length = 0;
const n_cards = this.cards.length;
for (let i=0; i<n_cards; i++) {
this.can_play.push(true);
this.is_star_point.push(false);
this.can_post_action.push(false);
this.skip_one_play.push(false);
}
if (2 < n_cards) {
this.is_star_point[2] = true;
}
if (5 < n_cards) {
this.is_star_point[5] = true;
}
if (swogi[this.cards[n_cards - 1]].name === "Space Spiritual Field") {
this.skip_one_play[n_cards - 1] = true;
}
if (swogi[this.cards[n_cards - 2]].name === "Space Spiritual Field") {
this.skip_one_play[n_cards - 2] = true;
}
if (this.cards[n_cards - 1] === "601011" && this.heptastar_soulstat_stacks > 0) {
this.cards[n_cards - 1] = "624011";
}
if (this.star_moon_folding_fan_stacks > 0 && this.cards.length > 6) {
this.is_star_point[6] = true;
}
let has_wood = false;
let has_fire = false;
let has_earth = false;
let has_metal = false;
let has_water = false;
let different_elements = 0;
for (let i=0; i<this.cards.length; i++) {
let card_id = this.cards[i];
let card = swogi[card_id];
if (card.is_wood_spirit && !has_wood) {
has_wood = true;
different_elements += 1;
}
if (card.is_fire_spirit && !has_fire) {
has_fire = true;
different_elements += 1;
}
if (card.is_earth_spirit && !has_earth) {
has_earth = true;
different_elements += 1;
}
if (card.is_metal_spirit && !has_metal) {
has_metal = true;
different_elements += 1;
}
if (card.is_water_spirit && !has_water) {
has_water = true;
different_elements += 1;
}
}
this.different_five_elements = different_elements;
this.cosmos_seal_stacks = this.mark_of_five_elements_stacks;
}
reset_deck_counts() {
const n_cards = this.cards.length;
for (let i=0; i<n_cards; i++) {
let card_id = this.cards[i];
let card = swogi[card_id];
if (card.is_sword_formation) {
this.sword_formation_deck_count += 1;
}
}
}
post_deck_setup() {
this.xuanming_recurring_hp = this.hp;
this.reset_can_play();
this.reset_deck_counts();
}
}
export class GameState {
constructor(a, b) {
this.indentation = "";
if (a === undefined) {
a = new Player();
} else {
a.reset();
}
if (b === undefined) {
b = new Player();
} else {
b.reset();
}
this.players = [a, b];
this.output = [];
this.used_randomness = false;
}
crash() {
this.dump();
console.trace();
process.exit(1);
}
dump() {
console.log(this.output.join("\n"));
}
log(str) {
this.output.push(this.indentation + str);
//console.log(this.indentation + str);
}
indent() {
this.indentation += " ";
}
unindent() {
this.indentation = this.indentation.substring(2);
}
do_coral_sword(idx) {
for (let i=0; i<this.players[idx].coral_sword_stacks; i++) {
this.increase_idx_x_by_c(idx, "ignore_def", 2);
}
}
do_store_qi(idx) {
const me = this.players[idx];
for (let i=0; i<me.p2_store_qi_stacks; i++) {
this.increase_idx_x_by_c(idx, "qi", 1);
}
for (let i=0; i<me.p3_store_qi_stacks; i++) {
this.increase_idx_x_by_c(idx, "qi", 1);
}
for (let i=0; i<me.p4_store_qi_stacks; i++) {
this.increase_idx_x_by_c(idx, "qi", 2);
}
for (let i=0; i<me.p5_store_qi_stacks; i++) {
this.increase_idx_x_by_c(idx, "qi", 3);
}
}
do_mad_obsession(idx) {
const me = this.players[idx];
this.increase_idx_x_by_c(idx, "unrestrained_sword_count", me.p4_mad_obsession_stacks);