Merge pull request #5075 from NoahGleason/equipment

Fix equip and fortify abilities
This commit is contained in:
theelk801 2018-06-25 22:44:47 -04:00 committed by GitHub
commit 127e70a799
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 81 additions and 22 deletions

View file

@ -0,0 +1,39 @@
package mage.abilities.effects;
import mage.abilities.Ability;
import mage.abilities.effects.common.AttachEffect;
import mage.constants.Outcome;
import mage.constants.SubType;
import mage.game.Game;
import mage.game.permanent.Permanent;
public class EquipEffect extends AttachEffect {
public EquipEffect(Outcome outcome) {
super(outcome, "Equip");
}
public EquipEffect(EquipEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
//301.5c An Equipment thats also a creature cant equip a creature. An Equipment that loses the subtype
// Equipment cant equip a creature. An Equipment cant equip itself. An Equipment that equips an illegal or
// nonexistent permanent becomes unattached from that permanent but remains on the battlefield. (This is a
// state-based action. See rule 704.) An Equipment cant equip more than one creature. If a spell or ability
// would cause an Equipment to equip more than one creature, the Equipments controller chooses which creature
// it equips.
if (sourcePermanent != null && sourcePermanent.hasSubtype(SubType.EQUIPMENT, game) && !sourcePermanent.isCreature()) {
return super.apply(game, source);
}
return false;
}
@Override
public EquipEffect copy(){
return new EquipEffect(this);
}
}

View file

@ -0,0 +1,38 @@
package mage.abilities.effects.common;
import mage.abilities.Ability;
import mage.constants.Outcome;
import mage.constants.SubType;
import mage.game.Game;
import mage.game.permanent.Permanent;
public class FortifyEffect extends AttachEffect{
public FortifyEffect(Outcome outcome) {
super(outcome, "Fortify");
}
public FortifyEffect(FortifyEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
//Some artifacts have the subtype Fortification. A Fortification can be attached to a land. It cant legally
// be attached to an object that isnt a land. Fortifications analog to the equip keyword ability is the
// fortify keyword ability. Rules 301.5ae apply to Fortifications in relation to lands just as they apply to
// Equipment in relation to creatures, with one clarification relating to rule 301.5c: a Fortification thats
// also a creature (not a land) cant fortify a land. (See rule 702.66, Fortify.)
if (sourcePermanent != null && sourcePermanent.hasSubtype(SubType.FORTIFICATION, game) && !sourcePermanent.isCreature()
&& !sourcePermanent.isLand()) {
return super.apply(game, source);
}
return false;
}
@Override
public FortifyEffect copy(){
return new FortifyEffect(this);
}
}

View file

@ -4,6 +4,7 @@ import java.util.UUID;
import mage.abilities.ActivatedAbilityImpl;
import mage.abilities.costs.Cost;
import mage.abilities.costs.mana.GenericManaCost;
import mage.abilities.effects.EquipEffect;
import mage.abilities.effects.common.AttachEffect;
import mage.constants.Outcome;
import mage.constants.SubType;
@ -28,21 +29,11 @@ public class EquipAbility extends ActivatedAbilityImpl {
}
public EquipAbility(Outcome outcome, Cost cost, Target target) {
super(Zone.BATTLEFIELD, new AttachEffect(outcome, "Equip"), cost);
super(Zone.BATTLEFIELD, new EquipEffect(outcome), cost);
this.addTarget(target);
this.timing = TimingRule.SORCERY;
}
@Override
public ActivationStatus canActivate(UUID playerId, Game game) {
Permanent permanent = game.getPermanent(sourceId);
if (permanent != null && permanent.hasSubtype(SubType.EQUIPMENT, game) && !permanent.isCreature()) {
return super.canActivate(playerId, game);
} else {
return ActivationStatus.getFalse();
}
}
public EquipAbility(final EquipAbility ability) {
super(ability);
}

View file

@ -3,6 +3,7 @@
package mage.abilities.keyword;
import mage.abilities.costs.mana.GenericManaCost;
import mage.abilities.effects.common.FortifyEffect;
import mage.constants.Outcome;
import mage.constants.SubType;
import mage.constants.TimingRule;
@ -36,21 +37,11 @@ public class FortifyAbility extends ActivatedAbilityImpl {
}
public FortifyAbility(Outcome outcome, Cost cost, Target target) {
super(Zone.BATTLEFIELD, new AttachEffect(outcome, "Fortify"), cost);
super(Zone.BATTLEFIELD, new FortifyEffect(outcome), cost);
this.addTarget(target);
this.timing = TimingRule.SORCERY;
}
@Override
public ActivationStatus canActivate(UUID playerId, Game game) {
Permanent permanent = game.getPermanent(sourceId);
if (permanent != null && permanent.hasSubtype(SubType.FORTIFICATION, game) && !permanent.isCreature() && !permanent.isLand()) {
return super.canActivate(playerId, game);
} else {
return ActivationStatus.getFalse();
}
}
public FortifyAbility(final FortifyAbility ability) {
super(ability);
}