mirror of
https://github.com/magefree/mage.git
synced 2025-12-26 05:22:02 -08:00
Make BoosterCollator not share state between tables on a server (#8312)
This commit is contained in:
parent
bcb42b8f46
commit
384051d9eb
14 changed files with 712 additions and 1406 deletions
|
|
@ -94,7 +94,6 @@ public abstract class ExpansionSet implements Serializable {
|
|||
protected Date releaseDate;
|
||||
protected ExpansionSet parentSet;
|
||||
protected SetType setType;
|
||||
protected BoosterCollator boosterCollator;
|
||||
|
||||
// TODO: 03.10.2018, hasBasicLands can be removed someday -- it's uses to optimize lands search in deck generation and lands adding (search all available lands from sets)
|
||||
protected boolean hasBasicLands = true;
|
||||
|
|
@ -126,20 +125,12 @@ public abstract class ExpansionSet implements Serializable {
|
|||
protected final Map<String, CardInfo> inBoosterMap = new HashMap<>();
|
||||
|
||||
public ExpansionSet(String name, String code, Date releaseDate, SetType setType) {
|
||||
this(name, code, releaseDate, setType, null);
|
||||
}
|
||||
|
||||
public ExpansionSet(String name, String code, Date releaseDate, SetType setType, BoosterCollator boosterCollator) {
|
||||
this.name = name;
|
||||
this.code = code;
|
||||
this.releaseDate = releaseDate;
|
||||
this.setType = setType;
|
||||
this.maxCardNumberInBooster = Integer.MAX_VALUE;
|
||||
savedCards = new EnumMap<>(Rarity.class);
|
||||
this.boosterCollator = boosterCollator;
|
||||
if (this.boosterCollator != null) {
|
||||
this.boosterCollator.shuffle();
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
|
@ -251,9 +242,14 @@ public abstract class ExpansionSet implements Serializable {
|
|||
}
|
||||
}
|
||||
|
||||
public BoosterCollator createCollator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<Card> createBooster() {
|
||||
if (boosterCollator != null) {
|
||||
return createBoosterUsingCollator();
|
||||
BoosterCollator collator = createCollator();
|
||||
if (collator != null) {
|
||||
return createBoosterUsingCollator(collator);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 100; i++) {//don't want to somehow loop forever
|
||||
|
|
@ -277,17 +273,11 @@ public abstract class ExpansionSet implements Serializable {
|
|||
return tryBooster();
|
||||
}
|
||||
|
||||
public void shuffleCollator() {
|
||||
if (boosterCollator != null) {
|
||||
boosterCollator.shuffle();
|
||||
}
|
||||
}
|
||||
|
||||
private List<Card> createBoosterUsingCollator() {
|
||||
private List<Card> createBoosterUsingCollator(BoosterCollator collator) {
|
||||
if (inBoosterMap.isEmpty()) {
|
||||
generateBoosterMap();
|
||||
}
|
||||
return boosterCollator
|
||||
return collator
|
||||
.makeBooster()
|
||||
.stream()
|
||||
.map(inBoosterMap::get)
|
||||
|
|
|
|||
|
|
@ -6,8 +6,5 @@ import java.util.List;
|
|||
* @author TheElk801
|
||||
*/
|
||||
public interface BoosterCollator {
|
||||
|
||||
public void shuffle();
|
||||
|
||||
public List<String> makeBooster();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,11 +12,11 @@ import java.util.List;
|
|||
*
|
||||
* @author TheElk801
|
||||
*/
|
||||
public abstract class BoosterStructure {
|
||||
public class BoosterStructure {
|
||||
|
||||
private final List<CardRun> slots;
|
||||
|
||||
protected BoosterStructure(CardRun... runs) {
|
||||
public BoosterStructure(CardRun... runs) {
|
||||
this.slots = Arrays.asList(runs);
|
||||
}
|
||||
|
||||
|
|
@ -27,10 +27,4 @@ public abstract class BoosterStructure {
|
|||
}
|
||||
return cards;
|
||||
}
|
||||
|
||||
public void shuffle() {
|
||||
for (CardRun run : this.slots) {
|
||||
run.shuffle();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package mage.collation;
|
|||
/**
|
||||
* @author TheElk801
|
||||
*/
|
||||
public abstract class CardRun extends Rotater<String> {
|
||||
public class CardRun extends Rotater<String> {
|
||||
|
||||
public CardRun(boolean keepOrder, String... numbers) {
|
||||
super(keepOrder, numbers);
|
||||
|
|
|
|||
|
|
@ -13,15 +13,8 @@ public class RarityConfiguration extends Rotater<BoosterStructure> {
|
|||
super(item1, item2);
|
||||
}
|
||||
|
||||
public RarityConfiguration(boolean keepOrder, BoosterStructure... items) {
|
||||
super(keepOrder, items);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shuffle() {
|
||||
for (BoosterStructure structure : this.items) {
|
||||
structure.shuffle();
|
||||
}
|
||||
super.shuffle();
|
||||
public RarityConfiguration(BoosterStructure... items) {
|
||||
// change to false if we ever decide to generate sequential boosters
|
||||
super(true, items);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package mage.collation;
|
|||
|
||||
import mage.util.RandomUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
|
@ -13,9 +14,8 @@ import java.util.List;
|
|||
*/
|
||||
public class Rotater<T> {
|
||||
|
||||
protected final List<T> items;
|
||||
private final boolean keepOrder;
|
||||
private int position = 0;
|
||||
private final List<T> items;
|
||||
private int position;
|
||||
|
||||
public Rotater(T item) {
|
||||
this(true, item);
|
||||
|
|
@ -26,8 +26,15 @@ public class Rotater<T> {
|
|||
}
|
||||
|
||||
public Rotater(boolean keepOrder, T... items) {
|
||||
this.items = Arrays.asList(items);
|
||||
this.keepOrder = keepOrder;
|
||||
if (keepOrder) {
|
||||
this.items = Arrays.asList(items);
|
||||
this.position = RandomUtil.nextInt(this.items.size());
|
||||
} else {
|
||||
this.items = new ArrayList<T>();
|
||||
Collections.addAll(this.items, items);
|
||||
Collections.shuffle(this.items, RandomUtil.getRandom());
|
||||
this.position = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public int iterate() {
|
||||
|
|
@ -40,11 +47,4 @@ public class Rotater<T> {
|
|||
public T getNext() {
|
||||
return items.get(iterate());
|
||||
}
|
||||
|
||||
public void shuffle() {
|
||||
position = RandomUtil.nextInt(items.size());
|
||||
if (!keepOrder) {
|
||||
Collections.shuffle(items, RandomUtil.getRandom());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue