New framework effect, added random targets to targets, some rule text changes.

This commit is contained in:
LevelX2 2013-04-29 22:59:42 +02:00
parent a8c430e839
commit 0a8e1ff014
7 changed files with 283 additions and 4 deletions

View file

@ -99,7 +99,11 @@ public class ReturnToHandTargetEffect extends OneShotEffect<ReturnToHandTargetEf
if (mode.getTargets().get(0).getNumberOfTargets() == 0 && mode.getTargets().get(0).getMaxNumberOfTargets() > 0) {
return "Return up to " + mode.getTargets().get(0).getMaxNumberOfTargets() +" target " + mode.getTargets().get(0).getTargetName() + " to their owners' hand";
} else {
return "Return target " + mode.getTargets().get(0).getTargetName() + " to it's owner's hand";
StringBuilder sb = new StringBuilder("Return ");
if (!mode.getTargets().get(0).getTargetName().startsWith("another")) {
sb.append(" target ");
}
return sb.append(mode.getTargets().get(0).getTargetName()).append(" to it's owner's hand").toString();
}
}

View file

@ -0,0 +1,146 @@
/*
* Copyright 2011 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.continious;
import mage.Constants.CardType;
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;
import mage.game.permanent.token.Token;
/**
* @author LevelX2
*
*/
public class BecomesCreatureAllEffect extends ContinuousEffectImpl<BecomesCreatureAllEffect> {
protected Token token;
protected String type;
private FilterPermanent filter;
public BecomesCreatureAllEffect(Token token, String type, FilterPermanent filter, Duration duration) {
super(duration, Outcome.BecomeCreature);
this.token = token;
this.type = type;
this.filter = filter;
}
public BecomesCreatureAllEffect(final BecomesCreatureAllEffect effect) {
super(effect);
token = effect.token.copy();
type = effect.type;
this.filter = effect.filter.copy();
}
@Override
public BecomesCreatureAllEffect copy() {
return new BecomesCreatureAllEffect(this);
}
@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
for (Permanent permanent: game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
if (permanent != null) {
switch (layer) {
case TypeChangingEffects_4:
if (sublayer == SubLayer.NA) {
if (token.getCardType().size() > 0) {
for (CardType t : token.getCardType()) {
if (!permanent.getCardType().contains(t)) {
permanent.getCardType().add(t);
}
}
}
if (type == null) {
permanent.getSubtype().clear();
}
if (token.getSubtype().size() > 0) {
permanent.getSubtype().addAll(token.getSubtype());
}
}
break;
case ColorChangingEffects_5:
if (sublayer == SubLayer.NA) {
if (token.getColor().hasColor())
permanent.getColor().setColor(token.getColor());
}
break;
case AbilityAddingRemovingEffects_6:
if (sublayer == SubLayer.NA) {
if (token.getAbilities().size() > 0) {
for (Ability ability : token.getAbilities()) {
permanent.addAbility(ability, game);
}
}
}
break;
case PTChangingEffects_7:
if (sublayer == SubLayer.SetPT_7b) {
int power = token.getPower().getValue();
int toughness = token.getToughness().getValue();
if (power != 0 && toughness != 0) {
permanent.getPower().setValue(power);
permanent.getToughness().setValue(toughness);
}
}
}
}
}
return true;
}
@Override
public boolean apply(Game game, Ability source) {
return false;
}
@Override
public boolean hasLayer(Layer layer) {
return layer == Layer.PTChangingEffects_7 || layer == Layer.AbilityAddingRemovingEffects_6 || layer == Layer.ColorChangingEffects_5 || layer == Layer.TypeChangingEffects_4;
}
@Override
public String getText(Mode mode) {
StringBuilder sb = new StringBuilder();
sb.append(duration.toString()).append(", ");
sb.append(filter.getMessage());
sb.append(" become a ").append(token.getDescription());
if (type != null && type.length() > 0) {
sb.append(". They are still ").append(type);
}
return sb.toString();
}
}

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.effects.common.continious;
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;
public LoseAllAbilitiesAllEffect(FilterPermanent filter, Duration duration) {
super(duration, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.AddAbility);
this.filter = filter;
}
public LoseAllAbilitiesAllEffect(final LoseAllAbilitiesAllEffect effect) {
super(effect);
this.filter = effect.filter.copy();
}
@Override
public LoseAllAbilitiesAllEffect copy() {
return new LoseAllAbilitiesAllEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
for (Permanent permanent: game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
if (permanent != null) {
permanent.removeAllAbilities(source.getSourceId(), game);
}
}
return true;
}
@Override
public String getText(Mode mode) {
StringBuilder sb = new StringBuilder();
if (duration.equals(Duration.EndOfTurn)) {
sb.append(duration.toString()).append(", ");
}
sb.append(filter.getMessage()).append(" lose all abilities.");
return sb.toString();
}
}

View file

@ -72,6 +72,11 @@ public class OverloadAbility extends SpellAbility {
return new OverloadAbility(this);
}
@Override
public String getRule(boolean all) {
return getRule();
}
@Override
public String getRule() {
return "Overload " + getManaCostsToPay().getText()+ " <i>(You may cast this spell for its overload cost. If you do, change its text by replacing all instances of \"target\" with \"each.\")</i>";

View file

@ -88,6 +88,9 @@ public interface Target extends Serializable {
boolean isRequired();
void setRequired(boolean required);
boolean isRandom();
void setRandom(boolean atRandom);
UUID getFirstTarget();
Target copy();

View file

@ -55,6 +55,7 @@ public abstract class TargetImpl<T extends TargetImpl<T>> implements Target {
protected boolean required = false;
protected boolean chosen = false;
protected boolean notTarget = false;
protected boolean atRandom = false;
@Override
public abstract T copy();
@ -76,6 +77,7 @@ public abstract class TargetImpl<T extends TargetImpl<T>> implements Target {
this.chosen = target.chosen;
this.targets.putAll(target.targets);
this.zoneChangeCounters.putAll(target.zoneChangeCounters);
this.atRandom = target.atRandom;
}
@Override
@ -113,7 +115,11 @@ public abstract class TargetImpl<T extends TargetImpl<T>> implements Target {
@Override
public String getTargetName() {
return targetName;
StringBuilder sb = new StringBuilder(targetName);
if (isRandom()) {
sb.append(" chosen at random");
}
return sb.toString();
}
@Override
@ -263,8 +269,24 @@ public abstract class TargetImpl<T extends TargetImpl<T>> implements Target {
Player player = game.getPlayer(playerId);
while (!isChosen() && !doneChosing()) {
chosen = targets.size() >= minNumberOfTargets;
if (!player.chooseTarget(outcome, this, source, game)) {
return chosen;
if (isRandom()) {
Set<UUID> possibleTargets = possibleTargets(source.getSourceId(), playerId, game);
if (possibleTargets.size() > 0) {
int i = 0;
int rnd = new Random().nextInt(possibleTargets.size());
Iterator it = possibleTargets.iterator();
while( i < rnd) {
it.next();
i++;
}
this.addTarget(((UUID) it.next()), source, game);
} else {
return chosen;
}
} else {
if (!player.chooseTarget(outcome, this, source, game)) {
return chosen;
}
}
chosen = targets.size() >= minNumberOfTargets;
}
@ -344,4 +366,16 @@ public abstract class TargetImpl<T extends TargetImpl<T>> implements Target {
public void setNotTarget(boolean notTarget) {
this.notTarget = notTarget;
}
@Override
public boolean isRandom() {
return this.atRandom;
}
@Override
public void setRandom(boolean atRandom) {
this.atRandom = atRandom;
}
}

View file

@ -100,6 +100,7 @@ public class TargetCreatureOrPlayer extends TargetImpl<TargetCreatureOrPlayer> {
return canTarget(null, id, source, game);
}
@Override
public boolean canTarget(UUID controllerId, UUID id, Ability source, Game game) {
Permanent permanent = game.getPermanent(id);
Player player = game.getPlayer(id);