Skip to content

Commit b0a6d2d

Browse files
tool4EvErtool4EvEr
authored andcommitted
Add zone ordering
1 parent 66028d3 commit b0a6d2d

File tree

5 files changed

+30
-3
lines changed

5 files changed

+30
-3
lines changed

forge-game/src/main/java/forge/game/GameActionUtil.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import forge.game.ability.AbilityUtils;
2727
import forge.game.ability.ApiType;
2828
import forge.game.ability.SpellAbilityEffect;
29+
import forge.game.ability.effects.DetachedCardEffect;
2930
import forge.game.card.*;
3031
import forge.game.card.CardPlayOption.PayManaCost;
3132
import forge.game.cost.Cost;
@@ -34,6 +35,7 @@
3435
import forge.game.player.Player;
3536
import forge.game.player.PlayerCollection;
3637
import forge.game.player.PlayerController;
38+
import forge.game.player.PlayerController.FullControlFlag;
3739
import forge.game.replacement.ReplacementEffect;
3840
import forge.game.replacement.ReplacementHandler;
3941
import forge.game.replacement.ReplacementLayer;
@@ -835,9 +837,11 @@ public static String generatedMana(final SpellAbility sa) {
835837
}
836838

837839
public static CardCollectionView orderCardsByTheirOwners(Game game, CardCollectionView list, ZoneType dest, SpellAbility sa) {
838-
if (list.size() <= 1) {
840+
if (list.size() <= 1 &&
841+
(sa == null || !sa.getActivatingPlayer().getController().isFullControl(FullControlFlag.LayerTimestampOrder))) {
839842
return list;
840843
}
844+
Card eff = null;
841845
CardCollection completeList = new CardCollection();
842846
// CR 613.7m use APNAP
843847
PlayerCollection players = game.getPlayersInTurnOrder(game.getPhaseHandler().getPlayerTurn());
@@ -853,12 +857,28 @@ public static CardCollectionView orderCardsByTheirOwners(Game game, CardCollecti
853857
subList.add(c);
854858
}
855859
}
860+
if (sa.getActivatingPlayer() == p && sa.hasParam("StaticEffect")) {
861+
String name = "Static Effect of " + sa.getHostCard();
862+
// create helper card for ordering
863+
eff = new DetachedCardEffect(sa.getHostCard(), name);
864+
subList.add(eff);
865+
}
856866
CardCollectionView subListView = subList;
857867
if (subList.size() > 1) {
858868
subListView = p.getController().orderMoveToZoneList(subList, dest, sa);
859869
}
860870
completeList.addAll(subListView);
861871
}
872+
if (eff != null) {
873+
int idx = completeList.indexOf(eff);
874+
// add generous buffer to timestamp, to ensure it applies last compared to cards that were ordered to ETB before it
875+
sa.setSVar("StaticEffectTimestamp", String.valueOf(game.getTimestamp() + idx + 100));
876+
// effects with this param have the responsibility to realign it when later cards are reached
877+
if (idx < completeList.size() - 1) {
878+
sa.setSVar("StaticEffectUntilCardID", String.valueOf(completeList.get(idx + 1).getId()));
879+
}
880+
completeList.remove(eff);
881+
}
862882
return completeList;
863883
}
864884

forge-game/src/main/java/forge/game/ability/effects/ChangeZoneEffect.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import forge.game.event.GameEventCombatChanged;
1414
import forge.game.keyword.Keyword;
1515
import forge.game.player.*;
16+
import forge.game.player.PlayerController.FullControlFlag;
1617
import forge.game.replacement.ReplacementEffect;
1718
import forge.game.replacement.ReplacementType;
1819
import forge.game.spellability.SpellAbility;
@@ -516,7 +517,7 @@ private void changeKnownOriginResolve(final SpellAbility sa) {
516517
}
517518

518519
// CR 401.4
519-
if (destination.isDeck() && !shuffle && tgtCards.size() > 1) {
520+
if (((destination.isDeck() && tgtCards.size() > 1) || chooser.getController().isFullControl(FullControlFlag.LayerTimestampOrder)) && !shuffle) {
520521
if (sa.hasParam("RandomOrder")) {
521522
final CardCollection random = new CardCollection(tgtCards);
522523
CardLists.shuffle(random);
@@ -534,6 +535,10 @@ private void changeKnownOriginResolve(final SpellAbility sa) {
534535
}
535536

536537
for (final Card tgtC : tgtCards) {
538+
if (sa.hasSVar("StaticEffectUntilCardID") && sa.getSVarInt("StaticEffectUntilCardID") == tgtC.getId()) {
539+
sa.setSVar("StaticEffectTimestamp", String.valueOf(game.getNextTimestamp()));
540+
}
541+
537542
final Card gameCard = game.getCardState(tgtC, null);
538543
// gameCard is LKI in that case, the card is not in game anymore
539544
// or the timestamp did change

forge-game/src/main/java/forge/game/player/PlayerController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public enum FullControlFlag {
6565
NoPaymentFromManaAbility,
6666
NoFreeCombatCostHandling,
6767
AllowPaymentStartWithMissingResources,
68-
//AdditionalLayerTimestampOrder // tokens etc.
68+
LayerTimestampOrder // for StaticEffect$, tokens later etc.
6969
}
7070

7171
private Set<FullControlFlag> fullControls = EnumSet.noneOf(FullControlFlag.class);

forge-gui-desktop/src/main/java/forge/screens/match/CMatchUI.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,6 +1516,7 @@ public void showFullControl(PlayerView pv, MouseEvent e) {
15161516
addFullControlEntry(menu, "lblNoPaymentFromManaAbility", FullControlFlag.NoPaymentFromManaAbility, controlFlags);
15171517
addFullControlEntry(menu, "lblNoFreeCombatCostHandling", FullControlFlag.NoFreeCombatCostHandling, controlFlags);
15181518
addFullControlEntry(menu, "lblAllowPaymentStartWithMissingResources", FullControlFlag.AllowPaymentStartWithMissingResources, controlFlags);
1519+
addFullControlEntry(menu, "lblLayerTimestampOrder", FullControlFlag.LayerTimestampOrder, controlFlags);
15191520

15201521
menu.show(view.getControl().getFieldViewFor(pv).getAvatarArea(), e.getX(), e.getY());
15211522
}

forge-gui-mobile/src/forge/screens/match/MatchController.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,7 @@ protected void buildMenu() {
757757
addItem(getFullControlMenuEntry("lblNoPaymentFromManaAbility", FullControlFlag.NoPaymentFromManaAbility, controlFlags));
758758
addItem(getFullControlMenuEntry("lblNoFreeCombatCostHandling", FullControlFlag.NoFreeCombatCostHandling, controlFlags));
759759
addItem(getFullControlMenuEntry("lblAllowPaymentStartWithMissingResources", FullControlFlag.AllowPaymentStartWithMissingResources, controlFlags));
760+
addItem(getFullControlMenuEntry("lblLayerTimestampOrder", FullControlFlag.LayerTimestampOrder, controlFlags));
760761
}
761762
};
762763

0 commit comments

Comments
 (0)