PumpEffect: make DefinedKW better Keywords

This commit is contained in:
Hans Mackowiak
2023-04-05 07:16:50 +02:00
parent fede3c1749
commit c763b597cb
8 changed files with 54 additions and 48 deletions

View File

@@ -1004,6 +1004,14 @@ public class AbilityUtils {
players.addAll(tc.getTargetPlayers()); players.addAll(tc.getTargetPlayers());
} }
} }
else if (defined.startsWith("PlayerUID_")) {
int id = Integer.parseInt(defined.split("PlayerUID_")[1]);
for (Player p : game.getRegisteredPlayers()) {
if (p.getId() == id) {
players.add(p);
}
}
}
else if (defined.equals("ParentTarget") && sa instanceof SpellAbility) { else if (defined.equals("ParentTarget") && sa instanceof SpellAbility) {
final SpellAbility parent = ((SpellAbility)sa).getParentTargetingPlayer(); final SpellAbility parent = ((SpellAbility)sa).getParentTargetingPlayer();
if (parent != null) { if (parent != null) {

View File

@@ -3,6 +3,8 @@ package forge.game.ability.effects;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.apache.commons.lang3.StringUtils;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
@@ -298,39 +300,47 @@ public class PumpEffect extends SpellAbilityEffect {
if (sa.hasParam("DefinedKW")) { if (sa.hasParam("DefinedKW")) {
String defined = sa.getParam("DefinedKW"); String defined = sa.getParam("DefinedKW");
String replaced = "";
String name = "";
if (defined.equals("ChosenType")) { if (defined.equals("ChosenType")) {
replaced = host.getChosenType(); if (!host.hasChosenType()) {
} else if (defined.equals("ActivatorName")) { return;
replaced = activator.getName(); }
String replaced = host.getChosenType();
for (int i = 0; i < keywords.size(); i++) {
String s = keywords.get(i);
s = s.replaceAll(defined, replaced);
keywords.set(i, s);
}
} else if (defined.equals("ChosenPlayer")) { } else if (defined.equals("ChosenPlayer")) {
replaced = host.getChosenPlayer().getName(); if (!host.hasChosenPlayer()) {
} else if (defined.endsWith("Player")) { return;
}
Player cp = host.getChosenPlayer();
for (int i = 0; i < keywords.size(); i++) {
String s = keywords.get(i);
s = s.replaceAll("ChosenPlayerUID", String.valueOf(cp.getId()));
s = s.replaceAll("ChosenPlayerName", cp.getName());
keywords.set(i, s);
}
} else if (defined.equals("You") || defined.endsWith("Player")) {
PlayerCollection players = AbilityUtils.getDefinedPlayers(host, defined, sa); PlayerCollection players = AbilityUtils.getDefinedPlayers(host, defined, sa);
if (players.isEmpty()) return; if (players.isEmpty()) return;
replaced = "PlayerUID_" + players.get(0).getId(); String replacedID = String.valueOf(players.get(0).getId());
name = players.get(0).getName(); String replacedName = players.get(0).getName();
for (int i = 0; i < keywords.size(); i++) {
String s = keywords.get(i);
s = s.replaceAll("ChosenPlayerUID", replacedID);
s = s.replaceAll("ChosenPlayerName", replacedName);
keywords.set(i, s);
}
} else if (defined.equals("ChosenColor")) { } else if (defined.equals("ChosenColor")) {
String color = host.getChosenColor(); if (!host.hasChosenColor()) {
replaced = color.substring(0, 1).toUpperCase() + color.substring(1); return;
} }
for (int i = 0; i < keywords.size(); i++) { for (int i = 0; i < keywords.size(); i++) {
keywords.set(i, TextUtil.fastReplace(keywords.get(i), defined, replaced)); String s = keywords.get(i);
if (keywords.get(i).startsWith("Protection:") && !name.equals("")) { s = s.replaceAll("ChosenColor", StringUtils.capitalize(host.getChosenColor()));
List<String> parts = Arrays.asList(keywords.get(i).split(":")); s = s.replaceAll("chosenColor", host.getChosenColor().toLowerCase());
String desc = parts.get(2); keywords.set(i, s);
if (desc.contains("PlayerUID")) {
parts.set(2, TextUtil.fastReplace(desc, replaced, name));
StringBuilder mod = new StringBuilder();
for (int n = 0; n < parts.size(); n++) {
mod.append(parts.get(n));
if (n + 1 < parts.size()) {
mod.append(":");
}
}
keywords.set(i, mod.toString());
}
} }
} }
} }

View File

@@ -721,9 +721,6 @@ public class CardFactoryUtil {
validSource = "nonColorless" + (damage ? "Source" : ""); validSource = "nonColorless" + (damage ? "Source" : "");
} else if (protectType.equals("everything")) { } else if (protectType.equals("everything")) {
return ""; return "";
} else if (protectType.startsWith("opponent of ")) {
final String playerName = protectType.substring("opponent of ".length());
validSource = "ControlledBy Player.OpponentOf PlayerNamed_" + playerName;
} else { } else {
validSource = CardType.getSingularType(protectType); validSource = CardType.getSingularType(protectType);
} }
@@ -2599,7 +2596,7 @@ public class CardFactoryUtil {
if (isCombat) { if (isCombat) {
rep += "| IsCombat$ True"; rep += "| IsCombat$ True";
} }
rep += "| Secondary$ True | TiedToKeyword$ " + keyword + " | Description$ " + keyword; rep += "| Secondary$ True | Description$ " + keyword;
if (from) { if (from) {
String fromRep = rep + " | ValidSource$ Card.Self"; String fromRep = rep + " | ValidSource$ Card.Self";
@@ -2621,7 +2618,7 @@ public class CardFactoryUtil {
if (!validSource.isEmpty()) { if (!validSource.isEmpty()) {
rep += " | ValidSource$ " + validSource; rep += " | ValidSource$ " + validSource;
} }
rep += " | Secondary$ True | TiedToKeyword$ " + keyword + " | Description$ " + keyword; rep += " | Secondary$ True | Description$ " + keyword;
ReplacementEffect re = ReplacementHandler.parseReplacement(rep, host, intrinsic, card); ReplacementEffect re = ReplacementHandler.parseReplacement(rep, host, intrinsic, card);
inst.addReplacement(re); inst.addReplacement(re);

View File

@@ -143,15 +143,6 @@ public class ReplacementHandler {
} }
for (final ReplacementEffect replacementEffect : c.getReplacementEffects()) { for (final ReplacementEffect replacementEffect : c.getReplacementEffects()) {
// Replacement effects that are tied to keywords (e.g. damage prevention effects - if the keyword is removed, the replacement
// effect should be inactive)
if (replacementEffect.hasParam("TiedToKeyword")) {
String kw = replacementEffect.getParam("TiedToKeyword");
if (!c.hasKeyword(kw)) {
continue;
}
}
if (!replacementEffect.hasRun() && !hasRun.contains(replacementEffect) if (!replacementEffect.hasRun() && !hasRun.contains(replacementEffect)
&& (layer == null || replacementEffect.getLayer() == layer) && (layer == null || replacementEffect.getLayer() == layer)
&& event.equals(replacementEffect.getMode()) && event.equals(replacementEffect.getMode())

View File

@@ -3,5 +3,5 @@ ManaCost:1 W
Types:Creature Kor Soldier Types:Creature Kor Soldier
PT:2/2 PT:2/2
K:Vigilance K:Vigilance
A:AB$ Pump | Cost$ T Sac<1/CARDNAME> | ValidTgts$ Permanent.YouCtrl | TgtPrompt$ Select target permanent you control | KW$ Protection from opponent of ActivatorName | DefinedKW$ ActivatorName | SpellDescription$ Target permanent you control gains protection from each of your opponents until end of turn. (It can't be blocked, targeted, dealt damage, enchanted, or equipped by anything controlled by those players.) A:AB$ Pump | Cost$ T Sac<1/CARDNAME> | ValidTgts$ Permanent.YouCtrl | TgtPrompt$ Select target permanent you control | KW$ Protection:Card.ControlledBy Player.OpponentOf PlayerUID_ChosenPlayerUID,Emblem.ControlledBy Player.OpponentOf PlayerUID_ChosenPlayerUID:Protection from all opponents of ChosenPlayerName | DefinedKW$ You | SpellDescription$ Target permanent you control gains protection from each of your opponents until end of turn. (It can't be blocked, targeted, dealt damage, enchanted, or equipped by anything controlled by those players.)
Oracle:Vigilance\n{T}, Sacrifice Cliffside Rescuer: Target permanent you control gains protection from each of your opponents until end of turn. (It can't be blocked, targeted, dealt damage, enchanted, or equipped by anything controlled by those players.) Oracle:Vigilance\n{T}, Sacrifice Cliffside Rescuer: Target permanent you control gains protection from each of your opponents until end of turn. (It can't be blocked, targeted, dealt damage, enchanted, or equipped by anything controlled by those players.)

View File

@@ -5,6 +5,6 @@ PT:5/5
K:Flying K:Flying
T:Mode$ ChangesZone | ValidCard$ Card.wasCastByYou+Self | Destination$ Battlefield | Execute$ DBAddTurn | TriggerDescription$ When CARDNAME enters the battlefield, if you cast it, target opponent takes an extra turn after this one. Until your next turn, you and planeswalkers you control gain protection from that player. (You and planeswalkers you control can't be targeted, dealt damage, or enchanted by anything controlled by that player.) T:Mode$ ChangesZone | ValidCard$ Card.wasCastByYou+Self | Destination$ Battlefield | Execute$ DBAddTurn | TriggerDescription$ When CARDNAME enters the battlefield, if you cast it, target opponent takes an extra turn after this one. Until your next turn, you and planeswalkers you control gain protection from that player. (You and planeswalkers you control can't be targeted, dealt damage, or enchanted by anything controlled by that player.)
SVar:DBAddTurn:DB$ AddTurn | ValidTgts$ Opponent | TgtPrompt$ Select target opponent | NumTurns$ 1 | SubAbility$ DBPump SVar:DBAddTurn:DB$ AddTurn | ValidTgts$ Opponent | TgtPrompt$ Select target opponent | NumTurns$ 1 | SubAbility$ DBPump
SVar:DBPump:DB$ Pump | Defined$ You | KW$ Protection:Player.TargetedPlayer:Protection from TargetedPlayer | DefinedKW$ TargetedPlayer | Duration$ UntilYourNextTurn | SubAbility$ DBPumpWalkers SVar:DBPump:DB$ Pump | Defined$ You | KW$ Protection:Player.PlayerUID_ChosenPlayerUID:Protection from ChosenPlayerName | DefinedKW$ TargetedPlayer | Duration$ UntilYourNextTurn | SubAbility$ DBPumpWalkers
SVar:DBPumpWalkers:DB$ Pump | Defined$ Valid Planeswalker.YouCtrl | KW$ Protection:Player.TargetedPlayer:Protection from TargetedPlayer | DefinedKW$ TargetedPlayer | Duration$ UntilYourNextTurn SVar:DBPumpWalkers:DB$ Pump | Defined$ Valid Planeswalker.YouCtrl | KW$ Protection:Player.PlayerUID_ChosenPlayerUID:Protection from ChosenPlayerName | DefinedKW$ TargetedPlayer | Duration$ UntilYourNextTurn
Oracle:Flying\nWhen Eon Frolicker enters the battlefield, if you cast it, target opponent takes an extra turn after this one. Until your next turn, you and planeswalkers you control gain protection from that player. (You and planeswalkers you control can't be targeted, dealt damage, or enchanted by anything controlled by that player.) Oracle:Flying\nWhen Eon Frolicker enters the battlefield, if you cast it, target opponent takes an extra turn after this one. Until your next turn, you and planeswalkers you control gain protection from that player. (You and planeswalkers you control can't be targeted, dealt damage, or enchanted by anything controlled by that player.)

View File

@@ -5,6 +5,6 @@ PT:5/5
K:Flying K:Flying
K:ETBReplacement:Other:ChooseP K:ETBReplacement:Other:ChooseP
SVar:ChooseP:DB$ ChoosePlayer | Defined$ You | Choices$ Player.Opponent | ChoiceTitle$ Choose an opponent | Secretly$ True | SpellDescription$ As CARDNAME enters the battlefield, secretly choose an opponent. SVar:ChooseP:DB$ ChoosePlayer | Defined$ You | Choices$ Player.Opponent | ChoiceTitle$ Choose an opponent | Secretly$ True | SpellDescription$ As CARDNAME enters the battlefield, secretly choose an opponent.
A:AB$ Pump | Cost$ RevealChosenPlayer | Defined$ You | KW$ Protection:Player.ChosenPlayer:Protection from ChosenPlayer | DefinedKW$ ChosenPlayer | SubAbility$ DBPump | GameActivationLimit$ 1 | StackDescription$ {p:You} and | SpellDescription$ You and target permanent you control each gain protection from the chosen player until end of turn. Activate only once. A:AB$ Pump | Cost$ RevealChosenPlayer | Defined$ You | KW$ Protection:Player.PlayerUID_ChosenPlayerUID:Protection from ChosenPlayerName | DefinedKW$ ChosenPlayer | SubAbility$ DBPump | GameActivationLimit$ 1 | StackDescription$ {p:You} and | SpellDescription$ You and target permanent you control each gain protection from the chosen player until end of turn. Activate only once.
SVar:DBPump:DB$ Pump | ValidTgts$ Permanent.YouCtrl | TgtPrompt$ Select target permanent you control | KW$ Protection:Player.ChosenPlayer:Protection from ChosenPlayer | DefinedKW$ ChosenPlayer | StackDescription$ {c:Targeted} each gain protection from {p:ChosenPlayer} until end of turn. Activate only once. SVar:DBPump:DB$ Pump | ValidTgts$ Permanent.YouCtrl | TgtPrompt$ Select target permanent you control | KW$ Protection:Player.PlayerUID_ChosenPlayerUID:Protection from ChosenPlayerName | DefinedKW$ ChosenPlayer | StackDescription$ {c:Targeted} each gain protection from {p:ChosenPlayer} until end of turn. Activate only once.
Oracle:Flying\nAs Guardian Archon enters the battlefield, secretly choose an opponent.\nReveal the player you chose: You and target permanent you control each gain protection from the chosen player until end of turn. Activate only once. Oracle:Flying\nAs Guardian Archon enters the battlefield, secretly choose an opponent.\nReveal the player you chose: You and target permanent you control each gain protection from the chosen player until end of turn. Activate only once.

View File

@@ -9,6 +9,6 @@ SVar:DBChoice:DB$ ChooseCard | Defined$ Player.IsRemembered | Amount$ 1 | MinAmo
SVar:DBPutCounter:DB$ PutCounterAll | ValidCards$ Creature.IsRemembered | CounterType$ P1P1 | CounterNum$ 2 | SubAbility$ DBRememberPlayer SVar:DBPutCounter:DB$ PutCounterAll | ValidCards$ Creature.IsRemembered | CounterType$ P1P1 | CounterNum$ 2 | SubAbility$ DBRememberPlayer
SVar:DBRememberPlayer:DB$ Pump | RememberObjects$ RememberedController | SubAbility$ DBRepeatEach SVar:DBRememberPlayer:DB$ Pump | RememberObjects$ RememberedController | SubAbility$ DBRepeatEach
SVar:DBRepeatEach:DB$ RepeatEach | RepeatPlayers$ Opponent.IsRemembered | RepeatSubAbility$ DBPump | SubAbility$ DBCleanup SVar:DBRepeatEach:DB$ RepeatEach | RepeatPlayers$ Opponent.IsRemembered | RepeatSubAbility$ DBPump | SubAbility$ DBCleanup
SVar:DBPump:DB$ Pump | Defined$ You | KW$ Protection:Player.RememberedPlayer:Protection from RememberedPlayer | DefinedKW$ RememberedPlayer | Duration$ UntilYourNextTurn SVar:DBPump:DB$ Pump | Defined$ You | KW$ Protection:Player.PlayerUID_ChosenPlayerUID:Protection from ChosenPlayerName | DefinedKW$ RememberedPlayer | Duration$ UntilYourNextTurn
SVar:DBCleanup:DB$ Cleanup | ClearChosenCard$ True | ClearRemembered$ True SVar:DBCleanup:DB$ Cleanup | ClearChosenCard$ True | ClearRemembered$ True
Oracle:Commander creatures you own have "When this creature enters the battlefield and at the beginning of your upkeep, each player may put two +1/+1 counters on a creature they control. For each opponent who does, you gain protection from that player until your next turn." (You can't be targeted, dealt damage, or enchanted by anything controlled by that player.) Oracle:Commander creatures you own have "When this creature enters the battlefield and at the beginning of your upkeep, each player may put two +1/+1 counters on a creature they control. For each opponent who does, you gain protection from that player until your next turn." (You can't be targeted, dealt damage, or enchanted by anything controlled by that player.)