Code cleanup

This commit is contained in:
drdev
2013-12-02 07:31:12 +00:00
parent 93b6ac15dd
commit fe04d56568

View File

@@ -240,7 +240,7 @@ public class Card extends GameEntity implements Comparable<Card> {
private final List<Command> untapCommandList = new ArrayList<Command>();
private final List<Command> changeControllerCommandList = new ArrayList<Command>();
private final static ImmutableList<String> storableSVars = ImmutableList.of("ChosenX" );
private final static ImmutableList<String> storableSVars = ImmutableList.of("ChosenX");
private final List<Card> hauntedBy = new ArrayList<Card>();
private Card haunting = null;
@@ -1144,7 +1144,7 @@ public class Card extends GameEntity implements Comparable<Card> {
public final void addCounter(final CounterType counterType, final int n, final boolean applyMultiplier) {
final int addAmount = getTotalCountersToAdd(counterType, n, applyMultiplier);
if ( addAmount == 0 )
if (addAmount == 0)
return;
Integer oldValue = this.counters.get(counterType);
@@ -1564,7 +1564,7 @@ public class Card extends GameEntity implements Comparable<Card> {
List<CardColor> colorList = this.getCharacteristics().getCardColor();
byte colors = 0;
for(int i = colorList.size() - 1;i >= 0;i--) {
for (int i = colorList.size() - 1;i >= 0;i--) {
final CardColor cc = colorList.get(i);
colors |= cc.getColorMask();
if (!cc.isAdditional()) {
@@ -1847,11 +1847,11 @@ public class Card extends GameEntity implements Comparable<Card> {
sb.append("\r\nLife Modifier: ").append(getRules().getLife());
sb.append("\r\n\r\n");
}
if(this.isCommander)
if (this.isCommander)
{
sb.append(getOwner() + "'s Commander\r\n\r\n");
}
if(this.getName().equals("Commander effect"))
if (this.getName().equals("Commander effect"))
{
sb.append("Zone: " + getOwner().getCommander().getZone().toString() + "\r\n");
sb.append(CardFactoryUtil.getCommanderInfo(getOwner()));
@@ -2106,7 +2106,7 @@ public class Card extends GameEntity implements Comparable<Card> {
continue;
} else if (keyword.startsWith("CantBeBlockedBy")) {
sbLong.append(this.getName()).append(" can't be blocked ");
if( keyword.startsWith("CantBeBlockedByAmount"))
if (keyword.startsWith("CantBeBlockedByAmount"))
sbLong.append(getTextForKwCantBeBlockedByAmount(keyword));
else
sbLong.append(getTextForKwCantBeBlockedByType(keyword));
@@ -2149,12 +2149,12 @@ public class Card extends GameEntity implements Comparable<Card> {
List<String> subs = Lists.newArrayList(TextUtil.split(keyword.split(" ", 2)[1], ','));
List<List<String>> subsAnd = Lists.newArrayList();
List<String> orClauses = new ArrayList<String>();
for( int iOr = 0; iOr < subs.size(); iOr++ ) {
for (int iOr = 0; iOr < subs.size(); iOr++) {
String expession = subs.get(iOr);
List<String> parts = Lists.newArrayList(expession.split("[.+]"));
for(int p = 0; p < parts.size(); p++) {
for (int p = 0; p < parts.size(); p++) {
String part = parts.get(p);
if( part.equalsIgnoreCase("creature")) {
if (part.equalsIgnoreCase("creature")) {
parts.remove(p--);
continue;
}
@@ -2171,53 +2171,53 @@ public class Card extends GameEntity implements Comparable<Card> {
@Override
public String apply(Pair<Boolean, String> inp) {
boolean useNon = inp.getKey().booleanValue() == allNegative;
return (useNon ? "*NO* " : "" ) + inp.getRight();
return (useNon ? "*NO* " : "") + inp.getRight();
}
};
for( int iOr = 0; iOr < subsAnd.size(); iOr++ ) {
for (int iOr = 0; iOr < subsAnd.size(); iOr++) {
List<String> andOperands = subsAnd.get(iOr);
List<Pair<Boolean, String>> prependedAdjectives = Lists.newArrayList();
List<Pair<Boolean, String>> postponedAdjectives = Lists.newArrayList();
String creatures = null;
for(String part : andOperands) {
for (String part : andOperands) {
boolean positive = true;
if (part.startsWith("non")) {
part = part.substring(3);
positive = false;
}
if(part.startsWith("with")) {
if (part.startsWith("with")) {
positive = !part.startsWith("without");
postponedAdjectives.add(Pair.of(positive, part.substring(positive ? 4 : 7)));
} else if ( part.startsWith("power") ) {
} else if (part.startsWith("power")) {
int kwLength = 5;
String opName = Expressions.operatorName(part.substring(kwLength, kwLength + 2));
String operand = part.substring(kwLength + 2);
postponedAdjectives.add(Pair.of(true, "power" + opName + operand));
} else if ( forge.card.CardType.isACreatureType(part)) {
creatures = StringUtils.capitalize(Lang.getPlural(part)) + ( creatures == null ? "" : " or " + creatures );
} else if (forge.card.CardType.isACreatureType(part)) {
creatures = StringUtils.capitalize(Lang.getPlural(part)) + (creatures == null ? "" : " or " + creatures);
} else {
prependedAdjectives.add(Pair.of(positive, part.toLowerCase()));
}
}
StringBuilder sbShort = new StringBuilder();
if ( allNegative ) {
if (allNegative) {
boolean isFirst = true;
for(Pair<Boolean, String> pre : prependedAdjectives) {
if ( isFirst ) isFirst = false;
for (Pair<Boolean, String> pre : prependedAdjectives) {
if (isFirst) isFirst = false;
else sbShort.append(" and/or ");
boolean useNon = pre.getKey().booleanValue() == allNegative;
if( useNon ) sbShort.append("non-");
if (useNon) sbShort.append("non-");
sbShort.append(pre.getValue()).append(" ").append(creatures == null ? "creatures" : creatures);
}
if (prependedAdjectives.isEmpty())
sbShort.append(creatures == null ? "creatures" : creatures);
if(!postponedAdjectives.isEmpty()) {
if( !prependedAdjectives.isEmpty() ) {
if (!postponedAdjectives.isEmpty()) {
if (!prependedAdjectives.isEmpty()) {
sbShort.append(" and/or creatures");
}
@@ -2226,14 +2226,14 @@ public class Card extends GameEntity implements Comparable<Card> {
}
} else {
for(Pair<Boolean, String> pre : prependedAdjectives) {
for (Pair<Boolean, String> pre : prependedAdjectives) {
boolean useNon = pre.getKey().booleanValue() == allNegative;
if( useNon ) sbShort.append("non-");
if (useNon) sbShort.append("non-");
sbShort.append(pre.getValue()).append(" ");
}
sbShort.append(creatures == null ? "creatures" : creatures);
if(!postponedAdjectives.isEmpty()) {
if (!postponedAdjectives.isEmpty()) {
sbShort.append(" with ");
sbShort.append(Lang.joinHomogenous(postponedAdjectives, withToString, allNegative ? "or" : "and"));
}
@@ -2981,7 +2981,6 @@ public class Card extends GameEntity implements Comparable<Card> {
this.changeControllerCommandList.add(c);
}
public final void runChangeControllerCommands() {
for (final Command c : this.changeControllerCommandList) {
c.run();
@@ -3040,7 +3039,6 @@ public class Card extends GameEntity implements Comparable<Card> {
this.becameTargetThisTurn = becameTargetThisTurn;
}
/**
* @return the startedTheTurnUntapped
*/
@@ -3055,7 +3053,6 @@ public class Card extends GameEntity implements Comparable<Card> {
this.startedTheTurnUntapped = untapped;
}
/**
* <p>
* Getter for the field <code>owner</code>.
@@ -3096,7 +3093,6 @@ public class Card extends GameEntity implements Comparable<Card> {
public final void clearTempControllers() {
this.tempControllers.clear();
}
public final void clearControllers() {
@@ -3369,8 +3365,7 @@ public class Card extends GameEntity implements Comparable<Card> {
* @param c
* a {@link forge.game.card.Card} object.
*/
public final void unEquipCard(final Card c) // equipment.unEquipCard(equippedCard);
{
public final void unEquipCard(final Card c) { // equipment.unEquipCard(equippedCard);
this.equipping.remove(c);
c.equippedBy.remove(this);
@@ -3636,7 +3631,6 @@ public class Card extends GameEntity implements Comparable<Card> {
}
return newType;
}
/**
@@ -4047,7 +4041,7 @@ public class Card extends GameEntity implements Comparable<Card> {
public final void addMultiKickerMagnitude(final int n) { this.multiKickerMagnitude += n; }
public final void setKickerMagnitude(final int n) { this.multiKickerMagnitude = n; }
public final int getKickerMagnitude() {
if ( this.multiKickerMagnitude > 0 )
if (this.multiKickerMagnitude > 0)
return multiKickerMagnitude;
boolean hasK1 = costsPaid.contains(OptionalCost.Kicker1);
return hasK1 == costsPaid.contains(OptionalCost.Kicker2) ? (hasK1 ? 2 : 0) : 1;
@@ -4688,14 +4682,11 @@ public class Card extends GameEntity implements Comparable<Card> {
public final boolean isFortification() { return this.typeContains("Fortification"); }
public final boolean isScheme() { return this.typeContains("Scheme"); }
public final boolean isPlaneswalker() { return this.typeContains("Planeswalker"); }
public final boolean isEnchantment() { return this.typeContains("Enchantment"); }
public final boolean isAura() { return this.typeContains("Aura"); }
private boolean typeContains(final String s) {
final Iterator<String> it = this.getType().iterator();
while (it.hasNext()) {
@@ -5190,8 +5181,8 @@ public class Card extends GameEntity implements Comparable<Card> {
final String[] incR = restriction.split("\\.", 2);
boolean testFailed = false;
if(incR[0].startsWith("!")) {
testFailed = true; // a bit counter logical ))
if (incR[0].startsWith("!")) {
testFailed = true; // a bit counter logical))
incR[0] = incR[0].substring(1); // consume negation sign
}
@@ -5282,32 +5273,32 @@ public class Card extends GameEntity implements Comparable<Card> {
}
// ... Card colors
else if (property.contains("White") || property.contains("Blue") || property.contains("Black")
|| property.contains("Red") || property.contains("Green") ) {
|| property.contains("Red") || property.contains("Green")) {
boolean mustHave = !property.startsWith("non");
int desiredColor = MagicColor.fromName(mustHave ? property : property.substring(3));
boolean hasColor = CardUtil.getColors(this).hasAnyColor(desiredColor);
if( mustHave != hasColor )
if (mustHave != hasColor)
return false;
} else if (property.contains("Colorless")) { // ... Card is colorless
if( property.startsWith("non") == CardUtil.getColors(this).isColorless() ) return false;
if (property.startsWith("non") == CardUtil.getColors(this).isColorless()) return false;
} else if (property.contains("MultiColor")) { // ... Card is multicolored
if( property.startsWith("non") == CardUtil.getColors(this).isMulticolor() ) return false;
if (property.startsWith("non") == CardUtil.getColors(this).isMulticolor()) return false;
} else if (property.contains("MonoColor")) { // ... Card is monocolored
if( property.startsWith("non") == CardUtil.getColors(this).isMonoColor() ) return false;
if (property.startsWith("non") == CardUtil.getColors(this).isMonoColor()) return false;
} else if (property.equals("ChosenColor")) {
if (source.getChosenColor().isEmpty() || !CardUtil.getColors(this).hasAnyColor(MagicColor.fromName(source.getChosenColor().get(0))))
return false;
} else if (property.equals("AllChosenColors")) {
if ( source.getChosenColor().isEmpty() || !CardUtil.getColors(this).hasAllColors(ColorSet.fromNames(source.getChosenColor()).getColor()) )
if (source.getChosenColor().isEmpty() || !CardUtil.getColors(this).hasAllColors(ColorSet.fromNames(source.getChosenColor()).getColor()))
return false;
} else if (property.equals("AnyChosenColor")) {
if ( source.getChosenColor().isEmpty() || !CardUtil.getColors(this).hasAnyColor(ColorSet.fromNames(source.getChosenColor()).getColor()) )
if (source.getChosenColor().isEmpty() || !CardUtil.getColors(this).hasAnyColor(ColorSet.fromNames(source.getChosenColor()).getColor()))
return false;
} else if (property.equals("DoubleFaced")) {
@@ -5790,14 +5781,14 @@ public class Card extends GameEntity implements Comparable<Card> {
}
} else if (restriction.equals("MostProminentColor")) {
byte mask = CardFactoryUtil.getMostProminentColors(game.getCardsIn(ZoneType.Battlefield));
if( !CardUtil.getColors(this).hasAnyColor(mask))
if (!CardUtil.getColors(this).hasAnyColor(mask))
return false;
} else if (restriction.equals("LastCastThisTurn")) {
final List<Card> c = game.getStack().getCardsCastThisTurn();
if (c.isEmpty() || !this.sharesColorWith(c.get(c.size() - 1))) {
return false;
}
} else if (restriction.equals("ActivationColor" )) {
} else if (restriction.equals("ActivationColor")) {
byte manaSpent = source.getColorsPaid();
if (!CardUtil.getColors(this).hasAnyColor(manaSpent)) {
return false;
@@ -6368,7 +6359,7 @@ public class Card extends GameEntity implements Comparable<Card> {
}
} else if (property.startsWith("hasXCost")) {
SpellAbility sa1 = this.getFirstSpellAbility();
if( sa1 != null && !sa1.isXCost()) {
if (sa1 != null && !sa1.isXCost()) {
return false;
}
} else if (property.startsWith("suspended")) {
@@ -6431,7 +6422,7 @@ public class Card extends GameEntity implements Comparable<Card> {
/*
* Pattern p = Pattern.compile("[a-z]*[A-Z][A-Z][X0-9]+.*$");
* String[] parse = ???
* System.out.println("Parsing completed of: "+Property); for(int i
* System.out.println("Parsing completed of: "+Property); for (int i
* = 0; i < parse.length; i++) {
* System.out.println("parse["+i+"]: "+parse[i]); }
*/
@@ -6458,13 +6449,13 @@ public class Card extends GameEntity implements Comparable<Card> {
}
// These predicated refer to ongoing combat. If no combat happens, they'll return false (meaning not attacking/blocking ATM)
else if (property.startsWith("attacking")) {
if ( null == combat ) return false;
if (null == combat) return false;
if (property.equals("attacking")) return combat.isAttacking(this);
if (property.equals("attackingYou")) return combat.isAttacking(this, sourceController);
} else if (property.startsWith("notattacking")) {
return null == combat || !combat.isAttacking(this);
} else if (property.equals("attackedBySourceThisCombat")) {
if ( null == combat ) return false;
if (null == combat) return false;
final GameEntity defender = combat.getDefenderByAttacker(source);
if (defender instanceof Card) {
if (!this.equals((Card) defender)) {
@@ -6472,10 +6463,10 @@ public class Card extends GameEntity implements Comparable<Card> {
}
}
} else if (property.startsWith("blocking")) {
if ( null == combat ) return false;
if (null == combat) return false;
String what = property.substring("blocking".length());
if( StringUtils.isEmpty(what)) return combat.isBlocking(this);
if (StringUtils.isEmpty(what)) return combat.isBlocking(this);
if (what.startsWith("Source")) return combat.isBlocking(this, source) ;
if (what.startsWith("CreatureYouCtrl")) {
for (final Card c : CardLists.filter(sourceController.getCardsIn(ZoneType.Battlefield), Presets.CREATURES))
@@ -6517,7 +6508,7 @@ public class Card extends GameEntity implements Comparable<Card> {
} else if (property.startsWith("blockedSource")) {
return null != combat && combat.isBlocking(this, source);
} else if (property.startsWith("isBlockedByRemembered")) {
if ( null == combat ) return false;
if (null == combat) return false;
for (final Object o : source.getRemembered()) {
if (o instanceof Card && combat.isBlocking((Card) o, this)) {
return true;
@@ -6684,7 +6675,7 @@ public class Card extends GameEntity implements Comparable<Card> {
return false;
}
} else if (property.equals("IsCommander")) {
if(!this.isCommander) {
if (!this.isCommander) {
return false;
}
} else {
@@ -7048,7 +7039,7 @@ public class Card extends GameEntity implements Comparable<Card> {
public final void setDamage(final int n) {
int oldDamae = damage;
this.damage = n;
if( n != oldDamae )
if (n != oldDamae)
getGame().fireEvent(new GameEventCardStatsChanged(this));
}
@@ -7605,14 +7596,14 @@ public class Card extends GameEntity implements Comparable<Card> {
if (this.isPlaneswalker()) {
this.subtractCounter(CounterType.LOYALTY, damageToAdd);
damageType = DamageType.LoyaltyLoss;
} else {
}
else {
final Game game = source.getGame();
final String s = this + " - destroy";
final int amount = this.getAmountOfKeyword("When CARDNAME is dealt damage, destroy it.");
if(amount > 0) {
if (amount > 0) {
final Ability abDestroy = new Ability(source, ManaCost.ZERO){
@Override public void resolve() { game.getAction().destroy(Card.this, this); }
};
@@ -7624,7 +7615,7 @@ public class Card extends GameEntity implements Comparable<Card> {
}
final int amount2 = this.getAmountOfKeyword("When CARDNAME is dealt damage, destroy it. It can't be regenerated.");
if( amount2 > 0 ) {
if (amount2 > 0) {
final Ability abDestoryNoRegen = new Ability(source, ManaCost.ZERO){
@Override public void resolve() { game.getAction().destroyNoRegeneration(Card.this, this); }
};
@@ -8575,7 +8566,7 @@ public class Card extends GameEntity implements Comparable<Card> {
}
public void setSplitStateToPlayAbility(SpellAbility sa) {
if( !isSplitCard() ) return; // just in case
if (!isSplitCard()) return; // just in case
// Split card support
for (SpellAbility a : getState(CardCharacteristicName.LeftSplit).getSpellAbility()) {
if (sa == a || sa.getDescription().equals(String.format("%s (without paying its mana cost)", a.getDescription()))) {
@@ -8589,7 +8580,7 @@ public class Card extends GameEntity implements Comparable<Card> {
return;
}
}
if ( sa.getSourceCard().hasKeyword("Fuse") ) // it's ok that such card won't change its side
if (sa.getSourceCard().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);
@@ -8607,7 +8598,6 @@ public class Card extends GameEntity implements Comparable<Card> {
*/
@Override
public Game getGame() {
Player controller = getController();
if (null != controller)
return controller.getGame();
@@ -8655,7 +8645,6 @@ public class Card extends GameEntity implements Comparable<Card> {
return abilities;
}
public static Card fromPaperCard(IPaperCard pc, Player owner) {
return CardFactory.getCard(pc, owner);
}