Commit c1b818e8 authored by Hanmac's avatar Hanmac

DebuffEffect: improved the removing of Protection, while something has...

DebuffEffect: improved the removing of Protection, while something has protection from all colors or some special wording like Spectra Ward
parent 91cb47a6
package forge.game.ability.effects;
import forge.GameCommand;
import forge.card.MagicColor;
import forge.game.Game;
import forge.game.ability.SpellAbilityEffect;
import forge.game.card.Card;
......@@ -11,6 +12,8 @@ import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
public class DebuffEffect extends SpellAbilityEffect {
@Override
......@@ -64,6 +67,8 @@ public class DebuffEffect extends SpellAbilityEffect {
for (final Card tgtC : getTargetCards(sa)) {
final List<String> hadIntrinsic = new ArrayList<String>();
final List<String> addedKW = new ArrayList<String>();
final List<String> removedKW = new ArrayList<String>();
if (tgtC.isInPlay() && tgtC.canBeTargetedBy(sa)) {
if (sa.hasParam("AllSuffixKeywords")) {
String suffix = sa.getParam("AllSuffixKeywords");
......@@ -73,14 +78,79 @@ public class DebuffEffect extends SpellAbilityEffect {
}
}
}
// special for Protection:Card.<color>:Protection from <color>:*
for (final String keyword : tgtC.getKeywords()) {
if (keyword.startsWith("Protection:")) {
for (final String kw : kws) {
if (keyword.contains(":" + kw + ":"))
removedKW.add(keyword);
}
}
}
boolean ProtectionFromColor = false;
for (final String kw : kws) {
// Check if some of the Keywords are Protection from <color>
if (!ProtectionFromColor && kw.startsWith("Protection from ")) {
for(byte col : MagicColor.WUBRG) {
final String colString = MagicColor.toLongString(col);
if (kw.endsWith(colString.toLowerCase())) {
ProtectionFromColor = true;
}
}
}
if (tgtC.getCurrentState().hasIntrinsicKeyword(kw)) {
hadIntrinsic.add(kw);
}
tgtC.removeIntrinsicKeyword(kw);
tgtC.removeAllExtrinsicKeyword(kw);
}
tgtC.addChangedCardKeywords(new ArrayList<String>(), kws, false, timestamp);
// Split "Protection from all colors" into extra Protection from <color>
String allColors = "Protection from all colors";
if (ProtectionFromColor && tgtC.hasKeyword(allColors)) {
final List<String> allColorsProtect = new ArrayList<String>();
for(byte col : MagicColor.WUBRG) {
allColorsProtect.add("Protection from " + MagicColor.toLongString(col).toLowerCase());
}
if (tgtC.getCurrentState().hasIntrinsicKeyword(allColors)) {
hadIntrinsic.add(allColors);
}
tgtC.removeIntrinsicKeyword(allColors);
tgtC.removeAllExtrinsicKeyword(allColors);
allColorsProtect.removeAll(kws);
addedKW.addAll(allColorsProtect);
removedKW.add(allColors);
}
// Extra for Spectra Ward
allColors = "Protection:Card.nonColorless:Protection from all colors:Aura";
if (ProtectionFromColor && tgtC.hasKeyword(allColors)) {
final List<String> allColorsProtect = new ArrayList<String>();
for(byte col : MagicColor.WUBRG) {
final String colString = MagicColor.toLongString(col);
if (!kws.contains("Protection from " + colString)) {
allColorsProtect.add(
"Protection:Card." + StringUtils.capitalize(colString) +
":Protection from " + colString + ":Aura"
);
}
}
if (tgtC.getCurrentState().hasIntrinsicKeyword(allColors)) {
hadIntrinsic.add(allColors);
}
tgtC.removeIntrinsicKeyword(allColors);
tgtC.removeAllExtrinsicKeyword(allColors);
addedKW.addAll(allColorsProtect);
removedKW.add(allColors);
}
removedKW.addAll(kws);
tgtC.addChangedCardKeywords(addedKW, removedKW, false, timestamp);
}
if (!sa.hasParam("Permanent")) {
game.getEndOfTurn().addUntil(new GameCommand() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment