fix multitargeting, todo: fix tooltip

This commit is contained in:
Loki 2011-08-22 00:01:32 +03:00
parent 4eaf896cff
commit 54a2e7c497

View file

@ -40,98 +40,103 @@ import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.game.permanent.token.Token; import mage.game.permanent.token.Token;
import java.util.UUID;
/** /**
*
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
public class BecomesCreatureTargetEffect extends ContinuousEffectImpl<BecomesCreatureTargetEffect> { public class BecomesCreatureTargetEffect extends ContinuousEffectImpl<BecomesCreatureTargetEffect> {
protected Token token; protected Token token;
protected String type; protected String type;
public BecomesCreatureTargetEffect(Token token, String type, Duration duration) { public BecomesCreatureTargetEffect(Token token, String type, Duration duration) {
super(duration, Outcome.BecomeCreature); super(duration, Outcome.BecomeCreature);
this.token = token; this.token = token;
this.type = type; this.type = type;
} }
public BecomesCreatureTargetEffect(final BecomesCreatureTargetEffect effect) { public BecomesCreatureTargetEffect(final BecomesCreatureTargetEffect effect) {
super(effect); super(effect);
token = effect.token.copy(); token = effect.token.copy();
type = effect.type; type = effect.type;
} }
@Override @Override
public BecomesCreatureTargetEffect copy() { public BecomesCreatureTargetEffect copy() {
return new BecomesCreatureTargetEffect(this); return new BecomesCreatureTargetEffect(this);
} }
@Override @Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) { public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
Permanent permanent = game.getPermanent(source.getFirstTarget()); boolean result = false;
if (permanent != null) { for (UUID permanentId : targetPointer.getTargets(source)) {
switch (layer) { Permanent permanent = game.getPermanent(permanentId);
case TypeChangingEffects_4: if (permanent != null) {
if (sublayer == SubLayer.NA) { switch (layer) {
if (token.getCardType().size() > 0) { case TypeChangingEffects_4:
for (Constants.CardType t : token.getCardType()) { if (sublayer == SubLayer.NA) {
if (!permanent.getCardType().contains(t)) { if (token.getCardType().size() > 0) {
permanent.getCardType().add(t); for (Constants.CardType t : token.getCardType()) {
} if (!permanent.getCardType().contains(t)) {
} permanent.getCardType().add(t);
} }
if (type == null) { }
permanent.getSubtype().clear(); }
} if (type == null) {
if (token.getSubtype().size() > 0) { permanent.getSubtype().clear();
permanent.getSubtype().addAll(token.getSubtype()); }
} if (token.getSubtype().size() > 0) {
} permanent.getSubtype().addAll(token.getSubtype());
break; }
case ColorChangingEffects_5: }
if (sublayer == SubLayer.NA) { break;
if (token.getColor().hasColor()) case ColorChangingEffects_5:
permanent.getColor().setColor(token.getColor()); if (sublayer == SubLayer.NA) {
} if (token.getColor().hasColor())
break; permanent.getColor().setColor(token.getColor());
case AbilityAddingRemovingEffects_6: }
if (sublayer == SubLayer.NA) { break;
if (token.getAbilities().size() > 0) { case AbilityAddingRemovingEffects_6:
for (Ability ability: token.getAbilities()) { if (sublayer == SubLayer.NA) {
permanent.addAbility(ability); if (token.getAbilities().size() > 0) {
} for (Ability ability : token.getAbilities()) {
} permanent.addAbility(ability);
} }
break; }
case PTChangingEffects_7: }
if (sublayer == SubLayer.SetPT_7b) { break;
if (token.getPower() != MageInt.EmptyMageInt) case PTChangingEffects_7:
permanent.getPower().setValue(token.getPower().getValue()); if (sublayer == SubLayer.SetPT_7b) {
if (token.getToughness() != MageInt.EmptyMageInt) if (token.getPower() != MageInt.EmptyMageInt)
permanent.getToughness().setValue(token.getToughness().getValue()); permanent.getPower().setValue(token.getPower().getValue());
} if (token.getToughness() != MageInt.EmptyMageInt)
} permanent.getToughness().setValue(token.getToughness().getValue());
} }
return true; }
} }
result |= true;
}
return result;
}
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
return false; return false;
} }
@Override @Override
public boolean hasLayer(Layer layer) { public boolean hasLayer(Layer layer) {
return layer == Layer.PTChangingEffects_7 || layer == Layer.AbilityAddingRemovingEffects_6 || layer == Layer.ColorChangingEffects_5 || layer == layer.TypeChangingEffects_4; return layer == Layer.PTChangingEffects_7 || layer == Layer.AbilityAddingRemovingEffects_6 || layer == Layer.ColorChangingEffects_5 || layer == layer.TypeChangingEffects_4;
} }
@Override @Override
public String getText(Mode mode) { public String getText(Mode mode) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append(duration.toString()); sb.append(duration.toString());
sb.append(" target ").append(mode.getTargets().get(0).getTargetName()).append(" becomes a ").append(token.getDescription()); sb.append(" target ").append(mode.getTargets().get(0).getTargetName()).append(" becomes a ").append(token.getDescription());
if (type != null && type.length() > 0) if (type != null && type.length() > 0)
sb.append(" that's still a ").append(type); sb.append(" that's still a ").append(type);
return sb.toString(); return sb.toString();
} }