Optimize getCardTypesFromList

This commit is contained in:
drdev
2014-10-13 03:12:58 +00:00
parent d3c3e6fe43
commit 498283f9b4
4 changed files with 11 additions and 75 deletions

View File

@@ -535,7 +535,7 @@ public class GameAction {
game.getTriggerHandler().cleanUpTemporaryTriggers();
game.getReplacementHandler().cleanUpTemporaryReplacements();
for(Player p : game.getPlayers()) {
for (Player p : game.getPlayers()) {
p.getManaPool().restoreColorReplacements();
}

View File

@@ -1886,10 +1886,9 @@ public class Card extends GameEntity implements Comparable<Card>, IIdentifiable
public final FCollectionView<SpellAbility> getSpells() {
final FCollection<SpellAbility> res = new FCollection<SpellAbility>();
for (final SpellAbility sa : currentState.getNonManaAbilities()) {
if (!sa.isSpell()) {
continue;
if (sa.isSpell()) {
res.add(sa);
}
res.add(sa);
}
return res;
}
@@ -6226,7 +6225,7 @@ public class Card extends GameEntity implements Comparable<Card>, IIdentifiable
}
public void setSplitStateToPlayAbility(SpellAbility sa) {
if (!isSplitCard()) return; // just in case
if (!isSplitCard()) { return; } // just in case
// Split card support
for (SpellAbility a : getState(CardStateName.LeftSplit).getNonManaAbilities()) {
if (sa == a || sa.getDescription().equals(String.format("%s (without paying its mana cost)", a.getDescription()))) {
@@ -6240,9 +6239,9 @@ public class Card extends GameEntity implements Comparable<Card>, IIdentifiable
return;
}
}
if (sa.getHostCard().hasKeyword("Fuse")) // it's ok that such card won't change its side
if (sa.getHostCard().hasKeyword("Fuse")) { // it's ok that such card won't change its side
return;
}
throw new RuntimeException("Not found which part to choose for ability " + sa + " from card " + this);
}

View File

@@ -19,9 +19,11 @@ package forge.game.card;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.Iterables;
import forge.GameCommand;
import forge.card.CardStateName;
import forge.card.CardType;
import forge.card.ColorSet;
import forge.card.MagicColor;
import forge.card.mana.ManaCost;
@@ -1931,77 +1933,14 @@ public class CardFactoryUtil {
return filteredkw;
}
/**
* <p>
* getCardTypesFromList.
* </p>
*
* @param list
* a {@link forge.CardList} object.
* @return a int.
*/
public static int getCardTypesFromList(final CardCollectionView list) {
int count = 0;
EnumSet<CardType.CoreType> types = EnumSet.noneOf(CardType.CoreType.class);
for (Card c1 : list) {
if (c1.isCreature()) {
count++;
break;
}
Iterables.addAll(types, c1.getType().getCoreTypes());
}
for (Card c1 : list) {
if (c1.isSorcery()) {
count++;
break;
}
}
for (Card c1 : list) {
if (c1.isInstant()) {
count++;
break;
}
}
for (Card c1 : list) {
if (c1.isArtifact()) {
count++;
break;
}
}
for (Card c1 : list) {
if (c1.isEnchantment()) {
count++;
break;
}
}
for (Card c1 : list) {
if (c1.isLand()) {
count++;
break;
}
}
for (Card c1 : list) {
if (c1.isPlaneswalker()) {
count++;
break;
}
}
for (Card c1 : list) {
if (c1.isTribal()) {
count++;
break;
}
}
return count;
return types.size();
}
/**
* <p>
* getBushidoEffects.
* </p>
*
* @param c
* a {@link forge.game.card.Card} object.
* @return a {@link java.util.ArrayList} object.
*/
public static ArrayList<SpellAbility> getBushidoEffects(final Card c) {
final ArrayList<SpellAbility> list = new ArrayList<SpellAbility>();
for (final String kw : c.getKeywords()) {

View File

@@ -504,7 +504,6 @@ public class MagicStack /* extends MyObservable */ implements Iterable<SpellAbil
}
private final void finishResolving(final SpellAbility sa, final boolean fizzle) {
// remove SA and card from the stack
removeCardFromStack(sa, fizzle);
// SpellAbility is removed from the stack here
@@ -544,7 +543,6 @@ public class MagicStack /* extends MyObservable */ implements Iterable<SpellAbil
private final void removeCardFromStack(final SpellAbility sa, final boolean fizzle) {
Card source = sa.getHostCard();
if (sa.getHostCard().isCopiedSpell() || sa.isAbility()) {
// do nothing
}