mirror of
https://github.com/correl/mage.git
synced 2025-01-12 03:00:13 +00:00
Proliferate
This commit is contained in:
parent
b71a5ed9b4
commit
04b9db5c60
8 changed files with 731 additions and 22 deletions
|
@ -55,6 +55,7 @@ public class PermanentView extends CardView {
|
|||
|
||||
public PermanentView(Permanent permanent, Card card) {
|
||||
super(permanent);
|
||||
this.rules = permanent.getRules();
|
||||
this.tapped = permanent.isTapped();
|
||||
this.flipped = permanent.isFlipped();
|
||||
this.phasedIn = permanent.isPhasedIn();
|
||||
|
|
144
Mage/src/mage/abilities/effects/common/ProliferateEffect.java
Normal file
144
Mage/src/mage/abilities/effects/common/ProliferateEffect.java
Normal file
|
@ -0,0 +1,144 @@
|
|||
/*
|
||||
* 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.Constants.Outcome;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.choices.Choice;
|
||||
import mage.choices.ChoiceImpl;
|
||||
import mage.counters.Counter;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
import mage.target.Target;
|
||||
import mage.target.common.TargetPermanentOrPlayerWithCounter;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author nantuko
|
||||
*/
|
||||
public class ProliferateEffect extends OneShotEffect<ProliferateEffect> {
|
||||
|
||||
public ProliferateEffect() {
|
||||
super(Outcome.Benefit);
|
||||
}
|
||||
|
||||
public ProliferateEffect(ProliferateEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
Target target = new TargetPermanentOrPlayerWithCounter(0, Integer.MAX_VALUE, true);
|
||||
|
||||
//A spell or ability could have removed the only legal target this player
|
||||
//had, if thats the case this ability should fizzle.
|
||||
if (target.canChoose(controller.getId(), game)) {
|
||||
boolean abilityApplied = false;
|
||||
while (target.canChoose(controller.getId(), game)) {
|
||||
if (!controller.choose(Outcome.Benefit, target, game)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (int idx = 0; idx < target.getTargets().size(); idx++) {
|
||||
UUID chosen = (UUID) target.getTargets().get(idx);
|
||||
Permanent permanent = game.getPermanent(chosen);
|
||||
if (permanent != null) {
|
||||
if (permanent.getCounters().size() > 0) {
|
||||
if (permanent.getCounters().size() == 1) {
|
||||
for (Counter counter : permanent.getCounters().values()) {
|
||||
permanent.getCounters().addCounter(counter.getName(), 1);
|
||||
}
|
||||
} else {
|
||||
Choice choice = new ChoiceImpl(true);
|
||||
Set<String> choices = new HashSet<String>();
|
||||
for (Counter counter : permanent.getCounters().values()) {
|
||||
choices.add(counter.getName());
|
||||
}
|
||||
choice.setChoices(choices);
|
||||
choice.setMessage("Choose a counter to proliferate (" + permanent.getName() + ")");
|
||||
controller.choose(Outcome.Benefit, choice, game);
|
||||
for (Counter counter : permanent.getCounters().values()) {
|
||||
if (counter.getName().equals(choice.getChoice())) {
|
||||
permanent.getCounters().addCounter(counter.getName(), 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Player player = game.getPlayer(chosen);
|
||||
if (player != null) {
|
||||
if (player.getCounters().size() > 0) {
|
||||
if (player.getCounters().size() == 1) {
|
||||
for (Counter counter : player.getCounters().values()) {
|
||||
player.getCounters().addCounter(counter.getName(), 1);
|
||||
}
|
||||
} else {
|
||||
Choice choice = new ChoiceImpl(true);
|
||||
Set<String> choices = new HashSet<String>();
|
||||
for (Counter counter : player.getCounters().values()) {
|
||||
choices.add(counter.getName());
|
||||
}
|
||||
choice.setChoices(choices);
|
||||
choice.setMessage("Choose a counter to proliferate (" + player.getName() + ")");
|
||||
controller.choose(Outcome.Benefit, choice, game);
|
||||
for (Counter counter : player.getCounters().values()) {
|
||||
if (counter.getName().equals(choice.getChoice())) {
|
||||
player.getCounters().addCounter(counter.getName(), 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return abilityApplied;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProliferateEffect copy() {
|
||||
return new ProliferateEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText(Ability source) {
|
||||
return "Proliferate. (You choose any number of permanents and/or players with counters on them, then give each another counter of a kind already there.)";
|
||||
}
|
||||
}
|
106
Mage/src/mage/filter/common/FilterPermanentOrPlayer.java
Normal file
106
Mage/src/mage/filter/common/FilterPermanentOrPlayer.java
Normal 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.filter.common;
|
||||
|
||||
import mage.filter.FilterImpl;
|
||||
import mage.filter.FilterInPlay;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.filter.FilterPlayer;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author nantuko
|
||||
*/
|
||||
public class FilterPermanentOrPlayer extends FilterImpl<Object, FilterPermanentOrPlayer> implements FilterInPlay<Object> {
|
||||
|
||||
protected FilterPermanent permanentFilter;
|
||||
protected FilterPlayer playerFilter;
|
||||
|
||||
public FilterPermanentOrPlayer() {
|
||||
this("player or permanent");
|
||||
}
|
||||
|
||||
public FilterPermanentOrPlayer(String name, UUID controllerId) {
|
||||
super(name);
|
||||
permanentFilter = new FilterPermanent();
|
||||
playerFilter = new FilterPlayer();
|
||||
permanentFilter.getControllerId().add(controllerId);
|
||||
playerFilter.getPlayerId().add(controllerId);
|
||||
}
|
||||
|
||||
public FilterPermanentOrPlayer(String name) {
|
||||
super(name);
|
||||
permanentFilter = new FilterPermanent();
|
||||
playerFilter = new FilterPlayer();
|
||||
}
|
||||
|
||||
public FilterPermanentOrPlayer(final FilterPermanentOrPlayer filter) {
|
||||
super(filter);
|
||||
this.permanentFilter = filter.permanentFilter.copy();
|
||||
this.playerFilter = filter.playerFilter.copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean match(Object o) {
|
||||
if (o instanceof Player) {
|
||||
return playerFilter.match((Player) o);
|
||||
} else if (o instanceof Permanent) {
|
||||
return permanentFilter.match((Permanent) o);
|
||||
}
|
||||
return notFilter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean match(Object o, UUID playerId, Game game) {
|
||||
if (o instanceof Player) {
|
||||
return playerFilter.match((Player) o, playerId, game);
|
||||
} else if (o instanceof Permanent) {
|
||||
return permanentFilter.match((Permanent) o, playerId, game);
|
||||
}
|
||||
return notFilter;
|
||||
}
|
||||
|
||||
public FilterPermanent getPermanentFilter() {
|
||||
return this.permanentFilter;
|
||||
}
|
||||
|
||||
public FilterPlayer getPlayerFilter() {
|
||||
return this.playerFilter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FilterPermanentOrPlayer copy() {
|
||||
return new FilterPermanentOrPlayer(this);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
* 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.filter.common;
|
||||
|
||||
import mage.filter.FilterImpl;
|
||||
import mage.filter.FilterInPlay;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.filter.FilterPlayer;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author nantuko
|
||||
*/
|
||||
public class FilterPermanentOrPlayerWithCounter extends FilterPermanentOrPlayer {
|
||||
|
||||
protected FilterPermanent permanentFilter;
|
||||
protected FilterPlayer playerFilter;
|
||||
|
||||
public FilterPermanentOrPlayerWithCounter() {
|
||||
this("player or permanent with counters on them");
|
||||
}
|
||||
|
||||
public FilterPermanentOrPlayerWithCounter(String name, UUID controllerId) {
|
||||
super(name);
|
||||
permanentFilter = new FilterPermanent();
|
||||
playerFilter = new FilterPlayer();
|
||||
permanentFilter.getControllerId().add(controllerId);
|
||||
playerFilter.getPlayerId().add(controllerId);
|
||||
}
|
||||
|
||||
public FilterPermanentOrPlayerWithCounter(String name) {
|
||||
super(name);
|
||||
permanentFilter = new FilterPermanent();
|
||||
playerFilter = new FilterPlayer();
|
||||
}
|
||||
|
||||
public FilterPermanentOrPlayerWithCounter(final FilterPermanentOrPlayerWithCounter filter) {
|
||||
super(filter);
|
||||
this.permanentFilter = filter.permanentFilter.copy();
|
||||
this.playerFilter = filter.playerFilter.copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean match(Object o) {
|
||||
if (o instanceof Player) {
|
||||
if (((Player)o).getCounters().size() == 0) {
|
||||
return false;
|
||||
}
|
||||
} else if (o instanceof Permanent) {
|
||||
if (((Permanent)o).getCounters().size() == 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return super.match(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean match(Object o, UUID playerId, Game game) {
|
||||
if (o instanceof Player) {
|
||||
return playerFilter.match((Player) o, playerId, game);
|
||||
} else if (o instanceof Permanent) {
|
||||
return permanentFilter.match((Permanent) o, playerId, game);
|
||||
}
|
||||
return notFilter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FilterPermanentOrPlayerWithCounter copy() {
|
||||
return new FilterPermanentOrPlayerWithCounter(this);
|
||||
}
|
||||
|
||||
}
|
|
@ -28,9 +28,6 @@
|
|||
|
||||
package mage.game.permanent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.Constants.CardType;
|
||||
import mage.Constants.Zone;
|
||||
import mage.MageObject;
|
||||
|
@ -42,18 +39,16 @@ import mage.cards.CardImpl;
|
|||
import mage.counters.Counter;
|
||||
import mage.counters.CounterType;
|
||||
import mage.counters.Counters;
|
||||
import mage.counters.common.MinusOneCounter;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.DamageCreatureEvent;
|
||||
import mage.game.events.DamagePlaneswalkerEvent;
|
||||
import mage.game.events.DamagedCreatureEvent;
|
||||
import mage.game.events.DamagedPlaneswalkerEvent;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.events.*;
|
||||
import mage.game.events.GameEvent.EventType;
|
||||
import mage.players.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl<T> implements Permanent {
|
||||
|
@ -103,7 +98,7 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
|
|||
this.loyaltyUsed = permanent.loyaltyUsed;
|
||||
this.deathtouched = permanent.deathtouched;
|
||||
this.counters = permanent.counters.copy();
|
||||
for (UUID attachmentId: permanent.attachments) {
|
||||
for (UUID attachmentId : permanent.attachments) {
|
||||
this.attachments.add(attachmentId);
|
||||
}
|
||||
this.attachedTo = permanent.attachedTo;
|
||||
|
@ -166,17 +161,17 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
|
|||
this.damage = 0;
|
||||
this.loyaltyUsed = false;
|
||||
this.turnsOnBattlefield++;
|
||||
for (Ability ability: this.abilities) {
|
||||
for (Ability ability : this.abilities) {
|
||||
ability.reset(game);
|
||||
}
|
||||
this.controllerId = this.ownerId;
|
||||
this.controllerId = this.ownerId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkTriggers(GameEvent event, Game game) {
|
||||
if (event.getType() == EventType.BEGINNING_PHASE_PRE && game.getActivePlayerId().equals(controllerId))
|
||||
this.controlledFromStartOfTurn = true;
|
||||
for (TriggeredAbility ability: abilities.getTriggeredAbilities(Zone.BATTLEFIELD)) {
|
||||
for (TriggeredAbility ability : abilities.getTriggeredAbilities(Zone.BATTLEFIELD)) {
|
||||
if (ability.checkTrigger(event, game)) {
|
||||
ability.trigger(game, controllerId);
|
||||
}
|
||||
|
@ -422,8 +417,7 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
|
|||
if (damageAmount > 0 && canDamage(game.getObject(sourceId))) {
|
||||
if (cardType.contains(CardType.PLANESWALKER)) {
|
||||
damageDone = damagePlaneswalker(damageAmount, sourceId, game, preventable, combat);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
damageDone = damageCreature(damageAmount, sourceId, game, preventable, combat);
|
||||
}
|
||||
if (damageDone > 0) {
|
||||
|
@ -471,7 +465,7 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
|
|||
}
|
||||
Permanent source = game.getPermanent(sourceId);
|
||||
if (source != null && (source.getAbilities().containsKey(InfectAbility.getInstance().getId())
|
||||
|| source.getAbilities().containsKey(WitherAbility.getInstance().getId()))) {
|
||||
|| source.getAbilities().containsKey(WitherAbility.getInstance().getId()))) {
|
||||
addCounters(CounterType.M1M1.createInstance(actualDamage));
|
||||
} else {
|
||||
this.damage += actualDamage;
|
||||
|
@ -504,7 +498,7 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
|
|||
|
||||
@Override
|
||||
public boolean hasProtectionFrom(MageObject source) {
|
||||
for (ProtectionAbility ability: abilities.getProtectionAbilities()) {
|
||||
for (ProtectionAbility ability : abilities.getProtectionAbilities()) {
|
||||
if (!ability.canTarget(source))
|
||||
return true;
|
||||
}
|
||||
|
@ -519,7 +513,7 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
|
|||
public boolean destroy(UUID sourceId, Game game, boolean noRegen) {
|
||||
//20091005 - 701.6
|
||||
//TODO: handle noRegen
|
||||
if (!game.replaceEvent(GameEvent.getEvent(EventType.DESTROY_PERMANENT, objectId, sourceId, controllerId, noRegen?1:0))) {
|
||||
if (!game.replaceEvent(GameEvent.getEvent(EventType.DESTROY_PERMANENT, objectId, sourceId, controllerId, noRegen ? 1 : 0))) {
|
||||
if (!this.getAbilities().containsKey(IndestructibleAbility.getInstance().getId())) {
|
||||
if (moveToZone(Zone.GRAVEYARD, sourceId, game, false)) {
|
||||
game.fireEvent(GameEvent.getEvent(EventType.DESTROYED_PERMANENT, objectId, sourceId, controllerId));
|
||||
|
@ -568,7 +562,7 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
|
|||
if (hasSummoningSickness())
|
||||
return false;
|
||||
//20101001 - 508.1c
|
||||
for (RestrictionEffect effect: game.getContinuousEffects().getApplicableRestrictionEffects(this, game)) {
|
||||
for (RestrictionEffect effect : game.getContinuousEffects().getApplicableRestrictionEffects(this, game)) {
|
||||
if (!effect.canAttack(game))
|
||||
return false;
|
||||
}
|
||||
|
@ -583,7 +577,7 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
|
|||
return false;
|
||||
Permanent attacker = game.getPermanent(attackerId);
|
||||
//20101001 - 509.1b
|
||||
for (RestrictionEffect effect: game.getContinuousEffects().getApplicableRestrictionEffects(attacker, game)) {
|
||||
for (RestrictionEffect effect : game.getContinuousEffects().getApplicableRestrictionEffects(attacker, game)) {
|
||||
if (!effect.canBlock(attacker, this, game))
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -95,7 +95,11 @@ public abstract class TargetImpl<T extends TargetImpl<T>> implements Target {
|
|||
if (maxNumberOfTargets > 1) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Select ").append(targetName);
|
||||
sb.append(" (").append(targets.size()).append("/").append(maxNumberOfTargets).append(")");
|
||||
if (maxNumberOfTargets != Integer.MAX_VALUE) {
|
||||
sb.append(" (").append(targets.size()).append("/").append(maxNumberOfTargets).append(")");
|
||||
} else {
|
||||
sb.append(" (").append(targets.size()).append(")");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
return "Select a " + targetName;
|
||||
|
|
238
Mage/src/mage/target/common/TargetPermanentOrPlayer.java
Normal file
238
Mage/src/mage/target/common/TargetPermanentOrPlayer.java
Normal file
|
@ -0,0 +1,238 @@
|
|||
/*
|
||||
* 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 mage.Constants.Zone;
|
||||
import mage.MageObject;
|
||||
import mage.abilities.Ability;
|
||||
import mage.filter.Filter;
|
||||
import mage.filter.common.FilterCreatureOrPlayer;
|
||||
import mage.filter.common.FilterCreaturePermanent;
|
||||
import mage.filter.common.FilterPermanentOrPlayer;
|
||||
import mage.filter.common.FilterPermanentOrPlayerWithCounter;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
import mage.target.TargetImpl;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author nantuko
|
||||
*/
|
||||
public class TargetPermanentOrPlayer extends TargetImpl<TargetPermanentOrPlayer> {
|
||||
|
||||
protected FilterPermanentOrPlayer filter;
|
||||
|
||||
public TargetPermanentOrPlayer() {
|
||||
this(1, 1);
|
||||
}
|
||||
|
||||
public TargetPermanentOrPlayer(int numTargets) {
|
||||
this(numTargets, numTargets);
|
||||
}
|
||||
|
||||
public TargetPermanentOrPlayer(int minNumTargets, int maxNumTargets) {
|
||||
this.minNumberOfTargets = minNumTargets;
|
||||
this.maxNumberOfTargets = maxNumTargets;
|
||||
this.zone = Zone.ALL;
|
||||
this.filter = new FilterPermanentOrPlayer();
|
||||
this.targetName = filter.getMessage();
|
||||
}
|
||||
|
||||
public TargetPermanentOrPlayer(int minNumTargets, int maxNumTargets, boolean notTarget) {
|
||||
this(minNumTargets, maxNumTargets);
|
||||
this.notTarget = notTarget;
|
||||
}
|
||||
|
||||
public TargetPermanentOrPlayer(final TargetPermanentOrPlayer target) {
|
||||
super(target);
|
||||
this.filter = target.filter.copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter getFilter() {
|
||||
return this.filter;
|
||||
}
|
||||
|
||||
public void setFilter(FilterPermanentOrPlayer filter) {
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTarget(UUID id, Game game) {
|
||||
Permanent permanent = game.getPermanent(id);
|
||||
if (permanent != null) {
|
||||
return filter.match(permanent);
|
||||
}
|
||||
Player player = game.getPlayer(id);
|
||||
if (player != null)
|
||||
return filter.match(player);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTarget(UUID id, Ability source, Game game) {
|
||||
Permanent permanent = game.getPermanent(id);
|
||||
MageObject targetSource = game.getObject(source.getSourceId());
|
||||
if (permanent != null) {
|
||||
if (source != null)
|
||||
return permanent.canBeTargetedBy(targetSource) && filter.match(permanent, source.getControllerId(), game);
|
||||
else
|
||||
return filter.match(permanent);
|
||||
}
|
||||
Player player = game.getPlayer(id);
|
||||
if (player != null)
|
||||
if (source != null)
|
||||
return player.canBeTargetedBy(targetSource) && filter.match(player);
|
||||
else
|
||||
return filter.match(player);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if there are enough {@link mage.game.permanent.Permanent} or {@link mage.players.Player} that can be chosen. Should only be used
|
||||
* for Ability targets since this checks for protection, shroud etc.
|
||||
*
|
||||
* @param sourceId - the target event source
|
||||
* @param sourceControllerId - controller of the target event source
|
||||
* @param game
|
||||
* @return - true if enough valid {@link mage.game.permanent.Permanent} or {@link mage.players.Player} exist
|
||||
*/
|
||||
@Override
|
||||
public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) {
|
||||
int count = 0;
|
||||
MageObject targetSource = game.getObject(sourceId);
|
||||
for (UUID playerId: game.getPlayer(sourceControllerId).getInRange()) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null && player.canBeTargetedBy(targetSource) && filter.match(player)) {
|
||||
count++;
|
||||
if (count >= this.minNumberOfTargets)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (Permanent permanent: game.getBattlefield().getActivePermanents(FilterCreaturePermanent.getDefault(), sourceControllerId, game)) {
|
||||
if (permanent.canBeTargetedBy(targetSource) && filter.match(permanent, sourceControllerId, game)) {
|
||||
count++;
|
||||
if (count >= this.minNumberOfTargets)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if there are enough {@link mage.game.permanent.Permanent} or {@link mage.players.Player} that can be selected. Should not be used
|
||||
* for Ability targets since this does not check for protection, shroud etc.
|
||||
*
|
||||
* @param sourceControllerId - controller of the select event
|
||||
* @param game
|
||||
* @return - true if enough valid {@link mage.game.permanent.Permanent} or {@link mage.players.Player} exist
|
||||
*/
|
||||
@Override
|
||||
public boolean canChoose(UUID sourceControllerId, Game game) {
|
||||
int count = 0;
|
||||
for (UUID playerId: game.getPlayer(sourceControllerId).getInRange()) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null && filter.match(player)) {
|
||||
count++;
|
||||
if (count >= this.minNumberOfTargets)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (Permanent permanent: game.getBattlefield().getActivePermanents(FilterCreaturePermanent.getDefault(), sourceControllerId, game)) {
|
||||
if (filter.match(permanent, sourceControllerId, game)) {
|
||||
count++;
|
||||
if (count >= this.minNumberOfTargets)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
|
||||
Set<UUID> possibleTargets = new HashSet<UUID>();
|
||||
MageObject targetSource = game.getObject(sourceId);
|
||||
for (UUID playerId: game.getPlayer(sourceControllerId).getInRange()) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null && player.canBeTargetedBy(targetSource) && filter.match(player)) {
|
||||
possibleTargets.add(playerId);
|
||||
}
|
||||
}
|
||||
for (Permanent permanent: game.getBattlefield().getActivePermanents(FilterCreaturePermanent.getDefault(), sourceControllerId, game)) {
|
||||
if (permanent.canBeTargetedBy(targetSource) && filter.match(permanent, sourceControllerId, game)) {
|
||||
possibleTargets.add(permanent.getId());
|
||||
}
|
||||
}
|
||||
return possibleTargets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UUID> possibleTargets(UUID sourceControllerId, Game game) {
|
||||
Set<UUID> possibleTargets = new HashSet<UUID>();
|
||||
for (UUID playerId: game.getPlayer(sourceControllerId).getInRange()) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null && filter.match(player)) {
|
||||
possibleTargets.add(playerId);
|
||||
}
|
||||
}
|
||||
for (Permanent permanent: game.getBattlefield().getActivePermanents(FilterCreaturePermanent.getDefault(), sourceControllerId, game)) {
|
||||
if (filter.match(permanent, sourceControllerId, game)) {
|
||||
possibleTargets.add(permanent.getId());
|
||||
}
|
||||
}
|
||||
return possibleTargets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTargetedName(Game game) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (UUID targetId: getTargets()) {
|
||||
Permanent permanent = game.getPermanent(targetId);
|
||||
if (permanent != null) {
|
||||
sb.append(permanent.getName()).append(" ");
|
||||
}
|
||||
else {
|
||||
Player player = game.getPlayer(targetId);
|
||||
sb.append(player.getName()).append(" ");
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TargetPermanentOrPlayer copy() {
|
||||
return new TargetPermanentOrPlayer(this);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,120 @@
|
|||
/*
|
||||
* 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 mage.Constants.Zone;
|
||||
import mage.MageObject;
|
||||
import mage.abilities.Ability;
|
||||
import mage.filter.Filter;
|
||||
import mage.filter.common.FilterCreaturePermanent;
|
||||
import mage.filter.common.FilterPermanentOrPlayer;
|
||||
import mage.filter.common.FilterPermanentOrPlayerWithCounter;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
import mage.target.TargetImpl;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author nantuko
|
||||
*/
|
||||
public class TargetPermanentOrPlayerWithCounter extends TargetPermanentOrPlayer {
|
||||
|
||||
protected FilterPermanentOrPlayerWithCounter filter;
|
||||
|
||||
public TargetPermanentOrPlayerWithCounter() {
|
||||
this(1, 1);
|
||||
}
|
||||
|
||||
public TargetPermanentOrPlayerWithCounter(int numTargets) {
|
||||
this(numTargets, numTargets);
|
||||
}
|
||||
|
||||
public TargetPermanentOrPlayerWithCounter(int minNumTargets, int maxNumTargets) {
|
||||
super(minNumTargets, maxNumTargets);
|
||||
this.filter = new FilterPermanentOrPlayerWithCounter();
|
||||
this.targetName = filter.getMessage();
|
||||
super.setFilter(this.filter);
|
||||
}
|
||||
|
||||
public TargetPermanentOrPlayerWithCounter(int minNumTargets, int maxNumTargets, boolean notTarget) {
|
||||
this(minNumTargets, maxNumTargets);
|
||||
this.notTarget = notTarget;
|
||||
}
|
||||
|
||||
public TargetPermanentOrPlayerWithCounter(final TargetPermanentOrPlayerWithCounter target) {
|
||||
super(target);
|
||||
this.filter = target.filter.copy();
|
||||
super.setFilter(this.filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TargetPermanentOrPlayerWithCounter copy() {
|
||||
return new TargetPermanentOrPlayerWithCounter(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTarget(UUID id, Game game) {
|
||||
Permanent permanent = game.getPermanent(id);
|
||||
if (permanent != null) {
|
||||
if (permanent.getCounters().size() == 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Player player = game.getPlayer(id);
|
||||
if (player != null) {
|
||||
if (player.getCounters().size() == 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return super.canTarget(id, game);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTarget(UUID id, Ability source, Game game) {
|
||||
Permanent permanent = game.getPermanent(id);
|
||||
if (permanent != null) {
|
||||
if (permanent.getCounters().size() == 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Player player = game.getPlayer(id);
|
||||
if (player != null) {
|
||||
if (player.getCounters().size() == 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return super.canTarget(id, source, game);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue