[refactor] removed BoostCounter implementations

This commit is contained in:
North 2014-05-31 18:43:05 +03:00
parent 44785267ec
commit ca1af753eb
12 changed files with 31 additions and 170 deletions

View file

@ -86,23 +86,6 @@ public class Contagion extends CardImpl<Contagion> {
} }
} }
class ContagionCounter extends BoostCounter {
public ContagionCounter(int count) {
super(-2, -1);
this.count = count;
}
public ContagionCounter(final ContagionCounter counter) {
super(counter);
}
@Override
public ContagionCounter copy() {
return new ContagionCounter(this);
}
}
class DistributeCountersEffect extends OneShotEffect<DistributeCountersEffect> { class DistributeCountersEffect extends OneShotEffect<DistributeCountersEffect> {
@ -126,7 +109,8 @@ class DistributeCountersEffect extends OneShotEffect<DistributeCountersEffect> {
for (UUID target: multiTarget.getTargets()) { for (UUID target: multiTarget.getTargets()) {
Permanent permanent = game.getPermanent(target); Permanent permanent = game.getPermanent(target);
if (permanent != null) { if (permanent != null) {
permanent.addCounters(new ContagionCounter(multiTarget.getTargetAmount(target)), game); int amount = multiTarget.getTargetAmount(target);
permanent.addCounters(new BoostCounter(-2, -1, amount), game);
} }
} }
} }

View file

@ -39,7 +39,7 @@ import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.constants.Zone; import mage.constants.Zone;
import mage.counters.common.PlusOneCounter; import mage.counters.CounterType;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType; import mage.game.events.GameEvent.EventType;
@ -63,9 +63,9 @@ public class SavageFirecat extends CardImpl<SavageFirecat> {
// Trample // Trample
this.addAbility(TrampleAbility.getInstance()); this.addAbility(TrampleAbility.getInstance());
// Savage Firecat enters the battlefield with seven +1/+1 counters on it. // Savage Firecat enters the battlefield with seven +1/+1 counters on it.
this.addAbility(new EntersBattlefieldAbility(new AddCountersSourceEffect(new PlusOneCounter(7)))); this.addAbility(new EntersBattlefieldAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance(7))));
// Whenever you tap a land for mana, remove a +1/+1 counter from Savage Firecat. // Whenever you tap a land for mana, remove a +1/+1 counter from Savage Firecat.
this.addAbility(new SavageFirecatTriggeredAbility(new RemoveCounterSourceEffect(new PlusOneCounter(1)))); this.addAbility(new SavageFirecatTriggeredAbility(new RemoveCounterSourceEffect(CounterType.P1P1.createInstance())));
} }

View file

@ -35,7 +35,7 @@ import mage.abilities.keyword.FlyingAbility;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.counters.common.PlusOneCounter; import mage.counters.CounterType;
import mage.filter.common.FilterCreaturePermanent; import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.mageobject.AbilityPredicate; import mage.filter.predicate.mageobject.AbilityPredicate;
@ -64,7 +64,7 @@ public class Soulcatcher extends CardImpl<Soulcatcher> {
// Flying // Flying
this.addAbility(FlyingAbility.getInstance()); this.addAbility(FlyingAbility.getInstance());
// Whenever a creature with flying dies, put a +1/+1 counter on Soulcatcher. // Whenever a creature with flying dies, put a +1/+1 counter on Soulcatcher.
this.addAbility(new DiesCreatureTriggeredAbility(new AddCountersSourceEffect(new PlusOneCounter()), false, filter)); this.addAbility(new DiesCreatureTriggeredAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance()), false, filter));
} }
public Soulcatcher(final Soulcatcher card) { public Soulcatcher(final Soulcatcher card) {

View file

@ -35,7 +35,7 @@ import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.counters.common.PlusOneCounter; import mage.counters.CounterType;
/** /**
* *
@ -53,7 +53,7 @@ public class IvyElemental extends CardImpl<IvyElemental> {
this.toughness = new MageInt(0); this.toughness = new MageInt(0);
// Ivy Elemental enters the battlefield with X +1/+1 counters on it. // Ivy Elemental enters the battlefield with X +1/+1 counters on it.
this.addAbility(new EntersBattlefieldAbility(new AddCountersSourceEffect(new PlusOneCounter(), new ManacostVariableValue(), true), "with X +1/+1 counters on it")); this.addAbility(new EntersBattlefieldAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance(), new ManacostVariableValue(), true), "with X +1/+1 counters on it"));
} }
public IvyElemental(final IvyElemental card) { public IvyElemental(final IvyElemental card) {

View file

@ -95,7 +95,7 @@ class WallOfRootsCost extends CostImpl<WallOfRootsCost> {
public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana) { public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana) {
Permanent permanent = game.getPermanent(sourceId); Permanent permanent = game.getPermanent(sourceId);
if (permanent != null) { if (permanent != null) {
permanent.addCounters(new WallOfRootsCounter(), game); permanent.addCounters(new BoostCounter(0, -1), game);
this.paid = true; this.paid = true;
} }
return paid; return paid;
@ -106,19 +106,3 @@ class WallOfRootsCost extends CostImpl<WallOfRootsCost> {
return new WallOfRootsCost(this); return new WallOfRootsCost(this);
} }
} }
class WallOfRootsCounter extends BoostCounter {
public WallOfRootsCounter() {
super(0, -1);
}
public WallOfRootsCounter(final WallOfRootsCounter counter) {
super(counter);
}
@Override
public WallOfRootsCounter copy() {
return new WallOfRootsCounter(this);
}
}

View file

@ -39,7 +39,7 @@ import mage.abilities.costs.mana.GenericManaCost;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.keyword.EquipAbility; import mage.abilities.keyword.EquipAbility;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.counters.common.PlusOneCounter; import mage.counters.CounterType;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType; import mage.game.events.GameEvent.EventType;
@ -129,10 +129,10 @@ class BladeOfTheBloodchiefEffect extends OneShotEffect<BladeOfTheBloodchiefEffec
Permanent creature = game.getPermanent(enchantment.getAttachedTo()); Permanent creature = game.getPermanent(enchantment.getAttachedTo());
if (creature != null) { if (creature != null) {
if ( creature.hasSubtype("Vampire") ) { if ( creature.hasSubtype("Vampire") ) {
creature.addCounters(new PlusOneCounter(2), game); creature.addCounters(CounterType.P1P1.createInstance(2), game);
} }
else { else {
creature.addCounters(new PlusOneCounter(1), game); creature.addCounters(CounterType.P1P1.createInstance(), game);
} }
} }
} }

View file

@ -38,7 +38,7 @@ import mage.abilities.effects.common.counter.AddCountersTargetEffect;
import mage.abilities.effects.common.UntapTargetEffect; import mage.abilities.effects.common.UntapTargetEffect;
import mage.abilities.keyword.HasteAbility; import mage.abilities.keyword.HasteAbility;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.counters.common.PlusOneCounter; import mage.counters.CounterType;
import mage.target.common.TargetCreaturePermanent; import mage.target.common.TargetCreaturePermanent;
/** /**
@ -54,7 +54,7 @@ public class MarkOfMutiny extends CardImpl<MarkOfMutiny> {
this.color.setRed(true); this.color.setRed(true);
this.getSpellAbility().addTarget(new TargetCreaturePermanent()); this.getSpellAbility().addTarget(new TargetCreaturePermanent());
this.getSpellAbility().addEffect(new GainControlTargetEffect(Duration.EndOfTurn)); this.getSpellAbility().addEffect(new GainControlTargetEffect(Duration.EndOfTurn));
this.getSpellAbility().addEffect(new AddCountersTargetEffect(new PlusOneCounter())); this.getSpellAbility().addEffect(new AddCountersTargetEffect(CounterType.P1P1.createInstance()));
this.getSpellAbility().addEffect(new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn)); this.getSpellAbility().addEffect(new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn));
this.getSpellAbility().addEffect(new UntapTargetEffect()); this.getSpellAbility().addEffect(new UntapTargetEffect());
} }

View file

@ -32,7 +32,7 @@ import mage.constants.Outcome;
import mage.constants.Zone; import mage.constants.Zone;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.counters.common.PlusOneCounter; import mage.counters.CounterType;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.util.CardUtil; import mage.util.CardUtil;
@ -70,7 +70,7 @@ public class AddPlusOneCountersAttachedEffect extends OneShotEffect<AddPlusOneCo
if (enchantment != null && enchantment.getAttachedTo() != null) { if (enchantment != null && enchantment.getAttachedTo() != null) {
Permanent creature = game.getPermanent(enchantment.getAttachedTo()); Permanent creature = game.getPermanent(enchantment.getAttachedTo());
if (creature != null) { if (creature != null) {
creature.addCounters(new PlusOneCounter(amount), game); creature.addCounters(CounterType.P1P1.createInstance(amount), game);
} }
} }
return true; return true;

View file

@ -32,13 +32,17 @@ package mage.counters;
* *
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
public abstract class BoostCounter extends Counter { public class BoostCounter extends Counter {
protected int power; protected int power;
protected int toughness; protected int toughness;
public BoostCounter(int power, int toughness) { public BoostCounter(int power, int toughness) {
super(String.format("%1$+d/%2$+d", power, toughness)); this(power, toughness, 1);
}
public BoostCounter(int power, int toughness, int count) {
super(String.format("%1$+d/%2$+d", power, toughness), count);
this.power = power; this.power = power;
this.toughness = toughness; this.toughness = toughness;
} }
@ -57,4 +61,8 @@ public abstract class BoostCounter extends Counter {
return toughness; return toughness;
} }
@Override
public BoostCounter copy() {
return new BoostCounter(this);
}
} }

View file

@ -28,9 +28,6 @@
package mage.counters; package mage.counters;
import mage.counters.common.MinusOneCounter;
import mage.counters.common.PlusOneCounter;
/** /**
* Enum for counters, names and instances. * Enum for counters, names and instances.
* *
@ -63,9 +60,9 @@ public enum CounterType {
LEVEL("Level"), LEVEL("Level"),
LORE("Lore"), LORE("Lore"),
LOYALTY("Loyalty"), LOYALTY("Loyalty"),
M1M1(new MinusOneCounter().name), M1M1(new BoostCounter(-1, -1).name),
MINING("Mining"), MINING("Mining"),
P1P1(new PlusOneCounter().name), P1P1(new BoostCounter(1, 1).name),
PAGE("Page"), PAGE("Page"),
PAIN("Pain"), PAIN("Pain"),
PETRIFICATION("Petrification"), PETRIFICATION("Petrification"),
@ -116,9 +113,9 @@ public enum CounterType {
public Counter createInstance(int amount) { public Counter createInstance(int amount) {
switch (this) { switch (this) {
case P1P1: case P1P1:
return new PlusOneCounter(amount); return new BoostCounter(1, 1, amount);
case M1M1: case M1M1:
return new MinusOneCounter(amount); return new BoostCounter(-1, -1, amount);
default: default:
return new Counter(name, amount); return new Counter(name, amount);
} }

View file

@ -1,56 +0,0 @@
/*
* 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.counters.common;
import mage.counters.BoostCounter;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class MinusOneCounter extends BoostCounter {
public MinusOneCounter() {
super(-1, -1);
}
public MinusOneCounter(int amount) {
super(-1, -1);
this.count = amount;
}
public MinusOneCounter(final MinusOneCounter counter) {
super(counter);
}
@Override
public MinusOneCounter copy() {
return new MinusOneCounter(this);
}
}

View file

@ -1,56 +0,0 @@
/*
* 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.counters.common;
import mage.counters.BoostCounter;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class PlusOneCounter extends BoostCounter {
public PlusOneCounter() {
this(1);
}
public PlusOneCounter(int amount) {
super(1, 1);
this.count = amount;
}
public PlusOneCounter(final PlusOneCounter counter) {
super(counter);
}
@Override
public PlusOneCounter copy() {
return new PlusOneCounter(this);
}
}