Some fixes to M15 cards or by M15 used classes.

This commit is contained in:
LevelX2 2014-07-06 16:00:32 +02:00
parent 9ad45a6ab9
commit 18e78b8294
23 changed files with 105 additions and 50 deletions

View file

@ -167,7 +167,19 @@ public abstract class AbilityImpl implements Ability {
for (Effect effect: getEffects()) {
if (effect instanceof OneShotEffect) {
if (!(effect instanceof PostResolveEffect)) {
result &= effect.apply(game, this);
boolean effectResult = effect.apply(game, this);
result &= effectResult;
if (logger.isDebugEnabled()) {
if (!effectResult) {
if (this.getSourceId() != null) {
MageObject mageObject = game.getObject(this.getSourceId());
if (mageObject != null) {
logger.debug("AbilityImpl.resolve: object: " + mageObject.getName());
}
}
logger.debug("AbilityImpl.resolve: effect returned false -" + effect.getText(this.getModes().getMode()));
}
}
}
}
else {

View file

@ -33,7 +33,8 @@ import mage.abilities.condition.Condition;
import mage.game.Game;
public class NotMyTurnCondition implements Condition {
private static NotMyTurnCondition fInstance = new NotMyTurnCondition();
private static final NotMyTurnCondition fInstance = new NotMyTurnCondition();
public static Condition getInstance() {
return fInstance;
@ -42,8 +43,9 @@ public class NotMyTurnCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
UUID activePlayerId = game.getActivePlayerId();
if (activePlayerId != null)
if (activePlayerId != null) {
return !activePlayerId.equals(source.getControllerId());
}
return false;
}
}

View file

@ -28,9 +28,10 @@
package mage.abilities.effects.common;
import mage.constants.Outcome;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.game.Game;
import mage.game.command.Emblem;
@ -40,7 +41,7 @@ import mage.game.command.Emblem;
*/
public class GetEmblemEffect extends OneShotEffect {
private Emblem emblem;
private final Emblem emblem;
public GetEmblemEffect(Emblem emblem) {
super(Outcome.Benefit);
@ -60,6 +61,10 @@ public class GetEmblemEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
MageObject sourceObject = game.getObject(source.getSourceId());
if (sourceObject == null) {
return false;
}
game.addEmblem(emblem, source);
return true;
}

View file

@ -48,15 +48,18 @@ import mage.game.stack.Spell;
public class ProtectionAbility extends StaticAbility {
protected Filter filter;
protected boolean removeAuras;
public ProtectionAbility(Filter filter) {
super(Zone.BATTLEFIELD, null);
this.filter = filter;
this.removeAuras = true;
}
public ProtectionAbility(final ProtectionAbility ability) {
super(ability);
this.filter = ability.filter.copy();
this.removeAuras = ability.removeAuras;
}
@Override
@ -66,7 +69,7 @@ public class ProtectionAbility extends StaticAbility {
@Override
public String getRule() {
return "Protection from " + filter.getMessage();
return "Protection from " + filter.getMessage() + (removeAuras ? "":". This effect doesn't remove auras.");
}
public boolean canTarget(MageObject source, Game game) {
@ -101,4 +104,12 @@ public class ProtectionAbility extends StaticAbility {
public void setFilter(FilterCard filter) {
this.filter = filter;
}
public void setRemovesAuras(boolean removeAuras) {
this.removeAuras = removeAuras;
}
public boolean removesAuras() {
return removeAuras;
}
}

View file

@ -507,6 +507,10 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
break;
case EXILED:
game.getExile().removeCard(this, game);
if (isFaceDown()) {
// 110.6b Permanents enter the battlefield untapped, unflipped, face up, and phased in unless a spell or ability says otherwise.
this.setFaceDown(false);
}
removed = true;
break;
case COMMAND:

View file

@ -1419,13 +1419,14 @@ public abstract class GameImpl implements Game, Serializable {
else {
Filter auraFilter = perm.getSpellAbility().getTargets().get(0).getFilter();
if (auraFilter instanceof FilterControlledCreaturePermanent) {
if (!((FilterControlledCreaturePermanent)auraFilter).match(attachedTo, perm.getId(), perm.getControllerId(), this) || attachedTo.hasProtectionFrom(perm, this)) {
if (!((FilterControlledCreaturePermanent)auraFilter).match(attachedTo, perm.getId(), perm.getControllerId(), this)
|| attachedTo.cantBeEnchantedBy(perm, this)) {
if (movePermanentToGraveyardWithInfo(perm)) {
somethingHappened = true;
}
}
} else {
if (!auraFilter.match(attachedTo, this) || attachedTo.hasProtectionFrom(perm, this)) {
if (!auraFilter.match(attachedTo, this) || attachedTo.cantBeEnchantedBy(perm, this)) {
// handle bestow unattachment
Card card = this.getCard(perm.getId());
if (card != null && card.getCardType().contains(CardType.CREATURE)) {
@ -1442,15 +1443,15 @@ public abstract class GameImpl implements Game, Serializable {
}
}
else if (target instanceof TargetPlayer) {
Player attachedTo = getPlayer(perm.getAttachedTo());
if (attachedTo == null) {
Player attachedToPlayer = getPlayer(perm.getAttachedTo());
if (attachedToPlayer == null) {
if (movePermanentToGraveyardWithInfo(perm)) {
somethingHappened = true;
}
}
else {
Filter auraFilter = perm.getSpellAbility().getTargets().get(0).getFilter();
if (!auraFilter.match(attachedTo, this) || attachedTo.hasProtectionFrom(perm, this)) {
if (!auraFilter.match(attachedToPlayer, this) || attachedToPlayer.hasProtectionFrom(perm, this)) {
if (movePermanentToGraveyardWithInfo(perm)) {
somethingHappened = true;
}
@ -1988,9 +1989,9 @@ public abstract class GameImpl implements Game, Serializable {
targetName = targetPlayer.getName();
}
} else {
targetName = targetObject.getName();
targetName = targetObject.getLogName();
}
StringBuilder message = new StringBuilder(preventionSource.getName()).append(": Prevented ");
StringBuilder message = new StringBuilder(preventionSource.getLogName()).append(": Prevented ");
message.append(Integer.toString(result.getPreventedDamage())).append(" damage from ").append(damageSource.getName());
if (!targetName.isEmpty()) {
message.append(" to ").append(targetName);

View file

@ -63,6 +63,7 @@ public class Emblem implements CommandObject {
public Emblem(final Emblem emblem) {
this.id = emblem.id;
this.name = emblem.name;
this.controllerId = emblem.controllerId;
this.sourceId = emblem.sourceId;
this.abilites = emblem.abilites.copy();

View file

@ -78,6 +78,7 @@ public interface Permanent extends Card, Controllable {
boolean canBeTargetedBy(MageObject source, UUID controllerId, Game game);
boolean hasProtectionFrom(MageObject source, Game game);
boolean cantBeEnchantedBy(MageObject source, Game game);
boolean hasSummoningSickness();
int getDamage();
int damage(int damage, UUID sourceId, Game game, boolean preventable, boolean combat);

View file

@ -765,6 +765,16 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
return false;
}
@Override
public boolean cantBeEnchantedBy(MageObject source, Game game) {
for (ProtectionAbility ability : abilities.getProtectionAbilities()) {
if (!(source.getSubtype().contains("Aura") && !ability.removesAuras()) && !ability.canTarget(source, game)) {
return true;
}
}
return false;
}
protected boolean canDamage(MageObject source, Game game) {
//noxx: having protection doesn't prevents from dealing damage
// instead it adds damage prevention

View file

@ -37,13 +37,24 @@ import mage.constants.CardType;
public class SpiritWhiteToken extends Token {
public SpiritWhiteToken() {
this("SHM", 0);
}
public SpiritWhiteToken(String setCode) {
this(setCode, 0);
}
public SpiritWhiteToken(String setCode, int tokenType) {
super("Spirit", "1/1 white Spirit creature token with flying");
setOriginalExpansionSetCode(setCode);
if (tokenType > 0) {
setTokenType(tokenType);
}
cardType.add(CardType.CREATURE);
subtype.add("Spirit");
color.setWhite(true);
power = new MageInt(1);
toughness = new MageInt(1);
addAbility(FlyingAbility.getInstance());
this.setOriginalExpansionSetCode("SHM");
}
}

View file

@ -63,9 +63,6 @@ public class PlayerLostLifeWatcher extends Watcher {
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.UNTAP_STEP_PRE) {
reset();
}
if (event.getType() == GameEvent.EventType.LOST_LIFE) {
UUID playerId = event.getPlayerId();
if (playerId != null) {