diff --git a/Mage.Sets/src/mage/sets/planarchaos/KeenSense.java b/Mage.Sets/src/mage/sets/planarchaos/KeenSense.java new file mode 100644 index 00000000000..4dbf7f1e67c --- /dev/null +++ b/Mage.Sets/src/mage/sets/planarchaos/KeenSense.java @@ -0,0 +1,76 @@ +/* + * 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.planarchaos; + +import java.util.UUID; +import mage.abilities.Ability; +import mage.abilities.common.DealsDamageToAPlayerAttachedTriggeredAbility; +import mage.abilities.effects.common.AttachEffect; +import mage.abilities.effects.common.DrawCardControllerEffect; +import mage.abilities.keyword.EnchantAbility; +import mage.cards.CardImpl; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.constants.Rarity; +import mage.constants.TargetController; +import mage.target.TargetPermanent; +import mage.target.common.TargetCreaturePermanent; + +/** + * + * @author LevelX2 + */ +public class KeenSense extends CardImpl { + + public KeenSense(UUID ownerId) { + super(ownerId, 152, "Keen Sense", Rarity.UNCOMMON, new CardType[]{CardType.ENCHANTMENT}, "{G}"); + this.expansionSetCode = "PLC"; + this.subtype.add("Aura"); + + this.color.setGreen(true); + + // Enchant creature + TargetPermanent auraTarget = new TargetCreaturePermanent(); + this.getSpellAbility().addTarget(auraTarget); + this.getSpellAbility().addEffect(new AttachEffect(Outcome.DrawCard)); + Ability ability = new EnchantAbility(auraTarget.getTargetName()); + this.addAbility(ability); + + // Whenever enchanted creature deals damage to an opponent, you may draw a card. + this.addAbility(new DealsDamageToAPlayerAttachedTriggeredAbility(new DrawCardControllerEffect(1), "enchanted creature", true, false, false, TargetController.OPPONENT)); + } + + public KeenSense(final KeenSense card) { + super(card); + } + + @Override + public KeenSense copy() { + return new KeenSense(this); + } +} diff --git a/Mage/src/mage/abilities/common/DealsDamageToAPlayerAttachedTriggeredAbility.java b/Mage/src/mage/abilities/common/DealsDamageToAPlayerAttachedTriggeredAbility.java index 3a682c492eb..bdd283def17 100644 --- a/Mage/src/mage/abilities/common/DealsDamageToAPlayerAttachedTriggeredAbility.java +++ b/Mage/src/mage/abilities/common/DealsDamageToAPlayerAttachedTriggeredAbility.java @@ -2,11 +2,13 @@ package mage.abilities.common; import mage.abilities.TriggeredAbilityImpl; import mage.abilities.effects.Effect; +import mage.constants.TargetController; import mage.constants.Zone; import mage.game.Game; import mage.game.events.DamagedPlayerEvent; import mage.game.events.GameEvent; import mage.game.permanent.Permanent; +import mage.players.Player; import mage.target.targetpointer.FixedTarget; /** @@ -16,6 +18,7 @@ public class DealsDamageToAPlayerAttachedTriggeredAbility extends TriggeredAbili private boolean setFixedTargetPointer; private String attachedDescription; private boolean onlyCombat; + private TargetController targetController; public DealsDamageToAPlayerAttachedTriggeredAbility(Effect effect, String attachedDescription, boolean optional) { this(effect, attachedDescription, optional, false); @@ -26,9 +29,15 @@ public class DealsDamageToAPlayerAttachedTriggeredAbility extends TriggeredAbili } public DealsDamageToAPlayerAttachedTriggeredAbility(Effect effect, String attachedDescription, boolean optional, boolean setFixedTargetPointer, boolean onlyCombat) { + this(effect, attachedDescription, optional, setFixedTargetPointer, onlyCombat, TargetController.ANY); + } + + public DealsDamageToAPlayerAttachedTriggeredAbility(Effect effect, String attachedDescription, boolean optional, boolean setFixedTargetPointer, boolean onlyCombat, TargetController targetController) { super(Zone.BATTLEFIELD, effect, optional); this.setFixedTargetPointer = setFixedTargetPointer; this.attachedDescription = attachedDescription; + this.targetController = targetController; + this.onlyCombat = onlyCombat; } public DealsDamageToAPlayerAttachedTriggeredAbility(final DealsDamageToAPlayerAttachedTriggeredAbility ability) { @@ -36,6 +45,7 @@ public class DealsDamageToAPlayerAttachedTriggeredAbility extends TriggeredAbili this.setFixedTargetPointer = ability.setFixedTargetPointer; this.attachedDescription = ability.attachedDescription; this.onlyCombat = ability.onlyCombat; + this.targetController = ability.targetController; } @Override @@ -46,6 +56,12 @@ public class DealsDamageToAPlayerAttachedTriggeredAbility extends TriggeredAbili @Override public boolean checkTrigger(GameEvent event, Game game) { if (event instanceof DamagedPlayerEvent) { + if (targetController.equals(TargetController.OPPONENT)) { + Player controller = game.getPlayer(this.getControllerId()); + if (controller == null || !game.isOpponent(controller, event.getPlayerId())) { + return false; + } + } DamagedPlayerEvent damageEvent = (DamagedPlayerEvent) event; Permanent p = game.getPermanent(event.getSourceId()); if ((!onlyCombat || damageEvent.isCombatDamage()) @@ -65,10 +81,21 @@ public class DealsDamageToAPlayerAttachedTriggeredAbility extends TriggeredAbili public String getRule() { StringBuilder sb = new StringBuilder("Whenever ").append(attachedDescription); sb.append(" deals"); - if (!onlyCombat) { + if (onlyCombat) { sb.append(" combat"); } - sb.append(" damage to a player, ").append(super.getRule()); + sb.append(" damage to "); + switch(targetController) { + case OPPONENT: + sb.append("an opponent, "); + break; + case ANY: + sb.append("a player, "); + break; + default: + throw new UnsupportedOperationException(); + } + sb.append(super.getRule()); return sb.toString(); } } diff --git a/Mage/src/mage/cards/repository/CardRepository.java b/Mage/src/mage/cards/repository/CardRepository.java index 4980a0fa6d9..19cb775bd9f 100644 --- a/Mage/src/mage/cards/repository/CardRepository.java +++ b/Mage/src/mage/cards/repository/CardRepository.java @@ -55,9 +55,9 @@ public enum CardRepository { private static final String JDBC_URL = "jdbc:sqlite:db/cards.db"; private static final String VERSION_ENTITY_NAME = "card"; - private static final long CARD_DB_VERSION = 17; + private static final long CARD_DB_VERSION = 18; - private Random random = new Random(); + private final Random random = new Random(); private Dao cardDao; private Set classNames; @@ -107,7 +107,7 @@ public enum CardRepository { QueryBuilder qb = cardDao.queryBuilder(); qb.distinct().selectColumns("className").where().isNotNull("className"); List results = cardDao.query(qb.prepare()); - classNames = new TreeSet(); + classNames = new TreeSet<>(); for (CardInfo card : results) { classNames.add(card.getClassName()); } @@ -119,7 +119,7 @@ public enum CardRepository { } public Set getNames() { - Set names = new TreeSet(); + Set names = new TreeSet<>(); try { QueryBuilder qb = cardDao.queryBuilder(); qb.distinct().selectColumns("name"); @@ -139,7 +139,7 @@ public enum CardRepository { } public Set getNonLandNames() { - Set names = new TreeSet(); + Set names = new TreeSet<>(); try { QueryBuilder qb = cardDao.queryBuilder(); qb.distinct().selectColumns("name"); @@ -160,7 +160,7 @@ public enum CardRepository { } public Set getNonLandAndNonCreatureNames() { - Set names = new TreeSet(); + Set names = new TreeSet<>(); try { QueryBuilder qb = cardDao.queryBuilder(); qb.distinct().selectColumns("name"); @@ -186,7 +186,7 @@ public enum CardRepository { } public Set getCreatureTypes() { - TreeSet subtypes = new TreeSet(); + TreeSet subtypes = new TreeSet<>(); try { QueryBuilder qb = cardDao.queryBuilder(); qb.distinct().selectColumns("subtypes"); @@ -215,7 +215,7 @@ public enum CardRepository { public List getClassNames() { - List names = new ArrayList(); + List names = new ArrayList<>(); try { List results = cardDao.queryForAll(); for (CardInfo card : results) { @@ -234,7 +234,7 @@ public enum CardRepository { return cardDao.query(queryBuilder.prepare()); } catch (SQLException ex) { } - return new ArrayList(); + return new ArrayList<>(); } /** @@ -258,7 +258,7 @@ public enum CardRepository { return cardDao.query(queryBuilder.prepare()); } catch (SQLException ex) { } - return new ArrayList(); + return new ArrayList<>(); } public List findCards(CardCriteria criteria) { @@ -269,6 +269,6 @@ public enum CardRepository { return cardDao.query(queryBuilder.prepare()); } catch (SQLException ex) { } - return new ArrayList(); + return new ArrayList<>(); } }