Merge origin/master

This commit is contained in:
fireshoes 2015-08-11 08:39:31 -05:00
commit 538bb91222
5 changed files with 53 additions and 85 deletions

View file

@ -80,7 +80,7 @@ public class Necroskitter extends CardImpl {
class NecroskitterTriggeredAbility extends TriggeredAbilityImpl {
public NecroskitterTriggeredAbility() {
super(Zone.BATTLEFIELD, new ReturnToBattlefieldUnderYourControlTargetEffect());
super(Zone.BATTLEFIELD, new ReturnToBattlefieldUnderYourControlTargetEffect(), true);
}
public NecroskitterTriggeredAbility(NecroskitterTriggeredAbility ability) {
@ -100,18 +100,13 @@ class NecroskitterTriggeredAbility extends TriggeredAbilityImpl {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
if (game.getPermanent(sourceId) == null) {
if (game.getLastKnownInformation(sourceId, Zone.BATTLEFIELD) == null) {
return false;
}
}
if (zEvent.getFromZone() == Zone.BATTLEFIELD && zEvent.getToZone() == Zone.GRAVEYARD) {
Permanent permanent = (Permanent) game.getLastKnownInformation(event.getTargetId(), Zone.BATTLEFIELD);
Permanent permanent = zEvent.getTarget();
if (permanent != null
&& permanent.getCounters().containsKey(CounterType.M1M1)
&& game.getOpponents(controllerId).contains(permanent.getControllerId())) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getTargetId()));
effect.setTargetPointer(new FixedTarget(event.getTargetId(), game.getState().getZoneChangeCounter(event.getTargetId())));
}
return true;
}

View file

@ -1,16 +1,16 @@
/*
* 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
@ -20,16 +20,13 @@
* 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.decks.importer;
import java.util.List;
import java.util.Random;
import mage.cards.decks.DeckCardInfo;
import mage.cards.decks.DeckCardLists;
import mage.cards.repository.CardInfo;
@ -58,17 +55,15 @@ public class DecDeckImporter extends DeckImporter {
String lineName = line.substring(delim).trim();
try {
int num = Integer.parseInt(lineNum);
List<CardInfo> cards = CardRepository.instance.findCards(lineName);
if (cards.isEmpty()) {
CardInfo cardInfo = CardRepository.instance.findPreferedCoreExpansionCard(lineName);
if (cardInfo == null) {
sbMessage.append("Could not find card: '").append(lineName).append("' at line ").append(lineCount).append("\n");
} else {
Random random = new Random();
for (int i = 0; i < num; i++) {
CardInfo cardInfo = cards.get(random.nextInt(cards.size()));
if (!sideboard) {
deckList.getCards().add(new DeckCardInfo(cardInfo.getName(),cardInfo.getCardNumber(), cardInfo.getSetCode()));
deckList.getCards().add(new DeckCardInfo(cardInfo.getName(), cardInfo.getCardNumber(), cardInfo.getSetCode()));
} else {
deckList.getSideboard().add(new DeckCardInfo(cardInfo.getName(),cardInfo.getCardNumber(), cardInfo.getSetCode()));
deckList.getSideboard().add(new DeckCardInfo(cardInfo.getName(), cardInfo.getCardNumber(), cardInfo.getSetCode()));
}
}
}

View file

@ -1,16 +1,16 @@
/*
* 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
@ -20,7 +20,7 @@
* 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.
@ -63,27 +63,28 @@ public class MWSDeckImporter extends DeckImporter {
String lineName = line.substring(delim + 1).trim();
try {
int num = Integer.parseInt(lineNum);
List<CardInfo> cards = null;
CardInfo cardInfo = null;
if (!setCode.isEmpty()) {
CardCriteria criteria = new CardCriteria();
criteria.name(lineName);
criteria.setCodes(setCode);
List<CardInfo> cards = null;
cards = CardRepository.instance.findCards(criteria);
}
if (cards == null || cards.isEmpty()) {
cards = CardRepository.instance.findCards(lineName);
if (!cards.isEmpty()) {
cardInfo = cards.get(new Random().nextInt(cards.size()));
}
} else {
cardInfo = CardRepository.instance.findPreferedCoreExpansionCard(lineName);
}
if (cards.isEmpty()) {
if (cardInfo == null) {
sbMessage.append("Could not find card: '").append(lineName).append("' at line ").append(lineCount).append("\n");
} else {
Random random = new Random();
for (int i = 0; i < num; i++) {
CardInfo cardInfo = cards.get(random.nextInt(cards.size()));
if (!sideboard) {
deckList.getCards().add(new DeckCardInfo(cardInfo.getName(),cardInfo.getCardNumber(), cardInfo.getSetCode()));
deckList.getCards().add(new DeckCardInfo(cardInfo.getName(), cardInfo.getCardNumber(), cardInfo.getSetCode()));
} else {
deckList.getSideboard().add(new DeckCardInfo(cardInfo.getName(),cardInfo.getCardNumber(), cardInfo.getSetCode()));
deckList.getSideboard().add(new DeckCardInfo(cardInfo.getName(), cardInfo.getCardNumber(), cardInfo.getSetCode()));
}
}
}

View file

@ -28,18 +28,12 @@
package mage.cards.decks.importer;
import java.util.Arrays;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import mage.cards.decks.DeckCardInfo;
import mage.cards.decks.DeckCardLists;
import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository;
import mage.cards.repository.ExpansionInfo;
import mage.cards.repository.ExpansionRepository;
import mage.constants.SetType;
/**
*
@ -56,6 +50,10 @@ public class TxtDeckImporter extends DeckImporter {
@Override
protected void readLine(String line, DeckCardLists deckList) {
if (line.toLowerCase().contains("sideboard")) {
sideboard = true;
return;
}
if (line.startsWith("//")) {
return;
}
@ -69,11 +67,6 @@ public class TxtDeckImporter extends DeckImporter {
emptyLinesInARow = 0;
}
if (line.toLowerCase().startsWith("sideboard")) {
sideboard = true;
return;
}
line = line.replace("\t", " "); // changing tabs to blanks as delimiter
int delim = line.indexOf(' ');
if (delim < 0) {
@ -93,36 +86,15 @@ public class TxtDeckImporter extends DeckImporter {
}
try {
int num = Integer.parseInt(lineNum.replaceAll("\\D+", ""));
List<CardInfo> cards = CardRepository.instance.findCards(lineName);
if (cards.isEmpty()) {
CardInfo cardInfo = CardRepository.instance.findPreferedCoreExpansionCard(lineName);
if (cardInfo == null) {
sbMessage.append("Could not find card: '").append(lineName).append("' at line ").append(lineCount).append("\n");
} else {
// search the card released last with this name
Date lastReleaseDate = new GregorianCalendar(1900, 1, 1).getTime();
Date lastExpansionDate = new GregorianCalendar(1900, 1, 1).getTime();
CardInfo cardToUse = null;
for (CardInfo cardinfo : cards) {
ExpansionInfo set = ExpansionRepository.instance.getSetByCode(cardinfo.getSetCode());
if (set != null) {
if ((set.getType().equals(SetType.EXPANSION) || set.getType().equals(SetType.CORE))
&& (lastExpansionDate == null || set.getReleaseDate().after(lastExpansionDate))) {
cardToUse = cardinfo;
lastExpansionDate = set.getReleaseDate();
}
if (lastExpansionDate == null && (lastReleaseDate == null || set.getReleaseDate().after(lastReleaseDate))) {
cardToUse = cardinfo;
lastReleaseDate = set.getReleaseDate();
}
}
}
if (cardToUse == null) {
cardToUse = cards.get(0);
}
for (int i = 0; i < num; i++) {
if (!sideboard) {
deckList.getCards().add(new DeckCardInfo(cardToUse.getName(), cardToUse.getCardNumber(), cardToUse.getSetCode()));
deckList.getCards().add(new DeckCardInfo(cardInfo.getName(), cardInfo.getCardNumber(), cardInfo.getSetCode()));
} else {
deckList.getSideboard().add(new DeckCardInfo(cardToUse.getName(), cardToUse.getCardNumber(), cardToUse.getSetCode()));
deckList.getSideboard().add(new DeckCardInfo(cardInfo.getName(), cardInfo.getCardNumber(), cardInfo.getSetCode()));
}
}
}

View file

@ -39,13 +39,13 @@ import com.j256.ormlite.table.TableUtils;
import java.io.File;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.Callable;
import mage.cards.ExpansionSet;
import mage.cards.Sets;
import mage.constants.CardType;
import mage.constants.SetType;
import org.apache.log4j.Logger;
@ -303,18 +303,24 @@ public enum CardRepository {
public CardInfo findPreferedCoreExpansionCard(String name) {
List<CardInfo> cards = findCards(name);
if (!cards.isEmpty()) {
CardInfo cardInfo = cards.get(random.nextInt(cards.size()));
ExpansionSet set = Sets.getInstance().get(cardInfo.getSetCode());
if (set.getSetType().equals(SetType.EXPANSION) || set.getSetType().equals(SetType.CORE)) {
return cardInfo;
}
for (CardInfo cardInfoToCheck : cards) {
set = Sets.getInstance().get(cardInfoToCheck.getSetCode());
if (set.getSetType().equals(SetType.CORE) || set.getSetType().equals(SetType.EXPANSION)) {
return cardInfoToCheck;
Date lastReleaseDate = new GregorianCalendar(1900, 1, 1).getTime();
Date lastExpansionDate = new GregorianCalendar(1900, 1, 1).getTime();
CardInfo cardToUse = null;
for (CardInfo cardinfo : cards) {
ExpansionInfo set = ExpansionRepository.instance.getSetByCode(cardinfo.getSetCode());
if (set != null) {
if ((set.getType().equals(SetType.EXPANSION) || set.getType().equals(SetType.CORE))
&& (lastExpansionDate == null || set.getReleaseDate().after(lastExpansionDate))) {
cardToUse = cardinfo;
lastExpansionDate = set.getReleaseDate();
}
if (lastExpansionDate == null && (lastReleaseDate == null || set.getReleaseDate().after(lastReleaseDate))) {
cardToUse = cardinfo;
lastReleaseDate = set.getReleaseDate();
}
}
}
return cardInfo;
return cardToUse;
}
return null;
}
@ -323,7 +329,6 @@ public enum CardRepository {
try {
QueryBuilder<CardInfo, Object> queryBuilder = cardDao.queryBuilder();
queryBuilder.where().eq("name", new SelectArg(name));
return cardDao.query(queryBuilder.prepare());
} catch (SQLException ex) {
}