New ExileAllEffect, new SecondTargetPointer, changes to BoostTargetEffect (rule text), Added setText method to Effect .

This commit is contained in:
LevelX2 2013-01-26 15:56:33 +01:00
parent b7d0017385
commit 3ade484a45
5 changed files with 171 additions and 0 deletions

View file

@ -46,6 +46,7 @@ public interface Effect<T extends Effect<T>> extends Serializable {
UUID getId();
void newId();
String getText(Mode mode);
void setText(String staticText);
boolean apply(Game game, Ability source);
Outcome getOutcome();
EffectType getEffectType();

View file

@ -82,6 +82,11 @@ public abstract class EffectImpl<T extends Effect<T>> implements Effect<T> {
return staticText;
}
@Override
public void setText(String staticText) {
this.staticText = staticText;
}
@Override
public Outcome getOutcome() {
return outcome;

View file

@ -0,0 +1,87 @@
/*
* 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 java.util.List;
import java.util.UUID;
import mage.Constants.Outcome;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.filter.FilterPermanent;
import mage.game.Game;
import mage.game.permanent.Permanent;
/**
*
* @author LevelX2
*/
public class ExileAllEffect extends OneShotEffect<ExileAllEffect> {
private FilterPermanent filter;
private String exileZone = null;
private UUID exileId = null;
public ExileAllEffect(FilterPermanent filter) {
this(filter, null, null);
}
public ExileAllEffect(FilterPermanent filter, UUID exileId, String exileZone) {
super(Outcome.Exile);
this.filter = filter;
this.exileZone = exileZone;
this.exileId = exileId;
setText();
}
public ExileAllEffect(final ExileAllEffect effect) {
super(effect);
this.filter = effect.filter.copy();
this.exileZone = effect.exileZone;
this.exileId = effect.exileId;
}
@Override
public ExileAllEffect copy() {
return new ExileAllEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
List<Permanent> permanents = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getId(), game);
for (Permanent permanent: permanents) {
permanent.moveToExile(exileId, exileZone, source.getSourceId(), game);
}
return true;
}
private void setText() {
StringBuilder sb = new StringBuilder();
sb.append("Exile all ").append(filter.getMessage());
staticText = sb.toString();
}
}

View file

@ -108,6 +108,9 @@ public class BoostTargetEffect extends ContinuousEffectImpl<BoostTargetEffect> {
@Override
public String getText(Mode mode) {
if (staticText != null && !staticText.isEmpty()) {
return staticText;
}
StringBuilder sb = new StringBuilder();
Target target = mode.getTargets().get(0);
if(target.getNumberOfTargets() > 1){

View file

@ -0,0 +1,75 @@
package mage.target.targetpointer;
import java.util.*;
import mage.abilities.Ability;
import mage.cards.Card;
import mage.game.Game;
public class SecondTargetPointer implements TargetPointer {
private Map<UUID, Integer> zoneChangeCounter = new HashMap<UUID, Integer>();
public static SecondTargetPointer getInstance() {
return new SecondTargetPointer();
}
public SecondTargetPointer() {
}
public SecondTargetPointer(SecondTargetPointer firstTargetPointer) {
this.zoneChangeCounter = new HashMap<UUID, Integer>();
for (Map.Entry<UUID, Integer> entry : firstTargetPointer.zoneChangeCounter.entrySet()) {
this.zoneChangeCounter.put(entry.getKey(), entry.getValue());
}
}
@Override
public void init(Game game, Ability source) {
if (source.getTargets().size() > 1) {
for (UUID target : source.getTargets().get(1).getTargets()) {
Card card = game.getCard(target);
if (card != null) {
this.zoneChangeCounter.put(target, card.getZoneChangeCounter());
}
}
}
}
@Override
public List<UUID> getTargets(Game game, Ability source) {
ArrayList<UUID> target = new ArrayList<UUID>();
if (source.getTargets().size() > 1) {
for (UUID targetId : source.getTargets().get(1).getTargets()) {
Card card = game.getCard(targetId);
if (card != null && zoneChangeCounter.containsKey(targetId)
&& card.getZoneChangeCounter() != zoneChangeCounter.get(targetId)) {
continue;
}
target.add(targetId);
}
}
return target;
}
@Override
public UUID getFirst(Game game, Ability source) {
if (source.getTargets().size() > 1) {
UUID targetId = source.getTargets().get(1).getFirstTarget();
if (zoneChangeCounter.containsKey(targetId)) {
Card card = game.getCard(targetId);
if (card != null && zoneChangeCounter.containsKey(targetId)
&& card.getZoneChangeCounter() != zoneChangeCounter.get(targetId)) {
return null;
}
}
return targetId;
}
return null;
}
@Override
public TargetPointer copy() {
return new SecondTargetPointer(this);
}
}