use of mage.game.permanent.token.Token in project mage by magefree.
the class RecklessCrewEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
int equipCount = game.getBattlefield().count(filter1, source.getSourceId(), source.getControllerId(), game);
int vehicleCount = game.getBattlefield().count(filter2, source.getSourceId(), source.getControllerId(), game);
if (equipCount + vehicleCount < 1) {
return false;
}
Token token = new DwarfBerserkerToken();
token.putOntoBattlefield(equipCount + vehicleCount, game, source, source.getControllerId());
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
if (equipCount < 1) {
return true;
}
for (UUID tokenId : token.getLastAddedTokenIds()) {
Permanent permanent = game.getPermanent(tokenId);
if (permanent == null) {
continue;
}
TargetPermanent target = new TargetPermanent(0, 1, filter1, true);
target.withChooseHint("(to attach to " + permanent.getIdName() + ")");
player.choose(outcome, target, source.getSourceId(), game);
permanent.addAttachment(target.getFirstTarget(), source, game);
}
return true;
}
use of mage.game.permanent.token.Token in project mage by magefree.
the class ThroneOfEmpiresEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
boolean scepter = false;
boolean crown = false;
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(source.getControllerId())) {
if (permanent.getName().equals("Scepter of Empires")) {
scepter = true;
} else if (permanent.getName().equals("Crown of Empires")) {
crown = true;
}
if (scepter && crown)
break;
}
Token soldier = new SoldierToken();
int count = scepter && crown ? 5 : 1;
soldier.putOntoBattlefield(count, game, source, source.getControllerId());
return false;
}
use of mage.game.permanent.token.Token in project mage by magefree.
the class TidalWaveEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Token token = new TidalWaveWallToken();
if (token.putOntoBattlefield(1, game, source, source.getControllerId())) {
for (UUID tokenId : token.getLastAddedTokenIds()) {
Permanent tokenPermanent = game.getPermanent(tokenId);
if (tokenPermanent != null) {
SacrificeTargetEffect sacrificeEffect = new SacrificeTargetEffect();
sacrificeEffect.setTargetPointer(new FixedTarget(tokenPermanent, game));
game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(sacrificeEffect), source);
}
}
return true;
}
return false;
}
use of mage.game.permanent.token.Token in project mage by magefree.
the class ZaxaraTheExemplaryHydraTokenEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Player controller = game.getPlayer(source.getControllerId());
if (player != null && controller != null) {
Object needObject = game.getState().getValue(source.getSourceId() + ZaxaraTheExemplary.needPrefix);
// create token
if (needObject instanceof Spell) {
Spell spell = (Spell) needObject;
int xValue = spell.getSpellAbility().getManaCostsToPay().getX();
Token hydraToken = new ZaxaraTheExemplaryHydraToken();
hydraToken.putOntoBattlefield(1, game, source, source.getControllerId());
for (UUID tokenId : hydraToken.getLastAddedTokenIds()) {
Permanent permanent = game.getPermanent(tokenId);
if (permanent != null)
permanent.addCounters(CounterType.P1P1.createInstance(xValue), source.getControllerId(), source, game);
}
return true;
}
}
return false;
}
use of mage.game.permanent.token.Token in project mage by magefree.
the class MomirEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
int value = 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(value, value + 1);
token.putOntoBattlefield(1, game, source, source.getControllerId(), false, false);
return true;
}
// should this be random across card names
CardCriteria criteria = new CardCriteria().types(CardType.CREATURE).manaValue(value);
List<CardInfo> options = CardRepository.instance.findCards(criteria);
if (options == null || options.isEmpty()) {
game.informPlayers("No random creature card with mana value of " + value + " was found.");
return false;
}
// search for a random non custom set creature
EmptyToken token = null;
while (!options.isEmpty()) {
int index = RandomUtil.nextInt(options.size());
ExpansionSet expansionSet = Sets.findSet(options.get(index).getSetCode());
if (expansionSet == null || !expansionSet.getSetType().isEternalLegal()) {
options.remove(index);
} else {
Card card = options.get(index).getCard();
if (card != null) {
token = new EmptyToken();
CardUtil.copyTo(token).from(card, game);
break;
} else {
options.remove(index);
}
}
}
if (token != null) {
token.putOntoBattlefield(1, game, source, source.getControllerId(), false, false);
return true;
}
return false;
}
Aggregations