-
Notifications
You must be signed in to change notification settings - Fork 773
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
karapuzz14
wants to merge
4
commits into
magefree:master
Choose a base branch
from
karapuzz14:PoolOfVigorousGrowth
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
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; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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:
mage/Mage/src/main/java/mage/game/command/emblems/MomirEmblem.java
Line 76 in da48821