mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 03:08:02 +00:00
ManaPart: use Effect for enter the battlefield when mana was spent
This commit is contained in:
committed by
Michael Kamensky
parent
3c5a62056b
commit
9f35da4698
@@ -22,8 +22,10 @@ import com.google.common.collect.Iterables;
|
|||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
|
||||||
|
import forge.card.MagicColor;
|
||||||
import forge.card.mana.ManaCost;
|
import forge.card.mana.ManaCost;
|
||||||
import forge.card.mana.ManaCostParser;
|
import forge.card.mana.ManaCostParser;
|
||||||
|
import forge.game.ability.AbilityFactory;
|
||||||
import forge.game.ability.AbilityUtils;
|
import forge.game.ability.AbilityUtils;
|
||||||
import forge.game.ability.ApiType;
|
import forge.game.ability.ApiType;
|
||||||
import forge.game.card.*;
|
import forge.game.card.*;
|
||||||
@@ -32,9 +34,15 @@ import forge.game.cost.Cost;
|
|||||||
import forge.game.keyword.KeywordInterface;
|
import forge.game.keyword.KeywordInterface;
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
import forge.game.player.PlayerController;
|
import forge.game.player.PlayerController;
|
||||||
|
import forge.game.replacement.ReplacementEffect;
|
||||||
|
import forge.game.replacement.ReplacementHandler;
|
||||||
|
import forge.game.replacement.ReplacementLayer;
|
||||||
import forge.game.spellability.*;
|
import forge.game.spellability.*;
|
||||||
import forge.game.trigger.Trigger;
|
import forge.game.trigger.Trigger;
|
||||||
|
import forge.game.trigger.TriggerHandler;
|
||||||
|
import forge.game.trigger.TriggerType;
|
||||||
import forge.game.zone.ZoneType;
|
import forge.game.zone.ZoneType;
|
||||||
|
import forge.util.Lang;
|
||||||
import forge.util.TextUtil;
|
import forge.util.TextUtil;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
@@ -363,10 +371,11 @@ public final class GameActionUtil {
|
|||||||
}
|
}
|
||||||
SpellAbility result = null;
|
SpellAbility result = null;
|
||||||
final Card host = sa.getHostCard();
|
final Card host = sa.getHostCard();
|
||||||
|
final Game game = host.getGame();
|
||||||
final Player activator = sa.getActivatingPlayer();
|
final Player activator = sa.getActivatingPlayer();
|
||||||
final PlayerController pc = activator.getController();
|
final PlayerController pc = activator.getController();
|
||||||
|
|
||||||
host.getGame().getAction().checkStaticAbilities(false);
|
game.getAction().checkStaticAbilities(false);
|
||||||
|
|
||||||
boolean reset = false;
|
boolean reset = false;
|
||||||
|
|
||||||
@@ -429,7 +438,60 @@ public final class GameActionUtil {
|
|||||||
int v = pc.chooseNumberForKeywordCost(sa, cost, ki, str, Integer.MAX_VALUE);
|
int v = pc.chooseNumberForKeywordCost(sa, cost, ki, str, Integer.MAX_VALUE);
|
||||||
|
|
||||||
if (v > 0) {
|
if (v > 0) {
|
||||||
host.addReplacementEffect(CardFactoryUtil.makeEtbCounter("etbCounter:P1P1:" + v, host, false));
|
|
||||||
|
final Card eff = new Card(game.nextCardId(), game);
|
||||||
|
eff.setTimestamp(game.getNextTimestamp());
|
||||||
|
eff.setName(c.getName() + "'s Effect");
|
||||||
|
eff.addType("Effect");
|
||||||
|
eff.setToken(true); // Set token to true, so when leaving play it gets nuked
|
||||||
|
eff.setOwner(activator);
|
||||||
|
|
||||||
|
eff.setImageKey(c.getImageKey());
|
||||||
|
eff.setColor(MagicColor.COLORLESS);
|
||||||
|
eff.setImmutable(true);
|
||||||
|
// try to get the SpellAbility from the mana ability
|
||||||
|
//eff.setEffectSource((SpellAbility)null);
|
||||||
|
|
||||||
|
eff.addRemembered(host);
|
||||||
|
|
||||||
|
String abStr = "DB$ PutCounter | Defined$ ReplacedCard | CounterType$ P1P1 | ETB$ True | CounterNum$ " + v;
|
||||||
|
|
||||||
|
SpellAbility saAb = AbilityFactory.getAbility(abStr, c);
|
||||||
|
|
||||||
|
CardFactoryUtil.setupETBReplacementAbility(saAb);
|
||||||
|
|
||||||
|
String desc = "It enters the battlefield with ";
|
||||||
|
desc += Lang.nounWithNumeral(v, CounterType.P1P1.getName() + " counter");
|
||||||
|
desc += " on it.";
|
||||||
|
|
||||||
|
String repeffstr = "Event$ Moved | ValidCard$ Card.IsRemembered | Destination$ Battlefield | Description$ " + desc;
|
||||||
|
|
||||||
|
ReplacementEffect re = ReplacementHandler.parseReplacement(repeffstr, eff, true);
|
||||||
|
re.setLayer(ReplacementLayer.Other);
|
||||||
|
re.setOverridingAbility(saAb);
|
||||||
|
|
||||||
|
eff.addReplacementEffect(re);
|
||||||
|
|
||||||
|
// Forgot Trigger
|
||||||
|
String trig = "Mode$ ChangesZone | ValidCard$ Card.IsRemembered | Origin$ Stack | Destination$ Any | TriggerZones$ Command | Static$ True";
|
||||||
|
String forgetEffect = "DB$ Pump | ForgetObjects$ TriggeredCard";
|
||||||
|
String exileEffect = "DB$ ChangeZone | Defined$ Self | Origin$ Command | Destination$ Exile"
|
||||||
|
+ " | ConditionDefined$ Remembered | ConditionPresent$ Card | ConditionCompare$ EQ0";
|
||||||
|
|
||||||
|
SpellAbility saForget = AbilityFactory.getAbility(forgetEffect, eff);
|
||||||
|
AbilitySub saExile = (AbilitySub) AbilityFactory.getAbility(exileEffect, eff);
|
||||||
|
saForget.setSubAbility(saExile);
|
||||||
|
|
||||||
|
final Trigger parsedTrigger = TriggerHandler.parseTrigger(trig, eff, true);
|
||||||
|
parsedTrigger.setOverridingAbility(saForget);
|
||||||
|
eff.addTrigger(parsedTrigger);
|
||||||
|
eff.updateStateForView();
|
||||||
|
|
||||||
|
// TODO: Add targeting to the effect so it knows who it's dealing with
|
||||||
|
game.getTriggerHandler().suppressMode(TriggerType.ChangesZone);
|
||||||
|
game.getAction().moveTo(ZoneType.Command, eff, null);
|
||||||
|
game.getTriggerHandler().clearSuppression(TriggerType.ChangesZone);
|
||||||
|
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
result = sa.copy();
|
result = sa.copy();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -254,7 +254,7 @@ public class ManaPool extends ManaConversionMatrix implements Iterable<Mana> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mana.addsCounters(sa)) {
|
if (mana.addsCounters(sa)) {
|
||||||
mana.getManaAbility().createETBCounters(host);
|
mana.getManaAbility().createETBCounters(host, this.owner);
|
||||||
}
|
}
|
||||||
if (mana.triggersWhenSpent()) {
|
if (mana.triggersWhenSpent()) {
|
||||||
mana.getManaAbility().addTriggersWhenSpent(sa, host);
|
mana.getManaAbility().addTriggersWhenSpent(sa, host);
|
||||||
|
|||||||
@@ -6,23 +6,24 @@
|
|||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package forge.game.spellability;
|
package forge.game.spellability;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
import forge.card.ColorSet;
|
import forge.card.ColorSet;
|
||||||
import forge.card.MagicColor;
|
import forge.card.MagicColor;
|
||||||
import forge.card.mana.ManaAtom;
|
import forge.card.mana.ManaAtom;
|
||||||
|
import forge.game.Game;
|
||||||
import forge.game.ability.AbilityFactory;
|
import forge.game.ability.AbilityFactory;
|
||||||
import forge.game.ability.AbilityKey;
|
import forge.game.ability.AbilityKey;
|
||||||
import forge.game.card.Card;
|
import forge.game.card.Card;
|
||||||
@@ -35,6 +36,8 @@ import forge.game.replacement.*;
|
|||||||
import forge.game.trigger.Trigger;
|
import forge.game.trigger.Trigger;
|
||||||
import forge.game.trigger.TriggerHandler;
|
import forge.game.trigger.TriggerHandler;
|
||||||
import forge.game.trigger.TriggerType;
|
import forge.game.trigger.TriggerType;
|
||||||
|
import forge.game.zone.ZoneType;
|
||||||
|
import forge.util.Lang;
|
||||||
import forge.util.TextUtil;
|
import forge.util.TextUtil;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
@@ -47,7 +50,7 @@ import java.util.regex.Pattern;
|
|||||||
* <p>
|
* <p>
|
||||||
* Abstract AbilityMana class.
|
* Abstract AbilityMana class.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @author Forge
|
* @author Forge
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
@@ -79,7 +82,7 @@ public class AbilityManaPart implements java.io.Serializable {
|
|||||||
* <p>
|
* <p>
|
||||||
* Constructor for AbilityMana.
|
* Constructor for AbilityMana.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param sourceCard
|
* @param sourceCard
|
||||||
* a {@link forge.game.card.Card} object.
|
* a {@link forge.game.card.Card} object.
|
||||||
*/
|
*/
|
||||||
@@ -112,7 +115,7 @@ public class AbilityManaPart implements java.io.Serializable {
|
|||||||
* <p>
|
* <p>
|
||||||
* produceMana.
|
* produceMana.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param produced
|
* @param produced
|
||||||
* a {@link java.lang.String} object.
|
* a {@link java.lang.String} object.
|
||||||
* @param player
|
* @param player
|
||||||
@@ -170,7 +173,7 @@ public class AbilityManaPart implements java.io.Serializable {
|
|||||||
* cannotCounterPaidWith.
|
* cannotCounterPaidWith.
|
||||||
* </p>
|
* </p>
|
||||||
* @param saBeingPaid
|
* @param saBeingPaid
|
||||||
*
|
*
|
||||||
* @return a {@link java.lang.String} object.
|
* @return a {@link java.lang.String} object.
|
||||||
*/
|
*/
|
||||||
public boolean cannotCounterPaidWith(SpellAbility saBeingPaid) {
|
public boolean cannotCounterPaidWith(SpellAbility saBeingPaid) {
|
||||||
@@ -187,7 +190,7 @@ public class AbilityManaPart implements java.io.Serializable {
|
|||||||
* addKeywords.
|
* addKeywords.
|
||||||
* </p>
|
* </p>
|
||||||
* @param saBeingPaid
|
* @param saBeingPaid
|
||||||
*
|
*
|
||||||
* @return a {@link java.lang.String} object.
|
* @return a {@link java.lang.String} object.
|
||||||
*/
|
*/
|
||||||
public boolean addKeywords(SpellAbility saBeingPaid) {
|
public boolean addKeywords(SpellAbility saBeingPaid) {
|
||||||
@@ -206,7 +209,7 @@ public class AbilityManaPart implements java.io.Serializable {
|
|||||||
* <p>
|
* <p>
|
||||||
* getKeywords.
|
* getKeywords.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @return a {@link java.lang.String} object.
|
* @return a {@link java.lang.String} object.
|
||||||
*/
|
*/
|
||||||
public String getKeywords() {
|
public String getKeywords() {
|
||||||
@@ -218,7 +221,7 @@ public class AbilityManaPart implements java.io.Serializable {
|
|||||||
* addsCounters.
|
* addsCounters.
|
||||||
* </p>
|
* </p>
|
||||||
* @param saBeingPaid
|
* @param saBeingPaid
|
||||||
*
|
*
|
||||||
* @return a {@link java.lang.String} object.
|
* @return a {@link java.lang.String} object.
|
||||||
*/
|
*/
|
||||||
public boolean addsCounters(SpellAbility saBeingPaid) {
|
public boolean addsCounters(SpellAbility saBeingPaid) {
|
||||||
@@ -228,10 +231,26 @@ public class AbilityManaPart implements java.io.Serializable {
|
|||||||
/**
|
/**
|
||||||
* createETBCounters
|
* createETBCounters
|
||||||
*/
|
*/
|
||||||
public void createETBCounters(Card c) {
|
public void createETBCounters(Card c, Player controller) {
|
||||||
String[] parse = this.addsCounters.split("_");
|
String[] parse = this.addsCounters.split("_");
|
||||||
// Convert random SVars if there are other cards with this effect
|
// Convert random SVars if there are other cards with this effect
|
||||||
if (c.isValid(parse[0], c.getController(), c, null)) {
|
if (c.isValid(parse[0], c.getController(), c, null)) {
|
||||||
|
final Game game = this.sourceCard.getGame();
|
||||||
|
final Card eff = new Card(game.nextCardId(), game);
|
||||||
|
eff.setTimestamp(game.getNextTimestamp());
|
||||||
|
eff.setName(sourceCard.getName() + "'s Effect");
|
||||||
|
eff.addType("Effect");
|
||||||
|
eff.setToken(true); // Set token to true, so when leaving play it gets nuked
|
||||||
|
eff.setOwner(controller);
|
||||||
|
|
||||||
|
eff.setImageKey(sourceCard.getImageKey());
|
||||||
|
eff.setColor(MagicColor.COLORLESS);
|
||||||
|
eff.setImmutable(true);
|
||||||
|
// try to get the SpellAbility from the mana ability
|
||||||
|
//eff.setEffectSource((SpellAbility)null);
|
||||||
|
|
||||||
|
eff.addRemembered(c);
|
||||||
|
|
||||||
String abStr = "DB$ PutCounter | Defined$ ReplacedCard | CounterType$ " + parse[1]
|
String abStr = "DB$ PutCounter | Defined$ ReplacedCard | CounterType$ " + parse[1]
|
||||||
+ " | ETB$ True | CounterNum$ " + parse[2];
|
+ " | ETB$ True | CounterNum$ " + parse[2];
|
||||||
|
|
||||||
@@ -241,15 +260,37 @@ public class AbilityManaPart implements java.io.Serializable {
|
|||||||
}
|
}
|
||||||
CardFactoryUtil.setupETBReplacementAbility(sa);
|
CardFactoryUtil.setupETBReplacementAbility(sa);
|
||||||
|
|
||||||
String repeffstr = "Event$ Moved | ValidCard$ Card.Self | Destination$ Battlefield "
|
String desc = "It enters the battlefield with ";
|
||||||
+ " | Secondary$ True | Description$ CARDNAME"
|
desc += Lang.nounWithNumeral(parse[2], CounterType.valueOf(parse[1]).getName() + " counter");
|
||||||
+ " enters the battlefield with " + CounterType.valueOf(parse[1]).getName() + " counters.";
|
desc += " on it.";
|
||||||
|
|
||||||
ReplacementEffect re = ReplacementHandler.parseReplacement(repeffstr, c, false);
|
String repeffstr = "Event$ Moved | ValidCard$ Card.IsRemembered | Destination$ Battlefield | Description$ " + desc;
|
||||||
|
|
||||||
|
ReplacementEffect re = ReplacementHandler.parseReplacement(repeffstr, eff, true);
|
||||||
re.setLayer(ReplacementLayer.Other);
|
re.setLayer(ReplacementLayer.Other);
|
||||||
re.setOverridingAbility(sa);
|
re.setOverridingAbility(sa);
|
||||||
|
|
||||||
c.addChangedCardTraits(null, null, null, ImmutableList.of(re), null, false, false, false, sa.getHostCard().getGame().getNextTimestamp());
|
eff.addReplacementEffect(re);
|
||||||
|
|
||||||
|
// Forgot Trigger
|
||||||
|
String trig = "Mode$ ChangesZone | ValidCard$ Card.IsRemembered | Origin$ Stack | Destination$ Any | TriggerZones$ Command | Static$ True";
|
||||||
|
String forgetEffect = "DB$ Pump | ForgetObjects$ TriggeredCard";
|
||||||
|
String exileEffect = "DB$ ChangeZone | Defined$ Self | Origin$ Command | Destination$ Exile"
|
||||||
|
+ " | ConditionDefined$ Remembered | ConditionPresent$ Card | ConditionCompare$ EQ0";
|
||||||
|
|
||||||
|
SpellAbility saForget = AbilityFactory.getAbility(forgetEffect, eff);
|
||||||
|
AbilitySub saExile = (AbilitySub) AbilityFactory.getAbility(exileEffect, eff);
|
||||||
|
saForget.setSubAbility(saExile);
|
||||||
|
|
||||||
|
final Trigger parsedTrigger = TriggerHandler.parseTrigger(trig, eff, true);
|
||||||
|
parsedTrigger.setOverridingAbility(saForget);
|
||||||
|
eff.addTrigger(parsedTrigger);
|
||||||
|
eff.updateStateForView();
|
||||||
|
|
||||||
|
// TODO: Add targeting to the effect so it knows who it's dealing with
|
||||||
|
game.getTriggerHandler().suppressMode(TriggerType.ChangesZone);
|
||||||
|
game.getAction().moveTo(ZoneType.Command, eff, null);
|
||||||
|
game.getTriggerHandler().clearSuppression(TriggerType.ChangesZone);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -270,7 +311,7 @@ public class AbilityManaPart implements java.io.Serializable {
|
|||||||
* <p>
|
* <p>
|
||||||
* getManaRestrictions.
|
* getManaRestrictions.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @return a {@link java.lang.String} object.
|
* @return a {@link java.lang.String} object.
|
||||||
*/
|
*/
|
||||||
public String getManaRestrictions() {
|
public String getManaRestrictions() {
|
||||||
@@ -281,7 +322,7 @@ public class AbilityManaPart implements java.io.Serializable {
|
|||||||
* <p>
|
* <p>
|
||||||
* meetsManaRestrictions.
|
* meetsManaRestrictions.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param sa
|
* @param sa
|
||||||
* a {@link forge.game.spellability.SpellAbility} object.
|
* a {@link forge.game.spellability.SpellAbility} object.
|
||||||
* @return a boolean.
|
* @return a boolean.
|
||||||
@@ -297,7 +338,7 @@ public class AbilityManaPart implements java.io.Serializable {
|
|||||||
if (restriction.equals("nonSpell")) {
|
if (restriction.equals("nonSpell")) {
|
||||||
return !sa.isSpell();
|
return !sa.isSpell();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (restriction.equals("CumulativeUpkeep")) {
|
if (restriction.equals("CumulativeUpkeep")) {
|
||||||
if (sa.isCumulativeupkeep()) {
|
if (sa.isCumulativeupkeep()) {
|
||||||
return true;
|
return true;
|
||||||
@@ -350,7 +391,7 @@ public class AbilityManaPart implements java.io.Serializable {
|
|||||||
* <p>
|
* <p>
|
||||||
* mana.
|
* mana.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @return a {@link java.lang.String} object.
|
* @return a {@link java.lang.String} object.
|
||||||
*/
|
*/
|
||||||
public final String mana() {
|
public final String mana() {
|
||||||
@@ -439,7 +480,7 @@ public class AbilityManaPart implements java.io.Serializable {
|
|||||||
* <p>
|
* <p>
|
||||||
* canProduce.
|
* canProduce.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param s
|
* @param s
|
||||||
* a {@link java.lang.String} object.
|
* a {@link java.lang.String} object.
|
||||||
* @return a boolean.
|
* @return a boolean.
|
||||||
@@ -469,7 +510,7 @@ public class AbilityManaPart implements java.io.Serializable {
|
|||||||
* <p>
|
* <p>
|
||||||
* isBasic.
|
* isBasic.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @return a boolean.
|
* @return a boolean.
|
||||||
*/
|
*/
|
||||||
public final boolean isBasic() {
|
public final boolean isBasic() {
|
||||||
@@ -542,7 +583,7 @@ public class AbilityManaPart implements java.io.Serializable {
|
|||||||
public Card getSourceCard() {
|
public Card getSourceCard() {
|
||||||
return sourceCard;
|
return sourceCard;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSourceCard(final Card host) {
|
public void setSourceCard(final Card host) {
|
||||||
sourceCard = host;
|
sourceCard = host;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user