mirror of
https://github.com/correl/mage.git
synced 2025-01-11 11:05:23 +00:00
* Improved mana source check. Fixed #1513.
This commit is contained in:
parent
6726f48669
commit
74799d286b
19 changed files with 294 additions and 170 deletions
|
@ -343,11 +343,9 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
|||
target.add(abilityControllerId, game);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (target.canTarget(randomOpponentId, null, game)) {
|
||||
target.add(randomOpponentId, game);
|
||||
return true;
|
||||
}
|
||||
} else if (target.canTarget(randomOpponentId, null, game)) {
|
||||
target.add(randomOpponentId, game);
|
||||
return true;
|
||||
}
|
||||
if (!target.isRequired(sourceId, game)) {
|
||||
return false;
|
||||
|
@ -378,11 +376,9 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
|||
target.add(abilityControllerId, game);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (target.canTarget(randomOpponentId, null, game)) {
|
||||
target.add(randomOpponentId, game);
|
||||
return true;
|
||||
}
|
||||
} else if (target.canTarget(randomOpponentId, null, game)) {
|
||||
target.add(randomOpponentId, game);
|
||||
return true;
|
||||
}
|
||||
if (!target.isRequired(sourceId, game) || target.getNumberOfTargets() == 0) {
|
||||
return false;
|
||||
|
@ -580,11 +576,9 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
|||
target.addTarget(abilityControllerId, source, game);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (target.canTarget(getId(), randomOpponentId, source, game)) {
|
||||
target.addTarget(randomOpponentId, source, game);
|
||||
return true;
|
||||
}
|
||||
} else if (target.canTarget(getId(), randomOpponentId, source, game)) {
|
||||
target.addTarget(randomOpponentId, source, game);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -606,11 +600,9 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
|||
target.addTarget(abilityControllerId, source, game);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (target.canTarget(getId(), randomOpponentId, source, game)) {
|
||||
target.addTarget(randomOpponentId, source, game);
|
||||
return true;
|
||||
}
|
||||
} else if (target.canTarget(getId(), randomOpponentId, source, game)) {
|
||||
target.addTarget(randomOpponentId, source, game);
|
||||
return true;
|
||||
}
|
||||
|
||||
//if (!target.isRequired())
|
||||
|
@ -1024,10 +1016,8 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
|||
playableNonInstant.add(card);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!playableInstant.contains(card) && !playableNonInstant.contains(card)) {
|
||||
unplayable.put(mana.needed(avail), card);
|
||||
}
|
||||
} else if (!playableInstant.contains(card) && !playableNonInstant.contains(card)) {
|
||||
unplayable.put(mana.needed(avail), card);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1045,7 +1035,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
|||
option.add(Mana.GenericMana(3));
|
||||
}
|
||||
}
|
||||
if (abilityOptions.size() == 0) {
|
||||
if (abilityOptions.isEmpty()) {
|
||||
playableAbilities.add(ability);
|
||||
} else {
|
||||
for (Mana mana : abilityOptions) {
|
||||
|
@ -1063,7 +1053,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
|||
for (ActivatedAbility ability : card.getAbilities().getActivatedAbilities(Zone.GRAVEYARD)) {
|
||||
if (ability.canActivate(playerId, game)) {
|
||||
ManaOptions abilityOptions = ability.getManaCosts().getOptions();
|
||||
if (abilityOptions.size() == 0) {
|
||||
if (abilityOptions.isEmpty()) {
|
||||
playableAbilities.add(ability);
|
||||
} else {
|
||||
for (Mana mana : abilityOptions) {
|
||||
|
@ -1096,7 +1086,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
|||
// log.info("paying for " + unpaid.getText());
|
||||
boolean spendAnyMana = game.getContinuousEffects().asThough(ability.getSourceId(), AsThoughEffectType.SPEND_OTHER_MANA, ability, ability.getControllerId(), game);
|
||||
ManaCost cost;
|
||||
List<Permanent> producers;
|
||||
List<MageObject> producers;
|
||||
if (unpaid instanceof ManaCosts) {
|
||||
ManaCosts<ManaCost> manaCosts = (ManaCosts<ManaCost>) unpaid;
|
||||
cost = manaCosts.get(manaCosts.size() - 1);
|
||||
|
@ -1106,11 +1096,11 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
|||
producers = this.getAvailableManaProducers(game);
|
||||
producers.addAll(this.getAvailableManaProducersWithCost(game));
|
||||
}
|
||||
for (Permanent perm : producers) {
|
||||
for (MageObject mageObject : producers) {
|
||||
// use color producing mana abilities with costs first that produce all color manas that are needed to pay
|
||||
// otherwise the computer may not be able to pay the cost for that source
|
||||
ManaAbility:
|
||||
for (ManaAbility manaAbility : perm.getAbilities().getAvailableManaAbilities(Zone.BATTLEFIELD, game)) {
|
||||
for (ManaAbility manaAbility : mageObject.getAbilities().getAvailableManaAbilities(Zone.BATTLEFIELD, game)) {
|
||||
int colored = 0;
|
||||
for (Mana mana : manaAbility.getNetMana(game)) {
|
||||
if (!unpaid.getMana().includesMana(mana)) {
|
||||
|
@ -1131,9 +1121,9 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
|||
}
|
||||
}
|
||||
|
||||
for (Permanent perm : producers) {
|
||||
for (MageObject mageObject : producers) {
|
||||
// pay all colored costs first
|
||||
for (ManaAbility manaAbility : perm.getAbilities().getAvailableManaAbilities(Zone.BATTLEFIELD, game)) {
|
||||
for (ManaAbility manaAbility : mageObject.getAbilities().getAvailableManaAbilities(Zone.BATTLEFIELD, game)) {
|
||||
if (cost instanceof ColoredManaCost) {
|
||||
for (Mana netMana : manaAbility.getNetMana(game)) {
|
||||
if (cost.testPay(netMana) || spendAnyMana) {
|
||||
|
@ -1145,7 +1135,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
|||
}
|
||||
}
|
||||
// then pay hybrid
|
||||
for (ManaAbility manaAbility : perm.getAbilities().getAvailableManaAbilities(Zone.BATTLEFIELD, game)) {
|
||||
for (ManaAbility manaAbility : mageObject.getAbilities().getAvailableManaAbilities(Zone.BATTLEFIELD, game)) {
|
||||
if (cost instanceof HybridManaCost) {
|
||||
for (Mana netMana : manaAbility.getNetMana(game)) {
|
||||
if (cost.testPay(netMana) || spendAnyMana) {
|
||||
|
@ -1157,7 +1147,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
|||
}
|
||||
}
|
||||
// then pay mono hybrid
|
||||
for (ManaAbility manaAbility : perm.getAbilities().getAvailableManaAbilities(Zone.BATTLEFIELD, game)) {
|
||||
for (ManaAbility manaAbility : mageObject.getAbilities().getAvailableManaAbilities(Zone.BATTLEFIELD, game)) {
|
||||
if (cost instanceof MonoHybridManaCost) {
|
||||
for (Mana netMana : manaAbility.getNetMana(game)) {
|
||||
if (cost.testPay(netMana) || spendAnyMana) {
|
||||
|
@ -1169,7 +1159,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
|||
}
|
||||
}
|
||||
// pay colorless
|
||||
for (ManaAbility manaAbility : perm.getAbilities().getAvailableManaAbilities(Zone.BATTLEFIELD, game)) {
|
||||
for (ManaAbility manaAbility : mageObject.getAbilities().getAvailableManaAbilities(Zone.BATTLEFIELD, game)) {
|
||||
if (cost instanceof ColorlessManaCost) {
|
||||
for (Mana netMana : manaAbility.getNetMana(game)) {
|
||||
if (cost.testPay(netMana) || spendAnyMana) {
|
||||
|
@ -1181,7 +1171,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
|||
}
|
||||
}
|
||||
// finally pay generic
|
||||
for (ManaAbility manaAbility : perm.getAbilities().getAvailableManaAbilities(Zone.BATTLEFIELD, game)) {
|
||||
for (ManaAbility manaAbility : mageObject.getAbilities().getAvailableManaAbilities(Zone.BATTLEFIELD, game)) {
|
||||
if (cost instanceof GenericManaCost) {
|
||||
for (Mana netMana : manaAbility.getNetMana(game)) {
|
||||
if (cost.testPay(netMana) || spendAnyMana) {
|
||||
|
@ -1216,15 +1206,15 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
|||
* @param game
|
||||
* @return List<Permanent>
|
||||
*/
|
||||
private List<Permanent> getSortedProducers(ManaCosts<ManaCost> unpaid, Game game) {
|
||||
List<Permanent> unsorted = this.getAvailableManaProducers(game);
|
||||
private List<MageObject> getSortedProducers(ManaCosts<ManaCost> unpaid, Game game) {
|
||||
List<MageObject> unsorted = this.getAvailableManaProducers(game);
|
||||
unsorted.addAll(this.getAvailableManaProducersWithCost(game));
|
||||
Map<Permanent, Integer> scored = new HashMap<>();
|
||||
for (Permanent permanent : unsorted) {
|
||||
Map<MageObject, Integer> scored = new HashMap<>();
|
||||
for (MageObject mageObject : unsorted) {
|
||||
int score = 0;
|
||||
for (ManaCost cost : unpaid) {
|
||||
Abilities:
|
||||
for (ManaAbility ability : permanent.getAbilities().getAvailableManaAbilities(Zone.BATTLEFIELD, game)) {
|
||||
for (ManaAbility ability : mageObject.getAbilities().getAvailableManaAbilities(Zone.BATTLEFIELD, game)) {
|
||||
for (Mana netMana : ability.getNetMana(game)) {
|
||||
if (cost.testPay(netMana)) {
|
||||
score++;
|
||||
|
@ -1234,29 +1224,29 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
|||
}
|
||||
}
|
||||
if (score > 0) { // score mana producers that produce other mana types and have other uses higher
|
||||
score += permanent.getAbilities().getAvailableManaAbilities(Zone.BATTLEFIELD, game).size();
|
||||
score += permanent.getAbilities().getActivatedAbilities(Zone.BATTLEFIELD).size();
|
||||
if (!permanent.getCardType().contains(CardType.LAND)) {
|
||||
score += mageObject.getAbilities().getAvailableManaAbilities(Zone.BATTLEFIELD, game).size();
|
||||
score += mageObject.getAbilities().getActivatedAbilities(Zone.BATTLEFIELD).size();
|
||||
if (!mageObject.getCardType().contains(CardType.LAND)) {
|
||||
score += 2;
|
||||
} else if (permanent.getCardType().contains(CardType.CREATURE)) {
|
||||
} else if (mageObject.getCardType().contains(CardType.CREATURE)) {
|
||||
score += 2;
|
||||
}
|
||||
}
|
||||
scored.put(permanent, score);
|
||||
scored.put(mageObject, score);
|
||||
}
|
||||
return sortByValue(scored);
|
||||
}
|
||||
|
||||
private List<Permanent> sortByValue(Map<Permanent, Integer> map) {
|
||||
List<Entry<Permanent, Integer>> list = new LinkedList<>(map.entrySet());
|
||||
Collections.sort(list, new Comparator<Entry<Permanent, Integer>>() {
|
||||
private List<MageObject> sortByValue(Map<MageObject, Integer> map) {
|
||||
List<Entry<MageObject, Integer>> list = new LinkedList<>(map.entrySet());
|
||||
Collections.sort(list, new Comparator<Entry<MageObject, Integer>>() {
|
||||
@Override
|
||||
public int compare(Entry<Permanent, Integer> o1, Entry<Permanent, Integer> o2) {
|
||||
public int compare(Entry<MageObject, Integer> o1, Entry<MageObject, Integer> o2) {
|
||||
return (o1.getValue().compareTo(o2.getValue()));
|
||||
}
|
||||
});
|
||||
List<Permanent> result = new ArrayList<>();
|
||||
for (Entry<Permanent, Integer> entry : list) {
|
||||
List<MageObject> result = new ArrayList<>();
|
||||
for (Entry<MageObject, Integer> entry : list) {
|
||||
result.add(entry.getKey());
|
||||
}
|
||||
return result;
|
||||
|
@ -1595,7 +1585,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<Permanent> getAvailableManaProducers(Game game) {
|
||||
public List<MageObject> getAvailableManaProducers(Game game) {
|
||||
return super.getAvailableManaProducers(game);
|
||||
}
|
||||
|
||||
|
@ -2174,11 +2164,9 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
|||
target.add(randomOpponentId, game);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (((TargetOpponent) target).canTarget(randomOpponentId, source, game)) {
|
||||
target.add(randomOpponentId, game);
|
||||
return true;
|
||||
}
|
||||
} else if (((TargetOpponent) target).canTarget(randomOpponentId, source, game)) {
|
||||
target.add(randomOpponentId, game);
|
||||
return true;
|
||||
}
|
||||
for (UUID currentId : game.getOpponents(abilityControllerId)) {
|
||||
if (source == null) {
|
||||
|
@ -2186,11 +2174,9 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
|||
target.add(currentId, game);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (((TargetOpponent) target).canTarget(currentId, source, game)) {
|
||||
target.add(currentId, game);
|
||||
return true;
|
||||
}
|
||||
} else if (((TargetOpponent) target).canTarget(currentId, source, game)) {
|
||||
target.add(currentId, game);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -2222,29 +2208,27 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
|||
}
|
||||
}
|
||||
|
||||
} else if (source == null) {
|
||||
if (target.canTarget(randomOpponentId, game)) {
|
||||
target.add(randomOpponentId, game);
|
||||
return true;
|
||||
}
|
||||
if (target.isRequired(sourceId, game)) {
|
||||
if (target.canTarget(abilityControllerId, game)) {
|
||||
target.add(abilityControllerId, game);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (source == null) {
|
||||
if (target.canTarget(randomOpponentId, game)) {
|
||||
target.add(randomOpponentId, game);
|
||||
if (target.canTarget(randomOpponentId, game)) {
|
||||
target.add(randomOpponentId, game);
|
||||
return true;
|
||||
}
|
||||
if (target.isRequired(sourceId, game)) {
|
||||
if (target.canTarget(abilityControllerId, game)) {
|
||||
target.add(abilityControllerId, game);
|
||||
return true;
|
||||
}
|
||||
if (target.isRequired(sourceId, game)) {
|
||||
if (target.canTarget(abilityControllerId, game)) {
|
||||
target.add(abilityControllerId, game);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (target.canTarget(randomOpponentId, game)) {
|
||||
target.add(randomOpponentId, game);
|
||||
return true;
|
||||
}
|
||||
if (target.isRequired(sourceId, game)) {
|
||||
if (target.canTarget(abilityControllerId, game)) {
|
||||
target.add(abilityControllerId, game);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -29,7 +29,6 @@ package mage.sets.newphyrexia;
|
|||
|
||||
import java.util.UUID;
|
||||
import mage.MageInt;
|
||||
import mage.abilities.StaticAbility;
|
||||
import mage.abilities.common.SimpleStaticAbility;
|
||||
import mage.abilities.effects.common.InfoEffect;
|
||||
import mage.cards.CardImpl;
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* 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 org.mage.test.cards.mana;
|
||||
|
||||
import mage.constants.PhaseStep;
|
||||
import mage.constants.Zone;
|
||||
import org.junit.Test;
|
||||
import org.mage.test.serverside.base.CardTestPlayerBase;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class ManaSourceTest extends CardTestPlayerBase {
|
||||
|
||||
/**
|
||||
* I can use Simian Spirit Guide's mana to cast Myr Superion, but it is a
|
||||
* creature card and not a creature when it is in hand, so it's wrong.
|
||||
*/
|
||||
@Test
|
||||
public void testCantCastWithCreatureCard() {
|
||||
// Exile Simian Spirit Guide from your hand: Add {R} to your mana pool.
|
||||
addCard(Zone.HAND, playerB, "Simian Spirit Guide", 1);
|
||||
// Spend only mana produced by creatures to cast Myr Superion.
|
||||
addCard(Zone.HAND, playerB, "Myr Superion", 1); // {2}
|
||||
|
||||
addCard(Zone.BATTLEFIELD, playerB, "Manakin", 1);
|
||||
|
||||
activateManaAbility(2, PhaseStep.PRECOMBAT_MAIN, playerB, "Exile");
|
||||
castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerB, "Myr Superion");
|
||||
|
||||
setStopAt(2, PhaseStep.BEGIN_COMBAT);
|
||||
execute();
|
||||
|
||||
assertExileCount("Simian Spirit Guide", 1);
|
||||
|
||||
assertPermanentCount(playerB, "Myr Superion", 0);
|
||||
assertHandCount(playerB, "Myr Superion", 1);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -392,14 +392,34 @@ public class TestPlayer implements Player {
|
|||
String command = action.getAction();
|
||||
command = command.substring(command.indexOf("manaActivate:") + 13);
|
||||
String[] groups = command.split("\\$");
|
||||
List<Permanent> manaPerms = computerPlayer.getAvailableManaProducers(game);
|
||||
for (Permanent perm : manaPerms) {
|
||||
for (Ability manaAbility : perm.getAbilities().getAvailableManaAbilities(Zone.BATTLEFIELD, game)) {
|
||||
if (manaAbility.toString().startsWith(groups[0])) {
|
||||
Ability newManaAbility = manaAbility.copy();
|
||||
computerPlayer.activateAbility((ActivatedAbility) newManaAbility, game);
|
||||
actions.remove(action);
|
||||
return true;
|
||||
List<MageObject> manaObjects = computerPlayer.getAvailableManaProducers(game);
|
||||
for (MageObject mageObject : manaObjects) {
|
||||
if (mageObject instanceof Permanent) {
|
||||
for (Ability manaAbility : ((Permanent) mageObject).getAbilities(game).getAvailableManaAbilities(Zone.BATTLEFIELD, game)) {
|
||||
if (manaAbility.toString().startsWith(groups[0])) {
|
||||
Ability newManaAbility = manaAbility.copy();
|
||||
computerPlayer.activateAbility((ActivatedAbility) newManaAbility, game);
|
||||
actions.remove(action);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if (mageObject instanceof Card) {
|
||||
for (Ability manaAbility : ((Card) mageObject).getAbilities(game).getAvailableManaAbilities(game.getState().getZone(mageObject.getId()), game)) {
|
||||
if (manaAbility.toString().startsWith(groups[0])) {
|
||||
Ability newManaAbility = manaAbility.copy();
|
||||
computerPlayer.activateAbility((ActivatedAbility) newManaAbility, game);
|
||||
actions.remove(action);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (Ability manaAbility : mageObject.getAbilities().getAvailableManaAbilities(game.getState().getZone(mageObject.getId()), game)) {
|
||||
if (manaAbility.toString().startsWith(groups[0])) {
|
||||
Ability newManaAbility = manaAbility.copy();
|
||||
computerPlayer.activateAbility((ActivatedAbility) newManaAbility, game);
|
||||
actions.remove(action);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -127,7 +127,7 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
|
|||
|
||||
@Override
|
||||
public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana, Cost costToPay) {
|
||||
if (this.size() == 0 || noMana) {
|
||||
if (this.isEmpty() || noMana) {
|
||||
setPaid();
|
||||
return true;
|
||||
}
|
||||
|
@ -330,35 +330,28 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
|
|||
if (symbol.length() == 1 || isNumeric(symbol)) {
|
||||
if (Character.isDigit(symbol.charAt(0))) {
|
||||
this.add(new GenericManaCost(Integer.valueOf(symbol)));
|
||||
} else {
|
||||
if (symbol.equals("S")) {
|
||||
this.add(new SnowManaCost());
|
||||
} else if (symbol.equals("C")) {
|
||||
this.add(new ColorlessManaCost(1));
|
||||
} else if (!symbol.equals("X")) {
|
||||
this.add(new ColoredManaCost(ColoredManaSymbol.lookup(symbol.charAt(0))));
|
||||
} else {
|
||||
// check X wasn't added before
|
||||
if (modifierForX == 0) {
|
||||
// count X occurence
|
||||
for (String s : symbols) {
|
||||
if (s.equals("X")) {
|
||||
modifierForX++;
|
||||
}
|
||||
}
|
||||
this.add(new VariableManaCost(modifierForX));
|
||||
} else if (symbol.equals("S")) {
|
||||
this.add(new SnowManaCost());
|
||||
} else if (symbol.equals("C")) {
|
||||
this.add(new ColorlessManaCost(1));
|
||||
} else if (!symbol.equals("X")) {
|
||||
this.add(new ColoredManaCost(ColoredManaSymbol.lookup(symbol.charAt(0))));
|
||||
} else // check X wasn't added before
|
||||
if (modifierForX == 0) {
|
||||
// count X occurence
|
||||
for (String s : symbols) {
|
||||
if (s.equals("X")) {
|
||||
modifierForX++;
|
||||
}
|
||||
}
|
||||
//TODO: handle multiple {X} and/or {Y} symbols
|
||||
}
|
||||
this.add(new VariableManaCost(modifierForX));
|
||||
} //TODO: handle multiple {X} and/or {Y} symbols
|
||||
} else if (Character.isDigit(symbol.charAt(0))) {
|
||||
this.add((T) new MonoHybridManaCost(ColoredManaSymbol.lookup(symbol.charAt(2))));
|
||||
} else if (symbol.contains("P")) {
|
||||
this.add((T) new PhyrexianManaCost(ColoredManaSymbol.lookup(symbol.charAt(0))));
|
||||
} else {
|
||||
if (Character.isDigit(symbol.charAt(0))) {
|
||||
this.add((T) new MonoHybridManaCost(ColoredManaSymbol.lookup(symbol.charAt(2))));
|
||||
} else if (symbol.contains("P")) {
|
||||
this.add((T) new PhyrexianManaCost(ColoredManaSymbol.lookup(symbol.charAt(0))));
|
||||
} else {
|
||||
this.add((T) new HybridManaCost(ColoredManaSymbol.lookup(symbol.charAt(0)), ColoredManaSymbol.lookup(symbol.charAt(2))));
|
||||
}
|
||||
this.add((T) new HybridManaCost(ColoredManaSymbol.lookup(symbol.charAt(0)), ColoredManaSymbol.lookup(symbol.charAt(2))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,8 +24,7 @@
|
|||
* 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.filter;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
@ -36,7 +35,7 @@ import mage.game.Game;
|
|||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
* @author North
|
||||
*
|
||||
*
|
||||
* @param <E>
|
||||
*/
|
||||
public interface Filter<E> extends Serializable {
|
||||
|
@ -64,9 +63,13 @@ public interface Filter<E> extends Serializable {
|
|||
}
|
||||
|
||||
boolean match(E o, Game game);
|
||||
|
||||
void add(Predicate predicate);
|
||||
|
||||
boolean checkObjectClass(Object object);
|
||||
|
||||
String getMessage();
|
||||
|
||||
void setMessage(String message);
|
||||
|
||||
Filter<E> copy();
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
/*
|
||||
* 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
|
||||
|
@ -20,16 +20,16 @@
|
|||
* 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.filter;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.constants.AbilityType;
|
||||
import mage.constants.Zone;
|
||||
import mage.abilities.Ability;
|
||||
import mage.filter.predicate.Predicate;
|
||||
import mage.game.Game;
|
||||
|
||||
|
@ -60,9 +60,14 @@ public class FilterAbility extends FilterImpl<Ability> {
|
|||
return new AbilityTypePredicate(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkObjectClass(Object object) {
|
||||
return object instanceof Ability;
|
||||
}
|
||||
|
||||
private static final class AbilityZonePredicate implements Predicate<Ability> {
|
||||
|
||||
private Zone zone;
|
||||
private final Zone zone;
|
||||
|
||||
public AbilityZonePredicate(Zone zone) {
|
||||
this.zone = zone;
|
||||
|
@ -81,7 +86,7 @@ public class FilterAbility extends FilterImpl<Ability> {
|
|||
|
||||
private static final class AbilityTypePredicate implements Predicate<Ability> {
|
||||
|
||||
private AbilityType type;
|
||||
private final AbilityType type;
|
||||
|
||||
public AbilityTypePredicate(AbilityType type) {
|
||||
this.type = type;
|
||||
|
|
|
@ -58,7 +58,10 @@ public abstract class FilterImpl<E> implements Filter<E> {
|
|||
|
||||
@Override
|
||||
public boolean match(E e, Game game) {
|
||||
return Predicates.and(predicates).apply(e, game);
|
||||
if (checkObjectClass(e)) {
|
||||
return Predicates.and(predicates).apply(e, game);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -41,6 +41,11 @@ public class FilterObject<E extends MageObject> extends FilterImpl<E> {
|
|||
return new FilterObject<>(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkObjectClass(Object object) {
|
||||
return object instanceof MageObject;
|
||||
}
|
||||
|
||||
public FilterObject(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
|
|
@ -64,6 +64,11 @@ public class FilterPermanent extends FilterObject<Permanent> implements FilterIn
|
|||
this.add(new SubtypePredicate(subtype));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkObjectClass(Object object) {
|
||||
return object instanceof Permanent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean match(Permanent permanent, UUID sourceId, UUID playerId, Game game) {
|
||||
if (!this.match(permanent, game)) {
|
||||
|
|
|
@ -24,8 +24,7 @@
|
|||
* 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.filter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -64,6 +63,11 @@ public class FilterPlayer extends FilterImpl<Player> {
|
|||
extraPredicates.add(predicate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkObjectClass(Object object) {
|
||||
return object instanceof Player;
|
||||
}
|
||||
|
||||
public boolean match(Player player, UUID sourceId, UUID playerId, Game game) {
|
||||
if (!this.match(player, game)) {
|
||||
return false;
|
||||
|
|
|
@ -24,8 +24,7 @@
|
|||
* 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.filter.common;
|
||||
|
||||
import java.util.UUID;
|
||||
|
@ -54,6 +53,11 @@ public class FilterControlledCreatureInPlay extends FilterImpl<Object> implement
|
|||
creatureFilter.add(new ControllerPredicate(TargetController.YOU));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkObjectClass(Object object) {
|
||||
return object instanceof Permanent;
|
||||
}
|
||||
|
||||
public FilterControlledCreatureInPlay(final FilterControlledCreatureInPlay filter) {
|
||||
super(filter);
|
||||
this.creatureFilter = filter.creatureFilter.copy();
|
||||
|
@ -62,7 +66,7 @@ public class FilterControlledCreatureInPlay extends FilterImpl<Object> implement
|
|||
@Override
|
||||
public boolean match(Object o, Game game) {
|
||||
if (o instanceof Permanent) {
|
||||
return creatureFilter.match((Permanent)o, game);
|
||||
return creatureFilter.match((Permanent) o, game);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -70,7 +74,7 @@ public class FilterControlledCreatureInPlay extends FilterImpl<Object> implement
|
|||
@Override
|
||||
public boolean match(Object o, UUID sourceId, UUID playerId, Game game) {
|
||||
if (o instanceof Permanent) {
|
||||
return creatureFilter.match((Permanent)o, sourceId, playerId, game);
|
||||
return creatureFilter.match((Permanent) o, sourceId, playerId, game);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -24,19 +24,17 @@
|
|||
* 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.filter.common;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.MageItem;
|
||||
import mage.filter.FilterImpl;
|
||||
import mage.filter.FilterInPlay;
|
||||
import mage.filter.FilterPlayer;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
import mage.MageItem;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -63,13 +61,17 @@ public class FilterCreatureOrPlayer extends FilterImpl<MageItem> implements Filt
|
|||
this.playerFilter = filter.playerFilter.copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkObjectClass(Object object) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean match(MageItem o, Game game) {
|
||||
if (o instanceof Player) {
|
||||
return playerFilter.match((Player)o, game);
|
||||
}
|
||||
else if (o instanceof Permanent) {
|
||||
return creatureFilter.match((Permanent)o, game);
|
||||
return playerFilter.match((Player) o, game);
|
||||
} else if (o instanceof Permanent) {
|
||||
return creatureFilter.match((Permanent) o, game);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -77,10 +79,9 @@ public class FilterCreatureOrPlayer extends FilterImpl<MageItem> implements Filt
|
|||
@Override
|
||||
public boolean match(MageItem o, UUID sourceId, UUID playerId, Game game) {
|
||||
if (o instanceof Player) {
|
||||
return playerFilter.match((Player)o, sourceId, playerId, game);
|
||||
}
|
||||
else if (o instanceof Permanent) {
|
||||
return creatureFilter.match((Permanent)o, sourceId, playerId, game);
|
||||
return playerFilter.match((Player) o, sourceId, playerId, game);
|
||||
} else if (o instanceof Permanent) {
|
||||
return creatureFilter.match((Permanent) o, sourceId, playerId, game);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -24,10 +24,11 @@
|
|||
* 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.filter.common;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.MageItem;
|
||||
import mage.filter.FilterImpl;
|
||||
import mage.filter.FilterInPlay;
|
||||
import mage.filter.FilterPermanent;
|
||||
|
@ -36,9 +37,6 @@ import mage.game.Game;
|
|||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.MageItem;
|
||||
|
||||
/**
|
||||
* @author nantuko
|
||||
*/
|
||||
|
@ -63,6 +61,11 @@ public class FilterPermanentOrPlayer extends FilterImpl<MageItem> implements Fil
|
|||
this.playerFilter = filter.playerFilter.copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkObjectClass(Object object) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean match(MageItem o, Game game) {
|
||||
if (o instanceof Player) {
|
||||
|
|
|
@ -73,6 +73,11 @@ public class FilterPlaneswalkerOrPlayer extends FilterImpl<Object> {
|
|||
this.playerFilter = filter.playerFilter.copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkObjectClass(Object object) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean match(Object o, Game game) {
|
||||
if (o instanceof Player) {
|
||||
|
|
|
@ -63,6 +63,11 @@ public class FilterSpellOrPermanent extends FilterImpl<Object> implements Filter
|
|||
this.spellFilter = filter.spellFilter.copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkObjectClass(Object object) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean match(Object o, Game game) {
|
||||
if (o instanceof Spell) {
|
||||
|
|
|
@ -35,7 +35,6 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import mage.ConditionalMana;
|
||||
import mage.MageObject;
|
||||
import mage.Mana;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.costs.Cost;
|
||||
|
@ -130,8 +129,7 @@ public class ManaPool implements Serializable {
|
|||
}
|
||||
for (ManaPoolItem mana : manaItems) {
|
||||
if (filter != null) {
|
||||
MageObject sourceObject = game.getObject(mana.getSourceId());
|
||||
if (!filter.match(sourceObject, game)) {
|
||||
if (!filter.match(mana.getSourceObject(), game)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -170,7 +168,7 @@ public class ManaPool implements Serializable {
|
|||
if (mana.isConditional()
|
||||
&& mana.getConditionalMana().get(manaType) > 0
|
||||
&& mana.getConditionalMana().apply(ability, game, mana.getSourceId(), costToPay)) {
|
||||
if (filter == null || filter.match(game.getObject(mana.getSourceId()), game)) {
|
||||
if (filter == null || filter.match(mana.getSourceObject(), game)) {
|
||||
return mana.getConditionalMana().get(manaType);
|
||||
}
|
||||
}
|
||||
|
@ -378,13 +376,13 @@ public class ManaPool implements Serializable {
|
|||
Mana mana = manaToAdd.copy();
|
||||
if (!game.replaceEvent(new ManaEvent(EventType.ADD_MANA, source.getId(), source.getSourceId(), playerId, mana))) {
|
||||
if (mana instanceof ConditionalMana) {
|
||||
ManaPoolItem item = new ManaPoolItem((ConditionalMana) mana, source.getSourceId(), source.getOriginalId());
|
||||
ManaPoolItem item = new ManaPoolItem((ConditionalMana) mana, source.getSourceObject(game), source.getOriginalId());
|
||||
if (emptyOnTurnsEnd) {
|
||||
item.setDuration(Duration.EndOfTurn);
|
||||
}
|
||||
this.manaItems.add(item);
|
||||
} else {
|
||||
ManaPoolItem item = new ManaPoolItem(mana.getRed(), mana.getGreen(), mana.getBlue(), mana.getWhite(), mana.getBlack(), mana.getGeneric() + mana.getColorless(), source.getSourceId(), source.getOriginalId(), mana.getFlag());
|
||||
ManaPoolItem item = new ManaPoolItem(mana.getRed(), mana.getGreen(), mana.getBlue(), mana.getWhite(), mana.getBlack(), mana.getGeneric() + mana.getColorless(), source.getSourceObject(game), source.getOriginalId(), mana.getFlag());
|
||||
if (emptyOnTurnsEnd) {
|
||||
item.setDuration(Duration.EndOfTurn);
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ package mage.players;
|
|||
import java.io.Serializable;
|
||||
import java.util.UUID;
|
||||
import mage.ConditionalMana;
|
||||
import mage.MageObject;
|
||||
import mage.Mana;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.ManaType;
|
||||
|
@ -47,7 +48,7 @@ public class ManaPoolItem implements Serializable {
|
|||
private int black = 0;
|
||||
private int colorless = 0;
|
||||
private ConditionalMana conditionalMana;
|
||||
private UUID sourceId;
|
||||
private MageObject sourceObject;
|
||||
private UUID originalId; // originalId of the mana producing ability
|
||||
private boolean flag = false;
|
||||
private Duration duration;
|
||||
|
@ -56,24 +57,24 @@ public class ManaPoolItem implements Serializable {
|
|||
public ManaPoolItem() {
|
||||
}
|
||||
|
||||
public ManaPoolItem(int red, int green, int blue, int white, int black, int colorless, UUID sourceId, UUID originalId, boolean flag) {
|
||||
public ManaPoolItem(int red, int green, int blue, int white, int black, int colorless, MageObject sourceObject, UUID originalId, boolean flag) {
|
||||
this.red = red;
|
||||
this.green = green;
|
||||
this.blue = blue;
|
||||
this.white = white;
|
||||
this.black = black;
|
||||
this.colorless = colorless;
|
||||
this.sourceId = sourceId;
|
||||
this.sourceObject = sourceObject;
|
||||
this.originalId = originalId;
|
||||
this.flag = flag;
|
||||
this.duration = Duration.EndOfStep;
|
||||
}
|
||||
|
||||
public ManaPoolItem(ConditionalMana conditionalMana, UUID sourceId, UUID originalId) {
|
||||
public ManaPoolItem(ConditionalMana conditionalMana, MageObject sourceObject, UUID originalId) {
|
||||
this.conditionalMana = conditionalMana;
|
||||
this.sourceId = sourceId;
|
||||
this.sourceObject = sourceObject;
|
||||
this.originalId = originalId;
|
||||
this.conditionalMana.setManaProducerId(sourceId);
|
||||
this.conditionalMana.setManaProducerId(sourceObject.getId());
|
||||
this.conditionalMana.setManaProducerOriginalId(originalId);
|
||||
this.flag = conditionalMana.getFlag();
|
||||
this.duration = Duration.EndOfStep;
|
||||
|
@ -89,7 +90,7 @@ public class ManaPoolItem implements Serializable {
|
|||
if (item.conditionalMana != null) {
|
||||
this.conditionalMana = item.conditionalMana.copy();
|
||||
}
|
||||
this.sourceId = item.sourceId;
|
||||
this.sourceObject = item.sourceObject;
|
||||
this.originalId = item.originalId;
|
||||
this.flag = item.flag;
|
||||
this.duration = item.duration;
|
||||
|
@ -100,8 +101,12 @@ public class ManaPoolItem implements Serializable {
|
|||
return new ManaPoolItem(this);
|
||||
}
|
||||
|
||||
public MageObject getSourceObject() {
|
||||
return sourceObject;
|
||||
}
|
||||
|
||||
public UUID getSourceId() {
|
||||
return sourceId;
|
||||
return sourceObject.getId();
|
||||
}
|
||||
|
||||
public UUID getOriginalId() {
|
||||
|
|
|
@ -2336,8 +2336,8 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
}
|
||||
|
||||
// returns only mana producers that don't require mana payment
|
||||
protected List<Permanent> getAvailableManaProducers(Game game) {
|
||||
List<Permanent> result = new ArrayList<>();
|
||||
protected List<MageObject> getAvailableManaProducers(Game game) {
|
||||
List<MageObject> result = new ArrayList<>();
|
||||
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(playerId)) {
|
||||
boolean canAdd = false;
|
||||
for (ManaAbility ability : permanent.getAbilities().getManaAbilities(Zone.BATTLEFIELD)) {
|
||||
|
@ -2353,6 +2353,21 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
result.add(permanent);
|
||||
}
|
||||
}
|
||||
for (Card card : getHand().getCards(game)) {
|
||||
boolean canAdd = false;
|
||||
for (ManaAbility ability : card.getAbilities(game).getManaAbilities(Zone.HAND)) {
|
||||
if (!ability.getManaCosts().isEmpty()) {
|
||||
canAdd = false;
|
||||
break;
|
||||
}
|
||||
if (ability.canActivate(playerId, game)) {
|
||||
canAdd = true;
|
||||
}
|
||||
}
|
||||
if (canAdd) {
|
||||
result.add(card);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue