mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
- Another attempt at fixing Morbid + Awaken and other similar interactions (e.g. Awaken + Flesh Allergy).
This commit is contained in:
@@ -251,7 +251,7 @@ public class GameAction {
|
|||||||
|
|
||||||
// "enter the battlefield as a copy" - apply code here
|
// "enter the battlefield as a copy" - apply code here
|
||||||
// but how to query for input here and continue later while the callers assume synchronous result?
|
// but how to query for input here and continue later while the callers assume synchronous result?
|
||||||
zoneTo.add(copied, position);
|
zoneTo.add(copied, position, c); // the modified state of the card is also reported here (e.g. for Morbid + Awaken)
|
||||||
|
|
||||||
if (fromBattlefield) {
|
if (fromBattlefield) {
|
||||||
c.setZone(zoneTo);
|
c.setZone(zoneTo);
|
||||||
|
|||||||
@@ -1443,7 +1443,7 @@ public class CardFactoryUtil {
|
|||||||
|
|
||||||
// Count$Morbid.<True>.<False>
|
// Count$Morbid.<True>.<False>
|
||||||
if (sq[0].startsWith("Morbid")) {
|
if (sq[0].startsWith("Morbid")) {
|
||||||
final CardCollection res = CardUtil.getThisTurnEntered(ZoneType.Graveyard, ZoneType.Battlefield, "Creature", c);
|
final CardCollection res = CardUtil.getThisTurnEntered(ZoneType.Graveyard, ZoneType.Battlefield, "Creature", c, true);
|
||||||
if (res.size() > 0) {
|
if (res.size() > 0) {
|
||||||
return doXMath(Integer.parseInt(sq[1]), m, c);
|
return doXMath(Integer.parseInt(sq[1]), m, c);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -151,18 +151,33 @@ public final class CardUtil {
|
|||||||
* @param from zone coming from
|
* @param from zone coming from
|
||||||
* @param valid a isValid expression
|
* @param valid a isValid expression
|
||||||
* @param src a Card object
|
* @param src a Card object
|
||||||
|
* @param checkLatestState a boolean, true if the latest state of the card as it left the original zone needs to be checked
|
||||||
* @return a CardCollection that matches the given criteria
|
* @return a CardCollection that matches the given criteria
|
||||||
*/
|
*/
|
||||||
public static CardCollection getThisTurnEntered(final ZoneType to, final ZoneType from, final String valid, final Card src) {
|
public static CardCollection getThisTurnEntered(final ZoneType to, final ZoneType from, final String valid, final Card src) {
|
||||||
|
return getThisTurnEntered(to, from, valid, src, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getThisTurnEntered.
|
||||||
|
*
|
||||||
|
* @param to zone going to
|
||||||
|
* @param from zone coming from
|
||||||
|
* @param valid a isValid expression
|
||||||
|
* @param src a Card object
|
||||||
|
* @param checkLatestState a boolean, true if the latest state of the card as it left the original zone needs to be checked
|
||||||
|
* @return a CardCollection that matches the given criteria
|
||||||
|
*/
|
||||||
|
public static CardCollection getThisTurnEntered(final ZoneType to, final ZoneType from, final String valid, final Card src, final boolean checkLatestState) {
|
||||||
CardCollection res = new CardCollection();
|
CardCollection res = new CardCollection();
|
||||||
final Game game = src.getGame();
|
final Game game = src.getGame();
|
||||||
if (to != ZoneType.Stack) {
|
if (to != ZoneType.Stack) {
|
||||||
for (Player p : game.getPlayers()) {
|
for (Player p : game.getPlayers()) {
|
||||||
res.addAll(p.getZone(to).getCardsAddedThisTurn(from));
|
res.addAll(p.getZone(to).getCardsAddedThisTurn(from, checkLatestState));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
res.addAll(game.getStackZone().getCardsAddedThisTurn(from));
|
res.addAll(game.getStackZone().getCardsAddedThisTurn(from, checkLatestState));
|
||||||
}
|
}
|
||||||
res = CardLists.getValidCards(res, valid, src.getController(), src);
|
res = CardLists.getValidCards(res, valid, src.getController(), src);
|
||||||
return res;
|
return res;
|
||||||
@@ -175,18 +190,32 @@ public final class CardUtil {
|
|||||||
* @param from zone coming from
|
* @param from zone coming from
|
||||||
* @param valid a isValid expression
|
* @param valid a isValid expression
|
||||||
* @param src a Card object
|
* @param src a Card object
|
||||||
|
* @param checkLatestState a boolean, true if the latest state of the card as it left the original zone needs to be checked
|
||||||
* @return a CardCollection that matches the given criteria
|
* @return a CardCollection that matches the given criteria
|
||||||
*/
|
*/
|
||||||
public static CardCollection getLastTurnEntered(final ZoneType to, final ZoneType from, final String valid, final Card src) {
|
public static CardCollection getLastTurnEntered(final ZoneType to, final ZoneType from, final String valid, final Card src) {
|
||||||
|
return getLastTurnEntered(to, from, valid, src, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getLastTurnEntered.
|
||||||
|
*
|
||||||
|
* @param to zone going to
|
||||||
|
* @param from zone coming from
|
||||||
|
* @param valid a isValid expression
|
||||||
|
* @param src a Card object
|
||||||
|
* @return a CardCollection that matches the given criteria
|
||||||
|
*/
|
||||||
|
public static CardCollection getLastTurnEntered(final ZoneType to, final ZoneType from, final String valid, final Card src, final boolean checkLatestState) {
|
||||||
CardCollection res = new CardCollection();
|
CardCollection res = new CardCollection();
|
||||||
final Game game = src.getGame();
|
final Game game = src.getGame();
|
||||||
if (to != ZoneType.Stack) {
|
if (to != ZoneType.Stack) {
|
||||||
for (Player p : game.getPlayers()) {
|
for (Player p : game.getPlayers()) {
|
||||||
res.addAll(p.getZone(to).getCardsAddedLastTurn(from));
|
res.addAll(p.getZone(to).getCardsAddedLastTurn(from, checkLatestState));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
res.addAll(game.getStackZone().getCardsAddedLastTurn(from));
|
res.addAll(game.getStackZone().getCardsAddedLastTurn(from, checkLatestState));
|
||||||
}
|
}
|
||||||
res = CardLists.getValidCards(res, valid, src.getController(), src);
|
res = CardLists.getValidCards(res, valid, src.getController(), src);
|
||||||
return res;
|
return res;
|
||||||
|
|||||||
@@ -45,12 +45,12 @@ public class PlayerZoneBattlefield extends PlayerZone {
|
|||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public final void add(final Card c, final Integer position) {
|
public final void add(final Card c, final Integer position, final Card latestState) {
|
||||||
if (c == null) {
|
if (c == null) {
|
||||||
throw new RuntimeException("PlayerZoneComesInto Play : add() object is null");
|
throw new RuntimeException("PlayerZoneComesInto Play : add() object is null");
|
||||||
}
|
}
|
||||||
|
|
||||||
super.add(c, position);
|
super.add(c, position, latestState);
|
||||||
|
|
||||||
if (trigger) {
|
if (trigger) {
|
||||||
// ETBTapped static abilities
|
// ETBTapped static abilities
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ public class Zone implements java.io.Serializable, Iterable<Card> {
|
|||||||
|
|
||||||
protected final transient MapOfLists<ZoneType, Card> cardsAddedThisTurn = new EnumMapOfLists<>(ZoneType.class, CollectionSuppliers.<Card>arrayLists());
|
protected final transient MapOfLists<ZoneType, Card> cardsAddedThisTurn = new EnumMapOfLists<>(ZoneType.class, CollectionSuppliers.<Card>arrayLists());
|
||||||
protected final transient MapOfLists<ZoneType, Card> cardsAddedLastTurn = new EnumMapOfLists<>(ZoneType.class, CollectionSuppliers.<Card>arrayLists());
|
protected final transient MapOfLists<ZoneType, Card> cardsAddedLastTurn = new EnumMapOfLists<>(ZoneType.class, CollectionSuppliers.<Card>arrayLists());
|
||||||
|
protected final transient MapOfLists<ZoneType, Card> latestStateCardsAddedThisTurn = new EnumMapOfLists<>(ZoneType.class, CollectionSuppliers.<Card>arrayLists());
|
||||||
|
protected final transient MapOfLists<ZoneType, Card> latestStateCardsAddedLastTurn = new EnumMapOfLists<>(ZoneType.class, CollectionSuppliers.<Card>arrayLists());
|
||||||
|
|
||||||
public Zone(final ZoneType zone0, Game game0) {
|
public Zone(final ZoneType zone0, Game game0) {
|
||||||
zoneType = zone0;
|
zoneType = zone0;
|
||||||
@@ -72,12 +74,17 @@ public class Zone implements java.io.Serializable, Iterable<Card> {
|
|||||||
add(c, null);
|
add(c, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(final Card c, final Integer index) {
|
public final void add(final Card c, final Integer index) {
|
||||||
|
add(c, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(final Card c, final Integer index, final Card latestState) {
|
||||||
// Immutable cards are usually emblems and effects
|
// Immutable cards are usually emblems and effects
|
||||||
if (!c.isImmutable()) {
|
if (!c.isImmutable()) {
|
||||||
final Zone oldZone = game.getZoneOf(c);
|
final Zone oldZone = game.getZoneOf(c);
|
||||||
final ZoneType zt = oldZone == null ? ZoneType.Stack : oldZone.getZoneType();
|
final ZoneType zt = oldZone == null ? ZoneType.Stack : oldZone.getZoneType();
|
||||||
cardsAddedThisTurn.add(zt, c);
|
cardsAddedThisTurn.add(zt, c);
|
||||||
|
latestStateCardsAddedThisTurn.add(zt, latestState != null ? latestState : c);
|
||||||
}
|
}
|
||||||
|
|
||||||
c.setTurnInZone(game.getPhaseHandler().getTurn());
|
c.setTurnInZone(game.getPhaseHandler().getTurn());
|
||||||
@@ -157,18 +164,42 @@ public class Zone implements java.io.Serializable, Iterable<Card> {
|
|||||||
return cardsAddedThisTurn;
|
return cardsAddedThisTurn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final MapOfLists<ZoneType, Card> getCardsAddedThisTurn(boolean latestState) {
|
||||||
|
if (latestState) {
|
||||||
|
return latestStateCardsAddedThisTurn;
|
||||||
|
} else {
|
||||||
|
return cardsAddedThisTurn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public final MapOfLists<ZoneType, Card> getCardsAddedLastTurn() {
|
public final MapOfLists<ZoneType, Card> getCardsAddedLastTurn() {
|
||||||
return cardsAddedLastTurn;
|
return cardsAddedLastTurn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final MapOfLists<ZoneType, Card> getCardsAddedLastTurn(boolean latestState) {
|
||||||
|
if (latestState) {
|
||||||
|
return latestStateCardsAddedLastTurn;
|
||||||
|
} else {
|
||||||
|
return cardsAddedLastTurn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public final CardCollectionView getCardsAddedThisTurn(final ZoneType origin) {
|
public final CardCollectionView getCardsAddedThisTurn(final ZoneType origin) {
|
||||||
|
return getCardsAddedThisTurn(origin, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final CardCollectionView getCardsAddedThisTurn(final ZoneType origin, boolean latestState) {
|
||||||
//System.out.print("Request cards put into " + getZoneType() + " from " + origin + ".Amount: ");
|
//System.out.print("Request cards put into " + getZoneType() + " from " + origin + ".Amount: ");
|
||||||
return getCardsAdded(cardsAddedThisTurn, origin);
|
return getCardsAdded(latestState ? latestStateCardsAddedThisTurn : cardsAddedThisTurn, origin);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final CardCollectionView getCardsAddedLastTurn(final ZoneType origin) {
|
public final CardCollectionView getCardsAddedLastTurn(final ZoneType origin) {
|
||||||
|
return getCardsAddedLastTurn(origin, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final CardCollectionView getCardsAddedLastTurn(final ZoneType origin, boolean latestState) {
|
||||||
//System.out.print("Last turn - Request cards put into " + getZoneType() + " from " + origin + ".Amount: ");
|
//System.out.print("Last turn - Request cards put into " + getZoneType() + " from " + origin + ".Amount: ");
|
||||||
return getCardsAdded(cardsAddedLastTurn, origin);
|
return getCardsAdded(latestState ? latestStateCardsAddedLastTurn : cardsAddedLastTurn, origin);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static CardCollectionView getCardsAdded(final MapOfLists<ZoneType, Card> cardsAdded, final ZoneType origin) {
|
private static CardCollectionView getCardsAdded(final MapOfLists<ZoneType, Card> cardsAdded, final ZoneType origin) {
|
||||||
@@ -187,10 +218,15 @@ public class Zone implements java.io.Serializable, Iterable<Card> {
|
|||||||
|
|
||||||
public final void resetCardsAddedThisTurn() {
|
public final void resetCardsAddedThisTurn() {
|
||||||
cardsAddedLastTurn.clear();
|
cardsAddedLastTurn.clear();
|
||||||
|
latestStateCardsAddedLastTurn.clear();
|
||||||
for (final Entry<ZoneType, Collection<Card>> entry : cardsAddedThisTurn.entrySet()) {
|
for (final Entry<ZoneType, Collection<Card>> entry : cardsAddedThisTurn.entrySet()) {
|
||||||
cardsAddedLastTurn.addAll(entry.getKey(), entry.getValue());
|
cardsAddedLastTurn.addAll(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
|
for (final Entry<ZoneType, Collection<Card>> entry : latestStateCardsAddedThisTurn.entrySet()) {
|
||||||
|
latestStateCardsAddedLastTurn.addAll(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
cardsAddedThisTurn.clear();
|
cardsAddedThisTurn.clear();
|
||||||
|
latestStateCardsAddedThisTurn.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user