* Reworked some parts of transform handling. Fixes #2396.

This commit is contained in:
LevelX2 2016-09-28 17:02:37 +02:00
parent e57da7598e
commit 86648c7190
157 changed files with 246 additions and 204 deletions

View file

@ -83,7 +83,7 @@ public class DiesTriggeredAbility extends ZoneChangeTriggeredAbility {
public boolean checkTrigger(GameEvent event, Game game) {
if (super.checkTrigger(event, game)) {
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
if (zEvent.getTarget().canTransform()) {
if (zEvent.getTarget().isTransformable()) {
if (!zEvent.getTarget().getAbilities().contains(this)) {
return false;
}

View file

@ -459,7 +459,7 @@ public class ContinuousEffects implements Serializable {
exists = false;
if (object instanceof PermanentCard) {
PermanentCard permanent = (PermanentCard) object;
if (permanent.canTransform() && event.getType() == GameEvent.EventType.TRANSFORMED) {
if (permanent.isTransformable() && event.getType() == GameEvent.EventType.TRANSFORMED) {
exists = permanent.getCard().getAbilities().contains(ability);
}
}

View file

@ -84,7 +84,7 @@ public abstract class RestrictionEffect extends ContinuousEffectImpl {
public boolean canBeBlocked(Permanent attacker, Permanent blocker, Ability source, Game game) {
return true;
}
/**
* Called for all attackers after all blocking decisions are made
*
@ -106,7 +106,7 @@ public abstract class RestrictionEffect extends ContinuousEffectImpl {
return true;
}
public boolean canTransform(Game game) {
public boolean canTransform(Permanent permanent, Ability source, Game game) {
return true;
}

View file

@ -15,8 +15,8 @@ import mage.game.permanent.Permanent;
*
* @author halljared
*/
public class CantAttackBlockTransformAttachedEffect extends RestrictionEffect{
public class CantAttackBlockTransformAttachedEffect extends RestrictionEffect {
public CantAttackBlockTransformAttachedEffect() {
super(Duration.WhileOnBattlefield);
staticText = "Enchanted creature can't attack, block, or transform.";
@ -36,7 +36,7 @@ public class CantAttackBlockTransformAttachedEffect extends RestrictionEffect{
}
return false;
}
@Override
public boolean canAttack(Game game) {
return false;
@ -48,7 +48,7 @@ public class CantAttackBlockTransformAttachedEffect extends RestrictionEffect{
}
@Override
public boolean canTransform(Game game) {
public boolean canTransform(Permanent permanent, Ability source, Game game) {
return false;
}
@ -56,5 +56,5 @@ public class CantAttackBlockTransformAttachedEffect extends RestrictionEffect{
public CantAttackBlockTransformAttachedEffect copy() {
return new CantAttackBlockTransformAttachedEffect(this);
}
}

View file

@ -73,7 +73,7 @@ public class TransformSourceEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
if (permanent.canTransform(game)) {
if (permanent.canTransform(source, game)) {
// check not to transform twice the same side
if (permanent.isTransformed() != fromDayToNight) {
if (withoutTrigger) {

View file

@ -46,7 +46,7 @@ public class TransformTargetEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
if (permanent != null) {
if (permanent.canTransform(game)) {
if (permanent.canTransform(source, game)) {
// check not to transform twice the same side
if (withoutTrigger) {
permanent.setTransformed(!permanent.isTransformed());

View file

@ -81,7 +81,7 @@ public class BecomesFaceDownCreatureAllEffect extends ContinuousEffectImpl imple
public void init(Ability source, Game game) {
super.init(source, game);
for (Permanent perm: game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
if (!perm.isFaceDown(game) && !perm.canTransform()) {
if (!perm.isFaceDown(game) && !perm.isTransformable()) {
affectedObjectList.add(new MageObjectReference(perm, game));
perm.setFaceDown(true, game);
// check for Morph

View file

@ -38,13 +38,11 @@ public class RepairAbility extends DiesTriggeredAbility {
super(new AddCountersSourceEffect(CounterType.REPAIR.createInstance(), new StaticValue(count), false, true));
addSubAbility(new RepairBeginningOfUpkeepTriggeredAbility());
addSubAbility(new RepairCastFromGraveyardTriggeredAbility());
StringBuilder sb = new StringBuilder("Repair ");
sb.append(count)
.append(" <i>(When this creature dies, put ")
.append(count)
.append(" repair counters on it. At the beggining of your upkeep, remove a repair counter. Whenever the last is removed, you may cast it from graveyard until end of turn.)</i>");
ruleText = sb.toString();
ruleText = "Repair " + count + " <i>(When this creature dies, put " + count
+ " repair counters on it. At the beggining of your upkeep, remove a repair counter. "
+ "Whenever the last is removed, you may cast it from graveyard until end of turn.)</i>";
}
public RepairAbility(final RepairAbility ability) {

View file

@ -44,9 +44,9 @@ public class TransformAbility extends SimpleStaticAbility {
public static final String NO_SPELLS_TRANSFORM_RULE = "At the beginning of each upkeep, if no spells were cast last turn, transform {this}.";
public static final String TWO_OR_MORE_SPELLS_TRANSFORM_RULE = "At the beginning of each upkeep, if a player cast two or more spells last turn, transform {this}.";
// this state value controlls if a permanent enters the battlefield already transformed
// this state value controlls if a permanent enters the battlefield already transformed
public static final String VALUE_KEY_ENTER_TRANSFORMED = "EnterTransformed";
public TransformAbility() {
super(Zone.BATTLEFIELD, new TransformEffect());
}
@ -94,6 +94,7 @@ public class TransformAbility extends SimpleStaticAbility {
}
permanent.getPower().setValue(sourceCard.getPower().getValue());
permanent.getToughness().setValue(sourceCard.getToughness().getValue());
permanent.setTransformable(sourceCard.isTransformable());
}
}

View file

@ -66,7 +66,7 @@ public interface Card extends MageObject {
String getExpansionSetCode();
String getTokenSetCode();
String getTokenDescriptor();
void checkForCountersToAdd(Permanent permanent, Game game);
@ -85,7 +85,9 @@ public interface Card extends MageObject {
boolean isSplitCard();
boolean canTransform();
boolean isTransformable();
void setTransformable(boolean transformable);
Card getSecondCardFace();

View file

@ -71,7 +71,7 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
protected String tokenSetCode;
protected String tokenDescriptor;
protected Rarity rarity;
protected boolean canTransform;
protected boolean transformable;
protected Card secondSideCard;
protected boolean nightCard;
protected SpellAbility spellAbility;
@ -139,8 +139,8 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
tokenDescriptor = card.tokenDescriptor;
rarity = card.rarity;
canTransform = card.canTransform;
if (canTransform) {
transformable = card.transformable;
if (transformable) {
secondSideCard = card.secondSideCard;
nightCard = card.nightCard;
}
@ -532,8 +532,13 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
}
@Override
public boolean canTransform() {
return this.canTransform;
public boolean isTransformable() {
return this.transformable;
}
@Override
public void setTransformable(boolean transformable) {
this.transformable = transformable;
}
@Override

View file

@ -134,7 +134,7 @@ public class CardInfo {
this.flipCard = card.isFlipCard();
this.flipCardName = card.getFlipCardName();
this.doubleFaced = card.canTransform() && card.getSecondCardFace() != null;
this.doubleFaced = card.isTransformable() && card.getSecondCardFace() != null;
this.nightCard = card.isNightCard();
Card secondSide = card.getSecondCardFace();
if (secondSide != null) {

View file

@ -37,7 +37,6 @@ import mage.abilities.Ability;
import mage.cards.Card;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.counters.Counters;
import mage.game.Controllable;
import mage.game.Game;
import mage.game.GameState;
@ -251,10 +250,11 @@ public interface Permanent extends Card, Controllable {
/**
* Checks by restriction effects if the permanent can transform
*
* @param ability the ability that causes the transform
* @param game
* @return true - permanent can transform
*/
boolean canTransform(Game game);
boolean canTransform(Ability ability, Game game);
boolean removeFromCombat(Game game);

View file

@ -71,7 +71,7 @@ public class PermanentCard extends PermanentImpl {
if (card instanceof LevelerCard) {
maxLevelCounters = ((LevelerCard) card).getMaxLevelCounters();
}
if (canTransform()) {
if (isTransformable()) {
if (game.getState().getValue(TransformAbility.VALUE_KEY_ENTER_TRANSFORMED + getId()) != null) {
game.getState().setValue(TransformAbility.VALUE_KEY_ENTER_TRANSFORMED + getId(), null);
setTransformed(true);
@ -129,8 +129,8 @@ public class PermanentCard extends PermanentImpl {
this.cardNumber = card.getCardNumber();
this.usesVariousArt = card.getUsesVariousArt();
canTransform = card.canTransform();
if (canTransform) {
transformable = card.isTransformable();
if (transformable) {
secondSideCard = card.getSecondCardFace();
nightCard = card.isNightCard();
}

View file

@ -455,7 +455,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
@Override
public boolean transform(Game game) {
if (canTransform) {
if (transformable) {
if (!replaceEvent(EventType.TRANSFORM, game)) {
setTransformed(!transformed);
game.applyEffects();
@ -1111,9 +1111,9 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
}
//20101001 - 509.1b
for (Map.Entry entry : game.getContinuousEffects().getApplicableRestrictionEffects(this, game).entrySet()) {
RestrictionEffect effect = (RestrictionEffect) entry.getKey();
for (Ability ability : (HashSet<Ability>) entry.getValue()) {
for (Map.Entry<RestrictionEffect, HashSet<Ability>> entry : game.getContinuousEffects().getApplicableRestrictionEffects(this, game).entrySet()) {
RestrictionEffect effect = entry.getKey();
for (Ability ability : entry.getValue()) {
if (!effect.canBlock(null, this, ability, game)) {
return false;
}
@ -1132,30 +1132,30 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
*/
@Override
public boolean canUseActivatedAbilities(Game game) {
for (Map.Entry entry : game.getContinuousEffects().getApplicableRestrictionEffects(this, game).entrySet()) {
RestrictionEffect effect = (RestrictionEffect) entry.getKey();
for (Ability ability : (HashSet<Ability>) entry.getValue()) {
for (Map.Entry<RestrictionEffect, HashSet<Ability>> entry : game.getContinuousEffects().getApplicableRestrictionEffects(this, game).entrySet()) {
RestrictionEffect effect = entry.getKey();
for (Ability ability : entry.getValue()) {
if (!effect.canUseActivatedAbilities(this, ability, game)) {
return false;
}
}
}
return true;
}
@Override
public boolean canTransform(Game game) {
for (Map.Entry entry : game.getContinuousEffects().getApplicableRestrictionEffects(this, game).entrySet()) {
RestrictionEffect effect = (RestrictionEffect) entry.getKey();
for (Ability ability : (HashSet<Ability>) entry.getValue()) {
if (!effect.canTransform(game)) {
return false;
public boolean canTransform(Ability source, Game game) {
if (transformable) {
for (Map.Entry<RestrictionEffect, HashSet<Ability>> entry : game.getContinuousEffects().getApplicableRestrictionEffects(this, game).entrySet()) {
RestrictionEffect effect = entry.getKey();
for (Ability ability : entry.getValue()) {
if (!effect.canTransform(this, ability, game)) {
return false;
}
}
}
}
return true;
return transformable;
}
@Override

View file

@ -646,7 +646,7 @@ public class Spell extends StackObjImpl implements Card {
}
@Override
public boolean canTransform() {
public boolean isTransformable() {
return false;
}
@ -804,6 +804,11 @@ public class Spell extends StackObjImpl implements Card {
throw new UnsupportedOperationException("Unsupported operation");
}
@Override
public void setTransformable(boolean value) {
throw new UnsupportedOperationException("Unsupported operation");
}
@Override
public int getZoneChangeCounter(Game game) {
return card.getZoneChangeCounter(game);

View file

@ -640,7 +640,7 @@ public class CardUtil {
mana.setWhite(true);
}
}
if (card.canTransform()) {
if (card.isTransformable()) {
Card secondCard = card.getSecondCardFace();
ObjectColor color = secondCard.getColor(null);
mana.setBlack(mana.isBlack() || color.isBlack());