mirror of
https://github.com/correl/mage.git
synced 2024-12-24 11:50:45 +00:00
Rework of "spend mana as though it were mana of" handling.
This commit is contained in:
parent
2c54cacbc3
commit
625aa29d6e
12 changed files with 184 additions and 152 deletions
|
@ -1135,7 +1135,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
|
|
||||||
protected boolean playManaHandling(Ability ability, ManaCost unpaid, Game game) {
|
protected boolean playManaHandling(Ability ability, ManaCost unpaid, Game game) {
|
||||||
// log.info("paying for " + unpaid.getText());
|
// log.info("paying for " + unpaid.getText());
|
||||||
boolean spendAnyMana = game.getContinuousEffects().asThough(ability.getSourceId(), AsThoughEffectType.SPEND_ANY_MANA, ability, ability.getControllerId(), game);
|
boolean spendAnyMana = game.getContinuousEffects().asThough(ability.getSourceId(), AsThoughEffectType.SPEND_OTHER_MANA, ability, ability.getControllerId(), game);
|
||||||
ManaCost cost;
|
ManaCost cost;
|
||||||
List<Permanent> producers;
|
List<Permanent> producers;
|
||||||
if (unpaid instanceof ManaCosts) {
|
if (unpaid instanceof ManaCosts) {
|
||||||
|
|
|
@ -34,6 +34,7 @@ import mage.ObjectColor;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.common.SimpleStaticAbility;
|
import mage.abilities.common.SimpleStaticAbility;
|
||||||
import mage.abilities.effects.AsThoughEffectImpl;
|
import mage.abilities.effects.AsThoughEffectImpl;
|
||||||
|
import mage.abilities.effects.AsThoughManaEffect;
|
||||||
import mage.abilities.effects.ContinuousEffectImpl;
|
import mage.abilities.effects.ContinuousEffectImpl;
|
||||||
import mage.cards.Card;
|
import mage.cards.Card;
|
||||||
import mage.cards.CardImpl;
|
import mage.cards.CardImpl;
|
||||||
|
@ -170,10 +171,10 @@ class EverythingIsColorlessEffect extends ContinuousEffectImpl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ManaCanBeSpentAsAnyColorEffect extends AsThoughEffectImpl {
|
class ManaCanBeSpentAsAnyColorEffect extends AsThoughEffectImpl implements AsThoughManaEffect {
|
||||||
|
|
||||||
public ManaCanBeSpentAsAnyColorEffect() {
|
public ManaCanBeSpentAsAnyColorEffect() {
|
||||||
super(AsThoughEffectType.SPEND_ANY_MANA, Duration.WhileOnBattlefield, Outcome.Benefit);
|
super(AsThoughEffectType.SPEND_OTHER_MANA, Duration.WhileOnBattlefield, Outcome.Benefit);
|
||||||
staticText = "Players may spend mana as though it were mana of any color";
|
staticText = "Players may spend mana as though it were mana of any color";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,12 +185,13 @@ class ManaCanBeSpentAsAnyColorEffect extends AsThoughEffectImpl {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
|
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
|
||||||
return true; // not used for mana thought as effects
|
Player controller = game.getPlayer(source.getControllerId());
|
||||||
|
return controller != null && controller.getInRange().contains(affectedControllerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game, ManaType manaType, ManaPoolItem mana) {
|
public ManaType getAsThoughtManaType(ManaType manaType, ManaPoolItem mana, UUID affectedControllerId, Ability source, Game game) {
|
||||||
return true;
|
return mana.getFirstAvailable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -34,6 +34,7 @@ import mage.abilities.Ability;
|
||||||
import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility;
|
import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility;
|
||||||
import mage.abilities.common.SimpleEvasionAbility;
|
import mage.abilities.common.SimpleEvasionAbility;
|
||||||
import mage.abilities.effects.AsThoughEffectImpl;
|
import mage.abilities.effects.AsThoughEffectImpl;
|
||||||
|
import mage.abilities.effects.AsThoughManaEffect;
|
||||||
import mage.abilities.effects.ContinuousEffect;
|
import mage.abilities.effects.ContinuousEffect;
|
||||||
import mage.abilities.effects.OneShotEffect;
|
import mage.abilities.effects.OneShotEffect;
|
||||||
import mage.abilities.effects.common.combat.CantBeBlockedByCreaturesSourceEffect;
|
import mage.abilities.effects.common.combat.CantBeBlockedByCreaturesSourceEffect;
|
||||||
|
@ -183,10 +184,10 @@ class DaxosOfMeletisCastFromExileEffect extends AsThoughEffectImpl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DaxosOfMeletisSpendAnyManaEffect extends AsThoughEffectImpl {
|
class DaxosOfMeletisSpendAnyManaEffect extends AsThoughEffectImpl implements AsThoughManaEffect {
|
||||||
|
|
||||||
public DaxosOfMeletisSpendAnyManaEffect() {
|
public DaxosOfMeletisSpendAnyManaEffect() {
|
||||||
super(AsThoughEffectType.SPEND_ANY_MANA, Duration.EndOfTurn, Outcome.Benefit);
|
super(AsThoughEffectType.SPEND_OTHER_MANA, Duration.EndOfTurn, Outcome.Benefit);
|
||||||
staticText = "you may spend mana as though it were mana of any color to cast it";
|
staticText = "you may spend mana as though it were mana of any color to cast it";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,14 +207,16 @@ class DaxosOfMeletisSpendAnyManaEffect extends AsThoughEffectImpl {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
|
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
|
||||||
return true; // not used for mana thought as effects
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game, ManaType manaType, ManaPoolItem mana) {
|
|
||||||
return source.getControllerId().equals(affectedControllerId)
|
return source.getControllerId().equals(affectedControllerId)
|
||||||
&& objectId == ((FixedTarget) getTargetPointer()).getTarget()
|
&& objectId == ((FixedTarget) getTargetPointer()).getTarget()
|
||||||
&& ((FixedTarget) getTargetPointer()).getZoneChangeCounter() + 1 == game.getState().getZoneChangeCounter(objectId)
|
&& ((FixedTarget) getTargetPointer()).getZoneChangeCounter() + 1 == game.getState().getZoneChangeCounter(objectId)
|
||||||
|
&& (((FixedTarget) getTargetPointer()).getZoneChangeCounter() + 1 == game.getState().getZoneChangeCounter(objectId))
|
||||||
&& game.getState().getZone(objectId).equals(Zone.STACK);
|
&& game.getState().getZone(objectId).equals(Zone.STACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ManaType getAsThoughtManaType(ManaType manaType, ManaPoolItem mana, UUID affectedControllerId, Ability source, Game game) {
|
||||||
|
return mana.getFirstAvailable();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ import java.util.UUID;
|
||||||
import mage.MageObject;
|
import mage.MageObject;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.effects.AsThoughEffectImpl;
|
import mage.abilities.effects.AsThoughEffectImpl;
|
||||||
|
import mage.abilities.effects.AsThoughManaEffect;
|
||||||
import mage.abilities.effects.ContinuousEffect;
|
import mage.abilities.effects.ContinuousEffect;
|
||||||
import mage.abilities.effects.OneShotEffect;
|
import mage.abilities.effects.OneShotEffect;
|
||||||
import mage.cards.Card;
|
import mage.cards.Card;
|
||||||
|
@ -190,10 +191,10 @@ class PsychicIntrusionCastFromExileEffect extends AsThoughEffectImpl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PsychicIntrusionSpendAnyManaEffect extends AsThoughEffectImpl {
|
class PsychicIntrusionSpendAnyManaEffect extends AsThoughEffectImpl implements AsThoughManaEffect {
|
||||||
|
|
||||||
public PsychicIntrusionSpendAnyManaEffect() {
|
public PsychicIntrusionSpendAnyManaEffect() {
|
||||||
super(AsThoughEffectType.SPEND_ANY_MANA, Duration.Custom, Outcome.Benefit);
|
super(AsThoughEffectType.SPEND_OTHER_MANA, Duration.Custom, Outcome.Benefit);
|
||||||
staticText = "you may spend mana as though it were mana of any color to cast it";
|
staticText = "you may spend mana as though it were mana of any color to cast it";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,11 +214,6 @@ class PsychicIntrusionSpendAnyManaEffect extends AsThoughEffectImpl {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
|
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
|
||||||
return true; // not used for mana thought as effects
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game, ManaType manaType, ManaPoolItem mana) {
|
|
||||||
if (objectId.equals(((FixedTarget) getTargetPointer()).getTarget())
|
if (objectId.equals(((FixedTarget) getTargetPointer()).getTarget())
|
||||||
&& game.getState().getZoneChangeCounter(objectId) <= ((FixedTarget) getTargetPointer()).getZoneChangeCounter() + 1) {
|
&& game.getState().getZoneChangeCounter(objectId) <= ((FixedTarget) getTargetPointer()).getZoneChangeCounter() + 1) {
|
||||||
|
|
||||||
|
@ -236,4 +232,9 @@ class PsychicIntrusionSpendAnyManaEffect extends AsThoughEffectImpl {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ManaType getAsThoughtManaType(ManaType manaType, ManaPoolItem mana, UUID affectedControllerId, Ability source, Game game) {
|
||||||
|
return mana.getFirstAvailable();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@ import mage.ObjectColor;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.common.SimpleStaticAbility;
|
import mage.abilities.common.SimpleStaticAbility;
|
||||||
import mage.abilities.effects.AsThoughEffectImpl;
|
import mage.abilities.effects.AsThoughEffectImpl;
|
||||||
|
import mage.abilities.effects.AsThoughManaEffect;
|
||||||
import mage.abilities.effects.ContinuousEffectImpl;
|
import mage.abilities.effects.ContinuousEffectImpl;
|
||||||
import mage.abilities.mana.WhiteManaAbility;
|
import mage.abilities.mana.WhiteManaAbility;
|
||||||
import mage.cards.Card;
|
import mage.cards.Card;
|
||||||
|
@ -146,7 +147,6 @@ class CelestialDawnToWhiteEffect extends ContinuousEffectImpl {
|
||||||
public CelestialDawnToWhiteEffect() {
|
public CelestialDawnToWhiteEffect() {
|
||||||
super(Duration.WhileOnBattlefield, Layer.ColorChangingEffects_5, SubLayer.NA, Outcome.Benefit);
|
super(Duration.WhileOnBattlefield, Layer.ColorChangingEffects_5, SubLayer.NA, Outcome.Benefit);
|
||||||
staticText = "Nonland cards you own that aren't on the battlefield, spells you control, and nonland permanents you control are white";
|
staticText = "Nonland cards you own that aren't on the battlefield, spells you control, and nonland permanents you control are white";
|
||||||
staticText = "All cards that aren't on the battlefield, spells, and permanents are the chosen color in addition to their other colors";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -213,10 +213,10 @@ class CelestialDawnToWhiteEffect extends ContinuousEffectImpl {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class CelestialDawnSpendAnyManaEffect extends AsThoughEffectImpl {
|
class CelestialDawnSpendAnyManaEffect extends AsThoughEffectImpl implements AsThoughManaEffect {
|
||||||
|
|
||||||
public CelestialDawnSpendAnyManaEffect() {
|
public CelestialDawnSpendAnyManaEffect() {
|
||||||
super(AsThoughEffectType.SPEND_ANY_MANA, Duration.Custom, Outcome.Benefit);
|
super(AsThoughEffectType.SPEND_OTHER_MANA, Duration.Custom, Outcome.Benefit);
|
||||||
staticText = "You may spend white mana as though it were mana of any color";
|
staticText = "You may spend white mana as though it were mana of any color";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,22 +236,22 @@ class CelestialDawnSpendAnyManaEffect extends AsThoughEffectImpl {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
|
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
|
||||||
return true; // not used for mana thought as effects
|
return affectedControllerId.equals(source.getControllerId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game, ManaType manaType, ManaPoolItem mana) {
|
public ManaType getAsThoughtManaType(ManaType manaType, ManaPoolItem mana, UUID affectedControllerId, Ability source, Game game) {
|
||||||
if (affectedControllerId.equals(source.getControllerId())) {
|
if (mana.getWhite() > 0) {
|
||||||
return mana.getWhite() > 0;
|
return ManaType.WHITE;
|
||||||
}
|
}
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class CelestialDawnSpendColorlessManaEffect extends AsThoughEffectImpl {
|
class CelestialDawnSpendColorlessManaEffect extends AsThoughEffectImpl implements AsThoughManaEffect {
|
||||||
|
|
||||||
public CelestialDawnSpendColorlessManaEffect() {
|
public CelestialDawnSpendColorlessManaEffect() {
|
||||||
super(AsThoughEffectType.SPEND_COLORLESS_MANA, Duration.Custom, Outcome.Detriment);
|
super(AsThoughEffectType.SPEND_ONLY_MANA, Duration.Custom, Outcome.Detriment);
|
||||||
staticText = "You may spend other mana only as though it were colorless mana";
|
staticText = "You may spend other mana only as though it were colorless mana";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,14 +271,14 @@ class CelestialDawnSpendColorlessManaEffect extends AsThoughEffectImpl {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
|
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
|
||||||
return true; // not used for mana thought as effects
|
return affectedControllerId.equals(source.getControllerId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game, ManaType manaType, ManaPoolItem mana) {
|
public ManaType getAsThoughtManaType(ManaType manaType, ManaPoolItem mana, UUID affectedControllerId, Ability source, Game game) {
|
||||||
if (affectedControllerId.equals(source.getControllerId())) {
|
if (mana.getWhite() == 0 && !ManaType.COLORLESS.equals(manaType)) {
|
||||||
return mana.getWhite() == 0;
|
return null;
|
||||||
}
|
}
|
||||||
return false;
|
return manaType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,9 +30,7 @@ package mage.abilities.effects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.constants.AsThoughEffectType;
|
import mage.constants.AsThoughEffectType;
|
||||||
import mage.constants.ManaType;
|
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.players.ManaPoolItem;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -44,8 +42,6 @@ public interface AsThoughEffect extends ContinuousEffect {
|
||||||
|
|
||||||
boolean applies(UUID sourceId, Ability source, UUID affectedControllerId, Game game);
|
boolean applies(UUID sourceId, Ability source, UUID affectedControllerId, Game game);
|
||||||
|
|
||||||
boolean applies(UUID sourceId, Ability source, UUID affectedControllerId, Game game, ManaType manaType, ManaPoolItem mana);
|
|
||||||
|
|
||||||
AsThoughEffectType getAsThoughEffectType();
|
AsThoughEffectType getAsThoughEffectType();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -32,10 +32,8 @@ import mage.abilities.Ability;
|
||||||
import mage.constants.AsThoughEffectType;
|
import mage.constants.AsThoughEffectType;
|
||||||
import mage.constants.Duration;
|
import mage.constants.Duration;
|
||||||
import mage.constants.EffectType;
|
import mage.constants.EffectType;
|
||||||
import mage.constants.ManaType;
|
|
||||||
import mage.constants.Outcome;
|
import mage.constants.Outcome;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.players.ManaPoolItem;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -61,11 +59,6 @@ public abstract class AsThoughEffectImpl extends ContinuousEffectImpl implements
|
||||||
return applies(objectId, source, affectedAbility.getControllerId(), game);
|
return applies(objectId, source, affectedAbility.getControllerId(), game);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean applies(UUID sourceId, Ability source, UUID affectedControllerId, Game game, ManaType manaType, ManaPoolItem mana) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AsThoughEffectType getAsThoughEffectType() {
|
public AsThoughEffectType getAsThoughEffectType() {
|
||||||
return type;
|
return type;
|
||||||
|
|
45
Mage/src/mage/abilities/effects/AsThoughManaEffect.java
Normal file
45
Mage/src/mage/abilities/effects/AsThoughManaEffect.java
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
import mage.abilities.Ability;
|
||||||
|
import mage.constants.ManaType;
|
||||||
|
import mage.game.Game;
|
||||||
|
import mage.players.ManaPoolItem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author LevelX2
|
||||||
|
*/
|
||||||
|
public interface AsThoughManaEffect extends AsThoughEffect {
|
||||||
|
|
||||||
|
// return a mana type that can be used to pay a mana cost instead of the normally needed mana type
|
||||||
|
ManaType getAsThoughtManaType(ManaType manaType, ManaPoolItem mana, UUID affectedControllerId, Ability source, Game game);
|
||||||
|
|
||||||
|
}
|
|
@ -548,24 +548,35 @@ public class ContinuousEffects implements Serializable {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean asThoughMana(UUID objectId, AsThoughEffectType type, Ability affectedAbility, UUID controllerId, Game game, ManaType manaType, ManaPoolItem mana) {
|
public ManaType asThoughMana(ManaType manaType, ManaPoolItem mana, UUID objectId, Ability affectedAbility, UUID controllerId, Game game) {
|
||||||
List<AsThoughEffect> asThoughEffectsList = getApplicableAsThoughEffects(type, game);
|
// First check existing only effects
|
||||||
|
List<AsThoughEffect> asThoughEffectsList = getApplicableAsThoughEffects(AsThoughEffectType.SPEND_ONLY_MANA, game);
|
||||||
for (AsThoughEffect effect : asThoughEffectsList) {
|
for (AsThoughEffect effect : asThoughEffectsList) {
|
||||||
HashSet<Ability> abilities = asThoughEffectsMap.get(type).getAbility(effect.getId());
|
HashSet<Ability> abilities = asThoughEffectsMap.get(AsThoughEffectType.SPEND_ONLY_MANA).getAbility(effect.getId());
|
||||||
for (Ability ability : abilities) {
|
for (Ability ability : abilities) {
|
||||||
if (affectedAbility == null) {
|
if ((affectedAbility == null && effect.applies(objectId, ability, controllerId, game))
|
||||||
if (effect.applies(objectId, ability, controllerId, game)) {
|
|| effect.applies(objectId, affectedAbility, ability, game)) {
|
||||||
return true;
|
if (((AsThoughManaEffect) effect).getAsThoughtManaType(manaType, mana, controllerId, ability, game) == null) {
|
||||||
}
|
return null;
|
||||||
} else {
|
|
||||||
if (effect.applies(objectId, affectedAbility, ability, game)) {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
// then check effects that allow to use other mana types to pay the current mana type to pay
|
||||||
|
asThoughEffectsList = getApplicableAsThoughEffects(AsThoughEffectType.SPEND_OTHER_MANA, game);
|
||||||
|
for (AsThoughEffect effect : asThoughEffectsList) {
|
||||||
|
HashSet<Ability> abilities = asThoughEffectsMap.get(AsThoughEffectType.SPEND_OTHER_MANA).getAbility(effect.getId());
|
||||||
|
for (Ability ability : abilities) {
|
||||||
|
if ((affectedAbility == null && effect.applies(objectId, ability, controllerId, game))
|
||||||
|
|| effect.applies(objectId, affectedAbility, ability, game)) {
|
||||||
|
ManaType usableManaType = ((AsThoughManaEffect) effect).getAsThoughtManaType(manaType, mana, controllerId, ability, game);
|
||||||
|
if (usableManaType != null) {
|
||||||
|
return usableManaType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return manaType;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -19,7 +19,7 @@ public enum AsThoughEffectType {
|
||||||
HEXPROOF,
|
HEXPROOF,
|
||||||
PAY,
|
PAY,
|
||||||
LOOK_AT_FACE_DOWN,
|
LOOK_AT_FACE_DOWN,
|
||||||
SPEND_ANY_MANA,
|
SPEND_OTHER_MANA,
|
||||||
SPEND_COLORLESS_MANA,
|
SPEND_ONLY_MANA,
|
||||||
TARGET
|
TARGET
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,6 @@ import mage.ConditionalMana;
|
||||||
import mage.MageObject;
|
import mage.MageObject;
|
||||||
import mage.Mana;
|
import mage.Mana;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.constants.AsThoughEffectType;
|
|
||||||
import mage.constants.Duration;
|
import mage.constants.Duration;
|
||||||
import mage.constants.ManaType;
|
import mage.constants.ManaType;
|
||||||
import mage.constants.TurnPhase;
|
import mage.constants.TurnPhase;
|
||||||
|
@ -65,13 +64,6 @@ public class ManaPool implements Serializable {
|
||||||
|
|
||||||
private final Set<ManaType> doNotEmptyManaTypes = new HashSet<>();
|
private final Set<ManaType> doNotEmptyManaTypes = new HashSet<>();
|
||||||
|
|
||||||
private enum SpendType {
|
|
||||||
|
|
||||||
NORMAL,
|
|
||||||
ANY,
|
|
||||||
COLORLESS
|
|
||||||
}
|
|
||||||
|
|
||||||
public ManaPool(UUID playerId) {
|
public ManaPool(UUID playerId) {
|
||||||
this.playerId = playerId;
|
this.playerId = playerId;
|
||||||
autoPayment = true;
|
autoPayment = true;
|
||||||
|
@ -145,39 +137,25 @@ public class ManaPool implements Serializable {
|
||||||
// no mana added beyond the stock so don't auto pay this
|
// no mana added beyond the stock so don't auto pay this
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
SpendType spendType = getSpendType(ability, game, manaType, mana);
|
ManaType usableManaType = game.getContinuousEffects().asThoughMana(manaType, mana, ability.getSourceId(), ability, ability.getControllerId(), game);
|
||||||
if (!SpendType.COLORLESS.equals(spendType) || ManaType.COLORLESS.equals(manaType)) {
|
if (usableManaType == null) {
|
||||||
if (mana.get(manaType) > 0 || (spendType.equals(SpendType.ANY) && mana.count() > 0)) {
|
continue;
|
||||||
GameEvent event = new GameEvent(GameEvent.EventType.MANA_PAYED, ability.getId(), mana.getSourceId(), ability.getControllerId(), 0, mana.getFlag());
|
}
|
||||||
event.setData(mana.getOriginalId().toString());
|
if (mana.get(usableManaType) > 0) {
|
||||||
game.fireEvent(event);
|
GameEvent event = new GameEvent(GameEvent.EventType.MANA_PAYED, ability.getId(), mana.getSourceId(), ability.getControllerId(), 0, mana.getFlag());
|
||||||
if (!SpendType.NORMAL.equals(spendType)) {
|
event.setData(mana.getOriginalId().toString());
|
||||||
mana.removeAny();
|
game.fireEvent(event);
|
||||||
} else {
|
mana.remove(usableManaType);
|
||||||
mana.remove(manaType);
|
if (mana.count() == 0) { // so no items with count 0 stay in list
|
||||||
}
|
manaItems.remove(mana);
|
||||||
if (mana.count() == 0) { // so no items with count 0 stay in list
|
|
||||||
manaItems.remove(mana);
|
|
||||||
}
|
|
||||||
lockManaType(); // pay only one mana if mana payment is set to manually
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
lockManaType(); // pay only one mana if mana payment is set to manually
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if any mana can be spend to cast the mana cost of an ability
|
|
||||||
private SpendType getSpendType(Ability ability, Game game, ManaType manaType, ManaPoolItem mana) {
|
|
||||||
if (game.getContinuousEffects().asThoughMana(ability.getSourceId(), AsThoughEffectType.SPEND_ANY_MANA, ability, ability.getControllerId(), game, manaType, mana)) {
|
|
||||||
return SpendType.ANY;
|
|
||||||
}
|
|
||||||
if (game.getContinuousEffects().asThoughMana(ability.getSourceId(), AsThoughEffectType.SPEND_COLORLESS_MANA, ability, ability.getControllerId(), game, manaType, mana)) {
|
|
||||||
return SpendType.COLORLESS;
|
|
||||||
}
|
|
||||||
return SpendType.NORMAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int get(ManaType manaType) {
|
public int get(ManaType manaType) {
|
||||||
return getMana().get(manaType);
|
return getMana().get(manaType);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,30 +1,30 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without modification, are
|
* Redistribution and use in source and binary forms, with or without modification, are
|
||||||
* permitted provided that the following conditions are met:
|
* permitted provided that the following conditions are met:
|
||||||
*
|
*
|
||||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||||
* conditions and the following disclaimer.
|
* conditions and the following disclaimer.
|
||||||
*
|
*
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
* 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
|
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||||
* provided with the distribution.
|
* provided with the distribution.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
* 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
|
* 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
|
* 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
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 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
|
* 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
|
* 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
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* The views and conclusions contained in the software and documentation are those of the
|
* 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
|
* authors and should not be interpreted as representing official policies, either expressed
|
||||||
* or implied, of BetaSteward_at_googlemail.com.
|
* or implied, of BetaSteward_at_googlemail.com.
|
||||||
*/
|
*/
|
||||||
package mage.players;
|
package mage.players;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
@ -53,7 +53,8 @@ public class ManaPoolItem implements Serializable {
|
||||||
private Duration duration;
|
private Duration duration;
|
||||||
private int stock; // amount the item had at the start of casting something
|
private int stock; // amount the item had at the start of casting something
|
||||||
|
|
||||||
public ManaPoolItem() {}
|
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, UUID sourceId, UUID originalId, boolean flag) {
|
||||||
this.red = red;
|
this.red = red;
|
||||||
|
@ -75,7 +76,7 @@ public class ManaPoolItem implements Serializable {
|
||||||
this.conditionalMana.setManaProducerId(sourceId);
|
this.conditionalMana.setManaProducerId(sourceId);
|
||||||
this.conditionalMana.setManaProducerOriginalId(originalId);
|
this.conditionalMana.setManaProducerOriginalId(originalId);
|
||||||
this.flag = conditionalMana.getFlag();
|
this.flag = conditionalMana.getFlag();
|
||||||
this.duration = Duration.EndOfStep;
|
this.duration = Duration.EndOfStep;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ManaPoolItem(final ManaPoolItem item) {
|
public ManaPoolItem(final ManaPoolItem item) {
|
||||||
|
@ -191,7 +192,7 @@ public class ManaPoolItem implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int get(ManaType manaType) {
|
public int get(ManaType manaType) {
|
||||||
switch(manaType) {
|
switch (manaType) {
|
||||||
case BLACK:
|
case BLACK:
|
||||||
return black;
|
return black;
|
||||||
case BLUE:
|
case BLUE:
|
||||||
|
@ -208,29 +209,26 @@ public class ManaPoolItem implements Serializable {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeAny() {
|
public ManaType getFirstAvailable() {
|
||||||
int oldCount = count();
|
|
||||||
if (black > 0) {
|
if (black > 0) {
|
||||||
black--;
|
return ManaType.BLACK;
|
||||||
} else if (blue > 0) {
|
} else if (blue > 0) {
|
||||||
blue--;
|
return ManaType.BLUE;
|
||||||
} else if (green > 0) {
|
} else if (green > 0) {
|
||||||
green--;
|
return ManaType.GREEN;
|
||||||
} else if (red > 0) {
|
} else if (red > 0) {
|
||||||
red--;
|
return ManaType.RED;
|
||||||
} else if (white > 0) {
|
} else if (white > 0) {
|
||||||
white--;
|
return ManaType.WHITE;
|
||||||
} else if (colorless > 0) {
|
} else if (colorless > 0) {
|
||||||
colorless--;
|
return ManaType.COLORLESS;
|
||||||
}
|
}
|
||||||
if (stock == oldCount && oldCount > count()) {
|
return null;
|
||||||
stock--;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(ManaType manaType) {
|
public void remove(ManaType manaType) {
|
||||||
int oldCount = count();
|
int oldCount = count();
|
||||||
switch(manaType) {
|
switch (manaType) {
|
||||||
case BLACK:
|
case BLACK:
|
||||||
if (black > 0) {
|
if (black > 0) {
|
||||||
black--;
|
black--;
|
||||||
|
@ -264,11 +262,11 @@ public class ManaPoolItem implements Serializable {
|
||||||
}
|
}
|
||||||
if (stock == oldCount && oldCount > count()) {
|
if (stock == oldCount && oldCount > count()) {
|
||||||
stock--;
|
stock--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear(ManaType manaType) {
|
public void clear(ManaType manaType) {
|
||||||
switch(manaType) {
|
switch (manaType) {
|
||||||
case BLACK:
|
case BLACK:
|
||||||
black = 0;
|
black = 0;
|
||||||
break;
|
break;
|
||||||
|
@ -287,31 +285,36 @@ public class ManaPoolItem implements Serializable {
|
||||||
case COLORLESS:
|
case COLORLESS:
|
||||||
colorless = 0;
|
colorless = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(ManaType manaType, int amount) {
|
public void add(ManaType manaType, int amount) {
|
||||||
switch(manaType) {
|
switch (manaType) {
|
||||||
case BLACK:
|
case BLACK:
|
||||||
black += amount;
|
black += amount;
|
||||||
break;
|
break;
|
||||||
case BLUE:
|
case BLUE:
|
||||||
blue += amount;;
|
blue += amount;
|
||||||
|
;
|
||||||
break;
|
break;
|
||||||
case GREEN:
|
case GREEN:
|
||||||
green += amount;;
|
green += amount;
|
||||||
|
;
|
||||||
break;
|
break;
|
||||||
case RED:
|
case RED:
|
||||||
red += amount;;
|
red += amount;
|
||||||
|
;
|
||||||
break;
|
break;
|
||||||
case WHITE:
|
case WHITE:
|
||||||
white += amount;;
|
white += amount;
|
||||||
|
;
|
||||||
break;
|
break;
|
||||||
case COLORLESS:
|
case COLORLESS:
|
||||||
colorless += amount;;
|
colorless += amount;
|
||||||
|
;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Duration getDuration() {
|
public Duration getDuration() {
|
||||||
return duration;
|
return duration;
|
||||||
|
@ -328,5 +331,5 @@ public class ManaPoolItem implements Serializable {
|
||||||
public void setStock(int stock) {
|
public void setStock(int stock) {
|
||||||
this.stock = stock;
|
this.stock = stock;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue