Skip to content

Commit

Permalink
improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Northmoc committed Nov 15, 2023
1 parent 14205e0 commit 06a71ce
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package forge.game.ability.effects;

import com.google.common.collect.Maps;
import forge.game.Game;
import forge.game.ability.AbilityKey;
import forge.game.ability.AbilityUtils;
import forge.game.ability.SpellAbilityEffect;
import forge.game.card.Card;
import forge.game.card.CardCollection;
import forge.game.card.CardLists;
import forge.game.card.CardCollectionView;
import forge.game.player.Player;
import forge.game.spellability.AbilitySub;
import forge.game.spellability.SpellAbility;
Expand All @@ -27,22 +29,32 @@ protected String getStackDescription(SpellAbility sa) {
public void resolve(SpellAbility sa) {
final Card card = sa.getHostCard();
final Player activator = sa.getActivatingPlayer();
final String valid = sa.getParamOrDefault("ValidCards", "");
final Game game = activator.getGame();
Map<Player, CardCollection> untapMap = Maps.newHashMap();

for (Player p : getTargetPlayers(sa)) {
for (Card c : CardLists.getValidCards(p.getCardsIn(ZoneType.Battlefield), valid, activator, card, sa)) {
if (c.untap(true)) {
untapMap.computeIfAbsent(p, i -> new CardCollection()).add(c);
CardCollectionView list = !sa.usesTargeting() && !sa.hasParam("Defined") ?
game.getCardsIn(ZoneType.Battlefield) :
getDefinedPlayersOrTargeted(sa).getCardsIn(ZoneType.Battlefield);

list = AbilityUtils.filterListByType(list, sa.getParamOrDefault("ValidCards", ""), sa);

Player untapper = activator;

for (Card c : list) {
if (sa.hasParam("ControllerUntaps")) {
untapper = c.getController();
}
if (c.untap(true)) {
untapMap.computeIfAbsent(untapper, i -> new CardCollection()).add(c);
if (sa.hasParam("RememberUntapped")) card.addRemembered(c);
}

}
}

if (!untapMap.isEmpty()) {
final Map<AbilityKey, Object> runParams = AbilityKey.newMap();
runParams.put(AbilityKey.Map, untapMap);
activator.getGame().getTriggerHandler().runTrigger(TriggerType.UntapAll, runParams, false);
game.getTriggerHandler().runTrigger(TriggerType.UntapAll, runParams, false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected String getStackDescription(SpellAbility sa) {
@Override
public void resolve(SpellAbility sa) {
final Player activator = sa.getActivatingPlayer();
final boolean ETB = sa.hasParam("ETB");
final boolean etb = sa.hasParam("ETB");

if (sa.hasParam("UntapUpTo")) {
untapChoose(sa, false);
Expand All @@ -62,12 +62,12 @@ public void resolve(SpellAbility sa) {
if (tgtC.isInPlay()) {
if (tgtC.untap(true)) untapped.add(tgtC);
}
if (ETB) {
if (etb) {
// do not fire triggers
tgtC.setTapped(false);
}
}
if (!untapped.isEmpty() && !ETB) {
if (!untapped.isEmpty() && !etb) {
final Map<AbilityKey, Object> runParams = AbilityKey.newMap();
final Map<Player, CardCollection> map = Maps.newHashMap();
map.put(activator, untapped);
Expand Down
6 changes: 3 additions & 3 deletions forge-gui/res/cardsfolder/g/great_oak_guardian.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Types:Creature Treefolk
PT:4/5
K:Flash
K:Reach
T:Mode$ ChangesZone | Origin$ Any | Destination$ Battlefield | ValidCard$ Card.Self | Execute$ TrigPumpAll | TriggerDescription$ When Great Oak Guardian enters the battlefield, creatures target player controls get +2/+2 until end of turn. Untap them.
SVar:TrigPumpAll:DB$ PumpAll | ValidTgts$ Player | TgtPrompt$ Select target player | ValidCards$ Creature | NumAtt$ +2 | NumDef$ +2 | SubAbility$ DBUntapAll
SVar:DBUntapAll:DB$ UntapAll | Defined$ Targeted | ValidCards$ Creature
T:Mode$ ChangesZone | Origin$ Any | Destination$ Battlefield | ValidCard$ Card.Self | Execute$ TrigPumpAll | TriggerDescription$ When CARDNAME enters the battlefield, creatures target player controls get +2/+2 until end of turn. Untap them.
SVar:TrigPumpAll:DB$ PumpAll | ValidTgts$ Player | ValidCards$ Creature | NumAtt$ +2 | NumDef$ +2 | SubAbility$ DBUntapAll
SVar:DBUntapAll:DB$ UntapAll | ValidCards$ Creature.TargetedPlayerCtrl
Oracle:Flash (You may cast this spell any time you could cast an instant.)\nReach\nWhen Great Oak Guardian enters the battlefield, creatures target player controls get +2/+2 until end of turn. Untap them.
2 changes: 1 addition & 1 deletion forge-gui/res/cardsfolder/r/reins_of_power.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Name:Reins of Power
ManaCost:2 U U
Types:Instant
A:SP$ UntapAll | Cost$ 2 U U | ValidTgts$ Opponent | TgtPrompt$ Select target opponent | ValidCards$ Creature.YouCtrl,Creature.TargetedPlayerCtrl | SubAbility$ DBGainCtrl | SpellDescription$ Untap all creatures you control and all creatures target opponent controls. You and that opponent each gain control of all creatures the other controls until end of turn. Those creatures gain haste until end of turn.
A:SP$ UntapAll | ValidTgts$ Opponent | Defined$ TargetedAndYou | ValidCards$ Creature | SubAbility$ DBGainCtrl | SpellDescription$ Untap all creatures you control and all creatures target opponent controls. You and that opponent each gain control of all creatures the other controls until end of turn. Those creatures gain haste until end of turn.
SVar:DBGainCtrl:DB$ GainControl | AllValid$ Creature.TargetedPlayerCtrl | AddKWs$ Haste | NewController$ You | LoseControl$ EOT | RememberControlled$ True | StackDescription$ None | SubAbility$ DBGainCtrlOpp
SVar:DBGainCtrlOpp:DB$ GainControl | AllValid$ Creature.IsNotRemembered+YouCtrl | AddKWs$ Haste | NewController$ Targeted | LoseControl$ EOT | StackDescription$ None | SubAbility$ DBCleanup
SVar:DBCleanup:DB$ Cleanup | ClearRemembered$ True
Expand Down
6 changes: 4 additions & 2 deletions forge-gui/res/cardsfolder/t/twist_allegiance.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
Name:Twist Allegiance
ManaCost:6 R
Types:Sorcery
A:SP$ GainControl | Cost$ 6 R | ValidTgts$ Opponent | TgtPrompt$ Select target opponent | AllValid$ Creature.TargetedPlayerCtrl | AddKWs$ Haste | Untap$ True | NewController$ You | LoseControl$ EOT | RememberControlled$ True | StackDescription$ SpellDescription | SubAbility$ DBGainCtrlOpp | SpellDescription$ You and target opponent each gain control of all creatures the other controls until end of turn. Untap those creatures. Those creatures gain haste until end of turn.
SVar:DBGainCtrlOpp:DB$ GainControl | AllValid$ Creature.IsNotRemembered+YouCtrl | AddKWs$ Haste | NewController$ Targeted | Untap$ True | LoseControl$ EOT | StackDescription$ None | SubAbility$ DBCleanup
A:SP$ GainControl | ValidTgts$ Opponent | AllValid$ Creature.TargetedPlayerCtrl | NewController$ You | LoseControl$ EOT | RememberControlled$ True | StackDescription$ REP You_{p:You} & target opponent_{p:Targeted} | SubAbility$ DBGainCtrlOpp | SpellDescription$ You and target opponent each gain control of all creatures the other controls until end of turn. Untap those creatures. Those creatures gain haste until end of turn.
SVar:DBGainCtrlOpp:DB$ GainControl | AllValid$ Creature.IsNotRemembered+YouCtrl | NewController$ Targeted | LoseControl$ EOT | RememberControlled$ True | StackDescription$ None | SubAbility$ DBUntapAll
SVar:DBDUntapAll:DB$ UntapAll | ValidCards$ Creature.IsRemembered | SubAbility$ DBPumpAll
SVar:PumpAll:DB$ PumpAll | ValidCards$ Creature.IsRemembered | KW$ Haste | SubAbility$ DBCleanup
SVar:DBCleanup:DB$ Cleanup | ClearRemembered$ True
AI:RemoveDeck:All
Oracle:You and target opponent each gain control of all creatures the other controls until end of turn. Untap those creatures. Those creatures gain haste until end of turn.

0 comments on commit 06a71ce

Please sign in to comment.