moved info from CardImpl to CardState and PermanentImpl + created InfoEffect for displaying rule info on Card

This commit is contained in:
betasteward 2015-03-10 14:57:55 -04:00
parent eb86378bc1
commit fe2cd395a6
55 changed files with 333 additions and 94 deletions

View file

@ -65,7 +65,7 @@ public class ChooseColorEffect extends OneShotEffect {
}
game.informPlayers(new StringBuilder(permanent.getLogName()).append(": ").append(controller.getName()).append(" has chosen ").append(choice.getChoice()).toString());
game.getState().setValue(source.getSourceId() + "_color", choice.getColor());
permanent.addInfo("chosen color", "<font color = 'blue'>Chosen color: " + choice.getColor().getDescription() + "</font>");
permanent.addInfo("chosen color", "<font color = 'blue'>Chosen color: " + choice.getColor().getDescription() + "</font>", game);
return true;
}
return false;

View file

@ -69,7 +69,7 @@ public class ChooseCreatureTypeEffect extends OneShotEffect {
}
game.informPlayers(permanent.getName() + ": " + controller.getName() + " has chosen " + typeChoice.getChoice());
game.getState().setValue(permanent.getId() + "_type", typeChoice.getChoice());
permanent.addInfo("chosen type", CardUtil.addToolTipMarkTags("Chosen type: " + typeChoice.getChoice()));
permanent.addInfo("chosen type", CardUtil.addToolTipMarkTags("Chosen type: " + typeChoice.getChoice()), game);
}
return false;
}

View file

@ -82,7 +82,7 @@ public class ChooseModeEffect extends OneShotEffect {
if (choice.isChosen()) {
game.informPlayers(new StringBuilder(sourcePermanent.getLogName()).append(": ").append(controller.getName()).append(" has chosen ").append(choice.getChoice()).toString());
game.getState().setValue(source.getSourceId() + "_modeChoice", choice.getChoice());
sourcePermanent.addInfo("_modeChoice", "<font color = 'blue'>Chosen mode: " + choice.getChoice() + "</font>");
sourcePermanent.addInfo("_modeChoice", "<font color = 'blue'>Chosen mode: " + choice.getChoice() + "</font>", game);
}
return true;
}

View file

@ -105,7 +105,7 @@ class DetainAllRestrictionEffect extends RestrictionEffect {
for(FixedTarget fixedTarget :this.detainedObjects) {
Permanent permanent = game.getPermanent(fixedTarget.getFirst(game, source));
if (permanent != null) {
permanent.addInfo(new StringBuilder("detain").append(getId()).toString(),"[Detained]");
permanent.addInfo(new StringBuilder("detain").append(getId()).toString(),"[Detained]", game);
}
}
}
@ -118,7 +118,7 @@ class DetainAllRestrictionEffect extends RestrictionEffect {
for(FixedTarget fixedTarget :this.detainedObjects) {
Permanent permanent = game.getPermanent(fixedTarget.getFirst(game, source));
if (permanent != null) {
permanent.addInfo(new StringBuilder("detain").append(getId()).toString(),"");
permanent.addInfo(new StringBuilder("detain").append(getId()).toString(),"", game);
}
}
return true;

View file

@ -141,7 +141,7 @@ class DetainRestrictionEffect extends RestrictionEffect {
for(UUID targetId :this.getTargetPointer().getTargets(game, source)) {
Permanent permanent = game.getPermanent(targetId);
if (permanent != null) {
permanent.addInfo(new StringBuilder("detain").append(getId()).toString(),"[Detained]");
permanent.addInfo(new StringBuilder("detain").append(getId()).toString(),"[Detained]", game);
}
}
}
@ -154,7 +154,7 @@ class DetainRestrictionEffect extends RestrictionEffect {
for(UUID targetId :this.getTargetPointer().getTargets(game, source)) {
Permanent permanent = game.getPermanent(targetId);
if (permanent != null) {
permanent.addInfo(new StringBuilder("detain").append(getId()).toString(),"");
permanent.addInfo(new StringBuilder("detain").append(getId()).toString(),"", game);
}
}
return true;

View file

@ -0,0 +1,61 @@
/*
* 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.effects.common;
import mage.constants.Outcome;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.game.Game;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class InfoEffect extends OneShotEffect {
public InfoEffect(String text) {
super(Outcome.Neutral);
this.staticText = text;
}
public InfoEffect(final InfoEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public InfoEffect copy() {
return new InfoEffect(this);
}
}

View file

@ -96,7 +96,7 @@ public class NameACardEffect extends OneShotEffect {
game.informPlayers(sourceObject.getLogName() + ", named card: [" + cardName + "]");
game.getState().setValue(source.getSourceId().toString() + INFO_KEY, cardName);
if (sourceObject instanceof Permanent) {
((Permanent)sourceObject).addInfo(INFO_KEY, CardUtil.addToolTipMarkTags("Named card: " + cardName));
((Permanent)sourceObject).addInfo(INFO_KEY, CardUtil.addToolTipMarkTags("Named card: " + cardName), game);
}
return true;
}

View file

@ -180,8 +180,8 @@ class HauntEffect extends OneShotEffect {
// remember the haunted creature
String key = new StringBuilder("Haunting_").append(source.getSourceId().toString()).append("_").append(card.getZoneChangeCounter()).toString();
game.getState().setValue(key, new FixedTarget(targetPointer.getFirst(game, source)));
card.addInfo("hauntinfo", new StringBuilder("Haunting ").append(hauntedCreature.getLogName()).toString());
hauntedCreature.addInfo("hauntinfo", new StringBuilder("Haunted by ").append(card.getLogName()).toString());
card.addInfo("hauntinfo", new StringBuilder("Haunting ").append(hauntedCreature.getLogName()).toString(), game);
hauntedCreature.addInfo("hauntinfo", new StringBuilder("Haunted by ").append(card.getLogName()).toString(), game);
game.informPlayers(new StringBuilder(card.getName()).append(" haunting ").append(hauntedCreature.getLogName()).toString());
}
return true;

View file

@ -40,7 +40,6 @@ import mage.constants.Zone;
import mage.counters.Counter;
import mage.counters.Counters;
import mage.game.Game;
import mage.watchers.Watcher;
public interface Card extends MageObject {
@ -51,7 +50,8 @@ public interface Card extends MageObject {
void addAbility(Ability ability);
void setSpellAbility(SpellAbility ability);
SpellAbility getSpellAbility();
List<String> getRules();
List<String> getRules(); // gets base card rules
List<String> getRules(Game game); // gets card rules + in game modifications
String getExpansionSetCode();
String getTokenSetCode();
void setFaceDown(boolean value);
@ -71,7 +71,7 @@ public interface Card extends MageObject {
int getZoneChangeCounter();
void updateZoneChangeCounter();
void addInfo(String key, String value);
void addInfo(String key, String value, Game game);
/**
* Moves the card to the specified zone

View file

@ -31,9 +31,7 @@ package mage.cards;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import mage.MageObject;
import mage.MageObjectImpl;
@ -59,6 +57,7 @@ import static mage.constants.Zone.PICK;
import static mage.constants.Zone.STACK;
import mage.counters.Counter;
import mage.counters.Counters;
import mage.game.CardState;
import mage.game.Game;
import mage.game.command.Commander;
import mage.game.events.GameEvent;
@ -87,7 +86,6 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
protected boolean flipCard;
protected String flipCardName;
protected int zoneChangeCounter = 1;
protected Map<String, String> info;
protected boolean usesVariousArt = false;
protected boolean splitCard;
protected boolean morphCard;
@ -153,10 +151,6 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
nightCard = card.nightCard;
}
zoneChangeCounter = card.zoneChangeCounter;
if (card.info != null) {
info = new HashMap<>();
info.putAll(card.info);
}
flipCard = card.flipCard;
flipCardName = card.flipCardName;
splitCard = card.splitCard;
@ -207,23 +201,39 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
return rarity;
}
@Override
public void addInfo(String key, String value, Game game) {
game.getState().getCardState(objectId).addInfo(key, value);
}
protected static final ArrayList<String> rulesError = new ArrayList<String>() {{add("Exception occured in rules generation");}};
@Override
public List<String> getRules() {
try {
List<String> rules = abilities.getRules(this.getLogName());
if (info != null) {
for (String data : info.values()) {
rules.add(data);
}
return abilities.getRules(this.getLogName());
} catch (Exception e) {
logger.info("Exception in rules generation for card: " + this.getName(), e);
}
return rulesError;
}
@Override
public List<String> getRules(Game game) {
try {
List<String> rules = getRules();
CardState state = game.getState().getCardState(objectId);
for (String data : state.getInfo().values()) {
rules.add(data);
}
// for (Ability ability: state.getAbilities()) {
// rules.add(ability.getRule());
// }
return rules;
} catch (Exception e) {
System.out.println("Exception in rules generation for card: " + this.getName());
e.printStackTrace();
logger.error("Exception in rules generation for card: " + this.getName(), e);
}
ArrayList<String> rules = new ArrayList<>();
rules.add("Exception occured in rules generation");
return rules;
return rulesError;
}
@Override
@ -621,18 +631,6 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
// logger.info(name + " set= " + zoneChangeCounter + " " + ((this instanceof Permanent) ? " Permanent":"Card"));
}
@Override
public void addInfo(String key, String value) {
if (info == null) {
info = new HashMap<>();
}
if (value == null || value.isEmpty()) {
info.remove(key);
} else {
info.put(key, value);
}
}
@Override
public void build() {}

View file

@ -59,7 +59,7 @@ public class CardTextPredicate implements Predicate<Card> {
boolean found = false;
if (!token.isEmpty()) {
// then try to find in rules
for (String rule : input.getRules()) {
for (String rule : input.getRules(game)) {
if (rule.toLowerCase().contains(token)) {
found = true;
break;

View file

@ -63,6 +63,7 @@ import mage.constants.Zone;
import mage.counters.Counter;
import mage.counters.CounterType;
import mage.counters.Counters;
import mage.game.CardState;
import mage.game.Game;
import mage.game.events.DamageCreatureEvent;
import mage.game.events.DamagePlaneswalkerEvent;
@ -110,7 +111,8 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
protected Counters counters;
protected List<Counter> markedDamage;
protected int timesLoyaltyUsed = 0;
protected Map<String, String> info;
private static final List<UUID> emptyList = Collections.unmodifiableList(new ArrayList<UUID>());
public PermanentImpl(UUID ownerId, UUID controllerId, String name) {
@ -154,6 +156,10 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
markedDamage.add(counter.copy());
}
}
if (permanent.info != null) {
info = new HashMap<>();
info.putAll(permanent.info);
}
this.counters = permanent.counters.copy();
this.attachedTo = permanent.attachedTo;
this.minBlockedBy = permanent.minBlockedBy;
@ -209,6 +215,33 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
return sb.toString();
}
@Override
public void addInfo(String key, String value, Game game) {
if (info == null) {
info = new HashMap<>();
}
if (value == null || value.isEmpty()) {
info.remove(key);
} else {
info.put(key, value);
}
}
@Override
public List<String> getRules(Game game) {
try {
List<String> rules = getRules();
if (info != null) {
for (String data : info.values()) {
rules.add(data);
}
}
return rules;
} catch (Exception e) {
return rulesError;
}
}
@Override
@Deprecated
public void addAbility(Ability ability) {

View file

@ -701,6 +701,11 @@ public class Spell implements StackObject, Card {
return card.getRules();
}
@Override
public List<String> getRules(Game game) {
return card.getRules(game);
}
@Override
public String getExpansionSetCode() {
return card.getExpansionSetCode();
@ -900,7 +905,7 @@ public class Spell implements StackObject, Card {
}
@Override
public void addInfo(String key, String value) {
public void addInfo(String key, String value, Game game) {
// do nothing
}

View file

@ -108,21 +108,21 @@ public class CommanderCombatDamageWatcher extends Watcher {
if (castCount != null) {
sb.append(" ").append(castCount).append(castCount.intValue() == 1 ? " time":" times").append(" casted from the command zone.");
}
this.addInfo(object, "Commander",sb.toString());
this.addInfo(object, "Commander",sb.toString(), game);
for (Map.Entry<UUID, Integer> entry : damageToPlayer.entrySet()) {
Player damagedPlayer = game.getPlayer(entry.getKey());
sb.setLength(0);
sb.append("<b>Commander</b> did ").append(entry.getValue()).append(" combat damage to player ").append(damagedPlayer.getName()).append(".");
this.addInfo(object, new StringBuilder("Commander").append(entry.getKey()).toString(),sb.toString());
this.addInfo(object, new StringBuilder("Commander").append(entry.getKey()).toString(),sb.toString(), game);
}
}
}
private void addInfo(MageObject object, String key, String value) {
private void addInfo(MageObject object, String key, String value, Game game) {
if (object instanceof Card) {
((Card) object).addInfo(key, value);
((Card) object).addInfo(key, value, game);
} else if (object instanceof Permanent) {
((Permanent) object).addInfo(key, value);
((Permanent) object).addInfo(key, value, game);
}
}