public DeckGenerator2Color(IDeckGenPool pool, final String clr1, final String clr2) { super(pool); int c1 = MagicColor.fromName(clr1); int c2 = MagicColor.fromName(clr2); if (c1 == 0 && c2 == 0) { int color1 = r.nextInt(5); int color2 = (color1 + 1 + r.nextInt(4)) % 5; colors = ColorSet.fromMask(MagicColor.WHITE << color1 | MagicColor.WHITE << color2); } else if (c1 == 0 || c2 == 0) { byte knownColor = (byte) (c1 | c2); int color1 = Arrays.binarySearch(MagicColor.WUBRG, knownColor); int color2 = (color1 + 1 + r.nextInt(4)) % 5; colors = ColorSet.fromMask(MagicColor.WHITE << color1 | MagicColor.WHITE << color2); } else { colors = ColorSet.fromMask(c1 | c2); } }
void assignMissingFields() { // Most scripts do not specify color explicitly if (null == oracleText) { System.err.println(name + " has no Oracle text."); oracleText = ""; } if (manaCost == null && color == null) System.err.println(name + " has neither ManaCost nor Color"); if (color == null) color = ColorSet.fromManaCost(manaCost); if (keywords == null) keywords = emptyList; if (abilities == null) abilities = emptyList; if (staticAbilities == null) staticAbilities = emptyList; if (triggers == null) triggers = emptyList; if (replacements == null) replacements = emptyList; if (variables == null) variables = emptyMap; if (null == nonAbilityText) nonAbilityText = ""; }
@Override public void resolve(SpellAbility sa) { final Card card = sa.getHostCard(); AbilityManaPart abMana = sa.getManaPart(); // Spells are not undoable sa.setUndoable(sa.isAbility() && sa.isUndoable()); final List<Player> tgtPlayers = getTargetPlayers(sa); final TargetRestrictions tgt = sa.getTargetRestrictions(); final boolean optional = sa.hasParam("Optional"); final Game game = sa.getActivatingPlayer().getGame(); if (optional && !sa.getActivatingPlayer() .getController() .confirmAction(sa, null, "Do you want to add mana to your mana pool?")) { return; } if (abMana.isComboMana()) { for (Player p : tgtPlayers) { int amount = sa.hasParam("Amount") ? AbilityUtils.calculateAmount(card, sa.getParam("Amount"), sa) : 1; if (tgt == null || p.canBeTargetedBy(sa)) { Player activator = sa.getActivatingPlayer(); // String colorsNeeded = abMana.getExpressChoice(); String[] colorsProduced = abMana.getComboColors().split(" "); final StringBuilder choiceString = new StringBuilder(); ColorSet colorOptions = null; if (!abMana.isAnyMana()) { colorOptions = ColorSet.fromNames(colorsProduced); } else { colorOptions = ColorSet.fromNames(MagicColor.Constant.ONLY_COLORS); } for (int nMana = 1; nMana <= amount; nMana++) { String choice = ""; byte chosenColor = activator.getController().chooseColor("Select Mana to Produce", sa, colorOptions); if (chosenColor == 0) throw new RuntimeException( "ManaEffect::resolve() /*combo mana*/ - " + activator + " color mana choice is empty for " + card.getName()); choice = MagicColor.toShortString(chosenColor); if (nMana != 1) { choiceString.append(" "); } choiceString.append(choice); } game.action.nofityOfValue(sa, card, activator + " picked " + choiceString, activator); abMana.setExpressChoice(choiceString.toString()); } } } else if (abMana.isAnyMana()) { for (Player p : tgtPlayers) { if (tgt == null || p.canBeTargetedBy(sa)) { Player act = sa.getActivatingPlayer(); // AI color choice is set in ComputerUtils so only human players need to make a choice String colorsNeeded = abMana.getExpressChoice(); String choice = ""; ColorSet colorMenu = null; byte mask = 0; // loop through colors to make menu for (int nChar = 0; nChar < colorsNeeded.length(); nChar++) { mask |= MagicColor.fromName(colorsNeeded.charAt(nChar)); } colorMenu = mask == 0 ? ColorSet.ALL_COLORS : ColorSet.fromMask(mask); byte val = act.getController().chooseColor("Select Mana to Produce", sa, colorMenu); if (0 == val) { throw new RuntimeException( "ManaEffect::resolve() /*any mana*/ - " + act + " color mana choice is empty for " + card.getName()); } choice = MagicColor.toShortString(val); game.action.nofityOfValue(sa, card, act + " picked " + choice, act); abMana.setExpressChoice(choice); } } } else if (abMana.isSpecialMana()) { for (Player p : tgtPlayers) { if (tgt == null || p.canBeTargetedBy(sa)) { String type = abMana.getOrigProduced().split("Special ")[1]; if (type.equals("EnchantedManaCost")) { Card enchanted = card.getEnchantingCard(); if (enchanted == null) continue; StringBuilder sb = new StringBuilder(); int generic = enchanted.getManaCost().getGenericCost(); if (generic > 0) sb.append(generic); for (ManaCostShard s : enchanted.getManaCost()) { ColorSet cs = ColorSet.fromMask(s.getColorMask()); if (cs.isColorless()) continue; sb.append(' '); if (cs.isMonoColor()) sb.append(MagicColor.toShortString(s.getColorMask())); else /* (cs.isMulticolor()) */ { byte chosenColor = sa.getActivatingPlayer() .getController() .chooseColor("Choose a single color from " + s.toString(), sa, cs); sb.append(MagicColor.toShortString(chosenColor)); } } abMana.setExpressChoice(sb.toString().trim()); } else if (type.equals("LastNotedType")) { Mana manaType = (Mana) Iterables.getFirst(card.getRemembered(), null); if (manaType == null) { return; } String cs = manaType.toString(); abMana.setExpressChoice(cs); } if (abMana.getExpressChoice().isEmpty()) { System.out.println( "AbilityFactoryMana::manaResolve() - special mana effect is empty for " + sa.getHostCard().getName()); } } } } for (final Player player : tgtPlayers) { abMana.produceMana(GameActionUtil.generatedMana(sa), player, sa); } // Only clear express choice after mana has been produced abMana.clearExpressChoice(); // resolveDrawback(sa); }
void updateColors(CardState c) { set(TrackableProperty.Colors, ColorSet.fromMask(c.getColor())); }
public ColorSet getSharedColors(final ColorSet ccOther) { return fromMask(getColor() & ccOther.getColor()); }
/** this has no other colors except defined by operand. */ public boolean hasNoColorsExcept(final ColorSet other) { return hasNoColorsExcept(other.getColor()); }