Added ChokingFumes card

Added AddCountersAllEffect
Refactoring and fixes for Counter adding effects
This commit is contained in:
North 2011-06-24 00:28:07 +03:00
parent a121913f22
commit 273ab90154
23 changed files with 213 additions and 143 deletions

View file

@ -0,0 +1,94 @@
/*
* 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.counter;
import java.util.List;
import java.util.UUID;
import mage.Constants.Outcome;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.counters.Counter;
import mage.filter.FilterPermanent;
import mage.game.Game;
import mage.game.permanent.Permanent;
/**
*
* @author North
*/
public class AddCountersAllEffect extends OneShotEffect<AddCountersAllEffect> {
private Counter counter;
private FilterPermanent filter;
public AddCountersAllEffect(Counter counter, FilterPermanent filter) {
super(Outcome.Benefit);
this.counter = counter;
this.filter = filter;
}
public AddCountersAllEffect(final AddCountersAllEffect effect) {
super(effect);
this.counter = effect.counter.copy();
this.filter = effect.filter.copy();
}
@Override
public boolean apply(Game game, Ability source) {
boolean applied = false;
if (counter != null) {
UUID controllerId = source.getControllerId();
List<Permanent> permanents = game.getBattlefield().getAllActivePermanents();
for (Permanent permanent : permanents) {
if (filter.match(permanent, controllerId, game)) {
permanent.addCounters(counter);
applied = true;
}
}
}
return applied;
}
@Override
public String getText(Ability source) {
StringBuilder sb = new StringBuilder();
sb.append("put ");
if (counter.getCount() > 1) {
sb.append(Integer.toString(counter.getCount())).append(" ").append(counter.getName()).append(" counters on each ");
} else {
sb.append("a ").append(counter.getName()).append(" counter on each ");
}
sb.append(filter.getMessage());
return sb.toString();
}
@Override
public AddCountersAllEffect copy() {
return new AddCountersAllEffect(this);
}
}

View file

@ -40,27 +40,15 @@ import mage.game.permanent.Permanent;
*/
public class AddCountersSourceEffect extends OneShotEffect<AddCountersSourceEffect> {
private int amount;
private String name;
private Counter counter;
public AddCountersSourceEffect(String name, int amount) {
super(Outcome.Benefit);
this.name = name;
this.amount = amount;
}
public AddCountersSourceEffect(Counter counter) {
super(Outcome.Benefit);
this.name = counter.getName();
this.counter = counter.copy();
this.amount = counter.getCount();
}
public AddCountersSourceEffect(final AddCountersSourceEffect effect) {
super(effect);
this.amount = effect.amount;
this.name = effect.name;
if (effect.counter != null)
this.counter = effect.counter.copy();
}
@ -71,8 +59,6 @@ public class AddCountersSourceEffect extends OneShotEffect<AddCountersSourceEffe
if (permanent != null) {
if (counter != null) {
permanent.addCounters(counter);
} else {
permanent.addCounters(name, amount);
}
}
return true;
@ -80,12 +66,12 @@ public class AddCountersSourceEffect extends OneShotEffect<AddCountersSourceEffe
@Override
public String getText(Ability source) {
if (amount > 1) {
if (counter.getCount() > 1) {
StringBuilder sb = new StringBuilder();
sb.append("put ").append(Integer.toString(amount)).append(" ").append(name).append(" counters on {this}");
sb.append("put ").append(Integer.toString(counter.getCount())).append(" ").append(counter.getName()).append(" counters on {this}");
return sb.toString();
} else
return "put a " + name + " counter on {this}";
return "put a " + counter.getName() + " counter on {this}";
}
@Override

View file

@ -44,20 +44,15 @@ import java.util.UUID;
*/
public class AddCountersTargetEffect extends OneShotEffect<AddCountersTargetEffect> {
private int amount;
private String name;
private Counter counter;
public AddCountersTargetEffect(Counter counter) {
super(Outcome.Benefit);
this.name = counter.getName();
this.counter = counter;
}
public AddCountersTargetEffect(final AddCountersTargetEffect effect) {
super(effect);
this.amount = effect.amount;
this.name = effect.name;
this.counter = effect.counter.copy();
}
@ -69,13 +64,13 @@ public class AddCountersTargetEffect extends OneShotEffect<AddCountersTargetEffe
if (permanent != null) {
if (counter != null) {
permanent.addCounters(counter);
} else {
permanent.addCounters(name, amount);
affectedTargets ++;
}
} else {
Player player = game.getPlayer(uuid);
if (player != null) {
player.getCounters().addCounter(counter);
affectedTargets ++;
}
}
}
@ -86,11 +81,11 @@ public class AddCountersTargetEffect extends OneShotEffect<AddCountersTargetEffe
public String getText(Ability source) {
StringBuilder sb = new StringBuilder();
sb.append("put ");
if (amount > 1) {
sb.append(Integer.toString(amount)).append(" ").append(name).append(" counters on ");
if (counter.getCount() > 1) {
sb.append(Integer.toString(counter.getCount())).append(" ").append(counter.getName()).append(" counters on target ");
}
else {
sb.append("a ").append(name).append(" counter on target ");
sb.append("a ").append(counter.getName()).append(" counter on target ");
}
sb.append(source.getTargets().get(0).getTargetName());
return sb.toString();

View file

@ -1,87 +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.abilities.effects.common.counter;
import mage.Constants.Outcome;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.counters.common.PlusOneCounter;
import mage.filter.FilterPermanent;
import mage.filter.common.FilterCreaturePermanent;
import mage.game.Game;
import mage.game.permanent.Permanent;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class AddPlusOneCountersControlledEffect extends OneShotEffect<AddPlusOneCountersControlledEffect> {
private int amount;
private FilterPermanent filter;
public AddPlusOneCountersControlledEffect(int amount) {
this(amount, FilterCreaturePermanent.getDefault());
}
public AddPlusOneCountersControlledEffect(int amount, FilterPermanent filter) {
super(Outcome.Benefit);
this.amount = amount;
this.filter = filter;
}
public AddPlusOneCountersControlledEffect(final AddPlusOneCountersControlledEffect effect) {
super(effect);
this.amount = effect.amount;
this.filter = effect.filter.copy();
}
@Override
public AddPlusOneCountersControlledEffect copy() {
return new AddPlusOneCountersControlledEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
for (Permanent perm: game.getBattlefield().getAllActivePermanents(filter, source.getControllerId())) {
perm.getCounters().addCounter(new PlusOneCounter(amount)); }
return true;
}
@Override
public String getText(Ability source) {
StringBuilder sb = new StringBuilder();
sb.append("Put ").append(amount).append(" +1/+1 counter");
if (amount > 1)
sb.append("s");
sb.append(" on each ").append(filter.getName()).append(" you control");
return sb.toString();
}
}

View file

@ -33,6 +33,7 @@ import mage.Constants.Zone;
import mage.abilities.ActivatedAbilityImpl;
import mage.abilities.costs.mana.ManaCosts;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.counters.common.LevelCounter;
/**
*
@ -41,7 +42,7 @@ import mage.abilities.effects.common.counter.AddCountersSourceEffect;
public class LevelUpAbility extends ActivatedAbilityImpl<LevelUpAbility> {
public LevelUpAbility(ManaCosts costs) {
super(Zone.BATTLEFIELD, new AddCountersSourceEffect("Level", 1), costs);
super(Zone.BATTLEFIELD, new AddCountersSourceEffect(new LevelCounter()), costs);
this.timing = TimingRule.SORCERY;
}

View file

@ -41,8 +41,14 @@ public class Counter<T extends Counter<T>> implements Serializable {
public Counter(String name) {
this.name = name;
this.count = 1;
}
public Counter(String name, int count) {
this.name = name;
this.count = count;
}
public Counter(Counter counter) {
this.name = counter.name;
this.count = counter.count;