mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 12:48:00 +00:00
Merge branch 'master' into mutate
This commit is contained in:
@@ -2,8 +2,19 @@ package forge.game;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import forge.game.card.Card;
|
||||
|
||||
public class CardTraitPredicates {
|
||||
|
||||
public static final Predicate<CardTraitBase> isHostCard(final Card host) {
|
||||
return new Predicate<CardTraitBase>() {
|
||||
@Override
|
||||
public boolean apply(final CardTraitBase sa) {
|
||||
return host.equals(sa.getHostCard());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static final Predicate<CardTraitBase> hasParam(final String name) {
|
||||
return new Predicate<CardTraitBase>() {
|
||||
@Override
|
||||
|
||||
@@ -5,6 +5,7 @@ import forge.card.MagicColor;
|
||||
import forge.game.ability.AbilityUtils;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.card.CardState;
|
||||
import forge.game.cost.Cost;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.game.staticability.StaticAbility;
|
||||
@@ -131,6 +132,9 @@ public class ForgeScript {
|
||||
return !sa.isManaAbility();
|
||||
} else if (property.equals("withoutXCost")) {
|
||||
return !sa.costHasManaX();
|
||||
} else if (property.equals("hasTapCost")) {
|
||||
Cost cost = sa.getPayCosts();
|
||||
return cost != null && cost.hasTapCost();
|
||||
} else if (property.equals("Buyback")) {
|
||||
return sa.isBuyBackAbility();
|
||||
} else if (property.equals("Cycling")) {
|
||||
|
||||
@@ -207,7 +207,7 @@ public class GameAction {
|
||||
if (!c.isRealToken()) {
|
||||
copied = CardFactory.copyCard(c, false);
|
||||
|
||||
if (fromBattlefield) {
|
||||
if (!zoneTo.is(ZoneType.Stack)) {
|
||||
// when a card leaves the battlefield, ensure it's in its original state
|
||||
// (we need to do this on the object before copying it, or it won't work correctly e.g.
|
||||
// on Transformed objects)
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
*/
|
||||
package forge.game;
|
||||
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
@@ -252,6 +251,18 @@ public final class GameActionUtil {
|
||||
}
|
||||
}
|
||||
|
||||
if (sa.isManaAbility() && sa.isActivatedAbility() && activator.hasKeyword("Piracy") && source.isLand() && source.isInPlay() && !activator.equals(source.getController()) && sa.getPayCosts().hasTapCost()) {
|
||||
SpellAbility newSA = sa.copy(activator);
|
||||
// to bypass Activator restriction, set Activator to Player
|
||||
sa.getRestrictions().setActivator("Player");
|
||||
|
||||
// extra Mana restriction to only Spells
|
||||
for (AbilityManaPart mp : newSA.getAllManaParts()) {
|
||||
mp.setExtraManaRestriction("Spell");
|
||||
}
|
||||
alternatives.add(newSA);
|
||||
}
|
||||
|
||||
// below are for some special cases of activated abilities
|
||||
if (sa.isCycling() && activator.hasKeyword("CyclingForZero")) {
|
||||
for (final KeywordInterface inst : source.getKeywords()) {
|
||||
@@ -277,7 +288,6 @@ public final class GameActionUtil {
|
||||
newSA.setDescription(sb.toString());
|
||||
|
||||
alternatives.add(newSA);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -473,62 +483,12 @@ public final class GameActionUtil {
|
||||
int v = pc.chooseNumberForKeywordCost(sa, cost, ki, str, Integer.MAX_VALUE);
|
||||
|
||||
if (v > 0) {
|
||||
|
||||
final Card eff = new Card(game.nextCardId(), game);
|
||||
eff.setTimestamp(game.getNextTimestamp());
|
||||
eff.setName(c.getName() + "'s Effect");
|
||||
eff.addType("Effect");
|
||||
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, CounterEnumType.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);
|
||||
Card eff = createETBCountersEffect(c, host, activator, "P1P1", String.valueOf(v));
|
||||
|
||||
if (result == null) {
|
||||
result = sa.copy();
|
||||
}
|
||||
result.addRollbackEffect(eff);
|
||||
for (int i = 0; i < v; i++) {
|
||||
result.getPayCosts().add(cost);
|
||||
}
|
||||
@@ -546,45 +506,85 @@ public final class GameActionUtil {
|
||||
return result != null ? result : sa;
|
||||
}
|
||||
|
||||
private static boolean hasUrzaLands(final Player p) {
|
||||
final CardCollectionView landsControlled = p.getCardsIn(ZoneType.Battlefield);
|
||||
return Iterables.any(landsControlled, Predicates.and(CardPredicates.isType("Urza's"), CardPredicates.isType("Mine")))
|
||||
&& Iterables.any(landsControlled, Predicates.and(CardPredicates.isType("Urza's"), CardPredicates.isType("Power-Plant")))
|
||||
&& Iterables.any(landsControlled, Predicates.and(CardPredicates.isType("Urza's"), CardPredicates.isType("Tower")));
|
||||
public static Card createETBCountersEffect(Card sourceCard, Card c, Player controller, String counter, String amount) {
|
||||
final Game game = sourceCard.getGame();
|
||||
final Card eff = new Card(game.nextCardId(), game);
|
||||
eff.setTimestamp(game.getNextTimestamp());
|
||||
eff.setName(sourceCard.getName() + "'s Effect");
|
||||
eff.addType("Effect");
|
||||
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$ " + counter
|
||||
+ " | ETB$ True | CounterNum$ " + amount;
|
||||
|
||||
SpellAbility sa = AbilityFactory.getAbility(abStr, c);
|
||||
if (!StringUtils.isNumeric(amount)) {
|
||||
sa.setSVar(amount, sourceCard.getSVar(amount));
|
||||
}
|
||||
CardFactoryUtil.setupETBReplacementAbility(sa);
|
||||
|
||||
String desc = "It enters the battlefield with ";
|
||||
desc += Lang.nounWithNumeral(amount, CounterType.getType(counter).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(sa);
|
||||
|
||||
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);
|
||||
|
||||
return eff;
|
||||
}
|
||||
|
||||
public static int amountOfManaGenerated(final SpellAbility sa, boolean multiply) {
|
||||
// Calculate generated mana here for stack description and resolving
|
||||
|
||||
int amount = sa.hasParam("Amount") ? AbilityUtils.calculateAmount(sa.getHostCard(), sa.getParam("Amount"), sa) : 1;
|
||||
AbilityManaPart abMana = sa.getManaPartRecursive();
|
||||
|
||||
if (sa.hasParam("Bonus")) {
|
||||
// For mana abilities that get a bonus
|
||||
// Bonus currently MULTIPLIES the base amount. Base Amounts should
|
||||
// ALWAYS be Base
|
||||
int bonus = 0;
|
||||
if (sa.getParam("Bonus").equals("UrzaLands")) {
|
||||
if (hasUrzaLands(sa.getActivatingPlayer())) {
|
||||
bonus = Integer.parseInt(sa.getParam("BonusProduced"));
|
||||
}
|
||||
public static String generatedTotalMana(final SpellAbility sa) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
SpellAbility tail = sa;
|
||||
while (tail != null) {
|
||||
String value = generatedMana(tail);
|
||||
if (!value.isEmpty() && !"0".equals(value)) {
|
||||
sb.append(value).append(" ");
|
||||
}
|
||||
|
||||
amount += bonus;
|
||||
}
|
||||
|
||||
if (!multiply || abMana.isAnyMana() || abMana.isComboMana() || abMana.isSpecialMana()) {
|
||||
return amount;
|
||||
} else {
|
||||
// For cards that produce like {C}{R} vs cards that produce {R}{R}.
|
||||
return abMana.mana().split(" ").length * amount;
|
||||
tail = tail.getSubAbility();
|
||||
}
|
||||
return sb.toString().trim();
|
||||
}
|
||||
|
||||
|
||||
public static String generatedMana(final SpellAbility sa) {
|
||||
int amount = amountOfManaGenerated(sa, false);
|
||||
int amount = sa.amountOfManaGenerated(false);
|
||||
AbilityManaPart abMana = sa.getManaPart();
|
||||
if (abMana == null) {
|
||||
return "";
|
||||
}
|
||||
String baseMana;
|
||||
|
||||
if (abMana.isComboMana()) {
|
||||
|
||||
@@ -77,4 +77,5 @@ public abstract class TriggerReplacementBase extends CardTraitBase implements II
|
||||
this.overridingAbility = overridingAbility0;
|
||||
}
|
||||
|
||||
abstract public SpellAbility ensureAbility();
|
||||
}
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
package forge.game.ability;
|
||||
|
||||
import forge.game.ability.effects.ChangeZoneAllEffect;
|
||||
import forge.game.ability.effects.ChangeZoneEffect;
|
||||
import forge.game.ability.effects.ManaEffect;
|
||||
import forge.game.ability.effects.ManaReflectedEffect;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.cost.Cost;
|
||||
import forge.game.spellability.AbilityActivated;
|
||||
@@ -15,8 +11,6 @@ import java.util.Map;
|
||||
public class AbilityApiBased extends AbilityActivated {
|
||||
private final SpellAbilityEffect effect;
|
||||
|
||||
private static final long serialVersionUID = -4183793555528531978L;
|
||||
|
||||
public AbilityApiBased(ApiType api0, Card sourceCard, Cost abCost, TargetRestrictions tgt, Map<String, String> params0) {
|
||||
super(sourceCard, abCost, tgt);
|
||||
originalMapParams.putAll(params0);
|
||||
@@ -24,13 +18,12 @@ public class AbilityApiBased extends AbilityActivated {
|
||||
api = api0;
|
||||
effect = api.getSpellEffect();
|
||||
|
||||
if (effect instanceof ManaEffect || effect instanceof ManaReflectedEffect) {
|
||||
|
||||
if (api.equals(ApiType.Mana) || api.equals(ApiType.ManaReflected)) {
|
||||
this.setManaPart(new AbilityManaPart(sourceCard, mapParams));
|
||||
this.setUndoable(true); // will try at least
|
||||
}
|
||||
|
||||
if (effect instanceof ChangeZoneEffect || effect instanceof ChangeZoneAllEffect) {
|
||||
if (api.equals(ApiType.ChangeZone) || api.equals(ApiType.ChangeZoneAll)) {
|
||||
AbilityFactory.adjustChangeZoneTarget(mapParams, this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,7 +249,7 @@ public final class AbilityFactory {
|
||||
}
|
||||
}
|
||||
|
||||
if (api == ApiType.DelayedTrigger && mapParams.containsKey("Execute")) {
|
||||
if ((api == ApiType.DelayedTrigger || api == ApiType.ImmediateTrigger) && mapParams.containsKey("Execute")) {
|
||||
spellAbility.setSVar(mapParams.get("Execute"), sVarHolder.getSVar(mapParams.get("Execute")));
|
||||
}
|
||||
|
||||
@@ -364,10 +364,6 @@ public final class AbilityFactory {
|
||||
if (mapParams.containsKey("TargetsWithDifferentCMC")) {
|
||||
abTgt.setDifferentCMC(true);
|
||||
}
|
||||
if (mapParams.containsKey("DividedAsYouChoose")) {
|
||||
abTgt.calculateStillToDivide(mapParams.get("DividedAsYouChoose"), null, null);
|
||||
abTgt.setDividedAsYouChoose(true);
|
||||
}
|
||||
if (mapParams.containsKey("TargetsAtRandom")) {
|
||||
abTgt.setRandomTarget(true);
|
||||
}
|
||||
|
||||
@@ -1400,7 +1400,7 @@ public class AbilityUtils {
|
||||
);
|
||||
|
||||
// check conditions
|
||||
if (sa.getConditions().areMet(sa)) {
|
||||
if (sa.metConditions()) {
|
||||
if (sa.isWrapper() || StringUtils.isBlank(sa.getParam("UnlessCost"))) {
|
||||
sa.resolve();
|
||||
}
|
||||
@@ -1668,10 +1668,15 @@ public class AbilityUtils {
|
||||
|
||||
// Count$Kicked.<numHB>.<numNotHB>
|
||||
if (sq[0].startsWith("Kicked")) {
|
||||
boolean kicked = ((SpellAbility)ctb).isKicked() || c.getKickerMagnitude() > 0;
|
||||
boolean kicked = sa.isKicked() || c.getKickerMagnitude() > 0;
|
||||
return CardFactoryUtil.doXMath(Integer.parseInt(kicked ? sq[1] : sq[2]), expr, c);
|
||||
}
|
||||
|
||||
// Count$UrzaLands.<numHB>.<numNotHB>
|
||||
if (sq[0].startsWith("UrzaLands")) {
|
||||
return CardFactoryUtil.doXMath(Integer.parseInt(sa.getActivatingPlayer().hasUrzaLands() ? sq[1] : sq[2]), expr, c);
|
||||
}
|
||||
|
||||
//Count$SearchedLibrary.<DefinedPlayer>
|
||||
if (sq[0].contains("SearchedLibrary")) {
|
||||
int sum = 0;
|
||||
|
||||
@@ -136,6 +136,7 @@ public enum ApiType {
|
||||
Repeat (RepeatEffect.class),
|
||||
RepeatEach (RepeatEachEffect.class),
|
||||
ReplaceEffect (ReplaceEffect.class),
|
||||
ReplaceMana (ReplaceManaEffect.class),
|
||||
ReplaceDamage (ReplaceDamageEffect.class),
|
||||
ReplaceSplitDamage (ReplaceSplitDamageEffect.class),
|
||||
RestartGame (RestartGameEffect.class),
|
||||
|
||||
@@ -429,7 +429,7 @@ public abstract class SpellAbilityEffect {
|
||||
+ " exile it instead of putting it anywhere else.";
|
||||
String effect = "DB$ ChangeZone | Defined$ ReplacedCard | Origin$ Battlefield | Destination$ " + zone;
|
||||
|
||||
ReplacementEffect re = ReplacementHandler.parseReplacement(repeffstr, eff, true);
|
||||
ReplacementEffect re = ReplacementHandler.parseReplacement(repeffstr, eff, true, null);
|
||||
re.setLayer(ReplacementLayer.Other);
|
||||
|
||||
re.setOverridingAbility(AbilityFactory.getAbility(effect, eff));
|
||||
|
||||
@@ -2,10 +2,6 @@ package forge.game.ability;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import forge.game.ability.effects.ChangeZoneAllEffect;
|
||||
import forge.game.ability.effects.ChangeZoneEffect;
|
||||
import forge.game.ability.effects.ManaEffect;
|
||||
import forge.game.ability.effects.ManaReflectedEffect;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.cost.Cost;
|
||||
import forge.game.spellability.AbilityManaPart;
|
||||
@@ -28,11 +24,11 @@ public class SpellApiBased extends Spell {
|
||||
// A spell is always intrinsic
|
||||
this.setIntrinsic(true);
|
||||
|
||||
if (effect instanceof ManaEffect || effect instanceof ManaReflectedEffect) {
|
||||
if (api.equals(ApiType.Mana) || api.equals(ApiType.ManaReflected)) {
|
||||
this.setManaPart(new AbilityManaPart(sourceCard, mapParams));
|
||||
}
|
||||
|
||||
if (effect instanceof ChangeZoneEffect || effect instanceof ChangeZoneAllEffect) {
|
||||
if (api.equals(ApiType.ChangeZone) || api.equals(ApiType.ChangeZoneAll)) {
|
||||
AbilityFactory.adjustChangeZoneTarget(mapParams, this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,8 +159,7 @@ public abstract class AnimateEffectBase extends SpellAbilityEffect {
|
||||
// Grant triggers
|
||||
final List<Trigger> addedTriggers = Lists.newArrayList();
|
||||
for (final String s : triggers) {
|
||||
final Trigger parsedTrigger = TriggerHandler.parseTrigger(AbilityUtils.getSVar(sa, s), c, false);
|
||||
parsedTrigger.setOverridingAbility(AbilityFactory.getAbility(c, parsedTrigger.getParam("Execute"), sa));
|
||||
final Trigger parsedTrigger = TriggerHandler.parseTrigger(AbilityUtils.getSVar(sa, s), c, false, sa);
|
||||
parsedTrigger.setOriginalHost(source);
|
||||
addedTriggers.add(parsedTrigger);
|
||||
}
|
||||
@@ -168,7 +167,7 @@ public abstract class AnimateEffectBase extends SpellAbilityEffect {
|
||||
// give replacement effects
|
||||
final List<ReplacementEffect> addedReplacements = Lists.newArrayList();
|
||||
for (final String s : replacements) {
|
||||
addedReplacements.add(ReplacementHandler.parseReplacement(AbilityUtils.getSVar(sa, s), c, false));
|
||||
addedReplacements.add(ReplacementHandler.parseReplacement(AbilityUtils.getSVar(sa, s), c, false, sa));
|
||||
}
|
||||
|
||||
// give static abilities (should only be used by cards to give
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package forge.game.ability.effects;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import forge.game.GameEntity;
|
||||
import forge.game.GameObject;
|
||||
import forge.game.GameObjectPredicates;
|
||||
import forge.game.ability.SpellAbilityEffect;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
@@ -19,7 +21,7 @@ import org.apache.commons.lang3.tuple.Pair;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
@@ -42,9 +44,6 @@ public class ChangeTargetsEffect extends SpellAbilityEffect {
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean changesOneTarget = sa.hasParam("ChangeSingleTarget"); // The only card known to replace targets with self is Spellskite
|
||||
// There is also Muck Drubb but it replaces ALL occurences of a single target with itself (unlike Spellskite that has to be activated for each).
|
||||
|
||||
SpellAbilityStackInstance changingTgtSI = si;
|
||||
Player chooser = sa.getActivatingPlayer();
|
||||
|
||||
@@ -54,11 +53,11 @@ public class ChangeTargetsEffect extends SpellAbilityEffect {
|
||||
if (isOptional && !chooser.getController().confirmAction(sa, null, Localizer.getInstance().getMessage("lblDoYouWantChangeAbilityTargets", tgtSA.getHostCard().toString()))) {
|
||||
continue;
|
||||
}
|
||||
if (changesOneTarget) {
|
||||
if (sa.hasParam("ChangeSingleTarget")) {
|
||||
// 1. choose a target of target spell
|
||||
List<Pair<SpellAbilityStackInstance, GameObject>> allTargets = new ArrayList<>();
|
||||
while(changingTgtSI != null) {
|
||||
SpellAbility changedSa = changingTgtSI.getSpellAbility(true);
|
||||
SpellAbility changedSa = changingTgtSI.getSpellAbility(true);
|
||||
if (changedSa.usesTargeting()) {
|
||||
for(GameObject it : changedSa.getTargets())
|
||||
allTargets.add(ImmutablePair.of(changingTgtSI, it));
|
||||
@@ -77,6 +76,8 @@ public class ChangeTargetsEffect extends SpellAbilityEffect {
|
||||
GameObject oldTarget = chosenTarget.getValue();
|
||||
TargetChoices oldTargetBlock = replaceIn.getTargetChoices();
|
||||
TargetChoices newTargetBlock = oldTargetBlock.clone();
|
||||
// gets the divied value from old target
|
||||
Integer div = oldTargetBlock.getDividedValue(oldTarget);
|
||||
newTargetBlock.remove(oldTarget);
|
||||
replaceIn.updateTarget(newTargetBlock);
|
||||
// 3. test if updated choices would be correct.
|
||||
@@ -84,7 +85,10 @@ public class ChangeTargetsEffect extends SpellAbilityEffect {
|
||||
|
||||
if (replaceIn.getSpellAbility(true).canTarget(newTarget)) {
|
||||
newTargetBlock.add(newTarget);
|
||||
replaceIn.updateTarget(newTargetBlock, oldTarget, newTarget);
|
||||
if (div != null) {
|
||||
newTargetBlock.addDividedAllocation(newTarget, div);
|
||||
}
|
||||
replaceIn.updateTarget(newTargetBlock);
|
||||
}
|
||||
else {
|
||||
replaceIn.updateTarget(oldTargetBlock);
|
||||
@@ -93,36 +97,38 @@ public class ChangeTargetsEffect extends SpellAbilityEffect {
|
||||
else {
|
||||
while(changingTgtSI != null) {
|
||||
SpellAbility changingTgtSA = changingTgtSI.getSpellAbility(true);
|
||||
if (sa.hasParam("RandomTarget")){
|
||||
if (changingTgtSA.usesTargeting()) {
|
||||
if (changingTgtSA.usesTargeting()) {
|
||||
// random target and DefinedMagnet works on single targets
|
||||
if (sa.hasParam("RandomTarget")){
|
||||
int div = changingTgtSA.getTotalDividedValue();
|
||||
changingTgtSA.resetTargets();
|
||||
List<GameEntity> candidates = changingTgtSA.getTargetRestrictions().getAllCandidates(changingTgtSA, true);
|
||||
GameEntity choice = Aggregates.random(candidates);
|
||||
changingTgtSA.getTargets().add(choice);
|
||||
changingTgtSI.updateTarget(changingTgtSA.getTargets(), null, choice);
|
||||
if (changingTgtSA.isDividedAsYouChoose()) {
|
||||
changingTgtSA.addDividedAllocation(choice, div);
|
||||
}
|
||||
|
||||
changingTgtSI.updateTarget(changingTgtSA.getTargets());
|
||||
}
|
||||
}
|
||||
else if (sa.hasParam("DefinedMagnet")){
|
||||
GameObject newTarget = Iterables.getFirst(getDefinedCardsOrTargeted(sa, "DefinedMagnet"), null);
|
||||
if (newTarget != null && changingTgtSA.canTarget(newTarget)) {
|
||||
changingTgtSA.resetTargets();
|
||||
changingTgtSA.getTargets().add(newTarget);
|
||||
changingTgtSI.updateTarget(changingTgtSA.getTargets(), null, newTarget);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Update targets, with a potential new target
|
||||
TargetChoices newTarget = sa.getActivatingPlayer().getController().chooseNewTargetsFor(changingTgtSA);
|
||||
if (null != newTarget) {
|
||||
if (sa.hasParam("TargetRestriction")) {
|
||||
if (newTarget.getFirstTargetedCard() != null && newTarget.getFirstTargetedCard().
|
||||
isValid(sa.getParam("TargetRestriction").split(","), activator, sa.getHostCard(), sa)) {
|
||||
changingTgtSI.updateTarget(newTarget);
|
||||
} else if (newTarget.getFirstTargetedPlayer() != null && newTarget.getFirstTargetedPlayer().
|
||||
isValid(sa.getParam("TargetRestriction").split(","), activator, sa.getHostCard(), sa)) {
|
||||
changingTgtSI.updateTarget(newTarget);
|
||||
else if (sa.hasParam("DefinedMagnet")){
|
||||
GameObject newTarget = Iterables.getFirst(getDefinedCardsOrTargeted(sa, "DefinedMagnet"), null);
|
||||
if (newTarget != null && changingTgtSA.canTarget(newTarget)) {
|
||||
int div = changingTgtSA.getTotalDividedValue();
|
||||
changingTgtSA.resetTargets();
|
||||
changingTgtSA.getTargets().add(newTarget);
|
||||
changingTgtSI.updateTarget(changingTgtSA.getTargets());
|
||||
if (changingTgtSA.isDividedAsYouChoose()) {
|
||||
changingTgtSA.addDividedAllocation(newTarget, div);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Update targets, with a potential new target
|
||||
Predicate<GameObject> filter = sa.hasParam("TargetRestriction") ? GameObjectPredicates.restriction(sa.getParam("TargetRestriction").split(","), activator, sa.getHostCard(), sa) : null;
|
||||
// TODO Creature.Other might not work yet as it should
|
||||
TargetChoices newTarget = sa.getActivatingPlayer().getController().chooseNewTargetsFor(changingTgtSA, filter, false);
|
||||
if (null != newTarget) {
|
||||
changingTgtSI.updateTarget(newTarget);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,6 +108,8 @@ public class CloneEffect extends SpellAbilityEffect {
|
||||
if (!cloneTargets.isEmpty()) {
|
||||
tgtCard = cloneTargets.get(0);
|
||||
game.getTriggerHandler().clearActiveTriggers(tgtCard, null);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} else if (sa.hasParam("Choices") && sa.usesTargeting()) {
|
||||
tgtCard = sa.getTargets().getFirstTargetedCard();
|
||||
|
||||
@@ -111,7 +111,7 @@ public class CopySpellAbilityEffect extends SpellAbilityEffect {
|
||||
candidates.remove(p);
|
||||
|
||||
for (GameEntity o : candidates) {
|
||||
SpellAbility copy = CardFactory.copySpellAbilityAndPossiblyHost(sa, chosenSA);
|
||||
SpellAbility copy = CardFactory.copySpellAbilityAndPossiblyHost(sa, chosenSA, controller);
|
||||
resetFirstTargetOnCopy(copy, o, targetedSA);
|
||||
copies.add(copy);
|
||||
}
|
||||
@@ -144,12 +144,12 @@ public class CopySpellAbilityEffect extends SpellAbilityEffect {
|
||||
}
|
||||
|
||||
for (final Card c : valid) {
|
||||
SpellAbility copy = CardFactory.copySpellAbilityAndPossiblyHost(sa, chosenSA);
|
||||
SpellAbility copy = CardFactory.copySpellAbilityAndPossiblyHost(sa, chosenSA, controller);
|
||||
resetFirstTargetOnCopy(copy, c, targetedSA);
|
||||
copies.add(copy);
|
||||
}
|
||||
for (final Player p : players) {
|
||||
SpellAbility copy = CardFactory.copySpellAbilityAndPossiblyHost(sa, chosenSA);
|
||||
SpellAbility copy = CardFactory.copySpellAbilityAndPossiblyHost(sa, chosenSA, controller);
|
||||
resetFirstTargetOnCopy(copy, p, targetedSA);
|
||||
copies.add(copy);
|
||||
}
|
||||
@@ -157,12 +157,9 @@ public class CopySpellAbilityEffect extends SpellAbilityEffect {
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < amount; i++) {
|
||||
SpellAbility copy = CardFactory.copySpellAbilityAndPossiblyHost(sa, chosenSA);
|
||||
SpellAbility copy = CardFactory.copySpellAbilityAndPossiblyHost(sa, chosenSA, controller);
|
||||
if (sa.hasParam("MayChooseTarget")) {
|
||||
copy.setMayChooseNewTargets(true);
|
||||
if (copy.usesTargeting()) {
|
||||
copy.getTargetRestrictions().setMandatory(true);
|
||||
}
|
||||
}
|
||||
|
||||
// extra case for Epic to remove the keyword and the last part of the SpellAbility
|
||||
@@ -206,12 +203,9 @@ public class CopySpellAbilityEffect extends SpellAbilityEffect {
|
||||
}
|
||||
int extraAmount = addAmount - copies.size();
|
||||
for (int i = 0; i < extraAmount; i++) {
|
||||
SpellAbility copy = CardFactory.copySpellAbilityAndPossiblyHost(sa, chosenSA);
|
||||
SpellAbility copy = CardFactory.copySpellAbilityAndPossiblyHost(sa, chosenSA, controller);
|
||||
// extra copies added with CopySpellReplacenment currently always has new choose targets
|
||||
copy.setMayChooseNewTargets(true);
|
||||
if (copy.usesTargeting()) {
|
||||
copy.getTargetRestrictions().setMandatory(true);
|
||||
}
|
||||
copies.add(copy);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,13 +27,12 @@ public class CountersMoveEffect extends SpellAbilityEffect {
|
||||
|
||||
@Override
|
||||
protected String getStackDescription(SpellAbility sa) {
|
||||
final Card host = sa.getHostCard();
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
|
||||
final List<Card> tgtCards = getDefinedCardsOrTargeted(sa);
|
||||
|
||||
Card source = null;
|
||||
if (sa.usesTargeting() && sa.getTargetRestrictions().getMinTargets(host, sa) == 2) {
|
||||
if (sa.usesTargeting() && sa.getMinTargets() == 2) {
|
||||
if (tgtCards.size() < 2) {
|
||||
return "";
|
||||
}
|
||||
@@ -241,7 +240,7 @@ public class CountersMoveEffect extends SpellAbilityEffect {
|
||||
Card source = null;
|
||||
List<Card> tgtCards = getDefinedCardsOrTargeted(sa);
|
||||
// special logic for moving from Target to Target
|
||||
if (sa.usesTargeting() && sa.getTargetRestrictions().getMinTargets(host, sa) == 2) {
|
||||
if (sa.usesTargeting() && sa.getMinTargets() == 2) {
|
||||
if (tgtCards.size() < 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,6 @@ public class CountersPutEffect extends SpellAbilityEffect {
|
||||
protected String getStackDescription(SpellAbility spellAbility) {
|
||||
final StringBuilder stringBuilder = new StringBuilder();
|
||||
final Card card = spellAbility.getHostCard();
|
||||
final boolean dividedAsYouChoose = spellAbility.hasParam("DividedAsYouChoose");
|
||||
|
||||
final int amount = AbilityUtils.calculateAmount(card, spellAbility.getParamOrDefault("CounterNum", "1"), spellAbility);
|
||||
//skip the StringBuilder if no targets are chosen ("up to" scenario)
|
||||
@@ -60,7 +59,7 @@ public class CountersPutEffect extends SpellAbilityEffect {
|
||||
stringBuilder.append("Bolster ").append(amount);
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
if (dividedAsYouChoose) {
|
||||
if (spellAbility.isDividedAsYouChoose()) {
|
||||
stringBuilder.append("Distribute ");
|
||||
} else {
|
||||
stringBuilder.append("Put ");
|
||||
@@ -84,7 +83,7 @@ public class CountersPutEffect extends SpellAbilityEffect {
|
||||
stringBuilder.append("s");
|
||||
}
|
||||
|
||||
if (dividedAsYouChoose) {
|
||||
if (spellAbility.isDividedAsYouChoose()) {
|
||||
stringBuilder.append(" among ");
|
||||
} else {
|
||||
stringBuilder.append(" on ");
|
||||
@@ -96,8 +95,9 @@ public class CountersPutEffect extends SpellAbilityEffect {
|
||||
for(int i = 0; i < targetCards.size(); i++) {
|
||||
Card targetCard = targetCards.get(i);
|
||||
stringBuilder.append(targetCard);
|
||||
if (spellAbility.getTargetRestrictions().getDividedMap().get(targetCard) != null) // fix null counter stack description
|
||||
stringBuilder.append(" (").append(spellAbility.getTargetRestrictions().getDividedMap().get(targetCard)).append(" counter)");
|
||||
Integer v = spellAbility.getDividedValue(targetCard);
|
||||
if (v != null) // fix null counter stack description
|
||||
stringBuilder.append(" (").append(v).append(" counter)");
|
||||
|
||||
if(i == targetCards.size() - 2) {
|
||||
stringBuilder.append(" and ");
|
||||
@@ -259,7 +259,7 @@ public class CountersPutEffect extends SpellAbilityEffect {
|
||||
|
||||
if (obj instanceof Card) {
|
||||
boolean counterAdded = false;
|
||||
counterAmount = sa.usesTargeting() && sa.hasParam("DividedAsYouChoose") ? sa.getTargetRestrictions().getDividedValue(gameCard) : counterAmount;
|
||||
counterAmount = sa.usesTargeting() && sa.isDividedAsYouChoose() ? sa.getDividedValue(gameCard) : counterAmount;
|
||||
if (!sa.usesTargeting() || gameCard.canBeTargetedBy(sa)) {
|
||||
if (max != -1) {
|
||||
counterAmount = Math.max(Math.min(max - gameCard.getCounters(counterType), counterAmount), 0);
|
||||
@@ -270,7 +270,7 @@ public class CountersPutEffect extends SpellAbilityEffect {
|
||||
params.put("CounterType", counterType);
|
||||
counterAmount = pc.chooseNumber(sa, Localizer.getInstance().getMessage("lblHowManyCounters"), 0, counterAmount, params);
|
||||
}
|
||||
if (sa.hasParam("DividedAsYouChoose") && !sa.usesTargeting()) {
|
||||
if (sa.isDividedAsYouChoose() && !sa.usesTargeting()) {
|
||||
Map<String, Object> params = Maps.newHashMap();
|
||||
params.put("Target", obj);
|
||||
params.put("CounterType", counterType);
|
||||
@@ -378,7 +378,7 @@ public class CountersPutEffect extends SpellAbilityEffect {
|
||||
card.addRemembered(gameCard);
|
||||
}
|
||||
game.updateLastStateForCard(gameCard);
|
||||
if (sa.hasParam("DividedAsYouChoose") && !sa.usesTargeting()) {
|
||||
if (sa.isDividedAsYouChoose() && !sa.usesTargeting()) {
|
||||
counterRemain = counterRemain - counterAmount;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ public class DamageDealEffect extends DamageBaseEffect {
|
||||
if (spellAbility.usesTargeting()) {
|
||||
if (spellAbility.hasParam("DivideEvenly")) {
|
||||
stringBuilder.append("divided evenly (rounded down) to\n");
|
||||
} else if (spellAbility.hasParam("DividedAsYouChoose")) {
|
||||
} else if (spellAbility.isDividedAsYouChoose()) {
|
||||
stringBuilder.append("divided to\n");
|
||||
} else
|
||||
stringBuilder.append("to ");
|
||||
@@ -75,8 +75,9 @@ public class DamageDealEffect extends DamageBaseEffect {
|
||||
for (int i = 0; i < targetCards.size(); i++) {
|
||||
Card targetCard = targetCards.get(i);
|
||||
stringBuilder.append(targetCard);
|
||||
if (spellAbility.getTargetRestrictions().getDividedMap().get(targetCard) != null) //fix null damage stack description
|
||||
stringBuilder.append(" (").append(spellAbility.getTargetRestrictions().getDividedMap().get(targetCard)).append(" damage)");
|
||||
Integer v = spellAbility.getDividedValue(targetCard);
|
||||
if (v != null) //fix null damage stack description
|
||||
stringBuilder.append(" (").append(v).append(" damage)");
|
||||
|
||||
if (i == targetCount - 2) {
|
||||
stringBuilder.append(" and ");
|
||||
@@ -89,8 +90,9 @@ public class DamageDealEffect extends DamageBaseEffect {
|
||||
for (int i = 0; i < players.size(); i++) {
|
||||
Player targetPlayer = players.get(i);
|
||||
stringBuilder.append(targetPlayer);
|
||||
if (spellAbility.getTargetRestrictions().getDividedMap().get(targetPlayer) != null) //fix null damage stack description
|
||||
stringBuilder.append(" (").append(spellAbility.getTargetRestrictions().getDividedMap().get(targetPlayer)).append(" damage)");
|
||||
Integer v = spellAbility.getDividedValue(targetPlayer);
|
||||
if (v != null) //fix null damage stack description
|
||||
stringBuilder.append(" (").append(v).append(" damage)");
|
||||
|
||||
if (i == players.size() - 2) {
|
||||
stringBuilder.append(" and ");
|
||||
@@ -102,7 +104,7 @@ public class DamageDealEffect extends DamageBaseEffect {
|
||||
} else {
|
||||
if (spellAbility.hasParam("DivideEvenly")) {
|
||||
stringBuilder.append("divided evenly (rounded down) ");
|
||||
} else if (spellAbility.hasParam("DividedAsYouChoose")) {
|
||||
} else if (spellAbility.isDividedAsYouChoose()) {
|
||||
stringBuilder.append("divided as you choose ");
|
||||
}
|
||||
stringBuilder.append("to ").append(Lang.joinHomogenous(targets));
|
||||
@@ -229,7 +231,7 @@ public class DamageDealEffect extends DamageBaseEffect {
|
||||
|
||||
for (final GameObject o : tgts) {
|
||||
if (!removeDamage) {
|
||||
dmg = (sa.usesTargeting() && sa.hasParam("DividedAsYouChoose")) ? sa.getTargetRestrictions().getDividedValue(o) : dmg;
|
||||
dmg = (sa.usesTargeting() && sa.isDividedAsYouChoose()) ? sa.getDividedValue(o) : dmg;
|
||||
if (dmg <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public class DamagePreventEffect extends SpellAbilityEffect {
|
||||
sb.append("Prevent the next ");
|
||||
sb.append(sa.getParam("Amount"));
|
||||
sb.append(" damage that would be dealt ");
|
||||
if (sa.hasParam("DividedAsYouChoose")) {
|
||||
if (sa.isDividedAsYouChoose()) {
|
||||
sb.append("between ");
|
||||
} else {
|
||||
sb.append("to ");
|
||||
@@ -75,8 +75,8 @@ public class DamagePreventEffect extends SpellAbilityEffect {
|
||||
final boolean targeted = (sa.usesTargeting());
|
||||
final boolean preventionWithEffect = sa.hasParam("PreventionSubAbility");
|
||||
|
||||
for (final Object o : tgts) {
|
||||
numDam = (sa.usesTargeting() && sa.hasParam("DividedAsYouChoose")) ? sa.getTargetRestrictions().getDividedValue(o) : numDam;
|
||||
for (final GameObject o : tgts) {
|
||||
numDam = (sa.usesTargeting() && sa.isDividedAsYouChoose()) ? sa.getDividedValue(o) : numDam;
|
||||
if (o instanceof Card) {
|
||||
final Card c = (Card) o;
|
||||
if (c.isInPlay() && (!targeted || c.canBeTargetedBy(sa))) {
|
||||
|
||||
@@ -58,7 +58,7 @@ public class DelayedTriggerEffect extends SpellAbilityEffect {
|
||||
Card lki = CardUtil.getLKICopy(gameCard);
|
||||
lki.clearControllers();
|
||||
lki.setOwner(sa.getActivatingPlayer());
|
||||
final Trigger delTrig = TriggerHandler.parseTrigger(mapParams, lki, sa.isIntrinsic());
|
||||
final Trigger delTrig = TriggerHandler.parseTrigger(mapParams, lki, sa.isIntrinsic(), null);
|
||||
delTrig.setSpawningAbility(sa.copy(lki, sa.getActivatingPlayer(), true));
|
||||
|
||||
if (triggerRemembered != null) {
|
||||
@@ -81,7 +81,7 @@ public class DelayedTriggerEffect extends SpellAbilityEffect {
|
||||
}
|
||||
}
|
||||
|
||||
if (mapParams.containsKey("Execute") || sa.hasAdditionalAbility("Execute")) {
|
||||
if (sa.hasAdditionalAbility("Execute")) {
|
||||
AbilitySub overridingSA = (AbilitySub)sa.getAdditionalAbility("Execute").copy(lki, sa.getActivatingPlayer(), false);
|
||||
// need to reset the parent, additionalAbility does set it to this
|
||||
overridingSA.setParent(null);
|
||||
@@ -96,7 +96,7 @@ public class DelayedTriggerEffect extends SpellAbilityEffect {
|
||||
|
||||
delTrig.setOverridingAbility(overridingSA);
|
||||
}
|
||||
final TriggerHandler trigHandler = sa.getActivatingPlayer().getGame().getTriggerHandler();
|
||||
final TriggerHandler trigHandler = game.getTriggerHandler();
|
||||
if (mapParams.containsKey("DelayedTriggerDefinedPlayer")) { // on sb's next turn
|
||||
Player p = Iterables.getFirst(AbilityUtils.getDefinedPlayers(sa.getHostCard(), mapParams.get("DelayedTriggerDefinedPlayer"), sa), null);
|
||||
trigHandler.registerPlayerDefinedDelayedTrigger(p, delTrig);
|
||||
|
||||
@@ -189,7 +189,7 @@ public class EffectEffect extends SpellAbilityEffect {
|
||||
for (final String s : effectReplacementEffects) {
|
||||
final String actualReplacement = AbilityUtils.getSVar(sa, s);
|
||||
|
||||
final ReplacementEffect parsedReplacement = ReplacementHandler.parseReplacement(actualReplacement, eff, true);
|
||||
final ReplacementEffect parsedReplacement = ReplacementHandler.parseReplacement(actualReplacement, eff, true, sa);
|
||||
parsedReplacement.setActiveZone(EnumSet.of(ZoneType.Command));
|
||||
parsedReplacement.setIntrinsic(true);
|
||||
eff.addReplacementEffect(parsedReplacement);
|
||||
|
||||
@@ -57,7 +57,7 @@ public class ImmediateTriggerEffect extends SpellAbilityEffect {
|
||||
Card lki = CardUtil.getLKICopy(gameCard);
|
||||
lki.clearControllers();
|
||||
lki.setOwner(sa.getActivatingPlayer());
|
||||
final Trigger immediateTrig = TriggerHandler.parseTrigger(mapParams, lki, sa.isIntrinsic());
|
||||
final Trigger immediateTrig = TriggerHandler.parseTrigger(mapParams, lki, sa.isIntrinsic(), null);
|
||||
immediateTrig.setSpawningAbility(sa.copy(lki, sa.getActivatingPlayer(), true));
|
||||
|
||||
// Need to copy paid costs
|
||||
@@ -74,7 +74,7 @@ public class ImmediateTriggerEffect extends SpellAbilityEffect {
|
||||
}
|
||||
}
|
||||
|
||||
if (mapParams.containsKey("Execute") || sa.hasAdditionalAbility("Execute")) {
|
||||
if (sa.hasAdditionalAbility("Execute")) {
|
||||
AbilitySub overridingSA = (AbilitySub)sa.getAdditionalAbility("Execute").copy(lki, sa.getActivatingPlayer(), false);
|
||||
// need to set Parent to null, otherwise it might have wrong root ability
|
||||
overridingSA.setParent(null);
|
||||
@@ -85,9 +85,8 @@ public class ImmediateTriggerEffect extends SpellAbilityEffect {
|
||||
|
||||
immediateTrig.setOverridingAbility(overridingSA);
|
||||
}
|
||||
final TriggerHandler trigHandler = sa.getActivatingPlayer().getGame().getTriggerHandler();
|
||||
|
||||
// Instead of registering this, add to the delayed triggers as an immediate trigger type? Which means it'll fire as soon as possible
|
||||
trigHandler.registerDelayedTrigger(immediateTrig);
|
||||
game.getTriggerHandler().registerDelayedTrigger(immediateTrig);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ import forge.game.mana.Mana;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.spellability.AbilityManaPart;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.game.spellability.TargetRestrictions;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.util.Localizer;
|
||||
|
||||
@@ -37,7 +36,6 @@ public class ManaEffect extends SpellAbilityEffect {
|
||||
sa.setUndoable(sa.isAbility() && sa.isUndoable());
|
||||
|
||||
final List<Player> tgtPlayers = getTargetPlayers(sa);
|
||||
final TargetRestrictions tgt = sa.getTargetRestrictions();
|
||||
final boolean optional = sa.hasParam("Optional");
|
||||
final Game game = sa.getActivatingPlayer().getGame();
|
||||
|
||||
@@ -45,46 +43,26 @@ public class ManaEffect extends SpellAbilityEffect {
|
||||
return;
|
||||
}
|
||||
|
||||
if (sa.hasParam("DoubleManaInPool")) {
|
||||
for (final Player player : tgtPlayers) {
|
||||
for (byte color : ManaAtom.MANATYPES) {
|
||||
int amountColor = player.getManaPool().getAmountOfColor(color);
|
||||
for (int i = 0; i < amountColor; i++) {
|
||||
abMana.produceMana(MagicColor.toShortString(color), player, sa);
|
||||
}
|
||||
}
|
||||
for (Player p : tgtPlayers) {
|
||||
if (sa.usesTargeting() && !p.canBeTargetedBy(sa)) {
|
||||
// Illegal target. Skip.
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (sa.hasParam("ProduceNoOtherMana")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (abMana.isComboMana()) {
|
||||
for (Player p : tgtPlayers) {
|
||||
if (abMana.isComboMana()) {
|
||||
int amount = sa.hasParam("Amount") ? AbilityUtils.calculateAmount(card, sa.getParam("Amount"), sa) : 1;
|
||||
if (tgt != null && !p.canBeTargetedBy(sa)) {
|
||||
// Illegal target. Skip.
|
||||
continue;
|
||||
}
|
||||
|
||||
Player activator = sa.getActivatingPlayer();
|
||||
String express = abMana.getExpressChoice();
|
||||
String[] colorsProduced = abMana.getComboColors().split(" ");
|
||||
|
||||
final StringBuilder choiceString = new StringBuilder();
|
||||
ColorSet colorOptions = null;
|
||||
ColorSet colorOptions = ColorSet.fromNames(colorsProduced);
|
||||
String[] colorsNeeded = express.isEmpty() ? null : express.split(" ");
|
||||
if (!abMana.isAnyMana()) {
|
||||
colorOptions = ColorSet.fromNames(colorsProduced);
|
||||
} else {
|
||||
colorOptions = ColorSet.fromNames(MagicColor.Constant.ONLY_COLORS);
|
||||
}
|
||||
boolean differentChoice = abMana.getOrigProduced().contains("Different");
|
||||
ColorSet fullOptions = colorOptions;
|
||||
for (int nMana = 0; nMana < amount; nMana++) {
|
||||
String choice = "";
|
||||
if (colorsNeeded != null && colorsNeeded.length > nMana) { // select from express choices if possible
|
||||
if (colorsNeeded != null && colorsNeeded.length > nMana) { // select from express choices if possible
|
||||
colorOptions = ColorSet
|
||||
.fromMask(fullOptions.getColor() & ManaAtom.fromName(colorsNeeded[nMana]));
|
||||
}
|
||||
@@ -93,10 +71,10 @@ public class ManaEffect extends SpellAbilityEffect {
|
||||
// just use the first possible color.
|
||||
choice = colorsProduced[differentChoice ? nMana : 0];
|
||||
} else {
|
||||
byte chosenColor = activator.getController().chooseColor(Localizer.getInstance().getMessage("lblSelectManaProduce"), sa,
|
||||
byte chosenColor = p.getController().chooseColor(Localizer.getInstance().getMessage("lblSelectManaProduce"), sa,
|
||||
differentChoice ? fullOptions : colorOptions);
|
||||
if (chosenColor == 0)
|
||||
throw new RuntimeException("ManaEffect::resolve() /*combo mana*/ - " + activator + " color mana choice is empty for " + card.getName());
|
||||
throw new RuntimeException("ManaEffect::resolve() /*combo mana*/ - " + p + " color mana choice is empty for " + card.getName());
|
||||
|
||||
fullOptions = ColorSet.fromMask(fullOptions.getMyColor() - chosenColor);
|
||||
choice = MagicColor.toShortString(chosenColor);
|
||||
@@ -116,18 +94,10 @@ public class ManaEffect extends SpellAbilityEffect {
|
||||
return;
|
||||
}
|
||||
|
||||
game.action.nofityOfValue(sa, card, Localizer.getInstance().getMessage("lblPlayerPickedChosen", activator.getName(), choiceString), activator);
|
||||
game.getAction().nofityOfValue(sa, card, Localizer.getInstance().getMessage("lblPlayerPickedChosen", p.getName(), choiceString), p);
|
||||
abMana.setExpressChoice(choiceString.toString());
|
||||
}
|
||||
}
|
||||
else if (abMana.isAnyMana()) {
|
||||
for (Player p : tgtPlayers) {
|
||||
if (tgt != null && !p.canBeTargetedBy(sa)) {
|
||||
// Illegal target. Skip.
|
||||
continue;
|
||||
}
|
||||
|
||||
Player act = sa.getActivatingPlayer();
|
||||
else if (abMana.isAnyMana()) {
|
||||
// AI color choice is set in ComputerUtils so only human players need to make a choice
|
||||
|
||||
String colorsNeeded = abMana.getExpressChoice();
|
||||
@@ -142,20 +112,14 @@ public class ManaEffect extends SpellAbilityEffect {
|
||||
colorMenu = mask == 0 ? ColorSet.ALL_COLORS : ColorSet.fromMask(mask);
|
||||
byte val = p.getController().chooseColor(Localizer.getInstance().getMessage("lblSelectManaProduce"), sa, colorMenu);
|
||||
if (0 == val) {
|
||||
throw new RuntimeException("ManaEffect::resolve() /*any mana*/ - " + act + " color mana choice is empty for " + card.getName());
|
||||
throw new RuntimeException("ManaEffect::resolve() /*any mana*/ - " + p + " color mana choice is empty for " + card.getName());
|
||||
}
|
||||
choice = MagicColor.toShortString(val);
|
||||
|
||||
game.action.nofityOfValue(sa, card, Localizer.getInstance().getMessage("lblPlayerPickedChosen", act.getName(), choice), act);
|
||||
game.getAction().nofityOfValue(sa, card, Localizer.getInstance().getMessage("lblPlayerPickedChosen", p.getName(), choice), p);
|
||||
abMana.setExpressChoice(choice);
|
||||
}
|
||||
}
|
||||
else if (abMana.isSpecialMana()) {
|
||||
for (Player p : tgtPlayers) {
|
||||
if (tgt != null && !p.canBeTargetedBy(sa)) {
|
||||
// Illegal target. Skip.
|
||||
continue;
|
||||
}
|
||||
else if (abMana.isSpecialMana()) {
|
||||
|
||||
String type = abMana.getOrigProduced().split("Special ")[1];
|
||||
|
||||
@@ -177,7 +141,7 @@ public class ManaEffect extends SpellAbilityEffect {
|
||||
if (cs.isMonoColor())
|
||||
sb.append(MagicColor.toShortString(s.getColorMask()));
|
||||
else /* (cs.isMulticolor()) */ {
|
||||
byte chosenColor = sa.getActivatingPlayer().getController().chooseColor(Localizer.getInstance().getMessage("lblChooseSingleColorFromTarget", s.toString()), sa, cs);
|
||||
byte chosenColor = p.getController().chooseColor(Localizer.getInstance().getMessage("lblChooseSingleColorFromTarget", s.toString()), sa, cs);
|
||||
sb.append(MagicColor.toShortString(chosenColor));
|
||||
}
|
||||
}
|
||||
@@ -210,34 +174,36 @@ public class ManaEffect extends SpellAbilityEffect {
|
||||
abMana.setExpressChoice(ColorSet.fromMask(colors));
|
||||
} else if (type.startsWith("EachColoredManaSymbol")) {
|
||||
final String res = type.split("_")[1];
|
||||
final CardCollection list = AbilityUtils.getDefinedCards(card, res, sa);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Card c : list) {
|
||||
String mana = c.getManaCost().toString();
|
||||
for (int i = 0; i < mana.length(); i++) {
|
||||
char symbol = mana.charAt(i);
|
||||
switch (symbol) {
|
||||
case 'W':
|
||||
case 'U':
|
||||
case 'B':
|
||||
case 'R':
|
||||
case 'G':
|
||||
sb.append(symbol).append(' ');
|
||||
break;
|
||||
for (Card c : AbilityUtils.getDefinedCards(card, res, sa)) {
|
||||
for (ManaCostShard s : c.getManaCost()) {
|
||||
ColorSet cs = ColorSet.fromMask(s.getColorMask());
|
||||
if(cs.isColorless())
|
||||
continue;
|
||||
sb.append(' ');
|
||||
if (cs.isMonoColor())
|
||||
sb.append(MagicColor.toShortString(s.getColorMask()));
|
||||
else /* (cs.isMulticolor()) */ {
|
||||
byte chosenColor = p.getController().chooseColor(Localizer.getInstance().getMessage("lblChooseSingleColorFromTarget", s.toString()), sa, cs);
|
||||
sb.append(MagicColor.toShortString(chosenColor));
|
||||
}
|
||||
}
|
||||
}
|
||||
abMana.setExpressChoice(sb.toString().trim());
|
||||
} else if (type.startsWith("DoubleManaInPool")) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (byte color : ManaAtom.MANATYPES) {
|
||||
sb.append(StringUtils.repeat(MagicColor.toShortString(color), " ", p.getManaPool().getAmountOfColor(color))).append(" ");
|
||||
}
|
||||
abMana.setExpressChoice(sb.toString().trim());
|
||||
}
|
||||
|
||||
if (abMana.getExpressChoice().isEmpty()) {
|
||||
System.out.println("AbilityFactoryMana::manaResolve() - special mana effect is empty for " + sa.getHostCard().getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (final Player player : tgtPlayers) {
|
||||
abMana.produceMana(GameActionUtil.generatedMana(sa), player, sa);
|
||||
abMana.produceMana(GameActionUtil.generatedMana(sa), p, sa);
|
||||
}
|
||||
|
||||
// Only clear express choice after mana has been produced
|
||||
|
||||
@@ -11,7 +11,6 @@ import forge.game.spellability.SpellAbility;
|
||||
import forge.util.Localizer;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
@@ -29,8 +28,7 @@ public class ManaReflectedEffect extends SpellAbilityEffect {
|
||||
|
||||
final Collection<String> colors = CardUtil.getReflectableManaColors(sa);
|
||||
|
||||
final List<Player> tgtPlayers = getTargetPlayers(sa);
|
||||
for (final Player player : tgtPlayers) {
|
||||
for (final Player player : getTargetPlayers(sa)) {
|
||||
final String generated = generatedReflectedMana(sa, colors, player);
|
||||
ma.produceMana(generated, player, sa);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package forge.game.ability.effects;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -149,14 +148,13 @@ public class PlayEffect extends SpellAbilityEffect {
|
||||
|
||||
if (sa.hasParam("ValidSA")) {
|
||||
final String valid[] = {sa.getParam("ValidSA")};
|
||||
final Iterator<Card> itr = tgtCards.iterator();
|
||||
while (itr.hasNext()) {
|
||||
final Card c = itr.next();
|
||||
final List<SpellAbility> validSA = Lists.newArrayList(Iterables.filter(AbilityUtils.getBasicSpellsFromPlayEffect(c, controller), SpellAbilityPredicates.isValid(valid, controller , c, sa)));
|
||||
if (validSA.size() == 0) {
|
||||
itr.remove();
|
||||
List<Card> toRemove = Lists.newArrayList();
|
||||
for (Card c : tgtCards) {
|
||||
if (!Iterables.any(AbilityUtils.getBasicSpellsFromPlayEffect(c, controller), SpellAbilityPredicates.isValid(valid, controller , c, sa))) {
|
||||
toRemove.add(c);
|
||||
}
|
||||
}
|
||||
tgtCards.removeAll(toRemove);
|
||||
if (tgtCards.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
@@ -260,13 +258,8 @@ public class PlayEffect extends SpellAbilityEffect {
|
||||
continue;
|
||||
}
|
||||
|
||||
final boolean noManaCost = sa.hasParam("WithoutManaCost");
|
||||
if (noManaCost) {
|
||||
if (sa.hasParam("WithoutManaCost")) {
|
||||
tgtSA = tgtSA.copyWithNoManaCost();
|
||||
// FIXME: a hack to get cards like Detonate only allow legal targets when cast without paying mana cost (with X=0).
|
||||
if (tgtSA.hasParam("ValidTgtsWithoutManaCost")) {
|
||||
tgtSA.getTargetRestrictions().changeValidTargets(tgtSA.getParam("ValidTgtsWithoutManaCost").split(","));
|
||||
}
|
||||
} else if (sa.hasParam("PlayCost")) {
|
||||
Cost abCost;
|
||||
if ("ManaCost".equals(sa.getParam("PlayCost"))) {
|
||||
|
||||
@@ -6,12 +6,14 @@ import forge.game.ability.AbilityKey;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import forge.game.Game;
|
||||
import forge.game.GameLogEntryType;
|
||||
import forge.game.ability.AbilityUtils;
|
||||
import forge.game.ability.SpellAbilityEffect;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.replacement.ReplacementResult;
|
||||
import forge.game.replacement.ReplacementType;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.util.TextUtil;
|
||||
|
||||
public class ReplaceDamageEffect extends SpellAbilityEffect {
|
||||
|
||||
@@ -58,6 +60,12 @@ public class ReplaceDamageEffect extends SpellAbilityEffect {
|
||||
}
|
||||
params.put(AbilityKey.DamageAmount, dmg);
|
||||
|
||||
// need to log Updated events there, or the log is wrong order
|
||||
String message = sa.getReplacementEffect().toString();
|
||||
if ( !StringUtils.isEmpty(message)) {
|
||||
message = TextUtil.fastReplace(message, "CARDNAME", card.getName());
|
||||
game.getGameLog().add(GameLogEntryType.EFFECT_REPLACED, message);
|
||||
}
|
||||
|
||||
//try to call replacementHandler with new Params
|
||||
ReplacementResult result = game.getReplacementHandler().run(event, params);
|
||||
|
||||
@@ -3,9 +3,12 @@ package forge.game.ability.effects;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import forge.game.Game;
|
||||
import forge.game.GameLogEntryType;
|
||||
import forge.game.GameObject;
|
||||
import forge.game.ability.AbilityKey;
|
||||
import forge.game.ability.AbilityUtils;
|
||||
@@ -16,6 +19,7 @@ import forge.game.player.Player;
|
||||
import forge.game.replacement.ReplacementResult;
|
||||
import forge.game.replacement.ReplacementType;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.util.TextUtil;
|
||||
|
||||
public class ReplaceEffect extends SpellAbilityEffect {
|
||||
|
||||
@@ -61,6 +65,13 @@ public class ReplaceEffect extends SpellAbilityEffect {
|
||||
params.put(AbilityKey.EffectOnly, true);
|
||||
}
|
||||
|
||||
// need to log Updated events there, or the log is wrong order
|
||||
String message = sa.getReplacementEffect().toString();
|
||||
if ( !StringUtils.isEmpty(message)) {
|
||||
message = TextUtil.fastReplace(message, "CARDNAME", card.getName());
|
||||
game.getGameLog().add(GameLogEntryType.EFFECT_REPLACED, message);
|
||||
}
|
||||
|
||||
//try to call replacementHandler with new Params
|
||||
ReplacementResult result = game.getReplacementHandler().run(retype, params);
|
||||
switch (result) {
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
package forge.game.ability.effects;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import forge.card.ColorSet;
|
||||
import forge.card.MagicColor;
|
||||
import forge.game.Game;
|
||||
import forge.game.GameLogEntryType;
|
||||
import forge.game.ability.AbilityKey;
|
||||
import forge.game.ability.SpellAbilityEffect;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.replacement.ReplacementResult;
|
||||
import forge.game.replacement.ReplacementType;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.util.TextUtil;
|
||||
|
||||
public class ReplaceManaEffect extends SpellAbilityEffect {
|
||||
|
||||
@Override
|
||||
public void resolve(SpellAbility sa) {
|
||||
final Card card = sa.getHostCard();
|
||||
final Player player = sa.getActivatingPlayer();
|
||||
final Game game = card.getGame();
|
||||
|
||||
// outside of Replacement Effect, unwanted result
|
||||
if (!sa.isReplacementAbility()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final ReplacementType event = sa.getReplacementEffect().getMode();
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<AbilityKey, Object> originalParams = (Map<AbilityKey, Object>) sa.getReplacingObject(AbilityKey.OriginalParams);
|
||||
Map<AbilityKey, Object> params = Maps.newHashMap(originalParams);
|
||||
|
||||
String replaced = (String)sa.getReplacingObject(AbilityKey.Mana);
|
||||
if (sa.hasParam("ReplaceMana")) {
|
||||
// replace type and amount
|
||||
replaced = sa.getParam("ReplaceMana");
|
||||
if ("Any".equals(replaced)) {
|
||||
byte rs = MagicColor.GREEN;
|
||||
rs = player.getController().chooseColor("Choose a color", sa, ColorSet.ALL_COLORS);
|
||||
replaced = MagicColor.toShortString(rs);
|
||||
}
|
||||
} else if (sa.hasParam("ReplaceType")) {
|
||||
// replace color and colorless
|
||||
String color = sa.getParam("ReplaceType");
|
||||
if ("Any".equals(color)) {
|
||||
byte rs = MagicColor.GREEN;
|
||||
rs = player.getController().chooseColor("Choose a color", sa, ColorSet.ALL_COLORS);
|
||||
color = MagicColor.toShortString(rs);
|
||||
}
|
||||
for (byte c : MagicColor.WUBRGC) {
|
||||
String s = MagicColor.toShortString(c);
|
||||
replaced = replaced.replace(s, color);
|
||||
}
|
||||
} else if (sa.hasParam("ReplaceColor")) {
|
||||
// replace color
|
||||
String color = sa.getParam("ReplaceColor");
|
||||
if ("Chosen".equals(color)) {
|
||||
if (card.hasChosenColor()) {
|
||||
color = MagicColor.toShortString(card.getChosenColor());
|
||||
}
|
||||
}
|
||||
if (sa.hasParam("ReplaceOnly")) {
|
||||
replaced = replaced.replace(sa.getParam("ReplaceOnly"), color);
|
||||
} else {
|
||||
for (byte c : MagicColor.WUBRG) {
|
||||
String s = MagicColor.toShortString(c);
|
||||
replaced = replaced.replace(s, color);
|
||||
}
|
||||
}
|
||||
} else if (sa.hasParam("ReplaceAmount")) {
|
||||
// replace amount = multiples
|
||||
replaced = StringUtils.repeat(replaced, " ", Integer.valueOf(sa.getParam("ReplaceAmount")));
|
||||
}
|
||||
params.put(AbilityKey.Mana, replaced);
|
||||
|
||||
// need to log Updated events there, or the log is wrong order
|
||||
String message = sa.getReplacementEffect().toString();
|
||||
if ( !StringUtils.isEmpty(message)) {
|
||||
message = TextUtil.fastReplace(message, "CARDNAME", card.getName());
|
||||
game.getGameLog().add(GameLogEntryType.EFFECT_REPLACED, message);
|
||||
}
|
||||
|
||||
//try to call replacementHandler with new Params
|
||||
ReplacementResult result = game.getReplacementHandler().run(event, params);
|
||||
switch (result) {
|
||||
case NotReplaced:
|
||||
case Updated: {
|
||||
for (Map.Entry<AbilityKey, Object> e : params.entrySet()) {
|
||||
originalParams.put(e.getKey(), e.getValue());
|
||||
}
|
||||
// effect was updated
|
||||
originalParams.put(AbilityKey.ReplacementResult, ReplacementResult.Updated);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// effect was replaced with something else
|
||||
originalParams.put(AbilityKey.ReplacementResult, result);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -53,7 +53,7 @@ public class ReplaceSplitDamageEffect extends SpellAbilityEffect {
|
||||
if (card.getType().hasStringType("Effect") && prevent <= 0) {
|
||||
game.getAction().exile(card, null);
|
||||
} else if (!StringUtils.isNumeric(varValue)) {
|
||||
card.setSVar(varValue, "Number$" + prevent);
|
||||
sa.setSVar(varValue, "Number$" + prevent);
|
||||
}
|
||||
|
||||
Card sourceLKI = (Card) sa.getReplacingObject(AbilityKey.Source);
|
||||
|
||||
@@ -625,10 +625,6 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
|
||||
|
||||
public Card manifest(Player p, SpellAbility sa) {
|
||||
// Turn Face Down (even if it's DFC).
|
||||
ManaCost cost = getState(CardStateName.Original).getManaCost();
|
||||
|
||||
boolean isCreature = isCreature();
|
||||
|
||||
// Sometimes cards are manifested while already being face down
|
||||
if (!turnFaceDown(true) && !isFaceDown()) {
|
||||
return null;
|
||||
@@ -643,11 +639,9 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
|
||||
setManifested(true);
|
||||
|
||||
Card c = game.getAction().moveToPlay(this, p, sa);
|
||||
|
||||
// Add manifest demorph static ability for creatures
|
||||
if (c.isManifested() && isCreature && !cost.isNoCost()) {
|
||||
// Add Manifest to original State
|
||||
c.getState(CardStateName.Original).addSpellAbility(CardFactoryUtil.abilityManifestFaceUp(c, cost));
|
||||
if (c.isInPlay()) {
|
||||
c.setManifested(true);
|
||||
c.turnFaceDown(true);
|
||||
c.updateStateForView();
|
||||
}
|
||||
|
||||
@@ -2491,7 +2485,7 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
|
||||
if (ab.getApi() == ApiType.ManaReflected) {
|
||||
colors.addAll(CardUtil.getReflectableManaColors(ab));
|
||||
} else {
|
||||
colors = CardUtil.canProduce(6, ab.getManaPart(), colors);
|
||||
colors = CardUtil.canProduce(6, ab, colors);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2502,7 +2496,7 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (mana.getManaPart().canProduce(MagicColor.toShortString(s))) {
|
||||
if (mana.canProduce(MagicColor.toShortString(s))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -5450,15 +5444,6 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
|
||||
// Note: This should only be called after state has been set to CardStateName.FaceDown,
|
||||
// so the below call should be valid since the state should have been created already.
|
||||
getState(CardStateName.FaceDown).setImageKey(ImageKeys.getTokenKey(image));
|
||||
if (!manifested) {
|
||||
// remove Manifest Up abilities from Original State
|
||||
CardState original = getState(CardStateName.Original);
|
||||
for (SpellAbility sa : original.getNonManaAbilities()) {
|
||||
if (sa.isManifestUp()) {
|
||||
original.removeSpellAbility(sa);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final boolean isForetold() {
|
||||
@@ -6090,21 +6075,20 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
|
||||
|
||||
public boolean hasETBTrigger(final boolean drawbackOnly) {
|
||||
for (final Trigger tr : getTriggers()) {
|
||||
final Map<String, String> params = tr.getMapParams();
|
||||
if (tr.getMode() != TriggerType.ChangesZone) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!params.get("Destination").equals(ZoneType.Battlefield.toString())) {
|
||||
if (!tr.getParam("Destination").equals(ZoneType.Battlefield.toString())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (params.containsKey("ValidCard") && !params.get("ValidCard").contains("Self")) {
|
||||
if (tr.hasParam("ValidCard") && !tr.getParam("ValidCard").contains("Self")) {
|
||||
continue;
|
||||
}
|
||||
if (drawbackOnly && params.containsKey("Execute")){
|
||||
String exec = this.getSVar(params.get("Execute"));
|
||||
if (exec.contains("AB$")) {
|
||||
if (drawbackOnly) {
|
||||
SpellAbility sa = tr.ensureAbility();
|
||||
if (sa == null || sa.isActivatedAbility()) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -6332,6 +6316,14 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
|
||||
}
|
||||
}
|
||||
|
||||
if (isInPlay() && isFaceDown() && isManifested()) {
|
||||
CardState oState = getState(CardStateName.Original);
|
||||
ManaCost cost = oState.getManaCost();
|
||||
if (oState.getType().isCreature()) {
|
||||
abilities.add(CardFactoryUtil.abilityManifestFaceUp(this, cost));
|
||||
}
|
||||
}
|
||||
|
||||
final Collection<SpellAbility> toRemove = Lists.newArrayListWithCapacity(abilities.size());
|
||||
for (final SpellAbility sa : abilities) {
|
||||
sa.setActivatingPlayer(player);
|
||||
|
||||
@@ -117,10 +117,9 @@ public class CardFactory {
|
||||
* which wouldn't ordinarily get set during a simple Card.copy() call.
|
||||
* </p>
|
||||
* */
|
||||
private final static Card copySpellHost(final SpellAbility sourceSA, final SpellAbility targetSA){
|
||||
private final static Card copySpellHost(final SpellAbility sourceSA, final SpellAbility targetSA, Player controller) {
|
||||
final Card source = sourceSA.getHostCard();
|
||||
final Card original = targetSA.getHostCard();
|
||||
Player controller = sourceSA.getActivatingPlayer();
|
||||
final Card c = copyCard(original, true);
|
||||
|
||||
// change the color of the copy (eg: Fork)
|
||||
@@ -168,17 +167,15 @@ public class CardFactory {
|
||||
* @param bCopyDetails
|
||||
* a boolean.
|
||||
*/
|
||||
public final static SpellAbility copySpellAbilityAndPossiblyHost(final SpellAbility sourceSA, final SpellAbility targetSA) {
|
||||
Player controller = sourceSA.getActivatingPlayer();
|
||||
|
||||
public final static SpellAbility copySpellAbilityAndPossiblyHost(final SpellAbility sourceSA, final SpellAbility targetSA, final Player controller) {
|
||||
//it is only necessary to copy the host card if the SpellAbility is a spell, not an ability
|
||||
final Card c = targetSA.isSpell() ? copySpellHost(sourceSA, targetSA) : targetSA.getHostCard();
|
||||
final Card c = targetSA.isSpell() ? copySpellHost(sourceSA, targetSA, controller) : targetSA.getHostCard();
|
||||
|
||||
final SpellAbility copySA;
|
||||
if (targetSA.isTrigger() && targetSA.isWrapper()) {
|
||||
copySA = getCopiedTriggeredAbility((WrappedAbility)targetSA, c);
|
||||
copySA = getCopiedTriggeredAbility((WrappedAbility)targetSA, c, controller);
|
||||
} else {
|
||||
copySA = targetSA.copy(c, false);
|
||||
copySA = targetSA.copy(c, controller, false);
|
||||
}
|
||||
|
||||
copySA.setCopied(true);
|
||||
@@ -361,12 +358,12 @@ public class CardFactory {
|
||||
// Name first so Senty has the Card name
|
||||
c.setName(face.getName());
|
||||
|
||||
for (Entry<String, String> v : face.getVariables()) c.setSVar(v.getKey(), v.getValue());
|
||||
|
||||
for (String r : face.getReplacements()) c.addReplacementEffect(ReplacementHandler.parseReplacement(r, c, true));
|
||||
for (String s : face.getStaticAbilities()) c.addStaticAbility(s);
|
||||
for (String t : face.getTriggers()) c.addTrigger(TriggerHandler.parseTrigger(t, c, true));
|
||||
|
||||
for (Entry<String, String> v : face.getVariables()) c.setSVar(v.getKey(), v.getValue());
|
||||
|
||||
// keywords not before variables
|
||||
c.addIntrinsicKeywords(face.getKeywords(), false);
|
||||
|
||||
@@ -555,12 +552,12 @@ public class CardFactory {
|
||||
*
|
||||
* return a wrapped ability
|
||||
*/
|
||||
public static SpellAbility getCopiedTriggeredAbility(final WrappedAbility sa, final Card newHost) {
|
||||
public static SpellAbility getCopiedTriggeredAbility(final WrappedAbility sa, final Card newHost, final Player controller) {
|
||||
if (!sa.isTrigger()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new WrappedAbility(sa.getTrigger(), sa.getWrappedAbility().copy(newHost, false), sa.getDecider());
|
||||
return new WrappedAbility(sa.getTrigger(), sa.getWrappedAbility().copy(newHost, controller, false), controller);
|
||||
}
|
||||
|
||||
public static CardCloneStates getCloneStates(final Card in, final Card out, final CardTraitBase sa) {
|
||||
@@ -667,6 +664,7 @@ public class CardFactory {
|
||||
if (origSVars.containsKey(s)) {
|
||||
final String actualTrigger = origSVars.get(s);
|
||||
final Trigger parsedTrigger = TriggerHandler.parseTrigger(actualTrigger, out, true);
|
||||
parsedTrigger.setOriginalHost(host);
|
||||
state.addTrigger(parsedTrigger);
|
||||
}
|
||||
}
|
||||
@@ -690,6 +688,7 @@ public class CardFactory {
|
||||
if (origSVars.containsKey(s)) {
|
||||
final String actualAbility = origSVars.get(s);
|
||||
final SpellAbility grantedAbility = AbilityFactory.getAbility(actualAbility, out);
|
||||
grantedAbility.setOriginalHost(host);
|
||||
grantedAbility.setIntrinsic(true);
|
||||
state.addSpellAbility(grantedAbility);
|
||||
}
|
||||
@@ -703,6 +702,7 @@ public class CardFactory {
|
||||
if (origSVars.containsKey(s)) {
|
||||
final String actualStatic = origSVars.get(s);
|
||||
final StaticAbility grantedStatic = new StaticAbility(actualStatic, out);
|
||||
grantedStatic.setOriginalHost(host);
|
||||
grantedStatic.setIntrinsic(true);
|
||||
state.addStaticAbility(grantedStatic);
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ public class CardFactoryUtil {
|
||||
// Cost need to be set later
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("ST$ SetState | Cost$ 0 | CostDesc$ Unmanifest ").append(costDesc);
|
||||
sb.append(" | ManifestUp$ True | Secondary$ True | IsPresent$ Card.Self+faceDown+manifested");
|
||||
sb.append(" | ManifestUp$ True | Secondary$ True | PresentDefined$ Self | IsPresent$ Card.faceDown+manifested");
|
||||
sb.append(" | Mode$ TurnFace | SpellDescription$ (Turn this face up any time for its mana cost.)");
|
||||
|
||||
final SpellAbility manifestUp = AbilityFactory.getAbility(sb.toString(), sourceCard);
|
||||
@@ -1478,7 +1478,7 @@ public class CardFactoryUtil {
|
||||
for (Card card : otb) {
|
||||
if (!card.isTapped() || !untappedOnly) {
|
||||
for (SpellAbility ma : card.getManaAbilities()) {
|
||||
if (ma.getManaPart().canProduce(MagicColor.toShortString(color))) {
|
||||
if (ma.canProduce(MagicColor.toShortString(color))) {
|
||||
uniqueColors++;
|
||||
continue outer;
|
||||
}
|
||||
@@ -2230,7 +2230,7 @@ public class CardFactoryUtil {
|
||||
final String abStringAfflict = "DB$ LoseLife | Defined$ TriggeredDefendingPlayer" +
|
||||
" | LifeAmount$ " + n;
|
||||
|
||||
final Trigger afflictTrigger = TriggerHandler.parseTrigger(trigStr, card, intrinsic);
|
||||
final Trigger afflictTrigger = TriggerHandler.parseTrigger(trigStr, card, intrinsic, null);
|
||||
afflictTrigger.setOverridingAbility(AbilityFactory.getAbility(abStringAfflict, card));
|
||||
|
||||
inst.addTrigger(afflictTrigger);
|
||||
|
||||
@@ -648,9 +648,10 @@ public class CardProperty {
|
||||
return false;
|
||||
}
|
||||
} else if (property.startsWith("DamagedBy")) {
|
||||
if ((property.endsWith("Source") || property.equals("DamagedBy")) &&
|
||||
!card.getReceivedDamageFromThisTurn().containsKey(source)) {
|
||||
return false;
|
||||
if (property.endsWith("Source") || property.equals("DamagedBy")) {
|
||||
if (!card.getReceivedDamageFromThisTurn().containsKey(source)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
String prop = property.substring("DamagedBy".length());
|
||||
|
||||
@@ -911,7 +912,7 @@ public class CardProperty {
|
||||
} else if (property.startsWith("canProduceManaColor")) {
|
||||
final String color = property.split("canProduceManaColor ")[1];
|
||||
for (SpellAbility ma : card.getManaAbilities()) {
|
||||
if (ma.getManaPart().canProduce(MagicColor.toShortString(color))) {
|
||||
if (ma.canProduce(MagicColor.toShortString(color))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -391,7 +391,6 @@ public final class CardUtil {
|
||||
|
||||
final String colorOrType = sa.getParam("ColorOrType");
|
||||
// currently Color or Type, Type is colors + colorless
|
||||
final String validCard = sa.getParam("Valid");
|
||||
final String reflectProperty = sa.getParam("ReflectProperty");
|
||||
// Produce (Reflecting Pool) or Is (Meteor Crater)
|
||||
|
||||
@@ -400,28 +399,30 @@ public final class CardUtil {
|
||||
maxChoices++;
|
||||
}
|
||||
|
||||
CardCollection cards = null;
|
||||
CardCollection cards;
|
||||
|
||||
// Reuse AF_Defined in a slightly different way
|
||||
if (validCard.startsWith("Defined.")) {
|
||||
cards = AbilityUtils.getDefinedCards(card, TextUtil.fastReplace(validCard, "Defined.", ""), abMana);
|
||||
} else {
|
||||
if (sa.getActivatingPlayer() == null) {
|
||||
sa.setActivatingPlayer(sa.getHostCard().getController());
|
||||
if (sa.hasParam("Valid")) {
|
||||
final String validCard = sa.getParam("Valid");
|
||||
// Reuse AF_Defined in a slightly different way
|
||||
if (validCard.startsWith("Defined.")) {
|
||||
cards = AbilityUtils.getDefinedCards(card, TextUtil.fastReplace(validCard, "Defined.", ""), abMana);
|
||||
} else {
|
||||
if (sa.getActivatingPlayer() == null) {
|
||||
sa.setActivatingPlayer(sa.getHostCard().getController());
|
||||
}
|
||||
final Game game = sa.getActivatingPlayer().getGame();
|
||||
cards = CardLists.getValidCards(game.getCardsIn(ZoneType.Battlefield), validCard, abMana.getActivatingPlayer(), card);
|
||||
}
|
||||
final Game game = sa.getActivatingPlayer().getGame();
|
||||
cards = CardLists.getValidCards(game.getCardsIn(ZoneType.Battlefield), validCard, abMana.getActivatingPlayer(), card);
|
||||
}
|
||||
|
||||
// remove anything cards that is already in parents
|
||||
for (final Card p : parents) {
|
||||
cards.remove(p);
|
||||
}
|
||||
// remove anything cards that is already in parents
|
||||
cards.removeAll(parents);
|
||||
|
||||
if ((cards.size() == 0) && !reflectProperty.equals("Produced")) {
|
||||
return colors;
|
||||
if (cards.isEmpty()) {
|
||||
return colors;
|
||||
}
|
||||
} else {
|
||||
cards = new CardCollection();
|
||||
}
|
||||
|
||||
if (reflectProperty.equals("Is")) { // Meteor Crater
|
||||
for (final Card card1 : cards) {
|
||||
// For each card, go through all the colors and if the card is that color, add
|
||||
@@ -436,7 +437,7 @@ public final class CardUtil {
|
||||
}
|
||||
} else if (reflectProperty.equals("Produced")) {
|
||||
// Why is this name so similar to the one below?
|
||||
final String producedColors = abMana instanceof AbilitySub ? (String) abMana.getRootAbility().getTriggeringObject(AbilityKey.Produced) : (String) abMana.getTriggeringObject(AbilityKey.Produced);
|
||||
final String producedColors = (String) abMana.getRootAbility().getTriggeringObject(AbilityKey.Produced);
|
||||
for (final String col : MagicColor.Constant.ONLY_COLORS) {
|
||||
final String s = MagicColor.toShortString(col);
|
||||
if (producedColors.contains(s)) {
|
||||
@@ -469,7 +470,7 @@ public final class CardUtil {
|
||||
}
|
||||
continue;
|
||||
}
|
||||
colors = canProduce(maxChoices, ab.getManaPart(), colors);
|
||||
colors = canProduce(maxChoices, ab, colors);
|
||||
if (!parents.contains(ab.getHostCard())) {
|
||||
parents.add(ab.getHostCard());
|
||||
}
|
||||
@@ -486,19 +487,18 @@ public final class CardUtil {
|
||||
return colors;
|
||||
}
|
||||
|
||||
public static Set<String> canProduce(final int maxChoices, final AbilityManaPart ab,
|
||||
public static Set<String> canProduce(final int maxChoices, final SpellAbility sa,
|
||||
final Set<String> colors) {
|
||||
if (ab == null) {
|
||||
if (sa == null) {
|
||||
return colors;
|
||||
}
|
||||
for (final String col : MagicColor.Constant.ONLY_COLORS) {
|
||||
final String s = MagicColor.toShortString(col);
|
||||
if (ab.canProduce(s)) {
|
||||
if (sa.canProduce(MagicColor.toShortString(col))) {
|
||||
colors.add(col);
|
||||
}
|
||||
}
|
||||
|
||||
if (maxChoices == 6 && ab.canProduce("C")) {
|
||||
if (maxChoices == 6 && sa.canProduce("C")) {
|
||||
colors.add(MagicColor.Constant.COLORLESS);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ package forge.game.mana;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import forge.card.ColorSet;
|
||||
import forge.card.MagicColor;
|
||||
import forge.card.mana.IParserManaCost;
|
||||
@@ -105,11 +107,16 @@ public class ManaCostBeingPaid {
|
||||
xCount = copy.xCount;
|
||||
totalCount = copy.totalCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{x=" + xCount + " total=" + totalCount + "}";
|
||||
}
|
||||
}
|
||||
|
||||
// holds Mana_Part objects
|
||||
// ManaPartColor is stored before ManaPartGeneric
|
||||
private final Map<ManaCostShard, ShardCount> unpaidShards = new HashMap<>();
|
||||
private final Map<ManaCostShard, ShardCount> unpaidShards = Maps.newHashMap();
|
||||
private Map<String, Integer> xManaCostPaidByColor;
|
||||
private final String sourceRestriction;
|
||||
private byte sunburstMap = 0;
|
||||
@@ -124,7 +131,7 @@ public class ManaCostBeingPaid {
|
||||
unpaidShards.put(m.getKey(), new ShardCount(m.getValue()));
|
||||
}
|
||||
if (manaCostBeingPaid.xManaCostPaidByColor != null) {
|
||||
xManaCostPaidByColor = new HashMap<>(manaCostBeingPaid.xManaCostPaidByColor);
|
||||
xManaCostPaidByColor = Maps.newHashMap(manaCostBeingPaid.xManaCostPaidByColor);
|
||||
}
|
||||
sourceRestriction = manaCostBeingPaid.sourceRestriction;
|
||||
sunburstMap = manaCostBeingPaid.sunburstMap;
|
||||
@@ -503,7 +510,7 @@ public class ManaCostBeingPaid {
|
||||
sc.xCount--;
|
||||
String color = MagicColor.toShortString(colorMask);
|
||||
if (xManaCostPaidByColor == null) {
|
||||
xManaCostPaidByColor = new HashMap<>();
|
||||
xManaCostPaidByColor = Maps.newHashMap();
|
||||
}
|
||||
Integer xColor = xManaCostPaidByColor.get(color);
|
||||
if (xColor == null) {
|
||||
@@ -602,19 +609,7 @@ public class ManaCostBeingPaid {
|
||||
}
|
||||
|
||||
int nGeneric = getGenericManaAmount();
|
||||
List<ManaCostShard> shards = new ArrayList<>(unpaidShards.keySet());
|
||||
|
||||
// TODO Fix this. Should we really be changing Shards here?
|
||||
if (false && pool != null) { //replace shards with generic mana if they can be paid with any color mana
|
||||
for (int i = 0; i < shards.size(); i++) {
|
||||
ManaCostShard shard = shards.get(i);
|
||||
if (shard != ManaCostShard.GENERIC && pool.getPossibleColorUses(shard.getColorMask()) == ManaAtom.ALL_MANA_TYPES) {
|
||||
nGeneric += unpaidShards.get(shard).totalCount;
|
||||
shards.remove(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
List<ManaCostShard> shards = Lists.newArrayList(unpaidShards.keySet());
|
||||
|
||||
if (nGeneric > 0) {
|
||||
if (nGeneric <= 20) {
|
||||
|
||||
@@ -166,23 +166,27 @@ public class ManaPool extends ManaConversionMatrix implements Iterable<Mana> {
|
||||
owner.updateManaForView();
|
||||
}
|
||||
|
||||
private void removeMana(final Mana mana) {
|
||||
Collection<Mana> cm = floatingMana.get(mana.getColor());
|
||||
if (cm.remove(mana)) {
|
||||
private boolean removeMana(final Mana mana) {
|
||||
if (floatingMana.remove(mana.getColor(), mana)) {
|
||||
owner.updateManaForView();
|
||||
owner.getGame().fireEvent(new GameEventManaPool(owner, EventValueChangeType.Removed, mana));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public final void payManaFromAbility(final SpellAbility saPaidFor, ManaCostBeingPaid manaCost, final SpellAbility saPayment) {
|
||||
// Mana restriction must be checked before this method is called
|
||||
final List<SpellAbility> paidAbs = saPaidFor.getPayingManaAbilities();
|
||||
AbilityManaPart abManaPart = saPayment.getManaPartRecursive();
|
||||
|
||||
paidAbs.add(saPayment); // assumes some part on the mana produced by the ability will get used
|
||||
for (final Mana mana : abManaPart.getLastManaProduced()) {
|
||||
if (tryPayCostWithMana(saPaidFor, manaCost, mana, false)) {
|
||||
saPaidFor.getPayingMana().add(0, mana);
|
||||
|
||||
// need to get all mana from all ManaAbilities of the SpellAbility
|
||||
for (AbilityManaPart mp : saPayment.getAllManaParts()) {
|
||||
for (final Mana mana : mp.getLastManaProduced()) {
|
||||
if (tryPayCostWithMana(saPaidFor, manaCost, mana, false)) {
|
||||
saPaidFor.getPayingMana().add(0, mana);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -216,8 +220,12 @@ public class ManaPool extends ManaConversionMatrix implements Iterable<Mana> {
|
||||
if (!manaCost.isNeeded(mana, this)) {
|
||||
return false;
|
||||
}
|
||||
// only pay mana into manaCost when the Mana could be removed from the Mana pool
|
||||
// if the mana wasn't in the mana pool then something is wrong
|
||||
if (!removeMana(mana)) {
|
||||
return false;
|
||||
}
|
||||
manaCost.payMana(mana, this);
|
||||
removeMana(mana);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -3539,4 +3539,11 @@ public class Player extends GameEntity implements Comparable<Player> {
|
||||
public void resetCycledThisTurn() {
|
||||
cycledThisTurn = 0;
|
||||
}
|
||||
|
||||
public boolean hasUrzaLands() {
|
||||
final CardCollectionView landsControlled = getCardsIn(ZoneType.Battlefield);
|
||||
return Iterables.any(landsControlled, Predicates.and(CardPredicates.isType("Urza's"), CardPredicates.isType("Mine")))
|
||||
&& Iterables.any(landsControlled, Predicates.and(CardPredicates.isType("Urza's"), CardPredicates.isType("Power-Plant")))
|
||||
&& Iterables.any(landsControlled, Predicates.and(CardPredicates.isType("Urza's"), CardPredicates.isType("Tower")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ public abstract class PlayerController {
|
||||
public abstract Integer announceRequirements(SpellAbility ability, String announce);
|
||||
public abstract CardCollectionView choosePermanentsToSacrifice(SpellAbility sa, int min, int max, CardCollectionView validTargets, String message);
|
||||
public abstract CardCollectionView choosePermanentsToDestroy(SpellAbility sa, int min, int max, CardCollectionView validTargets, String message);
|
||||
public abstract TargetChoices chooseNewTargetsFor(SpellAbility ability);
|
||||
public abstract TargetChoices chooseNewTargetsFor(SpellAbility ability, Predicate<GameObject> filter, boolean optional);
|
||||
public abstract boolean chooseTargetsFor(SpellAbility currentAbility); // this is bad a function for it assigns targets to sa inside its body
|
||||
|
||||
// Specify a target of a spell (Spellskite)
|
||||
|
||||
@@ -31,10 +31,10 @@ public class ReplaceProduceMana extends ReplacementEffect {
|
||||
*/
|
||||
@Override
|
||||
public boolean canReplace(Map<AbilityKey, Object> runParams) {
|
||||
//Check for tapping
|
||||
if (!hasParam("NoTapCheck")) {
|
||||
|
||||
if (hasParam("ValidAbility")) {
|
||||
final SpellAbility manaAbility = (SpellAbility) runParams.get(AbilityKey.AbilityMana);
|
||||
if (manaAbility == null || !manaAbility.getRootAbility().getPayCosts().hasTapCost()) {
|
||||
if (!matchesValid(manaAbility, getParam("ValidAbility").split(","), getHostCard())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -43,15 +43,23 @@ public class ReplaceProduceMana extends ReplacementEffect {
|
||||
String full = getParam("ManaAmount");
|
||||
String operator = full.substring(0, 2);
|
||||
String operand = full.substring(2);
|
||||
|
||||
int intoperand = AbilityUtils.calculateAmount(getHostCard(), operand, this);
|
||||
|
||||
int manaAmount = StringUtils.countMatches((String) runParams.get(AbilityKey.Mana), " ") + 1;
|
||||
if (!Expressions.compare(manaAmount, operator, intoperand)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasParam("ValidPlayer")) {
|
||||
if (!matchesValid(runParams.get(AbilityKey.Player), getParam("ValidPlayer").split(","), getHostCard())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasParam("ValidCard")) {
|
||||
if (!matchesValid(runParams.get(AbilityKey.Affected), getParam("ValidCard").split(","), this.getHostCard())) {
|
||||
if (!matchesValid(runParams.get(AbilityKey.Affected), getParam("ValidCard").split(","), getHostCard())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -60,4 +68,7 @@ public class ReplaceProduceMana extends ReplacementEffect {
|
||||
}
|
||||
|
||||
|
||||
public void setReplacingObjects(Map<AbilityKey, Object> runParams, SpellAbility sa) {
|
||||
sa.setReplacingObject(AbilityKey.Mana, runParams.get(AbilityKey.Mana));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package forge.game.replacement;
|
||||
|
||||
import forge.game.Game;
|
||||
import forge.game.TriggerReplacementBase;
|
||||
import forge.game.ability.AbilityFactory;
|
||||
import forge.game.ability.AbilityKey;
|
||||
import forge.game.ability.AbilityUtils;
|
||||
import forge.game.card.Card;
|
||||
@@ -271,4 +272,13 @@ public abstract class ReplacementEffect extends TriggerReplacementBase {
|
||||
void setMode(ReplacementType mode) {
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
public SpellAbility ensureAbility() {
|
||||
SpellAbility sa = getOverridingAbility();
|
||||
if (sa == null && hasParam("ReplaceWith")) {
|
||||
sa = AbilityFactory.getAbility(getHostCard(), getParam("ReplaceWith"));
|
||||
setOverridingAbility(sa);
|
||||
}
|
||||
return sa;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
*/
|
||||
package forge.game.replacement;
|
||||
|
||||
import forge.card.MagicColor;
|
||||
import forge.game.Game;
|
||||
import forge.game.GameLogEntryType;
|
||||
import forge.game.IHasSVars;
|
||||
import forge.game.ability.AbilityFactory;
|
||||
import forge.game.ability.AbilityKey;
|
||||
import forge.game.ability.AbilityUtils;
|
||||
@@ -259,12 +259,17 @@ public class ReplacementHandler {
|
||||
chosenRE.setHasRun(false);
|
||||
hasRun.remove(chosenRE);
|
||||
chosenRE.setOtherChoices(null);
|
||||
String message = chosenRE.getDescription();
|
||||
if ( !StringUtils.isEmpty(message))
|
||||
if (chosenRE.getHostCard() != null) {
|
||||
message = TextUtil.fastReplace(message, "CARDNAME", chosenRE.getHostCard().getName());
|
||||
}
|
||||
game.getGameLog().add(GameLogEntryType.EFFECT_REPLACED, message);
|
||||
|
||||
// Updated Replacements need to be logged elsewhere because its otherwise in the wrong order
|
||||
if (res != ReplacementResult.Updated) {
|
||||
String message = chosenRE.getDescription();
|
||||
if ( !StringUtils.isEmpty(message))
|
||||
if (chosenRE.getHostCard() != null) {
|
||||
message = TextUtil.fastReplace(message, "CARDNAME", chosenRE.getHostCard().getName());
|
||||
}
|
||||
game.getGameLog().add(GameLogEntryType.EFFECT_REPLACED, message);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -344,25 +349,11 @@ public class ReplacementHandler {
|
||||
|
||||
Player player = host.getController();
|
||||
|
||||
if (mapParams.containsKey("ManaReplacement")) {
|
||||
final SpellAbility manaAb = (SpellAbility) runParams.get(AbilityKey.AbilityMana);
|
||||
final Player player1 = (Player) runParams.get(AbilityKey.Player);
|
||||
final String rep = (String) runParams.get(AbilityKey.Mana);
|
||||
// Replaced mana type
|
||||
final Card repHost = host;
|
||||
String repType = repHost.getSVar(mapParams.get("ManaReplacement"));
|
||||
if (repType.contains("Chosen") && repHost.hasChosenColor()) {
|
||||
repType = TextUtil.fastReplace(repType, "Chosen", MagicColor.toShortString(repHost.getChosenColor()));
|
||||
}
|
||||
manaAb.getManaPart().setManaReplaceType(repType);
|
||||
manaAb.getManaPart().produceMana(rep, player1, manaAb);
|
||||
} else {
|
||||
player.getController().playSpellAbilityNoStack(effectSA, true);
|
||||
// if the spellability is a replace effect then its some new logic
|
||||
// if ReplacementResult is set in run params use that instead
|
||||
if (runParams.containsKey(AbilityKey.ReplacementResult)) {
|
||||
return (ReplacementResult) runParams.get(AbilityKey.ReplacementResult);
|
||||
}
|
||||
player.getController().playSpellAbilityNoStack(effectSA, true);
|
||||
// if the spellability is a replace effect then its some new logic
|
||||
// if ReplacementResult is set in run params use that instead
|
||||
if (runParams.containsKey(AbilityKey.ReplacementResult)) {
|
||||
return (ReplacementResult) runParams.get(AbilityKey.ReplacementResult);
|
||||
}
|
||||
|
||||
return ReplacementResult.Replaced;
|
||||
@@ -380,7 +371,10 @@ public class ReplacementHandler {
|
||||
* @return A finished instance
|
||||
*/
|
||||
public static ReplacementEffect parseReplacement(final String repParse, final Card host, final boolean intrinsic) {
|
||||
return ReplacementHandler.parseReplacement(parseParams(repParse), host, intrinsic);
|
||||
return parseReplacement(repParse, host, intrinsic, host);
|
||||
}
|
||||
public static ReplacementEffect parseReplacement(final String repParse, final Card host, final boolean intrinsic, final IHasSVars sVarHolder) {
|
||||
return ReplacementHandler.parseReplacement(parseParams(repParse), host, intrinsic, sVarHolder);
|
||||
}
|
||||
|
||||
public static Map<String, String> parseParams(final String repParse) {
|
||||
@@ -398,7 +392,7 @@ public class ReplacementHandler {
|
||||
* The card that hosts the replacement effect
|
||||
* @return The finished instance
|
||||
*/
|
||||
private static ReplacementEffect parseReplacement(final Map<String, String> mapParams, final Card host, final boolean intrinsic) {
|
||||
private static ReplacementEffect parseReplacement(final Map<String, String> mapParams, final Card host, final boolean intrinsic, final IHasSVars sVarHolder) {
|
||||
final ReplacementType rt = ReplacementType.smartValueOf(mapParams.get("Event"));
|
||||
ReplacementEffect ret = rt.createReplacement(mapParams, host, intrinsic);
|
||||
|
||||
@@ -407,6 +401,10 @@ public class ReplacementHandler {
|
||||
ret.setActiveZone(EnumSet.copyOf(ZoneType.listValueOf(activeZones)));
|
||||
}
|
||||
|
||||
if (mapParams.containsKey("ReplaceWith") && sVarHolder != null) {
|
||||
ret.setOverridingAbility(AbilityFactory.getAbility(host, mapParams.get("ReplaceWith"), sVarHolder));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,18 +18,18 @@
|
||||
package forge.game.spellability;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
|
||||
import forge.card.ColorSet;
|
||||
import forge.card.MagicColor;
|
||||
import forge.card.mana.ManaAtom;
|
||||
import forge.card.mana.ManaCostShard;
|
||||
import forge.game.Game;
|
||||
import forge.game.ability.AbilityFactory;
|
||||
import forge.game.GameActionUtil;
|
||||
import forge.game.ability.AbilityKey;
|
||||
import forge.game.ability.ApiType;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.card.CardFactoryUtil;
|
||||
import forge.game.card.CounterType;
|
||||
import forge.game.card.CardUtil;
|
||||
import forge.game.mana.Mana;
|
||||
import forge.game.mana.ManaPool;
|
||||
import forge.game.player.Player;
|
||||
@@ -37,15 +37,11 @@ import forge.game.replacement.*;
|
||||
import forge.game.trigger.Trigger;
|
||||
import forge.game.trigger.TriggerHandler;
|
||||
import forge.game.trigger.TriggerType;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.util.Lang;
|
||||
import forge.util.TextUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -62,6 +58,7 @@ public class AbilityManaPart implements java.io.Serializable {
|
||||
private final String origProduced;
|
||||
private String lastExpressChoice = "";
|
||||
private final String manaRestrictions;
|
||||
private String extraManaRestrictions = "";
|
||||
private final String cannotCounterSpell;
|
||||
private final String addsKeywords;
|
||||
private final String addsKeywordsType;
|
||||
@@ -69,7 +66,6 @@ public class AbilityManaPart implements java.io.Serializable {
|
||||
private final String addsCounters;
|
||||
private final String triggersWhenSpent;
|
||||
private final boolean persistentMana;
|
||||
private String manaReplaceType;
|
||||
|
||||
private transient List<Mana> lastManaProduced = Lists.newArrayList();
|
||||
|
||||
@@ -99,7 +95,6 @@ public class AbilityManaPart implements java.io.Serializable {
|
||||
this.addsCounters = params.get("AddsCounters");
|
||||
this.triggersWhenSpent = params.get("TriggersWhenSpent");
|
||||
this.persistentMana = (null != params.get("PersistentMana")) && "True".equalsIgnoreCase(params.get("PersistentMana"));
|
||||
this.manaReplaceType = params.containsKey("ManaReplaceType") ? params.get("ManaReplaceType") : "";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,14 +121,26 @@ public class AbilityManaPart implements java.io.Serializable {
|
||||
public final void produceMana(final String produced, final Player player, SpellAbility sa) {
|
||||
final Card source = this.getSourceCard();
|
||||
final ManaPool manaPool = player.getManaPool();
|
||||
String afterReplace = applyManaReplacement(sa, produced);
|
||||
String afterReplace = produced;
|
||||
|
||||
SpellAbility root = sa == null ? null : sa.getRootAbility();
|
||||
|
||||
final Map<AbilityKey, Object> repParams = AbilityKey.mapFromAffected(source);
|
||||
repParams.put(AbilityKey.Mana, produced);
|
||||
repParams.put(AbilityKey.Mana, afterReplace);
|
||||
repParams.put(AbilityKey.Player, player);
|
||||
repParams.put(AbilityKey.AbilityMana, sa);
|
||||
if (player.getGame().getReplacementHandler().run(ReplacementType.ProduceMana, repParams) != ReplacementResult.NotReplaced) {
|
||||
repParams.put(AbilityKey.AbilityMana, root);
|
||||
repParams.put(AbilityKey.Activator, root == null ? null : root.getActivatingPlayer());
|
||||
|
||||
switch (player.getGame().getReplacementHandler().run(ReplacementType.ProduceMana, repParams)) {
|
||||
case NotReplaced:
|
||||
break;
|
||||
case Updated:
|
||||
afterReplace = (String) repParams.get(AbilityKey.Mana);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
//clear lastProduced
|
||||
this.lastManaProduced.clear();
|
||||
|
||||
@@ -159,14 +166,14 @@ public class AbilityManaPart implements java.io.Serializable {
|
||||
// Run triggers
|
||||
final Map<AbilityKey, Object> runParams = AbilityKey.mapFromCard(source);
|
||||
runParams.put(AbilityKey.Player, player);
|
||||
runParams.put(AbilityKey.AbilityMana, sa);
|
||||
runParams.put(AbilityKey.Produced, afterReplace);
|
||||
runParams.put(AbilityKey.AbilityMana, root);
|
||||
runParams.put(AbilityKey.Activator, root == null ? null : root.getActivatingPlayer());
|
||||
|
||||
player.getGame().getTriggerHandler().runTrigger(TriggerType.TapsForMana, runParams, false);
|
||||
if (source.isLand()) {
|
||||
player.setTappedLandForManaThisTurn(true);
|
||||
if (source.isLand() && sa.getPayCosts() != null && sa.getPayCosts().hasTapCost() ) {
|
||||
player.setTappedLandForManaThisTurn(true);
|
||||
}
|
||||
// Clear Mana replacement
|
||||
this.manaReplaceType = "";
|
||||
} // end produceMana(String)
|
||||
|
||||
/**
|
||||
@@ -236,61 +243,7 @@ public class AbilityManaPart implements java.io.Serializable {
|
||||
String[] parse = this.addsCounters.split("_");
|
||||
// Convert random SVars if there are other cards with this effect
|
||||
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.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]
|
||||
+ " | ETB$ True | CounterNum$ " + parse[2];
|
||||
|
||||
SpellAbility sa = AbilityFactory.getAbility(abStr, c);
|
||||
if (!StringUtils.isNumeric(parse[2])) {
|
||||
sa.setSVar(parse[2], sourceCard.getSVar(parse[2]));
|
||||
}
|
||||
CardFactoryUtil.setupETBReplacementAbility(sa);
|
||||
|
||||
String desc = "It enters the battlefield with ";
|
||||
desc += Lang.nounWithNumeral(parse[2], CounterType.getType(parse[1]).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(sa);
|
||||
|
||||
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);
|
||||
GameActionUtil.createETBCountersEffect(sourceCard, c, controller, parse[1], parse[2]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -315,7 +268,15 @@ public class AbilityManaPart implements java.io.Serializable {
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
public String getManaRestrictions() {
|
||||
return this.manaRestrictions;
|
||||
return manaRestrictions;
|
||||
}
|
||||
|
||||
public void setExtraManaRestriction(String str) {
|
||||
this.extraManaRestrictions = str;
|
||||
}
|
||||
|
||||
public boolean meetsManaRestrictions(final SpellAbility sa) {
|
||||
return meetsManaRestrictions(sa, this.manaRestrictions) && meetsManaRestrictions(sa, this.extraManaRestrictions);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -327,14 +288,14 @@ public class AbilityManaPart implements java.io.Serializable {
|
||||
* a {@link forge.game.spellability.SpellAbility} object.
|
||||
* @return a boolean.
|
||||
*/
|
||||
public boolean meetsManaRestrictions(final SpellAbility sa) {
|
||||
public boolean meetsManaRestrictions(final SpellAbility sa, String restrictions) {
|
||||
// No restrictions
|
||||
if (this.manaRestrictions.isEmpty()) {
|
||||
if (restrictions.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Loop over restrictions
|
||||
for (String restriction : this.manaRestrictions.split(",")) {
|
||||
for (String restriction : restrictions.split(",")) {
|
||||
if (restriction.equals("nonSpell")) {
|
||||
return !sa.isSpell();
|
||||
}
|
||||
@@ -365,9 +326,9 @@ public class AbilityManaPart implements java.io.Serializable {
|
||||
if (sa.isValid(restriction, this.getSourceCard().getController(), this.getSourceCard(), null)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if (restriction.equals("CantPayGenericCosts")) {
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (sa.isAbility()) {
|
||||
@@ -390,7 +351,7 @@ public class AbilityManaPart implements java.io.Serializable {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* meetsManaShardRestrictions.
|
||||
@@ -399,44 +360,44 @@ public class AbilityManaPart implements java.io.Serializable {
|
||||
* @param shard
|
||||
* a {@link forge.card.mana.ManaCostShard} object.
|
||||
* @param color
|
||||
* the color of mana being paid
|
||||
* the color of mana being paid
|
||||
* @return a boolean.
|
||||
*/
|
||||
public boolean meetsManaShardRestrictions(final ManaCostShard shard, final byte color) {
|
||||
if (this.manaRestrictions.isEmpty()) {
|
||||
if (this.manaRestrictions.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
for (String restriction : this.manaRestrictions.split(",")) {
|
||||
if (restriction.equals("CantPayGenericCosts")) {
|
||||
if (shard.isGeneric()) {
|
||||
if (shard.isOr2Generic() && shard.isColor(color)) {
|
||||
continue;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (restriction.equals("CantPayGenericCosts")) {
|
||||
if (shard.isGeneric()) {
|
||||
if (shard.isOr2Generic() && shard.isColor(color)) {
|
||||
continue;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* meetsSpellAndShardRestrictions.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @param sa
|
||||
* a {@link forge.game.spellability.SpellAbility} object.
|
||||
* @param shard
|
||||
* a {@link forge.card.mana.ManaCostShard} object.
|
||||
* @param color
|
||||
* the color of mana being paid
|
||||
* the color of mana being paid
|
||||
* @return a boolean.
|
||||
*/
|
||||
public boolean meetsSpellAndShardRestrictions(final SpellAbility sa, final ManaCostShard shard, final byte color) {
|
||||
return this.meetsManaRestrictions(sa) && this.meetsManaShardRestrictions(shard, color);
|
||||
return this.meetsManaRestrictions(sa) && this.meetsManaShardRestrictions(shard, color);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -524,10 +485,6 @@ public class AbilityManaPart implements java.io.Serializable {
|
||||
return this.getOrigProduced().contains("Special");
|
||||
}
|
||||
|
||||
public final boolean canProduce(final String s) {
|
||||
return canProduce(s, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* canProduce.
|
||||
@@ -552,24 +509,9 @@ public class AbilityManaPart implements java.io.Serializable {
|
||||
if (isComboMana()) {
|
||||
return getComboColors().contains(s);
|
||||
}
|
||||
if (sa != null) {
|
||||
return applyManaReplacement(sa, origProduced).contains(s);
|
||||
}
|
||||
return origProduced.contains(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* isBasic.
|
||||
* </p>
|
||||
*
|
||||
* @return a boolean.
|
||||
*/
|
||||
public final boolean isBasic() {
|
||||
return this.getOrigProduced().length() == 1 || this.getOrigProduced().contains("Any")
|
||||
|| this.getOrigProduced().contains("Chosen");
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public final boolean equals(final Object o) {
|
||||
@@ -645,81 +587,59 @@ public class AbilityManaPart implements java.io.Serializable {
|
||||
return this.persistentMana;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the manaReplaceType
|
||||
*/
|
||||
public String getManaReplaceType() {
|
||||
return manaReplaceType;
|
||||
}
|
||||
boolean abilityProducesManaColor(final SpellAbility am, final byte neededColor) {
|
||||
if (0 != (neededColor & ManaAtom.GENERIC)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* setManaReplaceType.
|
||||
*/
|
||||
public void setManaReplaceType(final String type) {
|
||||
this.manaReplaceType = type;
|
||||
}
|
||||
/**
|
||||
* <p>
|
||||
* applyManaReplacement.
|
||||
* </p>
|
||||
* @return a String
|
||||
*/
|
||||
public static String applyManaReplacement(final SpellAbility sa, final String original) {
|
||||
final Map<String, String> repMap = Maps.newHashMap();
|
||||
final Player act = sa != null ? sa.getActivatingPlayer() : null;
|
||||
final String manaReplace = sa != null ? sa.getManaPart().getManaReplaceType(): "";
|
||||
if (manaReplace.isEmpty()) {
|
||||
if (act != null && act.getLandsPlayedThisTurn() > 0 && sa.hasParam("ReplaceIfLandPlayed")) {
|
||||
return sa.getParam("ReplaceIfLandPlayed");
|
||||
}
|
||||
return original;
|
||||
if (isAnyMana()) {
|
||||
return true;
|
||||
}
|
||||
if (manaReplace.startsWith("Any")) {
|
||||
// Replace any type and amount
|
||||
String replaced = manaReplace.split("->")[1];
|
||||
if (replaced.equals("Any")) {
|
||||
byte rs = MagicColor.GREEN;
|
||||
if (act != null) {
|
||||
rs = act.getController().chooseColor("Choose a color", sa, ColorSet.ALL_COLORS);
|
||||
|
||||
// check for produce mana replacement effects - they mess this up, so just use the mana ability
|
||||
final Card source = am.getHostCard();
|
||||
final Player activator = am.getActivatingPlayer();
|
||||
final Game g = source.getGame();
|
||||
final Map<AbilityKey, Object> repParams = AbilityKey.newMap();
|
||||
repParams.put(AbilityKey.Mana, getOrigProduced());
|
||||
repParams.put(AbilityKey.Affected, source);
|
||||
repParams.put(AbilityKey.Player, activator);
|
||||
repParams.put(AbilityKey.AbilityMana, am.getRootAbility());
|
||||
|
||||
for (final Player p : g.getPlayers()) {
|
||||
for (final Card crd : p.getAllCards()) {
|
||||
for (final ReplacementEffect replacementEffect : crd.getReplacementEffects()) {
|
||||
if (replacementEffect.requirementsCheck(g)
|
||||
&& replacementEffect.getMode() == ReplacementType.ProduceMana
|
||||
&& replacementEffect.canReplace(repParams)
|
||||
&& replacementEffect.zonesCheck(g.getZoneOf(crd))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
replaced = MagicColor.toShortString(rs);
|
||||
}
|
||||
return replaced;
|
||||
}
|
||||
final Pattern splitter = Pattern.compile("->");
|
||||
// Replace any type
|
||||
for (String part : manaReplace.split(" & ")) {
|
||||
final String[] v = splitter.split(part, 2);
|
||||
// TODO Colorless mana replacement is probably different now?
|
||||
if (v[0].equals("Colorless")) {
|
||||
repMap.put("[0-9][0-9]?", v.length > 1 ? v[1].trim() : "");
|
||||
} else {
|
||||
repMap.put(v[0], v.length > 1 ? v[1].trim() : "");
|
||||
}
|
||||
}
|
||||
// Handle different replacement simultaneously
|
||||
Pattern pattern = Pattern.compile(StringUtils.join(repMap.keySet().iterator(), "|"));
|
||||
Matcher m = pattern.matcher(original);
|
||||
StringBuffer sb = new StringBuffer();
|
||||
while(m.find()) {
|
||||
if (m.group().matches("[0-9][0-9]?")) {
|
||||
final String rep = StringUtils.repeat(repMap.get("[0-9][0-9]?") + " ",
|
||||
Integer.parseInt(m.group())).trim();
|
||||
m.appendReplacement(sb, rep);
|
||||
} else {
|
||||
m.appendReplacement(sb, repMap.get(m.group()));
|
||||
|
||||
if (am.getApi() == ApiType.ManaReflected) {
|
||||
final Iterable<String> reflectableColors = CardUtil.getReflectableManaColors(am);
|
||||
for (final String color : reflectableColors) {
|
||||
if (0 != (neededColor & ManaAtom.fromName(color))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
m.appendTail(sb);
|
||||
String replaced = sb.toString();
|
||||
while (replaced.contains("Any")) {
|
||||
byte rs = MagicColor.GREEN;
|
||||
if (act != null) {
|
||||
rs = act.getController().chooseColor("Choose a color", sa, ColorSet.ALL_COLORS);
|
||||
else {
|
||||
// treat special mana if it always can be paid
|
||||
if (isSpecialMana()) {
|
||||
return true;
|
||||
}
|
||||
String colorsProduced = isComboMana() ? getComboColors() : mana();
|
||||
for (final String color : colorsProduced.split(" ")) {
|
||||
if (0 != (neededColor & ManaAtom.fromName(color))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
replaced = replaced.replaceFirst("Any", MagicColor.toShortString(rs));
|
||||
}
|
||||
return replaced;
|
||||
return false;
|
||||
}
|
||||
|
||||
} // end class AbilityMana
|
||||
|
||||
@@ -20,10 +20,6 @@ package forge.game.spellability;
|
||||
import forge.game.ability.AbilityFactory;
|
||||
import forge.game.ability.ApiType;
|
||||
import forge.game.ability.SpellAbilityEffect;
|
||||
import forge.game.ability.effects.ChangeZoneAllEffect;
|
||||
import forge.game.ability.effects.ChangeZoneEffect;
|
||||
import forge.game.ability.effects.ManaEffect;
|
||||
import forge.game.ability.effects.ManaReflectedEffect;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.cost.Cost;
|
||||
|
||||
@@ -92,11 +88,11 @@ public final class AbilitySub extends SpellAbility implements java.io.Serializab
|
||||
|
||||
effect = api.getSpellEffect();
|
||||
|
||||
if (effect instanceof ManaEffect || effect instanceof ManaReflectedEffect) {
|
||||
if (api.equals(ApiType.Mana) || api.equals(ApiType.ManaReflected)) {
|
||||
this.setManaPart(new AbilityManaPart(ca, mapParams));
|
||||
}
|
||||
|
||||
if (effect instanceof ChangeZoneEffect || effect instanceof ChangeZoneAllEffect) {
|
||||
if (api.equals(ApiType.ChangeZone) || api.equals(ApiType.ChangeZoneAll)) {
|
||||
AbilityFactory.adjustChangeZoneTarget(mapParams, this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,6 +152,8 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit
|
||||
private TargetRestrictions targetRestrictions = null;
|
||||
private TargetChoices targetChosen = new TargetChoices();
|
||||
|
||||
private Integer dividedValue = null;
|
||||
|
||||
private SpellAbilityView view;
|
||||
|
||||
private StaticAbility mayPlay = null;
|
||||
@@ -159,6 +161,8 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit
|
||||
private CardCollection lastStateBattlefield = null;
|
||||
private CardCollection lastStateGraveyard = null;
|
||||
|
||||
private CardCollection rollbackEffects = new CardCollection();
|
||||
|
||||
private CardDamageMap damageMap = null;
|
||||
private CardDamageMap preventMap = null;
|
||||
private CardZoneTable changeZoneTable = null;
|
||||
@@ -233,19 +237,101 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit
|
||||
view.updateDescription(this); //description can change if host card does
|
||||
}
|
||||
|
||||
public boolean canThisProduce(final String s) {
|
||||
AbilityManaPart mp = getManaPart();
|
||||
if (mp != null && metConditions() && mp.canProduce(s, this)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean canProduce(final String s) {
|
||||
if (canThisProduce(s)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return this.subAbility != null ? this.subAbility.canProduce(s) : false;
|
||||
}
|
||||
|
||||
public boolean isManaAbilityFor(SpellAbility saPaidFor, byte colorNeeded) {
|
||||
// is root ability
|
||||
if (this.getParent() == null) {
|
||||
if (!canPlay()) {
|
||||
return false;
|
||||
}
|
||||
if (isAbility() && getRestrictions().isInstantSpeed()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
AbilityManaPart mp = getManaPart();
|
||||
if (mp != null && metConditions() && mp.meetsManaRestrictions(saPaidFor) && mp.abilityProducesManaColor(this, colorNeeded)) {
|
||||
return true;
|
||||
}
|
||||
return this.subAbility != null ? this.subAbility.isManaAbilityFor(saPaidFor, colorNeeded) : false;
|
||||
}
|
||||
|
||||
public boolean isManaCannotCounter(SpellAbility saPaidFor) {
|
||||
AbilityManaPart mp = getManaPart();
|
||||
if (mp != null && metConditions() && mp.meetsManaRestrictions(saPaidFor) && mp.cannotCounterPaidWith(saPaidFor)) {
|
||||
return true;
|
||||
}
|
||||
return this.subAbility != null ? this.subAbility.isManaCannotCounter(saPaidFor) : false;
|
||||
}
|
||||
|
||||
public int amountOfManaGenerated(boolean multiply) {
|
||||
int result = 0;
|
||||
AbilityManaPart mp = getManaPart();
|
||||
if (mp != null && metConditions()) {
|
||||
int amount = hasParam("Amount") ? AbilityUtils.calculateAmount(getHostCard(), getParam("Amount"), this) : 1;
|
||||
|
||||
if (!multiply || mp.isAnyMana() || mp.isComboMana() || mp.isSpecialMana()) {
|
||||
result += amount;
|
||||
} else {
|
||||
// For cards that produce like {C}{R} vs cards that produce {R}{R}.
|
||||
result += mp.mana().split(" ").length * amount;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public int totalAmountOfManaGenerated(SpellAbility saPaidFor, boolean multiply) {
|
||||
int result = 0;
|
||||
AbilityManaPart mp = getManaPart();
|
||||
if (mp != null && metConditions() && mp.meetsManaRestrictions(saPaidFor)) {
|
||||
result += amountOfManaGenerated(multiply);
|
||||
}
|
||||
result += subAbility != null ? subAbility.totalAmountOfManaGenerated(saPaidFor, multiply) : 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setManaExpressChoice(ColorSet cs) {
|
||||
AbilityManaPart mp = getManaPart();
|
||||
if (mp != null) {
|
||||
mp.setExpressChoice(cs);
|
||||
}
|
||||
if (subAbility != null) {
|
||||
subAbility.setManaExpressChoice(cs);
|
||||
}
|
||||
}
|
||||
|
||||
public final AbilityManaPart getManaPart() {
|
||||
return manaPart;
|
||||
}
|
||||
|
||||
public final AbilityManaPart getManaPartRecursive() {
|
||||
SpellAbility tail = this;
|
||||
while (tail != null) {
|
||||
if (tail.manaPart != null) {
|
||||
return tail.manaPart;
|
||||
}
|
||||
tail = tail.getSubAbility();
|
||||
public final List<AbilityManaPart> getAllManaParts() {
|
||||
AbilityManaPart mp = getManaPart();
|
||||
if (mp == null && subAbility == null) {
|
||||
return ImmutableList.of();
|
||||
}
|
||||
return null;
|
||||
List<AbilityManaPart> result = Lists.newArrayList();
|
||||
if (mp != null) {
|
||||
result.add(mp);
|
||||
}
|
||||
if (subAbility != null) {
|
||||
result.addAll(subAbility.getAllManaParts());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public final boolean isManaAbility() {
|
||||
@@ -262,7 +348,14 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit
|
||||
return false;
|
||||
}
|
||||
|
||||
return getManaPartRecursive() != null;
|
||||
SpellAbility tail = this;
|
||||
while (tail != null) {
|
||||
if (tail.manaPart != null) {
|
||||
return true;
|
||||
}
|
||||
tail = tail.getSubAbility();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected final void setManaPart(AbilityManaPart manaPart0) {
|
||||
@@ -460,6 +553,10 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit
|
||||
conditions = condition;
|
||||
}
|
||||
|
||||
public boolean metConditions() {
|
||||
return getConditions() != null && getConditions().areMet(this);
|
||||
}
|
||||
|
||||
public List<Mana> getPayingMana() {
|
||||
return payingMana;
|
||||
}
|
||||
@@ -1101,7 +1198,7 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit
|
||||
|
||||
if (hasParam("TargetingPlayerControls") && entity instanceof Card) {
|
||||
final Card c = (Card) entity;
|
||||
if (!c.getController().equals(targetingPlayer)) {
|
||||
if (!c.getController().equals(getTargetingPlayer())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1421,6 +1518,35 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit
|
||||
targetChosen = new TargetChoices();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a boolean dividedAsYouChoose
|
||||
*/
|
||||
public boolean isDividedAsYouChoose() {
|
||||
return hasParam("DividedAsYouChoose");
|
||||
}
|
||||
|
||||
public final void addDividedAllocation(final GameObject tgt, final Integer portionAllocated) {
|
||||
getTargets().addDividedAllocation(tgt, portionAllocated);
|
||||
}
|
||||
public Integer getDividedValue(GameObject c) {
|
||||
return getTargets().getDividedValue(c);
|
||||
}
|
||||
|
||||
public int getTotalDividedValue() {
|
||||
return getTargets().getTotalDividedValue();
|
||||
}
|
||||
|
||||
public Integer getDividedValue() {
|
||||
return this.dividedValue;
|
||||
}
|
||||
|
||||
public int getStillToDivide() {
|
||||
if (!isDividedAsYouChoose() || dividedValue == null) {
|
||||
return 0;
|
||||
}
|
||||
return dividedValue - getTotalDividedValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the first target.
|
||||
*
|
||||
@@ -1428,16 +1554,15 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit
|
||||
public void resetFirstTarget(GameObject c, SpellAbility originalSA) {
|
||||
SpellAbility sa = this;
|
||||
while (sa != null) {
|
||||
if (sa.targetRestrictions != null) {
|
||||
sa.targetChosen = new TargetChoices();
|
||||
sa.targetChosen.add(c);
|
||||
if (!originalSA.targetRestrictions.getDividedMap().isEmpty()) {
|
||||
sa.targetRestrictions.addDividedAllocation(c,
|
||||
Iterables.getFirst(originalSA.targetRestrictions.getDividedMap().values(), null));
|
||||
if (sa.usesTargeting()) {
|
||||
sa.resetTargets();
|
||||
sa.getTargets().add(c);
|
||||
if (!originalSA.getTargets().getDividedValues().isEmpty()) {
|
||||
sa.addDividedAllocation(c, Iterables.getFirst(originalSA.getTargets().getDividedValues(), null));
|
||||
}
|
||||
break;
|
||||
}
|
||||
sa = sa.subAbility;
|
||||
sa = sa.getSubAbility();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1454,7 +1579,7 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit
|
||||
}
|
||||
|
||||
public boolean isZeroTargets() {
|
||||
return getTargetRestrictions().getMinTargets(hostCard, this) == 0 && getTargets().size() == 0;
|
||||
return getMinTargets() == 0 && getTargets().size() == 0;
|
||||
}
|
||||
|
||||
public boolean isMinTargetChosen() {
|
||||
@@ -1728,6 +1853,27 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit
|
||||
return p != null && p.isTargeting(o);
|
||||
}
|
||||
|
||||
public boolean setupNewTargets(Player forceTargetingPlayer) {
|
||||
// Skip to paying if parent ability doesn't target and has no subAbilities.
|
||||
// (or trigger case where its already targeted)
|
||||
SpellAbility currentAbility = this;
|
||||
do {
|
||||
if (currentAbility.usesTargeting()) {
|
||||
TargetChoices oldTargets = currentAbility.getTargets();
|
||||
if (forceTargetingPlayer.getController().chooseNewTargetsFor(currentAbility, null, true) == null) {
|
||||
currentAbility.setTargets(oldTargets);
|
||||
}
|
||||
}
|
||||
final AbilitySub subAbility = currentAbility.getSubAbility();
|
||||
if (subAbility != null) {
|
||||
// This is necessary for "TargetsWithDefinedController$ ParentTarget"
|
||||
subAbility.setParent(currentAbility);
|
||||
}
|
||||
currentAbility = subAbility;
|
||||
} while (currentAbility != null);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean setupTargets() {
|
||||
// Skip to paying if parent ability doesn't target and has no subAbilities.
|
||||
// (or trigger case where its already targeted)
|
||||
@@ -1745,6 +1891,8 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit
|
||||
} else {
|
||||
targetingPlayer = getActivatingPlayer();
|
||||
}
|
||||
// don't set targeting player when forceful target,
|
||||
// "targeting player controls" should not be reset when the spell is copied
|
||||
currentAbility.setTargetingPlayer(targetingPlayer);
|
||||
if (!targetingPlayer.getController().chooseTargetsFor(currentAbility)) {
|
||||
return false;
|
||||
@@ -1760,11 +1908,10 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit
|
||||
return true;
|
||||
}
|
||||
public final void clearTargets() {
|
||||
final TargetRestrictions tg = getTargetRestrictions();
|
||||
if (tg != null) {
|
||||
if (usesTargeting()) {
|
||||
resetTargets();
|
||||
if (hasParam("DividedAsYouChoose")) {
|
||||
tg.calculateStillToDivide(getParam("DividedAsYouChoose"), getHostCard(), this);
|
||||
if (isDividedAsYouChoose()) {
|
||||
this.dividedValue = AbilityUtils.calculateAmount(getHostCard(), this.getParam("DividedAsYouChoose"), this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1830,9 +1977,10 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit
|
||||
public boolean tracksManaSpent() {
|
||||
if (hostCard == null || hostCard.getRules() == null) { return false; }
|
||||
|
||||
if (hostCard.hasKeyword(Keyword.SUNBURST)) {
|
||||
if (isSpell() && hostCard.hasConverge()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String text = hostCard.getRules().getOracleText();
|
||||
if (isSpell() && text.contains("was spent to cast")) {
|
||||
return true;
|
||||
@@ -1969,7 +2117,7 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit
|
||||
String mana = manaPart.mana();
|
||||
if (!mana.equals("Any")) {
|
||||
score += mana.length();
|
||||
if (!manaPart.canProduce("C")) {
|
||||
if (!canProduce("C")) {
|
||||
// Producing colorless should produce a slightly lower score
|
||||
score += 1;
|
||||
}
|
||||
@@ -2134,4 +2282,15 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit
|
||||
public boolean checkRestrictions(Card host, Player activator) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void addRollbackEffect(Card eff) {
|
||||
rollbackEffects.add(eff);
|
||||
}
|
||||
|
||||
public void rollback() {
|
||||
for (Card c : rollbackEffects) {
|
||||
c.ceaseToExist();
|
||||
}
|
||||
rollbackEffects.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,11 +32,10 @@ import forge.util.TextUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import forge.game.GameObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
@@ -85,7 +84,7 @@ public class SpellAbilityStackInstance implements IIdentifiable, IHasCardView {
|
||||
private Integer xManaPaid = null;
|
||||
|
||||
// Other Paid things
|
||||
private final HashMap<String, CardCollection> paidHash;
|
||||
private final Map<String, CardCollection> paidHash;
|
||||
|
||||
// Additional info
|
||||
// is Kicked, is Buyback
|
||||
@@ -96,7 +95,6 @@ public class SpellAbilityStackInstance implements IIdentifiable, IHasCardView {
|
||||
|
||||
private final Map<String, String> storedSVars = Maps.newHashMap();
|
||||
|
||||
private final List<ZoneType> zonesToOpen;
|
||||
private final Map<Player, Object> playersWithValidTargets;
|
||||
|
||||
private final StackItemView view;
|
||||
@@ -109,7 +107,7 @@ public class SpellAbilityStackInstance implements IIdentifiable, IHasCardView {
|
||||
activatingPlayer = sa.getActivatingPlayer();
|
||||
|
||||
// Payment info
|
||||
paidHash = new HashMap<>(ability.getPaidHash());
|
||||
paidHash = Maps.newHashMap(ability.getPaidHash());
|
||||
ability.resetPaidHash();
|
||||
splicedCards = sa.getSplicedCards();
|
||||
|
||||
@@ -149,18 +147,13 @@ public class SpellAbilityStackInstance implements IIdentifiable, IHasCardView {
|
||||
|
||||
//store zones to open and players to open them for at the time the SpellAbility first goes on the stack based on the selected targets
|
||||
if (tc == null) {
|
||||
zonesToOpen = null;
|
||||
playersWithValidTargets = null;
|
||||
}
|
||||
else {
|
||||
zonesToOpen = new ArrayList<>();
|
||||
playersWithValidTargets = new HashMap<>();
|
||||
playersWithValidTargets = Maps.newHashMap();
|
||||
for (Card card : tc.getTargetCards()) {
|
||||
ZoneType zoneType = card.getZone() != null ? card.getZone().getZoneType() : null;
|
||||
if (zoneType != ZoneType.Battlefield) { //don't need to worry about targets on battlefield
|
||||
if (zoneType != null && !zonesToOpen.contains(zoneType)) {
|
||||
zonesToOpen.add(zoneType);
|
||||
}
|
||||
playersWithValidTargets.put(card.getController(), null);
|
||||
}
|
||||
}
|
||||
@@ -253,75 +246,32 @@ public class SpellAbilityStackInstance implements IIdentifiable, IHasCardView {
|
||||
return tc;
|
||||
}
|
||||
|
||||
public final List<ZoneType> getZonesToOpen() {
|
||||
return zonesToOpen;
|
||||
}
|
||||
|
||||
public final Map<Player, Object> getPlayersWithValidTargets() {
|
||||
return playersWithValidTargets;
|
||||
}
|
||||
|
||||
public void updateTarget(TargetChoices target) {
|
||||
updateTarget(target, null, null);
|
||||
}
|
||||
|
||||
public void updateTarget(TargetChoices target, GameObject oldTarget, GameObject newTarget) {
|
||||
if (target != null) {
|
||||
TargetChoices oldTarget = tc;
|
||||
tc = target;
|
||||
ability.setTargets(tc);
|
||||
stackDescription = ability.getStackDescription();
|
||||
view.updateTargetCards(this);
|
||||
view.updateTargetPlayers(this);
|
||||
view.updateText(this);
|
||||
|
||||
if (ability.hasParam("DividedAsYouChoose")) {
|
||||
// try to update DividedAsYouChoose after retargeting
|
||||
Object toRemove = null;
|
||||
Object toAdd = null;
|
||||
HashMap<Object,Integer> map = ability.getTargetRestrictions().getDividedMap();
|
||||
|
||||
if (oldTarget != null) {
|
||||
toRemove = oldTarget;
|
||||
} else {
|
||||
// try to deduce which target has been replaced
|
||||
// (this may be imprecise, updateTarget should specify old target if possible)
|
||||
for (Object obj : map.keySet()) {
|
||||
if (!target.contains(obj)) {
|
||||
toRemove = obj;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (newTarget != null) {
|
||||
toAdd = newTarget;
|
||||
} else {
|
||||
// try to deduce which target was added
|
||||
// (this may be imprecise, updateTarget should specify new target if possible)
|
||||
for (Object newTgts : target) {
|
||||
if (!map.containsKey(newTgts)) {
|
||||
toAdd = newTgts;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (toRemove != null && toAdd != null) {
|
||||
int div = map.get(toRemove);
|
||||
map.remove(toRemove);
|
||||
ability.getTargetRestrictions().addDividedAllocation(toAdd, div);
|
||||
}
|
||||
}
|
||||
|
||||
// Run BecomesTargetTrigger
|
||||
final Map<AbilityKey, Object> runParams = AbilityKey.newMap();
|
||||
Map<AbilityKey, Object> runParams = AbilityKey.newMap();
|
||||
runParams.put(AbilityKey.SourceSA, ability);
|
||||
Set<Object> distinctObjects = new HashSet<>();
|
||||
for (final Object tgt : target) {
|
||||
if (distinctObjects.contains(tgt)) {
|
||||
Set<GameObject> distinctObjects = Sets.newHashSet();
|
||||
for (final GameObject tgt : target) {
|
||||
if (oldTarget != null && oldTarget.contains(tgt)) {
|
||||
// it was an old target, so don't trigger becomes target
|
||||
continue;
|
||||
}
|
||||
if (!distinctObjects.add(tgt)) {
|
||||
continue;
|
||||
}
|
||||
distinctObjects.add(tgt);
|
||||
|
||||
if (tgt instanceof Card && !((Card) tgt).hasBecomeTargetThisTurn()) {
|
||||
runParams.put(AbilityKey.FirstTime, null);
|
||||
@@ -330,7 +280,8 @@ public class SpellAbilityStackInstance implements IIdentifiable, IHasCardView {
|
||||
runParams.put(AbilityKey.Target, tgt);
|
||||
getSourceCard().getGame().getTriggerHandler().runTrigger(TriggerType.BecomesTarget, runParams, false);
|
||||
}
|
||||
runParams.put(AbilityKey.Targets, target);
|
||||
runParams = AbilityKey.newMap();
|
||||
runParams.put(AbilityKey.Targets, distinctObjects);
|
||||
getSourceCard().getGame().getTriggerHandler().runTrigger(TriggerType.BecomesTargetOnce, runParams, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.ForwardingList;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import forge.game.GameEntity;
|
||||
import forge.game.GameObject;
|
||||
@@ -30,7 +31,9 @@ import forge.game.card.CardCollectionView;
|
||||
import forge.game.player.Player;
|
||||
import forge.util.collect.FCollection;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -44,6 +47,8 @@ public class TargetChoices extends ForwardingList<GameObject> implements Cloneab
|
||||
|
||||
private final FCollection<GameObject> targets = new FCollection<GameObject>();
|
||||
|
||||
private final Map<GameObject, Integer> dividedMap = Maps.newHashMap();
|
||||
|
||||
public final int getTotalTargetedCMC() {
|
||||
int totalCMC = 0;
|
||||
for (Card c : Iterables.filter(targets, Card.class)) {
|
||||
@@ -52,6 +57,7 @@ public class TargetChoices extends ForwardingList<GameObject> implements Cloneab
|
||||
return totalCMC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean add(final GameObject o) {
|
||||
if (o instanceof Player || o instanceof Card || o instanceof SpellAbility) {
|
||||
return super.add(o);
|
||||
@@ -59,6 +65,22 @@ public class TargetChoices extends ForwardingList<GameObject> implements Cloneab
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAll(Collection<?> collection) {
|
||||
boolean result = super.removeAll(collection);
|
||||
for (Object e : collection) {
|
||||
this.dividedMap.remove(e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Object object) {
|
||||
boolean result = super.remove(object);
|
||||
dividedMap.remove(object);
|
||||
return result;
|
||||
}
|
||||
|
||||
public final CardCollectionView getTargetCards() {
|
||||
return new CardCollection(Iterables.filter(targets, Card.class));
|
||||
}
|
||||
@@ -108,10 +130,31 @@ public class TargetChoices extends ForwardingList<GameObject> implements Cloneab
|
||||
public TargetChoices clone() {
|
||||
TargetChoices tc = new TargetChoices();
|
||||
tc.targets.addAll(targets);
|
||||
tc.dividedMap.putAll(dividedMap);
|
||||
return tc;
|
||||
}
|
||||
@Override
|
||||
protected List<GameObject> delegate() {
|
||||
return targets;
|
||||
}
|
||||
|
||||
public final void addDividedAllocation(final GameObject tgt, final Integer portionAllocated) {
|
||||
this.dividedMap.put(tgt, portionAllocated);
|
||||
}
|
||||
public Integer getDividedValue(GameObject c) {
|
||||
return dividedMap.get(c);
|
||||
}
|
||||
|
||||
public Collection<Integer> getDividedValues() {
|
||||
return dividedMap.values();
|
||||
}
|
||||
|
||||
public int getTotalDividedValue() {
|
||||
int result = 0;
|
||||
for (Integer i : getDividedValues()) {
|
||||
if (i != null)
|
||||
result += i;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,11 +18,9 @@
|
||||
package forge.game.spellability;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import forge.util.TextUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
@@ -75,11 +73,6 @@ public class TargetRestrictions {
|
||||
|
||||
// What's the max total CMC of targets?
|
||||
private String maxTotalCMC;
|
||||
|
||||
// For "Divided" cards. Is this better in TargetChoices?
|
||||
private boolean dividedAsYouChoose = false;
|
||||
private HashMap<Object, Integer> dividedMap = new HashMap<>();
|
||||
private int stillToDivide = 0;
|
||||
|
||||
// Not sure what's up with Mandatory? Why wouldn't targeting be mandatory?
|
||||
private boolean bMandatory = false;
|
||||
@@ -101,7 +94,6 @@ public class TargetRestrictions {
|
||||
this.maxTotalCMC = target.getMaxTotalCMC();
|
||||
this.tgtZone = target.getZone();
|
||||
this.saValidTargeting = target.getSAValidTargeting();
|
||||
this.dividedAsYouChoose = target.isDividedAsYouChoose();
|
||||
this.uniqueTargets = target.isUniqueTargets();
|
||||
this.singleZone = target.isSingleZone();
|
||||
this.differentControllers = target.isDifferentControllers();
|
||||
@@ -728,82 +720,9 @@ public class TargetRestrictions {
|
||||
this.singleTarget = singleTarget;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a boolean dividedAsYouChoose
|
||||
*/
|
||||
public boolean isDividedAsYouChoose() {
|
||||
return this.dividedAsYouChoose;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param divided the boolean to set
|
||||
*/
|
||||
public void setDividedAsYouChoose(boolean divided) {
|
||||
this.dividedAsYouChoose = divided;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the amount remaining to distribute.
|
||||
* @return int stillToDivide
|
||||
*/
|
||||
public int getStillToDivide() {
|
||||
return this.stillToDivide;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param remaining set the amount still to be divided
|
||||
*/
|
||||
public void setStillToDivide(final int remaining) {
|
||||
this.stillToDivide = remaining;
|
||||
}
|
||||
|
||||
public void calculateStillToDivide(String toDistribute, Card source, SpellAbility sa) {
|
||||
// Recalculate this value just in case it's variable
|
||||
if (!this.dividedAsYouChoose) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (StringUtils.isNumeric(toDistribute)) {
|
||||
this.setStillToDivide(Integer.parseInt(toDistribute));
|
||||
} else if ( source == null ) {
|
||||
return; // such calls come from AbilityFactory.readTarget - at this moment we don't yet know X or any other variables
|
||||
} else if (source.getSVar(toDistribute).equals("xPaid")) {
|
||||
this.setStillToDivide(source.getXManaCostPaid());
|
||||
} else {
|
||||
this.setStillToDivide(AbilityUtils.calculateAmount(source, toDistribute, sa));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store divided amount relative to a specific card/player.
|
||||
* @param tgt the targeted object
|
||||
* @param portionAllocated the divided portion allocated
|
||||
*/
|
||||
public final void addDividedAllocation(final Object tgt, final Integer portionAllocated) {
|
||||
this.dividedMap.remove(tgt);
|
||||
this.dividedMap.put(tgt, portionAllocated);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the divided amount relative to a specific card/player.
|
||||
* @param tgt the targeted object
|
||||
* @return an int.
|
||||
*/
|
||||
public int getDividedValue(Object tgt) {
|
||||
return this.dividedMap.get(tgt);
|
||||
}
|
||||
|
||||
public HashMap<Object, Integer> getDividedMap() {
|
||||
return this.dividedMap;
|
||||
}
|
||||
|
||||
public final void applyTargetTextChanges(final SpellAbility sa) {
|
||||
for (int i = 0; i < validTgts.length; i++) {
|
||||
validTgts[i] = AbilityUtils.applyAbilityTextChangeEffects(originalValidTgts[i], sa);
|
||||
}
|
||||
}
|
||||
|
||||
public final void changeValidTargets(final String[] validTgts) {
|
||||
this.originalValidTgts = validTgts;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -781,8 +781,7 @@ public final class StaticAbilityContinuous {
|
||||
// add Replacement effects
|
||||
if (addReplacements != null) {
|
||||
for (String rep : addReplacements) {
|
||||
final ReplacementEffect actualRep = ReplacementHandler.parseReplacement(rep, affectedCard, false);
|
||||
actualRep.setIntrinsic(false);
|
||||
final ReplacementEffect actualRep = ReplacementHandler.parseReplacement(rep, affectedCard, false, stAb);
|
||||
addedReplacementEffects.add(actualRep);
|
||||
}
|
||||
}
|
||||
@@ -790,17 +789,12 @@ public final class StaticAbilityContinuous {
|
||||
// add triggers
|
||||
if (addTriggers != null) {
|
||||
for (final String trigger : addTriggers) {
|
||||
final Trigger actualTrigger = TriggerHandler.parseTrigger(trigger, affectedCard, false);
|
||||
final Trigger actualTrigger = TriggerHandler.parseTrigger(trigger, affectedCard, false, stAb);
|
||||
// if the trigger has Execute param, which most trigger gained by Static Abilties should have
|
||||
// turn them into SpellAbility object before adding to card
|
||||
// with that the TargetedCard does not need the Svars added to them anymore
|
||||
// but only do it if the trigger doesn't already have a overriding ability
|
||||
if (actualTrigger.hasParam("Execute") && actualTrigger.getOverridingAbility() == null) {
|
||||
// set overriding ability to the trigger
|
||||
actualTrigger.setOverridingAbility(AbilityFactory.getAbility(affectedCard, actualTrigger.getParam("Execute"), stAb));
|
||||
}
|
||||
actualTrigger.setOriginalHost(hostCard);
|
||||
actualTrigger.setIntrinsic(false);
|
||||
addedTrigger.add(actualTrigger);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package forge.game.trigger;
|
||||
|
||||
import forge.game.Game;
|
||||
import forge.game.GameEntity;
|
||||
import forge.game.IHasSVars;
|
||||
import forge.game.TriggerReplacementBase;
|
||||
import forge.game.ability.AbilityFactory;
|
||||
import forge.game.ability.AbilityKey;
|
||||
@@ -562,12 +563,16 @@ public abstract class Trigger extends TriggerReplacementBase {
|
||||
}
|
||||
}
|
||||
|
||||
public SpellAbility ensureAbility() {
|
||||
public SpellAbility ensureAbility(final IHasSVars sVarHolder) {
|
||||
SpellAbility sa = getOverridingAbility();
|
||||
if (sa == null && hasParam("Execute")) {
|
||||
sa = AbilityFactory.getAbility(getHostCard(), getParam("Execute"));
|
||||
sa = AbilityFactory.getAbility(getHostCard(), getParam("Execute"), sVarHolder);
|
||||
setOverridingAbility(sa);
|
||||
}
|
||||
return sa;
|
||||
}
|
||||
|
||||
public SpellAbility ensureAbility() {
|
||||
return ensureAbility(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ import forge.game.card.Card;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.util.Localizer;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -64,9 +63,8 @@ public class TriggerBecomesTargetOnce extends Trigger {
|
||||
}
|
||||
}
|
||||
if (hasParam("ValidTarget")) {
|
||||
List<GameObject> targets = (List<GameObject>) runParams.get(AbilityKey.Targets);
|
||||
boolean valid = false;
|
||||
for (GameObject b : targets) {
|
||||
for (GameObject b : (Iterable<GameObject>) runParams.get(AbilityKey.Targets)) {
|
||||
if (matchesValid(b, getParam("ValidTarget").split(","), this.getHostCard())) {
|
||||
valid = true;
|
||||
break;
|
||||
|
||||
@@ -19,6 +19,7 @@ package forge.game.trigger;
|
||||
|
||||
import forge.game.Game;
|
||||
import forge.game.GlobalRuleChange;
|
||||
import forge.game.IHasSVars;
|
||||
import forge.game.ability.AbilityFactory;
|
||||
import forge.game.ability.AbilityUtils;
|
||||
import forge.game.ability.ApiType;
|
||||
@@ -124,9 +125,13 @@ public class TriggerHandler {
|
||||
}
|
||||
|
||||
public static Trigger parseTrigger(final String trigParse, final Card host, final boolean intrinsic) {
|
||||
return parseTrigger(trigParse, host, intrinsic, host);
|
||||
}
|
||||
|
||||
public static Trigger parseTrigger(final String trigParse, final Card host, final boolean intrinsic, final IHasSVars sVarHolder) {
|
||||
try {
|
||||
final Map<String, String> mapParams = TriggerHandler.parseParams(trigParse);
|
||||
return TriggerHandler.parseTrigger(mapParams, host, intrinsic);
|
||||
return TriggerHandler.parseTrigger(mapParams, host, intrinsic, sVarHolder);
|
||||
} catch (Exception e) {
|
||||
String msg = "TriggerHandler:parseTrigger failed to parse";
|
||||
Sentry.getContext().recordBreadcrumb(
|
||||
@@ -138,12 +143,15 @@ public class TriggerHandler {
|
||||
}
|
||||
}
|
||||
|
||||
public static Trigger parseTrigger(final Map<String, String> mapParams, final Card host, final boolean intrinsic) {
|
||||
public static Trigger parseTrigger(final Map<String, String> mapParams, final Card host, final boolean intrinsic, final IHasSVars sVarHolder) {
|
||||
Trigger ret = null;
|
||||
|
||||
try {
|
||||
final TriggerType type = TriggerType.smartValueOf(mapParams.get("Mode"));
|
||||
ret = type.createTrigger(mapParams, host, intrinsic);
|
||||
if (sVarHolder != null) {
|
||||
ret.ensureAbility(sVarHolder);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
String msg = "TriggerHandler:parseTrigger failed to parse";
|
||||
Sentry.getContext().recordBreadcrumb(
|
||||
@@ -170,13 +178,7 @@ public class TriggerHandler {
|
||||
if (wt.getTriggers() != null)
|
||||
continue;
|
||||
|
||||
List<Trigger> trigger = Lists.newArrayList();
|
||||
for (final Trigger t : activeTriggers) {
|
||||
if (canRunTrigger(t,wt.getMode(),wt.getParams())) {
|
||||
trigger.add(t);
|
||||
}
|
||||
}
|
||||
wt.setTriggers(trigger);
|
||||
wt.setTriggers(getActiveTrigger(wt.getMode(), wt.getParams()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -708,4 +710,14 @@ public class TriggerHandler {
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
public List<Trigger> getActiveTrigger(final TriggerType mode, final Map<AbilityKey, Object> runParams) {
|
||||
List<Trigger> trigger = Lists.newArrayList();
|
||||
for (final Trigger t : activeTriggers) {
|
||||
if (canRunTrigger(t, mode, runParams)) {
|
||||
trigger.add(t);
|
||||
}
|
||||
}
|
||||
return trigger;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ package forge.game.trigger;
|
||||
import forge.card.MagicColor;
|
||||
import forge.game.ability.AbilityKey;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.util.Localizer;
|
||||
|
||||
@@ -68,25 +67,19 @@ public class TriggerTapsForMana extends Trigger {
|
||||
}
|
||||
|
||||
if (hasParam("ValidCard")) {
|
||||
final Card tapper = (Card) runParams.get(AbilityKey.Card);
|
||||
if (!tapper.isValid(getParam("ValidCard").split(","), this.getHostCard().getController(),
|
||||
this.getHostCard(), null)) {
|
||||
if (!matchesValid(runParams.get(AbilityKey.Card), getParam("ValidCard").split(","), getHostCard())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasParam("Player")) {
|
||||
final Player player = (Player) runParams.get(AbilityKey.Player);
|
||||
if (!player.isValid(getParam("Player").split(","), this.getHostCard().getController(), this.getHostCard(), null)) {
|
||||
if (!matchesValid(runParams.get(AbilityKey.Player), getParam("Player").split(","), getHostCard())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasParam("Activator")) {
|
||||
final SpellAbility sa = (SpellAbility) runParams.get(AbilityKey.AbilityMana);
|
||||
if (sa == null) return false;
|
||||
final Player activator = sa.getActivatingPlayer();
|
||||
if (!activator.isValid(getParam("Activator").split(","), this.getHostCard().getController(), this.getHostCard(), null)) {
|
||||
if (!matchesValid(runParams.get(AbilityKey.Activator), getParam("Activator").split(","), getHostCard())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -113,7 +106,7 @@ public class TriggerTapsForMana extends Trigger {
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public final void setTriggeringObjects(final SpellAbility sa, Map<AbilityKey, Object> runParams) {
|
||||
sa.setTriggeringObjectsFrom(runParams, AbilityKey.Card, AbilityKey.Player, AbilityKey.Produced);
|
||||
sa.setTriggeringObjectsFrom(runParams, AbilityKey.Card, AbilityKey.Player, AbilityKey.Produced, AbilityKey.Activator);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -247,7 +247,7 @@ public class MagicStack /* extends MyObservable */ implements Iterable<SpellAbil
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasLegalTargeting(sp, source)) {
|
||||
if (!sp.isCopied() && !hasLegalTargeting(sp, source)) {
|
||||
String str = source + " - [Couldn't add to stack, failed to target] - " + sp.getDescription();
|
||||
System.err.println(str + sp.getAllTargetChoices());
|
||||
game.getGameLog().add(GameLogEntryType.STACK_ADD, str);
|
||||
|
||||
Reference in New Issue
Block a user