fix subtype in game state

This commit is contained in:
igoudt 2017-08-06 22:11:17 +02:00
parent 7ac35808bf
commit 5d99bacf73
20 changed files with 86 additions and 89 deletions

View file

@ -27,7 +27,6 @@
*/
package mage.cards.a;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.AsEntersBattlefieldAbility;
@ -44,6 +43,8 @@ import mage.filter.predicate.permanent.ControllerPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import java.util.UUID;
/**
* @author nantuko
*/
@ -98,7 +99,7 @@ class AdaptiveAutomatonAddSubtypeEffect extends ContinuousEffectImpl {
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
String subtype = (String) game.getState().getValue(permanent.getId() + "_type");
SubType subtype = (SubType) game.getState().getValue(permanent.getId() + "_type");
if (subtype != null && !permanent.getSubtype(game).contains(subtype)) {
permanent.getSubtype(game).add(subtype);
}

View file

@ -27,7 +27,6 @@
*/
package mage.cards.a;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.common.AsEntersBattlefieldAbility;
import mage.abilities.common.SimpleStaticAbility;
@ -41,6 +40,8 @@ import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import java.util.UUID;
/**
*
* @author emerald000
@ -83,7 +84,7 @@ class AshesOfTheFallenEffect extends ContinuousEffectImpl {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (controller != null && permanent != null) {
String subtype = (String) game.getState().getValue(permanent.getId() + "_type");
SubType subtype = (SubType) game.getState().getValue(permanent.getId() + "_type");
for (UUID cardId : controller.getGraveyard()) {
Card card = game.getCard(cardId);
if (card != null && card.isCreature() && !card.getSubtype(game).contains(subtype)) {

View file

@ -40,10 +40,7 @@ import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.choices.Choice;
import mage.choices.ChoiceCreatureType;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.constants.*;
import mage.filter.FilterPermanent;
import mage.filter.predicate.mageobject.ChosenSubtypePredicate;
import mage.game.Game;
@ -141,7 +138,7 @@ class ChooseCreatureTypeEffect extends OneShotEffect { // code by LevelX2, but t
if (!game.isSimulation()) {
game.informPlayers(mageObject.getName() + ": " + controller.getLogName() + " has chosen " + typeChoice.getChoice());
}
game.getState().setValue(mageObject.getId() + "_type", typeChoice.getChoice());
game.getState().setValue(mageObject.getId() + "_type", SubType.byDescription(typeChoice.getChoice()));
return true;
}
return false;

View file

@ -27,9 +27,6 @@
*/
package mage.cards.c;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import mage.ConditionalMana;
import mage.MageObject;
import mage.Mana;
@ -53,6 +50,10 @@ import mage.game.stack.Spell;
import mage.players.Player;
import mage.watchers.Watcher;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
/**
*
* @author noxx
@ -90,9 +91,9 @@ class CavernOfSoulsManaBuilder extends ConditionalManaBuilder {
@Override
public ConditionalManaBuilder setMana(Mana mana, Ability source, Game game) {
Object value = game.getState().getValue(source.getSourceId() + "_type");
if (value != null && value instanceof String) {
creatureType = SubType.byDescription((String) value);
SubType value = (SubType) game.getState().getValue(source.getSourceId() + "_type");
if (value != null ) {
creatureType = value;
}
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());

View file

@ -27,9 +27,6 @@
*/
package mage.cards.c;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.common.EntersBattlefieldAbility;
@ -48,6 +45,10 @@ import mage.game.stack.StackObject;
import mage.players.Player;
import mage.util.SubTypeList;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
/**
*
* @author anonymous
@ -92,34 +93,33 @@ class ConspiracyEffect extends ContinuousEffectImpl {
@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
Player controller = game.getPlayer(source.getControllerId());
String choice = (String) game.getState().getValue(source.getSourceId().toString() + "_type");
SubType chosenSubtype = SubType.byDescription(choice);
SubType choice = (SubType) game.getState().getValue(source.getSourceId().toString() + "_type");
if (controller != null && choice != null) {
// Creature cards you own that aren't on the battlefield
// in graveyard
for (UUID cardId : controller.getGraveyard()) {
Card card = game.getCard(cardId);
if (card.isCreature()) {
setCreatureSubtype(card, chosenSubtype, game);
setCreatureSubtype(card, choice, game);
}
}
// on Hand
for (UUID cardId : controller.getHand()) {
Card card = game.getCard(cardId);
if (card.isCreature()) {
setCreatureSubtype(card, chosenSubtype, game);
setCreatureSubtype(card, choice, game);
}
}
// in Exile
for (Card card : game.getState().getExile().getAllCards(game)) {
if (card.getOwnerId().equals(controller.getId()) && card.isCreature()) {
setCreatureSubtype(card, chosenSubtype, game);
setCreatureSubtype(card, choice, game);
}
}
// in Library (e.g. for Mystical Teachings)
for (Card card : controller.getLibrary().getCards(game)) {
if (card.getOwnerId().equals(controller.getId()) && card.isCreature()) {
setCreatureSubtype(card, chosenSubtype, game);
setCreatureSubtype(card, choice, game);
}
}
// commander in command zone
@ -127,7 +127,7 @@ class ConspiracyEffect extends ContinuousEffectImpl {
if (game.getState().getZone(commanderId) == Zone.COMMAND) {
Card card = game.getCard(commanderId);
if (card.isCreature()) {
setCreatureSubtype(card, chosenSubtype, game);
setCreatureSubtype(card, choice, game);
}
}
}
@ -138,14 +138,14 @@ class ConspiracyEffect extends ContinuousEffectImpl {
stackObject.getControllerId().equals(source.getControllerId()) &&
stackObject.isCreature()) {
Card card = ((Spell) stackObject).getCard();
setCreatureSubtype(card, chosenSubtype, game);
setCreatureSubtype(card, choice, game);
}
}
// creatures you control
List<Permanent> creatures = game.getBattlefield().getAllActivePermanents(
new FilterControlledCreaturePermanent(), source.getControllerId(), game);
for (Permanent creature : creatures) {
setCreatureSubtype(creature, chosenSubtype, game);
setCreatureSubtype(creature, choice, game);
}
return true;
}

View file

@ -102,11 +102,11 @@ class AddCounterAbility extends TriggeredAbilityImpl {
public boolean checkTrigger(GameEvent event, Game game) {
Permanent doorOfDestinies = game.getPermanent(getSourceId());
if (doorOfDestinies != null) {
String subtype = (String) game.getState().getValue(doorOfDestinies.getId() + "_type");
SubType subtype = (SubType) game.getState().getValue(doorOfDestinies.getId() + "_type");
if (subtype != null) {
FilterSpell filter = new FilterSpell();
filter.add(new ControllerPredicate(TargetController.YOU));
filter.add(new SubtypePredicate(SubType.byDescription(subtype)));
filter.add(new SubtypePredicate(subtype));
Spell spell = game.getStack().getSpell(event.getTargetId());
if (spell != null && filter.match(spell, getSourceId(), getControllerId(), game)) {
return true;

View file

@ -27,7 +27,6 @@
*/
package mage.cards.r;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.AsEntersBattlefieldAbility;
@ -45,6 +44,8 @@ import mage.filter.predicate.mageobject.SubtypePredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import java.util.UUID;
/**
* @author noxx
*/
@ -107,10 +108,10 @@ class RidersOfGavonyGainAbilityControlledEffect extends ContinuousEffectImpl {
if (protectionFilter == null) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
String subtype = (String) game.getState().getValue(permanent.getId() + "_type");
SubType subtype = (SubType) game.getState().getValue(permanent.getId() + "_type");
if (subtype != null) {
protectionFilter = new FilterPermanent(subtype + 's');
protectionFilter.add(new SubtypePredicate(SubType.byDescription(subtype)));
protectionFilter = new FilterPermanent(subtype.getDescription() + 's');
protectionFilter.add(new SubtypePredicate(subtype));
}
}
}

View file

@ -27,7 +27,6 @@
*/
package mage.cards.r;
import java.util.UUID;
import mage.ObjectColor;
import mage.abilities.Ability;
import mage.abilities.common.EntersBattlefieldAbility;
@ -44,12 +43,15 @@ import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.SubType;
import mage.constants.Zone;
import mage.counters.CounterType;
import mage.game.Game;
import mage.game.permanent.token.RiptideReplicatorToken;
import mage.game.permanent.token.Token;
import java.util.UUID;
/**
*
* @author HanClinto
@ -104,7 +106,7 @@ class RiptideReplicatorEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
ObjectColor color = (ObjectColor) game.getState().getValue(source.getSourceId() + "_color");
String type = (String) game.getState().getValue(source.getSourceId() + "_type");
SubType type = (SubType) game.getState().getValue(source.getSourceId() + "_type");
int x = (new CountersSourceCount(CounterType.CHARGE)).calculate(game, source, this);
Token token = new RiptideReplicatorToken(color, type, x);
return token.putOntoBattlefield(1, game, source.getSourceId(), source.getControllerId());

View file

@ -27,7 +27,6 @@
*/
package mage.cards.v;
import java.util.UUID;
import mage.ObjectColor;
import mage.abilities.Ability;
import mage.abilities.common.EntersBattlefieldAbility;
@ -42,11 +41,14 @@ import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.SubType;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.permanent.token.Token;
import mage.game.permanent.token.VolrathsLaboratoryToken;
import java.util.UUID;
/**
*
* @author emerald000
@ -98,7 +100,7 @@ class VolrathsLaboratoryEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
ObjectColor color = (ObjectColor) game.getState().getValue(source.getSourceId() + "_color");
String type = (String) game.getState().getValue(source.getSourceId() + "_type");
SubType type = (SubType) game.getState().getValue(source.getSourceId() + "_type");
Token token = new VolrathsLaboratoryToken(color, type);
return token.putOntoBattlefield(1, game, source.getSourceId(), source.getControllerId());
}

View file

@ -27,8 +27,6 @@
*/
package mage.cards.x;
import java.util.List;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.common.AsEntersBattlefieldAbility;
import mage.abilities.common.SimpleStaticAbility;
@ -36,16 +34,14 @@ import mage.abilities.effects.ContinuousEffectImpl;
import mage.abilities.effects.common.ChooseCreatureTypeEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Layer;
import mage.constants.Outcome;
import mage.constants.SubLayer;
import mage.constants.Zone;
import mage.constants.*;
import mage.filter.StaticFilters;
import mage.game.Game;
import mage.game.permanent.Permanent;
import java.util.List;
import java.util.UUID;
/**
*
* @author North
@ -84,7 +80,7 @@ class XenograftAddSubtypeEffect extends ContinuousEffectImpl {
@Override
public boolean apply(Game game, Ability source) {
String subtype = (String) game.getState().getValue(source.getSourceId() + "_type");
SubType subtype = (SubType) game.getState().getValue(source.getSourceId() + "_type");
if (subtype != null) {
List<Permanent> permanents = game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), game);
for (Permanent permanent : permanents) {

View file

@ -75,7 +75,7 @@ public class ChooseCreatureTypeEffect extends OneShotEffect {
if (!game.isSimulation()) {
game.informPlayers(mageObject.getName() + ": " + controller.getLogName() + " has chosen " + typeChoice.getChoice());
}
game.getState().setValue(mageObject.getId() + "_type", typeChoice.getChoice());
game.getState().setValue(mageObject.getId() + "_type", SubType.byDescription(typeChoice.getChoice()));
if (mageObject instanceof Permanent) {
((Permanent) mageObject).addInfo("chosen type", CardUtil.addToolTipMarkTags("Chosen type: " + typeChoice.getChoice()), game);
}

View file

@ -53,7 +53,7 @@ public class ChooseLandTypeEffect extends OneShotEffect {
if (!game.isSimulation()) {
game.informPlayers(mageObject.getName() + ": " + controller.getLogName() + " has chosen " + typeChoice.getChoice());
}
game.getState().setValue(mageObject.getId() + "_type", typeChoice.getChoice());
game.getState().setValue(mageObject.getId() + "_type", SubType.byDescription(typeChoice.getChoice()));
if (mageObject instanceof Permanent) {
((Permanent) mageObject).addInfo("chosen type", CardUtil.addToolTipMarkTags("Chosen type: " + typeChoice.getChoice()), game);
}

View file

@ -48,9 +48,9 @@ public class BoostAllOfChosenSubtypeEffect extends BoostAllEffect {
@Override
protected void setRuntimeData(Ability source, Game game) {
String s = (String) game.getState().getValue(source.getSourceId() + "_type");
if (subtype != null) {
subtype = SubType.byDescription(s);
SubType s = (SubType) game.getState().getValue(source.getSourceId() + "_type");
if (s != null) {
subtype = s;
} else {
discard();
}

View file

@ -44,8 +44,8 @@ public class GainAbilityAllOfChosenSubtypeEffect extends GainAbilityAllEffect {
@Override
protected void setRuntimeData(Ability source, Game game) {
String s = (String) game.getState().getValue(source.getSourceId() + "_type");
subtype = SubType.byDescription(s);
subtype = (SubType) game.getState().getValue(source.getSourceId() + "_type");
}
}

View file

@ -32,9 +32,9 @@ public class SpellsCostReductionAllOfChosenSubtypeEffect extends SpellsCostReduc
@Override
protected boolean selectedByRuntimeData(Card card, Ability source, Game game) {
String subtype = (String) game.getState().getValue(source.getSourceId() + "_type");
SubType subtype = (SubType) game.getState().getValue(source.getSourceId() + "_type");
if (subtype != null) {
return card.hasSubtype(SubType.byDescription(subtype), game);
return card.hasSubtype(subtype, game);
}
return false;
}

View file

@ -31,6 +31,7 @@ import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.constants.SubType;
import mage.game.Game;
import mage.game.permanent.Permanent;
@ -57,7 +58,7 @@ public class EnterAttributeAddChosenSubtypeEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanentEntering(source.getSourceId());
String subtype = (String) game.getState().getValue(source.getSourceId() + "_type");
SubType subtype = (SubType) game.getState().getValue(source.getSourceId() + "_type");
if (permanent != null && subtype != null) {
MageObject mageObject = permanent.getBasicMageObject(game);
if (!mageObject.getSubtype(null).contains(subtype)) {

View file

@ -308,29 +308,22 @@ public abstract class ExpansionSet implements Serializable {
private void addSpecial(List<Card> booster) {
int specialCards = 0;
List<CardInfo> specialBonus = getSpecialBonus();
if (specialBonus != null) {
specialCards += specialBonus.size();
}
specialCards += specialBonus.size();
List<CardInfo> specialMythic = getSpecialMythic();
if (specialMythic != null) {
specialCards += specialMythic.size();
}
specialCards += specialMythic.size();
List<CardInfo> specialRare = getSpecialRare();
if (specialRare != null) {
specialCards += specialRare.size();
}
specialCards += specialRare.size();
List<CardInfo> specialUncommon = getSpecialUncommon();
if (specialUncommon != null) {
specialCards += specialUncommon.size();
}
specialCards += specialUncommon.size();
List<CardInfo> specialCommon = getSpecialCommon();
if (specialCommon != null) {
specialCards += specialCommon.size();
}
specialCards += specialCommon.size();
if (specialCards > 0) {
for (int i = 0; i < numBoosterSpecial; i++) {
if (RandomUtil.nextInt(15) < 10) {
if (specialCommon != null && !specialCommon.isEmpty()) {
if (!specialCommon.isEmpty()) {
addToBooster(booster, specialCommon);
} else {
i--;
@ -338,7 +331,7 @@ public abstract class ExpansionSet implements Serializable {
continue;
}
if (RandomUtil.nextInt(4) < 3) {
if (specialUncommon != null && !specialUncommon.isEmpty()) {
if (!specialUncommon.isEmpty()) {
addToBooster(booster, specialUncommon);
} else {
i--;
@ -346,15 +339,15 @@ public abstract class ExpansionSet implements Serializable {
continue;
}
if (RandomUtil.nextInt(8) < 7) {
if (specialRare != null && !specialRare.isEmpty()) {
if (!specialRare.isEmpty()) {
addToBooster(booster, specialRare);
} else {
i--;
}
continue;
}
if (specialMythic != null && !specialMythic.isEmpty()) {
if (specialBonus != null && !specialBonus.isEmpty()) {
if (!specialMythic.isEmpty()) {
if (!specialBonus.isEmpty()) {
if (RandomUtil.nextInt(3) < 2) {
addToBooster(booster, specialMythic);
continue;
@ -366,7 +359,7 @@ public abstract class ExpansionSet implements Serializable {
} else {
i--;
}
if (specialBonus != null && !specialBonus.isEmpty()) {
if (!specialBonus.isEmpty()) {
addToBooster(booster, specialBonus);
}
}
@ -407,27 +400,27 @@ public abstract class ExpansionSet implements Serializable {
}
public List<CardInfo> getSpecialCommon() {
return null;
return new ArrayList<>();
}
public List<CardInfo> getSpecialUncommon() {
return null;
return new ArrayList<>();
}
public List<CardInfo> getSpecialRare() {
return null;
return new ArrayList<>();
}
public List<CardInfo> getSpecialMythic() {
return null;
return new ArrayList<>();
}
public List<CardInfo> getSpecialBonus() {
return null;
return new ArrayList<>();
}
public List<CardInfo> getSpecialLand() {
return null;
return new ArrayList<>();
}
public boolean isCustomSet() {

View file

@ -48,8 +48,8 @@ public class ChosenSubtypePredicate implements Predicate<MageObject> {
@Override
public boolean apply(MageObject input, Game game) {
String subtype = (String) game.getState().getValue(cardID + "_type");
return input.hasSubtype(SubType.byDescription(subtype), game);
SubType subtype = (SubType) game.getState().getValue(cardID + "_type");
return input.hasSubtype(subtype, game);
}
@Override

View file

@ -30,6 +30,7 @@ package mage.game.permanent.token;
import mage.constants.CardType;
import mage.MageInt;
import mage.ObjectColor;
import mage.constants.SubType;
/**
*
@ -40,8 +41,8 @@ public class RiptideReplicatorToken extends Token {
public RiptideReplicatorToken() {
this(null, null, 1);
}
public RiptideReplicatorToken(ObjectColor color, String type, int x) {
super(type, "X/X creature token of the chosen color and type");
public RiptideReplicatorToken(ObjectColor color, SubType type, int x) {
super(type.getDescription(), "X/X creature token of the chosen color and type");
cardType.add(CardType.CREATURE);
if (color != null) {
this.color.setColor(color);

View file

@ -30,6 +30,7 @@ package mage.game.permanent.token;
import mage.constants.CardType;
import mage.MageInt;
import mage.ObjectColor;
import mage.constants.SubType;
/**
*
@ -40,8 +41,8 @@ public class VolrathsLaboratoryToken extends Token {
public VolrathsLaboratoryToken() {
this(null, null);
}
public VolrathsLaboratoryToken(ObjectColor color, String type) {
super(type, "2/2 creature token of the chosen color and type");
public VolrathsLaboratoryToken(ObjectColor color, SubType type) {
super(type.getDescription(), "2/2 creature token of the chosen color and type");
cardType.add(CardType.CREATURE);
if (color != null) {
this.color.setColor(color);