Refactored Blocked Creature effect

This commit is contained in:
markedagain 2016-02-23 23:54:57 -05:00
parent 3ac7976dda
commit 188db6eedc
11 changed files with 537 additions and 709 deletions

View file

@ -29,9 +29,11 @@ package mage.sets.guildpact;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.common.BecomesBlockedAllTriggeredAbility;
import mage.abilities.common.BecomesBlockedTriggeredAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.BlockedCreatureCount;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.AttachEffect;
import mage.abilities.effects.common.continuous.BoostAllEffect;
@ -79,7 +81,10 @@ public class BeastmastersMagemark extends CardImpl {
ability = new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostAllEffect(1,1, Duration.WhileOnBattlefield, filter, false));
this.addAbility(ability);
// Whenever a creature you control that's enchanted becomes blocked, it gets +1/+1 until end of turn for each creature blocking it.
this.addAbility(new BeastmastersMagemarkAbility());
BlockedCreatureCount value = new BlockedCreatureCount();
Effect effect = new BoostSourceEffect(value, value, Duration.EndOfTurn);
effect.setText("it gets +1/+1 until end of turn for each creature blocking it");
this.addAbility(new BecomesBlockedAllTriggeredAbility(effect, false,filter,false));
}
public BeastmastersMagemark(final BeastmastersMagemark card) {

View file

@ -29,9 +29,9 @@ package mage.sets.iceage;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.BecomesBlockedTriggeredAbility;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.BlockedCreatureCount;
import mage.abilities.dynamicvalue.MultipliedValue;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.continuous.BoostSourceEffect;
@ -39,8 +39,6 @@ import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Rarity;
import mage.game.Game;
import mage.game.combat.CombatGroup;
/**
*
@ -56,7 +54,12 @@ public class JohtullWurm extends CardImpl {
this.toughness = new MageInt(6);
// Whenever Johtull Wurm becomes blocked, it gets -2/-1 until end of turn for each creature blocking it beyond the first.
this.addAbility(new JohtullWurmAbility());
DynamicValue toughnessValue = new MultipliedValue(new BlockedCreatureCount(),2);
int value = Math.negateExact(Integer.parseInt(toughnessValue.toString()) - 1);
Effect effect = new BoostSourceEffect(powerValue, value, Duration.EndOfTurn);
effect.setText("it gets -2/-1 until end of turn for each creature blocking it beyond the first");
this.addAbility(new BecomesBlockedTriggeredAbility(effect, false));
}
public JohtullWurm(final JohtullWurm card) {
@ -68,52 +71,3 @@ public class JohtullWurm extends CardImpl {
return new JohtullWurm(this);
}
}
class JohtullWurmAbility extends BecomesBlockedTriggeredAbility {
public JohtullWurmAbility() {
super(null, false);
JohtullWurmValue toughnessValue = new JohtullWurmValue();
DynamicValue powerValue = new MultipliedValue(toughnessValue, 2);
this.addEffect(new BoostSourceEffect(powerValue, toughnessValue, Duration.EndOfTurn));
}
public JohtullWurmAbility(final JohtullWurmAbility ability) {
super(ability);
}
@Override
public JohtullWurmAbility copy() {
return new JohtullWurmAbility(this);
}
@Override
public String getRule() {
return "Whenever {this} becomes blocked, it gets -2/-1 until end of turn for each creature blocking it beyond the first.";
}
}
class JohtullWurmValue implements DynamicValue {
@Override
public JohtullWurmValue copy() {
return new JohtullWurmValue();
}
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
for(CombatGroup combatGroup : game.getCombat().getGroups()) {
if(combatGroup.getAttackers().contains(sourceAbility.getSourceId())) {
int blockers = combatGroup.getBlockers().size();
return blockers > 1 ? -(blockers - 1) : 0;
}
}
return 0;
}
@Override
public String getMessage() {
return "-2/-1 until end of turn for each creature blocking it beyond the first";
}
}

View file

@ -29,17 +29,14 @@ package mage.sets.invasion;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.BecomesBlockedTriggeredAbility;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.BlockedCreatureCount;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.continuous.BoostSourceEffect;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Rarity;
import mage.game.Game;
import mage.game.combat.CombatGroup;
/**
*
@ -55,7 +52,10 @@ public class SparringGolem extends CardImpl {
this.toughness = new MageInt(2);
// Whenever Sparring Golem becomes blocked, it gets +1/+1 until end of turn for each creature blocking it.
this.addAbility(new SparringGolemAbility());
BlockedCreatureCount value = new BlockedCreatureCount();
Effect effect = new BoostSourceEffect(value, value, Duration.EndOfTurn);
effect.setText("it gets +1/+1 until end of turn for each creature blocking it");
this.addAbility(new BecomesBlockedTriggeredAbility(effect, false));
}
public SparringGolem(final SparringGolem card) {
@ -67,50 +67,3 @@ public class SparringGolem extends CardImpl {
return new SparringGolem(this);
}
}
class SparringGolemAbility extends BecomesBlockedTriggeredAbility {
public SparringGolemAbility() {
super(null, false);
SparringGolemValue value = new SparringGolemValue();
this.addEffect(new BoostSourceEffect(value, value, Duration.EndOfTurn));
}
public SparringGolemAbility(final SparringGolemAbility ability) {
super(ability);
}
@Override
public SparringGolemAbility copy() {
return new SparringGolemAbility(this);
}
@Override
public String getRule() {
return "Whenever {this} becomes blocked, it gets +1/+1 until end of turn for each creature blocking it.";
}
}
class SparringGolemValue implements DynamicValue {
@Override
public SparringGolemValue copy() {
return new SparringGolemValue();
}
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
for(CombatGroup combatGroup : game.getCombat().getGroups()) {
if(combatGroup.getAttackers().contains(sourceAbility.getSourceId())) {
int blockers = combatGroup.getBlockers().size();
return blockers > 1 ? (blockers) : 0;
}
}
return 0;
}
@Override
public String getMessage() {
return "+1/+1 until end of turn for each creature blocking it";
}
}

View file

@ -29,20 +29,28 @@ package mage.sets.legions;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.common.BecomesBlockedByCreatureTriggeredAbility;
import mage.abilities.common.BecomesBlockedAllTriggeredAbility;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.continuous.BoostSourceEffect;
import mage.abilities.dynamicvalue.common.BlockedCreatureCount;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Rarity;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.mageobject.SubtypePredicate;
/**
*
* @author fireshoes
* @author Markedagain
*/
public class BerserkMurlodont extends CardImpl {
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("a Beast");
static {
filter.add(new SubtypePredicate("Beast"));
}
public BerserkMurlodont(UUID ownerId) {
super(ownerId, 117, "Berserk Murlodont", Rarity.COMMON, new CardType[]{CardType.CREATURE}, "{4}{G}");
this.expansionSetCode = "LGN";
@ -51,9 +59,10 @@ public class BerserkMurlodont extends CardImpl {
this.toughness = new MageInt(3);
// Whenever a Beast becomes blocked, it gets +1/+1 until end of turn for each creature blocking it.
Effect effect = new BoostSourceEffect(1, 1, Duration.EndOfTurn);
BlockedCreatureCount value = new BlockedCreatureCount();
Effect effect = new BoostSourceEffect(value, value, Duration.EndOfTurn);
effect.setText("it gets +1/+1 until end of turn for each creature blocking it");
this.addAbility(new BecomesBlockedByCreatureTriggeredAbility(effect, false));
this.addAbility(new BecomesBlockedAllTriggeredAbility(effect, false,filter,false));
}
public BerserkMurlodont(final BerserkMurlodont card) {

View file

@ -29,18 +29,14 @@ package mage.sets.mirage;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.BecomesBlockedTriggeredAbility;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.BlockedCreatureCount;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.continuous.BoostSourceEffect;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Rarity;
import mage.game.Game;
import mage.game.combat.CombatGroup;
import mage.game.events.GameEvent;
/**
*
@ -56,7 +52,12 @@ public class JungleWurm extends CardImpl {
this.toughness = new MageInt(5);
// Whenever Jungle Wurm becomes blocked, it gets -1/-1 until end of turn for each creature blocking it beyond the first.
this.addAbility(new JungleWurmAbility());
BlockedCreatureCount blockedCreatureCount = new BlockedCreatureCount();
int value = Math.negateExact(Integer.parseInt(blockedCreatureCount.toString()) - 1);
Effect effect = new BoostSourceEffect(value, value, Duration.EndOfTurn);
effect.setText("it gets -1/-1 until end of turn for each creature blocking it beyond the first");
this.addAbility(new BecomesBlockedTriggeredAbility(effect, false));
}
public JungleWurm(final JungleWurm card) {
@ -68,52 +69,3 @@ public class JungleWurm extends CardImpl {
return new JungleWurm(this);
}
}
class JungleWurmAbility extends BecomesBlockedTriggeredAbility {
public JungleWurmAbility() {
super(null, false);
JungleWurmValue value = new JungleWurmValue();
this.addEffect(new BoostSourceEffect(value, value, Duration.EndOfTurn));
}
public JungleWurmAbility(final JungleWurmAbility ability) {
super(ability);
}
@Override
public JungleWurmAbility copy() {
return new JungleWurmAbility(this);
}
@Override
public String getRule() {
return "Whenever {this} becomes blocked, it gets -1/-1 until end of turn for each creature blocking it beyond the first.";
}
}
class JungleWurmValue implements DynamicValue {
@Override
public JungleWurmValue copy() {
return new JungleWurmValue();
}
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
int count = 0;
for(CombatGroup combatGroup : game.getCombat().getGroups()) {
if(combatGroup.getAttackers().contains(sourceAbility.getSourceId())) {
int blockers = combatGroup.getBlockers().size();
return blockers > 1 ? -(blockers - 1) : 0;
}
}
return 0;
}
@Override
public String getMessage() {
return "-1/-1 until end of turn for each creature blocking it beyond the first";
}
}

View file

@ -32,6 +32,7 @@ import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.BecomesBlockedTriggeredAbility;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.BlockedCreatureCount;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.continuous.BoostSourceEffect;
import mage.cards.CardImpl;
@ -56,7 +57,10 @@ public class ElvishBerserker extends CardImpl {
this.toughness = new MageInt(1);
// Whenever Elvish Berserker becomes blocked, it gets +1/+1 until end of turn for each creature blocking it.
this.addAbility(new ElvishBerserkerAbility());
BlockedCreatureCount value = new BlockedCreatureCount();
Effect effect = new BoostSourceEffect(value, value, Duration.EndOfTurn);
effect.setText("it gets +1/+1 until end of turn for each creature blocking it");
this.addAbility(new BecomesBlockedTriggeredAbility(effect, false));
}
public ElvishBerserker(final ElvishBerserker card) {
@ -68,50 +72,3 @@ public class ElvishBerserker extends CardImpl {
return new ElvishBerserker(this);
}
}
class ElvishBerserkerAbility extends BecomesBlockedTriggeredAbility {
public ElvishBerserkerAbility() {
super(null, false);
ElvishBerserkerValue value = new ElvishBerserkerValue();
this.addEffect(new BoostSourceEffect(value, value, Duration.EndOfTurn));
}
public ElvishBerserkerAbility(final ElvishBerserkerAbility ability) {
super(ability);
}
@Override
public ElvishBerserkerAbility copy() {
return new ElvishBerserkerAbility(this);
}
@Override
public String getRule() {
return "Whenever {this} becomes blocked, it gets +1/+1 until end of turn for each creature blocking it.";
}
}
class ElvishBerserkerValue implements DynamicValue {
@Override
public ElvishBerserkerValue copy() {
return new ElvishBerserkerValue();
}
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
for(CombatGroup combatGroup : game.getCombat().getGroups()) {
if(combatGroup.getAttackers().contains(sourceAbility.getSourceId())) {
int blockers = combatGroup.getBlockers().size();
return blockers > 1 ? (blockers) : 0;
}
}
return 0;
}
@Override
public String getMessage() {
return "+1/+1 until end of turn for each creature blocking it";
}
}

View file

@ -29,17 +29,16 @@ package mage.sets.odyssey;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.BecomesBlockedTriggeredAbility;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.MultipliedValue;
import mage.abilities.dynamicvalue.common.BlockedCreatureCount;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.continuous.BoostSourceEffect;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Rarity;
import mage.game.Game;
import mage.game.combat.CombatGroup;
/**
*
@ -56,7 +55,10 @@ public class RabidElephant extends CardImpl {
this.toughness = new MageInt(4);
// Whenever Rabid Elephant becomes blocked, it gets +2/+2 until end of turn for each creature blocking it.
this.addAbility(new RabidElephantAbility());
DynamicValue value = new MultipliedValue(new BlockedCreatureCount(),2);
Effect effect = new BoostSourceEffect(value, value, Duration.EndOfTurn);
effect.setText("it gets +2/+2 until end of turn for each creature blocking it");
this.addAbility(new BecomesBlockedTriggeredAbility(effect, false));
}
public RabidElephant(final RabidElephant card) {
@ -68,50 +70,3 @@ public class RabidElephant extends CardImpl {
return new RabidElephant(this);
}
}
class RabidElephantAbility extends BecomesBlockedTriggeredAbility {
public RabidElephantAbility() {
super(null, false);
RabidElephantValue value = new RabidElephantValue();
this.addEffect(new BoostSourceEffect(value, value, Duration.EndOfTurn));
}
public RabidElephantAbility(final RabidElephantAbility ability) {
super(ability);
}
@Override
public RabidElephantAbility copy() {
return new RabidElephantAbility(this);
}
@Override
public String getRule() {
return "Whenever {this} becomes blocked, it gets +2/+2 until end of turn for each creature blocking it.";
}
}
class RabidElephantValue implements DynamicValue {
@Override
public RabidElephantValue copy() {
return new RabidElephantValue();
}
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
for(CombatGroup combatGroup : game.getCombat().getGroups()) {
if(combatGroup.getAttackers().contains(sourceAbility.getSourceId())) {
int blockers = combatGroup.getBlockers().size();
return blockers > 1 ? (blockers) * 2 : 0;
}
}
return 0;
}
@Override
public String getMessage() {
return "+2/+2 until end of turn for each creature blocking it";
}
}

View file

@ -52,7 +52,7 @@ public class RazorclawBear extends CardImpl {
// Whenever Razorclaw Bear becomes blocked, it gets +2/+2 until end of turn.
Effect effect = new BoostSourceEffect(2, 2, Duration.EndOfTurn);
effect.setText("it gets +2/+2 until end of turn for each creature blocking it");
effect.setText("it gets +2/+2 until end of turn");
this.addAbility(new BecomesBlockedTriggeredAbility(effect, false));
}

View file

@ -32,6 +32,8 @@ import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.BecomesBlockedByCreatureTriggeredAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.dynamicvalue.common.BlockedCreatureCount;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.continuous.BoostSourceEffect;
import mage.abilities.effects.common.continuous.GainAbilityAllEffect;
import mage.cards.CardImpl;
@ -54,7 +56,6 @@ public class SpinedSliver extends CardImpl {
filter.add(new SubtypePredicate("Sliver"));
}
public SpinedSliver(UUID ownerId) {
super(ownerId, 142, "Spined Sliver", Rarity.UNCOMMON, new CardType[]{CardType.CREATURE}, "{R}{G}");
this.expansionSetCode = "STH";
@ -64,7 +65,10 @@ public class SpinedSliver extends CardImpl {
this.toughness = new MageInt(2);
// Whenever a Sliver becomes blocked, that Sliver gets +1/+1 until end of turn for each creature blocking it.
Ability ability = new BecomesBlockedByCreatureTriggeredAbility(new BoostSourceEffect(1, 1, Duration.EndOfTurn), false);
BlockedCreatureCount value = new BlockedCreatureCount();
Effect effect = new BoostSourceEffect(value, value, Duration.EndOfTurn);
effect.setText("it gets +1/+1 until end of turn for each creature blocking it");
Ability ability = new BecomesBlockedByCreatureTriggeredAbility(effect, false);
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD,
new GainAbilityAllEffect(ability,
Duration.WhileOnBattlefield, filter,

View file

@ -32,6 +32,8 @@ import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.BecomesBlockedTriggeredAbility;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.MultipliedValue;
import mage.abilities.dynamicvalue.common.BlockedCreatureCount;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.continuous.BoostSourceEffect;
import mage.cards.CardImpl;
@ -57,7 +59,10 @@ public class GangOfElk extends CardImpl {
this.toughness = new MageInt(4);
// Whenever Gang of Elk becomes blocked, it gets +2/+2 until end of turn for each creature blocking it.
this.addAbility(new GangOfElkAbility());
DynamicValue value = new MultipliedValue(new BlockedCreatureCount(),2);
Effect effect = new BoostSourceEffect(value, value, Duration.EndOfTurn);
effect.setText("it gets +2/+2 until end of turn for each creature blocking it");
this.addAbility(new BecomesBlockedTriggeredAbility(effect, false));
}
public GangOfElk(final GangOfElk card) {
@ -69,50 +74,3 @@ public class GangOfElk extends CardImpl {
return new GangOfElk(this);
}
}
class GangOfElkAbility extends BecomesBlockedTriggeredAbility {
public GangOfElkAbility() {
super(null, false);
GangOfElkValue value = new GangOfElkValue();
this.addEffect(new BoostSourceEffect(value, value, Duration.EndOfTurn));
}
public GangOfElkAbility(final GangOfElkAbility ability) {
super(ability);
}
@Override
public GangOfElkAbility copy() {
return new GangOfElkAbility(this);
}
@Override
public String getRule() {
return "Whenever {this} becomes blocked, it gets +2/+2 until end of turn for each creature blocking it.";
}
}
class GangOfElkValue implements DynamicValue {
@Override
public GangOfElkValue copy() {
return new GangOfElkValue();
}
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
for(CombatGroup combatGroup : game.getCombat().getGroups()) {
if(combatGroup.getAttackers().contains(sourceAbility.getSourceId())) {
int blockers = combatGroup.getBlockers().size();
return blockers > 1 ? (blockers) * 2 : 0;
}
}
return 0;
}
@Override
public String getMessage() {
return "+2/+2 until end of turn for each creature blocking it";
}
}

View file

@ -0,0 +1,81 @@
/*
* 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.dynamicvalue.common;
import mage.abilities.Ability;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.effects.Effect;
import mage.game.Game;
import mage.game.combat.CombatGroup;
/**
*
* @author Markedagain
*/
public class BlockedCreatureCount implements DynamicValue {
private String message;
public BlockedCreatureCount() {
this("each creature blocking it");
}
public BlockedCreatureCount(String message) {
this.message = message;
}
public BlockedCreatureCount(final BlockedCreatureCount dynamicValue) {
super();
this.message = dynamicValue.message;
}
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
for(CombatGroup combatGroup : game.getCombat().getGroups()) {
if(combatGroup.getAttackers().contains(sourceAbility.getSourceId())) {
int blockers = combatGroup.getBlockers().size();
return blockers > 1 ? (blockers) : 0;
}
}
return 0;
}
@Override
public BlockedCreatureCount copy() {
return new BlockedCreatureCount(this);
}
@Override
public String getMessage() {
return message;
}
@Override
public String toString() {
return "X";
}
}