Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[J21] Implement Pool of Vigorous Growth #12734

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions Mage.Sets/src/mage/cards/p/PoolOfVigorousGrowth.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package mage.cards.p;

import java.util.List;
import java.util.UUID;

import mage.abilities.Ability;
import mage.abilities.common.ActivateAsSorceryActivatedAbility;
import mage.abilities.costs.common.DiscardCardCost;
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.OneShotEffect;
import mage.cards.*;
import mage.cards.repository.CardCriteria;
import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.game.Game;
import mage.game.permanent.token.Token;
import mage.game.permanent.token.custom.CreatureToken;
import mage.players.Player;
import mage.util.RandomUtil;
import mage.util.functions.CopyTokenFunction;

/**
*
* @author karapuzz14
*/
public final class PoolOfVigorousGrowth extends CardImpl {

public PoolOfVigorousGrowth(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{1}{G}");


// {X}, {T}, Discard a card: Create a token that's a copy of a random creature card with mana value X. Activate only as a sorcery.
Ability ability = new ActivateAsSorceryActivatedAbility(
new PoolOfVigorousGrowthEffect(), new ManaCostsImpl<>("{X}")
);
ability.addCost(new TapSourceCost());
ability.addCost(new DiscardCardCost());
this.addAbility(ability);
}

private PoolOfVigorousGrowth(final PoolOfVigorousGrowth card) {
super(card);
}

@Override
public PoolOfVigorousGrowth copy() {
return new PoolOfVigorousGrowth(this);
}
}
class PoolOfVigorousGrowthEffect extends OneShotEffect {

PoolOfVigorousGrowthEffect() {
super(Outcome.PutCardInPlay);
staticText = "Create a token that's a copy of a random creature card with mana value X";
}

private PoolOfVigorousGrowthEffect(final PoolOfVigorousGrowthEffect effect) {
super(effect);
}

@Override
public PoolOfVigorousGrowthEffect copy() {
return new PoolOfVigorousGrowthEffect(this);
}

@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}

int xValue = source.getManaCostsToPay().getX();
if (game.isSimulation()) {
// Create dummy token to prevent multiple DB find cards what causes H2 java.lang.IllegalStateException if AI cancels calculation because of time out
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain details about broken AI here? Is it catch error all time or at random? How to reproduce that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that's just old comment from Momir's Emblem implementation. I decided that it's known issue and just left the same comment as explanation.
I think it says about next issue:
#7014

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this trick with dummy token is also stolen from here:

// Create dummy token to prevent multiple DB find cards what causes H2 java.lang.IllegalStateException if AI cancels calculation because of time out

Token token = new CreatureToken(xValue, xValue + 1);
token.putOntoBattlefield(1, game, source, source.getControllerId(), false, false);
return true;
}

CardCriteria criteria = new CardCriteria().types(CardType.CREATURE).manaValue(xValue);
List<CardInfo> options = CardRepository.instance.findCards(criteria);
if (options == null || options.isEmpty()) {
game.informPlayers("No random creature card with mana value of " + xValue + " was found.");
return false;
}

Token token = null;
while (!options.isEmpty()) {
int index = RandomUtil.nextInt(options.size());
ExpansionSet expansionSet = Sets.findSet(options.get(index).getSetCode());
if (expansionSet == null || expansionSet.getSetType().isCustomSet() || expansionSet.getSetType().isJokeSet()) {
options.remove(index);
} else {
Card card = options.get(index).createCard();
if (card != null) {
token = CopyTokenFunction.createTokenCopy(card, game);
break;
} else {
options.remove(index);
}
}
}
if (token != null) {
token.putOntoBattlefield(1, game, source, source.getControllerId(), false, false);
return true;
}

return false;

}
}
1 change: 1 addition & 0 deletions Mage.Sets/src/mage/sets/JumpstartHistoricHorizons.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ private JumpstartHistoricHorizons() {
cards.add(new SetCardInfo("Phantasmal Form", 229, Rarity.COMMON, mage.cards.p.PhantasmalForm.class));
cards.add(new SetCardInfo("Phantom Ninja", 230, Rarity.COMMON, mage.cards.p.PhantomNinja.class));
cards.add(new SetCardInfo("Pondering Mage", 231, Rarity.COMMON, mage.cards.p.PonderingMage.class));
cards.add(new SetCardInfo("Pool of Vigorous Growth", 28, Rarity.RARE, mage.cards.p.PoolOfVigorousGrowth.class));
cards.add(new SetCardInfo("Predatory Sliver", 619, Rarity.COMMON, mage.cards.p.PredatorySliver.class));
cards.add(new SetCardInfo("Prey's Vengeance", 620, Rarity.COMMON, mage.cards.p.PreysVengeance.class));
cards.add(new SetCardInfo("Priest of Fell Rites", 707, Rarity.RARE, mage.cards.p.PriestOfFellRites.class));
Expand Down
Loading