From cabe33395c52d4962129be36a11a8e4a95cd2c0b Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Tue, 11 Mar 2014 16:39:01 +0100 Subject: [PATCH] Added new attribute ability word to ability to simplify rule text generation. --- Mage/src/mage/abilities/Ability.java | 14 +++++- Mage/src/mage/abilities/AbilityImpl.java | 15 ++++++- Mage/src/mage/constants/AbilityWord.java | 52 ++++++++++++++++++++++ Mage/src/mage/game/stack/StackAbility.java | 13 +++++- 4 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 Mage/src/mage/constants/AbilityWord.java diff --git a/Mage/src/mage/abilities/Ability.java b/Mage/src/mage/abilities/Ability.java index af119eacf8..731c8f868a 100644 --- a/Mage/src/mage/abilities/Ability.java +++ b/Mage/src/mage/abilities/Ability.java @@ -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); + } diff --git a/Mage/src/mage/abilities/AbilityImpl.java b/Mage/src/mage/abilities/AbilityImpl.java index 49edbb1504..a35fae1448 100644 --- a/Mage/src/mage/abilities/AbilityImpl.java +++ b/Mage/src/mage/abilities/AbilityImpl.java @@ -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> 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> 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> implements Ability { sbRule.append(": "); } } + if (abilityWord != null) { + sbRule.insert(0, new StringBuilder("").append(abilityWord.toString()).append(" - ")); + } String text = modes.getText(); if (!text.isEmpty()) { if (sbRule.length() > 1) { @@ -741,5 +745,12 @@ public abstract class AbilityImpl> implements Ability { public UUID getOriginalId() { return this.originalId; } + + @Override + public void setAbilityWord(AbilityWord abilityWord) { + this.abilityWord = abilityWord; + } + + } diff --git a/Mage/src/mage/constants/AbilityWord.java b/Mage/src/mage/constants/AbilityWord.java new file mode 100644 index 0000000000..46e2437202 --- /dev/null +++ b/Mage/src/mage/constants/AbilityWord.java @@ -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; + } + +} diff --git a/Mage/src/mage/game/stack/StackAbility.java b/Mage/src/mage/game/stack/StackAbility.java index fa93d08d94..749c4ddfa7 100644 --- a/Mage/src/mage/game/stack/StackAbility.java +++ b/Mage/src/mage/game/stack/StackAbility.java @@ -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 emptyAbilites = new AbilitiesImpl(); + private static Abilities 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."); + } + + }