Fixed anymanacolor ability. Enhanced mana system.

This commit is contained in:
magenoxx 2012-05-23 12:49:38 +04:00
parent dc288e0c89
commit d88b373df2
12 changed files with 149 additions and 68 deletions

View file

@ -1,4 +1,4 @@
package org.mage.test.cards.single;
package org.mage.test.cards.abilities.curses;
import mage.Constants;
import org.junit.Test;

View file

@ -27,9 +27,9 @@
*/
package mage;
import mage.Constants.ManaType;
import mage.abilities.Ability;
import mage.abilities.condition.Condition;
import mage.abilities.mana.conditional.ManaCondition;
import mage.filter.Filter;
import mage.filter.FilterMana;
import mage.game.Game;
@ -37,6 +37,7 @@ import mage.game.Game;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
/**
* @author nantuko
@ -59,6 +60,11 @@ public class ConditionalMana extends Mana implements Serializable {
*/
private Filter.ComparisonScope scope = Filter.ComparisonScope.All;
/**
* UUID of source for mana.
*/
private UUID manaProducerId;
public ConditionalMana(Mana mana) {
super(mana);
}
@ -78,12 +84,15 @@ public class ConditionalMana extends Mana implements Serializable {
this.scope = scope;
}
public boolean apply(Ability ability, Game game) {
public boolean apply(Ability ability, Game game, UUID manaProducerId) {
if (conditions.size() == 0) {
throw new IllegalStateException("Conditional mana should contain at least one Condition");
}
for (Condition condition : conditions) {
if (!condition.apply(game, ability)) {
boolean applied = (condition instanceof ManaCondition) ?
((ManaCondition)condition).apply(game, ability, manaProducerId) : condition.apply(game, ability);
if (!applied) {
// if one condition fails, return false only if All conditions should be met
// otherwise it may happen that Any other condition will be ok
if (scope.equals(Filter.ComparisonScope.All)) {
@ -124,4 +133,11 @@ public class ConditionalMana extends Mana implements Serializable {
if (filter.isColorless()) colorless = 0;
}
public UUID getManaProducerId() {
return manaProducerId;
}
public void setManaProducerId(UUID manaProducerId) {
this.manaProducerId = manaProducerId;
}
}

View file

@ -8,10 +8,11 @@ import java.io.Serializable;
/**
* Interface describing condition occurrence.
*
* @author nantuko
* @author nantuko, noxx
*/
public interface Condition extends Serializable {
/**
/**
* Checks the game to see if this condition applies for the given ability.
*
* @param game

View file

@ -33,57 +33,59 @@ import mage.counters.CounterType;
import mage.game.Game;
import mage.filter.FilterPermanent;
import mage.game.permanent.Permanent;
import java.util.List;
/**
*
* @author jeffwadsworth
*/
public class PermanentHasCounterCondition implements Condition {
public static enum CountType { MORE_THAN, FEWER_THAN, EQUAL_TO };
private CounterType counterType;
private int amount;
private FilterPermanent filter;
private CountType type;
public PermanentHasCounterCondition(CounterType counterType, int amount, FilterPermanent filter) {
this(counterType, amount, filter, CountType.EQUAL_TO);
}
public PermanentHasCounterCondition(CounterType counterType, int amount, FilterPermanent filter, CountType type) {
this.counterType = counterType;
this.amount = amount;
this.filter = filter;
this.type = type;
}
@Override
public boolean apply(Game game, Ability source) {
boolean conditionApplies = false;
List<Permanent> permanents = game.getBattlefield().getAllActivePermanents(this.filter, source.getControllerId());
for (Permanent permanent : permanents) {
switch ( this.type ) {
case FEWER_THAN:
if (permanent.getCounters().getCount(this.counterType) < this.amount) {
conditionApplies = true;
break;
}
break;
case MORE_THAN:
if (permanent.getCounters().getCount(this.counterType) > this.amount) {
conditionApplies = true;
break;
}
break;
case EQUAL_TO:
if (permanent.getCounters().getCount(this.counterType) == this.amount) {
conditionApplies = true;
break;
}
break;
public static enum CountType {MORE_THAN, FEWER_THAN, EQUAL_TO}
;
private CounterType counterType;
private int amount;
private FilterPermanent filter;
private CountType type;
public PermanentHasCounterCondition(CounterType counterType, int amount, FilterPermanent filter) {
this(counterType, amount, filter, CountType.EQUAL_TO);
}
public PermanentHasCounterCondition(CounterType counterType, int amount, FilterPermanent filter, CountType type) {
this.counterType = counterType;
this.amount = amount;
this.filter = filter;
this.type = type;
}
@Override
public boolean apply(Game game, Ability source) {
boolean conditionApplies = false;
List<Permanent> permanents = game.getBattlefield().getAllActivePermanents(this.filter, source.getControllerId());
for (Permanent permanent : permanents) {
switch (this.type) {
case FEWER_THAN:
if (permanent.getCounters().getCount(this.counterType) < this.amount) {
conditionApplies = true;
break;
}
}
return conditionApplies;
}
break;
case MORE_THAN:
if (permanent.getCounters().getCount(this.counterType) > this.amount) {
conditionApplies = true;
break;
}
break;
case EQUAL_TO:
if (permanent.getCounters().getCount(this.counterType) == this.amount) {
conditionApplies = true;
break;
}
break;
}
}
return conditionApplies;
}
}

View file

@ -78,6 +78,9 @@ public class ColoredManaCost extends ManaCostImpl<ColoredManaCost> {
@Override
public boolean testPay(Mana testMana) {
if (testMana.getAny() > 0) {
return true;
}
switch (mana) {
case B:
return testMana.getBlack() > 0;

View file

@ -41,6 +41,7 @@ public class AnyColorManaAbility extends ManaAbility<AnyColorManaAbility> {
public AnyColorManaAbility(Cost cost) {
super(Constants.Zone.BATTLEFIELD, new AddManaOfAnyColorEffect(), cost);
this.addChoice(new ChoiceColor());
this.netMana.setAny(1);
}
public AnyColorManaAbility(final AnyColorManaAbility ability) {

View file

@ -51,6 +51,7 @@ public class ConditionalAnyColorManaAbility extends ManaAbility<ConditionalAnyCo
for (int i = 0; i < amount; i++) {
this.addChoice(new ChoiceColor());
}
this.netMana.setAny(amount);
}
public ConditionalAnyColorManaAbility(final ConditionalAnyColorManaAbility ability) {

View file

@ -28,7 +28,6 @@
package mage.abilities.mana;
import java.util.UUID;
import mage.Constants.AbilityType;
import mage.Constants.Zone;
import mage.Mana;
@ -37,6 +36,8 @@ import mage.abilities.costs.Cost;
import mage.abilities.effects.common.ManaEffect;
import mage.game.Game;
import java.util.UUID;
/**
*
* @author BetaSteward_at_googlemail.com

View file

@ -34,10 +34,12 @@ import mage.abilities.SpellAbility;
import mage.abilities.condition.Condition;
import mage.game.Game;
import java.util.UUID;
/**
* @author noxx
*/
class CreatureCastManaCondition implements Condition {
public class CreatureCastManaCondition extends ManaCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
if (source instanceof SpellAbility) {
@ -48,4 +50,9 @@ class CreatureCastManaCondition implements Condition {
}
return false;
}
@Override
public boolean apply(Game game, Ability source, UUID originalId) {
return apply(game, source, null);
}
}

View file

@ -0,0 +1,46 @@
/*
* 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.mana.conditional;
import mage.abilities.Ability;
import mage.abilities.condition.Condition;
import mage.game.Game;
import java.util.UUID;
/**
* @author noxx
*/
public abstract class ManaCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
return false;
}
public abstract boolean apply(Game game, Ability source, UUID originalId);
}

View file

@ -28,11 +28,6 @@
package mage.players;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import mage.ConditionalMana;
import mage.Constants.ManaType;
import mage.Mana;
@ -42,6 +37,11 @@ import mage.filter.FilterMana;
import mage.game.Game;
import mage.game.events.GameEvent;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
*
* @author BetaSteward_at_googlemail.com
@ -103,7 +103,7 @@ public class ManaPool implements Serializable {
return 0;
}
for (ManaPoolItem mana : manaItems) {
if (mana.isConditional() && mana.getConditionalMana().get(manaType) > 0 && mana.getConditionalMana().apply(ability, game)) {
if (mana.isConditional() && mana.getConditionalMana().get(manaType) > 0 && mana.getConditionalMana().apply(ability, game, mana.getSourceId())) {
if (filter == null || filter.match(game.getObject(mana.getSourceId())))
return mana.getConditionalMana().get(manaType);
}
@ -117,7 +117,7 @@ public class ManaPool implements Serializable {
}
int count = 0;
for (ConditionalMana mana : getConditionalMana()) {
if (mana.apply(ability, game)) {
if (mana.apply(ability, game, mana.getManaProducerId())) {
count += mana.count(filter);
}
}
@ -140,7 +140,8 @@ public class ManaPool implements Serializable {
while (it.hasNext()) {
ManaPoolItem item = it.next();
if (item.isConditional()) {
if (item.getConditionalMana().apply(ability, game)) {
ConditionalMana cm = item.getConditionalMana();
if (cm.apply(ability, game, cm.getManaProducerId())) {
total += item.count();
it.remove();
}
@ -170,7 +171,7 @@ public class ManaPool implements Serializable {
ManaPoolItem item = it.next();
if (item.isConditional()) {
ConditionalMana c = item.getConditionalMana();
if (c.apply(ability, game)) {
if (c.apply(ability, game, c.getManaProducerId())) {
int count = c.count(filter);
if (count > 0) {
total += count;
@ -246,10 +247,10 @@ public class ManaPool implements Serializable {
this.manaItems.add(new ManaPoolItem((ConditionalMana)mana, source.getSourceId()));
} else {
this.manaItems.add(new ManaPoolItem(mana.getRed(), mana.getGreen(), mana.getBlue(), mana.getWhite(), mana.getBlack(), mana.getColorless(), source.getSourceId()));
GameEvent event = GameEvent.getEvent(GameEvent.EventType.MANA_ADDED, source.getSourceId(), source.getId(), source.getControllerId());
event.setData(mana.toString());
game.fireEvent(event);
}
GameEvent event = GameEvent.getEvent(GameEvent.EventType.MANA_ADDED, source.getSourceId(), source.getId(), source.getControllerId());
event.setData(mana.toString());
game.fireEvent(event);
}
public List<ConditionalMana> getConditionalMana() {
@ -276,7 +277,7 @@ public class ManaPool implements Serializable {
private void removeConditional(ManaType manaType, Ability ability, Game game) {
for (ConditionalMana mana : getConditionalMana()) {
if (mana.get(manaType) > 0 && mana.apply(ability, game)) {
if (mana.get(manaType) > 0 && mana.apply(ability, game, mana.getManaProducerId())) {
mana.set(manaType, mana.get(manaType) - 1);
break;
}

View file

@ -27,12 +27,13 @@
*/
package mage.players;
import java.io.Serializable;
import java.util.UUID;
import mage.ConditionalMana;
import mage.Constants.ManaType;
import mage.Mana;
import java.io.Serializable;
import java.util.UUID;
/**
*
* @author BetaSteward_at_googlemail.com
@ -63,6 +64,7 @@ public class ManaPoolItem implements Serializable {
public ManaPoolItem(ConditionalMana conditionalMana, UUID sourceId) {
this.conditionalMana = conditionalMana;
this.sourceId = sourceId;
this.conditionalMana.setManaProducerId(sourceId);
}
public ManaPoolItem(final ManaPoolItem item) {