Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.megacrit.cardcrawl.actions.AbstractGameAction;
- import com.megacrit.cardcrawl.cards.AbstractCard;
- import com.megacrit.cardcrawl.cards.CardGroup;
- import com.megacrit.cardcrawl.characters.AbstractPlayer;
- import com.megacrit.cardcrawl.core.CardCrawlGame;
- import com.megacrit.cardcrawl.core.Settings;
- import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
- import java.util.ArrayList;
- // This is really just a fix to the vanilla action so the card isn't responsible for checking the discard pile.
- // Also organizes card by alphabet for better UX.
- public class BetterDiscardPileToHandAction extends AbstractGameAction {
- // TODO: Use your own strings. My json looked like this:
- //"TEXT": [
- // "Choose a Card to Put into Your Hand.",
- // "Choose ",
- // " Cards to Put into Your Hand."
- //]
- public static final String[] TEXT = CardCrawlGame.languagePack.getUIString("").TEXT;
- private AbstractPlayer player;
- private int numberOfCards;
- private boolean optional;
- public BetterDiscardPileToHandAction(int numberOfCards, boolean optional) {
- this.actionType = ActionType.CARD_MANIPULATION;
- this.duration = this.startDuration = Settings.ACTION_DUR_FAST;
- this.player = AbstractDungeon.player;
- this.numberOfCards = numberOfCards;
- this.optional = optional;
- }
- public BetterDiscardPileToHandAction(int numberOfCards) {
- this(numberOfCards, false);
- }
- public void update() {
- if (this.duration == this.startDuration) {
- if (this.player.discardPile.isEmpty()) {
- this.isDone = true;
- return;
- }
- else if (this.player.discardPile.size() <= this.numberOfCards) {
- ArrayList<AbstractCard> cardsToMove = new ArrayList<>();
- for (AbstractCard c : this.player.discardPile.group) {
- cardsToMove.add(c);
- }
- for (AbstractCard c : cardsToMove) {
- this.player.discardPile.moveToHand(c, this.player.discardPile);
- }
- this.isDone = true;
- return;
- }
- else {
- CardGroup temp = new CardGroup(CardGroup.CardGroupType.UNSPECIFIED);
- for (AbstractCard c : this.player.discardPile.group) {
- temp.addToTop(c);
- }
- temp.sortAlphabetically(true);
- temp.sortByRarityPlusStatusCardType(false);
- if (this.numberOfCards == 1) {
- if (this.optional) {
- AbstractDungeon.gridSelectScreen.open(temp, this.numberOfCards, true, TEXT[0]);
- }
- else {
- AbstractDungeon.gridSelectScreen.open(temp, this.numberOfCards, TEXT[0], false);
- }
- }
- else {
- if (this.optional) {
- AbstractDungeon.gridSelectScreen.open(temp, this.numberOfCards, true, TEXT[1] + this.numberOfCards + TEXT[2]);
- }
- else {
- AbstractDungeon.gridSelectScreen.open(temp, this.numberOfCards, TEXT[1] + this.numberOfCards + TEXT[2], false);
- }
- }
- tickDuration();
- return;
- }
- }
- if (!AbstractDungeon.gridSelectScreen.selectedCards.isEmpty()) {
- for (AbstractCard c : AbstractDungeon.gridSelectScreen.selectedCards) {
- this.player.discardPile.moveToHand(c, this.player.discardPile);
- }
- AbstractDungeon.gridSelectScreen.selectedCards.clear();
- AbstractDungeon.player.hand.refreshHandLayout();
- }
- tickDuration();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement