Added Keen Sense.

This commit is contained in:
LevelX2 2014-03-22 09:29:53 +01:00
parent 8bd9523360
commit 6993d7f725
3 changed files with 116 additions and 13 deletions

View file

@ -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<KeenSense> {
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);
}
}

View file

@ -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();
}
}

View file

@ -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<CardInfo, Object> cardDao;
private Set<String> classNames;
@ -107,7 +107,7 @@ public enum CardRepository {
QueryBuilder<CardInfo, Object> qb = cardDao.queryBuilder();
qb.distinct().selectColumns("className").where().isNotNull("className");
List<CardInfo> results = cardDao.query(qb.prepare());
classNames = new TreeSet<String>();
classNames = new TreeSet<>();
for (CardInfo card : results) {
classNames.add(card.getClassName());
}
@ -119,7 +119,7 @@ public enum CardRepository {
}
public Set<String> getNames() {
Set<String> names = new TreeSet<String>();
Set<String> names = new TreeSet<>();
try {
QueryBuilder<CardInfo, Object> qb = cardDao.queryBuilder();
qb.distinct().selectColumns("name");
@ -139,7 +139,7 @@ public enum CardRepository {
}
public Set<String> getNonLandNames() {
Set<String> names = new TreeSet<String>();
Set<String> names = new TreeSet<>();
try {
QueryBuilder<CardInfo, Object> qb = cardDao.queryBuilder();
qb.distinct().selectColumns("name");
@ -160,7 +160,7 @@ public enum CardRepository {
}
public Set<String> getNonLandAndNonCreatureNames() {
Set<String> names = new TreeSet<String>();
Set<String> names = new TreeSet<>();
try {
QueryBuilder<CardInfo, Object> qb = cardDao.queryBuilder();
qb.distinct().selectColumns("name");
@ -186,7 +186,7 @@ public enum CardRepository {
}
public Set<String> getCreatureTypes() {
TreeSet<String> subtypes = new TreeSet<String>();
TreeSet<String> subtypes = new TreeSet<>();
try {
QueryBuilder<CardInfo, Object> qb = cardDao.queryBuilder();
qb.distinct().selectColumns("subtypes");
@ -215,7 +215,7 @@ public enum CardRepository {
public List<String> getClassNames() {
List<String> names = new ArrayList<String>();
List<String> names = new ArrayList<>();
try {
List<CardInfo> 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<CardInfo>();
return new ArrayList<>();
}
/**
@ -258,7 +258,7 @@ public enum CardRepository {
return cardDao.query(queryBuilder.prepare());
} catch (SQLException ex) {
}
return new ArrayList<CardInfo>();
return new ArrayList<>();
}
public List<CardInfo> findCards(CardCriteria criteria) {
@ -269,6 +269,6 @@ public enum CardRepository {
return cardDao.query(queryBuilder.prepare());
} catch (SQLException ex) {
}
return new ArrayList<CardInfo>();
return new ArrayList<>();
}
}