forked from External/mage
Fixed errors on empty targets in some effects;
Added export code example for mtgjson4 project;
This commit is contained in:
parent
fd043fa913
commit
942ecc5328
4 changed files with 149 additions and 13 deletions
|
|
@ -1,7 +1,5 @@
|
|||
|
||||
package mage.cards.b;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.MageInt;
|
||||
import mage.abilities.TriggeredAbilityImpl;
|
||||
import mage.abilities.dynamicvalue.common.StaticValue;
|
||||
|
|
@ -18,19 +16,23 @@ import mage.game.events.GameEvent.EventType;
|
|||
import mage.players.Player;
|
||||
import mage.target.targetpointer.FixedTarget;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author nantuko
|
||||
*/
|
||||
public final class BelltowerSphinx extends CardImpl {
|
||||
|
||||
public BelltowerSphinx(UUID ownerId, CardSetInfo setInfo) {
|
||||
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{4}{U}");
|
||||
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{4}{U}");
|
||||
this.subtype.add(SubType.SPHINX);
|
||||
|
||||
this.power = new MageInt(2);
|
||||
this.toughness = new MageInt(5);
|
||||
|
||||
// Flying
|
||||
this.addAbility(FlyingAbility.getInstance());
|
||||
|
||||
// Whenever a source deals damage to Belltower Sphinx, that source's controller puts that many cards from the top of their library into their graveyard.
|
||||
this.addAbility(new BelltowerSphinxEffect());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,128 @@
|
|||
package org.mage.test.utils;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.Mode;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.cards.*;
|
||||
import mage.target.Target;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author JayDi85
|
||||
*/
|
||||
public class ExportJsonGameplayDataTest {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(ExportJsonGameplayDataTest.class);
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
/**
|
||||
* It's export code example for https://github.com/mtgjson/mtgjson4
|
||||
*/
|
||||
public void exportTest() {
|
||||
List<Card> cards = new ArrayList<>();
|
||||
Collection<ExpansionSet> sets = Sets.getInstance().values();
|
||||
for (ExpansionSet set : sets) {
|
||||
if (!set.getCode().equals("GRN")) {
|
||||
//continue;
|
||||
}
|
||||
|
||||
for (ExpansionSet.SetCardInfo setInfo : set.getSetCardInfo()) {
|
||||
if (cards.size() >= 10) {
|
||||
//break;
|
||||
}
|
||||
cards.add(CardImpl.createCard(setInfo.getCardClass(), new CardSetInfo(setInfo.getName(), set.getCode(),
|
||||
setInfo.getCardNumber(), setInfo.getRarity(), setInfo.getGraphicInfo())));
|
||||
}
|
||||
}
|
||||
|
||||
JsonObject res = new JsonObject();
|
||||
|
||||
for (Card card : cards) {
|
||||
try {
|
||||
JsonObject resCard = new JsonObject();
|
||||
res.add(card.getName(), resCard);
|
||||
|
||||
JsonArray resAbilities = new JsonArray();
|
||||
resCard.add("abilities", resAbilities);
|
||||
for (Ability ability : card.getAbilities()) {
|
||||
JsonObject resAbility = new JsonObject();
|
||||
resAbilities.add(resAbility);
|
||||
|
||||
// basic
|
||||
resAbility.addProperty("cost", ability.getManaCosts().getText());
|
||||
resAbility.addProperty("name", ability.toString());
|
||||
resAbility.addProperty("class", ability.getClass().getSimpleName());
|
||||
//resAbility.addProperty("rule", ability.getRule());
|
||||
|
||||
// modes
|
||||
JsonArray resModes = new JsonArray();
|
||||
resAbility.add("modes", resModes);
|
||||
for (Mode mode : ability.getModes().values()) {
|
||||
JsonObject resMode = new JsonObject();
|
||||
resModes.add(resMode);
|
||||
|
||||
// basic
|
||||
//resMode.addProperty("name", mode.toString());
|
||||
|
||||
// effects
|
||||
JsonArray resEffects = new JsonArray();
|
||||
resMode.add("effects", resEffects);
|
||||
for (Effect effect : mode.getEffects()) {
|
||||
JsonObject resEffect = new JsonObject();
|
||||
resEffects.add(resEffect);
|
||||
|
||||
resEffect.addProperty("class", effect.getClass().getSimpleName());
|
||||
resEffect.addProperty("outcome", effect.getOutcome().toString());
|
||||
resEffect.addProperty("text", effect.getText(mode));
|
||||
}
|
||||
if (resEffects.size() == 0) {
|
||||
resMode.remove("effects");
|
||||
}
|
||||
|
||||
// targets
|
||||
JsonArray resTargets = new JsonArray();
|
||||
resMode.add("targets", resTargets);
|
||||
for (Target target : mode.getTargets()) {
|
||||
JsonObject resTarget = new JsonObject();
|
||||
resTargets.add(resTarget);
|
||||
|
||||
resTarget.addProperty("name", target.getTargetName());
|
||||
resTarget.addProperty("class", target.getClass().getSimpleName());
|
||||
resTarget.addProperty("min", target.getMinNumberOfTargets());
|
||||
resTarget.addProperty("max", target.getMaxNumberOfTargets());
|
||||
}
|
||||
if (resTargets.size() == 0) {
|
||||
resMode.remove("targets");
|
||||
}
|
||||
|
||||
if (resMode.get("effects") == null && resMode.get("targets") == null) {
|
||||
resModes.remove(resMode);
|
||||
}
|
||||
}
|
||||
if (resModes.size() == 0) {
|
||||
resAbility.remove("modes");
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
logger.error("Inner error for " + card.getName() + ": " + e.getMessage(), e);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Gson gson = new GsonBuilder()
|
||||
.setPrettyPrinting()
|
||||
.create();
|
||||
System.out.println(gson.toJson(res));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,5 @@
|
|||
|
||||
package mage.abilities.effects.common;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.Mode;
|
||||
import mage.abilities.dynamicvalue.DynamicValue;
|
||||
|
|
@ -14,8 +12,9 @@ import mage.game.permanent.Permanent;
|
|||
import mage.players.Player;
|
||||
import mage.target.Target;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
* @author North
|
||||
*/
|
||||
|
|
@ -161,11 +160,15 @@ public class DamageTargetEffect extends OneShotEffect {
|
|||
if (!targetDescription.isEmpty()) {
|
||||
sb.append(targetDescription);
|
||||
} else {
|
||||
String targetName = mode.getTargets().get(0).getTargetName();
|
||||
if (targetName.contains("any")) {
|
||||
sb.append(targetName);
|
||||
if (!mode.getTargets().isEmpty()) {
|
||||
String targetName = mode.getTargets().get(0).getTargetName();
|
||||
if (targetName.contains("any")) {
|
||||
sb.append(targetName);
|
||||
} else {
|
||||
sb.append("target ").append(targetName);
|
||||
}
|
||||
} else {
|
||||
sb.append("target ").append(targetName);
|
||||
sb.append("that target");
|
||||
}
|
||||
}
|
||||
if (!message.isEmpty()) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
package mage.abilities.effects.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
|
|
@ -13,7 +12,6 @@ import mage.players.Player;
|
|||
import mage.util.CardUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class PutLibraryIntoGraveTargetEffect extends OneShotEffect {
|
||||
|
|
@ -61,7 +59,12 @@ public class PutLibraryIntoGraveTargetEffect extends OneShotEffect {
|
|||
StringBuilder sb = new StringBuilder();
|
||||
String message = amount.getMessage();
|
||||
|
||||
sb.append("target ").append(mode.getTargets().get(0).getTargetName());
|
||||
if (!mode.getTargets().isEmpty()) {
|
||||
sb.append("target ").append(mode.getTargets().get(0).getTargetName());
|
||||
} else {
|
||||
sb.append("that target");
|
||||
}
|
||||
|
||||
sb.append(" puts the top ");
|
||||
if (message.isEmpty()) {
|
||||
if (amount.toString().equals("1")) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue