use of mage.MageObjectReference in project mage by magefree.
the class CommanderStormEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
MageObjectReference spellRef = (MageObjectReference) this.getValue("StormSpellRef");
if (spellRef == null) {
return false;
}
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
CommanderPlaysCountWatcher watcher = game.getState().getWatcher(CommanderPlaysCountWatcher.class);
if (watcher == null) {
return false;
}
int stormCount = game.getCommandersIds(player, CommanderCardType.COMMANDER_OR_OATHBREAKER, false).stream().mapToInt(watcher::getPlaysCount).sum();
if (stormCount == 0) {
return true;
}
Spell spell = (Spell) this.getValue("StormSpell");
if (spell == null) {
return false;
}
game.informPlayers(spell.getLogName() + " will be copied " + stormCount + " time" + (stormCount > 1 ? "s" : ""));
spell.createCopyOnStack(game, source, source.getControllerId(), true, stormCount);
return true;
}
use of mage.MageObjectReference in project mage by magefree.
the class CommanderStormEffect method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (!event.getSourceId().equals(getSourceId())) {
return false;
}
StackObject spell = game.getStack().getStackObject(getSourceId());
if (!(spell instanceof Spell)) {
return false;
}
for (Effect effect : this.getEffects()) {
effect.setValue("StormSpell", spell);
effect.setValue("StormSpellRef", new MageObjectReference(spell.getId(), game));
}
return true;
}
use of mage.MageObjectReference in project mage by magefree.
the class ExertedThisTurnWatcher method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Permanent creature = game.getPermanent(event.getSourceId());
Player controller = game.getPlayer(source.getControllerId());
if (creature != null && controller != null) {
if (exertOnlyOncePerTurn) {
MageObjectReference creatureReference = new MageObjectReference(creature.getId(), creature.getZoneChangeCounter(game), game);
ExertedThisTurnWatcher watcher = game.getState().getWatcher(ExertedThisTurnWatcher.class);
if (watcher != null && watcher.getExertedThisTurnCreatures().contains(creatureReference)) {
return false;
}
}
if (controller.chooseUse(outcome, "Exert " + creature.getLogName() + '?', "An exerted creature won't untap during your next untap step.", "Yes", "No", source, game)) {
if (!game.isSimulation()) {
game.informPlayers(controller.getLogName() + " exerted " + creature.getName());
}
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.BECOMES_EXERTED, creature.getId(), source, source.getControllerId()));
ContinuousEffect effect = new DontUntapInControllersNextUntapStepTargetEffect("", creature.getControllerId());
effect.setTargetPointer(new FixedTarget(creature, game));
game.addEffect(effect, source);
}
}
return false;
}
use of mage.MageObjectReference in project mage by magefree.
the class EncoreSacrificeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Card card = game.getCard(source.getSourceId());
if (card == null) {
return false;
}
EmptyToken token = new EmptyToken();
CardUtil.copyTo(token).from(card, game);
Set<MageObjectReference> addedTokens = new HashSet<>();
int opponentCount = OpponentsCount.instance.calculate(game, source, this);
if (opponentCount < 1) {
return false;
}
token.putOntoBattlefield(opponentCount, game, source, source.getControllerId());
Iterator<UUID> it = token.getLastAddedTokenIds().iterator();
while (it.hasNext()) {
for (UUID playerId : game.getOpponents(source.getControllerId())) {
if (game.getPlayer(playerId) == null) {
continue;
}
UUID tokenId = it.next();
MageObjectReference mageObjectReference = new MageObjectReference(tokenId, game);
game.addEffect(new EncoreRequirementEffect(mageObjectReference, playerId), source);
game.addEffect(new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.Custom).setTargetPointer(new FixedTarget(mageObjectReference)), source);
addedTokens.add(mageObjectReference);
}
}
game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(new EncoreSacrificeEffect(addedTokens)), source);
return true;
}
use of mage.MageObjectReference in project mage by magefree.
the class CalixDestinysHandReturnEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (source.getTargets().size() > 2) {
return false;
}
source.getTargets();
Permanent theirPerm = game.getPermanent(source.getTargets().get(0).getFirstTarget());
Permanent myPerm = game.getPermanent(source.getTargets().get(1).getFirstTarget());
if (controller == null || theirPerm == null || myPerm == null) {
return false;
}
MageObjectReference theirMor = new MageObjectReference(theirPerm.getId(), theirPerm.getZoneChangeCounter(game) + 1, game);
MageObjectReference myMor = new MageObjectReference(myPerm, game);
UUID exileId = CardUtil.getExileZoneId(myPerm.toString(), game);
controller.moveCardsToExile(theirPerm, source, game, true, exileId, myPerm.getIdName());
game.addDelayedTriggeredAbility(new CalixDestinysHandDelayedTriggeredAbility(theirMor, myMor), source);
return true;
}
Aggregations