Started to implement a solution for effects that change words in rule text.

This commit is contained in:
LevelX2 2017-09-03 07:31:36 +02:00
parent e3f6a6b418
commit 66c69e51a3
14 changed files with 441 additions and 40 deletions

View file

@ -222,6 +222,7 @@ public class Commander2017 extends ExpansionSet {
cards.add(new SetCardInfo("Nazahn, Revered Bladesmith", 44, Rarity.MYTHIC, mage.cards.n.NazahnReveredBladesmith.class));
cards.add(new SetCardInfo("Necromantic Selection", 117, Rarity.RARE, mage.cards.n.NecromanticSelection.class));
cards.add(new SetCardInfo("Nevinyrral's Disk", 217, Rarity.RARE, mage.cards.n.NevinyrralsDisk.class));
cards.add(new SetCardInfo("New Blood", 19, Rarity.RARE, mage.cards.n.NewBlood.class));
cards.add(new SetCardInfo("Nihil Spellbomb", 218, Rarity.COMMON, mage.cards.n.NihilSpellbomb.class));
cards.add(new SetCardInfo("Nin, the Pain Artist", 183, Rarity.RARE, mage.cards.n.NinThePainArtist.class));
cards.add(new SetCardInfo("Nissa's Pilgrimage", 155, Rarity.COMMON, mage.cards.n.NissasPilgrimage.class));

View file

@ -1,10 +1,15 @@
package mage;
import java.io.Serializable;
import java.util.EnumSet;
import java.util.List;
import java.util.UUID;
import mage.abilities.Abilities;
import mage.abilities.Ability;
import mage.abilities.costs.mana.ManaCost;
import mage.abilities.costs.mana.ManaCosts;
import mage.abilities.keyword.ChangelingAbility;
import mage.abilities.text.TextPart;
import mage.cards.Card;
import mage.cards.FrameStyle;
import mage.constants.CardType;
@ -14,10 +19,6 @@ import mage.game.Game;
import mage.game.events.ZoneChangeEvent;
import mage.util.SubTypeList;
import java.io.Serializable;
import java.util.EnumSet;
import java.util.UUID;
public interface MageObject extends MageItem, Serializable {
String getName();
@ -58,7 +59,6 @@ public interface MageObject extends MageItem, Serializable {
int getStartingLoyalty();
void adjustCosts(Ability ability, Game game);
void adjustTargets(Ability ability, Game game);
@ -85,7 +85,6 @@ public interface MageObject extends MageItem, Serializable {
void setZoneChangeCounter(int value, Game game);
default boolean isCreature() {
return getCardType().contains(CardType.CREATURE);
}
@ -163,7 +162,6 @@ public interface MageObject extends MageItem, Serializable {
return false;
}
default boolean shareSubtypes(Card otherCard, Game game) {
if (otherCard == null) {
@ -191,7 +189,15 @@ public interface MageObject extends MageItem, Serializable {
void setIsAllCreatureTypes(boolean value);
default void addCardTypes(EnumSet<CardType> cardType){
default void addCardTypes(EnumSet<CardType> cardType) {
getCardType().addAll(cardType);
}
List<TextPart> getTextParts();
TextPart addTextPart(TextPart textPart);
default void changeSubType(SubType fromSubType, SubType toSubType) {
}
}

View file

@ -27,6 +27,10 @@
*/
package mage;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.UUID;
import mage.abilities.Abilities;
import mage.abilities.AbilitiesImpl;
import mage.abilities.Ability;
@ -36,6 +40,8 @@ import mage.abilities.costs.mana.ManaCosts;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.keyword.ChangelingAbility;
import mage.abilities.mana.ActivatedManaAbilityImpl;
import mage.abilities.text.TextPart;
import mage.abilities.text.TextPartSubType;
import mage.cards.FrameStyle;
import mage.constants.CardType;
import mage.constants.SubType;
@ -46,10 +52,6 @@ import mage.game.events.ZoneChangeEvent;
import mage.util.GameLog;
import mage.util.SubTypeList;
import java.util.EnumSet;
import java.util.List;
import java.util.UUID;
public abstract class MageObjectImpl implements MageObject {
protected UUID objectId;
@ -68,6 +70,7 @@ public abstract class MageObjectImpl implements MageObject {
protected MageInt power;
protected MageInt toughness;
protected boolean copy;
protected List<TextPart> textParts;
public MageObjectImpl() {
this(UUID.randomUUID());
@ -82,6 +85,7 @@ public abstract class MageObjectImpl implements MageObject {
frameStyle = FrameStyle.M15_NORMAL;
manaCost = new ManaCostsImpl<>("");
abilities = new AbilitiesImpl<>();
textParts = new ArrayList<>();
}
public MageObjectImpl(final MageObjectImpl object) {
@ -99,6 +103,7 @@ public abstract class MageObjectImpl implements MageObject {
this.subtype.addAll(object.subtype);
supertype.addAll(object.supertype);
this.copy = object.copy;
textParts = new ArrayList<>(object.textParts);
}
@Override
@ -303,13 +308,33 @@ public abstract class MageObjectImpl implements MageObject {
}
@Override
public boolean isAllCreatureTypes(){
public boolean isAllCreatureTypes() {
return isAllCreatureTypes;
}
@Override
public void setIsAllCreatureTypes(boolean value){
public void setIsAllCreatureTypes(boolean value) {
isAllCreatureTypes = value;
}
@Override
public List<TextPart> getTextParts() {
return textParts;
}
@Override
public TextPart addTextPart(TextPart textPart) {
textParts.add(textPart);
return textPart;
}
@Override
public void changeSubType(SubType fromSubType, SubType toSubType) {
for (TextPart textPart : textParts) {
if (textPart instanceof TextPartSubType && textPart.getCurrentValue().equals(fromSubType)) {
textPart.replaceWith(toSubType);
}
}
}
}

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.abilities.text;
import java.io.Serializable;
import java.util.UUID;
import mage.util.Copyable;
/**
*
* @author LevelX2
* @param <E>
*/
public interface TextPart<E> extends Serializable, Copyable<TextPart> {
UUID getId();
String getText();
E getBaseValue();
E getCurrentValue();
void replaceWith(E o);
void reset();
}

View file

@ -0,0 +1,90 @@
/*
* 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.abilities.text;
import mage.ObjectColor;
/**
*
* This implementation is not finished yet. There is no support to also change
* the rules text of an object.
*
* @author LevelX2
*/
public class TextPartColor extends TextPartImpl<ObjectColor> {
private final ObjectColor objectColorBase;
private ObjectColor objectColorCurrent;
public TextPartColor(ObjectColor objectColor) {
this.objectColorBase = objectColor;
this.objectColorCurrent = objectColor;
}
public TextPartColor(final TextPartColor textPartColor) {
super();
this.objectColorBase = textPartColor.objectColorBase;
this.objectColorCurrent = textPartColor.objectColorCurrent;
}
@Override
public String getText() {
return objectColorCurrent.getDescription();
}
@Override
public ObjectColor getCurrentValue() {
return objectColorCurrent;
}
@Override
public ObjectColor getBaseValue() {
return objectColorBase;
}
@Override
public void replaceWith(ObjectColor objectColor) {
this.objectColorCurrent = objectColor;
}
@Override
public void reset() {
this.objectColorCurrent = this.objectColorBase;
}
@Override
public TextPartColor copy() {
return new TextPartColor(this);
}
@Override
public String toString() {
return objectColorCurrent.toString();
}
}

View file

@ -0,0 +1,32 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mage.abilities.text;
import java.util.UUID;
/**
*
* @author LevelX2
* @param <E>
*/
public abstract class TextPartImpl<E> implements TextPart<E> {
private final UUID id;
public TextPartImpl() {
this.id = UUID.randomUUID();
}
public TextPartImpl(final TextPartImpl textPartimpl) {
this.id = textPartimpl.id;
}
@Override
public UUID getId() {
return id;
}
}

View file

@ -0,0 +1,90 @@
/*
* 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.abilities.text;
import mage.constants.SubType;
/**
* This implementation is not finished yet. There is no support to also change
* the rules text of an object. Also all the cards that user subtypes in the
* text have to be updated with the new elements.
*
* @author LevelX2
*/
public class TextPartSubType extends TextPartImpl<SubType> {
private final SubType subTypeBase;
private SubType subTypeCurrent;
public TextPartSubType(SubType subType) {
this.subTypeBase = subType;
this.subTypeCurrent = subType;
}
public TextPartSubType(final TextPartSubType textPartSubType) {
super();
this.subTypeBase = textPartSubType.subTypeBase;
this.subTypeCurrent = textPartSubType.subTypeCurrent;
}
@Override
public String getText() {
return subTypeCurrent.getDescription();
}
@Override
public SubType getCurrentValue() {
return subTypeCurrent;
}
@Override
public SubType getBaseValue() {
return subTypeBase;
}
@Override
public void replaceWith(SubType subType) {
this.subTypeCurrent = subType;
}
@Override
public void reset() {
this.subTypeCurrent = this.subTypeBase;
}
@Override
public TextPartSubType copy() {
return new TextPartSubType(this);
}
@Override
public String toString() {
return subTypeCurrent.toString();
}
}

View file

@ -27,11 +27,14 @@
*/
package mage.designations;
import java.util.List;
import java.util.UUID;
import mage.MageObject;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.common.BeginningOfEndStepTriggeredAbility;
import mage.abilities.effects.common.BecomesMonarchTargetEffect;
import mage.abilities.effects.common.DrawCardTargetEffect;
import mage.abilities.text.TextPart;
import mage.constants.TargetController;
import mage.constants.Zone;
import mage.game.Game;
@ -40,8 +43,6 @@ import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.target.targetpointer.FixedTarget;
import java.util.UUID;
/**
*
* @author LevelX2
@ -73,6 +74,16 @@ public class Monarch extends Designation {
public void setIsAllCreatureTypes(boolean value) {
}
@Override
public List<TextPart> getTextParts() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public TextPart addTextPart(TextPart textPart) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
// At the beginning of the monarchs end step, that player draws a card
@ -159,5 +170,4 @@ class MonarchDealsCombatDamageToAPlayerTriggeredAbility extends TriggeredAbility
return "Whenever a creature deals combat damage to the monarch, its controller becomes the monarch.";
}
}

View file

@ -0,0 +1,34 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mage.filter.predicate.mageobject;
import mage.MageObject;
import mage.abilities.text.TextPartSubType;
import mage.filter.predicate.Predicate;
import mage.game.Game;
/**
*
* @author LevelX2
*/
public class TextPartSubtypePredicate implements Predicate<MageObject> {
private final TextPartSubType textPartSubtype;
public TextPartSubtypePredicate(TextPartSubType textPartSubtype) {
this.textPartSubtype = textPartSubtype;
}
@Override
public boolean apply(MageObject input, Game game) {
return input.hasSubtype(textPartSubtype.getCurrentValue(), game);
}
@Override
public String toString() {
return "Subtype(" + textPartSubtype.getCurrentValue() + ')';
}
}

View file

@ -27,6 +27,9 @@
*/
package mage.game.command;
import java.util.EnumSet;
import java.util.List;
import java.util.UUID;
import mage.MageInt;
import mage.ObjectColor;
import mage.abilities.Abilities;
@ -36,6 +39,7 @@ import mage.abilities.SpellAbility;
import mage.abilities.common.CastCommanderAbility;
import mage.abilities.costs.mana.ManaCost;
import mage.abilities.costs.mana.ManaCosts;
import mage.abilities.text.TextPart;
import mage.cards.Card;
import mage.cards.FrameStyle;
import mage.constants.CardType;
@ -46,9 +50,6 @@ import mage.game.events.ZoneChangeEvent;
import mage.util.GameLog;
import mage.util.SubTypeList;
import java.util.EnumSet;
import java.util.UUID;
public class Commander implements CommandObject {
private final Card sourceObject;
@ -229,7 +230,23 @@ public class Commander implements CommandObject {
sourceObject.setZoneChangeCounter(value, game);
}
public boolean isAllCreatureTypes() { return false;}
@Override
public boolean isAllCreatureTypes() {
return false;
}
@Override
public void setIsAllCreatureTypes(boolean value) {
}
@Override
public List<TextPart> getTextParts() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public TextPart addTextPart(TextPart textPart) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
public void setIsAllCreatureTypes(boolean value){}
}

View file

@ -27,6 +27,10 @@
*/
package mage.game.command;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.UUID;
import mage.MageInt;
import mage.MageObject;
import mage.ObjectColor;
@ -36,6 +40,7 @@ import mage.abilities.Ability;
import mage.abilities.costs.mana.ManaCost;
import mage.abilities.costs.mana.ManaCosts;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.text.TextPart;
import mage.cards.Card;
import mage.cards.FrameStyle;
import mage.constants.CardType;
@ -46,18 +51,13 @@ import mage.game.events.ZoneChangeEvent;
import mage.util.GameLog;
import mage.util.SubTypeList;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.UUID;
/**
* @author nantuko
*/
public class Emblem implements CommandObject {
private static EnumSet<CardType> emptySet = EnumSet.noneOf(CardType.class);
private static List emptyList = new ArrayList();
private static List emptyList = new ArrayList();
private static ObjectColor emptyColor = new ObjectColor();
private static ManaCosts emptyCost = new ManaCostsImpl();
@ -268,8 +268,21 @@ public class Emblem implements CommandObject {
throw new UnsupportedOperationException("Unsupported operation");
}
public boolean isAllCreatureTypes(){ return false;}
public boolean isAllCreatureTypes() {
return false;
}
public void setIsAllCreatureTypes(boolean value){}
public void setIsAllCreatureTypes(boolean value) {
}
@Override
public List<TextPart> getTextParts() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public TextPart addTextPart(TextPart textPart) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}

View file

@ -27,6 +27,7 @@
*/
package mage.game.permanent;
import java.util.*;
import mage.MageObject;
import mage.MageObjectReference;
import mage.ObjectColor;
@ -36,6 +37,7 @@ import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.Effect;
import mage.abilities.effects.RestrictionEffect;
import mage.abilities.keyword.*;
import mage.abilities.text.TextPart;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.constants.*;
@ -55,8 +57,6 @@ import mage.players.Player;
import mage.util.GameLog;
import mage.util.ThreadLocalStringBuilder;
import java.util.*;
/**
* @author BetaSteward_at_googlemail.com
*/
@ -204,6 +204,9 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
this.minBlockedBy = 1;
this.maxBlockedBy = 0;
this.copy = false;
for (TextPart textPart : textParts) {
textPart.reset();
}
}
@Override
@ -1210,7 +1213,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
@Override
public boolean imprint(UUID imprintedCard, Game game) {
if (!game.getExile().containsId(imprintedCard, game)){
if (!game.getExile().containsId(imprintedCard, game)) {
return false;
}
if (connectedCards.containsKey("imprint")) {

View file

@ -45,6 +45,7 @@ import mage.abilities.costs.mana.ManaCost;
import mage.abilities.costs.mana.ManaCosts;
import mage.abilities.keyword.BestowAbility;
import mage.abilities.keyword.MorphAbility;
import mage.abilities.text.TextPart;
import mage.cards.Card;
import mage.cards.CardsImpl;
import mage.cards.FrameStyle;
@ -927,10 +928,23 @@ public class Spell extends StackObjImpl implements Card {
return copy;
}
@Override
public boolean isAllCreatureTypes() {
return false;
}
@Override
public void setIsAllCreatureTypes(boolean value) {
}
@Override
public List<TextPart> getTextParts() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public TextPart addTextPart(TextPart textPart) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}

View file

@ -27,6 +27,10 @@
*/
package mage.game.stack;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.UUID;
import mage.MageInt;
import mage.MageObject;
import mage.ObjectColor;
@ -39,6 +43,7 @@ import mage.abilities.costs.mana.ManaCosts;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.Effect;
import mage.abilities.effects.Effects;
import mage.abilities.text.TextPart;
import mage.cards.Card;
import mage.cards.FrameStyle;
import mage.constants.*;
@ -52,11 +57,6 @@ import mage.util.GameLog;
import mage.util.SubTypeList;
import mage.watchers.Watcher;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.UUID;
/**
*
* @author BetaSteward_at_googlemail.com
@ -593,9 +593,23 @@ public class StackAbility extends StackObjImpl implements Ability {
return newStackAbility;
}
public boolean isAllCreatureTypes(){
@Override
public boolean isAllCreatureTypes() {
return false;
}
public void setIsAllCreatureTypes(boolean value){}
@Override
public void setIsAllCreatureTypes(boolean value) {
}
@Override
public List<TextPart> getTextParts() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public TextPart addTextPart(TextPart textPart) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}