mirror of
https://github.com/magefree/mage.git
synced 2025-12-28 22:42:03 -08:00
moved copied cards to GameState
This commit is contained in:
parent
42d34e754f
commit
18a4a98f1a
6 changed files with 328 additions and 95 deletions
|
|
@ -80,7 +80,6 @@ public interface Game extends MageItem, Serializable {
|
|||
|
||||
//game data methods
|
||||
void loadCards(Set<Card> cards, UUID ownerId);
|
||||
void unloadCard(Card card);
|
||||
Collection<Card> getCards();
|
||||
Object getCustomData();
|
||||
void setCustomData(Object data);
|
||||
|
|
|
|||
|
|
@ -220,10 +220,7 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
this.freeMulligans = game.freeMulligans;
|
||||
this.attackOption = game.attackOption;
|
||||
this.state = game.state.copy();
|
||||
// Ai simulation modifies e.g. zoneChangeCounter so copy is needed if AI active
|
||||
for (Map.Entry<UUID, Card> entry: game.gameCards.entrySet()) {
|
||||
this.gameCards.put(entry.getKey(), entry.getValue().copy());
|
||||
}
|
||||
this.gameCards = game.gameCards;
|
||||
this.simulation = game.simulation;
|
||||
this.gameOptions = game.gameOptions;
|
||||
this.lki.putAll(game.lki);
|
||||
|
|
@ -294,20 +291,6 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unloadCard(Card card) {
|
||||
gameCards.remove(card.getId());
|
||||
state.removeCard(card);
|
||||
if (card.isSplitCard()) {
|
||||
Card leftCard = ((SplitCard)card).getLeftHalfCard();
|
||||
gameCards.remove(leftCard.getId());
|
||||
state.removeCard(leftCard);
|
||||
Card rightCard = ((SplitCard)card).getRightHalfCard();
|
||||
gameCards.remove(rightCard.getId());
|
||||
state.removeCard(rightCard);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Card> getCards() {
|
||||
return gameCards.values();
|
||||
|
|
@ -428,7 +411,11 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
if (cardId == null) {
|
||||
return null;
|
||||
}
|
||||
return gameCards.get(cardId);
|
||||
Card card = gameCards.get(cardId);
|
||||
if (card == null) {
|
||||
return state.getCopiedCard(cardId);
|
||||
}
|
||||
return card;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -1328,14 +1315,7 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
|
||||
@Override
|
||||
public Card copyCard(Card cardToCopy, Ability source, UUID newController) {
|
||||
Card copiedCard = cardToCopy.copy();
|
||||
copiedCard.assignNewId();
|
||||
copiedCard.setCopy(true);
|
||||
Set<Card> cards = new HashSet<>();
|
||||
cards.add(copiedCard);
|
||||
loadCards(cards, source.getControllerId());
|
||||
|
||||
return copiedCard;
|
||||
return state.copyCard(cardToCopy, source, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -1437,30 +1417,13 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
}
|
||||
}
|
||||
|
||||
// 704.5e
|
||||
for (Player player: getPlayers().values()) {
|
||||
for (Card card: player.getHand().getCards(this)) {
|
||||
if (card.isCopy()) {
|
||||
player.getHand().remove(card);
|
||||
this.unloadCard(card);
|
||||
}
|
||||
}
|
||||
for (Card card: player.getGraveyard().getCards(this)) {
|
||||
if (card.isCopy()) {
|
||||
player.getGraveyard().remove(card);
|
||||
this.unloadCard(card);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 704.5e If a copy of a spell is in a zone other than the stack, it ceases to exist. If a copy of a card is in any zone other than the stack or the battlefield, it ceases to exist.
|
||||
// (Isochron Scepter) 12/1/2004: If you don't want to cast the copy, you can choose not to; the copy ceases to exist the next time state-based actions are checked.
|
||||
for (Card card: this.getState().getExile().getAllCards(this)) {
|
||||
if (card.isCopy()) {
|
||||
this.getState().getExile().removeCard(card, this);
|
||||
this.unloadCard(card);
|
||||
}
|
||||
}
|
||||
// TODO Library + graveyard
|
||||
|
||||
for (Card card: this.getState().getCopiedCards()) {
|
||||
Zone zone = state.getZone(card.getId());
|
||||
if (zone != Zone.BATTLEFIELD && zone != Zone.STACK)
|
||||
state.removeCopiedCard(card);
|
||||
}
|
||||
|
||||
List<Permanent> planeswalkers = new ArrayList<>();
|
||||
List<Permanent> legendary = new ArrayList<>();
|
||||
|
|
@ -2277,14 +2240,11 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
switch (command.getKey()) {
|
||||
case HAND:
|
||||
if (command.getValue().equals("clear")) {
|
||||
removeCards(player.getHand());
|
||||
player.getHand().clear();
|
||||
}
|
||||
break;
|
||||
case LIBRARY:
|
||||
if (command.getValue().equals("clear")) {
|
||||
for (UUID card : player.getLibrary().getCardList()) {
|
||||
removeCard(card);
|
||||
}
|
||||
player.getLibrary().clear();
|
||||
}
|
||||
break;
|
||||
|
|
@ -2315,22 +2275,6 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
return lki;
|
||||
}
|
||||
|
||||
private void removeCards(Cards cards) {
|
||||
for (UUID card : cards) {
|
||||
removeCard(card);
|
||||
}
|
||||
cards.clear();
|
||||
}
|
||||
|
||||
private void removeCard(UUID cardId) {
|
||||
Card card = this.getCard(cardId);
|
||||
if(card != null && card.isSplitCard()) {
|
||||
gameCards.remove(((SplitCard)card).getLeftHalfCard().getId());
|
||||
gameCards.remove(((SplitCard)card).getRightHalfCard().getId());
|
||||
}
|
||||
gameCards.remove(cardId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cheat(UUID ownerId, List<Card> library, List<Card> hand, List<PermanentCard> battlefield, List<Card> graveyard) {
|
||||
Player player = getPlayer(ownerId);
|
||||
|
|
@ -2374,25 +2318,6 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
loadCards(set, ownerId);
|
||||
}
|
||||
|
||||
public void replaceLibrary(List<Card> cardsDownToTop, UUID ownerId) {
|
||||
Player player = getPlayer(ownerId);
|
||||
if (player != null) {
|
||||
for (UUID card : player.getLibrary().getCardList()) {
|
||||
removeCard(card);
|
||||
}
|
||||
player.getLibrary().clear();
|
||||
Set<Card> cards = new HashSet<>();
|
||||
for (Card card : cardsDownToTop) {
|
||||
cards.add(card);
|
||||
}
|
||||
loadCards(cards, ownerId);
|
||||
|
||||
for (Card card : cards) {
|
||||
player.getLibrary().putOnTop(card, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean endTurn() {
|
||||
getTurn().endTurn(this, getActivePlayerId());
|
||||
|
|
|
|||
|
|
@ -105,7 +105,8 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
private List<GameEvent> simultaneousEvents = new ArrayList<>();
|
||||
private Map<UUID, CardState> cardState = new HashMap<>();
|
||||
private Map<UUID, Integer> zoneChangeCounter = new HashMap<>();
|
||||
|
||||
private Map<UUID, Card> copiedCards = new HashMap<>();
|
||||
|
||||
public GameState() {
|
||||
players = new Players();
|
||||
playerList = new PlayerList();
|
||||
|
|
@ -161,6 +162,7 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
cardState.put(entry.getKey(), entry.getValue().copy());
|
||||
}
|
||||
this.zoneChangeCounter.putAll(state.zoneChangeCounter);
|
||||
this.copiedCards.putAll(state.copiedCards);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -499,6 +501,7 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
this.simultaneousEvents = state.simultaneousEvents;
|
||||
this.cardState = state.cardState;
|
||||
this.zoneChangeCounter = state.zoneChangeCounter;
|
||||
this.copiedCards = state.copiedCards;
|
||||
}
|
||||
|
||||
public void addSimultaneousEvent(GameEvent event, Game game) {
|
||||
|
|
@ -540,13 +543,18 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
}
|
||||
}
|
||||
|
||||
public void removeCard(Card card) {
|
||||
zones.remove(card.getId());
|
||||
public void removeCopiedCard(Card card) {
|
||||
if (copiedCards.containsKey(card.getId())) {
|
||||
copiedCards.remove(card.getId());
|
||||
cardState.remove(card.getId());
|
||||
zones.remove(card.getId());
|
||||
zoneChangeCounter.remove(card.getId());
|
||||
}
|
||||
// TODO Watchers?
|
||||
// TODO Abilities?
|
||||
if (card.isSplitCard()) {
|
||||
removeCard( ((SplitCard)card).getLeftHalfCard());
|
||||
removeCard( ((SplitCard)card).getRightHalfCard());
|
||||
removeCopiedCard( ((SplitCard)card).getLeftHalfCard());
|
||||
removeCopiedCard( ((SplitCard)card).getRightHalfCard());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -819,4 +827,29 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
this.zoneChangeCounter.put(objectId, value);
|
||||
}
|
||||
|
||||
public Card getCopiedCard(UUID cardId) {
|
||||
return copiedCards.get(cardId);
|
||||
}
|
||||
|
||||
public Collection<Card> getCopiedCards() {
|
||||
return copiedCards.values();
|
||||
}
|
||||
|
||||
public Card copyCard(Card cardToCopy, Ability source, Game game) {
|
||||
Card copiedCard = cardToCopy.copy();
|
||||
copiedCard.assignNewId();
|
||||
copiedCard.setOwnerId(source.getControllerId());
|
||||
copiedCard.setCopy(true);
|
||||
copiedCards.put(copiedCard.getId(), copiedCard);
|
||||
addCard(copiedCard);
|
||||
if (copiedCard.isSplitCard()) {
|
||||
Card leftCard = ((SplitCard)copiedCard).getLeftHalfCard();
|
||||
copiedCards.put(leftCard.getId(), leftCard);
|
||||
addCard(leftCard);
|
||||
Card rightCard = ((SplitCard)copiedCard).getRightHalfCard();
|
||||
copiedCards.put(rightCard.getId(), rightCard);
|
||||
addCard(rightCard);
|
||||
}
|
||||
return copiedCard;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue