Update to split cards functionality. Fuse and flashback works now. No correct ability filtering yet for split cards.

This commit is contained in:
LevelX2 2013-05-07 00:44:57 +02:00
parent 623264d9c0
commit b01cb551b7
11 changed files with 301 additions and 226 deletions

View file

@ -108,7 +108,7 @@ class ChainOfVaporEffect extends OneShotEffect<ChainOfVaporEffect> {
copy.setCopiedSpell(true); copy.setCopiedSpell(true);
game.getStack().push(copy); game.getStack().push(copy);
copy.chooseNewTargets(game, source.getControllerId()); copy.chooseNewTargets(game, source.getControllerId());
String activateMessage = copy.getSpellAbility().getActivatedMessage(game); String activateMessage = copy.getActivatedMessage(game);
if (activateMessage.startsWith(" casts ")) { if (activateMessage.startsWith(" casts ")) {
activateMessage = activateMessage.substring(6); activateMessage = activateMessage.substring(6);
} }

View file

@ -154,6 +154,27 @@ public final class Constants {
} }
} }
public enum SpellAbilityType {
BASE("Basic SpellAbility"),
SPLIT("Split SpellAbility"),
SPLIT_FUSED("Split SpellAbility"),
SPLIT_LEFT("LeftSplit SpellAbility"),
SPLIT_RIGHT("RightSplit SpellAbility"),
MODE("Mode SpellAbility"),
SPLICE("Spliced SpellAbility");
private String text;
SpellAbilityType(String text) {
this.text = text;
}
@Override
public String toString() {
return text;
}
}
public enum EffectType { public enum EffectType {
ONESHOT("One Shot Effect"), ONESHOT("One Shot Effect"),

View file

@ -40,6 +40,7 @@ import mage.abilities.keyword.FlashAbility;
import mage.game.Game; import mage.game.Game;
import java.util.UUID; import java.util.UUID;
import mage.Constants.SpellAbilityType;
/** /**
* *
@ -47,23 +48,39 @@ import java.util.UUID;
*/ */
public class SpellAbility extends ActivatedAbilityImpl<SpellAbility> { public class SpellAbility extends ActivatedAbilityImpl<SpellAbility> {
private SpellAbilityType spellAbilityType;
public SpellAbility(ManaCost cost, String cardName) { public SpellAbility(ManaCost cost, String cardName) {
this(cost, cardName, Zone.HAND); this(cost, cardName, Zone.HAND);
} }
public SpellAbility(ManaCost cost, String cardName, Zone zone) { public SpellAbility(ManaCost cost, String cardName, Zone zone) {
super(AbilityType.SPELL, zone); this(cost, cardName, zone, SpellAbilityType.BASE);
this.addManaCost(cost);
this.name = "Cast " + cardName;
} }
public SpellAbility(Cost cost, String cardName, Effect effect, Zone zone) { public SpellAbility(ManaCost cost, String cardName, Zone zone, SpellAbilityType spellAbilityType) {
super(zone, effect, cost); super(AbilityType.SPELL, zone);
this.name = "Cast " + cardName; this.spellAbilityType = spellAbilityType;
this.addManaCost(cost);
switch(spellAbilityType) {
case SPLIT_FUSED:
this.name = "Cast fused " + cardName;
break;
default:
this.name = "Cast " + cardName;
}
} }
// public SpellAbility(Cost cost, String cardName, Effect effect, Zone zone) {
// super(zone, effect, cost);
// this.spellAbilityType = SpellAbilityType.BASE;
// this.name = "Cast " + cardName;
// }
public SpellAbility(SpellAbility ability) { public SpellAbility(SpellAbility ability) {
super(ability); super(ability);
this.spellAbilityType = ability.spellAbilityType;
} }
@Override @Override
@ -124,4 +141,12 @@ public class SpellAbility extends ActivatedAbilityImpl<SpellAbility> {
return spell; return spell;
} }
public SpellAbilityType getSpellAbilityType() {
return spellAbilityType;
}
public void setSpellAbilityType(SpellAbilityType spellAbilityType) {
this.spellAbilityType = spellAbilityType;
}
} }

View file

@ -61,7 +61,7 @@ public class CopyTargetSpellEffect extends OneShotEffect<CopyTargetSpellEffect>
game.getStack().push(copy); game.getStack().push(copy);
copy.chooseNewTargets(game, source.getControllerId()); copy.chooseNewTargets(game, source.getControllerId());
Player player = game.getPlayer(source.getControllerId()); Player player = game.getPlayer(source.getControllerId());
String activateMessage = copy.getSpellAbility().getActivatedMessage(game); String activateMessage = copy.getActivatedMessage(game);
if (activateMessage.startsWith(" casts ")) { if (activateMessage.startsWith(" casts ")) {
activateMessage = activateMessage.substring(6); activateMessage = activateMessage.substring(6);
} }

View file

@ -28,14 +28,18 @@
package mage.abilities.keyword; package mage.abilities.keyword;
import mage.Constants; import mage.Constants;
import mage.Constants.SpellAbilityType;
import static mage.Constants.SpellAbilityType.SPLIT_LEFT;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.ActivatedAbilityImpl; import mage.abilities.ActivatedAbilityImpl;
import mage.abilities.DelayedTriggeredAbility; import mage.abilities.DelayedTriggeredAbility;
import mage.abilities.SpellAbility;
import mage.abilities.costs.Cost; import mage.abilities.costs.Cost;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect; import mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect;
import mage.abilities.effects.common.ExileSourceEffect; import mage.abilities.effects.common.ExileSourceEffect;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.SplitCard;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent; import mage.game.events.ZoneChangeEvent;
@ -48,16 +52,22 @@ import mage.target.Target;
*/ */
public class FlashbackAbility extends /*SpellAbility*/ ActivatedAbilityImpl<FlashbackAbility> { public class FlashbackAbility extends /*SpellAbility*/ ActivatedAbilityImpl<FlashbackAbility> {
private Constants.SpellAbilityType spellAbilityType;
private String abilityName;
public FlashbackAbility(Cost cost, Constants.TimingRule timingRule) { public FlashbackAbility(Cost cost, Constants.TimingRule timingRule) {
//super(cost, "", new FlashbackEffect(), Constants.Zone.GRAVEYARD); //super(cost, "", new FlashbackEffect(), Constants.Zone.GRAVEYARD);
super(Constants.Zone.GRAVEYARD, new FlashbackEffect(), cost); super(Constants.Zone.GRAVEYARD, new FlashbackEffect(), cost);
this.timing = timingRule; this.timing = timingRule;
this.usesStack = false; this.usesStack = false;
this.spellAbilityType = SpellAbilityType.BASE;
this.addEffect(new CreateDelayedTriggeredAbilityEffect(new FlashbackTriggeredAbility())); this.addEffect(new CreateDelayedTriggeredAbilityEffect(new FlashbackTriggeredAbility()));
} }
public FlashbackAbility(final FlashbackAbility ability) { public FlashbackAbility(final FlashbackAbility ability) {
super(ability); super(ability);
this.spellAbilityType = ability.spellAbilityType;
this.abilityName = ability.abilityName;
} }
@Override @Override
@ -65,11 +75,16 @@ public class FlashbackAbility extends /*SpellAbility*/ ActivatedAbilityImpl<Flas
return new FlashbackAbility(this); return new FlashbackAbility(this);
} }
@Override
public String getRule(boolean all) {
return this.getRule();
}
@Override @Override
public String getRule() { public String getRule() {
StringBuilder sbRule = new StringBuilder("Flashback"); StringBuilder sbRule = new StringBuilder("Flashback");
if (costs.size() > 0) { if (costs.size() > 0) {
sbRule.append("--"); sbRule.append(" - ");
} else { } else {
sbRule.append(" "); sbRule.append(" ");
} }
@ -80,9 +95,26 @@ public class FlashbackAbility extends /*SpellAbility*/ ActivatedAbilityImpl<Flas
sbRule.append(costs.getText()); sbRule.append(costs.getText());
sbRule.append("."); sbRule.append(".");
} }
if (abilityName != null) {
sbRule.append(" ");
sbRule.append(abilityName);
}
sbRule.append(" <i>(You may cast this card from your graveyard for its flashback cost. Then exile it.)</i>"); sbRule.append(" <i>(You may cast this card from your graveyard for its flashback cost. Then exile it.)</i>");
return sbRule.toString(); return sbRule.toString();
} }
public void setSpellAbilityType(SpellAbilityType spellAbilityType) {
this.spellAbilityType = spellAbilityType;
}
public SpellAbilityType getSpellAbilityType() {
return this.spellAbilityType;
}
public void setAbilityName(String abilityName) {
this.abilityName = abilityName;
}
} }
class FlashbackEffect extends OneShotEffect<FlashbackEffect> { class FlashbackEffect extends OneShotEffect<FlashbackEffect> {
@ -107,13 +139,25 @@ class FlashbackEffect extends OneShotEffect<FlashbackEffect> {
if (card != null) { if (card != null) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
if (controller != null) { if (controller != null) {
card.getSpellAbility().clear(); SpellAbility spellAbility;
switch(((FlashbackAbility) source).getSpellAbilityType()) {
case SPLIT_LEFT:
spellAbility = ((SplitCard)card).getLeftHalfCard().getSpellAbility();
break;
case SPLIT_RIGHT:
spellAbility = ((SplitCard)card).getRightHalfCard().getSpellAbility();
break;
default:
spellAbility = card.getSpellAbility();
}
spellAbility.clear();
int amount = source.getManaCostsToPay().getX(); int amount = source.getManaCostsToPay().getX();
card.getSpellAbility().getManaCostsToPay().setX(amount); spellAbility.getManaCostsToPay().setX(amount);
for (Target target : card.getSpellAbility().getTargets()) { for (Target target : spellAbility.getTargets()) {
target.setRequired(true); target.setRequired(true);
} }
return controller.cast(card.getSpellAbility(), game, true); return controller.cast(spellAbility, game, true);
} }
} }
return false; return false;

View file

@ -1,66 +0,0 @@
/*
* 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.keyword;
import mage.Constants.Zone;
import mage.abilities.SpellAbility;
import mage.abilities.costs.mana.ManaCosts;
import mage.cards.Card;
/**
*
* @author LevelX2
*/
public class FuseAbility extends SpellAbility {
public FuseAbility(Card card, ManaCosts costs) {
super(costs, "fused " + card.getName(), Zone.HAND);
}
public FuseAbility(final FuseAbility ability) {
super(ability);
}
@Override
public FuseAbility copy() {
return new FuseAbility(this);
}
@Override
public String getRule(boolean all) {
return getRule();
}
@Override
public String getRule() {
return "Fuse <i>(You may cast one or both halves of this card from your hand.)</i>";
}
}

View file

@ -49,6 +49,7 @@ import org.apache.log4j.Logger;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.util.*; import java.util.*;
import mage.Constants.SpellAbilityType;
public abstract class CardImpl<T extends CardImpl<T>> extends MageObjectImpl<T> implements Card { public abstract class CardImpl<T extends CardImpl<T>> extends MageObjectImpl<T> implements Card {
@ -75,6 +76,10 @@ public abstract class CardImpl<T extends CardImpl<T>> extends MageObjectImpl<T>
protected boolean splitCard; protected boolean splitCard;
public CardImpl(UUID ownerId, int cardNumber, String name, Rarity rarity, CardType[] cardTypes, String costs) { public CardImpl(UUID ownerId, int cardNumber, String name, Rarity rarity, CardType[] cardTypes, String costs) {
this(ownerId, cardNumber, name, rarity, cardTypes, costs, SpellAbilityType.BASE);
}
public CardImpl(UUID ownerId, int cardNumber, String name, Rarity rarity, CardType[] cardTypes, String costs, SpellAbilityType spellAbilityType) {
this(ownerId, name); this(ownerId, name);
this.rarity = rarity; this.rarity = rarity;
this.cardNumber = cardNumber; this.cardNumber = cardNumber;
@ -84,7 +89,7 @@ public abstract class CardImpl<T extends CardImpl<T>> extends MageObjectImpl<T>
addAbility(new PlayLandAbility(name)); addAbility(new PlayLandAbility(name));
} }
else { else {
addAbility(new SpellAbility(manaCost, name)); addAbility(new SpellAbility(manaCost, name, Zone.HAND, spellAbilityType));
} }
this.usesVariousArt = Character.isDigit(this.getClass().getName().charAt(this.getClass().getName().length()-1)); this.usesVariousArt = Character.isDigit(this.getClass().getName().charAt(this.getClass().getName().length()-1));
this.counters = new Counters(); this.counters = new Counters();

View file

@ -31,16 +31,13 @@ package mage.cards;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import mage.Constants;
import mage.Constants.CardType; import mage.Constants.CardType;
import mage.Constants.Rarity; import mage.Constants.Rarity;
import mage.Constants.Zone; import mage.Constants.SpellAbilityType;
import mage.abilities.Abilities; import mage.abilities.Abilities;
import mage.abilities.AbilitiesImpl; import mage.abilities.AbilitiesImpl;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.SpellAbility; import mage.abilities.SpellAbility;
import mage.abilities.keyword.FuseAbility;
import mage.game.Game;
import mage.watchers.Watcher; import mage.watchers.Watcher;
/** /**
@ -50,16 +47,11 @@ import mage.watchers.Watcher;
public abstract class SplitCard<T extends SplitCard<T>> extends CardImpl<T> { public abstract class SplitCard<T extends SplitCard<T>> extends CardImpl<T> {
public enum ActiveCardHalf {
NONE, LEFT, RIGHT, BOTH
}
private Card leftHalfCard; private Card leftHalfCard;
private Card rightHalfCard; private Card rightHalfCard;
private ActiveCardHalf activeCardHalf = ActiveCardHalf.NONE; public SplitCard(UUID ownerId, int cardNumber, String nameLeft, String nameRight, Rarity rarity, CardType[] cardTypes, String costsLeft, String costsRight, boolean fused) {
super(ownerId, cardNumber, new StringBuilder(nameLeft).append(" - ").append(nameRight).toString(), rarity, cardTypes, costsLeft + costsRight, (fused ?SpellAbilityType.SPLIT_FUSED:SpellAbilityType.SPLIT));
public SplitCard(UUID ownerId, int cardNumber, String nameLeft, String nameRight, Rarity rarity, CardType[] cardTypes, String costsLeft, String costsRight) {
super(ownerId, cardNumber, new StringBuilder(nameLeft).append(" - ").append(nameRight).toString(), rarity, cardTypes, costsLeft + costsRight);
this.createLeftHalfCard(nameLeft, costsLeft); this.createLeftHalfCard(nameLeft, costsLeft);
this.createRightHalfCard(nameRight, costsRight); this.createRightHalfCard(nameRight, costsRight);
this.splitCard = true; this.splitCard = true;
@ -69,7 +61,6 @@ public abstract class SplitCard<T extends SplitCard<T>> extends CardImpl<T> {
super(card); super(card);
this.leftHalfCard = card.leftHalfCard.copy(); this.leftHalfCard = card.leftHalfCard.copy();
this.rightHalfCard = card.rightHalfCard.copy(); this.rightHalfCard = card.rightHalfCard.copy();
this.activeCardHalf = card.activeCardHalf;
} }
private Card createLeftHalfCard (String nameLeft, String costsLeft) { private Card createLeftHalfCard (String nameLeft, String costsLeft) {
@ -83,7 +74,7 @@ public abstract class SplitCard<T extends SplitCard<T>> extends CardImpl<T> {
private Card createRightHalfCard (String nameRight, String costsRight) { private Card createRightHalfCard (String nameRight, String costsRight) {
CardType[] cardTypes = new CardType[getCardType().size()]; CardType[] cardTypes = new CardType[getCardType().size()];
this.getCardType().toArray(cardTypes); this.getCardType().toArray(cardTypes);
rightHalfCard = new LeftHalfCard(this.getOwnerId(), this.getCardNumber(), nameRight, this.rarity, cardTypes, costsRight); rightHalfCard = new RightHalfCard(this.getOwnerId(), this.getCardNumber(), nameRight, this.rarity, cardTypes, costsRight);
rightHalfCard.getAbilities().setSourceId(objectId); rightHalfCard.getAbilities().setSourceId(objectId);
return rightHalfCard; return rightHalfCard;
} }
@ -98,96 +89,28 @@ public abstract class SplitCard<T extends SplitCard<T>> extends CardImpl<T> {
return rightHalfCard; return rightHalfCard;
} }
public ActiveCardHalf getActiveCardHalf() {
return activeCardHalf;
}
@Override
public boolean cast(Game game, Constants.Zone fromZone, SpellAbility ability, UUID controllerId) {
if (this.getAbilities().contains(ability)) {
activeCardHalf = ActiveCardHalf.BOTH;
} else if (leftHalfCard.getAbilities().contains(ability)) {
activeCardHalf = ActiveCardHalf.LEFT;
} else if (rightHalfCard.getAbilities().contains(ability)) {
activeCardHalf = ActiveCardHalf.RIGHT;
} else {
activeCardHalf = ActiveCardHalf.NONE;
}
if (super.cast(game, fromZone, ability, controllerId)) {
return true;
}
activeCardHalf = ActiveCardHalf.NONE;
return false;
}
@Override
public boolean moveToZone(Constants.Zone toZone, UUID sourceId, Game game, boolean flag, ArrayList<UUID> appliedEffects) {
if (super.moveToZone(toZone, sourceId, game, flag, appliedEffects)) {
if (!toZone.equals(Zone.STACK)) {
activeCardHalf = ActiveCardHalf.NONE;
}
return true;
}
return false;
}
@Override
public boolean moveToExile(UUID exileId, String name, UUID sourceId, Game game, ArrayList<UUID> appliedEffects) {
if(super.moveToExile(exileId, name, sourceId, game, appliedEffects)) {
activeCardHalf = ActiveCardHalf.NONE;
return true;
}
return false;
}
@Override @Override
public Abilities<Ability> getAbilities(){ public Abilities<Ability> getAbilities(){
Abilities<Ability> allAbilites = new AbilitiesImpl<Ability>(); Abilities<Ability> allAbilites = new AbilitiesImpl<Ability>();
if (activeCardHalf.equals(ActiveCardHalf.NONE) || activeCardHalf.equals(ActiveCardHalf.LEFT)) { for (Ability ability : super.getAbilities()) {
allAbilites.addAll(leftHalfCard.getAbilities()); if (ability instanceof SpellAbility && !((SpellAbility)ability).getSpellAbilityType().equals(SpellAbilityType.SPLIT)) {
}
if (activeCardHalf.equals(ActiveCardHalf.NONE) || activeCardHalf.equals(ActiveCardHalf.RIGHT)) {
allAbilites.addAll(rightHalfCard.getAbilities());
}
for (Ability ability: super.getAbilities()) {
if (ability instanceof FuseAbility) {
allAbilites.add(ability); allAbilites.add(ability);
} }
} }
allAbilites.addAll(super.getAbilities());
allAbilites.addAll(leftHalfCard.getAbilities());
allAbilites.addAll(rightHalfCard.getAbilities());
return allAbilites; return allAbilites;
} }
@Override
public SpellAbility getSpellAbility() {
switch (activeCardHalf) {
case LEFT:
return leftHalfCard.getSpellAbility();
case RIGHT:
return rightHalfCard.getSpellAbility();
}
return null;
}
@Override @Override
public List<String> getRules() { public List<String> getRules() {
List<String> rules = new ArrayList<String>(); List<String> rules = new ArrayList<String>();
if (activeCardHalf.equals(ActiveCardHalf.NONE) || activeCardHalf.equals(ActiveCardHalf.LEFT)) { rules.addAll(leftHalfCard.getRules());
rules.add(new StringBuilder("<b>").append(leftHalfCard.getName()).append("<b/>").toString()); rules.addAll(rightHalfCard.getRules());
rules.addAll(leftHalfCard.getRules()); if (getSpellAbility().getSpellAbilityType().equals(SpellAbilityType.SPLIT_FUSED)) {
} rules.add("------------------------------------------------------------------------");
if (activeCardHalf.equals(ActiveCardHalf.NONE)) { rules.add("Fuse (You may cast one or both halves of this card from your hand.)");
rules.add("<br/>");
}
if (activeCardHalf.equals(ActiveCardHalf.NONE) || activeCardHalf.equals(ActiveCardHalf.RIGHT)) {
rules.add(new StringBuilder("<b>").append(rightHalfCard.getName()).append("<b/>").toString());
rules.addAll(rightHalfCard.getRules());
}
for (Ability ability: super.getAbilities()) {
if (ability instanceof FuseAbility) {
rules.add("<br/>------------------------------------------------------------");
rules.add(ability.getRule());
}
} }
return rules; return rules;
} }
@ -213,14 +136,9 @@ public abstract class SplitCard<T extends SplitCard<T>> extends CardImpl<T> {
@Override @Override
public List<Watcher> getWatchers() { public List<Watcher> getWatchers() {
List<Watcher> allWatchers = new ArrayList<Watcher>(); List<Watcher> allWatchers = new ArrayList<Watcher>();
switch (activeCardHalf) { allWatchers.addAll(super.getWatchers());
case LEFT: allWatchers.addAll(leftHalfCard.getWatchers());
allWatchers.addAll(leftHalfCard.getWatchers()); allWatchers.addAll(rightHalfCard.getWatchers());
break;
case RIGHT:
allWatchers.addAll(rightHalfCard.getWatchers());
break;
}
return allWatchers; return allWatchers;
} }
} }
@ -230,8 +148,8 @@ public abstract class SplitCard<T extends SplitCard<T>> extends CardImpl<T> {
*/ */
class LeftHalfCard extends CardImpl<LeftHalfCard> { class LeftHalfCard extends CardImpl<LeftHalfCard> {
public LeftHalfCard(UUID ownerId, int cardNumber, String name, Rarity rarity, CardType[] cardTypes, String costs) { public LeftHalfCard(UUID ownerId, int cardNumber, String name, Rarity rarity, CardType[] cardTypes, String costs ) {
super(ownerId, cardNumber, name, rarity, cardTypes, costs); super(ownerId, cardNumber, name, rarity, cardTypes, costs, SpellAbilityType.SPLIT_LEFT);
} }
public LeftHalfCard(final LeftHalfCard card) { public LeftHalfCard(final LeftHalfCard card) {
@ -242,6 +160,16 @@ class LeftHalfCard extends CardImpl<LeftHalfCard> {
public LeftHalfCard copy() { public LeftHalfCard copy() {
return new LeftHalfCard(this); return new LeftHalfCard(this);
} }
@Override
public List<String> getRules() {
List<String> rules = new ArrayList<String>();
rules.add(new StringBuilder("<b>").append(this.getName()).append("<b/>").toString());
rules.addAll(super.getRules());
return rules;
}
} }
/* /*
@ -250,7 +178,7 @@ class LeftHalfCard extends CardImpl<LeftHalfCard> {
class RightHalfCard extends CardImpl<RightHalfCard> { class RightHalfCard extends CardImpl<RightHalfCard> {
public RightHalfCard(UUID ownerId, int cardNumber, String name, Rarity rarity, CardType[] cardTypes, String costs) { public RightHalfCard(UUID ownerId, int cardNumber, String name, Rarity rarity, CardType[] cardTypes, String costs) {
super(ownerId, cardNumber, name, rarity, cardTypes, costs); super(ownerId, cardNumber, name, rarity, cardTypes, costs, SpellAbilityType.SPLIT_RIGHT);
} }
public RightHalfCard(final RightHalfCard card) { public RightHalfCard(final RightHalfCard card) {
@ -261,4 +189,12 @@ class RightHalfCard extends CardImpl<RightHalfCard> {
public RightHalfCard copy() { public RightHalfCard copy() {
return new RightHalfCard(this); return new RightHalfCard(this);
} }
@Override
public List<String> getRules() {
List<String> rules = new ArrayList<String>();
rules.add(new StringBuilder("<b>").append(this.getName()).append("<b/>").toString());
rules.addAll(super.getRules());
return rules;
}
} }

View file

@ -37,6 +37,7 @@ import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.ContinuousEffects; import mage.abilities.effects.ContinuousEffects;
import mage.abilities.effects.Effect; import mage.abilities.effects.Effect;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.SplitCard;
import mage.choices.Choice; import mage.choices.Choice;
import mage.game.combat.Combat; import mage.game.combat.Combat;
import mage.game.combat.CombatGroup; import mage.game.combat.CombatGroup;
@ -454,6 +455,10 @@ public class GameState implements Serializable, Copyable<GameState> {
for (Ability ability: card.getAbilities()) { for (Ability ability: card.getAbilities()) {
addAbility(ability, card); addAbility(ability, card);
} }
if (card.isSplitCard()) {
addCard( ((SplitCard)card).getLeftHalfCard());
addCard( ((SplitCard)card).getRightHalfCard());
}
} }
@Deprecated @Deprecated

View file

@ -55,6 +55,10 @@ import mage.watchers.Watcher;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import mage.Constants;
import static mage.Constants.SpellAbilityType.SPLIT_LEFT;
import static mage.Constants.SpellAbilityType.SPLIT_RIGHT;
import mage.cards.SplitCard;
/** /**
* *
@ -62,35 +66,87 @@ import java.util.UUID;
*/ */
public class Spell<T extends Spell<T>> implements StackObject, Card { public class Spell<T extends Spell<T>> implements StackObject, Card {
private List<Card> spellCards = new ArrayList<Card>();
private List<SpellAbility> spellAbilities = new ArrayList<SpellAbility>();
private Card card; private Card card;
private SpellAbility ability; private SpellAbility ability;
private UUID controllerId; private UUID controllerId;
private boolean copiedSpell; private boolean copiedSpell;
private Zone fromZone; private Zone fromZone;
private UUID id;
public Spell(Card card, SpellAbility ability, UUID controllerId, Zone fromZone) { public Spell(Card card, SpellAbility ability, UUID controllerId, Zone fromZone) {
this.card = card; this.card = card;
id = ability.getId();
this.ability = ability; this.ability = ability;
this.ability.setControllerId(controllerId); this.ability.setControllerId(controllerId);
if (ability.getSpellAbilityType().equals(Constants.SpellAbilityType.SPLIT_FUSED)) {
spellCards.add(((SplitCard) card).getLeftHalfCard());
spellAbilities.add(((SplitCard) card).getLeftHalfCard().getSpellAbility().copy());
spellCards.add(((SplitCard) card).getRightHalfCard());
spellAbilities.add(((SplitCard) card).getRightHalfCard().getSpellAbility().copy());
} else {
spellCards.add(card);
spellAbilities.add(ability);
}
this.controllerId = controllerId; this.controllerId = controllerId;
this.fromZone = fromZone; this.fromZone = fromZone;
} }
public Spell(final Spell<T> spell) { public Spell(final Spell<T> spell) {
this.card = spell.card.copy(); this.id = spell.id;
this.ability = spell.ability.copy(); for (SpellAbility spellAbility: spell.spellAbilities) {
this.spellAbilities.add(spellAbility.copy());
}
for (Card spellCard: spell.spellCards) {
this.spellCards.add(spellCard.copy());
}
if (spell.spellAbilities.get(0).equals(spell.ability)) {
this.ability = spellAbilities.get(0);
} else {
this.ability = spell.ability.copy();
}
if (spell.spellCards.get(0).equals(spell.card)) {
this.card = spellCards.get(0);
} else {
this.card = spell.card.copy();
}
this.controllerId = spell.controllerId; this.controllerId = spell.controllerId;
this.fromZone = spell.fromZone; this.fromZone = spell.fromZone;
this.copiedSpell = spell.copiedSpell; this.copiedSpell = spell.copiedSpell;
} }
public boolean activate(Game game, boolean noMana) {
for (SpellAbility spellAbility: spellAbilities) {
if (!spellAbility.activate(game, noMana)) {
return false;
}
}
return true;
}
public String getActivatedMessage(Game game) {
return ability.getActivatedMessage(game);
}
@Override @Override
public boolean resolve(Game game) { public boolean resolve(Game game) {
boolean result; boolean result;
if (card.getCardType().contains(CardType.INSTANT) || card.getCardType().contains(CardType.SORCERY)) { if (card.getCardType().contains(CardType.INSTANT) || card.getCardType().contains(CardType.SORCERY)) {
if (ability.getTargets().stillLegal(ability, game)) { int index = 0;
updateOptionalCosts(); result = false;
result = ability.resolve(game); boolean legalParts = false;
for(SpellAbility spellAbility: this.spellAbilities) {
if (spellAbility.getTargets().stillLegal(ability, game)) {
legalParts = true;
updateOptionalCosts(index);
result |= spellAbility.resolve(game);
}
index++;
}
if (legalParts) {
if (!copiedSpell) { if (!copiedSpell) {
for (Effect effect : ability.getEffects()) { for (Effect effect : ability.getEffects()) {
if (effect instanceof PostResolveEffect) { if (effect instanceof PostResolveEffect) {
@ -102,7 +158,6 @@ public class Spell<T extends Spell<T>> implements StackObject, Card {
card.moveToZone(Zone.GRAVEYARD, ability.getId(), game, false); card.moveToZone(Zone.GRAVEYARD, ability.getId(), game, false);
} }
} }
return result; return result;
} }
//20091005 - 608.2b //20091005 - 608.2b
@ -111,7 +166,7 @@ public class Spell<T extends Spell<T>> implements StackObject, Card {
return false; return false;
} else if (card.getCardType().contains(CardType.ENCHANTMENT) && card.getSubtype().contains("Aura")) { } else if (card.getCardType().contains(CardType.ENCHANTMENT) && card.getSubtype().contains("Aura")) {
if (ability.getTargets().stillLegal(ability, game)) { if (ability.getTargets().stillLegal(ability, game)) {
updateOptionalCosts(); updateOptionalCosts(0);
if (card.putOntoBattlefield(game, Zone.HAND, ability.getId(), controllerId)) { if (card.putOntoBattlefield(game, Zone.HAND, ability.getId(), controllerId)) {
return ability.resolve(game); return ability.resolve(game);
} }
@ -122,7 +177,7 @@ public class Spell<T extends Spell<T>> implements StackObject, Card {
counter(null, game); counter(null, game);
return false; return false;
} else { } else {
updateOptionalCosts(); updateOptionalCosts(0);
result = card.putOntoBattlefield(game, Zone.HAND, ability.getId(), controllerId); result = card.putOntoBattlefield(game, Zone.HAND, ability.getId(), controllerId);
return result; return result;
} }
@ -133,10 +188,10 @@ public class Spell<T extends Spell<T>> implements StackObject, Card {
* This information will be used later by effects, e.g. to determine whether card was kicked or not. * This information will be used later by effects, e.g. to determine whether card was kicked or not.
* E.g. Desolation Angel * E.g. Desolation Angel
*/ */
private void updateOptionalCosts() { private void updateOptionalCosts(int index) {
Ability abilityOrig = card.getAbilities().get(ability.getId()); Ability abilityOrig = spellCards.get(index).getAbilities().get(spellAbilities.get(index).getId());
if (abilityOrig != null) { if (abilityOrig != null) {
for (Object object : ability.getOptionalCosts()) { for (Object object : spellAbilities.get(index).getOptionalCosts()) {
Cost cost = (Cost) object; Cost cost = (Cost) object;
for (Cost costOrig : abilityOrig.getOptionalCosts()) { for (Cost costOrig : abilityOrig.getOptionalCosts()) {
if (cost.getId().equals(costOrig.getId())) { if (cost.getId().equals(costOrig.getId())) {
@ -163,29 +218,31 @@ public class Spell<T extends Spell<T>> implements StackObject, Card {
public boolean chooseNewTargets(Game game, UUID playerId) { public boolean chooseNewTargets(Game game, UUID playerId) {
Player player = game.getPlayer(playerId); Player player = game.getPlayer(playerId);
if (player != null) { if (player != null) {
for (Target target: ability.getTargets()) { for(SpellAbility spellAbility: spellAbilities) {
Target newTarget = target.copy(); for (Target target: spellAbility.getTargets()) {
newTarget.clearChosen(); Target newTarget = target.copy();
for (UUID targetId: target.getTargets()) { newTarget.clearChosen();
MageObject object = game.getObject(targetId); for (UUID targetId: target.getTargets()) {
String name = null; MageObject object = game.getObject(targetId);
if (object == null) { String name = null;
Player targetPlayer = game.getPlayer(targetId); if (object == null) {
if (targetPlayer != null) name = targetPlayer.getName(); Player targetPlayer = game.getPlayer(targetId);
} else { if (targetPlayer != null) name = targetPlayer.getName();
name = object.getName(); } else {
name = object.getName();
}
if (name != null && player.chooseUse(spellAbility.getEffects().get(0).getOutcome(), "Change target from " + name + "?", game)) {
if (!player.chooseTarget(spellAbility.getEffects().get(0).getOutcome(), newTarget, spellAbility, game))
newTarget.addTarget(targetId, spellAbility, game, false);
}
else {
newTarget.addTarget(targetId, spellAbility, game, false);
}
} }
if (name != null && player.chooseUse(ability.getEffects().get(0).getOutcome(), "Change target from " + name + "?", game)) { target.clearChosen();
if (!player.chooseTarget(ability.getEffects().get(0).getOutcome(), newTarget, ability, game)) for (UUID newTargetId: newTarget.getTargets()) {
newTarget.addTarget(targetId, ability, game, false); target.addTarget(newTargetId, spellAbility, game, false);
} }
else {
newTarget.addTarget(targetId, ability, game, false);
}
}
target.clearChosen();
for (UUID newTargetId: newTarget.getTargets()) {
target.addTarget(newTargetId, ability, game, false);
} }
} }
return true; return true;
@ -271,7 +328,7 @@ public class Spell<T extends Spell<T>> implements StackObject, Card {
@Override @Override
public UUID getId() { public UUID getId() {
return ability.getId(); return id;
} }
@Override @Override
@ -293,6 +350,9 @@ public class Spell<T extends Spell<T>> implements StackObject, Card {
@Override @Override
public void setControllerId(UUID controllerId) { public void setControllerId(UUID controllerId) {
this.ability.setControllerId(controllerId); this.ability.setControllerId(controllerId);
for (SpellAbility spellAbility: spellAbilities) {
spellAbility.setControllerId(controllerId);
}
this.controllerId = controllerId; this.controllerId = controllerId;
} }
@ -301,12 +361,26 @@ public class Spell<T extends Spell<T>> implements StackObject, Card {
@Override @Override
public List<String> getRules() { public List<String> getRules() {
return card.getRules(); switch (ability.getSpellAbilityType()) {
case SPLIT_LEFT:
return ((SplitCard)card).getLeftHalfCard().getRules();
case SPLIT_RIGHT:
return ((SplitCard)card).getRightHalfCard().getRules();
default:
return card.getRules();
}
} }
@Override @Override
public List<Watcher> getWatchers() { public List<Watcher> getWatchers() {
return card.getWatchers(); switch (ability.getSpellAbilityType()) {
case SPLIT_LEFT:
return ((SplitCard)card).getLeftHalfCard().getWatchers();
case SPLIT_RIGHT:
return ((SplitCard)card).getLeftHalfCard().getWatchers();
default:
return card.getWatchers();
}
} }
@Override @Override

View file

@ -73,6 +73,10 @@ import org.apache.log4j.Logger;
import java.io.Serializable; import java.io.Serializable;
import java.util.*; import java.util.*;
import mage.Constants;
import mage.Constants.SpellAbilityType;
import mage.cards.SplitCard;
import mage.game.stack.Spell;
public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Serializable { public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Serializable {
@ -598,13 +602,12 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
int bookmark = game.bookmarkState(); int bookmark = game.bookmarkState();
Zone fromZone = game.getState().getZone(card.getId()); Zone fromZone = game.getState().getZone(card.getId());
card.cast(game, fromZone, ability, playerId); card.cast(game, fromZone, ability, playerId);
Spell spell = game.getStack().getSpell(ability.getId());
SpellAbility spellAbility = game.getStack().getSpell(ability.getId()).getSpellAbility(); if (spell.activate(game, noMana)) {
if (spellAbility.activate(game, noMana)) { GameEvent event = GameEvent.getEvent(GameEvent.EventType.SPELL_CAST, spell.getSpellAbility().getId(), spell.getSpellAbility().getSourceId(), playerId);
GameEvent event = GameEvent.getEvent(GameEvent.EventType.SPELL_CAST, spellAbility.getId(), spellAbility.getSourceId(), playerId);
event.setZone(fromZone); event.setZone(fromZone);
game.fireEvent(event); game.fireEvent(event);
game.fireInformEvent(name + spellAbility.getActivatedMessage(game)); game.fireInformEvent(new StringBuilder(name).append(spell.getActivatedMessage(game)).toString());
game.removeBookmark(bookmark); game.removeBookmark(bookmark);
resetStoredBookmark(game); resetStoredBookmark(game);
return true; return true;
@ -801,7 +804,35 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
Abilities<ActivatedAbility> otherAbilities = game.getState().getOtherAbilities(object.getId(), zone); Abilities<ActivatedAbility> otherAbilities = game.getState().getOtherAbilities(object.getId(), zone);
if (otherAbilities != null) { if (otherAbilities != null) {
for (ActivatedAbility ability: otherAbilities) { for (ActivatedAbility ability: otherAbilities) {
useable.put(ability.getId(), ability); Card card = game.getCard(ability.getSourceId());
if (card.isSplitCard() && ability instanceof FlashbackAbility) {
FlashbackAbility flashbackAbility;
if (card.getCardType().contains(Constants.CardType.INSTANT)) {
flashbackAbility = new FlashbackAbility(((SplitCard) card).getLeftHalfCard().getManaCost(), Constants.TimingRule.INSTANT);
}
else {
flashbackAbility = new FlashbackAbility(((SplitCard) card).getLeftHalfCard().getManaCost(), Constants.TimingRule.SORCERY);
}
flashbackAbility.setSourceId(card.getId());
flashbackAbility.setControllerId(card.getOwnerId());
flashbackAbility.setSpellAbilityType(SpellAbilityType.SPLIT_LEFT);
flashbackAbility.setAbilityName(((SplitCard) card).getLeftHalfCard().getName());
useable.put(flashbackAbility.getId(), flashbackAbility);
if (card.getCardType().contains(Constants.CardType.INSTANT)) {
flashbackAbility = new FlashbackAbility(((SplitCard) card).getRightHalfCard().getManaCost(), Constants.TimingRule.INSTANT);
}
else {
flashbackAbility = new FlashbackAbility(((SplitCard) card).getRightHalfCard().getManaCost(), Constants.TimingRule.SORCERY);
}
flashbackAbility.setSourceId(card.getId());
flashbackAbility.setControllerId(card.getOwnerId());
flashbackAbility.setSpellAbilityType(SpellAbilityType.SPLIT_RIGHT);
flashbackAbility.setAbilityName(((SplitCard) card).getRightHalfCard().getName());
useable.put(flashbackAbility.getId(), flashbackAbility);
} else {
useable.put(ability.getId(), ability);
}
} }
} }
return useable; return useable;