mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
optimizations + leave game fix
This commit is contained in:
parent
99735b368b
commit
42509dd4f8
21 changed files with 175 additions and 120 deletions
|
@ -33,7 +33,7 @@ public class CardsStorage {
|
||||||
static {
|
static {
|
||||||
for (ExpansionSet set : Sets.getInstance().values()) {
|
for (ExpansionSet set : Sets.getInstance().values()) {
|
||||||
setCodes.add(set.getCode());
|
setCodes.add(set.getCode());
|
||||||
Set<Card> cards = set.createCards();
|
List<Card> cards = set.getCards();
|
||||||
allCards.addAll(cards);
|
allCards.addAll(cards);
|
||||||
for (Card card : cards) {
|
for (Card card : cards) {
|
||||||
if (CardUtil.isLand(card) && !CardUtil.isBasicLand(card)) {
|
if (CardUtil.isLand(card) && !CardUtil.isBasicLand(card)) {
|
||||||
|
|
|
@ -15,7 +15,7 @@ public class CardsStorage {
|
||||||
|
|
||||||
static {
|
static {
|
||||||
for (ExpansionSet set: Sets.getInstance().values()) {
|
for (ExpansionSet set: Sets.getInstance().values()) {
|
||||||
allCards.addAll(set.createCards());
|
allCards.addAll(set.getCards());
|
||||||
}
|
}
|
||||||
Set<String> names = new HashSet<String>();
|
Set<String> names = new HashSet<String>();
|
||||||
for (Card card : allCards) {
|
for (Card card : allCards) {
|
||||||
|
|
|
@ -84,6 +84,11 @@ public class TwoPlayerDuel extends GameImpl<TwoPlayerDuel> {
|
||||||
return opponents;
|
return opponents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void leave(UUID playerId) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TwoPlayerDuel copy() {
|
public TwoPlayerDuel copy() {
|
||||||
return new TwoPlayerDuel(this);
|
return new TwoPlayerDuel(this);
|
||||||
|
|
Binary file not shown.
|
@ -82,7 +82,7 @@ public class Sets extends HashMap<String, ExpansionSet> {
|
||||||
|
|
||||||
private void addSet(ExpansionSet set) {
|
private void addSet(ExpansionSet set) {
|
||||||
this.put(set.getCode(), set);
|
this.put(set.getCode(), set);
|
||||||
for (Card card: set.createCards()) {
|
for (Card card: set.getCards()) {
|
||||||
names.add(card.getName());
|
names.add(card.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
|
@ -43,7 +43,7 @@ import mage.game.Game;
|
||||||
|
|
||||||
public abstract class MageObjectImpl<T extends MageObjectImpl<T>> implements MageObject {
|
public abstract class MageObjectImpl<T extends MageObjectImpl<T>> implements MageObject {
|
||||||
|
|
||||||
protected final UUID objectId;
|
protected UUID objectId;
|
||||||
|
|
||||||
protected String name;
|
protected String name;
|
||||||
protected ManaCosts<ManaCost> manaCost;
|
protected ManaCosts<ManaCost> manaCost;
|
||||||
|
|
|
@ -96,7 +96,7 @@ public abstract class AbilityImpl<T extends AbilityImpl<T>> implements Ability {
|
||||||
this.choices = new Choices();
|
this.choices = new Choices();
|
||||||
}
|
}
|
||||||
|
|
||||||
public AbilityImpl(AbilityImpl<T> ability) {
|
public AbilityImpl(final AbilityImpl<T> ability) {
|
||||||
this.id = ability.id;
|
this.id = ability.id;
|
||||||
this.originalId = ability.originalId;
|
this.originalId = ability.originalId;
|
||||||
this.abilityType = ability.abilityType;
|
this.abilityType = ability.abilityType;
|
||||||
|
|
|
@ -29,11 +29,12 @@
|
||||||
package mage.abilities.costs.mana;
|
package mage.abilities.costs.mana;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import mage.Constants.ColoredManaSymbol;
|
import mage.Constants.ColoredManaSymbol;
|
||||||
import mage.Mana;
|
import mage.Mana;
|
||||||
import mage.abilities.Ability;
|
|
||||||
import mage.abilities.costs.VariableCost;
|
import mage.abilities.costs.VariableCost;
|
||||||
import mage.abilities.mana.ManaOptions;
|
import mage.abilities.mana.ManaOptions;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
|
@ -47,6 +48,8 @@ import mage.target.Targets;
|
||||||
*/
|
*/
|
||||||
public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements ManaCosts<T> {
|
public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements ManaCosts<T> {
|
||||||
|
|
||||||
|
private static Map<String, ManaCosts> costs = new HashMap<String, ManaCosts>();
|
||||||
|
|
||||||
public ManaCostsImpl() {}
|
public ManaCostsImpl() {}
|
||||||
|
|
||||||
public ManaCostsImpl(String mana) {
|
public ManaCostsImpl(String mana) {
|
||||||
|
@ -196,32 +199,41 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
|
||||||
@Override
|
@Override
|
||||||
public void load(String mana) {
|
public void load(String mana) {
|
||||||
this.clear();
|
this.clear();
|
||||||
if (mana == null || mana.length() == 0)
|
if (costs.containsKey(mana)) {
|
||||||
return;
|
ManaCosts<T> savedCosts = costs.get(mana);
|
||||||
String[] symbols = mana.split("^\\{|\\}\\{|\\}$");
|
for (ManaCost cost: savedCosts) {
|
||||||
for (String symbol: symbols) {
|
this.add((T)cost.copy());
|
||||||
if (symbol.length() > 0) {
|
}
|
||||||
if (symbol.length() == 1 || isNumeric(symbol)) {
|
}
|
||||||
if (Character.isDigit(symbol.charAt(0))) {
|
else {
|
||||||
this.add((T)new GenericManaCost(Integer.valueOf(symbol)));
|
if (mana == null || mana.length() == 0)
|
||||||
|
return;
|
||||||
|
String[] symbols = mana.split("^\\{|\\}\\{|\\}$");
|
||||||
|
for (String symbol: symbols) {
|
||||||
|
if (symbol.length() > 0) {
|
||||||
|
if (symbol.length() == 1 || isNumeric(symbol)) {
|
||||||
|
if (Character.isDigit(symbol.charAt(0))) {
|
||||||
|
this.add((T)new GenericManaCost(Integer.valueOf(symbol)));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (!symbol.equals("X"))
|
||||||
|
this.add((T)new ColoredManaCost(ColoredManaSymbol.lookup(symbol.charAt(0))));
|
||||||
|
else
|
||||||
|
this.add((T)new VariableManaCost());
|
||||||
|
//TODO: handle multiple {X} and/or {Y} symbols
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!symbol.equals("X"))
|
if (Character.isDigit(symbol.charAt(0))) {
|
||||||
this.add((T)new ColoredManaCost(ColoredManaSymbol.lookup(symbol.charAt(0))));
|
this.add((T)new MonoHybridManaCost(ColoredManaSymbol.lookup(symbol.charAt(2))));
|
||||||
else
|
}
|
||||||
this.add((T)new VariableManaCost());
|
else {
|
||||||
//TODO: handle multiple {X} and/or {Y} symbols
|
this.add((T)new HybridManaCost(ColoredManaSymbol.lookup(symbol.charAt(0)), ColoredManaSymbol.lookup(symbol.charAt(2))));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (Character.isDigit(symbol.charAt(0))) {
|
|
||||||
this.add((T)new MonoHybridManaCost(ColoredManaSymbol.lookup(symbol.charAt(2))));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.add((T)new HybridManaCost(ColoredManaSymbol.lookup(symbol.charAt(0)), ColoredManaSymbol.lookup(symbol.charAt(2))));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
costs.put(mana, this.copy());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,7 @@ public interface Card extends MageObject {
|
||||||
public String getExpansionSetCode();
|
public String getExpansionSetCode();
|
||||||
public void setExpansionSetCode(String expansionSetCode);
|
public void setExpansionSetCode(String expansionSetCode);
|
||||||
|
|
||||||
|
public void assignNewId();
|
||||||
public boolean moveToZone(Zone zone, UUID sourceId, Game game, boolean flag);
|
public boolean moveToZone(Zone zone, UUID sourceId, Game game, boolean flag);
|
||||||
public boolean moveToExile(UUID exileId, String name, UUID sourceId, Game game);
|
public boolean moveToExile(UUID exileId, String name, UUID sourceId, Game game);
|
||||||
public boolean cast(Game game, Zone fromZone, SpellAbility ability, UUID controllerId);
|
public boolean cast(Game game, Zone fromZone, SpellAbility ability, UUID controllerId);
|
||||||
|
|
|
@ -30,6 +30,7 @@ package mage.cards;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
@ -66,8 +67,7 @@ public abstract class CardImpl<T extends CardImpl<T>> extends MageObjectImpl<T>
|
||||||
this(ownerId, name);
|
this(ownerId, name);
|
||||||
this.rarity = rarity;
|
this.rarity = rarity;
|
||||||
this.cardNumber = cardNumber;
|
this.cardNumber = cardNumber;
|
||||||
for (CardType newCardType: cardTypes)
|
this.cardType.addAll(Arrays.asList(cardTypes));
|
||||||
this.cardType.add(newCardType);
|
|
||||||
this.manaCost.load(costs);
|
this.manaCost.load(costs);
|
||||||
if (cardType.contains(CardType.LAND))
|
if (cardType.contains(CardType.LAND))
|
||||||
addAbility(new PlayLandAbility(name));
|
addAbility(new PlayLandAbility(name));
|
||||||
|
@ -95,6 +95,12 @@ public abstract class CardImpl<T extends CardImpl<T>> extends MageObjectImpl<T>
|
||||||
watchers = card.watchers.copy();
|
watchers = card.watchers.copy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void assignNewId() {
|
||||||
|
this.objectId = UUID.randomUUID();
|
||||||
|
this.abilities.setSourceId(objectId);
|
||||||
|
}
|
||||||
|
|
||||||
public static Card createCard(String name) {
|
public static Card createCard(String name) {
|
||||||
try {
|
try {
|
||||||
Class<?> theClass = Class.forName(name);
|
Class<?> theClass = Class.forName(name);
|
||||||
|
|
|
@ -61,9 +61,9 @@ public abstract class ExpansionSet implements Serializable {
|
||||||
protected String symbolCode;
|
protected String symbolCode;
|
||||||
protected Date releaseDate;
|
protected Date releaseDate;
|
||||||
protected ExpansionSet parentSet;
|
protected ExpansionSet parentSet;
|
||||||
protected List<Class> cards;
|
protected List<Card> cards;
|
||||||
protected SetType setType;
|
protected SetType setType;
|
||||||
protected Map<Rarity, List<Class>> rarities;
|
protected Map<Rarity, List<Card>> rarities;
|
||||||
|
|
||||||
protected String blockName;
|
protected String blockName;
|
||||||
protected boolean hasBoosters = false;
|
protected boolean hasBoosters = false;
|
||||||
|
@ -83,7 +83,7 @@ public abstract class ExpansionSet implements Serializable {
|
||||||
this.rarities = getCardsByRarity();
|
this.rarities = getCardsByRarity();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Class> getCards() {
|
public List<Card> getCards() {
|
||||||
return cards;
|
return cards;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ public abstract class ExpansionSet implements Serializable {
|
||||||
return setType;
|
return setType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Card createCard(Class clazz) {
|
private Card createCard(Class clazz) {
|
||||||
try {
|
try {
|
||||||
Constructor<?> con = clazz.getConstructor(new Class[]{UUID.class});
|
Constructor<?> con = clazz.getConstructor(new Class[]{UUID.class});
|
||||||
return (Card) con.newInstance(new Object[]{null});
|
return (Card) con.newInstance(new Object[]{null});
|
||||||
|
@ -118,49 +118,46 @@ public abstract class ExpansionSet implements Serializable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Card> createCards() {
|
|
||||||
Set<Card> created = new HashSet<Card>();
|
|
||||||
for (Class clazz : cards) {
|
|
||||||
created.add(createCard(clazz));
|
|
||||||
}
|
|
||||||
return created;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Card findCard(String name) {
|
public Card findCard(String name) {
|
||||||
for (Card card : createCards()) {
|
for (Card card : cards) {
|
||||||
if (name.equals(card.getName()))
|
if (name.equals(card.getName())) {
|
||||||
return card;
|
Card newCard = card.copy();
|
||||||
|
newCard.assignNewId();
|
||||||
|
return newCard;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Card findCard(String name, boolean random) {
|
public Card findCard(String name, boolean random) {
|
||||||
List<Card> cards = new ArrayList<Card>();
|
List<Card> foundCards = new ArrayList<Card>();
|
||||||
for (Card card : createCards()) {
|
for (Card card : cards) {
|
||||||
if (name.equals(card.getName())) {
|
if (name.equals(card.getName())) {
|
||||||
cards.add(card);
|
foundCards.add(card);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (cards.size() > 0) {
|
if (foundCards.size() > 0) {
|
||||||
return cards.get(rnd.nextInt(cards.size()));
|
Card newCard = foundCards.get(rnd.nextInt(foundCards.size())).copy();
|
||||||
|
newCard.assignNewId();
|
||||||
|
return newCard;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String findCard(int cardNum) {
|
public String findCard(int cardNum) {
|
||||||
for (Card card : createCards()) {
|
for (Card card : cards) {
|
||||||
if (card.getCardNumber() == cardNum)
|
if (card.getCardNumber() == cardNum)
|
||||||
return card.getClass().getCanonicalName();
|
return card.getClass().getCanonicalName();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ArrayList<Class> getCardClassesForPackage(String packageName) {
|
private List<Card> getCardClassesForPackage(String packageName) {
|
||||||
ClassLoader classLoader = this.getClass().getClassLoader();
|
ClassLoader classLoader = this.getClass().getClassLoader();
|
||||||
assert classLoader != null;
|
assert classLoader != null;
|
||||||
String path = packageName.replace('.', '/');
|
String path = packageName.replace('.', '/');
|
||||||
|
@ -187,7 +184,7 @@ public abstract class ExpansionSet implements Serializable {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ArrayList<Class> classes = new ArrayList<Class>();
|
List<Class> classes = new ArrayList<Class>();
|
||||||
if (isLoadingFromJar) {
|
if (isLoadingFromJar) {
|
||||||
if (jarPath.contains("!")) {
|
if (jarPath.contains("!")) {
|
||||||
jarPath = jarPath.substring(0, jarPath.lastIndexOf('!'));
|
jarPath = jarPath.substring(0, jarPath.lastIndexOf('!'));
|
||||||
|
@ -214,7 +211,11 @@ public abstract class ExpansionSet implements Serializable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return classes;
|
List<Card> newCards = new ArrayList<Card>();
|
||||||
|
for (Class clazz: classes) {
|
||||||
|
newCards.add(createCard(clazz));
|
||||||
|
}
|
||||||
|
return newCards;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<Class> findClasses(File directory, String packageName) throws ClassNotFoundException {
|
private static List<Class> findClasses(File directory, String packageName) throws ClassNotFoundException {
|
||||||
|
@ -276,14 +277,13 @@ public abstract class ExpansionSet implements Serializable {
|
||||||
return classes;
|
return classes;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<Rarity, List<Class>> getCardsByRarity() {
|
private Map<Rarity, List<Card>> getCardsByRarity() {
|
||||||
Map<Rarity, List<Class>> cardsByRarity = new HashMap<Rarity, List<Class>>();
|
Map<Rarity, List<Card>> cardsByRarity = new HashMap<Rarity, List<Card>>();
|
||||||
|
|
||||||
for (Class clazz : cards) {
|
for (Card card : cards) {
|
||||||
Card card = createCard(clazz);
|
|
||||||
if (!cardsByRarity.containsKey(card.getRarity()))
|
if (!cardsByRarity.containsKey(card.getRarity()))
|
||||||
cardsByRarity.put(card.getRarity(), new ArrayList<Class>());
|
cardsByRarity.put(card.getRarity(), new ArrayList<Card>());
|
||||||
cardsByRarity.get(card.getRarity()).add(clazz);
|
cardsByRarity.get(card.getRarity()).add(card);
|
||||||
}
|
}
|
||||||
|
|
||||||
return cardsByRarity;
|
return cardsByRarity;
|
||||||
|
@ -332,7 +332,7 @@ public abstract class ExpansionSet implements Serializable {
|
||||||
return null;
|
return null;
|
||||||
int size = rarities.get(rarity).size();
|
int size = rarities.get(rarity).size();
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
return createCard(rarities.get(rarity).get(rnd.nextInt(size)));
|
return rarities.get(rarity).get(rnd.nextInt(size)).copy();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,6 @@
|
||||||
|
|
||||||
package mage.game;
|
package mage.game;
|
||||||
|
|
||||||
import mage.Constants;
|
|
||||||
import mage.game.match.MatchType;
|
import mage.game.match.MatchType;
|
||||||
import mage.cards.Card;
|
import mage.cards.Card;
|
||||||
import mage.game.stack.SpellStack;
|
import mage.game.stack.SpellStack;
|
||||||
|
@ -61,7 +60,6 @@ import mage.game.permanent.PermanentCard;
|
||||||
import mage.game.turn.Phase;
|
import mage.game.turn.Phase;
|
||||||
import mage.game.turn.Step;
|
import mage.game.turn.Step;
|
||||||
import mage.game.turn.Turn;
|
import mage.game.turn.Turn;
|
||||||
import mage.players.Library;
|
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
import mage.players.PlayerList;
|
import mage.players.PlayerList;
|
||||||
import mage.players.Players;
|
import mage.players.Players;
|
||||||
|
@ -97,6 +95,7 @@ public interface Game extends MageItem, Serializable {
|
||||||
public boolean canPlaySorcery(UUID playerId);
|
public boolean canPlaySorcery(UUID playerId);
|
||||||
public UUID getActivePlayerId();
|
public UUID getActivePlayerId();
|
||||||
public UUID getPriorityPlayerId();
|
public UUID getPriorityPlayerId();
|
||||||
|
public void leave(UUID playerId);
|
||||||
public boolean isGameOver();
|
public boolean isGameOver();
|
||||||
public Battlefield getBattlefield();
|
public Battlefield getBattlefield();
|
||||||
public SpellStack getStack();
|
public SpellStack getStack();
|
||||||
|
|
|
@ -53,7 +53,6 @@ import mage.game.stack.StackObject;
|
||||||
import mage.game.turn.Phase;
|
import mage.game.turn.Phase;
|
||||||
import mage.game.turn.Step;
|
import mage.game.turn.Step;
|
||||||
import mage.game.turn.Turn;
|
import mage.game.turn.Turn;
|
||||||
import mage.players.Library;
|
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
import mage.players.PlayerList;
|
import mage.players.PlayerList;
|
||||||
import mage.players.Players;
|
import mage.players.Players;
|
||||||
|
@ -114,9 +113,10 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
|
||||||
this.range = game.range;
|
this.range = game.range;
|
||||||
this.attackOption = game.attackOption;
|
this.attackOption = game.attackOption;
|
||||||
this.state = game.state.copy();
|
this.state = game.state.copy();
|
||||||
for (Map.Entry<UUID, Card> entry: game.gameCards.entrySet()) {
|
// for (Map.Entry<UUID, Card> entry: game.gameCards.entrySet()) {
|
||||||
this.gameCards.put(entry.getKey(), entry.getValue().copy());
|
// this.gameCards.put(entry.getKey(), entry.getValue().copy());
|
||||||
}
|
// }
|
||||||
|
this.gameCards = game.gameCards;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -457,7 +457,7 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
|
||||||
public synchronized void quit(UUID playerId) {
|
public synchronized void quit(UUID playerId) {
|
||||||
Player player = state.getPlayer(playerId);
|
Player player = state.getPlayer(playerId);
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
player.leaveGame(this);
|
leave(playerId);
|
||||||
fireInformEvent(player.getName() + " has left the game.");
|
fireInformEvent(player.getName() + " has left the game.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -869,6 +869,36 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
|
||||||
return getActivePlayerId().equals(playerId) && getStack().isEmpty() && isMainPhase();
|
return getActivePlayerId().equals(playerId) && getStack().isEmpty() && isMainPhase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void leave(UUID playerId) {
|
||||||
|
Player player = getPlayer(playerId);
|
||||||
|
player.leave();
|
||||||
|
//20100423 - 800.4a
|
||||||
|
for (Iterator<Permanent> it = getBattlefield().getAllPermanents().iterator(); it.hasNext();) {
|
||||||
|
Permanent perm = it.next();
|
||||||
|
if (perm.getOwnerId().equals(playerId)) {
|
||||||
|
if (perm.getAttachedTo() != null) {
|
||||||
|
Permanent attachedTo = getPermanent(perm.getAttachedTo());
|
||||||
|
if (attachedTo != null)
|
||||||
|
attachedTo.removeAttachment(perm.getId(), this);
|
||||||
|
}
|
||||||
|
it.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (Iterator<StackObject> it = getStack().iterator(); it.hasNext();) {
|
||||||
|
StackObject object = it.next();
|
||||||
|
if (object.getControllerId().equals(playerId)) {
|
||||||
|
it.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (Iterator<Permanent> it = getBattlefield().getAllPermanents().iterator(); it.hasNext();) {
|
||||||
|
Permanent perm = it.next();
|
||||||
|
if (perm.getControllerId().equals(playerId)) {
|
||||||
|
perm.moveToExile(null, "", null, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UUID getActivePlayerId() {
|
public UUID getActivePlayerId() {
|
||||||
return state.getActivePlayerId();
|
return state.getActivePlayerId();
|
||||||
|
|
|
@ -34,6 +34,7 @@ import java.util.Collection;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import mage.Constants.CardType;
|
import mage.Constants.CardType;
|
||||||
|
@ -54,8 +55,8 @@ public class Battlefield implements Serializable {
|
||||||
public Battlefield () {}
|
public Battlefield () {}
|
||||||
|
|
||||||
public Battlefield(final Battlefield battlefield) {
|
public Battlefield(final Battlefield battlefield) {
|
||||||
for (UUID permId: battlefield.field.keySet()) {
|
for (Entry<UUID, Permanent> entry: battlefield.field.entrySet()) {
|
||||||
field.put(permId, battlefield.field.get(permId).copy());
|
field.put(entry.getKey(), entry.getValue().copy());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,20 +83,32 @@ public class PermanentCard extends PermanentImpl<PermanentCard> {
|
||||||
public void reset(Game game) {
|
public void reset(Game game) {
|
||||||
// when the permanent is reset copy all original values from the card
|
// when the permanent is reset copy all original values from the card
|
||||||
// must copy card each reset so that the original values don't get modified
|
// must copy card each reset so that the original values don't get modified
|
||||||
Card copy = game.getCard(objectId).copy();
|
// Card copy = game.getCard(objectId).copy();
|
||||||
copyFromCard(copy);
|
copyFromCard(game.getCard(objectId));
|
||||||
super.reset(game);
|
super.reset(game);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void copyFromCard(Card card) {
|
protected void copyFromCard(Card card) {
|
||||||
this.name = card.getName();
|
this.name = card.getName();
|
||||||
this.abilities = card.getAbilities();
|
this.manaCost = card.getManaCost().copy();
|
||||||
this.abilities.setControllerId(this.controllerId);
|
this.color = card.getColor().copy();
|
||||||
this.cardType = card.getCardType();
|
this.power = card.getPower().copy();
|
||||||
this.color = card.getColor();
|
this.toughness = card.getToughness().copy();
|
||||||
this.manaCost = card.getManaCost();
|
this.loyalty = card.getLoyalty().copy();
|
||||||
this.power = card.getPower();
|
this.abilities = card.getAbilities().copy();
|
||||||
this.toughness = card.getToughness();
|
this.abilities.setControllerId(controllerId);
|
||||||
|
this.cardType.clear();
|
||||||
|
for (CardType cType: card.getCardType()) {
|
||||||
|
this.cardType.add(cType);
|
||||||
|
}
|
||||||
|
this.subtype.clear();
|
||||||
|
for (String subType: card.getSubtype()) {
|
||||||
|
this.subtype.add(subType);
|
||||||
|
}
|
||||||
|
this.supertype.clear();
|
||||||
|
for (String superType: card.getSupertype()) {
|
||||||
|
this.supertype.add(superType);
|
||||||
|
}
|
||||||
if (card instanceof LevelerCard) {
|
if (card instanceof LevelerCard) {
|
||||||
LevelAbility level = ((LevelerCard)card).getLevel(this.getCounters().getCount("Level"));
|
LevelAbility level = ((LevelerCard)card).getLevel(this.getCounters().getCount("Level"));
|
||||||
if (level != null) {
|
if (level != null) {
|
||||||
|
@ -107,8 +119,6 @@ public class PermanentCard extends PermanentImpl<PermanentCard> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.subtype = card.getSubtype();
|
|
||||||
this.supertype = card.getSupertype();
|
|
||||||
this.art = card.getArt();
|
this.art = card.getArt();
|
||||||
this.expansionSetCode = card.getExpansionSetCode();
|
this.expansionSetCode = card.getExpansionSetCode();
|
||||||
this.rarity = card.getRarity();
|
this.rarity = card.getRarity();
|
||||||
|
|
|
@ -55,6 +55,7 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
|
||||||
|
|
||||||
protected boolean tapped;
|
protected boolean tapped;
|
||||||
protected boolean flipped;
|
protected boolean flipped;
|
||||||
|
protected UUID originalControllerId;
|
||||||
protected UUID controllerId;
|
protected UUID controllerId;
|
||||||
protected int damage;
|
protected int damage;
|
||||||
protected boolean controlledFromStartOfTurn;
|
protected boolean controlledFromStartOfTurn;
|
||||||
|
@ -72,12 +73,14 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
|
||||||
|
|
||||||
public PermanentImpl(UUID ownerId, UUID controllerId, String name) {
|
public PermanentImpl(UUID ownerId, UUID controllerId, String name) {
|
||||||
super(ownerId, name);
|
super(ownerId, name);
|
||||||
|
this.originalControllerId = controllerId;
|
||||||
this.controllerId = controllerId;
|
this.controllerId = controllerId;
|
||||||
this.counters = new Counters();
|
this.counters = new Counters();
|
||||||
}
|
}
|
||||||
|
|
||||||
public PermanentImpl(UUID id, UUID ownerId, UUID controllerId, String name) {
|
public PermanentImpl(UUID id, UUID ownerId, UUID controllerId, String name) {
|
||||||
super(id, ownerId, name);
|
super(id, ownerId, name);
|
||||||
|
this.originalControllerId = controllerId;
|
||||||
this.controllerId = controllerId;
|
this.controllerId = controllerId;
|
||||||
this.counters = new Counters();
|
this.counters = new Counters();
|
||||||
}
|
}
|
||||||
|
@ -86,6 +89,7 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
|
||||||
super(permanent);
|
super(permanent);
|
||||||
this.tapped = permanent.tapped;
|
this.tapped = permanent.tapped;
|
||||||
this.flipped = permanent.flipped;
|
this.flipped = permanent.flipped;
|
||||||
|
this.originalControllerId = permanent.originalControllerId;
|
||||||
this.controllerId = permanent.controllerId;
|
this.controllerId = permanent.controllerId;
|
||||||
this.damage = permanent.damage;
|
this.damage = permanent.damage;
|
||||||
this.controlledFromStartOfTurn = permanent.controlledFromStartOfTurn;
|
this.controlledFromStartOfTurn = permanent.controlledFromStartOfTurn;
|
||||||
|
@ -111,7 +115,7 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reset(Game game) {
|
public void reset(Game game) {
|
||||||
// this.controllerId = ownerId;
|
this.controllerId = originalControllerId;
|
||||||
this.maxBlocks = 1;
|
this.maxBlocks = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,7 +173,6 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
|
||||||
for (Ability ability : this.abilities) {
|
for (Ability ability : this.abilities) {
|
||||||
ability.reset(game);
|
ability.reset(game);
|
||||||
}
|
}
|
||||||
this.controllerId = this.ownerId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -30,6 +30,7 @@ package mage.game.permanent;
|
||||||
|
|
||||||
import mage.game.permanent.token.Token;
|
import mage.game.permanent.token.Token;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import mage.Constants.CardType;
|
||||||
import mage.Constants.Zone;
|
import mage.Constants.Zone;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
|
@ -56,22 +57,25 @@ public class PermanentToken extends PermanentImpl<PermanentToken> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reset(Game game) {
|
public void reset(Game game) {
|
||||||
Token copy = token.copy();
|
// Token copy = token.copy();
|
||||||
copyFromToken(copy);
|
copyFromToken(token);
|
||||||
super.reset(game);
|
super.reset(game);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void copyFromToken(Token token) {
|
protected void copyFromToken(Token token) {
|
||||||
this.name = token.getName();
|
this.name = token.getName();
|
||||||
this.abilities.clear();
|
this.abilities = token.getAbilities().copy();
|
||||||
for (Ability ability: token.getAbilities()) {
|
this.cardType.clear();
|
||||||
this.addAbility(ability);
|
for (CardType cType: token.getCardType()) {
|
||||||
|
this.cardType.add(cType);
|
||||||
}
|
}
|
||||||
this.cardType = token.getCardType();
|
this.subtype.clear();
|
||||||
this.color = token.getColor();
|
for (String subType: token.getSubtype()) {
|
||||||
this.power = token.getPower();
|
this.subtype.add(subType);
|
||||||
this.toughness = token.getToughness();
|
}
|
||||||
this.subtype = token.getSubtype();
|
this.color = token.getColor().copy();
|
||||||
|
this.power = token.getPower().copy();
|
||||||
|
this.toughness = token.getToughness().copy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -330,8 +330,14 @@ public class Spell<T extends Spell<T>> implements StackObject, Card {
|
||||||
throw new UnsupportedOperationException("Unsupported operation");
|
throw new UnsupportedOperationException("Unsupported operation");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Ability getStackAbility() {
|
public Ability getStackAbility() {
|
||||||
return this.ability;
|
return this.ability;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void assignNewId() {
|
||||||
|
throw new UnsupportedOperationException("Unsupported operation");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,6 @@ import mage.counters.Counters;
|
||||||
import mage.filter.FilterAbility;
|
import mage.filter.FilterAbility;
|
||||||
import mage.game.events.GameEvent;
|
import mage.game.events.GameEvent;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.Table;
|
|
||||||
import mage.game.draft.Draft;
|
import mage.game.draft.Draft;
|
||||||
import mage.game.match.Match;
|
import mage.game.match.Match;
|
||||||
import mage.game.permanent.Permanent;
|
import mage.game.permanent.Permanent;
|
||||||
|
@ -126,7 +125,7 @@ public interface Player extends MageItem, Copyable<Player> {
|
||||||
public boolean discard(Card card, Ability source, Game game);
|
public boolean discard(Card card, Ability source, Game game);
|
||||||
public void lost(Game game);
|
public void lost(Game game);
|
||||||
public void won(Game game);
|
public void won(Game game);
|
||||||
public void leaveGame(Game game);
|
public void leave();
|
||||||
public void concede(Game game);
|
public void concede(Game game);
|
||||||
public void abort();
|
public void abort();
|
||||||
|
|
||||||
|
|
|
@ -732,11 +732,13 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void concede(Game game) {
|
public void concede(Game game) {
|
||||||
leaveGame(game);
|
this.loses = true;
|
||||||
|
this.abort();
|
||||||
|
game.leave(playerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void leaveGame(Game game) {
|
public void leave() {
|
||||||
this.passed = true;
|
this.passed = true;
|
||||||
this.abort();
|
this.abort();
|
||||||
this.loses = true;
|
this.loses = true;
|
||||||
|
@ -745,29 +747,6 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
|
||||||
this.hand.clear();
|
this.hand.clear();
|
||||||
this.graveyard.clear();
|
this.graveyard.clear();
|
||||||
this.library.clear();
|
this.library.clear();
|
||||||
for (Iterator<Permanent> it = game.getBattlefield().getAllPermanents().iterator(); it.hasNext();) {
|
|
||||||
Permanent perm = it.next();
|
|
||||||
if (perm.getOwnerId().equals(playerId)) {
|
|
||||||
if (perm.getAttachedTo() != null) {
|
|
||||||
Permanent attachedTo = game.getPermanent(perm.getAttachedTo());
|
|
||||||
if (attachedTo != null)
|
|
||||||
attachedTo.removeAttachment(perm.getId(), game);
|
|
||||||
}
|
|
||||||
it.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (Iterator<StackObject> it = game.getStack().iterator(); it.hasNext();) {
|
|
||||||
StackObject object = it.next();
|
|
||||||
if (object.getControllerId().equals(playerId)) {
|
|
||||||
it.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (Iterator<Permanent> it = game.getBattlefield().getAllPermanents().iterator(); it.hasNext();) {
|
|
||||||
Permanent perm = it.next();
|
|
||||||
if (perm.getControllerId().equals(playerId)) {
|
|
||||||
perm.moveToExile(null, "", null, game);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -782,7 +761,7 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
|
||||||
//20100423 - 603.9
|
//20100423 - 603.9
|
||||||
if (!this.wins)
|
if (!this.wins)
|
||||||
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.LOST, null, null, playerId));
|
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.LOST, null, null, playerId));
|
||||||
leaveGame(game);
|
game.leave(playerId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue