[refactor] moved effect to common

This commit is contained in:
North 2012-05-19 22:02:36 +03:00
parent 36e5d2bcd0
commit e91f610d01
2 changed files with 73 additions and 38 deletions

View file

@ -33,15 +33,12 @@ import mage.Constants.Duration;
import mage.Constants.Rarity; import mage.Constants.Rarity;
import mage.Constants.Zone; import mage.Constants.Zone;
import mage.MageInt; import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility; import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount; import mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount;
import mage.abilities.effects.RestrictionEffect;
import mage.abilities.effects.common.continious.BoostSourceEffect; import mage.abilities.effects.common.continious.BoostSourceEffect;
import mage.abilities.effects.common.continious.CantBeBlockedByCreaturesWithLessPowerEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.filter.FilterPermanent; import mage.filter.FilterPermanent;
import mage.game.Game;
import mage.game.permanent.Permanent;
/** /**
* *
@ -65,7 +62,7 @@ public class AuraGnarlid extends CardImpl<AuraGnarlid> {
this.toughness = new MageInt(2); this.toughness = new MageInt(2);
// Creatures with power less than Aura Gnarlid's power can't block it. // Creatures with power less than Aura Gnarlid's power can't block it.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new AuraGnarlidRestrictionEffect())); this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new CantBeBlockedByCreaturesWithLessPowerEffect()));
// Aura Gnarlid gets +1/+1 for each Aura on the battlefield. // Aura Gnarlid gets +1/+1 for each Aura on the battlefield.
PermanentsOnBattlefieldCount count = new PermanentsOnBattlefieldCount(filter); PermanentsOnBattlefieldCount count = new PermanentsOnBattlefieldCount(filter);
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostSourceEffect(count, count, Duration.WhileOnBattlefield))); this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostSourceEffect(count, count, Duration.WhileOnBattlefield)));
@ -80,36 +77,3 @@ public class AuraGnarlid extends CardImpl<AuraGnarlid> {
return new AuraGnarlid(this); return new AuraGnarlid(this);
} }
} }
class AuraGnarlidRestrictionEffect extends RestrictionEffect<AuraGnarlidRestrictionEffect> {
public AuraGnarlidRestrictionEffect() {
super(Duration.WhileOnBattlefield);
staticText = "Creatures with power less than {this}'s power can't block it";
}
public AuraGnarlidRestrictionEffect(final AuraGnarlidRestrictionEffect effect) {
super(effect);
}
@Override
public boolean applies(Permanent permanent, Ability source, Game game) {
if (permanent.getId().equals(source.getSourceId())) {
return true;
}
return false;
}
@Override
public boolean canBeBlocked(Permanent attacker, Permanent blocker, Ability source, Game game) {
if (blocker.getPower().getValue() < attacker.getPower().getValue()) {
return false;
}
return true;
}
@Override
public AuraGnarlidRestrictionEffect copy() {
return new AuraGnarlidRestrictionEffect(this);
}
}

View file

@ -0,0 +1,71 @@
/*
* 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.effects.common.continious;
import mage.Constants.Duration;
import mage.abilities.Ability;
import mage.abilities.effects.RestrictionEffect;
import mage.game.Game;
import mage.game.permanent.Permanent;
/**
*
* @author North
*/
public class CantBeBlockedByCreaturesWithLessPowerEffect extends RestrictionEffect<CantBeBlockedByCreaturesWithLessPowerEffect> {
public CantBeBlockedByCreaturesWithLessPowerEffect() {
super(Duration.WhileOnBattlefield);
staticText = "Creatures with power less than {this}'s power can't block it";
}
public CantBeBlockedByCreaturesWithLessPowerEffect(final CantBeBlockedByCreaturesWithLessPowerEffect effect) {
super(effect);
}
@Override
public boolean applies(Permanent permanent, Ability source, Game game) {
if (permanent.getId().equals(source.getSourceId())) {
return true;
}
return false;
}
@Override
public boolean canBeBlocked(Permanent attacker, Permanent blocker, Ability source, Game game) {
if (blocker.getPower().getValue() < attacker.getPower().getValue()) {
return false;
}
return true;
}
@Override
public CantBeBlockedByCreaturesWithLessPowerEffect copy() {
return new CantBeBlockedByCreaturesWithLessPowerEffect(this);
}
}