From a5e6a3109b21263f66bc0fbbb8802d4ad77bbe3d Mon Sep 17 00:00:00 2001 From: magenoxx Date: Wed, 29 Dec 2010 12:32:32 +0300 Subject: [PATCH] [mage.core] Infect and Wither abilities. --- .../mage/abilities/keyword/InfectAbility.java | 84 +++++++++++++++++++ .../mage/abilities/keyword/WitherAbility.java | 75 +++++++++++++++++ .../mage/game/permanent/PermanentImpl.java | 17 ++-- Mage/src/mage/players/PlayerImpl.java | 13 +-- 4 files changed, 176 insertions(+), 13 deletions(-) create mode 100644 Mage/src/mage/abilities/keyword/InfectAbility.java create mode 100644 Mage/src/mage/abilities/keyword/WitherAbility.java diff --git a/Mage/src/mage/abilities/keyword/InfectAbility.java b/Mage/src/mage/abilities/keyword/InfectAbility.java new file mode 100644 index 00000000000..5c35d540a2d --- /dev/null +++ b/Mage/src/mage/abilities/keyword/InfectAbility.java @@ -0,0 +1,84 @@ +/* +* 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; + +/** + * 702.87. Infect + * + * 702.87a. Infect is a static ability. + * + * 702.87b. Damage dealt to a player by a source with infect doesn't cause that player to lose life. Rather, it causes the player to get that many poison counters. See rule 119.3. + * + * 702.87c. Damage dealt to a creature by a source with infect isn't marked on that creature. Rather, it causes that many -1/-1 counters to be put on that creature. See rule 119.3. + * + * 702.87d. If a permanent leaves the battlefield before an effect causes it to deal damage, its last known information + * (Last Known Information: Information about an object that's no longer in the zone it's expected to be in, or information about a player that's no longer in the game. This information captures that object's last existence in that zone or that player's last existence in the game....) + * 112.7a. Once activated or triggered, an ability exists on the stack independently of its source. Destruction or removal of the source after that time won't affect the ability. Note that some abilities cause a source to do something (for example, "Prodigal Sorcerer deals 1 damage... + * 608.2b. If the spell or ability specifies targets, it checks whether the targets are still legal. A target that's no longer in the zone it was in when it was targeted is illegal. Other changes to the game state may cause a target to no longer be legal; for example, its... + * 608.2g. If an effect requires information from the game (such as the number of creatures on the battlefield), the answer is determined only once, when the effect is applied. If the effect requires information from a specific object, including the source of the ability itself or a... + * 800.4f. If an effect requires information about a specific player, the effect uses the current information about that player if he or she is still in the game; otherwise, the effect uses the last known information about that player before he or she left the game. + * is used to determine whether it had infect. + * + * 702.87e. The infect rules function no matter what zone an object with infect deals damage from. + * + * 702.87f. Multiple instances of infect on the same object are redundant. + * + * @author nantuko + */ +public class InfectAbility extends StaticAbility { + + private static final InfectAbility fINSTANCE = new InfectAbility(); + + private Object readResolve() throws ObjectStreamException { + return fINSTANCE; + } + + public static InfectAbility getInstance() { + return fINSTANCE; + } + + private InfectAbility() { + super(Zone.ALL, null); + } + + @Override + public String getRule() { + return "Infect"; + } + + @Override + public InfectAbility copy() { + return fINSTANCE; + } + +} diff --git a/Mage/src/mage/abilities/keyword/WitherAbility.java b/Mage/src/mage/abilities/keyword/WitherAbility.java new file mode 100644 index 00000000000..53d05434cf0 --- /dev/null +++ b/Mage/src/mage/abilities/keyword/WitherAbility.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.keyword; + +import mage.Constants.Zone; +import mage.abilities.StaticAbility; + +import java.io.ObjectStreamException; + +/** + * 702.77. Wither + * + * 702.77a. Wither is a static ability. Damage dealt to a creature by a source with wither isn't marked on that creature. Rather, it causes that many -1/-1 counters to be put on that creature. See rule 119.3. + * + * 702.77b. If a permanent leaves the battlefield before an effect causes it to deal damage, its last known information is used to determine whether it had wither. + * + * 702.77c. The wither rules function no matter what zone an object with wither deals damage from. + * + * 702.77d. Multiple instances of wither on the same object are redundant. + * + * @author nantuko + */ +public class WitherAbility extends StaticAbility { + + private static final WitherAbility fINSTANCE = new WitherAbility(); + + private Object readResolve() throws ObjectStreamException { + return fINSTANCE; + } + + public static WitherAbility getInstance() { + return fINSTANCE; + } + + private WitherAbility() { + super(Zone.ALL, null); + } + + @Override + public String getRule() { + return "Wither"; + } + + @Override + public WitherAbility copy() { + return fINSTANCE; + } + +} diff --git a/Mage/src/mage/game/permanent/PermanentImpl.java b/Mage/src/mage/game/permanent/PermanentImpl.java index a6c501f9fca..53dd3b887a5 100644 --- a/Mage/src/mage/game/permanent/PermanentImpl.java +++ b/Mage/src/mage/game/permanent/PermanentImpl.java @@ -38,16 +38,11 @@ import mage.abilities.Ability; import mage.abilities.EvasionAbility; import mage.abilities.TriggeredAbility; import mage.abilities.effects.RestrictionEffect; -import mage.abilities.keyword.DeathtouchAbility; -import mage.abilities.keyword.DefenderAbility; -import mage.abilities.keyword.HasteAbility; -import mage.abilities.keyword.IndestructibleAbility; -import mage.abilities.keyword.LifelinkAbility; -import mage.abilities.keyword.ProtectionAbility; -import mage.abilities.keyword.ShroudAbility; +import mage.abilities.keyword.*; import mage.cards.CardImpl; import mage.counters.Counter; import mage.counters.Counters; +import mage.counters.MinusOneCounter; import mage.game.Game; import mage.game.events.DamageCreatureEvent; import mage.game.events.DamagePlaneswalkerEvent; @@ -467,7 +462,13 @@ public abstract class PermanentImpl> extends CardImpl if (this.damage + event.getAmount() > this.toughness.getValue()) { actualDamage = this.toughness.getValue() - this.damage; } - this.damage += actualDamage; + Permanent source = game.getPermanent(sourceId); + if (source != null && (source.getAbilities().containsKey(InfectAbility.getInstance().getId()) + || source.getAbilities().containsKey(WitherAbility.getInstance().getId()))) { + addCounters(new MinusOneCounter(actualDamage)); + } else { + this.damage += actualDamage; + } game.fireEvent(new DamagedCreatureEvent(objectId, sourceId, controllerId, actualDamage, combat)); return actualDamage; } diff --git a/Mage/src/mage/players/PlayerImpl.java b/Mage/src/mage/players/PlayerImpl.java index e6b58264df9..ac433d94ee5 100644 --- a/Mage/src/mage/players/PlayerImpl.java +++ b/Mage/src/mage/players/PlayerImpl.java @@ -52,17 +52,16 @@ import mage.abilities.SpecialAction; import mage.abilities.SpellAbility; import mage.abilities.TriggeredAbility; import mage.abilities.common.PassAbility; -import mage.abilities.keyword.KickerAbility; -import mage.abilities.keyword.LifelinkAbility; -import mage.abilities.keyword.ProtectionAbility; -import mage.abilities.keyword.ShroudAbility; +import mage.abilities.keyword.*; import mage.abilities.mana.ManaAbility; import mage.abilities.mana.ManaOptions; import mage.cards.Card; import mage.cards.Cards; import mage.cards.CardsImpl; import mage.cards.decks.Deck; +import mage.counters.CounterType; import mage.counters.Counters; +import mage.counters.MinusOneCounter; import mage.filter.FilterAbility; import mage.filter.common.FilterCreatureForAttack; import mage.filter.common.FilterCreatureForCombat; @@ -626,8 +625,12 @@ public abstract class PlayerImpl> implements Player, Ser if (!game.replaceEvent(event)) { int actualDamage = event.getAmount(); if (actualDamage > 0) { - actualDamage = this.loseLife(actualDamage, game); Permanent source = game.getPermanent(sourceId); + if (source != null && (source.getAbilities().containsKey(InfectAbility.getInstance().getId()))) { + getCounters().addCounter(CounterType.POISON.getInstance()); + } else { + actualDamage = this.loseLife(actualDamage, game); + } if (source != null && source.getAbilities().containsKey(LifelinkAbility.getInstance().getId())) { Player player = game.getPlayer(source.getControllerId()); player.gainLife(actualDamage, game);