Some improvements for Splice onto Arcane Ability (game log text, reveal all spliced cards at once).

This commit is contained in:
LevelX2 2013-06-26 22:03:12 +02:00
parent 1bd3f6d318
commit c8c1680084
3 changed files with 108 additions and 42 deletions

View file

@ -243,31 +243,53 @@ public abstract class ActivatedAbilityImpl<T extends ActivatedAbilityImpl<T>> ex
} else {
sb.append("unknown");
}
if (object instanceof Spell && ((Spell) object).getSpellAbility().getSpellAbilityType().equals(SpellAbilityType.SPLIT_FUSED)) {
Spell<?> spell = (Spell<?>) object;
int i = 0;
for (SpellAbility spellAbility : spell.getSpellAbilities()) {
i++;
String half;
if (i == 1) {
half = " left";
} else {
half = " right";
if (object instanceof Spell && ((Spell) object).getSpellAbilities().size() > 1) {
if (((Spell) object).getSpellAbility().getSpellAbilityType().equals(SpellAbilityType.SPLIT_FUSED)) {
Spell<?> spell = (Spell<?>) object;
int i = 0;
for (SpellAbility spellAbility : spell.getSpellAbilities()) {
i++;
String half;
if (i == 1) {
half = " left";
} else {
half = " right";
}
if (spellAbility.getTargets().size() > 0) {
sb.append(half).append(" half targeting ");
for (Target target: spellAbility.getTargets()) {
sb.append(target.getTargetedName(game));
}
}
}
if (spellAbility.getTargets().size() > 0) {
sb.append(half).append(" half targeting ");
for (Target target: spellAbility.getTargets()) {
sb.append(target.getTargetedName(game));
} else {
Spell<?> spell = (Spell<?>) object;
int i = 0;
for (SpellAbility spellAbility : spell.getSpellAbilities()) {
i++;
if ( i > 1) {
sb.append(" splicing ");
if (spellAbility.name.length() > 5 && spellAbility.name.startsWith("Cast ")) {
sb.append(spellAbility.name.substring(5));
} else {
sb.append(spellAbility.name);
}
}
if (spellAbility.getTargets().size() > 0) {
for (Target target: spellAbility.getTargets()) {
sb.append(" targeting ");
sb.append(target.getTargetedName(game));
}
}
}
}
} else if (object instanceof Spell && ((Spell) object).getSpellAbility().getModes().size() > 1) {
Modes modes = ((Spell) object).getSpellAbility().getModes();
Modes spellModes = ((Spell) object).getSpellAbility().getModes();
int item = 0;
for (Mode mode : modes.values()) {
for (Mode mode : spellModes.values()) {
item++;
if (modes.getSelectedModes().contains(mode.getId())) {
modes.setMode(mode);
if (spellModes.getSelectedModes().contains(mode.getId())) {
spellModes.setMode(mode);
sb.append(" (mode ").append(item).append(")");
if (getTargets().size() > 0) {
sb.append(" targeting ");

View file

@ -38,11 +38,20 @@ import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.SpellAbility;
import mage.abilities.StaticAbility;
import mage.abilities.keyword.SpliceOntoArcaneAbility;
import mage.cards.Cards;
import mage.cards.CardsImpl;
import mage.constants.Outcome;
import mage.constants.SpellAbilityType;
import mage.filter.FilterCard;
import mage.filter.predicate.Predicate;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.mageobject.CardIdPredicate;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.common.TargetCardInHand;
/**
*
@ -434,15 +443,52 @@ public class ContinuousEffects implements Serializable {
return;
}
List<SpliceCardEffect> spliceEffects = getApplicableSpliceCardEffects(game);
for ( SpliceCardEffect effect : spliceEffects) {
// get the applyable splice abilities
List<SpliceOntoArcaneAbility> spliceAbilities = new ArrayList<SpliceOntoArcaneAbility>();
for (SpliceCardEffect effect : spliceEffects) {
HashSet<Ability> abilities = spliceCardEffects.getAbility(effect.getId());
for (Ability ability : abilities) {
if ( effect.applies(abilityToModify, ability, game) ) {
effect.apply(game, ability, abilityToModify);
if (effect.applies(abilityToModify, ability, game) ) {
spliceAbilities.add((SpliceOntoArcaneAbility) ability);
}
}
}
// check if player wants to use splice
if (spliceAbilities.size() > 0) {
Player controller = game.getPlayer(abilityToModify.getControllerId());
if (controller.chooseUse(Outcome.Benefit, "Splice a card?", game)) {
Cards cardsToReveal = new CardsImpl();
do {
FilterCard filter = new FilterCard("a card to splice");
ArrayList<Predicate<MageObject>> idPredicates = new ArrayList<Predicate<MageObject>>();
for (SpliceOntoArcaneAbility ability : spliceAbilities) {
idPredicates.add(new CardIdPredicate((ability.getSourceId())));
}
filter.add(Predicates.or(idPredicates));
TargetCardInHand target = new TargetCardInHand(filter);
target.setRequired(true);
controller.chooseTarget(Outcome.Benefit, target, abilityToModify, game);
UUID cardId = target.getFirstTarget();
if (cardId != null) {
SpliceOntoArcaneAbility selectedAbility = null;
for(SpliceOntoArcaneAbility ability :spliceAbilities) {
if (ability.getSourceId().equals(cardId)) {
selectedAbility = ability;
break;
}
}
if (selectedAbility != null) {
SpliceCardEffect spliceEffect = (SpliceCardEffect) selectedAbility.getEffects().get(0);
spliceEffect.apply(game, selectedAbility, abilityToModify);
cardsToReveal.add(game.getCard(cardId));
spliceAbilities.remove(selectedAbility);
}
}
} while (!spliceAbilities.isEmpty() && controller.chooseUse(Outcome.Benefit, "Splice another card?", game));
controller.revealCards("Spliced cards", cardsToReveal, game);
}
}
}

View file

@ -106,6 +106,7 @@ public class SpliceOntoArcaneAbility extends SimpleStaticAbility {
private static final String KEYWORD_TEXT = "Splice onto Arcane";
private Costs spliceCosts = new CostsImpl();
private boolean nonManaCosts = false;
public SpliceOntoArcaneAbility(String manaString) {
super(Zone.HAND, new SpliceOntoArcaneEffect());
@ -115,11 +116,13 @@ public class SpliceOntoArcaneAbility extends SimpleStaticAbility {
public SpliceOntoArcaneAbility(Cost cost) {
super(Zone.HAND, new SpliceOntoArcaneEffect());
spliceCosts.add(cost);
nonManaCosts = true;
}
public SpliceOntoArcaneAbility(final SpliceOntoArcaneAbility ability) {
super(ability);
this.spliceCosts = ability.spliceCosts.copy();
this.nonManaCosts = ability.nonManaCosts;
}
@Override
@ -134,9 +137,9 @@ public class SpliceOntoArcaneAbility extends SimpleStaticAbility {
@Override
public String getRule() {
StringBuilder sb = new StringBuilder();
sb.append(KEYWORD_TEXT).append(" ");
sb.append(spliceCosts.getText());
sb.append(" <i>(As you cast an Arcane spell, you may reveal this card from your hand and pay its splice cost. If you do, add this card's effects to that spell.)</i>");
sb.append(KEYWORD_TEXT).append(nonManaCosts?"-":" ");
sb.append(spliceCosts.getText()).append(nonManaCosts?". ":" ");
sb.append("<i>(As you cast an Arcane spell, you may reveal this card from your hand and pay its splice cost. If you do, add this card's effects to that spell.)</i>");
return sb.toString();
}
}
@ -165,24 +168,19 @@ class SpliceOntoArcaneEffect extends SpliceCardEffectImpl<SpliceOntoArcaneEffect
Player controller = game.getPlayer(source.getControllerId());
Card spliceCard = game.getCard(source.getSourceId());
if (spliceCard != null && controller != null) {
if (controller.chooseUse(outcome, new StringBuilder("Splice ").append(spliceCard.getName())
.append(" ").append(((SpliceOntoArcaneAbility) source).getSpliceCosts().getText()).append("?").toString(), game)) {
Spell spell = game.getStack().getSpell(abilityToModify.getId());
if (spell != null) {
SpellAbility splicedAbility = spliceCard.getSpellAbility().copy();
splicedAbility.setSpellAbilityType(SpellAbilityType.SPLICE);
splicedAbility.setSourceId(abilityToModify.getSourceId());
spell.addSpellAbility(splicedAbility);
for (Iterator it = ((SpliceOntoArcaneAbility) source).getSpliceCosts().iterator(); it.hasNext();) {
Cost cost = (Cost) it.next();
if (cost instanceof ManaCostsImpl) {
spell.getSpellAbility().getManaCostsToPay().add((ManaCostsImpl) cost.copy());
} else {
spell.getSpellAbility().getCosts().add(cost.copy());
}
Spell spell = game.getStack().getSpell(abilityToModify.getId());
if (spell != null) {
SpellAbility splicedAbility = spliceCard.getSpellAbility().copy();
splicedAbility.setSpellAbilityType(SpellAbilityType.SPLICE);
splicedAbility.setSourceId(abilityToModify.getSourceId());
spell.addSpellAbility(splicedAbility);
for (Iterator it = ((SpliceOntoArcaneAbility) source).getSpliceCosts().iterator(); it.hasNext();) {
Cost cost = (Cost) it.next();
if (cost instanceof ManaCostsImpl) {
spell.getSpellAbility().getManaCostsToPay().add((ManaCostsImpl) cost.copy());
} else {
spell.getSpellAbility().getCosts().add(cost.copy());
}
// reveal the spliced card
controller.revealCards("Spliced card", new CardsImpl(spliceCard), game);
}
}
return true;