Added Riddlekeeper and refactored similar cards

This commit is contained in:
Styxo 2016-10-25 12:54:46 +02:00
parent 070a0ca3fa
commit a0e3571d7b
5 changed files with 464 additions and 491 deletions

View file

@ -28,18 +28,14 @@
package mage.cards.b;
import java.util.UUID;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.common.AttacksAllTriggeredAbility;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.LoseLifeTargetEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.permanent.Permanent;
import mage.target.targetpointer.FixedTarget;
import mage.constants.SetTargetPointer;
import mage.filter.common.FilterCreaturePermanent;
/**
*
@ -48,11 +44,12 @@ import mage.target.targetpointer.FixedTarget;
public class BloodReckoning extends CardImpl {
public BloodReckoning(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{3}{B}");
super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{3}{B}");
// Whenever a creature attacks you or a planeswalker you control, that creature's controller loses 1 life.
this.addAbility(new BloodReckoningTriggeredAbility());
Effect effect = new LoseLifeTargetEffect(1);
effect.setText("that creature's controller loses 1 life");
this.addAbility(new AttacksAllTriggeredAbility(effect, false, new FilterCreaturePermanent(), SetTargetPointer.PLAYER, true, true));
}
public BloodReckoning(final BloodReckoning card) {
@ -64,57 +61,3 @@ public class BloodReckoning extends CardImpl {
return new BloodReckoning(this);
}
}
class BloodReckoningTriggeredAbility extends TriggeredAbilityImpl {
public BloodReckoningTriggeredAbility() {
super(Zone.BATTLEFIELD, new LoseLifeTargetEffect(1));
}
public BloodReckoningTriggeredAbility(final BloodReckoningTriggeredAbility ability) {
super(ability);
}
@Override
public BloodReckoningTriggeredAbility copy() {
return new BloodReckoningTriggeredAbility(this);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == EventType.ATTACKER_DECLARED;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Permanent attacker = game.getPermanent(event.getSourceId());
if (attacker != null) {
// check attacks you
boolean youOrYourPlaneswalker = false;
boolean you = event.getTargetId().equals(this.getControllerId());
if (you) {
youOrYourPlaneswalker = true;
} else{ // check attacks your planeswalker
Permanent permanent = game.getPermanent(event.getTargetId());
youOrYourPlaneswalker = permanent != null
&& permanent.getCardType().contains(CardType.PLANESWALKER)
&& permanent.getControllerId().equals(this.getControllerId());
}
if (youOrYourPlaneswalker) {
for (Effect effect : this.getEffects()) {
UUID controller = attacker.getControllerId();
if (controller != null) {
effect.setTargetPointer(new FixedTarget(controller));
}
}
return true;
}
}
return false;
}
@Override
public String getRule() {
return "Whenever a creature attacks you or a planeswalker you control, that creature's controller loses 1 life.";
}
}

View file

@ -0,0 +1,68 @@
/*
* 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.cards.r;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.common.AttacksAllTriggeredAbility;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.PutTopCardOfLibraryIntoGraveTargetEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SetTargetPointer;
import mage.filter.common.FilterCreaturePermanent;
/**
*
* @author Styxo
*/
public class Riddlekeeper extends CardImpl {
public Riddlekeeper(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{U}");
this.subtype.add("Homunculus");
this.power = new MageInt(1);
this.toughness = new MageInt(4);
// Whenever a creature attacks you or a planeswalker you control, that creature's controller puts the top two cards of his or her library into his or her graveyard.
Effect effect = new PutTopCardOfLibraryIntoGraveTargetEffect(2);
effect.setText("that creature's controller puts the top two cards of his or her library into his or her graveyard");
this.addAbility(new AttacksAllTriggeredAbility(effect, false, new FilterCreaturePermanent(), SetTargetPointer.PLAYER, true, true));
}
public Riddlekeeper(final Riddlekeeper card) {
super(card);
}
@Override
public Riddlekeeper copy() {
return new Riddlekeeper(this);
}
}

View file

@ -30,7 +30,7 @@ package mage.cards.s;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.common.AttacksAllTriggeredAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.RestrictionEffect;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
@ -39,13 +39,12 @@ import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.SetTargetPointer;
import mage.constants.Zone;
import mage.counters.CounterType;
import mage.filter.common.FilterCreaturePermanent;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.permanent.Permanent;
import mage.target.targetpointer.FixedTarget;
/**
*
@ -54,7 +53,7 @@ import mage.target.targetpointer.FixedTarget;
public class SlumberingDragon extends CardImpl {
public SlumberingDragon(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{R}");
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{R}");
this.subtype.add("Dragon");
this.power = new MageInt(3);
@ -67,8 +66,7 @@ public class SlumberingDragon extends CardImpl {
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new SlumberingDragonEffect()));
// Whenever a creature attacks you or a planeswalker you control, put a +1/+1 counter on Slumbering Dragon.
this.addAbility(new SlumberingDragonTriggeredAbility());
this.addAbility(new AttacksAllTriggeredAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance()), false, new FilterCreaturePermanent(), SetTargetPointer.PERMANENT, true));
}
public SlumberingDragon(final SlumberingDragon card) {
@ -119,45 +117,3 @@ class SlumberingDragonEffect extends RestrictionEffect {
return new SlumberingDragonEffect(this);
}
}
class SlumberingDragonTriggeredAbility extends TriggeredAbilityImpl {
public SlumberingDragonTriggeredAbility() {
super(Zone.BATTLEFIELD, new AddCountersSourceEffect(CounterType.P1P1.createInstance()), false);
}
public SlumberingDragonTriggeredAbility(final SlumberingDragonTriggeredAbility ability) {
super(ability);
}
@Override
public SlumberingDragonTriggeredAbility copy() {
return new SlumberingDragonTriggeredAbility(this);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == EventType.ATTACKER_DECLARED;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getTargetId().equals(controllerId)) {
this.getEffects().get(0).setTargetPointer(new FixedTarget(event.getSourceId()));
return true;
}
Permanent permanent = game.getPermanent(event.getTargetId());
if (permanent != null && permanent.getCardType().contains(CardType.PLANESWALKER) && permanent.getControllerId().equals(controllerId)) {
this.getEffects().get(0).setTargetPointer(new FixedTarget(event.getSourceId()));
return true;
}
return false;
}
@Override
public String getRule() {
return "Whenever a creature attacks you or a planeswalker you control, put a +1/+1 counter on {this}.";
}
}

View file

@ -267,6 +267,7 @@ public class Commander extends ExpansionSet {
cards.add(new SetCardInfo("Relic Crush", 168, Rarity.COMMON, mage.cards.r.RelicCrush.class));
cards.add(new SetCardInfo("Repulse", 58, Rarity.COMMON, mage.cards.r.Repulse.class));
cards.add(new SetCardInfo("Return to Dust", 28, Rarity.UNCOMMON, mage.cards.r.ReturnToDust.class));
cards.add(new SetCardInfo("Riddlekeeper", 59, Rarity.RARE, mage.cards.r.Riddlekeeper.class));
cards.add(new SetCardInfo("Righteous Cause", 29, Rarity.UNCOMMON, mage.cards.r.RighteousCause.class));
cards.add(new SetCardInfo("Riku of Two Reflections", 220, Rarity.MYTHIC, mage.cards.r.RikuOfTwoReflections.class));
cards.add(new SetCardInfo("Rise from the Grave", 96, Rarity.UNCOMMON, mage.cards.r.RiseFromTheGrave.class));

View file

@ -43,12 +43,12 @@ import mage.target.targetpointer.FixedTarget;
*
* @author LevelX2
*/
public class AttacksAllTriggeredAbility extends TriggeredAbilityImpl {
protected FilterCreaturePermanent filter;
protected boolean attacksYouOrYourPlaneswalker;
protected SetTargetPointer setTargetPointer;
protected boolean controller;
public AttacksAllTriggeredAbility(Effect effect, boolean optional) {
this(effect, optional, new FilterCreaturePermanent(), SetTargetPointer.NONE, false);
@ -59,10 +59,15 @@ public class AttacksAllTriggeredAbility extends TriggeredAbilityImpl {
}
public AttacksAllTriggeredAbility(Effect effect, boolean optional, FilterCreaturePermanent filter, SetTargetPointer setTargetPointer, boolean attacksYouOrYourPlaneswalker) {
this(effect, optional, filter, setTargetPointer, attacksYouOrYourPlaneswalker, false);
}
public AttacksAllTriggeredAbility(Effect effect, boolean optional, FilterCreaturePermanent filter, SetTargetPointer setTargetPointer, boolean attacksYouOrYourPlaneswalker, boolean controller) {
super(Zone.BATTLEFIELD, effect, optional);
this.filter = filter;
this.attacksYouOrYourPlaneswalker = attacksYouOrYourPlaneswalker;
this.setTargetPointer = setTargetPointer;
this.controller = controller;
}
public AttacksAllTriggeredAbility(final AttacksAllTriggeredAbility ability) {
@ -70,6 +75,7 @@ public class AttacksAllTriggeredAbility extends TriggeredAbilityImpl {
this.filter = ability.filter.copy();
this.attacksYouOrYourPlaneswalker = ability.attacksYouOrYourPlaneswalker;
this.setTargetPointer = ability.setTargetPointer;
this.controller = ability.controller;
}
@Override
@ -95,21 +101,20 @@ public class AttacksAllTriggeredAbility extends TriggeredAbilityImpl {
return false;
}
}
switch(setTargetPointer) {
switch (setTargetPointer) {
case PERMANENT:
for (Effect effect: getEffects()) {
for (Effect effect : getEffects()) {
effect.setTargetPointer(new FixedTarget(permanent.getId()));
}
break;
case PLAYER:
UUID defendingPlayerId = game.getCombat().getDefendingPlayerId(permanent.getId(), game);
if (defendingPlayerId != null) {
for (Effect effect: getEffects()) {
effect.setTargetPointer(new FixedTarget(defendingPlayerId));
UUID playerId = controller ? permanent.getControllerId() : game.getCombat().getDefendingPlayerId(permanent.getId(), game);
if (playerId != null) {
for (Effect effect : getEffects()) {
effect.setTargetPointer(new FixedTarget(playerId));
}
}
break;
}
return true;
}
@ -123,7 +128,7 @@ public class AttacksAllTriggeredAbility extends TriggeredAbilityImpl {
@Override
public String getRule() {
return "Whenever a " + filter.getMessage() + " attacks" + (attacksYouOrYourPlaneswalker ? " you or a planeswalker you control":"") +", " + super.getRule();
return "Whenever a " + filter.getMessage() + " attacks" + (attacksYouOrYourPlaneswalker ? " you or a planeswalker you control" : "") + ", " + super.getRule();
}
}