From 13b69f942ca3ebdcc42fc7666a40805d4dc47398 Mon Sep 17 00:00:00 2001 From: beholder Date: Thu, 27 Oct 2011 09:22:16 +0200 Subject: [PATCH] added MagicCMCTargetFilter. added AEther Vial and Goblin Lackey --- resources/magic/data/cards.txt | 23 +++++ src/magic/card/AEther_Vial.java | 98 +++++++++++++++++++ src/magic/card/Goblin_Lackey.java | 57 +++++++++++ src/magic/model/choice/MagicTargetChoice.java | 3 + src/magic/model/target/MagicTargetFilter.java | 30 ++++++ 5 files changed, 211 insertions(+) create mode 100644 src/magic/card/AEther_Vial.java create mode 100644 src/magic/card/Goblin_Lackey.java diff --git a/resources/magic/data/cards.txt b/resources/magic/data/cards.txt index 8e6c54fd00..72db1a8d44 100644 --- a/resources/magic/data/cards.txt +++ b/resources/magic/data/cards.txt @@ -17303,3 +17303,26 @@ converted=3 cost={2}{U} pt=1/3 timing=main + +>AEther Vial +url=http://magiccards.info/ds/en/91.html +image=http://magiccards.info/scans/en/ds/91.jpg +value=2 +rarity=U +type=Artifact +converted=1 +cost={1} +timing=main + +>Goblin Lackey +url=http://magiccards.info/fve/en/5.html +image=http://magiccards.info/scans/en/fve/5.jpg +value=2 +rarity=M +type=Creature +subtype=Goblin +color=r +converted=1 +cost={R} +pt=1/1 +timing=main diff --git a/src/magic/card/AEther_Vial.java b/src/magic/card/AEther_Vial.java new file mode 100644 index 0000000000..9aa56c224e --- /dev/null +++ b/src/magic/card/AEther_Vial.java @@ -0,0 +1,98 @@ +package magic.card; + +import magic.model.MagicCard; +import magic.model.MagicCounterType; +import magic.model.MagicGame; +import magic.model.MagicLocationType; +import magic.model.MagicPayedCost; +import magic.model.MagicPermanent; +import magic.model.MagicPlayer; +import magic.model.MagicSource; +import magic.model.action.MagicCardAction; +import magic.model.action.MagicChangeCountersAction; +import magic.model.action.MagicPlayCardAction; +import magic.model.action.MagicRemoveCardAction; +import magic.model.choice.MagicMayChoice; +import magic.model.choice.MagicTargetChoice; +import magic.model.condition.MagicCondition; +import magic.model.event.MagicActivationHints; +import magic.model.event.MagicEvent; +import magic.model.event.MagicPermanentActivation; +import magic.model.event.MagicTapEvent; +import magic.model.event.MagicTiming; +import magic.model.target.MagicGraveyardTargetPicker; +import magic.model.target.MagicTargetFilter; +import magic.model.target.MagicTargetHint; +import magic.model.trigger.MagicAtUpkeepTrigger; + +public class AEther_Vial { + public static final MagicAtUpkeepTrigger T = new MagicAtUpkeepTrigger() { + @Override + public MagicEvent executeTrigger(final MagicGame game,final MagicPermanent permanent,final MagicPlayer data) { + final MagicPlayer player = permanent.getController(); + return (player == data) ? + new MagicEvent( + permanent, + player, + new MagicMayChoice( + player + " may put a charge counter on " + permanent + "."), + new Object[]{permanent}, + this, + player + " may$ put a charge counter on " + permanent + "."): + MagicEvent.NONE; + } + @Override + public void executeEvent( + final MagicGame game, + final MagicEvent event, + final Object data[], + final Object[] choiceResults) { + if (MagicMayChoice.isYesChoice(choiceResults[0])) { + game.doAction(new MagicChangeCountersAction((MagicPermanent)data[0],MagicCounterType.Charge,1,true)); + } + } + }; + + public static final MagicPermanentActivation A = new MagicPermanentActivation( + new MagicCondition[]{MagicCondition.CAN_TAP_CONDITION}, + new MagicActivationHints(MagicTiming.Token), + "Token" + ) { + + @Override + public MagicEvent[] getCostEvent(final MagicSource source) { + return new MagicEvent[]{new MagicTapEvent((MagicPermanent)source)}; + } + + @Override + public MagicEvent getPermanentEvent(final MagicPermanent source,final MagicPayedCost payedCost) { + final MagicTargetFilter targetFilter = + new MagicTargetFilter.MagicCMCTargetFilter( + MagicTargetFilter.TARGET_CREATURE_CARD_FROM_HAND, + source.getCounters(MagicCounterType.Charge)); + final MagicTargetChoice targetChoice = + new MagicTargetChoice( + targetFilter,false,MagicTargetHint.None,"a creature card from your hand"); + return new MagicEvent( + source, + source.getController(), + targetChoice, + new MagicGraveyardTargetPicker(true), + new Object[]{source.getController()}, + this, + "Put a creature card$ with converted mana cost equal to " + + "the number of charge counters on " + source + + " from your hand onto the battlefield."); + } + + @Override + public void executeEvent(final MagicGame game,final MagicEvent event,final Object[] data,final Object[] choiceResults) { + event.processTargetCard(game,choiceResults,0,new MagicCardAction() { + public void doAction(final MagicCard card) { + game.doAction(new MagicRemoveCardAction(card,MagicLocationType.OwnersHand)); + game.doAction(new MagicPlayCardAction(card,(MagicPlayer)data[0],MagicPlayCardAction.NONE)); + } + }); + } + }; +} diff --git a/src/magic/card/Goblin_Lackey.java b/src/magic/card/Goblin_Lackey.java new file mode 100644 index 0000000000..0ba9417eda --- /dev/null +++ b/src/magic/card/Goblin_Lackey.java @@ -0,0 +1,57 @@ +package magic.card; + +import magic.model.MagicCard; +import magic.model.MagicDamage; +import magic.model.MagicGame; +import magic.model.MagicLocationType; +import magic.model.MagicPermanent; +import magic.model.MagicPlayer; +import magic.model.action.MagicCardAction; +import magic.model.action.MagicPlayCardAction; +import magic.model.action.MagicRemoveCardAction; +import magic.model.choice.MagicMayChoice; +import magic.model.choice.MagicTargetChoice; +import magic.model.event.MagicEvent; +import magic.model.target.MagicGraveyardTargetPicker; +import magic.model.trigger.MagicWhenDamageIsDealtTrigger; + + +public class Goblin_Lackey { + public static final MagicWhenDamageIsDealtTrigger T = new MagicWhenDamageIsDealtTrigger() { + @Override + public MagicEvent executeTrigger(final MagicGame game,final MagicPermanent permanent,final MagicDamage damage) { + final MagicPlayer player = permanent.getController(); + return (damage.getSource() == permanent && + damage.getTarget().isPlayer()) ? + new MagicEvent( + permanent, + player, + new MagicMayChoice( + player + " may put a Goblin permanent card from " + + "his or her hand onto the battlefield.", + MagicTargetChoice.TARGET_GOBLIN_CARD_FROM_HAND), + new MagicGraveyardTargetPicker(true), + new Object[]{player}, + this, + player + " may$ put a Goblin permanent card$ from " + + "his or her hand onto the battlefield."): + MagicEvent.NONE; + } + + @Override + public void executeEvent( + final MagicGame game, + final MagicEvent event, + final Object data[], + final Object[] choiceResults) { + if (MagicMayChoice.isYesChoice(choiceResults[0])) { + event.processTargetCard(game,choiceResults,1,new MagicCardAction() { + public void doAction(final MagicCard card) { + game.doAction(new MagicRemoveCardAction(card,MagicLocationType.OwnersHand)); + game.doAction(new MagicPlayCardAction(card,(MagicPlayer)data[0],MagicPlayCardAction.NONE)); + } + }); + } + } + }; +} diff --git a/src/magic/model/choice/MagicTargetChoice.java b/src/magic/model/choice/MagicTargetChoice.java index 42f99df13a..3a3bac5d57 100644 --- a/src/magic/model/choice/MagicTargetChoice.java +++ b/src/magic/model/choice/MagicTargetChoice.java @@ -315,6 +315,9 @@ public class MagicTargetChoice extends MagicChoice { public static final MagicTargetChoice TARGET_LAND_CARD_FROM_HAND = new MagicTargetChoice(MagicTargetFilter.TARGET_LAND_CARD_FROM_HAND,false,MagicTargetHint.None, "a land card from your hand"); + public static final MagicTargetChoice TARGET_GOBLIN_CARD_FROM_HAND = + new MagicTargetChoice(MagicTargetFilter.TARGET_GOBLIN_CARD_FROM_HAND,false,MagicTargetHint.None, + "a Goblin permanent card from your hand"); private final String targetDescription; private final MagicTargetFilter targetFilter; diff --git a/src/magic/model/target/MagicTargetFilter.java b/src/magic/model/target/MagicTargetFilter.java index 8f7e8958bc..7857456365 100644 --- a/src/magic/model/target/MagicTargetFilter.java +++ b/src/magic/model/target/MagicTargetFilter.java @@ -1643,6 +1643,16 @@ public interface MagicTargetFilter { } }; + MagicTargetFilter TARGET_GOBLIN_CARD_FROM_HAND = new MagicTargetFilter() { + public boolean accept(final MagicGame game,final MagicPlayer player,final MagicTarget target) { + final MagicCardDefinition cardDefinition = ((MagicCard)target).getCardDefinition(); + return cardDefinition.hasSubType(MagicSubType.Goblin); + } + public boolean acceptType(final MagicTargetType targetType) { + return targetType == MagicTargetType.Hand; + } + }; + // Permanent reference can not be used because game is copied. public static final class MagicOtherPermanentTargetFilter implements MagicTargetFilter { @@ -1688,6 +1698,26 @@ public interface MagicTargetFilter { } }; + public static final class MagicCMCTargetFilter implements MagicTargetFilter { + + private final MagicTargetFilter targetFilter; + private final int cmc; + + public MagicCMCTargetFilter(final MagicTargetFilter targetFilter,final int cmc) { + this.targetFilter = targetFilter; + this.cmc = cmc; + } + @Override + public boolean accept(final MagicGame game,final MagicPlayer player,final MagicTarget target) { + return targetFilter.accept(game,player,target) && + ((MagicCard)target).getCardDefinition().hasConvertedCost(cmc); + } + @Override + public boolean acceptType(final MagicTargetType targetType) { + return targetFilter.acceptType(targetType); + } + }; + public static final class CardTargetFilter implements MagicTargetFilter { private final MagicCardDefinition cardDefinition;