Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.81 KB | None | 0 0
  1. import com.megacrit.cardcrawl.actions.AbstractGameAction;
  2. import com.megacrit.cardcrawl.cards.AbstractCard;
  3. import com.megacrit.cardcrawl.cards.CardGroup;
  4. import com.megacrit.cardcrawl.characters.AbstractPlayer;
  5. import com.megacrit.cardcrawl.core.CardCrawlGame;
  6. import com.megacrit.cardcrawl.core.Settings;
  7. import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
  8.  
  9. import java.util.ArrayList;
  10.  
  11. // This is really just a fix to the vanilla action so the card isn't responsible for checking the discard pile.
  12. // Also organizes card by alphabet for better UX.
  13. public class BetterDiscardPileToHandAction extends AbstractGameAction {
  14.  
  15. // TODO: Use your own strings. My json looked like this:
  16. //"TEXT": [
  17. // "Choose a Card to Put into Your Hand.",
  18. // "Choose ",
  19. // " Cards to Put into Your Hand."
  20. //]
  21. public static final String[] TEXT = CardCrawlGame.languagePack.getUIString("").TEXT;
  22. private AbstractPlayer player;
  23. private int numberOfCards;
  24. private boolean optional;
  25.  
  26. public BetterDiscardPileToHandAction(int numberOfCards, boolean optional) {
  27. this.actionType = ActionType.CARD_MANIPULATION;
  28. this.duration = this.startDuration = Settings.ACTION_DUR_FAST;
  29. this.player = AbstractDungeon.player;
  30. this.numberOfCards = numberOfCards;
  31. this.optional = optional;
  32. }
  33.  
  34. public BetterDiscardPileToHandAction(int numberOfCards) {
  35. this(numberOfCards, false);
  36. }
  37.  
  38. public void update() {
  39. if (this.duration == this.startDuration) {
  40. if (this.player.discardPile.isEmpty()) {
  41. this.isDone = true;
  42. return;
  43. }
  44. else if (this.player.discardPile.size() <= this.numberOfCards) {
  45. ArrayList<AbstractCard> cardsToMove = new ArrayList<>();
  46. for (AbstractCard c : this.player.discardPile.group) {
  47. cardsToMove.add(c);
  48. }
  49. for (AbstractCard c : cardsToMove) {
  50. this.player.discardPile.moveToHand(c, this.player.discardPile);
  51. }
  52. this.isDone = true;
  53. return;
  54. }
  55. else {
  56. CardGroup temp = new CardGroup(CardGroup.CardGroupType.UNSPECIFIED);
  57. for (AbstractCard c : this.player.discardPile.group) {
  58. temp.addToTop(c);
  59. }
  60. temp.sortAlphabetically(true);
  61. temp.sortByRarityPlusStatusCardType(false);
  62. if (this.numberOfCards == 1) {
  63. if (this.optional) {
  64. AbstractDungeon.gridSelectScreen.open(temp, this.numberOfCards, true, TEXT[0]);
  65. }
  66. else {
  67. AbstractDungeon.gridSelectScreen.open(temp, this.numberOfCards, TEXT[0], false);
  68. }
  69. }
  70. else {
  71. if (this.optional) {
  72. AbstractDungeon.gridSelectScreen.open(temp, this.numberOfCards, true, TEXT[1] + this.numberOfCards + TEXT[2]);
  73. }
  74. else {
  75. AbstractDungeon.gridSelectScreen.open(temp, this.numberOfCards, TEXT[1] + this.numberOfCards + TEXT[2], false);
  76. }
  77. }
  78. tickDuration();
  79. return;
  80. }
  81. }
  82. if (!AbstractDungeon.gridSelectScreen.selectedCards.isEmpty()) {
  83. for (AbstractCard c : AbstractDungeon.gridSelectScreen.selectedCards) {
  84. this.player.discardPile.moveToHand(c, this.player.discardPile);
  85. }
  86. AbstractDungeon.gridSelectScreen.selectedCards.clear();
  87. AbstractDungeon.player.hand.refreshHandLayout();
  88. }
  89. tickDuration();
  90. }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement