From c1a02e9418c4679231e19c67fe7025cf7d18cfd1 Mon Sep 17 00:00:00 2001 From: LevelX Date: Sun, 15 Jan 2012 01:54:12 +0100 Subject: [PATCH] 2 new cards [CHK] Hisoka, Minamo Sensei / Hisoka's Guard Fixes Hankyu - fixed possible null pointer exception HamletCaptain - fixed issue 446 RakishHeir - fixed issue 445 Levitation - minor text change --- .../mage/sets/championsofkamigawa/Hankyu.java | 10 +- .../HisokaMinamoSensei.java | 159 +++++++++++++ .../championsofkamigawa/HisokasGuard.java | 209 ++++++++++++++++++ .../mage/sets/innistrad/HamletCaptain.java | 2 +- .../src/mage/sets/innistrad/RakishHeir.java | 5 +- .../src/mage/sets/magic2012/Levitation.java | 2 +- 6 files changed, 379 insertions(+), 8 deletions(-) create mode 100644 Mage.Sets/src/mage/sets/championsofkamigawa/HisokaMinamoSensei.java create mode 100644 Mage.Sets/src/mage/sets/championsofkamigawa/HisokasGuard.java diff --git a/Mage.Sets/src/mage/sets/championsofkamigawa/Hankyu.java b/Mage.Sets/src/mage/sets/championsofkamigawa/Hankyu.java index 52cdfa5e8b6..78cd9e16c40 100644 --- a/Mage.Sets/src/mage/sets/championsofkamigawa/Hankyu.java +++ b/Mage.Sets/src/mage/sets/championsofkamigawa/Hankyu.java @@ -189,10 +189,12 @@ class HankyuCountersSourceCost extends CostImpl { @Override public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana) { Permanent equipment = game.getPermanent(this.effectGivingEquipmentId); - this.removedCounters = equipment.getCounters().getCount(CounterType.AIM); - if (equipment != null && this.removedCounters > 0) { - equipment.removeCounters("aim", this.removedCounters, game); - } + if (equipment != null ) { + this.removedCounters = equipment.getCounters().getCount(CounterType.AIM); + if (this.removedCounters > 0) { + equipment.removeCounters("aim", this.removedCounters, game); + } + } this.paid = true; return true; } diff --git a/Mage.Sets/src/mage/sets/championsofkamigawa/HisokaMinamoSensei.java b/Mage.Sets/src/mage/sets/championsofkamigawa/HisokaMinamoSensei.java new file mode 100644 index 00000000000..b7cd54a341f --- /dev/null +++ b/Mage.Sets/src/mage/sets/championsofkamigawa/HisokaMinamoSensei.java @@ -0,0 +1,159 @@ +/* + * 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.sets.championsofkamigawa; + +import java.util.UUID; + +import mage.Constants; +import mage.Constants.CardType; +import mage.Constants.Outcome; +import mage.Constants.Rarity; +import mage.MageInt; +import mage.abilities.Ability; +import mage.abilities.common.SimpleActivatedAbility; +import mage.abilities.costs.CostImpl; +import mage.abilities.costs.mana.ManaCostsImpl; +import mage.abilities.effects.OneShotEffect; +import mage.cards.Card; +import mage.cards.CardImpl; +import mage.filter.Filter; +import mage.filter.FilterCard; +import mage.filter.common.FilterControlledPermanent; +import mage.game.Game; +import mage.game.stack.Spell; +import mage.players.Player; +import mage.target.TargetSpell; +import mage.target.common.TargetCardInHand; + +/** + * @author LevelX + */ +public class HisokaMinamoSensei extends CardImpl { + + public HisokaMinamoSensei(UUID ownerId) { + super(ownerId, 66, "Hisoka, Minamo Sensei", Rarity.RARE, new CardType[]{CardType.CREATURE}, "{2}{U}{U}"); + this.expansionSetCode = "CHK"; + this.supertype.add("Legendary"); + this.subtype.add("Human"); + this.subtype.add("Wizard"); + this.color.setBlue(true); + this.power = new MageInt(1); + this.toughness = new MageInt(3); + + // {2}{U}, Discard a card: Counter target spell if it has the same converted mana cost as the discarded card. + Ability ability = new SimpleActivatedAbility(Constants.Zone.BATTLEFIELD, new HisokaMinamoSenseiCounterEffect(), new ManaCostsImpl("{2}{U}")); + ability.addTarget(new TargetSpell()); + TargetCardInHand targetCard = new TargetCardInHand(new FilterCard("a card")); + ability.addCost(new HisokaMinamoSenseiDiscardTargetCost(targetCard)); + this.addAbility(ability); + } + + public HisokaMinamoSensei(final HisokaMinamoSensei card) { + super(card); + } + + @Override + public HisokaMinamoSensei copy() { + return new HisokaMinamoSensei(this); + } + +} + +class HisokaMinamoSenseiDiscardTargetCost extends CostImpl { + + protected int convertedManaCosts = 0; + + public HisokaMinamoSenseiDiscardTargetCost(TargetCardInHand target) { + this.addTarget(target); + this.text = "Discard " + target.getTargetName(); + } + + public HisokaMinamoSenseiDiscardTargetCost(HisokaMinamoSenseiDiscardTargetCost cost) { + super(cost); + } + + @Override + public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana) { + if (targets.choose(Outcome.Discard, controllerId, sourceId, game)) { + Player player = game.getPlayer(controllerId); + for (UUID targetId: targets.get(0).getTargets()) { + Card card = player.getHand().get(targetId, game); + if (card == null) + return false; + convertedManaCosts = card.getManaCost().convertedManaCost(); + paid |= player.discard(card, null, game); + + } + } + return paid; + } + + @Override + public boolean canPay(UUID sourceId, UUID controllerId, Game game) { + return targets.canChoose(controllerId, game); + } + + @Override + public HisokaMinamoSenseiDiscardTargetCost copy() { + return new HisokaMinamoSenseiDiscardTargetCost(this); + } + + public int getConvertedCosts() { + return convertedManaCosts; + } + +} + +class HisokaMinamoSenseiCounterEffect extends OneShotEffect { + HisokaMinamoSenseiCounterEffect() { + super(Constants.Outcome.Detriment); + staticText = "Counter target spell if it has the same converted mana cost as the discarded card"; + } + + HisokaMinamoSenseiCounterEffect(final HisokaMinamoSenseiCounterEffect effect) { + super(effect); + } + + @Override + public boolean apply(Game game, Ability source) { + Spell spell = game.getStack().getSpell(targetPointer.getFirst(source)); + if (spell != null) { + HisokaMinamoSenseiDiscardTargetCost cost = (HisokaMinamoSenseiDiscardTargetCost) source.getCosts().get(0); + if (cost != null && cost.getConvertedCosts() == spell.getManaCost().convertedManaCost()) { + return game.getStack().counter(targetPointer.getFirst(source), source.getSourceId(), game); + } + } + return false; + } + + @Override + public HisokaMinamoSenseiCounterEffect copy() { + return new HisokaMinamoSenseiCounterEffect(this); + } +} \ No newline at end of file diff --git a/Mage.Sets/src/mage/sets/championsofkamigawa/HisokasGuard.java b/Mage.Sets/src/mage/sets/championsofkamigawa/HisokasGuard.java new file mode 100644 index 00000000000..6acf5eba966 --- /dev/null +++ b/Mage.Sets/src/mage/sets/championsofkamigawa/HisokasGuard.java @@ -0,0 +1,209 @@ +/* + * 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.sets.championsofkamigawa; + +import java.util.UUID; + +import mage.Constants; +import mage.Constants.CardType; +import mage.Constants.Duration; +import mage.Constants.Layer; +import mage.Constants.Outcome; +import mage.Constants.Rarity; +import mage.Constants.SubLayer; +import mage.Constants.Zone; +import mage.MageInt; +import mage.abilities.Ability; +import mage.abilities.common.SimpleActivatedAbility; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.costs.common.TapSourceCost; +import mage.abilities.costs.mana.ManaCosts; +import mage.abilities.costs.mana.ManaCostsImpl; +import mage.abilities.effects.ContinuousEffectImpl; +import mage.abilities.effects.Effect; +import mage.abilities.effects.RestrictionEffect; +import mage.abilities.keyword.ShroudAbility; +import mage.cards.CardImpl; +import mage.filter.common.FilterControlledCreaturePermanent; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; +import mage.target.Target; +import mage.target.common.TargetControlledCreaturePermanent; + +/** + * + * @author nantuko + */ +public class HisokasGuard extends CardImpl { + + public HisokasGuard(UUID ownerId) { + super(ownerId, 68, "Hisoka's Guard", Rarity.COMMON, new CardType[]{CardType.CREATURE}, "{1}{U}"); + this.expansionSetCode = "CHK"; + this.subtype.add("Human"); + this.subtype.add("Wizard"); + + this.color.setBlue(true); + this.power = new MageInt(1); + this.toughness = new MageInt(1); + + // You may choose not to untap Hisoka's Guard during your untap step. + this.addAbility(new SimpleStaticAbility(Constants.Zone.BATTLEFIELD, new HisokasGuardRestrictionEffect())); + + // {1}{U}, {T}: Target creature you control other than Hisoka's Guard has shroud for as long as Hisoka's Guard remains tapped. (It can't be the target of spells or abilities.) + FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent(); + filter.setAnother(true); + Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new HisokasGuardGainAbilityTargetEffect(), new ManaCostsImpl("{1}{U}")); + ability.addCost(new TapSourceCost()); + Target target = new TargetControlledCreaturePermanent(1, 1, filter, true, true); + ability.addTarget(target); + this.addAbility(ability); + + } + + public HisokasGuard(final HisokasGuard card) { + super(card); + } + + @Override + public HisokasGuard copy() { + return new HisokasGuard(this); + } +} + +//class HisokasGuardActivatedAbility extends SimpleActivatedAbility { +// +// public HisokasGuardActivatedAbility(Zone zone, Effect effect, ManaCosts cost) { +// super(zone, effect, cost); +// } +// +// public HisokasGuardActivatedAbility(HisokasGuardActivatedAbility ability) { +// super(ability); +// } +// +// @Override +// public boolean resolve(Game game) { +// if (super.resolve(game)) { +// // remember the guarded creature +// Permanent guardedCreature = game.getPermanent(this.getTargets().getFirstTarget()); +// Permanent hisokasGuard = game.getPermanent(this.getSourceId()); +// if (guardedCreature != null && hisokasGuard != null) { +// hisokasGuard.addConnectedCard(guardedCreature.getId()); +// } +// return true; +// } +// return false; +// } +// +// @Override +// public HisokasGuardActivatedAbility copy() { +// return new HisokasGuardActivatedAbility(this); +// } +// +//} + +class HisokasGuardGainAbilityTargetEffect extends ContinuousEffectImpl { + + protected Ability ability; + + public HisokasGuardGainAbilityTargetEffect() { + super(Duration.WhileOnBattlefield, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.AddAbility); + staticText = "Target creature you control other than Hisoka's Guard has shroud for as long as Hisoka's Guard remains tapped"; + this.ability = ShroudAbility.getInstance(); + } + + public HisokasGuardGainAbilityTargetEffect(final HisokasGuardGainAbilityTargetEffect effect) { + super(effect); + this.ability = effect.ability.copy(); + } + + @Override + public HisokasGuardGainAbilityTargetEffect copy() { + return new HisokasGuardGainAbilityTargetEffect(this); + } + + @Override + public void init(Ability source, Game game) { + // remember the guarded creature + Permanent guardedCreature = game.getPermanent(this.getTargetPointer().getFirst(source)); + Permanent hisokasGuard = game.getPermanent(source.getSourceId()); + if (guardedCreature != null && hisokasGuard != null) { + hisokasGuard.addConnectedCard(guardedCreature.getId()); + } + } + + @Override + public boolean apply(Game game, Ability source) { + Permanent hisokasGuard = game.getPermanent(source.getSourceId()); + if (hisokasGuard != null && hisokasGuard.getConnectedCards().size() > 0) { + Permanent guardedCreature = game.getPermanent(hisokasGuard.getConnectedCards().get(0)); + if (guardedCreature != null && hisokasGuard.isTapped()) { + guardedCreature.addAbility(ability); + return true; + } + else { + // if guard isn't tapped, the effect is no more valid + if (!hisokasGuard.isTapped()) + hisokasGuard.clearConnectedCards(); + } + } + return false; + } + +} + + + +class HisokasGuardRestrictionEffect extends RestrictionEffect { + + public HisokasGuardRestrictionEffect() { + super(Constants.Duration.WhileOnBattlefield); + staticText = "You may choose not to untap {this} during your untap step"; + } + + public HisokasGuardRestrictionEffect(final HisokasGuardRestrictionEffect effect) { + super(effect); + } + + @Override + public boolean applies(Permanent permanent, Ability source, Game game) { + return permanent.getId().equals(source.getSourceId()) && permanent.isTapped(); + } + + @Override + public boolean canBeUntapped(Permanent permanent, Game game) { + Player player = game.getPlayer(permanent.getControllerId()); + return player != null && player.chooseUse(Constants.Outcome.Benefit, "Untap " + permanent.getName() +"?", game); + } + + @Override + public HisokasGuardRestrictionEffect copy() { + return new HisokasGuardRestrictionEffect(this); + } + +} \ No newline at end of file diff --git a/Mage.Sets/src/mage/sets/innistrad/HamletCaptain.java b/Mage.Sets/src/mage/sets/innistrad/HamletCaptain.java index 40caa5eadd9..6ece35514e6 100644 --- a/Mage.Sets/src/mage/sets/innistrad/HamletCaptain.java +++ b/Mage.Sets/src/mage/sets/innistrad/HamletCaptain.java @@ -60,7 +60,7 @@ public class HamletCaptain extends CardImpl { this.toughness = new MageInt(2); // Whenever Hamlet Captain attacks or blocks, other Human creatures you control get +1/+1 until end of turn. - this.addAbility(new AttacksOrBlocksTriggeredAbility(new BoostControlledEffect(1, 1, Duration.EndOfTurn, filter), false)); + this.addAbility(new AttacksOrBlocksTriggeredAbility(new BoostControlledEffect(1, 1, Duration.EndOfTurn, filter, true), false)); } public HamletCaptain(final HamletCaptain card) { diff --git a/Mage.Sets/src/mage/sets/innistrad/RakishHeir.java b/Mage.Sets/src/mage/sets/innistrad/RakishHeir.java index 9787bdea2c4..ed789f197df 100644 --- a/Mage.Sets/src/mage/sets/innistrad/RakishHeir.java +++ b/Mage.Sets/src/mage/sets/innistrad/RakishHeir.java @@ -33,13 +33,13 @@ import mage.Constants.Rarity; import mage.Constants.Zone; import mage.MageInt; import mage.abilities.TriggeredAbilityImpl; -import mage.abilities.effects.Effect; import mage.abilities.effects.common.counter.AddCountersTargetEffect; import mage.cards.CardImpl; import mage.counters.CounterType; import mage.game.Game; import mage.game.events.DamagedPlayerEvent; import mage.game.events.GameEvent; +import mage.game.events.GameEvent.EventType; import mage.game.permanent.Permanent; import mage.target.targetpointer.FixedTarget; @@ -94,6 +94,7 @@ class RakishHeirTriggeredAbility extends TriggeredAbilityImpl { - private final static FilterPermanent filter = new FilterPermanent("creature"); + private final static FilterPermanent filter = new FilterPermanent("creatures "); static { filter.getCardType().add(CardType.CREATURE);