Merge branch 'fix_subgame_mutate' into 'master'

Handle mutate and subgame interaction

See merge request core-developers/forge!3846
This commit is contained in:
Michael Kamensky
2021-02-15 08:23:52 +00:00
4 changed files with 58 additions and 9 deletions

View File

@@ -109,7 +109,7 @@ public class Game {
private final Match match;
private GameStage age = GameStage.BeforeMulligan;
private GameOutcome outcome;
private Game maingame = null;
private final Game maingame;
private final GameView view;
private final Tracker tracker = new Tracker();
@@ -221,12 +221,13 @@ public class Game {
}
public Game(Iterable<RegisteredPlayer> players0, GameRules rules0, Match match0) {
this(players0, rules0, match0, -1);
this(players0, rules0, match0, null, -1);
}
public Game(Iterable<RegisteredPlayer> players0, GameRules rules0, Match match0, int startingLife) { /* no more zones to map here */
public Game(Iterable<RegisteredPlayer> players0, GameRules rules0, Match match0, Game maingame0, int startingLife) { /* no more zones to map here */
rules = rules0;
match = match0;
maingame = maingame0;
this.id = nextId();
int highestTeam = -1;
@@ -443,10 +444,6 @@ public class Game {
return maingame;
}
public void setMaingame(final Game maingame0) {
maingame = maingame0;
}
public ReplacementHandler getReplacementHandler() {
return replacementHandler;
}

View File

@@ -624,6 +624,11 @@ public class GameAction {
// Card lastKnownInfo = c;
// Handle the case that one component of a merged permanent got take to the subgame
if (zoneTo.is(ZoneType.Subgame) && (c.hasMergedCard() || c.isMerged())) {
c.moveMergedToSubgame(cause);
}
c = changeZone(zoneFrom, zoneTo, c, position, cause, params);
// Move card in maingame if take card from subgame

View File

@@ -35,7 +35,7 @@ public class SubgameEffect extends SpellAbilityEffect {
players.add(p.getRegisteredPlayer());
}
return new Game(players, maingame.getRules(), maingame.getMatch(), startingLife);
return new Game(players, maingame.getRules(), maingame.getMatch(), maingame, startingLife);
}
private final void setCardsInZone(Player player, final ZoneType zoneType, final CardCollectionView oldCards, boolean addMapping) {
@@ -157,7 +157,6 @@ public class SubgameEffect extends SpellAbilityEffect {
startingLife = Integer.parseInt(sa.getParam("StartingLife"));
}
Game subgame = createSubGame(maingame, startingLife);
subgame.setMaingame(maingame);
String startMessage = Localizer.getInstance().getMessage("lblSubgameStart",
CardTranslation.getTranslatedName(hostCard.getName()));

View File

@@ -1120,6 +1120,54 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
}
}
public final void moveMergedToSubgame(SpellAbility cause) {
if (hasMergedCard()) {
Zone zone = getZone();
int pos = -1;
for (int i = 0; i < zone.size(); i++) {
if (zone.get(i) == this) {
pos = i;
break;
}
}
Card newTop = null;
for (final Card c : mergedCards) {
if (c != this) {
newTop = c;
}
}
if (newTop != null) {
removeMutatedStates();
newTop.mergedCards = mergedCards;
newTop.mergedTo = null;
mergedCards = null;
mergedTo = newTop;
newTop.mutatedTimestamp = mutatedTimestamp;
newTop.timesMutated = timesMutated;
mutatedTimestamp = -1;
timesMutated = 0;
zone.remove(this);
newTop.getZone().add(this);
setZone(newTop.getZone());
newTop.getZone().remove(newTop);
zone.add(newTop, pos);
newTop.setZone(zone);
}
}
Card topCard = getMergedToCard();
if (topCard != null) {
setMergedToCard(null);
topCard.removeMergedCard(this);
topCard.removeMutatedStates();
topCard.rebuildMutatedStates(cause);
}
}
public final String getFlipResult(final Player flipper) {
if (flipResult == null) {
return null;