Merge pull request #23 from magefree/master

Merge https://github.com/magefree/mage
This commit is contained in:
Zzooouhh 2017-12-18 03:08:01 +01:00 committed by GitHub
commit a4ce4e4b17
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
75 changed files with 4096 additions and 256 deletions

View file

@ -0,0 +1,102 @@
/*
* 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.abilities.effects.common;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.cards.repository.ExpansionRepository;
import mage.choices.Choice;
import mage.choices.ChoiceImpl;
import mage.constants.Outcome;
import mage.constants.SubType;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.util.CardUtil;
/**
* @author LevelX2 (spjspj)
*/
public class ChooseExpansionSetEffect extends OneShotEffect {
public ChooseExpansionSetEffect(Outcome outcome) {
super(outcome);
staticText = "choose an expansion set";
}
public ChooseExpansionSetEffect(final ChooseExpansionSetEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject mageObject = game.getPermanentEntering(source.getSourceId());
if (mageObject == null) {
mageObject = game.getObject(source.getSourceId());
}
if (controller != null) {
Choice setChoice = new ChoiceImpl(true);
setChoice.setMessage("Choose expansion set");
List<String> setCodes = ExpansionRepository.instance.getSetCodes();
Set<String> sets = new HashSet<String>(setCodes);
setChoice.setChoices(sets);
while (!controller.choose(outcome, setChoice, game)) {
if (!controller.canRespond()) {
return false;
}
}
if (setChoice.getChoice() == null) {
return false;
}
if (!game.isSimulation()) {
game.informPlayers(controller.getLogName() + " has chosen set " + setChoice.getChoice());
}
game.getState().setValue(mageObject.getId() + "_set", setChoice.getChoice());
this.setValue("setchosen", setChoice.getChoice());
if (mageObject instanceof Permanent) {
((Permanent) mageObject).addInfo("chosen set", CardUtil.addToolTipMarkTags("Chosen set: " + setChoice.getChoice()), game);
}
}
return false;
}
@Override
public ChooseExpansionSetEffect copy() {
return new ChooseExpansionSetEffect(this);
}
}

View file

@ -0,0 +1,96 @@
/*
* 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.abilities.effects.common;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.Effect;
import mage.abilities.effects.Effects;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.game.Game;
import mage.players.Player;
/**
*
* @author spjspj
*/
public class RollDiceEffect extends OneShotEffect {
protected Effects executingEffects = new Effects();
protected int numSides;
public RollDiceEffect(Effect effect, int numSides) {
this(effect, Outcome.Neutral, numSides);
}
public RollDiceEffect(Effect effect, Outcome outcome, int numSides) {
super(outcome);
addEffect(effect);
this.numSides = numSides;
}
public RollDiceEffect(final RollDiceEffect effect) {
super(effect);
this.executingEffects = effect.executingEffects.copy();
this.numSides = effect.numSides;
}
public void addEffect(Effect effect) {
if (effect != null) {
executingEffects.add(effect);
}
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject mageObject = game.getObject(source.getSourceId());
if (controller != null && mageObject != null) {
controller.rollDice(game, numSides);
return true;
}
return false;
}
@Override
public String getText(Mode mode) {
if (!staticText.isEmpty()) {
return staticText;
}
StringBuilder sb = new StringBuilder("Roll a " + numSides + " sided dice");
return sb.toString();
}
@Override
public RollDiceEffect copy() {
return new RollDiceEffect(this);
}
}

View file

@ -0,0 +1,66 @@
/*
* 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.abilities.keyword;
import mage.constants.Zone;
import mage.abilities.MageSingleton;
import mage.abilities.StaticAbility;
import java.io.ObjectStreamException;
/**
*
* @author BetaSteward_at_googlemail.com (spjspj)
*/
public class SquirrellinkAbility extends StaticAbility implements MageSingleton {
private static final SquirrellinkAbility instance = new SquirrellinkAbility();
private Object readResolve() throws ObjectStreamException {
return instance;
}
public static SquirrellinkAbility getInstance() {
return instance;
}
private SquirrellinkAbility() {
super(Zone.ALL, null);
}
@Override
public String getRule() {
return "Squirrellink <i>(Damage dealt by this creature also causes you to create that many 1/1/ green Squirrel creature tokens.)</i>";
}
@Override
public SquirrellinkAbility copy() {
return instance;
}
}

View file

@ -594,6 +594,9 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
} else if (game.getPhase() == null) {
// E.g. Commander of commander game
removed = true;
} else {
// Unstable - Summon the Pack
removed = true;
}
break;
case BATTLEFIELD: // for sacrificing permanents or putting to library

View file

@ -32,6 +32,7 @@ import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository;
import mage.constants.Rarity;
import mage.constants.SetType;
import mage.util.CardUtil;
import mage.util.RandomUtil;
import java.io.Serializable;
@ -82,6 +83,10 @@ public abstract class ExpansionSet implements Serializable {
return this.cardNumber;
}
public int getCardNumberAsInt(){
return CardUtil.parseCardNumberAsInt(this.cardNumber);
}
public Rarity getRarity() {
return this.rarity;
}
@ -390,7 +395,7 @@ public abstract class ExpansionSet implements Serializable {
savedCardsInfos = CardRepository.instance.findCards(criteria);
// Workaround after card number is numeric
if (maxCardNumberInBooster != Integer.MAX_VALUE) {
savedCardsInfos.removeIf(next -> Integer.valueOf(next.getCardNumber()) > maxCardNumberInBooster && rarity != Rarity.LAND);
savedCardsInfos.removeIf(next -> next.getCardNumberAsInt() > maxCardNumberInBooster && rarity != Rarity.LAND);
}
savedCards.put(rarity, savedCardsInfos);
@ -431,4 +436,6 @@ public abstract class ExpansionSet implements Serializable {
savedCards.clear();
}
public int getMaxCardNumberInBooster() { return maxCardNumberInBooster; }
}

View file

@ -45,7 +45,14 @@ public abstract class DeckImporter {
protected StringBuilder sbMessage = new StringBuilder(); //TODO we should stop using this not garbage collectable StringBuilder. It just bloats
protected int lineCount;
public DeckCardLists importDeck(String file) {
/**
*
* @param file file to import
* @param errorMessages you can setup output messages to showup to user (set null for fatal exception on messages.count > 0)
* @return decks list
*/
public DeckCardLists importDeck(String file, StringBuilder errorMessages) {
File f = new File(file);
DeckCardLists deckList = new DeckCardLists();
if (!f.exists()) {
@ -62,8 +69,15 @@ public abstract class DeckImporter {
lineCount++;
readLine(line, deckList);
}
if (sbMessage.length() > 0) {
logger.fatal(sbMessage);
if(errorMessages != null) {
// normal output for user
errorMessages.append(sbMessage);
}else{
// fatal error
logger.fatal(sbMessage);
}
}
} catch (Exception ex) {
logger.fatal(null, ex);
@ -74,6 +88,10 @@ public abstract class DeckImporter {
return deckList;
}
public DeckCardLists importDeck(String file) {
return importDeck(file, null);
}
public String getErrors(){
return sbMessage.toString();
}

View file

@ -29,19 +29,48 @@ package mage.cards.decks.importer;
import mage.cards.decks.DeckCardLists;
import java.io.File;
import java.util.Scanner;
/**
*
* @author North
*/
public final class DeckImporterUtil {
public static final String[] SIDEBOARD_MARKS = new String[]{"//sideboard", "sb: "};
public static boolean haveSideboardSection(String file){
// search for sideboard section:
// or //sideboard
// or SB: 1 card name -- special deckstats.net
File f = new File(file);
try (Scanner scanner = new Scanner(f)) {
while (scanner.hasNextLine()) {
String line = scanner.nextLine().trim().toLowerCase();
for(String mark: SIDEBOARD_MARKS){
if (line.startsWith(mark)){
return true;
}
}
}
} catch (Exception e) {
// ignore error, deckimporter will process it
}
// not found
return false;
}
public static DeckImporter getDeckImporter(String file) {
if (file.toLowerCase().endsWith("dec")) {
return new DecDeckImporter();
} else if (file.toLowerCase().endsWith("mwdeck")) {
return new MWSDeckImporter();
} else if (file.toLowerCase().endsWith("txt")) {
return new TxtDeckImporter();
return new TxtDeckImporter(haveSideboardSection(file));
} else if (file.toLowerCase().endsWith("dck")) {
return new DckDeckImporter();
} else if (file.toLowerCase().endsWith("dek")) {
@ -51,12 +80,16 @@ public final class DeckImporterUtil {
}
}
public static DeckCardLists importDeck(String file) {
public static DeckCardLists importDeck(String file, StringBuilder errorMessages) {
DeckImporter deckImporter = getDeckImporter(file);
if (deckImporter != null) {
return deckImporter.importDeck(file);
return deckImporter.importDeck(file, errorMessages);
} else {
return new DeckCardLists();
}
}
public static DeckCardLists importDeck(String file) {
return importDeck(file, null);
}
}

View file

@ -47,25 +47,60 @@ public class TxtDeckImporter extends DeckImporter {
public static final Set<String> IGNORE_NAMES = new HashSet<>(Arrays.asList(SET_VALUES));
private boolean sideboard = false;
private boolean switchSideboardByEmptyLine = true; // all cards after first empty line will be sideboard (like mtgo format)
private int nonEmptyLinesTotal = 0;
public TxtDeckImporter(boolean haveSideboardSection){
if(haveSideboardSection){
switchSideboardByEmptyLine = false;
}
}
@Override
protected void readLine(String line, DeckCardLists deckList) {
if (line.toLowerCase().contains("sideboard")) {
sideboard = true;
return;
}
if (line.startsWith("//")) {
line = line.trim();
// process comment:
// skip or force to sideboard
String commentString = line.toLowerCase();
if (commentString.startsWith("//")){
// use start, not contains (card names may contain commands like "Legerdemain")
if (commentString.startsWith("//sideboard")) {
sideboard = true;
}
// skip comment line
return;
}
// Start the sideboard on empty line that follows
// at least 1 non-empty line
if (line.isEmpty() && nonEmptyLinesTotal > 0) {
sideboard = true;
// remove inner card comments from text line: 2 Blinding Fog #some text (like deckstats format)
int commentDelim = line.indexOf('#');
if(commentDelim >= 0){
line = line.substring(0, commentDelim).trim();
}
// switch sideboard by empty line
if (switchSideboardByEmptyLine && line.isEmpty() && nonEmptyLinesTotal > 0) {
if(!sideboard){
sideboard = true;
}else{
sbMessage.append("Found empty line at ").append(lineCount).append(", but sideboard already used. Use //sideboard switcher OR one empty line to devide your cards.").append('\n');
}
// skip empty line
return;
} else {
nonEmptyLinesTotal++;
}
nonEmptyLinesTotal++;
// single line sideboard card from deckstats.net
// SB: 3 Carnage Tyrant
boolean singleLineSideBoard = false;
if (line.startsWith("SB:")){
line = line.replace("SB:", "").trim();
singleLineSideBoard = true;
}
line = line.replace("\t", " "); // changing tabs to blanks as delimiter
@ -87,12 +122,17 @@ public class TxtDeckImporter extends DeckImporter {
}
try {
int num = Integer.parseInt(lineNum.replaceAll("\\D+", ""));
if ((num < 0) || (num > 100)){
sbMessage.append("Invalid number (too small or too big): ").append(lineNum).append(" at line ").append(lineCount).append('\n');
return;
}
CardInfo cardInfo = CardRepository.instance.findPreferedCoreExpansionCard(lineName, true);
if (cardInfo == null) {
sbMessage.append("Could not find card: '").append(lineName).append("' at line ").append(lineCount).append('\n');
} else {
for (int i = 0; i < num; i++) {
if (!sideboard) {
if (!sideboard && !singleLineSideBoard) {
deckList.getCards().add(new DeckCardInfo(cardInfo.getName(), cardInfo.getCardNumber(), cardInfo.getSetCode()));
} else {
deckList.getSideboard().add(new DeckCardInfo(cardInfo.getName(), cardInfo.getCardNumber(), cardInfo.getSetCode()));
@ -103,5 +143,4 @@ public class TxtDeckImporter extends DeckImporter {
sbMessage.append("Invalid number: ").append(lineNum).append(" at line ").append(lineCount).append('\n');
}
}
}

View file

@ -40,6 +40,7 @@ import mage.cards.*;
import mage.cards.mock.MockCard;
import mage.cards.mock.MockSplitCard;
import mage.constants.*;
import mage.util.CardUtil;
import mage.util.SubTypeList;
import org.apache.log4j.Logger;
@ -374,6 +375,10 @@ public class CardInfo {
return cardNumber;
}
public int getCardNumberAsInt() {
return CardUtil.parseCardNumberAsInt(cardNumber);
}
public boolean isSplitCard() {
return splitCard;
}

View file

@ -58,7 +58,7 @@ public enum CardRepository {
// raise this if db structure was changed
private static final long CARD_DB_VERSION = 51;
// raise this if new cards were added to the server
private static final long CARD_CONTENT_VERSION = 95;
private static final long CARD_CONTENT_VERSION = 96;
private Dao<CardInfo, Object> cardDao;
private Set<String> classNames;

View file

@ -72,6 +72,7 @@ public enum SubType {
BITH("Bith", SubTypeSet.CreatureType, true), // Star Wars
BLINKMOTH("Blinkmoth", SubTypeSet.CreatureType),
BOAR("Boar", SubTypeSet.CreatureType),
BRAINIAC("Brainiac", SubTypeSet.CreatureType, true), // Unstable
BRINGER("Bringer", SubTypeSet.CreatureType),
BRUSHWAGG("Brushwagg", SubTypeSet.CreatureType),
// C
@ -177,7 +178,8 @@ public enum SubType {
KALEESH("Kaleesh", SubTypeSet.CreatureType, true), // Star Wars
KAVU("Kavu", SubTypeSet.CreatureType),
KELDOR("KelDor", SubTypeSet.CreatureType, true),
KIRIN("Kirin", SubTypeSet.CreatureType),
KILLBOT("Killbot", SubTypeSet.CreatureType, true), // Unstable
KIRIN("Kirin", SubTypeSet.CreatureType),
KITHKIN("Kithkin", SubTypeSet.CreatureType),
KNIGHT("Knight", SubTypeSet.CreatureType),
KOBOLD("Kobold", SubTypeSet.CreatureType),
@ -268,6 +270,7 @@ public enum SubType {
SAPROLING("Saproling", SubTypeSet.CreatureType),
SATYR("Satyr", SubTypeSet.CreatureType),
SCARECROW("Scarecrow", SubTypeSet.CreatureType),
SCIENTIST("Scientist", SubTypeSet.CreatureType, true), // Unstable
SCION("Scion", SubTypeSet.CreatureType),
SCORPION("Scorpion", SubTypeSet.CreatureType),
SCOUT("Scout", SubTypeSet.CreatureType),

View file

@ -578,6 +578,9 @@ public class Combat implements Serializable, Copyable<Combat> {
* @param game
*/
private void retrieveMustBlockAttackerRequirements(Player attackingPlayer, Game game) {
if (attackingPlayer == null) {
return;
}
if (!game.getContinuousEffects().existRequirementEffects()) {
return;
}

View file

@ -229,6 +229,7 @@ public class GameEvent implements Serializable {
ENCHANT_PLAYER, ENCHANTED_PLAYER,
CAN_TAKE_MULLIGAN,
FLIP_COIN, COIN_FLIPPED, SCRY, FATESEAL,
ROLL_DICE, DICE_ROLLED,
PAID_CUMULATIVE_UPKEEP,
DIDNT_PAY_CUMULATIVE_UPKEEP,
//permanent events

View file

@ -52,6 +52,7 @@ import mage.game.combat.CombatGroup;
import mage.game.command.CommandObject;
import mage.game.events.*;
import mage.game.events.GameEvent.EventType;
import mage.game.permanent.token.SquirrelToken;
import mage.game.stack.Spell;
import mage.game.stack.StackObject;
import mage.players.Player;
@ -802,6 +803,11 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
if (dealtDamageByThisTurn == null) {
dealtDamageByThisTurn = new HashSet<>();
}
// Unstable ability - Earl of Squirrel
if (sourceAbilities.containsKey(SquirrellinkAbility.getInstance().getId())) {
Player player = game.getPlayer(sourceControllerId);
new SquirrelToken().putOntoBattlefield(damageDone, game, sourceId, player.getId());
}
dealtDamageByThisTurn.add(new MageObjectReference(source, game));
}
if (source == null) {

View file

@ -0,0 +1,50 @@
/*
* 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.game.permanent.token;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.MageInt;
import mage.abilities.keyword.FlyingAbility;
/**
*
* @author spjspj
*/
public class StormCrowToken extends Token {
public StormCrowToken() {
super("Storm Crow", "1/2 blue Bird creature token with flying named Storm Crow");
cardType.add(CardType.CREATURE);
color.setBlue(true);
subtype.add(SubType.BIRD);
power = new MageInt(1);
toughness = new MageInt(2);
this.addAbility(FlyingAbility.getInstance());
}
}

View file

@ -417,6 +417,10 @@ public interface Player extends MageItem, Copyable<Player> {
boolean flipCoin(Game game, ArrayList<UUID> appliedEffects);
int rollDice(Game game, int numSides);
int rollDice(Game game, ArrayList<UUID> appliedEffects, int numSides);
@Deprecated
void discard(int amount, Ability source, Game game);

View file

@ -80,6 +80,7 @@ import mage.game.events.ZoneChangeEvent;
import mage.game.match.MatchPlayer;
import mage.game.permanent.Permanent;
import mage.game.permanent.PermanentCard;
import mage.game.permanent.token.SquirrelToken;
import mage.game.stack.Spell;
import mage.game.stack.StackAbility;
import mage.game.stack.StackObject;
@ -1841,6 +1842,11 @@ public abstract class PlayerImpl implements Player, Serializable {
Player player = game.getPlayer(sourceControllerId);
player.gainLife(actualDamage, game);
}
// Unstable ability - Earl of Squirrel
if (sourceAbilities.containsKey(SquirrellinkAbility.getInstance().getId())) {
Player player = game.getPlayer(sourceControllerId);
new SquirrelToken().putOntoBattlefield(actualDamage, game, sourceId, player.getId());
}
game.fireEvent(new DamagedPlayerEvent(playerId, sourceId, playerId, actualDamage, combatDamage));
return actualDamage;
}
@ -2332,6 +2338,34 @@ public abstract class PlayerImpl implements Player, Serializable {
return event.getFlag();
}
@Override
public int rollDice(Game game, int numSides) {
return this.rollDice(game, null, numSides);
}
/**
* @param game
* @param appliedEffects
* @return the number that the player rolled
*/
@Override
public int rollDice(Game game, ArrayList<UUID> appliedEffects, int numSides) {
int result = RandomUtil.nextInt(numSides) + 1;
if (!game.isSimulation()) {
game.informPlayers("[Roll a die] " + getLogName() + " rolled a " + result + " on a " + numSides + " sided dice");
}
GameEvent event = new GameEvent(GameEvent.EventType.ROLL_DICE, playerId, null, playerId, result, true);
event.setAppliedEffects(appliedEffects);
event.setAmount(result);
event.setData(numSides + "");
if (!game.replaceEvent(event)) {
GameEvent ge = new GameEvent(GameEvent.EventType.DICE_ROLLED, playerId, null, playerId, event.getAmount(), event.getFlag());
ge.setData(numSides + "");
game.fireEvent(ge);
}
return event.getAmount();
}
@Override
public List<Permanent> getAvailableAttackers(Game game) {
// TODO: get available opponents and their planeswalkers, check for each if permanent can attack one

View file

@ -382,6 +382,25 @@ public final class CardUtil {
return true;
}
/**
* Parse card number as int (support base [123] and alternative numbers [123b]).
*
* @param cardNumber origin card number
* @return int
*/
public static int parseCardNumberAsInt(String cardNumber){
if (cardNumber.isEmpty()){ throw new IllegalArgumentException("Card number is empty.");}
if(Character.isDigit(cardNumber.charAt(cardNumber.length() - 1)))
{
return Integer.parseInt(cardNumber);
}else{
return Integer.parseInt(cardNumber.substring(0, cardNumber.length() - 1));
}
}
/**
* Creates and saves a (card + zoneChangeCounter) specific exileId.
*