Minor improvements - StringBuilder now have initial value

This commit is contained in:
vraskulin 2017-02-28 15:26:07 +03:00
parent aa01db1432
commit 0bc9cf91a8
15 changed files with 61 additions and 81 deletions

View file

@ -38,7 +38,7 @@ public class ArrowBuilder {
private int currentHeight;
public enum Type {
PAIRED, SOURCE, TARGET, COMBAT, ENCHANT_PLAYERS;
PAIRED, SOURCE, TARGET, COMBAT, ENCHANT_PLAYERS
}
/**

View file

@ -27,6 +27,8 @@
*/
package mage.server.util;
import org.apache.log4j.Logger;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
@ -39,7 +41,6 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.apache.log4j.Logger;
/**
* Handles server messages (Messages of the Day). Reloads messages every 5
@ -193,7 +194,7 @@ public class ServerMessagesUtil {
// }
// });
public void setStartDate(long milliseconds) {
this.startDate = milliseconds;
startDate = milliseconds;
}
public void incGamesStarted() {

View file

@ -27,9 +27,6 @@
*/
package mage.cards.b;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility;
@ -47,6 +44,10 @@ import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.target.common.TargetCreaturePermanent;
import java.util.ArrayList;
import java.util.Collections;
import java.util.UUID;
/**
*
* @author fireshoes
@ -64,14 +65,14 @@ public class BoldwyrIntimidator extends CardImpl {
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoldwyrIntimidatorEffect()));
// {R}: Target creature becomes a Coward until end of turn.
Effect effect = new BecomesCreatureTypeTargetEffect(Duration.EndOfTurn, new ArrayList<>(Arrays.asList("Coward")), true);
Effect effect = new BecomesCreatureTypeTargetEffect(Duration.EndOfTurn, new ArrayList<>(Collections.singletonList("Coward")), true);
effect.setText("Target creature becomes a Coward until end of turn");
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, effect, new ManaCostsImpl("{R}"));
ability.addTarget(new TargetCreaturePermanent());
this.addAbility(ability);
// {2}{R}: Target creature becomes a Warrior until end of turn.
effect = new BecomesCreatureTypeTargetEffect(Duration.EndOfTurn, new ArrayList<>(Arrays.asList("Warrior")), true);
effect = new BecomesCreatureTypeTargetEffect(Duration.EndOfTurn, new ArrayList<>(Collections.singletonList("Warrior")), true);
effect.setText("Target creature becomes a Warrior until end of turn");
ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, effect, new ManaCostsImpl("{2}{R}"));
ability.addTarget(new TargetCreaturePermanent());

View file

@ -27,9 +27,6 @@
*/
package mage.cards.c;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.UUID;
import mage.MageInt;
import mage.ObjectColor;
import mage.abilities.Ability;
@ -61,6 +58,10 @@ import mage.players.Player;
import mage.target.common.TargetCardInGraveyard;
import mage.target.targetpointer.FixedTarget;
import java.util.ArrayList;
import java.util.Collections;
import java.util.UUID;
/**
*
* @author emerald000
@ -132,7 +133,7 @@ class ChainerDementiaMasterEffect extends OneShotEffect {
ContinuousEffectImpl effect = new BecomesColorTargetEffect(ObjectColor.BLACK, Duration.WhileOnBattlefield);
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
effect = new BecomesCreatureTypeTargetEffect(Duration.WhileOnBattlefield, new ArrayList<>(Arrays.asList("Nightmare")), false);
effect = new BecomesCreatureTypeTargetEffect(Duration.WhileOnBattlefield, new ArrayList<>(Collections.singletonList("Nightmare")), false);
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
}

View file

@ -27,7 +27,6 @@
*/
package mage.cards.c;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.costs.Cost;
import mage.abilities.costs.common.PayEnergyCost;
@ -49,6 +48,8 @@ import mage.players.Player;
import mage.target.TargetPermanent;
import mage.target.targetpointer.FixedTarget;
import java.util.UUID;
/**
*
* @author LevelX2
@ -104,9 +105,10 @@ class ConfiscationCoupEffect extends OneShotEffect {
if (targetPermanent != null) {
Cost cost = new PayEnergyCost(targetPermanent.getManaCost().convertedManaCost());
if (cost.canPay(source, source.getSourceId(), source.getControllerId(), game)) {
String energy = "";
for (int i = 0; i < targetPermanent.getManaCost().convertedManaCost(); i++) {
energy += "{E}";
int convertedManaCost = targetPermanent.getManaCost().convertedManaCost();
StringBuilder energy = new StringBuilder(convertedManaCost);
for (int i = 0; i < convertedManaCost; i++) {
energy.append("{E}");
}
if (controller.chooseUse(outcome, "Pay " + energy + " to get control of " + targetPermanent.getLogName() + '?', source, game)) {
if (cost.pay(source, game, source.getSourceId(), source.getControllerId(), true)) {

View file

@ -27,10 +27,12 @@
*/
package mage.cards.c;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.common.BeginningOfUpkeepTriggeredAbility;
import mage.abilities.costs.Cost;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.DamageEverythingEffect;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
@ -40,11 +42,9 @@ import mage.constants.TargetController;
import mage.counters.CounterType;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.abilities.costs.Cost;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.common.DamageEverythingEffect;
import java.util.UUID;
@ -93,14 +93,12 @@ class CycloneEffect extends OneShotEffect {
Player player = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId());
int total = permanent.getCounters(game).getCount(CounterType.WIND);
String greens = "";
StringBuilder greens = new StringBuilder(total);
for (int i=0; i < total; i++){
greens+="{G}";
greens.append("{G}");
}
if(this.choice(game, source, player, new ManaCostsImpl(greens))){
if(this.choice(game, source, player, new ManaCostsImpl(greens.toString()))){
DamageEverythingEffect dmg = new DamageEverythingEffect(total);
dmg.apply(game, source);
} else {

View file

@ -27,8 +27,6 @@
*/
package mage.cards.e;
import java.util.Arrays;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.common.SimpleStaticAbility;
@ -46,6 +44,9 @@ import mage.constants.Zone;
import mage.filter.common.FilterCreatureCard;
import mage.target.common.TargetCardInHand;
import java.util.Collections;
import java.util.UUID;
/**
*
* @author LevelX2
@ -65,7 +66,7 @@ public class ErebossEmissary extends CardImpl {
this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new ConditionalContinuousEffect(
new BoostEnchantedEffect(2, 2, Duration.EndOfTurn),
new BoostSourceEffect(2, 2, Duration.EndOfTurn),
new SourceHasSubtypeCondition(Arrays.asList("Aura")),
new SourceHasSubtypeCondition(Collections.singletonList("Aura")),
"{this} gets +2/+2 until end of turn. If Erebos's Emissary is an Aura, enchanted creature gets +2/+2 until end of turn instead"),
new DiscardTargetCost(new TargetCardInHand(new FilterCreatureCard()))));

View file

@ -27,9 +27,6 @@
*/
package mage.cards.o;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.common.EntersBattlefieldControlledTriggeredAbility;
import mage.abilities.costs.common.DiscardCardCost;
@ -51,6 +48,10 @@ import mage.filter.FilterPermanent;
import mage.filter.common.FilterControlledCreaturePermanent;
import mage.filter.predicate.permanent.AnotherPredicate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.UUID;
/**
*
* @author fireshoes
@ -82,7 +83,7 @@ public class OliviaMobilizedForWar extends CardImpl {
effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn);
effect.setText(", it gains haste until end of turn,");
doIfCostPaid.addEffect(effect);
effect = new BecomesCreatureTypeTargetEffect(Duration.WhileOnBattlefield, new ArrayList<>(Arrays.asList("Vampire")), false);
effect = new BecomesCreatureTypeTargetEffect(Duration.WhileOnBattlefield, new ArrayList<>(Collections.singletonList("Vampire")), false);
effect.setText("and it becomes a Vampire in addition to its other types");
doIfCostPaid.addEffect(effect);
this.addAbility(new EntersBattlefieldControlledTriggeredAbility(Zone.BATTLEFIELD, doIfCostPaid, filter, false, SetTargetPointer.PERMANENT, null));

View file

@ -27,20 +27,10 @@
*/
package mage.abilities;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import mage.MageObject;
import mage.MageObjectReference;
import mage.Mana;
import mage.abilities.costs.AdjustingSourceCosts;
import mage.abilities.costs.AlternativeSourceCosts;
import mage.abilities.costs.Cost;
import mage.abilities.costs.Costs;
import mage.abilities.costs.CostsImpl;
import mage.abilities.costs.OptionalAdditionalModeSourceCosts;
import mage.abilities.costs.OptionalAdditionalSourceCosts;
import mage.abilities.costs.VariableCost;
import mage.abilities.costs.*;
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.costs.mana.ManaCost;
import mage.abilities.costs.mana.ManaCosts;
@ -55,12 +45,7 @@ import mage.abilities.effects.common.ManaEffect;
import mage.abilities.keyword.FlashbackAbility;
import mage.abilities.mana.ActivatedManaAbilityImpl;
import mage.cards.Card;
import mage.constants.AbilityType;
import mage.constants.AbilityWord;
import mage.constants.EffectType;
import mage.constants.Outcome;
import mage.constants.SpellAbilityType;
import mage.constants.Zone;
import mage.constants.*;
import mage.game.Game;
import mage.game.command.Emblem;
import mage.game.events.GameEvent;
@ -76,6 +61,10 @@ import mage.util.ThreadLocalStringBuilder;
import mage.watchers.Watcher;
import org.apache.log4j.Logger;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
/**
* @author BetaSteward_at_googlemail.com
*/
@ -496,7 +485,7 @@ public abstract class AbilityImpl implements Ability {
* @return announce message
*/
protected String handleOtherXCosts(Game game, Player controller) {
String announceString = null;
StringBuilder announceString = new StringBuilder();
for (VariableCost variableCost : this.costs.getVariableCosts()) {
if (!(variableCost instanceof VariableManaCost)) {
int xValue = variableCost.announceXValue(this, game);
@ -508,14 +497,10 @@ public abstract class AbilityImpl implements Ability {
variableCost.setAmount(xValue);
((Cost) variableCost).setPaid();
String message = controller.getLogName() + " announces a value of " + xValue + " (" + variableCost.getActionText() + ')';
if (announceString == null) {
announceString = message;
} else {
announceString = announceString + ' ' + message;
}
announceString.append(message);
}
}
return announceString;
return announceString.toString();
}
/**

View file

@ -62,7 +62,7 @@ public class CantHaveMoreThanAmountCountersSourceAbility extends SimpleStaticAbi
@Override
public String getRule() {
return "Rasputin can't have more than " + CardUtil.numberToText(this.amount) + " " + this.counterType.getName() + " counters on it.";
return "Rasputin can't have more than " + CardUtil.numberToText(this.amount) + ' ' + this.counterType.getName() + " counters on it.";
}
@Override

View file

@ -82,11 +82,11 @@ public class VariableManaCost extends ManaCostImpl implements VariableCost {
@Override
public String getText() {
if (multiplier > 1) {
String symbol = "";
StringBuilder symbol = new StringBuilder(multiplier);
for (int i = 0; i < multiplier; i++) {
symbol += "{X}";
symbol.append("{X}");
}
return symbol;
return symbol.toString();
} else {
return "{X}";
}

View file

@ -109,7 +109,7 @@ public class CantBeTargetedAttachedEffect extends ContinuousRuleModifyingEffectI
return staticText;
}
StringBuilder sb = new StringBuilder();
sb.append(attachmentType.verb() + " creature");
sb.append(attachmentType.verb()).append(" creature");
sb.append(" can't be the target of ");
sb.append(filterSource.getMessage());
if (!duration.toString().isEmpty()) {

View file

@ -70,8 +70,7 @@ class DredgeEffect extends ReplacementEffectImpl {
public DredgeEffect(int value) {
super(Duration.WhileInGraveyard, Outcome.ReturnToHand);
this.amount = value;
this.staticText = new StringBuilder("Dredge ").append(Integer.toString(value))
.append(" <i>(If you would draw a card, instead you may put exactly " + value + " card(s) from the top of your library into your graveyard. If you do, return this card from your graveyard to your hand. Otherwise, draw a card.)</i>").toString();
this.staticText = new StringBuilder("Dredge ").append(Integer.toString(value)).append(" <i>(If you would draw a card, instead you may put exactly ").append(value).append(" card(s) from the top of your library into your graveyard. If you do, return this card from your graveyard to your hand. Otherwise, draw a card.)</i>").toString();
}
public DredgeEffect(final DredgeEffect effect) {

View file

@ -5,8 +5,6 @@
*/
package mage.game.stack;
import java.util.Set;
import java.util.UUID;
import mage.MageObject;
import mage.abilities.Abilities;
import mage.abilities.AbilitiesImpl;
@ -21,6 +19,9 @@ import mage.players.Player;
import mage.target.Target;
import mage.target.TargetAmount;
import java.util.Set;
import java.util.UUID;
/**
*
* @author LevelX2
@ -135,7 +136,7 @@ public abstract class StackObjImpl implements StackObject {
}
if (!newTargetDescription.toString().equals(oldTargetDescription.toString()) && !game.isSimulation()) {
game.informPlayers(this.getLogName() + " is now " + newTargetDescription.toString());
game.informPlayers(this.getLogName() + " is now " + newTargetDescription);
}
return true;
}

View file

@ -1,10 +1,5 @@
package mage.util;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Set;
import java.util.UUID;
import mage.MageObject;
import mage.Mana;
import mage.ManaSymbol;
@ -12,19 +7,14 @@ import mage.abilities.Ability;
import mage.abilities.costs.mana.AlternateManaPaymentAbility;
import mage.abilities.costs.mana.ManaCost;
import mage.abilities.costs.mana.ManaSymbols;
import mage.abilities.mana.BasicManaAbility;
import mage.abilities.mana.BlackManaAbility;
import mage.abilities.mana.BlueManaAbility;
import mage.abilities.mana.GreenManaAbility;
import mage.abilities.mana.ActivatedManaAbilityImpl;
import mage.abilities.mana.AnyColorManaAbility;
import mage.abilities.mana.RedManaAbility;
import mage.abilities.mana.WhiteManaAbility;
import mage.abilities.mana.*;
import mage.cards.Card;
import mage.choices.Choice;
import mage.constants.ColoredManaSymbol;
import mage.game.Game;
import java.util.*;
/**
* @author noxx
*/
@ -471,7 +461,7 @@ public final class ManaUtil {
// Combine the cost back as a mana string
StringBuilder sb = new StringBuilder();
for (String s : finalCost) {
sb.append('{' + s + '}');
sb.append('{').append(s).append('}');
}
// Return the condensed string
return sb.toString();