Added new attribute ability word to ability to simplify rule text generation.

This commit is contained in:
LevelX2 2014-03-11 16:39:01 +01:00
parent 42e0581533
commit cabe33395c
4 changed files with 89 additions and 5 deletions

View file

@ -49,6 +49,7 @@ import mage.target.Targets;
import java.io.Serializable;
import java.util.List;
import java.util.UUID;
import mage.constants.AbilityWord;
/**
* Practically everything in the game is started from an Ability. This
@ -395,7 +396,7 @@ public interface Ability extends Controllable, Serializable {
* true = rule will be shown for the card / permanent
* false = rule won't be shown
*
* @param ruleAtTheTop
* @param ruleVisible
*/
void setRuleVisible(boolean ruleVisible);
@ -407,4 +408,15 @@ public interface Ability extends Controllable, Serializable {
*/
UUID getOriginalId();
/**
* Sets the ability word for the given ability.
* An ability word is a word that, in essence, groups, and reminds players of, cards
* that have a common functionality and does not imply any particular rules.
*
* --- Not usable yet for rule text generation of triggered abilities ---
*
* @param abilityWord
*/
void setAbilityWord(AbilityWord abilityWord);
}

View file

@ -54,6 +54,7 @@ import mage.cards.Card;
import mage.choices.Choice;
import mage.choices.Choices;
import mage.constants.AbilityType;
import mage.constants.AbilityWord;
import mage.constants.EffectType;
import mage.constants.Outcome;
import mage.constants.Zone;
@ -87,6 +88,7 @@ public abstract class AbilityImpl<T extends AbilityImpl<T>> implements Ability {
protected Modes modes;
protected Zone zone;
protected String name;
protected AbilityWord abilityWord;
protected boolean usesStack = true;
protected boolean ruleAtTheTop = false;
protected boolean ruleVisible = true;
@ -524,8 +526,7 @@ public abstract class AbilityImpl<T extends AbilityImpl<T>> implements Ability {
@Override
public String getRule(boolean all) {
StringBuilder sbRule = new StringBuilder();
StringBuilder sbRule = new StringBuilder();
if (all || this.abilityType != AbilityType.SPELL) {
if (manaCosts.size() > 0) {
sbRule.append(manaCosts.getText());
@ -540,6 +541,9 @@ public abstract class AbilityImpl<T extends AbilityImpl<T>> implements Ability {
sbRule.append(": ");
}
}
if (abilityWord != null) {
sbRule.insert(0, new StringBuilder("<i>").append(abilityWord.toString()).append("</i> - "));
}
String text = modes.getText();
if (!text.isEmpty()) {
if (sbRule.length() > 1) {
@ -741,5 +745,12 @@ public abstract class AbilityImpl<T extends AbilityImpl<T>> implements Ability {
public UUID getOriginalId() {
return this.originalId;
}
@Override
public void setAbilityWord(AbilityWord abilityWord) {
this.abilityWord = abilityWord;
}
}

View file

@ -0,0 +1,52 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.constants;
/**
*
* @author LevelX2
*/
public enum AbilityWord {
BLOODRUSH("Bloodrush"),
HEROIC("Heroic"),
LANDFALL("Landfall"),
METALCRAFT("Metalcraft");
private final String text;
AbilityWord(String text) {
this.text = text;
}
@Override
public String toString() {
return text;
}
}

View file

@ -54,6 +54,7 @@ import mage.target.Targets;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import mage.constants.AbilityWord;
/**
*
@ -65,9 +66,9 @@ public class StackAbility implements StackObject, Ability {
private static ObjectColor emptyColor = new ObjectColor();
private static ManaCosts emptyCost = new ManaCostsImpl();
private static Costs emptyCosts = new CostsImpl();
private static Abilities<Ability> emptyAbilites = new AbilitiesImpl<Ability>();
private static Abilities<Ability> emptyAbilites = new AbilitiesImpl<>();
private Ability ability;
private final Ability ability;
private UUID controllerId;
private String name = "";
private String expansionSetCode;
@ -75,6 +76,7 @@ public class StackAbility implements StackObject, Ability {
public StackAbility(Ability ability, UUID controllerId) {
this.ability = ability;
this.controllerId = controllerId;
this.name = new StringBuilder("stack ability (").append(ability.getRule()).append(")").toString();
}
public StackAbility(final StackAbility spell) {
@ -392,4 +394,11 @@ public class StackAbility implements StackObject, Ability {
public UUID getOriginalId() {
return this.ability.getOriginalId();
}
@Override
public void setAbilityWord(AbilityWord abilityWord) {
throw new UnsupportedOperationException("Not supported.");
}
}