-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathChoiceScreenUtils.java
More file actions
898 lines (822 loc) · 34.2 KB
/
ChoiceScreenUtils.java
File metadata and controls
898 lines (822 loc) · 34.2 KB
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
package communicationmod;
import basemod.ReflectionHacks;
import com.badlogic.gdx.Gdx;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.cards.CardGroup;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.dungeons.TheEnding;
import com.megacrit.cardcrawl.events.AbstractImageEvent;
import com.megacrit.cardcrawl.events.GenericEventDialog;
import com.megacrit.cardcrawl.events.RoomEventDialog;
import com.megacrit.cardcrawl.events.shrines.GremlinMatchGame;
import com.megacrit.cardcrawl.events.shrines.GremlinWheelGame;
import com.megacrit.cardcrawl.helpers.Hitbox;
import com.megacrit.cardcrawl.helpers.input.InputHelper;
import com.megacrit.cardcrawl.map.DungeonMap;
import com.megacrit.cardcrawl.map.MapRoomNode;
import com.megacrit.cardcrawl.relics.AbstractRelic;
import com.megacrit.cardcrawl.rewards.RewardItem;
import com.megacrit.cardcrawl.rewards.chests.AbstractChest;
import com.megacrit.cardcrawl.rooms.*;
import com.megacrit.cardcrawl.screens.CardRewardScreen;
import com.megacrit.cardcrawl.screens.mainMenu.MenuCancelButton;
import com.megacrit.cardcrawl.screens.select.BossRelicSelectScreen;
import com.megacrit.cardcrawl.screens.select.GridCardSelectScreen;
import com.megacrit.cardcrawl.screens.select.HandCardSelectScreen;
import com.megacrit.cardcrawl.shop.ShopScreen;
import com.megacrit.cardcrawl.shop.StorePotion;
import com.megacrit.cardcrawl.shop.StoreRelic;
import com.megacrit.cardcrawl.ui.buttons.*;
import com.megacrit.cardcrawl.ui.campfire.AbstractCampfireOption;
import communicationmod.patches.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ChoiceScreenUtils {
private static final Logger logger = LogManager.getLogger(ChoiceScreenUtils.class.getName());
public enum ChoiceType {
EVENT,
CHEST,
SHOP_ROOM,
REST,
CARD_REWARD,
COMBAT_REWARD,
MAP,
BOSS_REWARD,
SHOP_SCREEN,
GRID,
HAND_SELECT,
GAME_OVER,
COMPLETE,
NONE
}
public enum EventDialogType {
IMAGE, ROOM, NONE
}
public static ChoiceType getCurrentChoiceType() {
if (!AbstractDungeon.isScreenUp) {
if (AbstractDungeon.getCurrRoom().phase == AbstractRoom.RoomPhase.EVENT || (AbstractDungeon.getCurrRoom().event != null && AbstractDungeon.getCurrRoom().phase == AbstractRoom.RoomPhase.COMPLETE)) {
return ChoiceType.EVENT;
} else if (AbstractDungeon.getCurrRoom() instanceof TreasureRoomBoss || AbstractDungeon.getCurrRoom() instanceof TreasureRoom) {
return ChoiceType.CHEST;
} else if (AbstractDungeon.getCurrRoom() instanceof ShopRoom) {
return ChoiceType.SHOP_ROOM;
} else if (AbstractDungeon.getCurrRoom() instanceof RestRoom) {
return ChoiceType.REST;
} else if (AbstractDungeon.getCurrRoom().phase == AbstractRoom.RoomPhase.COMPLETE && AbstractDungeon.actionManager.isEmpty() && !AbstractDungeon.isFadingOut) {
if (AbstractDungeon.getCurrRoom().event == null || (!(AbstractDungeon.getCurrRoom().event instanceof AbstractImageEvent) && (!AbstractDungeon.getCurrRoom().event.hasFocus))) {
return ChoiceType.COMPLETE;
}
} else {
return ChoiceType.NONE;
}
}
AbstractDungeon.CurrentScreen screen = AbstractDungeon.screen;
switch(screen) {
case CARD_REWARD:
return ChoiceType.CARD_REWARD;
case COMBAT_REWARD:
return ChoiceType.COMBAT_REWARD;
case MAP:
return ChoiceType.MAP;
case BOSS_REWARD:
return ChoiceType.BOSS_REWARD;
case SHOP:
return ChoiceType.SHOP_SCREEN;
case GRID:
return ChoiceType.GRID;
case HAND_SELECT:
return ChoiceType.HAND_SELECT;
case DEATH:
case VICTORY:
case UNLOCK:
case NEOW_UNLOCK:
return ChoiceType.GAME_OVER;
default:
return ChoiceType.NONE;
}
}
public static ArrayList<String> getCurrentChoiceList() {
ChoiceType choiceType = getCurrentChoiceType();
ArrayList<String> choices;
switch (choiceType) {
case EVENT:
choices = getEventScreenChoices();
break;
case CHEST:
choices = getChestRoomChoices();
break;
case SHOP_ROOM:
choices = getShopRoomChoices();
break;
case REST:
choices = getRestRoomChoices();
break;
case CARD_REWARD:
choices = getCardRewardScreenChoices();
break;
case COMBAT_REWARD:
choices = getCombatRewardScreenChoices();
break;
case MAP:
choices = getMapScreenChoices();
break;
case BOSS_REWARD:
choices = getBossRewardScreenChoices();
break;
case SHOP_SCREEN:
choices = getShopScreenChoices();
break;
case GRID:
choices = getGridScreenChoices();
break;
case HAND_SELECT:
choices = getHandSelectScreenChoices();
break;
default:
return new ArrayList<>();
}
ArrayList<String> lowerCaseChoices = new ArrayList<>();
for(String item : choices) {
lowerCaseChoices.add(item.toLowerCase());
}
return lowerCaseChoices;
}
public static void executeChoice(int choice_index) {
ChoiceType choiceType = getCurrentChoiceType();
switch (choiceType) {
case EVENT:
makeEventChoice(choice_index);
return;
case CHEST:
makeChestRoomChoice(choice_index);
return;
case SHOP_ROOM:
makeShopRoomChoice(choice_index);
return;
case REST:
makeRestRoomChoice(choice_index);
return;
case CARD_REWARD:
makeCardRewardChoice(choice_index);
return;
case COMBAT_REWARD:
makeCombatRewardChoice(choice_index);
return;
case MAP:
makeMapChoice(choice_index);
return;
case BOSS_REWARD:
makeBossRewardChoice(choice_index);
return;
case SHOP_SCREEN:
makeShopScreenChoice(choice_index);
return;
case GRID:
makeGridScreenChoice(choice_index);
return;
case HAND_SELECT:
makeHandSelectScreenChoice(choice_index);
return;
default:
logger.info("Unimplemented choice.");
}
}
private static boolean isCancelButtonAvailable(ChoiceType choiceType) {
switch (choiceType) {
case EVENT:
return false;
case CHEST:
return false;
case SHOP_ROOM:
return false;
case REST:
return false;
case CARD_REWARD:
return isCardRewardSkipAvailable();
case COMBAT_REWARD:
return isCombatRewardCloseAvailable();
case MAP:
return AbstractDungeon.dungeonMapScreen.dismissable;
case BOSS_REWARD:
return true;
case SHOP_SCREEN:
return true;
case GRID:
return isGridScreenCancelAvailable();
case HAND_SELECT:
return false;
case GAME_OVER:
return false;
case COMPLETE:
return false;
default:
return false;
}
}
public static boolean isCancelButtonAvailable() {
return isCancelButtonAvailable(getCurrentChoiceType());
}
private static String getCancelButtonText(ChoiceType choiceType) {
switch (choiceType) {
case CARD_REWARD:
return "skip";
case COMBAT_REWARD:
return "skip";
case MAP:
return "return";
case BOSS_REWARD:
return "skip";
case SHOP_SCREEN:
return "leave";
case GRID:
return "cancel";
default:
return "cancel";
}
}
public static String getCancelButtonText() {
return getCancelButtonText(getCurrentChoiceType());
}
private static void pressCancelButton(ChoiceType choiceType) {
switch (choiceType) {
case CARD_REWARD:
case COMBAT_REWARD:
AbstractDungeon.closeCurrentScreen();
return;
case MAP:
clickCancelButton();
return;
case BOSS_REWARD:
MenuCancelButton button = (MenuCancelButton)ReflectionHacks.getPrivate(AbstractDungeon.bossRelicScreen, BossRelicSelectScreen.class, "cancelButton");
button.hb.clicked = true;
return;
case SHOP_SCREEN:
clickCancelButton();
return;
case GRID:
clickCancelButton();
}
}
public static void pressCancelButton() {
pressCancelButton(getCurrentChoiceType());
}
private static boolean isConfirmButtonAvailable(ChoiceType choiceType) {
switch (choiceType) {
case EVENT:
return false;
case CHEST:
return true;
case SHOP_ROOM:
return true;
case REST:
return isRestRoomProceedAvailable();
case CARD_REWARD:
return false;
case COMBAT_REWARD:
return true;
case MAP:
return false;
case BOSS_REWARD:
return false;
case SHOP_SCREEN:
return false;
case GRID:
return isGridScreenConfirmAvailable();
case HAND_SELECT:
return isHandSelectConfirmButtonEnabled();
case GAME_OVER:
return true;
case COMPLETE:
return true;
default:
return false;
}
}
public static boolean isConfirmButtonAvailable() {
return isConfirmButtonAvailable(getCurrentChoiceType());
}
private static String getConfirmButtonText(ChoiceType choiceType) {
switch (choiceType) {
case CHEST:
return "proceed";
case SHOP_ROOM:
return "proceed";
case REST:
return "proceed";
case COMBAT_REWARD:
return "proceed";
case GRID:
return "confirm";
case HAND_SELECT:
return "confirm";
case GAME_OVER:
return "proceed";
case COMPLETE:
return "proceed";
default:
return "confirm";
}
}
public static String getConfirmButtonText() {
return getConfirmButtonText(getCurrentChoiceType());
}
public static void pressConfirmButton(ChoiceType choiceType) {
switch (choiceType) {
case CHEST:
clickProceedButton();
return;
case SHOP_ROOM:
clickProceedButton();
return;
case REST:
clickProceedButton();
return;
case COMBAT_REWARD:
clickProceedButton();
return;
case GRID:
clickGridScreenConfirmButton();
return;
case HAND_SELECT:
clickHandSelectScreenConfirmButton();
return;
case GAME_OVER:
clickGameOverReturnButton();
return;
case COMPLETE:
clickProceedButton();
}
}
public static void pressConfirmButton() {
pressConfirmButton(getCurrentChoiceType());
}
public static ArrayList<String> getCardRewardScreenChoices() {
ArrayList<String> choices = new ArrayList<>();
for(AbstractCard card : AbstractDungeon.cardRewardScreen.rewardGroup) {
choices.add(card.name.toLowerCase());
}
if(isBowlAvailable()) {
choices.add("bowl");
}
return choices;
}
public static boolean isBowlAvailable() {
SingingBowlButton bowlButton = (SingingBowlButton) ReflectionHacks.getPrivate(AbstractDungeon.cardRewardScreen, CardRewardScreen.class, "bowlButton");
return !((boolean) ReflectionHacks.getPrivate(bowlButton, SingingBowlButton.class, "isHidden"));
}
public static boolean isCardRewardSkipAvailable() {
SkipCardButton skipButton = (SkipCardButton) ReflectionHacks.getPrivate(AbstractDungeon.cardRewardScreen, CardRewardScreen.class, "skipButton");
return !((boolean) ReflectionHacks.getPrivate(skipButton, SkipCardButton.class, "isHidden"));
}
public static boolean isCombatRewardCloseAvailable() {
CancelButton cancelButton = AbstractDungeon.overlayMenu.cancelButton;
return !cancelButton.isHidden;
}
public static void makeCardRewardChoice(int choice) {
ArrayList<String> choices = getCardRewardScreenChoices();
if(choices.get(choice).equals("bowl")) {
SingingBowlButton bowlButton = (SingingBowlButton) ReflectionHacks.getPrivate(AbstractDungeon.cardRewardScreen, CardRewardScreen.class, "bowlButton");
bowlButton.onClick();
AbstractDungeon.cardRewardScreen.closeFromBowlButton();
AbstractDungeon.closeCurrentScreen();
} else {
AbstractCard selectedCard = AbstractDungeon.cardRewardScreen.rewardGroup.get(choice);
CardRewardScreenPatch.doHover = true;
CardRewardScreenPatch.hoverCard = selectedCard;
selectedCard.hb.clicked = true;
}
}
public static ArrayList<String> getHandSelectScreenChoices() {
ArrayList<String> choices = new ArrayList<>();
HandCardSelectScreen screen = AbstractDungeon.handCardSelectScreen;
if(screen.numCardsToSelect == screen.selectedCards.group.size()) {
return choices;
}
for(AbstractCard card : AbstractDungeon.player.hand.group) {
choices.add(card.name.toLowerCase());
}
return choices;
}
public static void makeHandSelectScreenChoice(int choice) {
HandCardSelectScreen screen = AbstractDungeon.handCardSelectScreen;
screen.hoveredCard = AbstractDungeon.player.hand.group.get(choice);
screen.hoveredCard.setAngle(0.0f, false); // This might not be necessary
try {
Method hotkeyCheck = HandCardSelectScreen.class.getDeclaredMethod("selectHoveredCard");
hotkeyCheck.setAccessible(true);
hotkeyCheck.invoke(screen);
} catch(NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
throw new RuntimeException("selectHoveredCard method somehow can't be called.");
}
}
private static void clickHandSelectScreenConfirmButton() {
HandCardSelectScreen screen = AbstractDungeon.handCardSelectScreen;
screen.button.hb.clicked = true;
}
private static boolean isHandSelectConfirmButtonEnabled() {
CardSelectConfirmButton button = AbstractDungeon.handCardSelectScreen.button;
boolean isHidden = (boolean)ReflectionHacks.getPrivate(button, CardSelectConfirmButton.class, "isHidden");
boolean isDisabled = button.isDisabled;
return !(isHidden || isDisabled);
}
public static ArrayList<AbstractCard> getGridScreenCards() {
GridCardSelectScreen screen = AbstractDungeon.gridSelectScreen;
CardGroup cards = (CardGroup) ReflectionHacks.getPrivate(screen, GridCardSelectScreen.class, "targetGroup");
return cards.group;
}
public static ArrayList<String> getGridScreenChoices() {
ArrayList<String> choices = new ArrayList<>();
if(AbstractDungeon.gridSelectScreen.confirmScreenUp || AbstractDungeon.gridSelectScreen.isJustForConfirming) {
return choices;
}
for(AbstractCard card : getGridScreenCards()) {
choices.add(card.name.toLowerCase());
}
return choices;
}
public static void makeGridScreenChoice (int choice) {
GridCardSelectScreen screen = AbstractDungeon.gridSelectScreen;
GridCardSelectScreenPatch.hoverCard = getGridScreenCards().get(choice);
GridCardSelectScreenPatch.replaceHoverCard = true;
}
private static void clickGridScreenConfirmButton() {
GridCardSelectScreen screen = AbstractDungeon.gridSelectScreen;
screen.confirmButton.hb.clicked = true;
if (AbstractDungeon.previousScreen == AbstractDungeon.CurrentScreen.SHOP) {
// The rest of the associated shop purge logic will not run in this update, so we need to block until it does.
GameStateListener.blockStateUpdate();
}
}
private static boolean isGridScreenCancelAvailable() {
GridCardSelectScreen screen = AbstractDungeon.gridSelectScreen;
boolean canCancel = (boolean)ReflectionHacks.getPrivate(screen, GridCardSelectScreen.class, "canCancel");
if(canCancel && (screen.forPurge || screen.forTransform || screen.forUpgrade || (AbstractDungeon.previousScreen == AbstractDungeon.CurrentScreen.SHOP))) {
return true;
} else {
return screen.confirmScreenUp;
}
}
private static boolean isGridScreenConfirmAvailable() {
GridCardSelectScreen screen = AbstractDungeon.gridSelectScreen;
if (screen.confirmScreenUp || screen.isJustForConfirming) {
return true;
} else if ((!screen.confirmButton.isDisabled) && (!(boolean)ReflectionHacks.getPrivate(screen.confirmButton, GridSelectConfirmButton.class, "isHidden")) ) {
if(screen.forUpgrade || screen.forTransform || screen.forPurge || screen.anyNumber) {
return true;
}
}
return false;
}
public static ArrayList<String> getCombatRewardScreenChoices() {
ArrayList<String> choices = new ArrayList<>();
for(RewardItem reward : AbstractDungeon.combatRewardScreen.rewards) {
choices.add(reward.type.name().toLowerCase());
}
return choices;
}
public static void makeCombatRewardChoice(int choice) {
RewardItem reward = AbstractDungeon.combatRewardScreen.rewards.get(choice);
reward.isDone = true;
}
public static ArrayList<String> getBossRewardScreenChoices() {
ArrayList<String> choices = new ArrayList<>();
for(AbstractRelic relic : AbstractDungeon.bossRelicScreen.relics) {
choices.add(relic.name);
}
return choices;
}
public static void makeBossRewardChoice(int choice) {
AbstractRelic chosenRelic = AbstractDungeon.bossRelicScreen.relics.get(choice);
AbstractRelicUpdatePatch.doHover = true;
AbstractRelicUpdatePatch.hoverRelic = chosenRelic;
InputHelper.justClickedLeft = true;
}
public static ArrayList<String> getChestRoomChoices() {
ArrayList<String> choices = new ArrayList<>();
AbstractChest chest = null;
if (AbstractDungeon.getCurrRoom() instanceof TreasureRoomBoss) {
chest = ((TreasureRoomBoss) AbstractDungeon.getCurrRoom()).chest;
} else if (AbstractDungeon.getCurrRoom() instanceof TreasureRoom) {
chest = ((TreasureRoom) AbstractDungeon.getCurrRoom()).chest;
}
if (chest != null && !chest.isOpen) {
choices.add("open");
}
return choices;
}
public static void makeChestRoomChoice (int choice) {
if (AbstractDungeon.getCurrRoom() instanceof TreasureRoomBoss) {
AbstractChest chest = ((TreasureRoomBoss) AbstractDungeon.getCurrRoom()).chest;
chest.isOpen = true;
chest.open(false);
} else if (AbstractDungeon.getCurrRoom() instanceof TreasureRoom) {
AbstractChest chest = ((TreasureRoom) AbstractDungeon.getCurrRoom()).chest;
chest.isOpen = true;
chest.open(false);
}
}
public static ArrayList<String> getShopRoomChoices() {
ArrayList<String> choices = new ArrayList<>();
choices.add("shop");
return choices;
}
public static void makeShopRoomChoice (int choice) {
MerchantPatch.visitMerchant = true;
}
public static ArrayList<String> getShopScreenChoices() {
ArrayList<String> choices = new ArrayList<>();
ArrayList<Object> shopItems = getAvailableShopItems();
for (Object item : shopItems) {
if (item instanceof String) {
choices.add((String) item);
} else if (item instanceof AbstractCard) {
choices.add(((AbstractCard) item).name.toLowerCase());
} else if (item instanceof StoreRelic) {
choices.add(((StoreRelic)item).relic.name);
} else if (item instanceof StorePotion) {
choices.add(((StorePotion)item).potion.name);
}
}
return choices;
}
@SuppressWarnings("unchecked")
public static ArrayList<AbstractCard> getShopScreenCards() {
ArrayList<AbstractCard> cards = new ArrayList<>();
ShopScreen screen = AbstractDungeon.shopScreen;
ArrayList<AbstractCard> coloredCards = (ArrayList<AbstractCard>) ReflectionHacks.getPrivate(screen, ShopScreen.class, "coloredCards");
ArrayList<AbstractCard> colorlessCards = (ArrayList<AbstractCard>) ReflectionHacks.getPrivate(screen, ShopScreen.class, "colorlessCards");
cards.addAll(coloredCards);
cards.addAll(colorlessCards);
return cards;
}
@SuppressWarnings("unchecked")
public static ArrayList<StoreRelic> getShopScreenRelics() {
ShopScreen screen = AbstractDungeon.shopScreen;
return (ArrayList<StoreRelic>) ReflectionHacks.getPrivate(screen, ShopScreen.class, "relics");
}
@SuppressWarnings("unchecked")
public static ArrayList<StorePotion> getShopScreenPotions() {
ShopScreen screen = AbstractDungeon.shopScreen;
return (ArrayList<StorePotion>) ReflectionHacks.getPrivate(screen, ShopScreen.class, "potions");
}
private static ArrayList<Object> getAvailableShopItems() {
ArrayList<Object> choices = new ArrayList<>();
ShopScreen screen = AbstractDungeon.shopScreen;
if(screen.purgeAvailable && AbstractDungeon.player.gold >= ShopScreen.actualPurgeCost) {
choices.add("purge");
}
for(AbstractCard card : getShopScreenCards()) {
if(card.price <= AbstractDungeon.player.gold) {
choices.add(card);
}
}
for(StoreRelic relic : getShopScreenRelics()) {
if(relic.price <= AbstractDungeon.player.gold) {
choices.add(relic);
}
}
for(StorePotion potion : getShopScreenPotions()) {
if(potion.price <= AbstractDungeon.player.gold) {
choices.add(potion);
}
}
return choices;
}
public static void makeShopScreenChoice(int choice) {
ArrayList<Object> shopItems = getAvailableShopItems();
Object shopItem = shopItems.get(choice);
if (shopItem instanceof String) {
AbstractDungeon.previousScreen = AbstractDungeon.CurrentScreen.SHOP;
AbstractDungeon.gridSelectScreen.open(
CardGroup.getGroupWithoutBottledCards(AbstractDungeon.player.masterDeck.getPurgeableCards()),
1, ShopScreen.NAMES[13], false, false, true, true);
} else if (shopItem instanceof AbstractCard) {
AbstractCard card = (AbstractCard)shopItem;
ShopScreenPatch.doHover = true;
ShopScreenPatch.hoverCard = card;
card.hb.clicked = true;
} else if (shopItem instanceof StoreRelic) {
StoreRelic relic = (StoreRelic) shopItem;
relic.relic.hb.clicked = true;
} else if (shopItem instanceof StorePotion) {
StorePotion potion = (StorePotion) shopItem;
potion.potion.hb.clicked = true;
}
}
private static void clickProceedButton() {
AbstractDungeon.overlayMenu.proceedButton.show();
Hitbox hb = (Hitbox) ReflectionHacks.getPrivate(AbstractDungeon.overlayMenu.proceedButton, ProceedButton.class, "hb");
hb.clicked = true;
}
private static void clickCancelButton() {
AbstractDungeon.overlayMenu.cancelButton.hb.clicked = true;
}
private static void setCursorPosition(float x, float y) {
Gdx.input.setCursorPosition((int)x, (int)y);
InputHelper.updateFirst();
}
public static boolean bossNodeAvailable() {
MapRoomNode currMapNode = AbstractDungeon.getCurrMapNode();
return (currMapNode.y == 14 || (AbstractDungeon.id.equals(TheEnding.ID) && currMapNode.y == 2));
}
/**
* Return the room with the emeraldKey containing a "flame elite".
* @return MapRoomNode|null The map screen state object
*/
public static MapRoomNode findEmeraldKeyNode() {
ArrayList<ArrayList<MapRoomNode>> map = AbstractDungeon.map;
for (ArrayList<MapRoomNode> layer : map) {
for (MapRoomNode node : layer) {
if (node.hasEmeraldKey) {
return node;
}
}
}
return null;
}
public static ArrayList<String> getMapScreenChoices() {
ArrayList<String> choices = new ArrayList<>();
MapRoomNode currMapNode = AbstractDungeon.getCurrMapNode();
if(bossNodeAvailable()) {
choices.add("boss");
return choices;
}
ArrayList<MapRoomNode> availableNodes = getMapScreenNodeChoices();
for (MapRoomNode node: availableNodes) {
choices.add(String.format("x=%d", node.x).toLowerCase());
}
return choices;
}
public static ArrayList<MapRoomNode> getMapScreenNodeChoices() {
ArrayList<MapRoomNode> choices = new ArrayList<>();
MapRoomNode currMapNode = AbstractDungeon.getCurrMapNode();
ArrayList<ArrayList<MapRoomNode>> map = AbstractDungeon.map;
if(!AbstractDungeon.firstRoomChosen) {
for(MapRoomNode node : map.get(0)) {
if (node.hasEdges()) {
choices.add(node);
}
}
} else {
for (ArrayList<MapRoomNode> rows : map) {
for (MapRoomNode node : rows) {
if (node.hasEdges()) {
boolean normalConnection = currMapNode.isConnectedTo(node);
boolean wingedConnection = currMapNode.wingedIsConnectedTo(node);
if (normalConnection || wingedConnection) {
choices.add(node);
}
}
}
}
}
return choices;
}
public static void makeMapChoice(int choice) {
MapRoomNode currMapNode = AbstractDungeon.getCurrMapNode();
if(currMapNode.y == 14 || (AbstractDungeon.id.equals(TheEnding.ID) && currMapNode.y == 2)) {
if(choice == 0) {
DungeonMapPatch.doBossHover = true;
return;
} else {
throw new IndexOutOfBoundsException("Only a boss node can be chosen here.");
}
}
ArrayList<MapRoomNode> nodeChoices = getMapScreenNodeChoices();
MapRoomNodeHoverPatch.hoverNode = nodeChoices.get(choice);
MapRoomNodeHoverPatch.doHover = true;
AbstractDungeon.dungeonMapScreen.clicked = true;
}
public static String getOptionName(String input) {
String unformatted = input.replaceAll("#.|NL", "");
Pattern regex = Pattern.compile("\\[(.*?)\\]");
Matcher matcher = regex.matcher(unformatted);
if(matcher.find()) {
return matcher.group(1).trim();
} else {
return unformatted.trim();
}
}
public static EventDialogType getEventDialogType() {
boolean genericShown = (boolean) ReflectionHacks.getPrivateStatic(GenericEventDialog.class, "show");
if (genericShown) {
return EventDialogType.IMAGE;
}
boolean roomShown = (boolean) ReflectionHacks.getPrivate(AbstractDungeon.getCurrRoom().event.roomEventText, RoomEventDialog.class, "show");
if (roomShown) {
return EventDialogType.ROOM;
} else {
return EventDialogType.NONE;
}
}
public static ArrayList<LargeDialogOptionButton> getEventButtons() {
EventDialogType eventType = getEventDialogType();
switch(eventType) {
case IMAGE:
return AbstractDungeon.getCurrRoom().event.imageEventText.optionList;
case ROOM:
return RoomEventDialog.optionList;
default:
return new ArrayList<>();
}
}
public static ArrayList<LargeDialogOptionButton> getActiveEventButtons() {
ArrayList<LargeDialogOptionButton> buttons = getEventButtons();
ArrayList<LargeDialogOptionButton> activeButtons = new ArrayList<>();
for(LargeDialogOptionButton button : buttons) {
if(!button.isDisabled) {
activeButtons.add(button);
}
}
return activeButtons;
}
public static ArrayList<String> getEventScreenChoices() {
ArrayList<String> choiceList = new ArrayList<>();
ArrayList<LargeDialogOptionButton> activeButtons = getActiveEventButtons();
if (activeButtons.size() > 0) {
for(LargeDialogOptionButton button : activeButtons) {
choiceList.add(getOptionName(button.msg).toLowerCase());
}
} else if(AbstractDungeon.getCurrRoom().event instanceof GremlinWheelGame) {
choiceList.add("spin");
} else if(AbstractDungeon.getCurrRoom().event instanceof GremlinMatchGame) {
ArrayList<AbstractCard> pickableCards = GremlinMatchGamePatch.getOrderedCards();
for (AbstractCard c : pickableCards) {
if (GremlinMatchGamePatch.revealedCards.contains(c.uuid)) {
choiceList.add(c.cardID);
} else {
choiceList.add(String.format("card%d", GremlinMatchGamePatch.cardPositions.get(c.uuid)));
}
}
}
return choiceList;
}
public static void makeEventChoice(int choice) {
ArrayList<LargeDialogOptionButton> activeButtons = getActiveEventButtons();
if (activeButtons.size() > 0) {
activeButtons.get(choice).pressed = true;
} else if (AbstractDungeon.getCurrRoom().event instanceof GremlinWheelGame) {
GremlinWheelGame event = (GremlinWheelGame) AbstractDungeon.getCurrRoom().event;
ReflectionHacks.setPrivate(event, GremlinWheelGame.class, "buttonPressed", true);
CardCrawlGame.sound.play("WHEEL");
} else if (AbstractDungeon.getCurrRoom().event instanceof GremlinMatchGame) {
ArrayList<AbstractCard> pickable = GremlinMatchGamePatch.getOrderedCards();
GremlinMatchGamePatch.HoverCardPatch.hoverCard = pickable.get(choice);
GremlinMatchGamePatch.HoverCardPatch.doHover = true;
}
}
public static ArrayList<String> getRestRoomChoices() {
ArrayList<String> choiceList = new ArrayList<>();
ArrayList<AbstractCampfireOption> buttons = getValidRestRoomButtons();
for(AbstractCampfireOption button : buttons) {
choiceList.add(getCampfireOptionName(button));
}
return choiceList;
}
public static void makeRestRoomChoice(int choice_index) {
ArrayList<AbstractCampfireOption> buttons = getValidRestRoomButtons();
AbstractCampfireOption button = buttons.get(choice_index);
RestRoom room = (RestRoom) AbstractDungeon.getCurrRoom();
button.useOption();
room.campfireUI.somethingSelected = true;
}
private static boolean isRestRoomProceedAvailable() {
return AbstractDungeon.getCurrRoom().phase == AbstractRoom.RoomPhase.COMPLETE;
}
@SuppressWarnings("unchecked")
private static ArrayList<AbstractCampfireOption> getValidRestRoomButtons() {
ArrayList<AbstractCampfireOption> choiceList = new ArrayList<>();
RestRoom room = (RestRoom) AbstractDungeon.getCurrRoom();
if(!isRestRoomProceedAvailable()) {
ArrayList<AbstractCampfireOption> buttons = (ArrayList<AbstractCampfireOption>) ReflectionHacks.getPrivate(room.campfireUI, CampfireUI.class, "buttons");
for (AbstractCampfireOption button : buttons) {
if (button.usable) {
choiceList.add(button);
}
}
}
return choiceList;
}
private static String getCampfireOptionName(AbstractCampfireOption option) {
String classname = option.getClass().getSimpleName();
String nameWithoutOption = classname.substring(0, classname.length() - "Option".length());
return nameWithoutOption.toLowerCase();
}
private static void clickGameOverReturnButton() {
//For now, just copying the functionality from VictoryScreen.update(), always skipping credits
AbstractDungeon.unlocks.clear();
Settings.isTrial = false;
Settings.isDailyRun = false;
Settings.isEndless = false;
CardCrawlGame.trial = null;
CardCrawlGame.startOver();
}
}