mirror of
https://github.com/magefree/mage.git
synced 2025-12-26 21:42:07 -08:00
* Fixed some problems with color changes of cards and spells - e.g. Painter's Servant (fixes #7325 fixes #6487).
This commit is contained in:
parent
f6c70d5d4a
commit
c67ce93ec4
13 changed files with 294 additions and 115 deletions
|
|
@ -1,5 +1,6 @@
|
|||
package mage;
|
||||
|
||||
import java.util.*;
|
||||
import mage.abilities.Abilities;
|
||||
import mage.abilities.AbilitiesImpl;
|
||||
import mage.abilities.Ability;
|
||||
|
|
@ -16,12 +17,11 @@ import mage.cards.FrameStyle;
|
|||
import mage.cards.mock.MockCard;
|
||||
import mage.constants.*;
|
||||
import mage.game.Game;
|
||||
import mage.game.MageObjectAttribute;
|
||||
import mage.game.events.ZoneChangeEvent;
|
||||
import mage.util.GameLog;
|
||||
import mage.util.SubTypeList;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public abstract class MageObjectImpl implements MageObject {
|
||||
|
||||
protected UUID objectId;
|
||||
|
|
@ -117,6 +117,12 @@ public abstract class MageObjectImpl implements MageObject {
|
|||
|
||||
@Override
|
||||
public SubTypeList getSubtype(Game game) {
|
||||
if (game != null) {
|
||||
MageObjectAttribute mageObjectAttribute = game.getState().getMageObjectAttribute(getId());
|
||||
if (mageObjectAttribute != null) {
|
||||
return mageObjectAttribute.getSubtype();
|
||||
}
|
||||
}
|
||||
return subtype;
|
||||
}
|
||||
|
||||
|
|
@ -170,6 +176,12 @@ public abstract class MageObjectImpl implements MageObject {
|
|||
|
||||
@Override
|
||||
public ObjectColor getColor(Game game) {
|
||||
if (game != null) {
|
||||
MageObjectAttribute mageObjectAttribute = game.getState().getMageObjectAttribute(getId());
|
||||
if (mageObjectAttribute != null) {
|
||||
return mageObjectAttribute.getColor();
|
||||
}
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -207,14 +207,14 @@ public class MorphAbility extends StaticAbility implements AlternativeSourceCost
|
|||
ability.getCosts().add(cost.copy());
|
||||
}
|
||||
}
|
||||
// change spell colors
|
||||
// change spell colors and subtype *TODO probably this needs to be done by continuous effect (while on the stack)
|
||||
ObjectColor spellColor = spell.getColor(game);
|
||||
spellColor.setBlack(false);
|
||||
spellColor.setRed(false);
|
||||
spellColor.setGreen(false);
|
||||
spellColor.setWhite(false);
|
||||
spellColor.setBlue(false);
|
||||
game.getState().getCreateCardAttribute(spell.getCard(), game).getSubtype().clear();
|
||||
game.getState().getCreateMageObjectAttribute(spell.getCard(), game).getSubtype().clear();
|
||||
} else {
|
||||
spell.setFaceDown(false, game);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
package mage.cards;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.*;
|
||||
import mage.MageObject;
|
||||
import mage.MageObjectImpl;
|
||||
import mage.Mana;
|
||||
|
|
@ -20,14 +23,9 @@ import mage.game.stack.Spell;
|
|||
import mage.game.stack.StackObject;
|
||||
import mage.util.CardUtil;
|
||||
import mage.util.GameLog;
|
||||
import mage.util.SubTypeList;
|
||||
import mage.watchers.Watcher;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.*;
|
||||
|
||||
public abstract class CardImpl extends MageObjectImpl implements Card {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
|
@ -869,28 +867,6 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
|
|||
spellAbility = ability;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectColor getColor(Game game) {
|
||||
if (game != null) {
|
||||
CardAttribute cardAttribute = game.getState().getCardAttribute(getId());
|
||||
if (cardAttribute != null) {
|
||||
return cardAttribute.getColor();
|
||||
}
|
||||
}
|
||||
return super.getColor(game);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubTypeList getSubtype(Game game) {
|
||||
if (game != null) {
|
||||
CardAttribute cardAttribute = game.getState().getCardAttribute(getId());
|
||||
if (cardAttribute != null) {
|
||||
return cardAttribute.getSubtype();
|
||||
}
|
||||
}
|
||||
return super.getSubtype(game);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UUID> getAttachments() {
|
||||
return attachments;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
package mage.game;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import static java.util.Collections.emptyList;
|
||||
import java.util.stream.Collectors;
|
||||
import mage.MageObject;
|
||||
import mage.MageObjectReference;
|
||||
import mage.abilities.*;
|
||||
|
|
@ -35,12 +39,6 @@ import mage.util.ThreadLocalStringBuilder;
|
|||
import mage.watchers.Watcher;
|
||||
import mage.watchers.Watchers;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
|
||||
/**
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
* <p>
|
||||
|
|
@ -95,7 +93,7 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
private Map<UUID, Zone> zones = new HashMap<>();
|
||||
private List<GameEvent> simultaneousEvents = new ArrayList<>();
|
||||
private Map<UUID, CardState> cardState = new HashMap<>();
|
||||
private Map<UUID, CardAttribute> cardAttribute = new HashMap<>();
|
||||
private Map<UUID, MageObjectAttribute> mageObjectAttribute = new HashMap<>();
|
||||
private Map<UUID, Integer> zoneChangeCounter = new HashMap<>();
|
||||
private Map<UUID, Card> copiedCards = new HashMap<>();
|
||||
private int permanentOrderNumber;
|
||||
|
|
@ -178,8 +176,8 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
for (Map.Entry<UUID, CardState> entry : state.cardState.entrySet()) {
|
||||
cardState.put(entry.getKey(), entry.getValue().copy());
|
||||
}
|
||||
for (Map.Entry<UUID, CardAttribute> entry : state.cardAttribute.entrySet()) {
|
||||
cardAttribute.put(entry.getKey(), entry.getValue().copy());
|
||||
for (Map.Entry<UUID, MageObjectAttribute> entry : state.mageObjectAttribute.entrySet()) {
|
||||
mageObjectAttribute.put(entry.getKey(), entry.getValue().copy());
|
||||
}
|
||||
this.zoneChangeCounter.putAll(state.zoneChangeCounter);
|
||||
this.copiedCards.putAll(state.copiedCards);
|
||||
|
|
@ -228,7 +226,7 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
this.zones = state.zones;
|
||||
this.simultaneousEvents = state.simultaneousEvents;
|
||||
this.cardState = state.cardState;
|
||||
this.cardAttribute = state.cardAttribute;
|
||||
this.mageObjectAttribute = state.mageObjectAttribute;
|
||||
this.zoneChangeCounter = state.zoneChangeCounter;
|
||||
this.copiedCards = state.copiedCards;
|
||||
this.permanentOrderNumber = state.permanentOrderNumber;
|
||||
|
|
@ -1117,7 +1115,7 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
for (CardState state : cardState.values()) {
|
||||
state.clearAbilities();
|
||||
}
|
||||
cardAttribute.clear();
|
||||
mageObjectAttribute.clear();
|
||||
this.setManaBurn(false);
|
||||
}
|
||||
|
||||
|
|
@ -1188,13 +1186,13 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
return cardState.get(cardId);
|
||||
}
|
||||
|
||||
public CardAttribute getCardAttribute(UUID cardId) {
|
||||
return cardAttribute.get(cardId);
|
||||
public MageObjectAttribute getMageObjectAttribute(UUID cardId) {
|
||||
return mageObjectAttribute.get(cardId);
|
||||
}
|
||||
|
||||
public CardAttribute getCreateCardAttribute(Card card, Game game) {
|
||||
CardAttribute cardAtt = cardAttribute.computeIfAbsent(card.getId(), k -> new CardAttribute(card, game));
|
||||
return cardAtt;
|
||||
public MageObjectAttribute getCreateMageObjectAttribute(MageObject mageObject, Game game) {
|
||||
MageObjectAttribute mageObjectAtt = mageObjectAttribute.computeIfAbsent(mageObject.getId(), k -> new MageObjectAttribute(mageObject, game));
|
||||
return mageObjectAtt;
|
||||
}
|
||||
|
||||
public void addWatcher(Watcher watcher) {
|
||||
|
|
|
|||
|
|
@ -6,34 +6,34 @@
|
|||
package mage.game;
|
||||
|
||||
import java.io.Serializable;
|
||||
import mage.MageObject;
|
||||
import mage.ObjectColor;
|
||||
import mage.cards.Card;
|
||||
import mage.util.SubTypeList;
|
||||
|
||||
/**
|
||||
* This class saves changed attributes of cards (e.g. in graveyard, exile or
|
||||
* This class saves changed attributes of mage objects (e.g. in command zone, graveyard, exile or
|
||||
* player hands or libraries).
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class CardAttribute implements Serializable {
|
||||
public class MageObjectAttribute implements Serializable {
|
||||
|
||||
protected ObjectColor color;
|
||||
protected SubTypeList subtype;
|
||||
|
||||
public CardAttribute(Card card, Game game) {
|
||||
color = card.getColor(null).copy();
|
||||
public MageObjectAttribute(MageObject mageObject, Game game) {
|
||||
color = mageObject.getColor(null).copy();
|
||||
subtype = new SubTypeList();
|
||||
subtype.addAll(card.getSubtype(game));
|
||||
subtype.addAll(mageObject.getSubtype(game));
|
||||
}
|
||||
|
||||
public CardAttribute(CardAttribute cardAttribute) {
|
||||
this.color = cardAttribute.color;
|
||||
this.subtype = cardAttribute.subtype;
|
||||
public MageObjectAttribute(MageObjectAttribute mageObjectAttribute) {
|
||||
this.color = mageObjectAttribute.color;
|
||||
this.subtype = mageObjectAttribute.subtype;
|
||||
}
|
||||
|
||||
public CardAttribute copy() {
|
||||
return new CardAttribute(this);
|
||||
public MageObjectAttribute copy() {
|
||||
return new MageObjectAttribute(this);
|
||||
}
|
||||
|
||||
public ObjectColor getColor() {
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package mage.game.stack;
|
||||
|
||||
import java.util.*;
|
||||
import mage.MageInt;
|
||||
import mage.MageObject;
|
||||
import mage.Mana;
|
||||
|
|
@ -22,6 +23,7 @@ import mage.counters.Counters;
|
|||
import mage.filter.FilterMana;
|
||||
import mage.game.Game;
|
||||
import mage.game.GameState;
|
||||
import mage.game.MageObjectAttribute;
|
||||
import mage.game.events.CopiedStackObjectEvent;
|
||||
import mage.game.events.CopyStackObjectEvent;
|
||||
import mage.game.events.GameEvent;
|
||||
|
|
@ -34,8 +36,6 @@ import mage.util.CardUtil;
|
|||
import mage.util.GameLog;
|
||||
import mage.util.SubTypeList;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
|
|
@ -575,6 +575,12 @@ public class Spell extends StackObjImpl implements Card {
|
|||
|
||||
@Override
|
||||
public ObjectColor getColor(Game game) {
|
||||
if (game != null) {
|
||||
MageObjectAttribute mageObjectAttribute = game.getState().getMageObjectAttribute(getId());
|
||||
if (mageObjectAttribute != null) {
|
||||
return mageObjectAttribute.getColor();
|
||||
}
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue