mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 21:12:04 -08:00
add jumpstart swiss and elimiation tournament formats.
This commit is contained in:
parent
57ed834c14
commit
1695e6767d
12 changed files with 272 additions and 5 deletions
|
|
@ -0,0 +1,84 @@
|
|||
package mage.game.jumpstart;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.io.CharSource;
|
||||
import com.google.common.io.Files;
|
||||
import com.google.common.io.Resources;
|
||||
|
||||
import mage.cards.Card;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.cards.decks.DeckCardInfo;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
import mage.game.GameException;
|
||||
|
||||
public class JumpstartPoolGenerator {
|
||||
|
||||
private static final String RESOURCE_NAME = "mage/game/jumpstart/jumpstart.txt";
|
||||
private static final List<JumpstartPack> JUMPSTART_PACKS;
|
||||
|
||||
static {
|
||||
try {
|
||||
CharSource source = Resources.asCharSource(Resources.getResource(RESOURCE_NAME), Charsets.UTF_8);
|
||||
List<JumpstartPack> packs = new ArrayList<>();
|
||||
JumpstartPack pack = new JumpstartPack();
|
||||
for (String line : source.readLines()) {
|
||||
if (line.isEmpty()) {
|
||||
if (!pack.isEmpty()) {
|
||||
packs.add(pack);
|
||||
pack = new JumpstartPack();
|
||||
}
|
||||
} else if (line.startsWith("#")) {
|
||||
// skip comment
|
||||
} else {
|
||||
String[] ls = line.split(" ", 3);
|
||||
pack.add(new DeckCardInfo(ls[2], ls[1], ls[0]));
|
||||
}
|
||||
}
|
||||
JUMPSTART_PACKS = Collections.unmodifiableList(packs);
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Set<Card> generatePool() {
|
||||
try {
|
||||
DeckCardLists list = new DeckCardLists();
|
||||
SecureRandom random = new SecureRandom();
|
||||
for (int i = 0; i < 2; i++) {
|
||||
int index = random.nextInt(JUMPSTART_PACKS.size());
|
||||
list.getCards().addAll(JUMPSTART_PACKS.get(index).getCards());
|
||||
}
|
||||
return Deck.load(list).getCards();
|
||||
} catch (GameException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static class JumpstartPack {
|
||||
|
||||
private final List<DeckCardInfo> cards = new ArrayList<>();
|
||||
|
||||
public void add(DeckCardInfo card) {
|
||||
cards.add(card);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return cards.isEmpty();
|
||||
}
|
||||
|
||||
public List<DeckCardInfo> getCards() {
|
||||
return Collections.unmodifiableList(cards);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
15
Mage/src/main/java/mage/game/jumpstart/jumpstart.txt
Normal file
15
Mage/src/main/java/mage/game/jumpstart/jumpstart.txt
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
# setCode cardNum cardName
|
||||
IKO 105 Whisper Squad
|
||||
IKO 105 Whisper Squad
|
||||
IKO 105 Whisper Squad
|
||||
IKO 105 Whisper Squad
|
||||
|
||||
IKO 113 Drannith Stinger
|
||||
IKO 113 Drannith Stinger
|
||||
IKO 113 Drannith Stinger
|
||||
IKO 113 Drannith Stinger
|
||||
|
||||
IKO 149 Essence Symbiote
|
||||
IKO 149 Essence Symbiote
|
||||
IKO 149 Essence Symbiote
|
||||
IKO 149 Essence Symbiote
|
||||
|
|
@ -19,7 +19,8 @@ public class LimitedOptions implements Serializable {
|
|||
protected int numberBoosters;
|
||||
protected boolean isRandom;
|
||||
protected boolean isRichMan;
|
||||
protected Deck cubeFromDeck = null;
|
||||
protected Deck cubeFromDeck;
|
||||
protected boolean isJumpstart;
|
||||
|
||||
public List<String> getSetCodes() {
|
||||
return sets;
|
||||
|
|
@ -80,4 +81,13 @@ public class LimitedOptions implements Serializable {
|
|||
public void setIsRichMan(boolean isRichMan) {
|
||||
this.isRichMan = isRichMan;
|
||||
}
|
||||
|
||||
public void setIsJumpstart(boolean isJumpstart) {
|
||||
this.isJumpstart = isJumpstart;
|
||||
}
|
||||
|
||||
public boolean getIsJumpstart() {
|
||||
return this.isJumpstart;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,32 @@
|
|||
|
||||
package mage.game.tournament;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import mage.cards.ExpansionSet;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.constants.TournamentPlayerState;
|
||||
import mage.game.draft.Draft;
|
||||
import mage.game.draft.DraftCube;
|
||||
import mage.game.events.*;
|
||||
import mage.game.events.Listener;
|
||||
import mage.game.events.PlayerQueryEvent;
|
||||
import mage.game.events.PlayerQueryEventSource;
|
||||
import mage.game.events.TableEvent;
|
||||
import mage.game.events.TableEvent.EventType;
|
||||
import mage.game.events.TableEventSource;
|
||||
import mage.game.jumpstart.JumpstartPoolGenerator;
|
||||
import mage.game.match.Match;
|
||||
import mage.game.match.MatchPlayer;
|
||||
import mage.game.result.ResultProtos.MatchPlayerProto;
|
||||
|
|
@ -20,7 +37,6 @@ import mage.game.result.ResultProtos.TourneyRoundProto;
|
|||
import mage.players.Player;
|
||||
import mage.players.PlayerType;
|
||||
import mage.util.RandomUtil;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -394,6 +410,8 @@ public abstract class TournamentImpl implements Tournament {
|
|||
for (int i = 0; i < options.getLimitedOptions().getNumberBoosters(); i++) {
|
||||
player.getDeck().getSideboard().addAll(cube.createBooster());
|
||||
}
|
||||
} else if (options.getLimitedOptions().getIsJumpstart()) {
|
||||
player.getDeck().getSideboard().addAll(JumpstartPoolGenerator.generatePool());
|
||||
} else {
|
||||
for (ExpansionSet set : sets) {
|
||||
player.getDeck().getSideboard().addAll(set.createBooster());
|
||||
|
|
|
|||
|
|
@ -18,7 +18,8 @@ public class TournamentType implements Serializable {
|
|||
protected boolean limited; // or construced
|
||||
protected boolean elimination; // or Swiss
|
||||
protected boolean isRandom;
|
||||
protected boolean isRichMan = false; // or Rich Man Draft
|
||||
protected boolean isRichMan; // or Rich Man Draft
|
||||
protected boolean isJumpstart;
|
||||
|
||||
protected TournamentType() {
|
||||
}
|
||||
|
|
@ -68,4 +69,8 @@ public class TournamentType implements Serializable {
|
|||
return this.isRichMan;
|
||||
}
|
||||
|
||||
public boolean isJumpstart() {
|
||||
return this.isJumpstart;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue