use of mage.cards.ExpansionSet in project mage by magefree.
the class MomirEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
int value = source.getManaCostsToPay().getX();
if (game.isSimulation()) {
// Create dummy token to prevent multiple DB find cards what causes H2 java.lang.IllegalStateException if AI cancels calculation because of time out
Token token = new CreatureToken(value, value + 1);
token.putOntoBattlefield(1, game, source, source.getControllerId(), false, false);
return true;
}
// should this be random across card names
CardCriteria criteria = new CardCriteria().types(CardType.CREATURE).manaValue(value);
List<CardInfo> options = CardRepository.instance.findCards(criteria);
if (options == null || options.isEmpty()) {
game.informPlayers("No random creature card with mana value of " + value + " was found.");
return false;
}
// search for a random non custom set creature
EmptyToken token = null;
while (!options.isEmpty()) {
int index = RandomUtil.nextInt(options.size());
ExpansionSet expansionSet = Sets.findSet(options.get(index).getSetCode());
if (expansionSet == null || !expansionSet.getSetType().isEternalLegal()) {
options.remove(index);
} else {
Card card = options.get(index).getCard();
if (card != null) {
token = new EmptyToken();
CardUtil.copyTo(token).from(card, game);
break;
} else {
options.remove(index);
}
}
}
if (token != null) {
token.putOntoBattlefield(1, game, source, source.getControllerId(), false, false);
return true;
}
return false;
}
use of mage.cards.ExpansionSet in project mage by magefree.
the class BoosterGenerationTest method test_CollectBoosterStats.
// debug only: collect info about cards in boosters, see https://github.com/magefree/mage/issues/8081
@Ignore
@Test
public void test_CollectBoosterStats() {
ExpansionSet setToAnalyse = Innistrad.getInstance();
int openBoosters = 1000;
Map<String, Integer> resRatio = new HashMap<>();
int totalCards = 0;
for (int i = 1; i <= openBoosters; i++) {
List<Card> booster = setToAnalyse.createBooster();
totalCards += booster.size();
booster.forEach(card -> {
String code = String.format("%s %s", card.getRarity().getCode(), card.getName());
resRatio.putIfAbsent(code, 0);
resRatio.computeIfPresent(code, (u, count) -> count + 1);
});
}
final Integer totalCardsFinal = totalCards;
List<String> info = resRatio.entrySet().stream().sorted(new Comparator<Map.Entry<String, Integer>>() {
@Override
public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
return Integer.compare(o2.getValue(), o1.getValue());
}
}).map(e -> String.format("%s: %d", e.getKey(), e.getValue())).collect(Collectors.toList());
System.out.println(setToAnalyse.getName() + " - boosters opened: " + openBoosters + ". Found cards: " + totalCardsFinal + "\n" + info.stream().collect(Collectors.joining("\n")));
}
use of mage.cards.ExpansionSet in project mage by magefree.
the class SummonThePackEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
ChooseExpansionSetEffect effect = new ChooseExpansionSetEffect(Outcome.UnboostCreature);
effect.apply(game, source);
Player controller = game.getPlayer(source.getControllerId());
String setChosen = null;
if (effect.getValue("setchosen") != null) {
setChosen = (String) effect.getValue("setchosen");
} else if (game.getState().getValue(this.getId() + "_set") != null) {
setChosen = (String) game.getState().getValue(this.getId() + "_set");
}
if (setChosen != null && controller != null) {
// ExpansionInfo set = ExpansionRepository.instance.getSetByName(setChosen);
ExpansionSet expansionSet = Sets.findSet(setChosen);
if (expansionSet != null) {
List<Card> boosterPack = expansionSet.create15CardBooster();
List<Card> creatureCards = new ArrayList<>();
if (boosterPack != null) {
StringBuilder message = new StringBuilder(controller.getLogName()).append(" opened: ");
for (Card c : boosterPack) {
if (c != null && c.isCreature(game)) {
message.append(c.getName()).append(" ");
message.append(" (creature card) ");
ContinuousEffect effect2 = new BecomesBlackZombieAdditionEffect(false);
effect2.setTargetPointer(new FixedTarget(c.getId()));
game.addEffect(effect2, source);
creatureCards.add(c);
c.setZone(Zone.OUTSIDE, game);
}
}
if (creatureCards.size() > 0) {
Set<Card> ccs = new HashSet<>(creatureCards);
game.loadCards(ccs, controller.getId());
controller.moveCards(ccs, Zone.BATTLEFIELD, source, game);
}
game.informPlayers(message.toString());
}
}
}
return false;
}
use of mage.cards.ExpansionSet in project mage by magefree.
the class RandomBoosterDraft method getNextBooster.
private ExpansionSet getNextBooster() {
if (useBoosters.isEmpty()) {
resetBoosters();
}
ExpansionSet theBooster = useBoosters.get(0);
useBoosters.remove(theBooster);
return theBooster;
}
use of mage.cards.ExpansionSet in project mage by magefree.
the class MageBook method updateCardStats.
private void updateCardStats(String setCode, boolean isCardsShow) {
// sets do not have total cards number, it's a workaround
ExpansionSet set = Sets.findSet(setCode);
if (set != null) {
setCaption.setText(set.getCode() + " - " + set.getName());
} else {
setCaption.setText("ERROR");
setInfo.setText("ERROR");
return;
}
if (!isCardsShow) {
// tokens or emblems, stats not need
setInfo.setText("");
return;
}
// cards stats
List<Integer> haveNumbers = set.getSetCardInfo().stream().map(ExpansionSet.SetCardInfo::getCardNumberAsInt).collect(Collectors.toList());
int startNumber = haveNumbers.stream().min(Integer::compareTo).orElse(9999);
int endNumber = haveNumbers.stream().max(Integer::compareTo).orElse(0);
// second run for empty numbers
int countHave = haveNumbers.size();
int countNotHave = IntStream.range(startNumber, endNumber + 1).map(x -> haveNumbers.contains(x) ? 0 : 1).sum();
// result
setInfo.setText(String.format("%d cards of %d are available", countHave, countHave + countNotHave));
if (countNotHave > 0) {
setInfo.setForeground(new Color(150, 0, 0));
} else {
setInfo.setForeground(jLayeredPane.getForeground());
}
}
Aggregations