Skip to content

Commit

Permalink
Averna: use ReplaceCascade Effect
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanmac committed Jan 12, 2025
1 parent 3fb07c5 commit d3d4dab
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 14 deletions.
4 changes: 0 additions & 4 deletions forge-game/src/main/java/forge/game/ability/AbilityUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2295,10 +2295,6 @@ public static int xCount(Card c, final String s, final CardTraitBase ctb) {
if (sq[0].equals("ExtraTurn")) {
return doXMath(calculateAmount(c, sq[game.getPhaseHandler().getPlayerTurn().isExtraTurn() ? 1 : 2], ctb), expr, c, ctb);
}
if (sq[0].equals("Averna")) {
String str = "As you cascade, you may put a land card from among the exiled cards onto the battlefield tapped.";
return doXMath(player.getKeywords().getAmount(str), expr, c, ctb);
}
if (sq[0].equals("YourStartingLife")) {
return doXMath(player.getStartingLife(), expr, c, ctb);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
import forge.game.card.CardPredicates;
import forge.game.card.CardZoneTable;
import forge.game.event.GameEventCombatChanged;
import forge.game.keyword.Keyword;
import forge.game.player.Player;
import forge.game.replacement.ReplacementType;
import forge.game.spellability.SpellAbility;
import forge.game.zone.PlayerZone;
import forge.game.zone.ZoneType;
Expand Down Expand Up @@ -294,6 +296,17 @@ public void resolve(SpellAbility sa) {
if (shuffle) {
p.shuffle(sa);
}

if (sa.isKeyword(Keyword.CASCADE)) {
Map<AbilityKey, Object> runParams = AbilityKey.mapFromAffected(p);
runParams.put(AbilityKey.Cards, revealed);
game.getReplacementHandler().run(ReplacementType.Cascade, runParams);

if (sa.hasParam("RememberRevealed")) {
final ZoneType removeZone = foundDest;
host.removeRemembered(revealed.filter(c -> !c.isInZone(removeZone)));
}
}
} // end foreach player
if (combatChanged) {
game.updateCombatForView();
Expand Down
10 changes: 1 addition & 9 deletions forge-game/src/main/java/forge/game/card/CardFactoryUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -825,18 +825,10 @@ public static void addTriggerAbility(final KeywordInterface inst, final Card car
SpellAbility dig = AbilityFactory.getAbility(abString, card);
dig.setSVar("CascadeX", "Count$CardManaCost");

final String dbLandPut = "DB$ ChangeZone | ConditionCheckSVar$ X | ConditionSVarCompare$ GE1" +
" | Hidden$ True | Origin$ Exile | Destination$ Battlefield | ChangeType$ Land.IsRemembered" +
" | ChangeNum$ X | Tapped$ True | ForgetChanged$ True" +
" | SelectPrompt$ You may select a land to put on the battlefield tapped";
AbilitySub landPut = (AbilitySub)AbilityFactory.getAbility(dbLandPut, card);
landPut.setSVar("X", "Count$Averna");
dig.setSubAbility(landPut);

final String dbCascadeCast = "DB$ Play | Defined$ Imprinted | WithoutManaCost$ True | Optional$ True | ValidSA$ Spell.cmcLTCascadeX";
AbilitySub cascadeCast = (AbilitySub)AbilityFactory.getAbility(dbCascadeCast, card);
cascadeCast.setSVar("CascadeX", "Count$CardManaCost");
landPut.setSubAbility(cascadeCast);
dig.setSubAbility(cascadeCast);

final String dbMoveToLib = "DB$ ChangeZoneAll | ChangeType$ Card.IsRemembered,Card.IsImprinted"
+ " | Origin$ Exile | Destination$ Library | RandomOrder$ True | LibraryPosition$ -1";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package forge.game.replacement;

import java.util.Map;

import forge.game.ability.AbilityKey;
import forge.game.card.Card;
import forge.game.spellability.SpellAbility;

public class ReplaceCascade extends ReplacementEffect {

public ReplaceCascade(Map<String, String> map, Card host, boolean intrinsic) {
super(map, host, intrinsic);
}

@Override
public boolean canReplace(Map<AbilityKey, Object> runParams) {
if (!matchesValidParam("ValidPlayer", runParams.get(AbilityKey.Affected))) {
return false;
}
return true;
}

@Override
public void setReplacingObjects(Map<AbilityKey, Object> runParams, SpellAbility sa) {
sa.setReplacingObject(AbilityKey.Player, runParams.get(AbilityKey.Affected));
sa.setReplacingObjectsFrom(runParams, AbilityKey.Cards);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public enum ReplacementType {
Attached(ReplaceAttached.class),
BeginPhase(ReplaceBeginPhase.class),
BeginTurn(ReplaceBeginTurn.class),
Cascade(ReplaceCascade.class),
Counter(ReplaceCounter.class),
CopySpell(ReplaceCopySpell.class),
CreateToken(ReplaceToken.class),
Expand Down
3 changes: 2 additions & 1 deletion forge-gui/res/cardsfolder/a/averna_the_chaos_bloom.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ Name:Averna, the Chaos Bloom
ManaCost:G U R
Types:Legendary Creature Elemental Shaman
PT:4/2
S:Mode$ Continuous | Affected$ You | AddKeyword$ As you cascade, you may put a land card from among the exiled cards onto the battlefield tapped. | Description$ As you cascade, you may put a land card from among the exiled cards onto the battlefield tapped. (Do this after the last card is exiled but before deciding whether to cast a nonland card.)
R:Event$ Cascade | ValidPlayer$ You | ActiveZones$ Battlefield | ReplaceWith$ DBLand | ReplacementResult$ Updated | Description$ As you cascade, you may put a land card from among the exiled cards onto the battlefield tapped. (Do this after the last card is exiled but before deciding whether to cast a nonland card.)
SVar:DBLand:DB$ ChangeZone | Hidden$ True | Origin$ Exile | ChooseFromDefined$ ReplacedCards | ChangeNum$ 1 | Destination$ Battlefield | ChangeType$ Land | Tapped$ True
Oracle:As you cascade, you may put a land card from among the exiled cards onto the battlefield tapped. (Do this after the last card is exiled but before deciding whether to cast a nonland card.)

0 comments on commit d3d4dab

Please sign in to comment.