use of mage.game.stack.StackObject in project mage by magefree.
the class Turn method endTurn.
/*protected void playExtraTurns(Game game) {
while (game.getState().getTurnMods().extraTurn(activePlayerId)) {
this.play(game, activePlayerId);
}
}*/
/**
* Used for some spells with end turn effect (e.g. Time Stop).
*
* @param game
* @param activePlayerId
* @param source
*/
public void endTurn(Game game, UUID activePlayerId, Ability source) {
// Ending the turn this way (Time Stop) means the following things happen in order:
setEndTurnRequested(true);
// It also includes spells and abilities that can't be countered.
while (!game.hasEnded() && !game.getStack().isEmpty()) {
StackObject stackObject = game.getStack().peekFirst();
if (stackObject instanceof Spell) {
((Spell) stackObject).moveToExile(null, "", source, game);
} else {
// stack ability
game.getStack().remove(stackObject, game);
}
}
// 2) All attacking and blocking creatures are removed from combat.
for (UUID attackerId : game.getCombat().getAttackers()) {
Permanent permanent = game.getPermanent(attackerId);
if (permanent != null) {
permanent.removeFromCombat(game);
}
game.getCombat().removeAttacker(attackerId, game);
}
for (UUID blockerId : game.getCombat().getBlockers()) {
Permanent permanent = game.getPermanent(blockerId);
if (permanent != null) {
permanent.removeFromCombat(game);
}
}
// 3) State-based actions are checked. No player gets priority, and no triggered abilities are put onto the stack.
// seems like trigger events have to be removed: http://tabakrules.tumblr.com/post/122350751009/days-undoing-has-been-officially-spoiled-on
game.getState().clearTriggeredAbilities();
// triggered effects don't go to stack because check of endTurnRequested
game.checkStateAndTriggered();
// 4) The current phase and/or step ends.
// The game skips straight to the cleanup step. The cleanup step happens in its entirety.
// this is caused by the endTurnRequest state
}
use of mage.game.stack.StackObject in project mage by magefree.
the class TrailOfTheMageRingsReboundEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Plane cPlane = game.getState().getCurrentPlane();
if (cPlane == null) {
return false;
}
if (!cPlane.getPlaneType().equals(Planes.PLANE_TRAIL_OF_THE_MAGE_RINGS)) {
return false;
}
for (UUID playerId : game.getPlayers().keySet()) {
Player player = game.getPlayer(playerId);
if (player != null) {
for (Card card : player.getHand().getCards(filter, game)) {
addReboundAbility(card, source, game);
}
for (Iterator<StackObject> iterator = game.getStack().iterator(); iterator.hasNext(); ) {
StackObject stackObject = iterator.next();
if (stackObject instanceof Spell && stackObject.isControlledBy(source.getControllerId())) {
Spell spell = (Spell) stackObject;
Card card = spell.getCard();
if (card != null) {
addReboundAbility(card, source, game);
}
}
}
}
}
return true;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class WardAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (!getSourceId().equals(event.getTargetId())) {
return false;
}
StackObject stackObject = getTargetingObject(event, game);
if (stackObject == null || !game.getOpponents(getControllerId()).contains(stackObject.getControllerId())) {
return false;
}
getEffects().setTargetPointer(new FixedTarget(stackObject.getId(), game));
return true;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class HarshJudgmentEffect method applies.
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getTargetId().equals(source.getControllerId())) {
Spell spell = null;
StackObject stackObject = game.getStack().getStackObject(event.getSourceId());
if (stackObject == null) {
stackObject = (StackObject) game.getLastKnownInformation(event.getSourceId(), Zone.STACK);
}
if (stackObject instanceof Spell) {
spell = (Spell) stackObject;
}
// Checks if damage is from a sorcery or instants and spell is of chosen color
Permanent permanent = game.getPermanent(source.getSourceId());
ObjectColor color = (ObjectColor) game.getState().getValue(permanent.getId() + "_color");
if (spell != null && instantOrSorceryFilter.match(spell.getCard(), game) && spell.getColor(game).contains(color)) {
TargetPlayer target = new TargetPlayer();
target.add(spell.getControllerId(), game);
redirectTarget = target;
return true;
}
}
return false;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class InduceParanoiaEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
StackObject spell = game.getStack().getStackObject(targetPointer.getFirst(game, source));
if (spell != null) {
game.getStack().counter(spell.getId(), source, game);
int spellCMC = spell.getManaValue();
Player player = game.getPlayer(spell.getControllerId());
if (player != null) {
player.millCards(spellCMC, source, game);
return true;
}
}
return false;
}
Aggregations