Merge remote-tracking branch 'magefree/master'

# Conflicts:
#
Mage/src/main/java/mage/abilities/condition/common/SourceHasSubtypeCondi
tion.java
#	Mage/src/main/java/mage/game/permanent/PermanentToken.java
This commit is contained in:
Samuel Sandeen 2016-09-03 20:06:33 -04:00
commit 434be545f7
23 changed files with 602 additions and 72 deletions

View file

@ -0,0 +1,47 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mage.abilities.common;
import mage.abilities.Ability;
import mage.abilities.effects.common.InfoEffect;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.target.Target;
/**
*
* @author LevelX2
*/
public class AttachableToRestrictedAbility extends SimpleStaticAbility {
public AttachableToRestrictedAbility(Target target) {
super(Zone.BATTLEFIELD, new InfoEffect("{this} can be attached only to a " + target.getTargetName()));
addTarget(target);
}
private AttachableToRestrictedAbility(AttachableToRestrictedAbility ability) {
super(ability);
}
public boolean canEquip(Permanent toEquip, Ability source, Game game) {
for (Target target : getTargets()) {
if (source == null) {
if (!target.canTarget(toEquip.getId(), game)) {
return false;
}
} else if (!target.canTarget(toEquip.getId(), source, game)) {
return false;
}
}
return true;
}
@Override
public AttachableToRestrictedAbility copy() {
return new AttachableToRestrictedAbility(this);
}
}

View file

@ -146,20 +146,22 @@ public class AddCountersTargetEffect extends OneShotEffect {
}
sb.append(" on ");
Target target = mode.getTargets().get(0);
if (target.getNumberOfTargets() == 0) {
sb.append("up to ");
}
if (target.getMaxNumberOfTargets() > 1 || target.getNumberOfTargets() == 0) {
sb.append(target.getMaxNumberOfTargets()).append(" target ").append(target.getTargetName());
} else {
if (!target.getTargetName().startsWith("another")) {
sb.append("target ");
if (mode.getTargets().size() > 0) {
Target target = mode.getTargets().get(0);
if (target.getNumberOfTargets() == 0) {
sb.append("up to ");
}
sb.append(target.getTargetName());
if (target.getMaxNumberOfTargets() > 1 || target.getNumberOfTargets() == 0) {
sb.append(target.getMaxNumberOfTargets()).append(" target ").append(target.getTargetName());
} else {
if (!target.getTargetName().startsWith("another")) {
sb.append("target ");
}
sb.append(target.getTargetName());
}
} else {
sb.append("that creature");
}
if (amount.getMessage().length() > 0) {

View file

@ -1,16 +1,16 @@
/*
* 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
@ -20,12 +20,11 @@
* 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 java.util.UUID;
@ -57,17 +56,15 @@ public class EquipAbility extends ActivatedAbilityImpl {
@Override
public boolean canActivate(UUID playerId, Game game) {
if(super.canActivate(playerId, game)){
if (super.canActivate(playerId, game)) {
Permanent permanent = game.getPermanent(sourceId);
if(permanent != null && permanent.hasSubtype("Equipment", game)){
if (permanent != null && permanent.hasSubtype("Equipment", game)) {
return true;
}
}
return false;
}
public EquipAbility(final EquipAbility ability) {
super(ability);
}
@ -79,9 +76,7 @@ public class EquipAbility extends ActivatedAbilityImpl {
@Override
public String getRule() {
StringBuilder sb = new StringBuilder("Equip ").append(costs.getText()).append(manaCosts.getText());
sb.append(" (").append(manaCosts.getText()).append(": <i>Attach to target creature you control. Equip only as a sorcery.)</i>");
return sb.toString();
return "Equip " + costs.getText() + manaCosts.getText() + " (" + manaCosts.getText() + ": <i>Attach to target creature you control. Equip only as a sorcery.)</i>";
}
}

View file

@ -45,7 +45,7 @@ public class CanBeEnchantedByPredicate implements Predicate<Permanent> {
@Override
public boolean apply(Permanent input, Game game) {
return !input.cantBeEnchantedBy(auraEnchantment, game);
return !input.cantBeAttachedBy(auraEnchantment, game);
}
@Override

View file

@ -51,6 +51,7 @@ import mage.abilities.ActivatedAbility;
import mage.abilities.DelayedTriggeredAbility;
import mage.abilities.SpellAbility;
import mage.abilities.TriggeredAbility;
import mage.abilities.common.AttachableToRestrictedAbility;
import mage.abilities.common.ChancellorAbility;
import mage.abilities.common.GemstoneCavernsAbility;
import mage.abilities.effects.ContinuousEffect;
@ -1775,12 +1776,12 @@ public abstract class GameImpl implements Game, Serializable {
Filter auraFilter = spellAbility.getTargets().get(0).getFilter();
if (auraFilter instanceof FilterControlledCreaturePermanent) {
if (!((FilterControlledCreaturePermanent) auraFilter).match(attachedTo, perm.getId(), perm.getControllerId(), this)
|| attachedTo.cantBeEnchantedBy(perm, this)) {
|| attachedTo.cantBeAttachedBy(perm, this)) {
if (movePermanentToGraveyardWithInfo(perm)) {
somethingHappened = true;
}
}
} else if (!auraFilter.match(attachedTo, this) || attachedTo.cantBeEnchantedBy(perm, this)) {
} else if (!auraFilter.match(attachedTo, this) || attachedTo.cantBeAttachedBy(perm, this)) {
// handle bestow unattachment
Card card = this.getCard(perm.getId());
if (card != null && card.getCardType().contains(CardType.CREATURE)) {
@ -1816,13 +1817,23 @@ public abstract class GameImpl implements Game, Serializable {
if (FILTER_EQUIPMENT.match(perm, this)) {
//20091005 - 704.5p, 702.14d
if (perm.getAttachedTo() != null) {
Permanent creature = getPermanent(perm.getAttachedTo());
if (creature == null || !creature.getAttachments().contains(perm.getId())) {
Permanent attachedTo = getPermanent(perm.getAttachedTo());
if (attachedTo != null) {
for (Ability ability : perm.getAbilities(this)) {
if (ability instanceof AttachableToRestrictedAbility) {
if (!((AttachableToRestrictedAbility) ability).canEquip(attachedTo, null, this)) {
attachedTo = null;
break;
}
}
}
}
if (attachedTo == null || !attachedTo.getAttachments().contains(perm.getId())) {
UUID wasAttachedTo = perm.getAttachedTo();
perm.attachTo(null, this);
fireEvent(new GameEvent(GameEvent.EventType.UNATTACHED, wasAttachedTo, perm.getId(), perm.getControllerId()));
} else if (!creature.getCardType().contains(CardType.CREATURE) || creature.hasProtectionFrom(perm, this)) {
if (creature.removeAttachment(perm.getId(), this)) {
} else if (!attachedTo.getCardType().contains(CardType.CREATURE) || attachedTo.hasProtectionFrom(perm, this)) {
if (attachedTo.removeAttachment(perm.getId(), this)) {
somethingHappened = true;
}
}

View file

@ -120,7 +120,7 @@ public interface Permanent extends Card, Controllable {
boolean hasProtectionFrom(MageObject source, Game game);
boolean cantBeEnchantedBy(MageObject source, Game game);
boolean cantBeAttachedBy(MageObject source, Game game);
boolean wasControlledFromStartOfControllerTurn();

View file

@ -562,13 +562,13 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
@Override
public boolean changeControllerId(UUID controllerId, Game game) {
Player newController = game.getPlayer(controllerId);
GameEvent loseControlEvent = GameEvent.getEvent(GameEvent.EventType.LOSE_CONTROL, this.getId(), null, controllerId);
if (game.replaceEvent(loseControlEvent)) {
return false;
}
if (newController != null && (!newController.hasLeft() || !newController.hasLost())) {
this.controllerId = controllerId;
return true;
@ -918,7 +918,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
@Override
public boolean hasProtectionFrom(MageObject source, Game game) {
for (ProtectionAbility ability : abilities.getProtectionAbilities()) {
for (ProtectionAbility ability : this.getAbilities(game).getProtectionAbilities()) {
if (!ability.canTarget(source, game)) {
return true;
}
@ -927,8 +927,8 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
}
@Override
public boolean cantBeEnchantedBy(MageObject source, Game game) {
for (ProtectionAbility ability : abilities.getProtectionAbilities()) {
public boolean cantBeAttachedBy(MageObject source, Game game) {
for (ProtectionAbility ability : this.getAbilities(game).getProtectionAbilities()) {
if (!(source.getSubtype(game).contains("Aura")
&& !ability.removesAuras())
&& !source.getId().equals(ability.getAuraIdNotToBeRemoved())