mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 20:28:00 +00:00
ChangeZoneEffect: add UntilHostLeavesPlay to use GameCommand instead of StaticTrigger
This commit is contained in:
committed by
Michael Kamensky
parent
19d88abee0
commit
34a813baeb
@@ -362,10 +362,6 @@ public class GameAction {
|
||||
}
|
||||
}
|
||||
zoneFrom.remove(c);
|
||||
if (!zoneTo.is(ZoneType.Exile) && !zoneTo.is(ZoneType.Stack)) {
|
||||
c.setExiledWith(null);
|
||||
c.setExiledBy(null);
|
||||
}
|
||||
|
||||
// cleanup Encoding
|
||||
if (c.hasEncodedCard()) {
|
||||
@@ -379,6 +375,16 @@ public class GameAction {
|
||||
e.removeEncodedCard(c);
|
||||
}
|
||||
}
|
||||
|
||||
if (!zoneTo.is(ZoneType.Exile) && !zoneTo.is(ZoneType.Stack)) {
|
||||
Card with = c.getExiledWith();
|
||||
if (with != null) {
|
||||
with.removeUntilLeavesBattlefield(c);
|
||||
}
|
||||
|
||||
c.setExiledWith(null);
|
||||
c.setExiledBy(null);
|
||||
}
|
||||
}
|
||||
|
||||
// if an adventureCard is put from Stack somewhere else, need to reset to Original State
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Table;
|
||||
|
||||
import forge.GameCommand;
|
||||
import forge.card.CardType;
|
||||
@@ -20,6 +21,7 @@ import forge.game.GameObject;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.card.CardCollection;
|
||||
import forge.game.card.CardFactoryUtil;
|
||||
import forge.game.card.CardZoneTable;
|
||||
import forge.game.combat.Combat;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.player.PlayerCollection;
|
||||
@@ -613,4 +615,32 @@ public abstract class SpellAbilityEffect {
|
||||
}
|
||||
return combatChanged;
|
||||
}
|
||||
|
||||
protected static GameCommand untilHostLeavesPlayCommand(final CardZoneTable triggerList, final Card hostCard) {
|
||||
final Game game = hostCard.getGame();
|
||||
hostCard.addUntilLeavesBattlefield(triggerList.allCards());
|
||||
return new GameCommand() {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
CardZoneTable untilTable = new CardZoneTable();
|
||||
for (Table.Cell<ZoneType, ZoneType, CardCollection> cell : triggerList.cellSet()) {
|
||||
for (Card c : cell.getValue()) {
|
||||
// better check if card didn't changed zones again?
|
||||
Card newCard = c.getZone().getCards().get(c);
|
||||
if (newCard == null || !newCard.equalsWithTimestamp(c)) {
|
||||
continue;
|
||||
}
|
||||
// no cause there?
|
||||
Card movedCard = game.getAction().moveTo(cell.getRowKey(), newCard, null);
|
||||
untilTable.put(cell.getColumnKey(), cell.getRowKey(), movedCard);
|
||||
}
|
||||
}
|
||||
untilTable.triggerChangesZoneAll(game);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,11 @@ public class ChangeZoneAllEffect extends SpellAbilityEffect {
|
||||
|
||||
@Override
|
||||
public void resolve(SpellAbility sa) {
|
||||
//if host is not on the battlefield don't apply
|
||||
if (sa.hasParam("UntilHostLeavesPlay") && !sa.getHostCard().isInPlay()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final ZoneType destination = ZoneType.smartValueOf(sa.getParam("Destination"));
|
||||
final List<ZoneType> origin = ZoneType.listValueOf(sa.getParam("Origin"));
|
||||
|
||||
@@ -260,6 +265,10 @@ public class ChangeZoneAllEffect extends SpellAbilityEffect {
|
||||
|
||||
triggerList.triggerChangesZoneAll(game);
|
||||
|
||||
if (sa.hasParam("UntilHostLeavesPlay")) {
|
||||
source.addLeavesPlayCommand(untilHostLeavesPlayCommand(triggerList, source));
|
||||
}
|
||||
|
||||
// if Shuffle parameter exists, and any amount of cards were owned by
|
||||
// that player, then shuffle that library
|
||||
if (sa.hasParam("Shuffle")) {
|
||||
@@ -270,5 +279,4 @@ public class ChangeZoneAllEffect extends SpellAbilityEffect {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -409,6 +409,11 @@ public class ChangeZoneEffect extends SpellAbilityEffect {
|
||||
|
||||
@Override
|
||||
public void resolve(SpellAbility sa) {
|
||||
//if host is not on the battlefield don't apply
|
||||
if (sa.hasParam("UntilHostLeavesPlay") && !sa.getHostCard().isInPlay()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isHidden(sa) && !sa.hasParam("Ninjutsu")) {
|
||||
changeHiddenOriginResolve(sa);
|
||||
} else {
|
||||
@@ -711,7 +716,7 @@ public class ChangeZoneEffect extends SpellAbilityEffect {
|
||||
movedCard.addCounter(cType, cAmount, player, true, counterTable);
|
||||
}
|
||||
|
||||
if (sa.hasParam("ExileFaceDown")) {
|
||||
if (sa.hasParam("ExileFaceDown") || sa.hasParam("FaceDown")) {
|
||||
movedCard.turnFaceDown(true);
|
||||
}
|
||||
if (sa.hasParam("Foretold")) {
|
||||
@@ -744,7 +749,6 @@ public class ChangeZoneEffect extends SpellAbilityEffect {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (remember != null) {
|
||||
hostCard.addRemembered(movedCard);
|
||||
// addRememberedFromCardState ?
|
||||
@@ -797,9 +801,13 @@ public class ChangeZoneEffect extends SpellAbilityEffect {
|
||||
triggerList.triggerChangesZoneAll(game);
|
||||
counterTable.triggerCountersPutAll(game);
|
||||
|
||||
|
||||
if (sa.hasParam("AtEOT") && !triggerList.isEmpty()) {
|
||||
registerDelayedTrigger(sa, sa.getParam("AtEOT"), triggerList.allCards());
|
||||
}
|
||||
if (sa.hasParam("UntilHostLeavesPlay")) {
|
||||
hostCard.addLeavesPlayCommand(untilHostLeavesPlayCommand(triggerList, hostCard));
|
||||
}
|
||||
|
||||
// for things like Gaea's Blessing
|
||||
if (destination.equals(ZoneType.Library) && sa.hasParam("Shuffle") && "True".equals(sa.getParam("Shuffle"))) {
|
||||
@@ -1388,6 +1396,10 @@ public class ChangeZoneEffect extends SpellAbilityEffect {
|
||||
}
|
||||
triggerList.triggerChangesZoneAll(game);
|
||||
|
||||
if (sa.hasParam("UntilHostLeavesPlay")) {
|
||||
source.addLeavesPlayCommand(untilHostLeavesPlayCommand(triggerList, source));
|
||||
}
|
||||
|
||||
// remove Controlled While Searching
|
||||
if (controlTimestamp != null) {
|
||||
player.removeController(controlTimestamp);
|
||||
|
||||
@@ -98,6 +98,8 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
|
||||
private CardCollection mustBlockCards, gainControlTargets, chosenCards, blockedThisTurn, blockedByThisTurn;
|
||||
private CardCollection mergedCards;
|
||||
|
||||
private CardCollection untilLeavesBattlefield = new CardCollection();
|
||||
|
||||
// if this card is attached or linked to something, what card is it currently attached to
|
||||
private Card encoding, cloneOrigin, haunting, effectSource, pairedWith, meldedWith;
|
||||
private Card mergedTo;
|
||||
@@ -7002,4 +7004,20 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
|
||||
}
|
||||
return edition.getBorderColor();
|
||||
}
|
||||
|
||||
public final void addUntilLeavesBattlefield(final Card c) {
|
||||
untilLeavesBattlefield = view.addCard(untilLeavesBattlefield, c, TrackableProperty.UntilLeavesBattlefield);
|
||||
}
|
||||
public final void addUntilLeavesBattlefield(final Iterable<Card> cards) {
|
||||
untilLeavesBattlefield = view.addCards(untilLeavesBattlefield, cards, TrackableProperty.UntilLeavesBattlefield);
|
||||
}
|
||||
public final void removeUntilLeavesBattlefield(final Card c) {
|
||||
untilLeavesBattlefield = view.removeCard(untilLeavesBattlefield, c, TrackableProperty.UntilLeavesBattlefield);
|
||||
}
|
||||
public final void removeUntilLeavesBattlefield(final Iterable<Card> cards) {
|
||||
untilLeavesBattlefield = view.removeCards(untilLeavesBattlefield, cards, TrackableProperty.UntilLeavesBattlefield);
|
||||
}
|
||||
public final void clearUntilLeavesBattlefield() {
|
||||
untilLeavesBattlefield = view.clearCards(untilLeavesBattlefield, TrackableProperty.UntilLeavesBattlefield);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -519,6 +519,10 @@ public class CardView extends GameEntityView {
|
||||
return get(TrackableProperty.EncodedCards);
|
||||
}
|
||||
|
||||
public FCollectionView<CardView> getUntilLeavesBattlefield() {
|
||||
return get(TrackableProperty.UntilLeavesBattlefield);
|
||||
}
|
||||
|
||||
public GameEntityView getEntityAttachedTo() {
|
||||
return get(TrackableProperty.EntityAttachedTo);
|
||||
}
|
||||
|
||||
@@ -65,6 +65,7 @@ public enum TrackableProperty {
|
||||
PlayerMayLook(TrackableTypes.PlayerViewCollectionType, FreezeMode.IgnoresFreeze),
|
||||
EntityAttachedTo(TrackableTypes.GameEntityViewType),
|
||||
EncodedCards(TrackableTypes.CardViewCollectionType),
|
||||
UntilLeavesBattlefield(TrackableTypes.CardViewCollectionType),
|
||||
GainControlTargets(TrackableTypes.CardViewCollectionType),
|
||||
CloneOrigin(TrackableTypes.CardViewType),
|
||||
|
||||
|
||||
Reference in New Issue
Block a user