mirror of
https://github.com/magefree/mage.git
synced 2025-12-26 05:22:02 -08:00
#5935 Fix and standardise firing of TAPPED_FOR_MANA event
This commit is contained in:
parent
0cf758ea5e
commit
48fbd30f2d
62 changed files with 556 additions and 1115 deletions
|
|
@ -404,27 +404,6 @@ public abstract class AbilityImpl implements Ability {
|
|||
game.informPlayers(controller.getLogName() + " announces a value of " + xValue + " for " + variableManaCost.getText());
|
||||
}
|
||||
activated = true;
|
||||
// fire if tapped for mana (may only fire now because else costs of ability itself can be payed with mana of abilities that trigger for that event
|
||||
if (this.getAbilityType() == AbilityType.MANA) {
|
||||
for (Cost cost : costs) {
|
||||
if (cost instanceof TapSourceCost) {
|
||||
Mana mana = null;
|
||||
Effect effect = getEffects().get(0);
|
||||
if (effect instanceof DynamicManaEffect) {
|
||||
mana = ((DynamicManaEffect) effect).getMana(game, this);
|
||||
} else if (effect instanceof ManaEffect) {
|
||||
mana = ((ManaEffect) effect).getMana(game, this);
|
||||
}
|
||||
if (mana != null && mana.getAny() == 0) { // if mana == null or Any > 0 the event has to be fired in the mana effect to know which mana was produced
|
||||
ManaEvent event = new ManaEvent(GameEvent.EventType.TAPPED_FOR_MANA, sourceId, sourceId, controllerId, mana);
|
||||
if (!game.replaceEvent(event)) {
|
||||
game.fireEvent(event);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,30 +41,11 @@ public class ConditionalManaEffect extends ManaEffect {
|
|||
this.condition = effect.condition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller == null) {
|
||||
return false;
|
||||
}
|
||||
Mana mana = getMana(game, source);
|
||||
if (produceMana(true, game, source).getAny() > 0) {
|
||||
checkToFirePossibleEvents(mana, game, source);
|
||||
}
|
||||
controller.getManaPool().addMana(mana, game, source);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConditionalManaEffect copy() {
|
||||
return new ConditionalManaEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mana getMana(Game game, Ability source) {
|
||||
return produceMana(false, game, source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Mana> getNetMana(Game game, Ability source) {
|
||||
if (condition.apply(game, source)) {
|
||||
|
|
@ -76,7 +57,7 @@ public class ConditionalManaEffect extends ManaEffect {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Mana produceMana(boolean netMana, Game game, Ability source) {
|
||||
public Mana produceMana(Game game, Ability source) {
|
||||
Mana mana = new Mana();
|
||||
if (condition.apply(game, source)) {
|
||||
mana = effect.getManaTemplate().copy();
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ import mage.constants.Outcome;
|
|||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.events.ManaEvent;
|
||||
import mage.players.ManaPool;
|
||||
import mage.players.Player;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -32,19 +34,26 @@ public abstract class ManaEffect extends OneShotEffect {
|
|||
this.createdMana = effect.createdMana == null ? null : effect.createdMana.copy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the mana the effect can produce or if that already has happened
|
||||
* returns the mana the effect has created during its process of resolving
|
||||
*
|
||||
* @param game
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
public Mana getMana(Game game, Ability source) {
|
||||
if (createdMana == null) {
|
||||
return createdMana = produceMana(false, game, source);
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player player = getPlayer(game, source);
|
||||
if (player == null) {
|
||||
return false;
|
||||
}
|
||||
return createdMana;
|
||||
Mana manaToAdd = produceMana(game, source);
|
||||
if (manaToAdd.count() > 0) {
|
||||
checkToFirePossibleEvents(manaToAdd, game, source);
|
||||
addManaToPool(player, manaToAdd, game, source);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected Player getPlayer(Game game, Ability source) {
|
||||
return game.getPlayer(source.getControllerId());
|
||||
}
|
||||
|
||||
protected void addManaToPool(Player player, Mana manaToAdd, Game game, Ability source) {
|
||||
player.getManaPool().addMana(manaToAdd, game, source);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -57,7 +66,7 @@ public abstract class ManaEffect extends OneShotEffect {
|
|||
*/
|
||||
public List<Mana> getNetMana(Game game, Ability source) {
|
||||
List<Mana> netMana = new ArrayList<>();
|
||||
Mana mana = produceMana(true, game, source);
|
||||
Mana mana = produceMana(game, source);
|
||||
if (mana != null) {
|
||||
netMana.add(mana);
|
||||
}
|
||||
|
|
@ -67,13 +76,11 @@ public abstract class ManaEffect extends OneShotEffect {
|
|||
/**
|
||||
* Produced the mana the effect can produce
|
||||
*
|
||||
* @param netMana true - produce the hypotetical possible mana for check of
|
||||
* possible castable spells
|
||||
* @param game
|
||||
* @param source
|
||||
* @return
|
||||
*/
|
||||
public abstract Mana produceMana(boolean netMana, Game game, Ability source);
|
||||
public abstract Mana produceMana(Game game, Ability source);
|
||||
|
||||
/**
|
||||
* Only used for mana effects that decide which kind of mana is produced
|
||||
|
|
|
|||
|
|
@ -40,17 +40,7 @@ public class AddConditionalManaEffect extends ManaEffect {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
if (player != null) {
|
||||
player.getManaPool().addMana(getMana(game, source), game, source);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mana produceMana(boolean netMana, Game game, Ability source) {
|
||||
public Mana produceMana(Game game, Ability source) {
|
||||
return manaBuilder.setMana(mana, source, game).build();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -61,23 +61,7 @@ public class AddConditionalManaOfAnyColorEffect extends ManaEffect {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
Mana mana = getMana(game, source);
|
||||
if (mana != null) {
|
||||
checkToFirePossibleEvents(mana, game, source);
|
||||
controller.getManaPool().addMana(mana, game, source);
|
||||
} else {
|
||||
logger.error("There was no mana created: " + source.getSourceObject(game).getName() + " - Ability: " + source.getRule());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mana produceMana(boolean netMana, Game game, Ability source) {
|
||||
public Mana produceMana(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller == null) {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -27,20 +27,15 @@ public class AddManaAnyColorAttachedControllerEffect extends ManaEffect {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
public Player getPlayer(Game game, Ability source) {
|
||||
Permanent enchantment = game.getPermanent(source.getSourceId());
|
||||
if (enchantment != null) {
|
||||
Permanent permanentattachedTo = game.getPermanent(enchantment.getAttachedTo());
|
||||
if (permanentattachedTo != null) {
|
||||
Player player = game.getPlayer(permanentattachedTo.getControllerId());
|
||||
if (player != null) {
|
||||
checkToFirePossibleEvents(getMana(game, source), game, source);
|
||||
player.getManaPool().addMana(getMana(game, source), game, source);
|
||||
return true;
|
||||
}
|
||||
Permanent permanentAttachedTo = game.getPermanent(enchantment.getAttachedTo());
|
||||
if (permanentAttachedTo != null) {
|
||||
return game.getPlayer(permanentAttachedTo.getControllerId());
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -49,7 +44,7 @@ public class AddManaAnyColorAttachedControllerEffect extends ManaEffect {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Mana produceMana(boolean netMana, Game game, Ability source) {
|
||||
public Mana produceMana(Game game, Ability source) {
|
||||
Permanent enchantment = game.getPermanent(source.getSourceId());
|
||||
if (enchantment != null) {
|
||||
Permanent land = game.getPermanent(enchantment.getAttachedTo());
|
||||
|
|
|
|||
|
|
@ -29,16 +29,7 @@ public class AddManaChosenColorEffect extends ManaEffect {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
if (player != null) {
|
||||
player.getManaPool().addMana(getMana(game, source), game, source);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mana produceMana(boolean netMana, Game game, Ability source) {
|
||||
public Mana produceMana(Game game, Ability source) {
|
||||
ObjectColor color = (ObjectColor) game.getState().getValue(source.getSourceId() + "_color");
|
||||
if (color != null) {
|
||||
return new Mana(ColoredManaSymbol.lookup(color.toString().charAt(0)));
|
||||
|
|
|
|||
|
|
@ -65,18 +65,7 @@ public class AddManaInAnyCombinationEffect extends ManaEffect {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
if (player != null) {
|
||||
checkToFirePossibleEvents(getMana(game, source), game, source);
|
||||
player.getManaPool().addMana(getMana(game, source), game, source);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mana produceMana(boolean netMana, Game game, Ability source) {
|
||||
public Mana produceMana(Game game, Ability source) {
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
if (player != null) {
|
||||
Mana mana = new Mana();
|
||||
|
|
|
|||
|
|
@ -50,23 +50,13 @@ public class AddManaOfAnyColorEffect extends BasicManaEffect {
|
|||
return new AddManaOfAnyColorEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
controller.getManaPool().addMana(getMana(game, source), game, source);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Mana> getNetMana(Game game, Ability source) {
|
||||
return netMana;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mana produceMana(boolean netMana, Game game, Ability source) {
|
||||
public Mana produceMana(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
String mes = String.format("Select color of %d mana to add it", this.amount);
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ import mage.game.Game;
|
|||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
|
|
@ -26,25 +28,16 @@ public class AddManaOfAnyTypeProducedEffect extends ManaEffect {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
public Player getPlayer(Game game, Ability source) {
|
||||
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
|
||||
if (permanent != null) {
|
||||
Player targetController = game.getPlayer(permanent.getControllerId());
|
||||
if (targetController == null) {
|
||||
return false;
|
||||
}
|
||||
checkToFirePossibleEvents(getMana(game, source), game, source);
|
||||
targetController.getManaPool().addMana(getMana(game, source), game, source);
|
||||
return true;
|
||||
return game.getPlayer(permanent.getControllerId());
|
||||
}
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mana produceMana(boolean netMana, Game game, Ability source) {
|
||||
if (netMana) {
|
||||
return null;
|
||||
}
|
||||
public Mana produceMana(Game game, Ability source) {
|
||||
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
|
||||
if (permanent != null) {
|
||||
Player targetController = game.getPlayer(permanent.getControllerId());
|
||||
|
|
@ -109,6 +102,11 @@ public class AddManaOfAnyTypeProducedEffect extends ManaEffect {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Mana> getNetMana(Game game, Ability source) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AddManaOfAnyTypeProducedEffect copy() {
|
||||
return new AddManaOfAnyTypeProducedEffect(this);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,42 @@
|
|||
package mage.abilities.effects.mana;
|
||||
|
||||
|
||||
import mage.Mana;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.common.ManaEffect;
|
||||
import mage.choices.ManaChoice;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AddManaOfTwoDifferentColorsEffect extends ManaEffect {
|
||||
|
||||
public AddManaOfTwoDifferentColorsEffect() {
|
||||
super();
|
||||
staticText = "Add two mana of different colors.";
|
||||
}
|
||||
|
||||
private AddManaOfTwoDifferentColorsEffect(final AddManaOfTwoDifferentColorsEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mana produceMana(Game game, Ability source) {
|
||||
Player player = getPlayer(game, source);
|
||||
return ManaChoice.chooseTwoDifferentColors(player, game);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Mana> getNetMana(Game game, Ability source) {
|
||||
ArrayList<Mana> netMana = new ArrayList<>();
|
||||
netMana.add(new Mana(0, 0, 0, 0, 0, 0, 2, 0));
|
||||
return netMana;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AddManaOfTwoDifferentColorsEffect copy() {
|
||||
return new AddManaOfTwoDifferentColorsEffect(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -11,6 +11,8 @@ import mage.abilities.effects.common.ManaEffect;
|
|||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
|
|
@ -53,20 +55,22 @@ public class AddManaToManaPoolTargetControllerEffect extends ManaEffect {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
|
||||
if (player != null) {
|
||||
player.getManaPool().addMana(getMana(game, source), game, source, emptyOnlyOnTurnsEnd);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
public Player getPlayer(Game game, Ability source) {
|
||||
return game.getPlayer(getTargetPointer().getFirst(game, source));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mana produceMana(boolean netMana, Game game, Ability source) {
|
||||
if (netMana) {
|
||||
return null;
|
||||
}
|
||||
public Mana produceMana(Game game, Ability source) {
|
||||
return mana.copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addManaToPool(Player player, Mana manaToAdd, Game game, Ability source) {
|
||||
player.getManaPool().addMana(manaToAdd, game, source, emptyOnlyOnTurnsEnd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Mana> getNetMana(Game game, Ability source) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import mage.Mana;
|
|||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.common.ManaEffect;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
|
||||
public class BasicManaEffect extends ManaEffect {
|
||||
|
||||
|
|
@ -33,18 +34,12 @@ public class BasicManaEffect extends ManaEffect {
|
|||
return new BasicManaEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
game.getPlayer(source.getControllerId()).getManaPool().addMana(getMana(game, source), game, source);
|
||||
return true;
|
||||
}
|
||||
|
||||
public Mana getManaTemplate() {
|
||||
return manaTemplate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mana produceMana(boolean netMana, Game game, Ability source) {
|
||||
public Mana produceMana(Game game, Ability source) {
|
||||
return manaTemplate.copy();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,58 +43,30 @@ public class DoUnlessAnyPlayerPaysManaEffect extends ManaEffect {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
public List<Mana> getNetMana(Game game, Ability source) {
|
||||
return manaEffect.getNetMana(game, source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mana produceMana(Game game, Ability source) {
|
||||
Player controller = getPlayer(game, source);
|
||||
MageObject sourceObject = game.getObject(source.getSourceId());
|
||||
if (controller != null && sourceObject != null) {
|
||||
String message = CardUtil.replaceSourceName(chooseUseText, sourceObject.getName());
|
||||
boolean result = true;
|
||||
boolean doEffect = true;
|
||||
// check if any player is willing to pay
|
||||
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null && player.canRespond()
|
||||
&& cost.canPay(source, source.getSourceId(), player.getId(), game)
|
||||
&& player.chooseUse(Outcome.Detriment, message, source, game)) {
|
||||
cost.clearPaid();
|
||||
if (cost.pay(source, game, source.getSourceId(), player.getId(), false, null)) {
|
||||
if (!game.isSimulation()) {
|
||||
game.informPlayers(player.getLogName() + " pays the cost to prevent the effect");
|
||||
}
|
||||
doEffect = false;
|
||||
break;
|
||||
String message = CardUtil.replaceSourceName(chooseUseText, sourceObject.getName());
|
||||
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null && player.canRespond()
|
||||
&& cost.canPay(source, source.getSourceId(), player.getId(), game)
|
||||
&& player.chooseUse(Outcome.Detriment, message, source, game)) {
|
||||
cost.clearPaid();
|
||||
if (cost.pay(source, game, source.getSourceId(), player.getId(), false, null)) {
|
||||
if (!game.isSimulation()) {
|
||||
game.informPlayers(player.getLogName() + " pays the cost to prevent the effect");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// do the effects if nobody paid
|
||||
if (doEffect) {
|
||||
return manaEffect.apply(game, source);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Mana> getNetMana(Game game, Ability source) {
|
||||
if (cost.canPay(source, source.getSourceId(), source.getControllerId(), game)) {
|
||||
return manaEffect.getNetMana(game, source);
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mana getMana(Game game, Ability source) {
|
||||
return manaEffect.getMana(game, source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mana produceMana(boolean netMana, Game game, Ability source) {
|
||||
return manaEffect.produceMana(netMana, game, source);
|
||||
}
|
||||
|
||||
protected Player getPayingPlayer(Game game, Ability source) {
|
||||
return game.getPlayer(source.getControllerId());
|
||||
return manaEffect.produceMana(game, source);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -5,20 +5,25 @@ import mage.Mana;
|
|||
import mage.abilities.Ability;
|
||||
import mage.abilities.Mode;
|
||||
import mage.abilities.dynamicvalue.DynamicValue;
|
||||
import mage.abilities.effects.common.ManaEffect;
|
||||
import mage.choices.ChoiceColor;
|
||||
import mage.constants.Outcome;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author North
|
||||
*/
|
||||
public class DynamicManaEffect extends BasicManaEffect {
|
||||
public class DynamicManaEffect extends ManaEffect {
|
||||
|
||||
private Mana baseMana;
|
||||
private final DynamicValue amount;
|
||||
private final DynamicValue netAmount;
|
||||
private String text = null;
|
||||
private String text;
|
||||
private boolean oneChoice;
|
||||
|
||||
public DynamicManaEffect(Mana mana, DynamicValue amount) {
|
||||
|
|
@ -38,13 +43,14 @@ public class DynamicManaEffect extends BasicManaEffect {
|
|||
* @param mana
|
||||
* @param amount
|
||||
* @param text
|
||||
* @param oneChoice is all manaTemplate from the same colour or if false the
|
||||
* @param oneChoice is all mana from the same colour or if false the
|
||||
* player can choose different colours
|
||||
* @param netAmount a dynamic value that calculates the possible available
|
||||
* manaTemplate (e.g. if you have to pay by removing counters from source)
|
||||
* mana (e.g. if you have to pay by removing counters from source)
|
||||
*/
|
||||
public DynamicManaEffect(Mana mana, DynamicValue amount, String text, boolean oneChoice, DynamicValue netAmount) {
|
||||
super(mana);
|
||||
super();
|
||||
this.baseMana = mana;
|
||||
this.amount = amount;
|
||||
this.text = text;
|
||||
this.oneChoice = oneChoice;
|
||||
|
|
@ -53,6 +59,7 @@ public class DynamicManaEffect extends BasicManaEffect {
|
|||
|
||||
public DynamicManaEffect(final DynamicManaEffect effect) {
|
||||
super(effect);
|
||||
this.baseMana = effect.baseMana.copy();
|
||||
this.amount = effect.amount.copy();
|
||||
this.text = effect.text;
|
||||
this.oneChoice = effect.oneChoice;
|
||||
|
|
@ -68,13 +75,6 @@ public class DynamicManaEffect extends BasicManaEffect {
|
|||
return new DynamicManaEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
checkToFirePossibleEvents(getMana(game, source), game, source);
|
||||
game.getPlayer(source.getControllerId()).getManaPool().addMana(getMana(game, source), game, source);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText(Mode mode) {
|
||||
if (text != null && !text.isEmpty()) {
|
||||
|
|
@ -84,46 +84,69 @@ public class DynamicManaEffect extends BasicManaEffect {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Mana produceMana(boolean netMana, Game game, Ability source) {
|
||||
public List<Mana> getNetMana(Game game, Ability source) {
|
||||
Mana computedMana = new Mana();
|
||||
int count;
|
||||
if (netMana && netAmount != null) {
|
||||
// calculate the maximum available manaTemplate
|
||||
if (netAmount != null) {
|
||||
// calculate the maximum available mana
|
||||
count = netAmount.calculate(game, source, this);
|
||||
} else {
|
||||
count = amount.calculate(game, source, this);
|
||||
}
|
||||
|
||||
if (manaTemplate.getBlack() > 0) {
|
||||
if (baseMana.getBlack() > 0) {
|
||||
computedMana.setBlack(count);
|
||||
} else if (manaTemplate.getBlue() > 0) {
|
||||
} else if (baseMana.getBlue() > 0) {
|
||||
computedMana.setBlue(count);
|
||||
} else if (manaTemplate.getGreen() > 0) {
|
||||
} else if (baseMana.getGreen() > 0) {
|
||||
computedMana.setGreen(count);
|
||||
} else if (manaTemplate.getRed() > 0) {
|
||||
} else if (baseMana.getRed() > 0) {
|
||||
computedMana.setRed(count);
|
||||
} else if (manaTemplate.getWhite() > 0) {
|
||||
} else if (baseMana.getWhite() > 0) {
|
||||
computedMana.setWhite(count);
|
||||
} else if (manaTemplate.getColorless() > 0) {
|
||||
} else if (baseMana.getColorless() > 0) {
|
||||
computedMana.setColorless(count);
|
||||
} else if (manaTemplate.getAny() > 0) {
|
||||
if (netMana) {
|
||||
computedMana.setAny(count);
|
||||
} else {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
ChoiceColor choiceColor = new ChoiceColor(true);
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (!choiceColor.isChosen()) {
|
||||
if (!controller.choose(Outcome.Benefit, choiceColor, game)) {
|
||||
return computedMana;
|
||||
}
|
||||
}
|
||||
choiceColor.increaseMana(computedMana);
|
||||
if (!oneChoice) {
|
||||
choiceColor.clearChoice();
|
||||
} else if (baseMana.getAny() > 0) {
|
||||
computedMana.setAny(count);
|
||||
} else {
|
||||
computedMana.setGeneric(count);
|
||||
}
|
||||
List<Mana> netMana = new ArrayList<>();
|
||||
netMana.add(computedMana);
|
||||
return netMana;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mana produceMana(Game game, Ability source) {
|
||||
Mana computedMana = new Mana();
|
||||
int count = amount.calculate(game, source, this);
|
||||
|
||||
if (baseMana.getBlack() > 0) {
|
||||
computedMana.setBlack(count);
|
||||
} else if (baseMana.getBlue() > 0) {
|
||||
computedMana.setBlue(count);
|
||||
} else if (baseMana.getGreen() > 0) {
|
||||
computedMana.setGreen(count);
|
||||
} else if (baseMana.getRed() > 0) {
|
||||
computedMana.setRed(count);
|
||||
} else if (baseMana.getWhite() > 0) {
|
||||
computedMana.setWhite(count);
|
||||
} else if (baseMana.getColorless() > 0) {
|
||||
computedMana.setColorless(count);
|
||||
} else if (baseMana.getAny() > 0) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
ChoiceColor choiceColor = new ChoiceColor(true);
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (!choiceColor.isChosen()) {
|
||||
if (!controller.choose(Outcome.Benefit, choiceColor, game)) {
|
||||
return computedMana;
|
||||
}
|
||||
}
|
||||
choiceColor.increaseMana(computedMana);
|
||||
if (!oneChoice) {
|
||||
choiceColor.clearChoice();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -87,18 +87,7 @@ class AnyColorLandsProduceManaEffect extends ManaEffect {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
checkToFirePossibleEvents(getMana(game, source), game, source);
|
||||
controller.getManaPool().addMana(getMana(game, source), game, source);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mana produceMana(boolean netMana, Game game, Ability source) {
|
||||
public Mana produceMana(Game game, Ability source) {
|
||||
Mana mana = new Mana();
|
||||
Mana types = getManaTypes(game, source);
|
||||
Choice choice = new ChoiceColor(true);
|
||||
|
|
|
|||
|
|
@ -81,18 +81,7 @@ class AnyColorPermanentTypesManaEffect extends ManaEffect {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
checkToFirePossibleEvents(getMana(game, source), game, source);
|
||||
controller.getManaPool().addMana(getMana(game, source), game, source);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mana produceMana(boolean netMana, Game game, Ability source) {
|
||||
public Mana produceMana(Game game, Ability source) {
|
||||
Mana mana = new Mana();
|
||||
Mana types = getManaTypes(game, source);
|
||||
Choice choice = new ChoiceColor(true);
|
||||
|
|
|
|||
|
|
@ -14,9 +14,7 @@ import mage.filter.FilterMana;
|
|||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author LevelX2
|
||||
|
|
@ -40,39 +38,6 @@ public class CommanderColorIdentityManaAbility extends ActivatedManaAbilityImpl
|
|||
return new CommanderColorIdentityManaAbility(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Mana> getNetMana(Game game) {
|
||||
List<Mana> netManas = new ArrayList<>();
|
||||
if (netMana.isEmpty() && game != null) {
|
||||
Player controller = game.getPlayer(getControllerId());
|
||||
if (controller != null) {
|
||||
for (UUID commanderId : game.getCommandersIds(controller)) {
|
||||
Card commander = game.getCard(commanderId);
|
||||
if (commander != null) {
|
||||
FilterMana commanderMana = commander.getColorIdentity();
|
||||
if (commanderMana.isBlack()) {
|
||||
netMana.add(new Mana(ColoredManaSymbol.B));
|
||||
}
|
||||
if (commanderMana.isBlue()) {
|
||||
netMana.add(new Mana(ColoredManaSymbol.U));
|
||||
}
|
||||
if (commanderMana.isGreen()) {
|
||||
netMana.add(new Mana(ColoredManaSymbol.G));
|
||||
}
|
||||
if (commanderMana.isRed()) {
|
||||
netMana.add(new Mana(ColoredManaSymbol.R));
|
||||
}
|
||||
if (commanderMana.isWhite()) {
|
||||
netMana.add(new Mana(ColoredManaSymbol.W));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
netManas.addAll(netMana);
|
||||
return netManas;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean definesMana(Game game) {
|
||||
return true;
|
||||
|
|
@ -97,18 +62,7 @@ class CommanderIdentityManaEffect extends ManaEffect {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
checkToFirePossibleEvents(getMana(game, source), game, source);
|
||||
controller.getManaPool().addMana(getMana(game, source), game, source);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mana produceMana(boolean netMana, Game game, Ability source) {
|
||||
public Mana produceMana(Game game, Ability source) {
|
||||
Mana mana = new Mana();
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
|
|
@ -167,4 +121,34 @@ class CommanderIdentityManaEffect extends ManaEffect {
|
|||
return mana;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Mana> getNetMana(Game game, Ability source) {
|
||||
List<Mana> netMana = new ArrayList<>();
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
for (UUID commanderId : game.getCommandersIds(controller)) {
|
||||
Card commander = game.getCard(commanderId);
|
||||
if (commander != null) {
|
||||
FilterMana commanderMana = commander.getColorIdentity();
|
||||
if (commanderMana.isBlack()) {
|
||||
netMana.add(new Mana(ColoredManaSymbol.B));
|
||||
}
|
||||
if (commanderMana.isBlue()) {
|
||||
netMana.add(new Mana(ColoredManaSymbol.U));
|
||||
}
|
||||
if (commanderMana.isGreen()) {
|
||||
netMana.add(new Mana(ColoredManaSymbol.G));
|
||||
}
|
||||
if (commanderMana.isRed()) {
|
||||
netMana.add(new Mana(ColoredManaSymbol.R));
|
||||
}
|
||||
if (commanderMana.isWhite()) {
|
||||
netMana.add(new Mana(ColoredManaSymbol.W));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return netMana;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
53
Mage/src/main/java/mage/choices/ManaChoice.java
Normal file
53
Mage/src/main/java/mage/choices/ManaChoice.java
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
package mage.choices;
|
||||
|
||||
import mage.Mana;
|
||||
import mage.constants.Outcome;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
|
||||
public class ManaChoice {
|
||||
public static Mana chooseAnyColor(Player player, Game game, int amount) {
|
||||
if (player == null) {
|
||||
return null;
|
||||
}
|
||||
Mana mana = new Mana();
|
||||
for (int i = 0; i < amount; i++) {
|
||||
ChoiceColor choiceColor = new ChoiceColor();
|
||||
if (amount > 1) {
|
||||
choiceColor.setMessage("Choose color " + (i+1));
|
||||
}
|
||||
if (!player.choose(Outcome.Benefit, choiceColor, game)) {
|
||||
return null;
|
||||
}
|
||||
choiceColor.increaseMana(mana);
|
||||
}
|
||||
return mana;
|
||||
}
|
||||
|
||||
public static Mana chooseTwoDifferentColors(Player player, Game game) {
|
||||
if (player == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ChoiceColor color1 = new ChoiceColor(true, "Choose color 1");
|
||||
if (!player.choose(Outcome.PutManaInPool, color1, game) || color1.getColor() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ChoiceColor color2 = new ChoiceColor(true, "Choose color 2");
|
||||
color2.removeColorFromChoices(color1.getChoice());
|
||||
if (!player.choose(Outcome.PutManaInPool, color2, game) || color2.getColor() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (color1.getColor().equals(color2.getColor())) {
|
||||
game.informPlayers("Player " + player.getName() + " is cheating with mana choices.");
|
||||
return null;
|
||||
}
|
||||
|
||||
Mana mana = new Mana();
|
||||
mana.add(color1.getMana(1));
|
||||
mana.add(color2.getMana(1));
|
||||
return mana;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue