foul-magics/Mage/src/main/java/mage/abilities/effects/Effects.java
2018-06-02 17:59:49 +02:00

121 lines
3.3 KiB
Java

package mage.abilities.effects;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import mage.abilities.Mode;
import mage.constants.Outcome;
import mage.target.targetpointer.TargetPointer;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class Effects extends ArrayList<Effect> {
public Effects() {
}
public Effects(Effect effect) {
this.add(effect);
}
public Effects(final Effects effects) {
for (Effect effect : effects) {
this.add(effect.copy());
}
}
public Effects copy() {
return new Effects(this);
}
public String getTextStartingUpperCase(Mode mode) {
String text = getText(mode);
if (text.length() > 3) {
return Character.toUpperCase(text.charAt(0)) + text.substring(1);
}
return text;
}
public String getText(Mode mode) {
StringBuilder sbText = new StringBuilder();
String lastRule = null;
for (Effect effect : this) {
String endString = "";
String nextRule = effect.getText(mode);
if (nextRule != null) {
if (nextRule.startsWith("and ") || nextRule.startsWith("with ")) {
endString = " ";
} else if (nextRule.startsWith(",") || nextRule.startsWith(" ")) {
endString = "";
} else if (lastRule != null && lastRule.length() > 3) {
if (!lastRule.endsWith(".") && !lastRule.endsWith("<br>")) {
endString = ". ";
}
if (nextRule.length() > 3) {
nextRule = Character.toUpperCase(nextRule.charAt(0)) + nextRule.substring(1);
}
}
sbText.append(endString).append(nextRule);
}
lastRule = nextRule;
}
if (lastRule != null && lastRule.length() > 3
&& !lastRule.endsWith(".")
&& !lastRule.endsWith("\"")
&& !lastRule.startsWith("<b>Level ")
&& !lastRule.endsWith(".)")
&& !lastRule.endsWith("</i>")) {
sbText.append('.');
}
return sbText.toString();
}
public boolean hasOutcome(Outcome outcome) {
for (Effect effect : this) {
if (effect.getOutcome() == outcome) {
return true;
}
}
return false;
}
public List<Outcome> getOutcomes() {
Set<Outcome> outcomes = new HashSet<>();
for (Effect effect : this) {
outcomes.add(effect.getOutcome());
}
return new ArrayList<>(outcomes);
}
public int getOutcomeTotal() {
int total = 0;
for (Effect effect : this) {
if (effect.getOutcome().isGood()) {
total++;
} else {
total--;
}
}
return total;
}
public void newId() {
for (Effect effect : this) {
effect.newId();
}
}
public void setTargetPointer(TargetPointer targetPointer) {
if (targetPointer == null) {
return;
}
for (Effect effect : this) {
effect.setTargetPointer(targetPointer.copy());
}
}
}