Some cleanup and minor rework.

This commit is contained in:
LevelX2 2016-01-18 08:18:17 +01:00
parent 2985fb8af1
commit f3154fab54
89 changed files with 358 additions and 569 deletions

View file

@ -74,9 +74,6 @@ public class CreateDelayedTriggeredAbilityEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
DelayedTriggeredAbility delayedAbility = ability.copy();
delayedAbility.setSourceId(source.getSourceId());
delayedAbility.setControllerId(source.getControllerId());
delayedAbility.setSourceObject(source.getSourceObject(game), game);
if (this.copyTargets) {
if (source.getTargets().isEmpty()) {
for (Effect effect : delayedAbility.getEffects()) {
@ -92,7 +89,7 @@ public class CreateDelayedTriggeredAbilityEffect extends OneShotEffect {
if (initAbility) {
delayedAbility.init(game);
}
game.addDelayedTriggeredAbility(delayedAbility);
game.addDelayedTriggeredAbility(delayedAbility, source);
return true;
}

View file

@ -30,7 +30,6 @@ package mage.abilities.effects.common;
import mage.abilities.Ability;
import mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.DestroyTargetEffect;
import mage.constants.Outcome;
import mage.game.Game;
import mage.target.targetpointer.FixedTarget;
@ -60,10 +59,7 @@ public class DestroyTargetAtBeginningOfNextEndStepEffect extends OneShotEffect {
DestroyTargetEffect effect = new DestroyTargetEffect();
effect.setTargetPointer(new FixedTarget(source.getFirstTarget()));
AtTheBeginOfNextEndStepDelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect);
delayedAbility.setSourceId(source.getSourceId());
delayedAbility.setControllerId(source.getControllerId());
delayedAbility.setSourceObject(source.getSourceObject(game), game);
game.addDelayedTriggeredAbility(delayedAbility);
game.addDelayedTriggeredAbility(delayedAbility, source);
return true;
}
}

View file

@ -64,9 +64,7 @@ public class EpicEffect extends OneShotEffect {
}
spell.getSpellAbility().getEffects().remove(epicEffect);
DelayedTriggeredAbility ability = new AtTheBeginOfYourNextUpkeepDelayedTriggeredAbility(new EpicPushEffect(spell, rule), Duration.EndOfGame, false);
ability.setSourceId(source.getSourceId());
ability.setControllerId(source.getControllerId());
game.addDelayedTriggeredAbility(ability);
game.addDelayedTriggeredAbility(ability, source);
game.addEffect(new EpicReplacementEffect(), source);
return true;
}
@ -104,7 +102,7 @@ class EpicReplacementEffect extends ContinuousRuleModifyingEffectImpl {
public String getInfoMessage(Ability source, GameEvent event, Game game) {
MageObject mageObject = game.getObject(source.getSourceId());
if (mageObject != null) {
return "For the rest of the game, you can't cast spells (Epic - " + mageObject.getName() +")";
return "For the rest of the game, you can't cast spells (Epic - " + mageObject.getName() + ")";
}
return null;
}

View file

@ -40,12 +40,12 @@ import mage.players.Player;
*
* @author LevelX2
*/
public class ExileReturnToBattlefieldOwnerNextEndStepEffect extends OneShotEffect {
public class ExileReturnBattlefieldOwnerNextEndStepSourceEffect extends OneShotEffect {
private static final String effectText = "exile {this}. Return it to the battlefield under its owner's control at the beginning of the next end step";
private boolean returnAlways;
public ExileReturnToBattlefieldOwnerNextEndStepEffect() {
public ExileReturnBattlefieldOwnerNextEndStepSourceEffect() {
this(false);
}
@ -55,13 +55,13 @@ public class ExileReturnToBattlefieldOwnerNextEndStepEffect extends OneShotEffec
* but is moved to another zone (e.g. command zone by commander replacement
* effect)
*/
public ExileReturnToBattlefieldOwnerNextEndStepEffect(boolean returnAlways) {
public ExileReturnBattlefieldOwnerNextEndStepSourceEffect(boolean returnAlways) {
super(Outcome.Benefit);
staticText = effectText;
this.returnAlways = returnAlways;
}
public ExileReturnToBattlefieldOwnerNextEndStepEffect(ExileReturnToBattlefieldOwnerNextEndStepEffect effect) {
public ExileReturnBattlefieldOwnerNextEndStepSourceEffect(ExileReturnBattlefieldOwnerNextEndStepSourceEffect effect) {
super(effect);
this.returnAlways = effect.returnAlways;
}
@ -78,10 +78,7 @@ public class ExileReturnToBattlefieldOwnerNextEndStepEffect extends OneShotEffec
//create delayed triggered ability and return it from every public zone he was next moved to
AtTheBeginOfNextEndStepDelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(
new ReturnToBattlefieldUnderOwnerControlSourceEffect(false, zcc + 1));
delayedAbility.setSourceId(source.getSourceId());
delayedAbility.setControllerId(source.getControllerId());
delayedAbility.setSourceObject(source.getSourceObject(game), game);
game.addDelayedTriggeredAbility(delayedAbility);
game.addDelayedTriggeredAbility(delayedAbility, source);
}
}
return true;
@ -90,8 +87,8 @@ public class ExileReturnToBattlefieldOwnerNextEndStepEffect extends OneShotEffec
}
@Override
public ExileReturnToBattlefieldOwnerNextEndStepEffect copy() {
return new ExileReturnToBattlefieldOwnerNextEndStepEffect(this);
public ExileReturnBattlefieldOwnerNextEndStepSourceEffect copy() {
return new ExileReturnBattlefieldOwnerNextEndStepSourceEffect(this);
}
}

View file

@ -35,20 +35,18 @@ import mage.abilities.SpecialAction;
import mage.abilities.costs.Cost;
import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.RemoveDelayedTriggeredAbilityEffect;
import mage.abilities.effects.common.RemoveSpecialActionEffect;
import mage.constants.Outcome;
import mage.constants.PhaseStep;
import mage.game.Game;
import mage.game.events.GameEvent.EventType;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.target.targetpointer.FixedTarget;
/**
*
* @author LoneFox (based on Quenchable Fire code by BetaSteward_at_googlemail.com)
* @author LoneFox (based on Quenchable Fire code by
* BetaSteward_at_googlemail.com)
*/
public class UnlessPaysDelayedEffect extends OneShotEffect {
private final Cost cost;
@ -63,7 +61,7 @@ public class UnlessPaysDelayedEffect extends OneShotEffect {
this.step = step;
this.affectedPlayersTurn = affectedPlayersTurn;
staticText = text + "<br><i>Use the Special button to pay the " + cost.getText()
+ " with a special action before that step.</i>";
+ " with a special action before that step.</i>";
}
public UnlessPaysDelayedEffect(final UnlessPaysDelayedEffect effect) {
@ -91,11 +89,8 @@ public class UnlessPaysDelayedEffect extends OneShotEffect {
UUID turnPlayer = affectedPlayersTurn ? getTargetPointer().getFirst(game, source) : source.getControllerId();
effect.setTargetPointer(new FixedTarget(getTargetPointer().getFirst(game, source)));
UnlessPaysDelayedEffectTriggeredAbility delayedAbility = new UnlessPaysDelayedEffectTriggeredAbility(turnPlayer, step, effect);
delayedAbility.setSourceId(source.getSourceId());
delayedAbility.setControllerId(source.getControllerId());
delayedAbility.setSourceObject(sourceObject, game);
delayedAbility.setSpecialActionId(newAction.getId());
UUID delayedAbilityId = game.addDelayedTriggeredAbility(delayedAbility);
UUID delayedAbilityId = game.addDelayedTriggeredAbility(delayedAbility, source);
// update special action
newAction.addCost(cost);
@ -143,7 +138,7 @@ class UnlessPaysDelayedEffectTriggeredAbility extends DelayedTriggeredAbility {
@Override
public boolean checkEventType(GameEvent event, Game game) {
switch(step) {
switch (step) {
case UPKEEP:
return event.getType() == EventType.UPKEEP_STEP_PRE;
case DRAW:
@ -156,7 +151,7 @@ class UnlessPaysDelayedEffectTriggeredAbility extends DelayedTriggeredAbility {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getPlayerId().equals(turnPlayer)) {
for (SpecialAction action: game.getState().getSpecialActions()) {
for (SpecialAction action : game.getState().getSpecialActions()) {
if (action.getId().equals(specialActionId)) {
game.getState().getSpecialActions().remove(action);
break;

View file

@ -37,7 +37,6 @@ import mage.constants.Outcome;
import mage.counters.CounterType;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.Target;
import mage.util.CardUtil;
@ -75,23 +74,20 @@ public class DistributeCountersEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
if(source.getTargets().size() > 0) {
if (source.getTargets().size() > 0) {
Target multiTarget = source.getTargets().get(0);
for(UUID target : multiTarget.getTargets()) {
for (UUID target : multiTarget.getTargets()) {
Permanent permanent = game.getPermanent(target);
if(permanent != null) {
if (permanent != null) {
permanent.addCounters(counterType.createInstance(multiTarget.getTargetAmount(target)), game);
}
}
if(removeAtEndOfTurn) {
if (removeAtEndOfTurn) {
DelayedTriggeredAbility ability = new AtTheBeginOfNextCleanupDelayedTriggeredAbility(
new RemoveCountersAtEndOfTurn(counterType));
ability.setSourceId(source.getSourceId());
ability.setControllerId(source.getControllerId());
ability.setSourceObject(source.getSourceObject(game), game);
new RemoveCountersAtEndOfTurn(counterType));
ability.getTargets().addAll(source.getTargets());
game.addDelayedTriggeredAbility(ability);
game.addDelayedTriggeredAbility(ability, source);
}
return true;
@ -107,9 +103,9 @@ public class DistributeCountersEffect extends OneShotEffect {
String name = counterType.getName();
String text = "distribute " + CardUtil.numberToText(amount) + " " + name + " counters among " + targetDescription + ".";
if(removeAtEndOfTurn) {
if (removeAtEndOfTurn) {
text += " For each " + name + " counter you put on a creature this way, remove a "
+ name + " counter from that creature at the beginning of the next cleanup step.";
+ name + " counter from that creature at the beginning of the next cleanup step.";
}
return text;
}
@ -124,7 +120,7 @@ class RemoveCountersAtEndOfTurn extends OneShotEffect {
this.counterType = counterType;
String name = counterType.getName();
staticText = "For each " + name + " counter you put on a creature this way, remove a "
+ name + " counter from that creature at the beginning of the next cleanup step.";
+ name + " counter from that creature at the beginning of the next cleanup step.";
}
public RemoveCountersAtEndOfTurn(final RemoveCountersAtEndOfTurn effect) {
@ -139,11 +135,11 @@ class RemoveCountersAtEndOfTurn extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
if(source.getTargets().size() > 0) {
if (source.getTargets().size() > 0) {
Target multiTarget = source.getTargets().get(0);
for(UUID target : multiTarget.getTargets()) {
for (UUID target : multiTarget.getTargets()) {
Permanent permanent = game.getPermanent(target);
if(permanent != null) {
if (permanent != null) {
permanent.removeCounters(counterType.getName(), multiTarget.getTargetAmount(target), game);
}
}

View file

@ -78,10 +78,8 @@ public class AddExtraTurnControllerEffect extends OneShotEffect {
game.getState().getTurnMods().add(extraTurn);
if (loseGameAtEnd) {
LoseGameDelayedTriggeredAbility delayedTriggeredAbility = new LoseGameDelayedTriggeredAbility();
delayedTriggeredAbility.setSourceId(source.getSourceId());
delayedTriggeredAbility.setControllerId(source.getControllerId());
delayedTriggeredAbility.setConnectedTurnMod(extraTurn.getId());
game.addDelayedTriggeredAbility(delayedTriggeredAbility);
game.addDelayedTriggeredAbility(delayedTriggeredAbility, source);
}
}
return true;

View file

@ -232,10 +232,7 @@ class DashAddDelayedTriggeredAbilityEffect extends OneShotEffect {
// init target pointer now because the dashed creature will only be returned from battlefield zone (now in entering state so zone change counter is not raised yet)
effect.setTargetPointer(new FixedTarget(source.getSourceId(), game.getState().getZoneChangeCounter(source.getSourceId()) + 1));
DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect);
delayedAbility.setSourceId(source.getSourceId());
delayedAbility.setControllerId(source.getControllerId());
delayedAbility.setSourceObject(source.getSourceObject(game), game);
game.addDelayedTriggeredAbility(delayedAbility);
game.addDelayedTriggeredAbility(delayedAbility, source);
return true;
}
return false;

View file

@ -19,6 +19,7 @@ import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.targetpointer.FixedTarget;
import mage.target.targetpointer.FixedTargets;
public class MyriadAbility extends AttacksTriggeredAbility {
@ -70,15 +71,10 @@ class MyriadEffect extends OneShotEffect {
PutTokenOntoBattlefieldCopyTargetEffect effect = new PutTokenOntoBattlefieldCopyTargetEffect(controller.getId(), null, false, 1, true, true, playerId);
effect.setTargetPointer(new FixedTarget(sourceObject, game));
effect.apply(game, source);
for (Permanent tokenPermanent : effect.getAddedPermanent()) {
ExileTargetEffect exileEffect = new ExileTargetEffect();
exileEffect.setTargetPointer(new FixedTarget(tokenPermanent, game));
DelayedTriggeredAbility delayedAbility = new AtTheEndOfCombatDelayedTriggeredAbility(exileEffect);
delayedAbility.setSourceId(source.getSourceId());
delayedAbility.setControllerId(source.getControllerId());
delayedAbility.setSourceObject(source.getSourceObject(game), game);
game.addDelayedTriggeredAbility(delayedAbility);
}
ExileTargetEffect exileEffect = new ExileTargetEffect();
exileEffect.setTargetPointer(new FixedTargets(effect.getAddedPermanent(), game));
DelayedTriggeredAbility delayedAbility = new AtTheEndOfCombatDelayedTriggeredAbility(exileEffect);
game.addDelayedTriggeredAbility(delayedAbility, source);
}
}

View file

@ -127,9 +127,7 @@ class ReboundCastFromHandReplacementEffect extends ReplacementEffectImpl {
if (player != null) {
// Add the delayed triggered effect
ReboundEffectCastFromExileDelayedTrigger trigger = new ReboundEffectCastFromExileDelayedTrigger(source.getSourceId(), source.getSourceId());
trigger.setControllerId(source.getControllerId());
trigger.setSourceObject(source.getSourceObject(game), game);
game.addDelayedTriggeredAbility(trigger);
game.addDelayedTriggeredAbility(trigger, source);
player.moveCardToExileWithInfo(sourceCard, sourceCard.getId(), player.getName() + " Rebound", source.getSourceId(), game, Zone.STACK, true);
return true;

View file

@ -1495,9 +1495,17 @@ public abstract class GameImpl implements Game, Serializable {
delayedAbility.setSourceId(source.getSourceId());
delayedAbility.setControllerId(source.getControllerId());
delayedAbility.setSourceObject(source.getSourceObject(this), this);
return addDelayedTriggeredAbility(delayedAbility);
// return addDelayedTriggeredAbility(delayedAbility);
DelayedTriggeredAbility newAbility = delayedAbility.copy();
newAbility.newId();
// ability.init is called as the ability triggeres not now.
// If a FixedTarget pointer is already set from the effect setting up this delayed ability
// it has to be already initialized so it won't be overwitten as the ability triggers
state.addDelayedTriggeredAbility(newAbility);
return newAbility.getId();
}
@Deprecated
@Override
public UUID addDelayedTriggeredAbility(DelayedTriggeredAbility delayedAbility) {
DelayedTriggeredAbility newAbility = delayedAbility.copy();