commit a4ecfa58fa632ae0b1ee715ab474889c67a2f105 Author: BetaSteward Date: Sat Mar 20 02:47:42 2010 +0000 Initial diff --git a/Mage/build.xml b/Mage/build.xml new file mode 100644 index 00000000000..dcaf798cdda --- /dev/null +++ b/Mage/build.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + Builds, tests, and runs the project Mage. + + + diff --git a/Mage/manifest.mf b/Mage/manifest.mf new file mode 100644 index 00000000000..1574df4a2de --- /dev/null +++ b/Mage/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Mage/nbproject/build-impl.xml b/Mage/nbproject/build-impl.xml new file mode 100644 index 00000000000..e95037c845e --- /dev/null +++ b/Mage/nbproject/build-impl.xml @@ -0,0 +1,742 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set platform.home + Must set platform.bootcp + Must set platform.java + Must set platform.javac + + The J2SE Platform is not correctly set up. + Your active platform is: ${platform.active}, but the corresponding property "platforms.${platform.active}.home" is not found in the project's properties files. + Either open the project in the IDE and setup the Platform with the same name or add it manually. + For example like this: + ant -Duser.properties.file=<path_to_property_file> jar (where you put the property "platforms.${platform.active}.home" in a .properties file) + or ant -Dplatforms.${platform.active}.home=<path_to_JDK_home> jar (where no properties file is used) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + + + + + + ${platform.java} -cp "${run.classpath.with.dist.jar}" ${main.class} + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + ${platform.java} -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + diff --git a/Mage/nbproject/genfiles.properties b/Mage/nbproject/genfiles.properties new file mode 100644 index 00000000000..dc7f4fd157b --- /dev/null +++ b/Mage/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=a914693d +build.xml.script.CRC32=2b92e42a +build.xml.stylesheet.CRC32=958a1d3e@1.26.2.45 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=a914693d +nbproject/build-impl.xml.script.CRC32=d85ef4d8 +nbproject/build-impl.xml.stylesheet.CRC32=5c621a33@1.26.2.45 diff --git a/Mage/nbproject/project.properties b/Mage/nbproject/project.properties new file mode 100644 index 00000000000..29c001db34e --- /dev/null +++ b/Mage/nbproject/project.properties @@ -0,0 +1,65 @@ +application.title=Mage +application.vendor=BetaSteward_at_googlemail.com +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/Mage.jar +dist.javadoc.dir=${dist.dir}/javadoc +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.source=1.6 +javac.target=1.6 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit.classpath}:\ + ${libs.junit_4.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class= +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +platform.active=JDK_1.6 +project.license=bsd +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value +# or test-sys-prop.name=value to set system properties for unit tests): +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Mage/nbproject/project.xml b/Mage/nbproject/project.xml new file mode 100644 index 00000000000..0feb5ef256d --- /dev/null +++ b/Mage/nbproject/project.xml @@ -0,0 +1,17 @@ + + + org.netbeans.modules.java.j2seproject + + + Mage + + + + + + + + + + + diff --git a/Mage/src/mage/Constants.java b/Mage/src/mage/Constants.java new file mode 100644 index 00000000000..967cf56e7bf --- /dev/null +++ b/Mage/src/mage/Constants.java @@ -0,0 +1,271 @@ +/* +* 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; + +import java.util.ArrayList; +import java.util.List; + +public final class Constants { + + public enum ColoredManaSymbol { + W("W"), U("U"), B("B"), R("R"), G("G"); + + private String text; + + ColoredManaSymbol(String text) { + this.text = text; + } + + @Override + public String toString() { + return text; + } + + public static ColoredManaSymbol lookup(char c) { + switch (c) { + case 'W': + return W; + case 'R': + return R; + case 'G': + return G; + case 'B': + return B; + case 'U': + return U; + } + return null; + } + + } + + public enum DeckType { + CONSTRUCTED_STANDARD ("Constructed - Standard"), + CONSTRUCTED_EXTENDED ("Constructed - Extended"), + LIMITED ("Limited"); + + private String text; + + DeckType(String text) { + this.text = text; + } + + @Override + public String toString() { + return text; + } + + } + + public enum CardType { + ARTIFACT ("Artifact"), + CREATURE ("Creature"), + ENCHANTMENT ("Enchantment"), + INSTANT ("Instant"), + LAND ("Land"), + PLANESWALKER ("Planeswalker"), + SORCERY ("Sorcery"), + TRIBAL ("Tribal"); + + private String text; + + CardType(String text) { + this.text = text; + } + + @Override + public String toString() { + return text; + } + + } + + public enum Duration { + OneShot, + OneUse, + EndOfGame, + WhileInPlay, + EndOfTurn, + EndOfCombat, + Conditional + } + + public enum Layer { + CopyEffects_1, + ControlChangingEffects_2, + TextChangingEffects_3, + TypeChangingEffects_4, + ColorChangingEffects_5, + AbilityAddingRemovingEffects_6, + PTChangingEffects_7, + PlayerEffects, + RulesEffects + } + + public enum SubLayer { + CharacteristicDefining_7a, + SetPT_7b, + ModifyPT_7c, + Counters_7d, + SwitchPT_e, + NA + } + + public enum TableState { + WAITING ("Waiting for players"), + STARTING ("Waiting to start"), + DUELING ("Dueling"), + SIDEBOARDING ("Sideboarding"), + FINISHED ("Finished"); + + private String text; + + TableState(String text) { + this.text = text; + } + + @Override + public String toString() { + return text; + } + + } + + public enum TurnPhase { + BEGINNING ("Beginning"), + PRECOMBAT_MAIN ("Precombat Main"), + COMBAT ("Combat"), + POSTCOMBAT_MAIN ("Postcombat Main"), + END ("End"); + + private String text; + + TurnPhase(String text) { + this.text = text; + } + + @Override + public String toString() { + return text; + } + + } + + public enum PhaseStep { + UNTAP ("Untap"), + UPKEEP ("Upkeep"), + DRAW ("Draw"), + PRECOMBAT_MAIN ("Precombat Main"), + BEGIN_COMBAT ("Begin Combat"), + DECLARE_ATTACKERS ("Declare Attackers"), + DECLARE_BLOCKERS ("Declare Blockers"), + FIRST_COMBAT_DAMAGE ("First Combat Damage"), + COMBAT_DAMAGE ("Combat Damage"), + END_COMBAT ("End Combat"), + POSTCOMBAT_MAIN ("Postcombat Main"), + END_TURN ("End Turn"), + CLEANUP ("Cleanup"); + + private String text; + + PhaseStep(String text) { + this.text = text; + } + + @Override + public String toString() { + return text; + } + + } + + public enum Outcome { + Damage(false), + DestroyPermanent(false), + BoostCreature(true), + UnboostCreature(false), + AddAbility(true), + GainLife(true), + BecomeCreature(true), + PutCreatureInPlay(true), + PutCardInPlay(true), + PutLandInPlay(true), + GainControl(true), + DrawCard(true), + Discard(false), + Exile(false), + Protect(true), + PutManaInPool(true), + Regenerate(true), + PreventDamage(true), + Tap(false), + Untap(true), + Win(true), + Benefit(true), + Detriment(false), + Neutral(true); + + private boolean good; + + Outcome(boolean good) { + this.good = good; + } + + public boolean isGood() { + return good; + } + + } + + public enum Zone { + HAND, GRAVEYARD, LIBRARY, BATTLEFIELD, STACK, EXILED, ALL, OUTSIDE, CARD_PICKER, REVEALED, PLAYER, ATTACKERS, BLOCKERS; + + public boolean match(Zone zone) { + if (this == zone || this == ALL || zone == ALL) + return true; + return false; + } + } + + public enum TimingRule { + INSTANT, SORCERY + } + + public enum TargetController { + ANY, YOU, NOT_YOU, OPPONENT + } + + public static List PlaneswalkerTypes = new ArrayList() + {{add("Ajani"); add("Bolas"); add("Chandra"); add("Elspeth");add("Garruk"); add("Jace"); add("Liliana"); add("Nissa"); add("Sarkhan"); add("Sorin"); add("Tezzeret");}}; + + private Constants() { + throw new AssertionError(); + } + +} diff --git a/Mage/src/mage/MageInt.java b/Mage/src/mage/MageInt.java new file mode 100644 index 00000000000..99ab7c3728a --- /dev/null +++ b/Mage/src/mage/MageInt.java @@ -0,0 +1,68 @@ +/* +* 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; + +import java.io.Serializable; + +public class MageInt implements Serializable { + + public static MageInt EmptyMageInt = new MageInt(0, ""); + + protected int baseValue; + protected String cardValue = ""; + + public MageInt(int value) { + this.baseValue = value; + this.cardValue = Integer.toString(value); + } + + public MageInt(int baseValue, String cardValue) { + this.baseValue = baseValue; + this.cardValue = cardValue; + } + + public int getValue() { + return baseValue; + } + + public void setValue(int value) { + this.baseValue = value; + } + + public void boostValue(int amount) { + this.baseValue += amount; + if (this.baseValue < 0) + this.baseValue = 0; + } + + @Override + public String toString() { + return cardValue; + } +} diff --git a/Mage/src/mage/MageItem.java b/Mage/src/mage/MageItem.java new file mode 100644 index 00000000000..16790e2375b --- /dev/null +++ b/Mage/src/mage/MageItem.java @@ -0,0 +1,42 @@ +/* +* 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; + +import java.io.Serializable; +import java.util.UUID; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public interface MageItem extends Serializable { + + public UUID getId(); + +} diff --git a/Mage/src/mage/MageObject.java b/Mage/src/mage/MageObject.java new file mode 100644 index 00000000000..b3e8d9af6db --- /dev/null +++ b/Mage/src/mage/MageObject.java @@ -0,0 +1,29 @@ +package mage; + +import java.io.Serializable; +import java.util.List; +import mage.Constants.CardType; +import mage.Constants.Zone; +import mage.abilities.Abilities; +import mage.abilities.costs.mana.ManaCosts; + +public interface MageObject extends MageItem, Serializable { + + public String getName(); + + public List getCardType(); + public List getSubtype(); + public List getSupertype(); + + public Abilities getAbilities(); + public ObjectColor getColor(); + public ManaCosts getManaCost(); + + public MageInt getPower(); + public MageInt getToughness(); + public MageInt getLoyalty(); + + public Zone getZone(); + public void setZone(Zone zone); + +} diff --git a/Mage/src/mage/MageObjectImpl.java b/Mage/src/mage/MageObjectImpl.java new file mode 100644 index 00000000000..cc1f7a94108 --- /dev/null +++ b/Mage/src/mage/MageObjectImpl.java @@ -0,0 +1,131 @@ +/* +* 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; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +import mage.Constants.*; +import mage.abilities.Abilities; +import mage.abilities.AbilitiesImpl; +import mage.abilities.costs.mana.ManaCosts; + +public abstract class MageObjectImpl implements MageObject { + + protected UUID objectId; + + protected String name; + protected ManaCosts manaCost = new ManaCosts(""); + protected ObjectColor color = new ObjectColor(); + protected List cardType = new ArrayList(); + protected List subtype = new ArrayList(); + protected List supertype = new ArrayList(); + protected Abilities abilities = new AbilitiesImpl(); + protected String text; + protected MageInt power = new MageInt(0); + protected MageInt toughness = new MageInt(0); + protected MageInt loyalty = new MageInt(0); + protected Zone zone; + + public MageObjectImpl() { + objectId = UUID.randomUUID(); + } + + @Override + public UUID getId() { + return objectId; + } + + @Override + public String getName() { + return name; + } + + @Override + public List getCardType() { + return cardType; + } + + @Override + public List getSubtype(){ + return subtype; + } + + @Override + public List getSupertype(){ + return supertype; + } + + @Override + public Abilities getAbilities(){ + return abilities; + } + + @Override + public MageInt getPower() { +// if (power != null) + return power; +// return MageInt.EmptyMageInt; + } + + @Override + public MageInt getToughness() { +// if (toughness != null) + return toughness; +// return MageInt.EmptyMageInt; + } + + @Override + public MageInt getLoyalty() { +// if (loyalty != null) + return loyalty; +// return MageInt.EmptyMageInt; + } + + @Override + public ObjectColor getColor() { + return color; + } + + @Override + public ManaCosts getManaCost() { + return manaCost; + } + + @Override + public Zone getZone() { + return zone; + } + + @Override + public void setZone(Zone zone) { + this.zone = zone; + } +} diff --git a/Mage/src/mage/MageObjects.java b/Mage/src/mage/MageObjects.java new file mode 100644 index 00000000000..3c19ac72b79 --- /dev/null +++ b/Mage/src/mage/MageObjects.java @@ -0,0 +1,40 @@ +/* +* 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; + +import java.util.Map; +import java.util.UUID; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public interface MageObjects extends Map { + +} diff --git a/Mage/src/mage/MageObjectsImpl.java b/Mage/src/mage/MageObjectsImpl.java new file mode 100644 index 00000000000..bae0fedc49a --- /dev/null +++ b/Mage/src/mage/MageObjectsImpl.java @@ -0,0 +1,40 @@ +/* +* 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; + +import java.util.LinkedHashMap; +import java.util.UUID; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class MageObjectsImpl extends LinkedHashMap implements MageObjects { + +} diff --git a/Mage/src/mage/Mana.java b/Mage/src/mage/Mana.java new file mode 100644 index 00000000000..a6455d3de4c --- /dev/null +++ b/Mage/src/mage/Mana.java @@ -0,0 +1,356 @@ +/* +* 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; + +import java.io.Serializable; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class Mana implements Comparable, Serializable { + + private int red = 0; + private int green = 0; + private int blue = 0; + private int white = 0; + private int black = 0; + private int colorless = 0; + private int any = 0; + + public static Mana RedMana = RedMana(1); + public static Mana GreenMana = GreenMana(1); + public static Mana BlueMana = BlueMana(1); + public static Mana WhiteMana = WhiteMana(1); + public static Mana BlackMana = BlackMana(1); + public static Mana ColorlessMana = ColorlessMana(1); + + public Mana() {} + + public static Mana RedMana(int num) { + return new Mana(num, 0, 0, 0, 0, 0, 0); + } + + public static Mana GreenMana(int num) { + return new Mana(0, num, 0, 0, 0, 0, 0); + } + + public static Mana BlueMana(int num) { + return new Mana(0, 0, num, 0, 0, 0, 0); + } + + public static Mana WhiteMana(int num) { + return new Mana(0, 0, 0, num, 0, 0, 0); + } + + public static Mana BlackMana(int num) { + return new Mana(0, 0, 0, 0, num, 0, 0); + } + + public static Mana ColorlessMana(int num) { + return new Mana(0, 0, 0, 0, 0, num, 0); + } + + public Mana(int red, int green, int blue, int white, int black, int colorless, int any) { + this.red = red; + this.green = green; + this.blue = blue; + this.white = white; + this.black = black; + this.colorless = colorless; + this.any = any; + } + + public void add(Mana mana) { + red += mana.getRed(); + green += mana.getGreen(); + blue += mana.getBlue(); + white += mana.getWhite(); + black += mana.getBlack(); + colorless += mana.getColorless(); + any += mana.getAny(); + } + + public void addRed() { + red++; + } + + public void addGreen() { + green++; + } + + public void addBlue() { + blue++; + } + + public void addWhite() { + white++; + } + + public void addBlack() { + black++; + } + + public void addColorless() { + colorless++; + } + + public void subtract(Mana mana) { + red -= mana.getRed(); + green -= mana.getGreen(); + blue -= mana.getBlue(); + white -= mana.getWhite(); + black -= mana.getBlack(); + colorless -= mana.getColorless(); + any -= mana.getAny(); + } + + public int count() { + return red +green + blue + white + black + colorless + any; + } + + public void clear() { + red = 0; + green = 0; + blue = 0; + white = 0; + black = 0; + colorless = 0; + any = 0; + } + + @Override + public String toString() { + StringBuilder sbMana = new StringBuilder(); + + for (int i = 0; i < red; i++) + sbMana.append("{R}"); + for (int i = 0; i < green; i++) + sbMana.append("{G}"); + for (int i = 0; i < blue; i++) + sbMana.append("{U}"); + for (int i = 0; i < black; i++) + sbMana.append("{B}"); + for (int i = 0; i < white; i++) + sbMana.append("{W}"); + if (colorless > 0) { + sbMana.append("{"); + sbMana.append(Integer.toString(colorless)); + sbMana.append("}"); + } + return sbMana.toString(); + } + + public Mana copy() { + Mana copy = new Mana(); + copy.add(this); + return copy; + } + + public boolean enough(Mana avail) { + Mana compare = avail.copy(); + compare.subtract(this); + if (compare.getRed() < 0) { + compare.setAny(compare.getAny() + compare.getRed()); + if (compare.getAny() < 0) + return false; + compare.setRed(0); + } + if (compare.getGreen() < 0) { + compare.setAny(compare.getAny() + compare.getGreen()); + if (compare.getAny() < 0) + return false; + compare.setGreen(0); + } + if (compare.getBlue() < 0) { + compare.setAny(compare.getAny() + compare.getBlue()); + if (compare.getAny() < 0) + return false; + compare.setBlue(0); + } + if (compare.getBlack() < 0) { + compare.setAny(compare.getAny() + compare.getBlack()); + if (compare.getAny() < 0) + return false; + compare.setBlack(0); + } + if (compare.getWhite() < 0) { + compare.setAny(compare.getAny() + compare.getWhite()); + if (compare.getAny() < 0) + return false; + compare.setWhite(0); + } + if (compare.getColorless() < 0) { + int remaining = compare.getRed() + compare.getGreen() + compare.getBlack() + compare.getBlue() + compare.getWhite(); + if (compare.getColorless() + remaining < 0) + return false; + } + return true; + } + + public Mana needed(Mana avail) { + Mana compare = avail.copy(); + compare.subtract(this); + if (compare.getRed() < 0 && compare.getAny() > 0) { + int diff = Math.min( compare.getAny(), Math.abs(compare.getRed())); + compare.setAny(compare.getAny() - diff); + compare.setRed(compare.getRed() + diff); + } + if (compare.getGreen() < 0 && compare.getAny() > 0) { + int diff = Math.min( compare.getAny(), Math.abs(compare.getGreen())); + compare.setAny(compare.getAny() - diff); + compare.setGreen(compare.getGreen() + diff); + } + if (compare.getBlue() < 0 && compare.getAny() > 0) { + int diff = Math.min( compare.getAny(), Math.abs(compare.getBlue())); + compare.setAny(compare.getAny() - diff); + compare.setBlue(compare.getBlue() + diff); + } + if (compare.getBlack() < 0 && compare.getAny() > 0) { + int diff = Math.min( compare.getAny(), Math.abs(compare.getBlack())); + compare.setAny(compare.getAny() - diff); + compare.setBlack(compare.getBlack() + diff); + } + if (compare.getWhite() < 0 && compare.getAny() > 0) { + int diff = Math.min( compare.getAny(), Math.abs(compare.getWhite())); + compare.setAny(compare.getAny() - diff); + compare.setWhite(compare.getWhite() + diff); + } + if (compare.getColorless() < 0) { + int remaining = 0; + remaining += Math.min(0,compare.getRed()); + remaining += Math.min(0,compare.getWhite()); + remaining += Math.min(0,compare.getGreen()); + remaining += Math.min(0,compare.getBlack()); + remaining += Math.min(0,compare.getBlue()); + remaining += Math.min(0,compare.getAny()); + if (remaining > 0) { + int diff = Math.min(remaining, Math.abs(compare.getColorless())); + compare.setColorless(compare.getColorless() + diff); + } + } + Mana needed = new Mana(); + if (compare.getRed() < 0) + needed.setRed(Math.abs(compare.getRed())); + if (compare.getWhite() < 0) + needed.setWhite(Math.abs(compare.getWhite())); + if (compare.getGreen() < 0) + needed.setGreen(Math.abs(compare.getGreen())); + if (compare.getBlack() < 0) + needed.setBlack(Math.abs(compare.getBlack())); + if (compare.getBlue() < 0) + needed.setBlue(Math.abs(compare.getBlue())); + if (compare.getColorless() < 0) + needed.setColorless(Math.abs(compare.getColorless())); + return needed; + } + + public int getRed() { + return red; + } + + public void setRed(int red) { + this.red = red; + } + + public int getGreen() { + return green; + } + + public void setGreen(int green) { + this.green = green; + } + + public int getBlue() { + return blue; + } + + public void setBlue(int blue) { + this.blue = blue; + } + + public int getWhite() { + return white; + } + + public void setWhite(int white) { + this.white = white; + } + + public int getBlack() { + return black; + } + + public void setBlack(int black) { + this.black = black; + } + + public int getColorless() { + return colorless; + } + + public void setColorless(int colorless) { + this.colorless = colorless; + } + + public int getAny() { + return any; + } + + public void setAny(int any) { + this.any = any; + } + + public int compareTo(Mana o) { + return this.count() - o.count(); + } + + /** + * + * @param netMana + * @return true if this contains any values that mana has + */ + public boolean contains(Mana mana) { + if (mana.black > 0 && this.black > 0) + return true; + if (mana.blue > 0 && this.blue > 0) + return true; + if (mana.red > 0 && this.red > 0) + return true; + if (mana.white > 0 && this.white > 0) + return true; + if (mana.green > 0 && this.green > 0) + return true; + if (mana.colorless > 0 && this.count() > 0) + return true; + + return false; + } + +} diff --git a/Mage/src/mage/ObjectColor.java b/Mage/src/mage/ObjectColor.java new file mode 100644 index 00000000000..4f1965a28aa --- /dev/null +++ b/Mage/src/mage/ObjectColor.java @@ -0,0 +1,192 @@ +/* +* 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; + +import java.io.Serializable; + +public class ObjectColor implements Serializable { + + private static final long serialVersionUID = 1L; + + public static final ObjectColor WHITE = new ObjectColor("W"); + public static final ObjectColor BLUE = new ObjectColor("U"); + public static final ObjectColor BLACK = new ObjectColor("B"); + public static final ObjectColor RED = new ObjectColor("R"); + public static final ObjectColor GREEN = new ObjectColor("G"); + + private boolean white; + private boolean blue; + private boolean black; + private boolean red; + private boolean green; + + public ObjectColor() {} + + public ObjectColor(String color) { + for (int i = 0; i < color.length(); i++) { + switch (color.charAt(i)) { + case 'W': + white = true; + case 'U': + blue = true; + case 'B': + black = true; + case 'R': + red = true; + case 'G': + green = true; + } + } + } + + public void setColor(ObjectColor color) { + this.setBlack(color.isBlack()); + this.setBlue(color.isBlue()); + this.setGreen(color.isGreen()); + this.setRed(color.isRed()); + this.setWhite(color.isWhite()); + } + + public boolean isColorless() { + return !(hasColor()); + } + + public boolean hasColor() { + return white | blue | black | red | green; + } + + public boolean isMulticolored() { + if (isColorless()) + return false; + if (white && (blue | black | red | green)) + return true; + if (blue && (black | red | green)) + return true; + if (black && (red | green)) + return true; + if (red && green) + return true; + return false; + } + + public boolean isWhite() { + return white; + } + public void setWhite(boolean white) { + this.white = white; + } + public boolean isBlue() { + return blue; + } + public void setBlue(boolean blue) { + this.blue = blue; + } + public boolean isBlack() { + return black; + } + public void setBlack(boolean black) { + this.black = black; + } + public boolean isRed() { + return red; + } + public void setRed(boolean red) { + this.red = red; + } + public boolean isGreen() { + return green; + } + public void setGreen(boolean green) { + this.green = green; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + if (white) + sb.append("W"); + if (blue) + sb.append("U"); + if (black) + sb.append("B"); + if (red) + sb.append("R"); + if (green) + sb.append("G"); + return sb.toString(); + } + + @Override + public boolean equals(Object color) { + if (this == color) + return true; + if (!(color instanceof ObjectColor)) + return false; + ObjectColor test = (ObjectColor) color; + if (test.white != this.white) + return false; + if (test.blue != this.blue) + return false; + if (test.black != this.black) + return false; + if (test.red != this.red) + return false; + if (test.green != this.green) + return false; + return true; + } + + @Override + public int hashCode() { + int hash = 3; + hash = 23 * hash + (this.white ? 1 : 0); + hash = 23 * hash + (this.blue ? 1 : 0); + hash = 23 * hash + (this.black ? 1 : 0); + hash = 23 * hash + (this.red ? 1 : 0); + hash = 23 * hash + (this.green ? 1 : 0); + return hash; + } + + public boolean contains(ObjectColor color) { + if (this == color) + return true; + if (color.white & this.white) + return true; + if (color.blue & this.blue) + return true; + if (color.black & this.black) + return true; + if (color.red & this.red) + return true; + if (color.green & this.green) + return true; + return false; + } + +} diff --git a/Mage/src/mage/abilities/Abilities.java b/Mage/src/mage/abilities/Abilities.java new file mode 100644 index 00000000000..f85b5cce42f --- /dev/null +++ b/Mage/src/mage/abilities/Abilities.java @@ -0,0 +1,60 @@ +/* +* 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; + +import java.util.List; +import java.util.UUID; +import mage.Constants.Zone; +import mage.abilities.keyword.KickerAbility; +import mage.abilities.keyword.ProtectionAbility; +import mage.abilities.mana.ManaAbility; + +public interface Abilities extends List { + + public List getRules(); + public List getActivatedAbilities(Zone zone); + public List getManaAbilities(Zone zone); + public List getStaticAbilities(Zone zone); + public List getEvasionAbilities(); + public List getTriggeredAbilities(Zone zone); + public List getProtectionAbilities(); + public List getKickerAbilities(); + + public Abilities copy(); + + public void setControllerId(UUID controllerId); + public void setSourceId(UUID sourceId); + public boolean containsKey(UUID abilityId); + public Ability get(UUID abilityId); + + public boolean containsAll(Abilities abilities); + + + +} diff --git a/Mage/src/mage/abilities/AbilitiesImpl.java b/Mage/src/mage/abilities/AbilitiesImpl.java new file mode 100644 index 00000000000..ba2875ea539 --- /dev/null +++ b/Mage/src/mage/abilities/AbilitiesImpl.java @@ -0,0 +1,189 @@ +/* +* 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; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import mage.Constants.Zone; +import mage.abilities.keyword.KickerAbility; +import mage.abilities.keyword.ProtectionAbility; +import mage.abilities.mana.ManaAbility; +import mage.util.Copier; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class AbilitiesImpl extends ArrayList implements Abilities, Serializable { + + + @Override + public List getRules() { + List rules = new ArrayList(); + + for (Ability ability:this) { + if (!(ability instanceof SpellAbility || ability instanceof PlayLandAbility)) + rules.add(ability.getRule()); + } + + return rules; + } + + @Override + public List getActivatedAbilities(Zone zone) { + List zonedAbilities = new ArrayList(); + for (Ability ability: this) { + if (ability.isEnabled() && ability instanceof ActivatedAbility && ability.getZone().match(zone)) { + zonedAbilities.add((ActivatedAbility)ability); + } + } + return zonedAbilities; + } + + @Override + public Abilities copy() { + return new Copier().copy(this); + } + + @Override + public List getManaAbilities(Zone zone) { + List abilities = new ArrayList(); + for (Ability ability: this) { + if (ability.isEnabled() && ability instanceof ManaAbility && ability.getZone().match(zone)) { + abilities.add((ManaAbility)ability); + } + } + return abilities; + } + + @Override + public List getEvasionAbilities() { + List abilities = new ArrayList(); + for (Ability ability: this) { + if (ability.isEnabled() && ability instanceof EvasionAbility) { + abilities.add((EvasionAbility)ability); + } + } + return abilities; + } + + @Override + public List getStaticAbilities(Zone zone) { + List zonedAbilities = new ArrayList(); + for (Ability ability: this) { + if (ability.isEnabled() && ability instanceof StaticAbility && ability.getZone().match(zone)) { + zonedAbilities.add((StaticAbility)ability); + } + } + return zonedAbilities; + } + + @Override + public List getTriggeredAbilities(Zone zone) { + List zonedAbilities = new ArrayList(); + for (Ability ability: this) { + if (ability.isEnabled() && ability instanceof TriggeredAbility && ability.getZone().match(zone)) { + zonedAbilities.add((TriggeredAbility)ability); + } + } + return zonedAbilities; + } + + @Override + public List getProtectionAbilities() { + List abilities = new ArrayList(); + for (Ability ability: this) { + if (ability.isEnabled() && ability instanceof ProtectionAbility) { + abilities.add((ProtectionAbility)ability); + } + } + return abilities; + } + + @Override + public List getKickerAbilities() { + List abilities = new ArrayList(); + for (Ability ability: this) { + if (ability.isEnabled() && ability instanceof KickerAbility) { + abilities.add((KickerAbility)ability); + } + } + return abilities; + } + + @Override + public void setControllerId(UUID controllerId) { + for (Ability ability: this) { + ability.setControllerId(controllerId); + } + } + + @Override + public void setSourceId(UUID sourceId) { + for (Ability ability: this) { + ability.setSourceId(sourceId); + } + } + + public boolean containsAll(Abilities abilities) { + if (this.size() < abilities.size()) + return false; + for (Ability ability: abilities) { + boolean found = false; + for (Ability test: this) { + if (ability.getRule().equals(test.getRule())) { + found = true; + break; + } + if (!found) + return false; + } + } + return true; + } + + public boolean containsKey(UUID abilityId) { + for (Ability ability: this) { + if (ability.getId().equals(abilityId)) + return true; + } + return false; + } + + public Ability get(UUID abilityId) { + for (Ability ability: this) { + if (ability.getId().equals(abilityId)) + return ability; + } + return null; + } + +} diff --git a/Mage/src/mage/abilities/Ability.java b/Mage/src/mage/abilities/Ability.java new file mode 100644 index 00000000000..96cc4e297fe --- /dev/null +++ b/Mage/src/mage/abilities/Ability.java @@ -0,0 +1,72 @@ +/* +* 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; + +import java.io.Serializable; +import java.util.UUID; +import mage.Constants.Zone; +import mage.abilities.costs.Cost; +import mage.abilities.costs.Costs; +import mage.abilities.effects.Effect; +import mage.abilities.effects.Effects; +import mage.choices.Choice; +import mage.choices.Choices; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.target.Target; +import mage.target.Targets; + +public interface Ability extends Serializable { + + public UUID getId(); + public UUID getControllerId(); + public UUID getSourceId(); + public Costs getCosts(); + public void addCost(Cost cost); + public Effects getEffects(); + public void addEffect(Effect effect); + public Targets getTargets(); + public UUID getFirstTarget(); + public void addTarget(Target target); + public Choices getChoices(); + public void addChoice(Choice choice); + public Zone getZone(); + public String getRule(); + public String getName(); + public boolean isEnabled(); + public void setEnabled(boolean enabled); + public boolean activate(Game game, boolean noMana); + public boolean resolve(Game game); + public void handleEvent(GameEvent event, Game game); + + public void setControllerId(UUID controllerId); + public void setSourceId(UUID sourceID); + public Ability copy(); + +} diff --git a/Mage/src/mage/abilities/AbilityImpl.java b/Mage/src/mage/abilities/AbilityImpl.java new file mode 100644 index 00000000000..187fd4e5d2e --- /dev/null +++ b/Mage/src/mage/abilities/AbilityImpl.java @@ -0,0 +1,231 @@ +/* +* 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; + +import java.io.Serializable; +import java.util.UUID; +import mage.Constants.Zone; +import mage.abilities.costs.Cost; +import mage.abilities.costs.Costs; +import mage.abilities.costs.CostsImpl; +import mage.abilities.effects.ContinuousEffectImpl; +import mage.abilities.effects.Effect; +import mage.abilities.effects.Effects; +import mage.abilities.effects.OneShotEffect; +import mage.choices.Choice; +import mage.choices.Choices; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.target.Target; +import mage.target.Targets; +import mage.util.Copier; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public abstract class AbilityImpl implements Ability, Serializable { + + protected static Copier copier = new Copier(); + + protected UUID id; + protected UUID controllerId; + protected UUID sourceId; + protected Costs costs = new CostsImpl(this); + protected Targets targets = new Targets(this); + protected Choices choices = new Choices(this); + protected Effects effects = new Effects(this); + protected Zone zone; + protected String name; + protected boolean enabled = true; + + public AbilityImpl(Zone zone) { + this.id = UUID.randomUUID(); + this.zone = zone; + targets.setSource(this); + costs.setAbility(this); + choices.setSource(this); + effects.setSource(this); + } + + @Override + public UUID getId() { + return id; + } + + @Override + public boolean resolve(Game game) { + boolean result = true; + if (enabled) { + for (Effect effect: getEffects()) { + if (effect instanceof OneShotEffect) { + result &= effect.apply(game); + } + else { + game.addEffect((ContinuousEffectImpl) effect); + } + } + } + return result; + } + + @Override + public boolean activate(Game game, boolean noMana) { + if (choices.size() > 0 && choices.choose(game) == false) + return false; + if (targets.size() > 0 && targets.choose(effects.get(0).getOutcome(), game) == false) + return false; + return getCosts().pay(game, noMana); + } + + @Override + public UUID getControllerId() { + return controllerId; + } + + @Override + public void setControllerId(UUID controllerId) { + this.controllerId = controllerId; + } + + + @Override + public UUID getSourceId() { + return sourceId; + } + + @Override + public void setSourceId(UUID sourceId) { + this.sourceId = sourceId; + } + + @Override + public Costs getCosts() { + return costs; + } + + @Override + public Effects getEffects() { + return effects; + } + + @Override + public Choices getChoices() { + return choices; + } + + @Override + public Zone getZone() { + return zone; + } + + @Override + public String getRule() { + StringBuilder sbRule = new StringBuilder(); + + if (!(this instanceof SpellAbility)) { + if (!costs.getText().equals("")) { + sbRule.append(costs.getText()); + sbRule.append(": "); + } + } + sbRule.append(effects.getText()); + + return sbRule.toString(); + } + + @Override + public String getName() { + return name; + } + + @Override + public boolean isEnabled() { + return enabled; + } + + @Override + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + @Override + public void handleEvent(GameEvent event, Game game) { + + } + + @Override + public void addCost(Cost cost) { + if (cost != null) { + cost.setAbility(this); + this.costs.add(cost); + } + } + + @Override + public void addEffect(Effect effect) { + if (effect != null) { + effect.setSource(this); + this.effects.add(effect); + } + } + + @Override + public void addTarget(Target target) { + if (target != null) { + target.setAbility(this); + this.targets.add(target); + } + } + + @Override + public void addChoice(Choice choice) { + if (choice != null) { + choice.setAbility(this); + this.choices.add(choice); + } + } + + @Override + public Targets getTargets() { + return this.targets; + } + + @Override + public UUID getFirstTarget() { + if (this.targets.size() > 0) + return this.targets.get(0).getFirstTarget(); + return null; + } + + @Override + public Ability copy() { + return copier.copy(this); + } +} diff --git a/Mage/src/mage/abilities/ActivatedAbility.java b/Mage/src/mage/abilities/ActivatedAbility.java new file mode 100644 index 00000000000..c7eca462743 --- /dev/null +++ b/Mage/src/mage/abilities/ActivatedAbility.java @@ -0,0 +1,44 @@ +/* +* 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; + +import java.util.UUID; +import mage.game.Game; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public interface ActivatedAbility extends Ability { + + public boolean canActivate(UUID playerId, Game game); + public boolean isActivated(Game game); + public String getActivatedMessage(Game game); + +} diff --git a/Mage/src/mage/abilities/ActivatedAbilityImpl.java b/Mage/src/mage/abilities/ActivatedAbilityImpl.java new file mode 100644 index 00000000000..dac656a9827 --- /dev/null +++ b/Mage/src/mage/abilities/ActivatedAbilityImpl.java @@ -0,0 +1,130 @@ +/* +* 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; + +import java.util.UUID; +import mage.Constants.TimingRule; +import mage.Constants.Zone; +import mage.abilities.costs.Cost; +import mage.abilities.effects.Effect; +import mage.abilities.effects.Effects; +import mage.cards.Card; +import mage.game.Game; +import mage.target.Target; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public abstract class ActivatedAbilityImpl extends AbilityImpl implements ActivatedAbility { + + protected TimingRule timing = TimingRule.INSTANT; + protected UUID effectId; + + public ActivatedAbilityImpl(Zone zone, Cost cost) { + super(zone); + if (cost != null) + this.addCost(cost); + } + + public ActivatedAbilityImpl(Zone zone, Effect effect, Cost cost) { + super(zone); + if (effect != null) { + this.addEffect(effect); + effectId = effect.getId(); + } + if (cost != null) + this.addCost(cost); + } + + public ActivatedAbilityImpl(Zone zone, Effects effects, Cost cost) { + super(zone); + for (Effect effect: effects) { + if (effect != null) { + this.addEffect(effect); + } + } + if (cost != null) + this.addCost(cost); + } + + @Override + public boolean canActivate(UUID playerId, Game game) { + //20091005 - 602.2 + if (!controlsAbility(playerId, game)) + return false; + //20091005 - 602.5d/602.5e + if (timing == TimingRule.INSTANT || (game.isMainPhase() && + game.getStack().isEmpty() && + game.getActivePlayerId().equals(playerId)) && + costs.canPay(playerId, game) && + targets.canChoose(sourceId, game) + ) { + return true; + } + return false; + } + + @Override + public boolean isActivated(Game game) { + + if (effectId != null) + return game.getContinuousEffects().effectExists(this.id); + return false; + } + + protected boolean controlsAbility(UUID playerId, Game game) { + if (this.controllerId != null && this.controllerId.equals(playerId)) + return true; + else { + Card card = (Card)game.getObject(this.sourceId); + if (card != null) + return card.getOwnerId().equals(playerId); + } + return false; + } + + @Override + public String getActivatedMessage(Game game) { + return " activates ability from " + getMessageText(game); + } + + protected String getMessageText(Game game) { + StringBuilder sb = new StringBuilder(); + sb.append(game.getObject(this.sourceId).getName()); + if (this.targets.size() > 0) { + sb.append(" targeting "); + for (Target target: targets) { + sb.append(target.getTargetedName(game)); + } + } + return sb.toString(); + } + +} diff --git a/Mage/src/mage/abilities/EvasionAbility.java b/Mage/src/mage/abilities/EvasionAbility.java new file mode 100644 index 00000000000..f4c317b7f70 --- /dev/null +++ b/Mage/src/mage/abilities/EvasionAbility.java @@ -0,0 +1,43 @@ +/* +* 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; + +import java.util.UUID; +import mage.game.Game; +import mage.game.permanent.Permanent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public interface EvasionAbility { + + public boolean canBlock(Permanent permanent, Game game); + +} diff --git a/Mage/src/mage/abilities/EvasionAbilityImpl.java b/Mage/src/mage/abilities/EvasionAbilityImpl.java new file mode 100644 index 00000000000..399b43a7cfb --- /dev/null +++ b/Mage/src/mage/abilities/EvasionAbilityImpl.java @@ -0,0 +1,43 @@ +/* +* 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; + +import mage.Constants.Zone; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public abstract class EvasionAbilityImpl extends StaticAbility implements EvasionAbility { + + public EvasionAbilityImpl() { + super(Zone.BATTLEFIELD, null); + } + +} diff --git a/Mage/src/mage/abilities/LoyaltyAbility.java b/Mage/src/mage/abilities/LoyaltyAbility.java new file mode 100644 index 00000000000..f200eac0eb6 --- /dev/null +++ b/Mage/src/mage/abilities/LoyaltyAbility.java @@ -0,0 +1,53 @@ +/* +* 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; + +import mage.Constants.TimingRule; +import mage.Constants.Zone; +import mage.abilities.costs.common.PayLoyaltyCost; +import mage.abilities.effects.Effect; +import mage.abilities.effects.Effects; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class LoyaltyAbility extends ActivatedAbilityImpl { + + public LoyaltyAbility(Effect effect, int loyalty) { + super(Zone.BATTLEFIELD, effect, new PayLoyaltyCost(loyalty)); + this.timing = TimingRule.SORCERY; + } + + public LoyaltyAbility(Effects effects, int loyalty) { + super(Zone.BATTLEFIELD, effects, new PayLoyaltyCost(loyalty)); + this.timing = TimingRule.SORCERY; + } + +} diff --git a/Mage/src/mage/abilities/PlayLandAbility.java b/Mage/src/mage/abilities/PlayLandAbility.java new file mode 100644 index 00000000000..09c6a10ef05 --- /dev/null +++ b/Mage/src/mage/abilities/PlayLandAbility.java @@ -0,0 +1,61 @@ +/* +* 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; + +import java.util.UUID; +import mage.Constants.Zone; +import mage.game.Game; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class PlayLandAbility extends ActivatedAbilityImpl { + + public PlayLandAbility() { + super(Zone.HAND, null); + this.name = "Play"; + } + + @Override + public boolean canActivate(UUID playerId, Game game) { + if (!controlsAbility(playerId, game)) + return false; + //20091005 - 114.2a + if (game.getActivePlayerId().equals(playerId) && game.getStack().isEmpty() && game.isMainPhase()) { + return game.getPlayer(playerId).canPlayLand(); + } + return false; + } + + @Override + public String getActivatedMessage(Game game) { + return " plays " + getMessageText(game); + } +} diff --git a/Mage/src/mage/abilities/SpellAbility.java b/Mage/src/mage/abilities/SpellAbility.java new file mode 100644 index 00000000000..de385f7f248 --- /dev/null +++ b/Mage/src/mage/abilities/SpellAbility.java @@ -0,0 +1,65 @@ +/* +* 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; + +import java.util.UUID; +import mage.Constants.CardType; +import mage.Constants.Zone; +import mage.abilities.costs.Cost; +import mage.game.Game; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class SpellAbility extends ActivatedAbilityImpl { + + public SpellAbility(Cost cost) { + super(Zone.HAND, cost); + this.name = "Cast"; + } + + @Override + public boolean canActivate(UUID playerId, Game game) { + if (game.getObject(sourceId).getCardType().contains(CardType.INSTANT) || + (game.isMainPhase() && + game.getStack().isEmpty() && + game.getActivePlayerId().equals(playerId)) && + costs.canPay(playerId, game) && + targets.canChoose(sourceId, game)) + return true; + return false; + } + + @Override + public String getActivatedMessage(Game game) { + return " casts " + getMessageText(game); + } + +} diff --git a/Mage/src/mage/abilities/StaticAbility.java b/Mage/src/mage/abilities/StaticAbility.java new file mode 100644 index 00000000000..9cb7a859784 --- /dev/null +++ b/Mage/src/mage/abilities/StaticAbility.java @@ -0,0 +1,45 @@ +/* +* 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; + +import mage.Constants.Zone; +import mage.abilities.effects.Effect; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public abstract class StaticAbility extends AbilityImpl { + + public StaticAbility(Zone zone, Effect effect) { + super(zone); + if (effect != null) + this.addEffect(effect); + } +} diff --git a/Mage/src/mage/abilities/TriggeredAbilities.java b/Mage/src/mage/abilities/TriggeredAbilities.java new file mode 100644 index 00000000000..c5ca3e6030c --- /dev/null +++ b/Mage/src/mage/abilities/TriggeredAbilities.java @@ -0,0 +1,57 @@ +/* +* 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; + +import java.util.ArrayList; +import mage.game.Game; +import mage.game.events.GameEvent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class TriggeredAbilities extends ArrayList { + + public void handleEvent(GameEvent event, Game game) { + for(TriggeredAbility ability: this) { + ability.handleEvent(event, game); + } + } + + public boolean check(Game game) { + boolean played = false; + for (TriggeredAbility ability: this) { + played |= game.getPlayer(ability.getControllerId()).triggerAbility(ability, game); + } + clear(); + return played; + } + + +} diff --git a/Mage/src/mage/abilities/TriggeredAbility.java b/Mage/src/mage/abilities/TriggeredAbility.java new file mode 100644 index 00000000000..b9304febd28 --- /dev/null +++ b/Mage/src/mage/abilities/TriggeredAbility.java @@ -0,0 +1,42 @@ +/* +* 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; + +import java.util.UUID; +import mage.game.Game; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public interface TriggeredAbility extends Ability { + + public void trigger(Game game, UUID controllerId); + +} diff --git a/Mage/src/mage/abilities/TriggeredAbilityImpl.java b/Mage/src/mage/abilities/TriggeredAbilityImpl.java new file mode 100644 index 00000000000..7f34a8907d2 --- /dev/null +++ b/Mage/src/mage/abilities/TriggeredAbilityImpl.java @@ -0,0 +1,75 @@ +/* +* 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; + +import java.util.UUID; +import mage.Constants.Outcome; +import mage.Constants.Zone; +import mage.abilities.effects.Effect; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public abstract class TriggeredAbilityImpl extends AbilityImpl implements TriggeredAbility { + + protected boolean optional; + + public TriggeredAbilityImpl(Zone zone, Effect effect) { + this(zone, effect, false); + } + + public TriggeredAbilityImpl(Zone zone, Effect effect, boolean optional) { + super(zone); + if (effect != null) + addEffect(effect); + this.optional = optional; + } + + @Override + public void trigger(Game game, UUID controllerId) { + this.controllerId = controllerId; + game.addTriggeredAbility(this); + } + + @Override + public boolean resolve(Game game) { + if (optional) { + Player player = game.getPlayer(this.getControllerId()); + Permanent permanent = game.getPermanent(sourceId); + if (!player.chooseUse(this.effects.get(0).getOutcome(), "Use " + this.getRule() + " ability from " + permanent.getName() + "?", game)) { + return false; + } + } + return super.resolve(game); + } +} diff --git a/Mage/src/mage/abilities/common/ActivateOncePerTurnActivatedAbility.java b/Mage/src/mage/abilities/common/ActivateOncePerTurnActivatedAbility.java new file mode 100644 index 00000000000..a9761f45796 --- /dev/null +++ b/Mage/src/mage/abilities/common/ActivateOncePerTurnActivatedAbility.java @@ -0,0 +1,68 @@ +/* +* 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.common; + +import java.util.UUID; +import mage.Constants.Zone; +import mage.abilities.ActivatedAbilityImpl; +import mage.abilities.costs.Cost; +import mage.abilities.effects.Effect; +import mage.game.Game; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class ActivateOncePerTurnActivatedAbility extends ActivatedAbilityImpl { + + public ActivateOncePerTurnActivatedAbility(Zone zone, Effect effect, Cost cost) { + super(zone, effect, cost); + } + + @Override + public boolean canActivate(UUID playerId, Game game) { + if (isActivated(game)) + return false; + return super.canActivate(playerId, game); + } + + @Override + public boolean resolve(Game game) { + if (super.resolve(game)) { + return true; + } + return false; + } + + @Override + public String getRule() { + return super.getRule() + " Activate this ability only once each turn."; + } + +} diff --git a/Mage/src/mage/abilities/common/AsRequiredTriggeredAbility.java b/Mage/src/mage/abilities/common/AsRequiredTriggeredAbility.java new file mode 100644 index 00000000000..0c5d1124ac3 --- /dev/null +++ b/Mage/src/mage/abilities/common/AsRequiredTriggeredAbility.java @@ -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.abilities.common; + +import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.effects.Effect; +import mage.game.Game; +import mage.game.events.GameEvent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class AsRequiredTriggeredAbility extends TriggeredAbilityImpl { + + public AsRequiredTriggeredAbility(Effect effect) { + super(null, effect); + + } + + @Override + public void handleEvent(GameEvent event, Game game) { + } +} diff --git a/Mage/src/mage/abilities/common/CantCounterAbility.java b/Mage/src/mage/abilities/common/CantCounterAbility.java new file mode 100644 index 00000000000..b2de0a9cb45 --- /dev/null +++ b/Mage/src/mage/abilities/common/CantCounterAbility.java @@ -0,0 +1,49 @@ +/* +* 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.common; + +import mage.Constants.Zone; +import mage.abilities.StaticAbility; +import mage.abilities.effects.common.CantCounterSourceEffect; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class CantCounterAbility extends StaticAbility { + + public CantCounterAbility() { + super(Zone.STACK, new CantCounterSourceEffect()); + } + + @Override + public String getRule() { + return "{this} can't be countered"; + } +} diff --git a/Mage/src/mage/abilities/common/CreateTokenActivatedAbility.java b/Mage/src/mage/abilities/common/CreateTokenActivatedAbility.java new file mode 100644 index 00000000000..8bfad0e4d44 --- /dev/null +++ b/Mage/src/mage/abilities/common/CreateTokenActivatedAbility.java @@ -0,0 +1,47 @@ +/* +* 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.common; + +import mage.Constants.Zone; +import mage.abilities.ActivatedAbilityImpl; +import mage.abilities.costs.Cost; +import mage.abilities.effects.common.CreateTokenEffect; +import mage.game.permanent.token.Token; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class CreateTokenActivatedAbility extends ActivatedAbilityImpl { + + public CreateTokenActivatedAbility(Zone zone, Token token, Cost cost) { + super(zone, new CreateTokenEffect(token), cost); + } + +} diff --git a/Mage/src/mage/abilities/common/EntersBattlefieldStaticAbility.java b/Mage/src/mage/abilities/common/EntersBattlefieldStaticAbility.java new file mode 100644 index 00000000000..7f66d175727 --- /dev/null +++ b/Mage/src/mage/abilities/common/EntersBattlefieldStaticAbility.java @@ -0,0 +1,45 @@ +/* +* 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.common; + +import mage.Constants.Zone; +import mage.abilities.StaticAbility; +import mage.abilities.effects.EntersBattlefieldEffect; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class EntersBattlefieldStaticAbility extends StaticAbility { + + public EntersBattlefieldStaticAbility(EntersBattlefieldEffect effect) { + super(Zone.BATTLEFIELD, effect); + } + +} diff --git a/Mage/src/mage/abilities/common/EntersBattlefieldTriggeredAbility.java b/Mage/src/mage/abilities/common/EntersBattlefieldTriggeredAbility.java new file mode 100644 index 00000000000..3abc862fe6d --- /dev/null +++ b/Mage/src/mage/abilities/common/EntersBattlefieldTriggeredAbility.java @@ -0,0 +1,63 @@ +/* +* 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.common; + +import mage.Constants.Zone; +import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.effects.Effect; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.events.GameEvent.EventType; +import mage.game.events.ZoneChangeEvent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class EntersBattlefieldTriggeredAbility extends TriggeredAbilityImpl { + + public EntersBattlefieldTriggeredAbility(Effect effect, boolean optional) { + super(Zone.BATTLEFIELD, effect, optional); + } + + @Override + public void handleEvent(GameEvent event, Game game) { + if (event.getType() == EventType.ZONE_CHANGE && event.getTargetId().equals(this.getSourceId()) ) { + ZoneChangeEvent zEvent = (ZoneChangeEvent)event; + if (zEvent.getToZone() == Zone.BATTLEFIELD) + trigger(game, this.controllerId); + } + } + + @Override + public String getRule() { + return "When {this} enters the battlefield, " + super.getRule(); + } + +} diff --git a/Mage/src/mage/abilities/common/LandfallAbility.java b/Mage/src/mage/abilities/common/LandfallAbility.java new file mode 100644 index 00000000000..141b241a6ef --- /dev/null +++ b/Mage/src/mage/abilities/common/LandfallAbility.java @@ -0,0 +1,67 @@ +/* +* 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.common; + +import mage.Constants.CardType; +import mage.Constants.Zone; +import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.effects.Effect; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.events.GameEvent.EventType; +import mage.game.events.ZoneChangeEvent; +import mage.game.permanent.Permanent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class LandfallAbility extends TriggeredAbilityImpl { + + public LandfallAbility(Effect effect, boolean optional) { + super(Zone.BATTLEFIELD, effect, optional); + } + + @Override + public void handleEvent(GameEvent event, Game game) { + if (event.getType() == EventType.ZONE_CHANGE && ((ZoneChangeEvent)event).getToZone() == Zone.BATTLEFIELD) { + Permanent permanent = game.getPermanent(event.getTargetId()); + if (permanent != null && permanent.getCardType().contains(CardType.LAND) && permanent.getControllerId().equals(this.controllerId)) + trigger(game, this.controllerId); + } + } + + @Override + public String getRule() { + return "Landfall - Whenever a land enters the battlefield under your control, " + (optional?" you may ":"") + super.getRule(); + } + + + +} diff --git a/Mage/src/mage/abilities/common/LeavesBattlefieldTriggeredAbility.java b/Mage/src/mage/abilities/common/LeavesBattlefieldTriggeredAbility.java new file mode 100644 index 00000000000..70b0106bfcc --- /dev/null +++ b/Mage/src/mage/abilities/common/LeavesBattlefieldTriggeredAbility.java @@ -0,0 +1,63 @@ +/* +* 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.common; + +import mage.Constants.Zone; +import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.effects.Effect; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.events.GameEvent.EventType; +import mage.game.events.ZoneChangeEvent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class LeavesBattlefieldTriggeredAbility extends TriggeredAbilityImpl { + + public LeavesBattlefieldTriggeredAbility(Effect effect, boolean optional) { + super(Zone.BATTLEFIELD, effect, optional); + } + + @Override + public void handleEvent(GameEvent event, Game game) { + if (event.getType() == EventType.ZONE_CHANGE && event.getTargetId().equals(this.getSourceId()) ) { + ZoneChangeEvent zEvent = (ZoneChangeEvent)event; + if (zEvent.getFromZone() == Zone.BATTLEFIELD) + trigger(game, this.controllerId); + } + } + + @Override + public String getRule() { + return "When {this} leaves the battlefield, " + super.getRule(); + } + +} diff --git a/Mage/src/mage/abilities/common/OnEventTriggeredAbility.java b/Mage/src/mage/abilities/common/OnEventTriggeredAbility.java new file mode 100644 index 00000000000..b795fa1d60e --- /dev/null +++ b/Mage/src/mage/abilities/common/OnEventTriggeredAbility.java @@ -0,0 +1,75 @@ +/* +* 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.common; + +import mage.Constants.Zone; +import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.effects.Effect; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.events.GameEvent.EventType; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class OnEventTriggeredAbility extends TriggeredAbilityImpl { + + private EventType eventType; + private String eventName; + private boolean allPlayers = false; + + public OnEventTriggeredAbility(EventType eventType, String eventName, Effect effect) { + super(Zone.BATTLEFIELD, effect); + this.eventType = eventType; + this.eventName = eventName; + } + + public OnEventTriggeredAbility(EventType eventType, String eventName, boolean allPlayers, Effect effect) { + super(Zone.BATTLEFIELD, effect); + this.eventType = eventType; + this.eventName = eventName; + this.allPlayers = allPlayers; + } + + @Override + public void handleEvent(GameEvent event, Game game) { + if (event.getType() == eventType) { + if (allPlayers || event.getPlayerId().equals(this.controllerId) ) { + trigger(game, this.controllerId); + } + } + } + + @Override + public String getRule() { + return "At the " + eventName + ", " + super.getRule(); + } + +} diff --git a/Mage/src/mage/abilities/common/PutIntoGraveFromBattlefieldTriggeredAbility.java b/Mage/src/mage/abilities/common/PutIntoGraveFromBattlefieldTriggeredAbility.java new file mode 100644 index 00000000000..0ac52019d37 --- /dev/null +++ b/Mage/src/mage/abilities/common/PutIntoGraveFromBattlefieldTriggeredAbility.java @@ -0,0 +1,63 @@ +/* +* 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.common; + +import mage.Constants.Zone; +import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.effects.Effect; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.events.GameEvent.EventType; +import mage.game.events.ZoneChangeEvent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class PutIntoGraveFromBattlefieldTriggeredAbility extends TriggeredAbilityImpl { + + public PutIntoGraveFromBattlefieldTriggeredAbility(Effect effect, boolean optional) { + super(Zone.GRAVEYARD, effect, optional); + } + + @Override + public void handleEvent(GameEvent event, Game game) { + if (event.getType() == EventType.ZONE_CHANGE && event.getTargetId().equals(this.getSourceId()) ) { + ZoneChangeEvent zEvent = (ZoneChangeEvent)event; + if (zEvent.getFromZone() == Zone.BATTLEFIELD && zEvent.getToZone() == Zone.GRAVEYARD) + trigger(game, event.getPlayerId()); + } + } + + @Override + public String getRule() { + return "When {this} is put into a graveyard from the battlefield, " + super.getRule(); + } + +} diff --git a/Mage/src/mage/abilities/common/SimpleActivatedAbility.java b/Mage/src/mage/abilities/common/SimpleActivatedAbility.java new file mode 100644 index 00000000000..add350c1ca8 --- /dev/null +++ b/Mage/src/mage/abilities/common/SimpleActivatedAbility.java @@ -0,0 +1,46 @@ +/* +* 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.common; + +import mage.Constants.Zone; +import mage.abilities.ActivatedAbilityImpl; +import mage.abilities.costs.Cost; +import mage.abilities.effects.Effect; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class SimpleActivatedAbility extends ActivatedAbilityImpl { + + public SimpleActivatedAbility(Zone zone, Effect effect, Cost cost) { + super(zone, effect, cost); + } + +} diff --git a/Mage/src/mage/abilities/common/SimpleStaticAbility.java b/Mage/src/mage/abilities/common/SimpleStaticAbility.java new file mode 100644 index 00000000000..217b83620a4 --- /dev/null +++ b/Mage/src/mage/abilities/common/SimpleStaticAbility.java @@ -0,0 +1,45 @@ +/* +* 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.common; + +import mage.Constants.Zone; +import mage.abilities.StaticAbility; +import mage.abilities.effects.Effect; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class SimpleStaticAbility extends StaticAbility { + + public SimpleStaticAbility(Zone zone, Effect effect) { + super(zone, effect); + } + +} diff --git a/Mage/src/mage/abilities/common/SimpleTriggeredAbility.java b/Mage/src/mage/abilities/common/SimpleTriggeredAbility.java new file mode 100644 index 00000000000..977d4e50289 --- /dev/null +++ b/Mage/src/mage/abilities/common/SimpleTriggeredAbility.java @@ -0,0 +1,57 @@ +/* +* 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.common; + +import mage.Constants.Zone; +import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.effects.Effect; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.events.GameEvent.EventType; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class SimpleTriggeredAbility extends TriggeredAbilityImpl { + + EventType eventType; + + public SimpleTriggeredAbility(Zone zone, EventType eventType, Effect effect) { + super(zone, effect); + this.eventType = eventType; + } + + @Override + public void handleEvent(GameEvent event, Game game) { + if (event.getType() == eventType) { + trigger(game, event.getPlayerId()); + } + } +} diff --git a/Mage/src/mage/abilities/costs/AbstractCosts.java b/Mage/src/mage/abilities/costs/AbstractCosts.java new file mode 100644 index 00000000000..8da5dbb1254 --- /dev/null +++ b/Mage/src/mage/abilities/costs/AbstractCosts.java @@ -0,0 +1,136 @@ +/* +* 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.costs; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import mage.abilities.Ability; +import mage.abilities.costs.mana.ManaCosts; +import mage.game.Game; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public abstract class AbstractCosts extends ArrayList implements Costs { + + private Ability ability; + + public AbstractCosts(Ability ability) { + this.ability = ability; + } + + @Override + public String getText() { + if (this.size() == 0) + return ""; + + StringBuilder sbText = new StringBuilder(); + for (T cost: this) { + sbText.append(cost.getText()); + sbText.append(", "); + } + sbText.setLength(sbText.length() - 2); + return sbText.toString(); + } + + @Override + public boolean canPay(UUID playerId, Game game) { + for (Cost cost: this) { + if (!cost.canPay(playerId, game)) + return false; + } + return true; + } + + @Override + public boolean pay(Game game, boolean noMana) { + if (this.size() > 0) { + while (!isPaid()) { + Cost cost = getFirstUnpaid(); + if (!cost.pay(game, noMana)) + return false; + } + } + return true; + } + + @Override + public boolean isPaid() { + for (T cost: this) { + if (!cost.isPaid()) + return false; + } + return true; + } + + @Override + public void clearPaid() { + for (T cost: this) { + cost.clearPaid(); + } + } + + @Override + public Ability getAbility() { + return ability; + } + + @Override + public void setAbility(Ability ability) { + this.ability = ability; + for (T cost: this) { + cost.setAbility(ability); + } + } + + @Override + public boolean add(T cost) { + cost.setAbility(ability); + return super.add(cost); + } + + @Override + public List getUnpaid() { + List unpaid = new ArrayList(); + for (T cost: this) { + if (!cost.isPaid()) + unpaid.add(cost); + } + return unpaid; + } + + protected T getFirstUnpaid() { + if (this.size() > 0) { + return this.get(0); + } + return null; + } +} diff --git a/Mage/src/mage/abilities/costs/Cost.java b/Mage/src/mage/abilities/costs/Cost.java new file mode 100644 index 00000000000..03addd39919 --- /dev/null +++ b/Mage/src/mage/abilities/costs/Cost.java @@ -0,0 +1,48 @@ +/* +* 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.costs; + +import java.io.Serializable; +import java.util.UUID; +import mage.abilities.Ability; +import mage.game.Game; + +public interface Cost extends Serializable { + + public String getText(); + public boolean canPay(UUID playerId, Game game); + public boolean pay(Game game, boolean noMana); + public boolean isPaid(); + public void clearPaid(); + public void setPaid(); + + public Ability getAbility(); + public void setAbility(Ability ability); + +} diff --git a/Mage/src/mage/abilities/costs/CostImpl.java b/Mage/src/mage/abilities/costs/CostImpl.java new file mode 100644 index 00000000000..5eda3fd3bb0 --- /dev/null +++ b/Mage/src/mage/abilities/costs/CostImpl.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.abilities.costs; + +import mage.abilities.Ability; + +public abstract class CostImpl implements Cost { + + protected String text; + protected Ability ability; + protected boolean paid = false; + +// public CostImpl(Ability ability) { +// this.ability = ability; +// } + + public CostImpl() { + } + + @Override + public String getText() { + return text; + } + + @Override + public Ability getAbility() { + return ability; + } + + @Override + public void setAbility(Ability ability) { + this.ability = ability; + } + + @Override + public boolean isPaid() { + return paid; + } + + @Override + public void clearPaid() { + paid = false; + } + + @Override + public void setPaid() { + paid = true; + } + +} diff --git a/Mage/src/mage/abilities/costs/Costs.java b/Mage/src/mage/abilities/costs/Costs.java new file mode 100644 index 00000000000..6e1b3e3b191 --- /dev/null +++ b/Mage/src/mage/abilities/costs/Costs.java @@ -0,0 +1,43 @@ +/* +* 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.costs; + +import java.util.List; +import mage.abilities.costs.mana.ManaCosts; +import mage.abilities.costs.mana.VariableManaCost; + +public interface Costs extends List, Cost { + @Override + public boolean add(T cost); + + public List getUnpaid(); + public List getVariableCosts(); + public ManaCosts getManaCosts(); + +} diff --git a/Mage/src/mage/abilities/costs/CostsImpl.java b/Mage/src/mage/abilities/costs/CostsImpl.java new file mode 100644 index 00000000000..e468f9837df --- /dev/null +++ b/Mage/src/mage/abilities/costs/CostsImpl.java @@ -0,0 +1,168 @@ +/* +* 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.costs; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import mage.abilities.Ability; +import mage.abilities.costs.mana.ManaCost; +import mage.abilities.costs.mana.ManaCosts; +import mage.abilities.costs.mana.VariableManaCost; +import mage.game.Game; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class CostsImpl extends ArrayList implements Costs { + + protected Ability ability; + + public CostsImpl() {} + + public CostsImpl(Ability ability) { + this.ability = ability; + } + + @Override + public String getText() { + if (this.size() == 0) + return ""; + + StringBuilder sbText = new StringBuilder(); + for (T cost: this) { + sbText.append(cost.getText()); + sbText.append(", "); + } + sbText.setLength(sbText.length() - 2); + return sbText.toString(); + } + + @Override + public boolean canPay(UUID playerId, Game game) { + for (Cost cost: this) { + if (!cost.canPay(playerId, game)) + return false; + } + return true; + } + + @Override + public boolean pay(Game game, boolean noMana) { + if (this.size() > 0) { + while (!isPaid()) { + Cost cost = getFirstUnpaid(); + if (!cost.pay(game, noMana)) + return false; + } + } + return true; + } + + @Override + public boolean isPaid() { + for (T cost: this) { + if (!(cost instanceof VariableManaCost) && !cost.isPaid()) + return false; + } + return true; + } + + @Override + public void clearPaid() { + for (T cost: this) { + cost.clearPaid(); + } + } + + @Override + public void setPaid() { + for (T cost: this) { + cost.setPaid(); + } + } + + @Override + public Ability getAbility() { + return ability; + } + + @Override + public void setAbility(Ability ability) { + this.ability = ability; + for (T cost: this) { + cost.setAbility(ability); + } + } + + @Override + public boolean add(T cost) { + cost.setAbility(ability); + return super.add(cost); + } + + @Override + public Costs getUnpaid() { + Costs unpaid = new CostsImpl(ability); + for (T cost: this) { + if (!cost.isPaid()) + unpaid.add(cost); + } + return unpaid; + } + + protected T getFirstUnpaid() { + Costs unpaid = getUnpaid(); + if (unpaid.size() > 0) { + return unpaid.get(0); + } + return null; + } + + @Override + public ManaCosts getManaCosts() { + ManaCosts manaCosts = new ManaCosts(ability); + for (T cost: this) { + if (cost instanceof ManaCost) + manaCosts.add((ManaCost)cost); + } + return manaCosts; + } + + @Override + public List getVariableCosts() { + List variableCosts = new ArrayList(); + for (T cost: this) { + if (cost instanceof ManaCosts) + variableCosts.addAll(((ManaCosts)cost).getVariableCosts()); + } + return variableCosts; + } +} diff --git a/Mage/src/mage/abilities/costs/common/PayLifeCost.java b/Mage/src/mage/abilities/costs/common/PayLifeCost.java new file mode 100644 index 00000000000..6b5754bc685 --- /dev/null +++ b/Mage/src/mage/abilities/costs/common/PayLifeCost.java @@ -0,0 +1,60 @@ +/* +* 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.costs.common; + +import java.util.UUID; +import mage.abilities.costs.CostImpl; +import mage.game.Game; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class PayLifeCost extends CostImpl { + + private int amount; + + public PayLifeCost(int amount) { +// super(ability); + this.amount = amount; + this.text = "Pay " + Integer.toString(amount) + " life"; + } + + public boolean canPay(UUID playerId, Game game) { + if (ability.getControllerId().equals(playerId)) + return game.getPlayer(playerId).getLife() >= amount; + return false; + } + + public boolean pay(Game game, boolean noMana) { + this.paid = game.getPlayer(ability.getControllerId()).loseLife(amount, game) == amount; + return paid; + } + +} diff --git a/Mage/src/mage/abilities/costs/common/PayLoyaltyCost.java b/Mage/src/mage/abilities/costs/common/PayLoyaltyCost.java new file mode 100644 index 00000000000..4eef40f11d9 --- /dev/null +++ b/Mage/src/mage/abilities/costs/common/PayLoyaltyCost.java @@ -0,0 +1,68 @@ +/* +* 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.costs.common; + +import java.util.UUID; +import mage.abilities.costs.CostImpl; +import mage.game.Game; +import mage.game.permanent.Permanent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class PayLoyaltyCost extends CostImpl { + + private int amount; + + public PayLoyaltyCost(int amount) { + this.amount = amount; + this.text = Integer.toString(amount) + " loyalty"; + } + + @Override + public boolean canPay(UUID playerId, Game game) { + Permanent planeswalker = game.getPermanent(this.ability.getSourceId()); + if (planeswalker.getLoyalty().getValue() + amount >= 0 && !planeswalker.isLoyaltyUsed()) + return true; + return false; + } + + @Override + public boolean pay(Game game, boolean noMana) { + Permanent planeswalker = game.getPermanent(this.ability.getSourceId()); + if (planeswalker.getLoyalty().getValue() + amount > 0 && !planeswalker.isLoyaltyUsed()) { + planeswalker.getLoyalty().boostValue(amount); + planeswalker.setLoyaltyUsed(true); + this.paid = true; + } + return paid; + } + +} diff --git a/Mage/src/mage/abilities/costs/common/SacrificeSourceCost.java b/Mage/src/mage/abilities/costs/common/SacrificeSourceCost.java new file mode 100644 index 00000000000..4d6c892e56f --- /dev/null +++ b/Mage/src/mage/abilities/costs/common/SacrificeSourceCost.java @@ -0,0 +1,63 @@ +/* +* 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.costs.common; + +import java.util.UUID; +import mage.abilities.costs.CostImpl; +import mage.game.Game; +import mage.game.permanent.Permanent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class SacrificeSourceCost extends CostImpl { + + public SacrificeSourceCost() { + this.text = "Sacrifice {this}"; + } + + @Override + public boolean pay(Game game, boolean noMana) { + Permanent source = game.getPermanent(ability.getSourceId()); + if (source != null) { + paid = source.sacrifice(this.ability.getSourceId(), game); + } + return paid; + } + + public boolean canPay(UUID playerId, Game game) { + Permanent source = game.getPermanent(ability.getSourceId()); + if (source != null) { + return true; + } + return false; + } + +} diff --git a/Mage/src/mage/abilities/costs/common/TapSourceCost.java b/Mage/src/mage/abilities/costs/common/TapSourceCost.java new file mode 100644 index 00000000000..ba8b43c276a --- /dev/null +++ b/Mage/src/mage/abilities/costs/common/TapSourceCost.java @@ -0,0 +1,70 @@ +/* +* 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.costs.common; + +import java.util.UUID; +import mage.MageObject; +import mage.abilities.Ability; +import mage.abilities.costs.CostImpl; +import mage.game.Game; +import mage.game.permanent.Permanent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class TapSourceCost extends CostImpl { + + public TapSourceCost() { + this.text = "{T}"; + } + + @Override + public boolean pay(Game game, boolean noMana) { + Permanent source = game.getPermanent(ability.getSourceId()); + if (source != null) { + paid = source.tap(game); + } + return paid; + } + + public boolean canPay(UUID playerId, Game game) { + Permanent source = game.getPermanent(ability.getSourceId()); + if (source != null) { + return !source.isTapped() && source.canTap(); + } + return false; + } + + @Override + public void setAbility(Ability ability) { + this.ability = ability; + } + +} diff --git a/Mage/src/mage/abilities/costs/mana/ColoredManaCost.java b/Mage/src/mage/abilities/costs/mana/ColoredManaCost.java new file mode 100644 index 00000000000..3843bce2e11 --- /dev/null +++ b/Mage/src/mage/abilities/costs/mana/ColoredManaCost.java @@ -0,0 +1,92 @@ +/* +* 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.costs.mana; + +import mage.Constants.ColoredManaSymbol; +import mage.Mana; +import mage.players.ManaPool; + +public class ColoredManaCost extends ManaCostImpl implements ManaCost { + + protected ColoredManaSymbol mana; + + public ColoredManaCost(ColoredManaSymbol mana) { + this.mana = mana; + addColoredOption(mana); + } + + public ColoredManaSymbol getMana() { + return mana; + } + + @Override + public int convertedManaCost() { + return 1; + } + + @Override + public boolean isPaid() { + if (paid) + return true; + return this.isColoredPaid(mana); + } + + @Override + public void assignPayment(ManaPool pool) { + this.assignColored(pool, mana); + } + + @Override + public String getText() { + return "{" + mana.toString() + "}"; + } + + @Override + public ColoredManaCost getUnpaid() { + return this; + } + + @Override + public boolean testPay(Mana testMana) { + switch (mana) { + case B: + return testMana.getBlack() > 0; + case U: + return testMana.getBlue() > 0; + case R: + return testMana.getRed() > 0; + case W: + return testMana.getWhite() > 0; + case G: + return testMana.getGreen() > 0; + } + return false; + } + +} diff --git a/Mage/src/mage/abilities/costs/mana/GenericManaCost.java b/Mage/src/mage/abilities/costs/mana/GenericManaCost.java new file mode 100644 index 00000000000..9dc08dbfca4 --- /dev/null +++ b/Mage/src/mage/abilities/costs/mana/GenericManaCost.java @@ -0,0 +1,79 @@ +/* +* 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.costs.mana; + +import mage.Mana; +import mage.players.ManaPool; + +public class GenericManaCost extends ManaCostImpl implements ManaCost { + + protected int mana; + + public GenericManaCost(int mana) { + this.mana = mana; + this.options.addMana(Mana.ColorlessMana(mana)); + } + + public int getMana() { + return mana; + } + + @Override + public int convertedManaCost() { + return mana; + } + + @Override + public boolean isPaid() { + if (paid) + return true; + return this.isColorlessPaid(mana); + } + + @Override + public void assignPayment(ManaPool pool) { + this.assignColorless(pool, mana); + } + + @Override + public String getText() { + return "{" + Integer.toString(mana) + "}"; + } + + @Override + public GenericManaCost getUnpaid() { + return new GenericManaCost(mana - this.payment.count()); + } + + @Override + public boolean testPay(Mana testMana) { + return testMana.count() > 0; + } + +} diff --git a/Mage/src/mage/abilities/costs/mana/HybridManaCost.java b/Mage/src/mage/abilities/costs/mana/HybridManaCost.java new file mode 100644 index 00000000000..546a373a413 --- /dev/null +++ b/Mage/src/mage/abilities/costs/mana/HybridManaCost.java @@ -0,0 +1,116 @@ +/* +* 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.costs.mana; + +import mage.Constants.ColoredManaSymbol; +import mage.Mana; +import mage.players.ManaPool; + +public class HybridManaCost extends ManaCostImpl implements ManaCost { + private ColoredManaSymbol mana1; + private ColoredManaSymbol mana2; + + public HybridManaCost(ColoredManaSymbol mana1, ColoredManaSymbol mana2) { + this.mana1 = mana1; + this.mana2 = mana2; + addColoredOption(mana1); + addColoredOption(mana2); + } + + @Override + public int convertedManaCost() { + return 1; + } + + public ColoredManaSymbol getMana1() { + return mana1; + } + + public ColoredManaSymbol getMana2() { + return mana2; + } + + @Override + public boolean isPaid() { + if (paid || isColoredPaid(this.mana1) || isColoredPaid(this.mana2)) + return true; + return false; + } + + @Override + public void assignPayment(ManaPool pool) { + if (assignColored(pool, this.mana1)) + return; + assignColored(pool, this.mana2); + } + + @Override + public String getText() { + return "{" + mana1.toString() + "/" + mana2.toString() + "}"; + } + + @Override + public HybridManaCost getUnpaid() { + return this; + } + + @Override + public boolean testPay(Mana testMana) { + switch (mana1) { + case B: + if (testMana.getBlack() > 0) + return true; + case U: + if (testMana.getBlue() >0) + return true; + case R: + if (testMana.getRed() > 0) + return true; + case W: + if (testMana.getWhite() > 0) + return true; + case G: + if (testMana.getGreen() > 0) + return true; + } + switch (mana2) { + case B: + return testMana.getBlack() > 0; + case U: + return testMana.getBlue() > 0; + case R: + return testMana.getRed() > 0; + case W: + return testMana.getWhite() > 0; + case G: + return testMana.getGreen() > 0; + } + return false; + } +} diff --git a/Mage/src/mage/abilities/costs/mana/ManaCost.java b/Mage/src/mage/abilities/costs/mana/ManaCost.java new file mode 100644 index 00000000000..0afe90bc548 --- /dev/null +++ b/Mage/src/mage/abilities/costs/mana/ManaCost.java @@ -0,0 +1,47 @@ +/* +* 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.costs.mana; + +import mage.abilities.costs.*; +import mage.Mana; +import mage.abilities.mana.ManaOptions; +import mage.players.ManaPool; + +public interface ManaCost extends Cost { + + public int convertedManaCost(); + public Mana getPayment(); + public void assignPayment(ManaPool pool); + @Override + public String getText(); + public ManaCost getUnpaid(); + public ManaOptions getOptions(); + public boolean testPay(Mana testMana); + +} diff --git a/Mage/src/mage/abilities/costs/mana/ManaCostImpl.java b/Mage/src/mage/abilities/costs/mana/ManaCostImpl.java new file mode 100644 index 00000000000..c4c917c775b --- /dev/null +++ b/Mage/src/mage/abilities/costs/mana/ManaCostImpl.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.abilities.costs.mana; + +import java.util.UUID; +import mage.Constants.ColoredManaSymbol; +import mage.Mana; +import mage.abilities.costs.CostImpl; +import mage.abilities.mana.ManaOptions; +import mage.game.Game; +import mage.players.ManaPool; +import mage.players.Player; + +public abstract class ManaCostImpl extends CostImpl implements ManaCost { + + protected Mana payment = new Mana(); + protected ManaOptions options = new ManaOptions(); + + public ManaCostImpl() { + } + + @Override + public Mana getPayment() { + return payment; + } + + @Override + public ManaOptions getOptions() { + return options; + } + + protected boolean assignColored(ManaPool pool, ColoredManaSymbol mana) { + switch (mana) { + case B: + if (pool.getBlack() > 0) { + this.payment.addBlack(); + pool.removeBlack(); + return true; + } + break; + case U: + if (pool.getBlue() > 0) { + this.payment.addBlue(); + pool.removeBlue(); + return true; + } + break; + case W: + if (pool.getWhite() > 0) { + this.payment.addWhite(); + pool.removeWhite(); + return true; + } + break; + case G: + if (pool.getGreen() > 0) { + this.payment.addGreen(); + pool.removeGreen(); + return true; + } + break; + case R: + if (pool.getRed() > 0) { + this.payment.addRed(); + pool.removeRed(); + return true; + } + break; + } + return false; + } + + protected boolean assignColorless(ManaPool pool, int mana) { + while (mana > payment.count() && pool.count() > 0) { + if (pool.getColorless() > 0) { + this.payment.addColorless(); + pool.removeColorless(); + continue; + } + if (pool.getBlack() > 0) { + this.payment.addBlack(); + pool.removeBlack(); + continue; + } + if (pool.getBlue() > 0) { + this.payment.addBlue(); + pool.removeBlue(); + continue; + } + if (pool.getWhite() > 0) { + this.payment.addWhite(); + pool.removeWhite(); + continue; + } + if (pool.getGreen() > 0) { + this.payment.addGreen(); + pool.removeGreen(); + continue; + } + if (pool.getRed() > 0) { + this.payment.addRed(); + pool.removeRed(); + continue; + } + } + return mana > payment.count(); + } + + protected boolean isColoredPaid(ColoredManaSymbol mana) { + switch (mana) { + case B: + if (this.payment.getBlack() > 0) + return true; + case U: + if (this.payment.getBlue() > 0) + return true; + case W: + if (this.payment.getWhite() > 0) + return true; + case G: + if (this.payment.getGreen() > 0) + return true; + case R: + if (this.payment.getRed() > 0) + return true; + } + return false; + } + + protected boolean isColorlessPaid(int mana) { + if (this.payment.count() >= mana) + return true; + return false; + } + + @Override + public boolean canPay(UUID playerId, Game game) { + return true; + } + + @Override + public boolean pay(Game game, boolean noMana) { + if (noMana) { + setPaid(); + return true; + } + Player player = game.getPlayer(this.getAbility().getControllerId()); + assignPayment(player.getManaPool()); + while (!isPaid()) { + if (player.playMana(this, game)) + assignPayment(player.getManaPool()); + else + return false; + } + return true; + } + + @Override + public void setPaid() { + this.paid = true; + } + + protected void addColoredOption(ColoredManaSymbol symbol) { + switch (symbol) { + case B: + this.options.add(Mana.BlackMana); + break; + case U: + this.options.add(Mana.BlueMana); + break; + case W: + this.options.add(Mana.WhiteMana); + break; + case R: + this.options.add(Mana.RedMana); + break; + case G: + this.options.add(Mana.GreenMana); + break; + } + } + +} diff --git a/Mage/src/mage/abilities/costs/mana/ManaCosts.java b/Mage/src/mage/abilities/costs/mana/ManaCosts.java new file mode 100644 index 00000000000..78d57c15075 --- /dev/null +++ b/Mage/src/mage/abilities/costs/mana/ManaCosts.java @@ -0,0 +1,236 @@ +/* +* 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.costs.mana; + +import java.util.ArrayList; +import java.util.List; +import mage.Constants.ColoredManaSymbol; +import mage.Mana; +import mage.abilities.Ability; +import mage.abilities.costs.Costs; +import mage.abilities.costs.CostsImpl; +import mage.abilities.mana.ManaOptions; +import mage.game.Game; +import mage.players.ManaPool; +import mage.players.Player; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class ManaCosts extends CostsImpl implements Costs, ManaCost { + + public ManaCosts(String mana) { + load(mana); + } + + public ManaCosts(Ability ability) { + super(ability); + } + + public ManaCosts(Ability ability, String mana) { + super(ability); + load(mana); + } + + @Override + public int convertedManaCost() { + int total = 0; + for (ManaCost cost: this) { + total += cost.convertedManaCost(); + } + return total; + } + + @Override + public Mana getPayment() { + Mana manaTotal = new Mana(); + for (ManaCost cost: this) { + manaTotal.add(cost.getPayment()); + } + return manaTotal; + } + + @Override + public boolean pay(Game game, boolean noMana) { + if (noMana) { + setPaid(); + return true; + } + Player player = game.getPlayer(this.getAbility().getControllerId()); + assignPayment(player.getManaPool()); + while (!isPaid()) { + if (player.playMana(this.getUnpaid(), game)) + assignPayment(player.getManaPool()); + else + return false; + } + for (ManaCost cost: this.getUnpaidVariableCosts()) { + VariableManaCost vCost = (VariableManaCost) cost; + while (!vCost.isPaid()) { + if (player.playXMana(vCost, game)) + vCost.assignPayment(player.getManaPool()); + else + return false; + } + } + return true; + } + + @Override + public ManaCosts getUnpaid() { + ManaCosts unpaid = new ManaCosts(ability); + for (ManaCost cost: this) { + if (!(cost instanceof VariableManaCost) && !cost.isPaid()) + unpaid.add(cost.getUnpaid()); + } + return unpaid; + } + + public ManaCosts getUnpaidVariableCosts() { + ManaCosts unpaid = new ManaCosts(ability); + for (ManaCost cost: this) { + if (cost instanceof VariableManaCost && !cost.isPaid()) + unpaid.add(cost.getUnpaid()); + } + return unpaid; + } + + @Override + public List getVariableCosts() { + List variableCosts = new ArrayList(); + for (ManaCost cost: this) { + if (cost instanceof VariableManaCost) + variableCosts.add((VariableManaCost) cost); + } + return variableCosts; + } + + @Override + public void assignPayment(ManaPool pool) { + //attempt to pay colored costs first + for (ManaCost cost: this) { + if (!cost.isPaid() && cost instanceof ColoredManaCost) { + cost.assignPayment(pool); + } + } + + for (ManaCost cost: this) { + if (!cost.isPaid() && cost instanceof HybridManaCost) { + cost.assignPayment(pool); + } + } + + for (ManaCost cost: this) { + if (!cost.isPaid() && cost instanceof MonoHybridManaCost) { + cost.assignPayment(pool); + } + } + + for (ManaCost cost: this) { + if (!cost.isPaid() && cost instanceof GenericManaCost) { + cost.assignPayment(pool); + } + } + + for (ManaCost cost: this) { + if (!cost.isPaid() && cost instanceof VariableManaCost) { + cost.assignPayment(pool); + } + } + } + + public void load(String mana) { + this.clear(); + if (mana == null || mana.length() == 0) + return; + String[] symbols = mana.split("^\\{|\\}\\{|\\}$"); + for (String symbol: symbols) { + if (symbol.length() > 0) { + if (symbol.length() == 1) { + if (Character.isDigit(symbol.charAt(0))) { + this.add(new GenericManaCost(Integer.valueOf(symbol))); + } + else { + if (!symbol.equals("X")) + this.add(new ColoredManaCost(ColoredManaSymbol.lookup(symbol.charAt(0)))); + else + this.add(new VariableManaCost()); + //TODO: handle multiple {X} and/or {Y} symbols + } + } + else { + if (Character.isDigit(symbol.charAt(0))) { + this.add(new MonoHybridManaCost(ColoredManaSymbol.lookup(symbol.charAt(2)))); + } + else { + this.add(new HybridManaCost(ColoredManaSymbol.lookup(symbol.charAt(0)), ColoredManaSymbol.lookup(symbol.charAt(2)))); + } + } + } + } + } + + public List getSymbols() { + List symbols = new ArrayList(); + for (ManaCost cost: this) { + symbols.add(cost.getText()); + } + return symbols; + } + + @Override + public String getText() { + if (this.size() == 0) + return ""; + + StringBuilder sbText = new StringBuilder(); + for (ManaCost cost: this) { + sbText.append(cost.getText()); + } + return sbText.toString(); + } + + public ManaOptions getOptions() { + ManaOptions options = new ManaOptions(); + for (ManaCost cost: this) { + options.addMana(cost.getOptions()); + } + return options; + } + + public boolean testPay(Mana testMana) { + for (ManaCost cost: this) { + if (cost.testPay(testMana)) + return true; + } + return false; + } + +} diff --git a/Mage/src/mage/abilities/costs/mana/MonoHybridManaCost.java b/Mage/src/mage/abilities/costs/mana/MonoHybridManaCost.java new file mode 100644 index 00000000000..5fbc856e922 --- /dev/null +++ b/Mage/src/mage/abilities/costs/mana/MonoHybridManaCost.java @@ -0,0 +1,100 @@ +/* +* 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.costs.mana; + +import mage.Constants.ColoredManaSymbol; +import mage.Mana; +import mage.players.ManaPool; + +public class MonoHybridManaCost extends ManaCostImpl implements ManaCost { + + private ColoredManaSymbol mana; + private int mana2 = 2; + + public MonoHybridManaCost(ColoredManaSymbol mana) { + this.mana = mana; + addColoredOption(mana); + options.add(Mana.ColorlessMana(2)); + } + + @Override + public int convertedManaCost() { + return 2; + } + + public ColoredManaSymbol getMana() { + return mana; + } + + @Override + public boolean isPaid() { + if (paid || isColoredPaid(this.mana)) + return true; + return isColorlessPaid(this.mana2); + } + + @Override + public void assignPayment(ManaPool pool) { + if (!assignColored(pool, mana)) { + assignColorless(pool, mana2); + } + } + + @Override + public String getText() { + return "{2/" + mana.toString() + "}"; + } + + @Override + public MonoHybridManaCost getUnpaid() { + return this; + } + + public boolean testPay(Mana testMana) { + switch (mana) { + case B: + if (testMana.getBlack() > 0) + return true; + case U: + if (testMana.getBlue() > 0) + return true; + case R: + if (testMana.getRed() > 0) + return true; + case W: + if (testMana.getWhite() > 0) + return true; + case G: + if (testMana.getGreen() > 0) + return true; + } + return testMana.count() > 0; + } + +} diff --git a/Mage/src/mage/abilities/costs/mana/VariableManaCost.java b/Mage/src/mage/abilities/costs/mana/VariableManaCost.java new file mode 100644 index 00000000000..9f9b1fdabc9 --- /dev/null +++ b/Mage/src/mage/abilities/costs/mana/VariableManaCost.java @@ -0,0 +1,101 @@ +/* +* 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.costs.mana; + +import mage.Mana; +import mage.players.ManaPool; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class VariableManaCost extends ManaCostImpl implements ManaCost { + + protected Mana manaPaid = new Mana(); + protected int multiplier; + + public VariableManaCost() { + this(1); + options.add(new Mana()); + } + + public VariableManaCost(int multiplier) { + this.multiplier = multiplier; + } + + @Override + public int convertedManaCost() { + return 0; + } + + @Override + public void assignPayment(ManaPool pool) { + manaPaid.add(pool.getMana()); + pool.emptyPool(); + } + + @Override + public String getText() { + if (multiplier > 1) { + String symbol = ""; + for (int i = 0; i < multiplier; i++) { + symbol += "{X}"; + } + return symbol; + } + else { + return "{X}"; + } + } + + @Override + public VariableManaCost getUnpaid() { + return this; + } + + @Override + public void clearPaid() { + paid = false; + manaPaid.clear(); + } + + public Mana getPaid() { + return manaPaid; + } + + public int getValue() { + return manaPaid.count() / multiplier; + } + + @Override + public boolean testPay(Mana testMana) { + return true; + } + +} diff --git a/Mage/src/mage/abilities/effects/ContinuousEffect.java b/Mage/src/mage/abilities/effects/ContinuousEffect.java new file mode 100644 index 00000000000..f9a49b23269 --- /dev/null +++ b/Mage/src/mage/abilities/effects/ContinuousEffect.java @@ -0,0 +1,48 @@ +/* +* 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; + +import java.util.Date; +import mage.Constants.Duration; +import mage.Constants.Layer; +import mage.Constants.SubLayer; +import mage.game.Game; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public interface ContinuousEffect extends Effect { + + public Duration getDuration(); +// public Layer getLayer(); +// public SubLayer getSubLayer(); + public Date getTimestamp(); + public boolean apply(Layer layer, SubLayer sublayer, Game game); +} diff --git a/Mage/src/mage/abilities/effects/ContinuousEffectImpl.java b/Mage/src/mage/abilities/effects/ContinuousEffectImpl.java new file mode 100644 index 00000000000..7249a417bd7 --- /dev/null +++ b/Mage/src/mage/abilities/effects/ContinuousEffectImpl.java @@ -0,0 +1,90 @@ +/* +* 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; + +import java.util.Date; +import mage.Constants.Duration; +import mage.Constants.Layer; +import mage.Constants.Outcome; +import mage.Constants.SubLayer; +import mage.game.Game; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public abstract class ContinuousEffectImpl extends EffectImpl implements ContinuousEffect { + + protected Duration duration; + protected Layer layer; + protected SubLayer sublayer; + protected Date timestamp = new Date(); + + public ContinuousEffectImpl(Duration duration, Outcome outcome) { + super(outcome); + this.duration = duration; + } + + public ContinuousEffectImpl(Duration duration, Layer layer, SubLayer sublayer, Outcome outcome) { + super(outcome); + this.duration = duration; + this.layer = layer; + this.sublayer = sublayer; + } + + @Override + public Duration getDuration() { + return duration; + } + + @Override + public boolean apply(Layer layer, SubLayer sublayer, Game game) { + if (this.layer == layer && this.sublayer == sublayer) { + return apply(game); + } + return false; + } + +// @Override +// public Layer getLayer() { +// return layer; +// } +// +// @Override +// public SubLayer getSubLayer() { +// return sublayer; +// } + + @Override + public Date getTimestamp() { + return timestamp; + } + + +} diff --git a/Mage/src/mage/abilities/effects/ContinuousEffects.java b/Mage/src/mage/abilities/effects/ContinuousEffects.java new file mode 100644 index 00000000000..f77b76b452e --- /dev/null +++ b/Mage/src/mage/abilities/effects/ContinuousEffects.java @@ -0,0 +1,299 @@ +/* +* 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; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; +import java.util.UUID; +import mage.Constants.CardType; +import mage.Constants.Duration; +import mage.Constants.Layer; +import mage.Constants.SubLayer; +import mage.counters.BoostCounter; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.permanent.Permanent; +import mage.players.Player; + + + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class ContinuousEffects implements Serializable { + + private static final long serialVersionUID = 1L; + private List effects = new ArrayList(); + + public void removeEndOfTurnEffects() { + for (Iterator i = effects.iterator(); i.hasNext();) { + ContinuousEffect entry = i.next(); + if (entry.getDuration() == Duration.EndOfTurn) + i.remove(); + } + } + + public void removeInactiveEffects(Game game) { + for (Iterator i = effects.iterator(); i.hasNext();) { + ContinuousEffect entry = i.next(); + if (entry.getDuration() == Duration.WhileInPlay) { + Permanent permanent = (Permanent)game.getPermanent(entry.getSource().getSourceId()); + if (permanent == null || !permanent.isPhasedIn()) + i.remove(); + } + if (entry.getDuration() == Duration.OneUse) { + if (entry instanceof ReplacementEffect) { + if (((ReplacementEffect)entry).isUsed()) + i.remove(); + } + } + } + } + + private List getLayeredEffects() { + List layerEffects = new ArrayList(); + for (ContinuousEffect effect: effects) { + if (!(effect instanceof ReplacementEffect) && !(effect instanceof PreventionEffect)) { + layerEffects.add(effect); + } + } + Collections.sort(layerEffects, new TimestampSorter()); + return layerEffects; + } + + +// private List getLayer(Layer layer, SubLayer sublayer) { +// List layerEffects = new ArrayList(); +// for (ContinuousEffect effect: effects) { +// if (effect.getLayer() == layer && effect.getSubLayer() == sublayer) { +// layerEffects.add(effect); +// } +// } +// Collections.sort(layerEffects, new TimestampSorter()); +// return layerEffects; +// } + +// private List GetApplicablePreventionEffects(GameEvent event, Game game) { +// List effects = new ArrayList(); +// for (IEffect effect: this) { +// if (effect instanceof PreventionEffect && ((PreventionEffect)effect).Applies(event, game)) { +// effects.add((PreventionEffect)effect); +// } +// } +// return effects; +// } + +// public List GetApplicablePreventionEffects(IMageObject source, IPermanent target, Game game) { +// List effects = new ArrayList(); +// for (IEffect effect: this) { +// if (effect instanceof PreventionEffect && ((PreventionEffect)effect).Applies(source, target, game)) { +// effects.add((PreventionEffect)effect); +// } +// } +// return effects; +// } +// +// public List GetApplicablePreventionEffects(IMageObject source, IPlayer target, Game game) { +// List effects = new ArrayList(); +// for (IEffect effect: this) { +// if (effect instanceof PreventionEffect && ((PreventionEffect)effect).Applies(source, target, game)) { +// effects.add((PreventionEffect)effect); +// } +// } +// return effects; +// } + + private List getApplicableReplacementEffects(GameEvent event, Game game) { + List replacementEffects = new ArrayList(); + for (Effect effect: effects) { + if (effect instanceof ReplacementEffect && ((ReplacementEffect)effect).applies(event, game)) { + if (((ReplacementEffect)effect).getDuration() != Duration.OneUse || !((ReplacementEffect)effect).isUsed()) + replacementEffects.add((ReplacementEffect)effect); + } + } + return replacementEffects; + } + +// private List GetApplicableSelfReplacementEffects(GameEvent event, Game game) { +// List effects = new ArrayList(); +// for (IEffect effect: this) { +// if (effect instanceof SelfReplacementEffect && ((SelfReplacementEffect)effect).Applies(event, game)) { +// effects.add((SelfReplacementEffect)effect); +// } +// } +// return effects; +// } + + public boolean replaceEvent(GameEvent event, Game game) { + boolean caught = false; +// List srEffects = GetApplicableSelfReplacementEffects(event, game); +// +// if (srEffects.size() > 0) { +// if (srEffects.size() == 1) { +// caught = srEffects.get(0).ReplaceEvent(event, game); +// } +// else { +// //TODO: handle multiple +// } +// } + + if (!caught) { + List rEffects = getApplicableReplacementEffects(event, game); + if (rEffects.size() > 0) { + if (rEffects.size() == 1) { + caught = rEffects.get(0).replaceEvent(event, game); + } + else { + Player player = game.getPlayer(event.getPlayerId()); + caught = rEffects.get(player.chooseEffect(rEffects, game)).replaceEvent(event, game); + } + } + } + +// if (!caught) { +// List pEffects = GetApplicablePreventionEffects(event, game); +// if (pEffects.size() > 0) { +// if (pEffects.size() == 1) { +// caught = pEffects.get(0).ReplaceEvent(event, game); +// } +// else { +// //TODO: handle multiple +// } +// } +// } + + return caught; + } + + //20091005 - 613 + public void apply(Game game) { + removeInactiveEffects(game); + List layeredEffects = getLayeredEffects(); + for (ContinuousEffect effect: layeredEffects) { + effect.apply(Layer.CopyEffects_1, SubLayer.CharacteristicDefining_7a, game); + } + for (ContinuousEffect effect: layeredEffects) { + effect.apply(Layer.CopyEffects_1, SubLayer.NA, game); + } + for (ContinuousEffect effect: layeredEffects) { + effect.apply(Layer.ControlChangingEffects_2, SubLayer.CharacteristicDefining_7a, game); + } + for (ContinuousEffect effect: layeredEffects) { + effect.apply(Layer.ControlChangingEffects_2, SubLayer.NA, game); + } + for (ContinuousEffect effect: layeredEffects) { + effect.apply(Layer.TextChangingEffects_3, SubLayer.CharacteristicDefining_7a, game); + } + for (ContinuousEffect effect: layeredEffects) { + effect.apply(Layer.TextChangingEffects_3, SubLayer.NA, game); + } + for (ContinuousEffect effect: layeredEffects) { + effect.apply(Layer.TypeChangingEffects_4, SubLayer.CharacteristicDefining_7a, game); + } + for (ContinuousEffect effect: layeredEffects) { + effect.apply(Layer.TypeChangingEffects_4, SubLayer.NA, game); + } + for (ContinuousEffect effect: layeredEffects) { + effect.apply(Layer.ColorChangingEffects_5, SubLayer.CharacteristicDefining_7a, game); + } + for (ContinuousEffect effect: layeredEffects) { + effect.apply(Layer.ColorChangingEffects_5, SubLayer.NA, game); + } + for (ContinuousEffect effect: layeredEffects) { + effect.apply(Layer.AbilityAddingRemovingEffects_6, SubLayer.CharacteristicDefining_7a, game); + } + for (ContinuousEffect effect: layeredEffects) { + effect.apply(Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, game); + } + for (ContinuousEffect effect: layeredEffects) { + effect.apply(Layer.PTChangingEffects_7, SubLayer.CharacteristicDefining_7a, game); + } + for (ContinuousEffect effect: layeredEffects) { + effect.apply(Layer.PTChangingEffects_7, SubLayer.SetPT_7b, game); + } + applyCounters(game); + for (ContinuousEffect effect: layeredEffects) { + effect.apply(Layer.PTChangingEffects_7, SubLayer.ModifyPT_7c, game); + } + for (ContinuousEffect effect: layeredEffects) { + effect.apply(Layer.PTChangingEffects_7, SubLayer.Counters_7d, game); + } + for (ContinuousEffect effect: layeredEffects) { + effect.apply(Layer.PTChangingEffects_7, SubLayer.SwitchPT_e, game); + } + for (ContinuousEffect effect: layeredEffects) { + effect.apply(Layer.PlayerEffects, SubLayer.NA, game); + } + for (ContinuousEffect effect: layeredEffects) { + effect.apply(Layer.RulesEffects, SubLayer.NA, game); + } + } + + protected void applyCounters(Game game) { + for (Permanent permanent: game.getBattlefield().getActivePermanents(CardType.CREATURE)) { + for (BoostCounter counter: permanent.getCounters().getBoostCounters()) { + permanent.addPower(counter.getPower() * counter.getCount()); + permanent.addToughness(counter.getToughness() * counter.getCount()); + } + } + } + + public String getText() { + StringBuilder sbText = new StringBuilder(); + for (ContinuousEffect effect: effects) { + sbText.append(effect.getText() + " "); + } + return sbText.toString(); + } + + public void addEffect(ContinuousEffect effect) { + effects.add(effect); + } + + public boolean effectExists(UUID abilityId) { + for (ContinuousEffect effect: effects) { + if (effect.getSource().getId().equals(abilityId)) + return true; + } + return false; + } + +} + +class TimestampSorter implements Comparator { + @Override + public int compare(ContinuousEffect one, ContinuousEffect two) { + return one.getTimestamp().compareTo(two.getTimestamp()); + } +} diff --git a/Mage/src/mage/abilities/effects/Effect.java b/Mage/src/mage/abilities/effects/Effect.java new file mode 100644 index 00000000000..33e010128ef --- /dev/null +++ b/Mage/src/mage/abilities/effects/Effect.java @@ -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.abilities.effects; + +import java.io.Serializable; +import java.util.UUID; +import mage.Constants.Outcome; +import mage.abilities.Ability; +import mage.game.Game; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public interface Effect extends Serializable { + + public UUID getId(); + public String getText(); + public boolean apply(Game game); + public Ability getSource(); + public Outcome getOutcome(); + public void setSource(Ability ability); + +} diff --git a/Mage/src/mage/abilities/effects/EffectImpl.java b/Mage/src/mage/abilities/effects/EffectImpl.java new file mode 100644 index 00000000000..9bf22c7b0c5 --- /dev/null +++ b/Mage/src/mage/abilities/effects/EffectImpl.java @@ -0,0 +1,75 @@ +/* +* 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; + +import java.util.UUID; +import mage.Constants.Outcome; +import mage.abilities.Ability; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public abstract class EffectImpl implements Effect { + + protected UUID id; + protected String text = ""; + protected Ability source; + protected Outcome outcome; + + public EffectImpl(Outcome outcome) { + this.id = UUID.randomUUID(); + this.outcome = outcome; + } + + @Override + public String getText() { + return text; + } + + @Override + public Ability getSource() { + return source; + } + + @Override + public void setSource(Ability ability) { + this.source = ability; + } + + @Override + public UUID getId() { + return id; + } + + @Override + public Outcome getOutcome() { + return outcome; + } +} diff --git a/Mage/src/mage/abilities/effects/Effects.java b/Mage/src/mage/abilities/effects/Effects.java new file mode 100644 index 00000000000..a3eb482454c --- /dev/null +++ b/Mage/src/mage/abilities/effects/Effects.java @@ -0,0 +1,75 @@ +/* +* 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; + +import java.util.ArrayList; +import mage.Constants.Outcome; +import mage.abilities.Ability; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class Effects extends ArrayList { + + private Ability source; + + public Effects(Ability ability) { + this.source = ability; + } + + public String getText() { + StringBuilder sbText = new StringBuilder(); + for (Effect effect: this) { + sbText.append(effect.getText() + ". "); + } + return sbText.toString(); + } + + public void setSource(Ability ability) { + this.source = ability; + for (Effect effect: this) { + effect.setSource(ability); + } + } + + @Override + public boolean add(Effect effect) { + effect.setSource(source); + return super.add(effect); + } + + public boolean hasOutcome(Outcome outcome) { + for (Effect effect: this) { + if (effect.getOutcome() == outcome) + return true; + } + return false; + } +} diff --git a/Mage/src/mage/abilities/effects/EntersBattlefieldEffect.java b/Mage/src/mage/abilities/effects/EntersBattlefieldEffect.java new file mode 100644 index 00000000000..c87beb4044d --- /dev/null +++ b/Mage/src/mage/abilities/effects/EntersBattlefieldEffect.java @@ -0,0 +1,98 @@ +/* +* 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; + +import mage.Constants.Duration; +import mage.Constants.Layer; +import mage.Constants.SubLayer; +import mage.Constants.Zone; +import mage.abilities.Ability; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.events.GameEvent.EventType; +import mage.game.events.ZoneChangeEvent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class EntersBattlefieldEffect extends ReplacementEffectImpl { + + protected Effects baseEffects = new Effects(null); + + public EntersBattlefieldEffect(Effect baseEffect) { + super(Duration.OneShot, baseEffect.getOutcome()); + this.baseEffects.add(baseEffect); + } + + @Override + public boolean applies(GameEvent event, Game game) { + if (event.getType() == EventType.ZONE_CHANGE && event.getTargetId().equals(this.source.getSourceId())) { + ZoneChangeEvent zEvent = (ZoneChangeEvent)event; + if (zEvent.getToZone() == Zone.BATTLEFIELD) + return true; + } + return false; + } + + @Override + public boolean apply(Game game) { + for (Effect effect: baseEffects) { + if (effect instanceof ContinuousEffect) { + game.addEffect((ContinuousEffect) effect); + } + else + effect.apply(game); + } + return true; + } + + @Override + public boolean replaceEvent(GameEvent event, Game game) { + return apply(game); + } + + + @Override + public void setSource(Ability source) { + this.source = source; + baseEffects.setSource(source); + } + + @Override + public String getText() { + return "When {this} enters the battlefield, " + baseEffects.getText(); + } + + @Override + public boolean apply(Layer layer, SubLayer sublayer, Game game) { + throw new UnsupportedOperationException("Not supported yet."); + } + +} diff --git a/Mage/src/mage/abilities/effects/OneShotEffect.java b/Mage/src/mage/abilities/effects/OneShotEffect.java new file mode 100644 index 00000000000..7fc27872861 --- /dev/null +++ b/Mage/src/mage/abilities/effects/OneShotEffect.java @@ -0,0 +1,43 @@ +/* +* 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; + +import mage.Constants.Outcome; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public abstract class OneShotEffect extends EffectImpl { + + public OneShotEffect(Outcome outcome) { + super(outcome); + } + +} diff --git a/Mage/src/mage/abilities/effects/ReplacementEffect.java b/Mage/src/mage/abilities/effects/ReplacementEffect.java new file mode 100644 index 00000000000..3a00ad212d5 --- /dev/null +++ b/Mage/src/mage/abilities/effects/ReplacementEffect.java @@ -0,0 +1,44 @@ +/* +* 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; + +import mage.game.Game; +import mage.game.events.GameEvent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public interface ReplacementEffect extends ContinuousEffect { + + public boolean replaceEvent(GameEvent event, Game game); + public boolean applies(GameEvent event, Game game); + boolean isUsed(); + +} diff --git a/Mage/src/mage/abilities/effects/ReplacementEffectImpl.java b/Mage/src/mage/abilities/effects/ReplacementEffectImpl.java new file mode 100644 index 00000000000..bd652aea722 --- /dev/null +++ b/Mage/src/mage/abilities/effects/ReplacementEffectImpl.java @@ -0,0 +1,51 @@ +/* +* 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; + +import mage.Constants.Duration; +import mage.Constants.Outcome; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public abstract class ReplacementEffectImpl extends ContinuousEffectImpl implements ReplacementEffect { + + protected boolean used = false; + + public ReplacementEffectImpl(Duration duration, Outcome outcome) { + super(duration, outcome); + } + + @Override + public boolean isUsed() { + return used; + } + +} diff --git a/Mage/src/mage/abilities/effects/WhileControlsContinuousEffect.java b/Mage/src/mage/abilities/effects/WhileControlsContinuousEffect.java new file mode 100644 index 00000000000..b84e0cba4ed --- /dev/null +++ b/Mage/src/mage/abilities/effects/WhileControlsContinuousEffect.java @@ -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.effects; + +import mage.Constants.Duration; +import mage.Constants.Layer; +import mage.Constants.Outcome; +import mage.Constants.SubLayer; +import mage.abilities.effects.ContinuousEffectImpl; +import mage.filter.FilterPermanent; +import mage.game.Game; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public abstract class WhileControlsContinuousEffect extends ContinuousEffectImpl { + + protected FilterPermanent filter; + + public WhileControlsContinuousEffect(Duration duration, Layer layer, SubLayer sublayer, FilterPermanent filter, Outcome outcome) { + super(duration, outcome); + this.filter = filter; + this.layer = layer; + this.sublayer = sublayer; + } + + @Override + public boolean apply(Game game) { + filter.getControllerId().clear(); + filter.getControllerId().add(this.source.getControllerId()); + if (game.getBattlefield().count(filter) > 0) { + return applyEffect(game); + } + return false; + } + + protected abstract boolean applyEffect(Game game); + +} diff --git a/Mage/src/mage/abilities/effects/common/AddPlusOneCountersSourceEffect.java b/Mage/src/mage/abilities/effects/common/AddPlusOneCountersSourceEffect.java new file mode 100644 index 00000000000..204df50f79d --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/AddPlusOneCountersSourceEffect.java @@ -0,0 +1,67 @@ +/* +* 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.Constants.Outcome; +import mage.abilities.effects.OneShotEffect; +import mage.counters.PlusOneCounter; +import mage.game.Game; +import mage.game.permanent.Permanent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class AddPlusOneCountersSourceEffect extends OneShotEffect { + + private int amount; + + public AddPlusOneCountersSourceEffect(int amount) { + super(Outcome.BoostCreature); + this.amount = amount; + } + + @Override + public boolean apply(Game game) { + Permanent permanent = game.getPermanent(this.source.getSourceId()); + if (permanent != null) { + permanent.getCounters().addCounter(new PlusOneCounter(amount)); + } + return true; + } + + @Override + public String getText() { + if (amount > 1) + return "put " + Integer.toString(amount) + " +1/+1 counters on {this}"; + else + return "put a +1/+1 counter on {this}"; + } + +} diff --git a/Mage/src/mage/abilities/effects/common/BoostControlledEOTEffect.java b/Mage/src/mage/abilities/effects/common/BoostControlledEOTEffect.java new file mode 100644 index 00000000000..4df23af89c8 --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/BoostControlledEOTEffect.java @@ -0,0 +1,69 @@ +/* +* 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.Constants.CardType; +import mage.Constants.Duration; +import mage.Constants.Layer; +import mage.Constants.Outcome; +import mage.Constants.SubLayer; +import mage.abilities.effects.ContinuousEffectImpl; +import mage.game.Game; +import mage.game.permanent.Permanent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class BoostControlledEOTEffect extends ContinuousEffectImpl { + + private int power; + private int toughness; + + public BoostControlledEOTEffect(int power, int toughness) { + super(Duration.EndOfTurn, Layer.PTChangingEffects_7, SubLayer.ModifyPT_7c, Outcome.BoostCreature); + this.power = power; + this.toughness = toughness; + } + + @Override + public boolean apply(Game game) { + for (Permanent perm: game.getBattlefield().getActivePermanents(this.source.getControllerId(), CardType.CREATURE)) { + perm.addPower(power); + perm.addToughness(toughness); + } + return true; + } + + @Override + public String getText() { + return "Creatures you control get " + String.format("%1$+d/%2$+d", power, toughness) + " until end of turn."; + } + +} diff --git a/Mage/src/mage/abilities/effects/common/BoostControlledEffect.java b/Mage/src/mage/abilities/effects/common/BoostControlledEffect.java new file mode 100644 index 00000000000..2ac9d003410 --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/BoostControlledEffect.java @@ -0,0 +1,94 @@ +/* +* 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.Constants.CardType; +import mage.Constants.Duration; +import mage.Constants.Layer; +import mage.Constants.Outcome; +import mage.Constants.SubLayer; +import mage.abilities.effects.ContinuousEffectImpl; +import mage.filter.common.FilterCreaturePermanent; +import mage.game.Game; +import mage.game.permanent.Permanent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class BoostControlledEffect extends ContinuousEffectImpl { + + private int power; + private int toughness; + protected FilterCreaturePermanent filter; + + public BoostControlledEffect(int power, int toughness, Duration duration) { + this(power, toughness, duration, null); + } + + public BoostControlledEffect(int power, int toughness, Duration duration, FilterCreaturePermanent filter) { + super(duration, Layer.PTChangingEffects_7, SubLayer.ModifyPT_7c, Outcome.BoostCreature); + this.power = power; + this.toughness = toughness; + this.filter = filter; + } + + @Override + public boolean apply(Game game) { + if (filter != null) { + filter.getControllerId().clear(); + filter.getControllerId().add(this.source.getControllerId()); + for (Permanent perm: game.getBattlefield().getActivePermanents(filter)) { + perm.addPower(power); + perm.addToughness(toughness); + } + } + else { + for (Permanent perm: game.getBattlefield().getActivePermanents(this.source.getControllerId(), CardType.CREATURE)) { + perm.addPower(power); + perm.addToughness(toughness); + } + } + return true; + } + + @Override + public String getText() { + StringBuilder sb = new StringBuilder(); + if (filter == null) + sb.append("Creatures"); + else + sb.append(filter.getMessage()); + sb.append(" you control get "); + sb.append(String.format("%1$+d/%2$+d", power, toughness)); + sb.append((duration==Duration.EndOfTurn?" until end of turn":"")); + return sb.toString(); + } + +} diff --git a/Mage/src/mage/abilities/effects/common/BoostSourceEOTEffect.java b/Mage/src/mage/abilities/effects/common/BoostSourceEOTEffect.java new file mode 100644 index 00000000000..ea2298453fd --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/BoostSourceEOTEffect.java @@ -0,0 +1,70 @@ +/* +* 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.Constants.Duration; +import mage.Constants.Layer; +import mage.Constants.Outcome; +import mage.Constants.SubLayer; +import mage.abilities.effects.ContinuousEffectImpl; +import mage.game.Game; +import mage.game.permanent.Permanent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class BoostSourceEOTEffect extends ContinuousEffectImpl { + + private int power; + private int toughness; + + public BoostSourceEOTEffect(int power, int toughness) { + super(Duration.EndOfTurn, Layer.PTChangingEffects_7, SubLayer.ModifyPT_7c, Outcome.BoostCreature); + this.power = power; + this.toughness = toughness; + } + + @Override + public boolean apply(Game game) { + Permanent target = (Permanent) game.getPermanent(this.source.getSourceId()); + if (target != null) { + target.addPower(power); + target.addToughness(toughness); + return true; + } + return false; + } + + @Override + public String getText() { + return "{this} gets " + String.format("%1$+d/%2$+d", power, toughness) + " until end of turn"; + } + +} diff --git a/Mage/src/mage/abilities/effects/common/BoostSourceWhileControlsEffect.java b/Mage/src/mage/abilities/effects/common/BoostSourceWhileControlsEffect.java new file mode 100644 index 00000000000..4b6c6d19636 --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/BoostSourceWhileControlsEffect.java @@ -0,0 +1,69 @@ +/* +* 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.abilities.effects.WhileControlsContinuousEffect; +import mage.Constants.Duration; +import mage.Constants.Layer; +import mage.Constants.Outcome; +import mage.Constants.SubLayer; +import mage.filter.FilterPermanent; +import mage.game.Game; +import mage.game.permanent.Permanent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class BoostSourceWhileControlsEffect extends WhileControlsContinuousEffect { + + private int power; + private int toughness; + + public BoostSourceWhileControlsEffect(FilterPermanent filter, int power, int toughness) { + super(Duration.WhileInPlay, Layer.PTChangingEffects_7, SubLayer.ModifyPT_7c, filter, Outcome.BoostCreature); + this.power = power; + this.toughness = toughness; + } + + @Override + protected boolean applyEffect(Game game) { + Permanent permanent = game.getPermanent(this.source.getSourceId()); + if (permanent != null) { + permanent.addPower(power); + permanent.addToughness(toughness); + } + return true; + } + + @Override + public String getText() { + return "{this} gets " + String.format("%1$+d/%2$+d", power, toughness) + " as long as you control a " + filter.getName(); + } +} diff --git a/Mage/src/mage/abilities/effects/common/CantCounterControlledEffect.java b/Mage/src/mage/abilities/effects/common/CantCounterControlledEffect.java new file mode 100644 index 00000000000..2e1a317902f --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/CantCounterControlledEffect.java @@ -0,0 +1,80 @@ +/* +* 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.Constants.Duration; +import mage.Constants.Outcome; +import mage.abilities.effects.ReplacementEffectImpl; +import mage.filter.FilterSpell; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.events.GameEvent.EventType; +import mage.game.stack.Spell; +import mage.game.stack.StackObject; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class CantCounterControlledEffect extends ReplacementEffectImpl { + + private FilterSpell filter; + + public CantCounterControlledEffect(FilterSpell filter) { + super(Duration.OneShot, Outcome.Benefit); + this.filter = filter; + } + + public boolean apply(Game game) { + return true; + } + + public boolean replaceEvent(GameEvent event, Game game) { + return true; + } + + public boolean applies(GameEvent event, Game game) { + if (event.getType() == EventType.COUNTER) { + filter.getControllerId().clear(); + filter.getControllerId().add(this.source.getControllerId()); + StackObject stackObject = game.getStack().getStackObject(event.getTargetId()); + if (stackObject instanceof Spell) { + if (filter.match((Spell) stackObject)) + return true; + } + } + return false; + } + + @Override + public String getText() { + return filter.getMessage() + " can't be countered"; + } + +} diff --git a/Mage/src/mage/abilities/effects/common/CantCounterSourceEffect.java b/Mage/src/mage/abilities/effects/common/CantCounterSourceEffect.java new file mode 100644 index 00000000000..92c270ee851 --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/CantCounterSourceEffect.java @@ -0,0 +1,67 @@ +/* +* 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.Constants.Duration; +import mage.Constants.Outcome; +import mage.abilities.effects.ReplacementEffectImpl; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.events.GameEvent.EventType; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class CantCounterSourceEffect extends ReplacementEffectImpl { + + public CantCounterSourceEffect() { + super(Duration.OneShot, Outcome.Benefit); + } + + public boolean apply(Game game) { + return true; + } + + public boolean replaceEvent(GameEvent event, Game game) { + return true; + } + + public boolean applies(GameEvent event, Game game) { + if (event.getType() == EventType.COUNTER && event.getTargetId().equals(source.getSourceId())) + return true; + return false; + } + + @Override + public String getText() { + return "{this} can't be countered"; + } + +} diff --git a/Mage/src/mage/abilities/effects/common/CounterTargetEffect.java b/Mage/src/mage/abilities/effects/common/CounterTargetEffect.java new file mode 100644 index 00000000000..3cdd33f472f --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/CounterTargetEffect.java @@ -0,0 +1,54 @@ +/* +* 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.Constants.Outcome; +import mage.abilities.effects.OneShotEffect; +import mage.game.Game; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class CounterTargetEffect extends OneShotEffect { + + public CounterTargetEffect() { + super(Outcome.Detriment); + } + + public boolean apply(Game game) { + return game.getStack().counter(this.source.getFirstTarget(), source.getSourceId(), game); + } + + @Override + public String getText() { + return "Counter target " + this.source.getTargets().get(0).getTargetName(); + } + +} diff --git a/Mage/src/mage/abilities/effects/common/CreateTokenEffect.java b/Mage/src/mage/abilities/effects/common/CreateTokenEffect.java new file mode 100644 index 00000000000..227c0c504cd --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/CreateTokenEffect.java @@ -0,0 +1,72 @@ +/* +* 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.Constants.Outcome; +import mage.abilities.effects.OneShotEffect; +import mage.game.Game; +import mage.game.permanent.token.Token; +import mage.players.Player; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class CreateTokenEffect extends OneShotEffect { + + private Token token; + private int amount; + + public CreateTokenEffect(Token token) { + this(token, 1); + } + + public CreateTokenEffect(Token token, int amount) { + super(Outcome.PutCreatureInPlay); + this.token = token; + this.amount = amount; + if (amount == 1) { + text = "put a " + token.getDescription(); + } + else { + text = "put " + Integer.toString(amount) + " " + token.getDescription(); + } + text += " onto the battlefield"; + } + + @Override + public boolean apply(Game game) { + Player controller = game.getPlayer(this.source.getControllerId()); + for (int i = 0; i < amount; i++) { + controller.putOntoBattlefield(token, game); + } + return true; + } + +} diff --git a/Mage/src/mage/abilities/effects/common/DamageTargetEffect.java b/Mage/src/mage/abilities/effects/common/DamageTargetEffect.java new file mode 100644 index 00000000000..6cb13e0b292 --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/DamageTargetEffect.java @@ -0,0 +1,70 @@ +/* +* 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.Constants.Outcome; +import mage.abilities.effects.OneShotEffect; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class DamageTargetEffect extends OneShotEffect { + + protected int amount; + + public DamageTargetEffect(int amount) { + super(Outcome.Damage); + this.amount = amount; + } + + @Override + public boolean apply(Game game) { + Permanent permanent = game.getPermanent(this.source.getFirstTarget()); + if (permanent != null) { + permanent.damage(amount, this.source.getSourceId(), game); + return true; + } + Player player = game.getPlayer(this.source.getFirstTarget()); + if (player != null) { + player.damage(amount, this.source.getSourceId(), game); + return true; + } + return false; + } + + @Override + public String getText() { + return "{source} deals " + Integer.toString(amount) + " damage to target " + this.source.getTargets().get(0).getTargetName(); + } + +} diff --git a/Mage/src/mage/abilities/effects/common/DestroyAllControlledTargetEffect.java b/Mage/src/mage/abilities/effects/common/DestroyAllControlledTargetEffect.java new file mode 100644 index 00000000000..b416a35c695 --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/DestroyAllControlledTargetEffect.java @@ -0,0 +1,65 @@ +/* +* 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.Constants.Outcome; +import mage.abilities.effects.OneShotEffect; +import mage.filter.FilterPermanent; +import mage.game.Game; +import mage.game.permanent.Permanent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class DestroyAllControlledTargetEffect extends OneShotEffect { + + private FilterPermanent filter; + + public DestroyAllControlledTargetEffect(FilterPermanent filter) { + super(Outcome.DestroyPermanent); + this.filter = filter; + } + + public boolean apply(Game game) { + filter.getControllerId().clear(); + filter.getControllerId().add(this.source.getFirstTarget()); + filter.setNotController(false); + for (Permanent permanent: game.getBattlefield().getActivePermanents(filter)) { + permanent.destroy(this.source.getSourceId(), game, false); + } + return true; + } + + @Override + public String getText() { + return "Destroy all " + filter.getMessage() + " controlled by target player"; + } + +} diff --git a/Mage/src/mage/abilities/effects/common/DestroyAllEffect.java b/Mage/src/mage/abilities/effects/common/DestroyAllEffect.java new file mode 100644 index 00000000000..1359d671882 --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/DestroyAllEffect.java @@ -0,0 +1,62 @@ +/* +* 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.Constants.Outcome; +import mage.abilities.effects.OneShotEffect; +import mage.filter.FilterPermanent; +import mage.game.Game; +import mage.game.permanent.Permanent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class DestroyAllEffect extends OneShotEffect { + + private FilterPermanent filter; + + public DestroyAllEffect(FilterPermanent filter) { + super(Outcome.DestroyPermanent); + this.filter = filter; + } + + public boolean apply(Game game) { + for (Permanent permanent: game.getBattlefield().getActivePermanents(filter)) { + permanent.destroy(this.source.getSourceId(), game, false); + } + return true; + } + + @Override + public String getText() { + return "Destroy all " + filter.getMessage(); + } + +} diff --git a/Mage/src/mage/abilities/effects/common/DestroyAllNamedPermanentsEffect.java b/Mage/src/mage/abilities/effects/common/DestroyAllNamedPermanentsEffect.java new file mode 100644 index 00000000000..1036fb0a207 --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/DestroyAllNamedPermanentsEffect.java @@ -0,0 +1,65 @@ +/* +* 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.Constants.Outcome; +import mage.abilities.effects.OneShotEffect; +import mage.game.Game; +import mage.game.permanent.Permanent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class DestroyAllNamedPermanentsEffect extends OneShotEffect { + + public DestroyAllNamedPermanentsEffect() { + super(Outcome.DestroyPermanent); + } + + @Override + public boolean apply(Game game) { + Permanent permanent = game.getPermanent(this.source.getFirstTarget()); + String name = permanent.getName(); + + permanent.destroy(this.source.getSourceId(), game, false); + for (Permanent perm: game.getBattlefield().getActivePermanents()) { + if (perm.getName().equals(name)) + perm.destroy(this.source.getSourceId(), game, false); + } + + return true; + } + + @Override + public String getText() { + return "Destroy target " + this.source.getTargets().get(0).getTargetName() + " and all other permanents with the same name as that permanent"; + } + +} diff --git a/Mage/src/mage/abilities/effects/common/DestroyNoRegenTargetEffect.java b/Mage/src/mage/abilities/effects/common/DestroyNoRegenTargetEffect.java new file mode 100644 index 00000000000..d3f377ccd62 --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/DestroyNoRegenTargetEffect.java @@ -0,0 +1,57 @@ +/* +* 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.Constants.Outcome; +import mage.abilities.effects.OneShotEffect; +import mage.game.Game; +import mage.game.permanent.Permanent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class DestroyNoRegenTargetEffect extends OneShotEffect { + + public DestroyNoRegenTargetEffect() { + super(Outcome.DestroyPermanent); + } + + public boolean apply(Game game) { + Permanent permanent = game.getPermanent(this.source.getFirstTarget()); + permanent.destroy(this.source.getSourceId(), game, true); + return true; + } + + @Override + public String getText() { + return "Destroy target " + this.source.getTargets().get(0).getTargetName() + ". It can't be regenerated"; + } + +} diff --git a/Mage/src/mage/abilities/effects/common/DestroyTargetEffect.java b/Mage/src/mage/abilities/effects/common/DestroyTargetEffect.java new file mode 100644 index 00000000000..78989092e78 --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/DestroyTargetEffect.java @@ -0,0 +1,67 @@ +/* +* 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.Constants.Outcome; +import mage.abilities.effects.OneShotEffect; +import mage.game.Game; +import mage.game.permanent.Permanent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class DestroyTargetEffect extends OneShotEffect { + + protected boolean noRegen; + + public DestroyTargetEffect() { + this(false); + } + + public DestroyTargetEffect(boolean noRegen) { + super(Outcome.DestroyPermanent); + this.noRegen = noRegen; + } + + public boolean apply(Game game) { + Permanent permanent = game.getPermanent(this.source.getFirstTarget()); + if (permanent != null) { + permanent.destroy(this.source.getSourceId(), game, noRegen); + return true; + } + return false; + } + + @Override + public String getText() { + return "Destroy target " + source.getTargets().get(0).getTargetName(); + } + +} diff --git a/Mage/src/mage/abilities/effects/common/DiscardTargetEffect.java b/Mage/src/mage/abilities/effects/common/DiscardTargetEffect.java new file mode 100644 index 00000000000..475c8e9a36a --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/DiscardTargetEffect.java @@ -0,0 +1,64 @@ +/* +* 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.Constants.Outcome; +import mage.abilities.effects.OneShotEffect; +import mage.game.Game; +import mage.players.Player; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class DiscardTargetEffect extends OneShotEffect { + + protected int amount; + + public DiscardTargetEffect(int amount) { + super(Outcome.Discard); + this.amount = amount; + } + + @Override + public boolean apply(Game game) { + Player player = game.getPlayer(this.source.getFirstTarget()); + if (player != null) { + player.discard(amount, game); + return true; + } + return false; + } + + @Override + public String getText() { + return "Target player discards " + Integer.toString(amount) + " card" + (amount == 1?"":"s"); + } + +} diff --git a/Mage/src/mage/abilities/effects/common/EntersBattlefieldTappedEffect.java b/Mage/src/mage/abilities/effects/common/EntersBattlefieldTappedEffect.java new file mode 100644 index 00000000000..cfbbd4ff9b6 --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/EntersBattlefieldTappedEffect.java @@ -0,0 +1,47 @@ +/* +* 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.abilities.effects.EntersBattlefieldEffect; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class EntersBattlefieldTappedEffect extends EntersBattlefieldEffect { + + public EntersBattlefieldTappedEffect() { + super(new TapSourceEffect()); + } + + @Override + public String getText() { + return "{this} enters the battlefield tapped"; + } +} diff --git a/Mage/src/mage/abilities/effects/common/ExileSourceEffect.java b/Mage/src/mage/abilities/effects/common/ExileSourceEffect.java new file mode 100644 index 00000000000..3b250fb8c1a --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/ExileSourceEffect.java @@ -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.effects.common; + +import java.io.ObjectStreamException; +import mage.Constants.Outcome; +import mage.abilities.effects.OneShotEffect; +import mage.game.Game; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class ExileSourceEffect extends OneShotEffect { + + private static final ExileSourceEffect fINSTANCE = new ExileSourceEffect(); + + private Object readResolve() throws ObjectStreamException { + return fINSTANCE; + } + + private ExileSourceEffect() { + super(Outcome.Exile); + } + + public static ExileSourceEffect getInstance() { + return fINSTANCE; + } + + @Override + public boolean apply(Game game) { + //this effect is applied when a spell resolves - see Spell.java + return true; + } + + @Override + public String getText() { + return "Exile {this}"; + } +} diff --git a/Mage/src/mage/abilities/effects/common/ExileTargetEffect.java b/Mage/src/mage/abilities/effects/common/ExileTargetEffect.java new file mode 100644 index 00000000000..e1a47479847 --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/ExileTargetEffect.java @@ -0,0 +1,71 @@ +/* +* 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.UUID; +import mage.Constants.Outcome; +import mage.Constants.Zone; +import mage.abilities.effects.OneShotEffect; +import mage.game.Game; +import mage.game.permanent.Permanent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class ExileTargetEffect extends OneShotEffect { + + private String exileZone = null; + private UUID exileId = null; + + public ExileTargetEffect(UUID exileId, String exileZone) { + this(); + this.exileZone = exileZone; + this.exileId = exileId; + } + + public ExileTargetEffect() { + super(Outcome.Exile); + } + + @Override + public boolean apply(Game game) { + Permanent permanent = game.getPermanent(this.source.getFirstTarget()); + if (permanent != null) { + return permanent.moveToExile(exileId, exileZone, game); + } + return false; + } + + @Override + public String getText() { + return "Exile target " + this.source.getTargets().get(0).getTargetName(); + } + +} diff --git a/Mage/src/mage/abilities/effects/common/GainAbilityControlledEOTEffect.java b/Mage/src/mage/abilities/effects/common/GainAbilityControlledEOTEffect.java new file mode 100644 index 00000000000..2812388ac83 --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/GainAbilityControlledEOTEffect.java @@ -0,0 +1,67 @@ +/* +* 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.Constants.CardType; +import mage.Constants.Duration; +import mage.Constants.Layer; +import mage.Constants.Outcome; +import mage.Constants.SubLayer; +import mage.abilities.Ability; +import mage.abilities.effects.ContinuousEffectImpl; +import mage.game.Game; +import mage.game.permanent.Permanent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class GainAbilityControlledEOTEffect extends ContinuousEffectImpl { + + protected Ability ability; + + public GainAbilityControlledEOTEffect(Ability ability) { + super(Duration.EndOfTurn, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.AddAbility); + this.ability = ability; + } + + @Override + public boolean apply(Game game) { + for (Permanent perm: game.getBattlefield().getActivePermanents(this.source.getControllerId(), CardType.CREATURE)) { + perm.addAbility(ability); + } + return true; + } + + @Override + public String getText() { + return "Creatures you control gain " + ability.getRule() + " until end of turn"; + } + +} diff --git a/Mage/src/mage/abilities/effects/common/GainAbilityTargetEOTEffect.java b/Mage/src/mage/abilities/effects/common/GainAbilityTargetEOTEffect.java new file mode 100644 index 00000000000..06feec5cee7 --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/GainAbilityTargetEOTEffect.java @@ -0,0 +1,69 @@ +/* +* 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.Constants.CardType; +import mage.Constants.Duration; +import mage.Constants.Layer; +import mage.Constants.Outcome; +import mage.Constants.SubLayer; +import mage.abilities.Ability; +import mage.abilities.effects.ContinuousEffectImpl; +import mage.game.Game; +import mage.game.permanent.Permanent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class GainAbilityTargetEOTEffect extends ContinuousEffectImpl { + + private Ability ability; + + public GainAbilityTargetEOTEffect(Ability ability) { + super(Duration.EndOfTurn, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.AddAbility); + this.ability = ability; + } + + @Override + public boolean apply(Game game) { + Permanent permanent = game.getPermanent(this.source.getFirstTarget()); + if (permanent != null) { + permanent.addAbility(ability); + return true; + } + return false; + } + + @Override + public String getText() { + return "Target creature gains " + ability.getRule() + " until end of turn"; + } + +} \ No newline at end of file diff --git a/Mage/src/mage/abilities/effects/common/GainControlTargetEOTEffect.java b/Mage/src/mage/abilities/effects/common/GainControlTargetEOTEffect.java new file mode 100644 index 00000000000..80639669730 --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/GainControlTargetEOTEffect.java @@ -0,0 +1,62 @@ +/* +* 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.Constants.Duration; +import mage.Constants.Layer; +import mage.Constants.Outcome; +import mage.Constants.SubLayer; +import mage.abilities.effects.ContinuousEffectImpl; +import mage.game.Game; +import mage.game.permanent.Permanent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class GainControlTargetEOTEffect extends ContinuousEffectImpl { + + public GainControlTargetEOTEffect() { + super(Duration.EndOfTurn, Layer.ControlChangingEffects_2, SubLayer.NA, Outcome.GainControl); + } + + public boolean apply(Game game) { + Permanent permanent = game.getPermanent(this.source.getFirstTarget()); + if (permanent != null) { + permanent.setControllerId(this.source.getControllerId()); + return true; + } + return false; + } + + @Override + public String getText() { + return "Gain control of target " + this.source.getTargets().get(0).getTargetName() + " until end of turn"; + } +} diff --git a/Mage/src/mage/abilities/effects/common/GainLifeEffect.java b/Mage/src/mage/abilities/effects/common/GainLifeEffect.java new file mode 100644 index 00000000000..92624d3b9d0 --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/GainLifeEffect.java @@ -0,0 +1,63 @@ +/* +* 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.Constants.Outcome; +import mage.abilities.effects.OneShotEffect; +import mage.game.Game; +import mage.players.Player; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class GainLifeEffect extends OneShotEffect { + + private int life; + + public GainLifeEffect(int life) { + super(Outcome.GainLife); + this.life = life; + } + + @Override + public boolean apply(Game game) { + Player player = game.getPlayer(this.source.getControllerId()); + if (player != null) { + player.gainLife(life, game); + } + return false; + } + + @Override + public String getText() { + return "you gain " + Integer.toString(life) + " life"; + } + +} diff --git a/Mage/src/mage/abilities/effects/common/ManaEffect.java b/Mage/src/mage/abilities/effects/common/ManaEffect.java new file mode 100644 index 00000000000..1856c774e46 --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/ManaEffect.java @@ -0,0 +1,63 @@ +/* +* 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.Constants.Outcome; +import mage.Mana; +import mage.abilities.effects.OneShotEffect; +import mage.game.Game; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class ManaEffect extends OneShotEffect { + + protected Mana mana; + + public ManaEffect(Mana mana) { + super(Outcome.PutManaInPool); + this.mana = mana; + } + + @Override + public boolean apply(Game game) { + game.getPlayer(this.source.getControllerId()).getManaPool().changeMana(mana); + return true; + } + + @Override + public String getText() { + return "Add " + mana.toString() + " to your mana pool"; + } + + public Mana getMana() { + return mana; + } +} diff --git a/Mage/src/mage/abilities/effects/common/PlayTargetWithoutPayingManaEffect.java b/Mage/src/mage/abilities/effects/common/PlayTargetWithoutPayingManaEffect.java new file mode 100644 index 00000000000..807c267e666 --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/PlayTargetWithoutPayingManaEffect.java @@ -0,0 +1,58 @@ +/* +* 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.Constants.Outcome; +import mage.abilities.effects.OneShotEffect; +import mage.cards.Card; +import mage.game.Game; +import mage.players.Player; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class PlayTargetWithoutPayingManaEffect extends OneShotEffect { + + private Card target; + + public PlayTargetWithoutPayingManaEffect() { + super(Outcome.GainControl); + } + + @Override + public boolean apply(Game game) { + Player controller = game.getPlayer(this.source.getControllerId()); + return controller.cast(target, game, true); + } + + public void setTarget(Card card) { + this.target = card; + } +} diff --git a/Mage/src/mage/abilities/effects/common/ReturnFromExileEffect.java b/Mage/src/mage/abilities/effects/common/ReturnFromExileEffect.java new file mode 100644 index 00000000000..290a629b14b --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/ReturnFromExileEffect.java @@ -0,0 +1,92 @@ +/* +* 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.UUID; +import mage.Constants.Outcome; +import mage.Constants.Zone; +import mage.abilities.effects.OneShotEffect; +import mage.cards.Card; +import mage.game.Game; +import mage.players.Player; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class ReturnFromExileEffect extends OneShotEffect { + + private UUID exileId; + private Zone zone; + + public ReturnFromExileEffect(UUID exileId, Zone zone) { + super(Outcome.PutCardInPlay); + this.exileId = exileId; + this.zone = zone; + } + + public boolean apply(Game game) { + Player player; + for (Card card: game.getExile().getExileZone(exileId).values()) { + player = game.getPlayer(card.getOwnerId()); + switch(zone) { + case BATTLEFIELD: + player.putOntoBattlefield(card, game); + break; + case HAND: + player.putInHand(card, game); + break; + case GRAVEYARD: + player.putInGraveyard(card, game, false); + break; + } + } + game.getExile().getExileZone(exileId).clear(); + return true; + } + + @Override + public String getText() { + StringBuilder sb = new StringBuilder(); + sb.append("return the exiled cards "); + switch(zone) { + case BATTLEFIELD: + sb.append("to the battlefield under its owner's control"); + break; + case HAND: + sb.append("to their owner's hand"); + break; + case GRAVEYARD: + sb.append("to their owner's graveyard"); + break; + } + return sb.toString(); + } + +} diff --git a/Mage/src/mage/abilities/effects/common/SearchLibraryPutInPlayEffect.java b/Mage/src/mage/abilities/effects/common/SearchLibraryPutInPlayEffect.java new file mode 100644 index 00000000000..04967b8ea4d --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/SearchLibraryPutInPlayEffect.java @@ -0,0 +1,112 @@ +/* +* 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.UUID; +import mage.Constants.Outcome; +import mage.abilities.Ability; +import mage.abilities.effects.OneShotEffect; +import mage.cards.Card; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; +import mage.target.common.TargetCardInLibrary; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class SearchLibraryPutInPlayEffect extends OneShotEffect { + + private TargetCardInLibrary target; + private boolean tapped; + + public SearchLibraryPutInPlayEffect(TargetCardInLibrary target) { + this(target, false, Outcome.PutCardInPlay); + } + + public SearchLibraryPutInPlayEffect(TargetCardInLibrary target, boolean tapped) { + this(target, tapped, Outcome.PutCardInPlay); + } + + public SearchLibraryPutInPlayEffect(TargetCardInLibrary target, boolean tapped, Outcome outcome) { + super(outcome); + this.target = target; + this.tapped = tapped; + } + + @Override + public boolean apply(Game game) { + Player player = game.getPlayer(this.source.getControllerId()); + player.searchLibrary(target, game); + if (target.getTargets().size() > 0) { + for (UUID cardId: target.getTargets()) { + Card card = player.getLibrary().remove(cardId); + if (card != null) { + if (player.putOntoBattlefield(card, game)) { + if (tapped) { + Permanent permanent = game.getPermanent(card.getId()); + if (permanent != null) + permanent.setTapped(true); + } + } + } + } + player.shuffleLibrary(game); + } + return true; + } + + @Override + public String getText() { + StringBuilder sb = new StringBuilder(); + sb.append("Search your library for "); + if (target.getNumberOfTargets() == 0 && target.getMaxNumberOfTargets() > 0) { + sb.append("up to "); + sb.append(target.getMaxNumberOfTargets()); + sb.append(" "); + sb.append(target.getTargetName()); + sb.append(", and put them onto the battlefield"); + } + else { + sb.append("a "); + sb.append(target.getTargetName()); + sb.append(", and put it onto the battlefield"); + } + sb.append(". Then shuffle your library"); + return sb.toString(); + } + + @Override + public void setSource(Ability ability) { + super.setSource(ability); + target.setAbility(ability); + } + +} diff --git a/Mage/src/mage/abilities/effects/common/SearchLibraryRevealPutInHandEffect.java b/Mage/src/mage/abilities/effects/common/SearchLibraryRevealPutInHandEffect.java new file mode 100644 index 00000000000..b42b22bc733 --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/SearchLibraryRevealPutInHandEffect.java @@ -0,0 +1,101 @@ +/* + * 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.UUID; +import mage.Constants.Outcome; +import mage.Constants.Zone; +import mage.abilities.Ability; +import mage.abilities.effects.OneShotEffect; +import mage.cards.Card; +import mage.cards.Cards; +import mage.cards.CardsImpl; +import mage.game.Game; +import mage.players.Player; +import mage.target.common.TargetCardInLibrary; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class SearchLibraryRevealPutInHandEffect extends OneShotEffect { + + private TargetCardInLibrary target; + + public SearchLibraryRevealPutInHandEffect(TargetCardInLibrary target) { + super(Outcome.DrawCard); + this.target = target; + } + + @Override + public boolean apply(Game game) { + Player player = game.getPlayer(this.source.getControllerId()); + player.searchLibrary(target, game); + if (target.getTargets().size() > 0) { + Cards revealed = new CardsImpl(Zone.REVEALED); + for (UUID cardId: target.getTargets()) { + Card card = player.getLibrary().remove(cardId); + if (card != null) { + player.putInHand(card, game); + } + } + player.shuffleLibrary(game); + player.revealCards(revealed, game); + } + return true; + } + + @Override + public String getText() { + StringBuilder sb = new StringBuilder(); + sb.append("Search your library for "); + if (target.getNumberOfTargets() == 0 && target.getMaxNumberOfTargets() > 0) { + sb.append("up to "); + sb.append(target.getMaxNumberOfTargets()); + sb.append(" "); + sb.append(target.getTargetName()); + sb.append(", reveal them, and put them into your hand"); + } + else { + sb.append("a "); + sb.append(target.getTargetName()); + sb.append(", reveal that card, and put it into your hand"); + } + sb.append(". Then shuffle your library"); + + return sb.toString(); + } + + @Override + public void setSource(Ability ability) { + super.setSource(ability); + target.setAbility(ability); + } + +} diff --git a/Mage/src/mage/abilities/effects/common/SkipNextUntapTargetEffect.java b/Mage/src/mage/abilities/effects/common/SkipNextUntapTargetEffect.java new file mode 100644 index 00000000000..ce82588e303 --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/SkipNextUntapTargetEffect.java @@ -0,0 +1,71 @@ +/* +* 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.Constants.Duration; +import mage.Constants.Outcome; +import mage.Constants.PhaseStep; +import mage.abilities.effects.ReplacementEffectImpl; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.events.GameEvent.EventType; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class SkipNextUntapTargetEffect extends ReplacementEffectImpl { + + public SkipNextUntapTargetEffect() { + super(Duration.OneUse, Outcome.Detriment); + } + + public boolean apply(Game game) { + return false; + } + + public boolean replaceEvent(GameEvent event, Game game) { + return true; + } + + public boolean applies(GameEvent event, Game game) { + if (game.getStep() == PhaseStep.UNTAP && + event.getType() == EventType.UNTAP && + event.getSourceId().equals(source.getFirstTarget())) { + used = true; + } + return used; + } + + @Override + public String getText() { + return "Target " + source.getTargets().get(0).getTargetName() + " doesn't untap during its controller's next untap step"; + } + +} diff --git a/Mage/src/mage/abilities/effects/common/TapSourceEffect.java b/Mage/src/mage/abilities/effects/common/TapSourceEffect.java new file mode 100644 index 00000000000..ebff9235f67 --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/TapSourceEffect.java @@ -0,0 +1,56 @@ +/* +* 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.Constants.Outcome; +import mage.abilities.effects.OneShotEffect; +import mage.game.Game; +import mage.game.permanent.Permanent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class TapSourceEffect extends OneShotEffect { + + public TapSourceEffect() { + super(Outcome.Tap); + } + + @Override + public boolean apply(Game game) { + Permanent permanent = game.getPermanent(this.source.getSourceId()); + if (permanent != null) { + permanent.setTapped(true); + return true; + } + return false; + } + +} diff --git a/Mage/src/mage/abilities/effects/common/UntapTargetEffect.java b/Mage/src/mage/abilities/effects/common/UntapTargetEffect.java new file mode 100644 index 00000000000..ce61310a646 --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/UntapTargetEffect.java @@ -0,0 +1,71 @@ +/* +* 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.UUID; +import mage.Constants.Outcome; +import mage.abilities.effects.OneShotEffect; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.target.Target; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class UntapTargetEffect extends OneShotEffect { + + public UntapTargetEffect() { + super(Outcome.Untap); + } + + @Override + public boolean apply(Game game) { + for (UUID target: this.source.getTargets().get(0).getTargets()) { + Permanent permanent = game.getPermanent(target); + if (permanent != null) { + permanent.setTapped(false); + } + else { + return false; + } + } + return true; + } + + @Override + public String getText() { + Target target = this.source.getTargets().get(0); + if (target.getNumberOfTargets() > 1) + return "untap " + target.getNumberOfTargets() + " target " + this.source.getTargets().get(0).getTargetName() + "s"; + else + return "untap target " + this.source.getTargets().get(0).getTargetName(); + } + +} diff --git a/Mage/src/mage/abilities/keyword/CascadeAbility.java b/Mage/src/mage/abilities/keyword/CascadeAbility.java new file mode 100644 index 00000000000..97860f0e853 --- /dev/null +++ b/Mage/src/mage/abilities/keyword/CascadeAbility.java @@ -0,0 +1,105 @@ +/* +* 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.CardType; +import mage.Constants.Outcome; +import mage.Constants.Zone; +import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.PlayTargetWithoutPayingManaEffect; +import mage.cards.Card; +import mage.game.ExileZone; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.events.GameEvent.EventType; +import mage.players.Player; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class CascadeAbility extends TriggeredAbilityImpl { + //20091005 - 702.82 + + public CascadeAbility() { + super(Zone.STACK, new CascadeEffect()); + } + + @Override + public void handleEvent(GameEvent event, Game game) { + if (event.getType() == EventType.SPELL_CAST && event.getTargetId().equals(this.getSourceId()) ) { + trigger(game, event.getPlayerId()); + } + } + + @Override + public String getRule() { + return "Cascade"; + } +} + +class CascadeEffect extends OneShotEffect { + + public CascadeEffect() { + super(Outcome.PutCardInPlay); + } + + public boolean apply(Game game) { + Card card; + Player player = game.getPlayer(this.getSource().getControllerId()); + ExileZone exile = game.getExile().createZone(this.source.getSourceId(), player.getName() + " " + this.getSource().getName() + " Cascade"); + int sourceCost = game.getObject(this.source.getSourceId()).getManaCost().convertedManaCost(); + do { + card = player.getLibrary().removeFromTop(game); + if (card == null) + break; + exile.add(card); + } while (card.getCardType().contains(CardType.LAND) || card.getManaCost().convertedManaCost() >= sourceCost); + + if (card != null) { + if (player.chooseUse(outcome, "Use cascade effect on " + card.getName() + "?", game)) { + PlayTargetWithoutPayingManaEffect playEffect = new PlayTargetWithoutPayingManaEffect(); + playEffect.setSource(source); + playEffect.setTarget(card); + playEffect.apply(game); + exile.remove(card.getId()); + } + } + + while (exile.size() > 0) { + card = exile.getRandom(); + exile.remove(card.getId()); + player.getLibrary().putOnBottom(card, game); + } + + return true; + } + +} \ No newline at end of file diff --git a/Mage/src/mage/abilities/keyword/DefenderAbility.java b/Mage/src/mage/abilities/keyword/DefenderAbility.java new file mode 100644 index 00000000000..c0edd13a973 --- /dev/null +++ b/Mage/src/mage/abilities/keyword/DefenderAbility.java @@ -0,0 +1,60 @@ +/* +* 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 java.io.ObjectStreamException; +import mage.Constants.Zone; +import mage.abilities.StaticAbility; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class DefenderAbility extends StaticAbility { + + private static final DefenderAbility fINSTANCE = new DefenderAbility(); + + private Object readResolve() throws ObjectStreamException { + return fINSTANCE; + } + + public static DefenderAbility getInstance() { + return fINSTANCE; + } + + private DefenderAbility() { + super(Zone.BATTLEFIELD, null); + } + + @Override + public String getRule() { + return "Defender"; + } + +} diff --git a/Mage/src/mage/abilities/keyword/DoubleStrikeAbility.java b/Mage/src/mage/abilities/keyword/DoubleStrikeAbility.java new file mode 100644 index 00000000000..b4bfcc14965 --- /dev/null +++ b/Mage/src/mage/abilities/keyword/DoubleStrikeAbility.java @@ -0,0 +1,60 @@ +/* +* 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 java.io.ObjectStreamException; +import mage.Constants.Zone; +import mage.abilities.StaticAbility; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class DoubleStrikeAbility extends StaticAbility { + + private static final DoubleStrikeAbility fINSTANCE = new DoubleStrikeAbility(); + + private Object readResolve() throws ObjectStreamException { + return fINSTANCE; + } + + public static DoubleStrikeAbility getInstance() { + return fINSTANCE; + } + + private DoubleStrikeAbility() { + super(Zone.BATTLEFIELD, null); + } + + @Override + public String getRule() { + return "Double Strike"; + } + +} \ No newline at end of file diff --git a/Mage/src/mage/abilities/keyword/ExaltedAbility.java b/Mage/src/mage/abilities/keyword/ExaltedAbility.java new file mode 100644 index 00000000000..530d23068fc --- /dev/null +++ b/Mage/src/mage/abilities/keyword/ExaltedAbility.java @@ -0,0 +1,97 @@ +/* +* 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.Duration; +import mage.Constants.Layer; +import mage.Constants.Outcome; +import mage.Constants.SubLayer; +import mage.Constants.Zone; +import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.effects.ContinuousEffectImpl; +import mage.game.Game; +import mage.game.combat.Combat; +import mage.game.combat.CombatGroup; +import mage.game.events.GameEvent; +import mage.game.events.GameEvent.EventType; +import mage.game.permanent.Permanent; +import mage.target.common.TargetCreaturePermanent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class ExaltedAbility extends TriggeredAbilityImpl { + + public ExaltedAbility() { + super(Zone.BATTLEFIELD, new ExaltedEffect()); + } + + @Override + public void handleEvent(GameEvent event, Game game) { + if (event.getType() == EventType.DECLARED_ATTACKERS ) { + Combat combat = game.getCombat(); + if (combat.getGroups().size() == 1) { + CombatGroup group = combat.getGroups().get(0); + if (group.getAttackers().size() == 1) { + if (game.getPermanent(group.getAttackers().get(0)).getControllerId().equals(this.controllerId)) { + this.targets.add(new TargetCreaturePermanent()); + this.targets.get(0).getTargets().add(group.getAttackers().get(0)); + trigger(game, event.getPlayerId()); + } + } + } + } + } + + @Override + public String getRule() { + return "Exalted"; + } + +} + +class ExaltedEffect extends ContinuousEffectImpl { + + public ExaltedEffect() { + super(Duration.EndOfTurn, Layer.PTChangingEffects_7, SubLayer.ModifyPT_7c, Outcome.BoostCreature); + } + + @Override + public boolean apply(Game game) { + Permanent permanent = game.getPermanent(this.source.getFirstTarget()); + if (permanent != null) { + permanent.addPower(1); + permanent.addToughness(1); + return true; + } + return false; + } + +} \ No newline at end of file diff --git a/Mage/src/mage/abilities/keyword/FirstStrikeAbility.java b/Mage/src/mage/abilities/keyword/FirstStrikeAbility.java new file mode 100644 index 00000000000..334386999b8 --- /dev/null +++ b/Mage/src/mage/abilities/keyword/FirstStrikeAbility.java @@ -0,0 +1,60 @@ +/* +* 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 java.io.ObjectStreamException; +import mage.Constants.Zone; +import mage.abilities.StaticAbility; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class FirstStrikeAbility extends StaticAbility { + + private static final FirstStrikeAbility fINSTANCE = new FirstStrikeAbility(); + + private Object readResolve() throws ObjectStreamException { + return fINSTANCE; + } + + public static FirstStrikeAbility getInstance() { + return fINSTANCE; + } + + private FirstStrikeAbility() { + super(Zone.BATTLEFIELD, null); + } + + @Override + public String getRule() { + return "First Strike"; + } + +} \ No newline at end of file diff --git a/Mage/src/mage/abilities/keyword/FlyingAbility.java b/Mage/src/mage/abilities/keyword/FlyingAbility.java new file mode 100644 index 00000000000..779fa37f301 --- /dev/null +++ b/Mage/src/mage/abilities/keyword/FlyingAbility.java @@ -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 java.io.ObjectStreamException; +import mage.abilities.EvasionAbilityImpl; +import mage.game.Game; +import mage.game.permanent.Permanent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class FlyingAbility extends EvasionAbilityImpl { + + private static final FlyingAbility fINSTANCE = new FlyingAbility(); + + private Object readResolve() throws ObjectStreamException { + return fINSTANCE; + } + + public static FlyingAbility getInstance() { + return fINSTANCE; + } + + private FlyingAbility() {} + + @Override + public boolean canBlock(Permanent permanent, Game game) { + if (permanent.getAbilities().containsKey(id) || permanent.getAbilities().containsKey(ReachAbility.getInstance().getId())) + return true; + return false; + } + + @Override + public String getRule() { + return "Flying"; + } + +} diff --git a/Mage/src/mage/abilities/keyword/HasteAbility.java b/Mage/src/mage/abilities/keyword/HasteAbility.java new file mode 100644 index 00000000000..3410dc1622a --- /dev/null +++ b/Mage/src/mage/abilities/keyword/HasteAbility.java @@ -0,0 +1,60 @@ +/* +* 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 java.io.ObjectStreamException; +import mage.Constants.Zone; +import mage.abilities.StaticAbility; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class HasteAbility extends StaticAbility { + + private static final HasteAbility fINSTANCE = new HasteAbility(); + + private Object readResolve() throws ObjectStreamException { + return fINSTANCE; + } + + public static HasteAbility getInstance() { + return fINSTANCE; + } + + private HasteAbility() { + super(Zone.BATTLEFIELD, null); + } + + @Override + public String getRule() { + return "Haste"; + } + +} diff --git a/Mage/src/mage/abilities/keyword/KickerAbility.java b/Mage/src/mage/abilities/keyword/KickerAbility.java new file mode 100644 index 00000000000..d0d6c727f5e --- /dev/null +++ b/Mage/src/mage/abilities/keyword/KickerAbility.java @@ -0,0 +1,74 @@ +/* +* 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.StaticAbility; +import mage.abilities.effects.Effect; +import mage.game.Game; +import mage.players.Player; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class KickerAbility extends StaticAbility { + + protected boolean kicked = false; + protected boolean replaces = false; + + public KickerAbility(Effect effect, boolean replaces) { + super(Zone.STACK, effect); + this.replaces = replaces; + } + + @Override + public boolean activate(Game game, boolean noMana) { + Player player = game.getPlayer(this.getControllerId()); + if (player.chooseUse(this.effects.get(0).getOutcome(), "Use kicker " + this.effects.get(0).getText() + "?", game)) { + kicked = super.activate(game, noMana); + return kicked; + } + return false; + } + + public boolean isKicked() { + return kicked; + } + + public boolean isReplaces() { + return replaces; + } + + @Override + public String getRule() { + return "Kicker " + costs.getText() + ":" + effects.getText() + (replaces?" instead":""); + } + +} diff --git a/Mage/src/mage/abilities/keyword/LifelinkAbility.java b/Mage/src/mage/abilities/keyword/LifelinkAbility.java new file mode 100644 index 00000000000..9ca355346f7 --- /dev/null +++ b/Mage/src/mage/abilities/keyword/LifelinkAbility.java @@ -0,0 +1,60 @@ +/* +* 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 java.io.ObjectStreamException; +import mage.Constants.Zone; +import mage.abilities.StaticAbility; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class LifelinkAbility extends StaticAbility { + + private static final LifelinkAbility fINSTANCE = new LifelinkAbility(); + + private Object readResolve() throws ObjectStreamException { + return fINSTANCE; + } + + public static LifelinkAbility getInstance() { + return fINSTANCE; + } + + private LifelinkAbility() { + super(Zone.ALL, null); + } + + @Override + public String getRule() { + return "Lifelink"; + } + +} diff --git a/Mage/src/mage/abilities/keyword/PhasingAbility.java b/Mage/src/mage/abilities/keyword/PhasingAbility.java new file mode 100644 index 00000000000..16fdbcf99b5 --- /dev/null +++ b/Mage/src/mage/abilities/keyword/PhasingAbility.java @@ -0,0 +1,60 @@ +/* +* 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 java.io.ObjectStreamException; +import mage.Constants.Zone; +import mage.abilities.StaticAbility; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class PhasingAbility extends StaticAbility { + + private static final PhasingAbility fINSTANCE = new PhasingAbility(); + + private Object readResolve() throws ObjectStreamException { + return fINSTANCE; + } + + public static PhasingAbility getInstance() { + return fINSTANCE; + } + + private PhasingAbility() { + super(Zone.BATTLEFIELD, null); + } + + @Override + public String getRule() { + return "Phasing"; + } + +} diff --git a/Mage/src/mage/abilities/keyword/ProtectionAbility.java b/Mage/src/mage/abilities/keyword/ProtectionAbility.java new file mode 100644 index 00000000000..085631d0e37 --- /dev/null +++ b/Mage/src/mage/abilities/keyword/ProtectionAbility.java @@ -0,0 +1,61 @@ +/* +* 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.MageObject; +import mage.abilities.StaticAbility; +import mage.filter.Filter; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class ProtectionAbility extends StaticAbility { + + protected Filter filter; + + public ProtectionAbility(Filter filter) { + super(Zone.BATTLEFIELD, null); + this.filter = filter; + } + + @Override + public String getRule() { + return "Protection from " + filter.getMessage(); + } + + public boolean canTarget(MageObject source) { + return !filter.match(source); + } + + public Filter getFilter() { + return filter; + } +} diff --git a/Mage/src/mage/abilities/keyword/ReachAbility.java b/Mage/src/mage/abilities/keyword/ReachAbility.java new file mode 100644 index 00000000000..7ca1ce295fc --- /dev/null +++ b/Mage/src/mage/abilities/keyword/ReachAbility.java @@ -0,0 +1,60 @@ +/* +* 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 java.io.ObjectStreamException; +import mage.Constants.Zone; +import mage.abilities.StaticAbility; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class ReachAbility extends StaticAbility { + + private static final ReachAbility fINSTANCE = new ReachAbility(); + + private Object readResolve() throws ObjectStreamException { + return fINSTANCE; + } + + public static ReachAbility getInstance() { + return fINSTANCE; + } + + private ReachAbility() { + super(Zone.BATTLEFIELD, null); + } + + @Override + public String getRule() { + return "Reach"; + } + +} diff --git a/Mage/src/mage/abilities/keyword/ShroudAbility.java b/Mage/src/mage/abilities/keyword/ShroudAbility.java new file mode 100644 index 00000000000..3514094494c --- /dev/null +++ b/Mage/src/mage/abilities/keyword/ShroudAbility.java @@ -0,0 +1,60 @@ +/* +* 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 java.io.ObjectStreamException; +import mage.Constants.Zone; +import mage.abilities.StaticAbility; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class ShroudAbility extends StaticAbility { + + private static final ShroudAbility fINSTANCE = new ShroudAbility(); + + private Object readResolve() throws ObjectStreamException { + return fINSTANCE; + } + + public static ShroudAbility getInstance() { + return fINSTANCE; + } + + private ShroudAbility() { + super(Zone.BATTLEFIELD, null); + } + + @Override + public String getRule() { + return "Shroud"; + } + +} diff --git a/Mage/src/mage/abilities/keyword/TrampleAbility.java b/Mage/src/mage/abilities/keyword/TrampleAbility.java new file mode 100644 index 00000000000..4502939fa50 --- /dev/null +++ b/Mage/src/mage/abilities/keyword/TrampleAbility.java @@ -0,0 +1,60 @@ +/* +* 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 java.io.ObjectStreamException; +import mage.Constants.Zone; +import mage.abilities.StaticAbility; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class TrampleAbility extends StaticAbility { + + private static final TrampleAbility fINSTANCE = new TrampleAbility(); + + private Object readResolve() throws ObjectStreamException { + return fINSTANCE; + } + + public static TrampleAbility getInstance() { + return fINSTANCE; + } + + private TrampleAbility() { + super(Zone.BATTLEFIELD, null); + } + + @Override + public String getRule() { + return "Trample"; + } + +} \ No newline at end of file diff --git a/Mage/src/mage/abilities/keyword/UnblockableAbility.java b/Mage/src/mage/abilities/keyword/UnblockableAbility.java new file mode 100644 index 00000000000..9b265655180 --- /dev/null +++ b/Mage/src/mage/abilities/keyword/UnblockableAbility.java @@ -0,0 +1,64 @@ +/* +* 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 java.io.ObjectStreamException; +import mage.abilities.EvasionAbilityImpl; +import mage.game.Game; +import mage.game.permanent.Permanent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class UnblockableAbility extends EvasionAbilityImpl { + + private static final UnblockableAbility fINSTANCE = new UnblockableAbility(); + + private Object readResolve() throws ObjectStreamException { + return fINSTANCE; + } + + public static UnblockableAbility getInstance() { + return fINSTANCE; + } + + private UnblockableAbility() {} + + @Override + public boolean canBlock(Permanent permanent, Game game) { + return false; + } + + @Override + public String getRule() { + return "{this} is unblockable"; + } + +} diff --git a/Mage/src/mage/abilities/mana/BasicLandManaAbility.java b/Mage/src/mage/abilities/mana/BasicLandManaAbility.java new file mode 100644 index 00000000000..c971545da78 --- /dev/null +++ b/Mage/src/mage/abilities/mana/BasicLandManaAbility.java @@ -0,0 +1,45 @@ +/* +* 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.mana; + +import mage.Constants.Zone; +import mage.abilities.costs.common.TapSourceCost; +import mage.abilities.effects.common.ManaEffect; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public abstract class BasicLandManaAbility extends ManaAbility { + + public BasicLandManaAbility(ManaEffect effect) { + super(Zone.BATTLEFIELD, effect, new TapSourceCost()); + } + +} diff --git a/Mage/src/mage/abilities/mana/BasicManaAbility.java b/Mage/src/mage/abilities/mana/BasicManaAbility.java new file mode 100644 index 00000000000..757ec79cc5d --- /dev/null +++ b/Mage/src/mage/abilities/mana/BasicManaAbility.java @@ -0,0 +1,45 @@ +/* +* 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.mana; + +import mage.Constants.Zone; +import mage.abilities.costs.common.TapSourceCost; +import mage.abilities.effects.common.ManaEffect; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public abstract class BasicManaAbility extends ManaAbility { + + public BasicManaAbility(ManaEffect effect) { + super(Zone.BATTLEFIELD, effect, new TapSourceCost()); + } + +} diff --git a/Mage/src/mage/abilities/mana/BlackManaAbility.java b/Mage/src/mage/abilities/mana/BlackManaAbility.java new file mode 100644 index 00000000000..bfbfa618928 --- /dev/null +++ b/Mage/src/mage/abilities/mana/BlackManaAbility.java @@ -0,0 +1,45 @@ +/* +* 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.mana; + +import mage.Mana; +import mage.abilities.effects.common.ManaEffect; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class BlackManaAbility extends BasicManaAbility { + + public BlackManaAbility() { + super(new ManaEffect(Mana.BlackMana)); + this.netMana.setBlack(1); + } + +} diff --git a/Mage/src/mage/abilities/mana/BlueManaAbility.java b/Mage/src/mage/abilities/mana/BlueManaAbility.java new file mode 100644 index 00000000000..89d30542cb6 --- /dev/null +++ b/Mage/src/mage/abilities/mana/BlueManaAbility.java @@ -0,0 +1,45 @@ +/* +* 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.mana; + +import mage.Mana; +import mage.abilities.effects.common.ManaEffect; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class BlueManaAbility extends BasicManaAbility { + + public BlueManaAbility() { + super(new ManaEffect(Mana.BlueMana)); + this.netMana.setBlue(1); + } + +} diff --git a/Mage/src/mage/abilities/mana/ColorlessManaAbility.java b/Mage/src/mage/abilities/mana/ColorlessManaAbility.java new file mode 100644 index 00000000000..c155acb49b3 --- /dev/null +++ b/Mage/src/mage/abilities/mana/ColorlessManaAbility.java @@ -0,0 +1,45 @@ +/* +* 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.mana; + +import mage.Mana; +import mage.abilities.effects.common.ManaEffect; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class ColorlessManaAbility extends BasicManaAbility { + + public ColorlessManaAbility() { + super(new ManaEffect(Mana.ColorlessMana)); + this.netMana.setColorless(1); + } + +} diff --git a/Mage/src/mage/abilities/mana/GreenManaAbility.java b/Mage/src/mage/abilities/mana/GreenManaAbility.java new file mode 100644 index 00000000000..0decbd99080 --- /dev/null +++ b/Mage/src/mage/abilities/mana/GreenManaAbility.java @@ -0,0 +1,45 @@ +/* +* 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.mana; + +import mage.Mana; +import mage.abilities.effects.common.ManaEffect; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class GreenManaAbility extends BasicManaAbility { + + public GreenManaAbility() { + super(new ManaEffect(Mana.GreenMana)); + this.netMana.setGreen(1); + } + +} diff --git a/Mage/src/mage/abilities/mana/ManaAbility.java b/Mage/src/mage/abilities/mana/ManaAbility.java new file mode 100644 index 00000000000..973cf2efa8c --- /dev/null +++ b/Mage/src/mage/abilities/mana/ManaAbility.java @@ -0,0 +1,62 @@ +/* +* 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.mana; + +import java.util.UUID; +import mage.Constants.Zone; +import mage.Mana; +import mage.abilities.ActivatedAbilityImpl; +import mage.abilities.costs.Cost; +import mage.abilities.effects.common.ManaEffect; +import mage.game.Game; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public abstract class ManaAbility extends ActivatedAbilityImpl { + + protected Mana netMana = new Mana(); + + public ManaAbility(Zone zone, ManaEffect effect, Cost cost) { + super(zone, effect, cost); + } + + @Override + public boolean canActivate(UUID playerId, Game game) { + if (!controlsAbility(playerId, game)) + return false; + //20091005 - 605.3a + return costs.canPay(playerId, game); + } + + public Mana getNetMana() { + return netMana; + } +} diff --git a/Mage/src/mage/abilities/mana/ManaOptions.java b/Mage/src/mage/abilities/mana/ManaOptions.java new file mode 100644 index 00000000000..54e6ce4465d --- /dev/null +++ b/Mage/src/mage/abilities/mana/ManaOptions.java @@ -0,0 +1,105 @@ +/* +* 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.mana; + +import java.util.ArrayList; +import java.util.List; +import mage.Mana; +import mage.util.Copier; + +/** + * + * @author BetaSteward_at_googlemail.com + * + * this class is used to build a list of all possible mana combinations + * it can be used to find all the ways to pay a mana cost + * or all the different mana combinations available to a player + * + */ +public class ManaOptions extends ArrayList { + + public void addMana(List abilities) { + if (isEmpty()) + this.add(new Mana()); + if (!abilities.isEmpty()) { + if (abilities.size() == 1) { + //if there is only one mana option available add it to all the existing options + addMana(abilities.get(0).getNetMana()); + } + else if (abilities.size() > 1) { + //perform a union of all existing options and the new options + Copier> copier = new Copier>(); + List copy = copier.copy(this); + this.clear(); + for (ManaAbility ability: abilities) { + for (Mana mana: copy) { + Mana newMana = new Mana(); + newMana.add(mana); + newMana.add(ability.getNetMana()); + this.add(newMana); + } + } + } + } + } + + public void addMana(Mana addMana) { + if (isEmpty()) + this.add(new Mana()); + for (Mana mana: this) { + mana.add(addMana); + } + } + + public void addMana(ManaOptions options) { + if (isEmpty()) + this.add(new Mana()); + if (!options.isEmpty()) { + if (options.size() == 1) { + //if there is only one mana option available add it to all the existing options + addMana(options.get(0)); + } + else if (options.size() > 1) { + //perform a union of all existing options and the new options + Copier> copier = new Copier>(); + List copy = copier.copy(this); + this.clear(); + for (Mana addMana: options) { + for (Mana mana: copy) { + Mana newMana = new Mana(); + newMana.add(mana); + newMana.add(addMana); + this.add(newMana); + } + } + } + } + } + +} \ No newline at end of file diff --git a/Mage/src/mage/abilities/mana/RedManaAbility.java b/Mage/src/mage/abilities/mana/RedManaAbility.java new file mode 100644 index 00000000000..8f4ae45e343 --- /dev/null +++ b/Mage/src/mage/abilities/mana/RedManaAbility.java @@ -0,0 +1,45 @@ +/* +* 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.mana; + +import mage.Mana; +import mage.abilities.effects.common.ManaEffect; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class RedManaAbility extends BasicManaAbility { + + public RedManaAbility() { + super(new ManaEffect(Mana.RedMana)); + this.netMana.setRed(1); + } + +} diff --git a/Mage/src/mage/abilities/mana/WhiteManaAbility.java b/Mage/src/mage/abilities/mana/WhiteManaAbility.java new file mode 100644 index 00000000000..5711b878808 --- /dev/null +++ b/Mage/src/mage/abilities/mana/WhiteManaAbility.java @@ -0,0 +1,45 @@ +/* +* 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.mana; + +import mage.Mana; +import mage.abilities.effects.common.ManaEffect; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class WhiteManaAbility extends BasicManaAbility { + + public WhiteManaAbility() { + super(new ManaEffect(Mana.WhiteMana)); + this.netMana.setWhite(1); + } + +} diff --git a/Mage/src/mage/cards/Card.java b/Mage/src/mage/cards/Card.java new file mode 100644 index 00000000000..c5e3c0286cf --- /dev/null +++ b/Mage/src/mage/cards/Card.java @@ -0,0 +1,53 @@ +/* +* 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.cards; + +import java.util.List; +import java.util.UUID; +import mage.Constants.Zone; +import mage.MageObject; +import mage.abilities.Ability; +import mage.abilities.SpellAbility; +import mage.game.Game; +import mage.game.events.GameEvent; + +public interface Card extends MageObject { + + public UUID getOwnerId(); + public String getArt(); + public void setControllerId(UUID controllerId); + public void setOwnerId(UUID controllerId); + public void addAbility(Ability ability); + public SpellAbility getSpellAbility(); + public List getRules(); + public Card copy(); + + public void handleEvent(Zone zone, GameEvent event, Game game); + +} diff --git a/Mage/src/mage/cards/CardImpl.java b/Mage/src/mage/cards/CardImpl.java new file mode 100644 index 00000000000..233e8942c91 --- /dev/null +++ b/Mage/src/mage/cards/CardImpl.java @@ -0,0 +1,124 @@ +/* +* 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.cards; + +import java.util.List; +import java.util.UUID; +import mage.Constants.CardType; +import mage.Constants.Zone; +import mage.MageObjectImpl; +import mage.abilities.Ability; +import mage.abilities.PlayLandAbility; +import mage.abilities.SpellAbility; +import mage.abilities.TriggeredAbility; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.util.Copier; + +public abstract class CardImpl extends MageObjectImpl implements Card { + + private static final transient Copier copier = new Copier(); + + protected UUID ownerId; + protected String art = ""; + + public CardImpl(UUID ownerId, String name, CardType[] cardTypes, String costs) { + this.ownerId = ownerId; + this.name = name; + for (CardType newCardType: cardTypes) + this.cardType.add(newCardType); + this.manaCost.load(costs); + if (cardType.contains(CardType.LAND)) + addAbility(new PlayLandAbility()); + else + addAbility(new SpellAbility(manaCost)); + } + + protected CardImpl(UUID ownerId, String name) { + this.ownerId = ownerId; + this.name = name; + } + + @Override + public UUID getOwnerId() { + return ownerId; + } + + @Override + public String getArt() { + return art; + } + + @Override + public List getRules() { + List rules = abilities.getRules(); + if (cardType.contains(CardType.INSTANT) || cardType.contains(CardType.SORCERY)) { + rules.add(0, getSpellAbility().getRule()); + } + return rules; + } + + @Override + public void addAbility(Ability ability) { + ability.setSourceId(this.getId()); + abilities.add(ability); + } + + @Override + public SpellAbility getSpellAbility() { + for (Ability ability: abilities.getActivatedAbilities(Zone.HAND)) { + if (ability instanceof SpellAbility) + return (SpellAbility)ability; + } + return null; + } + + @Override + public void setControllerId(UUID controllerId) { + abilities.setControllerId(controllerId); + } + + @Override + public void setOwnerId(UUID ownerId) { + this.ownerId = ownerId; + abilities.setControllerId(ownerId); + } + + @Override + public Card copy() { + return copier.copy(this); + } + + @Override + public void handleEvent(Zone zone, GameEvent event, Game game) { + for (TriggeredAbility ability: abilities.getTriggeredAbilities(zone)) { + ability.handleEvent(event, game); + } + } +} diff --git a/Mage/src/mage/cards/Cards.java b/Mage/src/mage/cards/Cards.java new file mode 100644 index 00000000000..1e7d5f32373 --- /dev/null +++ b/Mage/src/mage/cards/Cards.java @@ -0,0 +1,49 @@ +/* +* 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.cards; + +import java.io.Serializable; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import mage.filter.FilterCard; +import mage.game.Game; +import mage.game.events.GameEvent; + +public interface Cards extends Map, Serializable { + + public void add(Card card); + public void remove(Card card); + public void setOwner(UUID ownerId); + public void handleEvent(GameEvent event, Game game); + public void addAll(List createCards); + public List getCards(FilterCard filter); + public Card getRandom(); + +} diff --git a/Mage/src/mage/cards/CardsImpl.java b/Mage/src/mage/cards/CardsImpl.java new file mode 100644 index 00000000000..f9bfad53cd7 --- /dev/null +++ b/Mage/src/mage/cards/CardsImpl.java @@ -0,0 +1,112 @@ +/* +* 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.cards; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Random; +import java.util.UUID; +import mage.Constants.Zone; +import mage.filter.FilterCard; +import mage.game.Game; +import mage.game.events.GameEvent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class CardsImpl extends LinkedHashMap implements Cards, Serializable { + + private static Random rnd = new Random(); + private UUID ownerId; + private Zone zone; + + public CardsImpl(Zone zone) { + this.zone = zone; + } + + public CardsImpl(Zone zone, List cards) { + this(zone); + for (Card card: cards) { + this.put(card.getId(), card); + } + } + + @Override + public void add(Card card) { + this.put(card.getId(), card); + } + + @Override + public void remove(Card card) { + this.remove(card.getId()); + } + + @Override + public void setOwner(UUID ownerId) { + this.ownerId = ownerId; + for (Card card: this.values()) { + card.setOwnerId(ownerId); + } + } + + @Override + public Card getRandom() { + Card[] cards = this.values().toArray(new Card[0]); + return cards[rnd.nextInt(cards.length)]; + } + + @Override + public void handleEvent(GameEvent event, Game game) { + for (Card card: this.values()) { + card.handleEvent(zone, event, game); + } + } + + @Override + public List getCards(FilterCard filter) { + List cards = new ArrayList(); + for (Card card: this.values()) { + boolean match = filter.match(card); + if (match) + cards.add(card); + } + return cards; + } + + @Override + public void addAll(List cards) { + for(Card card: cards) { + this.put(card.getId(), card); + } + } + +} diff --git a/Mage/src/mage/cards/ExpansionSet.java b/Mage/src/mage/cards/ExpansionSet.java new file mode 100644 index 00000000000..207945e1cc9 --- /dev/null +++ b/Mage/src/mage/cards/ExpansionSet.java @@ -0,0 +1,74 @@ +/* +* 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.cards; + +import java.io.Serializable; +import java.lang.reflect.Constructor; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class ExpansionSet implements Serializable { + + protected String name; + protected List cards = new ArrayList(); + + public List getCards() { + return cards; + } + + public String getName() { + return name; + } + + public static Card createCard(Class clazz) { + try { + Constructor con = clazz.getConstructor(new Class[]{UUID.class}); + return (Card) con.newInstance(new Object[] {null}); + } catch (Exception ex) { + Logger.getLogger(ExpansionSet.class.getName()).log(Level.SEVERE, null, ex); + return null; + } + } + + public List createCards() { + List created = new ArrayList(); + for (Class clazz: cards) { + created.add(createCard(clazz)); + } + return created; + } + +} diff --git a/Mage/src/mage/cards/basiclands/BasicLand.java b/Mage/src/mage/cards/basiclands/BasicLand.java new file mode 100644 index 00000000000..85952931eba --- /dev/null +++ b/Mage/src/mage/cards/basiclands/BasicLand.java @@ -0,0 +1,49 @@ +/* +* 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.cards.basiclands; + +import java.util.UUID; +import mage.Constants.CardType; +import mage.abilities.mana.ManaAbility; +import mage.cards.CardImpl; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class BasicLand extends CardImpl { + + public BasicLand(UUID ownerId, String name, ManaAbility mana) { + super(ownerId, name, new CardType[]{CardType.LAND}, null); + this.supertype.add("Basic"); + this.subtype.add(name); + this.addAbility(mana); + } + +} diff --git a/Mage/src/mage/cards/basiclands/Forest.java b/Mage/src/mage/cards/basiclands/Forest.java new file mode 100644 index 00000000000..4b2216b68fa --- /dev/null +++ b/Mage/src/mage/cards/basiclands/Forest.java @@ -0,0 +1,44 @@ +/* +* 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.cards.basiclands; + +import java.util.UUID; +import mage.abilities.mana.GreenManaAbility; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class Forest extends BasicLand { + + public Forest(UUID ownerId) { + super(ownerId, "Forest", new GreenManaAbility()); + } + +} diff --git a/Mage/src/mage/cards/basiclands/Island.java b/Mage/src/mage/cards/basiclands/Island.java new file mode 100644 index 00000000000..1153eceb0ea --- /dev/null +++ b/Mage/src/mage/cards/basiclands/Island.java @@ -0,0 +1,44 @@ +/* +* 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.cards.basiclands; + +import java.util.UUID; +import mage.abilities.mana.BlueManaAbility; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class Island extends BasicLand { + + public Island(UUID ownerId) { + super(ownerId, "Island", new BlueManaAbility()); + } + +} diff --git a/Mage/src/mage/cards/basiclands/Mountain.java b/Mage/src/mage/cards/basiclands/Mountain.java new file mode 100644 index 00000000000..9c7b8e0d68f --- /dev/null +++ b/Mage/src/mage/cards/basiclands/Mountain.java @@ -0,0 +1,44 @@ +/* +* 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.cards.basiclands; + +import java.util.UUID; +import mage.abilities.mana.RedManaAbility; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class Mountain extends BasicLand { + + public Mountain(UUID ownerId) { + super(ownerId, "Mountain", new RedManaAbility()); + } + +} diff --git a/Mage/src/mage/cards/basiclands/Plains.java b/Mage/src/mage/cards/basiclands/Plains.java new file mode 100644 index 00000000000..f791801f03d --- /dev/null +++ b/Mage/src/mage/cards/basiclands/Plains.java @@ -0,0 +1,44 @@ +/* +* 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.cards.basiclands; + +import java.util.UUID; +import mage.abilities.mana.WhiteManaAbility; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class Plains extends BasicLand { + + public Plains(UUID ownerId) { + super(ownerId, "Plains", new WhiteManaAbility()); + } + +} diff --git a/Mage/src/mage/cards/basiclands/Swamp.java b/Mage/src/mage/cards/basiclands/Swamp.java new file mode 100644 index 00000000000..fda5430121b --- /dev/null +++ b/Mage/src/mage/cards/basiclands/Swamp.java @@ -0,0 +1,44 @@ +/* +* 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.cards.basiclands; + +import java.util.UUID; +import mage.abilities.mana.BlackManaAbility; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class Swamp extends BasicLand { + + public Swamp(UUID ownerId) { + super(ownerId, "Swamp", new BlackManaAbility()); + } + +} diff --git a/Mage/src/mage/cards/decks/Deck.java b/Mage/src/mage/cards/decks/Deck.java new file mode 100644 index 00000000000..4380bb0847f --- /dev/null +++ b/Mage/src/mage/cards/decks/Deck.java @@ -0,0 +1,131 @@ +/* +* 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.cards.decks; + +import mage.cards.*; +import java.io.Serializable; +import java.lang.reflect.Constructor; +import java.util.UUID; +import mage.Constants.Zone; + +public class Deck implements Serializable { + + private String name; + private Cards cards = new CardsImpl(Zone.OUTSIDE); + private Cards sideboard = new CardsImpl(Zone.OUTSIDE); + + public static Deck load(DeckCardLists deckCardLists) { + Deck deck = new Deck(); + deck.setName(deckCardLists.getName()); + for (String cardName: deckCardLists.getCards()) { + deck.cards.add(createCard(cardName)); + } + for (String cardName: deckCardLists.getSideboard()) { + deck.sideboard.add(createCard(cardName)); + } + + return deck; + } + + private static Card createCard(String name) { + try { + Class theClass = Class.forName(name); + Constructor con = theClass.getConstructor(new Class[]{UUID.class}); + return (Card) con.newInstance(new Object[] {null}); + } + catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + public DeckCardLists getDeckCardLists() { + DeckCardLists deckCardLists = new DeckCardLists(); + + deckCardLists.setName(name); + for (Card card: cards.values()) { + deckCardLists.getCards().add(card.getClass().getCanonicalName()); + } + for (Card card: sideboard.values()) { + deckCardLists.getSideboard().add(card.getClass().getCanonicalName()); + } + + return deckCardLists; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return the cards + */ + public Cards getCards() { + return cards; + } + + /** + * @param cards the cards to set + */ + public void setCards(Cards cards) { + this.cards = cards; + } + + /** + * @return the sideboard + */ + public Cards getSideboard() { + return sideboard; + } + + /** + * @param sideboard the sideboard to set + */ + public void setSideboard(Cards sideboard) { + this.sideboard = sideboard; + } + + public void setOwnerId(UUID playerId) { + cards.setOwner(playerId); + sideboard.setOwner(playerId); + } + + + +} diff --git a/Mage/src/mage/cards/decks/DeckCardLists.java b/Mage/src/mage/cards/decks/DeckCardLists.java new file mode 100644 index 00000000000..6bae9746573 --- /dev/null +++ b/Mage/src/mage/cards/decks/DeckCardLists.java @@ -0,0 +1,118 @@ +/* +* 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.cards.decks; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Logger; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class DeckCardLists implements Serializable { + + private String name; + private List cards = new ArrayList(); + private List sideboard = new ArrayList(); + + public static DeckCardLists load(String file) throws FileNotFoundException, IOException, ClassNotFoundException { + + DeckCardLists deckList = new DeckCardLists(); + + FileInputStream fis; + ObjectInputStream ois; + + fis = new FileInputStream(file); + ois = new ObjectInputStream(fis); + try { + deckList = (DeckCardLists) ois.readObject(); + return deckList; + } finally { + ois.close(); + } + + } + + public void save(String file) throws FileNotFoundException, IOException { + + FileOutputStream fs = new FileOutputStream(file); + ObjectOutputStream os = new ObjectOutputStream(fs); + try { + os.writeObject(this); + } finally { + os.close(); + } + + } + + /** + * @return the cards + */ + public List getCards() { + return cards; + } + + /** + * @param cards the cards to set + */ + public void setCards(List cards) { + this.cards = cards; + } + + /** + * @return the sideboard + */ + public List getSideboard() { + return sideboard; + } + + /** + * @param sideboard the sideboard to set + */ + public void setSideboard(List sideboard) { + this.sideboard = sideboard; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} diff --git a/Mage/src/mage/cards/decks/DeckValidator.java b/Mage/src/mage/cards/decks/DeckValidator.java new file mode 100644 index 00000000000..ffdd77a8178 --- /dev/null +++ b/Mage/src/mage/cards/decks/DeckValidator.java @@ -0,0 +1,41 @@ +/* +* 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.cards.decks; + +import java.io.Serializable; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public interface DeckValidator extends Serializable { + + public boolean validate(Deck deck); + +} diff --git a/Mage/src/mage/cards/decks/DeckValidatorConstructed.java b/Mage/src/mage/cards/decks/DeckValidatorConstructed.java new file mode 100644 index 00000000000..1fa47a39f3f --- /dev/null +++ b/Mage/src/mage/cards/decks/DeckValidatorConstructed.java @@ -0,0 +1,43 @@ +/* +* 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.cards.decks; + +import java.io.Serializable; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class DeckValidatorConstructed implements DeckValidator, Serializable { + + public boolean validate(Deck deck) { + return true; + } + +} diff --git a/Mage/src/mage/cards/decks/DeckValidatorFactory.java b/Mage/src/mage/cards/decks/DeckValidatorFactory.java new file mode 100644 index 00000000000..a0f3e48e552 --- /dev/null +++ b/Mage/src/mage/cards/decks/DeckValidatorFactory.java @@ -0,0 +1,65 @@ +/* +* 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.cards.decks; + +import java.util.logging.Logger; +import mage.Constants; +import mage.util.Logging; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class DeckValidatorFactory { + + private final static DeckValidatorFactory INSTANCE = new DeckValidatorFactory(); + private final static Logger logger = Logging.getLogger(DeckValidatorFactory.class.getName()); + + public static DeckValidatorFactory getInstance() { + return INSTANCE; + } + + private DeckValidatorFactory() {} + + public DeckValidator createDeckValidator(Constants.DeckType deckType) { + + switch (deckType) { + case CONSTRUCTED_STANDARD: + + break; + case CONSTRUCTED_EXTENDED: + + break; + default: + + break; + } + return new DeckValidatorConstructed(); + } +} diff --git a/Mage/src/mage/choices/Choice.java b/Mage/src/mage/choices/Choice.java new file mode 100644 index 00000000000..5126c0f9c0e --- /dev/null +++ b/Mage/src/mage/choices/Choice.java @@ -0,0 +1,49 @@ +/* +* 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.choices; + +import java.util.List; +import mage.abilities.Ability; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public interface Choice { + + public boolean isChosen(); + public void clearChoice(); + public String getMessage(); + public void setChoice(String choice); + public List getChoices(); + public String getChoice(); + public Ability getAbility(); + public void setAbility(Ability ability); + +} diff --git a/Mage/src/mage/choices/ChoiceColor.java b/Mage/src/mage/choices/ChoiceColor.java new file mode 100644 index 00000000000..754300fab8d --- /dev/null +++ b/Mage/src/mage/choices/ChoiceColor.java @@ -0,0 +1,63 @@ +/* +* 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.choices; + +import mage.ObjectColor; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class ChoiceColor extends ChoiceImpl { + + public ChoiceColor() { + this.choices.add("Black"); + this.choices.add("Blue"); + this.choices.add("Green"); + this.choices.add("Red"); + this.choices.add("White"); + this.message = "Choose color"; + } + + public ObjectColor getColor() { + ObjectColor color = new ObjectColor(); + if (choice.equals("Black")) + color.setBlack(true); + else if (choice.equals("Blue")) + color.setBlue(true); + else if (choice.equals("Green")) + color.setGreen(true); + else if (choice.equals("Red")) + color.setRed(true); + else if (choice.equals("White")) + color.setWhite(true); + return color; + } + +} diff --git a/Mage/src/mage/choices/ChoiceImpl.java b/Mage/src/mage/choices/ChoiceImpl.java new file mode 100644 index 00000000000..73202fc660d --- /dev/null +++ b/Mage/src/mage/choices/ChoiceImpl.java @@ -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.choices; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import mage.abilities.Ability; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class ChoiceImpl implements Choice, Serializable { + + protected Ability source; + protected boolean chosen; + protected String choice; + protected List choices = new ArrayList(); + protected String message; + + public ChoiceImpl() { + + } + + @Override + public boolean isChosen() { + return chosen; + } + + @Override + public void clearChoice() { + choice = null; + chosen = false; + } + + @Override + public String getMessage() { + return message; + } + + @Override + public List getChoices() { + return choices; + } + + @Override + public String getChoice() { + return choice; + } + + @Override + public void setChoice(String choice) { + if (choices.contains(choice)) { + this.choice = choice; + this.chosen = true; + } + } + + @Override + public Ability getAbility() { + return source; + } + + @Override + public void setAbility(Ability source) { + this.source = source; + } + +} diff --git a/Mage/src/mage/choices/Choices.java b/Mage/src/mage/choices/Choices.java new file mode 100644 index 00000000000..8aff28fd027 --- /dev/null +++ b/Mage/src/mage/choices/Choices.java @@ -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.choices; + +import java.util.ArrayList; +import java.util.List; +import mage.Constants.Outcome; +import mage.abilities.Ability; +import mage.game.Game; +import mage.players.Player; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class Choices extends ArrayList{ + + protected Ability source; + protected Outcome outcome; + + public Choices(Ability ability) { + this.source = ability; + } + + public void setSource(Ability ability) { + this.source = ability; + } + + @Override + public boolean add(Choice choice) { + choice.setAbility(source); + return super.add(choice); + } + + public List getUnchosen() { + List unchosen = new ArrayList(); + for (Choice choice: this) { + if (!choice.isChosen()) + unchosen.add(choice); + } + return unchosen; + } + + public void clearChosen() { + for (Choice choice: this) { + choice.clearChoice(); + } + } + + public boolean isChosen() { + for (Choice choice: this) { + if (!choice.isChosen()) + return false; + } + return true; + } + + public boolean choose(Game game) { + if (this.size() > 0) { + Player player = game.getPlayer(this.source.getControllerId()); + while (!isChosen()) { + Choice choice = this.getUnchosen().get(0); + if (!player.choose(outcome, choice, game)) + return false; + } + } + return true; + } + +} diff --git a/Mage/src/mage/counters/BoostCounter.java b/Mage/src/mage/counters/BoostCounter.java new file mode 100644 index 00000000000..204e2677058 --- /dev/null +++ b/Mage/src/mage/counters/BoostCounter.java @@ -0,0 +1,54 @@ +/* +* 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.counters; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class BoostCounter extends Counter { + + protected int power; + protected int toughness; + + public BoostCounter(int power, int toughness) { + super(String.format("%1$+d/%2$+d", power, toughness)); + this.power = power; + this.toughness = toughness; + } + + public int getPower() { + return power; + } + + public int getToughness() { + return toughness; + } + +} diff --git a/Mage/src/mage/counters/Counter.java b/Mage/src/mage/counters/Counter.java new file mode 100644 index 00000000000..c30d8806139 --- /dev/null +++ b/Mage/src/mage/counters/Counter.java @@ -0,0 +1,73 @@ +/* +* 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.counters; + +import java.io.Serializable; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class Counter implements Serializable { + + protected String name; + protected int count; + + public Counter(String name) { + this.name = name; + } + + public void add() { + count++; + } + + public void add(int amount) { + count += amount; + } + + public void remove() { + if (count > 0) + count--; + } + + public void remove(int amount) { + if (count > amount) + count -= amount; + else + count = 0; + } + + public String getName() { + return name; + } + + public int getCount() { + return count; + } +} diff --git a/Mage/src/mage/counters/Counters.java b/Mage/src/mage/counters/Counters.java new file mode 100644 index 00000000000..6a7e81c3032 --- /dev/null +++ b/Mage/src/mage/counters/Counters.java @@ -0,0 +1,85 @@ +/* +* 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.counters; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class Counters extends HashMap implements Serializable { + + public void addCounter(String name) { + if (!this.containsKey(name)) + this.put(name, new Counter(name)); + this.get(name).add(); + } + + public void addCounter(String name, int amount) { + if (!this.containsKey(name)) + this.put(name, new Counter(name)); + this.get(name).add(amount); + } + + public void addCounter(Counter counter) { + if (!this.containsKey(counter.name)) + put(counter.name, counter); + else + get(counter.name).add(counter.getCount()); + } + + public void removeCounter(String name) { + if (this.containsKey(name)) + this.get(name).remove(); + } + + public void removeCounter(String name, int amount) { + if (this.containsKey(name)) + this.get(name).remove(amount); + } + + public int getCount(String name) { + if (this.containsKey(name)) + return this.get(name).getCount(); + return 0; + } + + public List getBoostCounters() { + List boosters = new ArrayList(); + for (Counter counter: this.values()) { + if (counter instanceof BoostCounter) + boosters.add((BoostCounter)counter); + } + return boosters; + } +} diff --git a/Mage/src/mage/counters/MinusOneCounter.java b/Mage/src/mage/counters/MinusOneCounter.java new file mode 100644 index 00000000000..545a6b64999 --- /dev/null +++ b/Mage/src/mage/counters/MinusOneCounter.java @@ -0,0 +1,46 @@ +/* +* 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.counters; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class MinusOneCounter extends BoostCounter { + + public MinusOneCounter() { + super(-1, -1); + } + + public MinusOneCounter(int amount) { + super(-1, -1); + this.count = amount; + } + +} diff --git a/Mage/src/mage/counters/PlusOneCounter.java b/Mage/src/mage/counters/PlusOneCounter.java new file mode 100644 index 00000000000..becfb59218e --- /dev/null +++ b/Mage/src/mage/counters/PlusOneCounter.java @@ -0,0 +1,45 @@ +/* +* 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.counters; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class PlusOneCounter extends BoostCounter { + + public PlusOneCounter() { + super(1, 1); + } + + public PlusOneCounter(int amount) { + super(1, 1); + this.count = amount; + } +} diff --git a/Mage/src/mage/filter/Filter.java b/Mage/src/mage/filter/Filter.java new file mode 100644 index 00000000000..9005e42d155 --- /dev/null +++ b/Mage/src/mage/filter/Filter.java @@ -0,0 +1,51 @@ +/* +* 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.filter; + +import java.io.Serializable; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public interface Filter extends Serializable { + + public enum ComparisonType { + GreaterThan, Equal, LessThan + } + + public enum ComparisonScope { + Any, All + } + + public boolean match(T o); + public String getMessage(); + public void setMessage(String message); + +} diff --git a/Mage/src/mage/filter/FilterCard.java b/Mage/src/mage/filter/FilterCard.java new file mode 100644 index 00000000000..ab7c1b4e693 --- /dev/null +++ b/Mage/src/mage/filter/FilterCard.java @@ -0,0 +1,78 @@ +/* +* 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.filter; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import mage.cards.Card; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class FilterCard extends FilterObject { + + protected List ownerId = new ArrayList(); + protected boolean notOwner = false; + + public FilterCard() { + super("card"); + } + + public FilterCard(String name) { + super(name); + } + + @Override + public boolean match(Card card) { + if (!super.match(card)) + return false; + + if (ownerId.size() > 0 && ownerId.contains(card.getOwnerId()) == notOwner) + return false; + + return true; + } + + public List getOwnerId() { + return ownerId; + } + + public void setNotOwner(boolean notOwner) { + this.notOwner = notOwner; + } + + public boolean matchOwner(UUID testOwnerId) { + if (ownerId.size() > 0 && ownerId.contains(testOwnerId) == notOwner) + return false; + return true; + } + +} diff --git a/Mage/src/mage/filter/FilterImpl.java b/Mage/src/mage/filter/FilterImpl.java new file mode 100644 index 00000000000..1a9c7b1ba86 --- /dev/null +++ b/Mage/src/mage/filter/FilterImpl.java @@ -0,0 +1,83 @@ +/* +* 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.filter; + +import mage.Constants.CardType; +import mage.ObjectColor; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public abstract class FilterImpl implements Filter { + + protected static ListComparer compCardType = new ListComparer(); + protected static ListComparer compString = new ListComparer(); + + public FilterImpl(String name) { + this.message = name; + } + + protected String message; + + protected boolean compareInts(int int1, int int2, ComparisonType type) { + switch (type) { + case Equal: + if (int1 != int2) + return false; + break; + case GreaterThan: + if (int1 <= int2) + return false; + break; + case LessThan: + if (int1 >= int2) + return false; + break; + } + return true; + } + + protected boolean compareColors(ObjectColor color1, ObjectColor color2, ComparisonScope scope) { + if (scope == ComparisonScope.All) + return color2.equals(color1); + else + return color2.contains(color1); + } + + @Override + public String getMessage() { + return message; + } + + @Override + public void setMessage(String message) { + this.message = message; + } +} diff --git a/Mage/src/mage/filter/FilterObject.java b/Mage/src/mage/filter/FilterObject.java new file mode 100644 index 00000000000..06bc04c09fc --- /dev/null +++ b/Mage/src/mage/filter/FilterObject.java @@ -0,0 +1,260 @@ +/* +* 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.filter; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import mage.Constants.CardType; +import mage.MageObject; +import mage.ObjectColor; +import mage.abilities.Abilities; +import mage.abilities.AbilitiesImpl; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class FilterObject extends FilterImpl implements Filter { + protected Abilities abilities = new AbilitiesImpl(); + protected boolean notAbilities = false; + protected List cardType = new ArrayList(); + protected ComparisonScope scopeCardType = ComparisonScope.All; + protected boolean notCardType = false; + protected boolean colorless = false; + protected boolean useColorless = false; + protected boolean useColor = false; + protected ObjectColor color = new ObjectColor(); + protected ComparisonScope scopeColor = ComparisonScope.All; + protected boolean notColor = false; + protected List name = new ArrayList(); + protected boolean notName = false; + protected List subtype = new ArrayList(); + protected ComparisonScope scopeSubtype = ComparisonScope.All; + protected boolean notSubtype = false; + protected List supertype = new ArrayList(); + protected ComparisonScope scopeSupertype = ComparisonScope.All; + protected boolean notSupertype = false; + protected int convertedManaCost = 0; + protected ComparisonType convertedManaCostComparison; + protected int power = 0; + protected ComparisonType powerComparison; + protected int toughness = 0; + protected ComparisonType toughnessComparison; + protected UUID id = null; + protected boolean notId; + + public FilterObject(String name) { + super(name); + } + + @Override + public boolean match(T object) { + + if (id != null) { + if (object.getId().equals(id) == notId) + return false; + } + + if (name.size() > 0) { + if (name.contains(object.getName()) == notName) + return false; + } + + if (useColor) { + if (scopeColor == ComparisonScope.All) { + if (object.getColor().equals(color) == notColor) { + return false; + } + } + else if (object.getColor().contains(color) == notColor) { + if (useColorless && colorless) { //need to treat colorless like a color in this case + if (object.getColor().isColorless() != colorless) { + return false; + } + } + else { + return false; + } + } + } + else if (useColorless && object.getColor().isColorless() != colorless) { + return false; + } + + if (cardType.size() > 0) { + if (!compCardType.compare(cardType, object.getCardType(), scopeCardType, notCardType)) + return false; + } + + if (subtype.size() > 0) { + if (!compString.compare(subtype, object.getSubtype(), scopeSubtype, notSubtype)) + return false; + } + + if (supertype.size() > 0) { + if (!compString.compare(supertype, object.getSubtype(), scopeSupertype, notSupertype)) + return false; + } + + if (abilities.size() > 0 && object.getAbilities().containsAll(abilities) == notAbilities) { + return false; + } + + if (convertedManaCostComparison != null) { + if (!compareInts(object.getManaCost().convertedManaCost(), convertedManaCost, convertedManaCostComparison)) + return false; + } + + if (powerComparison != null) { + if (!compareInts(object.getPower().getValue(), power, powerComparison)) + return false; + } + + if (toughnessComparison != null) { + if (!compareInts(object.getToughness().getValue(), toughness, toughnessComparison)) + return false; + } + + return true; + } + + public Abilities getAbilities() { + return this.abilities; + } + + public void setNotAbilities(boolean notAbilities) { + this.notAbilities = notAbilities; + } + + public List getCardType() { + return this.cardType; + } + + public void setScopeCardType(ComparisonScope scopeCardType) { + this.scopeCardType = scopeCardType; + } + + public void setNotCardType(boolean notCardType) { + this.notCardType = notCardType; + } + + public void setColor(ObjectColor color) { + this.color = color; + } + + public ObjectColor getColor() { + return this.color; + } + + public void setScopeColor(ComparisonScope scopeColor) { + this.scopeColor = scopeColor; + } + + public void setNotColor(boolean notColor) { + this.notColor = notColor; + } + + public List getName() { + return this.name; + } + + public void setNotName(boolean notName) { + this.notName = notName; + } + + public List getSubtype() { + return this.subtype; + } + + public void setScopeSubtype(ComparisonScope scopeSubtype) { + this.scopeSubtype = scopeSubtype; + } + + public void setNotSubtype(boolean notSubtype) { + this.notSubtype = notSubtype; + } + + public List getSupertype() { + return this.supertype; + } + + public void setScopeSupertype(ComparisonScope scopeSupertype) { + this.scopeSupertype = scopeSupertype; + } + + public void setNotSupertype(boolean notSupertype) { + this.notSupertype = notSupertype; + } + + public void setConvertedManaCost(int convertedManaCost) { + this.convertedManaCost = convertedManaCost; + } + + public void setConvertedManaCostComparison(ComparisonType convertedManaCostComparison) { + this.convertedManaCostComparison = convertedManaCostComparison; + } + + public void setPower(int power) { + this.power = power; + } + + public void setPowerComparison(ComparisonType powerComparison) { + this.powerComparison = powerComparison; + } + + public void setToughness(int toughness) { + this.toughness = toughness; + } + + public void setToughnessComparison(ComparisonType toughnessComparison) { + this.toughnessComparison = toughnessComparison; + } + + public void setUseColor(boolean useColor) { + this.useColor = useColor; + } + + public void setColorless(boolean colorless) { + this.colorless = colorless; + } + + public void setUseColorless(boolean useColorless) { + this.useColorless = useColorless; + } + + public void setId(UUID id) { + this.id = id; + } + + public void setNotId(boolean notId) { + this.notId = notId; + } + +} diff --git a/Mage/src/mage/filter/FilterPermanent.java b/Mage/src/mage/filter/FilterPermanent.java new file mode 100644 index 00000000000..e302cb0a421 --- /dev/null +++ b/Mage/src/mage/filter/FilterPermanent.java @@ -0,0 +1,140 @@ +/* +* 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.filter; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import mage.game.permanent.Permanent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class FilterPermanent extends FilterObject { + protected List ownerId = new ArrayList(); + protected boolean notOwner = false; + protected List controllerId = new ArrayList(); + protected boolean notController = false; + protected boolean useTapped = false; + protected boolean tapped; + protected boolean useFlipped = false; + protected boolean flipped; + protected boolean useFaceup = false; + protected boolean faceup; + protected boolean usePhased = false; + protected boolean phasedIn; + + public FilterPermanent() { + super("permanent"); + } + + public FilterPermanent(String name) { + super(name); + } + + @Override + public boolean match(Permanent permanent) { + if (!super.match(permanent)) + return false; + + if (ownerId.size() > 0 && ownerId.contains(permanent.getOwnerId()) == notOwner) + return false; + + if (controllerId.size() > 0 && controllerId.contains(permanent.getControllerId()) == notController) + return false; + + if (useTapped && permanent.isTapped() != tapped) + return false; + + if (useFlipped && permanent.isFlipped() != flipped) + return false; + + if (useFaceup && permanent.isFaceUp() != faceup) + return false; + + if (usePhased && permanent.isPhasedIn() != phasedIn) + return false; + + return true; + } + + public List getOwnerId() { + return ownerId; + } + + public void setNotOwner(boolean notOwner) { + this.notOwner = notOwner; + } + + public List getControllerId() { + return controllerId; + } + + public void setNotController(boolean notController) { + this.notController = notController; + } + + public void setUseTapped(boolean useTapped) { + this.useTapped = useTapped; + } + + public void setTapped(boolean tapped) { + this.tapped = tapped; + } + + public void setUseFlipped(boolean useFlipped) { + this.useFlipped = useFlipped; + } + + public void setFlipped(boolean flipped) { + this.flipped = flipped; + } + + public void setUseFaceup(boolean useFaceup) { + this.useFaceup = useFaceup; + } + + public void setFaceup(boolean faceup) { + this.faceup = faceup; + } + + public boolean matchOwner(UUID testOwnerId) { + if (ownerId.size() > 0 && ownerId.contains(testOwnerId) == notOwner) + return false; + return true; + } + + public boolean matchController(UUID testControllerId) { + if (controllerId.size() > 0 && controllerId.contains(testControllerId) == notController) + return false; + return true; + } + +} diff --git a/Mage/src/mage/filter/FilterPlayer.java b/Mage/src/mage/filter/FilterPlayer.java new file mode 100644 index 00000000000..be548adc318 --- /dev/null +++ b/Mage/src/mage/filter/FilterPlayer.java @@ -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.filter; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import mage.players.Player; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class FilterPlayer extends FilterImpl implements Filter { + + protected List playerId = new ArrayList(); + protected boolean notPlayer; + + public FilterPlayer() { + super("player"); + } + + @Override + public boolean match(Player player) { + + if (playerId.size() > 0 && playerId.contains(player.getId()) == notPlayer) + return false; + + return true; + } + + public List getPlayerId() { + return playerId; + } + + public void setNotPlayer(boolean notPlayer) { + this.notPlayer = notPlayer; + } + +} diff --git a/Mage/src/mage/filter/FilterSpell.java b/Mage/src/mage/filter/FilterSpell.java new file mode 100644 index 00000000000..b74d66836f5 --- /dev/null +++ b/Mage/src/mage/filter/FilterSpell.java @@ -0,0 +1,73 @@ +/* +* 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.filter; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import mage.game.stack.Spell; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class FilterSpell extends FilterObject { + + protected List controllerId = new ArrayList(); + protected boolean notController = false; + + public FilterSpell() { + super("spell"); + } + + public FilterSpell(String name) { + super(name); + } + + @Override + public boolean match(Spell spell) { + + if (!super.match(spell)) + return false; + + if (controllerId.size() > 0 && controllerId.contains(spell.getControllerId()) == notController) + return false; + + return true; + } + + public List getControllerId() { + return controllerId; + } + + public void setNotController(boolean notController) { + this.notController = notController; + } + +} diff --git a/Mage/src/mage/filter/ListComparer.java b/Mage/src/mage/filter/ListComparer.java new file mode 100644 index 00000000000..cf8dd866fc1 --- /dev/null +++ b/Mage/src/mage/filter/ListComparer.java @@ -0,0 +1,55 @@ +/* +* 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.filter; + +import java.util.ArrayList; +import java.util.List; +import mage.filter.Filter.ComparisonScope; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class ListComparer { + + public boolean compare(List list1, List list2, ComparisonScope scope, boolean negate) { + if (scope == ComparisonScope.All) { + if (list2.containsAll(list1) == negate) { + return false; + } + } + else { + List check = new ArrayList(list1); + if (check.removeAll(list2) == negate) { + return false; + } + } + return true; + } +} diff --git a/Mage/src/mage/filter/common/FilterAttackingCreature.java b/Mage/src/mage/filter/common/FilterAttackingCreature.java new file mode 100644 index 00000000000..28c24cb9ae7 --- /dev/null +++ b/Mage/src/mage/filter/common/FilterAttackingCreature.java @@ -0,0 +1,47 @@ +/* +* 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.filter.common; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class FilterAttackingCreature extends FilterCreaturePermanent { + + public FilterAttackingCreature() { + this(""); + } + + public FilterAttackingCreature(String name) { + super(name); + this.attacking = true; + this.useAttacking = true; + } + +} diff --git a/Mage/src/mage/filter/common/FilterBasicLandCard.java b/Mage/src/mage/filter/common/FilterBasicLandCard.java new file mode 100644 index 00000000000..4c61e719b66 --- /dev/null +++ b/Mage/src/mage/filter/common/FilterBasicLandCard.java @@ -0,0 +1,48 @@ +/* + * 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.filter.common; + +import mage.filter.FilterCard; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class FilterBasicLandCard extends FilterCard { + + public FilterBasicLandCard() { + super("basic land card"); + name.add("Island"); + name.add("Forest"); + name.add("Mountain"); + name.add("Swamp"); + name.add("Plains"); + + } +} diff --git a/Mage/src/mage/filter/common/FilterCreatureForAttack.java b/Mage/src/mage/filter/common/FilterCreatureForAttack.java new file mode 100644 index 00000000000..4f042572601 --- /dev/null +++ b/Mage/src/mage/filter/common/FilterCreatureForAttack.java @@ -0,0 +1,51 @@ +/* +* 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.filter.common; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class FilterCreatureForAttack extends FilterCreaturePermanent { + + public FilterCreatureForAttack() { + this(""); + } + + public FilterCreatureForAttack(String name) { + super(name); + this.attacking = false; + this.useAttacking = true; + this.blocking = false; + this.useBlocking = true; + this.tapped = false; + this.useTapped = true; + } + +} diff --git a/Mage/src/mage/filter/common/FilterCreatureForCombat.java b/Mage/src/mage/filter/common/FilterCreatureForCombat.java new file mode 100644 index 00000000000..4a62c4cc5db --- /dev/null +++ b/Mage/src/mage/filter/common/FilterCreatureForCombat.java @@ -0,0 +1,53 @@ +/* +* 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.filter.common; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class FilterCreatureForCombat extends FilterCreaturePermanent { + + public FilterCreatureForCombat() { + this(""); + } + + public FilterCreatureForCombat(String name) { + super(name); + this.attacking = false; + this.useAttacking = true; + this.blocking = false; + this.useBlocking = true; + this.tapped = false; + this.useTapped = true; + this.phasedIn = true; + this.usePhased = true; + } + +} diff --git a/Mage/src/mage/filter/common/FilterCreatureOrPlayer.java b/Mage/src/mage/filter/common/FilterCreatureOrPlayer.java new file mode 100644 index 00000000000..877fd5c0eb3 --- /dev/null +++ b/Mage/src/mage/filter/common/FilterCreatureOrPlayer.java @@ -0,0 +1,67 @@ +/* +* 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.filter.common; + +import mage.filter.Filter; +import mage.filter.FilterImpl; +import mage.filter.FilterPlayer; +import mage.game.permanent.Permanent; +import mage.players.Player; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class FilterCreatureOrPlayer extends FilterImpl implements Filter { + + protected FilterCreaturePermanent creatureFilter; + protected FilterPlayer playerFilter; + + public FilterCreatureOrPlayer() { + this("player or creature"); + } + + public FilterCreatureOrPlayer(String name) { + super(name); + creatureFilter = new FilterCreaturePermanent(); + playerFilter = new FilterPlayer(); + } + + @Override + public boolean match(Object o) { + if (o instanceof Player) { + return playerFilter.match((Player)o); + } + else if (o instanceof Permanent) { + return creatureFilter.match((Permanent)o); + } + return false; + } + +} diff --git a/Mage/src/mage/filter/common/FilterCreaturePermanent.java b/Mage/src/mage/filter/common/FilterCreaturePermanent.java new file mode 100644 index 00000000000..4d2ab6a8e0d --- /dev/null +++ b/Mage/src/mage/filter/common/FilterCreaturePermanent.java @@ -0,0 +1,69 @@ +/* +* 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.filter.common; + +import java.util.UUID; +import mage.Constants.CardType; +import mage.filter.FilterPermanent; +import mage.game.permanent.Permanent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class FilterCreaturePermanent extends FilterPermanent { + + protected boolean useAttacking = false; + protected boolean attacking; + protected boolean useBlocking = false; + protected boolean blocking; + + public FilterCreaturePermanent() { + this("creature"); + } + + public FilterCreaturePermanent(String name) { + super(name); + cardType.add(CardType.CREATURE); + } + + @Override + public boolean match(Permanent permanent) { + if (!super.match(permanent)) + return false; + + if (useAttacking && permanent.isAttacking() != attacking) + return false; + + if (useBlocking && permanent.isBlocking() != blocking) + return false; + + return true; + } +} diff --git a/Mage/src/mage/filter/common/FilterLandCard.java b/Mage/src/mage/filter/common/FilterLandCard.java new file mode 100644 index 00000000000..3fff2152d01 --- /dev/null +++ b/Mage/src/mage/filter/common/FilterLandCard.java @@ -0,0 +1,49 @@ +/* +* 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.filter.common; + +import mage.Constants.CardType; +import mage.filter.FilterCard; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class FilterLandCard extends FilterCard { + + public FilterLandCard() { + this("land card"); + } + + public FilterLandCard(String name) { + super(name); + cardType.add(CardType.LAND); + } + +} diff --git a/Mage/src/mage/filter/common/FilterLandPermanent.java b/Mage/src/mage/filter/common/FilterLandPermanent.java new file mode 100644 index 00000000000..d15b607af15 --- /dev/null +++ b/Mage/src/mage/filter/common/FilterLandPermanent.java @@ -0,0 +1,49 @@ +/* +* 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.filter.common; + +import mage.Constants.CardType; +import mage.filter.FilterPermanent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class FilterLandPermanent extends FilterPermanent { + + public FilterLandPermanent() { + this("land"); + } + + public FilterLandPermanent(String name) { + super(name); + cardType.add(CardType.LAND); + } + +} diff --git a/Mage/src/mage/filter/common/FilterNonlandCard.java b/Mage/src/mage/filter/common/FilterNonlandCard.java new file mode 100644 index 00000000000..7fe23a9abf3 --- /dev/null +++ b/Mage/src/mage/filter/common/FilterNonlandCard.java @@ -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.filter.common; + +import mage.Constants.CardType; +import mage.filter.FilterCard; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class FilterNonlandCard extends FilterCard { + + public FilterNonlandCard() { + this("non-land card"); + } + + public FilterNonlandCard(String name) { + super(name); + this.cardType.add(CardType.LAND); + this.setNotCardType(true); + } + +} diff --git a/Mage/src/mage/filter/common/FilterNonlandPermanent.java b/Mage/src/mage/filter/common/FilterNonlandPermanent.java new file mode 100644 index 00000000000..a3dba54b43d --- /dev/null +++ b/Mage/src/mage/filter/common/FilterNonlandPermanent.java @@ -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.filter.common; + +import mage.Constants.CardType; +import mage.filter.FilterPermanent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class FilterNonlandPermanent extends FilterPermanent { + + public FilterNonlandPermanent() { + this("nonland permanent"); + } + + public FilterNonlandPermanent(String name) { + super(name); + notCardType = true; + cardType.add(CardType.LAND); + } + +} diff --git a/Mage/src/mage/filter/common/FilterPlaneswalkerOrPlayer.java b/Mage/src/mage/filter/common/FilterPlaneswalkerOrPlayer.java new file mode 100644 index 00000000000..95e865048dd --- /dev/null +++ b/Mage/src/mage/filter/common/FilterPlaneswalkerOrPlayer.java @@ -0,0 +1,64 @@ +/* +* 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.filter.common; + +import java.util.List; +import java.util.UUID; +import mage.filter.Filter; +import mage.filter.FilterImpl; +import mage.filter.FilterPlayer; +import mage.game.permanent.Permanent; +import mage.players.Player; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class FilterPlaneswalkerOrPlayer extends FilterImpl implements Filter { + + protected FilterPlaneswalkerPermanent planeswalkerFilter = new FilterPlaneswalkerPermanent(); + protected FilterPlayer playerFilter = new FilterPlayer(); + + public FilterPlaneswalkerOrPlayer(List defenders) { + super("planeswalker or player"); + planeswalkerFilter.getControllerId().addAll(defenders); + playerFilter.getPlayerId().addAll(defenders); + } + + @Override + public boolean match(Object o) { + if (o instanceof Player) { + return playerFilter.match((Player)o); + } + else if (o instanceof Permanent) { + return planeswalkerFilter.match((Permanent)o); + } + return false; + } +} \ No newline at end of file diff --git a/Mage/src/mage/filter/common/FilterPlaneswalkerPermanent.java b/Mage/src/mage/filter/common/FilterPlaneswalkerPermanent.java new file mode 100644 index 00000000000..15aee14c3b6 --- /dev/null +++ b/Mage/src/mage/filter/common/FilterPlaneswalkerPermanent.java @@ -0,0 +1,59 @@ +/* +* 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.filter.common; + +import mage.Constants.CardType; +import mage.filter.FilterPermanent; +import mage.game.permanent.Permanent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class FilterPlaneswalkerPermanent extends FilterPermanent { + + public FilterPlaneswalkerPermanent() { + this("planeswalker"); + } + + + public FilterPlaneswalkerPermanent(String name) { + super(name); + cardType.add(CardType.PLANESWALKER); + } + + @Override + public boolean match(Permanent permanent) { + if (!super.match(permanent)) + return false; + + return true; + } + +} diff --git a/Mage/src/mage/game/Exile.java b/Mage/src/mage/game/Exile.java new file mode 100644 index 00000000000..48208968da8 --- /dev/null +++ b/Mage/src/mage/game/Exile.java @@ -0,0 +1,81 @@ +/* +* 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; + +import java.io.Serializable; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; +import mage.game.events.GameEvent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class Exile implements Serializable { + + private static final UUID PERMANENT = UUID.randomUUID(); + + private Map exileZones = new HashMap(); + + public Exile() { + createZone(PERMANENT, "Permanent"); + } + + public Collection getExileZones() { + return exileZones.values(); + } + + public ExileZone getPermanentExile() { + return exileZones.get(PERMANENT); + } + + public ExileZone createZone(UUID id, String name) { + return createZone(id, name, false); + } + + public ExileZone createZone(UUID id, String name, boolean hidden) { + if (!exileZones.containsKey(id)) { + ExileZone exile = new ExileZone(id, name, hidden); + exileZones.put(id, exile); + } + return exileZones.get(id); + } + + public ExileZone getExileZone(UUID id) { + return exileZones.get(id); + } + + void handleEvent(GameEvent event, Game game) { + for (ExileZone exile: exileZones.values()) { + exile.handleEvent(event, game); + } + } +} diff --git a/Mage/src/mage/game/ExileZone.java b/Mage/src/mage/game/ExileZone.java new file mode 100644 index 00000000000..b1fe749dadf --- /dev/null +++ b/Mage/src/mage/game/ExileZone.java @@ -0,0 +1,68 @@ +/* +* 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; + +import java.io.Serializable; +import java.util.UUID; +import mage.Constants.Zone; +import mage.cards.CardsImpl; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class ExileZone extends CardsImpl implements Serializable { + + private UUID id; + private String name; + private boolean hidden = false; + + public ExileZone(UUID id, String name) { + this(id, name, false); + } + + public ExileZone(UUID id, String name, boolean hidden) { + super(Zone.EXILED); + this.id = id; + this.name = name; + this.hidden = hidden; + } + + public UUID getId() { + return id; + } + + public String getName() { + return name; + } + + public boolean isHidden() { + return hidden; + } +} diff --git a/Mage/src/mage/game/Game.java b/Mage/src/mage/game/Game.java new file mode 100644 index 00000000000..200c4d2caf7 --- /dev/null +++ b/Mage/src/mage/game/Game.java @@ -0,0 +1,140 @@ +/* +* 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; + +import mage.game.stack.SpellStack; +import mage.MageObject; +import java.io.Serializable; +import java.util.Collection; +import java.util.List; +import java.util.UUID; +import mage.Constants.PhaseStep; +import mage.Constants.TurnPhase; +import mage.MageItem; +import mage.abilities.ActivatedAbility; +import mage.abilities.TriggeredAbility; +import mage.abilities.effects.ContinuousEffect; +import mage.abilities.effects.ContinuousEffects; +import mage.cards.Cards; +import mage.choices.Choice; +import mage.game.combat.Combat; +import mage.game.events.GameEvent; +import mage.game.events.TableEvent; +import mage.game.events.Listener; +import mage.game.events.PlayerQueryEvent; +import mage.game.permanent.Battlefield; +import mage.game.permanent.Permanent; +import mage.players.Player; +import mage.players.PlayerList; +import mage.players.Players; + +public interface Game extends MageItem, Serializable { + + public String getGameType(); + public int getNumPlayers(); + public int getLife(); + + //game data methods + public MageObject getObject(UUID objectId); + public Permanent getPermanent(UUID permanentId); + public void addPlayer(Player player) throws GameException; + public Player getPlayer(UUID playerId); + public Players getPlayers(); + public PlayerList getPlayerList(UUID playerId); + public List getOpponents(UUID controllerId); + public TurnPhase getPhase(); + public PhaseStep getStep(); + public int getTurnNum(); + public boolean isMainPhase(); + public UUID getActivePlayerId(); + public UUID getPriorityPlayerId(); + public boolean isGameOver(); + public Battlefield getBattlefield(); + public SpellStack getStack(); + public Exile getExile(); + public Combat getCombat(); + public GameStates getGameStates(); + public GameState getState(); + public String getWinner(); + public ContinuousEffects getContinuousEffects(); + + //client event methods + public void addTableEventListener(Listener listener); + public void addPlayerQueryEventListener(Listener listener); + public void fireAskPlayerEvent(UUID playerId, String message); + public void fireChooseEvent(UUID playerId, Choice choice); + public void fireSelectTargetEvent(UUID playerId, String message, boolean required); + public void fireSelectTargetEvent(UUID playerId, String message, Cards cards, boolean required); + public void fireSelectEvent(UUID playerId, String message); + public void firePriorityEvent(UUID playerId); + public void firePlayManaEvent(UUID playerId, String message); + public void firePlayXManaEvent(UUID playerId, String message); + public void fireGetChoiceEvent(UUID playerId, String message, Collection choices); + public void fireGetAmountEvent(UUID playerId, String message, int min, int max); + public void fireInformEvent(String message); + public void fireUpdatePlayersEvent(); + public void informPlayers(String message); + + //game event methods + public void fireEvent(GameEvent event); + public boolean replaceEvent(GameEvent event); + + //game play methods + public void start(); + public void end(); + public void mulligan(UUID playerId); + public void quit(UUID playerId); + public void concede(UUID playerId); + public void emptyManaPools(); + public void addEffect(ContinuousEffect continuousEffect); + public void addTriggeredAbility(TriggeredAbility ability); + public void applyEffects(); +// public boolean checkStateAndTriggered(); +// public boolean checkStateBasedActions(); + public void playPriority(); + public void playUntapStep(); + public void playUpkeepStep(); + public void playDrawStep(); + public void playPreCombatMainStep(); + public void playBeginCombatStep(); + public void playDeclareAttackersStep(); + public void playDeclareBlockersStep(); + public void playCombatDamageStep(boolean first); + public void playEndCombatStep(); + public void playPostMainStep(); + public void playEndStep(); + public void playCleanupStep(); + + //game transaction methods + public void saveState(); + public void bookmarkState(); + public void restoreState(); + public void removeLastBookmark(); + +} diff --git a/Mage/src/mage/game/GameException.java b/Mage/src/mage/game/GameException.java new file mode 100644 index 00000000000..e56753fb82f --- /dev/null +++ b/Mage/src/mage/game/GameException.java @@ -0,0 +1,41 @@ +/* +* 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; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class GameException extends Exception { + + public GameException (String message) { + super(message); + } + +} diff --git a/Mage/src/mage/game/GameImpl.java b/Mage/src/mage/game/GameImpl.java new file mode 100644 index 00000000000..40242a9df80 --- /dev/null +++ b/Mage/src/mage/game/GameImpl.java @@ -0,0 +1,756 @@ +/* +* 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; + +import mage.game.stack.SpellStack; +import java.io.Serializable; +import java.util.Collection; +import java.util.Random; +import java.util.Stack; +import java.util.UUID; +import mage.Constants; +import mage.Constants.CardType; +import mage.Constants.Outcome; +import mage.Constants.PhaseStep; +import mage.Constants.TurnPhase; +import mage.Constants.Zone; +import mage.MageObject; +import mage.abilities.ActivatedAbility; +import mage.abilities.TriggeredAbility; +import mage.abilities.effects.ContinuousEffect; +import mage.abilities.effects.ContinuousEffects; +import mage.cards.Cards; +import mage.choices.Choice; +import mage.filter.Filter.ComparisonScope; +import mage.filter.common.FilterEquipment; +import mage.filter.common.FilterFortification; +import mage.filter.common.FilterPlaneswalkerPermanent; +import mage.game.combat.Combat; +import mage.game.combat.CombatGroup; +import mage.game.events.GameEvent; +import mage.players.Player; +import mage.game.events.Listener; +import mage.game.events.TableEvent; +import mage.game.events.TableEvent.EventType; +import mage.game.events.TableEventSource; +import mage.game.events.PlayerQueryEvent; +import mage.game.events.PlayerQueryEventSource; +import mage.game.permanent.Battlefield; +import mage.game.permanent.Permanent; +import mage.players.PlayerList; +import mage.players.Players; +import mage.target.TargetPlayer; + +public abstract class GameImpl implements Game, Serializable { + + private Stack savedStates = new Stack(); + + protected UUID id; + protected boolean ready = false; + protected TableEventSource tableEventSource = new TableEventSource(); + protected PlayerQueryEventSource playerQueryEventSource = new PlayerQueryEventSource(); + + protected GameState state = new GameState(); + protected UUID startingPlayerId; + protected UUID choosingPlayerId; + protected String winner; + protected GameStates gameStates = new GameStates(); + + public GameImpl() { + id = UUID.randomUUID(); + } + + @Override + public UUID getId() { + return id; + } + + @Override + public void addPlayer(Player player) throws GameException { + state.addPlayer(player); + } + + @Override + public Player getPlayer(UUID playerId) { + return state.getPlayer(playerId); + } + + @Override + public MageObject getObject(UUID objectId) { + return state.getObject(objectId); + } + + @Override + public Permanent getPermanent(UUID permanentId) { + return state.getPermanent(permanentId); + } + + @Override + public GameStates getGameStates() { + return gameStates; + } + + @Override + public void saveState() { + gameStates.save(state); + } + + @Override + public boolean isGameOver() { + if (state.isGameOver()) + return true; + int remainingPlayers = 0; + int numLosers = 0; + for (Player player: state.getPlayers().values()) { + if (!player.hasLeft()) + remainingPlayers++; + if (player.hasLost()) + numLosers++; + } + if (remainingPlayers <= 1 || numLosers >= state.getPlayers().size() - 1) { + state.endGame(); + return true; + } + return false; + } + + @Override + public String getWinner() { + return winner; + } + + @Override + public GameState getState() { + return state; + } + + @Override + public void bookmarkState() { + savedStates.push(gameStates.getStates().size()); + } + + @Override + public void restoreState() { + state.restore(gameStates.rollback(savedStates.pop())); + } + + @Override + public void removeLastBookmark() { + savedStates.pop(); + } + + @Override + public void start() { + for (Player player: state.getPlayers().values()) { + player.init(); + } + fireInformEvent("game has started"); + saveState(); + + //20091005 - 103.1 + for (Player player: state.getPlayers().values()) { + player.shuffleLibrary(this); + } + + //20091005 - 103.2 + if (startingPlayerId == null) { + TargetPlayer targetPlayer = new TargetPlayer(); + targetPlayer.setRequired(true); + Player choosingPlayer = getPlayer(pickChoosingPlayer()); + if (choosingPlayer.chooseTarget(Outcome.Benefit, targetPlayer, this)) { + startingPlayerId = targetPlayer.getTargets().get(0); + fireInformEvent(state.getPlayer(startingPlayerId).getName() + " will start"); + } + else { + return; + } + } + saveState(); + + //20091005 - 103.3 + for (Player player: state.getPlayerList(startingPlayerId)) { + player.setLife(this.getLife(), this); + player.drawCards(7, this); + } + + //20091005 - 103.4 + for (Player player: state.getPlayerList(startingPlayerId)) { + while (player.getHand().size() > 0 && player.chooseMulligan(this)) { + mulligan(player.getId()); + } + fireInformEvent(player.getName() + " keeps hand"); + saveState(); + } + + while (!isGameOver()) { + state.setTurnNum(state.getTurnNum() + 1); + fireInformEvent("Turn " + Integer.toString(state.getTurnNum())); + for (Player player: state.getPlayerList(startingPlayerId)) { + state.getTurn().play(this, player.getId()); + if (isGameOver()) + break; + endOfTurn(); + } + } + + for (Player player: state.getPlayers().values()) { + if (player.hasWon() || (!player.hasLost() && !player.hasLeft())) { + winner = "Player " + player.getName() + " is the winner"; + break; + } + } + + if (winner == null) + winner = "Game is a draw"; + saveState(); + } + + protected void endOfTurn() { + for (Player player: getPlayers().values()) { + player.endOfTurn(this); + } + } + + protected UUID pickChoosingPlayer() { + UUID[] players = getPlayers().keySet().toArray(new UUID[0]); + UUID playerId = players[new Random().nextInt(players.length)]; + fireInformEvent(state.getPlayer(playerId).getName() + " won the toss"); + return playerId; + } + + @Override + public void end() { + state.endGame(); + for (Player player: state.getPlayers().values()) { + player.abort(); + } + } + + @Override + public void addTableEventListener(Listener listener) { + tableEventSource.addListener(listener); + } + + @Override + public void mulligan(UUID playerId) { + Player player = getPlayer(playerId); + int numCards = player.getHand().size(); + player.getLibrary().addAll(player.getHand()); + player.getHand().clear(); + player.shuffleLibrary(this); + player.drawCards(numCards - 1, this); + fireInformEvent(player.getName() + " mulligans down to " + Integer.toString(numCards - 1) + " cards"); + } + + @Override + public void quit(UUID playerId) { + Player player = state.getPlayer(playerId); + if (player != null) { + player.leaveGame(); + fireInformEvent(player.getName() + " has left the game."); + player.abort(); + } + } + + @Override + public void concede(UUID playerId) { + Player player = state.getPlayer(playerId); + if (player != null) { + player.concede(); + fireInformEvent(player.getName() + " has conceded."); + player.abort(); + } + } + + @Override + public void playPriority() { + while (!isGameOver()) { + while (!isGameOver()) { + int stackSize = state.getStack().size(); + state.getPlayers().resetPriority(); + for (Player player: getPlayerList(state.getTurn().getActivePlayerId())) { + state.getTurn().setPriorityPlayerId(player.getId()); + while (!player.isPassed() && !isGameOver()) { + checkStateAndTriggered(); + if (isGameOver()) + return; + player.priority(this); + if (isGameOver()) + return; + applyEffects(); + saveState(); + } + } + //no items have been added to the stack + if (isGameOver() || stackSize == state.getStack().size()) + break; + } + if (isGameOver() || state.getStack().isEmpty()) + break; + state.getStack().resolve(this); + applyEffects(); + saveState(); + } + } + + @Override + public void emptyManaPools() { + if (!replaceEvent(new GameEvent(GameEvent.EventType.EMPTY_MANA_POOLS, null, null, null))) { + for (Player player: getPlayers().values()) { + player.getManaPool().emptyPool(); + } + } + } + + @Override + public void applyEffects() { + state.applyEffects(this); + } + + @Override + public void addEffect(ContinuousEffect continuousEffect) { + state.addEffect(continuousEffect); + } + + @Override + public void addTriggeredAbility(TriggeredAbility ability) { + state.addTriggeredAbility(ability); + } + + protected boolean checkStateAndTriggered() { + boolean somethingHappened = false; + while (true) { + if (!checkStateBasedActions() ) { + if (!state.getTriggered().check(this)) { + break; + } + } + somethingHappened = true; + } + return somethingHappened; + } + + protected boolean checkStateBasedActions() { + boolean somethingHappened = false; + + //20091005 - 704.5a/704.5b/704.5c + for (Player player: state.getPlayers().values()) { + if (player.getLife() <= 0 || player.isEmptyDraw() || player.getCounters().getCount("Poison") >= 10) { + player.lost(this); + somethingHappened = true; + } + } + for (Permanent perm: getBattlefield().getActivePermanents(CardType.CREATURE)) { + //20091005 - 704.5f + if (perm.getToughness().getValue() == 0) { + perm.moveToZone(Zone.GRAVEYARD, this, false); + somethingHappened = true; + } + //20091005 - 704.5g/704.5h + else if (perm.getToughness().getValue() <= perm.getDamage() || perm.isDeathtouched()) { + perm.destroy(null, this, false); + somethingHappened = true; + } + } + //20091005 - 704.5j + FilterPlaneswalkerPermanent filter = new FilterPlaneswalkerPermanent(); + if (getBattlefield().count(filter) > 1) { //don't bother checking if less than 2 planeswalkers in play + for (String planeswalkerType: Constants.PlaneswalkerTypes) { + filter.getSubtype().clear(); + filter.getSubtype().add(planeswalkerType); + filter.setScopeSubtype(ComparisonScope.Any); + if (getBattlefield().count(filter) > 1) { + for (Permanent perm: getBattlefield().getActivePermanents(filter)) { + perm.moveToZone(Zone.GRAVEYARD, this, false); + somethingHappened = true; + } + } + } + } + //20091005 - 704.5i + for (Permanent perm: getBattlefield().getActivePermanents(CardType.PLANESWALKER)) { + if (perm.getLoyalty().getValue() == 0) { + perm.moveToZone(Zone.GRAVEYARD, this, false); + return true; + } + } + //20091005 - 704.5p + for (Permanent perm: getBattlefield().getActivePermanents(new FilterEquipment())) { + if (perm.getAttachedTo() != null) { + Permanent creature = getPermanent(perm.getAttachedTo()); + if (creature == null) { + perm.attachTo(null); + } + else if (!creature.getCardType().contains(CardType.CREATURE)) { + creature.removeAttachment(perm.getId(), this); + somethingHappened = true; + } + } + } + for (Permanent perm: getBattlefield().getActivePermanents(new FilterFortification())) { + if (perm.getAttachedTo() != null) { + Permanent land = getPermanent(perm.getAttachedTo()); + if (land == null) { + perm.attachTo(null); + } + else if (!land.getCardType().contains(CardType.LAND)) { + land.removeAttachment(perm.getId(), this); + somethingHappened = true; + } + } + } + //20091005 - 704.5q + for (Permanent perm: getBattlefield().getActivePermanents()) { + if (perm.getAttachments().size() > 0) { + for (UUID attachmentId: perm.getAttachments()) { + Permanent attachment = getPermanent(attachmentId); + if (!(attachment.getSubtype().contains("Aura") || + attachment.getSubtype().contains("Equipment") || + attachment.getSubtype().contains("Fortification"))) { + perm.removeAttachment(id, this); + return true; + } + } + } + } + + //TODO: implement the rest + + return somethingHappened; + } + + @Override + public void playUntapStep() { + UUID activePlayerId = state.getTurn().getActivePlayerId(); + fireEvent(new GameEvent(GameEvent.EventType.BEGINNING_PHASE_PRE, null, null, activePlayerId)); + if (!replaceEvent(new GameEvent(GameEvent.EventType.UNTAP_STEP, null, null, activePlayerId))) { + //20091005 - 502.1/703.4a + getPlayer(activePlayerId).phasing(this); + //20091005 - 502.2/703.4b + getPlayer(activePlayerId).untap(this); + fireEvent(new GameEvent(GameEvent.EventType.UNTAP_STEP_PRE, null, null, activePlayerId)); + fireEvent(new GameEvent(GameEvent.EventType.UNTAP_STEP_POST, null, null, activePlayerId)); + } + + } + + @Override + public void playUpkeepStep() { + UUID activePlayerId = state.getTurn().getActivePlayerId(); + if (!replaceEvent(new GameEvent(GameEvent.EventType.UPKEEP_STEP, null, null, activePlayerId))) { + fireEvent(new GameEvent(GameEvent.EventType.UPKEEP_STEP_PRE, null, null, activePlayerId)); + playPriority(); + fireEvent(new GameEvent(GameEvent.EventType.UPKEEP_STEP_POST, null, null, activePlayerId)); + } + } + + @Override + public void playDrawStep() { + UUID activePlayerId = state.getTurn().getActivePlayerId(); + if (!replaceEvent(new GameEvent(GameEvent.EventType.DRAW_STEP, null, null, activePlayerId))) { + //20091005 - 504.1/703.4c + getPlayer(activePlayerId).drawCards(1, this); + fireEvent(new GameEvent(GameEvent.EventType.DRAW_STEP_PRE, null, null, activePlayerId)); + playPriority(); + fireEvent(new GameEvent(GameEvent.EventType.DRAW_STEP_POST, null, null, activePlayerId)); + } + } + + @Override + public void playPreCombatMainStep() { + UUID activePlayerId = state.getTurn().getActivePlayerId(); + if (!replaceEvent(new GameEvent(GameEvent.EventType.PRECOMBAT_MAIN_STEP, null, null, activePlayerId))) { + fireEvent(new GameEvent(GameEvent.EventType.PRECOMBAT_MAIN_STEP_PRE, null, null, activePlayerId)); + playPriority(); + fireEvent(new GameEvent(GameEvent.EventType.PRECOMBAT_MAIN_STEP_POST, null, null, activePlayerId)); + } + } + + @Override + public void playBeginCombatStep() { + UUID activePlayerId = state.getTurn().getActivePlayerId(); + if (!replaceEvent(new GameEvent(GameEvent.EventType.BEGIN_COMBAT_STEP, null, null, activePlayerId))) { + //20091005 - 507.1 + state.getCombat().clear(); + state.getCombat().setAttacker(activePlayerId); + for (Player player: state.getPlayers().values()) { + if (!player.getId().equals(state.getTurn().getActivePlayerId())) + state.getCombat().getDefenders().add(player.getId()); + } + fireEvent(new GameEvent(GameEvent.EventType.BEGIN_COMBAT_STEP_PRE, null, null, activePlayerId)); + playPriority(); + fireEvent(new GameEvent(GameEvent.EventType.PRECOMBAT_MAIN_STEP_POST, null, null, activePlayerId)); + } + } + + @Override + public void playDeclareAttackersStep() { + UUID activePlayerId = state.getTurn().getActivePlayerId(); + if (!replaceEvent(new GameEvent(GameEvent.EventType.DECLARE_ATTACKERS_STEP, null, null, activePlayerId))) { + state.getCombat().selectAttackers(this); + fireEvent(new GameEvent(GameEvent.EventType.DECLARE_ATTACKERS_STEP_PRE, null, null, activePlayerId)); + playPriority(); + fireEvent(new GameEvent(GameEvent.EventType.DECLARE_ATTACKERS_STEP_POST, null, null, activePlayerId)); + } + } + + @Override + public void playDeclareBlockersStep() { + UUID activePlayerId = state.getTurn().getActivePlayerId(); + if (!replaceEvent(new GameEvent(GameEvent.EventType.DECLARE_BLOCKERS_STEP, null, null, activePlayerId))) { + state.getCombat().selectBlockers(this); + fireEvent(new GameEvent(GameEvent.EventType.DECLARE_BLOCKERS_STEP_PRE, null, null, activePlayerId)); + playPriority(); + fireEvent(new GameEvent(GameEvent.EventType.DECLARE_BLOCKERS_STEP_POST, null, null, activePlayerId)); + } + } + + @Override + public void playCombatDamageStep(boolean first) { + UUID activePlayerId = state.getTurn().getActivePlayerId(); + if (!replaceEvent(new GameEvent(GameEvent.EventType.COMBAT_DAMAGE_STEP, null, null, activePlayerId))) { + fireEvent(new GameEvent(GameEvent.EventType.COMBAT_DAMAGE_STEP_PRE, null, null, activePlayerId)); + for (CombatGroup group: getCombat().getGroups()) { + group.assignDamage(first, this); + } + playPriority(); + fireEvent(new GameEvent(GameEvent.EventType.COMBAT_DAMAGE_STEP_POST, null, null, activePlayerId)); + } + } + + @Override + public void playEndCombatStep() { + UUID activePlayerId = state.getTurn().getActivePlayerId(); + if (!replaceEvent(new GameEvent(GameEvent.EventType.END_COMBAT_STEP, null, null, activePlayerId))) { + fireEvent(new GameEvent(GameEvent.EventType.END_COMBAT_STEP_PRE, null, null, activePlayerId)); + playPriority(); + fireEvent(new GameEvent(GameEvent.EventType.END_COMBAT_STEP_POST, null, null, activePlayerId)); + removeCreaturesFromCombat(); + } + } + + @Override + public void playPostMainStep() { + UUID activePlayerId = state.getTurn().getActivePlayerId(); + if (!replaceEvent(new GameEvent(GameEvent.EventType.POSTCOMBAT_MAIN_STEP, null, null, activePlayerId))) { + fireEvent(new GameEvent(GameEvent.EventType.POSTCOMBAT_MAIN_STEP_PRE, null, null, activePlayerId)); + playPriority(); + fireEvent(new GameEvent(GameEvent.EventType.POSTCOMBAT_MAIN_STEP_POST, null, null, activePlayerId)); + } + } + + @Override + public void playEndStep() { + UUID activePlayerId = state.getTurn().getActivePlayerId(); + if (!replaceEvent(new GameEvent(GameEvent.EventType.END_TURN_STEP, null, null, activePlayerId))) { + fireEvent(new GameEvent(GameEvent.EventType.END_TURN_STEP_PRE, null, null, activePlayerId)); + playPriority(); + fireEvent(new GameEvent(GameEvent.EventType.END_TURN_STEP_POST, null, null, activePlayerId)); + } + } + + @Override + public void playCleanupStep() { + UUID activePlayerId = state.getTurn().getActivePlayerId(); + if (!replaceEvent(new GameEvent(GameEvent.EventType.CLEANUP_STEP, null, null, activePlayerId))) { + fireEvent(new GameEvent(GameEvent.EventType.CLEANUP_STEP_PRE, null, null, activePlayerId)); + //20091005 - 514.1 + Player player = getPlayer(activePlayerId); + player.discardToMax(this); + state.getBattlefield().endOfTurn(activePlayerId, this); + state.removeEotEffects(this); + if (checkStateAndTriggered()) { + playPriority(); + playCleanupStep(); + } + fireEvent(new GameEvent(GameEvent.EventType.CLEANUP_STEP_POST, null, null, activePlayerId)); + } + } + + @Override + public void addPlayerQueryEventListener(Listener listener) { + playerQueryEventSource.addListener(listener); + } + + @Override + public void firePriorityEvent(UUID playerId) { + String message = this.getStep().toString(); + if (this.getActivePlayerId().equals(playerId) && this.getStack().isEmpty() && this.isMainPhase()) + message += " - play spells and sorceries."; + else + message += " - play instants and activated abilites."; + + playerQueryEventSource.select(playerId, message); + } + + @Override + public void fireSelectEvent(UUID playerId, String message) { + playerQueryEventSource.select(playerId, message); + } + + @Override + public void firePlayManaEvent(UUID playerId, String message) { + playerQueryEventSource.playMana(playerId, message); + } + + @Override + public void firePlayXManaEvent(UUID playerId, String message) { + playerQueryEventSource.playXMana(playerId, message); + } + + @Override + public void fireAskPlayerEvent(UUID playerId, String message) { + playerQueryEventSource.ask(playerId, message); + } + + @Override + public void fireGetChoiceEvent(UUID playerId, String message, Collection choices) { + playerQueryEventSource.chooseAbility(playerId, message, choices); + } + + @Override + public void fireSelectTargetEvent(UUID playerId, String message, boolean required) { + playerQueryEventSource.target(playerId, message, required); + } + + @Override + public void fireSelectTargetEvent(UUID playerId, String message, Cards cards, boolean required) { + playerQueryEventSource.target(playerId, message, cards, required); + } + + @Override + public void fireGetAmountEvent(UUID playerId, String message, int min, int max) { + playerQueryEventSource.amount(playerId, message, min, max); + } + + @Override + public void fireChooseEvent(UUID playerId, Choice choice) { + playerQueryEventSource.choose(playerId, choice.getMessage(), choice.getChoices().toArray(new String[0])); + } + + @Override + public void informPlayers(String message) { + state.addMessage(message); + fireInformEvent(message); + } + + @Override + public void fireInformEvent(String message) { + tableEventSource.fireTableEvent(EventType.INFO, message, this); + } + + @Override + public void fireUpdatePlayersEvent() { + tableEventSource.fireTableEvent(EventType.UPDATE, null, this); + } + + @Override + public Players getPlayers() { + return state.getPlayers(); + } + + @Override + public PlayerList getPlayerList(UUID playerId) { + return state.getPlayerList(playerId); + } + + @Override + public TurnPhase getPhase() { + return state.getPhase(); + } + + @Override + public PhaseStep getStep() { + return state.getStep(); + } + + @Override + public Battlefield getBattlefield() { + return state.getBattlefield(); + } + + @Override + public SpellStack getStack() { + return state.getStack(); + } + + @Override + public Exile getExile() { + return state.getExile(); + } + + @Override + public Combat getCombat() { + return state.getCombat(); + } + + @Override + public int getTurnNum() { + return state.getTurnNum(); + } + + @Override + public boolean isMainPhase() { + return state.getStep() == PhaseStep.PRECOMBAT_MAIN || state.getStep() == PhaseStep.POSTCOMBAT_MAIN; + } + + + @Override + public UUID getActivePlayerId() { + return state.getTurn().getActivePlayerId(); + } + + @Override + public UUID getPriorityPlayerId() { + return state.getTurn().getPriorityPlayerId(); + } + + @Override + public void fireEvent(GameEvent event) { + applyEffects(); + state.handleEvent(event, this); + } + + @Override + public boolean replaceEvent(GameEvent event) { + applyEffects(); + return state.replaceEvent(event, this); + } + + protected void removeCreaturesFromCombat() { + //20091005 - 511.3 + getCombat().endCombat(this); + } + + @Override + public ContinuousEffects getContinuousEffects() { + return state.getContinuousEffects(); + } + +} diff --git a/Mage/src/mage/game/GameReplay.java b/Mage/src/mage/game/GameReplay.java new file mode 100644 index 00000000000..394d5270173 --- /dev/null +++ b/Mage/src/mage/game/GameReplay.java @@ -0,0 +1,62 @@ +/* +* 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; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class GameReplay { + + private GameStates savedGame; + private int stateIndex; + + public GameReplay(GameStates savedGame) { + this.savedGame = savedGame; + } + + public void start() { + this.stateIndex = 0; + } + + public GameState next() { + if (this.stateIndex < savedGame.getStates().size()) { + return savedGame.getStates().get(stateIndex++); + } + return null; + } + + public GameState previous() { + if (this.stateIndex > 0) { + return savedGame.getStates().get(--stateIndex); + } + return null; + } + +} diff --git a/Mage/src/mage/game/GameState.java b/Mage/src/mage/game/GameState.java new file mode 100644 index 00000000000..55a9bea7dc0 --- /dev/null +++ b/Mage/src/mage/game/GameState.java @@ -0,0 +1,267 @@ +/* +* 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; + +import mage.abilities.TriggeredAbility; +import mage.game.events.GameEvent; +import mage.game.stack.SpellStack; +import mage.game.stack.StackObject; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import mage.Constants.PhaseStep; +import mage.Constants.TurnPhase; +import mage.Constants.Zone; +import mage.MageObject; +import mage.abilities.TriggeredAbilities; +import mage.abilities.effects.ContinuousEffect; +import mage.abilities.effects.ContinuousEffects; +import mage.game.combat.Combat; +import mage.game.permanent.Battlefield; +import mage.game.permanent.Permanent; +import mage.game.turn.Turn; +import mage.players.Player; +import mage.players.PlayerList; +import mage.players.Players; +import mage.util.Copier; + +/** + * + * @author BetaSteward_at_googlemail.com + * + * since at any time the game state may be copied and restored you cannot + * rely on any object maintaining it's instance + * it then becomes necessary to only refer to objects by their ids since + * these will always remain constant throughout its lifetime + * + */ +public class GameState implements Serializable { + + private static final transient Copier copier = new Copier(); + private Players players = new Players(); + private Turn turn = new Turn(); + private SpellStack stack = new SpellStack(); + private Exile exile = new Exile(); + private Battlefield battlefield = new Battlefield(); + private int turnNum = 0; + private boolean gameOver = false; + private List messages = new ArrayList(); + private ContinuousEffects effects = new ContinuousEffects(); + private TriggeredAbilities triggers = new TriggeredAbilities(); + private Combat combat = new Combat(); + + public void addPlayer(Player player) { + players.put(player.getId(), player); + } + + public Players getPlayers() { + return players; + } + + public Player getPlayer(UUID playerId) { + return players.get(playerId); + } + + public TurnPhase getPhase() { + return turn.getPhase(); + } + + public PhaseStep getStep() { + return turn.getStep(); + } + + public Battlefield getBattlefield() { + return this.battlefield; + } + + public SpellStack getStack() { + return this.stack; + } + + public Exile getExile() { + return exile; + } + + public Turn getTurn() { + return turn; + } + + public Combat getCombat() { + return combat; + } + + public int getTurnNum() { + return turnNum; + } + + public void setTurnNum(int turnNum) { + this.turnNum = turnNum; + } + + public boolean isGameOver() { + return this.gameOver; + } + + public void endGame() { + this.gameOver = true; + } + + public void applyEffects(Game game) { + for (Player player: players.values()) { + player.reset(); + } + battlefield.reset(); + effects.apply(game); + } + + public void removeEotEffects(Game game) { + effects.removeEndOfTurnEffects(); + applyEffects(game); + } + + public void addEffect(ContinuousEffect effect) { + effects.addEffect(effect); + } + +// public boolean effectExists(UUID effectId) { +// return effects.effectExists(effectId); +// } + + public void addMessage(String message) { + this.messages.add(message); + } + + public PlayerList getPlayerList(UUID playerId) { + PlayerList playerList = new PlayerList(); + for (Player player: players.values()) { + if (!player.hasLeft()) + playerList.add(player); + } + playerList.setCurrent(playerId); + return playerList; + } + + public MageObject getObject(UUID objectId) { + MageObject object; + if (battlefield.containsPermanent(objectId)) { + object = battlefield.getPermanent(objectId); + object.setZone(Zone.BATTLEFIELD); + return object; + } + for(Player player: players.values()) { + if (player.getHand().containsKey(objectId)) { + object = player.getHand().get(objectId); + object.setZone(Zone.HAND); + return object; + } + if (player.getGraveyard().containsKey(objectId)) { + object = player.getGraveyard().get(objectId); + object.setZone(Zone.GRAVEYARD); + return object; + } +// if (player.getLibrary().containsKey(objectId)) { +// return player.getLibrary().get(objectId); +// } +// for (Cards cards: player..values()) { +// if (cards.containsKey(id)) +// return cards.get(id); +// } +// if (player.getSideboard().containsKey(id)) { +// return player.getSideboard().get(id); +// } + } + for (StackObject item: stack) { + if (item.getId().equals(objectId)) { + item.setZone(Zone.STACK); + return item; + } + } + + return null; + } + + public Permanent getPermanent(UUID permanentId) { + Permanent permanent; + if (battlefield.containsPermanent(permanentId)) { + permanent = battlefield.getPermanent(permanentId); + permanent.setZone(Zone.BATTLEFIELD); + return permanent; + } + return null; + } + + public GameState copy() { + + return copier.copy(this); + + } + + public void restore(GameState state) { + this.stack = state.stack; + this.effects = state.effects; + this.triggers = state.triggers; + this.combat = state.combat; + this.exile = state.exile; + this.battlefield = state.battlefield; + for (Player copyPlayer: state.players.values()) { + Player origPlayer = players.get(copyPlayer.getId()); + origPlayer.restore(copyPlayer); + } + } + + public void handleEvent(GameEvent event, Game game) { + if (!replaceEvent(event, game)) { + for (Player player: players.values()) { + player.handleEvent(event, game); + } + } + battlefield.handleEvent(event, game); + stack.handleEvent(event, game); + exile.handleEvent(event, game); + } + + public boolean replaceEvent(GameEvent event, Game game) { + return stack.replaceEvent(event, game) | effects.replaceEvent(event, game); + + } + + public void addTriggeredAbility(TriggeredAbility ability) { + this.triggers.add(ability); + } + + public TriggeredAbilities getTriggered() { + return this.triggers; + } + + ContinuousEffects getContinuousEffects() { + return effects; + } + +} diff --git a/Mage/src/mage/game/GameStates.java b/Mage/src/mage/game/GameStates.java new file mode 100644 index 00000000000..57e37f71f5d --- /dev/null +++ b/Mage/src/mage/game/GameStates.java @@ -0,0 +1,56 @@ +/* +* 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; + +import java.util.LinkedList; +import java.util.List; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class GameStates { + + private List states = new LinkedList(); + + public void save(GameState gameState) { + states.add(gameState.copy()); + } + + public List getStates() { + return states; + } + + public GameState rollback(int index) { + while (states.size() > index) { + states.remove(index); + } + return states.get(index - 1); + } +} diff --git a/Mage/src/mage/game/Seat.java b/Mage/src/mage/game/Seat.java new file mode 100644 index 00000000000..915983ca88e --- /dev/null +++ b/Mage/src/mage/game/Seat.java @@ -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.game; + +import java.io.Serializable; +import java.util.logging.Logger; +import mage.players.Player; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class Seat implements Serializable { + + private final static Logger logger = Logger.getLogger(Seat.class.getName()); + + private String playerType; + private Player player; + + public Seat(String playerType) { + this.playerType = playerType; + } + + public String getPlayerType() { + return playerType; + } + + public void setPlayerType(String playerType) { + this.playerType = playerType; + } + + public Player getPlayer() { + return player; + } + + public void setPlayer(Player player) { + this.player = player; + } + +} diff --git a/Mage/src/mage/game/Table.java b/Mage/src/mage/game/Table.java new file mode 100644 index 00000000000..0720fa8e3b3 --- /dev/null +++ b/Mage/src/mage/game/Table.java @@ -0,0 +1,152 @@ +/* +* 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; + +import java.io.Serializable; +import java.util.List; +import java.util.UUID; +import mage.Constants.DeckType; +import mage.Constants.TableState; +import mage.MageItem; +import mage.cards.decks.DeckValidator; +import mage.cards.decks.DeckValidatorFactory; +import mage.players.Player; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class Table implements MageItem, Serializable { + + private UUID tableId; + private String name; + private Game game; + private DeckType deckType; + private Seat[] seats; + private int numSeats; + private DeckValidator validator; + private TableState state = TableState.WAITING; + + public Table(Game game, DeckType deckType, List playerTypes) { + tableId = UUID.randomUUID(); + this.numSeats = game.getNumPlayers(); + this.game = game; + this.deckType = deckType; + createSeats(playerTypes); + this.validator = DeckValidatorFactory.getInstance().createDeckValidator(deckType); + } + + private void createSeats(List playerTypes) { + int i = 0; + seats = new Seat[numSeats]; + for(String playerType: playerTypes) { + seats[i] = new Seat(playerType); + i++; + } + } + + @Override + public UUID getId() { + return tableId; + } + + public void setGame(Game game) { + this.game = game; + } + + public void initGame() throws GameException { + for (int i = 0; i < numSeats; i++ ) { + game.addPlayer(seats[i].getPlayer()); + } + state = TableState.DUELING; + } + + public void replayGame() { + + } + + public void endGame() { + state = TableState.FINISHED; + } + + public String getGameType() { + return game.getGameType(); + } + + public DeckType getDeckType() { + return deckType; + } + + public UUID joinTable(Player player, int seatNum) throws GameException { + if (seatNum >= numSeats || seatNum < 0) { + throw new GameException("Invalid seat number"); + } + if (seats[seatNum].getPlayer() != null) { + throw new GameException("Seat is occupied."); + } + this.seats[seatNum].setPlayer(player); + if (isReady()) + state = TableState.STARTING; + return this.seats[seatNum].getPlayer().getId(); + } + + private boolean isReady() { + for (int i = 0; i < numSeats; i++ ) { + if (seats[i].getPlayer() == null) + return false; + } + return true; + } + + public Seat[] getSeats() { + return seats; + } + + public void leaveTable(UUID playerId) { + for (int i = 0; i < numSeats; i++ ) { + if (seats[i].getPlayer().getId().equals(playerId)) + seats[i].setPlayer(null); + } + + } + + public TableState getState() { + return state; + } + + public DeckValidator getValidator() { + return this.validator; + } + +// public void checkTable() { +// if (game != null && state == TableState.DUELING && game.isGameOver()) +// state = TableState.FINISHED; +// } + +} diff --git a/Mage/src/mage/game/Team.java b/Mage/src/mage/game/Team.java new file mode 100644 index 00000000000..dfd0b936909 --- /dev/null +++ b/Mage/src/mage/game/Team.java @@ -0,0 +1,59 @@ +/* +* 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; + +import java.util.UUID; +import mage.MageItem; +import mage.players.Player; +import mage.players.Players; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class Team implements MageItem { + + private UUID teamId; + private String name; + private Players players = new Players(); + + public Team (String name) { + teamId = UUID.randomUUID(); + this.name = name; + } + + public UUID getId() { + return teamId; + } + + public void addPlayer(Player player) { + players.addPlayer(player); + } + +} diff --git a/Mage/src/mage/game/combat/Combat.java b/Mage/src/mage/game/combat/Combat.java new file mode 100644 index 00000000000..8ec7b34ba64 --- /dev/null +++ b/Mage/src/mage/game/combat/Combat.java @@ -0,0 +1,162 @@ +/* +* 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.combat; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import mage.abilities.keyword.VigilanceAbility; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.permanent.Permanent; + + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class Combat implements Serializable { + + protected List groups = new ArrayList(); + protected List defenders = new ArrayList(); + protected UUID attackerId; + + public List getGroups() { + return groups; + } + + public List getDefenders() { + return defenders; + } + + public List getAttackers() { + List attackers = new ArrayList(); + for (CombatGroup group: groups) { + attackers.addAll(group.attackers); + } + return attackers; + } + + public void clear() { + groups.clear(); + defenders.clear(); + attackerId = null; + } + + public void setAttacker(UUID playerId) { + this.attackerId = playerId; + } + + public void selectAttackers(Game game) { + if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.DECLARING_ATTACKERS, attackerId, attackerId))) { + game.getPlayer(attackerId).selectAttackers(game); + game.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_ATTACKERS, attackerId, attackerId)); + } + } + + public void selectBlockers(Game game) { + if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.DECLARING_BLOCKERS, attackerId, attackerId))) { + for (UUID defenderId: defenders) { + game.getPlayer(defenderId).selectBlockers(game); + game.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_BLOCKERS, defenderId, defenderId)); + } + } + } + + public void declareAttacker(UUID attackerId, UUID defenderId, Game game) { + Permanent defender = game.getPermanent(defenderId); + CombatGroup newGroup = new CombatGroup(defenderId, defender != null); + newGroup.attackers.add(attackerId); + Permanent attacker = game.getPermanent(attackerId); + if (!attacker.getAbilities().containsKey(VigilanceAbility.getInstance().getId())) + attacker.setTapped(true); + attacker.setAttacking(true); + groups.add(newGroup); + } + + public void removeFromCombat(UUID creatureId, Game game) { + Permanent creature = game.getPermanent(creatureId); + if (creature != null) { + creature.setAttacking(false); + creature.setBlocking(false); + for (CombatGroup group: groups) { + group.remove(creatureId); + } + } + } + + public void endCombat(Game game) { + Permanent creature; + for (CombatGroup group: groups) { + for (UUID attacker: group.attackers) { + creature = game.getPermanent(attacker); + if (creature != null) { + creature.setAttacking(false); + creature.setBlocking(false); + } + } + for (UUID blocker: group.blockers) { + creature = game.getPermanent(blocker); + if (creature != null) { + creature.setAttacking(false); + creature.setBlocking(false); + } + } + } + clear(); + } + + public boolean hasFirstOrDoubleStrike(Game game) { + for (CombatGroup group: groups) { + if (group.hasFirstOrDoubleStrike(game)) + return true; + } + return false; + } + + public CombatGroup findGroup(UUID attackerId) { + for (CombatGroup group: groups) { + if (group.getAttackers().contains(attackerId)) + return group; + } + return null; + } + + public int totalUnblockedDamage(Game game) { + int total = 0; + for (CombatGroup group: groups) { + if (group.getBlockers().isEmpty()) { + total += group.totalAttackerDamage(game); + } + } + return total; + } + +} diff --git a/Mage/src/mage/game/combat/CombatGroup.java b/Mage/src/mage/game/combat/CombatGroup.java new file mode 100644 index 00000000000..63f2f27cbe2 --- /dev/null +++ b/Mage/src/mage/game/combat/CombatGroup.java @@ -0,0 +1,251 @@ +/* +* 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.combat; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import mage.abilities.keyword.DoubleStrikeAbility; +import mage.abilities.keyword.FirstStrikeAbility; +import mage.abilities.keyword.TrampleAbility; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.permanent.Permanent; +import mage.players.Player; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class CombatGroup implements Serializable { + + protected List attackers = new ArrayList(); + protected List blockers = new ArrayList(); + protected List blockerOrder = new ArrayList(); + protected boolean blocked; + protected UUID defenderId; + protected boolean defenderIsPlaneswalker; + + public CombatGroup(UUID defenderId, boolean defenderIsPlaneswalker) { + this.defenderId = defenderId; + this.defenderIsPlaneswalker = defenderIsPlaneswalker; + } + + public boolean hasFirstOrDoubleStrike(Game game) { + for (UUID permId: attackers) { + if (hasFirstOrDoubleStrike(game.getPermanent(permId))) { + return true; + } + } + for (UUID permId: blockers) { + if (hasFirstOrDoubleStrike(game.getPermanent(permId))) { + return true; + } + } + return false; + } + + public UUID getDefenderId() { + return defenderId; + } + + public List getAttackers() { + return attackers; + } + + public List getBlockers() { + return blockers; + } + + public List getBlockerOrder() { + return blockerOrder; + } + + private boolean hasFirstOrDoubleStrike(Permanent perm) { + return perm.getAbilities().containsKey(FirstStrikeAbility.getInstance().getId()) || perm.getAbilities().containsKey(DoubleStrikeAbility.getInstance().getId()); + } + + private boolean hasFirstStrike(Permanent perm) { + return perm.getAbilities().containsKey(FirstStrikeAbility.getInstance().getId()); + } + + private boolean hasTrample(Permanent perm) { + return perm.getAbilities().containsKey(TrampleAbility.getInstance().getId()); + } + + public void assignDamage(boolean first, Game game) { + if (attackers.size() > 0 && (!first || hasFirstOrDoubleStrike(game))) { + if (blockers.size() == 0) { + unblockedDamage(first, game); + } + else if (blockers.size() == 1) { + singleBlockerDamage(first, game); + } + else { + multiBlockerDamage(first, game); + } + } + } + + private boolean canDamage(Permanent perm, boolean first) { + return (first && hasFirstOrDoubleStrike(perm)) || (!first && !hasFirstStrike(perm)); + } + + private void unblockedDamage(boolean first, Game game) { + for (UUID attackerId: attackers) { + Permanent attacker = game.getPermanent(attackerId); + if (canDamage(attacker, first)) { + //20091005 - 510.1c, 702.17c + if (!blocked || hasTrample(attacker)) + defenderDamage(attacker, attacker.getPower().getValue(), game); + } + } + } + + private void singleBlockerDamage(boolean first, Game game) { + //TODO: handle banding + Permanent blocker = game.getPermanent(blockers.get(0)); + Permanent attacker = game.getPermanent(attackers.get(0)); + if (blocker != null && attacker != null) { + if (canDamage(attacker, first)) { + int damage = attacker.getPower().getValue(); + if (hasTrample(attacker)) { + int lethalDamage = blocker.getToughness().getValue() - blocker.getDamage(); + if (lethalDamage >= damage) { + blocker.damage(damage, attacker.getId(), game); + } + else { + Player player = game.getPlayer(attacker.getControllerId()); + int damageAssigned = player.getAmount(lethalDamage, damage, "Assign damage to " + blocker.getName(), game); + blocker.damage(damageAssigned, attacker.getId(), game); + damage -= damageAssigned; + if (damage > 0) + defenderDamage(attacker, damage, game); + } + } + else { + blocker.damage(damage, attacker.getId(), game); + } + } + if (canDamage(blocker, first)) { + attacker.damage(blocker.getPower().getValue(), blocker.getId(), game); + } + } + } + + private void multiBlockerDamage(boolean first, Game game) { + //TODO: handle banding + Permanent attacker = game.getPermanent(attackers.get(0)); + Player player = game.getPlayer(attacker.getControllerId()); + int damage = attacker.getPower().getValue(); + if (attacker != null && canDamage(attacker, first)) { + for (UUID blockerId: blockerOrder) { + Permanent blocker = game.getPermanent(blockerId); + int lethalDamage = blocker.getToughness().getValue() - blocker.getDamage(); + if (lethalDamage >= damage) { + blocker.damage(damage, attacker.getId(), game); + damage = 0; + break; + } + int damageAssigned = player.getAmount(lethalDamage, damage, "Assign damage to " + blocker.getName(), game); + blocker.damage(damageAssigned, attacker.getId(), game); + damage -= damageAssigned; + } + if (damage > 0 && hasTrample(attacker)) { + defenderDamage(attacker, damage, game); + } + for (UUID blockerId: blockerOrder) { + Permanent blocker = game.getPermanent(blockerId); + if (canDamage(blocker, first)) { + attacker.damage(blocker.getPower().getValue(), blocker.getId(), game); + } + } + } + } + + private void defenderDamage(Permanent attacker, int amount, Game game) { + if (this.defenderIsPlaneswalker) { + Permanent defender = game.getPermanent(defenderId); + if (defender != null) { + defender.damage(amount, attacker.getId(), game); + } + } + else { + Player defender = game.getPlayer(defenderId); + defender.damage(amount, attacker.getId(), game); + } + } + + public boolean canBlock(Permanent blocker, Game game) { + for (UUID attackerId: attackers) { + if (!blocker.canBlock(attackerId, game)) + return false; + } + return true; + } + + public void addBlocker(UUID blockerId, UUID playerId, Game game) { + for (UUID attackerId: attackers) { + if (game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.DECLARE_BLOCKER, blockerId, attackerId, playerId))) { + return; + } + } + game.getPermanent(blockerId).setBlocking(true); + blockers.add(blockerId); + this.blocked = true; + for (UUID attackerId: attackers) { + game.fireEvent(GameEvent.getEvent(GameEvent.EventType.BLOCKER_DECLARED, blockerId, attackerId, playerId)); + } + } + + public int totalAttackerDamage(Game game) { + int total = 0; + for (UUID attackerId: attackers) { + total += game.getPermanent(attackerId).getPower().getValue(); + } + return total; + } + + public boolean isDefenderIsPlaneswalker() { + return defenderIsPlaneswalker; + } + + void remove(UUID creatureId) { + if (attackers.contains(creatureId)) { + attackers.remove(creatureId); + } + if (blockers.contains(creatureId)) { + blockers.remove(creatureId); + if (blockerOrder.contains(creatureId)) + blockerOrder.remove(creatureId); + } + } + +} diff --git a/Mage/src/mage/game/events/EventDispatcher.java b/Mage/src/mage/game/events/EventDispatcher.java new file mode 100644 index 00000000000..a603b33ebbd --- /dev/null +++ b/Mage/src/mage/game/events/EventDispatcher.java @@ -0,0 +1,58 @@ +/* +* 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.events; + +import java.io.Serializable; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public abstract class EventDispatcher implements Serializable { + + private List> listeners = new CopyOnWriteArrayList>(); + + public void addListener(Listener listener) { + if (!listeners.contains(listener)) { + listeners.add(listener); + } + } + + public void removeListener(Listener listener) { + listeners.remove(listener); + } + + public void fireEvent(E event) { + for (Listener listener : listeners) { + listener.event(event); + } + } +} diff --git a/Mage/src/mage/game/events/EventSource.java b/Mage/src/mage/game/events/EventSource.java new file mode 100644 index 00000000000..091f9a5781c --- /dev/null +++ b/Mage/src/mage/game/events/EventSource.java @@ -0,0 +1,40 @@ +/* +* 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.events; + +import java.io.Serializable; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public interface EventSource extends Serializable { + + void addListener(Listener listener); +} diff --git a/Mage/src/mage/game/events/ExternalEvent.java b/Mage/src/mage/game/events/ExternalEvent.java new file mode 100644 index 00000000000..310416cb777 --- /dev/null +++ b/Mage/src/mage/game/events/ExternalEvent.java @@ -0,0 +1,39 @@ +/* +* 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.events; + +import java.io.Serializable; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public interface ExternalEvent extends Serializable { + +} diff --git a/Mage/src/mage/game/events/GameEvent.java b/Mage/src/mage/game/events/GameEvent.java new file mode 100644 index 00000000000..a7c9c5e3933 --- /dev/null +++ b/Mage/src/mage/game/events/GameEvent.java @@ -0,0 +1,150 @@ +/* +* 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.events; + +import java.util.UUID; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class GameEvent { + + private EventType type; + private UUID targetId; + private UUID sourceId; + private UUID playerId; + private int amount; + + public enum EventType { + + //Turn-based events + BEGINNING_PHASE_PRE, BEGINNING_PHASE_POST, + UNTAP_STEP_PRE, UNTAP_STEP, UNTAP_STEP_POST, + UPKEEP_STEP_PRE, UPKEEP_STEP, UPKEEP_STEP_POST, + DRAW_STEP_PRE, DRAW_STEP, DRAW_STEP_POST, + PRECOMBAT_MAIN_STEP_PRE, PRECOMBAT_MAIN_STEP, PRECOMBAT_MAIN_STEP_POST, + COMBAT_PHASE_PRE, COMBAT_PHASE_POST, + BEGIN_COMBAT_STEP_PRE, BEGIN_COMBAT_STEP, BEGIN_COMBAT_STEP_POST, + DECLARE_ATTACKERS_STEP_PRE, DECLARE_ATTACKERS_STEP, DECLARE_ATTACKERS_STEP_POST, + DECLARE_BLOCKERS_STEP_PRE, DECLARE_BLOCKERS_STEP, DECLARE_BLOCKERS_STEP_POST, + COMBAT_DAMAGE_STEP_PRE, COMBAT_DAMAGE_STEP, COMBAT_DAMAGE_STEP_POST, + END_COMBAT_STEP_PRE, END_COMBAT_STEP, END_COMBAT_STEP_POST, + POSTCOMBAT_MAIN_STEP_PRE, POSTCOMBAT_MAIN_STEP, POSTCOMBAT_MAIN_STEP_POST, + END_PHASE_PRE, END_PHASE_POST, + END_TURN_STEP_PRE, END_TURN_STEP, END_TURN_STEP_POST, + CLEANUP_STEP_PRE, CLEANUP_STEP, CLEANUP_STEP_POST, + + EMPTY_MANA_POOLS, + AT_END_OF_TURN, + + //player events + ZONE_CHANGE, + DRAW_CARD, DREW_CARD, + DISCARD_CARD, DISCARDED_CARD, + DAMAGE_PLAYER, DAMAGED_PLAYER, + PLAYER_LIFE_CHANGE, + PLAY_LAND, LAND_PLAYED, + CAST_SPELL, SPELL_CAST, + ACTIVATE_ABILITY, ACTIVATED_ABILITY, + LOSES, WINS, + TARGET, TARGETED, + COUNTER, COUNTERED, + DECLARING_ATTACKERS, DECLARED_ATTACKERS, + DECLARE_ATTACKER, ATTACKER_DECLARED, + DECLARING_BLOCKERS, DECLARED_BLOCKERS, + DECLARE_BLOCKER, BLOCKER_DECLARED, + + //permanent events + TAP, TAPPED, + UNTAP, UNTAPPED, + FLIP, FLIPPED, + UNFLIP, UNFLIPPED, + PHASE_OUT, PHASED_OUT, + PHASE_IN, PHASED_IN, + TURNFACEUP, TURNEDFACEUP, + TURNFACEDOWN, TURNEDFACEDOWN, + DAMAGE_CREATURE, DAMAGED_CREATURE, + DAMAGE_PLANESWALKER, DAMAGED_PLANESWALKER, + DESTROY_PERMANENT, DESTROYED_PERMANENT, + SACRIFICE_PERMANENT, SACRIFICED_PERMANENT, + ATTACH, ATTACHED, + UNATTACH, UNATTACHED, + + //combat events + COMBAT_DAMAGE_APPLIED, + SELECTED_ATTACKER, SELECTED_BLOCKER; + + } + + public GameEvent(EventType type, UUID targetId, UUID sourceId, UUID playerId) { + this(type, targetId, sourceId, playerId, 0); + } + + public GameEvent(EventType type, UUID targetId, UUID sourceId, UUID playerId, int amount) { + this.type = type; + this.targetId = targetId; + this.sourceId = sourceId; + this.amount = amount; + this.playerId = playerId; + } + + public static GameEvent getEvent(EventType type, UUID targetId, UUID sourceId, UUID playerId, int amount) { + return new GameEvent(type, targetId, sourceId, playerId, amount); + } + + public static GameEvent getEvent(EventType type, UUID targetId, UUID sourceId, UUID playerId) { + return new GameEvent(type, targetId, sourceId, playerId); + } + + public static GameEvent getEvent(EventType type, UUID targetId, UUID playerId) { + return new GameEvent(type, targetId, null, playerId); + } + + public EventType getType() { + return type; + } + + public UUID getTargetId() { + return targetId; + } + + public UUID getSourceId() { + return sourceId; + } + + public UUID getPlayerId() { + return playerId; + } + + public int getAmount() { + return amount; + } + +} diff --git a/Mage/src/mage/game/events/Listener.java b/Mage/src/mage/game/events/Listener.java new file mode 100644 index 00000000000..ee35c0ba48f --- /dev/null +++ b/Mage/src/mage/game/events/Listener.java @@ -0,0 +1,39 @@ +/* +* 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.events; + +import java.io.Serializable; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public interface Listener extends Serializable { + void event(E event); +} diff --git a/Mage/src/mage/game/events/MageEvent.java b/Mage/src/mage/game/events/MageEvent.java new file mode 100644 index 00000000000..75355c74638 --- /dev/null +++ b/Mage/src/mage/game/events/MageEvent.java @@ -0,0 +1,39 @@ +/* +* 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.events; + +import java.io.Serializable; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public interface MageEvent extends Serializable { + +} diff --git a/Mage/src/mage/game/events/PlayerQueryEvent.java b/Mage/src/mage/game/events/PlayerQueryEvent.java new file mode 100644 index 00000000000..597b2b9705c --- /dev/null +++ b/Mage/src/mage/game/events/PlayerQueryEvent.java @@ -0,0 +1,141 @@ +/* +* 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.events; + +import java.io.Serializable; +import java.util.Collection; +import java.util.EventObject; +import java.util.UUID; +import mage.abilities.ActivatedAbility; +import mage.cards.Cards; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class PlayerQueryEvent extends EventObject implements ExternalEvent, Serializable { + + public enum QueryType { + ASK, CHOOSE, CHOOSE_ABILITY, PICK_TARGET, SELECT, PLAY_MANA, PLAY_X_MANA, AMOUNT + } + + private String message; + private Collection abilities; + private String[] choices; + private Cards cards; + private QueryType queryType; + private UUID playerId; + private boolean required; + private int min; + private int max; + + private PlayerQueryEvent(UUID playerId, String message, Collection abilities, String[] choices, Cards cards, QueryType queryType, int min, int max, boolean required) { + super(playerId); + this.queryType = queryType; + this.message = message; + this.playerId = playerId; + this.abilities = abilities; + this.choices = choices; + this.cards = cards; + this.required = required; + this.min = min; + this.max = max; + } + + public static PlayerQueryEvent askEvent(UUID playerId, String message) { + return new PlayerQueryEvent(playerId, message, null, null, null, QueryType.ASK, 0, 0, false); + } + + public static PlayerQueryEvent chooseAbilityEvent(UUID playerId, String message, Collection choices) { + return new PlayerQueryEvent(playerId, message, choices, null, null, QueryType.CHOOSE_ABILITY, 0, 0, false); + } + public static PlayerQueryEvent chooseEvent(UUID playerId, String message, String[] choices) { + return new PlayerQueryEvent(playerId, message, null, choices, null, QueryType.CHOOSE, 0, 0, false); + } + + public static PlayerQueryEvent targetEvent(UUID playerId, String message, boolean required) { + return new PlayerQueryEvent(playerId, message, null, null, null, QueryType.PICK_TARGET, 0, 0, required); + } + + public static PlayerQueryEvent targetEvent(UUID playerId, String message, Cards cards, boolean required) { + return new PlayerQueryEvent(playerId, message, null, null, cards, QueryType.PICK_TARGET, 0, 0, required); + } + + public static PlayerQueryEvent selectEvent(UUID playerId, String message) { + return new PlayerQueryEvent(playerId, message, null, null, null, QueryType.SELECT, 0, 0, false); + } + + public static PlayerQueryEvent playManaEvent(UUID playerId, String message) { + return new PlayerQueryEvent(playerId, message, null, null, null, QueryType.PLAY_MANA, 0, 0, false); + } + + public static PlayerQueryEvent playXManaEvent(UUID playerId, String message) { + return new PlayerQueryEvent(playerId, message, null, null, null, QueryType.PLAY_X_MANA, 0, 0, false); + } + + public static PlayerQueryEvent amountEvent(UUID playerId, String message, int min , int max) { + return new PlayerQueryEvent(playerId, message, null, null, null, QueryType.AMOUNT, min, max, false); + } + + public String getMessage() { + return message; + } + + public QueryType getQueryType() { + return queryType; + } + + public Collection getAbilities() { + return abilities; + } + + public String[] getChoices() { + return choices; + } + + public UUID getPlayerId() { + return playerId; + } + + public boolean isRequired() { + return required; + } + + public Cards getCards() { + return cards; + } + + public int getMin() { + return min; + } + + public int getMax() { + return max; + } +} diff --git a/Mage/src/mage/game/events/PlayerQueryEventSource.java b/Mage/src/mage/game/events/PlayerQueryEventSource.java new file mode 100644 index 00000000000..d40aa14543f --- /dev/null +++ b/Mage/src/mage/game/events/PlayerQueryEventSource.java @@ -0,0 +1,86 @@ +/* +* 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.events; + +import java.io.Serializable; +import java.util.Collection; +import java.util.List; +import java.util.UUID; +import mage.abilities.ActivatedAbility; +import mage.cards.Cards; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class PlayerQueryEventSource implements EventSource, Serializable { + + protected final EventDispatcher dispatcher = new EventDispatcher() {}; + + public void addListener(Listener listener) { + dispatcher.addListener(listener); + } + + public void ask(UUID playerId, String message) { + dispatcher.fireEvent(PlayerQueryEvent.askEvent(playerId, message)); + } + + public void select(UUID playerId, String message) { + dispatcher.fireEvent(PlayerQueryEvent.selectEvent(playerId, message)); + } + + public void chooseAbility(UUID playerId, String message, Collection choices) { + dispatcher.fireEvent(PlayerQueryEvent.chooseAbilityEvent(playerId, message, choices)); + } + + public void target(UUID playerId, String message, boolean required) { + dispatcher.fireEvent(PlayerQueryEvent.targetEvent(playerId, message, required)); + } + + public void target(UUID playerId, String message, Cards cards, boolean required) { + dispatcher.fireEvent(PlayerQueryEvent.targetEvent(playerId, message, cards, required)); + } + + public void playMana(UUID playerId, String message) { + dispatcher.fireEvent(PlayerQueryEvent.playManaEvent(playerId, message)); + } + + public void amount(UUID playerId, String message, int min, int max) { + dispatcher.fireEvent(PlayerQueryEvent.amountEvent(playerId, message, min, max)); + } + + public void choose(UUID playerId, String message, String[] choices) { + dispatcher.fireEvent(PlayerQueryEvent.chooseEvent(playerId, message, choices)); + } + + public void playXMana(UUID playerId, String message) { + dispatcher.fireEvent(PlayerQueryEvent.playXManaEvent(playerId, message)); + } + +} diff --git a/Mage/src/mage/game/events/TableEvent.java b/Mage/src/mage/game/events/TableEvent.java new file mode 100644 index 00000000000..d1e13cba757 --- /dev/null +++ b/Mage/src/mage/game/events/TableEvent.java @@ -0,0 +1,68 @@ +/* +* 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.events; + +import java.io.Serializable; +import java.util.EventObject; +import mage.game.Game; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class TableEvent extends EventObject implements ExternalEvent, Serializable { + + public enum EventType { + UPDATE, INFO + } + + private Game game; + private EventType eventType; + private String message; + + public TableEvent(EventType eventType, String message, Game game) { + super(game); + this.game = game; + this.message = message; + this.eventType = eventType; + } + + public Game getGame() { + return game; + } + + public EventType getEventType() { + return eventType; + } + + public String getMessage() { + return message; + } + +} diff --git a/Mage/src/mage/game/events/TableEventSource.java b/Mage/src/mage/game/events/TableEventSource.java new file mode 100644 index 00000000000..fc25eb500b4 --- /dev/null +++ b/Mage/src/mage/game/events/TableEventSource.java @@ -0,0 +1,49 @@ +/* +* 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.events; + +import java.io.Serializable; +import mage.game.Game; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class TableEventSource implements EventSource, Serializable { + + protected final EventDispatcher dispatcher = new EventDispatcher() {}; + + public void addListener(Listener listener) { + dispatcher.addListener(listener); + } + + public void fireTableEvent(TableEvent.EventType eventType, String message, Game game) { + dispatcher.fireEvent(new TableEvent(eventType, message, game)); + } +} diff --git a/Mage/src/mage/game/events/ZoneChangeEvent.java b/Mage/src/mage/game/events/ZoneChangeEvent.java new file mode 100644 index 00000000000..70b68b7d0d3 --- /dev/null +++ b/Mage/src/mage/game/events/ZoneChangeEvent.java @@ -0,0 +1,60 @@ +/* +* 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.events; + +import java.util.UUID; +import mage.Constants.Zone; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class ZoneChangeEvent extends GameEvent { + + private Zone fromZone; + private Zone toZone; + + public ZoneChangeEvent(UUID targetId, UUID sourceId, UUID playerId, Zone fromZone, Zone toZone) { + super(EventType.ZONE_CHANGE, targetId, sourceId, playerId); + this.fromZone = fromZone; + this.toZone = toZone; + } + + public ZoneChangeEvent(UUID targetId, UUID playerId, Zone fromZone, Zone toZone) { + this(targetId, null, playerId, fromZone, toZone); + } + + public Zone getFromZone() { + return fromZone; + } + + public Zone getToZone() { + return toZone; + } +} diff --git a/Mage/src/mage/game/permanent/Battlefield.java b/Mage/src/mage/game/permanent/Battlefield.java new file mode 100644 index 00000000000..e64a8dff8da --- /dev/null +++ b/Mage/src/mage/game/permanent/Battlefield.java @@ -0,0 +1,188 @@ +/* +* 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; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import mage.Constants.CardType; +import mage.Constants.Zone; +import mage.abilities.keyword.PhasingAbility; +import mage.filter.FilterPermanent; +import mage.game.Game; +import mage.game.events.GameEvent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class Battlefield implements Serializable { + + private Map field = new HashMap(); + + public void reset() { + for (Permanent perm: field.values()) { + perm.reset(); + } + } + + public void clear() { + field.clear(); + } + + public int count(FilterPermanent filter) { + int count = 0; + for (Permanent permanent: field.values()) { + if (filter.match(permanent)) { + count++; + } + } + return count; + } + + public void addPermanent(Permanent permanent) { + field.put(permanent.getId(), permanent); + } + + public Permanent getPermanent(UUID key) { + return field.get(key); + } + + public void removePermanent(UUID key) { + field.remove(key); + } + + public boolean containsPermanent(UUID key) { + return field.containsKey(key); + } + + public void handleEvent(GameEvent event, Game game) { + for (Permanent perm: field.values()) { + if (perm.isPhasedIn()) + perm.handleEvent(event, game); + } + } + + public void endOfTurn(UUID controllerId, Game game) { + for (Permanent perm: field.values()) { + if (perm.getControllerId().equals(controllerId)) + perm.endOfTurn(game); + } + } + + public Collection getAllPermanents() { + return field.values(); + } + + public Collection getAllPermanents(UUID controllerId) { + List perms = new ArrayList(); + for (Permanent perm: field.values()) { + if (perm.getControllerId().equals(controllerId)) + perms.add(perm); + } + return perms; + } + + public List getActivePermanents() { + List active = new ArrayList(); + for (Permanent perm: field.values()) { + if (perm.isPhasedIn()) + active.add(perm); + } + return active; + } + + public List getActivePermanents(UUID controllerId) { + List active = new ArrayList(); + for (Permanent perm: field.values()) { + if (perm.isPhasedIn() && perm.getControllerId().equals(controllerId)) + active.add(perm); + } + return active; + } + + public List getActivePermanents(CardType type) { + List active = new ArrayList(); + for (Permanent perm: field.values()) { + if (perm.isPhasedIn() && perm.getCardType().contains(type)) + active.add(perm); + } + return active; + } + + public List getActivePermanents(FilterPermanent filter) { + List active = new ArrayList(); + for (Permanent perm: field.values()) { + if (perm.isPhasedIn() && filter.match(perm)) + active.add(perm); + } + return active; + } + + public List getActivePermanents(UUID controllerId, CardType type) { + List active = new ArrayList(); + for (Permanent perm: field.values()) { + if (perm.isPhasedIn() && perm.getCardType().contains(type) && perm.getControllerId().equals(controllerId)) + active.add(perm); + } + return active; + } + + public List getPhasedIn(UUID controllerId) { + List phasedIn = new ArrayList(); + for (Permanent perm: field.values()) { + if (perm.getAbilities().containsKey(PhasingAbility.getInstance().getId()) && perm.isPhasedIn() && perm.getControllerId().equals(controllerId)) + phasedIn.add(perm); + } + return phasedIn; + } + + public List getPhasedOut(UUID controllerId) { + List phasedOut = new ArrayList(); + for (Permanent perm: field.values()) { + if (!perm.isPhasedIn() && perm.getControllerId().equals(controllerId)) + phasedOut.add(perm); + } + return phasedOut; + } + +// public List getMatches(FilterPermanent filter) { +// List matches = new ArrayList(); +// for (Permanent perm: field.values()) { +// if (filter.match(perm)) +// matches.add(perm); +// } +// return matches; +// } + +} diff --git a/Mage/src/mage/game/permanent/Permanent.java b/Mage/src/mage/game/permanent/Permanent.java new file mode 100644 index 00000000000..d068923fec1 --- /dev/null +++ b/Mage/src/mage/game/permanent/Permanent.java @@ -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.game.permanent; + +import java.util.List; +import java.util.UUID; +import mage.Constants.Zone; +import mage.MageObject; +import mage.abilities.Ability; +import mage.cards.Card; +import mage.counters.Counters; +import mage.game.Game; +import mage.game.events.GameEvent; + +public interface Permanent extends Card { + + public boolean isTapped(); + public boolean untap(Game game); + public boolean tap(Game game); + public void setTapped(boolean tapped); + public boolean canTap(); + + public boolean isFlipped(); + public boolean unflip(Game game); + public boolean flip(Game game); + + public boolean isPhasedIn(); + public boolean phaseIn(Game game); + public boolean phaseOut(Game game); + + public boolean isFaceUp(); + public boolean turnFaceUp(Game game); + public boolean turnFaceDown(Game game); + + public List getAttachments(); + public UUID getAttachedTo(); + public void attachTo(UUID permanentId); + public boolean addAttachment(UUID permanentId, Game game); + public boolean removeAttachment(UUID permanentId, Game game); + + public UUID getControllerId(); + public void changeControllerId(UUID controllerId, Game game); + public boolean canTarget(MageObject source); + public int getDamage(); + public int damage(int damage, UUID sourceId, Game game); + public Counters getCounters(); + public void reset(); + public boolean destroy(UUID sourceId, Game game, boolean noRegen); + public boolean sacrifice(UUID sourceId, Game game); + public void entersBattlefield(Game game); + public boolean moveToZone(Zone zone, Game game, boolean sacrificed); + public boolean moveToExile(UUID exileId, String name, Game game); + + @Override + public void addAbility(Ability ability); + + public void setLoyaltyUsed(boolean used); + public boolean isLoyaltyUsed(); + + public void endOfTurn(Game game); + public void handleEvent(GameEvent event, Game game); + public int getTurnsOnBattlefield(); + + public void addPower(int power); + public void addToughness(int toughness); + + public boolean isAttacking(); + public boolean isBlocking(); + public void setAttacking(boolean attacking); + public void setBlocking(boolean blocking); + public boolean canAttack(Game game); + public boolean canBlock(UUID attackerId, Game game); + public boolean removeFromCombat(Game game); + public boolean isDeathtouched(); + +} diff --git a/Mage/src/mage/game/permanent/PermanentCard.java b/Mage/src/mage/game/permanent/PermanentCard.java new file mode 100644 index 00000000000..1c6b4915e32 --- /dev/null +++ b/Mage/src/mage/game/permanent/PermanentCard.java @@ -0,0 +1,120 @@ +/* +* 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; + +import java.util.UUID; +import mage.Constants.CardType; +import mage.Constants.Zone; +import mage.MageInt; +import mage.cards.Card; +import mage.game.Game; +import mage.game.events.ZoneChangeEvent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class PermanentCard extends PermanentImpl { + + protected Card card; + + public PermanentCard(Card card, UUID controllerId) { + super(card.getOwnerId(), controllerId, card.getName()); + this.card = card; + this.objectId = card.getId(); + reset(); + if (card.getCardType().contains(CardType.PLANESWALKER)) { + this.loyalty = new MageInt(card.getLoyalty().getValue()); + } + } + + @Override + public void reset() { + // when the permanent is reset copy all original values from the card + // must copy card each reset so that the original values don't get modified + // TODO: might need to find way to handle abilities that need to preserve state + Card copy = card.copy(); + this.name = copy.getName(); + this.abilities = copy.getAbilities(); + this.abilities.setControllerId(this.controllerId); + this.cardType = copy.getCardType(); + this.color = copy.getColor(); + this.manaCost = copy.getManaCost(); +// this.loyalty = copy.getLoyalty(); + this.power = copy.getPower(); + this.toughness = copy.getToughness(); + this.subtype = copy.getSubtype(); + this.supertype = copy.getSupertype(); + this.art = copy.getArt(); + super.reset(); + } + + public Card getCard() { + return card; + } + + @Override + public boolean moveToZone(Zone zone, Game game, boolean sacrificed) { + if (!game.replaceEvent(new ZoneChangeEvent(this.getId(), this.getControllerId(), Zone.BATTLEFIELD, zone))) { + if (game.getPlayer(controllerId).removeFromBattlefield(this, game)) { + switch (zone) { + case GRAVEYARD: + game.getPlayer(ownerId).putInGraveyard(card, game, !sacrificed); + break; + case HAND: + game.getPlayer(ownerId).getHand().add(card); + break; + case EXILED: + game.getExile().getPermanentExile().add(card); + break; + } + game.fireEvent(new ZoneChangeEvent(this.getId(), this.getControllerId(), Zone.BATTLEFIELD, zone)); + return true; + } + } + return false; + } + + @Override + public boolean moveToExile(UUID exileId, String name, Game game) { + if (!game.replaceEvent(new ZoneChangeEvent(this.getId(), this.getControllerId(), Zone.BATTLEFIELD, Zone.EXILED))) { + if (game.getPlayer(controllerId).removeFromBattlefield(this, game)) { + if (exileId == null) { + game.getExile().getPermanentExile().add(card); + } + else { + game.getExile().createZone(exileId, name).add(card); + } + game.fireEvent(new ZoneChangeEvent(this.getId(), this.getControllerId(), Zone.BATTLEFIELD, Zone.EXILED)); + return true; + } + } + return false; + } +} diff --git a/Mage/src/mage/game/permanent/PermanentImpl.java b/Mage/src/mage/game/permanent/PermanentImpl.java new file mode 100644 index 00000000000..0edb49a74d1 --- /dev/null +++ b/Mage/src/mage/game/permanent/PermanentImpl.java @@ -0,0 +1,508 @@ +/* +* 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; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import mage.Constants.CardType; +import mage.Constants.Zone; +import mage.MageObject; +import mage.abilities.Ability; +import mage.abilities.EvasionAbility; +import mage.abilities.StaticAbility; +import mage.abilities.effects.ContinuousEffect; +import mage.abilities.effects.Effect; +import mage.abilities.keyword.DeathtouchAbility; +import mage.abilities.keyword.DefenderAbility; +import mage.abilities.keyword.HasteAbility; +import mage.abilities.keyword.LifelinkAbility; +import mage.abilities.keyword.ProtectionAbility; +import mage.abilities.keyword.ShroudAbility; +import mage.cards.CardImpl; +import mage.counters.Counters; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.events.GameEvent.EventType; +import mage.players.Player; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public abstract class PermanentImpl extends CardImpl implements Permanent +{ + protected boolean tapped = false; + protected boolean flipped = false; + protected UUID controllerId; + protected int damage; + protected boolean controlledFromStartOfTurn = false; + protected int turnsOnBattlefield = 0; + protected boolean phasedIn = true; + protected boolean faceUp = true; + protected boolean attacking = false; + protected boolean blocking = false; + protected boolean loyaltyUsed = false; + protected boolean deathtouched = false; + protected Counters counters = new Counters(); + protected List attachments = new ArrayList(); + protected UUID attachedTo; + + public PermanentImpl(UUID ownerId, UUID controllerId, String name) { + super(ownerId, name); + this.controllerId = controllerId; + } + + @Override + public void reset() { + this.controllerId = ownerId; + } + + @Override + public void addAbility(Ability ability) { + Ability copy = ability.copy(); + copy.setControllerId(controllerId); + copy.setSourceId(objectId); + abilities.add(copy); + } + + + @Override + public Counters getCounters() { + return counters; + } + + @Override + public int getTurnsOnBattlefield() { + return turnsOnBattlefield; + } + + @Override + public void endOfTurn(Game game) { + this.damage = 0; + this.loyaltyUsed = false; + this.turnsOnBattlefield++; + } + + @Override + public void handleEvent(GameEvent event, Game game) { + if (event.getType() == EventType.BEGINNING_PHASE_PRE && game.getActivePlayerId().equals(controllerId)) + this.controlledFromStartOfTurn = true; + for (Ability ability: abilities.getTriggeredAbilities(Zone.BATTLEFIELD)) { + ability.handleEvent(event, game); + } + } + + @Override + public void setLoyaltyUsed(boolean used) { + this.loyaltyUsed = used; + } + + @Override + public boolean isLoyaltyUsed() { + return this.loyaltyUsed; + } + + @Override + public boolean isTapped() { + return tapped; + } + + @Override + public void setTapped(boolean tapped) { + this.tapped = tapped; + } + + @Override + public boolean canTap() { + if (!cardType.contains(CardType.CREATURE) || this.controlledFromStartOfTurn || this.abilities.containsKey(HasteAbility.getInstance().getId())) { + return true; + } + return false; + } + + @Override + public boolean untap(Game game) { + //20091005 - 701.15b + if (tapped) { + if (!replaceEvent(EventType.UNTAP, game)) { + this.tapped = false; + fireEvent(EventType.UNTAPPED, game); + return true; + } + } + return false; + } + + @Override + public boolean tap(Game game) { + //20091005 - 701.15a + if (!tapped) { + if (!replaceEvent(EventType.TAP, game)) { + this.tapped = true; + fireEvent(EventType.TAPPED, game); + return true; + } + } + return false; + } + + @Override + public boolean isFlipped() { + return flipped; + } + + @Override + public boolean unflip(Game game) { + if (flipped) { + if (!replaceEvent(EventType.UNFLIP, game)) { + this.flipped = false; + fireEvent(EventType.UNFLIPPED, game); + return true; + } + } + return false; + } + + @Override + public boolean flip(Game game) { + if (!flipped) { + if (!replaceEvent(EventType.FLIP, game)) { + this.flipped = true; + fireEvent(EventType.FLIPPED, game); + return true; + } + } + return false; + } + + @Override + public boolean isPhasedIn() { + return phasedIn; + } + + @Override + public boolean phaseIn(Game game) { + if (!phasedIn) { + if (!replaceEvent(EventType.PHASE_IN, game)) { + this.phasedIn = true; + addEffects(game); + fireEvent(EventType.PHASED_IN, game); + return true; + } + } + return false; + } + + @Override + public boolean phaseOut(Game game) { + if (phasedIn) { + if (!replaceEvent(EventType.PHASE_OUT, game)) { + this.phasedIn = false; + fireEvent(EventType.PHASED_OUT, game); + return true; + } + } + return false; + } + + @Override + public boolean isFaceUp() { + return faceUp; + } + + @Override + public boolean turnFaceUp(Game game) { + //TODO: implement this + return false; + } + + @Override + public boolean turnFaceDown(Game game) { + //TODO: implement this + return false; + } + + @Override + public boolean isAttacking() { + return attacking; + } + + @Override + public boolean isBlocking() { + return blocking; + } + + @Override + public UUID getControllerId() { + return this.controllerId; + } + + @Override + public void changeControllerId(UUID controllerId, Game game) { + if (!controllerId.equals(this.controllerId)) { + this.removeFromCombat(game); + this.controlledFromStartOfTurn = false; + this.controllerId = controllerId; + } + } + + @Override + public List getAttachments() { + return attachments; + } + + @Override + public boolean addAttachment(UUID permanentId, Game game) { + if (!this.attachments.contains(permanentId)) { + if (!game.replaceEvent(new GameEvent(GameEvent.EventType.ATTACH, objectId, permanentId, controllerId, damage))) { + this.attachments.add(permanentId); + game.getPermanent(permanentId).attachTo(objectId); + game.fireEvent(new GameEvent(GameEvent.EventType.ATTACHED, objectId, permanentId, controllerId, damage)); + return true; + } + } + return false; + } + + @Override + public boolean removeAttachment(UUID permanentId, Game game) { + if (this.attachments.contains(permanentId)) { + if (!game.replaceEvent(new GameEvent(GameEvent.EventType.UNATTACH, objectId, permanentId, controllerId, damage))) { + this.attachments.remove(permanentId); + game.getPermanent(permanentId).attachTo(null); + game.fireEvent(new GameEvent(GameEvent.EventType.UNATTACHED, objectId, permanentId, controllerId, damage)); + return true; + } + } + return false; + } + + @Override + public UUID getAttachedTo() { + return attachedTo; + } + + @Override + public void attachTo(UUID permanentId) { + this.attachedTo = permanentId; + } + + @Override + public boolean isDeathtouched() { + return deathtouched; + } + + @Override + public int getDamage() { + return this.damage; + } + + @Override + public int damage(int damage, UUID sourceId, Game game) { + int damageDone = 0; + if (damage > 0 && canDamage(game.getObject(sourceId))) { + if (cardType.contains(CardType.PLANESWALKER)) { + damageDone = damagePlaneswalker(damage, sourceId, game); + } + else { + damageDone = damageCreature(damage, sourceId, game); + } + if (damageDone > 0) { + Permanent source = game.getPermanent(sourceId); + if (source != null && source.getAbilities().containsKey(LifelinkAbility.getInstance().getId())) { + Player player = game.getPlayer(source.getControllerId()); + player.gainLife(damageDone, game); + } + if (source != null && source.getAbilities().containsKey(DeathtouchAbility.getInstance().getId())) { + deathtouched = true; + } + } + } + return damageDone; + } + + protected int damagePlaneswalker(int damage, UUID sourceId, Game game) { + GameEvent event = new GameEvent(GameEvent.EventType.DAMAGE_PLANESWALKER, objectId, sourceId, controllerId, damage); + if (!game.replaceEvent(event)) { + int actualDamage = event.getAmount(); + if (actualDamage > 0) { + if (event.getAmount() > this.loyalty.getValue()) { + actualDamage = this.loyalty.getValue(); + } + this.loyalty.boostValue(-actualDamage); + game.fireEvent(GameEvent.getEvent(EventType.DAMAGED_PLANESWALKER, objectId, sourceId, controllerId, actualDamage)); + return actualDamage; + } + } + return 0; + } + + protected int damageCreature(int damage, UUID sourceId, Game game) { + GameEvent event = new GameEvent(GameEvent.EventType.DAMAGE_CREATURE, objectId, sourceId, controllerId, damage); + if (!game.replaceEvent(event)) { + int actualDamage = event.getAmount(); + if (actualDamage > 0) { + if (this.damage + event.getAmount() > this.toughness.getValue()) { + actualDamage = this.toughness.getValue() - this.damage; + } + this.damage += actualDamage; + game.fireEvent(GameEvent.getEvent(EventType.DAMAGED_CREATURE, objectId, sourceId, controllerId, actualDamage)); + return actualDamage; + } + } + return 0; + } + + @Override + public void entersBattlefield(Game game) { + controlledFromStartOfTurn = false; + addEffects(game); + } + + @Override + public boolean canTarget(MageObject source) { + if (source != null) { + if (abilities.containsKey(ShroudAbility.getInstance().getId())) + return false; + + for (ProtectionAbility ability: abilities.getProtectionAbilities()) { + if (!ability.canTarget(source)) + return false; + } + } + + return true; + } + + protected boolean canDamage(MageObject source) { + for (ProtectionAbility ability: abilities.getProtectionAbilities()) { + if (!ability.canTarget(source)) + return false; + } + return true; + } + + protected void addEffects(Game game) { + for (StaticAbility ability: abilities.getStaticAbilities(Zone.BATTLEFIELD)) { + for (Effect effect: ability.getEffects()) { + if (effect instanceof ContinuousEffect) + game.addEffect((ContinuousEffect)effect); + } + } + } + + @Override + public boolean destroy(UUID sourceId, Game game, boolean noRegen) { + //20091005 - 701.6 + //TODO: handle noRegen + if (!game.replaceEvent(GameEvent.getEvent(EventType.DESTROY_PERMANENT, objectId, sourceId, controllerId))) { + if (moveToZone(Zone.GRAVEYARD, game, false)) { + game.fireEvent(GameEvent.getEvent(EventType.DESTROYED_PERMANENT, objectId, sourceId, controllerId)); + return true; + } + } + return false; + } + + @Override + public boolean sacrifice(UUID sourceId, Game game) { + //20091005 - 701.13 + if (!game.replaceEvent(GameEvent.getEvent(EventType.SACRIFICE_PERMANENT, objectId, sourceId, controllerId))) { + if (moveToZone(Zone.GRAVEYARD, game, true)) { + game.fireEvent(GameEvent.getEvent(EventType.SACRIFICED_PERMANENT, objectId, sourceId, controllerId)); + return true; + } + } + return false; + } + + + @Override + public void addPower(int power) { + this.power.boostValue(power); + } + + @Override + public void addToughness(int toughness) { + this.toughness.boostValue(toughness); + } + + protected void fireEvent(EventType eventType, Game game) { + game.fireEvent(GameEvent.getEvent(eventType, this.objectId, ownerId)); + } + + protected boolean replaceEvent(EventType eventType, Game game) { + return game.replaceEvent(GameEvent.getEvent(eventType, this.objectId, ownerId)); + } + + @Override + public boolean canAttack(Game game) { + if (tapped) + return false; + if (!controlledFromStartOfTurn && !abilities.containsKey(HasteAbility.getInstance().getId())) + return false; + if (abilities.containsKey(DefenderAbility.getInstance().getId())) + return false; + return true; + } + + @Override + public boolean canBlock(UUID attackerId, Game game) { + if (tapped) + return false; + Permanent attacker = game.getPermanent(attackerId); + for (EvasionAbility ability: attacker.getAbilities().getEvasionAbilities()) { + if (!ability.canBlock(this, game)) + return false; + } + for (ProtectionAbility ability: attacker.getAbilities().getProtectionAbilities()) { + if (!ability.canTarget(this)) + return false; + } + return true; + } + + @Override + public void setAttacking(boolean attacking) { + this.attacking = attacking; + } + + @Override + public void setBlocking(boolean blocking) { + this.blocking = blocking; + } + + @Override + public boolean removeFromCombat(Game game) { + game.getCombat().removeFromCombat(objectId, game); + return true; + } + +} diff --git a/Mage/src/mage/game/permanent/PermanentToken.java b/Mage/src/mage/game/permanent/PermanentToken.java new file mode 100644 index 00000000000..1a9dc0dbcb8 --- /dev/null +++ b/Mage/src/mage/game/permanent/PermanentToken.java @@ -0,0 +1,87 @@ +/* +* 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; + +import mage.game.permanent.token.Token; +import java.util.UUID; +import mage.Constants.Zone; +import mage.game.Game; +import mage.game.events.ZoneChangeEvent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class PermanentToken extends PermanentImpl { + + protected Token token; + + public PermanentToken(Token token, UUID ownerId, UUID controllerId) { + super(ownerId, controllerId, token.getName()); + this.token = token; + reset(); + } + + @Override + public void reset() { + Token copy = token.copy(); + this.name = copy.getName(); + this.abilities = copy.getAbilities(); + this.abilities.setControllerId(this.controllerId); + this.cardType = copy.getCardType(); + this.color = copy.getColor(); + this.power = copy.getPower(); + this.toughness = copy.getToughness(); + this.subtype = copy.getSubtype(); + super.reset(); + } + + @Override + public boolean moveToZone(Zone zone, Game game, boolean sacrificed) { + if (!game.replaceEvent(new ZoneChangeEvent(this.getId(), this.getControllerId(), Zone.BATTLEFIELD, zone))) { + if (game.getPlayer(controllerId).removeFromBattlefield(this, game)) { + game.fireEvent(new ZoneChangeEvent(this.getId(), this.getControllerId(), Zone.BATTLEFIELD, zone)); + return true; + } + } + return false; + } + + @Override + public boolean moveToExile(UUID exileId, String name, Game game) { + if (!game.replaceEvent(new ZoneChangeEvent(this.getId(), this.getControllerId(), Zone.BATTLEFIELD, Zone.EXILED))) { + if (game.getPlayer(controllerId).removeFromBattlefield(this, game)) { + game.fireEvent(new ZoneChangeEvent(this.getId(), this.getControllerId(), Zone.BATTLEFIELD, Zone.EXILED)); + return true; + } + } + return false; + } + +} diff --git a/Mage/src/mage/game/permanent/token/BeastToken.java b/Mage/src/mage/game/permanent/token/BeastToken.java new file mode 100644 index 00000000000..8a196ad525d --- /dev/null +++ b/Mage/src/mage/game/permanent/token/BeastToken.java @@ -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.MageInt; +import mage.ObjectColor; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class BeastToken extends Token { + + public BeastToken() { + super("Beast", "3/3 green Beast creature token"); + cardType.add(CardType.CREATURE); + color = ObjectColor.GREEN; + subtype.add("Beast"); + power = new MageInt(3); + toughness = new MageInt(3); + } + +} diff --git a/Mage/src/mage/game/permanent/token/DragonToken.java b/Mage/src/mage/game/permanent/token/DragonToken.java new file mode 100644 index 00000000000..1c64cd2ed4e --- /dev/null +++ b/Mage/src/mage/game/permanent/token/DragonToken.java @@ -0,0 +1,51 @@ +/* +* 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.MageInt; +import mage.ObjectColor; +import mage.abilities.keyword.FlyingAbility; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class DragonToken extends Token { + + public DragonToken() { + super("Dragon", "4/4 red Dragon creature token with flying"); + cardType.add(CardType.CREATURE); + color = ObjectColor.RED; + subtype.add("Dragon"); + power = new MageInt(4); + toughness = new MageInt(4); + addAbility(FlyingAbility.getInstance()); + } +} diff --git a/Mage/src/mage/game/permanent/token/SaprolingToken.java b/Mage/src/mage/game/permanent/token/SaprolingToken.java new file mode 100644 index 00000000000..879e0a7632e --- /dev/null +++ b/Mage/src/mage/game/permanent/token/SaprolingToken.java @@ -0,0 +1,49 @@ +/* +* 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.MageInt; +import mage.ObjectColor; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class SaprolingToken extends Token { + + public SaprolingToken() { + super("Saproling", "1/1 green Saproling creature token"); + cardType.add(CardType.CREATURE); + color = ObjectColor.GREEN; + subtype.add("Saproling"); + power = new MageInt(1); + toughness = new MageInt(1); + } +} \ No newline at end of file diff --git a/Mage/src/mage/game/permanent/token/SoldierToken.java b/Mage/src/mage/game/permanent/token/SoldierToken.java new file mode 100644 index 00000000000..556d34cee57 --- /dev/null +++ b/Mage/src/mage/game/permanent/token/SoldierToken.java @@ -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.MageInt; +import mage.ObjectColor; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class SoldierToken extends Token { + + public SoldierToken() { + super("Soldier", "1/1 white Soldier creature token"); + cardType.add(CardType.CREATURE); + color = ObjectColor.GREEN; + subtype.add("Soldier"); + power = new MageInt(1); + toughness = new MageInt(1); + } + +} diff --git a/Mage/src/mage/game/permanent/token/Token.java b/Mage/src/mage/game/permanent/token/Token.java new file mode 100644 index 00000000000..9b13c537ddb --- /dev/null +++ b/Mage/src/mage/game/permanent/token/Token.java @@ -0,0 +1,74 @@ +/* +* 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 java.util.List; +import mage.Constants.CardType; +import mage.MageObjectImpl; +import mage.ObjectColor; +import mage.abilities.Abilities; +import mage.abilities.Ability; +import mage.util.Copier; + +public class Token extends MageObjectImpl { + + private static final transient Copier copier = new Copier(); + + protected String description; + + public Token(String name, String description) { + this.name = name; + this.description = description; + } + + public Token(String name, String description, ObjectColor color, List subtype, int power, int toughness, Abilities abilities) { + this(name, description); + this.cardType.add(CardType.CREATURE); + this.color = color; + this.subtype = subtype; + this.power.setValue(power); + this.toughness.setValue(toughness); + if (abilities != null) { + this.abilities = abilities.copy(); + } + } + + public String getDescription() { + return description; + } + + public Token copy() { + return copier.copy(this); + } + + public void addAbility(Ability ability) { + ability.setSourceId(this.getId()); + abilities.add(ability); + } +} diff --git a/Mage/src/mage/game/permanent/token/WolfToken.java b/Mage/src/mage/game/permanent/token/WolfToken.java new file mode 100644 index 00000000000..2608630e725 --- /dev/null +++ b/Mage/src/mage/game/permanent/token/WolfToken.java @@ -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.MageInt; +import mage.ObjectColor; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class WolfToken extends Token { + + public WolfToken() { + super("Wolf", "2/2 green Wolf creature token"); + cardType.add(CardType.CREATURE); + color = ObjectColor.GREEN; + subtype.add("Wolf"); + power = new MageInt(2); + toughness = new MageInt(2); + } + +} diff --git a/Mage/src/mage/game/stack/Spell.java b/Mage/src/mage/game/stack/Spell.java new file mode 100644 index 00000000000..0c0cd67490f --- /dev/null +++ b/Mage/src/mage/game/stack/Spell.java @@ -0,0 +1,200 @@ +/* +* 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.stack; + +import mage.abilities.SpellAbility; +import mage.game.*; +import java.util.List; +import java.util.UUID; +import mage.Constants.CardType; +import mage.Constants.Zone; +import mage.MageInt; +import mage.ObjectColor; +import mage.abilities.Abilities; +import mage.abilities.Ability; +import mage.abilities.costs.mana.ManaCosts; +import mage.abilities.effects.common.ExileSourceEffect; +import mage.abilities.keyword.KickerAbility; +import mage.cards.Card; +import mage.game.events.GameEvent; +import mage.players.Player; +import mage.util.Copier; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class Spell implements StackObject, Card { + + private Card card; + private UUID controllerId; + + public Spell(Card card, UUID controllerId) { + this.card = card; + this.controllerId = controllerId; + } + + public boolean resolve(Game game) { + boolean result = false; + if (card.getCardType().contains(CardType.INSTANT) || card.getCardType().contains(CardType.SORCERY)) { + SpellAbility ability = card.getSpellAbility(); + if (ability.getTargets().stillLegal(game)) { + boolean replaced = false; + for (KickerAbility kicker: card.getAbilities().getKickerAbilities()) { + if (kicker.isKicked()) { + if (kicker.isReplaces()) { + replaced = true; + } + kicker.resolve(game); + } + } + if (!replaced) + result = ability.resolve(game); + + if (ability.getEffects().contains(ExileSourceEffect.getInstance())) + game.getExile().getPermanentExile().add(card); + else + game.getPlayers().get(controllerId).putInGraveyard(card, game, false); + return result; + } + //20091005 - 608.2b + counter(game); + return false; + } + else { + Player controller = game.getPlayers().get(controllerId); + return controller.putOntoBattlefield(card, game); + } + } + + public void counter(Game game) { + game.getPlayers().get(controllerId).putInGraveyard(card, game, false); + } + + public UUID getSourceId() { + return card.getId(); + } + + public UUID getControllerId() { + return this.controllerId; + } + + public String getName() { + return card.getName(); + } + + public List getCardType() { + return card.getCardType(); + } + + public List getSubtype() { + return card.getSubtype(); + } + + public List getSupertype() { + return card.getSupertype(); + } + + public Abilities getAbilities() { + return card.getAbilities(); + } + + public ObjectColor getColor() { + return card.getColor(); + } + + public ManaCosts getManaCost() { + return card.getManaCost(); + } + + public MageInt getPower() { + return card.getPower(); + } + + public MageInt getToughness() { + return card.getToughness(); + } + + public MageInt getLoyalty() { + return card.getLoyalty(); + } + + public Zone getZone() { + return Zone.STACK; + } + + public void setZone(Zone zone) { + + } + + public UUID getId() { + return card.getId(); + } + + public UUID getOwnerId() { + return card.getOwnerId(); + } + + public String getArt() { + return card.getArt(); + } + + public void addAbility(Ability ability) { + + } + + public SpellAbility getSpellAbility() { + return card.getSpellAbility(); + } + + public void setControllerId(UUID controllerId) { + this.controllerId = controllerId; + } + + public void setOwnerId(UUID controllerId) { + + } + + public Card copy() { + return new Copier().copy(this); + } + + public void handleEvent(GameEvent event, Game game) { + handleEvent(Zone.STACK, event, game); + } + + public void handleEvent(Zone zone, GameEvent event, Game game) { + card.handleEvent(zone, event, game); + } + + public List getRules() { + return card.getRules(); + } + +} diff --git a/Mage/src/mage/game/stack/SpellStack.java b/Mage/src/mage/game/stack/SpellStack.java new file mode 100644 index 00000000000..680f826f64b --- /dev/null +++ b/Mage/src/mage/game/stack/SpellStack.java @@ -0,0 +1,112 @@ +/* +* 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.stack; + +import java.util.ArrayList; +import java.util.List; +import java.util.Stack; +import java.util.UUID; +import mage.Constants.Zone; +import mage.abilities.Ability; +import mage.abilities.effects.Effect; +import mage.abilities.effects.ReplacementEffect; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.players.Player; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class SpellStack extends Stack { + + //resolve top StackObject + public void resolve(Game game) { + StackObject top = this.peek(); + top.resolve(game); + this.remove(top); + } + + public void handleEvent(GameEvent event, Game game) { + for (StackObject stackObject: this) { + stackObject.handleEvent(event, game); + } + } + + + public boolean counter(UUID objectId, UUID sourceId, Game game) { + StackObject stackObject = getStackObject(objectId); + if (stackObject != null) { + if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.COUNTER, objectId, sourceId, stackObject.getControllerId()))) { + this.remove(stackObject); + stackObject.counter(game); + game.fireEvent(GameEvent.getEvent(GameEvent.EventType.COUNTERED, objectId, sourceId, stackObject.getControllerId())); + return true; + } + return false; + } + return false; + } + + public boolean replaceEvent(GameEvent event, Game game) { + boolean caught = false; + List rEffects = new ArrayList(); + for (StackObject stackObject: this) { + for (Ability ability: stackObject.getAbilities()) { + if (ability.getZone() == Zone.STACK) { + for (Effect effect: ability.getEffects()) { + if (effect instanceof ReplacementEffect) { + if (((ReplacementEffect)effect).applies(event, game)) + rEffects.add((ReplacementEffect) effect); + } + } + } + } + } + if (rEffects.size() > 0) { + if (rEffects.size() == 1) { + caught = rEffects.get(0).replaceEvent(event, game); + } + else { + Player player = game.getPlayer(event.getPlayerId()); + caught = rEffects.get(player.chooseEffect(rEffects, game)).replaceEvent(event, game); + } + } + return caught; + } + + + public StackObject getStackObject(UUID id) { + for (StackObject stackObject: this) { + if (stackObject.getId().equals(id)) + return stackObject; + } + return null; + } +} diff --git a/Mage/src/mage/game/stack/StackAbility.java b/Mage/src/mage/game/stack/StackAbility.java new file mode 100644 index 00000000000..676cf12c479 --- /dev/null +++ b/Mage/src/mage/game/stack/StackAbility.java @@ -0,0 +1,235 @@ +/* +* 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.stack; + +import java.util.ArrayList; +import mage.abilities.costs.Cost; +import mage.abilities.costs.Costs; +import mage.abilities.effects.Effect; +import mage.abilities.effects.Effects; +import mage.choices.Choice; +import mage.choices.Choices; +import mage.game.*; +import java.util.List; +import java.util.UUID; +import mage.Constants.CardType; +import mage.Constants.Zone; +import mage.MageInt; +import mage.ObjectColor; +import mage.abilities.Abilities; +import mage.abilities.AbilitiesImpl; +import mage.abilities.Ability; +import mage.abilities.costs.mana.ManaCosts; +import mage.game.events.GameEvent; +import mage.target.Target; +import mage.target.Targets; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class StackAbility implements StackObject, Ability { + + private static List emptyList = new ArrayList(); + private static ObjectColor emptyColor = new ObjectColor(); + private static ManaCosts emptyCost = new ManaCosts(""); + private static Abilities emptyAbilites = new AbilitiesImpl(); + private static Effects emptyEffects = new Effects(null); + + private Ability ability; + private UUID controllerId; + private UUID id; + + public StackAbility(Ability ability, UUID controllerId) { + this.id = UUID.randomUUID(); + this.ability = ability; + this.controllerId = controllerId; + } + + @Override + public boolean resolve(Game game) { + if (ability.getTargets().stillLegal(game)) { + return ability.resolve(game); + } + counter(game); + return false; + } + + public void counter(Game game) { + + } + + @Override + public String getName() { + return ""; + } + + @Override + public List getCardType() { + return emptyList; + } + + @Override + public List getSubtype() { + return emptyList; + } + + @Override + public List getSupertype() { + return emptyList; + } + + @Override + public Abilities getAbilities() { + return emptyAbilites; + } + + @Override + public ObjectColor getColor() { + return emptyColor; + } + + @Override + public ManaCosts getManaCost() { + return emptyCost; + } + + @Override + public MageInt getPower() { + return MageInt.EmptyMageInt; + } + + @Override + public MageInt getToughness() { + return MageInt.EmptyMageInt; + } + + @Override + public MageInt getLoyalty() { + return MageInt.EmptyMageInt; + } + + @Override + public Zone getZone() { + return Zone.STACK; + } + + @Override + public void setZone(Zone zone) {} + + @Override + public UUID getId() { + return this.id; + } + + @Override + public UUID getSourceId() { + return this.ability.getSourceId(); + } + + @Override + public UUID getControllerId() { + return this.controllerId; + } + + @Override + public Costs getCosts() { + return emptyCost; + } + + @Override + public Effects getEffects() { + return emptyEffects; + } + + @Override + public String getRule() { + return ability.getRule(); + } + + @Override + public boolean isEnabled() { + return ability.isEnabled(); + } + + @Override + public void setEnabled(boolean enabled) {} + + @Override + public void setControllerId(UUID controllerId) { + this.controllerId = controllerId; + } + + @Override + public void setSourceId(UUID sourceID) {} + + @Override + public void addCost(Cost cost) {} + + @Override + public void handleEvent(GameEvent event, Game game) { + ability.handleEvent(event, game); + } + + @Override + public void addEffect(Effect effect) {} + + @Override + public boolean activate(Game game, boolean noMana) { + return ability.activate(game, noMana); + } + + @Override + public Targets getTargets() { + return ability.getTargets(); + } + + @Override + public void addTarget(Target target) {} + + @Override + public UUID getFirstTarget() { + return ability.getFirstTarget(); + } + + @Override + public Choices getChoices() { + return ability.getChoices(); + } + + @Override + public void addChoice(Choice choice) {} + + @Override + public Ability copy() { + //TODO: not sure if this will be needed + throw new UnsupportedOperationException("Not supported yet."); + } + +} diff --git a/Mage/src/mage/game/stack/StackObject.java b/Mage/src/mage/game/stack/StackObject.java new file mode 100644 index 00000000000..9ce7b703c12 --- /dev/null +++ b/Mage/src/mage/game/stack/StackObject.java @@ -0,0 +1,45 @@ +/* +* 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.stack; + +import mage.game.*; +import java.util.UUID; +import mage.MageObject; +import mage.game.events.GameEvent; + +public interface StackObject extends MageObject { + +// public Card getCard(); + public boolean resolve(Game game); + public UUID getSourceId(); + public UUID getControllerId(); + public void handleEvent(GameEvent event, Game game); + public void counter(Game game); + +} diff --git a/Mage/src/mage/game/turn/Turn.java b/Mage/src/mage/game/turn/Turn.java new file mode 100644 index 00000000000..b3ae325c759 --- /dev/null +++ b/Mage/src/mage/game/turn/Turn.java @@ -0,0 +1,198 @@ +/* +* 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.turn; + +import java.io.Serializable; +import java.util.UUID; +import mage.Constants.PhaseStep; +import mage.Constants.TurnPhase; +import mage.game.Game; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class Turn implements Serializable { + + private TurnPhase phase; + private PhaseStep step; + private UUID activePlayerId; + private UUID priorityPlayerId; + + public TurnPhase getPhase() { + return phase; + } + + public PhaseStep getStep() { + return step; + } + + public UUID getActivePlayerId() { + return activePlayerId; + } + + public void setActivePlayerId(UUID activePlayerId) { + this.activePlayerId = activePlayerId; + } + + public UUID getPriorityPlayerId() { + return priorityPlayerId; + } + + public void setPriorityPlayerId(UUID priorityPlayerId) { + this.priorityPlayerId = priorityPlayerId; + } + + private boolean nextStep(Game game) { + if (step == null) { + phase = TurnPhase.BEGINNING; + step = PhaseStep.UNTAP; + return true; + } + switch(step) { + case UNTAP: + step = PhaseStep.UPKEEP; + return true; + case UPKEEP: + step = PhaseStep.DRAW; + return true; + case DRAW: + phase = TurnPhase.PRECOMBAT_MAIN; + step = PhaseStep.PRECOMBAT_MAIN; + return true; + case PRECOMBAT_MAIN: + phase = TurnPhase.COMBAT; + step = PhaseStep.BEGIN_COMBAT; + return true; + case BEGIN_COMBAT: + step = PhaseStep.DECLARE_ATTACKERS; + return true; + case DECLARE_ATTACKERS: + //20091005 - 508.6 + if (game.getCombat().getGroups().size() > 0) + step = PhaseStep.DECLARE_BLOCKERS; + else + step = PhaseStep.END_COMBAT; + return true; + case DECLARE_BLOCKERS: + //20091005 - 510.5 + if (game.getCombat().hasFirstOrDoubleStrike(game)) + step = PhaseStep.FIRST_COMBAT_DAMAGE; + else + step = PhaseStep.COMBAT_DAMAGE; + return true; + case FIRST_COMBAT_DAMAGE: + step = PhaseStep.COMBAT_DAMAGE; + return true; + case COMBAT_DAMAGE: + step = PhaseStep.END_COMBAT; + return true; + case END_COMBAT: + phase = TurnPhase.POSTCOMBAT_MAIN; + step = PhaseStep.POSTCOMBAT_MAIN; + return true; + case POSTCOMBAT_MAIN: + phase = TurnPhase.END; + step = PhaseStep.END_TURN; + return true; + case END_TURN: + step = PhaseStep.CLEANUP; + return true; + case CLEANUP: + return false; + } + + return false; + } + + public void play(Game game, UUID activePlayerId) { + if (game.isGameOver()) + return; + + phase = null; + step = null; + this.activePlayerId = activePlayerId; + game.getPlayer(activePlayerId).beginTurn(); + while (nextStep(game)) { + playStep(game); + game.saveState(); + } + } + + private void playStep(Game game) { + if (game.isGameOver()) + return; + + switch(step) { + case UNTAP: + game.playUntapStep(); + break; + case UPKEEP: + game.playUpkeepStep(); + break; + case DRAW: + game.playDrawStep(); + break; + case PRECOMBAT_MAIN: + game.playPreCombatMainStep(); + break; + case BEGIN_COMBAT: + game.playBeginCombatStep(); + break; + case DECLARE_ATTACKERS: + game.playDeclareAttackersStep(); + break; + case DECLARE_BLOCKERS: + game.playDeclareBlockersStep(); + break; + case FIRST_COMBAT_DAMAGE: + game.playCombatDamageStep(true); + break; + case COMBAT_DAMAGE: + game.playCombatDamageStep(false); + break; + case END_COMBAT: + game.playEndCombatStep(); + break; + case POSTCOMBAT_MAIN: + game.playPostMainStep(); + break; + case END_TURN: + game.playEndStep(); + break; + case CLEANUP: + game.playCleanupStep(); + break; + } + //20091005 - 500.4/703.4n + game.emptyManaPools(); + } + + +} diff --git a/Mage/src/mage/players/Library.java b/Mage/src/mage/players/Library.java new file mode 100644 index 00000000000..a2cd115433e --- /dev/null +++ b/Mage/src/mage/players/Library.java @@ -0,0 +1,165 @@ +/* +* 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.players; + +import java.io.Serializable; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Deque; +import java.util.Iterator; +import java.util.List; +import java.util.Random; +import java.util.UUID; +import mage.cards.Card; +import mage.cards.Cards; +import mage.filter.FilterCard; +import mage.game.Game; +import mage.util.Copier; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class Library implements Serializable { + + private static Random rnd = new Random(); + + private boolean emptyDraw = false; + private Deque library = new ArrayDeque(); + private UUID playerId; + + public Library(UUID playerId) { + this.playerId = playerId; + } + + public void shuffle() { + Card[] shuffled = library.toArray(new Card[0]); + for (int n = shuffled.length - 1; n > 0; n--) { + int r = rnd.nextInt(n); + Card temp = shuffled[n]; + shuffled[n] = shuffled[r]; + shuffled[r] = temp; + } + library.clear(); + for (Card card: shuffled) { + library.add(card); + } + } + + public Card removeFromTop(Game game) { + Card card = library.pollFirst(); + if (card == null) { + emptyDraw = true; + } + return card; + } + + public void putOnTop(Card card, Game game) { + if (card.getOwnerId().equals(playerId)) + library.addFirst(card); + else + game.getPlayer(card.getOwnerId()).getLibrary().putOnTop(card, game); + } + + public void putOnBottom(Card card, Game game) { + if (card.getOwnerId().equals(playerId)) + library.add(card); + else + game.getPlayer(card.getOwnerId()).getLibrary().putOnBottom(card, game); + } + + public Library copy() { + return new Copier().copy(this); + } + + public void clear() { + library.clear(); + } + + public int size() { + return library.size(); + } + + public void set(Library newLibrary) { + library.clear(); + for (Card card: newLibrary.getCards()) { + library.add(card); + } + } + + public List getCards() { + return Arrays.asList(library.toArray(new Card[0])); + } + + public int count(FilterCard filter) { + int result = 0; + for (Card card: library) { + if (filter.match(card)) + result++; + } + return result; + } + + + public boolean isEmtpyDraw() { + return emptyDraw; + } + + void setControllerId(UUID playerId) { + for (Card card: library) { + card.setControllerId(playerId); + } + } + + public void addAll(Cards cards) { + library.addAll(cards.values()); + } + + public Card getCard(UUID cardId) { + for (Card card: library) { + if (card.getId().equals(cardId)) + return card; + } + return null; + } + + public Card remove(UUID cardId) { + Iterator it = library.iterator(); + while(it.hasNext()) { + Card card = it.next(); + if (card.getId().equals(cardId)) { + it.remove(); + return card; + } + } + return null; + } + +} diff --git a/Mage/src/mage/players/ManaPool.java b/Mage/src/mage/players/ManaPool.java new file mode 100644 index 00000000000..2ca6d7045ee --- /dev/null +++ b/Mage/src/mage/players/ManaPool.java @@ -0,0 +1,196 @@ +/* +* 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.players; + +import java.io.Serializable; +import mage.Mana; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class ManaPool implements Serializable { + + private int red = 0; + private int green = 0; + private int blue = 0; + private int white = 0; + private int black = 0; + private int colorless = 0; + + public void setRed(int red) { + this.red = red; + } + + public void removeRed() { + red--; + } + + public void addRed() { + red++; + } + + public int getRed() { + return red; + } + + public void setGreen(int green) { + this.green = green; + } + + public void removeGreen() { + green--; + } + + public void addGreen() { + green++; + } + + public int getGreen() { + return green; + } + + public void setBlue(int blue) { + this.blue = blue; +} + + public void removeBlue() { + blue--; + } + + public void addBlue() { + blue++; + } + + public int getBlue() { + return blue; + } + + public void setWhite(int white) { + this.white = white; + } + + public void removeWhite() { + white--; + } + + public void addWhite() { + white++; + } + + public int getWhite() { + return white; + } + + public void setBlack(int black) { + this.black = black; + } + + public void removeBlack() { + black--; + } + + public void addBlack() { + black++; + } + + public int getBlack() { + return black; + } + + public void setColorless(int colorless) { + this.colorless = colorless; + } + + public void removeColorless() { + colorless--; + } + + public void addColorless() { + colorless++; + } + + public int getColorless() { + return colorless; + } + + public int emptyPool() { + int total = count(); + black = 0; + blue = 0; + white = 0; + red = 0; + green = 0; + colorless = 0; + return total; + } + + public Mana getMana() { + Mana mana = new Mana(); + mana.setBlack(black); + mana.setBlue(blue); + mana.setColorless(colorless); + mana.setGreen(green); + mana.setRed(red); + mana.setWhite(white); + return mana; + } + + public void changeMana(Mana mana) { + this.black += mana.getBlack(); + this.blue += mana.getBlue(); + this.white += mana.getWhite(); + this.red += mana.getRed(); + this.green += mana.getGreen(); + this.colorless += mana.getColorless(); + } + + public boolean checkMana(Mana mana) { + if (this.black < mana.getBlack()) + return false; + if (this.blue < mana.getBlue()) + return false; + if (this.white < mana.getWhite()) + return false; + if (this.red < mana.getRed()) + return false; + if (this.green < mana.getGreen()) + return false; + if (this.colorless < mana.getColorless()) + return false; + + return true; + + } + + public int count() { + return red + green + blue + white + black + colorless; + } + +} diff --git a/Mage/src/mage/players/Player.java b/Mage/src/mage/players/Player.java new file mode 100644 index 00000000000..5daa36e30bb --- /dev/null +++ b/Mage/src/mage/players/Player.java @@ -0,0 +1,141 @@ +/* +* 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.players; + +import java.util.List; +import java.util.UUID; +import mage.Constants.Outcome; +import mage.MageItem; +import mage.MageObject; +import mage.abilities.Abilities; +import mage.abilities.ActivatedAbility; +import mage.abilities.TriggeredAbility; +import mage.abilities.costs.mana.ManaCost; +import mage.abilities.costs.mana.VariableManaCost; +import mage.abilities.effects.ReplacementEffect; +import mage.cards.Card; +import mage.cards.Cards; +import mage.cards.decks.Deck; +import mage.choices.Choice; +import mage.counters.Counters; +import mage.game.events.GameEvent; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.game.permanent.token.Token; +import mage.target.Target; +import mage.target.TargetCard; +import mage.target.common.TargetCardInLibrary; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public interface Player extends MageItem { + + public Deck getDeck(); + public void setDeck(Deck deck); + public String getName(); + public Library getLibrary(); + public Cards getGraveyard(); + public Abilities getAbilities(); + public Counters getCounters(); + public int getLife(); + public void setLife(int life, Game game); + public int loseLife(int amount, Game game); + public void gainLife(int amount, Game game); + public int damage(int damage, UUID sourceId, Game game); + public Cards getHand(); + public boolean isPassed(); + public boolean isEmptyDraw(); + public void resetPriority(); + public boolean hasLost(); + public boolean hasWon(); + public boolean hasLeft(); + public ManaPool getManaPool(); + + public void init(); + public void reset(); + public void shuffleLibrary(Game game); + public int drawCards(int num, Game game); + public boolean cast(Card card, Game game, boolean noMana); + public boolean putInHand(Card card, Game game); + public boolean removeFromHand(Card card, Game game); + public boolean putOntoBattlefield(Card card, Game game); + public boolean putOntoBattlefield(Token token, Game game); + public boolean removeFromBattlefield(Permanent permanent, Game game); + public boolean putInGraveyard(Card card, Game game, boolean fromBattlefield); + public boolean removeFromGraveyard(Card card, Game game); + public boolean searchLibrary(TargetCardInLibrary target, Game game); + public boolean canPlayLand(); + public boolean playLand(Card card, Game game); + public boolean activateAbility(ActivatedAbility ability, Game game); + public boolean triggerAbility(TriggeredAbility ability, Game game); + public boolean canTarget(MageObject source); + public void handleEvent(GameEvent event, Game game); + public void discard(int amount, Game game); + public void discardToMax(Game game); + public void lost(Game game); + public void won(Game game); + public void leaveGame(); + public void concede(); + public void abort(); + + public void revealCards(Cards cards, Game game); + + public Player copy(); + public void restore(Player player); + + public void setResponseString(String responseString); + public void setResponseUUID(UUID responseUUID); + public void setResponseBoolean(Boolean responseBoolean); + public void setResponseInteger(Integer data); + + public abstract void priority(Game game); + public abstract boolean chooseTarget(Outcome outcome, Target target, Game game); + public abstract boolean chooseMulligan(Game game); + public abstract boolean chooseUse(Outcome outcome, String message, Game game); + public abstract boolean choose(Outcome outcome, Choice choice, Game game); + public abstract boolean playMana(ManaCost unpaid, Game game); + public abstract boolean playXMana(VariableManaCost cost, Game game); + public abstract boolean searchCards(Cards cards, TargetCard target, Game game); + public abstract int chooseEffect(List rEffects, Game game); + public abstract void selectAttackers(Game game); + public abstract void selectBlockers(Game game); + public abstract void assignDamage(int damage, List targets, UUID sourceId, Game game); + public abstract int getAmount(int min, int max, String message, Game game); + + public void declareAttacker(UUID attackerId, UUID defenderId, Game game); + public void declareBlocker(UUID blockerId, UUID attackerId, Game game); + + public void beginTurn(); + public void endOfTurn(Game game); + public void phasing(Game game); + public void untap(Game game); + +} diff --git a/Mage/src/mage/players/PlayerDecision.java b/Mage/src/mage/players/PlayerDecision.java new file mode 100644 index 00000000000..19fcc4579b8 --- /dev/null +++ b/Mage/src/mage/players/PlayerDecision.java @@ -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.players; + +import java.io.Serializable; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class PlayerDecision implements Serializable { + + private String message; + private DecisionType type; + + public enum DecisionType { + USE_EFFECT, + PICK_COLOR, + PICK_ONE + } + + + +} diff --git a/Mage/src/mage/players/PlayerImpl.java b/Mage/src/mage/players/PlayerImpl.java new file mode 100644 index 00000000000..23fec1efa4d --- /dev/null +++ b/Mage/src/mage/players/PlayerImpl.java @@ -0,0 +1,640 @@ +/* +* 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.players; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import mage.Constants.Outcome; +import mage.Constants.Zone; +import mage.MageObject; +import mage.abilities.Abilities; +import mage.abilities.AbilitiesImpl; +import mage.abilities.ActivatedAbility; +import mage.abilities.PlayLandAbility; +import mage.abilities.SpellAbility; +import mage.abilities.TriggeredAbility; +import mage.abilities.keyword.KickerAbility; +import mage.abilities.keyword.ProtectionAbility; +import mage.abilities.keyword.ShroudAbility; +import mage.abilities.mana.ManaAbility; +import mage.cards.Card; +import mage.cards.Cards; +import mage.cards.CardsImpl; +import mage.cards.decks.Deck; +import mage.counters.Counters; +import mage.game.Game; +import mage.game.combat.CombatGroup; +import mage.game.permanent.Permanent; +import mage.game.events.GameEvent; +import mage.game.events.ZoneChangeEvent; +import mage.game.permanent.PermanentCard; +import mage.game.permanent.PermanentToken; +import mage.game.permanent.token.Token; +import mage.game.stack.Spell; +import mage.game.stack.StackAbility; +import mage.target.common.TargetCardInLibrary; +import mage.target.common.TargetDiscard; +import mage.util.Copier; + +public abstract class PlayerImpl implements Player, Serializable { + + private static final long serialVersionUID = 1L; + + protected UUID playerId; + protected String name; + protected int life; + protected boolean wins; + protected boolean loses; + protected Deck deck; + protected Library library; + protected Cards hand = new CardsImpl(Zone.HAND); + protected Cards graveyard = new CardsImpl(Zone.GRAVEYARD); + protected Abilities abilities = new AbilitiesImpl(); + protected Counters counters = new Counters(); + protected int landsPlayed; + protected int landsPerTurn = 1; + protected int maxHandSize = 7; + protected ManaPool manaPool = new ManaPool(); + protected boolean passed; + protected boolean passedTurn; + protected boolean left; + + public PlayerImpl(String name) { + this.playerId = UUID.randomUUID(); + this.name = name; + library = new Library(playerId); + } + + @Override + public void init() { + this.hand.clear(); + this.graveyard.clear(); + this.abilities.clear(); + this.library.clear(); + this.wins = false; + this.loses = false; + this.left = false; + this.passed = false; + this.passedTurn = false; + library.addAll(deck.getCards()); + } + + @Override + public void reset() { + this.abilities.clear(); + this.landsPerTurn = 1; + this.maxHandSize = 7; + } + + @Override + public Counters getCounters() { + return counters; + } + + @Override + public void beginTurn() { + this.landsPlayed = 0; + } + + @Override + public void endOfTurn(Game game) { + this.passedTurn = false; + } + + @Override + public void handleEvent(GameEvent event, Game game) { + hand.handleEvent(event, game); + graveyard.handleEvent(event, game); + } + + @Override + public boolean canTarget(MageObject source) { + if (source != null) { + if (abilities.containsKey(ShroudAbility.getInstance().getId())) + return false; + + for (ProtectionAbility ability: abilities.getProtectionAbilities()) { + if (!ability.canTarget(source)) + return false; + } + } + + return true; + } + +// @Override + protected boolean drawCard(Game game) { + if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.DRAW_CARD, null, playerId))) { + Card card = getLibrary().removeFromTop(game); + if (card != null) { + putInHand(card, game); + game.fireEvent(GameEvent.getEvent(GameEvent.EventType.DREW_CARD, card.getId(), playerId)); + return true; + } + } + return false; + } + + @Override + public int drawCards(int num, Game game) { + int numDrawn = 0; + for (int i = 0; i < num; i++) { + if (drawCard(game)) + numDrawn++; + else + break; + } + game.fireInformEvent(name + " draws " + Integer.toString(numDrawn) + " card" + (numDrawn > 1?"s":"")); + return numDrawn; + } + + @Override + public void discardToMax(Game game) { + while (hand.size() > this.maxHandSize) { + TargetDiscard target = new TargetDiscard(playerId); + chooseTarget(Outcome.Discard, target, game); + discard(hand.get(target.getFirstTarget()), game); + } + } + + @Override + public boolean putInHand(Card card, Game game) { + if (card.getOwnerId().equals(playerId)) { + this.hand.add(card); + } else { + return game.getPlayer(card.getOwnerId()).putInHand(card, game); + } + return true; + } + + @Override + public boolean removeFromHand(Card card, Game game) { + hand.remove(card); + return true; + } + + @Override + public void discard(int amount, Game game) { + if (amount >= hand.size()) { + int discardAmount = hand.size(); + for (Card card: hand.values()) { + discard(card, game); + } + game.fireInformEvent(name + " discards " + Integer.toString(discardAmount) + " card" + (discardAmount > 1?"s":"")); + return; + } + for (int i = 0; i < amount; i++) { + TargetDiscard target = new TargetDiscard(playerId); + chooseTarget(Outcome.Discard, target, game); + discard(hand.get(target.getFirstTarget()), game); + } + game.fireInformEvent(name + " discards " + Integer.toString(amount) + " card" + (amount > 1?"s":"")); + } + + protected void discard(Card card, Game game) { + //20091005 - 701.1 + if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.DISCARD_CARD, playerId, playerId))) { + removeFromHand(card, game); + putInGraveyard(card, game, false); + game.fireEvent(GameEvent.getEvent(GameEvent.EventType.DISCARDED_CARD, playerId, playerId)); + } + } + + @Override + public boolean putOntoBattlefield(Card card, Game game) { + PermanentCard permanent = new PermanentCard(card, playerId); + putOntoBattlefield(permanent, game); + return true; + } + + @Override + public boolean putOntoBattlefield(Token token, Game game) { + PermanentToken permanent = new PermanentToken(token, playerId, playerId); + putOntoBattlefield(permanent, game); + return true; + } + + protected void putOntoBattlefield(Permanent permanent, Game game) { + game.getBattlefield().addPermanent(permanent); + permanent.entersBattlefield(game); + game.fireEvent(new ZoneChangeEvent(permanent.getId(), playerId, Zone.ALL, Zone.BATTLEFIELD)); + } + + @Override + public boolean removeFromBattlefield(Permanent permanent, Game game) { + permanent.removeFromCombat(game); + game.getBattlefield().removePermanent(permanent.getId()); + return true; + } + + @Override + public boolean putInGraveyard(Card card, Game game, boolean fromBattlefield) { + if (card.getOwnerId().equals(playerId)) { + this.graveyard.add(card); + } else { + return game.getPlayer(card.getOwnerId()).putInGraveyard(card, game, fromBattlefield); + } + return true; + } + + @Override + public boolean removeFromGraveyard(Card card, Game game) { + this.graveyard.remove(card); + return true; + } + + @Override + public boolean cast(Card card, Game game, boolean noMana) { + //20091005 - 601.2a + if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.CAST_SPELL, card.getId(), playerId))) { + game.bookmarkState(); + removeFromHand(card, game); + game.getStack().push(new Spell(card, playerId)); + if (card.getSpellAbility().activate(game, noMana)) { + for (KickerAbility ability: card.getAbilities().getKickerAbilities()) { + ability.activate(game, false); + } + game.fireEvent(GameEvent.getEvent(GameEvent.EventType.SPELL_CAST, card.getId(), playerId)); + game.removeLastBookmark(); + return true; + } + } + game.restoreState(); + return false; + } + + @Override + public boolean playLand(Card card, Game game) { + //20091005 - 305.1 + if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.PLAY_LAND, card.getId(), playerId))) { + game.bookmarkState(); + removeFromHand(card, game); + if (putOntoBattlefield(card, game)) { + landsPlayed++; + game.fireEvent(GameEvent.getEvent(GameEvent.EventType.LAND_PLAYED, card.getId(), playerId)); + game.removeLastBookmark(); + return true; + } + } + game.restoreState(); + return false; + } + + protected boolean playManaAbility(ManaAbility ability, Game game) { + game.bookmarkState(); + if (ability.activate(game, false)) { + ability.resolve(game); + game.removeLastBookmark(); + return true; + } + game.restoreState(); + return false; + } + + protected boolean playAbility(ActivatedAbility ability, Game game) { + //20091005 - 602.2a + if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.ACTIVATE_ABILITY, ability.getId(), playerId))) { + game.bookmarkState(); + game.getStack().push(new StackAbility(ability, playerId)); + if (ability.activate(game, false)) { + game.fireEvent(GameEvent.getEvent(GameEvent.EventType.ACTIVATED_ABILITY, ability.getId(), playerId)); + game.removeLastBookmark(); + return true; + } + } + game.restoreState(); + return false; + } + + @Override + public boolean activateAbility(ActivatedAbility ability, Game game) { + boolean result; + if (!ability.canActivate(this.playerId, game)) + return false; + + if (ability instanceof PlayLandAbility) { + result = playLand(hand.get(ability.getSourceId()), game); + } + else if (ability instanceof ManaAbility) { + result = playManaAbility((ManaAbility)ability, game); + } + else if (ability instanceof SpellAbility) { + result = cast(hand.get(ability.getSourceId()), game, false); + } + else { + result = playAbility(ability, game); + } + if (result && !(ability instanceof ManaAbility)) + game.fireInformEvent(name + ability.getActivatedMessage(game)); + + return result; + } + + @Override + public boolean triggerAbility(TriggeredAbility ability, Game game) { + if (ability.activate(game, false)) { + game.getStack().push(new StackAbility(ability, playerId)); + return true; + } + return false; + } + + protected Map getUseableAbilities(List abilities, Game game) { + Map useable = new HashMap(); + for (ActivatedAbility ability: abilities) { + if (ability.canActivate(playerId, game)) + useable.put(ability.getId(), ability); + } + return useable; + } + + @Override + public boolean canPlayLand() { + //20091005 - 114.2a + return landsPlayed < landsPerTurn; + } + + protected boolean isActivePlayer(Game game) { + return game.getActivePlayerId().equals(this.playerId); + } + + @Override + public void shuffleLibrary(Game game) { + this.library.shuffle(); + } + + @Override + public void revealCards(Cards cards, Game game) { + //TODO: implement this + } + + @Override + public void phasing(Game game) { + //20091005 - 502.1 + for (Permanent permanent: game.getBattlefield().getPhasedIn(playerId)) { + permanent.phaseOut(game); + } + for (Permanent permanent: game.getBattlefield().getPhasedOut(playerId)) { + permanent.phaseIn(game); + } + } + + @Override + public void untap(Game game) { + //20091005 - 502.2 + for (Permanent permanent: game.getBattlefield().getAllPermanents(playerId)) { + permanent.untap(game); + } + } + + @Override + public UUID getId() { + return playerId; + } + + @Override + public Cards getHand() { + return hand; + } + + @Override + public Cards getGraveyard() { + return graveyard; + } + + @Override + public Deck getDeck() { + return deck; + } + + @Override + public void setDeck(Deck deck) { + this.deck = deck; + deck.setOwnerId(playerId); + } + + @Override + public ManaPool getManaPool() { + return this.manaPool; + } + + @Override + public String getName() { + return name; + } + + @Override + public Library getLibrary() { + return library; + } + + @Override + public int getLife() { + return life; + } + + @Override + public void setLife(int life, Game game) { + this.life = life; + } + + @Override + public int loseLife(int amount, Game game) { + if (amount > life) { + int curLife = life; + setLife(0, game); + return curLife; + } + else { + setLife(this.life - amount, game); + return amount; + } + } + + @Override + public void gainLife(int amount, Game game) { + setLife(this.life + amount, game); + } + + @Override + public int damage(int damage, UUID sourceId, Game game) { + if (damage > 0 && canDamage(game.getObject(sourceId))) { + GameEvent event = new GameEvent(GameEvent.EventType.DAMAGE_PLAYER, playerId, sourceId, playerId, damage); + if (!game.replaceEvent(event)) { + int actualDamage = event.getAmount(); + if (actualDamage > 0) { + actualDamage = this.loseLife(actualDamage, game); + game.fireEvent(GameEvent.getEvent(GameEvent.EventType.DAMAGED_PLAYER, playerId, sourceId, playerId, actualDamage)); + return actualDamage; + } + } + } + return 0; + } + + protected boolean canDamage(MageObject source) { + for (ProtectionAbility ability: abilities.getProtectionAbilities()) { + if (!ability.canTarget(source)) + return false; + } + return true; + } + + @Override + public Abilities getAbilities() { + return this.abilities; + } + + @Override + public void setResponseString(String responseString) {} + + @Override + public void setResponseUUID(UUID responseUUID) {} + + @Override + public void setResponseBoolean(Boolean responseBoolean) {} + + @Override + public void setResponseInteger(Integer responseInteger) {} + + @Override + public Player copy() { + return new Copier().copy(this); + } + + @Override + public void restore(Player player) { + this.library = player.getLibrary(); + this.deck = player.getDeck(); + this.hand = player.getHand(); + this.graveyard = player.getGraveyard(); + this.abilities = player.getAbilities(); + this.manaPool = player.getManaPool(); + this.life = player.getLife(); + this.counters = player.getCounters(); + } + + @Override + public boolean isPassed() { + return passed; + } + + @Override + public boolean isEmptyDraw() { + return library.isEmtpyDraw(); + } + + @Override + public void resetPriority() { + passed = false; + } + + @Override + public void concede() { + this.loses = true; + } + + @Override + public void leaveGame() { + this.loses = true; + this.left = true; + } + + @Override + public boolean hasLeft() { + return this.left; + } + + @Override + public void lost(Game game) { + if (!game.replaceEvent(new GameEvent(GameEvent.EventType.LOSES, null, null, playerId))) { + this.loses = true; + } + } + + @Override + public void won(Game game) { + if (!game.replaceEvent(new GameEvent(GameEvent.EventType.WINS, null, null, playerId))) { + if (!this.loses) { + this.wins = true; + game.end(); + } + } + } + + @Override + public boolean hasLost() { + return this.loses; + } + + @Override + public boolean hasWon() { + if (!this.loses) + return this.wins; + else + return false; + } + + @Override + public void declareAttacker(UUID attackerId, UUID defenderId, Game game) { + Permanent attacker = game.getPermanent(attackerId); + if (attacker.canAttack(game)) { + if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.DECLARE_ATTACKER, defenderId, attackerId, playerId))) { + game.getCombat().declareAttacker(attackerId, defenderId, game); + game.fireEvent(GameEvent.getEvent(GameEvent.EventType.ATTACKER_DECLARED, defenderId, attackerId, playerId)); + } + } + } + + @Override + public void declareBlocker(UUID blockerId, UUID attackerId, Game game) { + Permanent blocker = game.getPermanent(blockerId); + CombatGroup group = game.getCombat().findGroup(attackerId); + if (group != null && group.canBlock(blocker, game)) { + group.addBlocker(blockerId, playerId, game); + } + } + + @Override + public boolean searchLibrary(TargetCardInLibrary target, Game game) { + //20091005 - 701.14c + if (library.count(target.getFilter()) < target.getNumberOfTargets()) { + TargetCardInLibrary newTarget = new TargetCardInLibrary(library.count(target.getFilter()), target.getMaxNumberOfTargets(), target.getFilter()); + searchCards(new CardsImpl(Zone.LIBRARY, getLibrary().getCards()), newTarget, game); + } + else { + searchCards(new CardsImpl(Zone.LIBRARY, getLibrary().getCards()), target, game); + } + return true; + } + +} diff --git a/Mage/src/mage/players/PlayerList.java b/Mage/src/mage/players/PlayerList.java new file mode 100644 index 00000000000..fa0759cbe35 --- /dev/null +++ b/Mage/src/mage/players/PlayerList.java @@ -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.players; + +import java.util.UUID; +import mage.util.CircularList; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class PlayerList extends CircularList { + + public boolean setCurrent(UUID playerId) { + for (int i = 0; i < list.size(); i++) { + if (list.get(i).getId().equals(playerId)) { + index = i; + return true; + } + } + return false; + } + +} diff --git a/Mage/src/mage/players/PlayerResponse.java b/Mage/src/mage/players/PlayerResponse.java new file mode 100644 index 00000000000..771d87df5d2 --- /dev/null +++ b/Mage/src/mage/players/PlayerResponse.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.players; + +import java.io.Serializable; +import java.util.UUID; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class PlayerResponse implements Serializable { + + private String responseString; + private UUID responseUUID; + private Boolean responseBoolean; + + public void clear() { + responseString = null; + responseUUID = null; + responseBoolean = null; + } + + public String getString() { + return responseString; + } + + public void setString(String responseString) { + this.responseString = responseString; + } + + public UUID getUUID() { + return responseUUID; + } + + public void setUUID(UUID responseUUID) { + this.responseUUID = responseUUID; + } + + public Boolean getBoolean() { + return responseBoolean; + } + + public void setBoolean(Boolean responseBoolean) { + this.responseBoolean = responseBoolean; + } + + + +} diff --git a/Mage/src/mage/players/Players.java b/Mage/src/mage/players/Players.java new file mode 100644 index 00000000000..7b99688a315 --- /dev/null +++ b/Mage/src/mage/players/Players.java @@ -0,0 +1,49 @@ +/* +* 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.players; + +import java.util.LinkedHashMap; +import java.util.UUID; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class Players extends LinkedHashMap { + + public void addPlayer(Player player) { + this.put(player.getId(), player); + } + + public void resetPriority() { + for (Player player: this.values()) { + player.resetPriority(); + } + } +} diff --git a/Mage/src/mage/target/Target.java b/Mage/src/mage/target/Target.java new file mode 100644 index 00000000000..42d286fd3d4 --- /dev/null +++ b/Mage/src/mage/target/Target.java @@ -0,0 +1,69 @@ +/* +* 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.target; + +import java.io.Serializable; +import java.util.List; +import java.util.UUID; +import mage.Constants.Zone; +import mage.abilities.Ability; +import mage.filter.Filter; +import mage.game.Game; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public interface Target extends Serializable { + + public boolean isChosen(); + public boolean doneChosing(); + public void clearChosen(); + public boolean canChoose(UUID sourceId, Game game); + public String getMessage(); + public String getTargetName(); + public String getTargetedName(Game game); + public Zone getZone(); + public boolean isLegal(Game game); + public boolean canTarget(UUID id, Game game); + public void addTarget(UUID id, Game game); + + public int getNumberOfTargets(); + public int getMaxNumberOfTargets(); + public List getTargets(); + public Filter getFilter(); + public Ability getAbility(); + public void setAbility(Ability ability); + + public boolean isRequired(); + public void setRequired(boolean required); + + public UUID getLastTarget(); + public UUID getFirstTarget(); +} diff --git a/Mage/src/mage/target/TargetCard.java b/Mage/src/mage/target/TargetCard.java new file mode 100644 index 00000000000..b17806e7b76 --- /dev/null +++ b/Mage/src/mage/target/TargetCard.java @@ -0,0 +1,98 @@ +/* +* 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.target; + +import java.util.UUID; +import mage.Constants.Zone; +import mage.cards.Card; +import mage.cards.Cards; +import mage.filter.FilterCard; +import mage.game.Game; +import mage.players.Player; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class TargetCard extends TargetObject { + + protected FilterCard filter; + + protected TargetCard(Zone zone) { + this(1, 1, zone, new FilterCard()); + } + + public TargetCard(Zone zone, FilterCard filter) { + this(1, 1, zone, filter); + } + + public TargetCard(int numTargets, Zone zone, FilterCard filter) { + this(numTargets, numTargets, zone, filter); + } + + public TargetCard(int minNumTargets, int maxNumTargets, Zone zone, FilterCard filter) { + this.minNumberOfTargets = minNumTargets; + this.maxNumberOfTargets = maxNumTargets; + this.zone = zone; + this.filter = filter; + this.targetName = filter.getMessage(); + } + + @Override + public FilterCard getFilter() { + return this.filter; + } + + @Override + public boolean canChoose(UUID sourceId, Game game) { + for (Player player: game.getPlayers().values()) { + if (filter.matchOwner(player.getId())) { + switch (zone) { + case HAND: + if (player.getHand().getCards(filter).size() > this.minNumberOfTargets) + return true; + break; + case GRAVEYARD: + if (player.getGraveyard().getCards(filter).size() > this.minNumberOfTargets) + return true; + break; + } + } + } + return false; + } + + public boolean canTarget(UUID id, Cards cards, Game game) { + Card card = cards.get(id); + if (card != null) + return filter.match(card); + return false; + } + +} diff --git a/Mage/src/mage/target/TargetImpl.java b/Mage/src/mage/target/TargetImpl.java new file mode 100644 index 00000000000..0c3bb87002c --- /dev/null +++ b/Mage/src/mage/target/TargetImpl.java @@ -0,0 +1,162 @@ +/* +* 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.target; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import mage.Constants.Zone; +import mage.abilities.Ability; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.events.GameEvent.EventType; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public abstract class TargetImpl implements Target { + + protected List targets = new ArrayList(); + + protected String targetName; + protected Zone zone; + protected int maxNumberOfTargets; + protected int minNumberOfTargets; + protected boolean required = false; + protected Ability source; + + @Override + public int getNumberOfTargets() { + return this.minNumberOfTargets; + } + + @Override + public int getMaxNumberOfTargets() { + return this.maxNumberOfTargets; + } + + @Override + public String getMessage() { + return "Select a " + targetName; + } + + @Override + public String getTargetName() { + return targetName; + } + + @Override + public Zone getZone() { + return zone; + } + + @Override + public boolean isRequired() { + return required; + } + + @Override + public void setRequired(boolean required) { + this.required = required; + } + + @Override + public boolean isChosen() { + return targets.size() >= minNumberOfTargets; + } + + @Override + public boolean doneChosing() { + return targets.size() == maxNumberOfTargets; + } + + @Override + public void clearChosen() { + targets.clear(); + } + + /** + * + * @param id + * @param game + * @return true if able to add target + */ + @Override + public void addTarget(UUID id, Game game) { + if (source != null) { + if (!game.replaceEvent(GameEvent.getEvent(EventType.TARGET, id, source.getSourceId(), source.getControllerId()))) { + targets.add(id); + game.fireEvent(GameEvent.getEvent(EventType.TARGETED, id, source.getSourceId(), source.getControllerId())); + } + } + else { + targets.add(id); + } + } + + @Override + public boolean isLegal(Game game) { + for (UUID targetId: targets) { + if (!canTarget(targetId, game)) + return false; + } + return true; + } + + @Override + public List getTargets() { + return targets; + } + + @Override + public UUID getLastTarget() { + if (targets.size() > 0) + return targets.get(targets.size() - 1); + return null; + } + + @Override + public UUID getFirstTarget() { + if (targets.size() > 0) + return targets.get(0); + return null; + } + + @Override + public Ability getAbility() { + return source; + } + + @Override + public void setAbility(Ability ability) { + this.source = ability; + } + +} diff --git a/Mage/src/mage/target/TargetObject.java b/Mage/src/mage/target/TargetObject.java new file mode 100644 index 00000000000..729c8c69862 --- /dev/null +++ b/Mage/src/mage/target/TargetObject.java @@ -0,0 +1,78 @@ +/* +* 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.target; + +import java.util.UUID; +import mage.Constants.Zone; +import mage.MageObject; +import mage.game.Game; +import mage.players.Player; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public abstract class TargetObject extends TargetImpl { + + protected TargetObject() {} + + public TargetObject(Zone zone) { + this(1, 1, zone); + } + + public TargetObject(int numTargets, Zone zone) { + this(numTargets, numTargets, zone); + } + + public TargetObject(int minNumTargets, int maxNumTargets, Zone zone) { + this.minNumberOfTargets = minNumTargets; + this.maxNumberOfTargets = maxNumTargets; + this.zone = zone; + this.targetName = "card"; + } + + @Override + public String getTargetedName(Game game) { + StringBuilder sb = new StringBuilder(); + for (UUID targetId: getTargets()) { + sb.append(game.getObject(targetId).getName()); + sb.append(" "); + } + return sb.toString(); + } + + @Override + public boolean canTarget(UUID id, Game game) { + MageObject object = game.getObject(id); + if (object != null && object.getZone().match(zone)) + return getFilter().match(object); + return false; + } + +} diff --git a/Mage/src/mage/target/TargetPermanent.java b/Mage/src/mage/target/TargetPermanent.java new file mode 100644 index 00000000000..c49c02fbf0f --- /dev/null +++ b/Mage/src/mage/target/TargetPermanent.java @@ -0,0 +1,128 @@ +/* +* 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.target; + +import java.util.Iterator; +import java.util.List; +import java.util.UUID; +import mage.Constants.TargetController; +import mage.Constants.Zone; +import mage.filter.FilterPermanent; +import mage.game.Game; +import mage.game.permanent.Permanent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class TargetPermanent extends TargetObject { + + protected FilterPermanent filter; + protected TargetController controller; + + public TargetPermanent() { + this(1, 1, new FilterPermanent(), TargetController.ANY); + } + + public TargetPermanent(FilterPermanent filter, TargetController controller) { + this(1, 1, filter, controller); + } + + public TargetPermanent(int numTargets, FilterPermanent filter, TargetController controller) { + this(numTargets, numTargets, filter, controller); + } + + public TargetPermanent(int minNumTargets, int maxNumTargets, FilterPermanent filter, TargetController controller) { + this.minNumberOfTargets = minNumTargets; + this.maxNumberOfTargets = maxNumTargets; + this.zone = Zone.BATTLEFIELD; + this.filter = filter; + this.targetName = filter.getMessage(); + this.controller = controller; + } + + @Override + public boolean canTarget(UUID id, Game game) { + return canTarget(null, id, game); + } + + public boolean canTarget(UUID controllerId, UUID id, Game game) { + Permanent permanent = game.getPermanent(id); + if (controllerId != null) + setController(controllerId, game); + if (permanent != null) { + if (this.source != null) + return permanent.canTarget(game.getObject(this.source.getSourceId())) && filter.match(permanent); + else + return filter.match(permanent); + } + return false; + } + + protected void setController(UUID controllerId, Game game) { + filter.getControllerId().clear(); + switch (controller) { + case ANY: + break; + case YOU: + filter.getControllerId().add(controllerId); + filter.setNotController(false); + break; + case NOT_YOU: + filter.getControllerId().add(controllerId); + filter.setNotController(true); + break; + case OPPONENT: + filter.getControllerId().addAll(game.getOpponents(controllerId)); + filter.setNotController(false); + break; + } + } + + @Override + public FilterPermanent getFilter() { + return this.filter; + } + + @Override + public boolean canChoose(UUID sourceId, Game game) { + List permanents = game.getBattlefield().getActivePermanents(filter); + Iterator it = permanents.iterator(); + while(it.hasNext()) { + Permanent permanent = it.next(); + if (!permanent.canTarget(game.getObject(sourceId))) { + it.remove(); + } + } + if (permanents.size() >= this.minNumberOfTargets) + return true; + return false; + } + +} diff --git a/Mage/src/mage/target/TargetPlayer.java b/Mage/src/mage/target/TargetPlayer.java new file mode 100644 index 00000000000..2616f378613 --- /dev/null +++ b/Mage/src/mage/target/TargetPlayer.java @@ -0,0 +1,110 @@ +/* +* 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.target; + +import java.util.UUID; +import mage.Constants.Zone; +import mage.filter.FilterPlayer; +import mage.game.Game; +import mage.players.Player; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class TargetPlayer extends TargetImpl { + + protected FilterPlayer filter = new FilterPlayer(); + + public TargetPlayer() { + this(1, 1); + } + + public TargetPlayer(int numTargets) { + this(numTargets, numTargets); + } + + public TargetPlayer(int minNumTargets, int maxNumTargets) { + this.minNumberOfTargets = minNumTargets; + this.maxNumberOfTargets = maxNumTargets; + this.zone = Zone.PLAYER; + this.targetName = "player"; + } + + @Override + public FilterPlayer getFilter() { + return filter; + } + + @Override + public boolean canChoose(UUID sourceId, Game game) { + int count = 0; + for (Player player: game.getPlayers().values()) { + if (filter.match(player)) { + if (player.canTarget(game.getObject(sourceId))) + count++; + } + } + if (count >= this.minNumberOfTargets) + return true; + return false; + } + + @Override + public boolean isLegal(Game game) { + for (UUID playerId: targets) { + if (!canTarget(playerId, game)) + return false; + } + return true; + } + + @Override + public boolean canTarget(UUID id, Game game) { + Player player = game.getPlayer(id); + if (player != null) { + if (source != null) + return player.canTarget(game.getObject(this.source.getSourceId())) && filter.match(player); + else + return filter.match(player); + } + return false; + } + + @Override + public String getTargetedName(Game game) { + StringBuilder sb = new StringBuilder(); + for (UUID targetId: getTargets()) { + sb.append(game.getPlayer(targetId).getName()); + sb.append(" "); + } + return sb.toString(); + } + +} diff --git a/Mage/src/mage/target/TargetSpell.java b/Mage/src/mage/target/TargetSpell.java new file mode 100644 index 00000000000..c40d5a38101 --- /dev/null +++ b/Mage/src/mage/target/TargetSpell.java @@ -0,0 +1,90 @@ +/* +* 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.target; + +import java.util.UUID; +import mage.Constants.Zone; +import mage.filter.FilterSpell; +import mage.game.Game; +import mage.game.stack.Spell; +import mage.game.stack.StackObject; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class TargetSpell extends TargetObject { + + protected FilterSpell filter; + + public TargetSpell() { + this(1, 1, new FilterSpell()); + } + + public TargetSpell(FilterSpell filter) { + this(1, 1, filter); + } + + public TargetSpell(int numTargets, FilterSpell filter) { + this(numTargets, numTargets, filter); + } + + public TargetSpell(int minNumTargets, int maxNumTargets, FilterSpell filter) { + this.minNumberOfTargets = minNumTargets; + this.maxNumberOfTargets = maxNumTargets; + this.zone = Zone.STACK; + this.filter = filter; + this.targetName = filter.getMessage(); + } + + @Override + public FilterSpell getFilter() { + return filter; + } + + @Override + public boolean canTarget(UUID id, Game game) { + StackObject stackObject = game.getStack().getStackObject(id); + if (stackObject != null && stackObject instanceof Spell) { + return filter.match((Spell)stackObject); + } + return false; + } + + public boolean canChoose(UUID sourceId, Game game) { + int count = 0; + for (StackObject stackObject: game.getStack()) { + if (stackObject instanceof Spell && filter.match((Spell)stackObject)) { + count++; + } + } + return count >= this.minNumberOfTargets; + } + +} diff --git a/Mage/src/mage/target/Targets.java b/Mage/src/mage/target/Targets.java new file mode 100644 index 00000000000..f35d7efd1c5 --- /dev/null +++ b/Mage/src/mage/target/Targets.java @@ -0,0 +1,112 @@ +/* +* 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.target; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import mage.Constants.Outcome; +import mage.abilities.Ability; +import mage.game.Game; +import mage.players.Player; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class Targets extends ArrayList { + + protected Ability source; + + public Targets(Ability ability) { + this.source = ability; + } + + public void setSource(Ability ability) { + this.source = ability; + } + + @Override + public boolean add(Target target) { + target.setAbility(source); + return super.add(target); + } + + public List getUnchosen() { + List unchosen = new ArrayList(); + for (Target target: this) { + if (!target.isChosen()) + unchosen.add(target); + } + return unchosen; + } + + public void clearChosen() { + for (Target target: this) { + target.clearChosen(); + } + } + + public boolean isChosen() { + for (Target target: this) { + if (!target.isChosen()) + return false; + } + return true; + } + + public boolean choose(Outcome outcome, Game game) { + if (this.size() > 0) { + Player player = game.getPlayer(this.source.getControllerId()); + while (!isChosen()) { + Target target = this.getUnchosen().get(0); + if (!player.chooseTarget(outcome, target, game)) + return false; + } + } + return true; + } + + public boolean stillLegal(Game game) { + for (Target target: this) { + if (!target.isLegal(game)) { + return false; + } + } + return true; + } + + public boolean canChoose(UUID sourceId, Game game) { + for (Target target: this) { + if (!target.canChoose(sourceId, game)) + return false; + } + return true; + } +} diff --git a/Mage/src/mage/target/common/TargetAttackingCreature.java b/Mage/src/mage/target/common/TargetAttackingCreature.java new file mode 100644 index 00000000000..9c6801dcdc6 --- /dev/null +++ b/Mage/src/mage/target/common/TargetAttackingCreature.java @@ -0,0 +1,52 @@ +/* +* 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.target.common; + +import mage.Constants.TargetController; +import mage.filter.common.FilterAttackingCreature; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class TargetAttackingCreature extends TargetCreaturePermanent { + + public TargetAttackingCreature() { + this(1, 1, new FilterAttackingCreature(), TargetController.ANY); + } + + public TargetAttackingCreature(int numTargets, TargetController controller) { + this(numTargets, numTargets, new FilterAttackingCreature(), controller); + } + + public TargetAttackingCreature(int minNumTargets, int maxNumTargets, FilterAttackingCreature filter, TargetController controller) { + super(1, 1, filter, controller); + this.targetName = filter.getMessage(); + } +} diff --git a/Mage/src/mage/target/common/TargetBasicLandCard.java b/Mage/src/mage/target/common/TargetBasicLandCard.java new file mode 100644 index 00000000000..87ed7a54f07 --- /dev/null +++ b/Mage/src/mage/target/common/TargetBasicLandCard.java @@ -0,0 +1,49 @@ +/* +* 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.target.common; + +import mage.Constants.Zone; +import mage.target.TargetCard; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class TargetBasicLandCard extends TargetCard { + + public TargetBasicLandCard(Zone zone) { + super(zone); + filter.getName().add("Island"); + filter.getName().add("Forest"); + filter.getName().add("Mountain"); + filter.getName().add("Swamp"); + filter.getName().add("Plains"); + } + +} diff --git a/Mage/src/mage/target/common/TargetCardInGraveyard.java b/Mage/src/mage/target/common/TargetCardInGraveyard.java new file mode 100644 index 00000000000..4cce1bffdb6 --- /dev/null +++ b/Mage/src/mage/target/common/TargetCardInGraveyard.java @@ -0,0 +1,69 @@ +/* +* 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.target.common; + +import java.util.UUID; +import mage.Constants.Zone; +import mage.cards.Card; +import mage.filter.FilterCard; +import mage.game.Game; +import mage.target.TargetCard; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class TargetCardInGraveyard extends TargetCard { + + public TargetCardInGraveyard() { + this(1, 1, new FilterCard()); + } + + public TargetCardInGraveyard(FilterCard filter) { + this(1, 1, filter); + } + + public TargetCardInGraveyard(int numTargets, FilterCard filter) { + this(numTargets, numTargets, filter); + } + + public TargetCardInGraveyard(int minNumTargets, int maxNumTargets, FilterCard filter) { + super(minNumTargets, maxNumTargets, Zone.HAND, filter); + this.targetName = "card in graveyard"; + } + + @Override + public boolean canTarget(UUID id, Game game) { + Card card = game.getPlayer(this.source.getControllerId()).getHand().get(id); + if (card != null) + return filter.match(card); + return false; + } + +} diff --git a/Mage/src/mage/target/common/TargetCardInHand.java b/Mage/src/mage/target/common/TargetCardInHand.java new file mode 100644 index 00000000000..7412106b66a --- /dev/null +++ b/Mage/src/mage/target/common/TargetCardInHand.java @@ -0,0 +1,72 @@ +/* +* 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.target.common; + +import java.util.UUID; +import mage.Constants.Zone; +import mage.cards.Card; +import mage.filter.FilterCard; +import mage.game.Game; +import mage.target.TargetCard; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class TargetCardInHand extends TargetCard { + + protected UUID playerId; + + public TargetCardInHand(UUID playerId) { + this(1, 1, new FilterCard(), playerId); + } + + public TargetCardInHand(FilterCard filter, UUID playerId) { + this(1, 1, filter, playerId); + } + + public TargetCardInHand(int numTargets, FilterCard filter, UUID playerId) { + this(numTargets, numTargets, filter, playerId); + } + + public TargetCardInHand(int minNumTargets, int maxNumTargets, FilterCard filter, UUID playerId) { + super(minNumTargets, maxNumTargets, Zone.HAND, filter); + this.targetName = "card in hand"; + this.playerId = playerId; + } + + @Override + public boolean canTarget(UUID id, Game game) { + Card card = game.getPlayer(playerId).getHand().get(id); + if (card != null) + return filter.match(card); + return false; + } + +} diff --git a/Mage/src/mage/target/common/TargetCardInLibrary.java b/Mage/src/mage/target/common/TargetCardInLibrary.java new file mode 100644 index 00000000000..647af6cc330 --- /dev/null +++ b/Mage/src/mage/target/common/TargetCardInLibrary.java @@ -0,0 +1,69 @@ +/* +* 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.target.common; + +import java.util.UUID; +import mage.Constants.Zone; +import mage.cards.Card; +import mage.cards.Cards; +import mage.filter.FilterCard; +import mage.game.Game; +import mage.target.TargetCard; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class TargetCardInLibrary extends TargetCard { + + public TargetCardInLibrary() { + this(1, 1, new FilterCard()); + } + + public TargetCardInLibrary(FilterCard filter) { + this(1, 1, filter); + } + + public TargetCardInLibrary(int numTargets, FilterCard filter) { + this(numTargets, numTargets, filter); + } + + public TargetCardInLibrary(int minNumTargets, int maxNumTargets, FilterCard filter) { + super(minNumTargets, maxNumTargets, Zone.LIBRARY, filter); + } + + @Override + public boolean canTarget(UUID id, Game game) { + Card card = game.getPlayer(this.source.getControllerId()).getLibrary().getCard(id); + if (card != null) + return filter.match(card); + return false; + } + +} diff --git a/Mage/src/mage/target/common/TargetCreatureOrPlayer.java b/Mage/src/mage/target/common/TargetCreatureOrPlayer.java new file mode 100644 index 00000000000..5f0a4659b1f --- /dev/null +++ b/Mage/src/mage/target/common/TargetCreatureOrPlayer.java @@ -0,0 +1,123 @@ +/* +* 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.target.common; + +import java.util.UUID; +import mage.Constants.CardType; +import mage.Constants.Zone; +import mage.filter.Filter; +import mage.filter.common.FilterCreatureOrPlayer; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; +import mage.target.TargetImpl; +import mage.target.TargetObject; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class TargetCreatureOrPlayer extends TargetImpl { + + protected FilterCreatureOrPlayer filter; + + public TargetCreatureOrPlayer() { + this(1, 1); + } + + public TargetCreatureOrPlayer(int numTargets) { + this(numTargets, numTargets); + } + + public TargetCreatureOrPlayer(int minNumTargets, int maxNumTargets) { + this.minNumberOfTargets = minNumTargets; + this.maxNumberOfTargets = maxNumTargets; + this.zone = Zone.ALL; + this.filter = new FilterCreatureOrPlayer(); + this.targetName = filter.getMessage(); + } + + @Override + public Filter getFilter() { + return this.filter; + } + + @Override + public boolean canTarget(UUID id, Game game) { + Permanent permanent = game.getPermanent(id); + if (permanent != null) { + if (this.source != null) + return permanent.canTarget(game.getObject(this.source.getSourceId())) && filter.match(permanent); + else + return filter.match(permanent); + } + Player player = game.getPlayer(id); + if (player != null) + if (this.source != null) + return player.canTarget(game.getObject(this.source.getSourceId())) && filter.match(player); + else + return filter.match(player); + return false; + } + + @Override + public boolean canChoose(UUID sourceId, Game game) { + int count = 0; + for (Player player: game.getPlayers().values()) { + if (player.canTarget(game.getObject(this.source.getSourceId())) && filter.match(player)) + count++; + } + if (count >= this.minNumberOfTargets) + return true; + for (Permanent permanent: game.getBattlefield().getActivePermanents(CardType.CREATURE)) { + if (permanent.canTarget(game.getObject(this.source.getSourceId())) && filter.match(permanent)) + count++; + } + return count >= this.minNumberOfTargets; + } + + @Override + public String getTargetedName(Game game) { + StringBuilder sb = new StringBuilder(); + for (UUID targetId: getTargets()) { + Permanent permanent = game.getPermanent(targetId); + if (permanent != null) { + sb.append(permanent.getName()); + sb.append(" "); + } + else { + Player player = game.getPlayer(targetId); + sb.append(player.getName()); + sb.append(" "); + } + } + return sb.toString(); + } + +} diff --git a/Mage/src/mage/target/common/TargetCreaturePermanent.java b/Mage/src/mage/target/common/TargetCreaturePermanent.java new file mode 100644 index 00000000000..625510db371 --- /dev/null +++ b/Mage/src/mage/target/common/TargetCreaturePermanent.java @@ -0,0 +1,54 @@ +/* +* 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.target.common; + +import mage.Constants.TargetController; +import mage.filter.common.FilterCreaturePermanent; +import mage.target.TargetPermanent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class TargetCreaturePermanent extends TargetPermanent { + + public TargetCreaturePermanent() { + this(1, 1, new FilterCreaturePermanent(), TargetController.ANY); + } + + public TargetCreaturePermanent(int numTargets, TargetController controller) { + this(numTargets, numTargets, new FilterCreaturePermanent(), controller); + } + + public TargetCreaturePermanent(int minNumTargets, int maxNumTargets, FilterCreaturePermanent filter, TargetController controller) { + super(1, 1, filter, controller); + this.targetName = filter.getMessage(); + } + +} diff --git a/Mage/src/mage/target/common/TargetDefender.java b/Mage/src/mage/target/common/TargetDefender.java new file mode 100644 index 00000000000..c3851d49f92 --- /dev/null +++ b/Mage/src/mage/target/common/TargetDefender.java @@ -0,0 +1,87 @@ +/* +* 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.target.common; + +import java.util.List; +import java.util.UUID; +import mage.Constants.CardType; +import mage.Constants.Zone; +import mage.filter.Filter; +import mage.filter.common.FilterPlaneswalkerOrPlayer; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; +import mage.target.TargetObject; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class TargetDefender extends TargetObject { + + protected FilterPlaneswalkerOrPlayer filter; + + public TargetDefender(List defenders) { + this(1, 1, defenders); + } + + public TargetDefender(int numTargets, List defenders) { + this(numTargets, numTargets, defenders); + } + + public TargetDefender(int minNumTargets, int maxNumTargets, List defenders) { + this.minNumberOfTargets = minNumTargets; + this.maxNumberOfTargets = maxNumTargets; + this.zone = Zone.ALL; + this.filter = new FilterPlaneswalkerOrPlayer(defenders); + this.targetName = filter.getMessage(); + } + + @Override + public Filter getFilter() { + return this.filter; + } + + public boolean canChoose(UUID sourceId, Game game) { + int count = 0; + for (Player player: game.getPlayers().values()) { + if (player.canTarget(game.getObject(this.source.getSourceId())) && filter.match(player)) + count++; + } + if (count >= this.minNumberOfTargets) + return true; + for (Permanent permanent: game.getBattlefield().getActivePermanents(CardType.PLANESWALKER)) { + if (permanent.canTarget(game.getObject(this.source.getSourceId())) && filter.match(permanent)) + count++; + } + return count >= this.minNumberOfTargets; + } + + +} diff --git a/Mage/src/mage/target/common/TargetDiscard.java b/Mage/src/mage/target/common/TargetDiscard.java new file mode 100644 index 00000000000..d0dfda5d2cf --- /dev/null +++ b/Mage/src/mage/target/common/TargetDiscard.java @@ -0,0 +1,46 @@ +/* +* 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.target.common; + +import java.util.UUID; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class TargetDiscard extends TargetCardInHand { + + public TargetDiscard(UUID playerId) { + super(playerId); + filter.getOwnerId().add(playerId); + this.required = true; + this.targetName = "card to discard"; + } + +} diff --git a/Mage/src/mage/target/common/TargetLandPermanent.java b/Mage/src/mage/target/common/TargetLandPermanent.java new file mode 100644 index 00000000000..64bb2dabfb1 --- /dev/null +++ b/Mage/src/mage/target/common/TargetLandPermanent.java @@ -0,0 +1,55 @@ +/* +* 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.target.common; + +import mage.Constants.CardType; +import mage.Constants.TargetController; +import mage.filter.common.FilterLandPermanent; +import mage.target.TargetPermanent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class TargetLandPermanent extends TargetPermanent { + + public TargetLandPermanent() { + this(1, 1, new FilterLandPermanent(), TargetController.ANY); + } + + public TargetLandPermanent(int numTargets, TargetController controller) { + this(numTargets, numTargets, new FilterLandPermanent(), controller); + } + + public TargetLandPermanent(int minNumTargets, int maxNumTargets, FilterLandPermanent filter, TargetController controller) { + super(1, 1, filter, controller); + this.targetName = filter.getMessage(); + } + +} diff --git a/Mage/src/mage/target/common/TargetNonBasicLandPermanent.java b/Mage/src/mage/target/common/TargetNonBasicLandPermanent.java new file mode 100644 index 00000000000..f44d06c6507 --- /dev/null +++ b/Mage/src/mage/target/common/TargetNonBasicLandPermanent.java @@ -0,0 +1,46 @@ +/* +* 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.target.common; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class TargetNonBasicLandPermanent extends TargetLandPermanent { + + public TargetNonBasicLandPermanent() { + filter.setNotName(true); + filter.getName().add("Island"); + filter.getName().add("Forest"); + filter.getName().add("Mountain"); + filter.getName().add("Swamp"); + filter.getName().add("Plains"); + } + +} diff --git a/Mage/src/mage/target/common/TargetNonlandPermanent.java b/Mage/src/mage/target/common/TargetNonlandPermanent.java new file mode 100644 index 00000000000..789fa2093cd --- /dev/null +++ b/Mage/src/mage/target/common/TargetNonlandPermanent.java @@ -0,0 +1,54 @@ +/* +* 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.target.common; + +import mage.Constants.TargetController; +import mage.filter.common.FilterNonlandPermanent; +import mage.target.TargetPermanent; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class TargetNonlandPermanent extends TargetPermanent { + + public TargetNonlandPermanent() { + this(1, 1, TargetController.ANY); + } + + public TargetNonlandPermanent(int numTargets, TargetController controller) { + this(numTargets, numTargets, controller); + } + + public TargetNonlandPermanent(int minNumTargets, int maxNumTargets, TargetController controller) { + super(1, 1, new FilterNonlandPermanent(), controller); + this.targetName = filter.getMessage(); + } + +} diff --git a/Mage/src/mage/util/CircularList.java b/Mage/src/mage/util/CircularList.java new file mode 100644 index 00000000000..cfe05846e0a --- /dev/null +++ b/Mage/src/mage/util/CircularList.java @@ -0,0 +1,442 @@ +/* +* 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.util; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collection; +import java.util.ConcurrentModificationException; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; +import java.util.concurrent.locks.ReentrantLock; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class CircularList implements List, Iterable, Serializable { + + protected List list = new ArrayList(); + + protected final ReentrantLock lock = new ReentrantLock(); + + protected int modCount; + protected int index; + + /** + * Inserts an element into the current position + */ + @Override + public boolean add(E e) { + list.add(this.index, e); + return true; + } + + @Override + public void add(int index, E element) { + lock.lock(); + try { + list.add(index, element); + modCount++; + } + finally { + lock.unlock(); + } + } + + /** + * + * @param e the element to set as current + * @return true if element e exists and index was set + */ + public boolean setCurrent(E e) { + if (list.contains(e)) { + this.index = list.indexOf(e); + return true; + } + return false; + } + + /** + * Retrieves the element at the current position + */ + public E get() { + return list.get(this.index); + } + + @Override + public E get(int index) { + return list.get(index); + } + + public E getNext() { + return list.get(incrementPointer()); + } + + public E getPrevious() { + return list.get(decrementPointer()); + } + + public boolean remove() { + return this.remove(get()); + } + + @Override + public E remove(int index) { + lock.lock(); + try { + E ret = list.remove(index); + checkPointer(); + modCount++; + return ret; + } + finally { + lock.unlock(); + } + } + + @Override + public boolean remove(Object o) { + lock.lock(); + try { + boolean ret = list.remove(o); + checkPointer(); + modCount++; + return ret; + } + finally { + lock.unlock(); + } + } + + private int incrementPointer() { + lock.lock(); + try { + index = incrementListPointer(index); + return index; + } + finally { + lock.unlock(); + } + } + + private int incrementListPointer(int index) { + index++; + if (index >= list.size()) + index = 0; + return index; + } + + private int decrementPointer() { + lock.lock(); + try { + index = decrementListPointer(index); + return index; + } + finally { + lock.unlock(); + } + } + + private int decrementListPointer(int index) { + index--; + if (index < 0) + index = list.size() - 1; + return index; + } + + /** + * This method should only be called from a locked method + * thus it is not necessary to lock from this method + */ + private int checkPointer() { + if (index > list.size()) { + index = list.size() - 1; + } + else if (index < 0) + index = 0; + return index; + } + + @Override + public int size() { + return list.size(); + } + + @Override + public boolean isEmpty() { + return list.isEmpty(); + } + + @Override + public boolean contains(Object o) { + return list.contains(o); + } + + @Override + public Object[] toArray() { + return list.toArray(); + } + + @Override + public T[] toArray(T[] a) { + return list.toArray(a); + } + + public List toList() { + return list; + } + + @Override + public boolean containsAll(Collection c) { + return list.containsAll(c); + } + + @Override + public boolean addAll(Collection c) { + return this.addAll(this.index, c); + } + + @Override + public boolean addAll(int index, Collection c) { + lock.lock(); + try { + modCount++; + return list.addAll(index, c); + } + finally { + lock.unlock(); + } + } + + @Override + public boolean removeAll(Collection c) { + lock.lock(); + try { + boolean ret = list.removeAll(c); + modCount++; + checkPointer(); + return ret; + } + finally { + lock.unlock(); + } + } + + @Override + public boolean retainAll(Collection c) { + lock.lock(); + try { + boolean ret = list.retainAll(c); + modCount++; + checkPointer(); + return ret; + } + finally { + lock.unlock(); + } + } + + @Override + public void clear() { + lock.lock(); + try { + list.clear(); + modCount++; + index = 0; + } + finally { + lock.unlock(); + } + } + + @Override + public E set(int index, E element) { + lock.lock(); + try { + modCount++; + return list.set(index, element); + } + finally { + lock.unlock(); + } + } + + public E set(E element) { + return this.set(this.index, element); + } + + @Override + public int indexOf(Object o) { + return list.indexOf(o); + } + + @Override + public int lastIndexOf(Object o) { + return list.lastIndexOf(o); + } + + @Override + public List subList(int fromIndex, int toIndex) { + return list.subList(fromIndex, toIndex); + } + + @Override + public Iterator iterator() { + return new CircularIterator(); + } + + @Override + public ListIterator listIterator() { + return new CircularListIterator(); + } + + @Override + public ListIterator listIterator(int index) { + return new CircularListIterator(index); + } + + private class CircularIterator implements Iterator { + + int cursor; + int lastIndex; + int curModCount; + boolean hasMoved = false; + + private CircularIterator() { + curModCount = modCount; + cursor = index; + lastIndex = cursor; + } + + @Override + public boolean hasNext() { + if (!hasMoved && size() > 0) + return true; + return cursor != lastIndex; + } + + @Override + public E next() { + if (!this.hasNext()) + throw new IllegalStateException(); + if (curModCount != modCount) + throw new ConcurrentModificationException(); + E data = (E) list.get(cursor); + cursor = incrementListPointer(cursor); + hasMoved = true; + return data; + } + + public void remove() { + throw new UnsupportedOperationException("Not supported yet."); + } + + } + + private class CircularListIterator implements ListIterator { + int cursor; + int lastIndex; + int firstIndex; + int curModCount; + boolean hasMoved = false; + + private CircularListIterator() { + this(index); + } + + private CircularListIterator(int index) { + curModCount = modCount; + cursor = index; + firstIndex = index; + lastIndex = index; + } + + public boolean hasNext() { + if (!hasMoved && size() > 0) + return true; + return cursor != lastIndex; + } + + public E next() { + if (!this.hasNext()) + throw new IllegalStateException(); + if (curModCount != modCount) + throw new ConcurrentModificationException(); + E data = (E) list.get(cursor); + cursor = incrementListPointer(cursor); + hasMoved = true; + return data; + } + + public boolean hasPrevious() { + if (!hasMoved && size() > 0) + return true; + return cursor != firstIndex; + } + + public E previous() { + if (!this.hasPrevious()) + throw new IllegalStateException(); + if (curModCount != modCount) + throw new ConcurrentModificationException(); + cursor = decrementListPointer(cursor); + hasMoved = true; + return (E) list.get(cursor); + } + + public int nextIndex() { + if (this.hasNext()) + return incrementListPointer(cursor); + return list.size(); + } + + public int previousIndex() { + if (this.hasPrevious()) + return decrementListPointer(cursor); + return -1; + } + + public void remove() { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void set(E arg0) { + throw new UnsupportedOperationException("Not supported yet."); + } + + public void add(E arg0) { + throw new UnsupportedOperationException("Not supported yet."); + } + + } + + +} diff --git a/Mage/src/mage/util/Copier.java b/Mage/src/mage/util/Copier.java new file mode 100644 index 00000000000..662eccc4ac6 --- /dev/null +++ b/Mage/src/mage/util/Copier.java @@ -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.util; + +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class Copier { + + public T copy(T obj) { + T copy = null; + try { + FastByteArrayOutputStream fbos = new FastByteArrayOutputStream(); + ObjectOutputStream out= new ObjectOutputStream(fbos); + + // Write the object out to a byte array + out.writeObject(obj); + out.flush(); + out.close(); + + // Retrieve an input stream from the byte array and read + // a copy of the object back in. + ObjectInputStream in = new ObjectInputStream(fbos.getInputStream()); + copy = (T) in.readObject(); + } + catch(IOException e) { + e.printStackTrace(); + } + catch(ClassNotFoundException cnfe) { + cnfe.printStackTrace(); + } + return copy; + + } +} diff --git a/Mage/src/mage/util/FastByteArrayInputStream.java b/Mage/src/mage/util/FastByteArrayInputStream.java new file mode 100644 index 00000000000..6308e306651 --- /dev/null +++ b/Mage/src/mage/util/FastByteArrayInputStream.java @@ -0,0 +1,89 @@ +/* +* 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.util; + +import java.io.InputStream; + +/** + * ByteArrayInputStream implementation that does not synchronize methods. + */ +public class FastByteArrayInputStream extends InputStream { + /** + * Our byte buffer + */ + protected byte[] buf = null; + + /** + * Number of bytes that we can read from the buffer + */ + protected int count = 0; + + /** + * Number of bytes that have been read from the buffer + */ + protected int pos = 0; + + public FastByteArrayInputStream(byte[] buf, int count) { + this.buf = buf; + this.count = count; + } + + @Override + public final int available() { + return count - pos; + } + + public final int read() { + return (pos < count) ? (buf[pos++] & 0xff) : -1; + } + + @Override + public final int read(byte[] b, int off, int len) { + if (pos >= count) + return -1; + + if ((pos + len) > count) + len = (count - pos); + + System.arraycopy(buf, pos, b, off, len); + pos += len; + return len; + } + + @Override + public final long skip(long n) { + if ((pos + n) > count) + n = count - pos; + if (n < 0) + return 0; + pos += n; + return n; + } + +} diff --git a/Mage/src/mage/util/FastByteArrayOutputStream.java b/Mage/src/mage/util/FastByteArrayOutputStream.java new file mode 100644 index 00000000000..6ceaf562954 --- /dev/null +++ b/Mage/src/mage/util/FastByteArrayOutputStream.java @@ -0,0 +1,115 @@ +/* +* 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.util; + +import java.io.InputStream; +import java.io.OutputStream; + +/** + * ByteArrayOutputStream implementation that doesn't synchronize methods + * and doesn't copy the data on toByteArray(). + */ +public class FastByteArrayOutputStream extends OutputStream { + /** + * Buffer and size + */ + protected byte[] buf = null; + protected int size = 0; + + /** + * Constructs a stream with buffer capacity size 5K + */ + public FastByteArrayOutputStream() { + this(5 * 1024); + } + + /** + * Constructs a stream with the given initial size + */ + public FastByteArrayOutputStream(int initSize) { + this.size = 0; + this.buf = new byte[initSize]; + } + + /** + * Ensures that we have a large enough buffer for the given size. + */ + private void verifyBufferSize(int sz) { + if (sz > buf.length) { + byte[] old = buf; + buf = new byte[Math.max(sz, 2 * buf.length )]; + System.arraycopy(old, 0, buf, 0, old.length); + old = null; + } + } + + public int getSize() { + return size; + } + + /** + * Returns the byte array containing the written data. Note that this + * array will almost always be larger than the amount of data actually + * written. + */ + public byte[] getByteArray() { + return buf; + } + + @Override + public final void write(byte b[]) { + verifyBufferSize(size + b.length); + System.arraycopy(b, 0, buf, size, b.length); + size += b.length; + } + + @Override + public final void write(byte b[], int off, int len) { + verifyBufferSize(size + len); + System.arraycopy(b, off, buf, size, len); + size += len; + } + + public final void write(int b) { + verifyBufferSize(size + 1); + buf[size++] = (byte) b; + } + + public void reset() { + size = 0; + } + + /** + * Returns a ByteArrayInputStream for reading back the written data + */ + public InputStream getInputStream() { + return new FastByteArrayInputStream(buf, size); + } + +} diff --git a/Mage/src/mage/util/TreeNode.java b/Mage/src/mage/util/TreeNode.java new file mode 100644 index 00000000000..d548c6fd738 --- /dev/null +++ b/Mage/src/mage/util/TreeNode.java @@ -0,0 +1,125 @@ +/* + * 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.util; + +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class TreeNode { + protected T data; + protected List> children; + + public TreeNode() { + super(); + children = new ArrayList>(); + } + + public TreeNode(T data) { + this(); + setData(data); + } + + public List> getChildren() { + return this.children; + } + + public int getNumberOfChildren() { + return getChildren().size(); + } + + public boolean hasChildren() { + return (getNumberOfChildren() > 0); + } + + public void setChildren(List> children) { + this.children = children; + } + + public void addChild(TreeNode child) { + children.add(child); + } + + public void addChild(T child) { + children.add(new TreeNode(child)); + } + + public void addChildAt(int index, TreeNode child) throws IndexOutOfBoundsException { + children.add(index, child); + } + + public void removeChildren() { + this.children.clear(); + } + + public void removeChildAt(int index) throws IndexOutOfBoundsException { + children.remove(index); + } + + public TreeNode getChildAt(int index) throws IndexOutOfBoundsException { + return children.get(index); + } + + public T getData() { + return this.data; + } + + public void setData(T data) { + this.data = data; + } + + @Override + public String toString() { + return getData().toString(); + } + + @Override + public int hashCode() { + return getData().hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final TreeNode other = (TreeNode) obj; + if (this.data != other.data && (this.data == null || !this.data.equals(other.data))) { + return false; + } + return true; + } + +}