mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 13:02:06 -08:00
Merge origin/master
This commit is contained in:
commit
020beb1bf6
9 changed files with 882 additions and 304 deletions
|
|
@ -111,12 +111,14 @@ public class ContinuousEffects implements Serializable {
|
|||
|
||||
costModificationEffects = effect.costModificationEffects.copy();
|
||||
spliceCardEffects = effect.spliceCardEffects.copy();
|
||||
temporaryEffects.putAll(effect.temporaryEffects);
|
||||
for (Map.Entry<ContinuousEffect, Set<Ability>> entry: effect.temporaryEffects.entrySet()) {
|
||||
temporaryEffects.put(entry.getKey().copy(), entry.getValue());
|
||||
}
|
||||
collectAllEffects();
|
||||
order = effect.order;
|
||||
}
|
||||
|
||||
private void collectAllEffects() {
|
||||
private synchronized void collectAllEffects() {
|
||||
allEffectsLists.add(layeredEffects);
|
||||
allEffectsLists.add(continuousRuleModifyingEffects);
|
||||
allEffectsLists.add(replacementEffects);
|
||||
|
|
@ -143,7 +145,7 @@ public class ContinuousEffects implements Serializable {
|
|||
return restrictionEffects;
|
||||
}
|
||||
|
||||
public void removeEndOfCombatEffects() {
|
||||
public synchronized void removeEndOfCombatEffects() {
|
||||
layeredEffects.removeEndOfCombatEffects();
|
||||
continuousRuleModifyingEffects.removeEndOfCombatEffects();
|
||||
replacementEffects.removeEndOfCombatEffects();
|
||||
|
|
@ -157,7 +159,7 @@ public class ContinuousEffects implements Serializable {
|
|||
spliceCardEffects.removeEndOfCombatEffects();
|
||||
}
|
||||
|
||||
public void removeEndOfTurnEffects() {
|
||||
public synchronized void removeEndOfTurnEffects() {
|
||||
layeredEffects.removeEndOfTurnEffects();
|
||||
continuousRuleModifyingEffects.removeEndOfTurnEffects();
|
||||
replacementEffects.removeEndOfTurnEffects();
|
||||
|
|
@ -171,7 +173,7 @@ public class ContinuousEffects implements Serializable {
|
|||
spliceCardEffects.removeEndOfTurnEffects();
|
||||
}
|
||||
|
||||
public void removeInactiveEffects(Game game) {
|
||||
public synchronized void removeInactiveEffects(Game game) {
|
||||
layeredEffects.removeInactiveEffects(game);
|
||||
continuousRuleModifyingEffects.removeInactiveEffects(game);
|
||||
replacementEffects.removeInactiveEffects(game);
|
||||
|
|
@ -186,7 +188,7 @@ public class ContinuousEffects implements Serializable {
|
|||
spliceCardEffects.removeInactiveEffects(game);
|
||||
}
|
||||
|
||||
public List<ContinuousEffect> getLayeredEffects(Game game) {
|
||||
public synchronized List<ContinuousEffect> getLayeredEffects(Game game) {
|
||||
List<ContinuousEffect> layerEffects = new ArrayList<>();
|
||||
for (ContinuousEffect effect : layeredEffects) {
|
||||
switch (effect.getDuration()) {
|
||||
|
|
@ -226,7 +228,7 @@ public class ContinuousEffects implements Serializable {
|
|||
*
|
||||
* @param layerEffects
|
||||
*/
|
||||
private void updateTimestamps(List<ContinuousEffect> layerEffects) {
|
||||
private synchronized void updateTimestamps(List<ContinuousEffect> layerEffects) {
|
||||
for (ContinuousEffect continuousEffect : layerEffects) {
|
||||
// check if it's new, then set order
|
||||
if (!previous.contains(continuousEffect)) {
|
||||
|
|
@ -857,7 +859,7 @@ public class ContinuousEffects implements Serializable {
|
|||
}
|
||||
|
||||
//20091005 - 613
|
||||
public void apply(Game game) {
|
||||
public synchronized void apply(Game game) {
|
||||
removeInactiveEffects(game);
|
||||
List<ContinuousEffect> activeLayerEffects = getLayeredEffects(game);
|
||||
|
||||
|
|
@ -1071,7 +1073,7 @@ public class ContinuousEffects implements Serializable {
|
|||
* @param sourceId
|
||||
* @param source
|
||||
*/
|
||||
public void addEffect(ContinuousEffect effect, UUID sourceId, Ability source) {
|
||||
public synchronized void addEffect(ContinuousEffect effect, UUID sourceId, Ability source) {
|
||||
if (!(source instanceof MageSingleton)) { // because MageSingletons may never be removed by removing the temporary effecs they are not added to the temporaryEffects to prevent this
|
||||
effect.setTemporary(true);
|
||||
Set<Ability> abilities = temporaryEffects.get(effect);
|
||||
|
|
@ -1089,7 +1091,7 @@ public class ContinuousEffects implements Serializable {
|
|||
addEffect(effect, source);
|
||||
}
|
||||
|
||||
public void addEffect(ContinuousEffect effect, Ability source) {
|
||||
public synchronized void addEffect(ContinuousEffect effect, Ability source) {
|
||||
if (effect == null) {
|
||||
logger.error("Effect is null: " + source.toString());
|
||||
return;
|
||||
|
|
@ -1167,14 +1169,14 @@ public class ContinuousEffects implements Serializable {
|
|||
}
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
public synchronized void clear() {
|
||||
for (ContinuousEffectsList effectsList : allEffectsLists) {
|
||||
effectsList.clear();
|
||||
}
|
||||
temporaryEffects.clear();
|
||||
}
|
||||
|
||||
public void removeAllTemporaryEffects() {
|
||||
public synchronized void removeAllTemporaryEffects() {
|
||||
for (Map.Entry<ContinuousEffect, Set<Ability>> entry : temporaryEffects.entrySet()) {
|
||||
switch (entry.getKey().getEffectType()) {
|
||||
case REPLACEMENT:
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@
|
|||
*/
|
||||
package mage.cards;
|
||||
|
||||
import mage.Mana;
|
||||
import mage.cards.decks.DeckCardInfo;
|
||||
import mage.cards.decks.DeckCardLayout;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
|
|
@ -35,9 +36,12 @@ import mage.cards.repository.CardInfo;
|
|||
import mage.cards.repository.CardRepository;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.ColoredManaSymbol;
|
||||
import mage.constants.Rarity;
|
||||
import mage.filter.FilterMana;
|
||||
import mage.util.ClassScanner;
|
||||
import mage.util.RandomUtil;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.PrintWriter;
|
||||
|
|
@ -45,7 +49,7 @@ import java.util.*;
|
|||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
* @author BetaSteward_at_googlemail.com, JayDi85
|
||||
*/
|
||||
public class Sets extends HashMap<String, ExpansionSet> {
|
||||
|
||||
|
|
@ -93,23 +97,50 @@ public class Sets extends HashMap<String, ExpansionSet> {
|
|||
* @return
|
||||
*/
|
||||
public static List<Card> generateRandomCardPool(int cardsCount, List<ColoredManaSymbol> allowedColors) {
|
||||
return generateRandomCardPool(cardsCount, allowedColors, false);
|
||||
}
|
||||
|
||||
public static List<Card> generateRandomCardPool(int cardsCount, List<ColoredManaSymbol> allowedColors, boolean onlyBasicLands) {
|
||||
CardCriteria criteria = new CardCriteria();
|
||||
criteria.notTypes(CardType.LAND);
|
||||
|
||||
if (onlyBasicLands) {
|
||||
// only lands
|
||||
criteria.rarities(Rarity.LAND);
|
||||
criteria.colorless(true); // basic lands is colorless
|
||||
} else {
|
||||
// any card, but not basic lands
|
||||
criteria.notTypes(CardType.LAND);
|
||||
|
||||
// clear colors
|
||||
criteria.white(false);
|
||||
criteria.blue(false);
|
||||
criteria.black(false);
|
||||
criteria.red(false);
|
||||
criteria.green(false);
|
||||
criteria.colorless(false); // colorless is not allowed for gen
|
||||
}
|
||||
|
||||
FilterMana manaNeed = new FilterMana();
|
||||
for (ColoredManaSymbol color : allowedColors) {
|
||||
switch (color) {
|
||||
case W:
|
||||
manaNeed.setWhite(true);
|
||||
criteria.white(true);
|
||||
break;
|
||||
case U:
|
||||
manaNeed.setBlue(true);
|
||||
criteria.blue(true);
|
||||
break;
|
||||
case B:
|
||||
manaNeed.setBlack(true);
|
||||
criteria.black(true);
|
||||
break;
|
||||
case R:
|
||||
manaNeed.setRed(true);
|
||||
criteria.red(true);
|
||||
break;
|
||||
case G:
|
||||
manaNeed.setGreen(true);
|
||||
criteria.green(true);
|
||||
break;
|
||||
}
|
||||
|
|
@ -123,9 +154,37 @@ public class Sets extends HashMap<String, ExpansionSet> {
|
|||
CardInfo cardInfo = cards.get(RandomUtil.nextInt(cards.size()));
|
||||
Card card = cardInfo != null ? cardInfo.getCard() : null;
|
||||
if (card != null) {
|
||||
cardPool.add(card);
|
||||
count++;
|
||||
|
||||
FilterMana manaCard = card.getColorIdentity();
|
||||
boolean cardManaOK = true;
|
||||
|
||||
if (onlyBasicLands) {
|
||||
// lands is colorless
|
||||
// discard not needed color by mana produce
|
||||
Assert.assertEquals("only basic lands allow", 1, card.getMana().size());
|
||||
for (Mana manaLand : card.getMana()) {
|
||||
if (manaLand.getWhite() > 0 && !manaNeed.isWhite()) { cardManaOK = false; }
|
||||
if (manaLand.getBlue() > 0 && !manaNeed.isBlue()) { cardManaOK = false; }
|
||||
if (manaLand.getBlack() > 0 && !manaNeed.isBlack()) { cardManaOK = false; }
|
||||
if (manaLand.getRed() > 0 && !manaNeed.isRed()) { cardManaOK = false; }
|
||||
if (manaLand.getGreen() > 0 && !manaNeed.isGreen()) { cardManaOK = false; }
|
||||
}
|
||||
} else {
|
||||
// cards
|
||||
// discard any card that have not needed color
|
||||
if (manaCard.isWhite() && !manaNeed.isWhite()) { cardManaOK = false; }
|
||||
if (manaCard.isBlue() && !manaNeed.isBlue()) { cardManaOK = false; }
|
||||
if (manaCard.isBlack() && !manaNeed.isBlack()) { cardManaOK = false; }
|
||||
if (manaCard.isRed() && !manaNeed.isRed()) { cardManaOK = false; }
|
||||
if (manaCard.isGreen() && !manaNeed.isGreen()) { cardManaOK = false; }
|
||||
}
|
||||
|
||||
if (cardManaOK) {
|
||||
cardPool.add(card);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
tries++;
|
||||
if (tries > 4096) { // to avoid infinite loop
|
||||
throw new IllegalStateException("Not enough cards for chosen colors to generate deck: " + allowedColors);
|
||||
|
|
|
|||
|
|
@ -3773,4 +3773,22 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
public List<Designation> getDesignations() {
|
||||
return designations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
PlayerImpl obj = (PlayerImpl) o;
|
||||
if (this.getId() == null || obj.getId() == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.getId().equals(obj.getId());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue