Merge branch 'master' into Network_Upgrade

Conflicts:
	Mage.Client/src/main/java/mage/client/dialog/ConnectDialog.java
	Mage.Client/src/main/java/mage/client/game/FeedbackPanel.java
	Mage.Client/src/main/java/mage/client/game/GamePanel.java
	Mage.Server/src/main/java/mage/server/game/GameSessionPlayer.java
This commit is contained in:
betasteward 2015-09-10 10:30:51 -04:00
commit 49558e091d
687 changed files with 32892 additions and 4564 deletions

View file

@ -7,7 +7,7 @@
<parent>
<groupId>org.mage</groupId>
<artifactId>mage-root</artifactId>
<version>1.4.3</version>
<version>1.4.4</version>
</parent>
<artifactId>mage</artifactId>

View file

@ -237,6 +237,7 @@ public abstract class AbilityImpl implements Ability {
*/
if (effect.applyEffectsAfter()) {
game.applyEffects();
game.getState().getTriggers().checkStateTriggers(game);
}
}
}

View file

@ -1,16 +1,16 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
@ -20,12 +20,11 @@
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.abilities;
import java.util.UUID;
@ -48,8 +47,7 @@ public abstract class StateTriggeredAbility extends TriggeredAbilityImpl {
super(ability);
}
@Override
public final boolean checkEventType(GameEvent event, Game game) {
public boolean canTrigger(Game game) {
//20100716 - 603.8
Boolean triggered = (Boolean) game.getState().getValue(getSourceId().toString() + "triggered");
if (triggered == null) {
@ -58,7 +56,11 @@ public abstract class StateTriggeredAbility extends TriggeredAbilityImpl {
return !triggered;
}
@Override
public final boolean checkEventType(GameEvent event, Game game) {
return false;
}
@Override
public void trigger(Game game, UUID controllerId) {
//20100716 - 603.8
@ -71,7 +73,7 @@ public abstract class StateTriggeredAbility extends TriggeredAbilityImpl {
//20100716 - 603.8
boolean result = super.resolve(game);
game.getState().setValue(this.getSourceId().toString() + "triggered", Boolean.FALSE);
return result;
return result;
}
public void counter(Game game) {

View file

@ -69,45 +69,57 @@ public class TriggeredAbilities extends ConcurrentHashMap<String, TriggeredAbili
}
}
public void checkStateTriggers(Game game) {
for (Iterator<TriggeredAbility> it = this.values().iterator(); it.hasNext();) {
TriggeredAbility ability = it.next();
if (ability instanceof StateTriggeredAbility && ((StateTriggeredAbility) ability).canTrigger(game)) {
checkTrigger(ability, null, game);
}
}
}
public void checkTriggers(GameEvent event, Game game) {
for (Iterator<TriggeredAbility> it = this.values().iterator(); it.hasNext();) {
TriggeredAbility ability = it.next();
if (!ability.checkEventType(event, game)) {
continue;
if (ability.checkEventType(event, game)) {
checkTrigger(ability, event, game);
}
// for effects like when leaves battlefield or destroyed use ShortLKI to check if permanent was in the correct zone before (e.g. Oblivion Ring or Karmic Justice)
MageObject object = game.getObject(ability.getSourceId());
if (ability.isInUseableZone(game, object, event)) {
if (!game.getContinuousEffects().preventedByRuleModification(event, ability, game, false)) {
if (object != null) {
boolean controllerSet = false;
if (!ability.getZone().equals(Zone.COMMAND) && event.getTargetId() != null && event.getTargetId().equals(ability.getSourceId())
&& (event.getType().equals(EventType.ZONE_CHANGE) || event.getType().equals(EventType.DESTROYED_PERMANENT))) {
// need to check if object was face down for dies and destroy events because the ability triggers in the new zone, zone counter -1 is used
Permanent permanent = (Permanent) game.getLastKnownInformation(ability.getSourceId(), Zone.BATTLEFIELD, ability.getSourceObjectZoneChangeCounter() - 1);
if (permanent != null) {
if (!ability.getWorksFaceDown() && permanent.isFaceDown(game)) {
continue;
}
controllerSet = true;
ability.setControllerId(permanent.getControllerId());
}
}
if (!controllerSet) {
if (object instanceof Permanent) {
ability.setControllerId(((Permanent) object).getControllerId());
} else if (object instanceof Spell) {
// needed so that cast triggered abilities have to correct controller (e.g. Ulamog, the Infinite Gyre).
ability.setControllerId(((Spell) object).getControllerId());
} else if (object instanceof Card) {
ability.setControllerId(((Card) object).getOwnerId());
}
}
}
}
}
if (ability.checkTrigger(event, game)) {
ability.trigger(game, ability.getControllerId());
private void checkTrigger(TriggeredAbility ability, GameEvent event, Game game) {
// for effects like when leaves battlefield or destroyed use ShortLKI to check if permanent was in the correct zone before (e.g. Oblivion Ring or Karmic Justice)
MageObject object = game.getObject(ability.getSourceId());
if (ability.isInUseableZone(game, object, event)) {
if (event == null || !game.getContinuousEffects().preventedByRuleModification(event, ability, game, false)) {
if (object != null) {
boolean controllerSet = false;
if (!ability.getZone().equals(Zone.COMMAND) && event != null && event.getTargetId() != null && event.getTargetId().equals(ability.getSourceId())
&& (event.getType().equals(EventType.ZONE_CHANGE) || event.getType().equals(EventType.DESTROYED_PERMANENT))) {
// need to check if object was face down for dies and destroy events because the ability triggers in the new zone, zone counter -1 is used
Permanent permanent = (Permanent) game.getLastKnownInformation(ability.getSourceId(), Zone.BATTLEFIELD, ability.getSourceObjectZoneChangeCounter() - 1);
if (permanent != null) {
if (!ability.getWorksFaceDown() && permanent.isFaceDown(game)) {
return;
}
controllerSet = true;
ability.setControllerId(permanent.getControllerId());
}
}
if (!controllerSet) {
if (object instanceof Permanent) {
ability.setControllerId(((Permanent) object).getControllerId());
} else if (object instanceof Spell) {
// needed so that cast triggered abilities have to correct controller (e.g. Ulamog, the Infinite Gyre).
ability.setControllerId(((Spell) object).getControllerId());
} else if (object instanceof Card) {
ability.setControllerId(((Card) object).getOwnerId());
}
}
}
if (ability.checkTrigger(event, game)) {
ability.trigger(game, ability.getControllerId());
}
}
}

View file

@ -27,14 +27,12 @@
*/
package mage.abilities.common;
import java.util.UUID;
import mage.constants.Zone;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.EntersTheBattlefieldEvent;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.permanent.Permanent;
/**
*
@ -57,11 +55,10 @@ public class AllyEntersBattlefieldTriggeredAbility extends TriggeredAbilityImpl
@Override
public boolean checkTrigger(GameEvent event, Game game) {
UUID targetId = event.getTargetId();
Permanent permanent = game.getPermanent(targetId);
if (permanent.getControllerId().equals(this.controllerId)
&& (targetId.equals(this.getSourceId())
|| (permanent.hasSubtype("Ally") && !targetId.equals(this.getSourceId())))) {
EntersTheBattlefieldEvent ebe = (EntersTheBattlefieldEvent) event;
if (ebe.getTarget().getControllerId().equals(this.controllerId)
&& (event.getTargetId().equals(this.getSourceId())
|| (ebe.getTarget().hasSubtype("Ally") && !event.getTargetId().equals(this.getSourceId())))) {
return true;
}
return false;
@ -69,7 +66,7 @@ public class AllyEntersBattlefieldTriggeredAbility extends TriggeredAbilityImpl
@Override
public String getRule() {
return "Whenever {this} or another Ally enters the battlefield under your control, " + super.getRule();
return "<i>Rally</i> &mdash; Whenever {this} or another Ally enters the battlefield under your control, " + super.getRule();
}
@Override

View file

@ -0,0 +1,86 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.abilities.common;
import java.util.UUID;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent.EventType;
import mage.game.events.GameEvent;
import mage.target.targetpointer.FixedTarget;
/**
*
* @author LoneFox
*/
public class AttacksAloneTriggeredAbility extends TriggeredAbilityImpl {
public AttacksAloneTriggeredAbility(Effect effect) {
super(Zone.BATTLEFIELD, effect);
}
public AttacksAloneTriggeredAbility(final AttacksAloneTriggeredAbility ability) {
super(ability);
}
@Override
public AttacksAloneTriggeredAbility copy() {
return new AttacksAloneTriggeredAbility(this);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == EventType.DECLARED_ATTACKERS;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if(game.getActivePlayerId().equals(this.controllerId) ) {
UUID creatureId = this.getSourceId();
if(creatureId != null) {
if(game.getCombat().attacksAlone() && creatureId == game.getCombat().getAttackers().get(0)) {
UUID defender = game.getCombat().getDefenderId(creatureId);
if(defender != null) {
for(Effect effect: getEffects()) {
effect.setTargetPointer(new FixedTarget(defender));
}
}
return true;
}
}
}
return false;
}
@Override
public String getRule() {
return "Whenever {this} attacks alone, " + super.getRule();
}
}

View file

@ -0,0 +1,96 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.abilities.common;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.constants.Duration;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.combat.CombatGroup;
import mage.game.events.GameEvent.EventType;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.target.targetpointer.FixedTarget;
public class AttacksAndIsNotBlockedTriggeredAbility extends TriggeredAbilityImpl {
private boolean setTargetPointer;
public AttacksAndIsNotBlockedTriggeredAbility(Effect effect) {
this(effect, false, false);
}
public AttacksAndIsNotBlockedTriggeredAbility(Effect effect, boolean optional) {
this(effect, optional, false);
}
public AttacksAndIsNotBlockedTriggeredAbility(Effect effect, boolean optional, boolean setTargetPointer) {
super(Zone.BATTLEFIELD, effect, optional);
this.setTargetPointer = setTargetPointer;
}
public AttacksAndIsNotBlockedTriggeredAbility(final AttacksAndIsNotBlockedTriggeredAbility ability) {
super(ability);
this.setTargetPointer = ability.setTargetPointer;
}
@Override
public AttacksAndIsNotBlockedTriggeredAbility copy() {
return new AttacksAndIsNotBlockedTriggeredAbility(this);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == EventType.DECLARED_BLOCKERS;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Permanent sourcePermanent = game.getPermanent(getSourceId());
if(sourcePermanent.isAttacking()) {
for(CombatGroup combatGroup: game.getCombat().getGroups()) {
if(combatGroup.getBlockers().isEmpty() && combatGroup.getAttackers().contains(getSourceId())) {
if(setTargetPointer) {
for(Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(game.getCombat().getDefendingPlayerId(getSourceId(), game)));
}
}
return true;
}
}
}
return false;
}
@Override
public String getRule() {
return "Whenever {this} attacks and isn't blocked, " + super.getRule();
}
}

View file

@ -14,7 +14,6 @@ import mage.constants.Zone;
*
* @author LevelX2
*/
public class AttacksEachCombatStaticAbility extends StaticAbility {
public AttacksEachCombatStaticAbility() {

View file

@ -1,16 +1,16 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
@ -20,12 +20,11 @@
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.abilities.common;
import mage.abilities.TriggeredAbilityImpl;
@ -43,8 +42,8 @@ import mage.target.targetpointer.FixedTarget;
*
* @author LevelX2
*/
public class DealsDamageToAPlayerAllTriggeredAbility extends TriggeredAbilityImpl {
private final FilterPermanent filter;
private final SetTargetPointer setTargetPointer;
private final boolean onlyCombat;
@ -81,12 +80,12 @@ public class DealsDamageToAPlayerAllTriggeredAbility extends TriggeredAbilityImp
if (!setTargetPointer.equals(SetTargetPointer.NONE)) {
for (Effect effect : this.getEffects()) {
effect.setValue("damage", event.getAmount());
switch(setTargetPointer) {
switch (setTargetPointer) {
case PLAYER:
effect.setTargetPointer(new FixedTarget(permanent.getControllerId()));
break;
case PERMANENT:
effect.setTargetPointer(new FixedTarget(permanent.getId()));
effect.setTargetPointer(new FixedTarget(permanent.getId(), permanent.getZoneChangeCounter(game)));
break;
}
@ -100,7 +99,7 @@ public class DealsDamageToAPlayerAllTriggeredAbility extends TriggeredAbilityImp
@Override
public String getRule() {
return "Whenever " + filter.getMessage() + " deals "+(onlyCombat ? "combat ":"") + "damage to a player, " + super.getRule();
return "Whenever " + filter.getMessage() + " deals " + (onlyCombat ? "combat " : "") + "damage to a player, " + super.getRule();
}
}

View file

@ -28,9 +28,9 @@
package mage.abilities.common;
import mage.MageObject;
import mage.constants.Zone;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.constants.Zone;
import mage.filter.common.FilterCreaturePermanent;
import mage.game.Game;
import mage.game.events.GameEvent;
@ -67,7 +67,7 @@ public class DiesThisOrAnotherCreatureTriggeredAbility extends TriggeredAbilityI
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.ZONE_CHANGE;
}
@Override
public boolean isInUseableZone(Game game, MageObject source, GameEvent event) {
Permanent sourcePermanent;
@ -81,24 +81,21 @@ public class DiesThisOrAnotherCreatureTriggeredAbility extends TriggeredAbilityI
}
return hasSourceObjectAbility(game, sourcePermanent, event);
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
if (game.getPermanent(sourceId) == null) {
if (game.getLastKnownInformation(sourceId, Zone.BATTLEFIELD) == null) {
return false;
}
if (game.getPermanentOrLKIBattlefield(getSourceId()) == null) {
return false;
}
if (zEvent.getFromZone() == Zone.BATTLEFIELD && zEvent.getToZone() == Zone.GRAVEYARD) {
Permanent permanent = (Permanent) game.getLastKnownInformation(event.getTargetId(), Zone.BATTLEFIELD);
if (permanent != null) {
if (permanent.getId().equals(this.getSourceId())) {
if (zEvent.getTarget() != null) {
if (zEvent.getTarget().getId().equals(this.getSourceId())) {
return true;
} else {
if (filter.match(permanent, sourceId, controllerId, game)) {
if (filter.match(zEvent.getTarget(), sourceId, controllerId, game)) {
return true;
}
}

View file

@ -53,6 +53,8 @@ public class DiscardsACardOpponentTriggeredAbility extends TriggeredAbilityImpl
effect.setTargetPointer(new FixedTarget(event.getPlayerId()));
}
break;
case NONE:
break;
default:
throw new UnsupportedOperationException(setTargetPointer.toString() + " not supported for this ability.");
}

View file

@ -6,6 +6,7 @@
package mage.abilities.common;
import mage.abilities.SpellAbility;
import mage.abilities.costs.mana.ManaCost;
import mage.abilities.costs.mana.ManaCosts;
import mage.cards.Card;
import mage.constants.SpellAbilityType;
@ -21,7 +22,7 @@ public class PayMoreToCastAsThoughtItHadFlashAbility extends SpellAbility {
private final ManaCosts costsToAdd;
public PayMoreToCastAsThoughtItHadFlashAbility(Card card, ManaCosts costsToAdd) {
public PayMoreToCastAsThoughtItHadFlashAbility(Card card, ManaCosts<ManaCost> costsToAdd) {
super(card.getSpellAbility().getManaCosts().copy(), card.getName() + " as though it had flash", Zone.HAND, SpellAbilityType.BASE_ALTERNATE);
this.costsToAdd = costsToAdd;
this.timing = TimingRule.INSTANT;

View file

@ -1,149 +1,149 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.abilities.common.delayed;
import mage.constants.TargetController;
import mage.abilities.DelayedTriggeredAbility;
import mage.abilities.effects.Effect;
import mage.constants.Duration;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.permanent.Permanent;
/**
*
* @author LevelX2
*/
public class AtTheBeginOMainPhaseDelayedTriggeredAbility extends DelayedTriggeredAbility {
public enum PhaseSelection {
NEXT_PRECOMBAT_MAIN("next precombat"),
NEXT_POSTCOMAT_MAIN("next postcombat"),
NEXT_MAIN("next");
private final String text;
PhaseSelection(String text) {
this.text = text;
}
@Override
public String toString() {
return text;
}
}
private final TargetController targetController;
private final PhaseSelection phaseSelection;
public AtTheBeginOMainPhaseDelayedTriggeredAbility(Effect effect, boolean optional, TargetController targetController, PhaseSelection phaseSelection) {
super(effect, Duration.EndOfGame, true, optional);
this.targetController = targetController;
this.phaseSelection = phaseSelection;
}
public AtTheBeginOMainPhaseDelayedTriggeredAbility(final AtTheBeginOMainPhaseDelayedTriggeredAbility ability) {
super(ability);
this.targetController = ability.targetController;
this.phaseSelection = ability.phaseSelection;
}
@Override
public AtTheBeginOMainPhaseDelayedTriggeredAbility copy() {
return new AtTheBeginOMainPhaseDelayedTriggeredAbility(this);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return checkPhase(event.getType());
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
switch (targetController) {
case ANY:
return true;
case YOU:
boolean yours = event.getPlayerId().equals(this.controllerId);
return yours;
case OPPONENT:
if (game.getPlayer(this.getControllerId()).hasOpponent(event.getPlayerId(), game)) {
return true;
}
break;
case CONTROLLER_ATTACHED_TO:
Permanent attachment = game.getPermanent(sourceId);
if (attachment != null && attachment.getAttachedTo() != null) {
Permanent attachedTo = game.getPermanent(attachment.getAttachedTo());
if (attachedTo != null && attachedTo.getControllerId().equals(event.getPlayerId())) {
return true;
}
}
}
return false;
}
private boolean checkPhase(EventType eventType) {
switch (phaseSelection) {
case NEXT_MAIN:
return EventType.PRECOMBAT_MAIN_PHASE_PRE.equals(eventType) || EventType.POSTCOMBAT_MAIN_PHASE_PRE.equals(eventType);
case NEXT_POSTCOMAT_MAIN:
return EventType.POSTCOMBAT_MAIN_PHASE_PRE.equals(eventType);
case NEXT_PRECOMBAT_MAIN:
return EventType.PRECOMBAT_MAIN_PHASE_PRE.equals(eventType);
default:
return false;
}
}
@Override
public String getRule() {
StringBuilder sb = new StringBuilder();
switch (targetController) {
case YOU:
sb.append("At the beginning of your ").append(phaseSelection.toString()).append(" main phase, ");
break;
case OPPONENT:
sb.append("At the beginning of an opponent's ").append(phaseSelection.toString()).append(" main phase, ");
break;
case ANY:
sb.append("At the beginning of the ").append(phaseSelection.toString()).append(" main phase, ");
break;
case CONTROLLER_ATTACHED_TO:
sb.append("At the beginning of the ").append(phaseSelection.toString()).append(" main phase of enchanted creature's controller, ");
break;
}
sb.append(getEffects().getText(modes.getMode()));
return sb.toString();
}
}
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.abilities.common.delayed;
import mage.constants.TargetController;
import mage.abilities.DelayedTriggeredAbility;
import mage.abilities.effects.Effect;
import mage.constants.Duration;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.permanent.Permanent;
/**
*
* @author LevelX2
*/
public class AtTheBeginOfMainPhaseDelayedTriggeredAbility extends DelayedTriggeredAbility {
public enum PhaseSelection {
NEXT_PRECOMBAT_MAIN("next precombat"),
NEXT_POSTCOMAT_MAIN("next postcombat"),
NEXT_MAIN("next");
private final String text;
PhaseSelection(String text) {
this.text = text;
}
@Override
public String toString() {
return text;
}
}
private final TargetController targetController;
private final PhaseSelection phaseSelection;
public AtTheBeginOfMainPhaseDelayedTriggeredAbility(Effect effect, boolean optional, TargetController targetController, PhaseSelection phaseSelection) {
super(effect, Duration.EndOfGame, true, optional);
this.targetController = targetController;
this.phaseSelection = phaseSelection;
}
public AtTheBeginOfMainPhaseDelayedTriggeredAbility(final AtTheBeginOfMainPhaseDelayedTriggeredAbility ability) {
super(ability);
this.targetController = ability.targetController;
this.phaseSelection = ability.phaseSelection;
}
@Override
public AtTheBeginOfMainPhaseDelayedTriggeredAbility copy() {
return new AtTheBeginOfMainPhaseDelayedTriggeredAbility(this);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return checkPhase(event.getType());
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
switch (targetController) {
case ANY:
return true;
case YOU:
boolean yours = event.getPlayerId().equals(this.controllerId);
return yours;
case OPPONENT:
if (game.getPlayer(this.getControllerId()).hasOpponent(event.getPlayerId(), game)) {
return true;
}
break;
case CONTROLLER_ATTACHED_TO:
Permanent attachment = game.getPermanent(sourceId);
if (attachment != null && attachment.getAttachedTo() != null) {
Permanent attachedTo = game.getPermanent(attachment.getAttachedTo());
if (attachedTo != null && attachedTo.getControllerId().equals(event.getPlayerId())) {
return true;
}
}
}
return false;
}
private boolean checkPhase(EventType eventType) {
switch (phaseSelection) {
case NEXT_MAIN:
return EventType.PRECOMBAT_MAIN_PHASE_PRE.equals(eventType) || EventType.POSTCOMBAT_MAIN_PHASE_PRE.equals(eventType);
case NEXT_POSTCOMAT_MAIN:
return EventType.POSTCOMBAT_MAIN_PHASE_PRE.equals(eventType);
case NEXT_PRECOMBAT_MAIN:
return EventType.PRECOMBAT_MAIN_PHASE_PRE.equals(eventType);
default:
return false;
}
}
@Override
public String getRule() {
StringBuilder sb = new StringBuilder();
switch (targetController) {
case YOU:
sb.append("At the beginning of your ").append(phaseSelection.toString()).append(" main phase, ");
break;
case OPPONENT:
sb.append("At the beginning of an opponent's ").append(phaseSelection.toString()).append(" main phase, ");
break;
case ANY:
sb.append("At the beginning of the ").append(phaseSelection.toString()).append(" main phase, ");
break;
case CONTROLLER_ATTACHED_TO:
sb.append("At the beginning of the ").append(phaseSelection.toString()).append(" main phase of enchanted creature's controller, ");
break;
}
sb.append(getEffects().getText(modes.getMode()));
return sb.toString();
}
}

View file

@ -30,11 +30,11 @@ package mage.abilities.condition.common;
import mage.abilities.Ability;
import mage.abilities.condition.Condition;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
/**
* Checks if the player has its commander in play
* Checks if the player has its commander in play and controls it
*
* @author LevelX2
*/
@ -42,7 +42,8 @@ public class CommanderInPlayCondition implements Condition {
private static CommanderInPlayCondition fInstance = null;
private CommanderInPlayCondition() {}
private CommanderInPlayCondition() {
}
public static Condition getInstance() {
if (fInstance == null) {
@ -55,7 +56,8 @@ public class CommanderInPlayCondition implements Condition {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
return game.getPermanent(controller.getCommanderId()) != null;
Permanent commander = game.getPermanent(controller.getCommanderId());
return commander != null && commander.getControllerId().equals(source.getControllerId());
}
return false;
}
@ -65,4 +67,4 @@ public class CommanderInPlayCondition implements Condition {
return "As long as you control your commander";
}
}
}

View file

@ -28,6 +28,8 @@
// author jeffwadsworth
package mage.abilities.costs.common;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import mage.MageObject;
import mage.abilities.Ability;
@ -44,16 +46,19 @@ public class RevealTargetFromHandCost extends CostImpl {
public int convertedManaCosts = 0;
protected int numberCardsRevealed = 0;
protected List<Card> revealedCards;
public RevealTargetFromHandCost(TargetCardInHand target) {
this.addTarget(target);
this.text = (target.getNumberOfTargets() == 0 ? "you may " : "") + "reveal " + target.getTargetName();
this.revealedCards = new ArrayList<>();
}
public RevealTargetFromHandCost(final RevealTargetFromHandCost cost) {
super(cost);
this.convertedManaCosts = cost.convertedManaCosts;
this.numberCardsRevealed = cost.numberCardsRevealed;
this.revealedCards = new ArrayList<>(cost.revealedCards);
}
@Override
@ -69,6 +74,7 @@ public class RevealTargetFromHandCost extends CostImpl {
convertedManaCosts += card.getManaCost().convertedManaCost();
numberCardsRevealed++;
cards.add(card);
revealedCards.add(card);
}
}
if (numberCardsRevealed > 0) {
@ -92,6 +98,10 @@ public class RevealTargetFromHandCost extends CostImpl {
return numberCardsRevealed;
}
public List<Card> getRevealedCards() {
return revealedCards;
}
@Override
public boolean canPay(Ability ability, UUID sourceId, UUID controllerId, Game game) {
return targets.canChoose(controllerId, game);

View file

@ -0,0 +1,61 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.abilities.dynamicvalue.common;
import mage.abilities.Ability;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.effects.Effect;
import mage.game.Game;
import mage.players.Player;
/**
*
* @author LoneFox
*/
public class CardsInTargetPlayersGraveyardCount implements DynamicValue {
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
Player player = game.getPlayer(effect.getTargetPointer().getFirst(game, sourceAbility));
if (player != null) {
return player.getGraveyard().size();
}
return 0;
}
@Override
public CardsInTargetPlayersGraveyardCount copy() {
return new CardsInTargetPlayersGraveyardCount();
}
@Override
public String getMessage() {
return "cards in target player's graveyard";
}
}

View file

@ -0,0 +1,81 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mage.abilities.dynamicvalue.common;
import java.io.ObjectStreamException;
import mage.MageObject;
import mage.Mana;
import mage.abilities.Ability;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.effects.Effect;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.stack.Spell;
/**
*
* @author LevelX2
*/
public class ColorsOfManaSpentToCastCount implements DynamicValue {
private static final ColorsOfManaSpentToCastCount fINSTANCE = new ColorsOfManaSpentToCastCount();
private Object readResolve() throws ObjectStreamException {
return fINSTANCE;
}
public static ColorsOfManaSpentToCastCount getInstance() {
return fINSTANCE;
}
@Override
public int calculate(Game game, Ability source, Effect effect) {
int count = 0;
Spell spell = game.getStack().getSpell(source.getSourceId());
if (spell == null) {
MageObject mageObject = game.getLastKnownInformation(source.getSourceId(), Zone.STACK);
if (mageObject instanceof Spell) {
spell = (Spell) mageObject;
}
}
if (spell != null) {
// NOT the cmc of the spell on the stack
Mana mana = spell.getSpellAbility().getManaCostsToPay().getPayment();
if (mana.getBlack() > 0) {
count++;
}
if (mana.getBlue() > 0) {
count++;
}
if (mana.getGreen() > 0) {
count++;
}
if (mana.getRed() > 0) {
count++;
}
if (mana.getWhite() > 0) {
count++;
}
}
return count;
}
@Override
public ColorsOfManaSpentToCastCount copy() {
return new ColorsOfManaSpentToCastCount();
}
@Override
public String toString() {
return "X";
}
@Override
public String getMessage() {
return "the number of colors of mana spent to cast {this}";
}
}

View file

@ -0,0 +1,82 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.abilities.dynamicvalue.common;
import mage.abilities.Ability;
import mage.abilities.costs.Cost;
import mage.abilities.costs.common.SacrificeTargetCost;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.effects.Effect;
import mage.game.Game;
import mage.game.permanent.Permanent;
/**
* @author LoneFox
*/
public class SacrificeCostConvertedMana implements DynamicValue {
private final String type;
public SacrificeCostConvertedMana(String type) {
this.type = type;
}
public SacrificeCostConvertedMana(SacrificeCostConvertedMana value) {
this.type = value.type;
}
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
for(Cost cost : sourceAbility.getCosts()) {
if(cost instanceof SacrificeTargetCost) {
SacrificeTargetCost sacrificeCost = (SacrificeTargetCost) cost;
int totalCMC = 0;
for(Permanent permanent : sacrificeCost.getPermanents()) {
totalCMC += permanent.getManaCost().convertedManaCost();
}
return totalCMC;
}
}
return 0;
}
@Override
public SacrificeCostConvertedMana copy() {
return new SacrificeCostConvertedMana(this);
}
@Override
public String toString() {
return "X";
}
@Override
public String getMessage() {
return "the sacrificed " + type + "'s converted mana cost";
}
}

View file

@ -116,6 +116,7 @@ public class AuraReplacementEffect extends ReplacementEffectImpl {
}
}
game.applyEffects(); // So continuousEffects are removed if previous effect of the same ability did move objects that cuase continuous effects
if (targetId == null) {
Target target = card.getSpellAbility().getTargets().get(0);
enchantCardInGraveyard = target instanceof TargetCardInGraveyard;
@ -169,7 +170,6 @@ public class AuraReplacementEffect extends ReplacementEffectImpl {
PermanentCard permanent = new PermanentCard(card, card.getOwnerId(), game);
game.getBattlefield().addPermanent(permanent);
card.setZone(Zone.BATTLEFIELD, game);
game.applyEffects();
boolean entered = permanent.entersBattlefield(event.getSourceId(), game, fromZone, true);
game.applyEffects();
if (!entered) {

View file

@ -1,34 +1,35 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.abilities.effects;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import mage.MageObjectReference;
import mage.abilities.Ability;
import mage.constants.Duration;
@ -43,25 +44,42 @@ import mage.game.Game;
public interface ContinuousEffect extends Effect {
boolean isUsed();
boolean isDiscarded();
void discard();
Duration getDuration();
long getOrder();
void setOrder(long order);
boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game);
boolean hasLayer(Layer layer);
boolean isInactive(Ability source, Game game);
void init(Ability source, Game game);
Layer getLayer();
SubLayer getSublayer();
void overrideRuleText(String text);
List<MageObjectReference> getAffectedObjects();
Set<UUID> isDependentTo(List<ContinuousEffect> allEffectsInLayer);
@Override
void newId();
@Override
ContinuousEffect copy();
boolean isTemporary();
void setTemporary(boolean temporary);
}

View file

@ -29,6 +29,7 @@ package mage.abilities.effects;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import mage.MageObjectReference;
import mage.abilities.Ability;
@ -250,4 +251,9 @@ public abstract class ContinuousEffectImpl extends EffectImpl implements Continu
this.temporary = temporary;
}
@Override
public Set<UUID> isDependentTo(List<ContinuousEffect> allEffectsInLayer) {
return null;
}
}

View file

@ -38,6 +38,7 @@ import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
import mage.MageObject;
@ -851,8 +852,9 @@ public class ContinuousEffects implements Serializable {
//20091005 - 613
public void apply(Game game) {
removeInactiveEffects(game);
List<ContinuousEffect> layerEffects = getLayeredEffects(game);
List<ContinuousEffect> layer = filterLayeredEffects(layerEffects, Layer.CopyEffects_1);
List<ContinuousEffect> activeLayerEffects = getLayeredEffects(game);
List<ContinuousEffect> layer = filterLayeredEffects(activeLayerEffects, Layer.CopyEffects_1);
for (ContinuousEffect effect : layer) {
HashSet<Ability> abilities = layeredEffects.getAbility(effect.getId());
for (Ability ability : abilities) {
@ -861,10 +863,10 @@ public class ContinuousEffects implements Serializable {
}
//Reload layerEffect if copy effects were applied
if (layer.size() > 0) {
layerEffects = getLayeredEffects(game);
activeLayerEffects = getLayeredEffects(game);
}
layer = filterLayeredEffects(layerEffects, Layer.ControlChangingEffects_2);
layer = filterLayeredEffects(activeLayerEffects, Layer.ControlChangingEffects_2);
// apply control changing effects multiple times if it's needed
// for cases when control over permanents with change control abilities is changed
// e.g. Mind Control is controlled by Steal Enchantment
@ -882,55 +884,72 @@ public class ContinuousEffects implements Serializable {
// reset control before reapplying control changing effects
game.getBattlefield().resetPermanentsControl();
}
layer = filterLayeredEffects(layerEffects, Layer.TextChangingEffects_3);
for (ContinuousEffect effect : layer) {
HashSet<Ability> abilities = layeredEffects.getAbility(effect.getId());
for (Ability ability : abilities) {
effect.apply(Layer.TextChangingEffects_3, SubLayer.NA, ability, game);
}
}
layer = filterLayeredEffects(layerEffects, Layer.TypeChangingEffects_4);
for (ContinuousEffect effect : layer) {
HashSet<Ability> abilities = layeredEffects.getAbility(effect.getId());
for (Ability ability : abilities) {
effect.apply(Layer.TypeChangingEffects_4, SubLayer.NA, ability, game);
}
}
layer = filterLayeredEffects(layerEffects, Layer.ColorChangingEffects_5);
for (ContinuousEffect effect : layer) {
HashSet<Ability> abilities = layeredEffects.getAbility(effect.getId());
for (Ability ability : abilities) {
effect.apply(Layer.ColorChangingEffects_5, SubLayer.NA, ability, game);
}
}
Map<ContinuousEffect, List<Ability>> appliedEffects = new HashMap<>();
applyLayer(activeLayerEffects, Layer.TextChangingEffects_3, game);
applyLayer(activeLayerEffects, Layer.TypeChangingEffects_4, game);
applyLayer(activeLayerEffects, Layer.ColorChangingEffects_5, game);
Map<ContinuousEffect, List<Ability>> appliedEffectAbilities = new HashMap<>();
boolean done = false;
Map<ContinuousEffect, Set<UUID>> waitingEffects = new LinkedHashMap<>();
Set<UUID> appliedEffects = new HashSet<>();
while (!done) { // loop needed if a added effect adds again an effect (e.g. Level 5- of Joraga Treespeaker)
done = true;
layer = filterLayeredEffects(layerEffects, Layer.AbilityAddingRemovingEffects_6);
layer = filterLayeredEffects(activeLayerEffects, Layer.AbilityAddingRemovingEffects_6);
for (ContinuousEffect effect : layer) {
if (layerEffects.contains(effect)) {
List<Ability> appliedAbilities = appliedEffects.get(effect);
if (activeLayerEffects.contains(effect) && !appliedEffects.contains(effect.getId())) { // Effect does still exist and was not applied yet
Set<UUID> dependentTo = effect.isDependentTo(layer);
if (dependentTo != null && !appliedEffects.containsAll(dependentTo)) {
waitingEffects.put(effect, dependentTo);
continue;
}
List<Ability> appliedAbilities = appliedEffectAbilities.get(effect);
HashSet<Ability> abilities = layeredEffects.getAbility(effect.getId());
for (Ability ability : abilities) {
if (appliedAbilities == null || !appliedAbilities.contains(ability)) {
if (appliedAbilities == null) {
appliedAbilities = new ArrayList<>();
appliedEffects.put(effect, appliedAbilities);
appliedEffectAbilities.put(effect, appliedAbilities);
}
appliedAbilities.add(ability);
effect.apply(Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, ability, game);
done = false;
// list must be updated after each applied effect (eg. if "Turn to Frog" removes abilities)
layerEffects = getLayeredEffects(game);
activeLayerEffects = getLayeredEffects(game);
}
}
appliedEffects.add(effect.getId());
if (!waitingEffects.isEmpty()) {
// check if waiting effects can be applied now
for (Iterator<Map.Entry<ContinuousEffect, Set<UUID>>> iterator = waitingEffects.entrySet().iterator(); iterator.hasNext();) {
Map.Entry<ContinuousEffect, Set<UUID>> entry = iterator.next();
if (appliedEffects.containsAll(entry.getValue())) { // all dependent to effects are applied now so apply the effect itself
appliedAbilities = appliedEffectAbilities.get(entry.getKey());
abilities = layeredEffects.getAbility(entry.getKey().getId());
for (Ability ability : abilities) {
if (appliedAbilities == null || !appliedAbilities.contains(ability)) {
if (appliedAbilities == null) {
appliedAbilities = new ArrayList<>();
appliedEffectAbilities.put(entry.getKey(), appliedAbilities);
}
appliedAbilities.add(ability);
entry.getKey().apply(Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, ability, game);
done = false;
// list must be updated after each applied effect (eg. if "Turn to Frog" removes abilities)
activeLayerEffects = getLayeredEffects(game);
}
}
appliedEffects.add(entry.getKey().getId());
iterator.remove();
}
}
}
}
}
}
layer = filterLayeredEffects(layerEffects, Layer.PTChangingEffects_7);
layer = filterLayeredEffects(activeLayerEffects, Layer.PTChangingEffects_7);
for (ContinuousEffect effect : layer) {
HashSet<Ability> abilities = layeredEffects.getAbility(effect.getId());
for (Ability ability : abilities) {
@ -952,14 +971,14 @@ public class ContinuousEffects implements Serializable {
effect.apply(Layer.PTChangingEffects_7, SubLayer.SwitchPT_e, ability, game);
}
}
layer = filterLayeredEffects(layerEffects, Layer.PlayerEffects);
layer = filterLayeredEffects(activeLayerEffects, Layer.PlayerEffects);
for (ContinuousEffect effect : layer) {
HashSet<Ability> abilities = layeredEffects.getAbility(effect.getId());
for (Ability ability : abilities) {
effect.apply(Layer.PlayerEffects, SubLayer.NA, ability, game);
}
}
layer = filterLayeredEffects(layerEffects, Layer.RulesEffects);
layer = filterLayeredEffects(activeLayerEffects, Layer.RulesEffects);
for (ContinuousEffect effect : layer) {
HashSet<Ability> abilities = layeredEffects.getAbility(effect.getId());
for (Ability ability : abilities) {
@ -968,6 +987,42 @@ public class ContinuousEffects implements Serializable {
}
}
private void applyLayer(List<ContinuousEffect> activeLayerEffects, Layer currentLayer, Game game) {
List<ContinuousEffect> layer = filterLayeredEffects(activeLayerEffects, currentLayer);
if (!layer.isEmpty()) {
int numberOfEffects = layer.size();
Set<UUID> appliedEffects = new HashSet<>();
Map<ContinuousEffect, Set<UUID>> waitingEffects = new LinkedHashMap<>();
for (ContinuousEffect effect : layer) {
if (numberOfEffects > 1) { // If an effect is dependent to not applied effects yet of this layer, so wait to apply this effect
Set<UUID> dependentTo = effect.isDependentTo(layer);
if (dependentTo != null && !appliedEffects.containsAll(dependentTo)) {
waitingEffects.put(effect, dependentTo);
continue;
}
}
applyContinuousEffect(effect, currentLayer, game);
appliedEffects.add(effect.getId());
if (!waitingEffects.isEmpty()) {
// check if waiting effects can be applied now
for (Entry<ContinuousEffect, Set<UUID>> entry : waitingEffects.entrySet()) {
if (appliedEffects.containsAll(entry.getValue())) { // all dependent to effects are applied now so apply the effect itself
applyContinuousEffect(entry.getKey(), currentLayer, game);
appliedEffects.add(entry.getKey().getId());
}
}
}
}
}
}
private void applyContinuousEffect(ContinuousEffect effect, Layer currentLayer, Game game) {
HashSet<Ability> abilities = layeredEffects.getAbility(effect.getId());
for (Ability ability : abilities) {
effect.apply(currentLayer, SubLayer.NA, ability, game);
}
}
/**
* Adds a continuous ability with a reference to a sourceId. It's used for
* effects that cease to exist again So this effects were removed again

View file

@ -28,8 +28,6 @@
package mage.abilities.effects.common;
import java.util.UUID;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.abilities.Ability;
import mage.abilities.SpellAbility;
import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility;
@ -38,6 +36,9 @@ import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.continuous.GainAbilityTargetEffect;
import mage.cards.Card;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
@ -46,37 +47,37 @@ import mage.target.targetpointer.FixedTarget;
/**
* FAQ 2013/01/11
*
*
* 702.97. Cipher
*
* 702.97a Cipher appears on some instants and sorceries. It represents two static
* abilities, one that functions while the spell is on the stack and one that functions
* while the card with cipher is in the exile zone. "Cipher" means "If this spell is
* represented by a card, you may exile this card encoded on a creature you control"
* and "As long as this card is encoded on that creature, that creature has 'Whenever
* this creature deals combat damage to a player, you may copy this card and you may
* cast the copy without paying its mana cost.'"
* 702.97a Cipher appears on some instants and sorceries. It represents two
* static abilities, one that functions while the spell is on the stack and one
* that functions while the card with cipher is in the exile zone. "Cipher"
* means "If this spell is represented by a card, you may exile this card
* encoded on a creature you control" and "As long as this card is encoded on
* that creature, that creature has 'Whenever this creature deals combat damage
* to a player, you may copy this card and you may cast the copy without paying
* its mana cost.'"
*
* 702.97b The term "encoded" describes the relationship between the card with cipher
* while in the exile zone and the creature chosen when the spell represented by that
* card resolves.
* 702.97b The term "encoded" describes the relationship between the card with
* cipher while in the exile zone and the creature chosen when the spell
* represented by that card resolves.
*
* 702.97c The card with cipher remains encoded on the chosen creature as long as the
* card with cipher remains exiled and the creature remains on the battlefield. The
* card remains encoded on that object even if it changes controller or stops being
* a creature, as long as it remains on the battlefield.
* 702.97c The card with cipher remains encoded on the chosen creature as long
* as the card with cipher remains exiled and the creature remains on the
* battlefield. The card remains encoded on that object even if it changes
* controller or stops being a creature, as long as it remains on the
* battlefield.
*
* TODO: Implement Cipher as two static abilities concerning the rules.
*
* @author LevelX2
*/
public class CipherEffect extends OneShotEffect {
public CipherEffect() {
super(Outcome.Copy);
staticText ="<br><br/>Cipher <i>(Then you may exile this spell card encoded on a creature you control. Whenever that creature deals combat damage to a player, its controller may cast a copy of the encoded card without paying its mana cost.)</i>";
staticText = "<br><br/>Cipher <i>(Then you may exile this spell card encoded on a creature you control. Whenever that creature deals combat damage to a player, its controller may cast a copy of the encoded card without paying its mana cost.)</i>";
}
public CipherEffect(final CipherEffect effect) {
@ -86,10 +87,11 @@ public class CipherEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
TargetControlledCreaturePermanent target = new TargetControlledCreaturePermanent();
if (controller != null) {
TargetControlledCreaturePermanent target = new TargetControlledCreaturePermanent();
target.setNotTarget(true);
if (target.canChoose(source.getControllerId(), game)
&& controller.chooseUse(outcome, "Cipher this spell to a creature?", source, game)) {
&& controller.chooseUse(outcome, "Cipher this spell to a creature?", source, game)) {
controller.chooseTarget(outcome, target, source, game);
Card sourceCard = game.getCard(source.getSourceId());
Permanent targetCreature = game.getPermanent(target.getFirstTarget());
@ -99,9 +101,10 @@ public class CipherEffect extends OneShotEffect {
ContinuousEffect effect = new GainAbilityTargetEffect(ability, Duration.Custom);
effect.setTargetPointer(new FixedTarget(target.getFirstTarget()));
game.addEffect(effect, source);
if (!game.isSimulation())
if (!game.isSimulation()) {
game.informPlayers(new StringBuilder(sourceCard.getLogName()).append(": Spell ciphered to ").append(targetCreature.getLogName()).toString());
return sourceCard.moveToExile(null, "", source.getSourceId(), game);
}
return controller.moveCards(sourceCard, null, Zone.EXILED, source, game);
} else {
return false;
}
@ -119,7 +122,7 @@ public class CipherEffect extends OneShotEffect {
class CipherStoreEffect extends OneShotEffect {
private UUID cipherCardId;
private final UUID cipherCardId;
public CipherStoreEffect(UUID cipherCardId, String ruleText) {
super(Outcome.Copy);
@ -141,13 +144,13 @@ class CipherStoreEffect extends OneShotEffect {
SpellAbility ability = copyCard.getSpellAbility();
// remove the cipher effect from the copy
Effect cipherEffect = null;
for (Effect effect :ability.getEffects()) {
for (Effect effect : ability.getEffects()) {
if (effect instanceof CipherEffect) {
cipherEffect = effect;
}
}
ability.getEffects().remove(cipherEffect);
if (ability != null && ability instanceof SpellAbility) {
if (ability instanceof SpellAbility) {
controller.cast(ability, game, true);
}
}

View file

@ -1,16 +1,16 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
@ -20,20 +20,19 @@
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.abilities.effects.common;
import java.util.List;
import mage.constants.Outcome;
import mage.abilities.Ability;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.StaticValue;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.filter.FilterPermanent;
import mage.game.Game;
import mage.game.permanent.Permanent;
@ -50,6 +49,7 @@ public class DamageAllEffect extends OneShotEffect {
public DamageAllEffect(int amount, FilterPermanent filter) {
this(new StaticValue(amount), filter);
}
public DamageAllEffect(DynamicValue amount, FilterPermanent filter) {
super(Outcome.Damage);
this.amount = amount;
@ -71,7 +71,7 @@ public class DamageAllEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
List<Permanent> permanents = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game);
for (Permanent permanent: permanents) {
for (Permanent permanent : permanents) {
permanent.damage(amount.calculate(game, source, this), source.getSourceId(), game, false, true);
}
return true;
@ -82,9 +82,13 @@ public class DamageAllEffect extends OneShotEffect {
sb.append("{source} deals ").append(amount.toString()).append(" damage to each ").append(filter.getMessage());
String message = amount.getMessage();
if (message.length() > 0) {
sb.append(" for each ");
if (amount.toString().equals("X")) {
sb.append(", where X is ");
} else {
sb.append(" for each ");
}
sb.append(message);
}
sb.append(message);
staticText = sb.toString();
}

View file

@ -77,7 +77,7 @@ public class DamageTargetControllerEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
Permanent permanent = game.getPermanentOrLKIBattlefield(getTargetPointer().getFirst(game, source));
if(permanent != null) {
Player targetController = game.getPlayer(permanent.getControllerId());
if(targetController != null) {

View file

@ -1,31 +1,30 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.abilities.effects.common;
import mage.abilities.Ability;
@ -49,8 +48,7 @@ public class DestroyAllEffect extends OneShotEffect {
this.noRegen = noRegen;
if (noRegen) {
staticText = "destroy all " + filter.getMessage() + ". They can't be regenerated";
}
else {
} else {
staticText = "destroy all " + filter.getMessage();
}
}
@ -72,6 +70,7 @@ public class DestroyAllEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
permanent.destroy(source.getSourceId(), game, noRegen);
}

View file

@ -46,6 +46,7 @@ import mage.util.CardUtil;
public class DestroyTargetEffect extends OneShotEffect {
protected boolean noRegen;
protected boolean multitargetHandling;
public DestroyTargetEffect() {
this(false);
@ -57,13 +58,19 @@ public class DestroyTargetEffect extends OneShotEffect {
}
public DestroyTargetEffect(boolean noRegen) {
this(noRegen, false);
}
public DestroyTargetEffect(boolean noRegen, boolean multitargetHandling) {
super(Outcome.DestroyPermanent);
this.noRegen = noRegen;
this.multitargetHandling = multitargetHandling;
}
public DestroyTargetEffect(final DestroyTargetEffect effect) {
super(effect);
this.noRegen = effect.noRegen;
this.multitargetHandling = effect.multitargetHandling;
}
@Override
@ -74,7 +81,7 @@ public class DestroyTargetEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
int affectedTargets = 0;
if (source.getTargets().size() > 1 && targetPointer instanceof FirstTargetPointer) { // for Rain of Thorns
if (multitargetHandling && source.getTargets().size() > 1 && targetPointer instanceof FirstTargetPointer) { // Decimate
for (Target target : source.getTargets()) {
for (UUID permanentId : target.getTargets()) {
Permanent permanent = game.getPermanent(permanentId);
@ -84,7 +91,7 @@ public class DestroyTargetEffect extends OneShotEffect {
}
}
}
} else if (targetPointer.getTargets(game, source).size() > 0) {
} else {
for (UUID permanentId : targetPointer.getTargets(game, source)) {
Permanent permanent = game.getPermanent(permanentId);
if (permanent != null) {

View file

@ -0,0 +1,60 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mage.abilities.effects.common;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Cards;
import mage.cards.CardsImpl;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.game.Game;
import mage.players.Player;
import mage.util.CardUtil;
/**
*
* @author LevelX2
*/
public class ExileCardsFromTopOfLibraryTargetEffect extends OneShotEffect {
int amount;
String targetName;
public ExileCardsFromTopOfLibraryTargetEffect(int amount) {
this(amount, null);
}
public ExileCardsFromTopOfLibraryTargetEffect(int amount, String targetName) {
super(Outcome.Exile);
this.amount = amount;
this.staticText = (targetName == null ? "that player" : targetName) + " exiles the top "
+ CardUtil.numberToText(amount, "")
+ (amount == 1 ? "card" : " cards") + " of his or her library";
}
public ExileCardsFromTopOfLibraryTargetEffect(final ExileCardsFromTopOfLibraryTargetEffect effect) {
super(effect);
this.amount = effect.amount;
}
@Override
public ExileCardsFromTopOfLibraryTargetEffect copy() {
return new ExileCardsFromTopOfLibraryTargetEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
if (targetPlayer != null) {
Cards cards = new CardsImpl();
cards.addAll(targetPlayer.getLibrary().getTopCards(game, amount));
return targetPlayer.moveCards(cards, null, Zone.EXILED, source, game);
}
return false;
}
}

View file

@ -28,10 +28,12 @@
package mage.abilities.effects.common;
import mage.abilities.Ability;
import mage.abilities.condition.common.MyMainPhaseCondition;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.game.ExileZone;
import mage.game.Game;
import mage.players.Player;
@ -61,7 +63,7 @@ public class HideawayPlayEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
ExileZone zone = game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, source));
if (zone ==null || zone.isEmpty()) {
if (zone == null || zone.isEmpty()) {
return false;
}
Card card = zone.getCards(game).iterator().next();
@ -69,10 +71,11 @@ public class HideawayPlayEffect extends OneShotEffect {
if (card != null && controller != null) {
if (card.getCardType().contains(CardType.LAND)) {
// If the revealed card is a land, you can play it only if it's your turn and you haven't yet played a land this turn.
if (game.getActivePlayerId().equals(source.getControllerId()) && controller.canPlayLand()) {
if (game.getActivePlayerId().equals(source.getControllerId()) && controller.canPlayLand() && MyMainPhaseCondition.getInstance().apply(game, source)) {
if (controller.chooseUse(Outcome.Benefit, "Play " + card.getLogName() + " from Exile?", source, game)) {
// normal player.playLand(card, game) can't be used because this abilit is on the stack
card.setFaceDown(false, game);
return controller.playLand(card, game);
return controller.moveCards(card, Zone.EXILED, Zone.BATTLEFIELD, source, game);
}
} else if (!game.isSimulation()) {
game.informPlayer(controller, "You're not able to play the land now due to regular restrictions.");
@ -82,7 +85,7 @@ public class HideawayPlayEffect extends OneShotEffect {
// The land's last ability allows you to play the removed card as part of the resolution of that ability.
// Timing restrictions based on the card's type are ignored (for instance, if it's a creature or sorcery).
// Other play restrictions are not (such as "Play [this card] only during combat").
if (controller.chooseUse(Outcome.Benefit, "Cast "+ card.getLogName() + " without paying its mana cost?", source, game)) {
if (controller.chooseUse(Outcome.Benefit, "Cast " + card.getLogName() + " without paying its mana cost?", source, game)) {
card.setFaceDown(false, game);
return controller.cast(card.getSpellAbility(), game, true);
}
@ -96,4 +99,3 @@ public class HideawayPlayEffect extends OneShotEffect {
return false;
}
}

View file

@ -33,19 +33,14 @@ import java.util.UUID;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.continuous.AddCardTypeTargetEffect;
import mage.abilities.effects.common.continuous.GainAbilityTargetEffect;
import mage.abilities.keyword.HasteAbility;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.game.permanent.token.EmptyToken;
import mage.target.targetpointer.FixedTarget;
import mage.util.CardUtil;
import mage.util.functions.ApplyToPermanent;
import mage.util.functions.EmptyApplyToPermanent;
@ -72,6 +67,13 @@ public class PutTokenOntoBattlefieldCopyTargetEffect extends OneShotEffect {
this(playerId, null, false);
}
/**
*
* @param playerId null the token is controlled/owned by the controller of
* the source ability
* @param additionalCardType the token gains tis card types in addition
* @param gainsHaste the token gains haste
*/
public PutTokenOntoBattlefieldCopyTargetEffect(UUID playerId, CardType additionalCardType, boolean gainsHaste) {
super(Outcome.PutCreatureInPlay);
this.playerId = playerId;
@ -113,28 +115,19 @@ public class PutTokenOntoBattlefieldCopyTargetEffect extends OneShotEffect {
EmptyToken token = new EmptyToken();
CardUtil.copyTo(token).from(copyFromPermanent); // needed so that entersBattlefied triggered abilities see the attributes (e.g. Master Biomancer)
applier.apply(game, token);
if (additionalCardType != null && !token.getCardType().contains(additionalCardType)) {
token.getCardType().add(additionalCardType);
}
if (gainsHaste) {
token.addAbility(HasteAbility.getInstance());
}
token.putOntoBattlefield(1, game, source.getSourceId(), playerId == null ? source.getControllerId() : playerId);
for (UUID tokenId : token.getLastAddedTokenIds()) { // by cards like Doubling Season multiple tokens can be added to the battlefield
Permanent tokenPermanent = game.getPermanent(tokenId);
if (tokenPermanent != null) {
addedTokenPermanents.add(tokenPermanent);
game.copyPermanent(copyFromPermanent, tokenPermanent, source, applier);
if (additionalCardType != null) {
ContinuousEffect effect = new AddCardTypeTargetEffect(additionalCardType, Duration.Custom);
effect.setTargetPointer(new FixedTarget(tokenPermanent, game));
game.addEffect(effect, source);
}
if (gainsHaste) {
ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.Custom);
effect.setTargetPointer(new FixedTarget(tokenPermanent, game));
game.addEffect(effect, source);
}
}
}
return true;

View file

@ -96,7 +96,7 @@ public class ReturnFromExileEffect extends OneShotEffect {
case BATTLEFIELD:
card.moveToZone(zone, source.getSourceId(), game, tapped);
if (!game.isSimulation()) {
game.informPlayers(controller.getLogName() + " moves " + card.getName() + " to " + zone.toString().toLowerCase());
game.informPlayers(controller.getLogName() + " moves " + card.getLogName() + " to " + zone.toString().toLowerCase());
}
break;
case HAND:
@ -111,7 +111,7 @@ public class ReturnFromExileEffect extends OneShotEffect {
default:
card.moveToZone(zone, source.getSourceId(), game, tapped);
if (!game.isSimulation()) {
game.informPlayers(controller.getLogName() + " moves " + card.getName() + " to " + zone.toString().toLowerCase());
game.informPlayers(controller.getLogName() + " moves " + card.getLogName() + " to " + zone.toString().toLowerCase());
}
}
}

View file

@ -27,11 +27,11 @@
*/
package mage.abilities.effects.common;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.StaticValue;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.cards.Cards;
import mage.cards.CardsImpl;
import mage.constants.Outcome;
@ -42,9 +42,8 @@ import mage.util.CardUtil;
/**
*
* @author anonymous
* @author Luna Skyrise
*/
public class RevealTargetPlayerLibraryEffect extends OneShotEffect {
private DynamicValue amountCards;
@ -73,28 +72,18 @@ public class RevealTargetPlayerLibraryEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Player targetPlayer = game.getPlayer(source.getFirstTarget());
if (player == null || targetPlayer == null) {
MageObject sourceObject = source.getSourceObject(game);
if (player == null || targetPlayer == null || sourceObject == null) {
return false;
}
Cards cards = new CardsImpl(Zone.LIBRARY);
int count = Math.min(targetPlayer.getLibrary().size(), amountCards.calculate(game, source, this));
for (int i = 0; i < count; i++) {
Card card = targetPlayer.getLibrary().removeFromTop(game);
if (card != null) {
cards.add(card);
}
}
player.lookAtCards("Top " + amountCards.toString() + "cards of " + targetPlayer.getName() + "\'s library", cards, game);
cards.addAll(player.getLibrary().getTopCards(game, amountCards.calculate(game, source, this)));
player.revealCards(sourceObject.getIdName() + " - Top " + amountCards.toString() + "cards of " + targetPlayer.getName() + "\'s library", cards, game);
return true;
}
private String setText() {
StringBuilder sb = new StringBuilder("Reveal the top ");
sb.append(CardUtil.numberToText(amountCards.toString())).append(" cards of target player's library.");
return sb.toString();
return "Reveal the top " + CardUtil.numberToText(amountCards.toString()) + " cards of target player's library.";
}
}

View file

@ -39,7 +39,7 @@ public class SacrificeSourceUnlessPaysEffect extends OneShotEffect {
StringBuilder sb = new StringBuilder(cost.getText()).append("?");
if (!sb.toString().toLowerCase().startsWith("exile ") && !sb.toString().toLowerCase().startsWith("return ") ) {
sb.insert(0, "Pay ");
}
}
String message = CardUtil.replaceSourceName(sb.toString(), sourceObject.getLogName());
message = Character.toUpperCase(message.charAt(0)) + message.substring(1);
if (player.chooseUse(Outcome.Benefit, message, source, game)) {
@ -59,23 +59,26 @@ public class SacrificeSourceUnlessPaysEffect extends OneShotEffect {
return new SacrificeSourceUnlessPaysEffect(this);
}
@Override
@Override
public String getText(Mode mode) {
StringBuilder sb = new StringBuilder("sacrifice {this} unless you ");
String costText = cost.getText();
if (costText.toLowerCase().startsWith("discard")
|| costText.toLowerCase().startsWith("remove")
|| costText.toLowerCase().startsWith("return")
|| costText.toLowerCase().startsWith("exile")
|| costText.toLowerCase().startsWith("sacrifice")) {
sb.append(costText.substring(0, 1).toLowerCase());
sb.append(costText.substring(1));
}
else {
sb.append("pay ").append(costText);
}
if(staticText != null && !staticText.isEmpty()) {
return staticText;
}
return sb.toString();
StringBuilder sb = new StringBuilder("sacrifice {this} unless you ");
String costText = cost.getText();
if (costText.toLowerCase().startsWith("discard")
|| costText.toLowerCase().startsWith("remove")
|| costText.toLowerCase().startsWith("return")
|| costText.toLowerCase().startsWith("exile")
|| costText.toLowerCase().startsWith("sacrifice")) {
sb.append(costText.substring(0, 1).toLowerCase());
sb.append(costText.substring(1));
}
else {
sb.append("pay ").append(costText);
}
return sb.toString();
}
}

View file

@ -45,13 +45,21 @@ import static mage.game.events.GameEvent.EventType.DAMAGE_PLAYER;
public class AssignNoCombatDamageSourceEffect extends ReplacementEffectImpl {
private boolean partOfOptionalEffect;
public AssignNoCombatDamageSourceEffect(Duration duration) {
this(duration, false);
}
public AssignNoCombatDamageSourceEffect(Duration duration, boolean partOfOptionalEffect) {
super(duration, Outcome.PreventDamage);
this.partOfOptionalEffect = partOfOptionalEffect;
staticText = setText();
}
public AssignNoCombatDamageSourceEffect(final AssignNoCombatDamageSourceEffect effect) {
super(effect);
this.partOfOptionalEffect = effect.partOfOptionalEffect;
}
@Override
@ -88,19 +96,23 @@ public class AssignNoCombatDamageSourceEffect extends ReplacementEffectImpl {
}
private String setText() {
StringBuilder sb = new StringBuilder("{this} assigns no combat damage");
String text = "";
if(partOfOptionalEffect) {
text = "If you do, ";
}
text += "{this} assigns no combat damage";
switch(duration) {
case EndOfTurn:
sb.append("this turn");
text += " this turn";
break;
case EndOfCombat:
sb.append("this combat");
text += " this combat";
break;
default:
if (duration.toString().length() > 0) {
sb.append(" ").append(duration.toString());
text += " " + duration.toString();
}
}
return sb.toString();
return text;
}
}

View file

@ -45,7 +45,6 @@ import mage.players.Player;
*
* @author Plopman
*/
//20130711
/*
* 903.11. If a commander would be put into its owners graveyard from anywhere, that player may put it into the command zone instead.
@ -98,18 +97,18 @@ public class CommanderReplacementEffect extends ReplacementEffectImpl {
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
switch(((ZoneChangeEvent)event).getToZone()) {
switch (((ZoneChangeEvent) event).getToZone()) {
case HAND:
if (!alsoHand && ((ZoneChangeEvent)event).getToZone() == Zone.HAND) {
if (!alsoHand && ((ZoneChangeEvent) event).getToZone() == Zone.HAND) {
return false;
}
case LIBRARY:
if (!alsoLibrary && ((ZoneChangeEvent)event).getToZone() == Zone.LIBRARY) {
if (!alsoLibrary && ((ZoneChangeEvent) event).getToZone() == Zone.LIBRARY) {
return false;
}
case GRAVEYARD:
case EXILED:
if(commanderId.equals(event.getTargetId())){
case EXILED:
if (commanderId.equals(event.getTargetId())) {
return true;
}
break;
@ -125,23 +124,24 @@ public class CommanderReplacementEffect extends ReplacementEffectImpl {
}
return false;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
if (((ZoneChangeEvent)event).getFromZone() == Zone.BATTLEFIELD) {
Permanent permanent = ((ZoneChangeEvent)event).getTarget();
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
if (((ZoneChangeEvent) event).getFromZone() == Zone.BATTLEFIELD) {
Permanent permanent = ((ZoneChangeEvent) event).getTarget();
if (permanent != null) {
Player player = game.getPlayer(permanent.getOwnerId());
if (player != null && player.chooseUse(Outcome.Benefit, "Move commander to command zone?", source, game)){
if (player != null && player.chooseUse(Outcome.Benefit, "Move commander to command zone?", source, game)) {
boolean result = permanent.moveToZone(Zone.COMMAND, source.getSourceId(), game, false);
if (!game.isSimulation())
if (!game.isSimulation()) {
game.informPlayers(player.getLogName() + " has moved his or her commander to the command zone");
}
return result;
}
}
} else {
Card card = null;
if (((ZoneChangeEvent)event).getFromZone().equals(Zone.STACK)) {
if (((ZoneChangeEvent) event).getFromZone().equals(Zone.STACK)) {
Spell spell = game.getStack().getSpell(event.getTargetId());
if (spell != null) {
card = game.getCard(spell.getSourceId());
@ -149,13 +149,14 @@ public class CommanderReplacementEffect extends ReplacementEffectImpl {
}
if (card == null) {
card = game.getCard(event.getTargetId());
}
}
if (card != null) {
Player player = game.getPlayer(card.getOwnerId());
if (player != null && player.chooseUse(Outcome.Benefit, "Move commander to command zone?", source, game)){
if (player != null && player.chooseUse(Outcome.Benefit, "Move commander to command zone?", source, game)) {
boolean result = card.moveToZone(Zone.COMMAND, source.getSourceId(), game, false);
if (!game.isSimulation())
if (!game.isSimulation()) {
game.informPlayers(player.getLogName() + " has moved his or her commander to the command zone");
}
return result;
}
}

View file

@ -0,0 +1,57 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mage.abilities.effects.common.continuous;
import mage.abilities.Ability;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.constants.Duration;
import mage.constants.Layer;
import mage.constants.Outcome;
import mage.constants.SubLayer;
import mage.filter.FilterPermanent;
import mage.game.Game;
import mage.game.permanent.Permanent;
/**
*
* @author LevelX2
*/
public class LoseAbilityAllEffect extends ContinuousEffectImpl {
protected final FilterPermanent filter;
protected final Ability ability;
public LoseAbilityAllEffect(FilterPermanent filter, Ability ability, Duration duration) {
super(duration, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.AddAbility);
this.filter = filter;
this.ability = ability;
staticText = filter.getMessage() + " lose " + ability.toString() + (duration.toString().isEmpty() ? "" : " " + duration.toString());
}
public LoseAbilityAllEffect(final LoseAbilityAllEffect effect) {
super(effect);
this.filter = effect.filter.copy();
this.ability = effect.ability;
}
@Override
public LoseAbilityAllEffect copy() {
return new LoseAbilityAllEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
if (permanent != null) {
while (permanent.getAbilities().contains(ability)) {
permanent.getAbilities().remove(ability);
}
}
}
return true;
}
}

View file

@ -1,52 +1,50 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.abilities.effects.common.continuous;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.constants.Duration;
import mage.constants.Layer;
import mage.constants.Outcome;
import mage.constants.SubLayer;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.filter.FilterPermanent;
import mage.game.Game;
import mage.game.permanent.Permanent;
/**
*
* @author LevelX2
*/
public class LoseAllAbilitiesAllEffect extends ContinuousEffectImpl {
private FilterPermanent filter;
private final FilterPermanent filter;
public LoseAllAbilitiesAllEffect(FilterPermanent filter, Duration duration) {
super(duration, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.AddAbility);
@ -65,7 +63,7 @@ public class LoseAllAbilitiesAllEffect extends ContinuousEffectImpl {
@Override
public boolean apply(Game game, Ability source) {
for (Permanent permanent: game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
if (permanent != null) {
permanent.removeAllAbilities(source.getSourceId(), game);
}

View file

@ -74,6 +74,9 @@ public class AddPoisonCounterTargetEffect extends OneShotEffect {
@Override
public String getText(Mode mode) {
if(staticText != null && !staticText.isEmpty()) {
return staticText;
}
return "Target " + mode.getTargets().get(0).getTargetName() + " gets " + Integer.toString(amount) + " poison counter(s).";
}
}
}

View file

@ -1,16 +1,16 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
@ -20,26 +20,19 @@
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.abilities.effects.keyword;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.cards.Cards;
import mage.cards.CardsImpl;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.filter.FilterCard;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.players.Player;
import mage.target.TargetCard;
import mage.util.CardUtil;
/**
@ -67,33 +60,7 @@ public class ScryEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
boolean revealed = player.isTopCardRevealed(); // by looking at the cards with scry you have not to reveal the next card
player.setTopCardRevealed(false);
Cards cards = new CardsImpl();
int count = Math.min(scryNumber, player.getLibrary().size());
if (count == 0) {
return true;
}
for (int i = 0; i < count; i++) {
Card card = player.getLibrary().removeFromTop(game);
cards.add(card);
}
TargetCard target1 = new TargetCard(Zone.LIBRARY, filter1);
target1.setRequired(false);
// move cards to the bottom of the library
while (player.canRespond() && cards.size() > 0 && player.choose(Outcome.Detriment, cards, target1, game)) {
Card card = cards.get(target1.getFirstTarget(), game);
if (card != null) {
cards.remove(card);
player.moveCardToLibraryWithInfo(card, source.getSourceId(), game, Zone.LIBRARY, false, false);
}
target1.clearChosen();
}
// move cards to the top of the library
player.putCardsOnTopOfLibrary(cards, game, source, true);
game.fireEvent(new GameEvent(GameEvent.EventType.SCRY, source.getControllerId(), source.getSourceId(), source.getControllerId()));
player.setTopCardRevealed(revealed);
return true;
return player.scry(scryNumber, source, game);
}
return false;
}

View file

@ -0,0 +1,155 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.abilities.keyword;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.SpellAbility;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.continuous.BecomesCreatureTargetEffect;
import mage.abilities.effects.common.counter.AddCountersTargetEffect;
import mage.cards.Card;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.SpellAbilityType;
import mage.constants.Zone;
import mage.counters.CounterType;
import mage.filter.common.FilterControlledLandPermanent;
import mage.game.Game;
import mage.game.permanent.token.Token;
import mage.target.Target;
import mage.target.common.TargetControlledPermanent;
import mage.target.targetpointer.FixedTarget;
import mage.util.CardUtil;
/**
*
* @author LevelX2
*/
public class AwakenAbility extends SpellAbility {
static private String filterMessage = "a land you control to awake";
private String rule;
private int awakenValue;
public AwakenAbility(Card card, int awakenValue, String awakenCosts) {
super(new ManaCostsImpl<>(awakenCosts), card.getName() + " with awaken", Zone.HAND, SpellAbilityType.BASE_ALTERNATE);
this.getCosts().addAll(card.getSpellAbility().getCosts().copy());
this.getEffects().addAll(card.getSpellAbility().getEffects().copy());
this.getTargets().addAll(card.getSpellAbility().getTargets().copy());
this.getChoices().addAll(card.getSpellAbility().getChoices().copy());
this.spellAbilityType = SpellAbilityType.BASE_ALTERNATE;
this.timing = card.getSpellAbility().getTiming();
this.addTarget(new TargetControlledPermanent(new FilterControlledLandPermanent(filterMessage)));
this.addEffect(new AwakenEffect());
this.awakenValue = awakenValue;
rule = "Awaken " + awakenValue + "&mdash;" + awakenCosts
+ " <i>(If you cast this spell for " + awakenCosts + ", also put "
+ CardUtil.numberToText(awakenValue, "a")
+ " +1/+1 counters on target land you control and it becomes a 0/0 Elemental creature with haste. It's still a land.)</i>";
}
public AwakenAbility(final AwakenAbility ability) {
super(ability);
this.awakenValue = ability.awakenValue;
}
@Override
public AwakenAbility copy() {
return new AwakenAbility(this);
}
@Override
public String getRule(boolean all) {
return getRule();
}
@Override
public String getRule() {
return rule;
}
class AwakenEffect extends OneShotEffect {
private AwakenEffect() {
super(Outcome.BoostCreature);
this.staticText = "put " + CardUtil.numberToText(awakenValue, "a") + " +1/+1 counters on target land you control";
}
public AwakenEffect(final AwakenEffect effect) {
super(effect);
}
@Override
public AwakenEffect copy() {
return new AwakenEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
UUID targetId = null;
for (Target target : source.getTargets()) {
if (target.getFilter().getMessage().equals(filterMessage)) {
targetId = target.getFirstTarget();
}
}
if (targetId != null) {
FixedTarget fixedTarget = new FixedTarget(targetId);
ContinuousEffect continuousEffect = new BecomesCreatureTargetEffect(new AwakenElementalToken(), false, true, Duration.Custom);
continuousEffect.setTargetPointer(fixedTarget);
game.addEffect(continuousEffect, source);
Effect effect = new AddCountersTargetEffect(CounterType.P1P1.createInstance(awakenValue));
effect.setTargetPointer(fixedTarget);
return effect.apply(game, source);
}
return true;
}
}
}
class AwakenElementalToken extends Token {
public AwakenElementalToken() {
super("", "0/0 Elemental creature with haste");
this.cardType.add(CardType.CREATURE);
this.subtype.add("Elemental");
this.power = new MageInt(0);
this.toughness = new MageInt(0);
this.addAbility(HasteAbility.getInstance());
}
}

View file

@ -0,0 +1,41 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mage.abilities.keyword;
import mage.ObjectColor;
import mage.abilities.common.SimpleStaticAbility;
import mage.constants.Zone;
/**
*
* @author LevelX2
*/
public class DevoidAbility extends SimpleStaticAbility {
public DevoidAbility(ObjectColor color) {
super(Zone.ALL, null);
color.setBlack(false);
color.setWhite(false);
color.setGreen(false);
color.setBlue(false);
color.setRed(false);
}
public DevoidAbility(final DevoidAbility ability) {
super(ability);
}
@Override
public DevoidAbility copy() {
return new DevoidAbility(this);
}
@Override
public String getRule() {
return "Devoid <i>(This card has no color.)<i/>";
}
}

View file

@ -0,0 +1,71 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mage.abilities.keyword;
import mage.abilities.Ability;
import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.game.Game;
import mage.players.Player;
/**
*
* @author LevelX2
*/
public class IngestAbility extends DealsCombatDamageToAPlayerTriggeredAbility {
public IngestAbility() {
super(new IngestEffect(), false, true);
}
public IngestAbility(IngestAbility ability) {
super(ability);
}
@Override
public String getRule() {
return "Ingest (Whenever this creature deals combat damage to a player, that player exiles the top card of his or her library.)";
}
@Override
public IngestAbility copy() {
return new IngestAbility(this);
}
}
class IngestEffect extends OneShotEffect {
public IngestEffect() {
super(Outcome.Exile);
this.staticText = "that player exiles the top card of his or her library";
}
public IngestEffect(final IngestEffect effect) {
super(effect);
}
@Override
public IngestEffect copy() {
return new IngestEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
if (targetPlayer != null) {
Card card = targetPlayer.getLibrary().getFromTop(game);
if (card != null) {
targetPlayer.moveCards(card, Zone.LIBRARY, Zone.EXILED, source, game);
}
return true;
}
return false;
}
}

View file

@ -31,6 +31,7 @@ import java.util.UUID;
import mage.MageObject;
import mage.abilities.StaticAbility;
import mage.cards.Card;
import mage.constants.CardType;
import mage.constants.Zone;
import mage.filter.Filter;
import mage.filter.FilterCard;
@ -40,6 +41,7 @@ import mage.filter.FilterSpell;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.game.stack.Spell;
import mage.game.stack.StackObject;
/**
*
@ -83,18 +85,25 @@ public class ProtectionAbility extends StaticAbility {
}
return true;
}
if (filter instanceof FilterSpell) {
if (source instanceof Spell) {
return !filter.match(source, game);
}
return true;
}
if (filter instanceof FilterCard) {
if (source instanceof Card) {
return !filter.match(source, game);
}
return true;
}
if (filter instanceof FilterSpell) {
if (source instanceof Spell) {
return !filter.match(source, game);
}
// Problem here is that for the check if a player can play a Spell, the source
// object is still a card and not a spell yet. So retunr only if the source object can't be a spell
// otherwise the following FilterObject check will be appied
if (source instanceof StackObject
|| (!source.getCardType().contains(CardType.INSTANT) && !source.getCardType().contains(CardType.SORCERY))) {
return true;
}
}
if (filter instanceof FilterObject) {
return !filter.match(source, game);
}

View file

@ -0,0 +1,106 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.abilities.keyword;
import mage.abilities.Ability;
import mage.abilities.common.BecomesBlockedTriggeredAbility;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.continuous.BoostSourceEffect;
import mage.constants.Duration;
import mage.game.Game;
import mage.game.combat.CombatGroup;
import mage.game.events.GameEvent;
/**
*
* @author LoneFox
*/
public class RampageAbility extends BecomesBlockedTriggeredAbility {
private final String rule;
public RampageAbility(int amount) {
super(null, false);
rule = "rampage " + amount;
RampageValue rv = new RampageValue(amount);
this.addEffect(new BoostSourceEffect(rv, rv, Duration.EndOfTurn));
}
public RampageAbility(final RampageAbility ability) {
super(ability);
this.rule = ability.rule;
}
@Override
public RampageAbility copy() {
return new RampageAbility(this);
}
@Override
public String getRule() {
return rule;
}
}
class RampageValue implements DynamicValue {
private final int amount;
public RampageValue(int amount) {
this.amount = amount;
}
public RampageValue(final RampageValue value) {
this.amount = value.amount;
}
@Override
public RampageValue copy() {
return new RampageValue(this);
}
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
int count = 0;
for(CombatGroup combatGroup : game.getCombat().getGroups()) {
if(combatGroup.getAttackers().contains(sourceAbility.getSourceId())) {
int blockers = combatGroup.getBlockers().size();
return blockers > 1 ? (blockers - 1) * amount : 0;
}
}
return 0;
}
@Override
public String getMessage() {
return "Rampage " + amount;
}
}

View file

@ -39,7 +39,6 @@ import mage.target.common.TargetCardInHand;
*
* @author LevelX2
*/
public class RetraceAbility extends SpellAbility {
public RetraceAbility(Card card) {
@ -51,7 +50,7 @@ public class RetraceAbility extends SpellAbility {
this.getChoices().addAll(card.getSpellAbility().getChoices().copy());
this.spellAbilityType = SpellAbilityType.BASE_ALTERNATE;
this.timing = card.getSpellAbility().getTiming();
}
public RetraceAbility(final RetraceAbility ability) {

View file

@ -40,6 +40,7 @@ import mage.abilities.costs.mana.ManaCost;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.costs.mana.VariableManaCost;
import mage.abilities.decorator.ConditionalTriggeredAbility;
import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.counter.RemoveCounterSourceEffect;
@ -57,6 +58,7 @@ import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.targetpointer.FixedTarget;
/**
*
@ -183,7 +185,7 @@ public class SuspendAbility extends ActivatedAbilityImpl {
setRuleAtTheTop(true);
}
addSubAbility(new SuspendBeginningOfUpkeepTriggeredAbility());
addSubAbility(new SuspendPlayCardAbility(card.getCardType().contains(CardType.CREATURE)));
addSubAbility(new SuspendPlayCardAbility());
}
ruleText = sb.toString();
}
@ -208,7 +210,7 @@ public class SuspendAbility extends ActivatedAbilityImpl {
game.getState().addOtherAbility(card, ability1);
game.getState().addAbility(ability1, source.getSourceId(), card);
SuspendPlayCardAbility ability2 = new SuspendPlayCardAbility(card.getCardType().contains(CardType.CREATURE));
SuspendPlayCardAbility ability2 = new SuspendPlayCardAbility();
ability2.setSourceId(card.getId());
ability2.setControllerId(card.getOwnerId());
game.getState().addOtherAbility(card, ability2);
@ -298,11 +300,8 @@ class SuspendExileEffect extends OneShotEffect {
class SuspendPlayCardAbility extends TriggeredAbilityImpl {
public SuspendPlayCardAbility(boolean isCreature) {
super(Zone.EXILED, new SuspendPlayCardEffect(isCreature));
if (isCreature) {
this.addEffect(new GainHasteEffect());
}
public SuspendPlayCardAbility() {
super(Zone.EXILED, new SuspendPlayCardEffect());
setRuleVisible(false);
}
@ -340,7 +339,7 @@ class SuspendPlayCardAbility extends TriggeredAbilityImpl {
class SuspendPlayCardEffect extends OneShotEffect {
public SuspendPlayCardEffect(boolean isCreature) {
public SuspendPlayCardEffect() {
super(Outcome.PutCardInPlay);
this.staticText = "play it without paying its mana cost if able. If you can't, it remains removed from the game";
}
@ -378,7 +377,14 @@ class SuspendPlayCardEffect extends OneShotEffect {
card.getAbilities().removeAll(abilitiesToRemove);
}
// cast the card for free
return player.cast(card.getSpellAbility(), game, true);
if (player.cast(card.getSpellAbility(), game, true)) {
if (card.getCardType().contains(CardType.CREATURE)) {
ContinuousEffect effect = new GainHasteEffect();
effect.setTargetPointer(new FixedTarget(card.getId(), card.getZoneChangeCounter(game) + 1));
game.addEffect(effect, source);
}
return true;
}
}
return false;
}
@ -408,14 +414,17 @@ class GainHasteEffect extends ContinuousEffectImpl {
if (suspendController == null) {
suspendController = source.getControllerId();
}
Permanent permanent = game.getPermanent(source.getSourceId());
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
if (permanent != null) {
if (suspendController.equals(source.getControllerId())) {
permanent.addAbility(HasteAbility.getInstance(), source.getSourceId(), game);
return true;
} else {
this.discard();
}
return true;
}
if (game.getState().getZoneChangeCounter(((FixedTarget) getTargetPointer()).getTarget()) >= ((FixedTarget) getTargetPointer()).getZoneChangeCounter()) {
this.discard();
}
return false;
}

View file

@ -296,11 +296,9 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
public SpellAbility getSpellAbility() {
if (spellAbility == null) {
for (Ability ability : abilities.getActivatedAbilities(Zone.HAND)) {
// name check prevents that alternate casting methods (like "cast [card name] using bestow") are returned here
// BUG #1024: Bestow bug
//if (ability instanceof SpellAbility && ability.toString().endsWith(getName())) {
if (ability instanceof SpellAbility) {
spellAbility = (SpellAbility) ability;
if (ability instanceof SpellAbility
&& !((SpellAbility) ability).getSpellAbilityType().equals(SpellAbilityType.BASE_ALTERNATE)) {
return spellAbility = (SpellAbility) ability;
}
}
}
@ -365,13 +363,16 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
game.getState().getCommand().remove((Commander) game.getObject(objectId));
break;
case STACK:
StackObject stackObject = game.getStack().getSpell(getId());
if (stackObject == null && (this instanceof SplitCard)) { // handle if half od Split cast is on the stack
StackObject stackObject = game.getStack().getSpell(getSpellAbility().getId());
if (stackObject == null && (this instanceof SplitCard)) { // handle if half of Split cast is on the stack
stackObject = game.getStack().getSpell(((SplitCard) this).getLeftHalfCard().getId());
if (stackObject == null) {
stackObject = game.getStack().getSpell(((SplitCard) this).getRightHalfCard().getId());
}
}
if (stackObject == null) {
stackObject = game.getStack().getSpell(getId());
}
if (stackObject != null) {
game.getStack().remove(stackObject);
}
@ -602,10 +603,10 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
PermanentCard permanent = new PermanentCard(this, event.getPlayerId(), game);
// make sure the controller of all continuous effects of this card are switched to the current controller
game.getContinuousEffects().setController(objectId, event.getPlayerId());
// check if there are counters to add to the permanent (e.g. from non replacement effects like Persist)
checkForCountersToAdd(permanent, game);
game.addPermanent(permanent);
setZone(Zone.BATTLEFIELD, game);
// check if there are counters to add to the permanent (e.g. from non replacement effects like Persist)
checkForCountersToAdd(permanent, game);
game.setScopeRelevant(true);
permanent.setTapped(tapped);
permanent.setFaceDown(facedown, game);

View file

@ -169,10 +169,13 @@ public class CardsImpl extends LinkedHashSet<UUID> implements Cards, Serializabl
@Override
public Set<Card> getCards(FilterCard filter, UUID sourceId, UUID playerId, Game game) {
Set<Card> cards = new LinkedHashSet<>();
for (UUID card : this) {
boolean match = filter.match(game.getCard(card), sourceId, playerId, game);
if (match) {
cards.add(game.getCard(card));
for (UUID cardId : this) {
Card card = game.getCard(cardId);
if (card != null) {
boolean match = filter.match(card, sourceId, playerId, game);
if (match) {
cards.add(game.getCard(cardId));
}
}
}
return cards;

View file

@ -60,16 +60,32 @@ public abstract class SplitCard extends CardImpl {
public SplitCard(SplitCard card) {
super(card);
this.leftHalfCard = card.leftHalfCard.copy();
this.leftHalfCard = card.getLeftHalfCard().copy();
((SplitCardHalf) leftHalfCard).setParentCard(this);
this.rightHalfCard = card.rightHalfCard.copy();
((SplitCardHalf) rightHalfCard).setParentCard(this);
}
public Card getLeftHalfCard() {
return leftHalfCard;
public SplitCardHalf getLeftHalfCard() {
return (SplitCardHalf) leftHalfCard;
}
public Card getRightHalfCard() {
return rightHalfCard;
public SplitCardHalf getRightHalfCard() {
return (SplitCardHalf) rightHalfCard;
}
@Override
public void assignNewId() {
super.assignNewId();
leftHalfCard.assignNewId();
rightHalfCard.assignNewId();
}
@Override
public void setCopy(boolean isCopy) {
super.setCopy(isCopy);
leftHalfCard.setCopy(isCopy);
rightHalfCard.setCopy(isCopy);
}
@Override

View file

@ -12,5 +12,7 @@ package mage.cards;
public interface SplitCardHalf extends Card {
@Override
Card copy();
SplitCardHalf copy();
void setParentCard(SplitCard card);
}

View file

@ -62,7 +62,7 @@ public class SplitCardHalfImpl extends CardImpl implements SplitCardHalf {
}
@Override
public Card getMainCard() {
public SplitCard getMainCard() {
return splitCardParent;
}
@ -74,8 +74,13 @@ public class SplitCardHalfImpl extends CardImpl implements SplitCardHalf {
}
@Override
public SplitCardHalfImpl copy() {
public SplitCardHalf copy() {
return new SplitCardHalfImpl(this);
}
@Override
public void setParentCard(SplitCard card) {
this.splitCardParent = card;
}
}

View file

@ -50,13 +50,13 @@ public class MockSplitCard extends SplitCard {
}
CardInfo leftHalf = CardRepository.instance.findCard(getLeftHalfName(card));
if(leftHalf != null) {
this.leftHalfCard = new MockCard(leftHalf);
if (leftHalf != null) {
this.leftHalfCard = new MockSplitCardHalf(leftHalf);
}
CardInfo rightHalf = CardRepository.instance.findCard(getRightHalfName(card));
if(rightHalf != null) {
this.rightHalfCard = new MockCard(rightHalf);
if (rightHalf != null) {
this.rightHalfCard = new MockSplitCardHalf(rightHalf);
}
}

View file

@ -0,0 +1,58 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.cards.mock;
import mage.cards.SplitCard;
import mage.cards.SplitCardHalf;
import mage.cards.repository.CardInfo;
/**
*
* @author LevelX2
*/
public class MockSplitCardHalf extends MockCard implements SplitCardHalf {
public MockSplitCardHalf(CardInfo card) {
super(card);
}
public MockSplitCardHalf(final MockSplitCardHalf card) {
super(card);
}
@Override
public MockSplitCardHalf copy() {
return new MockSplitCardHalf(this);
}
@Override
public void setParentCard(SplitCard card) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}

View file

@ -63,7 +63,7 @@ public enum CardRepository {
// raise this if db structure was changed
private static final long CARD_DB_VERSION = 41;
// raise this if new cards were added to the server
private static final long CARD_CONTENT_VERSION = 34;
private static final long CARD_CONTENT_VERSION = 35;
private final Random random = new Random();
private Dao<CardInfo, Object> cardDao;

View file

@ -33,7 +33,9 @@ package mage.constants;
*/
public enum AbilityWord {
RALLY("Rally"),
BLOODRUSH("Bloodrush"),
CONVERGE("Converge"),
CONSTELLATION("Constellation"),
FEROCIOUS("Ferocious"),
FORMIDABLE("Formidable"),

View file

@ -60,5 +60,11 @@ public enum PlayerAction {
ADD_PERMISSION_TO_ROLLBACK_TURN,
DENY_PERMISSON_TO_ROLLBACK_TURN,
PERMISSION_REQUESTS_ALLOWED_ON,
PERMISSION_REQUESTS_ALLOWED_OFF
PERMISSION_REQUESTS_ALLOWED_OFF,
REQUEST_AUTO_ANSWER_ID_YES,
REQUEST_AUTO_ANSWER_ID_NO,
REQUEST_AUTO_ANSWER_TEXT_YES,
REQUEST_AUTO_ANSWER_TEXT_NO,
REQUEST_AUTO_ANSWER_RESET_ALL,
}

View file

@ -93,6 +93,7 @@ public enum CounterType {
VELOCITY("velocity"),
VERSE("verse"),
VILE("vile"),
VITALITY("vitality"),
WISH("wish");
private final String name;

View file

@ -64,30 +64,29 @@ public class FilterCard extends FilterObject<Card> {
}
//20130711 708.6c
/* If anything performs a comparison involving multiple characteristics or
* values of one or more split cards in any zone other than the stack or
* involving multiple characteristics or values of one or more fused split
* spells, each characteristic or value is compared separately. If each of
* the individual comparisons would return a yes answer, the whole
/* If anything performs a comparison involving multiple characteristics or
* values of one or more split cards in any zone other than the stack or
* involving multiple characteristics or values of one or more fused split
* spells, each characteristic or value is compared separately. If each of
* the individual comparisons would return a yes answer, the whole
* comparison returns a yes answer. The individual comparisons may involve
* different halves of the same split card.
*/
@Override
public boolean match(Card card, Game game) {
if(card.isSplitCard()){
return super.match(((SplitCard)card).getLeftHalfCard(), game) ||
super.match(((SplitCard)card).getRightHalfCard(), game);
}
else{
return super.match(card, game);
if (card.isSplitCard()) {
return super.match(((SplitCard) card).getLeftHalfCard(), game)
|| super.match(((SplitCard) card).getRightHalfCard(), game);
} else {
return super.match(card, game);
}
}
public boolean match(Card card, UUID playerId, Game game) {
if (!this.match(card, game)) {
return false;
}
return Predicates.and(extraPredicates).apply(new ObjectPlayer(card, playerId), game);
}
@ -111,7 +110,7 @@ public class FilterCard extends FilterObject<Card> {
}
return filtered;
}
public boolean hasPredicates() {
return predicates.size() > 0;
}

View file

@ -0,0 +1,27 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mage.filter.predicate.permanent;
import mage.filter.predicate.Predicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
/**
*
* @author LevelX2
*/
public class SummoningSicknessPredicate implements Predicate<Permanent> {
@Override
public boolean apply(Permanent input, Game game) {
return input.hasSummoningSickness();
}
@Override
public String toString() {
return "Summoning sickness";
}
}

View file

@ -100,7 +100,7 @@ public class Exile implements Serializable, Copyable<Exile> {
}
public List<Card> getAllCards(Game game) {
List<Card> cards = new ArrayList<Card>();
List<Card> cards = new ArrayList<>();
for (ExileZone exile : exileZones.values()) {
cards.addAll(exile.getCards(game));
}

View file

@ -73,6 +73,7 @@ import mage.game.turn.Turn;
import mage.players.Player;
import mage.players.PlayerList;
import mage.players.Players;
import mage.util.MessageToClient;
import mage.util.functions.ApplyToPermanent;
public interface Game extends MageItem, Serializable {
@ -221,13 +222,13 @@ public interface Game extends MageItem, Serializable {
void addPlayerQueryEventListener(Listener<PlayerQueryEvent> listener);
void fireAskPlayerEvent(UUID playerId, String message);
void fireAskPlayerEvent(UUID playerId, MessageToClient message, Ability source);
void fireChooseChoiceEvent(UUID playerId, Choice choice);
void fireSelectTargetEvent(UUID playerId, String message, Set<UUID> targets, boolean required, Map<String, Serializable> options);
void fireSelectTargetEvent(UUID playerId, MessageToClient message, Set<UUID> targets, boolean required, Map<String, Serializable> options);
void fireSelectTargetEvent(UUID playerId, String message, Cards cards, boolean required, Map<String, Serializable> options);
void fireSelectTargetEvent(UUID playerId, MessageToClient message, Cards cards, boolean required, Map<String, Serializable> options);
void fireSelectTargetTriggeredAbilityEvent(UUID playerId, String message, List<TriggeredAbility> abilities);

View file

@ -67,6 +67,7 @@ import mage.cards.Card;
import mage.cards.Cards;
import mage.cards.CardsImpl;
import mage.cards.SplitCard;
import mage.cards.SplitCardHalf;
import mage.cards.decks.Deck;
import mage.choices.Choice;
import mage.constants.CardType;
@ -118,6 +119,7 @@ import mage.target.Target;
import mage.target.TargetPermanent;
import mage.target.TargetPlayer;
import mage.util.GameLog;
import mage.util.MessageToClient;
import mage.util.functions.ApplyToPermanent;
import mage.watchers.Watchers;
import mage.watchers.common.BlockedAttackerWatcher;
@ -873,13 +875,14 @@ public abstract class GameImpl implements Game, Serializable {
}
//20091005 - 103.3
int startingHandSize = 7;
for (UUID playerId : state.getPlayerList(startingPlayerId)) {
Player player = getPlayer(playerId);
if (!gameOptions.testMode || player.getLife() == 0) {
player.initLife(this.getLife());
}
if (!gameOptions.testMode) {
player.drawCards(7, this);
player.drawCards(startingHandSize, this);
}
}
@ -921,6 +924,15 @@ public abstract class GameImpl implements Game, Serializable {
}
saveState(false);
} while (!mulliganPlayers.isEmpty());
// new scry rule
for (UUID playerId : state.getPlayerList(startingPlayerId)) {
Player player = getPlayer(playerId);
if (player != null && player.getHand().size() < startingHandSize) {
if (player.chooseUse(Outcome.Benefit, new MessageToClient("Scry 1?", "Look at the top card of your library. You may put that card on the bottom of your library."), null, this)) {
player.scry(1, null, this);
}
}
}
getState().setChoosingPlayerId(null);
Watchers watchers = state.getWatchers();
// add default watchers
@ -1083,15 +1095,6 @@ public abstract class GameImpl implements Game, Serializable {
player.drawCards(numCards - deduction, this);
}
// @Override
// public void quit(UUID playerId) {
// if (state != null) {
// Player player = state.getPlayer(playerId);
// if (player != null && player.isInGame()) {
// player.quit(this);
// }
// }
// }
@Override
public synchronized void timerTimeout(UUID playerId) {
Player player = state.getPlayer(playerId);
@ -1461,6 +1464,7 @@ public abstract class GameImpl implements Game, Serializable {
*/
public boolean checkTriggered() {
boolean played = false;
state.getTriggers().checkStateTriggers(this);
for (UUID playerId : state.getPlayerList(state.getActivePlayerId())) {
Player player = getPlayer(playerId);
while (player.isInGame()) { // player can die or win caused by triggered abilities or leave the game
@ -1524,6 +1528,9 @@ public abstract class GameImpl implements Game, Serializable {
Iterator<Card> copiedCards = this.getState().getCopiedCards().iterator();
while (copiedCards.hasNext()) {
Card card = copiedCards.next();
if (card instanceof SplitCardHalf) {
continue; // only the main card is moves, not the halves
}
Zone zone = state.getZone(card.getId());
if (zone != Zone.BATTLEFIELD && zone != Zone.STACK) {
switch (zone) {
@ -1886,11 +1893,11 @@ public abstract class GameImpl implements Game, Serializable {
}
@Override
public void fireAskPlayerEvent(UUID playerId, String message) {
public void fireAskPlayerEvent(UUID playerId, MessageToClient message, Ability source) {
if (simulation) {
return;
}
playerQueryEventSource.ask(playerId, message);
playerQueryEventSource.ask(playerId, message.getMessage(), source, addMessageToOptions(message, null));
}
@Override
@ -1914,19 +1921,19 @@ public abstract class GameImpl implements Game, Serializable {
}
@Override
public void fireSelectTargetEvent(UUID playerId, String message, Set<UUID> targets, boolean required, Map<String, Serializable> options) {
public void fireSelectTargetEvent(UUID playerId, MessageToClient message, Set<UUID> targets, boolean required, Map<String, Serializable> options) {
if (simulation) {
return;
}
playerQueryEventSource.target(playerId, message, targets, required, options);
playerQueryEventSource.target(playerId, message.getMessage(), targets, required, addMessageToOptions(message, options));
}
@Override
public void fireSelectTargetEvent(UUID playerId, String message, Cards cards, boolean required, Map<String, Serializable> options) {
public void fireSelectTargetEvent(UUID playerId, MessageToClient message, Cards cards, boolean required, Map<String, Serializable> options) {
if (simulation) {
return;
}
playerQueryEventSource.target(playerId, message, cards, required, options);
playerQueryEventSource.target(playerId, message.getMessage(), cards, required, addMessageToOptions(message, options));
}
/**
@ -2692,4 +2699,19 @@ public abstract class GameImpl implements Game, Serializable {
return enterWithCounters.get(sourceId);
}
private Map<String, Serializable> addMessageToOptions(MessageToClient message, Map<String, Serializable> options) {
if (message.getSecondMessage() != null) {
if (options == null) {
options = new HashMap<>();
}
options.put("secondMessage", message.getSecondMessage());
}
if (message.getHintText() != null) {
if (options == null) {
options = new HashMap<>();
}
options.put("hintText", message.getHintText());
}
return options;
}
}

View file

@ -742,9 +742,11 @@ public class GameState implements Serializable, Copyable<GameState> {
// TODO: add sources for triggers - the same way as in addEffect: sources
this.triggers.add((TriggeredAbility) ability, sourceId, attachedTo);
}
for (Watcher watcher : ability.getWatchers()) {
watcher.setControllerId(attachedTo.getOwnerId());
watcher.setSourceId(attachedTo.getId());
List<Watcher> watcherList = new ArrayList<>(ability.getWatchers()); // Workaround to prevent ConcurrentModificationException, not clear to me why this is happening now
for (Watcher watcher : watcherList) {
// TODO: Check that watcher for commanderAbility (where attachedTo = null) also work correctly
watcher.setControllerId(attachedTo == null ? ability.getControllerId() : attachedTo.getOwnerId());
watcher.setSourceId(attachedTo == null ? ability.getSourceId() : attachedTo.getId());
watchers.add(watcher);
}
for (Ability sub : ability.getSubAbilities()) {

View file

@ -149,8 +149,14 @@ public class PlayerQueryEvent extends EventObject implements ExternalEvent, Seri
this.playerId = playerId;
}
public static PlayerQueryEvent askEvent(UUID playerId, String message) {
return new PlayerQueryEvent(playerId, message, null, null, null, null, QueryType.ASK, 0, 0, false, null);
public static PlayerQueryEvent askEvent(UUID playerId, String message, Ability source, Map<String, Serializable> options) {
if (source != null) {
if (options == null) {
options = new HashMap<>();
}
options.put("originalId", source.getOriginalId());
}
return new PlayerQueryEvent(playerId, message, null, null, null, null, QueryType.ASK, 0, 0, false, options);
}
public static PlayerQueryEvent chooseAbilityEvent(UUID playerId, String message, String objectName, List<? extends ActivatedAbility> choices) {

View file

@ -32,6 +32,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.ActivatedAbility;
import mage.abilities.TriggeredAbility;
import mage.cards.Card;
@ -58,8 +59,8 @@ public class PlayerQueryEventSource implements EventSource<PlayerQueryEvent>, Se
dispatcher.removeAllListener();
}
public void ask(UUID playerId, String message) {
dispatcher.fireEvent(PlayerQueryEvent.askEvent(playerId, message));
public void ask(UUID playerId, String message, Ability source, Map<String, Serializable> options) {
dispatcher.fireEvent(PlayerQueryEvent.askEvent(playerId, message, source, options));
}
public void select(UUID playerId, String message) {

View file

@ -0,0 +1,55 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.game.permanent.token;
import mage.MageInt;
import mage.Mana;
import mage.abilities.costs.common.SacrificeSourceCost;
import mage.abilities.mana.SimpleManaAbility;
import mage.constants.CardType;
import mage.constants.Zone;
/**
*
* @author fireshoes
*/
public class EldraziScionToken extends Token {
public EldraziScionToken() {
super("Eldrazi Scion", "1/1 colorless Eldrazi Scion creature token with \"Sacrifice this creature: Add {1} to your mana pool.\"");
cardType.add(CardType.CREATURE);
subtype.add("Eldrazi");
subtype.add("Scion");
power = new MageInt(1);
toughness = new MageInt(1);
addAbility(new SimpleManaAbility(Zone.BATTLEFIELD, Mana.ColorlessMana, new SacrificeSourceCost()));
this.setOriginalExpansionSetCode("BFZ");
}
}

View file

@ -137,7 +137,7 @@ public class Token extends MageObjectImpl {
return false;
}
lastAddedTokenIds.clear();
// TODO: Check this setCode handling because it makes no sens if token put into play with e.g. "Feldon of the third Path"
// TODO: Check this setCode handling because it makes no sense if token put into play with e.g. "Feldon of the third Path"
Card source = game.getCard(sourceId);
String setCode;
if (this.getOriginalExpansionSetCode() != null && !this.getOriginalExpansionSetCode().isEmpty()) {

View file

@ -62,6 +62,9 @@ public class ZombieToken extends Token {
if (getOriginalExpansionSetCode().equals("ISD")) {
this.setTokenType(new Random().nextInt(3) + 1);
}
if (getOriginalExpansionSetCode().equals("C14")) {
this.setTokenType(2);
}
}
public ZombieToken(final ZombieToken token) {

View file

@ -197,9 +197,11 @@ public class Spell extends StackObjImpl implements Card {
}
}
if (game.getState().getZone(card.getMainCard().getId()) == Zone.STACK) {
Player player = game.getPlayer(getControllerId());
if (player != null) {
player.moveCards(card, Zone.STACK, Zone.GRAVEYARD, ability, game);
if (isCopy() == card.isCopy()) {
Player player = game.getPlayer(getControllerId());
if (player != null) {
player.moveCards(card, Zone.STACK, Zone.GRAVEYARD, ability, game);
}
}
}
return result;
@ -636,6 +638,10 @@ public class Spell extends StackObjImpl implements Card {
if (this.isCopiedSpell() && !zone.equals(Zone.STACK)) {
return true;
}
Card card = game.getCard(getSourceId());
if (card != null) {
return card.moveToZone(zone, sourceId, game, flag, appliedEffects);
}
throw new UnsupportedOperationException("Unsupported operation");
}

View file

@ -52,6 +52,7 @@ import mage.cards.Card;
import mage.cards.Cards;
import mage.cards.decks.Deck;
import mage.choices.Choice;
import mage.constants.AbilityType;
import mage.constants.ManaType;
import mage.constants.Outcome;
import mage.constants.PlayerAction;
@ -74,6 +75,7 @@ import mage.target.TargetAmount;
import mage.target.TargetCard;
import mage.target.common.TargetCardInLibrary;
import mage.util.Copyable;
import mage.util.MessageToClient;
/**
*
@ -191,6 +193,10 @@ public interface Player extends MageItem, Copyable<Player> {
boolean getPassedAllTurns();
AbilityType getJustActivatedType();
void setJustActivatedType(AbilityType abilityType);
boolean hasLost();
boolean hasWon();
@ -451,6 +457,8 @@ public interface Player extends MageItem, Copyable<Player> {
boolean chooseUse(Outcome outcome, String message, Ability source, Game game);
boolean chooseUse(Outcome outcome, MessageToClient message, Ability source, Game game);
boolean choose(Outcome outcome, Choice choice, Game game);
boolean choosePile(Outcome outcome, String message, List<? extends Card> pile1, List<? extends Card> pile2, Game game);
@ -661,6 +669,7 @@ public interface Player extends MageItem, Copyable<Player> {
* @param exileName name of exile zone (optional)
* @param sourceId
* @param game
* @param fromZone
* @param withName
* @return
*/
@ -786,4 +795,6 @@ public interface Player extends MageItem, Copyable<Player> {
void setMatchPlayer(MatchPlayer matchPlayer);
MatchPlayer getMatchPlayer();
boolean scry(int value, Ability source, Game game);
}

View file

@ -176,6 +176,7 @@ public abstract class PlayerImpl implements Player, Serializable {
* and abilities in the stack and will pass them as well.
*/
protected boolean passedAllTurns; // F9
protected AbilityType justActivatedType; // used to check if priority can be passed automatically
protected int turns;
protected int storedBookmark = -1;
@ -317,6 +318,7 @@ public abstract class PlayerImpl implements Player, Serializable {
this.passedUntilStackResolved = player.passedUntilStackResolved;
this.dateLastAddedToStack = player.dateLastAddedToStack;
this.passedAllTurns = player.passedAllTurns;
this.justActivatedType = player.justActivatedType;
this.priorityTimeLeft = player.getPriorityTimeLeft();
this.reachedNextTurnAfterLeaving = player.reachedNextTurnAfterLeaving;
@ -440,6 +442,7 @@ public abstract class PlayerImpl implements Player, Serializable {
this.skippedAtLeastOnce = false;
this.passedUntilStackResolved = false;
this.passedAllTurns = false;
this.justActivatedType = null;
this.canGainLife = true;
this.canLoseLife = true;
this.topCardRevealed = false;
@ -841,7 +844,7 @@ public abstract class PlayerImpl implements Player, Serializable {
if (cards.size() != 0) {
if (!anyOrder) {
for (UUID objectId : cards) {
moveObjectToLibrary(objectId, source.getSourceId(), game, false, false);
moveObjectToLibrary(objectId, source == null ? null : source.getSourceId(), game, false, false);
}
} else {
TargetCard target = new TargetCard(Zone.PICK, new FilterCard("card to put on the bottom of your library (last one chosen will be bottommost)"));
@ -850,11 +853,11 @@ public abstract class PlayerImpl implements Player, Serializable {
this.choose(Outcome.Neutral, cards, target, game);
UUID targetObjectId = target.getFirstTarget();
cards.remove(targetObjectId);
moveObjectToLibrary(targetObjectId, source.getSourceId(), game, false, false);
moveObjectToLibrary(targetObjectId, source == null ? null : source.getSourceId(), game, false, false);
target.clearChosen();
}
if (cards.size() == 1) {
moveObjectToLibrary(cards.iterator().next(), source.getSourceId(), game, false, false);
moveObjectToLibrary(cards.iterator().next(), source == null ? null : source.getSourceId(), game, false, false);
}
}
}
@ -875,9 +878,10 @@ public abstract class PlayerImpl implements Player, Serializable {
Cards cards = new CardsImpl(cardsToLibrary); // prevent possible ConcurrentModificationException
cards.addAll(cardsToLibrary);
if (cards.size() != 0) {
UUID sourceId = (source == null ? null : source.getSourceId());
if (!anyOrder) {
for (UUID cardId : cards) {
moveObjectToLibrary(cardId, source.getSourceId(), game, true, false);
moveObjectToLibrary(cardId, sourceId, game, true, false);
}
} else {
TargetCard target = new TargetCard(Zone.PICK, new FilterCard("card to put on the top of your library (last one chosen will be topmost)"));
@ -886,11 +890,11 @@ public abstract class PlayerImpl implements Player, Serializable {
this.choose(Outcome.Neutral, cards, target, game);
UUID targetObjectId = target.getFirstTarget();
cards.remove(targetObjectId);
moveObjectToLibrary(targetObjectId, source.getSourceId(), game, true, false);
moveObjectToLibrary(targetObjectId, sourceId, game, true, false);
target.clearChosen();
}
if (cards.size() == 1) {
moveObjectToLibrary(cards.iterator().next(), source.getSourceId(), game, true, false);
moveObjectToLibrary(cards.iterator().next(), sourceId, game, true, false);
}
}
}
@ -1129,7 +1133,11 @@ public abstract class PlayerImpl implements Player, Serializable {
}
//if player has taken an action then reset all player passed flags
justActivatedType = null;
if (result) {
if (isHuman() && (ability.getAbilityType().equals(AbilityType.SPELL) || ability.getAbilityType().equals(AbilityType.ACTIVATED))) {
setJustActivatedType(ability.getAbilityType());
}
game.getPlayers().resetPassed();
}
return result;
@ -2975,7 +2983,7 @@ public abstract class PlayerImpl implements Player, Serializable {
case BATTLEFIELD:
for (Card card : cards) {
fromZone = game.getState().getZone(card.getId());
if (putOntoBattlefieldWithInfo(card, game, fromZone, source == null ? null : source.getSourceId(), false, !card.isFaceDown(game))) {
if (putOntoBattlefieldWithInfo(card, game, fromZone, source == null ? null : source.getSourceId(), false, card.isFaceDown(game))) {
successfulMovedCards.add(card);
}
}
@ -2983,8 +2991,8 @@ public abstract class PlayerImpl implements Player, Serializable {
case LIBRARY:
for (Card card : cards) {
fromZone = game.getState().getZone(card.getId());
boolean withName = fromZone.equals(Zone.BATTLEFIELD) || !card.isFaceDown(game);
if (moveCardToLibraryWithInfo(card, source == null ? null : source.getSourceId(), game, fromZone, true, withName)) {
boolean hideCard = fromZone.equals(Zone.HAND) || fromZone.equals(Zone.LIBRARY);
if (moveCardToLibraryWithInfo(card, source == null ? null : source.getSourceId(), game, fromZone, true, !hideCard)) {
successfulMovedCards.add(card);
}
}
@ -3245,6 +3253,16 @@ public abstract class PlayerImpl implements Player, Serializable {
return passedUntilStackResolved;
}
@Override
public AbilityType getJustActivatedType() {
return justActivatedType;
}
@Override
public void setJustActivatedType(AbilityType justActivatedType) {
this.justActivatedType = justActivatedType;
}
@Override
public void revokePermissionToSeeHandCards() {
usersAllowedToSeeHandCards.clear();
@ -3284,4 +3302,27 @@ public abstract class PlayerImpl implements Player, Serializable {
public void abortReset() {
abort = false;
}
@Override
public boolean scry(int value, Ability source, Game game) {
game.informPlayers(getLogName() + " scries " + value);
Cards cards = new CardsImpl();
cards.addAll(getLibrary().getTopCards(game, value));
if (!cards.isEmpty()) {
String text;
if (cards.size() == 1) {
text = "card if you want to put it to the bottom of your library (Scry)";
} else {
text = "cards you want to put on the bottom of your library (Scry)";
}
TargetCard target = new TargetCard(0, cards.size(), Zone.LIBRARY, new FilterCard(text));
chooseTarget(Outcome.Benefit, cards, target, source, game);
putCardsOnBottomOfLibrary(new CardsImpl(target.getTargets()), game, source, true);
cards.removeAll(target.getTargets());
putCardsOnTopOfLibrary(cards, game, source, true);
}
game.fireEvent(new GameEvent(GameEvent.EventType.SCRY, getId(), source == null ? null : source.getSourceId(), getId(), value, true));
return true;
}
}

View file

@ -19,10 +19,14 @@ public class UserData implements Serializable {
protected boolean askMoveToGraveOrder;
protected boolean manaPoolAutomatic;
protected boolean manaPoolAutomaticRestricted;
protected boolean passPriorityCast;
protected boolean passPriorityActivation;
protected boolean autoOrderTrigger;
public UserData(UserGroup userGroup, int avatarId, boolean showAbilityPickerForced,
boolean allowRequestShowHandCards, boolean confirmEmptyManaPool, UserSkipPrioritySteps userSkipPrioritySteps,
String flagName, boolean askMoveToGraveOrder, boolean manaPoolAutomatic, boolean manaPoolAutomaticRestricted) {
String flagName, boolean askMoveToGraveOrder, boolean manaPoolAutomatic, boolean manaPoolAutomaticRestricted,
boolean passPriorityCast, boolean passPriorityActivation, boolean autoOrderTrigger) {
this.groupId = userGroup.getGroupId();
this.avatarId = avatarId;
this.showAbilityPickerForced = showAbilityPickerForced;
@ -33,6 +37,9 @@ public class UserData implements Serializable {
this.askMoveToGraveOrder = askMoveToGraveOrder;
this.manaPoolAutomatic = manaPoolAutomatic;
this.manaPoolAutomaticRestricted = manaPoolAutomaticRestricted;
this.passPriorityCast = passPriorityCast;
this.passPriorityActivation = passPriorityActivation;
this.autoOrderTrigger = autoOrderTrigger;
}
public void update(UserData userData) {
@ -46,10 +53,13 @@ public class UserData implements Serializable {
this.askMoveToGraveOrder = userData.askMoveToGraveOrder;
this.manaPoolAutomatic = userData.manaPoolAutomatic;
this.manaPoolAutomaticRestricted = userData.manaPoolAutomaticRestricted;
this.passPriorityCast = userData.passPriorityCast;
this.passPriorityActivation = userData.passPriorityActivation;
this.autoOrderTrigger = userData.autoOrderTrigger;
}
public static UserData getDefaultUserDataView() {
return new UserData(UserGroup.DEFAULT, 0, false, false, true, null, "world.png", false, true, true);
return new UserData(UserGroup.DEFAULT, 0, false, false, true, null, "world.png", false, true, true, false, false, false);
}
public void setGroupId(int groupId) {
@ -132,4 +142,28 @@ public class UserData implements Serializable {
this.manaPoolAutomaticRestricted = manaPoolAutomaticRestricted;
}
public boolean isPassPriorityCast() {
return passPriorityCast;
}
public void setPassPriorityCast(boolean passPriorityCast) {
this.passPriorityCast = passPriorityCast;
}
public boolean isPassPriorityActivation() {
return passPriorityActivation;
}
public void setPassPriorityActivation(boolean passPriorityActivation) {
this.passPriorityActivation = passPriorityActivation;
}
public boolean isAutoOrderTrigger() {
return autoOrderTrigger;
}
public void setAutoOrderTrigger(boolean autoOrderTrigger) {
this.autoOrderTrigger = autoOrderTrigger;
}
}

View file

@ -1,41 +1,40 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.target.common;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import mage.constants.Zone;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.StaticValue;
import mage.constants.Zone;
import mage.filter.Filter;
import mage.filter.common.FilterCreatureOrPlayer;
import mage.filter.common.FilterCreaturePermanent;
@ -64,7 +63,7 @@ public class TargetCreatureOrPlayerAmount extends TargetAmount {
public TargetCreatureOrPlayerAmount(DynamicValue amount) {
super(amount);
this.zone = Zone.ALL;
this.filter = new FilterCreatureOrPlayer();
this.filter = new FilterCreatureOrPlayer("creatures and/or players");
this.targetName = filter.getMessage();
}
@ -124,7 +123,7 @@ public class TargetCreatureOrPlayerAmount extends TargetAmount {
public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) {
int count = 0;
MageObject targetSource = game.getObject(sourceId);
for (UUID playerId: game.getPlayer(sourceControllerId).getInRange()) {
for (UUID playerId : game.getPlayer(sourceControllerId).getInRange()) {
Player player = game.getPlayer(playerId);
if (player != null && player.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(player, game)) {
count++;
@ -133,7 +132,7 @@ public class TargetCreatureOrPlayerAmount extends TargetAmount {
}
}
}
for (Permanent permanent: game.getBattlefield().getActivePermanents(new FilterCreaturePermanent(), sourceControllerId, game)) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterCreaturePermanent(), sourceControllerId, game)) {
if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(permanent, sourceId, sourceControllerId, game)) {
count++;
if (count >= this.minNumberOfTargets) {
@ -147,7 +146,7 @@ public class TargetCreatureOrPlayerAmount extends TargetAmount {
@Override
public boolean canChoose(UUID sourceControllerId, Game game) {
int count = 0;
for (UUID playerId: game.getPlayer(sourceControllerId).getInRange()) {
for (UUID playerId : game.getPlayer(sourceControllerId).getInRange()) {
Player player = game.getPlayer(playerId);
if (player != null && filter.match(player, game)) {
count++;
@ -156,7 +155,7 @@ public class TargetCreatureOrPlayerAmount extends TargetAmount {
}
}
}
for (Permanent permanent: game.getBattlefield().getActivePermanents(new FilterCreaturePermanent(), sourceControllerId, game)) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterCreaturePermanent(), sourceControllerId, game)) {
if (filter.match(permanent, null, sourceControllerId, game)) {
count++;
if (count >= this.minNumberOfTargets) {
@ -171,13 +170,13 @@ public class TargetCreatureOrPlayerAmount extends TargetAmount {
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
Set<UUID> possibleTargets = new HashSet<>();
MageObject targetSource = game.getObject(sourceId);
for (UUID playerId: game.getPlayer(sourceControllerId).getInRange()) {
for (UUID playerId : game.getPlayer(sourceControllerId).getInRange()) {
Player player = game.getPlayer(playerId);
if (player != null && player.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(player, game)) {
possibleTargets.add(playerId);
}
}
for (Permanent permanent: game.getBattlefield().getActivePermanents(new FilterCreaturePermanent(), sourceControllerId, game)) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterCreaturePermanent(), sourceControllerId, game)) {
if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(permanent, sourceId, sourceControllerId, game)) {
possibleTargets.add(permanent.getId());
}
@ -188,13 +187,13 @@ public class TargetCreatureOrPlayerAmount extends TargetAmount {
@Override
public Set<UUID> possibleTargets(UUID sourceControllerId, Game game) {
Set<UUID> possibleTargets = new HashSet<>();
for (UUID playerId: game.getPlayer(sourceControllerId).getInRange()) {
for (UUID playerId : game.getPlayer(sourceControllerId).getInRange()) {
Player player = game.getPlayer(playerId);
if (player != null && filter.match(player, game)) {
possibleTargets.add(playerId);
}
}
for (Permanent permanent: game.getBattlefield().getActivePermanents(new FilterCreaturePermanent(), sourceControllerId, game)) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterCreaturePermanent(), sourceControllerId, game)) {
if (filter.match(permanent, null, sourceControllerId, game)) {
possibleTargets.add(permanent.getId());
}
@ -205,12 +204,11 @@ public class TargetCreatureOrPlayerAmount extends TargetAmount {
@Override
public String getTargetedName(Game game) {
StringBuilder sb = new StringBuilder();
for (UUID targetId: getTargets()) {
for (UUID targetId : getTargets()) {
Permanent permanent = game.getPermanent(targetId);
if (permanent != null) {
sb.append(permanent.getLogName()).append("(").append(getTargetAmount(targetId)).append(") ");
}
else {
} else {
Player player = game.getPlayer(targetId);
sb.append(player.getLogName()).append("(").append(getTargetAmount(targetId)).append(") ");
}

View file

@ -0,0 +1,56 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mage.util;
/**
*
* @author LevelX2
*/
public class MessageToClient {
private String message;
private String secondMessage;
private String hintText;
public MessageToClient(String message) {
this(message, null);
}
public MessageToClient(String message, String secondMessage) {
this(message, secondMessage, null);
}
public MessageToClient(String message, String secondMessage, String hintText) {
this.message = message;
this.secondMessage = secondMessage;
this.hintText = hintText;
}
public String getMessage() {
return message;
}
public String getSecondMessage() {
return secondMessage;
}
public String getHintText() {
return hintText;
}
public void setMessage(String message) {
this.message = message;
}
public void setSecondMessage(String secondMessage) {
this.secondMessage = secondMessage;
}
public void setHintText(String hintText) {
this.hintText = hintText;
}
}

View file

@ -1,16 +1,16 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
@ -20,12 +20,11 @@
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.util;
import java.util.ArrayList;
@ -34,14 +33,16 @@ import java.util.List;
/**
*
* @author BetaSteward_at_googlemail.com
* @param <T>
*/
public class TreeNode<T> {
protected T data;
protected List<TreeNode<T>> children;
public TreeNode() {
super();
children = new ArrayList<TreeNode<T>>();
children = new ArrayList<>();
}
public TreeNode(T data) {
@ -70,7 +71,7 @@ public class TreeNode<T> {
}
public void addChild(T child) {
children.add(new TreeNode<T>(child));
children.add(new TreeNode<>(child));
}
public void addChildAt(int index, TreeNode<T> child) throws IndexOutOfBoundsException {
@ -93,7 +94,7 @@ public class TreeNode<T> {
return this.data;
}
public void setData(T data) {
private void setData(T data) {
this.data = data;
}
@ -116,10 +117,7 @@ public class TreeNode<T> {
return false;
}
final TreeNode<T> other = (TreeNode<T>) obj;
if (this.data != other.data && (this.data == null || !this.data.equals(other.data))) {
return false;
}
return true;
return !(this.data != other.data && (this.data == null || !this.data.equals(other.data)));
}
}

View file

@ -0,0 +1,59 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.util.functions;
import mage.MageObject;
import mage.abilities.Ability;
import mage.game.Game;
import mage.game.permanent.Permanent;
/**
*
* @author LevelX2
*/
public class AbilityApplier extends ApplyToPermanent {
private final Ability ability;
public AbilityApplier(Ability ability) {
this.ability = ability;
}
@Override
public Boolean apply(Game game, Permanent permanent) {
permanent.addAbility(ability, game);
return true;
}
@Override
public Boolean apply(Game game, MageObject mageObject) {
mageObject.getAbilities().add(ability);
return true;
}
}

View file

@ -0,0 +1,40 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.util.functions;
import mage.MageObject;
import mage.game.Game;
/**
*
* @author LevelX2
*/
public abstract class ApplyToMageObject {
public abstract Boolean apply(Game game, MageObject mageObject);
}

View file

@ -7,7 +7,7 @@ import mage.game.permanent.Permanent;
/**
* @author noxx
*/
public abstract class ApplyToPermanent implements Serializable {
public abstract class ApplyToPermanent extends ApplyToMageObject implements Serializable {
public abstract Boolean apply(Game game, Permanent permanent);
}

View file

@ -0,0 +1,36 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.util.functions;
/**
*
* @author LevelX2
*/
public class CardTypeApplier {
}

View file

@ -61,24 +61,24 @@ public class CopyTokenFunction implements Function<Token, Card> {
if (source instanceof PermanentToken) {
sourceObj = ((PermanentToken) source).getToken();
// to show the source image, the original values have to be used
target.setOriginalExpansionSetCode(((Token)sourceObj).getOriginalExpansionSetCode());
target.setOriginalCardNumber(((Token)sourceObj).getOriginalCardNumber());
target.setCopySourceCard(((PermanentToken)source).getToken().getCopySourceCard());
target.setOriginalExpansionSetCode(((Token) sourceObj).getOriginalExpansionSetCode());
target.setOriginalCardNumber(((Token) sourceObj).getOriginalCardNumber());
target.setCopySourceCard(((PermanentToken) source).getToken().getCopySourceCard());
} else if (source instanceof PermanentCard) {
if (((PermanentCard)source).isMorphed() || ((PermanentCard)source).isManifested()) {
if (((PermanentCard) source).isMorphed() || ((PermanentCard) source).isManifested()) {
MorphAbility.setPermanentToFaceDownCreature(target);
return target;
} else {
sourceObj = ((PermanentCard) source).getCard();
target.setOriginalExpansionSetCode(source.getExpansionSetCode());
target.setOriginalCardNumber(source.getCardNumber());
target.setCopySourceCard((Card)sourceObj);
sourceObj = ((PermanentCard) source).getCard();
target.setOriginalExpansionSetCode(source.getExpansionSetCode());
target.setOriginalCardNumber(source.getCardNumber());
target.setCopySourceCard((Card) sourceObj);
}
} else {
target.setOriginalExpansionSetCode(source.getExpansionSetCode());
target.setOriginalCardNumber(source.getCardNumber());
if (source instanceof Card) {
target.setCopySourceCard((Card)source);
target.setCopySourceCard(source);
}
}

View file

@ -1,5 +1,6 @@
package mage.util.functions;
import mage.MageObject;
import mage.game.Game;
import mage.game.permanent.Permanent;
@ -8,8 +9,15 @@ import mage.game.permanent.Permanent;
*/
public class EmptyApplyToPermanent extends ApplyToPermanent {
@Override
public Boolean apply(Game game, Permanent permanent) {
// do nothing
return true;
}
@Override
public Boolean apply(Game game, MageObject mageObject) {
return true;
}
}

View file

@ -17,14 +17,14 @@ import mage.watchers.Watcher;
public class LandfallWatcher extends Watcher {
Set<UUID> playerPlayedLand = new HashSet<>();
public LandfallWatcher() {
super("LandPlayed", WatcherScope.GAME);
}
public LandfallWatcher(final LandfallWatcher watcher) {
super(watcher);
playerPlayedLand.addAll(playerPlayedLand);
playerPlayedLand.addAll(watcher.playerPlayedLand);
}
@Override
@ -45,9 +45,9 @@ public class LandfallWatcher extends Watcher {
@Override
public void reset() {
playerPlayedLand.clear();
super.reset();
super.reset();
}
public boolean landPlayed(UUID playerId) {
return playerPlayedLand.contains(playerId);
}

View file

@ -25,7 +25,6 @@
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.watchers.common;
import mage.Mana;
@ -58,16 +57,16 @@ public class ManaSpentToCastWatcher extends Watcher {
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.SPELL_CAST && event.getZone() == Zone.HAND) {
if (event.getType() == GameEvent.EventType.SPELL_CAST && event.getZone() == Zone.HAND) {
Spell spell = (Spell) game.getObject(event.getTargetId());
if (this.getSourceId().equals(spell.getSourceId())) {
payment = spell.getSpellAbility().getManaCostsToPay().getPayment();
if (spell != null && this.getSourceId().equals(spell.getSourceId())) {
payment = spell.getSpellAbility().getManaCostsToPay().getPayment();
}
}
if (event.getType() == GameEvent.EventType.ZONE_CHANGE && this.getSourceId().equals(event.getSourceId())) {
if (((ZoneChangeEvent) event).getFromZone().equals(Zone.BATTLEFIELD)) {
payment = null;
}
if (((ZoneChangeEvent) event).getFromZone().equals(Zone.BATTLEFIELD)) {
payment = null;
}
}
}

View file

@ -109,7 +109,7 @@ public class SoulbondWatcher extends Watcher {
Cards cards = new CardsImpl();
cards.add(chosen);
controller.lookAtCards("Soulbond", cards, game);
if (controller.chooseUse(Outcome.Benefit, "Use Soulbond for recent " + permanent.getLogName() + "?", null, game)) {
if (controller.chooseUse(Outcome.Benefit, "Use Soulbond for recent " + permanent.getLogName() + "?", SoulbondAbility.getInstance(), game)) {
chosen.setPairedCard(permanent.getId());
permanent.setPairedCard(chosen.getId());
if (!game.isSimulation()) {